Expand textcmd size byte to 16-bit word
Raises hard limit from 255 to 65535
This commit is contained in:
parent
29c55acc65
commit
05ff2f9ce9
3 changed files with 54 additions and 35 deletions
|
|
@ -266,27 +266,27 @@ void RegisterNetXCmd(netxcmd_t id, void (*cmd_f)(UINT8 **p, INT32 playernum))
|
|||
|
||||
void SendNetXCmdForPlayer(UINT8 playerid, netxcmd_t id, const void *param, size_t nparam)
|
||||
{
|
||||
if (localtextcmd[playerid][0]+2+nparam > MAXTEXTCMD)
|
||||
if (((UINT16*)localtextcmd[playerid])[0]+3+nparam > MAXTEXTCMD)
|
||||
{
|
||||
// for future reference: if (cv_debug) != debug disabled.
|
||||
CONS_Alert(CONS_ERROR, M_GetText("NetXCmd buffer full, cannot add netcmd %d! (size: %d, needed: %s)\n"), id, localtextcmd[playerid][0], sizeu1(nparam));
|
||||
// for future reference: if (cht_debug) != debug disabled.
|
||||
CONS_Alert(CONS_ERROR, M_GetText("NetXCmd buffer full, cannot add netcmd %d! (size: %d, needed: %s)\n"), id, ((UINT16*)localtextcmd[playerid])[0], sizeu1(nparam));
|
||||
return;
|
||||
}
|
||||
|
||||
localtextcmd[playerid][0]++;
|
||||
localtextcmd[playerid][localtextcmd[playerid][0]] = (UINT8)id;
|
||||
((UINT16*)localtextcmd[playerid])[0]++;
|
||||
localtextcmd[playerid][((UINT16*)localtextcmd[playerid])[0] + 1] = (UINT8)id;
|
||||
|
||||
if (param && nparam)
|
||||
{
|
||||
M_Memcpy(&localtextcmd[playerid][localtextcmd[playerid][0] + 1], param, nparam);
|
||||
localtextcmd[playerid][0] = (UINT8)(localtextcmd[playerid][0] + (UINT8)nparam);
|
||||
M_Memcpy(&localtextcmd[playerid][((UINT16*)localtextcmd[playerid])[0] + 2], param, nparam);
|
||||
((UINT16*)localtextcmd[playerid])[0] = ((UINT16*)localtextcmd[playerid])[0] + (UINT8)nparam;
|
||||
}
|
||||
}
|
||||
|
||||
UINT8 GetFreeXCmdSize(UINT8 playerid)
|
||||
{
|
||||
// -1 for the size and another -1 for the ID.
|
||||
return (UINT8)(localtextcmd[playerid][0] - 2);
|
||||
// -2 for the size and another -1 for the ID.
|
||||
return (UINT8)(localtextcmd[playerid][0] - 3);
|
||||
}
|
||||
|
||||
// Frees all textcmd memory for the specified tic
|
||||
|
|
@ -397,9 +397,9 @@ static void ExtraDataTicker(void)
|
|||
if (bufferstart)
|
||||
{
|
||||
UINT8 *curpos = bufferstart;
|
||||
UINT8 *bufferend = &curpos[curpos[0]+1];
|
||||
UINT8 *bufferend = &curpos[((UINT16*)curpos)[0]+2];
|
||||
|
||||
curpos++;
|
||||
curpos += 2;
|
||||
while (curpos < bufferend)
|
||||
{
|
||||
if (*curpos < MAXNETXCMD && listnetxcmd[*curpos])
|
||||
|
|
@ -3895,7 +3895,7 @@ void SV_StopServer(void)
|
|||
gamestate = wipegamestate = GS_NULL;
|
||||
|
||||
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
|
||||
localtextcmd[i][0] = 0;
|
||||
((UINT16*)localtextcmd[i])[0] = 0;
|
||||
|
||||
for (i = firstticstosend; i < firstticstosend + BACKUPTICS; i++)
|
||||
D_Clearticcmd(i);
|
||||
|
|
@ -3953,7 +3953,7 @@ static size_t TotalTextCmdPerTic(tic_t tic)
|
|||
{
|
||||
UINT8 *textcmd = D_GetExistingTextcmd(tic, i);
|
||||
if ((!i || playeringame[i]) && textcmd)
|
||||
total += 2 + textcmd[0]; // "+2" for size and playernum
|
||||
total += 3 + ((UINT16*)textcmd)[0]; // "+2" for size and playernum
|
||||
}
|
||||
|
||||
return total;
|
||||
|
|
@ -4684,9 +4684,17 @@ static void HandlePacketFromPlayer(SINT8 node)
|
|||
tic_t tic = maketic;
|
||||
UINT8 *textcmd;
|
||||
|
||||
UINT16 incoming_size;
|
||||
|
||||
{
|
||||
UINT8 *incoming = netbuffer->u.textcmd;
|
||||
|
||||
incoming_size = READUINT16(incoming);
|
||||
}
|
||||
|
||||
// ignore if the textcmd has a reported size of zero
|
||||
// this shouldn't be sent at all
|
||||
if (!netbuffer->u.textcmd[0])
|
||||
if (!incoming_size)
|
||||
{
|
||||
DEBFILE(va("GetPacket: Textcmd with size 0 detected! (node %u, player %d)\n",
|
||||
node, netconsole));
|
||||
|
|
@ -4695,11 +4703,11 @@ static void HandlePacketFromPlayer(SINT8 node)
|
|||
}
|
||||
|
||||
// ignore if the textcmd size var is actually larger than it should be
|
||||
// BASEPACKETSIZE + 1 (for size) + textcmd[0] should == datalength
|
||||
if (netbuffer->u.textcmd[0] > (size_t)doomcom->datalength-BASEPACKETSIZE-1)
|
||||
// BASEPACKETSIZE + 2 (for size) + textcmd[0] should == datalength
|
||||
if (incoming_size > (size_t)doomcom->datalength-BASEPACKETSIZE-2)
|
||||
{
|
||||
DEBFILE(va("GetPacket: Bad Textcmd packet size! (expected %d, actual %s, node %u, player %d)\n",
|
||||
netbuffer->u.textcmd[0], sizeu1((size_t)doomcom->datalength-BASEPACKETSIZE-1),
|
||||
incoming_size, sizeu1((size_t)doomcom->datalength-BASEPACKETSIZE-2),
|
||||
node, netconsole));
|
||||
Net_UnAcknowledgePacket(node);
|
||||
break;
|
||||
|
|
@ -4708,12 +4716,12 @@ static void HandlePacketFromPlayer(SINT8 node)
|
|||
// check if tic that we are making isn't too large else we cannot send it :(
|
||||
// doomcom->numslots+1 "+1" since doomcom->numslots can change within this time and sent time
|
||||
j = software_MAXPACKETLENGTH
|
||||
- (netbuffer->u.textcmd[0]+2+BASESERVERTICSSIZE
|
||||
- (incoming_size + 3 + BASESERVERTICSSIZE
|
||||
+ (doomcom->numslots+1)*sizeof(ticcmd_t));
|
||||
|
||||
// search a tic that have enougth space in the ticcmd
|
||||
while ((textcmd = D_GetExistingTextcmd(tic, netconsole)),
|
||||
(TotalTextCmdPerTic(tic) > j || netbuffer->u.textcmd[0] + (textcmd ? textcmd[0] : 0) > MAXTEXTCMD)
|
||||
(TotalTextCmdPerTic(tic) > j || incoming_size + (textcmd ? ((UINT16*)textcmd)[0] : 0) > MAXTEXTCMD)
|
||||
&& tic < firstticstosend + BACKUPTICS)
|
||||
tic++;
|
||||
|
||||
|
|
@ -4730,10 +4738,10 @@ static void HandlePacketFromPlayer(SINT8 node)
|
|||
if (!textcmd) textcmd = D_GetTextcmd(tic, netconsole);
|
||||
|
||||
DEBFILE(va("textcmd put in tic %u at position %d (player %d) ftts %u mk %u\n",
|
||||
tic, textcmd[0]+1, netconsole, firstticstosend, maketic));
|
||||
tic, ((UINT16*)textcmd)[0]+2, netconsole, firstticstosend, maketic));
|
||||
|
||||
M_Memcpy(&textcmd[textcmd[0]+1], netbuffer->u.textcmd+1, netbuffer->u.textcmd[0]);
|
||||
textcmd[0] += (UINT8)netbuffer->u.textcmd[0];
|
||||
M_Memcpy(&textcmd[((UINT16*)textcmd)[0]+2], netbuffer->u.textcmd+2, incoming_size);
|
||||
((UINT16*)textcmd)[0] += incoming_size;
|
||||
}
|
||||
break;
|
||||
case PT_LOGIN:
|
||||
|
|
@ -4866,7 +4874,7 @@ static void HandlePacketFromPlayer(SINT8 node)
|
|||
for (j = 0; j < numtxtpak; j++)
|
||||
{
|
||||
INT32 k = *txtpak++; // playernum
|
||||
const size_t txtsize = txtpak[0]+1;
|
||||
const size_t txtsize = ((UINT16*)txtpak)[0]+2;
|
||||
|
||||
if (i >= gametic) // Don't copy old net commands
|
||||
M_Memcpy(D_GetTextcmd(i, k), txtpak, txtsize);
|
||||
|
|
@ -5246,7 +5254,7 @@ static void CL_SendClientCmd(void)
|
|||
// Send extra data if needed
|
||||
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
|
||||
{
|
||||
if (localtextcmd[i][0])
|
||||
if (((UINT16*)localtextcmd[i])[0])
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
|
|
@ -5264,10 +5272,10 @@ static void CL_SendClientCmd(void)
|
|||
break;
|
||||
}
|
||||
|
||||
M_Memcpy(netbuffer->u.textcmd, localtextcmd[i], localtextcmd[i][0]+1);
|
||||
M_Memcpy(netbuffer->u.textcmd, localtextcmd[i], ((UINT16*)localtextcmd[i])[0]+2);
|
||||
// All extra data have been sent
|
||||
if (HSendPacket(servernode, true, 0, localtextcmd[i][0]+1)) // Send can fail...
|
||||
localtextcmd[i][0] = 0;
|
||||
if (HSendPacket(servernode, true, 0, ((UINT16*)localtextcmd[i])[0]+2)) // Send can fail...
|
||||
((UINT16*)localtextcmd[i])[0] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5367,14 +5375,14 @@ static void SV_SendTics(void)
|
|||
for (j = 0; j < MAXPLAYERS; j++)
|
||||
{
|
||||
UINT8 *textcmd = D_GetExistingTextcmd(i, j);
|
||||
INT32 size = textcmd ? textcmd[0] : 0;
|
||||
INT32 size = textcmd ? ((UINT16*)textcmd)[0] : 0;
|
||||
|
||||
if ((!j || playeringame[j]) && size)
|
||||
{
|
||||
(*ntextcmd)++;
|
||||
WRITEUINT8(bufpos, j);
|
||||
M_Memcpy(bufpos, textcmd, size + 1);
|
||||
bufpos += size + 1;
|
||||
WRITEUINT16(bufpos, ((UINT16*)textcmd)[0]);
|
||||
WRITEMEM(bufpos, &textcmd[2], size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -357,7 +357,7 @@ typedef struct
|
|||
client4cmd_pak client4pak; // 324 bytes(?)
|
||||
servertics_pak serverpak; // 132495 bytes (more around 360, no?)
|
||||
serverconfig_pak servercfg; // 773 bytes
|
||||
UINT8 textcmd[MAXTEXTCMD+1]; // 66049 bytes (wut??? 64k??? More like 257 bytes...)
|
||||
UINT8 textcmd[MAXTEXTCMD+2]; // 66049 bytes (wut??? 64k??? More like 258 bytes...)
|
||||
char filetxpak[sizeof (filetx_pak)];// 139 bytes
|
||||
char fileack[sizeof (fileack_pak)];
|
||||
UINT8 filereceived;
|
||||
|
|
|
|||
19
src/d_net.c
19
src/d_net.c
|
|
@ -29,6 +29,8 @@
|
|||
#include "z_zone.h"
|
||||
#include "i_tcp.h"
|
||||
#include "d_main.h" // srb2home
|
||||
#include "stun.h"
|
||||
#include "byteptr.h"
|
||||
|
||||
//
|
||||
// NETWORKING
|
||||
|
|
@ -897,11 +899,20 @@ static void DebugPrintpacket(const char *header)
|
|||
case PT_TEXTCMD:
|
||||
case PT_TEXTCMD2:
|
||||
case PT_TEXTCMD3:
|
||||
case PT_TEXTCMD4:
|
||||
fprintf(debugfile, " length %d\n ", netbuffer->u.textcmd[0]);
|
||||
fprintf(debugfile, "[%s]", netxcmdnames[netbuffer->u.textcmd[1] - 1]);
|
||||
fprintfstringnewline((char *)netbuffer->u.textcmd + 2, netbuffer->u.textcmd[0] - 1);
|
||||
case PT_TEXTCMD4: {
|
||||
UINT16 size;
|
||||
|
||||
{
|
||||
UINT8 *p = netbuffer->u.textcmd;
|
||||
|
||||
size = READUINT16(p);
|
||||
}
|
||||
|
||||
fprintf(debugfile, " length %d\n", size);
|
||||
fprintf(debugfile, "[%s]", netxcmdnames[netbuffer->u.textcmd[2] - 1]);
|
||||
fprintfstringnewline((char *)netbuffer->u.textcmd + 3, size - 2);
|
||||
break;
|
||||
}
|
||||
case PT_SERVERCFG:
|
||||
fprintf(debugfile, " playerslots %d clientnode %d serverplayer %d "
|
||||
"gametic %u gamestate %d gametype %d modifiedgame %d\n",
|
||||
|
|
|
|||
Loading…
Reference in a new issue