From d257372c42544cec9f1ac0bd6cca38953eaef37a Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Mon, 22 Apr 2024 23:01:00 +0800 Subject: [PATCH] [server] Implement `CNetGame::SetNextScriptFile(...)` --- server/netgame.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++ server/netgame.h | 2 ++ server/runutil.cpp | 15 +++++++++++++ server/runutil.h | 1 + 4 files changed, 70 insertions(+) create mode 100644 server/runutil.cpp create mode 100644 server/runutil.h diff --git a/server/netgame.cpp b/server/netgame.cpp index ab8b35b..774071e 100644 --- a/server/netgame.cpp +++ b/server/netgame.cpp @@ -1,6 +1,8 @@ #include "main.h" +int CanFileBeOpenedForReading(char * filename); + char szGameModeFile[256]; CNetGame::CNetGame() @@ -239,8 +241,58 @@ char *CNetGame::GetNextScriptFile() return szTemp; } +BOOL CNetGame::SetNextScriptFile(char *szFile) +{ + char szConfigFileName[64]; + char *szTemp; + int iConfigRepeatCount=0; + if(NULL == szFile) { + // rotate by config + if(m_iCurrentGameModeRepeat || !m_bFirstGameModeLoaded) { + // repeats of this script, cycle to the current + m_iCurrentGameModeIndex--; + } + + szTemp = this->GetNextScriptFile(); + if (szTemp == NULL) return false; + + sscanf(szTemp,"%s%d",szConfigFileName,&iConfigRepeatCount); + + // set it and verify the file is readable + sprintf(szGameModeFile,"gamemodes/%s.amx",szConfigFileName); + + if(!CanFileBeOpenedForReading(szGameModeFile)) { + return FALSE; + } + + if(!m_iCurrentGameModeRepeat) { + m_iCurrentGameModeRepeat = iConfigRepeatCount; + } + + m_iCurrentGameModeRepeat--; + + m_bFirstGameModeLoaded = TRUE; + + return TRUE; + + } else { + // set the script from szFile + + // set it and verify the file is readable + sprintf(szGameModeFile,"gamemodes/%s.amx",szFile); + + if(!CanFileBeOpenedForReading(szGameModeFile)) { + return FALSE; + } + + m_iCurrentGameModeRepeat = 0; + + return TRUE; + } + +} //---------------------------------------------------- diff --git a/server/netgame.h b/server/netgame.h index 8b60bbb..63033af 100644 --- a/server/netgame.h +++ b/server/netgame.h @@ -74,6 +74,8 @@ public: void Init(BOOL bFirst); void ShutdownForGameModeRestart(); + BOOL SetNextScriptFile(char *szFile); + CPlayerPool * GetPlayerPool() { return m_pPlayerPool; }; RakServerInterface * GetRakServer() { return m_pRak; }; diff --git a/server/runutil.cpp b/server/runutil.cpp new file mode 100644 index 0000000..b7d790d --- /dev/null +++ b/server/runutil.cpp @@ -0,0 +1,15 @@ +#include + +//---------------------------------------------------- + +int CanFileBeOpenedForReading(char * filename) +{ + FILE *f; + if(f=fopen(filename,"r")) { + fclose(f); + return 1; + } + return 0; +} + +//---------------------------------------------------- diff --git a/server/runutil.h b/server/runutil.h new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/server/runutil.h @@ -0,0 +1 @@ +