X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fservermain.cpp;h=64853604b1a8ec64c11de1411005e66dec95a43f;hb=8492796a5c45787810aad7fe08fc63cadc0c96b5;hp=e8d7c471d6820a6e2c7b3001fdd0b96df3de0032;hpb=ab7477c4c3e2a3647dc4fb65c71567946d33b0e3;p=oweals%2Fminetest.git diff --git a/src/servermain.cpp b/src/servermain.cpp index e8d7c471d..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,52 +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; - -// Sets default settings -void set_default_settings() -{ - // Client stuff - g_settings.setDefault("wanted_fps", "30"); - g_settings.setDefault("fps_max", "60"); - g_settings.setDefault("viewing_range_nodes_max", "300"); - g_settings.setDefault("viewing_range_nodes_min", "35"); - g_settings.setDefault("screenW", ""); - g_settings.setDefault("screenH", ""); - g_settings.setDefault("host_game", ""); - g_settings.setDefault("port", ""); - g_settings.setDefault("address", ""); - g_settings.setDefault("name", ""); - g_settings.setDefault("random_input", "false"); - g_settings.setDefault("client_delete_unused_sectors_timeout", "1200"); - g_settings.setDefault("enable_fog", "true"); - - // Server stuff - g_settings.setDefault("creative_mode", "false"); - g_settings.setDefault("heightmap_blocksize", "32"); - g_settings.setDefault("height_randmax", "constant 50.0"); - g_settings.setDefault("height_randfactor", "constant 0.6"); - g_settings.setDefault("height_base", "linear 0 0 0"); - g_settings.setDefault("plants_amount", "1.0"); - g_settings.setDefault("ravines_amount", "1.0"); - g_settings.setDefault("objectdata_interval", "0.2"); - g_settings.setDefault("active_object_range", "2"); - g_settings.setDefault("max_simultaneous_block_sends_per_client", "1"); - g_settings.setDefault("max_simultaneous_block_sends_server_total", "4"); - g_settings.setDefault("disable_water_climb", "true"); - g_settings.setDefault("endless_water", "true"); - g_settings.setDefault("max_block_send_distance", "5"); - g_settings.setDefault("max_block_generate_distance", "4"); -} +// Global profiler +Profiler main_profiler; +Profiler *g_profiler = &main_profiler; /* Debug streams @@ -128,37 +94,64 @@ 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]; @@ -291,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 @@ -300,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 @@ -326,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 { @@ -348,70 +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; - } - } - - /* - Update configuration file - */ - if(configpath != "") - { - g_settings.updateConfigFile(configpath.c_str()); - } - + // Run server + dedicated_server_loop(server, kill); + } //try catch(con::PeerNotFoundException &e) { - dstream<