#include "irrlicht.h" // createDevice
-#include "main.h"
#include "mainmenumanager.h"
#include "irrlichttypes_extrabloated.h"
#include "debug.h"
-#include "test.h"
+#include "unittest/test.h"
#include "server.h"
#include "filesys.h"
#include "version.h"
#include "game.h"
#include "defaultsettings.h"
#include "gettext.h"
-#include "profiler.h"
#include "log.h"
#include "quicktune.h"
#include "httpfetch.h"
#include "guiEngine.h"
+#include "map.h"
#include "mapsector.h"
#include "fontengine.h"
#include "gameparams.h"
+#include "database.h"
#ifndef SERVER
#include "client/clientlauncher.h"
#endif
-#include "database-sqlite3.h"
-#ifdef USE_LEVELDB
-#include "database-leveldb.h"
-#endif
-
-#if USE_REDIS
-#include "database-redis.h"
-#endif
-
#ifdef HAVE_TOUCHSCREENGUI
#include "touchscreengui.h"
#endif
-/*
- Settings.
- These are loaded from the config file.
-*/
-static Settings main_settings;
-Settings *g_settings = &main_settings;
-std::string g_settings_path;
-
-// Global profiler
-Profiler main_profiler;
-Profiler *g_profiler = &main_profiler;
-
-// Menu clouds are created later
-Clouds *g_menuclouds = 0;
-irr::scene::ISceneManager *g_menucloudsmgr = 0;
-
-/*
- Debug streams
-*/
-
-// Connection
-std::ostream *dout_con_ptr = &dummyout;
-std::ostream *derr_con_ptr = &verbosestream;
-
-// Server
-std::ostream *dout_server_ptr = &infostream;
-std::ostream *derr_server_ptr = &errorstream;
-
-// Client
-std::ostream *dout_client_ptr = &infostream;
-std::ostream *derr_client_ptr = &errorstream;
-
#define DEBUGFILE "debug.txt"
#define DEFAULT_SERVER_PORT 30000
static bool determine_subgame(GameParams *game_params);
static bool run_dedicated_server(const GameParams &game_params, const Settings &cmd_args);
-static bool migrate_database(const GameParams &game_params, const Settings &cmd_args,
- Server *server);
+static bool migrate_database(const GameParams &game_params, const Settings &cmd_args);
/**********************************************************************/
-#ifndef SERVER
-/*
- Random stuff
-*/
-
-/* mainmenumanager.h */
-
-gui::IGUIEnvironment* guienv = NULL;
-gui::IGUIStaticText *guiroot = NULL;
-MainMenuManager g_menumgr;
-
-bool noMenuActive()
-{
- return (g_menumgr.menuCount() == 0);
-}
-
-// Passed to menus to allow disconnecting and exiting
-MainGameCallback *g_gamecallback = NULL;
-#endif
-
/*
gettime.h implementation
*/
log_add_output_maxlev(&main_stderr_log_out, LMT_ACTION);
log_add_output_all_levs(&main_dstream_no_stderr_log_out);
- log_register_thread("main");
+ log_register_thread("Main");
Settings cmd_args;
bool cmd_args_ok = get_cmdline_opts(argc, argv, &cmd_args);
if (!game_configure(&game_params, cmd_args))
return 1;
- assert(game_params.world_path != "");
+ sanity_check(game_params.world_path != "");
infostream << "Using commanded world path ["
<< game_params.world_path << "]" << std::endl;
static void print_version()
{
-#ifdef SERVER
- dstream << "minetestserver " << minetest_version_hash << std::endl;
-#else
- dstream << "Minetest " << minetest_version_hash << std::endl;
+ dstream << PROJECT_NAME_C " " << g_version_hash << std::endl;
+#ifndef SERVER
dstream << "Using Irrlicht " << IRRLICHT_SDK_VERSION << std::endl;
#endif
- dstream << "Build info: " << minetest_build_info << std::endl;
+ dstream << "Build info: " << g_build_info << std::endl;
}
static void list_game_ids()
{
std::set<std::string> gameids = getAvailableGameIds();
for (std::set<std::string>::const_iterator i = gameids.begin();
- i != gameids.end(); i++)
+ i != gameids.end(); ++i)
dstream << (*i) <<std::endl;
}
infostream << PROJECT_NAME << " " << _("with")
<< " SER_FMT_VER_HIGHEST_READ="
<< (int)SER_FMT_VER_HIGHEST_READ << ", "
- << minetest_build_info << std::endl;
+ << g_build_info << std::endl;
}
static bool read_config_file(const Settings &cmd_args)
{
// Path of configuration file in use
- assert(g_settings_path == ""); // Sanity check
+ sanity_check(g_settings_path == ""); // Sanity check
if (cmd_args.exists("config")) {
bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
<< world_path << "]" << std::endl;
}
- assert(world_path != "");
+ assert(world_path != ""); // Post-condition
game_params->world_path = world_path;
return true;
}
{
SubgameSpec gamespec;
- assert(game_params->world_path != ""); // pre-condition
+ assert(game_params->world_path != ""); // Pre-condition
verbosestream << _("Determining gameid/gamespec") << std::endl;
// If world doesn't exist
return false;
}
+ // Database migration
+ if (cmd_args.exists("migrate"))
+ return migrate_database(game_params, cmd_args);
+
// Create server
Server server(game_params.world_path,
game_params.game_spec, false, bind_addr.isIPv6());
- // Database migration
- if (cmd_args.exists("migrate"))
- return migrate_database(game_params, cmd_args, &server);
-
server.start(bind_addr);
// Run server
return true;
}
-static bool migrate_database(const GameParams &game_params, const Settings &cmd_args,
- Server *server)
+static bool migrate_database(const GameParams &game_params, const Settings &cmd_args)
{
std::string migrate_to = cmd_args.get("migrate");
Settings world_mt;
std::string world_mt_path = game_params.world_path + DIR_DELIM + "world.mt";
- bool success = world_mt.readConfigFile(world_mt_path.c_str());
- if (!success) {
- errorstream << "Cannot read world.mt" << std::endl;
- return 1;
+ if (!world_mt.readConfigFile(world_mt_path.c_str())) {
+ errorstream << "Cannot read world.mt!" << std::endl;
+ return false;
}
if (!world_mt.exists("backend")) {
errorstream << "Please specify your current backend in world.mt:"
+ << std::endl
+ << " backend = {sqlite3|leveldb|redis|dummy}"
<< std::endl;
- errorstream << " backend = {sqlite3|leveldb|redis|dummy}"
- << std::endl;
- return 1;
+ return false;
}
std::string backend = world_mt.get("backend");
- Database *new_db;
if (backend == migrate_to) {
errorstream << "Cannot migrate: new backend is same"
- <<" as the old one" << std::endl;
- return 1;
- }
- if (migrate_to == "sqlite3")
- new_db = new Database_SQLite3(game_params.world_path);
- #if USE_LEVELDB
- else if (migrate_to == "leveldb")
- new_db = new Database_LevelDB(game_params.world_path);
- #endif
- #if USE_REDIS
- else if (migrate_to == "redis")
- new_db = new Database_Redis(world_mt);
- #endif
- else {
- errorstream << "Migration to " << migrate_to
- << " is not supported" << std::endl;
- return 1;
+ << " as the old one" << std::endl;
+ return false;
}
+ Database *old_db = ServerMap::createDatabase(backend, game_params.world_path, world_mt),
+ *new_db = ServerMap::createDatabase(migrate_to, game_params.world_path, world_mt);
+
+ u32 count = 0;
+ time_t last_update_time = 0;
+ bool &kill = *porting::signal_handler_killstatus();
std::vector<v3s16> blocks;
- ServerMap &old_map = (ServerMap &) server->getMap();
- old_map.listAllLoadableBlocks(blocks);
- int count = 0;
+ old_db->listAllLoadableBlocks(blocks);
new_db->beginSave();
- for (std::vector<v3s16>::iterator i = blocks.begin(); i != blocks.end(); i++) {
- MapBlock *block = old_map.loadBlock(*i);
- if (!block) {
- errorstream << "Failed to load block " << PP(*i) << ", skipping it.";
+ for (std::vector<v3s16>::const_iterator it = blocks.begin(); it != blocks.end(); ++it) {
+ if (kill) return false;
+
+ const std::string &data = old_db->loadBlock(*it);
+ if (!data.empty()) {
+ new_db->saveBlock(*it, data);
+ } else {
+ errorstream << "Failed to load block " << PP(*it) << ", skipping it." << std::endl;
}
- else {
- old_map.saveBlock(block, new_db);
- MapSector *sector = old_map.getSectorNoGenerate(v2s16(i->X, i->Z));
- sector->deleteBlock(block);
+ if (++count % 0xFF == 0 && time(NULL) - last_update_time >= 1) {
+ std::cerr << " Migrated " << count << " blocks, "
+ << (100.0 * count / blocks.size()) << "% completed.\r";
+ new_db->endSave();
+ new_db->beginSave();
+ last_update_time = time(NULL);
}
- ++count;
- if (count % 500 == 0)
- actionstream << "Migrated " << count << " blocks "
- << (100.0 * count / blocks.size()) << "% completed" << std::endl;
}
+ std::cerr << std::endl;
new_db->endSave();
+ delete old_db;
delete new_db;
actionstream << "Successfully migrated " << count << " blocks" << std::endl;
return true;
}
+