mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 10:03:45 +01:00
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:
parent
4d15d63134
commit
38561023b4
@ -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);
|
||||
|
10
src/client.h
10
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();
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user