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
This commit is contained in:
Craig Robbins 2015-01-31 00:33:23 +10:00
parent 4d15d63134
commit 38561023b4
3 changed files with 55 additions and 35 deletions

@ -219,7 +219,6 @@ Client::Client(
IrrlichtDevice *device, IrrlichtDevice *device,
const char *playername, const char *playername,
std::string password, std::string password,
bool is_simple_singleplayer_game,
MapDrawControl &control, MapDrawControl &control,
IWritableTextureSource *tsrc, IWritableTextureSource *tsrc,
IWritableShaderSource *shsrc, IWritableShaderSource *shsrc,
@ -283,34 +282,6 @@ Client::Client(
m_env.addPlayer(player); 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"); m_cache_smooth_lighting = g_settings->getBool("smooth_lighting");
} }
@ -321,6 +292,7 @@ void Client::Stop()
if (localdb != NULL) { if (localdb != NULL) {
actionstream << "Local map saving ended" << std::endl; actionstream << "Local map saving ended" << std::endl;
localdb->endSave(); 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); DSTACK(__FUNCTION_NAME);
initLocalMapSaving(address, address_name, is_local_server);
m_con.SetTimeoutMs(0); m_con.SetTimeoutMs(0);
m_con.Connect(address); m_con.Connect(address);
} }
@ -964,6 +941,41 @@ void Client::received_media()
<<std::endl; <<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() void Client::ReceiveAll()
{ {
DSTACK(__FUNCTION_NAME); DSTACK(__FUNCTION_NAME);

@ -305,7 +305,6 @@ public:
IrrlichtDevice *device, IrrlichtDevice *device,
const char *playername, const char *playername,
std::string password, std::string password,
bool is_simple_singleplayer_game,
MapDrawControl &control, MapDrawControl &control,
IWritableTextureSource *tsrc, IWritableTextureSource *tsrc,
IWritableShaderSource *shsrc, IWritableShaderSource *shsrc,
@ -325,11 +324,14 @@ public:
bool isShutdown(); bool isShutdown();
/* /*
The name of the local player should already be set when The name of the local player should already be set when
calling this, as it is sent in the initialization. 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 Stuff that references the environment is valid only as
@ -477,6 +479,10 @@ private:
void peerAdded(con::Peer *peer); void peerAdded(con::Peer *peer);
void deletingPeer(con::Peer *peer, bool timeout); void deletingPeer(con::Peer *peer, bool timeout);
void initLocalMapSaving(const Address &address,
const std::string &hostname,
bool is_local_server);
void ReceiveAll(); void ReceiveAll();
void Receive(); void Receive();

@ -1923,7 +1923,6 @@ bool Game::createSingleplayerServer(const std::string map_dir,
try { try {
bind_addr.Resolve(bind_str.c_str()); bind_addr.Resolve(bind_str.c_str());
*address = bind_str;
} catch (ResolveError &e) { } catch (ResolveError &e) {
infostream << "Resolving bind address \"" << bind_str infostream << "Resolving bind address \"" << bind_str
<< "\" failed: " << e.what() << "\" failed: " << e.what()
@ -2121,6 +2120,7 @@ bool Game::connectToServer(const std::string &playername,
{ {
*connect_ok = false; // Let's not be overly optimistic *connect_ok = false; // Let's not be overly optimistic
*aborted = false; *aborted = false;
bool local_server_mode = false;
showOverlayMessage("Resolving address...", 0, 15); showOverlayMessage("Resolving address...", 0, 15);
@ -2138,6 +2138,7 @@ bool Game::connectToServer(const std::string &playername,
} else { } else {
connect_address.setAddress(127, 0, 0, 1); connect_address.setAddress(127, 0, 0, 1);
} }
local_server_mode = true;
} }
} catch (ResolveError &e) { } catch (ResolveError &e) {
*error_message = L"Couldn't resolve address: " + narrow_to_wide(e.what()); *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, client = new Client(device,
playername.c_str(), password, simple_singleplayer_mode, playername.c_str(), password,
*draw_control, texture_src, shader_src, *draw_control, texture_src, shader_src,
itemdef_manager, nodedef_manager, sound, eventmgr, itemdef_manager, nodedef_manager, sound, eventmgr,
connect_address.isIPv6()); connect_address.isIPv6());
@ -2168,7 +2169,8 @@ bool Game::connectToServer(const std::string &playername,
connect_address.print(&infostream); connect_address.print(&infostream);
infostream << std::endl; infostream << std::endl;
client->connect(connect_address); client->connect(connect_address, *address,
simple_singleplayer_mode || local_server_mode);
/* /*
Wait for server to accept connection Wait for server to accept connection