]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/servermain.cpp
Fix craftitem aliases
[dragonfireclient.git] / src / servermain.cpp
index 146c548c506d4a16c9e40f2cc3cff7fb152274aa..e8a54512ec29ddce54d5d5c411abe3392db668c2 100644 (file)
@@ -70,21 +70,24 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #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
+#include "mods.h"
 
 /*
        Settings.
        These are loaded from the config file.
 */
-
-Settings g_settings;
-
-extern void set_default_settings();
+Settings main_settings;
+Settings *g_settings = &main_settings;
 
 // Global profiler
-Profiler g_profiler;
-
-// A dummy thing
-ITextureSource *g_texturesource = NULL;
+Profiler main_profiler;
+Profiler *g_profiler = &main_profiler;
 
 /*
        Debug streams
@@ -92,15 +95,15 @@ ITextureSource *g_texturesource = NULL;
 
 // 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;
 
 /*
        gettime.h implementation
@@ -114,12 +117,37 @@ u32 getTimeMs()
        return porting::getTimeMs();
 }
 
+class StderrLogOutput: public ILogOutput
+{
+public:
+       /* line: Full line with timestamp, level and thread */
+       void printLog(const std::string &line)
+       {
+               std::cerr<<line<<std::endl;
+       }
+} main_stderr_log_out;
+
+class DstreamNoStderrLogOutput: public ILogOutput
+{
+public:
+       /* line: Full line with timestamp, level and thread */
+       void printLog(const std::string &line)
+       {
+               dstream_no_stderr<<line<<std::endl;
+       }
+} main_dstream_no_stderr_log_out;
+
 int main(int argc, char *argv[])
 {
        /*
                Initialization
        */
 
+       log_add_output_maxlev(&main_stderr_log_out, LMT_ACTION);
+       log_add_output_all_levs(&main_dstream_no_stderr_log_out);
+
+       log_register_thread("main");
+
        // Set locale. This is for forcing '.' as the decimal point.
        std::locale::global(std::locale("C"));
        // This enables printing all characters in bitmap font
@@ -147,7 +175,7 @@ int main(int argc, char *argv[])
 #ifdef RUN_IN_PLACE
        std::string debugfile = DEBUGFILE;
 #else
-       std::string debugfile = porting::path_userdata+"/"+DEBUGFILE;
+       std::string debugfile = porting::path_userdata+DIR_DELIM+DEBUGFILE;
 #endif
        debugstreams_init(disable_stderr, debugfile.c_str());
        // Initialize debug stacks
@@ -162,7 +190,7 @@ int main(int argc, char *argv[])
        BEGIN_DEBUG_EXCEPTION_HANDLER
 
        // Print startup message
-       dstream<<DTIME<<"minetest-c55"
+       actionstream<<PROJECT_NAME<<
                        " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
                        <<", "<<BUILD_INFO
                        <<std::endl;
@@ -183,6 +211,7 @@ int main(int argc, char *argv[])
        allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG));
        allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG));
        allowed_options.insert("map-dir", ValueSpec(VALUETYPE_STRING));
+       allowed_options.insert("info-on-stderr", ValueSpec(VALUETYPE_FLAG));
 
        Settings cmd_args;
        
@@ -215,13 +244,15 @@ int main(int argc, char *argv[])
                return cmd_args.getFlag("help") ? 0 : 1;
        }
 
+       if(cmd_args.getFlag("info-on-stderr"))
+               log_add_output(&main_stderr_log_out, LMT_INFO);
 
        /*
                Basic initialization
        */
 
        // Initialize default settings
-       set_default_settings();
+       set_default_settings(g_settings);
        
        // Initialize sockets
        sockets_init();
@@ -236,10 +267,10 @@ int main(int argc, char *argv[])
        
        if(cmd_args.exists("config"))
        {
-               bool r = g_settings.readConfigFile(cmd_args.get("config").c_str());
+               bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
                if(r == false)
                {
-                       dstream<<"Could not read configuration from \""
+                       errorstream<<"Could not read configuration from \""
                                        <<cmd_args.get("config")<<"\""<<std::endl;
                        return 1;
                }
@@ -248,14 +279,16 @@ int main(int argc, char *argv[])
        else
        {
                core::array<std::string> filenames;
-               filenames.push_back(porting::path_userdata + "/minetest.conf");
+               filenames.push_back(porting::path_userdata +
+                               DIR_DELIM + "minetest.conf");
 #ifdef RUN_IN_PLACE
-               filenames.push_back(porting::path_userdata + "/../minetest.conf");
+               filenames.push_back(porting::path_userdata +
+                               DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
 #endif
 
                for(u32 i=0; i<filenames.size(); i++)
                {
-                       bool r = g_settings.readConfigFile(filenames[i].c_str());
+                       bool r = g_settings->readConfigFile(filenames[i].c_str());
                        if(r)
                        {
                                configpath = filenames[i];
@@ -270,7 +303,6 @@ int main(int argc, char *argv[])
 
        // Initialize stuff
        
-       init_mapnode();
        init_mineral();
 
        /*
@@ -305,9 +337,9 @@ int main(int argc, char *argv[])
        {
                port = cmd_args.getU16("port");
        }
-       else if(g_settings.exists("port") && g_settings.getU16("port") != 0)
+       else if(g_settings->exists("port") && g_settings->getU16("port") != 0)
        {
-               port = g_settings.getU16("port");
+               port = g_settings->getU16("port");
        }
        else
        {
@@ -316,14 +348,14 @@ int main(int argc, char *argv[])
        }
        
        // Figure out path to map
-       std::string map_dir = porting::path_userdata+"/world";
+       std::string map_dir = porting::path_userdata+DIR_DELIM+"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");
+       else if(g_settings->exists("map-dir"))
+               map_dir = g_settings->get("map-dir");
        
        // Create server
-       Server server(map_dir.c_str());
+       Server server(map_dir.c_str(), configpath);
        server.start(port);
 
        // Run server
@@ -332,10 +364,14 @@ int main(int argc, char *argv[])
        } //try
        catch(con::PeerNotFoundException &e)
        {
-               dstream<<DTIME<<"Connection timed out."<<std::endl;
+               errorstream<<"Connection timed out."<<std::endl;
+       }
+       catch(ModError &e)
+       {
+               errorstream<<e.what()<<std::endl;
        }
 
-       END_DEBUG_EXCEPTION_HANDLER
+       END_DEBUG_EXCEPTION_HANDLER(errorstream)
 
        debugstreams_deinit();