diff options
author | Julian Laubstein <julianlaubstein@yahoo.de> | 2017-01-04 01:08:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-04 01:08:50 +0100 |
commit | 21ad5d7c4a452938346c7a286f6b1e00a6fe87cb (patch) | |
tree | 352aa5c7246b92cd61c70fd20fad9e36fd06faf7 /src/Root.cpp | |
parent | TCPLink: call networking callbacks with LibEvent unlocked. (#3515) (diff) | |
parent | Merge branch 'master' into DisconnectMessage (diff) | |
download | cuberite-21ad5d7c4a452938346c7a286f6b1e00a6fe87cb.tar cuberite-21ad5d7c4a452938346c7a286f6b1e00a6fe87cb.tar.gz cuberite-21ad5d7c4a452938346c7a286f6b1e00a6fe87cb.tar.bz2 cuberite-21ad5d7c4a452938346c7a286f6b1e00a6fe87cb.tar.lz cuberite-21ad5d7c4a452938346c7a286f6b1e00a6fe87cb.tar.xz cuberite-21ad5d7c4a452938346c7a286f6b1e00a6fe87cb.tar.zst cuberite-21ad5d7c4a452938346c7a286f6b1e00a6fe87cb.zip |
Diffstat (limited to 'src/Root.cpp')
-rw-r--r-- | src/Root.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Root.cpp b/src/Root.cpp index 3d3930975..8390cac7b 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -332,6 +332,26 @@ void cRoot::Start(std::unique_ptr<cSettingsRepositoryInterface> 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); + m_HasSentDisconnect = true; + return false; + } + public: + bool m_HasSentDisconnect; + cPlayerCallback(AString a_ShutdownMessage) : m_ShutdownMessage(a_ShutdownMessage) { m_HasSentDisconnect = false; } + } PlayerCallback(m_Server->GetShutdownMessage()); + + cRoot::Get()->ForEachPlayer(PlayerCallback); + if (PlayerCallback.m_HasSentDisconnect) + { + std::this_thread::sleep_for(std::chrono::seconds(1)); + } m_TerminateEventRaised = true; m_StopEvent.Set(); m_InputThreadRunFlag.clear(); |