3 Copyright (C) 2010 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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
15 You should have received a copy of the GNU 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.
21 =============================== NOTES ==============================
28 #pragma error ("For a server build, SERVER must be defined globally")
30 #error "For a server build, SERVER must be defined globally"
36 #pragma message ("Disabling unit tests")
38 #warning "Disabling unit tests"
41 #define ENABLE_TESTS 0
44 #define ENABLE_TESTS 1
48 #pragma comment(lib, "jthread.lib")
49 #pragma comment(lib, "zlibwapi.lib")
55 #include <jmutexautolock.h>
57 #include "common_irrlicht.h"
63 #include "environment.h"
65 #include "serialization.h"
66 #include "constants.h"
69 #include "materials.h"
75 These are loaded from the config file.
80 extern void set_default_settings();
87 std::ostream *dout_con_ptr = &dummyout;
88 std::ostream *derr_con_ptr = &dstream_no_stderr;
91 std::ostream *dout_server_ptr = &dstream;
92 std::ostream *derr_server_ptr = &dstream;
95 std::ostream *dout_client_ptr = &dstream;
96 std::ostream *derr_client_ptr = &dstream;
100 gettime.h implementation
106 Use imprecise system calls directly (from porting.h)
108 return porting::getTimeMs();
111 int main(int argc, char *argv[])
114 Low-level initialization
117 bool disable_stderr = false;
119 disable_stderr = true;
122 // Initialize debug streams
123 debugstreams_init(disable_stderr, DEBUGFILE);
124 // Initialize debug stacks
127 DSTACK(__FUNCTION_NAME);
129 porting::initializePaths();
131 initializeMaterialProperties();
133 BEGIN_DEBUG_EXCEPTION_HANDLER
135 // Print startup message
136 dstream<<DTIME<<"minetest-c55"
137 " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
148 // List all allowed options
149 core::map<std::string, ValueSpec> allowed_options;
150 allowed_options.insert("help", ValueSpec(VALUETYPE_FLAG));
151 allowed_options.insert("config", ValueSpec(VALUETYPE_STRING,
152 "Load configuration from specified file"));
153 allowed_options.insert("port", ValueSpec(VALUETYPE_STRING));
154 allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG));
155 allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG));
156 allowed_options.insert("map-dir", ValueSpec(VALUETYPE_STRING));
160 bool ret = cmd_args.parseCommandLine(argc, argv, allowed_options);
162 if(ret == false || cmd_args.getFlag("help"))
164 dstream<<"Allowed options:"<<std::endl;
165 for(core::map<std::string, ValueSpec>::Iterator
166 i = allowed_options.getIterator();
167 i.atEnd() == false; i++)
169 dstream<<" --"<<i.getNode()->getKey();
170 if(i.getNode()->getValue().type == VALUETYPE_FLAG)
179 if(i.getNode()->getValue().help != NULL)
181 dstream<<" "<<i.getNode()->getValue().help
186 return cmd_args.getFlag("help") ? 0 : 1;
194 // Initialize default settings
195 set_default_settings();
197 // Set locale. This is for forcing '.' as the decimal point.
198 std::locale::global(std::locale("C"));
199 // This enables printing all characters in bitmap font
200 setlocale(LC_CTYPE, "en_US");
202 // Initialize sockets
204 atexit(sockets_cleanup);
214 // Path of configuration file in use
215 std::string configpath = "";
217 if(cmd_args.exists("config"))
219 bool r = g_settings.readConfigFile(cmd_args.get("config").c_str());
222 dstream<<"Could not read configuration from \""
223 <<cmd_args.get("config")<<"\""<<std::endl;
226 configpath = cmd_args.get("config");
230 core::array<std::string> filenames;
231 filenames.push_back(porting::path_userdata + "/minetest.conf");
233 filenames.push_back(porting::path_userdata + "/../minetest.conf");
236 for(u32 i=0; i<filenames.size(); i++)
238 bool r = g_settings.readConfigFile(filenames[i].c_str());
241 configpath = filenames[i];
247 // Initialize random seed
254 if((ENABLE_TESTS && cmd_args.getFlag("disable-unittests") == false)
255 || cmd_args.getFlag("enable-unittests") == true)
262 IIrrlichtWrapper irrlicht; // Dummy
263 init_mapnode(&irrlicht);
264 init_mineral(&irrlicht);
266 // Read map parameters from settings
269 /*hm_params.blocksize = g_settings.getU16("heightmap_blocksize");
270 hm_params.randmax = g_settings.get("height_randmax");
271 hm_params.randfactor = g_settings.get("height_randfactor");
272 hm_params.base = g_settings.get("height_base");*/
274 MapParams map_params;
275 map_params.plants_amount = g_settings.getFloat("plants_amount");
276 map_params.ravines_amount = g_settings.getFloat("ravines_amount");
282 std::cout<<std::endl<<std::endl;
285 <<" .__ __ __ "<<std::endl
286 <<" _____ |__| ____ _____/ |_ ____ _______/ |_ "<<std::endl
287 <<" / \\| |/ \\_/ __ \\ __\\/ __ \\ / ___/\\ __\\"<<std::endl
288 <<"| Y Y \\ | | \\ ___/| | \\ ___/ \\___ \\ | | "<<std::endl
289 <<"|__|_| /__|___| /\\___ >__| \\___ >____ > |__| "<<std::endl
290 <<" \\/ \\/ \\/ \\/ \\/ "<<std::endl
293 std::cout<<std::endl;
297 if(cmd_args.exists("port") && cmd_args.getU16("port") != 0)
299 port = cmd_args.getU16("port");
301 else if(g_settings.exists("port") && g_settings.getU16("port") != 0)
303 port = g_settings.getU16("port");
307 dstream<<"Please specify port (in config or on command line)"
311 // Figure out path to map
312 std::string map_dir = porting::path_userdata+"/map";
313 if(cmd_args.exists("map-dir"))
314 map_dir = cmd_args.get("map-dir");
315 else if(g_settings.exists("map-dir"))
316 map_dir = g_settings.get("map-dir");
319 Server server(map_dir.c_str(), hm_params, map_params);
323 dedicated_server_loop(server);
326 catch(con::PeerNotFoundException &e)
328 dstream<<DTIME<<"Connection timed out."<<std::endl;
331 END_DEBUG_EXCEPTION_HANDLER
333 debugstreams_deinit();