diff --git a/src/d_clisrv.c b/src/d_clisrv.c index bdacaaaf0..d48f223c7 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3137,16 +3137,68 @@ static boolean SV_AddWaitingPlayers(void) { newplayer = true; - // search for a free playernum - // we can't use playeringame since it is not updated here - for (; newplayernum < MAXPLAYERS; newplayernum++) - { - for (n = 0; n < MAXNETNODES; n++) - if (nodetoplayer[n] == newplayernum || nodetoplayer2[n] == newplayernum) + if (netgame) + // !!!!!!!!! EXTREMELY SUPER MEGA GIGA ULTRA ULTIMATELY TERRIBLY IMPORTANT !!!!!!!!! + // + // The line just after that comment is an awful, horrible, terrible, TERRIBLE hack. + // + // Basically, the fix I did in order to fix the download freezes happens + // to cause situations in which a player number does not match + // the node number associated to that player. + // That is totally normal, there is absolutely *nothing* wrong with that. + // Really. Player 7 being tied to node 29, for instance, is totally fine. + // + // HOWEVER. A few (broken) parts of the netcode do the TERRIBLE mistake + // of mixing up the concepts of node and player, resulting in + // incorrect handling of cases where a player is tied to a node that has + // a different number (which is a totally normal case, or at least should be). + // This incorrect handling can go as far as literally + // anyone from joining your server at all, forever. + // + // Given those two facts, there are two options available + // in order to let this download freeze fix be: + // 1) Fix the broken parts that assume a node is a player or similar bullshit. + // 2) Change the part this comment is located at, so that any player who joins + // is given the same number as their associated node. + // + // No need to say, 1) is by far the obvious best, whereas 2) is a terrible hack. + // Unfortunately, after trying 1), I most likely didn't manage to find all + // of those broken parts, and thus 2) has become the only safe option that remains. + // + // So I did this hack. + // + // If it isn't clear enough, in order to get rid of this ugly hack, + // you will have to fix all parts of the netcode that + // make a confusion between nodes and players. + // + // And if it STILL isn't clear enough, a node and a player + // is NOT the same thing. Never. NEVER. *NEVER*. + // + // And if someday you make the terrible mistake of + // daring to have the unforgivable idea to try thinking + // that a node might possibly be the same as a player, + // or that a player should have the same number as its node, + // be sure that I will somehow know about it and + // hunt you down tirelessly and make you regret it, + // even if you live on the other side of the world. + // + // TODO: vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv + // \todo >>>>>>>>>> Remove this horrible hack as soon as possible <<<<<<<<<< + // TODO: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + // + // !!!!!!!!! EXTREMELY SUPER MEGA GIGA ULTRA ULTIMATELY TERRIBLY IMPORTANT !!!!!!!!! + newplayernum = node; // OMFG SAY WELCOME TO TEH NEW HACK FOR FIX FIL DOWNLOAD!!1! + else // Don't use the hack if we don't have to + // search for a free playernum + // we can't use playeringame since it is not updated here + for (; newplayernum < MAXPLAYERS; newplayernum++) + { + for (n = 0; n < MAXNETNODES; n++) + if (nodetoplayer[n] == newplayernum || nodetoplayer2[n] == newplayernum) + break; + if (n == MAXNETNODES) break; - if (n == MAXNETNODES) - break; - } + } // should never happen since we check the playernum // before accepting the join diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 83bbc7aad..2ca48180d 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3012,8 +3012,31 @@ static void Command_Addfile(void) if (*p == '\\' || *p == '/' || *p == ':') break; ++p; + // check total packet size and no of files currently loaded + { + size_t packetsize = 0; + serverinfo_pak *dummycheck = NULL; + + // Shut the compiler up. + (void)dummycheck; + + // See W_LoadWadFile in w_wad.c + for (i = 0; i < numwadfiles; i++) + packetsize += nameonlylength(wadfiles[i]->filename) + 22; + + packetsize += nameonlylength(fn) + 22; + + if ((numwadfiles >= MAX_WADFILES) + || (packetsize > sizeof(dummycheck->fileneeded))) + { + CONS_Alert(CONS_ERROR, M_GetText("Too many files loaded to add %s\n"), fn); + return; + } + } + WRITESTRINGN(buf_p,p,240); + // calculate and check md5 { UINT8 md5sum[16]; #ifdef NOMD5 @@ -3031,6 +3054,15 @@ static void Command_Addfile(void) } else // file not found return; + + for (i = 0; i < numwadfiles; i++) + { + if (!memcmp(wadfiles[i]->md5sum, md5sum, 16)) + { + CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), fn); + return; + } + } #endif WRITEMEM(buf_p, md5sum, 16); } diff --git a/src/i_tcp.c b/src/i_tcp.c index 5681a9d44..3d55236ec 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -498,8 +498,7 @@ static void cleanupnodes(void) // Why can't I start at zero? for (j = 1; j < MAXNETNODES; j++) - //if (!(nodeingame[j] || SV_SendingFile(j))) - if (!nodeingame[j]) + if (!(nodeingame[j] || SV_SendingFile(j))) nodeconnected[j] = false; }