Address pull request comments

This commit is contained in:
heinrich5991 2017-10-13 02:25:50 +02:00
parent d5008d87a3
commit 8e778cd9ab
7 changed files with 63 additions and 29 deletions

View file

@ -85,7 +85,7 @@ IOHANDLE io_stderr() { return (IOHANDLE)stderr; }
typedef struct
{
DBG_LOGGER logger;
void (*finish)(void *user);
DBG_LOGGER_FINISH finish;
void *user;
} DBG_LOGGER_DATA;
@ -194,7 +194,7 @@ static void dbg_logger_finish(void)
}
}
void dbg_logger(DBG_LOGGER logger, void (*finish)(void *user), void *user)
void dbg_logger(DBG_LOGGER logger, DBG_LOGGER_FINISH finish, void *user)
{
DBG_LOGGER_DATA data;
if(num_loggers == 0)
@ -737,7 +737,6 @@ void async_wait(ASYNCIO *aio)
thread_wait(thread);
}
void *thread_init(void (*threadfunc)(void *), void *u)
{
#if defined(CONF_FAMILY_UNIX)

View file

@ -1358,14 +1358,13 @@ void swap_endian(void *data, unsigned elem_size, unsigned num);
typedef void (*DBG_LOGGER)(const char *line, void *user);
void dbg_logger(DBG_LOGGER logger, void (*finish)(void *user), void *user);
typedef void (*DBG_LOGGER_FINISH)(void *user);
void dbg_logger(DBG_LOGGER logger, DBG_LOGGER_FINISH finish, void *user);
void dbg_logger_stdout();
void dbg_logger_debugger();
void dbg_logger_file(const char *filename);
void dbg_log_finish();
typedef struct
{
int allocated;

View file

@ -180,6 +180,8 @@ public:
virtual void ResetNetErrorString(int ClientID) = 0;
virtual bool SetTimedOut(int ClientID, int OrigID) = 0;
virtual void SetTimeoutProtected(int ClientID) = 0;
virtual void SetErrorShutdown(const char *pReason) = 0;
};
class IGameServer : public IInterface

View file

@ -334,6 +334,8 @@ CServer::CServer()
CSqlConnector::SetWriteServers(m_apSqlWriteServers);
#endif
m_aErrorShutdownReason[0] = 0;
Init();
}
@ -1746,6 +1748,10 @@ int CServer::Run()
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
GameServer()->OnInit();
if(ErrorShutdown())
{
return 1;
}
str_format(aBuf, sizeof(aBuf), "version %s", GameServer()->NetVersion());
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
@ -1808,6 +1814,10 @@ int CServer::Run()
m_ServerInfoFirstRequest = 0;
Kernel()->ReregisterInterface(GameServer());
GameServer()->OnInit();
if(ErrorShutdown())
{
break;
}
UpdateServerInfo();
}
else
@ -1885,6 +1895,10 @@ int CServer::Run()
}
GameServer()->OnTick();
if(ErrorShutdown())
{
break;
}
}
// snap game
@ -1942,11 +1956,16 @@ int CServer::Run()
}
}
}
const char *pDisconnectReason = "Server shutdown";
if(ErrorShutdown())
{
pDisconnectReason = m_aErrorShutdownReason;
}
// disconnect all clients on shutdown
for(int i = 0; i < MAX_CLIENTS; ++i)
{
if(m_aClients[i].m_State != CClient::STATE_EMPTY)
m_NetServer.Drop(i, "Server shutdown");
m_NetServer.Drop(i, pDisconnectReason);
}
m_Econ.Shutdown();
@ -1972,7 +1991,7 @@ int CServer::Run()
}
#endif
return 0;
return ErrorShutdown();
}
void CServer::ConTestingCommands(CConsole::IResult *pResult, void *pUser)
@ -2817,7 +2836,8 @@ int* CServer::GetIdMap(int ClientID)
return (int *)(IdMap + VANILLA_MAX_CLIENTS * ClientID);
}
bool CServer::SetTimedOut(int ClientID, int OrigID) {
bool CServer::SetTimedOut(int ClientID, int OrigID)
{
if (!m_NetServer.SetTimedOut(ClientID, OrigID))
{
return false;
@ -2826,3 +2846,8 @@ bool CServer::SetTimedOut(int ClientID, int OrigID) {
m_aClients[ClientID].m_Authed = IServer::AUTHED_NO;
return true;
}
void CServer::SetErrorShutdown(const char *pReason)
{
str_copy(m_aErrorShutdownReason, pReason, sizeof(m_aErrorShutdownReason));
}

View file

@ -209,6 +209,8 @@ public:
int64 m_ServerInfoFirstRequest;
int m_ServerInfoNumRequests;
char m_aErrorShutdownReason[128];
CServer();
int TrySetClientName(int ClientID, const char *pName);
@ -353,6 +355,9 @@ public:
void ResetNetErrorString(int ClientID) { m_NetServer.ResetErrorString(ClientID); };
bool SetTimedOut(int ClientID, int OrigID);
void SetTimeoutProtected(int ClientID) { m_NetServer.SetTimeoutProtected(ClientID); };
bool ErrorShutdown() const { return m_aErrorShutdownReason[0] != 0; }
void SetErrorShutdown(const char *pReason);
};
#endif

View file

@ -608,7 +608,7 @@ void CGameContext::OnTick()
if(Error)
{
dbg_msg("teehistorian", "error writing to file, err=%d", Error);
exit(1);
Server()->SetErrorShutdown("teehistorian io error");
}
if(!m_TeeHistorian.Starting())
@ -2454,6 +2454,7 @@ void CGameContext::OnConsoleInit()
{
m_pServer = Kernel()->RequestInterface<IServer>();
m_pConsole = Kernel()->RequestInterface<IConsole>();
m_pStorage = Kernel()->RequestInterface<IStorage>();
m_ChatPrintCBIndex = Console()->RegisterPrintCallback(0, SendChatResponse, this);
@ -2494,6 +2495,7 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
{
m_pServer = Kernel()->RequestInterface<IServer>();
m_pConsole = Kernel()->RequestInterface<IConsole>();
m_pStorage = Kernel()->RequestInterface<IStorage>();
m_World.SetGameServer(this);
m_Events.SetGameServer(this);
@ -2576,11 +2578,12 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
char aFilename[64];
str_format(aFilename, sizeof(aFilename), "teehistorian/%s.teehistorian", aGameUuid);
IOHANDLE File = Kernel()->RequestInterface<IStorage>()->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
IOHANDLE File = Storage()->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
if(!File)
{
dbg_msg("teehistorian", "failed to open '%s'", aFilename);
exit(1);
Server()->SetErrorShutdown("teehistorian open error");
return;
}
else
{
@ -2770,22 +2773,19 @@ void CGameContext::DeleteTempfile()
{
if(m_aDeleteTempfile[0] != 0)
{
IStorage *pStorage = Kernel()->RequestInterface<IStorage>();
pStorage->RemoveFile(m_aDeleteTempfile, IStorage::TYPE_SAVE);
Storage()->RemoveFile(m_aDeleteTempfile, IStorage::TYPE_SAVE);
m_aDeleteTempfile[0] = 0;
}
}
void CGameContext::OnMapChange(char *pNewMapName, int MapNameSize)
{
IStorage *pStorage = Kernel()->RequestInterface<IStorage>();
char aConfig[128];
char aTemp[128];
str_format(aConfig, sizeof(aConfig), "maps/%s.cfg", g_Config.m_SvMap);
str_format(aTemp, sizeof(aTemp), "%s.temp.%d", pNewMapName, pid());
IOHANDLE File = pStorage->OpenFile(aConfig, IOFLAG_READ, IStorage::TYPE_ALL);
IOHANDLE File = Storage()->OpenFile(aConfig, IOFLAG_READ, IStorage::TYPE_ALL);
if(!File)
{
// No map-specific config, just return.
@ -2818,7 +2818,7 @@ void CGameContext::OnMapChange(char *pNewMapName, int MapNameSize)
}
CDataFileReader Reader;
Reader.Open(pStorage, pNewMapName, IStorage::TYPE_ALL);
Reader.Open(Storage(), pNewMapName, IStorage::TYPE_ALL);
CDataFileWriter Writer;
Writer.Init();
@ -2896,7 +2896,7 @@ void CGameContext::OnMapChange(char *pNewMapName, int MapNameSize)
dbg_msg("mapchange", "imported settings");
Reader.Close();
Writer.OpenFile(pStorage, aTemp);
Writer.OpenFile(Storage(), aTemp);
Writer.Finish();
str_copy(pNewMapName, aTemp, MapNameSize);
@ -2917,7 +2917,7 @@ void CGameContext::OnShutdown(bool FullShutdown)
if(Error)
{
dbg_msg("teehistorian", "error closing file, err=%d", Error);
exit(1);
Server()->SetErrorShutdown("teehistorian close error");
}
async_free(m_pTeeHistorianFile);
}

View file

@ -52,10 +52,13 @@ enum
NUM_TUNEZONES = 256
};
class IStorage;
class CGameContext : public IGameServer
{
IServer *m_pServer;
class IConsole *m_pConsole;
IStorage *m_pStorage;
CLayers m_Layers;
CCollision m_Collision;
CNetObjHandler m_NetObjHandler;
@ -107,6 +110,7 @@ class CGameContext : public IGameServer
public:
IServer *Server() const { return m_pServer; }
class IConsole *Console() { return m_pConsole; }
IStorage *Storage() { return m_pStorage; }
CCollision *Collision() { return &m_Collision; }
CTuningParams *Tuning() { return &m_Tuning; }
CTuningParams *TuningList() { return &m_aTuningList[0]; }