2007-01-15 12:09:25 -08:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
|
|
|
Copyright (C) 2005-2007 Warzone Resurrection Project
|
|
|
|
|
|
|
|
Warzone 2100 is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Warzone 2100 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-06-28 10:47:08 -07:00
|
|
|
// ////////////////////////////////////////////////////////////////////////
|
|
|
|
// Includes
|
2006-06-02 12:34:58 -07:00
|
|
|
#include "lib/framework/frame.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
#include <time.h>
|
2006-06-21 10:15:18 -07:00
|
|
|
#include <physfs.h>
|
2008-03-16 05:39:08 -07:00
|
|
|
|
|
|
|
#include "netlog.h"
|
|
|
|
#include "netplay.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
// ////////////////////////////////////////////////////////////////////////
|
|
|
|
// Logging for degug only
|
|
|
|
// ////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-02-15 12:55:38 -08:00
|
|
|
static const char *packetname[NUM_GAME_PACKETS] =
|
2007-07-15 08:26:23 -07:00
|
|
|
{
|
|
|
|
"NET_DROID",
|
|
|
|
"NET_DROIDINFO",
|
|
|
|
"NET_DROIDDEST",
|
|
|
|
"NET_DROIDMOVE",
|
|
|
|
"NET_GROUPORDER",
|
|
|
|
"NET_TEMPLATE",
|
|
|
|
"NET_TEMPLATEDEST",
|
|
|
|
"NET_FEATUREDEST",
|
|
|
|
"NET_PING",
|
|
|
|
"NET_CHECK_DROID",
|
|
|
|
"NET_CHECK_STRUCT",
|
|
|
|
"NET_CHECK_POWER",
|
2008-02-03 06:42:02 -08:00
|
|
|
"NET_PLAYER_STATS",
|
2007-07-15 08:26:23 -07:00
|
|
|
"NET_BUILD",
|
|
|
|
"NET_STRUCTDEST",
|
|
|
|
"NET_BUILDFINISHED",
|
|
|
|
"NET_RESEARCH",
|
|
|
|
"NET_TEXTMSG",
|
|
|
|
"NET_LEAVING",
|
|
|
|
"NET_REQUESTDROID",
|
|
|
|
"NET_PLAYERCOMPLETE",
|
2008-02-10 13:01:57 -08:00
|
|
|
"NET_REQUESTPLAYER",
|
2007-07-15 08:26:23 -07:00
|
|
|
"NET_STRUCT",
|
|
|
|
"NET_WHOLEDROID",
|
|
|
|
"NET_FEATURES",
|
|
|
|
"NET_PLAYERRESPONDING",
|
|
|
|
"NET_OPTIONS",
|
|
|
|
"NET_KICK",
|
|
|
|
"NET_SECONDARY",
|
|
|
|
"NET_FIREUP",
|
|
|
|
"NET_ALLIANCE",
|
|
|
|
"NET_GIFT",
|
|
|
|
"NET_DEMOLISH",
|
|
|
|
"NET_COLOURREQUEST",
|
|
|
|
"NET_ARTIFACTS",
|
|
|
|
"NET_DMATCHWIN",
|
|
|
|
"NET_SCORESUBMIT",
|
|
|
|
"NET_DESTROYXTRA",
|
|
|
|
"NET_VTOL",
|
|
|
|
"NET_UNUSED_39",
|
|
|
|
"NET_WHITEBOARD",
|
|
|
|
"NET_SECONDARY_ALL",
|
|
|
|
"NET_DROIDEMBARK",
|
|
|
|
"NET_DROIDDISEMBARK",
|
|
|
|
"NET_RESEARCHSTATUS",
|
|
|
|
"NET_LASSAT",
|
|
|
|
"NET_REQUESTMAP",
|
|
|
|
"NET_AITEXTMSG",
|
|
|
|
"NET_TEAMS_ON",
|
|
|
|
"NET_BEACONMSG",
|
|
|
|
"NET_SET_TEAMS",
|
2008-02-15 12:55:38 -08:00
|
|
|
"NET_TEAMREQUEST",
|
|
|
|
"NET_JOIN",
|
|
|
|
"NET_ACCEPTED",
|
|
|
|
"NET_PLAYER_INFO",
|
|
|
|
"NET_PLAYER_JOINED",
|
|
|
|
"NET_PLAYER_LEFT",
|
|
|
|
"NET_GAME_FLAGS"
|
2007-07-15 08:26:23 -07:00
|
|
|
};
|
|
|
|
|
2006-06-21 10:15:18 -07:00
|
|
|
static PHYSFS_file *pFileHandle;
|
2008-02-15 12:55:38 -08:00
|
|
|
static uint32_t packetcount[2][NUM_GAME_PACKETS];
|
|
|
|
static uint32_t packetsize[2][NUM_GAME_PACKETS];
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2006-09-16 10:41:40 -07:00
|
|
|
BOOL NETstartLogging(void)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
time_t aclock;
|
|
|
|
struct tm *newtime;
|
2006-06-21 10:15:18 -07:00
|
|
|
char buf[256];
|
2008-03-23 06:12:58 -07:00
|
|
|
static const char filename[] = "netplay.log";
|
2007-07-15 08:26:23 -07:00
|
|
|
int i;
|
|
|
|
|
2008-02-15 12:55:38 -08:00
|
|
|
for (i = 0; i < NUM_GAME_PACKETS; i++)
|
2007-07-15 08:26:23 -07:00
|
|
|
{
|
|
|
|
packetcount[0][i] = 0;
|
|
|
|
packetsize[0][i] = 0;
|
|
|
|
packetcount[1][i] = 0;
|
|
|
|
packetsize[1][i] = 0;
|
|
|
|
}
|
2006-06-02 12:34:58 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
time( &aclock ); /* Get time in seconds */
|
2006-04-08 12:14:30 -07:00
|
|
|
newtime = localtime( &aclock ); /* Convert time to struct */
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-07-15 08:26:23 -07:00
|
|
|
pFileHandle = PHYSFS_openWrite( filename ); // open the file
|
2007-06-28 10:47:08 -07:00
|
|
|
if (!pFileHandle)
|
|
|
|
{
|
2007-07-15 08:26:23 -07:00
|
|
|
debug(LOG_ERROR, "Could not create net log %s: %s", filename,
|
|
|
|
PHYSFS_getLastError());
|
2007-06-28 10:47:08 -07:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-10-24 14:11:29 -07:00
|
|
|
snprintf(buf, sizeof(buf), "NETPLAY log: %s\n", asctime(newtime));
|
|
|
|
// Guarantee to nul-terminate
|
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
2006-06-21 10:15:18 -07:00
|
|
|
PHYSFS_write( pFileHandle, buf, strlen( buf ), 1 );
|
2007-06-28 10:47:08 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-09-16 10:41:40 -07:00
|
|
|
BOOL NETstopLogging(void)
|
2006-06-02 12:34:58 -07:00
|
|
|
{
|
2007-07-15 08:26:23 -07:00
|
|
|
char buf[256];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Output stats */
|
2008-02-15 12:55:38 -08:00
|
|
|
for (i = 0; i < NUM_GAME_PACKETS; i++)
|
2007-07-15 08:26:23 -07:00
|
|
|
{
|
2007-10-24 14:11:29 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s: received %u times, %u bytes; sent %u times, %u bytes\n", packetname[i],
|
2007-07-15 08:26:23 -07:00
|
|
|
packetcount[0][i], packetsize[0][i], packetcount[1][i], packetsize[1][i]);
|
2007-10-24 14:11:29 -07:00
|
|
|
// Guarantee to nul-terminate
|
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
2007-07-15 08:26:23 -07:00
|
|
|
PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
|
|
|
|
}
|
|
|
|
|
2006-08-06 03:23:39 -07:00
|
|
|
if (!PHYSFS_close(pFileHandle))
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2006-08-06 03:23:39 -07:00
|
|
|
debug(LOG_ERROR, "Could not close net log: %s", PHYSFS_getLastError());
|
2007-06-28 10:47:08 -07:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-07-15 08:26:23 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-07-15 08:26:23 -07:00
|
|
|
void NETlogPacket(NETMSG *msg, BOOL received)
|
|
|
|
{
|
2008-02-15 12:55:38 -08:00
|
|
|
if (msg->type >= NUM_GAME_PACKETS)
|
2007-07-15 08:26:23 -07:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
packetcount[received][msg->type]++;
|
|
|
|
packetsize[received][msg->type] += msg->size;
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2006-09-24 12:11:34 -07:00
|
|
|
BOOL NETlogEntry(const char *str,UDWORD a,UDWORD b)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-10-24 14:11:29 -07:00
|
|
|
static const char star_line[] = "************************************************************\n";
|
2007-06-28 10:47:08 -07:00
|
|
|
static UDWORD lastframe = 0;
|
|
|
|
UDWORD frame= frameGetFrameNumber();
|
|
|
|
time_t aclock;
|
|
|
|
struct tm *newtime;
|
2006-06-21 10:15:18 -07:00
|
|
|
char buf[256];
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
#ifndef MASSIVELOGS
|
|
|
|
if(a ==9 || a==10)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
2006-06-02 12:34:58 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
time( &aclock ); /* Get time in seconds */
|
|
|
|
newtime = localtime( &aclock ); /* Convert time to struct */
|
|
|
|
|
|
|
|
// check to see if a new frame.
|
|
|
|
if(frame != lastframe)
|
|
|
|
{
|
2007-10-24 14:11:29 -07:00
|
|
|
static const char dash_line[] = "-----------------------------------------------------------\n";
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
lastframe = frame;
|
2007-10-24 14:11:29 -07:00
|
|
|
|
|
|
|
PHYSFS_write(pFileHandle, dash_line, strlen(dash_line), 1);
|
2006-06-02 12:34:58 -07:00
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-24 14:11:29 -07:00
|
|
|
if (a <= 51)
|
|
|
|
// replace common msgs with txt descriptions
|
|
|
|
snprintf(buf, sizeof(buf), "%s \t: %s \t:%d\t\t%s", str, packetname[a], b, asctime(newtime));
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%s \t:%d \t\t\t:%d\t\t%s", str, a, b, asctime(newtime));
|
|
|
|
|
|
|
|
// Guarantee to nul-terminate
|
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
|
|
|
|
2008-01-09 15:07:36 -08:00
|
|
|
if (a == 18) // NET_LEAVING
|
2007-10-24 14:11:29 -07:00
|
|
|
// Write a starry line above NET_LEAVING messages
|
|
|
|
PHYSFS_write(pFileHandle, star_line, strlen(star_line), 1);
|
|
|
|
|
|
|
|
PHYSFS_write(pFileHandle, buf, strlen( buf ), 1);
|
|
|
|
|
2008-01-09 15:07:36 -08:00
|
|
|
if (a == 18) // NET_LEAVING
|
2007-10-24 14:11:29 -07:00
|
|
|
// Write a starry line below NET_LEAVING messages
|
|
|
|
PHYSFS_write(pFileHandle, star_line, strlen(star_line), 1);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2006-06-21 10:15:18 -07:00
|
|
|
PHYSFS_flush(pFileHandle);
|
2007-06-28 10:47:08 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|