From ccefc48af365da13c05bdefe55161b69c61e9af8 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sun, 24 Mar 2019 20:36:22 -0500 Subject: [PATCH] Use demo title as filename for multiplayer replays --- src/d_main.c | 2 ++ src/g_game.c | 41 ++++++++++++++++++++++++++++++++++++++++- src/m_menu.c | 2 ++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/d_main.c b/src/d_main.c index 84d5a6f3..674cf365 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1529,6 +1529,8 @@ void D_SRB2Main(void) // as having been modified for the first game. M_PushSpecialParameters(); // push all "+" parameter at the command buffer + strncpy(connectedservername, cv_servername.string, MAXSERVERNAME); + if (M_CheckParm("-gametype") && M_IsNextParm()) { // from Command_Map_f diff --git a/src/g_game.c b/src/g_game.c index 319c4a00..8e58c975 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -288,7 +288,7 @@ UINT32 timesBeatenWithEmeralds; //UINT32 timesBeatenUltimate; //@TODO put these all in a struct for namespacing purposes? -static char demoname[64]; +static char demoname[128]; char demotitle[65]; boolean demorecording, demosaved, demodefersave, demoplayback; boolean demo_loadfiles, demo_ignorefiles; // Demo file loading options @@ -7625,6 +7625,45 @@ void G_SaveDemo(void) M_Memcpy(p, demotitle, 64); // Write demo title here p += 64; + if (multiplayer) + { + // Change the demo's name to be a slug of the title + char demo_slug[128]; + char *writepoint; + size_t i, strindex = 0; + boolean dash = true; + + for (i = 0; demotitle[i] && i < 127; i++) + { + if ((demotitle[i] >= 'a' && demotitle[i] <= 'z') || (demotitle[i] >= '0' && demotitle[i] <= '9')) + { + demo_slug[strindex] = demotitle[i]; + strindex++; + dash = false; + } + else if (demotitle[i] >= 'A' && demotitle[i] <= 'Z') + { + demo_slug[strindex] = demotitle[i] + 'a' - 'A'; + strindex++; + dash = false; + } + else if (!dash) + { + demo_slug[strindex] = '-'; + strindex++; + dash = true; + } + } + + demo_slug[strindex] = 0; + if (dash) demo_slug[strindex-1] = 0; + CONS_Printf("%s\n%s\n", demotitle, demo_slug); + + writepoint = strstr(demoname, "-") + 1; + demo_slug[128 - (writepoint - demoname) - 4] = 0; + sprintf(writepoint, "%s.lmp", demo_slug); + } + #ifdef NOMD5 for (i = 0; i < 16; i++, p++) *p = M_RandomByte(); // This MD5 was chosen by fair dice roll and most likely < 50% correct. diff --git a/src/m_menu.c b/src/m_menu.c index 0fc62233..fa88d601 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -7579,6 +7579,8 @@ static void M_StartServer(INT32 choice) multiplayer = true; + strncpy(connectedservername, cv_servername.string, MAXSERVERNAME); + // Still need to reset devmode cv_debug = 0;