]> git.lizzy.rs Git - minetest.git/blobdiff - src/server.h
Use numeric indices and raw table access with LUA_REGISTRYINDEX
[minetest.git] / src / server.h
index 784f1e928aeededfe3076806abfc0d494b7f026c..26ec3ab73a42e52c8adbdb6ed0b9eba237e7af91 100644 (file)
@@ -63,11 +63,6 @@ enum ClientDeletionReason {
        CDR_DENY
 };
 
        CDR_DENY
 };
 
-/*
-       Some random functions
-*/
-v3f findSpawnPos(ServerMap &map);
-
 class MapEditEventIgnorer
 {
 public:
 class MapEditEventIgnorer
 {
 public:
@@ -198,6 +193,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        void handleCommand_Null(NetworkPacket* pkt) {};
        void handleCommand_Deprecated(NetworkPacket* pkt);
        void handleCommand_Init(NetworkPacket* pkt);
        void handleCommand_Null(NetworkPacket* pkt) {};
        void handleCommand_Deprecated(NetworkPacket* pkt);
        void handleCommand_Init(NetworkPacket* pkt);
+       void handleCommand_Init_Legacy(NetworkPacket* pkt);
        void handleCommand_Init2(NetworkPacket* pkt);
        void handleCommand_RequestMedia(NetworkPacket* pkt);
        void handleCommand_ReceivedMedia(NetworkPacket* pkt);
        void handleCommand_Init2(NetworkPacket* pkt);
        void handleCommand_RequestMedia(NetworkPacket* pkt);
        void handleCommand_ReceivedMedia(NetworkPacket* pkt);
@@ -216,8 +212,11 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        void handleCommand_RemovedSounds(NetworkPacket* pkt);
        void handleCommand_NodeMetaFields(NetworkPacket* pkt);
        void handleCommand_InventoryFields(NetworkPacket* pkt);
        void handleCommand_RemovedSounds(NetworkPacket* pkt);
        void handleCommand_NodeMetaFields(NetworkPacket* pkt);
        void handleCommand_InventoryFields(NetworkPacket* pkt);
+       void handleCommand_FirstSrp(NetworkPacket* pkt);
+       void handleCommand_SrpBytesA(NetworkPacket* pkt);
+       void handleCommand_SrpBytesM(NetworkPacket* pkt);
 
 
-       void ProcessData(u8 *data, u32 datasize, u16 peer_id);
+       void ProcessData(NetworkPacket *pkt);
 
        void Send(NetworkPacket* pkt);
 
 
        void Send(NetworkPacket* pkt);
 
@@ -235,7 +234,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
                Shall be called with the environment and the connection locked.
        */
        Inventory* getInventory(const InventoryLocation &loc);
                Shall be called with the environment and the connection locked.
        */
        Inventory* getInventory(const InventoryLocation &loc);
-       void setInventoryModified(const InventoryLocation &loc);
+       void setInventoryModified(const InventoryLocation &loc, bool playerSend = true);
 
        // Connection must be locked when called
        std::wstring getStatusString();
 
        // Connection must be locked when called
        std::wstring getStatusString();
@@ -245,8 +244,13 @@ class Server : public con::PeerHandler, public MapEventReceiver,
                        { return m_shutdown_requested; }
 
        // request server to shutdown
                        { return m_shutdown_requested; }
 
        // request server to shutdown
-       inline void requestShutdown(void)
-                       { m_shutdown_requested = true; }
+       inline void requestShutdown() { m_shutdown_requested = true; }
+       void requestShutdown(const std::string &msg, bool reconnect)
+       {
+               m_shutdown_requested = true;
+               m_shutdown_msg = msg;
+               m_shutdown_ask_reconnect = reconnect;
+       }
 
        // Returns -1 if failed, sound handle on success
        // Envlock
 
        // Returns -1 if failed, sound handle on success
        // Envlock
@@ -265,34 +269,21 @@ class Server : public con::PeerHandler, public MapEventReceiver,
 
        void notifyPlayer(const char *name, const std::wstring &msg);
        void notifyPlayers(const std::wstring &msg);
 
        void notifyPlayer(const char *name, const std::wstring &msg);
        void notifyPlayers(const std::wstring &msg);
-       void spawnParticle(const char *playername,
+       void spawnParticle(const std::string &playername,
                v3f pos, v3f velocity, v3f acceleration,
                float expirationtime, float size,
                v3f pos, v3f velocity, v3f acceleration,
                float expirationtime, float size,
-               bool collisiondetection, bool vertical, std::string texture);
+               bool collisiondetection, bool vertical, const std::string &texture);
 
 
-       void spawnParticleAll(v3f pos, v3f velocity, v3f acceleration,
-               float expirationtime, float size,
-               bool collisiondetection, bool vertical, std::string texture);
-
-       u32 addParticleSpawner(const char *playername,
-               u16 amount, float spawntime,
+       u32 addParticleSpawner(u16 amount, float spawntime,
                v3f minpos, v3f maxpos,
                v3f minvel, v3f maxvel,
                v3f minacc, v3f maxacc,
                float minexptime, float maxexptime,
                float minsize, float maxsize,
                v3f minpos, v3f maxpos,
                v3f minvel, v3f maxvel,
                v3f minacc, v3f maxacc,
                float minexptime, float maxexptime,
                float minsize, float maxsize,
-               bool collisiondetection, bool vertical, std::string texture);
+               bool collisiondetection, bool vertical, const std::string &texture,
+               const std::string &playername);
 
 
-       u32 addParticleSpawnerAll(u16 amount, float spawntime,
-               v3f minpos, v3f maxpos,
-               v3f minvel, v3f maxvel,
-               v3f minacc, v3f maxacc,
-               float minexptime, float maxexptime,
-               float minsize, float maxsize,
-               bool collisiondetection, bool vertical, std::string texture);
-
-       void deleteParticleSpawner(const char *playername, u32 id);
-       void deleteParticleSpawnerAll(u32 id);
+       void deleteParticleSpawner(const std::string &playername, u32 id);
 
        // Creates or resets inventory
        Inventory* createDetachedInventory(const std::string &name);
 
        // Creates or resets inventory
        Inventory* createDetachedInventory(const std::string &name);
@@ -300,9 +291,6 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        // Envlock and conlock should be locked when using scriptapi
        GameScripting *getScriptIface(){ return m_script; }
 
        // Envlock and conlock should be locked when using scriptapi
        GameScripting *getScriptIface(){ return m_script; }
 
-       //TODO: determine what (if anything) should be locked to access EmergeManager
-       EmergeManager *getEmergeManager(){ return m_emerge; }
-
        // actions: time-reversed list
        // Return value: success/failure
        bool rollbackRevertActions(const std::list<RollbackAction> &actions,
        // actions: time-reversed list
        // Return value: success/failure
        bool rollbackRevertActions(const std::list<RollbackAction> &actions,
@@ -320,16 +308,16 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        virtual MtEventManager* getEventManager();
        virtual scene::ISceneManager* getSceneManager();
        virtual IRollbackManager *getRollbackManager() { return m_rollback; }
        virtual MtEventManager* getEventManager();
        virtual scene::ISceneManager* getSceneManager();
        virtual IRollbackManager *getRollbackManager() { return m_rollback; }
-
+       virtual EmergeManager *getEmergeManager() { return m_emerge; }
 
        IWritableItemDefManager* getWritableItemDefManager();
        IWritableNodeDefManager* getWritableNodeDefManager();
        IWritableCraftDefManager* getWritableCraftDefManager();
 
 
        IWritableItemDefManager* getWritableItemDefManager();
        IWritableNodeDefManager* getWritableNodeDefManager();
        IWritableCraftDefManager* getWritableCraftDefManager();
 
-       const ModSpec* getModSpec(const std::string &modname);
-       void getModNames(std::list<std::string> &modlist);
+       const ModSpec* getModSpec(const std::string &modname) const;
+       void getModNames(std::vector<std::string> &modlist);
        std::string getBuiltinLuaPath();
        std::string getBuiltinLuaPath();
-       inline std::string getWorldPath()
+       inline std::string getWorldPath() const
                        { return m_path_world; }
 
        inline bool isSingleplayer()
                        { return m_path_world; }
 
        inline bool isSingleplayer()
@@ -347,8 +335,11 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        bool hudChange(Player *player, u32 id, HudElementStat stat, void *value);
        bool hudSetFlags(Player *player, u32 flags, u32 mask);
        bool hudSetHotbarItemcount(Player *player, s32 hotbar_itemcount);
        bool hudChange(Player *player, u32 id, HudElementStat stat, void *value);
        bool hudSetFlags(Player *player, u32 flags, u32 mask);
        bool hudSetHotbarItemcount(Player *player, s32 hotbar_itemcount);
+       s32 hudGetHotbarItemcount(Player *player);
        void hudSetHotbarImage(Player *player, std::string name);
        void hudSetHotbarImage(Player *player, std::string name);
+       std::string hudGetHotbarImage(Player *player);
        void hudSetHotbarSelectedImage(Player *player, std::string name);
        void hudSetHotbarSelectedImage(Player *player, std::string name);
+       std::string hudGetHotbarSelectedImage(Player *player);
 
        inline Address getPeerAddress(u16 peer_id)
                        { return m_con.GetPeerAddress(peer_id); }
 
        inline Address getPeerAddress(u16 peer_id)
                        { return m_con.GetPeerAddress(peer_id); }
@@ -366,13 +357,18 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        void peerAdded(con::Peer *peer);
        void deletingPeer(con::Peer *peer, bool timeout);
 
        void peerAdded(con::Peer *peer);
        void deletingPeer(con::Peer *peer, bool timeout);
 
-       void DenyAccess(u16 peer_id, const std::wstring &reason);
+       void DenySudoAccess(u16 peer_id);
+       void DenyAccessVerCompliant(u16 peer_id, u16 proto_ver, AccessDeniedCode reason,
+               const std::string &str_reason = "", bool reconnect = false);
+       void DenyAccess(u16 peer_id, AccessDeniedCode reason, const std::string &custom_reason="");
+       void acceptAuth(u16 peer_id, bool forSudoMode);
+       void DenyAccess_Legacy(u16 peer_id, const std::wstring &reason);
        bool getClientConInfo(u16 peer_id, con::rtt_stat_type type,float* retval);
        bool getClientInfo(u16 peer_id,ClientState* state, u32* uptime,
                        u8* ser_vers, u16* prot_vers, u8* major, u8* minor, u8* patch,
                        std::string* vers_string);
 
        bool getClientConInfo(u16 peer_id, con::rtt_stat_type type,float* retval);
        bool getClientInfo(u16 peer_id,ClientState* state, u32* uptime,
                        u8* ser_vers, u16* prot_vers, u8* major, u8* minor, u8* patch,
                        std::string* vers_string);
 
-       void SendPlayerHPOrDie(u16 peer_id, bool die) { die ? DiePlayer(peer_id) : SendPlayerHP(peer_id); }
+       void SendPlayerHPOrDie(PlayerSAO *player);
        void SendPlayerBreath(u16 peer_id);
        void SendInventory(PlayerSAO* playerSAO);
        void SendMovePlayer(u16 peer_id);
        void SendPlayerBreath(u16 peer_id);
        void SendInventory(PlayerSAO* playerSAO);
        void SendMovePlayer(u16 peer_id);
@@ -388,7 +384,9 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        void SendMovement(u16 peer_id);
        void SendHP(u16 peer_id, u8 hp);
        void SendBreath(u16 peer_id, u16 breath);
        void SendMovement(u16 peer_id);
        void SendHP(u16 peer_id, u8 hp);
        void SendBreath(u16 peer_id, u16 breath);
-       void SendAccessDenied(u16 peer_id,const std::wstring &reason);
+       void SendAccessDenied(u16 peer_id, AccessDeniedCode reason,
+               const std::string &custom_reason, bool reconnect = false);
+       void SendAccessDenied_Legacy(u16 peer_id, const std::wstring &reason);
        void SendDeathscreen(u16 peer_id,bool set_camera_point_target, v3f camera_point_target);
        void SendItemDef(u16 peer_id,IItemDefManager *itemdef, u16 protocol_version);
        void SendNodeDef(u16 peer_id,INodeDefManager *nodedef, u16 protocol_version);
        void SendDeathscreen(u16 peer_id,bool set_camera_point_target, v3f camera_point_target);
        void SendItemDef(u16 peer_id,IItemDefManager *itemdef, u16 protocol_version);
        void SendNodeDef(u16 peer_id,INodeDefManager *nodedef, u16 protocol_version);
@@ -422,9 +420,9 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        */
        // Envlock and conlock should be locked when calling these
        void sendRemoveNode(v3s16 p, u16 ignore_id=0,
        */
        // Envlock and conlock should be locked when calling these
        void sendRemoveNode(v3s16 p, u16 ignore_id=0,
-                       std::list<u16> *far_players=NULL, float far_d_nodes=100);
+                       std::vector<u16> *far_players=NULL, float far_d_nodes=100);
        void sendAddNode(v3s16 p, MapNode n, u16 ignore_id=0,
        void sendAddNode(v3s16 p, MapNode n, u16 ignore_id=0,
-                       std::list<u16> *far_players=NULL, float far_d_nodes=100,
+                       std::vector<u16> *far_players=NULL, float far_d_nodes=100,
                        bool remove_metadata=true);
        void setBlockNotSent(v3s16 p);
 
                        bool remove_metadata=true);
        void setBlockNotSent(v3s16 p);
 
@@ -437,7 +435,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        void fillMediaCache();
        void sendMediaAnnouncement(u16 peer_id);
        void sendRequestedMedia(u16 peer_id,
        void fillMediaCache();
        void sendMediaAnnouncement(u16 peer_id);
        void sendRequestedMedia(u16 peer_id,
-                       const std::list<std::string> &tosend);
+                       const std::vector<std::string> &tosend);
 
        void sendDetachedInventory(const std::string &name, u16 peer_id);
        void sendDetachedInventories(u16 peer_id);
 
        void sendDetachedInventory(const std::string &name, u16 peer_id);
        void sendDetachedInventories(u16 peer_id);
@@ -459,6 +457,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
                float expirationtime, float size,
                bool collisiondetection, bool vertical, std::string texture);
 
                float expirationtime, float size,
                bool collisiondetection, bool vertical, std::string texture);
 
+       u32 SendActiveObjectRemoveAdd(u16 peer_id, const std::string &datas);
+       void SendActiveObjectMessages(u16 peer_id, const std::string &datas, bool reliable = true);
        /*
                Something random
        */
        /*
                Something random
        */
@@ -468,6 +468,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        void DeleteClient(u16 peer_id, ClientDeletionReason reason);
        void UpdateCrafting(Player *player);
 
        void DeleteClient(u16 peer_id, ClientDeletionReason reason);
        void UpdateCrafting(Player *player);
 
+       v3f findSpawnPos();
+
        // When called, connection mutex should be locked
        RemoteClient* getClient(u16 peer_id,ClientState state_min=CS_Active);
        RemoteClient* getClientNoEx(u16 peer_id,ClientState state_min=CS_Active);
        // When called, connection mutex should be locked
        RemoteClient* getClient(u16 peer_id,ClientState state_min=CS_Active);
        RemoteClient* getClientNoEx(u16 peer_id,ClientState state_min=CS_Active);
@@ -483,7 +485,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
 
                Call with env and con locked.
        */
 
                Call with env and con locked.
        */
-       PlayerSAO *emergePlayer(const char *name, u16 peer_id);
+       PlayerSAO *emergePlayer(const char *name, u16 peer_id, u16 proto_version);
 
        void handlePeerChanges();
 
 
        void handlePeerChanges();
 
@@ -514,7 +516,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
 
        // Environment
        ServerEnvironment *m_env;
 
        // Environment
        ServerEnvironment *m_env;
-       JMutex m_env_mutex;
+       Mutex m_env_mutex;
 
        // server connection
        con::Connection m_con;
 
        // server connection
        con::Connection m_con;
@@ -555,7 +557,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        // A buffer for time steps
        // step() increments and AsyncRunStep() run by m_thread reads it.
        float m_step_dtime;
        // A buffer for time steps
        // step() increments and AsyncRunStep() run by m_thread reads it.
        float m_step_dtime;
-       JMutex m_step_dtime_mutex;
+       Mutex m_step_dtime_mutex;
 
        // current server step lag counter
        float m_lag;
 
        // current server step lag counter
        float m_lag;
@@ -582,16 +584,15 @@ class Server : public con::PeerHandler, public MapEventReceiver,
                Queues stuff from peerAdded() and deletingPeer() to
                handlePeerChanges()
        */
                Queues stuff from peerAdded() and deletingPeer() to
                handlePeerChanges()
        */
-       Queue<con::PeerChange> m_peer_change_queue;
+       std::queue<con::PeerChange> m_peer_change_queue;
 
        /*
                Random stuff
        */
 
 
        /*
                Random stuff
        */
 
-       // Mod parent directory paths
-       std::list<std::string> m_modspaths;
-
        bool m_shutdown_requested;
        bool m_shutdown_requested;
+       std::string m_shutdown_msg;
+       bool m_shutdown_ask_reconnect;
 
        /*
                Map edit event queue. Automatically receives all map edits.
 
        /*
                Map edit event queue. Automatically receives all map edits.
@@ -606,7 +607,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
                Queue of map edits from the environment for sending to the clients
                This is behind m_env_mutex
        */
                Queue of map edits from the environment for sending to the clients
                This is behind m_env_mutex
        */
-       Queue<MapEditEvent*> m_unsent_map_edit_queue;
+       std::queue<MapEditEvent*> m_unsent_map_edit_queue;
        /*
                Set to true when the server itself is modifying the map and does
                all sending of information by itself.
        /*
                Set to true when the server itself is modifying the map and does
                all sending of information by itself.
@@ -651,9 +652,9 @@ class Server : public con::PeerHandler, public MapEventReceiver,
 /*
        Runs a simple dedicated server loop.
 
 /*
        Runs a simple dedicated server loop.
 
-       Shuts down when run is set to false.
+       Shuts down when kill is set to true.
 */
 */
-void dedicated_server_loop(Server &server, bool &run);
+void dedicated_server_loop(Server &server, bool &kill);
 
 #endif
 
 
 #endif