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;
102 gettime.h implementation
108 Use imprecise system calls directly (from porting.h)
110 return porting::getTimeMs();
113 int main(int argc, char *argv[])
116 Low-level initialization
119 bool disable_stderr = false;
121 disable_stderr = true;
124 // Initialize debug streams
125 debugstreams_init(disable_stderr, DEBUGFILE);
126 // Initialize debug stacks
129 DSTACK(__FUNCTION_NAME);
131 porting::signal_handler_init();
132 bool &kill = *porting::signal_handler_killstatus();
134 porting::initializePaths();
136 initializeMaterialProperties();
138 BEGIN_DEBUG_EXCEPTION_HANDLER
140 // Print startup message
141 dstream<<DTIME<<"minetest-c55"
142 " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
153 // List all allowed options
154 core::map<std::string, ValueSpec> allowed_options;
155 allowed_options.insert("help", ValueSpec(VALUETYPE_FLAG));
156 allowed_options.insert("config", ValueSpec(VALUETYPE_STRING,
157 "Load configuration from specified file"));
158 allowed_options.insert("port", ValueSpec(VALUETYPE_STRING));
159 allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG));
160 allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG));
161 allowed_options.insert("map-dir", ValueSpec(VALUETYPE_STRING));
165 bool ret = cmd_args.parseCommandLine(argc, argv, allowed_options);
167 if(ret == false || cmd_args.getFlag("help"))
169 dstream<<"Allowed options:"<<std::endl;
170 for(core::map<std::string, ValueSpec>::Iterator
171 i = allowed_options.getIterator();
172 i.atEnd() == false; i++)
174 dstream<<" --"<<i.getNode()->getKey();
175 if(i.getNode()->getValue().type == VALUETYPE_FLAG)
184 if(i.getNode()->getValue().help != NULL)
186 dstream<<" "<<i.getNode()->getValue().help
191 return cmd_args.getFlag("help") ? 0 : 1;
199 // Initialize default settings
200 set_default_settings();
202 // Set locale. This is for forcing '.' as the decimal point.
203 std::locale::global(std::locale("C"));
204 // This enables printing all characters in bitmap font
205 setlocale(LC_CTYPE, "en_US");
207 // Initialize sockets
209 atexit(sockets_cleanup);
219 // Path of configuration file in use
220 std::string configpath = "";
222 if(cmd_args.exists("config"))
224 bool r = g_settings.readConfigFile(cmd_args.get("config").c_str());
227 dstream<<"Could not read configuration from \""
228 <<cmd_args.get("config")<<"\""<<std::endl;
231 configpath = cmd_args.get("config");
235 core::array<std::string> filenames;
236 filenames.push_back(porting::path_userdata + "/minetest.conf");
238 filenames.push_back(porting::path_userdata + "/../minetest.conf");
241 for(u32 i=0; i<filenames.size(); i++)
243 bool r = g_settings.readConfigFile(filenames[i].c_str());
246 configpath = filenames[i];
252 // Initialize random seed
264 if((ENABLE_TESTS && cmd_args.getFlag("disable-unittests") == false)
265 || cmd_args.getFlag("enable-unittests") == true)
274 std::cout<<std::endl<<std::endl;
277 <<" .__ __ __ "<<std::endl
278 <<" _____ |__| ____ _____/ |_ ____ _______/ |_ "<<std::endl
279 <<" / \\| |/ \\_/ __ \\ __\\/ __ \\ / ___/\\ __\\"<<std::endl
280 <<"| Y Y \\ | | \\ ___/| | \\ ___/ \\___ \\ | | "<<std::endl
281 <<"|__|_| /__|___| /\\___ >__| \\___ >____ > |__| "<<std::endl
282 <<" \\/ \\/ \\/ \\/ \\/ "<<std::endl
285 std::cout<<std::endl;
289 if(cmd_args.exists("port") && cmd_args.getU16("port") != 0)
291 port = cmd_args.getU16("port");
293 else if(g_settings.exists("port") && g_settings.getU16("port") != 0)
295 port = g_settings.getU16("port");
299 dstream<<"Please specify port (in config or on command line)"
303 // Figure out path to map
304 std::string map_dir = porting::path_userdata+"/map";
305 if(cmd_args.exists("map-dir"))
306 map_dir = cmd_args.get("map-dir");
307 else if(g_settings.exists("map-dir"))
308 map_dir = g_settings.get("map-dir");
311 Server server(map_dir.c_str());
315 dedicated_server_loop(server, kill);
318 catch(con::PeerNotFoundException &e)
320 dstream<<DTIME<<"Connection timed out."<<std::endl;
323 END_DEBUG_EXCEPTION_HANDLER
325 debugstreams_deinit();