[server] Implement CNetGame::SetNextScriptFile(...)

This commit is contained in:
RD42 2024-04-22 23:01:00 +08:00
parent 2fecf6f0ae
commit d257372c42
4 changed files with 70 additions and 0 deletions

View File

@ -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;
}
}
//----------------------------------------------------

View File

@ -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; };

15
server/runutil.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
//----------------------------------------------------
int CanFileBeOpenedForReading(char * filename)
{
FILE *f;
if(f=fopen(filename,"r")) {
fclose(f);
return 1;
}
return 0;
}
//----------------------------------------------------

1
server/runutil.h Normal file
View File

@ -0,0 +1 @@