Add Fifo console for easier automation

This commit is contained in:
def 2013-07-29 21:03:59 +02:00
parent 5e537f24c6
commit 5cd69f29ac
4 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,41 @@
#include "fifoconsole.h"
#include <engine/shared/config.h>
#include <fstream>
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
FifoConsole::FifoConsole(IConsole *pConsole)
{
void *fifoThread = thread_create(ListenFifoThread, pConsole);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)fifoThread);
#endif
}
void FifoConsole::ListenFifoThread(void *pUser)
{
IConsole *pConsole = (IConsole *)pUser;
if (str_comp(g_Config.m_SvInputFifo, "") == 0)
return;
if (mkfifo(g_Config.m_SvInputFifo, 0600))
return;
std::ifstream f;
char aBuf[256];
while (true)
{
f.open(g_Config.m_SvInputFifo);
while (f.getline(aBuf, 256))
{
pConsole->ExecuteLineFlag(aBuf, CFGFLAG_SERVER, -1);
}
f.close();
}
}

View file

@ -0,0 +1,14 @@
#ifndef ENGINE_FIFOCONSOLE_H
#define ENGINE_FIFOCONSOLE_H
#include <engine/console.h>
class FifoConsole
{
static void ListenFifoThread(void *pUser);
public:
FifoConsole(IConsole *pConsole);
};
#endif // FILE_ENGINE_FIFOCONSOLE_H

View file

@ -34,6 +34,7 @@
#include "register.h" #include "register.h"
#include "server.h" #include "server.h"
#include "fifoconsole.h"
#if defined(CONF_FAMILY_WINDOWS) #if defined(CONF_FAMILY_WINDOWS)
#define _WIN32_WINNT 0x0501 #define _WIN32_WINNT 0x0501
@ -1824,11 +1825,14 @@ int main(int argc, const char **argv) // ignore_convention
pEngine->InitLogfile(); pEngine->InitLogfile();
FifoConsole *fifoConsole = new FifoConsole(pConsole);
// run the server // run the server
dbg_msg("server", "starting..."); dbg_msg("server", "starting...");
pServer->Run(); pServer->Run();
// free // free
delete fifoConsole;
delete pServer; delete pServer;
delete pKernel; delete pKernel;
delete pEngineMap; delete pEngineMap;

View file

@ -204,6 +204,7 @@ MACRO_CONFIG_INT(SvVotePause, sv_vote_pause, 1, 0, 1, CFGFLAG_SERVER, "Allow vot
MACRO_CONFIG_INT(SvVotePauseTime, sv_vote_pause_time, 10, 0, 360, CFGFLAG_SERVER, "The time (in seconds) players have to wait in pause when paused by vote") MACRO_CONFIG_INT(SvVotePauseTime, sv_vote_pause_time, 10, 0, 360, CFGFLAG_SERVER, "The time (in seconds) players have to wait in pause when paused by vote")
MACRO_CONFIG_INT(SvTuneReset, sv_tune_reset, 0, 0, 1, CFGFLAG_SERVER, "Whether tuning is reset after each map change or not") MACRO_CONFIG_INT(SvTuneReset, sv_tune_reset, 0, 0, 1, CFGFLAG_SERVER, "Whether tuning is reset after each map change or not")
MACRO_CONFIG_STR(SvResetFile, sv_reset_file, 128, "reset.cfg", CFGFLAG_SERVER, "File to execute on map change or reload to set the default server settings") MACRO_CONFIG_STR(SvResetFile, sv_reset_file, 128, "reset.cfg", CFGFLAG_SERVER, "File to execute on map change or reload to set the default server settings")
MACRO_CONFIG_STR(SvInputFifo, sv_input_fifo, 128, "", CFGFLAG_SERVER, "Fifo file to use as input")
MACRO_CONFIG_INT(SvDDRaceTuneReset, sv_ddrace_tune_reset, 1, 0, 1, CFGFLAG_SERVER, "Whether DDRace tuning(sv_hit, Sv_Endless_Drag & Sv_Old_Laser) is reset after each map change or not") MACRO_CONFIG_INT(SvDDRaceTuneReset, sv_ddrace_tune_reset, 1, 0, 1, CFGFLAG_SERVER, "Whether DDRace tuning(sv_hit, Sv_Endless_Drag & Sv_Old_Laser) is reset after each map change or not")
MACRO_CONFIG_INT(SvNamelessScore, sv_nameless_score, 0, 0, 1, CFGFLAG_SERVER, "Whether nameless tee has a score or not") MACRO_CONFIG_INT(SvNamelessScore, sv_nameless_score, 0, 0, 1, CFGFLAG_SERVER, "Whether nameless tee has a score or not")
MACRO_CONFIG_INT(SvTimeInBroadcastInterval, sv_time_in_broadcast_interval, 1, 0, 60, CFGFLAG_SERVER, "How often to update the broadcast time") MACRO_CONFIG_INT(SvTimeInBroadcastInterval, sv_time_in_broadcast_interval, 1, 0, 60, CFGFLAG_SERVER, "How often to update the broadcast time")