diff options
author | Craig Robbins <kde.psych@gmail.com> | 2015-01-31 00:33:23 +1000 |
---|---|---|
committer | Craig Robbins <kde.psych@gmail.com> | 2015-01-31 00:42:08 +1000 |
commit | 38561023b468b923aa2b7957b807fa2700ea59ce (patch) | |
tree | f352ea600922f1a5da602aca51d85f74682cdcda | |
parent | 4d15d631349005528e8578a5750ad9a1b8cefe39 (diff) | |
download | minetest-38561023b468b923aa2b7957b807fa2700ea59ce.tar.gz minetest-38561023b468b923aa2b7957b807fa2700ea59ce.tar.bz2 minetest-38561023b468b923aa2b7957b807fa2700ea59ce.zip |
Fix local map saving when joining a local server from the server tab
Disables local map saving for all local server types
See: https://github.com/minetest/minetest/issues/2024
-rw-r--r-- | src/client.cpp | 72 | ||||
-rw-r--r-- | src/client.h | 10 | ||||
-rw-r--r-- | src/game.cpp | 8 |
3 files changed, 55 insertions, 35 deletions
diff --git a/src/client.cpp b/src/client.cpp index 536e9afa7..cb6419fad 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -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); diff --git a/src/client.h b/src/client.h index 9b1b63c0b..fd7e5f08d 100644 --- a/src/client.h +++ b/src/client.h @@ -305,7 +305,6 @@ public: IrrlichtDevice *device, const char *playername, std::string password, - bool is_simple_singleplayer_game, MapDrawControl &control, IWritableTextureSource *tsrc, IWritableShaderSource *shsrc, @@ -325,11 +324,14 @@ public: 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 @@ private: 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(); diff --git a/src/game.cpp b/src/game.cpp index b496cf3bf..1c8fa0924 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -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 |