Server list cleanup
authorShadowNinja <shadowninja@minetest.net>
Thu, 15 Oct 2015 17:04:15 +0000 (13:04 -0400)
committerSmallJoker <mk939@ymail.com>
Sat, 18 Mar 2017 11:37:57 +0000 (12:37 +0100)
This removes the hacky server_dedicated pseudo-setting.

src/game.cpp
src/main.cpp
src/server.cpp
src/server.h
src/serverlist.cpp
src/serverlist.h

index cb38208700162e5cec41b552a981dc6e95b0d5b5..12c81bf2fa468754352894f5931a2b65e041d12a 100644 (file)
@@ -1899,7 +1899,7 @@ bool Game::createSingleplayerServer(const std::string map_dir,
        }
 
        server = new Server(map_dir, gamespec, simple_singleplayer_mode,
-                           bind_addr.isIPv6());
+                           bind_addr.isIPv6(), false);
 
        server->start(bind_addr);
 
index a544546534ca68f115d5d30f57c9b82be21e3c5a..3599a36ce055138a4e4a05d22027162bd2767b3f 100644 (file)
@@ -213,10 +213,6 @@ int main(int argc, char *argv[])
        infostream << "Using commanded world path ["
                   << game_params.world_path << "]" << std::endl;
 
-       //Run dedicated server if asked to or no other option
-       g_settings->set("server_dedicated",
-                       game_params.is_dedicated_server ? "true" : "false");
-
        if (game_params.is_dedicated_server)
                return run_dedicated_server(game_params, cmd_args) ? 0 : 1;
 
@@ -852,8 +848,8 @@ static bool run_dedicated_server(const GameParams &game_params, const Settings &
 
                try {
                        // Create server
-                       Server server(game_params.world_path,
-                               game_params.game_spec, false, bind_addr.isIPv6(), &iface);
+                       Server server(game_params.world_path, game_params.game_spec,
+                                       false, bind_addr.isIPv6(), true, &iface);
 
                        g_term_console.setup(&iface, &kill, admin_nick);
 
@@ -887,7 +883,7 @@ static bool run_dedicated_server(const GameParams &game_params, const Settings &
                try {
                        // Create server
                        Server server(game_params.world_path, game_params.game_spec, false,
-                               bind_addr.isIPv6());
+                               bind_addr.isIPv6(), true);
                        server.start(bind_addr);
 
                        // Run server
index 293b32a81595403fa7c9c269f5efc6c52718fed8..9ed2a045de53747ca5c2802cbf50e7dfb7419ee2 100644 (file)
@@ -148,11 +148,13 @@ Server::Server(
                const SubgameSpec &gamespec,
                bool simple_singleplayer_mode,
                bool ipv6,
+               bool dedicated,
                ChatInterface *iface
        ):
        m_path_world(path_world),
        m_gamespec(gamespec),
        m_simple_singleplayer_mode(simple_singleplayer_mode),
+       m_dedicated(dedicated),
        m_async_fatal_error(""),
        m_env(NULL),
        m_con(PROTOCOL_ID,
@@ -629,10 +631,10 @@ void Server::AsyncRunStep(bool initial_step)
        // send masterserver announce
        {
                float &counter = m_masterserver_timer;
-               if(!isSingleplayer() && (!counter || counter >= 300.0) &&
-                               g_settings->getBool("server_announce"))
-               {
-                       ServerList::sendAnnounce(counter ? "update" : "start",
+               if (!isSingleplayer() && (!counter || counter >= 300.0) &&
+                               g_settings->getBool("server_announce")) {
+                       ServerList::sendAnnounce(counter ? ServerList::AA_UPDATE :
+                                               ServerList::AA_START,
                                        m_bind_addr.getPort(),
                                        m_clients.getPlayerNames(),
                                        m_uptime.get(),
@@ -640,7 +642,8 @@ void Server::AsyncRunStep(bool initial_step)
                                        m_lag,
                                        m_gamespec.id,
                                        Mapgen::getMapgenName(m_emerge->mgparams->mgtype),
-                                       m_mods);
+                                       m_mods,
+                                       m_dedicated);
                        counter = 0.01;
                }
                counter += dtime;
@@ -3574,16 +3577,6 @@ void dedicated_server_loop(Server &server, bool &kill)
                }
                server.step(steplen);
 
-               if(server.getShutdownRequested() || kill)
-               {
-                       infostream<<"Dedicated server quitting"<<std::endl;
-#if USE_CURL
-                       if(g_settings->getBool("server_announce"))
-                               ServerList::sendAnnounce("delete", server.m_bind_addr.getPort());
-#endif
-                       break;
-               }
-
                /*
                        Profiler
                */
@@ -3596,4 +3589,11 @@ void dedicated_server_loop(Server &server, bool &kill)
                        }
                }
        }
+
+       infostream << "Dedicated server quitting" << std::endl;
+#if USE_CURL
+       if (g_settings->getBool("server_announce"))
+               ServerList::sendAnnounce(ServerList::AA_DELETE,
+                       server.m_bind_addr.getPort());
+#endif
 }
index e1e8f84dc658d035c131d6b80f03b0a7a9f32b00..1df9d0a938149d02c7116f97d78b74affbb91a92 100644 (file)
@@ -148,6 +148,7 @@ public:
                const SubgameSpec &gamespec,
                bool simple_singleplayer_mode,
                bool ipv6,
+               bool dedicated,
                ChatInterface *iface = NULL
        );
        ~Server();
@@ -510,6 +511,8 @@ private:
        // functionality
        bool m_simple_singleplayer_mode;
        u16 m_max_chatmessage_length;
+       // For "dedicated" server list flag
+       bool m_dedicated;
 
        // Thread can set; step() will throw as ServerError
        MutexedVariable<std::string> m_async_fatal_error;
index 87ca5dc04487c1ba5b74af2dd85b6449d744c66d..cc38ec8ce5889dd440689536eec5bb5be14f2b02 100644 (file)
@@ -196,7 +196,7 @@ const std::string serializeJson(const std::vector<ServerListSpec> &serverlist)
 
 
 #if USE_CURL
-void sendAnnounce(const std::string &action,
+void sendAnnounce(AnnounceAction action,
                const u16 port,
                const std::vector<std::string> &clients_names,
                const double uptime,
@@ -204,15 +204,17 @@ void sendAnnounce(const std::string &action,
                const float lag,
                const std::string &gameid,
                const std::string &mg_name,
-               const std::vector<ModSpec> &mods)
+               const std::vector<ModSpec> &mods,
+               bool dedicated)
 {
+       static const char *aa_names[] = {"start", "update", "delete"};
        Json::Value server;
-       server["action"] = action;
+       server["action"] = aa_names[action];
        server["port"] = port;
        if (g_settings->exists("server_address")) {
                server["address"] = g_settings->get("server_address");
        }
-       if (action != "delete") {
+       if (action != AA_DELETE) {
                bool strict_checking = g_settings->getBool("strict_protocol_version_checking");
                server["name"]         = g_settings->get("server_name");
                server["description"]  = g_settings->get("server_description");
@@ -237,20 +239,19 @@ void sendAnnounce(const std::string &action,
                if (gameid != "") server["gameid"] = gameid;
        }
 
-       if (action == "start") {
-               server["dedicated"]         = g_settings->getBool("server_dedicated");
+       if (action == AA_START) {
+               server["dedicated"]         = dedicated;
                server["rollback"]          = g_settings->getBool("enable_rollback_recording");
                server["mapgen"]            = mg_name;
                server["privs"]             = g_settings->get("default_privs");
                server["can_see_far_names"] = g_settings->getS16("player_transfer_distance") <= 0;
                server["mods"]              = Json::Value(Json::arrayValue);
                for (std::vector<ModSpec>::const_iterator it = mods.begin();
-                               it != mods.end();
-                               ++it) {
+                               it != mods.end(); ++it) {
                        server["mods"].append(it->name);
                }
                actionstream << "Announcing to " << g_settings->get("serverlist_url") << std::endl;
-       } else {
+       } else if (action == AA_UPDATE) {
                if (lag)
                        server["lag"] = lag;
        }
@@ -264,4 +265,5 @@ void sendAnnounce(const std::string &action,
 }
 #endif
 
-} //namespace ServerList
+} // namespace ServerList
+
index 0747c39202fd0dc1d3714e2c196e61028a3991da..0790261998b13efcc0bd302dde2a4554145f1011 100644 (file)
@@ -29,22 +29,27 @@ typedef Json::Value ServerListSpec;
 
 namespace ServerList
 {
-       std::vector<ServerListSpec> getLocal();
-       std::vector<ServerListSpec> getOnline();
-       bool deleteEntry(const ServerListSpec &server);
-       bool insert(const ServerListSpec &server);
-       std::vector<ServerListSpec> deSerialize(const std::string &liststring);
-       const std::string serialize(const std::vector<ServerListSpec> &serverlist);
-       std::vector<ServerListSpec> deSerializeJson(const std::string &liststring);
-       const std::string serializeJson(const std::vector<ServerListSpec> &serverlist);
-       #if USE_CURL
-       void sendAnnounce(const std::string &action, const u16 port,
-                       const std::vector<std::string> &clients_names = std::vector<std::string>(),
-                       const double uptime = 0, const u32 game_time = 0,
-                       const float lag = 0, const std::string &gameid = "",
-                       const std::string &mg_name = "",
-                       const std::vector<ModSpec> &mods = std::vector<ModSpec>());
-       #endif
-} // ServerList namespace
+std::vector<ServerListSpec> getLocal();
+std::vector<ServerListSpec> getOnline();
+
+bool deleteEntry(const ServerListSpec &server);
+bool insert(const ServerListSpec &server);
+
+std::vector<ServerListSpec> deSerialize(const std::string &liststring);
+const std::string serialize(const std::vector<ServerListSpec> &serverlist);
+std::vector<ServerListSpec> deSerializeJson(const std::string &liststring);
+const std::string serializeJson(const std::vector<ServerListSpec> &serverlist);
+
+#if USE_CURL
+enum AnnounceAction {AA_START, AA_UPDATE, AA_DELETE};
+void sendAnnounce(AnnounceAction, u16 port,
+               const std::vector<std::string> &clients_names = std::vector<std::string>(),
+               double uptime = 0, u32 game_time = 0, float lag = 0,
+               const std::string &gameid = "", const std::string &mg_name = "",
+               const std::vector<ModSpec> &mods = std::vector<ModSpec>(),
+               bool dedicated = false);
+#endif
+
+} // namespace ServerList
 
 #endif