3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #pragma message ("Disabling unit tests")
24 #warning "Disabling unit tests"
27 #define ENABLE_TESTS 0
30 #define ENABLE_TESTS 1
34 #ifndef SERVER // Dedicated server isn't linked with Irrlicht
35 #pragma comment(lib, "Irrlicht.lib")
36 // This would get rid of the console window
37 //#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
39 #pragma comment(lib, "zlibwapi.lib")
40 #pragma comment(lib, "Shell32.lib")
43 #include "irrlicht.h" // createDevice
46 #include "mainmenumanager.h"
50 #include "irrlichttypes_extrabloated.h"
55 #include "constants.h"
61 #include "guiMainMenu.h"
66 #include "defaultsettings.h"
73 #include "xCGUITTFont.h"
75 #include "util/string.h"
77 #include "quicktune.h"
78 #include "serverlist.h"
79 #include "httpfetch.h"
80 #include "guiEngine.h"
81 #include "mapsector.h"
84 #include "database-sqlite3.h"
86 #include "database-leveldb.h"
90 #include "database-redis.h"
93 #ifdef HAVE_TOUCHSCREENGUI
94 #include "touchscreengui.h"
98 These are loaded from the config file.
100 Settings main_settings;
101 Settings *g_settings = &main_settings;
102 std::string g_settings_path;
105 Profiler main_profiler;
106 Profiler *g_profiler = &main_profiler;
108 // Menu clouds are created later
109 Clouds *g_menuclouds = 0;
110 irr::scene::ISceneManager *g_menucloudsmgr = 0;
117 std::ostream *dout_con_ptr = &dummyout;
118 std::ostream *derr_con_ptr = &verbosestream;
121 std::ostream *dout_server_ptr = &infostream;
122 std::ostream *derr_server_ptr = &errorstream;
125 std::ostream *dout_client_ptr = &infostream;
126 std::ostream *derr_client_ptr = &errorstream;
133 /* mainmenumanager.h */
135 gui::IGUIEnvironment* guienv = NULL;
136 gui::IGUIStaticText *guiroot = NULL;
137 MainMenuManager g_menumgr;
141 return (g_menumgr.menuCount() == 0);
144 // Passed to menus to allow disconnecting and exiting
145 MainGameCallback *g_gamecallback = NULL;
149 gettime.h implementation
156 /* Use imprecise system calls directly (from porting.h) */
157 return porting::getTime(PRECISION_MILLI);
160 u32 getTime(TimePrecision prec)
162 return porting::getTime(prec);
167 // A small helper class
171 virtual u32 getTime(TimePrecision prec) = 0;
174 // A precise irrlicht one
175 class IrrlichtTimeGetter: public TimeGetter
178 IrrlichtTimeGetter(IrrlichtDevice *device):
181 u32 getTime(TimePrecision prec)
183 if (prec == PRECISION_MILLI) {
184 if (m_device == NULL)
186 return m_device->getTimer()->getRealTime();
188 return porting::getTime(prec);
192 IrrlichtDevice *m_device;
194 // Not so precise one which works without irrlicht
195 class SimpleTimeGetter: public TimeGetter
198 u32 getTime(TimePrecision prec)
200 return porting::getTime(prec);
204 // A pointer to a global instance of the time getter
206 TimeGetter *g_timegetter = NULL;
210 if (g_timegetter == NULL)
212 return g_timegetter->getTime(PRECISION_MILLI);
215 u32 getTime(TimePrecision prec) {
216 if (g_timegetter == NULL)
218 return g_timegetter->getTime(prec);
222 class StderrLogOutput: public ILogOutput
225 /* line: Full line with timestamp, level and thread */
226 void printLog(const std::string &line)
228 std::cerr << line << std::endl;
230 } main_stderr_log_out;
232 class DstreamNoStderrLogOutput: public ILogOutput
235 /* line: Full line with timestamp, level and thread */
236 void printLog(const std::string &line)
238 dstream_no_stderr << line << std::endl;
240 } main_dstream_no_stderr_log_out;
245 Event handler for Irrlicht
247 NOTE: Everything possible should be moved out from here,
248 probably to InputHandler and the_game
251 class MyEventReceiver : public IEventReceiver
254 // This is the one method that we have to implement
255 virtual bool OnEvent(const SEvent& event)
258 React to nothing here if a menu is active
260 if (noMenuActive() == false) {
261 #ifdef HAVE_TOUCHSCREENGUI
262 if (m_touchscreengui != 0) {
263 m_touchscreengui->Toggle(false);
266 return g_menumgr.preprocessEvent(event);
269 // Remember whether each key is down or up
270 if (event.EventType == irr::EET_KEY_INPUT_EVENT) {
271 if (event.KeyInput.PressedDown) {
272 keyIsDown.set(event.KeyInput);
273 keyWasDown.set(event.KeyInput);
275 keyIsDown.unset(event.KeyInput);
279 #ifdef HAVE_TOUCHSCREENGUI
280 // case of touchscreengui we have to handle different events
281 if ((m_touchscreengui != 0) &&
282 (event.EventType == irr::EET_TOUCH_INPUT_EVENT)) {
283 m_touchscreengui->translateEvent(event);
287 // handle mouse events
288 if(event.EventType == irr::EET_MOUSE_INPUT_EVENT) {
289 if (noMenuActive() == false) {
291 middle_active = false;
292 right_active = false;
294 left_active = event.MouseInput.isLeftPressed();
295 middle_active = event.MouseInput.isMiddlePressed();
296 right_active = event.MouseInput.isRightPressed();
298 if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
301 if (event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN) {
304 if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) {
307 if (event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP) {
308 rightreleased = true;
310 if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) {
311 mouse_wheel += event.MouseInput.Wheel;
315 if(event.EventType == irr::EET_LOG_TEXT_EVENT) {
316 dstream<< std::string("Irrlicht log: ") + std::string(event.LogEvent.Text)<<std::endl;
319 /* always return false in order to continue processing events */
323 bool IsKeyDown(const KeyPress &keyCode) const
325 return keyIsDown[keyCode];
328 // Checks whether a key was down and resets the state
329 bool WasKeyDown(const KeyPress &keyCode)
331 bool b = keyWasDown[keyCode];
333 keyWasDown.unset(keyCode);
350 rightclicked = false;
351 leftreleased = false;
352 rightreleased = false;
355 middle_active = false;
356 right_active = false;
364 #ifdef HAVE_TOUCHSCREENGUI
365 m_touchscreengui = NULL;
380 #ifdef HAVE_TOUCHSCREENGUI
381 TouchScreenGUI* m_touchscreengui;
385 // The current state of keys
387 // Whether a key has been pressed or not
392 Separated input handler
395 class RealInputHandler : public InputHandler
398 RealInputHandler(IrrlichtDevice *device, MyEventReceiver *receiver):
400 m_receiver(receiver),
404 virtual bool isKeyDown(const KeyPress &keyCode)
406 return m_receiver->IsKeyDown(keyCode);
408 virtual bool wasKeyDown(const KeyPress &keyCode)
410 return m_receiver->WasKeyDown(keyCode);
412 virtual v2s32 getMousePos()
414 if (m_device->getCursorControl()) {
415 return m_device->getCursorControl()->getPosition();
421 virtual void setMousePos(s32 x, s32 y)
423 if (m_device->getCursorControl()) {
424 m_device->getCursorControl()->setPosition(x, y);
427 m_mousepos = v2s32(x,y);
431 virtual bool getLeftState()
433 return m_receiver->left_active;
435 virtual bool getRightState()
437 return m_receiver->right_active;
440 virtual bool getLeftClicked()
442 return m_receiver->leftclicked;
444 virtual bool getRightClicked()
446 return m_receiver->rightclicked;
448 virtual void resetLeftClicked()
450 m_receiver->leftclicked = false;
452 virtual void resetRightClicked()
454 m_receiver->rightclicked = false;
457 virtual bool getLeftReleased()
459 return m_receiver->leftreleased;
461 virtual bool getRightReleased()
463 return m_receiver->rightreleased;
465 virtual void resetLeftReleased()
467 m_receiver->leftreleased = false;
469 virtual void resetRightReleased()
471 m_receiver->rightreleased = false;
474 virtual s32 getMouseWheel()
476 return m_receiver->getMouseWheel();
481 m_receiver->clearInput();
484 IrrlichtDevice *m_device;
485 MyEventReceiver *m_receiver;
489 class RandomInputHandler : public InputHandler
497 rightclicked = false;
498 leftreleased = false;
499 rightreleased = false;
502 virtual bool isKeyDown(const KeyPress &keyCode)
504 return keydown[keyCode];
506 virtual bool wasKeyDown(const KeyPress &keyCode)
510 virtual v2s32 getMousePos()
514 virtual void setMousePos(s32 x, s32 y)
516 mousepos = v2s32(x, y);
519 virtual bool getLeftState()
523 virtual bool getRightState()
528 virtual bool getLeftClicked()
532 virtual bool getRightClicked()
536 virtual void resetLeftClicked()
540 virtual void resetRightClicked()
542 rightclicked = false;
545 virtual bool getLeftReleased()
549 virtual bool getRightReleased()
551 return rightreleased;
553 virtual void resetLeftReleased()
555 leftreleased = false;
557 virtual void resetRightReleased()
559 rightreleased = false;
562 virtual s32 getMouseWheel()
567 virtual void step(float dtime)
570 static float counter1 = 0;
572 if (counter1 < 0.0) {
573 counter1 = 0.1 * Rand(1, 40);
574 keydown.toggle(getKeySetting("keymap_jump"));
578 static float counter1 = 0;
580 if (counter1 < 0.0) {
581 counter1 = 0.1 * Rand(1, 40);
582 keydown.toggle(getKeySetting("keymap_special1"));
586 static float counter1 = 0;
588 if (counter1 < 0.0) {
589 counter1 = 0.1 * Rand(1, 40);
590 keydown.toggle(getKeySetting("keymap_forward"));
594 static float counter1 = 0;
596 if (counter1 < 0.0) {
597 counter1 = 0.1 * Rand(1, 40);
598 keydown.toggle(getKeySetting("keymap_left"));
602 static float counter1 = 0;
604 if (counter1 < 0.0) {
605 counter1 = 0.1 * Rand(1, 20);
606 mousespeed = v2s32(Rand(-20, 20), Rand(-15, 20));
610 static float counter1 = 0;
612 if (counter1 < 0.0) {
613 counter1 = 0.1 * Rand(1, 30);
614 leftdown = !leftdown;
622 static float counter1 = 0;
624 if (counter1 < 0.0) {
625 counter1 = 0.1 * Rand(1, 15);
626 rightdown = !rightdown;
630 rightreleased = true;
633 mousepos += mousespeed;
636 s32 Rand(s32 min, s32 max)
638 return (myrand()%(max-min+1))+min;
654 // These are defined global so that they're not optimized too much.
655 // Can't change them to volatile.
660 std::string tempstring;
661 std::string tempstring2;
666 infostream << "The following test should take around 20ms." << std::endl;
667 TimeTaker timer("Testing std::string speed");
668 const u32 jj = 10000;
669 for(u32 j = 0; j < jj; j++) {
673 for(u32 i = 0; i < ii; i++) {
674 tempstring2 += "asd";
676 for(u32 i = 0; i < ii+1; i++) {
678 if (tempstring == tempstring2)
684 infostream << "All of the following tests should take around 100ms each."
688 TimeTaker timer("Testing floating-point conversion speed");
690 for(u32 i = 0; i < 4000000; i++) {
697 TimeTaker timer("Testing floating-point vector speed");
699 tempv3f1 = v3f(1, 2, 3);
700 tempv3f2 = v3f(4, 5, 6);
701 for(u32 i = 0; i < 10000000; i++) {
702 tempf += tempv3f1.dotProduct(tempv3f2);
703 tempv3f2 += v3f(7, 8, 9);
708 TimeTaker timer("Testing std::map speed");
710 std::map<v2s16, f32> map1;
713 for(s16 y = 0; y < ii; y++) {
714 for(s16 x = 0; x < ii; x++) {
715 map1[v2s16(x, y)] = tempf;
719 for(s16 y = ii - 1; y >= 0; y--) {
720 for(s16 x = 0; x < ii; x++) {
721 tempf = map1[v2s16(x, y)];
727 infostream << "Around 5000/ms should do well here." << std::endl;
728 TimeTaker timer("Testing mutex speed");
741 while(timer.getTimerTime() < 10);
743 u32 dtime = timer.stop();
744 u32 per_ms = n / dtime;
745 infostream << "Done. " << dtime << "ms, " << per_ms << "/ms" << std::endl;
749 static void print_worldspecs(const std::vector<WorldSpec> &worldspecs, std::ostream &os)
751 for(u32 i = 0; i < worldspecs.size(); i++) {
752 std::string name = worldspecs[i].name;
753 std::string path = worldspecs[i].path;
754 if (name.find(" ") != std::string::npos)
755 name = std::string("'") + name + "'";
756 path = std::string("'") + path + "'";
757 name = padStringRight(name, 14);
758 os << " " << name << " " << path << std::endl;
762 int main(int argc, char *argv[])
770 log_add_output_maxlev(&main_stderr_log_out, LMT_ACTION);
771 log_add_output_all_levs(&main_dstream_no_stderr_log_out);
773 log_register_thread("main");
778 // List all allowed options
779 std::map<std::string, ValueSpec> allowed_options;
780 allowed_options.insert(std::make_pair("help", ValueSpec(VALUETYPE_FLAG,
781 _("Show allowed options"))));
782 allowed_options.insert(std::make_pair("version", ValueSpec(VALUETYPE_FLAG,
783 _("Show version information"))));
784 allowed_options.insert(std::make_pair("config", ValueSpec(VALUETYPE_STRING,
785 _("Load configuration from specified file"))));
786 allowed_options.insert(std::make_pair("port", ValueSpec(VALUETYPE_STRING,
787 _("Set network port (UDP)"))));
788 allowed_options.insert(std::make_pair("disable-unittests", ValueSpec(VALUETYPE_FLAG,
789 _("Disable unit tests"))));
790 allowed_options.insert(std::make_pair("enable-unittests", ValueSpec(VALUETYPE_FLAG,
791 _("Enable unit tests"))));
792 allowed_options.insert(std::make_pair("map-dir", ValueSpec(VALUETYPE_STRING,
793 _("Same as --world (deprecated)"))));
794 allowed_options.insert(std::make_pair("world", ValueSpec(VALUETYPE_STRING,
795 _("Set world path (implies local game) ('list' lists all)"))));
796 allowed_options.insert(std::make_pair("worldname", ValueSpec(VALUETYPE_STRING,
797 _("Set world by name (implies local game)"))));
798 allowed_options.insert(std::make_pair("quiet", ValueSpec(VALUETYPE_FLAG,
799 _("Print to console errors only"))));
800 allowed_options.insert(std::make_pair("info", ValueSpec(VALUETYPE_FLAG,
801 _("Print more information to console"))));
802 allowed_options.insert(std::make_pair("verbose", ValueSpec(VALUETYPE_FLAG,
803 _("Print even more information to console"))));
804 allowed_options.insert(std::make_pair("trace", ValueSpec(VALUETYPE_FLAG,
805 _("Print enormous amounts of information to log and console"))));
806 allowed_options.insert(std::make_pair("logfile", ValueSpec(VALUETYPE_STRING,
807 _("Set logfile path ('' = no logging)"))));
808 allowed_options.insert(std::make_pair("gameid", ValueSpec(VALUETYPE_STRING,
809 _("Set gameid (\"--gameid list\" prints available ones)"))));
810 allowed_options.insert(std::make_pair("migrate", ValueSpec(VALUETYPE_STRING,
811 _("Migrate from current map backend to another (Only works when using minetestserver or with --server)"))));
813 allowed_options.insert(std::make_pair("videomodes", ValueSpec(VALUETYPE_FLAG,
814 _("Show available video modes"))));
815 allowed_options.insert(std::make_pair("speedtests", ValueSpec(VALUETYPE_FLAG,
816 _("Run speed tests"))));
817 allowed_options.insert(std::make_pair("address", ValueSpec(VALUETYPE_STRING,
818 _("Address to connect to. ('' = local game)"))));
819 allowed_options.insert(std::make_pair("random-input", ValueSpec(VALUETYPE_FLAG,
820 _("Enable random user input, for testing"))));
821 allowed_options.insert(std::make_pair("server", ValueSpec(VALUETYPE_FLAG,
822 _("Run dedicated server"))));
823 allowed_options.insert(std::make_pair("name", ValueSpec(VALUETYPE_STRING,
824 _("Set player name"))));
825 allowed_options.insert(std::make_pair("password", ValueSpec(VALUETYPE_STRING,
826 _("Set password"))));
827 allowed_options.insert(std::make_pair("go", ValueSpec(VALUETYPE_FLAG,
828 _("Disable main menu"))));
833 bool ret = cmd_args.parseCommandLine(argc, argv, allowed_options);
835 if (ret == false || cmd_args.getFlag("help") || cmd_args.exists("nonopt1")) {
836 dstream << _("Allowed options:") << std::endl;
837 for(std::map<std::string, ValueSpec>::iterator
838 i = allowed_options.begin();
839 i != allowed_options.end(); ++i) {
840 std::ostringstream os1(std::ios::binary);
841 os1 << " --"<<i->first;
842 if (i->second.type == VALUETYPE_FLAG) {
844 os1 << _(" <value>");
845 dstream << padStringRight(os1.str(), 24);
847 if (i->second.help != NULL)
848 dstream << i->second.help;
849 dstream << std::endl;
852 return cmd_args.getFlag("help") ? 0 : 1;
855 if (cmd_args.getFlag("version")) {
857 dstream << "minetestserver " << minetest_version_hash << std::endl;
859 dstream << "Minetest " << minetest_version_hash << std::endl;
860 dstream << "Using Irrlicht " << IRRLICHT_SDK_VERSION << std::endl;
862 dstream << "Build info: " << minetest_build_info << std::endl;
867 Low-level initialization
870 // Quiet mode, print errors only
871 if (cmd_args.getFlag("quiet")) {
872 log_remove_output(&main_stderr_log_out);
873 log_add_output_maxlev(&main_stderr_log_out, LMT_ERROR);
875 // If trace is enabled, enable logging of certain things
876 if (cmd_args.getFlag("trace")) {
877 dstream << _("Enabling trace level debug output") << std::endl;
878 log_trace_level_enabled = true;
879 dout_con_ptr = &verbosestream; // this is somewhat old crap
880 socket_enable_debug_output = true; // socket doesn't use log.h
882 // In certain cases, output info level on stderr
883 if (cmd_args.getFlag("info") || cmd_args.getFlag("verbose") ||
884 cmd_args.getFlag("trace") || cmd_args.getFlag("speedtests"))
885 log_add_output(&main_stderr_log_out, LMT_INFO);
886 // In certain cases, output verbose level on stderr
887 if (cmd_args.getFlag("verbose") || cmd_args.getFlag("trace"))
888 log_add_output(&main_stderr_log_out, LMT_VERBOSE);
890 porting::signal_handler_init();
891 bool &kill = *porting::signal_handler_killstatus();
893 porting::initializePaths();
896 porting::initAndroid();
898 porting::setExternalStorageDir(porting::jnienv);
899 if (!fs::PathExists(porting::path_user)) {
900 fs::CreateDir(porting::path_user);
902 porting::copyAssets();
904 // Create user data directory
905 fs::CreateDir(porting::path_user);
908 infostream << "path_share = " << porting::path_share << std::endl;
909 infostream << "path_user = " << porting::path_user << std::endl;
911 // Initialize debug stacks
913 DSTACK(__FUNCTION_NAME);
916 BEGIN_DEBUG_EXCEPTION_HANDLER
918 // List gameids if requested
919 if (cmd_args.exists("gameid") && cmd_args.get("gameid") == "list") {
920 std::set<std::string> gameids = getAvailableGameIds();
921 for(std::set<std::string>::const_iterator i = gameids.begin();
922 i != gameids.end(); i++)
923 dstream<<(*i)<<std::endl;
927 // List worlds if requested
928 if (cmd_args.exists("world") && cmd_args.get("world") == "list") {
929 dstream << _("Available worlds:") << std::endl;
930 std::vector<WorldSpec> worldspecs = getAvailableWorlds();
931 print_worldspecs(worldspecs, dstream);
935 // Print startup message
936 infostream<<PROJECT_NAME << " "<< _("with") << " SER_FMT_VER_HIGHEST_READ="
937 << (int)SER_FMT_VER_HIGHEST_READ << ", " << minetest_build_info << std::endl;
943 // Initialize default settings
944 set_default_settings(g_settings);
946 // Initialize sockets
948 atexit(sockets_cleanup);
954 // Path of configuration file in use
955 g_settings_path = "";
957 if (cmd_args.exists("config")) {
958 bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
960 errorstream << "Could not read configuration from \""
961 << cmd_args.get("config") << "\"" << std::endl;
964 g_settings_path = cmd_args.get("config");
966 std::vector<std::string> filenames;
967 filenames.push_back(porting::path_user +
968 DIR_DELIM + "minetest.conf");
969 // Legacy configuration file location
970 filenames.push_back(porting::path_user +
971 DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
973 // Try also from a lower level (to aid having the same configuration
974 // for many RUN_IN_PLACE installs)
975 filenames.push_back(porting::path_user +
976 DIR_DELIM + ".." + DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
979 for(u32 i = 0; i < filenames.size(); i++) {
980 bool r = g_settings->readConfigFile(filenames[i].c_str());
982 g_settings_path = filenames[i];
987 // If no path found, use the first one (menu creates the file)
988 if (g_settings_path == "")
989 g_settings_path = filenames[0];
992 // Initialize debug streams
993 #define DEBUGFILE "debug.txt"
995 std::string logfile = DEBUGFILE;
997 std::string logfile = porting::path_user+DIR_DELIM+DEBUGFILE;
999 if (cmd_args.exists("logfile"))
1000 logfile = cmd_args.get("logfile");
1002 log_remove_output(&main_dstream_no_stderr_log_out);
1003 int loglevel = g_settings->getS32("debug_log_level");
1005 if (loglevel == 0) //no logging
1007 else if (loglevel > 0 && loglevel <= LMT_NUM_VALUES)
1008 log_add_output_maxlev(&main_dstream_no_stderr_log_out,
1009 (LogMessageLevel)(loglevel - 1));
1012 debugstreams_init(false, logfile.c_str());
1014 debugstreams_init(false, NULL);
1016 infostream << "logfile = " << logfile << std::endl;
1018 // Initialize random seed
1022 // Initialize HTTP fetcher
1023 httpfetch_init(g_settings->getS32("curl_parallel_limit"));
1029 if ((ENABLE_TESTS && cmd_args.getFlag("disable-unittests") == false)
1030 || cmd_args.getFlag("enable-unittests") == true) {
1035 init_gettext((porting::path_share + DIR_DELIM + "locale").c_str(),
1036 g_settings->get("language"), argc, argv);
1038 init_gettext((porting::path_share + DIR_DELIM + "locale").c_str(),
1039 g_settings->get("language"));
1048 if (cmd_args.exists("port"))
1049 port = cmd_args.getU16("port");
1050 else if (g_settings->exists("port"))
1051 port = g_settings->getU16("port");
1056 std::string commanded_world = "";
1057 if (cmd_args.exists("world"))
1058 commanded_world = cmd_args.get("world");
1059 else if (cmd_args.exists("map-dir"))
1060 commanded_world = cmd_args.get("map-dir");
1061 else if (cmd_args.exists("nonopt0")) // First nameless argument
1062 commanded_world = cmd_args.get("nonopt0");
1063 else if (g_settings->exists("map-dir"))
1064 commanded_world = g_settings->get("map-dir");
1067 std::string commanded_worldname = "";
1068 if (cmd_args.exists("worldname"))
1069 commanded_worldname = cmd_args.get("worldname");
1071 // Strip world.mt from commanded_world
1073 std::string worldmt = "world.mt";
1074 if (commanded_world.size() > worldmt.size() &&
1075 commanded_world.substr(commanded_world.size() - worldmt.size())
1077 dstream << _("Supplied world.mt file - stripping it off.") << std::endl;
1078 commanded_world = commanded_world.substr(0,
1079 commanded_world.size() - worldmt.size());
1083 // If a world name was specified, convert it to a path
1084 if (commanded_worldname != "") {
1085 // Get information about available worlds
1086 std::vector<WorldSpec> worldspecs = getAvailableWorlds();
1088 for(u32 i = 0; i < worldspecs.size(); i++) {
1089 std::string name = worldspecs[i].name;
1090 if (name == commanded_worldname) {
1091 if (commanded_world != "") {
1092 dstream << _("--worldname takes precedence over previously "
1093 "selected world.") << std::endl;
1095 commanded_world = worldspecs[i].path;
1101 dstream << _("World") << " '"<<commanded_worldname << _("' not "
1102 "available. Available worlds:") << std::endl;
1103 print_worldspecs(worldspecs, dstream);
1109 SubgameSpec commanded_gamespec;
1110 if (cmd_args.exists("gameid")) {
1111 std::string gameid = cmd_args.get("gameid");
1112 commanded_gamespec = findSubgame(gameid);
1113 if (!commanded_gamespec.isValid()) {
1114 errorstream << "Game \"" << gameid << "\" not found" << std::endl;
1121 Run dedicated server if asked to or no other option
1124 bool run_dedicated_server = true;
1126 bool run_dedicated_server = cmd_args.getFlag("server");
1128 g_settings->set("server_dedicated", run_dedicated_server ? "true" : "false");
1129 if (run_dedicated_server)
1131 DSTACK("Dedicated server branch");
1132 // Create time getter if built with Irrlicht
1134 g_timegetter = new SimpleTimeGetter();
1138 std::string world_path;
1139 verbosestream << _("Determining world path") << std::endl;
1140 bool is_legacy_world = false;
1141 // If a world was commanded, use it
1142 if (commanded_world != "") {
1143 world_path = commanded_world;
1144 infostream << "Using commanded world path [" << world_path << "]"
1146 } else { // No world was specified; try to select it automatically
1147 // Get information about available worlds
1148 std::vector<WorldSpec> worldspecs = getAvailableWorlds();
1149 // If a world name was specified, select it
1150 if (commanded_worldname != "") {
1152 for(u32 i = 0; i < worldspecs.size(); i++) {
1153 std::string name = worldspecs[i].name;
1154 if (name == commanded_worldname) {
1155 world_path = worldspecs[i].path;
1159 if (world_path == "") {
1160 dstream << _("World") << " '" << commanded_worldname << "' " << _("not "
1161 "available. Available worlds:") << std::endl;
1162 print_worldspecs(worldspecs, dstream);
1166 // If there is only a single world, use it
1167 if (worldspecs.size() == 1) {
1168 world_path = worldspecs[0].path;
1169 dstream <<_("Automatically selecting world at") << " ["
1170 << world_path << "]" << std::endl;
1171 // If there are multiple worlds, list them
1172 } else if (worldspecs.size() > 1) {
1173 dstream << _("Multiple worlds are available.") << std::endl;
1174 dstream << _("Please select one using --worldname <name>"
1175 " or --world <path>") << std::endl;
1176 print_worldspecs(worldspecs, dstream);
1178 // If there are no worlds, automatically create a new one
1180 // This is the ultimate default world path
1181 world_path = porting::path_user + DIR_DELIM + "worlds" +
1182 DIR_DELIM + "world";
1183 infostream << "Creating default world at ["
1184 << world_path << "]" << std::endl;
1188 if (world_path == "") {
1189 errorstream << "No world path specified or found." << std::endl;
1192 verbosestream << _("Using world path") << " [" << world_path << "]" << std::endl;
1194 // We need a gamespec.
1195 SubgameSpec gamespec;
1196 verbosestream << _("Determining gameid/gamespec") << std::endl;
1197 // If world doesn't exist
1198 if (!getWorldExists(world_path)) {
1199 // Try to take gamespec from command line
1200 if (commanded_gamespec.isValid()) {
1201 gamespec = commanded_gamespec;
1202 infostream << "Using commanded gameid [" << gamespec.id << "]" << std::endl;
1203 } else { // Otherwise we will be using "minetest"
1204 gamespec = findSubgame(g_settings->get("default_game"));
1205 infostream << "Using default gameid [" << gamespec.id << "]" << std::endl;
1207 } else { // World exists
1208 std::string world_gameid = getWorldGameId(world_path, is_legacy_world);
1209 // If commanded to use a gameid, do so
1210 if (commanded_gamespec.isValid()) {
1211 gamespec = commanded_gamespec;
1212 if (commanded_gamespec.id != world_gameid) {
1213 errorstream << "WARNING: Using commanded gameid ["
1214 << gamespec.id << "]" << " instead of world gameid ["
1215 << world_gameid << "]" << std::endl;
1218 // If world contains an embedded game, use it;
1219 // Otherwise find world from local system.
1220 gamespec = findWorldSubgame(world_path);
1221 infostream << "Using world gameid [" << gamespec.id << "]" << std::endl;
1224 if (!gamespec.isValid()) {
1225 errorstream << "Subgame [" << gamespec.id << "] could not be found."
1229 verbosestream << _("Using gameid") << " [" << gamespec.id<<"]" << std::endl;
1232 std::string bind_str = g_settings->get("bind_address");
1233 Address bind_addr(0, 0, 0, 0, port);
1235 if (g_settings->getBool("ipv6_server")) {
1236 bind_addr.setAddress((IPv6AddressBytes*) NULL);
1239 bind_addr.Resolve(bind_str.c_str());
1240 } catch (ResolveError &e) {
1241 infostream << "Resolving bind address \"" << bind_str
1242 << "\" failed: " << e.what()
1243 << " -- Listening on all addresses." << std::endl;
1245 if (bind_addr.isIPv6() && !g_settings->getBool("enable_ipv6")) {
1246 errorstream << "Unable to listen on "
1247 << bind_addr.serializeString()
1248 << L" because IPv6 is disabled" << std::endl;
1253 Server server(world_path, gamespec, false, bind_addr.isIPv6());
1255 // Database migration
1256 if (cmd_args.exists("migrate")) {
1257 std::string migrate_to = cmd_args.get("migrate");
1259 bool success = world_mt.readConfigFile((world_path + DIR_DELIM
1260 + "world.mt").c_str());
1262 errorstream << "Cannot read world.mt" << std::endl;
1265 if (!world_mt.exists("backend")) {
1266 errorstream << "Please specify your current backend in world.mt file:"
1267 << std::endl << " backend = {sqlite3|leveldb|redis|dummy}" << std::endl;
1270 std::string backend = world_mt.get("backend");
1272 if (backend == migrate_to) {
1273 errorstream << "Cannot migrate: new backend is same"
1274 <<" as the old one" << std::endl;
1277 if (migrate_to == "sqlite3")
1278 new_db = new Database_SQLite3(&(ServerMap&)server.getMap(), world_path);
1280 else if (migrate_to == "leveldb")
1281 new_db = new Database_LevelDB(&(ServerMap&)server.getMap(), world_path);
1284 else if (migrate_to == "redis")
1285 new_db = new Database_Redis(&(ServerMap&)server.getMap(), world_path);
1288 errorstream << "Migration to " << migrate_to
1289 << " is not supported" << std::endl;
1293 std::list<v3s16> blocks;
1294 ServerMap &old_map = ((ServerMap&)server.getMap());
1295 old_map.listAllLoadableBlocks(blocks);
1297 new_db->beginSave();
1298 for (std::list<v3s16>::iterator i = blocks.begin(); i != blocks.end(); i++) {
1299 MapBlock *block = old_map.loadBlock(*i);
1301 errorstream << "Failed to load block " << PP(*i) << ", skipping it.";
1303 old_map.saveBlock(block, new_db);
1304 MapSector *sector = old_map.getSectorNoGenerate(v2s16(i->X, i->Z));
1305 sector->deleteBlock(block);
1308 if (count % 500 == 0)
1309 actionstream << "Migrated " << count << " blocks "
1310 << (100.0 * count / blocks.size()) << "% completed" << std::endl;
1315 actionstream << "Successfully migrated " << count << " blocks" << std::endl;
1316 world_mt.set("backend", migrate_to);
1317 if (!world_mt.updateConfigFile((world_path + DIR_DELIM + "world.mt").c_str()))
1318 errorstream << "Failed to update world.mt!" << std::endl;
1320 actionstream << "world.mt updated" << std::endl;
1325 server.start(bind_addr);
1328 dedicated_server_loop(server, kill);
1333 #ifndef SERVER // Exclude from dedicated server build
1339 std::string address = g_settings->get("address");
1340 if (commanded_world != "")
1342 else if (cmd_args.exists("address"))
1343 address = cmd_args.get("address");
1345 std::string playername = g_settings->get("name");
1346 if (cmd_args.exists("name"))
1347 playername = cmd_args.get("name");
1349 bool skip_main_menu = cmd_args.getFlag("go");
1352 Device initialization
1355 // Resolution selection
1357 bool fullscreen = g_settings->getBool("fullscreen");
1358 u16 screenW = g_settings->getU16("screenW");
1359 u16 screenH = g_settings->getU16("screenH");
1363 bool vsync = g_settings->getBool("vsync");
1364 u16 bits = g_settings->getU16("fullscreen_bpp");
1365 u16 fsaa = g_settings->getU16("fsaa");
1368 video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
1369 static const char* driverids[] = {
1376 #ifdef _IRR_COMPILE_WITH_OGLES1_
1379 #ifdef _IRR_COMPILE_WITH_OGLES2_
1385 std::string driverstring = g_settings->get("video_driver");
1386 for (unsigned int i = 0;
1387 i < (sizeof(driverids)/sizeof(driverids[0]));
1390 if (strcasecmp(driverstring.c_str(), driverids[i]) == 0) {
1391 driverType = (video::E_DRIVER_TYPE) i;
1395 if (strcasecmp("invalid", driverids[i]) == 0) {
1396 errorstream << "WARNING: Invalid video_driver specified; defaulting "
1397 << "to opengl" << std::endl;
1403 List video modes if requested
1405 MyEventReceiver* receiver = new MyEventReceiver();
1407 if (cmd_args.getFlag("videomodes")) {
1408 IrrlichtDevice *nulldevice;
1410 SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
1411 params.DriverType = video::EDT_NULL;
1412 params.WindowSize = core::dimension2d<u32>(640, 480);
1414 params.AntiAlias = fsaa;
1415 params.Fullscreen = false;
1416 params.Stencilbuffer = false;
1417 params.Vsync = vsync;
1418 params.EventReceiver = receiver;
1419 params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
1421 nulldevice = createDeviceEx(params);
1423 if (nulldevice == 0)
1426 dstream << _("Available video modes (WxHxD):") << std::endl;
1428 video::IVideoModeList *videomode_list =
1429 nulldevice->getVideoModeList();
1431 if (videomode_list == 0) {
1436 s32 videomode_count = videomode_list->getVideoModeCount();
1437 core::dimension2d<u32> videomode_res;
1438 s32 videomode_depth;
1439 for (s32 i = 0; i < videomode_count; ++i) {
1440 videomode_res = videomode_list->getVideoModeResolution(i);
1441 videomode_depth = videomode_list->getVideoModeDepth(i);
1442 dstream<<videomode_res.Width << "x" << videomode_res.Height
1443 << "x" << videomode_depth << std::endl;
1446 dstream << _("Active video mode (WxHxD):") << std::endl;
1447 videomode_res = videomode_list->getDesktopResolution();
1448 videomode_depth = videomode_list->getDesktopDepth();
1449 dstream << videomode_res.Width << "x" << videomode_res.Height
1450 << "x" << videomode_depth << std::endl;
1459 Create device and exit if creation failed
1461 SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
1462 params.DriverType = driverType;
1463 params.WindowSize = core::dimension2d<u32>(screenW, screenH);
1465 params.AntiAlias = fsaa;
1466 params.Fullscreen = fullscreen;
1467 params.Stencilbuffer = false;
1468 params.Vsync = vsync;
1469 params.EventReceiver = receiver;
1470 params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
1472 params.PrivateData = porting::app_global;
1473 params.OGLES2ShaderPath = std::string(porting::path_user + DIR_DELIM +
1474 "media" + DIR_DELIM + "Shaders" + DIR_DELIM).c_str();
1477 IrrlichtDevice * device = createDeviceEx(params);
1481 return 1; // could not create selected driver.
1484 // Map our log level to irrlicht engine one.
1485 static const irr::ELOG_LEVEL irr_log_level[5] = {
1490 #if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
1497 ILogger* irr_logger = device->getLogger();
1498 irr_logger->setLogLevel(irr_log_level[loglevel]);
1500 porting::initIrrlicht(device);
1501 late_init_default_settings(g_settings);
1504 Continue initialization
1507 video::IVideoDriver* driver = device->getVideoDriver();
1510 This changes the minimum allowed number of vertices in a VBO.
1513 //driver->setMinHardwareBufferVertexCount(50);
1515 // Create time getter
1516 g_timegetter = new IrrlichtTimeGetter(device);
1518 // Create game callback for menus
1519 g_gamecallback = new MainGameCallback(device);
1522 Speed tests (done after irrlicht is loaded to get timer)
1524 if (cmd_args.getFlag("speedtests"))
1526 dstream << "Running speed tests" << std::endl;
1532 device->setResizable(true);
1534 bool random_input = g_settings->getBool("random_input")
1535 || cmd_args.getFlag("random-input");
1536 InputHandler *input = NULL;
1539 input = new RandomInputHandler();
1541 input = new RealInputHandler(device,receiver);
1544 scene::ISceneManager* smgr = device->getSceneManager();
1546 guienv = device->getGUIEnvironment();
1547 gui::IGUISkin* skin = guienv->getSkin();
1548 std::string font_path = g_settings->get("font_path");
1549 gui::IGUIFont *font;
1551 bool use_freetype = g_settings->getBool("freetype");
1553 std::string fallback;
1554 if (is_yes(gettext("needs_fallback_font")))
1555 fallback = "fallback_";
1556 u16 font_size = g_settings->getU16(fallback + "font_size");
1557 font_path = g_settings->get(fallback + "font_path");
1558 u32 font_shadow = g_settings->getU16(fallback + "font_shadow");
1559 u32 font_shadow_alpha = g_settings->getU16(fallback + "font_shadow_alpha");
1560 font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size,
1561 true, true, font_shadow, font_shadow_alpha);
1563 font = guienv->getFont(font_path.c_str());
1566 font = guienv->getFont(font_path.c_str());
1569 skin->setFont(font);
1571 errorstream << "WARNING: Font file was not found."
1572 << " Using default font." << std::endl;
1573 // If font was not found, this will get us one
1574 font = skin->getFont();
1577 u32 text_height = font->getDimension(L"Hello, world!").Height;
1578 infostream << "text_height=" << text_height << std::endl;
1580 skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255, 255, 255, 255));
1581 skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255, 0, 0, 0));
1582 skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255, 0, 0, 0));
1583 skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 70, 100, 50));
1584 skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255, 255, 255, 255));
1586 #if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2
1587 // Irrlicht 1.8 input colours
1588 skin->setColor(gui::EGDC_EDITABLE, video::SColor(255, 128, 128, 128));
1589 skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255, 96, 134, 49));
1593 // Create the menu clouds
1594 if (!g_menucloudsmgr)
1595 g_menucloudsmgr = smgr->createNewSceneManager();
1597 g_menuclouds = new Clouds(g_menucloudsmgr->getRootSceneNode(),
1598 g_menucloudsmgr, -1, rand(), 100);
1599 g_menuclouds->update(v2f(0, 0), video::SColor(255, 200, 200, 255));
1600 scene::ICameraSceneNode* camera;
1601 camera = g_menucloudsmgr->addCameraSceneNode(0,
1602 v3f(0, 0, 0), v3f(0, 60, 100));
1603 camera->setFarValue(10000);
1609 ChatBackend chat_backend;
1612 If an error occurs, this is set to something and the
1613 menu-game loop is restarted. It is then displayed before
1616 std::wstring error_message = L"";
1618 // The password entered during the menu screen,
1619 std::string password;
1621 bool first_loop = true;
1626 while (device->run() && (kill == false) &&
1627 (g_gamecallback->shutdown_requested == false))
1629 // Set the window caption
1630 wchar_t* text = wgettext("Main Menu");
1631 device->setWindowCaption((std::wstring(L"Minetest [") + text + L"]").c_str());
1634 // This is used for catching disconnects
1639 Clear everything from the GUIEnvironment
1644 We need some kind of a root node to be able to add
1645 custom gui elements directly on the screen.
1646 Otherwise they won't be automatically drawn.
1648 guiroot = guienv->addStaticText(L"",
1649 core::rect<s32>(0, 0, 10000, 10000));
1651 SubgameSpec gamespec;
1652 WorldSpec worldspec;
1653 bool simple_singleplayer_mode = false;
1655 // These are set up based on the menu and other things
1656 std::string current_playername = "inv£lid";
1657 std::string current_password = "";
1658 std::string current_address = "does-not-exist";
1659 int current_port = 0;
1662 Out-of-game menu loop.
1664 Loop quits when menu returns proper parameters.
1666 while (kill == false) {
1667 // If skip_main_menu, only go through here once
1668 if (skip_main_menu && !first_loop) {
1674 // Cursor can be non-visible when coming from the game
1676 device->getCursorControl()->setVisible(true);
1678 // Some stuff are left to scene manager when coming from the game
1682 // Initialize menu data
1683 MainMenuData menudata;
1684 menudata.address = address;
1685 menudata.name = playername;
1686 menudata.port = itos(port);
1687 menudata.errormessage = wide_to_narrow(error_message);
1688 error_message = L"";
1689 if (cmd_args.exists("password"))
1690 menudata.password = cmd_args.get("password");
1692 driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map"));
1694 menudata.enable_public = g_settings->getBool("server_announce");
1696 std::vector<WorldSpec> worldspecs = getAvailableWorlds();
1698 // If a world was commanded, append and select it
1699 if(commanded_world != "") {
1700 worldspec.gameid = getWorldGameId(commanded_world, true);
1701 worldspec.name = _("[--world parameter]");
1702 if(worldspec.gameid == "") {
1703 worldspec.gameid = g_settings->get("default_game");
1704 worldspec.name += " [new]";
1706 worldspec.path = commanded_world;
1709 if (skip_main_menu == false) {
1710 video::IVideoDriver* driver = device->getVideoDriver();
1712 infostream << "Waiting for other menus" << std::endl;
1713 while (device->run() && kill == false) {
1716 driver->beginScene(true, true,
1717 video::SColor(255, 128, 128, 128));
1720 // On some computers framerate doesn't seem to be
1721 // automatically limited
1724 infostream << "Waited for other menus" << std::endl;
1726 /* show main menu */
1727 GUIEngine mymenu(device, guiroot, &g_menumgr,smgr,&menudata,kill);
1729 //once finished you'll never end up here
1733 if (menudata.errormessage != "") {
1734 error_message = narrow_to_wide(menudata.errormessage);
1738 //update worldspecs (necessary as new world may have been created)
1739 worldspecs = getAvailableWorlds();
1741 if (menudata.name == "")
1742 menudata.name = std::string("Guest") + itos(myrand_range(1000,9999));
1744 playername = menudata.name;
1746 password = translatePassword(playername, narrow_to_wide(menudata.password));
1747 //infostream<<"Main: password hash: '"<<password<<"'"<<std::endl;
1749 address = menudata.address;
1750 int newport = stoi(menudata.port);
1754 simple_singleplayer_mode = menudata.simple_singleplayer_mode;
1757 g_settings->set("name", playername);
1759 // Break out of menu-game loop to shut down cleanly
1760 if (device->run() == false || kill == true)
1763 current_playername = playername;
1764 current_password = password;
1765 current_address = address;
1766 current_port = port;
1768 // If using simple singleplayer mode, override
1769 if (simple_singleplayer_mode) {
1770 current_playername = "singleplayer";
1771 current_password = "";
1772 current_address = "";
1773 current_port = myrand_range(49152, 65535);
1774 } else if (address != "") {
1775 ServerListSpec server;
1776 server["name"] = menudata.servername;
1777 server["address"] = menudata.address;
1778 server["port"] = menudata.port;
1779 server["description"] = menudata.serverdescription;
1780 ServerList::insert(server);
1783 if ((!skip_main_menu) &&
1784 (menudata.selected_world >= 0) &&
1785 (menudata.selected_world < (int)worldspecs.size())) {
1786 g_settings->set("selected_world_path",
1787 worldspecs[menudata.selected_world].path);
1788 worldspec = worldspecs[menudata.selected_world];
1792 infostream <<"Selected world: " << worldspec.name
1793 << " ["<<worldspec.path<<"]" <<std::endl;
1797 if (current_address == "") {
1798 if (worldspec.path == "") {
1799 error_message = wgettext("No world selected and no address "
1800 "provided. Nothing to do.");
1801 errorstream << wide_to_narrow(error_message) << std::endl;
1805 if (!fs::PathExists(worldspec.path)) {
1806 error_message = wgettext("Provided world path doesn't exist: ")
1807 + narrow_to_wide(worldspec.path);
1808 errorstream << wide_to_narrow(error_message) << std::endl;
1812 // Load gamespec for required game
1813 gamespec = findWorldSubgame(worldspec.path);
1814 if (!gamespec.isValid() && !commanded_gamespec.isValid()) {
1815 error_message = wgettext("Could not find or load game \"")
1816 + narrow_to_wide(worldspec.gameid) + L"\"";
1817 errorstream << wide_to_narrow(error_message) << std::endl;
1820 if (commanded_gamespec.isValid() &&
1821 commanded_gamespec.id != worldspec.gameid) {
1822 errorstream<<"WARNING: Overriding gamespec from \""
1823 << worldspec.gameid << "\" to \""
1824 << commanded_gamespec.id << "\"" << std::endl;
1825 gamespec = commanded_gamespec;
1828 if (!gamespec.isValid()) {
1829 error_message = wgettext("Invalid gamespec.");
1830 error_message += L" (world_gameid="
1831 + narrow_to_wide(worldspec.gameid) + L")";
1832 errorstream << wide_to_narrow(error_message) << std::endl;
1841 // Break out of menu-game loop to shut down cleanly
1842 if (device->run() == false || kill == true) {
1843 if (g_settings_path != "") {
1844 g_settings->updateConfigFile(g_settings_path.c_str());
1849 if (current_playername.length() > PLAYERNAME_SIZE-1) {
1850 error_message = wgettext("Player name too long.");
1851 playername = current_playername.substr(0,PLAYERNAME_SIZE-1);
1852 g_settings->set("name", playername);
1859 #ifdef HAVE_TOUCHSCREENGUI
1860 receiver->m_touchscreengui = new TouchScreenGUI(device, receiver);
1861 g_touchscreengui = receiver->m_touchscreengui;
1877 simple_singleplayer_mode
1880 #ifdef HAVE_TOUCHSCREENGUI
1881 delete g_touchscreengui;
1882 g_touchscreengui = NULL;
1883 receiver->m_touchscreengui = NULL;
1887 catch(con::PeerNotFoundException &e)
1889 error_message = wgettext("Connection error (timed out?)");
1890 errorstream << wide_to_narrow(error_message) << std::endl;
1893 catch(std::exception &e)
1895 std::string narrow_message = "Some exception: \"";
1896 narrow_message += e.what();
1897 narrow_message += "\"";
1898 errorstream << narrow_message << std::endl;
1899 error_message = narrow_to_wide(narrow_message);
1903 // If no main menu, show error and exit
1904 if (skip_main_menu) {
1905 if (error_message != L"") {
1906 verbosestream << "error_message = "
1907 << wide_to_narrow(error_message) << std::endl;
1915 g_menuclouds->drop();
1916 g_menucloudsmgr->drop();
1921 In the end, delete the Irrlicht device.
1932 // Update configuration file
1933 if (g_settings_path != "")
1934 g_settings->updateConfigFile(g_settings_path.c_str());
1936 // Print modified quicktune values
1938 bool header_printed = false;
1939 std::vector<std::string> names = getQuicktuneNames();
1940 for(u32 i = 0; i < names.size(); i++) {
1941 QuicktuneValue val = getQuicktuneValue(names[i]);
1944 if (!header_printed) {
1945 dstream << "Modified quicktune values:" << std::endl;
1946 header_printed = true;
1948 dstream<<names[i] << " = " << val.getString() << std::endl;
1952 // Stop httpfetch thread (if started)
1953 httpfetch_cleanup();
1955 END_DEBUG_EXCEPTION_HANDLER(errorstream)
1957 debugstreams_deinit();