diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 638a85ba4..c0d2cf52f 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -289,27 +289,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 (((UINT16*)localtextcmd[playerid])[0]+3+nparam > MAXTEXTCMD) + if (localtextcmd[playerid][0]+2+nparam > MAXTEXTCMD) { // 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)); + CONS_Alert(CONS_ERROR, M_GetText("NetXCmd buffer full, cannot add netcmd %d! (size: %d, needed: %s)\n"), id, localtextcmd[playerid][0], sizeu1(nparam)); return; } - ((UINT16*)localtextcmd[playerid])[0]++; - localtextcmd[playerid][((UINT16*)localtextcmd[playerid])[0] + 1] = (UINT8)id; + localtextcmd[playerid][0]++; + localtextcmd[playerid][localtextcmd[playerid][0]] = (UINT8)id; if (param && nparam) { - memcpy(&localtextcmd[playerid][((UINT16*)localtextcmd[playerid])[0] + 2], param, nparam); - ((UINT16*)localtextcmd[playerid])[0] = ((UINT16*)localtextcmd[playerid])[0] + (UINT8)nparam; + memcpy(&localtextcmd[playerid][localtextcmd[playerid][0] + 1], param, nparam); + localtextcmd[playerid][0] = (UINT8)(localtextcmd[playerid][0] + (UINT8)nparam); } } UINT8 GetFreeXCmdSize(UINT8 playerid) { - // -2 for the size and another -1 for the ID. - return (UINT8)(localtextcmd[playerid][0] - 3); + // -1 for the size and another -1 for the ID. + return (UINT8)(localtextcmd[playerid][0] - 2); } // Frees all textcmd memory for the specified tic @@ -422,9 +422,9 @@ static boolean ExtraDataTicker(void) if (bufferstart) { UINT8 *curpos = bufferstart; - UINT8 *bufferend = &curpos[((UINT16*)curpos)[0]+2]; + UINT8 *bufferend = &curpos[curpos[0]+1]; - curpos += 2; + curpos++; while (curpos < bufferend) { if (*curpos < MAXNETXCMD && listnetxcmd[*curpos]) @@ -4121,7 +4121,7 @@ void SV_StopServer(void) P_UnloadLevel(); for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) - ((UINT16*)localtextcmd[i])[0] = 0; + localtextcmd[i][0] = 0; for (i = firstticstosend; i < firstticstosend + BACKUPTICS; i++) D_Clearticcmd(i); @@ -4173,7 +4173,7 @@ static size_t TotalTextCmdPerTic(tic_t tic) { UINT8 *textcmd = D_GetExistingTextcmd(tic, i); if ((!i || playeringame[i]) && textcmd) - total += 3 + ((UINT16*)textcmd)[0]; // "+2" for size and playernum + total += 2 + textcmd[0]; // "+2" for size and playernum } return total; @@ -4815,17 +4815,9 @@ static void PT_TextCmd(SINT8 node, INT32 netconsole) 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 (!incoming_size) + if (!netbuffer->u.textcmd[0]) { DEBFILE(va("GetPacket: Textcmd with size 0 detected! (node %u, player %d)\n", node, netconsole)); @@ -4834,11 +4826,11 @@ static void PT_TextCmd(SINT8 node, INT32 netconsole) } // ignore if the textcmd size var is actually larger than it should be - // BASEPACKETSIZE + 2 (for size) + textcmd[0] should == datalength - if (incoming_size > (size_t)doomcom->datalength-BASEPACKETSIZE-2) + // BASEPACKETSIZE + 1 (for size) + textcmd[0] should == datalength + if (netbuffer->u.textcmd[0] > (size_t)doomcom->datalength-BASEPACKETSIZE-1) { DEBFILE(va("GetPacket: Bad Textcmd packet size! (expected %d, actual %s, node %u, player %d)\n", - incoming_size, sizeu1((size_t)doomcom->datalength-BASEPACKETSIZE-2), + netbuffer->u.textcmd[0], sizeu1((size_t)doomcom->datalength-BASEPACKETSIZE-1), node, netconsole)); Net_UnAcknowledgePacket(node); return; @@ -4847,12 +4839,12 @@ static void PT_TextCmd(SINT8 node, INT32 netconsole) // 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 - - (incoming_size + 3 + BASESERVERTICSSIZE + - (netbuffer->u.textcmd[0]+2+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 || incoming_size + (textcmd ? ((UINT16*)textcmd)[0] : 0) > MAXTEXTCMD) + (TotalTextCmdPerTic(tic) > j || netbuffer->u.textcmd[0] + (textcmd ? textcmd[0] : 0) > MAXTEXTCMD) && tic < firstticstosend + BACKUPTICS) tic++; @@ -4869,10 +4861,10 @@ static void PT_TextCmd(SINT8 node, INT32 netconsole) 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, ((UINT16*)textcmd)[0]+2, netconsole, firstticstosend, maketic)); + tic, textcmd[0]+1, netconsole, firstticstosend, maketic)); - memcpy(&textcmd[((UINT16*)textcmd)[0]+2], netbuffer->u.textcmd+2, incoming_size); - ((UINT16*)textcmd)[0] += incoming_size; + memcpy(&textcmd[textcmd[0]+1], netbuffer->u.textcmd+1, netbuffer->u.textcmd[0]); + textcmd[0] += (UINT8)netbuffer->u.textcmd[0]; } } @@ -5070,7 +5062,7 @@ static void PT_ServerTics(SINT8 node, INT32 netconsole) for (j = 0; j < numtxtpak; j++) { INT32 k = *txtpak++; // playernum - const size_t txtsize = ((UINT16*)txtpak)[0]+2; + const size_t txtsize = txtpak[0]+1; if (i >= gametic) // Don't copy old net commands memcpy(D_GetTextcmd(i, k), txtpak, txtsize); @@ -5761,7 +5753,7 @@ static void CL_SendClientCmd(void) // Send extra data if needed for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (((UINT16*)localtextcmd[i])[0]) + if (localtextcmd[i][0]) { switch (i) { @@ -5779,10 +5771,10 @@ static void CL_SendClientCmd(void) break; } - memcpy(netbuffer->u.textcmd, localtextcmd[i], ((UINT16*)localtextcmd[i])[0]+2); + memcpy(netbuffer->u.textcmd, localtextcmd[i], localtextcmd[i][0]+1); // All extra data have been sent - if (HSendPacket(servernode, true, 0, ((UINT16*)localtextcmd[i])[0]+2)) // Send can fail... - ((UINT16*)localtextcmd[i])[0] = 0; + if (HSendPacket(servernode, true, 0, localtextcmd[i][0]+1)) // Send can fail... + localtextcmd[i][0] = 0; } } } @@ -5880,14 +5872,14 @@ static void SV_SendTics(void) for (j = 0; j < MAXPLAYERS; j++) { UINT8 *textcmd = D_GetExistingTextcmd(i, j); - INT32 size = textcmd ? ((UINT16*)textcmd)[0] : 0; + INT32 size = textcmd ? textcmd[0] : 0; if ((!j || playeringame[j]) && size) { (*ntextcmd)++; WRITEUINT8(bufpos, j); - WRITEUINT16(bufpos, ((UINT16*)textcmd)[0]); - WRITEMEM(bufpos, &textcmd[2], size); + memcpy(bufpos, textcmd, size + 1); + bufpos += size + 1; } } } diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 9ea8b32bd..f08977d01 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -396,7 +396,7 @@ struct doomdata_t client4cmd_pak client4pak; servertics_pak serverpak; serverconfig_pak servercfg; - UINT8 textcmd[MAXTEXTCMD+2]; + UINT8 textcmd[MAXTEXTCMD+1]; char filetxpak[sizeof (filetx_pak)]; char fileack[sizeof (fileack_pak)]; UINT8 filereceived; diff --git a/src/d_net.c b/src/d_net.c index 58cab71d7..4e7c23191 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -884,20 +884,11 @@ static void DebugPrintpacket(const char *header) case PT_TEXTCMD: case PT_TEXTCMD2: case PT_TEXTCMD3: - 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); + 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); break; - } case PT_SERVERCFG: fprintf(debugfile, " playerslots %d clientnode %d serverplayer %d " "gametic %u gamestate %d gametype %d modifiedgame %d\n",