X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fservermain.cpp;h=64853604b1a8ec64c11de1411005e66dec95a43f;hb=8492796a5c45787810aad7fe08fc63cadc0c96b5;hp=70f11cba3ac6006f765f801b6132c03a90880704;hpb=6350c5d7a606924a12ba41468d126ff94d9e6d36;p=oweals%2Fminetest.git diff --git a/src/servermain.cpp b/src/servermain.cpp index 70f11cba3..64853604b 100644 --- a/src/servermain.cpp +++ b/src/servermain.cpp @@ -20,18 +20,18 @@ with this program; if not, write to the Free Software Foundation, Inc., /* =============================== NOTES ============================== -TODO: Move the default settings into some separate file */ #ifndef SERVER #ifdef _WIN32 + #pragma error ("For a server build, SERVER must be defined globally") #else #error "For a server build, SERVER must be defined globally" #endif #endif -#ifdef UNITTEST_DISABLE +#ifdef NDEBUG #ifdef _WIN32 #pragma message ("Disabling unit tests") #else @@ -49,15 +49,6 @@ TODO: Move the default settings into some separate file #pragma comment(lib, "zlibwapi.lib") #endif -#ifdef _WIN32 - #define WIN32_LEAN_AND_MEAN - #include - #define sleep_ms(x) Sleep(x) -#else - #include - #define sleep_ms(x) usleep(x*1000) -#endif - #include #include #include @@ -75,18 +66,27 @@ TODO: Move the default settings into some separate file #include "constants.h" #include "strfnd.h" #include "porting.h" - -// Dummy variable -IrrlichtDevice *g_device = NULL; +#include "materials.h" +#include "config.h" +#include "mineral.h" +#include "filesys.h" +#include "defaultsettings.h" +#include "settings.h" +#include "profiler.h" +#include "log.h" +#include "nodedef.h" // For init_contentfeatures +#include "content_mapnode.h" // For content_mapnode_init /* Settings. These are loaded from the config file. */ +Settings main_settings; +Settings *g_settings = &main_settings; -Settings g_settings; - -extern void set_default_settings(); +// Global profiler +Profiler main_profiler; +Profiler *g_profiler = &main_profiler; /* Debug streams @@ -94,37 +94,64 @@ extern void set_default_settings(); // Connection std::ostream *dout_con_ptr = &dummyout; -std::ostream *derr_con_ptr = &dstream_no_stderr; +std::ostream *derr_con_ptr = &verbosestream; // Server -std::ostream *dout_server_ptr = &dstream; -std::ostream *derr_server_ptr = &dstream; +std::ostream *dout_server_ptr = &infostream; +std::ostream *derr_server_ptr = &errorstream; // Client -std::ostream *dout_client_ptr = &dstream; -std::ostream *derr_client_ptr = &dstream; - +std::ostream *dout_client_ptr = &infostream; +std::ostream *derr_client_ptr = &errorstream; /* - Timestamp stuff + gettime.h implementation */ -JMutex g_timestamp_mutex; - -std::string getTimestamp() +u32 getTimeMs() { - if(g_timestamp_mutex.IsInitialized()==false) - return ""; - JMutexAutoLock lock(g_timestamp_mutex); - time_t t = time(NULL); - struct tm *tm = localtime(&t); - char cs[20]; - strftime(cs, 20, "%H:%M:%S", tm); - return cs; + /* + Use imprecise system calls directly (from porting.h) + */ + return porting::getTimeMs(); } +class StderrLogOutput: public ILogOutput +{ +public: + /* line: Full line with timestamp, level and thread */ + void printLog(const std::string &line) + { + std::cerr<readConfigFile(cmd_args.get("config").c_str()); if(r == false) { - dstream<<"Could not read configuration from \"" + errorstream<<"Could not read configuration from \"" < filenames; + filenames.push_back(porting::path_userdata + + DIR_DELIM + "minetest.conf"); +#ifdef RUN_IN_PLACE + filenames.push_back(porting::path_userdata + + DIR_DELIM + ".." + DIR_DELIM + "minetest.conf"); +#endif - for(u32 i=0; i<2; i++) + for(u32 i=0; ireadConfigFile(filenames[i].c_str()); if(r) { configpath = filenames[i]; @@ -257,6 +298,11 @@ int main(int argc, char *argv[]) // Initialize random seed srand(time(0)); + mysrand(time(0)); + + // Initialize stuff + + init_mineral(); /* Run unit tests @@ -266,18 +312,6 @@ int main(int argc, char *argv[]) { run_tests(); } - - // Read map parameters from settings - - HMParams hm_params; - hm_params.blocksize = g_settings.getU16("heightmap_blocksize"); - hm_params.randmax = g_settings.get("height_randmax"); - hm_params.randfactor = g_settings.get("height_randfactor"); - hm_params.base = g_settings.get("height_base"); - - MapParams map_params; - map_params.plants_amount = g_settings.getFloat("plants_amount"); - map_params.ravines_amount = g_settings.getFloat("ravines_amount"); /* Check parameters @@ -292,21 +326,19 @@ int main(int argc, char *argv[]) <<"| Y Y \\ | | \\ ___/| | \\ ___/ \\___ \\ | | "<__| \\___ >____ > |__| "<exists("port") && g_settings->getU16("port") != 0) { - port = g_settings.getU16("port"); + port = g_settings->getU16("port"); } else { @@ -314,62 +346,27 @@ int main(int argc, char *argv[]) <exists("map-dir")) + map_dir = g_settings->get("map-dir"); - std::cout< list = server.getPlayerInfo(); - core::list::Iterator i; - static u32 sum_old = 0; - u32 sum = PIChecksum(list); - if(sum != sum_old) - { - std::cout<PrintLine(&std::cout); - } - } - sum_old = sum; - } - } - + // Run server + dedicated_server_loop(server, kill); + } //try catch(con::PeerNotFoundException &e) { - dstream<