summaryrefslogtreecommitdiffstats
path: root/src/Root.cpp
diff options
context:
space:
mode:
authorTycho Bickerstaff <work.tycho@gmail.com>2013-12-22 16:21:34 +0100
committerTycho Bickerstaff <work.tycho@gmail.com>2013-12-22 16:21:34 +0100
commit1a9d93665f9f82ccd9054aa1c8e9c24f13776a91 (patch)
treee9572b3fdf1d47c0769a3d43d3fc4dfac68fd0dd /src/Root.cpp
parentbasic threadsafe queue interface (diff)
parentUpdate GETTING-STARTED.md (diff)
downloadcuberite-1a9d93665f9f82ccd9054aa1c8e9c24f13776a91.tar
cuberite-1a9d93665f9f82ccd9054aa1c8e9c24f13776a91.tar.gz
cuberite-1a9d93665f9f82ccd9054aa1c8e9c24f13776a91.tar.bz2
cuberite-1a9d93665f9f82ccd9054aa1c8e9c24f13776a91.tar.lz
cuberite-1a9d93665f9f82ccd9054aa1c8e9c24f13776a91.tar.xz
cuberite-1a9d93665f9f82ccd9054aa1c8e9c24f13776a91.tar.zst
cuberite-1a9d93665f9f82ccd9054aa1c8e9c24f13776a91.zip
Diffstat (limited to 'src/Root.cpp')
-rw-r--r--src/Root.cpp34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/Root.cpp b/src/Root.cpp
index fffd8fb47..798f965be 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -22,6 +22,7 @@
#include "inifile/iniFile.h"
#ifdef _WIN32
+ #include "conio.h"
#include <psapi.h>
#elif defined(__linux__)
#include <fstream>
@@ -29,6 +30,8 @@
#include <mach/mach.h>
#endif
+extern bool g_TERMINATE_EVENT_RAISED;
+
@@ -76,7 +79,7 @@ void cRoot::InputThread(void * a_Params)
cLogCommandOutputCallback Output;
- while (!(self.m_bStop || self.m_bRestart) && std::cin.good())
+ while (!self.m_bStop && !self.m_bRestart && !g_TERMINATE_EVENT_RAISED && std::cin.good())
{
AString Command;
std::getline(std::cin, Command);
@@ -85,10 +88,10 @@ void cRoot::InputThread(void * a_Params)
self.ExecuteConsoleCommand(TrimString(Command), Output);
}
}
-
- if (!(self.m_bStop || self.m_bRestart))
+
+ if (g_TERMINATE_EVENT_RAISED || !std::cin.good())
{
- // We have come here because the std::cin has received an EOF and the server is still running; stop the server:
+ // We have come here because the std::cin has received an EOF / a terminate signal has been sent, and the server is still running; stop the server:
self.m_bStop = true;
}
}
@@ -99,6 +102,12 @@ void cRoot::InputThread(void * a_Params)
void cRoot::Start(void)
{
+ #ifdef _WIN32
+ HWND hwnd = GetConsoleWindow();
+ HMENU hmenu = GetSystemMenu(hwnd, FALSE);
+ EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED); // Disable close button when starting up; it causes problems with our CTRL-CLOSE handling
+ #endif
+
cDeadlockDetect dd;
delete m_Log;
m_Log = new cMCLogger();
@@ -192,12 +201,20 @@ void cRoot::Start(void)
finishmseconds -= mseconds;
LOG("Startup complete, took %i ms!", finishmseconds);
+ #ifdef _WIN32
+ EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); // Re-enable close button
+ #endif
- while (!m_bStop && !m_bRestart) // These are modified by external threads
+ while (!m_bStop && !m_bRestart && !g_TERMINATE_EVENT_RAISED) // These are modified by external threads
{
cSleep::MilliSleep(1000);
}
+ if (g_TERMINATE_EVENT_RAISED)
+ {
+ m_bStop = true;
+ }
+
#if !defined(ANDROID_NDK)
delete m_InputThread; m_InputThread = NULL;
#endif
@@ -222,7 +239,7 @@ void cRoot::Start(void)
delete m_FurnaceRecipe; m_FurnaceRecipe = NULL;
delete m_CraftingRecipes; m_CraftingRecipes = NULL;
LOGD("Forgetting groups...");
- delete m_GroupManager; m_GroupManager = 0;
+ delete m_GroupManager; m_GroupManager = NULL;
LOGD("Unloading worlds...");
UnloadWorlds();
@@ -233,12 +250,11 @@ void cRoot::Start(void)
cBlockHandler::Deinit();
LOG("Cleaning up...");
- //delete HeartBeat; HeartBeat = 0;
- delete m_Server; m_Server = 0;
+ delete m_Server; m_Server = NULL;
LOG("Shutdown successful!");
}
- delete m_Log; m_Log = 0;
+ delete m_Log; m_Log = NULL;
}