ddnet/src/engine/server/fifoconsole.cpp

47 lines
848 B
C++
Raw Normal View History

2013-07-29 19:03:59 +00:00
#include "fifoconsole.h"
#include <engine/shared/config.h>
#include <fstream>
2013-08-06 04:45:13 +00:00
#if defined(CONF_FAMILY_UNIX)
2013-07-29 19:03:59 +00:00
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
FifoConsole::FifoConsole(IConsole *pConsole)
{
2013-08-03 15:22:50 +00:00
void *m_pFifoThread = thread_create(ListenFifoThread, pConsole);
pthread_detach((pthread_t)m_pFifoThread);
2013-07-29 19:03:59 +00:00
}
void FifoConsole::ListenFifoThread(void *pUser)
{
IConsole *pConsole = (IConsole *)pUser;
if (str_comp(g_Config.m_SvInputFifo, "") == 0)
return;
2013-07-30 01:16:02 +00:00
mkfifo(g_Config.m_SvInputFifo, 0600);
2013-07-29 19:03:59 +00:00
struct stat attribute;
stat(g_Config.m_SvInputFifo, &attribute);
if(!S_ISFIFO(attribute.st_mode))
return;
2013-07-29 19:03:59 +00:00
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();
}
}
2013-08-06 04:44:53 +00:00
#endif