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 @@ +