From 25e4f15488c1f56c1571f4aefd216830e62ad52b Mon Sep 17 00:00:00 2001 From: sweetgiorni Date: Tue, 3 Jan 2017 10:57:31 -0800 Subject: 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 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/Root.cpp') 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(); -- cgit v1.2.3 From 78b6d54bf86c892827fa0a470375ba50318a0bd0 Mon Sep 17 00:00:00 2001 From: sweetgiorni Date: Tue, 3 Jan 2017 12:18:53 -0800 Subject: Api Documentation Added API documentation for GetShutdownMessage. Style fix in Root.cpp --- src/Root.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index 90e5cb9db..a5567dc9b 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -343,7 +343,7 @@ void cRoot::StopServer() } public: cPlayerCallback(AString a_ShutdownMessage) : m_ShutdownMessage(a_ShutdownMessage) {} - }PlayerCallback((m_Server->GetShutdownMessage())); + } PlayerCallback((m_Server->GetShutdownMessage())); cRoot::Get()->ForEachPlayer(PlayerCallback); // What's a better way to do this? -- cgit v1.2.3 From 0718d82e1a5a6fdfe9346f801fa008f2b37cf69d Mon Sep 17 00:00:00 2001 From: sweetgiorni Date: Tue, 3 Jan 2017 12:26:58 -0800 Subject: Player check Checks if there are any players connected to the server before running PlayerCallback and waiting 1 second. --- src/Root.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index a5567dc9b..80366e5c1 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -343,11 +343,14 @@ void cRoot::StopServer() } 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)); + if (m_Server->GetNumPlayers()) + { + cPlayerCallback PlayerCallback((m_Server->GetShutdownMessage())); + cRoot::Get()->ForEachPlayer(PlayerCallback); + std::this_thread::sleep_for(std::chrono::seconds(1)); + } m_TerminateEventRaised = true; m_StopEvent.Set(); m_InputThreadRunFlag.clear(); -- cgit v1.2.3 From 6522385897788df4682a1744b17815c0767c46f8 Mon Sep 17 00:00:00 2001 From: sweetgiorni Date: Tue, 3 Jan 2017 12:39:39 -0800 Subject: Disconnect sent flag added Truthiness no longer assumed --- src/Root.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index 80366e5c1..8390cac7b 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -339,16 +339,17 @@ void cRoot::StopServer() virtual bool Item(cPlayer * a_Player) { a_Player->GetClientHandlePtr()->Kick(m_ShutdownMessage); + m_HasSentDisconnect = true; return false; } public: - cPlayerCallback(AString a_ShutdownMessage) : m_ShutdownMessage(a_ShutdownMessage) {} - }; + bool m_HasSentDisconnect; + cPlayerCallback(AString a_ShutdownMessage) : m_ShutdownMessage(a_ShutdownMessage) { m_HasSentDisconnect = false; } + } PlayerCallback(m_Server->GetShutdownMessage()); - if (m_Server->GetNumPlayers()) + cRoot::Get()->ForEachPlayer(PlayerCallback); + if (PlayerCallback.m_HasSentDisconnect) { - cPlayerCallback PlayerCallback((m_Server->GetShutdownMessage())); - cRoot::Get()->ForEachPlayer(PlayerCallback); std::this_thread::sleep_for(std::chrono::seconds(1)); } m_TerminateEventRaised = true; -- cgit v1.2.3