1
0

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
This commit is contained in:
faketruth 2011-10-26 13:07:39 +00:00
parent 459554201b
commit bcc1450ba9
3 changed files with 16 additions and 34 deletions

View File

@ -17,8 +17,8 @@ void cMakeDir::MakeDir( const char* a_Directory )
Attrib.nLength = sizeof(SECURITY_ATTRIBUTES); Attrib.nLength = sizeof(SECURITY_ATTRIBUTES);
Attrib.lpSecurityDescriptor = NULL; Attrib.lpSecurityDescriptor = NULL;
Attrib.bInheritHandle = false; Attrib.bInheritHandle = false;
::CreateDirectory("world", &Attrib); ::CreateDirectory(a_Directory, &Attrib);
#else #else
mkdir("world", S_IRWXU | S_IRWXG | S_IRWXO); mkdir(a_Directory, S_IRWXU | S_IRWXG | S_IRWXO);
#endif #endif
} }

View File

@ -9,6 +9,7 @@
#include "cPluginManager.h" #include "cPluginManager.h"
#include "cMonsterConfig.h" #include "cMonsterConfig.h"
#include "cSleep.h" #include "cSleep.h"
#include "cThread.h"
#include "../iniFile/iniFile.h" #include "../iniFile/iniFile.h"
@ -34,7 +35,7 @@ cRoot::cRoot()
, m_Log( 0 ) , m_Log( 0 )
, m_bStop( false ) , m_bStop( false )
, m_bRestart( false ) , m_bRestart( false )
, m_hInputThread( 0 ) , m_InputThread( 0 )
{ {
s_Root = this; s_Root = this;
} }
@ -44,21 +45,16 @@ cRoot::~cRoot()
s_Root = 0; s_Root = 0;
} }
#ifdef _WIN32 void cRoot::InputThread(void* a_Params)
DWORD WINAPI cRoot_InputThread(LPVOID lpParam)
#else
void *cRoot_InputThread( void *lpParam )
#endif
{ {
cRoot* Root = (cRoot*)lpParam; cRoot& self = *(cRoot*)a_Params;
while( 1 ) while( !(self.m_bStop || self.m_bRestart) )
{ {
std::string Command; std::string Command;
std::getline(std::cin, Command); std::getline(std::cin, Command);
Root->ServerCommand( Command.c_str() ); self.ServerCommand( Command.c_str() );
} }
return 0;
} }
void cRoot::Start() void cRoot::Start()
@ -66,19 +62,6 @@ void cRoot::Start()
if( m_Log ) delete m_Log, m_Log = 0; if( m_Log ) delete m_Log, m_Log = 0;
m_Log = new cMCLogger(); 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; m_bStop = false;
while(!m_bStop) while(!m_bStop)
{ {
@ -118,11 +101,16 @@ void cRoot::Start()
m_Server->StartListenThread(); m_Server->StartListenThread();
//cHeartBeat* HeartBeat = new cHeartBeat(); //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 while( !m_bStop && !m_bRestart ) // These are modified by external threads
{ {
cSleep::MilliSleep( 1000 ); cSleep::MilliSleep( 1000 );
} }
delete m_InputThread; m_InputThread = 0;
// Deallocate stuffs // Deallocate stuffs
m_Server->Shutdown(); // This waits for threads to stop and d/c clients m_Server->Shutdown(); // This waits for threads to stop and d/c clients
delete m_PluginManager; m_PluginManager = 0; // This should be first delete m_PluginManager; m_PluginManager = 0; // This should be first
@ -136,14 +124,6 @@ void cRoot::Start()
delete m_Server; m_Server = 0; 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; delete m_Log; m_Log = 0;
} }

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
class cThread;
class cMonsterConfig; class cMonsterConfig;
class cMCLogger; class cMCLogger;
class cGroupManager; class cGroupManager;
@ -46,7 +47,8 @@ private:
bool m_bStop; bool m_bStop;
bool m_bRestart; bool m_bRestart;
void* m_hInputThread; cThread* m_InputThread;
static void InputThread(void* a_Params);
static cRoot* s_Root; static cRoot* s_Root;
}; //tolua_export }; //tolua_export