diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 1a2717a12..729a8f698 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -159,7 +159,6 @@ boolean nodeingame[MAXNETNODES] = {}; // set false as nodes leave game tic_t servermaxping = 20; // server's max delay, in frames. Defaults to 20 static tic_t nettics[MAXNETNODES]; // what tic the client have received -static tic_t supposedtics[MAXNETNODES]; // nettics prevision for smaller packet static UINT8 nodewaiting[MAXNETNODES]; static tic_t firstticstosend; // min of the nettics static tic_t tictoclear = 0; // optimize d_clearticcmd @@ -186,7 +185,6 @@ boolean hu_stopped = false; // Client specific static ticcmd_t localcmds[MAXSPLITSCREENPLAYERS][MAXGENTLEMENDELAY]; -static boolean cl_packetmissed; // here it is for the secondary local player (splitscreen) static UINT8 mynode; // my address pointofview server @@ -4296,7 +4294,6 @@ static void ResetNode(INT32 node) playerpernode[node] = 0; nettics[node] = gametic; - supposedtics[node] = gametic; sendingsavegame[node] = false; @@ -4351,7 +4348,7 @@ void SV_ResetServer(void) ClearAdminPlayers(); mynode = 0; - cl_packetmissed = false; + #ifdef SATURNPAK cl_redownloadinggamestate = false; #endif @@ -4453,7 +4450,7 @@ void D_QuitNetGame(void) static inline void SV_AddNode(INT32 node) { nettics[node] = gametic; - supposedtics[node] = gametic; + // little hack because the server connects to itself and puts // nodeingame when connected not here if (node) @@ -5535,14 +5532,6 @@ static void PT_ClientCmd(INT32 netconsole, SINT8 node) realstart = ExpandTics(netbuffer->u.clientpak.client_tic, nettics[node]); realend = ExpandTics(netbuffer->u.clientpak.resendfrom, nettics[node]); - if (netbuffer->packettype == PT_CLIENTMIS || netbuffer->packettype == PT_CLIENT2MIS - || netbuffer->packettype == PT_CLIENT3MIS || netbuffer->packettype == PT_CLIENT4MIS - || netbuffer->packettype == PT_NODEKEEPALIVEMIS - || supposedtics[node] < realend) - { - supposedtics[node] = realend; - } - // Discard out of order packet if (nettics[node] > realend) { @@ -5894,7 +5883,6 @@ static void PT_ServerTics(SINT8 node) if (realend > gametic + CLIENTBACKUPTICS) realend = gametic + CLIENTBACKUPTICS; - cl_packetmissed = realstart > neededtic; UINT8 *pak = (UINT8 *)&packet->cmds; UINT8 *txtpak = (UINT8 *)&packet->cmds[packet->numslots * packet->numtics]; @@ -6027,11 +6015,12 @@ static void HandlePacketFromPlayer(SINT8 node) case PT_CLIENT2CMD: case PT_CLIENT3CMD: case PT_CLIENT4CMD: + case PT_NODEKEEPALIVE: + // "mis" tics kept for vanilla compat case PT_CLIENTMIS: case PT_CLIENT2MIS: case PT_CLIENT3MIS: case PT_CLIENT4MIS: - case PT_NODEKEEPALIVE: case PT_NODEKEEPALIVEMIS: PT_ClientCmd(netconsole, node); break; @@ -6323,25 +6312,18 @@ static void SV_SendServerKeepAlive(void) static void CL_SendClientCmd(void) { size_t packetsize = 0; - boolean mis = false; doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); netbuffer->packettype = PT_CLIENTCMD; - if (cl_packetmissed) - { - netbuffer->packettype = PT_CLIENTMIS; - mis = true; - } - netbuffer->u.clientpak.resendfrom = (UINT8)(neededtic & UINT8_MAX); netbuffer->u.clientpak.client_tic = (UINT8)(gametic & UINT8_MAX); if (gamestate == GS_WAITINGPLAYERS) { // Send PT_NODEKEEPALIVE packet - netbuffer->packettype = (mis ? PT_NODEKEEPALIVEMIS : PT_NODEKEEPALIVE); + netbuffer->packettype = PT_NODEKEEPALIVE; packetsize = sizeof (clientcmd_pak) - sizeof (ticcmd_t) - sizeof (INT16); HSendPacket(servernode, false, 0, packetsize); } @@ -6404,19 +6386,19 @@ static void CL_SendClientCmd(void) if (splitscreen || botingame) // Send a special packet with 2 cmd for splitscreen { - netbuffer->packettype = (mis ? PT_CLIENT2MIS : PT_CLIENT2CMD); + netbuffer->packettype = PT_CLIENT2CMD; packetsize = sizeof (client2cmd_pak); G_MoveTiccmd(&netbuffer->u.client2pak.cmd2, &localcmds[1][lagDelay], 1); if (splitscreen > 1) { - netbuffer->packettype = (mis ? PT_CLIENT3MIS : PT_CLIENT3CMD); + netbuffer->packettype = PT_CLIENT3CMD; packetsize = sizeof (client3cmd_pak); G_MoveTiccmd(&netbuffer->u.client3pak.cmd3, &localcmds[2][lagDelay], 1); if (splitscreen > 2) { - netbuffer->packettype = (mis ? PT_CLIENT4MIS : PT_CLIENT4CMD); + netbuffer->packettype = PT_CLIENT4CMD; packetsize = sizeof (client4cmd_pak); G_MoveTiccmd(&netbuffer->u.client4pak.cmd4, &localcmds[3][lagDelay], 1); } @@ -6471,14 +6453,13 @@ static void SV_SendTics(void) // send to all client but not to me // for each node create a packet with x tics and send it - // x is computed using supposedtics[n], max packet size and maketic + // x is computed using nettics[n], max packet size and maketic for (n = 1; n < MAXNETNODES; n++) { if (!nodeingame[n]) continue; - // assert supposedtics[n]>=nettics[n] - realfirsttic = supposedtics[n]; + realfirsttic = nettics[n]; lasttictosend = min(maketic, nettics[n] + CLIENTBACKUPTICS); if (realfirsttic >= lasttictosend) @@ -6487,8 +6468,8 @@ static void SV_SendTics(void) // to resent packet that are supposed lost (this is necessary since lost // packet detection work when we have received packet with firsttic > neededtic // (getpacket servertics case) - DEBFILE(va("Nothing to send node %u mak=%u sup=%u net=%u \n", - n, lasttictosend, supposedtics[n], nettics[n])); + DEBFILE(va("Nothing to send node %u mak=%u net=%u \n", + n, lasttictosend, nettics[n])); realfirsttic = nettics[n]; if (realfirsttic >= lasttictosend || (I_GetTime() + n)&3) // all tic are ok @@ -6568,17 +6549,10 @@ static void SV_SendTics(void) packsize = bufpos - (UINT8 *)&(netbuffer->u); HSendPacket(n, false, 0, packsize); - - // when tic are too large, only one tic is sent so don't go backward! - if (lasttictosend-doomcom->extratics > realfirsttic) - supposedtics[n] = lasttictosend-doomcom->extratics; - else - supposedtics[n] = lasttictosend; - - supposedtics[n] = max(supposedtics[n], nettics[n]); } + // node 0 is me! - supposedtics[0] = maketic; + nettics[0] = maketic; } // @@ -6652,7 +6626,7 @@ void SV_SpawnPlayer(INT32 playernum, INT32 x, INT32 y, angle_t angle) // create missed tic static void SV_Maketic(void) { - G_MoveTiccmd(netcmds[maketic % BACKUPTICS], playercmds, MAXPLAYERS); + G_CopyTiccmd(netcmds[maketic % BACKUPTICS], playercmds, MAXPLAYERS); maketic++; } diff --git a/src/d_main.c b/src/d_main.c index ab10af215..c46ef0c44 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -679,9 +679,6 @@ void D_SRB2Loop(void) for (;;) { - if (I_Interrupted()) - I_Quit(); - // capbudget is the minimum precise_t duration of a single loop iteration precise_t capbudget; precise_t elapsed; diff --git a/src/d_net.c b/src/d_net.c index fd8fb0e31..3e0d4410c 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -863,11 +863,12 @@ static void DebugPrintpacket(const char *header) case PT_CLIENT2CMD: case PT_CLIENT3CMD: case PT_CLIENT4CMD: + case PT_NODEKEEPALIVE: + // "mis" tics kept for vanilla compat case PT_CLIENTMIS: case PT_CLIENT2MIS: case PT_CLIENT3MIS: case PT_CLIENT4MIS: - case PT_NODEKEEPALIVE: case PT_NODEKEEPALIVEMIS: fprintf(debugfile, " tic %4u resendfrom %u\n", (UINT32)netbuffer->u.clientpak.client_tic, diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 38512cb78..b579e6848 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4409,8 +4409,6 @@ static void Command_LocateLump_f(void) } } -#define MAXDOOMEDNUM 4095 - static void Command_ListDoomednums_f(void) { INT16 i, j, k = 0, l = 0; diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 5edb71a99..31eaf0346 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -1075,19 +1075,11 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) } #endif -static volatile sig_atomic_t interrupted = 0; - -boolean I_Interrupted(void) -{ - return interrupted; -} - -static void quit_handler(int num) +FUNCNORETURN static ATTRNORETURN void quit_handler(int num) { signal(num, SIG_DFL); //default signal action raise(num); - //I_Quit(); - interrupted = true; + I_Quit(); } #ifdef HAVE_LIBBACKTRACE diff --git a/src/g_demo.c b/src/g_demo.c index a714f8e48..312e57530 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -55,6 +55,8 @@ #include "k_stats.h" // SRB2kart #include "r_fps.h" // frame interpolation/uncapped +#include + #ifdef HAVE_DISCORDRPC #include "discord.h" #endif @@ -2401,49 +2403,69 @@ static long G_GetCreationTime(char *filepath) static char *G_GetDemoDate(menudemo_t *pdemo) { - char *datetime; - datetime = malloc(sizeof(pdemo->date)); // mallocma balls - - // no mallocma balls... :c - if (!datetime) - { - return NULL; - } - + char *endPos = NULL; + static char datetime[11]; time_t file_time = 0; + const char *format = NULL; + struct tm *tm_buf = NULL; + CLEANUP(pfree) char *filename = NULL; // get le filepath - char *filename; filename = strdup(pdemo->filepath); -#if defined (_WIN32) if (!filename) { - // if we cant get a filename try just getting the file create time +#if defined (_WIN32) + // if we cant get a filename try just getting the file creation time file_time = G_GetCreationTime(pdemo->filepath); goto skipfilenametime; - } #else - if (!filename) - { - free(datetime); return NULL; - } #endif + } // get the actual filename Zzz... nameonly(filename); - // convert it to long Zzz.... - file_time = strtol(filename, NULL, 10); - free(filename); // dont need this anymore a + // the first 10 characters of a replay name usually is a unix timestamp + + // not long enough to contain a valid timestamp + if (strlen(filename) < 10) + { +#if defined (_WIN32) + // try to get file creation time + file_time = G_GetCreationTime(pdemo->filepath); + goto skipfilenametime; +#else + return NULL; +#endif + } + +#ifndef AVOID_ERRNO + errno = 0; +#endif + // get the timestamp as actual numbers lul + file_time = strtol(filename, &endPos, 10); + + if (endPos == filename // Empty string +#ifndef AVOID_ERRNO + || errno == ERANGE // Number out-of-range +#endif + || file_time < 0) // Number is not positive + { +#if defined (_WIN32) + // just try and get the creation time then + file_time = G_GetCreationTime(pdemo->filepath); +#else + return NULL; +#endif + } #if defined (_WIN32) skipfilenametime: #endif // then throw it into localtime to get an actual human readable format lmao - struct tm *tm_buf = NULL; tm_buf = localtime(&file_time); // cant believe we ended up in 1970 @@ -2456,14 +2478,10 @@ skipfilenametime: tm_buf = localtime(&file_time); if (tm_buf == NULL || tm_buf->tm_year <= 110) - { - free(datetime); return NULL; - } goto gotcreationtime; #else - free(datetime); return NULL; #endif } @@ -2472,17 +2490,27 @@ skipfilenametime: gotcreationtime: #endif - const char *format; - // US ppl are special (: if (cv_demodateformat.value == 2) format = "%m.%d.%Y"; else if (cv_demodateformat.value == 1) format = "%d.%m.%Y"; else - format = strstr(setlocale(LC_TIME, NULL), "en_US") ? "%m.%d.%Y" : "%d.%m.%Y"; + { + const char *locale = setlocale(LC_TIME, NULL); - strftime(datetime, sizeof(pdemo->date), format, tm_buf); + if (locale == NULL) + format = "%d.%m.%Y"; // fallback to non US format + else if (strstr(locale, "en_US")) + format = "%m.%d.%Y"; + else + format = "%d.%m.%Y"; + } + + if (strftime(datetime, sizeof(datetime), format, tm_buf) == 0) + { + return NULL; + } return datetime; } @@ -2491,6 +2519,7 @@ void G_LoadDemoTitle(menudemo_t *pdemo) { UINT8 infobuffer[96], *info_p; UINT16 pdemoversion; + char *demodate = NULL; size_t count; FILE *handle = fopen(pdemo->filepath, "rb"); @@ -2529,13 +2558,13 @@ void G_LoadDemoTitle(menudemo_t *pdemo) memcpy(pdemo->title, info_p, 64); // demo date - char *demodate; demodate = G_GetDemoDate(pdemo); if (demodate) - strncpy(pdemo->date, demodate, sizeof(pdemo->date)); + { + strlcpy(pdemo->date, demodate, sizeof(pdemo->date)); + } - free(demodate); break; #ifdef DEMO_COMPAT_100 case 0x0001: diff --git a/src/i_system.h b/src/i_system.h index 68d51f022..7084c655f 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -29,6 +29,7 @@ extern "C" { */ #define MAX_QUIT_FUNCS 16 + /** \brief Graphic system had started up */ extern UINT8 graphics_started; @@ -190,8 +191,6 @@ INT32 I_StartupSystem(void); */ void I_ShutdownSystem(void); -boolean I_Interrupted(void); - /** \brief The I_GetDiskFreeSpace function \param freespace a INT64 pointer to hold the free space amount diff --git a/src/info.h b/src/info.h index 4ee851cee..c84d63214 100644 --- a/src/info.h +++ b/src/info.h @@ -19,6 +19,8 @@ #include "sounds.h" #include "m_fixed.h" +#define MAXDOOMEDNUM 4095 + // dehacked.c now has lists for the more named enums! PLEASE keep them up to date! // For great modding!! diff --git a/src/p_local.h b/src/p_local.h index 4b6530eb9..3c16b5c62 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -272,7 +272,7 @@ extern consvar_t cv_gravity; void P_RespawnSpecials(void); -extern mobjtype_t g_doomednum_to_mobjtype[UINT16_MAX]; +extern mobjtype_t g_doomednum_to_mobjtype[MAXDOOMEDNUM+1]; void CalculateDoomednumToMobjtype(void); mobj_t *P_AllocateMobj(void); diff --git a/src/p_mobj.c b/src/p_mobj.c index cd7d44a62..ad7982d87 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10463,17 +10463,20 @@ void P_PrecipitationEffects(void) } } -mobjtype_t g_doomednum_to_mobjtype[UINT16_MAX]; +mobjtype_t g_doomednum_to_mobjtype[MAXDOOMEDNUM+1] = {}; void CalculateDoomednumToMobjtype(void) { memset(g_doomednum_to_mobjtype, MT_NULL, sizeof(g_doomednum_to_mobjtype)); - for (size_t i = MT_NULL+1; i < NUMMOBJTYPES; i++) + for (size_t i = 0; i < NUMMOBJTYPES; i++) { - if (mobjinfo[i].doomednum > 0 && mobjinfo[i].doomednum <= UINT16_MAX) + const INT32 doomednum = mobjinfo[i].doomednum; + + if (doomednum > 0 && doomednum <= MAXDOOMEDNUM) { - g_doomednum_to_mobjtype[ mobjinfo[i].doomednum ] = i; + if (g_doomednum_to_mobjtype[doomednum] == MT_NULL) + g_doomednum_to_mobjtype[doomednum] = (mobjtype_t)i; } } } @@ -10551,7 +10554,7 @@ void P_RespawnSpecials(void) if (mthing) { - mobjtype_t i; + mobjtype_t i = MT_NULL; x = mthing->x << FRACBITS; y = mthing->y << FRACBITS; ss = R_PointInSubsector(x, y); @@ -10987,7 +10990,7 @@ INT32 numhuntemeralds = 0; // void P_SpawnMapThing(mapthing_t *mthing) { - mobjtype_t i; + mobjtype_t i = MT_NULL; mobj_t *mobj; fixed_t x, y, z; subsector_t *ss; diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 8a9b8bd69..0c024a5bd 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1670,19 +1670,21 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) } #endif -static volatile sig_atomic_t interrupted = 0; - -boolean I_Interrupted(void) +FUNCNORETURN static ATTRNORETURN void quit_handler(int num) { - return interrupted; -} +#ifdef HAVE_THREADS + if (g_main_thread_id != std::this_thread::get_id()) + { + // Do not attempt any sort of recovery if this signal triggers off the main thread + signal(num, SIG_DFL); + raise(num); + exit(-2); + } +#endif -static void quit_handler(int num) -{ signal(num, SIG_DFL); //default signal action raise(num); - //I_Quit(); - interrupted = true; + I_Quit(); } static void I_RegisterSignals(void) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 6c99067f5..61c7fc744 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -2182,8 +2182,7 @@ void I_ShutdownGraphics(void) SDL_DestroyWindow(window); window = NULL; - if (SDL_WasInit(SDL_INIT_VIDEO) == SDL_INIT_VIDEO) - SDL_QuitSubSystem(SDL_INIT_VIDEO); + SDL_QuitSubSystem(SDL_INIT_VIDEO); framebuffer = SDL_FALSE; } diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index c455aab01..529b47399 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -237,8 +237,7 @@ void I_ShutdownSound(void) Mix_Quit(); #endif - if (SDL_WasInit(SDL_INIT_AUDIO) == SDL_INIT_AUDIO) - SDL_QuitSubSystem(SDL_INIT_AUDIO); + SDL_QuitSubSystem(SDL_INIT_AUDIO); #ifdef HAVE_LIBGME if (gme)