Skip to content

Commit

Permalink
Added a _DEBUG check for attempting to write too large of a packet to…
Browse files Browse the repository at this point in the history
… a demo file.
  • Loading branch information
danij committed Jan 23, 2008
1 parent b1a8ed3 commit decff35
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions doomsday/engine/portable/src/net_demo.c
Expand Up @@ -246,13 +246,15 @@ void Demo_WritePacket(int playerNum)
// Is this client recording?
if(!clients[playerNum].recording)
return;

if(!inf->canwrite)
{
if(netBuffer.msg.type != PSV_HANDSHAKE)
return;
// The handshake has arrived. Now we can begin writing.
inf->canwrite = true;
}

if(clients[playerNum].recordPaused)
{
// Some types of packet are not written in record-paused mode.
Expand All @@ -266,7 +268,7 @@ void Demo_WritePacket(int playerNum)

file = clients[playerNum].demo;

#ifdef _DEBUG
#if _DEBUG
if(!file)
Con_Error("Demo_WritePacket: No demo file!\n");
#endif
Expand All @@ -286,6 +288,12 @@ void Demo_WritePacket(int playerNum)
lzWrite(&ptime, 1, file);

// The header.

#if _DEBUG
if(netBuffer.length >= sizeof(hdr.length))
Con_Error("Demo_WritePacket: Write buffer too large!\n");
#endif

hdr.length = (ushort) 1 + netBuffer.length;
lzWrite(&hdr, sizeof(hdr), file);

Expand All @@ -296,32 +304,35 @@ void Demo_WritePacket(int playerNum)

void Demo_BroadcastPacket(void)
{
int i;
int i;

// Write packet to all recording demo files.
for(i = 0; i < MAXPLAYERS; i++)
for(i = 0; i < MAXPLAYERS; ++i)
Demo_WritePacket(i);
}

boolean Demo_BeginPlayback(char *fileName)
{
char buf[256];
int i;
char buf[256];
int i;

if(playback)
return false; // Already in playback.
return false; // Already in playback.
if(netgame || isClient)
return false; // Can't do it.
return false; // Can't do it.

// Check that we aren't recording anything.
for(i = 0; i < MAXPLAYERS; i++)
for(i = 0; i < MAXPLAYERS; ++i)
if(clients[i].recording)
return false;

// Open the demo file.
sprintf(buf, "%s%s", Dir_IsAbsolute(fileName) ? "" : demoPath, fileName);
M_TranslatePath(buf, buf);
playdemo = lzOpen(buf, "rp");
if(!playdemo)
return false; // Failed to open the file.
return false; // Failed to open the file.

// OK, let's begin the demo.
playback = true;
isServer = false;
Expand All @@ -337,12 +348,13 @@ boolean Demo_BeginPlayback(char *fileName)
// Start counting frames from here.
if(ArgCheck("-timedemo"))
r_framecounter = 0;

return true;
}

void Demo_StopPlayback(void)
{
float diff;
float diff;

if(!playback)
return;
Expand Down Expand Up @@ -376,12 +388,13 @@ void Demo_StopPlayback(void)

boolean Demo_ReadPacket(void)
{
static byte ptime;
int nowtime = DEMOTIC;
static byte ptime;
int nowtime = DEMOTIC;
demopacket_header_t hdr;

if(!playback)
return false;

if(lzEOF(playdemo))
{
Demo_StopPlayback();
Expand All @@ -400,14 +413,14 @@ boolean Demo_ReadPacket(void)

// Check if the packet can be read.
if(Net_TimeDelta(nowtime - readInfo.begintime, ptime) < 0)
return false; // Can't read yet.
return false; // Can't read yet.

// Read the packet.
lzRead(&hdr, sizeof(hdr), playdemo);

// Get the packet.
netBuffer.length = hdr.length - 1 /*netBuffer.headerLength */ ;
netBuffer.player = 0; // From the server.
netBuffer.length = hdr.length - 1;
netBuffer.player = 0; // From the server.
netBuffer.msg.id = 0;
netBuffer.msg.type = lzGetC(playdemo);
lzRead(netBuffer.msg.data, (long) netBuffer.length, playdemo);
Expand All @@ -429,11 +442,10 @@ Con_Printf("RDP: pt=%i ang=%i ld=%i len=%i type=%i\n", ptime,
*/
void Demo_WriteLocalCamera(int plnum)
{
mobj_t *mo = players[plnum].mo;
int z;
fixed_t x, y;
byte flags;
boolean incfov = (writeInfo[plnum].fov != fieldOfView);
mobj_t *mo = players[plnum].mo;
fixed_t x, y, z;
byte flags;
boolean incfov = (writeInfo[plnum].fov != fieldOfView);

if(!mo)
return;
Expand Down

0 comments on commit decff35

Please sign in to comment.