Merge pull request #3518 from sweetgiorni/DisconnectMessage
Custom Disconnect Message
This commit is contained in:
commit
21ad5d7c4a
@ -13061,6 +13061,16 @@ end
|
|||||||
},
|
},
|
||||||
Notes = "Returns the server description set in the settings.ini.",
|
Notes = "Returns the server description set in the settings.ini.",
|
||||||
},
|
},
|
||||||
|
GetShutdownMessage =
|
||||||
|
{
|
||||||
|
Returns =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
Type = "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Notes = "Returns the shutdown message set in the settings.ini.",
|
||||||
|
},
|
||||||
GetMaxPlayers =
|
GetMaxPlayers =
|
||||||
{
|
{
|
||||||
Returns =
|
Returns =
|
||||||
|
20
src/Root.cpp
20
src/Root.cpp
@ -332,6 +332,26 @@ void cRoot::Start(std::unique_ptr<cSettingsRepositoryInterface> a_OverridesRepo)
|
|||||||
|
|
||||||
void cRoot::StopServer()
|
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_TerminateEventRaised = true;
|
||||||
m_StopEvent.Set();
|
m_StopEvent.Set();
|
||||||
m_InputThreadRunFlag.clear();
|
m_InputThreadRunFlag.clear();
|
||||||
|
@ -190,6 +190,7 @@ void cServer::PlayerDestroying(const cPlayer * a_Player)
|
|||||||
bool cServer::InitServer(cSettingsRepositoryInterface & a_Settings, bool a_ShouldAuth)
|
bool cServer::InitServer(cSettingsRepositoryInterface & a_Settings, bool a_ShouldAuth)
|
||||||
{
|
{
|
||||||
m_Description = a_Settings.GetValueSet("Server", "Description", "Cuberite - in C++!");
|
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_MaxPlayers = a_Settings.GetValueSetI("Server", "MaxPlayers", 100);
|
||||||
m_bIsHardcore = a_Settings.GetValueSetB("Server", "HardcoreEnabled", false);
|
m_bIsHardcore = a_Settings.GetValueSetB("Server", "HardcoreEnabled", false);
|
||||||
m_bAllowMultiLogin = a_Settings.GetValueSetB("Server", "AllowMultiLogin", false);
|
m_bAllowMultiLogin = a_Settings.GetValueSetB("Server", "AllowMultiLogin", false);
|
||||||
|
@ -64,6 +64,8 @@ public:
|
|||||||
|
|
||||||
const AString & GetDescription(void) const {return m_Description; }
|
const AString & GetDescription(void) const {return m_Description; }
|
||||||
|
|
||||||
|
const AString & GetShutdownMessage(void) const { return m_ShutdownMessage; }
|
||||||
|
|
||||||
// Player counts:
|
// Player counts:
|
||||||
int GetMaxPlayers(void) const { return m_MaxPlayers; }
|
int GetMaxPlayers(void) const { return m_MaxPlayers; }
|
||||||
int GetNumPlayers(void) const;
|
int GetNumPlayers(void) const;
|
||||||
@ -204,6 +206,7 @@ private:
|
|||||||
cRCONServer m_RCONServer;
|
cRCONServer m_RCONServer;
|
||||||
|
|
||||||
AString m_Description;
|
AString m_Description;
|
||||||
|
AString m_ShutdownMessage;
|
||||||
AString m_FaviconData;
|
AString m_FaviconData;
|
||||||
int m_MaxPlayers;
|
int m_MaxPlayers;
|
||||||
bool m_bIsHardcore;
|
bool m_bIsHardcore;
|
||||||
|
Loading…
Reference in New Issue
Block a user