summaryrefslogtreecommitdiffstats
path: root/src/Root.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2013-12-26 08:57:02 +0100
committerMattes D <github@xoft.cz>2013-12-26 08:57:02 +0100
commite0e01d0615fdeeb32a87dc74ca882e92a450ceb7 (patch)
tree22ef418f2fd3ff628fc010f52a5fe8e945519701 /src/Root.cpp
parentMerge pull request #471 from mc-server/Fishing_Catapult (diff)
parentMoved increment operator to back of variables (diff)
downloadcuberite-e0e01d0615fdeeb32a87dc74ca882e92a450ceb7.tar
cuberite-e0e01d0615fdeeb32a87dc74ca882e92a450ceb7.tar.gz
cuberite-e0e01d0615fdeeb32a87dc74ca882e92a450ceb7.tar.bz2
cuberite-e0e01d0615fdeeb32a87dc74ca882e92a450ceb7.tar.lz
cuberite-e0e01d0615fdeeb32a87dc74ca882e92a450ceb7.tar.xz
cuberite-e0e01d0615fdeeb32a87dc74ca882e92a450ceb7.tar.zst
cuberite-e0e01d0615fdeeb32a87dc74ca882e92a450ceb7.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;
}