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();
83 ITextureSource *g_texturesource = NULL;
90 std::ostream *dout_con_ptr = &dummyout;
91 std::ostream *derr_con_ptr = &dstream_no_stderr;
94 std::ostream *dout_server_ptr = &dstream;
95 std::ostream *derr_server_ptr = &dstream;
98 std::ostream *dout_client_ptr = &dstream;
99 std::ostream *derr_client_ptr = &dstream;
103 gettime.h implementation
109 Use imprecise system calls directly (from porting.h)
111 return porting::getTimeMs();
114 int main(int argc, char *argv[])
117 Low-level initialization
120 bool disable_stderr = false;
122 disable_stderr = true;
125 // Initialize debug streams
126 debugstreams_init(disable_stderr, DEBUGFILE);
127 // Initialize debug stacks
130 DSTACK(__FUNCTION_NAME);
132 porting::initializePaths();
134 initializeMaterialProperties();
136 BEGIN_DEBUG_EXCEPTION_HANDLER
138 // Print startup message
139 dstream<<DTIME<<"minetest-c55"
140 " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
151 // List all allowed options
152 core::map<std::string, ValueSpec> allowed_options;
153 allowed_options.insert("help", ValueSpec(VALUETYPE_FLAG));
154 allowed_options.insert("config", ValueSpec(VALUETYPE_STRING,
155 "Load configuration from specified file"));
156 allowed_options.insert("port", ValueSpec(VALUETYPE_STRING));
157 allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG));
158 allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG));
159 allowed_options.insert("map-dir", ValueSpec(VALUETYPE_STRING));
163 bool ret = cmd_args.parseCommandLine(argc, argv, allowed_options);
165 if(ret == false || cmd_args.getFlag("help"))
167 dstream<<"Allowed options:"<<std::endl;
168 for(core::map<std::string, ValueSpec>::Iterator
169 i = allowed_options.getIterator();
170 i.atEnd() == false; i++)
172 dstream<<" --"<<i.getNode()->getKey();
173 if(i.getNode()->getValue().type == VALUETYPE_FLAG)
182 if(i.getNode()->getValue().help != NULL)
184 dstream<<" "<<i.getNode()->getValue().help
189 return cmd_args.getFlag("help") ? 0 : 1;
197 // Initialize default settings
198 set_default_settings();
200 // Set locale. This is for forcing '.' as the decimal point.
201 std::locale::global(std::locale("C"));
202 // This enables printing all characters in bitmap font
203 setlocale(LC_CTYPE, "en_US");
205 // Initialize sockets
207 atexit(sockets_cleanup);
217 // Path of configuration file in use
218 std::string configpath = "";
220 if(cmd_args.exists("config"))
222 bool r = g_settings.readConfigFile(cmd_args.get("config").c_str());
225 dstream<<"Could not read configuration from \""
226 <<cmd_args.get("config")<<"\""<<std::endl;
229 configpath = cmd_args.get("config");
233 core::array<std::string> filenames;
234 filenames.push_back(porting::path_userdata + "/minetest.conf");
236 filenames.push_back(porting::path_userdata + "/../minetest.conf");
239 for(u32 i=0; i<filenames.size(); i++)
241 bool r = g_settings.readConfigFile(filenames[i].c_str());
244 configpath = filenames[i];
250 // Initialize random seed
257 if((ENABLE_TESTS && cmd_args.getFlag("disable-unittests") == false)
258 || cmd_args.getFlag("enable-unittests") == true)
272 std::cout<<std::endl<<std::endl;
275 <<" .__ __ __ "<<std::endl
276 <<" _____ |__| ____ _____/ |_ ____ _______/ |_ "<<std::endl
277 <<" / \\| |/ \\_/ __ \\ __\\/ __ \\ / ___/\\ __\\"<<std::endl
278 <<"| Y Y \\ | | \\ ___/| | \\ ___/ \\___ \\ | | "<<std::endl
279 <<"|__|_| /__|___| /\\___ >__| \\___ >____ > |__| "<<std::endl
280 <<" \\/ \\/ \\/ \\/ \\/ "<<std::endl
283 std::cout<<std::endl;
287 if(cmd_args.exists("port") && cmd_args.getU16("port") != 0)
289 port = cmd_args.getU16("port");
291 else if(g_settings.exists("port") && g_settings.getU16("port") != 0)
293 port = g_settings.getU16("port");
297 dstream<<"Please specify port (in config or on command line)"
301 // Figure out path to map
302 std::string map_dir = porting::path_userdata+"/map";
303 if(cmd_args.exists("map-dir"))
304 map_dir = cmd_args.get("map-dir");
305 else if(g_settings.exists("map-dir"))
306 map_dir = g_settings.get("map-dir");
309 Server server(map_dir.c_str());
313 dedicated_server_loop(server);
316 catch(con::PeerNotFoundException &e)
318 dstream<<DTIME<<"Connection timed out."<<std::endl;
321 END_DEBUG_EXCEPTION_HANDLER
323 debugstreams_deinit();