]> git.lizzy.rs Git - minetest.git/blobdiff - src/server.h
Proper handling of failing to bind server socket
[minetest.git] / src / server.h
index 04bd61a87a51f7f65c3473e040825f4a67d05b66..0b4c67deb10a0008cb3fb1a10ff8529760039232 100644 (file)
@@ -34,12 +34,30 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "serverremoteplayer.h"
 #include "mods.h"
 #include "inventorymanager.h"
+#include "subgame.h"
 struct LuaState;
 typedef struct lua_State lua_State;
 class IWritableItemDefManager;
 class IWritableNodeDefManager;
 class IWritableCraftDefManager;
 
+class ServerError : public std::exception
+{
+public:
+       ServerError(const std::string &s)
+       {
+               m_s = "ServerError: ";
+               m_s += s;
+       }
+       virtual ~ServerError() throw()
+       {}
+       virtual const char * what() const throw()
+       {
+               return m_s.c_str();
+       }
+       std::string m_s;
+};
+
 /*
        Some random functions
 */
@@ -211,8 +229,6 @@ struct PlayerInfo
        void PrintLine(std::ostream *s);
 };
 
-u32 PIChecksum(core::list<PlayerInfo> &l);
-
 /*
        Used for queueing and sorting block transfers in containers
        
@@ -390,10 +406,11 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        /*
                NOTE: Every public method should be thread-safe
        */
-
+       
        Server(
-               std::string mapsavedir,
-               std::string configpath
+               const std::string &path_world,
+               const std::string &path_config,
+               const SubgameSpec &gamespec
        );
        ~Server();
        void start(unsigned short port);
@@ -526,7 +543,12 @@ class Server : public con::PeerHandler, public MapEventReceiver,
 
        const ModSpec* getModSpec(const std::string &modname);
        
-       std::string getWorldPath(){ return m_mapsavedir; }
+       std::string getWorldPath(){ return m_path_world; }
+
+       void setAsyncFatalError(const std::string &error)
+       {
+               m_async_fatal_error.set(error);
+       }
 
 private:
 
@@ -607,7 +629,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        {
                Player *player = m_env->getPlayer(peer_id);
                if(player == NULL)
-                       return "[id="+itos(peer_id);
+                       return "[id="+itos(peer_id)+"]";
                return player->getName();
        }
 
@@ -631,6 +653,19 @@ class Server : public con::PeerHandler, public MapEventReceiver,
                Variables
        */
        
+       // World directory
+       std::string m_path_world;
+       // Path to user's configuration file ("" = no configuration file)
+       std::string m_path_config;
+       // Subgame specification
+       SubgameSpec m_gamespec;
+
+       // Equivalent of /usr/share/minetest/server
+       std::string m_path_share;
+       
+       // Thread can set; step() will throw as ServerError
+       MutexedVariable<std::string> m_async_fatal_error;
+       
        // Some timers
        float m_liquid_transform_timer;
        float m_print_info_timer;
@@ -724,12 +759,6 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        /*
                Random stuff
        */
-
-       // Map directory
-       std::string m_mapsavedir;
-
-       // Configuration path ("" = no configuration file)
-       std::string m_configpath;
        
        // Mod parent directory paths
        core::list<std::string> m_modspaths;