Navigation Menu

Skip to content

Commit

Permalink
Add (optional) client-side saving of server map to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Nov 19, 2014
1 parent 0ee5a21 commit 9d69436
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions minetest.conf.example
Expand Up @@ -164,6 +164,8 @@
#selectionbox_width = 2
# maximum percentage of current window to be used for hotbar
#hud_hotbar_max_width = 1.0
# Save the map received by the client on disk
#enable_local_map_saving = false
# Enable highlighting for nodes (disables selectionboxes)
#enable_node_highlighting = false
# Texture filtering settings
Expand Down
39 changes: 39 additions & 0 deletions src/client.cpp
Expand Up @@ -52,6 +52,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "config.h"
#include "version.h"
#include "drawscene.h"
#include "subgame.h"
#include "server.h"
#include "database.h"
#include "database-sqlite3.h"

extern gui::IGUIEnvironment* guienv;

Expand Down Expand Up @@ -275,12 +279,43 @@ Client::Client(

m_env.addPlayer(player);
}

if (g_settings->getBool("enable_local_map_saving")) {
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;
}
}

void Client::Stop()
{
//request all client managed threads to stop
m_mesh_update_thread.Stop();
if (localdb != NULL) {
actionstream << "Local map saving ended" << std::endl;
localdb->endSave();
}
}

bool Client::isShutdown()
Expand Down Expand Up @@ -1156,6 +1191,10 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
sector->insertBlock(block);
}

if (localdb != NULL) {
((ServerMap&) localserver->getMap()).saveBlock(block, localdb);
}

/*
Add it to mesh update queue and set it to be acknowledged after update.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/client.h
Expand Up @@ -46,6 +46,8 @@ class ClientMediaDownloader;
struct MapDrawControl;
class MtEventManager;
struct PointedThing;
class Database;
class Server;

struct QueuedMeshUpdate
{
Expand Down Expand Up @@ -555,6 +557,10 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef

// own state
LocalClientState m_state;

// Used for saving server map to disk client-side
Database *localdb;
Server *localserver;
};

#endif // !CLIENT_HEADER
Expand Down
1 change: 1 addition & 0 deletions src/defaultsettings.cpp
Expand Up @@ -131,6 +131,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("desynchronize_mapblock_texture_animation", "true");
settings->setDefault("selectionbox_width","2");
settings->setDefault("hud_hotbar_max_width","1.0");
settings->setDefault("enable_local_map_saving", "false");

settings->setDefault("mip_map", "false");
settings->setDefault("anisotropic_filter", "false");
Expand Down

4 comments on commit 9d69436

@HybridDog
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

21:25:16: ACTION[main]: Local map saving started, map will be saved at '/home/h/.minetest/worlds/name.com_30000'
21:26:19: ERROR[ServerThread]: WARNING: saveBlock: Block failed to save (-12,3,6): database is locked

May you disallow using the setting on singleplayer mode?

@Megaf
Copy link
Contributor

@Megaf Megaf commented on 9d69436 Nov 21, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you cant play on the saved world on single player. Because it will save the saved world.

@sfan5
Copy link
Member Author

@sfan5 sfan5 commented on 9d69436 Nov 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just disable the setting

@Megaf
Copy link
Contributor

@Megaf Megaf commented on 9d69436 Nov 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ideal if the changing disabled itself on switching to single player mod.

Please sign in to comment.