From bcc1450ba930d991e9569d05810aa4aada68869d Mon Sep 17 00:00:00 2001 From: faketruth Date: Wed, 26 Oct 2011 13:07:39 +0000 Subject: Fixed bug in cMakeDir where it would only create directories named "world" The user input thread now properly stops when the server restarts or stops git-svn-id: http://mc-server.googlecode.com/svn/trunk@13 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cMakeDir.cpp | 4 ++-- source/cRoot.cpp | 42 +++++++++++------------------------------- source/cRoot.h | 4 +++- 3 files changed, 16 insertions(+), 34 deletions(-) diff --git a/source/cMakeDir.cpp b/source/cMakeDir.cpp index a4d62afdd..60817d5aa 100644 --- a/source/cMakeDir.cpp +++ b/source/cMakeDir.cpp @@ -17,8 +17,8 @@ void cMakeDir::MakeDir( const char* a_Directory ) Attrib.nLength = sizeof(SECURITY_ATTRIBUTES); Attrib.lpSecurityDescriptor = NULL; Attrib.bInheritHandle = false; - ::CreateDirectory("world", &Attrib); + ::CreateDirectory(a_Directory, &Attrib); #else - mkdir("world", S_IRWXU | S_IRWXG | S_IRWXO); + mkdir(a_Directory, S_IRWXU | S_IRWXG | S_IRWXO); #endif } \ No newline at end of file diff --git a/source/cRoot.cpp b/source/cRoot.cpp index 7f0012764..531d0c9f3 100644 --- a/source/cRoot.cpp +++ b/source/cRoot.cpp @@ -9,6 +9,7 @@ #include "cPluginManager.h" #include "cMonsterConfig.h" #include "cSleep.h" +#include "cThread.h" #include "../iniFile/iniFile.h" @@ -34,7 +35,7 @@ cRoot::cRoot() , m_Log( 0 ) , m_bStop( false ) , m_bRestart( false ) - , m_hInputThread( 0 ) + , m_InputThread( 0 ) { s_Root = this; } @@ -44,21 +45,16 @@ cRoot::~cRoot() s_Root = 0; } -#ifdef _WIN32 -DWORD WINAPI cRoot_InputThread(LPVOID lpParam) -#else -void *cRoot_InputThread( void *lpParam ) -#endif +void cRoot::InputThread(void* a_Params) { - cRoot* Root = (cRoot*)lpParam; + cRoot& self = *(cRoot*)a_Params; - while( 1 ) + while( !(self.m_bStop || self.m_bRestart) ) { std::string Command; std::getline(std::cin, Command); - Root->ServerCommand( Command.c_str() ); + self.ServerCommand( Command.c_str() ); } - return 0; } void cRoot::Start() @@ -66,19 +62,6 @@ void cRoot::Start() if( m_Log ) delete m_Log, m_Log = 0; m_Log = new cMCLogger(); -#ifdef _WIN32 - m_hInputThread = CreateThread( - NULL, // default security - 0, // default stack size - cRoot_InputThread, // name of the thread function - this, // thread parameters - 0, // default startup flags - NULL); -#else - m_hInputThread = new pthread_t; - pthread_create( (pthread_t*)m_hInputThread, NULL, cRoot_InputThread, this ); -#endif - m_bStop = false; while(!m_bStop) { @@ -118,11 +101,16 @@ void cRoot::Start() m_Server->StartListenThread(); //cHeartBeat* HeartBeat = new cHeartBeat(); + m_InputThread = new cThread( InputThread, this ); + m_InputThread->Start( true ); + while( !m_bStop && !m_bRestart ) // These are modified by external threads { cSleep::MilliSleep( 1000 ); } + delete m_InputThread; m_InputThread = 0; + // Deallocate stuffs m_Server->Shutdown(); // This waits for threads to stop and d/c clients delete m_PluginManager; m_PluginManager = 0; // This should be first @@ -136,14 +124,6 @@ void cRoot::Start() delete m_Server; m_Server = 0; } - // No other way to get it to exit -#ifdef _WIN32 - TerminateThread( m_hInputThread, 0 ); -#else - // TODO: pthread_kill - delete (pthread_t*)m_hInputThread; -#endif - delete m_Log; m_Log = 0; } diff --git a/source/cRoot.h b/source/cRoot.h index 0ba59ae93..95f2e236e 100644 --- a/source/cRoot.h +++ b/source/cRoot.h @@ -1,5 +1,6 @@ #pragma once +class cThread; class cMonsterConfig; class cMCLogger; class cGroupManager; @@ -46,7 +47,8 @@ private: bool m_bStop; bool m_bRestart; - void* m_hInputThread; + cThread* m_InputThread; + static void InputThread(void* a_Params); static cRoot* s_Root; }; //tolua_export \ No newline at end of file -- cgit v1.2.3