]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/client/client.h
Refactor CSM restriction code a bit
[dragonfireclient.git] / src / client / client.h
index 60735f665300f8c3133b58464bac4d5b4acfdede..5f33625094e46630fb783820ccdafe20cfe7ebca 100644 (file)
@@ -193,6 +193,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        void handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt);
        void handleCommand_ActiveObjectMessages(NetworkPacket* pkt);
        void handleCommand_Movement(NetworkPacket* pkt);
+       void handleCommand_Fov(NetworkPacket *pkt);
        void handleCommand_HP(NetworkPacket* pkt);
        void handleCommand_Breath(NetworkPacket* pkt);
        void handleCommand_MovePlayer(NetworkPacket* pkt);
@@ -227,12 +228,13 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        void handleCommand_SrpBytesSandB(NetworkPacket *pkt);
        void handleCommand_FormspecPrepend(NetworkPacket *pkt);
        void handleCommand_CSMRestrictionFlags(NetworkPacket *pkt);
+       void handleCommand_PlayerSpeed(NetworkPacket *pkt);
 
        void ProcessData(NetworkPacket *pkt);
 
        void Send(NetworkPacket* pkt);
 
-       void interact(u8 action, const PointedThing& pointed);
+       void interact(InteractAction action, const PointedThing &pointed);
 
        void sendNodemetaFields(v3s16 p, const std::string &formname,
                const StringMap &fields);
@@ -259,32 +261,25 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        // Causes urgent mesh updates (unlike Map::add/removeNodeWithEvent)
        void removeNode(v3s16 p);
 
-       /**
-        * Helper function for Client Side Modding
-        * CSM restrictions are applied there, this should not be used for core engine
-        * @param p
-        * @param is_valid_position
-        * @return
-        */
-       MapNode getNode(v3s16 p, bool *is_valid_position);
+       // helpers to enforce CSM restrictions
+       MapNode CSMGetNode(v3s16 p, bool *is_valid_position);
+       int CSMClampRadius(v3s16 pos, int radius);
+
        void addNode(v3s16 p, MapNode n, bool remove_metadata = true);
 
        void setPlayerControl(PlayerControl &control);
 
-       void selectPlayerItem(u16 item);
-       u16 getPlayerItem() const
-       { return m_playeritem; }
-
        // Returns true if the inventory of the local player has been
        // updated from the server. If it is true, it is set to false.
-       bool getLocalInventoryUpdated();
-       // Copies the inventory of the local player to parameter
-       void getLocalInventory(Inventory &dst);
+       bool updateWieldedItem();
 
        /* InventoryManager interface */
        Inventory* getInventory(const InventoryLocation &loc) override;
        void inventoryAction(InventoryAction *a) override;
 
+       // Send the item number 'item' as player item to the server
+       void setPlayerItem(u16 item);
+
        const std::list<std::string> &getConnectedPlayerNames()
        {
                return m_env.getPlayerNames();
@@ -335,12 +330,14 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        // disconnect client when CSM failed.
        const std::string &accessDeniedReason() const { return m_access_denied_reason; }
 
-       bool itemdefReceived()
+       const bool itemdefReceived() const
        { return m_itemdef_received; }
-       bool nodedefReceived()
+       const bool nodedefReceived() const
        { return m_nodedef_received; }
-       bool mediaReceived()
+       const bool mediaReceived() const
        { return !m_media_downloader; }
+       const bool activeObjectsReceived() const
+       { return m_activeobjects_received; }
 
        u16 getProtoVersion()
        { return m_proto_ver; }
@@ -377,7 +374,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        bool checkLocalPrivilege(const std::string &priv)
        { return checkPrivilege(priv); }
        virtual scene::IAnimatedMesh* getMesh(const std::string &filename, bool cache = false);
-       const std::string* getModFile(const std::string &filename);
+       const std::string* getModFile(std::string filename);
 
        std::string getModStoragePath() const override;
        bool registerModStorage(ModMetadata *meta) override;
@@ -399,7 +396,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        }
 
        ClientScripting *getScript() { return m_script; }
-       const bool moddingEnabled() const { return m_modding_enabled; }
        const bool modsLoaded() const { return m_mods_loaded; }
 
        void pushToEventQueue(ClientEvent *event);
@@ -454,8 +450,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        void Receive();
 
        void sendPlayerPos();
-       // Send the item number 'item' as player item to the server
-       void sendPlayerItem(u16 item);
 
        void deleteAuthData();
        // helper method shared with clientpackethandler
@@ -465,7 +459,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        void promptConfirmRegistration(AuthMechanism chosen_auth_mechanism);
        void startAuth(AuthMechanism chosen_auth_mechanism);
        void sendDeletedBlocks(std::vector<v3s16> &blocks);
-       void sendGotBlocks(v3s16 block);
+       void sendGotBlocks(const std::vector<v3s16> &blocks);
        void sendRemovedSounds(std::vector<s32> &soundList);
 
        // Helper function
@@ -506,8 +500,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        // If 0, server init hasn't been received yet.
        u16 m_proto_ver = 0;
 
-       u16 m_playeritem = 0;
-       bool m_inventory_updated = false;
+       bool m_update_wielded_item = false;
        Inventory *m_inventory_from_server = nullptr;
        float m_inventory_from_server_age = 0.0f;
        PacketCounter m_packetcounter;
@@ -545,6 +538,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        std::queue<ClientEvent *> m_client_event_queue;
        bool m_itemdef_received = false;
        bool m_nodedef_received = false;
+       bool m_activeobjects_received = false;
        bool m_mods_loaded = false;
        ClientMediaDownloader *m_media_downloader;
 
@@ -565,9 +559,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        // And relations to objects
        std::unordered_map<int, u16> m_sounds_to_objects;
 
-       // CSM/client IDs to SSM/server IDs Mapping
-       // Map server particle spawner IDs to client IDs
-       std::unordered_map<u32, u32> m_particles_server_to_client;
        // Map server hud ids to client hud ids
        std::unordered_map<u32, u32> m_hud_server_to_client;
 
@@ -581,8 +572,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        // Storage for mesh data for creating multiple instances of the same mesh
        StringMap m_mesh_data;
 
-       StringMap m_mod_files;
-
        // own state
        LocalClientState m_state;
 
@@ -593,11 +582,13 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        IntervalLimiter m_localdb_save_interval;
        u16 m_cache_save_interval;
 
+       // Client modding
        ClientScripting *m_script = nullptr;
        bool m_modding_enabled;
        std::unordered_map<std::string, ModMetadata *> m_mod_storages;
        float m_mod_storage_save_timer = 10.0f;
        std::vector<ModSpec> m_mods;
+       StringMap m_mod_vfs;
 
        bool m_shutdown = false;