]> git.lizzy.rs Git - minetest.git/commitdiff
Fix local map saving when joining a local server from the server tab
authorCraig Robbins <kde.psych@gmail.com>
Fri, 30 Jan 2015 14:33:23 +0000 (00:33 +1000)
committerCraig Robbins <kde.psych@gmail.com>
Fri, 30 Jan 2015 14:42:08 +0000 (00:42 +1000)
Disables local map saving for all local server types

See: https://github.com/minetest/minetest/issues/2024

src/client.cpp
src/client.h
src/game.cpp

index 536e9afa7c0e45ffea484821c0739f33c74ec9a6..cb6419fade8f2f0d7e5a4451a774a417543e3ab3 100644 (file)
@@ -219,7 +219,6 @@ Client::Client(
                IrrlichtDevice *device,
                const char *playername,
                std::string password,
-               bool is_simple_singleplayer_game,
                MapDrawControl &control,
                IWritableTextureSource *tsrc,
                IWritableShaderSource *shsrc,
@@ -283,34 +282,6 @@ Client::Client(
                m_env.addPlayer(player);
        }
 
-       if (g_settings->getBool("enable_local_map_saving")
-                       && !is_simple_singleplayer_game) {
-               const std::string world_path = porting::path_user + DIR_DELIM + "worlds"
-                               + DIR_DELIM + "server_" + g_settings->get("address")
-                               + "_" + g_settings->get("remote_port");
-
-               SubgameSpec gamespec;
-               if (!getWorldExists(world_path)) {
-                       gamespec = findSubgame(g_settings->get("default_game"));
-                       if (!gamespec.isValid())
-                               gamespec = findSubgame("minimal");
-               } else {
-                       std::string world_gameid = getWorldGameId(world_path, false);
-                       gamespec = findWorldSubgame(world_path);
-               }
-               if (!gamespec.isValid()) {
-                       errorstream << "Couldn't find subgame for local map saving." << std::endl;
-                       return;
-               }
-
-               localserver = new Server(world_path, gamespec, false, false);
-               localdb = new Database_SQLite3(&(ServerMap&)localserver->getMap(), world_path);
-               localdb->beginSave();
-               actionstream << "Local map saving started, map will be saved at '" << world_path << "'" << std::endl;
-       } else {
-               localdb = NULL;
-       }
-
        m_cache_smooth_lighting = g_settings->getBool("smooth_lighting");
 }
 
@@ -321,6 +292,7 @@ void Client::Stop()
        if (localdb != NULL) {
                actionstream << "Local map saving ended" << std::endl;
                localdb->endSave();
+               delete localserver;
        }
 }
 
@@ -363,9 +335,14 @@ Client::~Client()
        }
 }
 
-void Client::connect(Address address)
+void Client::connect(Address address,
+               const std::string &address_name,
+               bool is_local_server)
 {
        DSTACK(__FUNCTION_NAME);
+
+       initLocalMapSaving(address, address_name, is_local_server);
+
        m_con.SetTimeoutMs(0);
        m_con.Connect(address);
 }
@@ -964,6 +941,41 @@ void Client::received_media()
                        <<std::endl;
 }
 
+void Client::initLocalMapSaving(const Address &address,
+               const std::string &hostname,
+               bool is_local_server)
+{
+       localdb = NULL;
+
+       if (!g_settings->getBool("enable_local_map_saving") || is_local_server)
+               return;
+
+       const std::string world_path = porting::path_user
+               + DIR_DELIM + "worlds"
+               + DIR_DELIM + "server_"
+               + hostname + "_" + to_string(address.getPort());
+
+       SubgameSpec gamespec;
+
+       if (!getWorldExists(world_path)) {
+               gamespec = findSubgame(g_settings->get("default_game"));
+               if (!gamespec.isValid())
+                       gamespec = findSubgame("minimal");
+       } else {
+               gamespec = findWorldSubgame(world_path);
+       }
+
+       if (!gamespec.isValid()) {
+               errorstream << "Couldn't find subgame for local map saving." << std::endl;
+               return;
+       }
+
+       localserver = new Server(world_path, gamespec, false, false);
+       localdb = new Database_SQLite3(&(ServerMap&)localserver->getMap(), world_path);
+       localdb->beginSave();
+       actionstream << "Local map saving started, map will be saved at '" << world_path << "'" << std::endl;
+}
+
 void Client::ReceiveAll()
 {
        DSTACK(__FUNCTION_NAME);
index 9b1b63c0b2af28f05ddc46e496574b9784f9b301..fd7e5f08d8b8b2c58b82ee53dedbc46ab73b1e20 100644 (file)
@@ -305,7 +305,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
                        IrrlichtDevice *device,
                        const char *playername,
                        std::string password,
-                       bool is_simple_singleplayer_game,
                        MapDrawControl &control,
                        IWritableTextureSource *tsrc,
                        IWritableShaderSource *shsrc,
@@ -325,11 +324,14 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
 
 
        bool isShutdown();
+
        /*
                The name of the local player should already be set when
                calling this, as it is sent in the initialization.
        */
-       void connect(Address address);
+       void connect(Address address,
+                       const std::string &address_name,
+                       bool is_local_server);
 
        /*
                Stuff that references the environment is valid only as
@@ -477,6 +479,10 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        void peerAdded(con::Peer *peer);
        void deletingPeer(con::Peer *peer, bool timeout);
 
+       void initLocalMapSaving(const Address &address,
+                       const std::string &hostname,
+                       bool is_local_server);
+
        void ReceiveAll();
        void Receive();
 
index b496cf3bf335f792b259fb53da405b34be3def5d..1c8fa092417171b120bc6529e7aeacb8b16958c1 100644 (file)
@@ -1923,7 +1923,6 @@ bool Game::createSingleplayerServer(const std::string map_dir,
 
        try {
                bind_addr.Resolve(bind_str.c_str());
-               *address = bind_str;
        } catch (ResolveError &e) {
                infostream << "Resolving bind address \"" << bind_str
                           << "\" failed: " << e.what()
@@ -2121,6 +2120,7 @@ bool Game::connectToServer(const std::string &playername,
 {
        *connect_ok = false;    // Let's not be overly optimistic
        *aborted = false;
+       bool local_server_mode = false;
 
        showOverlayMessage("Resolving address...", 0, 15);
 
@@ -2138,6 +2138,7 @@ bool Game::connectToServer(const std::string &playername,
                        } else {
                                connect_address.setAddress(127, 0, 0, 1);
                        }
+                       local_server_mode = true;
                }
        } catch (ResolveError &e) {
                *error_message = L"Couldn't resolve address: " + narrow_to_wide(e.what());
@@ -2154,7 +2155,7 @@ bool Game::connectToServer(const std::string &playername,
        }
 
        client = new Client(device,
-                       playername.c_str(), password, simple_singleplayer_mode,
+                       playername.c_str(), password,
                        *draw_control, texture_src, shader_src,
                        itemdef_manager, nodedef_manager, sound, eventmgr,
                        connect_address.isIPv6());
@@ -2168,7 +2169,8 @@ bool Game::connectToServer(const std::string &playername,
        connect_address.print(&infostream);
        infostream << std::endl;
 
-       client->connect(connect_address);
+       client->connect(connect_address, *address,
+               simple_singleplayer_mode || local_server_mode);
 
        /*
                Wait for server to accept connection