IrrlichtDevice *device,
const char *playername,
std::string password,
- bool is_simple_singleplayer_game,
MapDrawControl &control,
IWritableTextureSource *tsrc,
IWritableShaderSource *shsrc,
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");
}
if (localdb != NULL) {
actionstream << "Local map saving ended" << std::endl;
localdb->endSave();
+ delete localserver;
}
}
}
}
-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);
}
<<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);
IrrlichtDevice *device,
const char *playername,
std::string password,
- bool is_simple_singleplayer_game,
MapDrawControl &control,
IWritableTextureSource *tsrc,
IWritableShaderSource *shsrc,
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
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();
try {
bind_addr.Resolve(bind_str.c_str());
- *address = bind_str;
} catch (ResolveError &e) {
infostream << "Resolving bind address \"" << bind_str
<< "\" failed: " << e.what()
{
*connect_ok = false; // Let's not be overly optimistic
*aborted = false;
+ bool local_server_mode = false;
showOverlayMessage("Resolving address...", 0, 15);
} 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());
}
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());
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