From 25e4f15488c1f56c1571f4aefd216830e62ad52b Mon Sep 17 00:00:00 2001 From: sweetgiorni Date: Tue, 3 Jan 2017 10:57:31 -0800 Subject: [PATCH] Custom Disconnect Message Adds a m_ShutdownMessage option to the settings. When the stop command is issued, players are kicked with said message before the server shuts down. --- src/Root.cpp | 16 ++++++++++++++++ src/Server.cpp | 1 + src/Server.h | 3 +++ 3 files changed, 20 insertions(+) diff --git a/src/Root.cpp b/src/Root.cpp index 3d3930975..90e5cb9db 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -332,6 +332,22 @@ void cRoot::Start(std::unique_ptr a_OverridesRepo) void cRoot::StopServer() { + // Kick all players from the server with custom disconnect message + class cPlayerCallback : public cPlayerListCallback + { + AString m_ShutdownMessage; + virtual bool Item(cPlayer * a_Player) + { + a_Player->GetClientHandlePtr()->Kick(m_ShutdownMessage); + return false; + } + public: + cPlayerCallback(AString a_ShutdownMessage) : m_ShutdownMessage(a_ShutdownMessage) {} + }PlayerCallback((m_Server->GetShutdownMessage())); + + cRoot::Get()->ForEachPlayer(PlayerCallback); + // What's a better way to do this? + std::this_thread::sleep_for(std::chrono::seconds(1)); m_TerminateEventRaised = true; m_StopEvent.Set(); m_InputThreadRunFlag.clear(); diff --git a/src/Server.cpp b/src/Server.cpp index ba469bd3e..95e0b535b 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -190,6 +190,7 @@ void cServer::PlayerDestroying(const cPlayer * a_Player) bool cServer::InitServer(cSettingsRepositoryInterface & a_Settings, bool a_ShouldAuth) { m_Description = a_Settings.GetValueSet("Server", "Description", "Cuberite - in C++!"); + m_ShutdownMessage = a_Settings.GetValueSet("Server", "ShutdownMessage", "Server shutdown"); m_MaxPlayers = a_Settings.GetValueSetI("Server", "MaxPlayers", 100); m_bIsHardcore = a_Settings.GetValueSetB("Server", "HardcoreEnabled", false); m_bAllowMultiLogin = a_Settings.GetValueSetB("Server", "AllowMultiLogin", false); diff --git a/src/Server.h b/src/Server.h index 600e7ca97..74f9581ae 100644 --- a/src/Server.h +++ b/src/Server.h @@ -64,6 +64,8 @@ public: const AString & GetDescription(void) const {return m_Description; } + const AString & GetShutdownMessage(void) const { return m_ShutdownMessage; } + // Player counts: int GetMaxPlayers(void) const { return m_MaxPlayers; } int GetNumPlayers(void) const; @@ -204,6 +206,7 @@ private: cRCONServer m_RCONServer; AString m_Description; + AString m_ShutdownMessage; AString m_FaviconData; int m_MaxPlayers; bool m_bIsHardcore;