Skip to content

Commit

Permalink
Add cl_shutdown_srv to shutdown server after 40s
Browse files Browse the repository at this point in the history
Can be used for automatic testing to see if the server survives 40s without crash
cl_shutdown_srv takes the rcon password of the server
  • Loading branch information
ChillerDragon committed Sep 15, 2019
1 parent 5b94be4 commit 6e8b7d8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/game/client/gameclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ void CGameClient::OnInit()
}
}

// chillerbot-ng

m_RequestCmdlist = 0;
m_EnterGameTime = 0;

int64 End = time_get();
str_format(aBuf, sizeof(aBuf), "initialisation finished after %.2fms", ((End-Start)*1000)/(float)time_freq());
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "gameclient", aBuf);
Expand Down Expand Up @@ -854,11 +859,34 @@ void CGameClient::ConsoleKeyInput()
}
}

void CGameClient::OnRender()
void CGameClient::ChillerBotTick()
{
// chillerbot-ng
ConsoleKeyInput();
PenetrateServer();
if (g_Config.m_ClShutdownSrv[0] && m_EnterGameTime)
{
if (!Client()->RconAuthed() && (time_get() - m_EnterGameTime) / time_freq() > 10) // wait 10 sec to authenticate
{
Client()->RconAuth(g_Config.m_ClShutdownSrv, g_Config.m_ClShutdownSrv);
dbg_msg("shutdown", "authed in rcon with password='%s'", g_Config.m_ClShutdownSrv);
}
if ((time_get() - m_EnterGameTime) / time_freq() > 40) // wait 40 sec to shutdown server
{
Client()->Rcon("shutdown");
g_Config.m_ClShutdownSrv[0] = '\0';
dbg_msg("shutdown", "executed shutdown server");
}
/*
if (time_get() % time_freq() == 0)
dbg_msg("shutdown", "on server since %lld seconds.", (time_get() - m_EnterGameTime) / time_freq());
*/
}
}

void CGameClient::OnRender()
{
// chillerbot-ng
ChillerBotTick();

// update the local character and spectate position
UpdatePositions();
Expand Down Expand Up @@ -1126,6 +1154,7 @@ void CGameClient::OnEnterGame()
{
g_GameClient.m_pEffects->ResetDamageIndicator();
m_RequestCmdlist = -(time_get() + time_freq() * 5); // wait a few seconds before requesting it
m_EnterGameTime = time_get();
}

void CGameClient::OnGameOver()
Expand Down
2 changes: 2 additions & 0 deletions src/game/client/gameclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,12 @@ class CGameClient : public IGameClient
void ChillerCommands(const char *pCmd);
void ShowServerList();
void PenetrateServer();
void ChillerBotTick();
const char *GetPentestCommand(const char *pFileName);
const char *GetRandomChatCommand();
int m_PenDelay;
int m_InputMode;
int64 m_EnterGameTime;

enum {
INPUT_CHAT,
Expand Down
1 change: 1 addition & 0 deletions src/game/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ MACRO_CONFIG_INT(ClChillerRender, cl_chiller_render, 0, 0, 1, CFGFLAG_CLIENT, "r
MACRO_CONFIG_INT(ClChillerInput, cl_chiller_inp, 1, 0, 1, CFGFLAG_CLIENT, "user keyboard input like chat and keypresses (set to 0 if the client seems broken)")
MACRO_CONFIG_INT(ClPenTest, cl_pentest, 0, 0, 1, CFGFLAG_CLIENT, "penetrate servers to test stability")
MACRO_CONFIG_STR(ClPenTestFile, cl_pentest_file, 128, "pentest.txt", CFGFLAG_CLIENT, "chat messages file for pentestmode")
MACRO_CONFIG_STR(ClShutdownSrv, cl_shutdown_srv, 128, "", CFGFLAG_CLIENT, "provide password of rcon to shutdown server after x seconds")

// client
MACRO_CONFIG_INT(ClPredict, cl_predict, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Predict client movements")
Expand Down

0 comments on commit 6e8b7d8

Please sign in to comment.