Kick players when shutting down server and there is a crash due to a Lua stack exception
authornerzhul <loic.blot@unix-experience.fr>
Thu, 16 Jul 2015 15:37:46 +0000 (17:37 +0200)
committerLoic Blot <loic.blot@unix-experience.fr>
Thu, 16 Jul 2015 18:27:42 +0000 (20:27 +0200)
src/environment.cpp
src/environment.h
src/server.cpp

index 5affda6fad71427d792b32b1751be051a70e570c..cad1f298bded3f0b92627b930154b52f17824aa2 100644 (file)
@@ -39,6 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "mapblock_mesh.h"
 #include "event.h"
 #endif
+#include "server.h"
 #include "daynightratio.h"
 #include "map.h"
 #include "emerge.h"
@@ -425,6 +426,15 @@ bool ServerEnvironment::line_of_sight(v3f pos1, v3f pos2, float stepsize, v3s16
        return true;
 }
 
+void ServerEnvironment::kickAllPlayers(const std::string &reason)
+{
+       for (std::vector<Player*>::iterator it = m_players.begin();
+                       it != m_players.end();
+                       ++it) {
+               ((Server*)m_gamedef)->DenyAccess_Legacy((*it)->peer_id, utf8_to_wide(reason));
+       }
+}
+
 void ServerEnvironment::saveLoadedPlayers()
 {
        std::string players_path = m_path_world + DIR_DELIM "players";
index b35ca42496b175bd4eea290b42faac9d2faddc68..794f1971c8bd94126a4d562f1f0ba7b4565668d1 100644 (file)
@@ -221,6 +221,7 @@ public:
        float getSendRecommendedInterval()
                { return m_recommended_send_interval; }
 
+       void kickAllPlayers(const std::string &reason);
        // Save players
        void saveLoadedPlayers();
        void savePlayer(const std::string &playername);
index 9d70ad7b76477c9ac813fc4347e30aab9c18e7b7..0cad82613307dfa2f2d464a8d51573d2a644cddf 100644 (file)
@@ -394,10 +394,13 @@ Server::~Server()
                // Execute script shutdown hooks
                m_script->on_shutdown();
 
-               infostream<<"Server: Saving players"<<std::endl;
+               infostream << "Server: Saving players" << std::endl;
                m_env->saveLoadedPlayers();
 
-               infostream<<"Server: Saving environment metadata"<<std::endl;
+               infostream << "Server: kick players" << std::endl;
+               m_env->kickAllPlayers("Server shutting down...");
+
+               infostream << "Server: Saving environment metadata" << std::endl;
                m_env->saveMeta();
        }
 
@@ -499,6 +502,7 @@ void Server::step(float dtime)
                        throw ServerError(async_err);
                }
                else {
+                       m_env->kickAllPlayers("The server has crashed. Disconnecting all players. Please reconnect soon...");
                        errorstream << "UNRECOVERABLE error occurred. Stopping server. "
                                        << "Please fix the following error:" << std::endl
                                        << async_err << std::endl;