summaryrefslogtreecommitdiffstats
path: root/src/Root.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2013-12-22 21:03:58 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2013-12-22 21:03:58 +0100
commit43e819630910e80f4420f15baad3d5322b54b0b3 (patch)
treec238ebc708831b1b1c8950e15c587cc42bd486fb /src/Root.cpp
parentImplemented fall particles (diff)
downloadcuberite-43e819630910e80f4420f15baad3d5322b54b0b3.tar
cuberite-43e819630910e80f4420f15baad3d5322b54b0b3.tar.gz
cuberite-43e819630910e80f4420f15baad3d5322b54b0b3.tar.bz2
cuberite-43e819630910e80f4420f15baad3d5322b54b0b3.tar.lz
cuberite-43e819630910e80f4420f15baad3d5322b54b0b3.tar.xz
cuberite-43e819630910e80f4420f15baad3d5322b54b0b3.tar.zst
cuberite-43e819630910e80f4420f15baad3d5322b54b0b3.zip
Diffstat (limited to '')
-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;
}