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"
74 These are loaded from the config file.
79 extern void set_default_settings();
86 std::ostream *dout_con_ptr = &dummyout;
87 std::ostream *derr_con_ptr = &dstream_no_stderr;
90 std::ostream *dout_server_ptr = &dstream;
91 std::ostream *derr_server_ptr = &dstream;
94 std::ostream *dout_client_ptr = &dstream;
95 std::ostream *derr_client_ptr = &dstream;
99 gettime.h implementation
105 Use imprecise system calls directly (from porting.h)
107 return porting::getTimeMs();
110 int main(int argc, char *argv[])
113 Low-level initialization
116 bool disable_stderr = false;
118 disable_stderr = true;
121 // Initialize debug streams
122 debugstreams_init(disable_stderr, DEBUGFILE);
123 // Initialize debug stacks
126 DSTACK(__FUNCTION_NAME);
128 porting::initializePaths();
130 initializeMaterialProperties();
132 BEGIN_DEBUG_EXCEPTION_HANDLER
134 // Print startup message
135 dstream<<DTIME<<"minetest-c55"
136 " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
147 // List all allowed options
148 core::map<std::string, ValueSpec> allowed_options;
149 allowed_options.insert("help", ValueSpec(VALUETYPE_FLAG));
150 allowed_options.insert("config", ValueSpec(VALUETYPE_STRING,
151 "Load configuration from specified file"));
152 allowed_options.insert("port", ValueSpec(VALUETYPE_STRING));
153 allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG));
154 allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG));
155 allowed_options.insert("map-dir", ValueSpec(VALUETYPE_STRING));
159 bool ret = cmd_args.parseCommandLine(argc, argv, allowed_options);
161 if(ret == false || cmd_args.getFlag("help"))
163 dstream<<"Allowed options:"<<std::endl;
164 for(core::map<std::string, ValueSpec>::Iterator
165 i = allowed_options.getIterator();
166 i.atEnd() == false; i++)
168 dstream<<" --"<<i.getNode()->getKey();
169 if(i.getNode()->getValue().type == VALUETYPE_FLAG)
178 if(i.getNode()->getValue().help != NULL)
180 dstream<<" "<<i.getNode()->getValue().help
185 return cmd_args.getFlag("help") ? 0 : 1;
193 // Initialize default settings
194 set_default_settings();
196 // Set locale. This is for forcing '.' as the decimal point.
197 std::locale::global(std::locale("C"));
198 // This enables printing all characters in bitmap font
199 setlocale(LC_CTYPE, "en_US");
201 // Initialize sockets
203 atexit(sockets_cleanup);
213 // Path of configuration file in use
214 std::string configpath = "";
216 if(cmd_args.exists("config"))
218 bool r = g_settings.readConfigFile(cmd_args.get("config").c_str());
221 dstream<<"Could not read configuration from \""
222 <<cmd_args.get("config")<<"\""<<std::endl;
225 configpath = cmd_args.get("config");
229 core::array<std::string> filenames;
230 filenames.push_back(porting::path_userdata + "/minetest.conf");
232 filenames.push_back(porting::path_userdata + "/../minetest.conf");
235 for(u32 i=0; i<filenames.size(); i++)
237 bool r = g_settings.readConfigFile(filenames[i].c_str());
240 configpath = filenames[i];
246 // Initialize random seed
253 if((ENABLE_TESTS && cmd_args.getFlag("disable-unittests") == false)
254 || cmd_args.getFlag("enable-unittests") == true)
259 // Read map parameters from settings
262 /*hm_params.blocksize = g_settings.getU16("heightmap_blocksize");
263 hm_params.randmax = g_settings.get("height_randmax");
264 hm_params.randfactor = g_settings.get("height_randfactor");
265 hm_params.base = g_settings.get("height_base");*/
267 MapParams map_params;
268 map_params.plants_amount = g_settings.getFloat("plants_amount");
269 map_params.ravines_amount = g_settings.getFloat("ravines_amount");
275 std::cout<<std::endl<<std::endl;
278 <<" .__ __ __ "<<std::endl
279 <<" _____ |__| ____ _____/ |_ ____ _______/ |_ "<<std::endl
280 <<" / \\| |/ \\_/ __ \\ __\\/ __ \\ / ___/\\ __\\"<<std::endl
281 <<"| Y Y \\ | | \\ ___/| | \\ ___/ \\___ \\ | | "<<std::endl
282 <<"|__|_| /__|___| /\\___ >__| \\___ >____ > |__| "<<std::endl
283 <<" \\/ \\/ \\/ \\/ \\/ "<<std::endl
286 std::cout<<std::endl;
290 if(cmd_args.exists("port") && cmd_args.getU16("port") != 0)
292 port = cmd_args.getU16("port");
294 else if(g_settings.exists("port") && g_settings.getU16("port") != 0)
296 port = g_settings.getU16("port");
300 dstream<<"Please specify port (in config or on command line)"
304 // Figure out path to map
305 std::string map_dir = porting::path_userdata+"/map";
306 if(cmd_args.exists("map-dir"))
307 map_dir = cmd_args.get("map-dir");
308 else if(g_settings.exists("map-dir"))
309 map_dir = g_settings.get("map-dir");
312 Server server(map_dir.c_str(), hm_params, map_params);
316 dedicated_server_loop(server);
319 catch(con::PeerNotFoundException &e)
321 dstream<<DTIME<<"Connection timed out."<<std::endl;
324 END_DEBUG_EXCEPTION_HANDLER
326 debugstreams_deinit();