Use std::queue for HTTPFetchRequest and std::vector for log_output instead of std...
[oweals/minetest.git] / src / server.h
index 21e9c811cf0460027301c731cc140b855aca80f5..ba6c37faa61a882f03da47e32d022e0b2b529d43 100644 (file)
@@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifndef SERVER_HEADER
 #define SERVER_HEADER
 
-#include "connection.h"
+#include "network/connection.h"
 #include "irr_v3d.h"
 #include "map.h"
 #include "hud.h"
@@ -29,11 +29,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "mods.h"
 #include "inventorymanager.h"
 #include "subgame.h"
-#include "rollback_interface.h" // Needed for rollbackRevertActions()
 #include "util/numeric.h"
 #include "util/thread.h"
 #include "environment.h"
 #include "clientiface.h"
+#include "network/networkpacket.h"
 #include <string>
 #include <list>
 #include <map>
@@ -50,6 +50,7 @@ class Inventory;
 class Player;
 class PlayerSAO;
 class IRollbackManager;
+struct RollbackAction;
 class EmergeManager;
 class GameScripting;
 class ServerEnvironment;
@@ -122,8 +123,8 @@ struct MediaInfo
        std::string path;
        std::string sha1_digest;
 
-       MediaInfo(const std::string path_="",
-                       const std::string sha1_digest_=""):
+       MediaInfo(const std::string &path_="",
+                 const std::string &sha1_digest_=""):
                path(path_),
                sha1_digest(sha1_digest_)
        {
@@ -174,10 +175,11 @@ public:
        Server(
                const std::string &path_world,
                const SubgameSpec &gamespec,
-               bool simple_singleplayer_mode
+               bool simple_singleplayer_mode,
+               bool ipv6
        );
        ~Server();
-       void start(unsigned short port);
+       void start(Address bind_addr);
        void stop();
        // This is mainly a way to pass the time to the server.
        // Actual processing is done in an another thread.
@@ -185,8 +187,40 @@ public:
        // This is run by ServerThread and does the actual processing
        void AsyncRunStep(bool initial_step=false);
        void Receive();
+       PlayerSAO* StageTwoClientInit(u16 peer_id);
+
+       /*
+        * Command Handlers
+        */
+
+       void handleCommand(NetworkPacket* pkt);
+
+       void handleCommand_Null(NetworkPacket* pkt) {};
+       void handleCommand_Deprecated(NetworkPacket* pkt);
+       void handleCommand_Init(NetworkPacket* pkt);
+       void handleCommand_Init2(NetworkPacket* pkt);
+       void handleCommand_RequestMedia(NetworkPacket* pkt);
+       void handleCommand_ReceivedMedia(NetworkPacket* pkt);
+       void handleCommand_ClientReady(NetworkPacket* pkt);
+       void handleCommand_GotBlocks(NetworkPacket* pkt);
+       void handleCommand_PlayerPos(NetworkPacket* pkt);
+       void handleCommand_DeletedBlocks(NetworkPacket* pkt);
+       void handleCommand_InventoryAction(NetworkPacket* pkt);
+       void handleCommand_ChatMessage(NetworkPacket* pkt);
+       void handleCommand_Damage(NetworkPacket* pkt);
+       void handleCommand_Breath(NetworkPacket* pkt);
+       void handleCommand_Password(NetworkPacket* pkt);
+       void handleCommand_PlayerItem(NetworkPacket* pkt);
+       void handleCommand_Respawn(NetworkPacket* pkt);
+       void handleCommand_Interact(NetworkPacket* pkt);
+       void handleCommand_RemovedSounds(NetworkPacket* pkt);
+       void handleCommand_NodeMetaFields(NetworkPacket* pkt);
+       void handleCommand_InventoryFields(NetworkPacket* pkt);
+
        void ProcessData(u8 *data, u32 datasize, u16 peer_id);
 
+       void Send(NetworkPacket* pkt);
+
        // Environment must be locked when called
        void setTimeOfDay(u32 time);
 
@@ -229,8 +263,8 @@ public:
        void unsetIpBanned(const std::string &ip_or_name);
        std::string getBanDescription(const std::string &ip_or_name);
 
-       void notifyPlayer(const char *name, const std::wstring msg, const bool prepend);
-       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,
                v3f pos, v3f velocity, v3f acceleration,
                float expirationtime, float size,
@@ -266,9 +300,6 @@ public:
        // Envlock and conlock should be locked when using scriptapi
        GameScripting *getScriptIface(){ return m_script; }
 
-       // Envlock should be locked when using the rollback manager
-       IRollbackManager *getRollbackManager(){ return m_rollback; }
-
        //TODO: determine what (if anything) should be locked to access EmergeManager
        EmergeManager *getEmergeManager(){ return m_emerge; }
 
@@ -287,14 +318,16 @@ public:
        virtual u16 allocateUnknownNodeId(const std::string &name);
        virtual ISoundManager* getSoundManager();
        virtual MtEventManager* getEventManager();
-       virtual IRollbackReportSink* getRollbackReportSink();
+       virtual scene::ISceneManager* getSceneManager();
+       virtual IRollbackManager *getRollbackManager() { return m_rollback; }
+
 
        IWritableItemDefManager* getWritableItemDefManager();
        IWritableNodeDefManager* getWritableNodeDefManager();
        IWritableCraftDefManager* getWritableCraftDefManager();
 
        const ModSpec* getModSpec(const std::string &modname);
-       void getModNames(std::list<std::string> &modlist);
+       void getModNames(std::vector<std::string> &modlist);
        std::string getBuiltinLuaPath();
        inline std::string getWorldPath()
                        { return m_path_world; }
@@ -308,7 +341,7 @@ public:
        bool showFormspec(const char *name, const std::string &formspec, const std::string &formname);
        Map & getMap() { return m_env->getMap(); }
        ServerEnvironment & getEnv() { return *m_env; }
-       
+
        u32 hudAdd(Player *player, HudElement *element);
        bool hudRemove(Player *player, u32 id);
        bool hudChange(Player *player, u32 id, HudElementStat stat, void *value);
@@ -319,10 +352,13 @@ public:
 
        inline Address getPeerAddress(u16 peer_id)
                        { return m_con.GetPeerAddress(peer_id); }
-                       
+
+       bool setLocalPlayerAnimations(Player *player, v2s32 animation_frames[4], f32 frame_speed);
+       bool setPlayerEyeOffset(Player *player, v3f first, v3f third);
+
        bool setSky(Player *player, const video::SColor &bgcolor,
                        const std::string &type, const std::vector<std::string> &params);
-       
+
        bool overrideDayNightRatio(Player *player, bool do_override,
                        float brightness);
 
@@ -330,6 +366,20 @@ public:
        void peerAdded(con::Peer *peer);
        void deletingPeer(con::Peer *peer, bool timeout);
 
+       void DenyAccess(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);
+
+       void SendPlayerHPOrDie(u16 peer_id, bool die) { die ? DiePlayer(peer_id) : SendPlayerHP(peer_id); }
+       void SendPlayerBreath(u16 peer_id);
+       void SendInventory(PlayerSAO* playerSAO);
+       void SendMovePlayer(u16 peer_id);
+
+       // Bind address
+       Address m_bind_addr;
+
 private:
 
        friend class EmergeThread;
@@ -346,16 +396,16 @@ private:
        /* mark blocks not sent for all clients */
        void SetBlocksNotSent(std::map<v3s16, MapBlock *>& block);
 
-       // Envlock and conlock should be locked when calling these
-       void SendInventory(u16 peer_id);
+
        void SendChatMessage(u16 peer_id, const std::wstring &message);
        void SendTimeOfDay(u16 peer_id, u16 time, f32 time_speed);
        void SendPlayerHP(u16 peer_id);
-       void SendPlayerBreath(u16 peer_id);
-       void SendMovePlayer(u16 peer_id);
+
+       void SendLocalPlayerAnimations(u16 peer_id, v2s32 animation_frames[4], f32 animation_speed);
+       void SendEyeOffset(u16 peer_id, v3f first, v3f third);
        void SendPlayerPrivileges(u16 peer_id);
        void SendPlayerInventoryFormspec(u16 peer_id);
-       void SendShowFormspecMessage(u16 peer_id, const std::string formspec, const std::string formname);
+       void SendShowFormspecMessage(u16 peer_id, const std::string &formspec, const std::string &formname);
        void SendHUDAdd(u16 peer_id, u32 id, HudElement *form);
        void SendHUDRemove(u16 peer_id, u32 id);
        void SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value);
@@ -364,7 +414,7 @@ private:
        void SendSetSky(u16 peer_id, const video::SColor &bgcolor,
                        const std::string &type, const std::vector<std::string> &params);
        void SendOverrideDayNightRatio(u16 peer_id, bool do_override, float ratio);
-       
+
        /*
                Send a node removal/addition event to all clients except ignore_id.
                Additionally, if far_players!=NULL, players further away than
@@ -372,9 +422,9 @@ private:
        */
        // 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,
-                       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);
 
@@ -387,7 +437,7 @@ private:
        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);
@@ -415,13 +465,12 @@ private:
 
        void DiePlayer(u16 peer_id);
        void RespawnPlayer(u16 peer_id);
-       void DenyAccess(u16 peer_id, const std::wstring &reason);
        void DeleteClient(u16 peer_id, ClientDeletionReason reason);
-       void UpdateCrafting(u16 peer_id);
+       void UpdateCrafting(Player *player);
 
        // When called, connection mutex should be locked
-       RemoteClient* getClient(u16 peer_id,ClientState state_min=Active);
-       RemoteClient* getClientNoEx(u16 peer_id,ClientState state_min=Active);
+       RemoteClient* getClient(u16 peer_id,ClientState state_min=CS_Active);
+       RemoteClient* getClientNoEx(u16 peer_id,ClientState state_min=CS_Active);
 
        // When called, environment mutex should be locked
        std::string getPlayerName(u16 peer_id);
@@ -475,7 +524,6 @@ private:
 
        // Rollback manager (behind m_env_mutex)
        IRollbackManager *m_rollback;
-       bool m_rollback_sink_enabled;
        bool m_enable_rollback_recording; // Updated once in a while
 
        // Emerge manager
@@ -534,15 +582,12 @@ private:
                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
        */
 
-       // Mod parent directory paths
-       std::list<std::string> m_modspaths;
-
        bool m_shutdown_requested;
 
        /*
@@ -558,7 +603,7 @@ private:
                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.