From e24b87adbdc4cf487c90fe5cca49f09922086228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 11 Oct 2024 21:07:29 +0200 Subject: [PATCH 1/2] Make `CServer::GetMapName` function more efficient by caching Store the current map filename (without path) separately when loading a new map instead of determining it again each time that the `CServer::GetMapName` function is called. Use the `fs_filename` function for this. Avoid the usage of the `sv_map` config variable for this, which may have caused the returned map filename to be out-of-sync with the real map on the server due to the map specified by the config variable not being reloaded immediately. --- src/engine/server/server.cpp | 11 +++-------- src/engine/server/server.h | 1 + 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index d1179df5a..c8a7d735d 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -246,6 +246,7 @@ CServer::CServer() m_SameMapReload = false; m_ReloadedWhenEmpty = false; m_aCurrentMap[0] = '\0'; + m_pCurrentMapName = m_aCurrentMap; m_RconClientId = IServer::RCON_CID_SERV; m_RconAuthLevel = AUTHED_ADMIN; @@ -2541,14 +2542,7 @@ void CServer::PumpNetwork(bool PacketWaiting) const char *CServer::GetMapName() const { - // get the name of the map without his path - const char *pMapShortName = &Config()->m_SvMap[0]; - for(int i = 0; i < str_length(Config()->m_SvMap) - 1; i++) - { - if(Config()->m_SvMap[i] == '/' || Config()->m_SvMap[i] == '\\') - pMapShortName = &Config()->m_SvMap[i + 1]; - } - return pMapShortName; + return m_pCurrentMapName; } void CServer::ChangeMap(const char *pMap) @@ -2587,6 +2581,7 @@ int CServer::LoadMap(const char *pMapName) Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBufMsg); str_copy(m_aCurrentMap, pMapName); + m_pCurrentMapName = fs_filename(m_aCurrentMap); // load complete map into memory for download { diff --git a/src/engine/server/server.h b/src/engine/server/server.h index 7a54efe36..ec4950716 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -242,6 +242,7 @@ public: }; char m_aCurrentMap[IO_MAX_PATH_LENGTH]; + const char *m_pCurrentMapName; SHA256_DIGEST m_aCurrentMapSha256[NUM_MAP_TYPES]; unsigned m_aCurrentMapCrc[NUM_MAP_TYPES]; unsigned char *m_apCurrentMapData[NUM_MAP_TYPES]; From ab60d0bf702ddabdf50c5a00907397e0b2213997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 11 Oct 2024 21:10:16 +0200 Subject: [PATCH 2/2] Fix server-side demos with maps in folders When maps are loaded from folders on the server, the same folders were used for demos but recording would usually fail due to the folders not existing in the demos folder. Furthermore, the map name being written in the demo header also included the folder names, which causes the client to not find the map unless it also exists at that location. Closes #9033. --- src/engine/server/server.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index c8a7d735d..13dcd93e2 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -3393,13 +3393,13 @@ void CServer::DemoRecorder_HandleAutoStart() char aTimestamp[20]; str_timestamp(aTimestamp, sizeof(aTimestamp)); char aFilename[IO_MAX_PATH_LENGTH]; - str_format(aFilename, sizeof(aFilename), "demos/auto/server/%s_%s.demo", m_aCurrentMap, aTimestamp); + str_format(aFilename, sizeof(aFilename), "demos/auto/server/%s_%s.demo", GetMapName(), aTimestamp); m_aDemoRecorder[RECORDER_AUTO].Start( Storage(), m_pConsole, aFilename, GameServer()->NetVersion(), - m_aCurrentMap, + GetMapName(), m_aCurrentMapSha256[MAP_TYPE_SIX], m_aCurrentMapCrc[MAP_TYPE_SIX], "server", @@ -3423,7 +3423,7 @@ void CServer::SaveDemo(int ClientId, float Time) if(IsRecording(ClientId)) { char aNewFilename[IO_MAX_PATH_LENGTH]; - str_format(aNewFilename, sizeof(aNewFilename), "demos/%s_%s_%05.2f.demo", m_aCurrentMap, m_aClients[ClientId].m_aName, Time); + str_format(aNewFilename, sizeof(aNewFilename), "demos/%s_%s_%05.2f.demo", GetMapName(), m_aClients[ClientId].m_aName, Time); m_aDemoRecorder[ClientId].Stop(IDemoRecorder::EStopMode::KEEP_FILE, aNewFilename); } } @@ -3433,13 +3433,13 @@ void CServer::StartRecord(int ClientId) if(Config()->m_SvPlayerDemoRecord) { char aFilename[IO_MAX_PATH_LENGTH]; - str_format(aFilename, sizeof(aFilename), "demos/%s_%d_%d_tmp.demo", m_aCurrentMap, m_NetServer.Address().port, ClientId); + str_format(aFilename, sizeof(aFilename), "demos/%s_%d_%d_tmp.demo", GetMapName(), m_NetServer.Address().port, ClientId); m_aDemoRecorder[ClientId].Start( Storage(), Console(), aFilename, GameServer()->NetVersion(), - m_aCurrentMap, + GetMapName(), m_aCurrentMapSha256[MAP_TYPE_SIX], m_aCurrentMapCrc[MAP_TYPE_SIX], "server", @@ -3501,7 +3501,7 @@ void CServer::ConRecord(IConsole::IResult *pResult, void *pUser) pServer->Console(), aFilename, pServer->GameServer()->NetVersion(), - pServer->m_aCurrentMap, + pServer->GetMapName(), pServer->m_aCurrentMapSha256[MAP_TYPE_SIX], pServer->m_aCurrentMapCrc[MAP_TYPE_SIX], "server",