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"
73 #include "defaultsettings.h"
79 These are loaded from the config file.
81 Settings main_settings;
82 Settings *g_settings = &main_settings;
85 Profiler main_profiler;
86 Profiler *g_profiler = &main_profiler;
89 ITextureSource *g_texturesource = NULL;
96 std::ostream *dout_con_ptr = &dummyout;
97 std::ostream *derr_con_ptr = &dstream_no_stderr;
100 std::ostream *dout_server_ptr = &dstream;
101 std::ostream *derr_server_ptr = &dstream;
104 std::ostream *dout_client_ptr = &dstream;
105 std::ostream *derr_client_ptr = &dstream;
108 gettime.h implementation
114 Use imprecise system calls directly (from porting.h)
116 return porting::getTimeMs();
119 int main(int argc, char *argv[])
125 // Set locale. This is for forcing '.' as the decimal point.
126 std::locale::global(std::locale("C"));
127 // This enables printing all characters in bitmap font
128 setlocale(LC_CTYPE, "en_US");
131 Low-level initialization
134 bool disable_stderr = false;
136 disable_stderr = true;
139 porting::signal_handler_init();
140 bool &kill = *porting::signal_handler_killstatus();
142 // Initialize porting::path_data and porting::path_userdata
143 porting::initializePaths();
145 // Create user data directory
146 fs::CreateDir(porting::path_userdata);
148 // Initialize debug streams
150 std::string debugfile = DEBUGFILE;
152 std::string debugfile = porting::path_userdata+"/"+DEBUGFILE;
154 debugstreams_init(disable_stderr, debugfile.c_str());
155 // Initialize debug stacks
158 DSTACK(__FUNCTION_NAME);
160 // Init material properties table
161 //initializeMaterialProperties();
164 BEGIN_DEBUG_EXCEPTION_HANDLER
166 // Print startup message
167 dstream<<DTIME<<PROJECT_NAME <<
168 " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
179 // List all allowed options
180 core::map<std::string, ValueSpec> allowed_options;
181 allowed_options.insert("help", ValueSpec(VALUETYPE_FLAG));
182 allowed_options.insert("config", ValueSpec(VALUETYPE_STRING,
183 "Load configuration from specified file"));
184 allowed_options.insert("port", ValueSpec(VALUETYPE_STRING));
185 allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG));
186 allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG));
187 allowed_options.insert("map-dir", ValueSpec(VALUETYPE_STRING));
191 bool ret = cmd_args.parseCommandLine(argc, argv, allowed_options);
193 if(ret == false || cmd_args.getFlag("help"))
195 dstream<<"Allowed options:"<<std::endl;
196 for(core::map<std::string, ValueSpec>::Iterator
197 i = allowed_options.getIterator();
198 i.atEnd() == false; i++)
200 dstream<<" --"<<i.getNode()->getKey();
201 if(i.getNode()->getValue().type == VALUETYPE_FLAG)
210 if(i.getNode()->getValue().help != NULL)
212 dstream<<" "<<i.getNode()->getValue().help
217 return cmd_args.getFlag("help") ? 0 : 1;
225 // Initialize default settings
226 set_default_settings(g_settings);
228 // Initialize sockets
230 atexit(sockets_cleanup);
236 // Path of configuration file in use
237 std::string configpath = "";
239 if(cmd_args.exists("config"))
241 bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
244 dstream<<"Could not read configuration from \""
245 <<cmd_args.get("config")<<"\""<<std::endl;
248 configpath = cmd_args.get("config");
252 core::array<std::string> filenames;
253 filenames.push_back(porting::path_userdata + "/minetest.conf");
255 filenames.push_back(porting::path_userdata + "/../minetest.conf");
258 for(u32 i=0; i<filenames.size(); i++)
260 bool r = g_settings->readConfigFile(filenames[i].c_str());
263 configpath = filenames[i];
269 // Initialize random seed
281 if((ENABLE_TESTS && cmd_args.getFlag("disable-unittests") == false)
282 || cmd_args.getFlag("enable-unittests") == true)
291 std::cout<<std::endl<<std::endl;
294 <<" .__ __ __ "<<std::endl
295 <<" _____ |__| ____ _____/ |_ ____ _______/ |_ "<<std::endl
296 <<" / \\| |/ \\_/ __ \\ __\\/ __ \\ / ___/\\ __\\"<<std::endl
297 <<"| Y Y \\ | | \\ ___/| | \\ ___/ \\___ \\ | | "<<std::endl
298 <<"|__|_| /__|___| /\\___ >__| \\___ >____ > |__| "<<std::endl
299 <<" \\/ \\/ \\/ \\/ \\/ "<<std::endl
302 std::cout<<std::endl;
306 if(cmd_args.exists("port") && cmd_args.getU16("port") != 0)
308 port = cmd_args.getU16("port");
310 else if(g_settings->exists("port") && g_settings->getU16("port") != 0)
312 port = g_settings->getU16("port");
316 dstream<<"Please specify port (in config or on command line)"
320 // Figure out path to map
321 std::string map_dir = porting::path_userdata+"/world";
322 if(cmd_args.exists("map-dir"))
323 map_dir = cmd_args.get("map-dir");
324 else if(g_settings->exists("map-dir"))
325 map_dir = g_settings->get("map-dir");
328 Server server(map_dir.c_str(), configpath);
332 dedicated_server_loop(server, kill);
335 catch(con::PeerNotFoundException &e)
337 dstream<<DTIME<<"Connection timed out."<<std::endl;
340 END_DEBUG_EXCEPTION_HANDLER
342 debugstreams_deinit();