From f9b953eeaeac54ffe169c99bb5f57ee2a1cdcde1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 16 Aug 2020 10:40:20 +0200 Subject: [PATCH] - removed SW's network code. --- source/sw/src/game.cpp | 77 +-- source/sw/src/game.h | 1 - source/sw/src/network.cpp | 1116 +------------------------------------ source/sw/src/network.h | 74 +-- source/sw/src/save.cpp | 2 +- source/sw/src/sync.cpp | 29 +- 6 files changed, 17 insertions(+), 1282 deletions(-) diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index cec1765ee..311604a10 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -312,10 +312,6 @@ Distance(int x1, int y1, int x2, int y2) void TerminateGame(void) { - ErrorCorrectionQuit(); - - // uninitmultiplayers(); - if (CleanExit) { //SybexScreen(); @@ -414,7 +410,6 @@ bool InitGame() numplayers = 1; myconnectindex = 0; connecthead = 0; connectpoint2[0] = -1; - initsynccrc(); // code to duplicate packets if (numplayers > 4 && MovesPerPacket == 1) @@ -435,7 +430,7 @@ bool InitGame() TileFiles.LoadArtSet("tiles%03d.art"); InitFonts(); - Connect(); + //Connect(); SortBreakInfo(); parallaxtype = 1; SW_InitMultiPsky(); @@ -908,26 +903,6 @@ void MenuLevel(void) if (totalclock >= ototalclock + synctics) { ototalclock += synctics; - if (CommEnabled) - getpackets(); - } - - if (CommEnabled) - { - if (MultiPlayQuitFlag) - { - uint8_t pbuf[1]; - QuitFlag = TRUE; - pbuf[0] = PACKET_TYPE_MENU_LEVEL_QUIT; - netbroadcastpacket(pbuf, 1); // TENSW - break; - } - - if (PlayerQuitMenuLevel >= 0) - { - MenuCommPlayerQuit(PlayerQuitMenuLevel); - PlayerQuitMenuLevel = -1; - } } if (ExitLevel) @@ -1088,7 +1063,7 @@ void MoveLoop(void) { int pnum; - getpackets(); + //getpackets(); if (PredictionOn && CommEnabled) { @@ -1166,16 +1141,8 @@ void InitRunLevel(void) return; } -#if 0 - // ensure we are through the initialization code before sending the game - // version. Otherwise, it is possible to send this too early and have it - // blown away on the other side. - waitforeverybody(); -#endif - - SendVersion(GameVersion); - - waitforeverybody(); + //SendVersion(GameVersion); + //waitforeverybody(); Mus_Stop(); @@ -1206,7 +1173,7 @@ void InitRunLevel(void) waitforeverybody(); - CheckVersion(GameVersion); + //CheckVersion(GameVersion); // IMPORTANT - MUST be right before game loop AFTER waitforeverybody InitTimingVars(); @@ -1522,23 +1489,11 @@ FunctionKeys(PLAYERp pp) if (inputState.AltPressed()) { - if (rts_delay > 16 && fn_key && CommEnabled && !adult_lockout && !Global_PLock) + if (rts_delay > 16 && fn_key && !adult_lockout && !Global_PLock) { inputState.ClearKeyStatus(sc_F1 + fn_key - 1); - rts_delay = 0; - PlaySoundRTS(fn_key); - - if (CommEnabled) - { - PACKET_RTS p; - - p.PacketType = PACKET_TYPE_RTS; - p.RTSnum = fn_key; - - netbroadcastpacket((uint8_t*)(&p), sizeof(p)); // TENSW - } } return; @@ -1546,27 +1501,9 @@ FunctionKeys(PLAYERp pp) if (inputState.ShiftPressed()) { - if (fn_key && CommEnabled) + if (fn_key) { - inputState.ClearKeyStatus(sc_Escape); inputState.ClearKeyStatus(sc_F1 + fn_key - 1); - - if (CommEnabled) - { - short pnum; - - sprintf(ds,"SENT: %s",**CombatMacros[fn_key-1]); - Printf(PRINT_NOTIFY | PRINT_TEAMCHAT, "%s\n", ds); - - TRAVERSE_CONNECT(pnum) - { - if (pnum != myconnectindex) - { - sprintf(ds,"%s: %s",pp->PlayerName, **CombatMacros[fn_key - 1]); - SW_SendMessage(pnum, ds); - } - } - } } return; diff --git a/source/sw/src/game.h b/source/sw/src/game.h index ae8172ee7..bf466191e 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -2284,7 +2284,6 @@ void DrawMenuLevelScreen(void); // game.c void DebugWriteString(char *string); // game.c void ManualPlayerInsert(PLAYERp pp); // game.c -void initsynccrc(void); // sync.c void getsyncstat(void); // sync.c void SyncStatMessage(void); // sync.c diff --git a/source/sw/src/network.cpp b/source/sw/src/network.cpp index e44cbb4c1..00b1de44d 100644 --- a/source/sw/src/network.cpp +++ b/source/sw/src/network.cpp @@ -45,28 +45,6 @@ BEGIN_SW_NS void getinput(SW_PACKET *, SWBOOL); -/* -SYNC BUG NOTES: - - 1. Look at Prediction code first when player movement is involved. If the - prediction code changes any variable not in the Player or Players - Sprite/User structure that effects movement then there will be a Out Of Sync - problem. - - EXAMPLE: Prediction player was updating a sop->drive_oangvel making it - invalid for movement. Look at DoPlayerBoatTurn for comment. - - 2. Changing movement variables in the draw code. Because the draw code is - called at a variable rate this don't work. This includes using RANDOM_RANGE - or RANDOM_P2 in the draw code. This updates the random seed variable and is - only for movement code. Use STD_RANDOM_RANGE for draw code. - - 3. Plain old bugs such as using uninitialized local variables. - -*/ - -//#undef MAXSYNCBYTES -//#define MAXSYNCBYTES 16 static uint8_t tempbuf[576], packbuf[576]; int PlayClock; @@ -130,257 +108,6 @@ SWBOOL NetBroadcastMode = TRUE; SWBOOL NetModeOverride = FALSE; -void netsendpacket(int ind, uint8_t* buf, int len) -{ - uint8_t bbuf[sizeof(packbuf) + sizeof(PACKET_PROXY)]; - PACKET_PROXYp prx = (PACKET_PROXYp)bbuf; - int i; - - // send via master if in M/S mode and we are not the master, and the recipient is not the master and not ourselves - if (!NetBroadcastMode && myconnectindex != connecthead && ind != myconnectindex && ind != connecthead) - { - if ((unsigned)len > sizeof(packbuf)) - { - len = sizeof(packbuf); - } - - prx->PacketType = PACKET_TYPE_PROXY; - prx->PlayerIndex = (uint8_t)ind; - memcpy(&prx[1], buf, len); // &prx[1] == (char*)prx + sizeof(PACKET_PROXY) - len += sizeof(PACKET_PROXY); - - //sendpacket(connecthead, bbuf, len); - return; - } - - //sendpacket(ind, buf, len); - -} - -void netbroadcastpacket(uint8_t* buf, int len) -{ - int i; - uint8_t bbuf[sizeof(packbuf) + sizeof(PACKET_PROXY)]; - PACKET_PROXYp prx = (PACKET_PROXYp)bbuf; - - // broadcast via master if in M/S mode and we are not the master - if (!NetBroadcastMode && myconnectindex != connecthead) - { - if ((unsigned)len > sizeof(packbuf)) - { - len = sizeof(packbuf); - } - - - prx->PacketType = PACKET_TYPE_PROXY; - prx->PlayerIndex = (uint8_t)(-1); - memcpy(&prx[1], buf, len); - len += sizeof(PACKET_PROXY); - - //sendpacket(connecthead, bbuf, len); - return; - } - - for (i = connecthead; i >= 0; i = connectpoint2[i]) - { - if (i == myconnectindex) continue; - //sendpacket(i, buf, len); - Printf("netsendpacket() sends normal to %d\n",i); - } - Printf("Contents:"); - for (i=0; i 0) - { - } - return len; - } - - prx = (PACKET_PROXYp)buf; - - - if (myconnectindex == connecthead) - { - // I am the master - - if (prx->PlayerIndex == (uint8_t)(-1)) - { - // broadcast - - // Rewrite the player index to be the sender's connection number - prx->PlayerIndex = (uint8_t)*ind; - - // Transmit to all the other players except ourselves and the sender - for (i = connecthead; i >= 0; i = connectpoint2[i]) - { - if (i == myconnectindex || i == *ind) continue; - Printf("netgetpacket(): distributing to %d\n", i); - //sendpacket(i, buf, len); - } - - // Return the packet payload to the caller - len -= sizeof(PACKET_PROXY); - memmove(buf, &prx[1], len); - return len; - } - else - { - // proxy send to a specific player - - i = prx->PlayerIndex; - - // Rewrite the player index to be the sender's connection number - prx->PlayerIndex = (uint8_t)*ind; - - // Transmit to the intended recipient - if (i == myconnectindex) - { - len -= sizeof(PACKET_PROXY); - memmove(buf, &prx[1], len); - return len; - } - - Printf("netgetpacket(): forwarding to %d\n", i); - //sendpacket(i, buf, len); - return 0; // nothing for us to do - } - } - else if (*ind == connecthead) - { - // I am a slave, and the proxy message came from the master - *ind = prx->PlayerIndex; - len -= sizeof(PACKET_PROXY); - memmove(buf, &prx[1], len); - return len; - } - else - { - Printf("netgetpacket(): Got a proxy message from %d instead of %d\n",*ind,connecthead); - } - return 0; -} - - -int EncodeBits(SW_PACKET *pak, SW_PACKET *old_pak, uint8_t* buf) -{ - uint8_t* base_ptr = buf; - unsigned i; - - // skipping the bits field sync test fake byte (Ed. Ken) - *buf = 0; - buf++; - - // TODO: Properly copy the values in a cross-platform manner - if (pak->vel != old_pak->vel) - { - *((short *)buf) = pak->vel; - buf += sizeof(pak->vel); - SET(*base_ptr, BIT(0)); - } - - if (pak->svel != old_pak->svel) - { - *((short *)buf) = pak->svel; - buf += sizeof(pak->svel); - SET(*base_ptr, BIT(1)); - } - - if ((pak->q16angvel != old_pak->q16angvel) || (pak->q16ang != old_pak->q16ang)) - { - *((fix16_t *)buf) = pak->q16angvel; - buf += sizeof(pak->q16angvel); - *((fix16_t *)buf) = pak->q16ang; - buf += sizeof(pak->q16ang); - SET(*base_ptr, BIT(2)); - } - - if ((pak->q16aimvel != old_pak->q16aimvel) || (pak->q16horiz != old_pak->q16horiz)) - { - *((fix16_t *)buf) = pak->q16aimvel; - buf += sizeof(pak->q16aimvel); - *((fix16_t *)buf) = pak->q16horiz; - buf += sizeof(pak->q16horiz); - SET(*base_ptr, BIT(3)); - } - - //won't work if > 4 bytes - for (i = 0; i < sizeof(pak->bits); i++) - { - if (TEST(pak->bits ^ old_pak->bits, 0xff<<(i<<3))) - { - *buf = (pak->bits>>(i<<3)); - buf++; - SET(*base_ptr, BIT(i+4)); - } - } - - return buf - base_ptr; -} - -int DecodeBits(SW_PACKET *pak, SW_PACKET *old_pak, uint8_t* buf) -{ - uint8_t* base_ptr = buf; - unsigned i; - - // skipping the bits field sync test fake byte (Ed. Ken) - buf++; - - *pak = *old_pak; - - // TODO: Properly copy the values in a cross-platform manner - if (TEST(*base_ptr, BIT(0))) - { - pak->vel = *(short *)buf; - buf += sizeof(pak->vel); - } - - if (TEST(*base_ptr, BIT(1))) - { - pak->svel = *(short *)buf; - buf += sizeof(pak->svel); - } - - if (TEST(*base_ptr, BIT(2))) - { - pak->q16angvel = *(fix16_t *)buf; - buf += sizeof(pak->q16angvel); - pak->q16ang = *(fix16_t *)buf; - buf += sizeof(pak->q16ang); - } - - if (TEST(*base_ptr, BIT(3))) - { - pak->q16aimvel = *(fix16_t *)buf; - buf += sizeof(pak->q16aimvel); - pak->q16horiz = *(fix16_t *)buf; - buf += sizeof(pak->q16horiz); - } - - //won't work if > 4 bytes - for (i = 0; i < sizeof(pak->bits); i++) - { - if (TEST(*base_ptr, BIT(i+4))) - { - RESET(pak->bits, 0xff<<(i<<3)); - SET(pak->bits, ((int)(*buf))<<(i<<3)); - buf++; - } - } - - return buf - base_ptr; -} void ResumeGame(void) @@ -392,38 +119,11 @@ ResumeGame(void) paused = 0; } -void -PauseAction(void) -{ - ready2send = 0; - save_totalclock = (int32_t) totalclock; -} - -void -ResumeAction(void) -{ - ready2send = 1; - totalclock = save_totalclock; -} - -void -SW_SendMessage(short pnum, const char *text) -{ - if (!CommEnabled) - return; - - tempbuf[0] = PACKET_TYPE_MESSAGE; - strcpy((char *)&tempbuf[1], text); - netsendpacket(pnum, tempbuf, strlen(text) + 2); -} - - void InitNetPlayerOptions(void) { // short pnum; PLAYERp pp = Player + myconnectindex; - PACKET_OPTIONS p; strncpy(pp->PlayerName, playername, 32); @@ -431,172 +131,11 @@ InitNetPlayerOptions(void) pp->TeamColor = gs.NetColor; pp->SpriteP->pal = PALETTE_PLAYER0 + pp->TeamColor; User[pp->SpriteP - sprite]->spal = pp->SpriteP->pal; - - if (CommEnabled) - { - p.PacketType = PACKET_TYPE_PLAYER_OPTIONS; - p.AutoRun = cl_autorun; - p.Color = gs.NetColor; - strncpy(p.PlayerName, playername, 32); - - //TRAVERSE_CONNECT(pnum) - { - //if (pnum != myconnectindex) - { - //netsendpacket(pnum, (char *)(&p), sizeof(p)); - netbroadcastpacket((uint8_t*)(&p), sizeof(p)); - } - } - } } -#if 0 -void -SendMulitNameChange(char *new_name) -{ -// short pnum; - PLAYERp pp = Player + myconnectindex; - PACKET_NAME_CHANGE p; - - if (!CommEnabled) - return; - - strcpy(pp->PlayerName, new_name); - playername = new_name; - - //TRAVERSE_CONNECT(pnum) - { - //if (pnum != myconnectindex) - { - p.PacketType = PACKET_TYPE_NAME_CHANGE; - strcpy(p.PlayerName, pp->PlayerName); - //netsendpacket(pnum, (char *)(&p), sizeof(p)); - netbroadcastpacket((uint8_t*)(&p), sizeof(p)); - } - } -} -#endif - -void -SendVersion(int version) -{ -// short pnum; - PLAYERp pp = Player + myconnectindex; - PACKET_VERSION p; - - if (!CommEnabled) - return; - - pp->PlayerVersion = version; - - //TRAVERSE_CONNECT(pnum) - { - //if (pnum != myconnectindex) - { - p.PacketType = PACKET_TYPE_VERSION; - p.Version = version; - //netsendpacket(pnum, (char *)(&p), sizeof(p)); - netbroadcastpacket((uint8_t*)(&p), sizeof(p)); - } - } -} - -void -CheckVersion(int GameVersion) -{ - short pnum; -#define VERSION_MSG "You cannot play with different versions!" - - if (!CommEnabled) - return; - - TRAVERSE_CONNECT(pnum) - { - if (pnum != myconnectindex) - { - if (GameVersion != Player[pnum].PlayerVersion) - { - Printf("CheckVersion(): player %d has version %d, expecting %d\n", - pnum, Player[pnum].PlayerVersion, GameVersion); - } - } - } -} - -void -Connect(void) -{ - if (CommEnabled) - { - screenpeek = myconnectindex; - } - - //InitTimingVars(); // resettiming(); -} - -SWBOOL (*wfe_ExitCallback)(void); - void waitforeverybody(void) { - int i, size = 1; - - if (!CommEnabled) - return; - - Printf("waitforeverybody() #%d\n", Player[myconnectindex].playerreadyflag + 1); - - //tenDbLprintf(gTenLog, 3, "in w4e"); - //tenDbFlushLog(gTenLog); - tempbuf[0] = PACKET_TYPE_PLAYER_READY; -#ifdef DEBUG - tempbuf[1] = Player[myconnectindex].playerreadyflag + 1; - size++; -#endif - // if we're a peer or slave, not a master - if (!NetBroadcastMode && myconnectindex != connecthead) - netsendpacket(connecthead, tempbuf, size); - else if (NetBroadcastMode) - netbroadcastpacket(tempbuf, size); - - Player[myconnectindex].playerreadyflag++; - - while (TRUE) - { - if (PlayerQuitMenuLevel >= 0) - { - MenuCommPlayerQuit(PlayerQuitMenuLevel); - PlayerQuitMenuLevel = -1; - } - - handleevents(); - getpackets(); - - if (wfe_ExitCallback && wfe_ExitCallback()) - { - tempbuf[0] = PACKET_TYPE_MENU_LEVEL_QUIT; - //netsendpacket(pnum, tempbuf, 1); - netbroadcastpacket(tempbuf, 1); - - TerminateGame(); - - } - - for (i = connecthead; i >= 0; i = connectpoint2[i]) - { - if (Player[i].playerreadyflag < Player[myconnectindex].playerreadyflag) - break; - if ((!NetBroadcastMode) && (myconnectindex != connecthead)) { i = -1; break; } //slaves in M/S mode only wait for master - } - - if (i < 0) - { - // master sends ready packet once it hears from all slaves - if (!NetBroadcastMode && myconnectindex == connecthead) - netbroadcastpacket(tempbuf, size); - return; - } - } } @@ -689,73 +228,6 @@ SWBOOL MyCommPlayerQuit(void) return FALSE; } -SWBOOL MenuCommPlayerQuit(short quit_player) -{ - short i; - short prev_player = 0; - short pnum; - - // tell everyone else you left the game - TRAVERSE_CONNECT(pnum) - { - if (pnum != quit_player) - { - sprintf(ds,"%s has quit the game.",Player[myconnectindex].PlayerName); - SW_SendMessage(pnum, ds); - } - } - - TRAVERSE_CONNECT(i) - { - // have to reorder the connect list - if (i != quit_player) - { - prev_player = i; - continue; - } - - // for COOP mode - if (screenpeek == i) - { - screenpeek = connectpoint2[i]; - if (screenpeek < 0) - screenpeek = connecthead; - } - - if (i == connecthead) - connecthead = connectpoint2[connecthead]; - else - connectpoint2[prev_player] = connectpoint2[i]; - - numplayers--; - CommPlayers--; - } - - return FALSE; -} - -void ErrorCorrectionQuit(void) -{ - int oldtotalclock; - short j; - - if (CommPlayers > 1) - { - for (j = 0; j < MAX_SW_PLAYERS; j++) - { - oldtotalclock = (int32_t) totalclock; - while (totalclock < oldtotalclock + synctics) - { - handleevents(); - getpackets(); - } - - tempbuf[0] = PACKET_TYPE_NULL_PACKET; - netbroadcastpacket(tempbuf, 1); - } - } -} - void InitNetVars(void) { @@ -815,22 +287,6 @@ InitTimingVars(void) } -void -AddSyncInfoToPacket(int *j) -{ - int sb; - int count = 0; - - // sync testing - while (Player[myconnectindex].syncvalhead != syncvaltail && count++ < 4) - { - for (sb = 0; sb < NumSyncBytes; sb++) - packbuf[(*j)++] = Player[myconnectindex].syncval[syncvaltail & (SYNCFIFOSIZ - 1)][sb]; - - syncvaltail++; - } -} - void UpdateInputs(void) { @@ -839,12 +295,8 @@ UpdateInputs(void) ototalclock += synctics; - getpackets(); + //getpackets(); - -// TENSW: this way we are guaranteed that the most advanced player is no more -// than 200 frames ahead of the most laggy. We're more healthy if the queue -// doesn't overflow, that's for sure. if (Player[myconnectindex].movefifoend - movefifoplc >= 100) return; @@ -898,572 +350,6 @@ UpdateInputs(void) } return; } - - TRAVERSE_CONNECT(i) - { - if (i != myconnectindex) - { - k = (Player[myconnectindex].movefifoend - 1) - Player[i].movefifoend; - Player[i].myminlag = min(Player[i].myminlag, k); - mymaxlag = max(mymaxlag, k); - } - } - - if (((Player[myconnectindex].movefifoend - 1) & (TIMERUPDATESIZ - 1)) == 0) - { - i = mymaxlag - bufferjitter; - mymaxlag = 0; - if (i > 0) - bufferjitter += ((2 + i) >> 2); - else if (i < 0) - bufferjitter -= ((2 - i) >> 2); - } - - // If this isn't the master, and the player decided to quit, leave - // the game after sending the message. Otherwise, before processing - // local message with SK_QUIT bit, we may wait in MoveLoop for another - // message with input from one of the peers, only to never get any, - // as the peer in question already removed this player from its list. - if ((NetBroadcastMode || (myconnectindex != connecthead)) && - TEST(pp->inputfifo[(pp->movefifoend - 1) & (MOVEFIFOSIZ - 1)].bits, BIT(SK_QUIT_GAME))) - QuitFlag = TRUE; - - if (NetBroadcastMode) - { - packbuf[0] = PACKET_TYPE_BROADCAST; - j = 1; - - if (((Player[myconnectindex].movefifoend - 1) & (TIMERUPDATESIZ - 1)) == 0 /* CTW REMOVED && !gTenActivated */) - { - if (myconnectindex == connecthead) - { - for (i = connectpoint2[connecthead]; i >= 0; i = connectpoint2[i]) - packbuf[j++] = min(max(Player[i].myminlag, -128), 127); - } - else - { - i = Player[connecthead].myminlag - otherminlag; - if (labs(i) > 2) - { - ////DSPRINTF(ds,"lag correction: %d,%d,%d",i,Player[connecthead].myminlag,otherminlag); - //MONO_PRINT(ds); - - if (labs(i) > 8) - { - if (i < 0) - i++; - i >>= 1; - } - else - { - if (i < 0) - i = -1; - if (i > 0) - i = 1; - } - totalclock -= synctics * i; - otherminlag += i; - } - } - - for (i = connecthead; i >= 0; i = connectpoint2[i]) - Player[i].myminlag = 0x7fffffff; - } - - pp = Player + myconnectindex; - -#if !BIT_CODEC - memcpy(&packbuf[j], &pp->inputfifo[(Player[myconnectindex].movefifoend - 1) & (MOVEFIFOSIZ - 1)], sizeof(SW_PACKET)); - j += sizeof(SW_PACKET); -#else - j += EncodeBits(&pp->inputfifo[(Player[myconnectindex].movefifoend - 1) & (MOVEFIFOSIZ - 1)], - &pp->inputfifo[(Player[myconnectindex].movefifoend - 2) & (MOVEFIFOSIZ - 1)], - &packbuf[j]); -#endif - -#if SYNC_TEST - AddSyncInfoToPacket(&j); -#endif - - netbroadcastpacket(packbuf, j); - - return; - } // NetBroadcastMode - - // SLAVE CODE - if (myconnectindex != connecthead) // I am the Slave - { - if (((Player[myconnectindex].movefifoend - 1) & (TIMERUPDATESIZ - 1)) == 0) - { - i = Player[connecthead].myminlag - otherminlag; - if (labs(i) > 2) - { - if (labs(i) > 8) - { - if (i < 0) - i++; - i >>= 1; - } - else - { - if (i < 0) - i = -1; - if (i > 0) - i = 1; - } - totalclock -= synctics * i; - otherminlag += i; - } - - for (i = connecthead; i >= 0; i = connectpoint2[i]) - { - Player[i].myminlag = 0x7fffffff; - } - } - packbuf[0] = PACKET_TYPE_SLAVE_TO_MASTER; - j = 1; - - pp = Player + myconnectindex; -#if !BIT_CODEC - memcpy(&packbuf[j], &pp->inputfifo[(pp->movefifoend - 1) & (MOVEFIFOSIZ - 1)], sizeof(SW_PACKET)); - j += sizeof(SW_PACKET); -#else - j += EncodeBits(&pp->inputfifo[(pp->movefifoend - 1) & (MOVEFIFOSIZ - 1)], - &pp->inputfifo[(pp->movefifoend - 2) & (MOVEFIFOSIZ - 1)], - &packbuf[j]); -#endif - -#if SYNC_TEST - AddSyncInfoToPacket(&j); -#endif - - netsendpacket(connecthead, packbuf, j); - return; - } - - // This allows packet-resends - //for (i = connecthead; i >= 0; i = connectpoint2[i]) - // { - // if ( /* (!playerquitflag[i]) && */ (Player[i].movefifoend <= movefifosendplc)) - // { - // packbuf[0] = 127; - // for (i = connectpoint2[connecthead]; i >= 0; i = connectpoint2[i]) - // { - // /* if (!playerquitflag[i]) */ sendpacket(i, packbuf, 1); - // } - // return; - // } - // } - - // I am MASTER... - while (1) - { - for (i = connecthead; i >= 0; i = connectpoint2[i]) - { - if (/* (!playerquitflag[i]) && */ (Player[i].movefifoend <= movefifosendplc)) - return; - } - - packbuf[0] = PACKET_TYPE_MASTER_TO_SLAVE; - j = 1; - - // Fix timers and buffer/jitter value - if ((movefifosendplc & (TIMERUPDATESIZ - 1)) == 0) - { - for (i = connectpoint2[connecthead]; i >= 0; i = connectpoint2[i]) - { - /* if (!playerquitflag[i]) */ - packbuf[j++] = min(max(Player[i].myminlag, -128), 127); - } - - for (i = connecthead; i >= 0; i = connectpoint2[i]) - Player[i].myminlag = 0x7fffffff; - } - - for (i = connecthead; i >= 0; i = connectpoint2[i]) - { - /* if (playerquitflag[i]) continue; */ - pp = Player + i; - -#if !BIT_CODEC - memcpy(&packbuf[j], &pp->inputfifo[movefifosendplc & (MOVEFIFOSIZ - 1)], sizeof(SW_PACKET)); - j += sizeof(SW_PACKET); -#else - j += EncodeBits(&pp->inputfifo[(movefifosendplc) & (MOVEFIFOSIZ - 1)], - &pp->inputfifo[(movefifosendplc - 1) & (MOVEFIFOSIZ - 1)], - &packbuf[j]); -#endif - //pp->movefifoend++; - } - -#if SYNC_TEST - AddSyncInfoToPacket(&j); -#endif - - for (i = connectpoint2[connecthead]; i >= 0; i = connectpoint2[i]) - /* if (!playerquitflag[i])*/ - { - netsendpacket(i, packbuf, j); - /* - pp = Player + i; - if (TEST(pp->inputfifo[movefifosendplc & (MOVEFIFOSIZ - 1)].bits,QUITBIT) - playerquitflag[i] = 1; - */ - } - // Master player should quit only after notifying all peers - if (TEST(Player[myconnectindex].inputfifo[movefifosendplc & (MOVEFIFOSIZ - 1)].bits, BIT(SK_QUIT_GAME))) - QuitFlag = TRUE; - - movefifosendplc += MovesPerPacket; - } } -void -checkmasterslaveswitch(void) -{ -} - -void -getpackets(void) -{ - int otherconnectindex, packbufleng; - int i, j, sb; - PLAYERp pp; - SW_PACKET tempinput; - - if (!CommEnabled) - return; - - while ((packbufleng = netgetpacket(&otherconnectindex, packbuf)) > 0) - { - switch (packbuf[0]) - { - case PACKET_TYPE_BROADCAST: - case SERVER_GENERATED_BROADCAST: - ////DSPRINTF(ds,"Receive Broadcast %d, ready2send %d",otherconnectindex, ready2send); - //MONO_PRINT(ds); - - //ASSERT(ready2send); - //if (!ready2send) - // break; - - j = 1; - - if ((Player[otherconnectindex].movefifoend & (TIMERUPDATESIZ - 1)) == 0) - { - if (otherconnectindex == connecthead) - { - for (i = connectpoint2[connecthead]; i >= 0; i = connectpoint2[i]) - { - if (i == myconnectindex) - otherminlag = (int)((signed char) packbuf[j]); - j++; - } - } - } - - pp = Player + otherconnectindex; - -#if !BIT_CODEC - memcpy(&pp->inputfifo[pp->movefifoend & (MOVEFIFOSIZ - 1)], &packbuf[j], sizeof(SW_PACKET)); - j += sizeof(SW_PACKET); -#else - j += DecodeBits(&pp->inputfifo[(pp->movefifoend) & (MOVEFIFOSIZ - 1)], - &pp->inputfifo[(pp->movefifoend - 1) & (MOVEFIFOSIZ - 1)], - &packbuf[j]); -#endif - - pp->movefifoend++; - - // Packet Duplication - for (i = 1; i < MovesPerPacket; i++) - { - memcpy( - &pp->inputfifo[pp->movefifoend & (MOVEFIFOSIZ - 1)], - &pp->inputfifo[(pp->movefifoend-1) & (MOVEFIFOSIZ - 1)], - sizeof(SW_PACKET)); - - pp->movefifoend++; - } - -#if SYNC_TEST - GetSyncInfoFromPacket(packbuf, packbufleng, &j, otherconnectindex); -#endif - - //DSPRINTF(ds,"Receive packet size %d",j); - //MONO_PRINT(ds); - - break; - - case PACKET_TYPE_MASTER_TO_SLAVE: - // Here slave is receiving - j = 1; - - if ((Player[otherconnectindex].movefifoend & (TIMERUPDATESIZ - 1)) == 0) - { - for (i = connectpoint2[connecthead]; i >= 0; i = connectpoint2[i]) - { - // if (playerquitflag[i]) continue; - if (i == myconnectindex) - otherminlag = (int)((signed char) packbuf[j]); - j++; - } - } - - for (i = connecthead; i >= 0; i = connectpoint2[i]) - { - /* if (playerquitflag[i]) continue;) */ - pp = Player + i; - -#if !BIT_CODEC - if (i != myconnectindex) - memcpy(&pp->inputfifo[pp->movefifoend & (MOVEFIFOSIZ - 1)], &packbuf[j], sizeof(SW_PACKET)); - j += sizeof(SW_PACKET); -#else - if (i == myconnectindex) - { - j += DecodeBits(&tempinput, - &pp->inputfifo[(pp->movefifoend - 1) & (MOVEFIFOSIZ - 1)], - &packbuf[j]); - } - else - { - j += DecodeBits(&pp->inputfifo[(pp->movefifoend) & (MOVEFIFOSIZ - 1)], - &pp->inputfifo[(pp->movefifoend - 1) & (MOVEFIFOSIZ - 1)], - &packbuf[j]); - } -#endif - - pp->movefifoend++; - } - - while (j != packbufleng) - { - for (i = connecthead; i >= 0; i = connectpoint2[i]) - { - if (i != myconnectindex) - { - for (sb = 0; sb < NumSyncBytes; sb++) - { - Player[i].syncval[Player[i].syncvalhead & (SYNCFIFOSIZ - 1)][sb] = packbuf[j + sb]; - } - - Player[i].syncvalhead++; - } - } - - j += NumSyncBytes; - } - -#if SYNC_TEST - GetSyncInfoFromPacket(packbuf, packbufleng, &j, otherconnectindex); -#endif - - for (i=connecthead; i>=0; i=connectpoint2[i]) - if (i != myconnectindex) - for (j=1; jinputfifo[pp->movefifoend & (MOVEFIFOSIZ - 1)], - &pp->inputfifo[(pp->movefifoend-1) & (MOVEFIFOSIZ - 1)], - sizeof(SW_PACKET)); - - pp->movefifoend++; - } - - break; - - case PACKET_TYPE_SLAVE_TO_MASTER: - // Here master is receiving - pp = Player + otherconnectindex; - j = 1; - -#if !BIT_CODEC - memcpy(&pp->inputfifo[Player[otherconnectindex].movefifoend & (MOVEFIFOSIZ - 1)], &packbuf[j], sizeof(SW_PACKET)); - j += sizeof(SW_PACKET); -#else - j += DecodeBits(&pp->inputfifo[(Player[otherconnectindex].movefifoend) & (MOVEFIFOSIZ - 1)], - &pp->inputfifo[(Player[otherconnectindex].movefifoend - 1) & (MOVEFIFOSIZ - 1)], - &packbuf[j]); -#endif - - Player[otherconnectindex].movefifoend++; - -#if SYNC_TEST - GetSyncInfoFromPacket(packbuf, packbufleng, &j, otherconnectindex); -#endif - - // Tic duping - for (i = 1; i < MovesPerPacket; i++) - { - memcpy(&pp->inputfifo[(Player[otherconnectindex].movefifoend) & (MOVEFIFOSIZ - 1)], - &pp->inputfifo[(Player[otherconnectindex].movefifoend - 1) & (MOVEFIFOSIZ - 1)], - sizeof(SW_PACKET)); - Player[otherconnectindex].movefifoend++; - } - - break; - - case PACKET_TYPE_MESSAGE: - { - PLAYERp tp = Player + myconnectindex; - - pp = Player + otherconnectindex; - - PlaySound(DIGI_PMESSAGE,tp,v3df_dontpan); - - memcpy(ds,&packbuf[3],packbufleng-3); - ds[packbufleng-3] = 0; - //sprintf(ds, "%s",&packbuf[3]); - Printf(PRINT_NOTIFY | PRINT_TEAMCHAT, "%s\n", ds); - break; - } - - case PACKET_TYPE_RTS: - { - PACKET_RTSp p; - - p = (PACKET_RTSp)packbuf; - - PlaySoundRTS(p->RTSnum); - - break; - } - - - case PACKET_TYPE_NEW_GAME: - { - extern SWBOOL NewGame, ShortGameMode; - PACKET_NEW_GAMEp p; - static const short TimeLimitTable[9] = { 0,3,5,10,15,20,30,45,60 }; - - - pp = Player + otherconnectindex; - - // Dukes New Game Packet - //level_number //volume_number //player_skill //monsters_off //respawn_monsters - //respawn_items //respawn_inventory //coop //marker //friendlyfire //boardname - - p = (PACKET_NEW_GAMEp)packbuf; - - ready2send = 0; - - Level = p->Level; - Skill = p->Skill; - - gNet.HurtTeammate = p->HurtTeammate; - gNet.SpawnMarkers = p->SpawnMarkers; - gNet.TeamPlay = p->TeamPlay; - gNet.AutoAim = p->AutoAim; - gNet.Nuke = p->Nuke; - gNet.KillLimit = p->KillLimit*10; - gNet.TimeLimit = TimeLimitTable[p->TimeLimit]*60*120; - - if (ShortGameMode) - { - gNet.KillLimit /= 10; - gNet.TimeLimit /= 2; - } - - gNet.TimeLimitClock = gNet.TimeLimit; - gNet.MultiGameType = p->GameType+1; - - // settings for No Respawn Commbat mode - if (gNet.MultiGameType == MULTI_GAME_COMMBAT_NO_RESPAWN) - { - gNet.MultiGameType = MULTI_GAME_COMMBAT; - gNet.NoRespawn = TRUE; - } - else - { - gNet.NoRespawn = FALSE; - } - - ExitLevel = TRUE; - NewGame = TRUE; - // restart demo for multi-play mode - break; - } - - case PACKET_TYPE_DUMMY: - break; - - case PACKET_TYPE_VERSION: - { - PACKET_VERSIONp p; - - pp = Player + otherconnectindex; - p = (PACKET_VERSIONp)packbuf; - - //tenDbLprintf(gTenLog, 3, "rcv pid %d version %lx", (int) otherconnectindex, (int) p->Version); - pp->PlayerVersion = p->Version; - break; - } - - case PACKET_TYPE_PLAYER_OPTIONS: - { - PACKET_OPTIONSp p; - - pp = Player + otherconnectindex; - p = (PACKET_OPTIONSp)packbuf; - - // palette - pp->TeamColor = p->Color; - pp->SpriteP->pal = PALETTE_PLAYER0 + pp->TeamColor; - User[pp->SpriteP - sprite]->spal = pp->SpriteP->pal; - - // names - strcpy(pp->PlayerName, p->PlayerName); - - break; - } - - case PACKET_TYPE_NAME_CHANGE: - { - PACKET_NAME_CHANGEp p; - pp = Player + otherconnectindex; - p = (PACKET_NAME_CHANGEp)packbuf; - - // someone else has changed their name - - DSPRINTF(ds,"Recieved name: %s",p->PlayerName); - MONO_PRINT(ds); - - strcpy(pp->PlayerName, p->PlayerName); - break; - } - - - case PACKET_TYPE_MENU_LEVEL_QUIT: - { - PlayerQuitMenuLevel = otherconnectindex; - break; - } - - case PACKET_TYPE_PLAYER_READY: - Player[otherconnectindex].playerreadyflag++; - // It's important to return from getpackets() when a ready packet comes in and - // you are inside waitforeverybody(). Otherwise multiple ready packets can come - // in inside one waitforeverybody() which causes havoc if that w4e is protecting - // an initialization step which (heh) for example resets the playerreadyflag count. - return; - //break; - - case PACKET_TYPE_DONT_USE: - break; - - case PACKET_TYPE_NULL_PACKET: - break; - - case PACKET_TYPE_PROXY: - break; - - default: - DSPRINTF(ds,"Packet type unknown %d",packbuf[0]); - MONO_PRINT(ds); - } - } -} END_SW_NS diff --git a/source/sw/src/network.h b/source/sw/src/network.h index acee18989..bbd0e2299 100644 --- a/source/sw/src/network.h +++ b/source/sw/src/network.h @@ -26,40 +26,10 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms //------------------------------------------------------------------------- BEGIN_SW_NS -#define PACKET_TYPE_MASTER_TO_SLAVE 0 -#define PACKET_TYPE_SLAVE_TO_MASTER 1 -//#define PACKET_TYPE_PLAYER_NAME 3 -#define PACKET_TYPE_MESSAGE 4 -//#define PACKET_TYPE_GAME_INFO 8 -#define PACKET_TYPE_BROADCAST 17 -#define SERVER_GENERATED_BROADCAST 18 -#define PACKET_TYPE_PROXY 19 - -#define PACKET_TYPE_NEW_GAME 30 -//#define PACKET_TYPE_NEW_LEVEL 31 -#define PACKET_TYPE_PLAYER_OPTIONS 32 -#define PACKET_TYPE_RTS 33 -#define PACKET_TYPE_DUMMY 34 -#define PACKET_TYPE_MENU_LEVEL_QUIT 35 -#define PACKET_TYPE_NAME_CHANGE 36 -#define PACKET_TYPE_VERSION 38 - -#define PACKET_TYPE_NULL_PACKET 127 -#define PACKET_TYPE_PLAYER_READY 250 -#define PACKET_TYPE_DONT_USE 255 // old logoff - -#define BIT_CODEC TRUE -#define SYNC_TEST TRUE +#define SYNC_TEST 0 #define MAXSYNCBYTES 16 #pragma pack(push,1) -// Slave->Master: PlayerIndex = who to send the packet to (-1 = all) -// Master->Slave: PlayerIndex = who sent the packet originally -typedef struct -{ - uint8_t PacketType; // first byte is always packet type - uint8_t PlayerIndex; -} PACKET_PROXY,*PACKET_PROXYp; typedef struct { @@ -78,31 +48,6 @@ typedef struct SWBOOL Nuke; } PACKET_NEW_GAME,*PACKET_NEW_GAMEp; -typedef struct -{ - uint8_t PacketType; // first byte is always packet type - SWBOOL AutoRun; - uint8_t Color; - char PlayerName[32]; -} PACKET_OPTIONS,*PACKET_OPTIONSp; - -typedef struct -{ - uint8_t PacketType; // first byte is always packet type - char PlayerName[32]; -} PACKET_NAME_CHANGE,*PACKET_NAME_CHANGEp; - -typedef struct -{ - uint8_t PacketType; // first byte is always packet type - uint8_t RTSnum; -} PACKET_RTS,*PACKET_RTSp; - -typedef struct -{ - uint8_t PacketType; // first byte is always packet type - int Version; -} PACKET_VERSION,*PACKET_VERSIONp; #pragma pack(pop) extern uint8_t syncstat[MAXSYNCBYTES]; @@ -112,17 +57,11 @@ extern PLAYERp ppp; extern short predictangpos[MOVEFIFOSIZ]; extern int predictmovefifoplc; extern SWBOOL Prediction; -extern short NumSyncBytes; void InitPrediction(PLAYERp pp); void DoPrediction(PLAYERp ppp); void CorrectPrediction(int actualfifoplc); -//TENSW: safe packet senders -void netsendpacket(int ind, uint8_t* buf, int len); -void netbroadcastpacket(uint8_t* buf, int len); -int netgetpacket(int *ind, uint8_t* buf); - enum MultiGameTypes { @@ -172,20 +111,11 @@ extern AUTO_NET Auto; extern SWBOOL AutoNet; void UpdateInputs(void); -void getpackets(void); -void SendMulitNameChange(char *new_name); void InitNetVars(void); void InitTimingVars(void); -void PauseAction(void); -void ResumeAction(void); -void ErrorCorrectionQuit(void); -void Connect(void); void waitforeverybody(void); -SWBOOL MenuCommPlayerQuit(short quit_player); -void SendVersion(int version); void InitNetPlayerOptions(void); -void CheckVersion(int GameVersion); -void SW_SendMessage(short pnum,const char *text); +inline void SW_SendMessage(short, const char*) {} void ResumeGame(void); END_SW_NS diff --git a/source/sw/src/save.cpp b/source/sw/src/save.cpp index 2820ddf14..495d76c47 100644 --- a/source/sw/src/save.cpp +++ b/source/sw/src/save.cpp @@ -672,7 +672,7 @@ extern SWBOOL InMenuLevel; Mus_Stop(); else { - PauseAction(); + //PauseAction(); TerminateLevel(); } StopFX(); diff --git a/source/sw/src/sync.cpp b/source/sw/src/sync.cpp index adbd040cb..33e103bbe 100644 --- a/source/sw/src/sync.cpp +++ b/source/sw/src/sync.cpp @@ -31,37 +31,20 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "names2.h" #include "network.h" #include "menus.h" +#include "m_crc32.h" BEGIN_SW_NS -SWBOOL SyncPrintMode = TRUE; -short NumSyncBytes = 1; char sync_first[MAXSYNCBYTES][60]; int sync_found = FALSE; -static int crctable[256]; -#define updatecrc(dcrc,xz) (dcrc = (crctable[((dcrc)>>8)^((xz)&255)]^((dcrc)<<8))) - -void initsynccrc(void) -{ - int i, j, k, a; - - for (j=0; j<256; j++) //Calculate CRC table - { - k = (j<<8); a = 0; - for (i=7; i>=0; i--) - { - if (((k^a)&0x8000) > 0) - a = ((a<<1)&65535) ^ 0x1021; //0x1021 = genpoly - else - a = ((a<<1)&65535); - k = ((k<<1)&65535); - } - crctable[j] = (a&65535); - } -} #if SYNC_TEST +SWBOOL SyncPrintMode = TRUE; +short NumSyncBytes = 1; + +inline void updatecrc(uint16_t& dcrc, uint8_t xz) { dcrc = (uint16_t)CRC1(dcrc, uint8_t(xz), GetCRCTable()); } + uint8_t PlayerSync(void) {