mirror of
https://github.com/dashr9230/SA-MP.git
synced 2024-12-22 14:37:29 +08:00
[server] Implement CNetGame::SetNextScriptFile(...)
This commit is contained in:
parent
2fecf6f0ae
commit
d257372c42
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
|
@ -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
15
server/runutil.cpp
Normal 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
1
server/runutil.h
Normal file
@ -0,0 +1 @@
|
||||
|
Loading…
Reference in New Issue
Block a user