mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
fifoconsole cleanup
This commit is contained in:
parent
1cf476c1f6
commit
9f4ac93d90
|
@ -68,8 +68,6 @@
|
|||
#undef main
|
||||
#endif
|
||||
|
||||
bool IsClient = true;
|
||||
|
||||
void CGraph::Init(float Min, float Max)
|
||||
{
|
||||
m_Min = Min;
|
||||
|
@ -3129,7 +3127,7 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
pClient->Engine()->InitLogfile();
|
||||
|
||||
#if defined(CONF_FAMILY_UNIX)
|
||||
FifoConsole *fifoConsole = new FifoConsole(pConsole);
|
||||
FifoConsole *fifoConsole = new FifoConsole(pConsole, g_Config.m_ClInputFifo, CFGFLAG_CLIENT);
|
||||
#endif
|
||||
|
||||
// run the client
|
||||
|
|
|
@ -42,8 +42,6 @@
|
|||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
bool IsClient = false;
|
||||
|
||||
static const char *StrLtrim(const char *pStr)
|
||||
{
|
||||
while(*pStr)
|
||||
|
@ -2032,7 +2030,7 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
pEngine->InitLogfile();
|
||||
|
||||
#if defined(CONF_FAMILY_UNIX)
|
||||
FifoConsole *fifoConsole = new FifoConsole(pConsole);
|
||||
FifoConsole *fifoConsole = new FifoConsole(pConsole, g_Config.m_SvInputFifo, CFGFLAG_SERVER);
|
||||
#endif
|
||||
|
||||
// run the server
|
||||
|
|
|
@ -10,31 +10,26 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
extern bool IsClient;
|
||||
|
||||
FifoConsole::FifoConsole(IConsole *pConsole)
|
||||
FifoConsole::FifoConsole(IConsole *pConsole, char *pFifoFile, int flag)
|
||||
{
|
||||
void *m_pFifoThread = thread_create(ListenFifoThread, pConsole);
|
||||
void *m_pFifoThread = thread_create(ListenFifoThread, this);
|
||||
m_pConsole = pConsole;
|
||||
m_pFifoFile = pFifoFile;
|
||||
m_flag = flag;
|
||||
pthread_detach((pthread_t)m_pFifoThread);
|
||||
}
|
||||
|
||||
void FifoConsole::ListenFifoThread(void *pUser)
|
||||
{
|
||||
IConsole *pConsole = (IConsole *)pUser;
|
||||
FifoConsole *pData = (FifoConsole *)pUser;
|
||||
|
||||
char *fifofile;
|
||||
if (IsClient)
|
||||
fifofile = g_Config.m_ClInputFifo;
|
||||
else
|
||||
fifofile = g_Config.m_SvInputFifo;
|
||||
|
||||
if (str_comp(fifofile, "") == 0)
|
||||
if (str_comp(pData->m_pFifoFile, "") == 0)
|
||||
return;
|
||||
|
||||
mkfifo(fifofile, 0600);
|
||||
mkfifo(pData->m_pFifoFile, 0600);
|
||||
|
||||
struct stat attribute;
|
||||
stat(fifofile, &attribute);
|
||||
stat(pData->m_pFifoFile, &attribute);
|
||||
|
||||
if(!S_ISFIFO(attribute.st_mode))
|
||||
return;
|
||||
|
@ -44,14 +39,9 @@ void FifoConsole::ListenFifoThread(void *pUser)
|
|||
|
||||
while (true)
|
||||
{
|
||||
f.open(fifofile);
|
||||
f.open(pData->m_pFifoFile);
|
||||
while (f.getline(aBuf, sizeof(aBuf)))
|
||||
{
|
||||
if (IsClient)
|
||||
pConsole->ExecuteLineFlag(aBuf, CFGFLAG_CLIENT, -1);
|
||||
else
|
||||
pConsole->ExecuteLineFlag(aBuf, CFGFLAG_SERVER, -1);
|
||||
}
|
||||
pData->m_pConsole->ExecuteLineFlag(aBuf, pData->m_flag, -1);
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,13 @@
|
|||
class FifoConsole
|
||||
{
|
||||
static void ListenFifoThread(void *pUser);
|
||||
IConsole *m_pConsole;
|
||||
void *m_pFifoThread;
|
||||
char *m_pFifoFile;
|
||||
int m_flag;
|
||||
|
||||
public:
|
||||
FifoConsole(IConsole *pConsole);
|
||||
FifoConsole(IConsole *pConsole, char *pFifoFile, int flag);
|
||||
};
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in a new issue