Merge remote-tracking branch 'queatz/mmb10'
[oweals/minetest.git] / src / servermain.cpp
index 7dcc304a014e585f8c1bac0c95bc5aa7756ba872..dc41720fb2ed44bdebbb796ed98a22af5f0fbd11 100644 (file)
@@ -25,12 +25,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #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
@@ -66,6 +67,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "strfnd.h"
 #include "porting.h"
 #include "materials.h"
+#include "config.h"
+#include "mineral.h"
+#include "filesys.h"
 
 /*
        Settings.
@@ -76,6 +80,12 @@ Settings g_settings;
 
 extern void set_default_settings();
 
+// Global profiler
+Profiler g_profiler;
+
+// A dummy thing
+ITextureSource *g_texturesource = NULL;
+
 /*
        Debug streams
 */
@@ -92,7 +102,6 @@ std::ostream *derr_server_ptr = &dstream;
 std::ostream *dout_client_ptr = &dstream;
 std::ostream *derr_client_ptr = &dstream;
 
-
 /*
        gettime.h implementation
 */
@@ -107,6 +116,15 @@ u32 getTimeMs()
 
 int main(int argc, char *argv[])
 {
+       /*
+               Initialization
+       */
+
+       // Set locale. This is for forcing '.' as the decimal point.
+       std::locale::global(std::locale("C"));
+       // This enables printing all characters in bitmap font
+       setlocale(LC_CTYPE, "en_US");
+
        /*
                Low-level initialization
        */
@@ -116,19 +134,39 @@ int main(int argc, char *argv[])
        disable_stderr = true;
 #endif
 
+       porting::signal_handler_init();
+       bool &kill = *porting::signal_handler_killstatus();
+       
+       // Initialize porting::path_data and porting::path_userdata
+       porting::initializePaths();
+
+       // Create user data directory
+       fs::CreateDir(porting::path_userdata);
+       
        // Initialize debug streams
-       debugstreams_init(disable_stderr, DEBUGFILE);
+#ifdef RUN_IN_PLACE
+       std::string debugfile = DEBUGFILE;
+#else
+       std::string debugfile = porting::path_userdata+"/"+DEBUGFILE;
+#endif
+       debugstreams_init(disable_stderr, debugfile.c_str());
        // Initialize debug stacks
        debug_stacks_init();
 
        DSTACK(__FUNCTION_NAME);
 
-       porting.initializePaths();
-
-       initializeMaterialProperties();
+       // Init material properties table
+       //initializeMaterialProperties();
 
+       // Debug handler
        BEGIN_DEBUG_EXCEPTION_HANDLER
 
+       // Print startup message
+       dstream<<DTIME<<PROJECT_NAME <<
+                       " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
+                       <<", "<<BUILD_INFO
+                       <<std::endl;
+       
        try
        {
        
@@ -185,25 +223,10 @@ int main(int argc, char *argv[])
        // Initialize default settings
        set_default_settings();
        
-       // Print startup message
-       dstream<<DTIME<<"minetest-c55 server"
-                       " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
-                       <<", ENABLE_TESTS="<<ENABLE_TESTS
-                       <<std::endl;
-       
-       // Set locale. This is for forcing '.' as the decimal point.
-       std::locale::global(std::locale("C"));
-       // This enables printing all characters in bitmap font
-       setlocale(LC_CTYPE, "en_US");
-
        // Initialize sockets
        sockets_init();
        atexit(sockets_cleanup);
        
-       /*
-               Initialization
-       */
-
        /*
                Read config file
        */
@@ -226,6 +249,9 @@ int main(int argc, char *argv[])
        {
                core::array<std::string> filenames;
                filenames.push_back(porting::path_userdata + "/minetest.conf");
+#ifdef RUN_IN_PLACE
+               filenames.push_back(porting::path_userdata + "/../minetest.conf");
+#endif
 
                for(u32 i=0; i<filenames.size(); i++)
                {
@@ -242,6 +268,11 @@ int main(int argc, char *argv[])
        srand(time(0));
        mysrand(time(0));
 
+       // Initialize stuff
+       
+       init_mapnode();
+       init_mineral();
+
        /*
                Run unit tests
        */
@@ -250,18 +281,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
@@ -296,51 +315,20 @@ int main(int argc, char *argv[])
                                <<std::endl;
        }
        
-       DSTACK("Dedicated server branch");
-       
-       std::cout<<std::endl;
-       std::cout<<"========================"<<std::endl;
-       std::cout<<"Running dedicated server"<<std::endl;
-       std::cout<<"========================"<<std::endl;
-       std::cout<<std::endl;
-       
        // Figure out path to map
-       std::string map_dir = porting::path_userdata+"/map";
+       std::string map_dir = porting::path_userdata+"/world";
        if(cmd_args.exists("map-dir"))
                map_dir = cmd_args.get("map-dir");
+       else if(g_settings.exists("map-dir"))
+               map_dir = g_settings.get("map-dir");
        
-       Server server(map_dir.c_str(), hm_params, map_params);
+       // Create server
+       Server server(map_dir.c_str(), configpath);
        server.start(port);
 
-       for(;;)
-       {
-               // This is kind of a hack but can be done like this
-               // because server.step() is very light
-               sleep_ms(30);
-               server.step(0.030);
-
-               static int counter = 0;
-               counter--;
-               if(counter <= 0)
-               {
-                       counter = 10;
-
-                       core::list<PlayerInfo> list = server.getPlayerInfo();
-                       core::list<PlayerInfo>::Iterator i;
-                       static u32 sum_old = 0;
-                       u32 sum = PIChecksum(list);
-                       if(sum != sum_old)
-                       {
-                               std::cout<<DTIME<<"Player info:"<<std::endl;
-                               for(i=list.begin(); i!=list.end(); i++)
-                               {
-                                       i->PrintLine(&std::cout);
-                               }
-                       }
-                       sum_old = sum;
-               }
-       }
-
+       // Run server
+       dedicated_server_loop(server, kill);
+       
        } //try
        catch(con::PeerNotFoundException &e)
        {