Merge pull request #9140 from Robyt3/Server-Demos-Filename-Fix

Fix server-side demos with maps in folders, make `CServer::GetMapName` function more efficient by caching
This commit is contained in:
Dennis Felsing 2024-10-11 20:23:53 +00:00 committed by GitHub
commit 0d76b482ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 14 deletions

View file

@ -246,6 +246,7 @@ CServer::CServer()
m_SameMapReload = false; m_SameMapReload = false;
m_ReloadedWhenEmpty = false; m_ReloadedWhenEmpty = false;
m_aCurrentMap[0] = '\0'; m_aCurrentMap[0] = '\0';
m_pCurrentMapName = m_aCurrentMap;
m_RconClientId = IServer::RCON_CID_SERV; m_RconClientId = IServer::RCON_CID_SERV;
m_RconAuthLevel = AUTHED_ADMIN; m_RconAuthLevel = AUTHED_ADMIN;
@ -2541,14 +2542,7 @@ void CServer::PumpNetwork(bool PacketWaiting)
const char *CServer::GetMapName() const const char *CServer::GetMapName() const
{ {
// get the name of the map without his path return m_pCurrentMapName;
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;
} }
void CServer::ChangeMap(const char *pMap) void CServer::ChangeMap(const char *pMap)
@ -2587,6 +2581,7 @@ int CServer::LoadMap(const char *pMapName)
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBufMsg); Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBufMsg);
str_copy(m_aCurrentMap, pMapName); str_copy(m_aCurrentMap, pMapName);
m_pCurrentMapName = fs_filename(m_aCurrentMap);
// load complete map into memory for download // load complete map into memory for download
{ {
@ -3398,13 +3393,13 @@ void CServer::DemoRecorder_HandleAutoStart()
char aTimestamp[20]; char aTimestamp[20];
str_timestamp(aTimestamp, sizeof(aTimestamp)); str_timestamp(aTimestamp, sizeof(aTimestamp));
char aFilename[IO_MAX_PATH_LENGTH]; 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( m_aDemoRecorder[RECORDER_AUTO].Start(
Storage(), Storage(),
m_pConsole, m_pConsole,
aFilename, aFilename,
GameServer()->NetVersion(), GameServer()->NetVersion(),
m_aCurrentMap, GetMapName(),
m_aCurrentMapSha256[MAP_TYPE_SIX], m_aCurrentMapSha256[MAP_TYPE_SIX],
m_aCurrentMapCrc[MAP_TYPE_SIX], m_aCurrentMapCrc[MAP_TYPE_SIX],
"server", "server",
@ -3428,7 +3423,7 @@ void CServer::SaveDemo(int ClientId, float Time)
if(IsRecording(ClientId)) if(IsRecording(ClientId))
{ {
char aNewFilename[IO_MAX_PATH_LENGTH]; 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); m_aDemoRecorder[ClientId].Stop(IDemoRecorder::EStopMode::KEEP_FILE, aNewFilename);
} }
} }
@ -3438,13 +3433,13 @@ void CServer::StartRecord(int ClientId)
if(Config()->m_SvPlayerDemoRecord) if(Config()->m_SvPlayerDemoRecord)
{ {
char aFilename[IO_MAX_PATH_LENGTH]; 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( m_aDemoRecorder[ClientId].Start(
Storage(), Storage(),
Console(), Console(),
aFilename, aFilename,
GameServer()->NetVersion(), GameServer()->NetVersion(),
m_aCurrentMap, GetMapName(),
m_aCurrentMapSha256[MAP_TYPE_SIX], m_aCurrentMapSha256[MAP_TYPE_SIX],
m_aCurrentMapCrc[MAP_TYPE_SIX], m_aCurrentMapCrc[MAP_TYPE_SIX],
"server", "server",
@ -3506,7 +3501,7 @@ void CServer::ConRecord(IConsole::IResult *pResult, void *pUser)
pServer->Console(), pServer->Console(),
aFilename, aFilename,
pServer->GameServer()->NetVersion(), pServer->GameServer()->NetVersion(),
pServer->m_aCurrentMap, pServer->GetMapName(),
pServer->m_aCurrentMapSha256[MAP_TYPE_SIX], pServer->m_aCurrentMapSha256[MAP_TYPE_SIX],
pServer->m_aCurrentMapCrc[MAP_TYPE_SIX], pServer->m_aCurrentMapCrc[MAP_TYPE_SIX],
"server", "server",

View file

@ -242,6 +242,7 @@ public:
}; };
char m_aCurrentMap[IO_MAX_PATH_LENGTH]; char m_aCurrentMap[IO_MAX_PATH_LENGTH];
const char *m_pCurrentMapName;
SHA256_DIGEST m_aCurrentMapSha256[NUM_MAP_TYPES]; SHA256_DIGEST m_aCurrentMapSha256[NUM_MAP_TYPES];
unsigned m_aCurrentMapCrc[NUM_MAP_TYPES]; unsigned m_aCurrentMapCrc[NUM_MAP_TYPES];
unsigned char *m_apCurrentMapData[NUM_MAP_TYPES]; unsigned char *m_apCurrentMapData[NUM_MAP_TYPES];