From 602701d6ddb42b85cb4779f7dacf1be81852c89a Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 11 Jan 2018 16:55:42 +0000 Subject: [PATCH 1/4] G_DoPlayDemo: prepend srb2home to the demo name (if an external file) so that demos in custom home paths can be loaded --- src/d_netcmd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 3696dd974..0d174548c 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1452,7 +1452,12 @@ static void Command_Playdemo_f(void) CONS_Printf(M_GetText("Playing back demo '%s'.\n"), name); - G_DoPlayDemo(name); + // Internal if no extension, external if one exists + // If external, convert the file name to a path in SRB2's home directory + if (FIL_CheckExtension(name)) + G_DoPlayDemo(va("%s"PATHSEP"%s", srb2home, name)) + else + G_DoPlayDemo(name); } static void Command_Timedemo_f(void) From f1b8e122a20b61289844013786a68dfddd349330 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 12 Jan 2018 20:05:09 +0000 Subject: [PATCH 2/4] Fix missing semicolon --- src/d_netcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 0d174548c..82d2a33a8 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1455,7 +1455,7 @@ static void Command_Playdemo_f(void) // Internal if no extension, external if one exists // If external, convert the file name to a path in SRB2's home directory if (FIL_CheckExtension(name)) - G_DoPlayDemo(va("%s"PATHSEP"%s", srb2home, name)) + G_DoPlayDemo(va("%s"PATHSEP"%s", srb2home, name)); else G_DoPlayDemo(name); } From 0ef7aff5c0a847a46147ef525695c4361f12e8ac Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 16 Jan 2018 15:21:49 +0000 Subject: [PATCH 3/4] Prevent SV_SpawnPlayer from being able to freeze the game if gametic is 0. Additionally add a sanity check to prevent the loop going on more than necessary anyway This commit fixes -playdemo and -timedemo params for command line, allowing them to actually work again --- src/d_clisrv.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index d48f223c7..378b23f95 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4445,6 +4445,7 @@ static void Local_Maketic(INT32 realtics) void SV_SpawnPlayer(INT32 playernum, INT32 x, INT32 y, angle_t angle) { tic_t tic; + UINT8 numadjust = 0; (void)x; (void)y; @@ -4454,7 +4455,21 @@ void SV_SpawnPlayer(INT32 playernum, INT32 x, INT32 y, angle_t angle) // spawning, but will be applied afterwards. for (tic = server ? maketic : (neededtic - 1); tic >= gametic; tic--) + { + if (numadjust++ == BACKUPTICS) + { + DEBFILE(va("SV_SpawnPlayer: All netcmds for player %d adjusted!\n", playernum)); + // We already adjusted them all, waste of time doing the same thing over and over + // This shouldn't happen normally though, either gametic was 0 (which is handled now anyway) + // or maketic >= gametic + BACKUPTICS + // -- Monster Iestyn 16/01/18 + break; + } netcmds[tic%BACKUPTICS][playernum].angleturn = (INT16)((angle>>16) | TICCMD_RECEIVED); + + if (!tic) // failsafe for gametic == 0 -- Monster Iestyn 16/01/18 + break; + } } // create missed tic From fa3998e942ca6600919ec5e594b11d1d1c2485ac Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 20 Jan 2018 21:18:16 +0000 Subject: [PATCH 4/4] Some fixes to prevent bad table key types causing Lua panic errors for joining players in netgames: * ArchiveTables: print an error if invalid key, to alert script author potentially * UnArchiveTables: if the key is found to be nil after reading key and value, print an error and don't set them in the table --- src/lua_script.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/lua_script.c b/src/lua_script.c index 167e4a0b4..ce0f19c14 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -767,11 +767,19 @@ static void ArchiveTables(void) lua_pushnil(gL); while (lua_next(gL, -2)) { - ArchiveValue(TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this. + // Write key + e = ArchiveValue(TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this. + if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise) + { + lua_pushvalue(gL, -2); + CONS_Alert(CONS_ERROR, "Index '%s' (%s) of table %d could not be archived!\n", lua_tostring(gL, -1), luaL_typename(gL, -1), i); + lua_pop(gL, 1); + } + // Write value e = ArchiveValue(TABLESINDEX, -1); if (e == 1) n++; // the table contained a new table we'll have to archive. :( - else if (e == 2) + else if (e == 2) // invalid value type { lua_pushvalue(gL, -2); CONS_Alert(CONS_ERROR, "Type of value for table %d entry '%s' (%s) could not be archived!\n", i, lua_tostring(gL, -1), luaL_typename(gL, -1)); @@ -912,11 +920,17 @@ static void UnArchiveTables(void) lua_rawgeti(gL, TABLESINDEX, i); while (true) { - if (UnArchiveValue(TABLESINDEX) == 1) + if (UnArchiveValue(TABLESINDEX) == 1) // read key break; - if (UnArchiveValue(TABLESINDEX) == 2) + if (UnArchiveValue(TABLESINDEX) == 2) // read value n++; - lua_rawset(gL, -3); + if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) + { + CONS_Alert(CONS_ERROR, "A nil key in table %d was found! (Invalid key type or corrupted save?)\n", i); + lua_pop(gL, 2); // pop key and value instead of setting them in the table, to prevent Lua panic errors + } + else + lua_rawset(gL, -3); } lua_pop(gL, 1); }