]> git.lizzy.rs Git - minetest.git/blobdiff - src/client.h
Overlays for wield and inventory images (#6107)
[minetest.git] / src / client.h
index 0255b2803337f2c361edd41e7b03db2febe6eb94..2ee81ea09b68ffff7cd3d95de1154cc5735e80c7 100644 (file)
@@ -17,10 +17,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
-#ifndef CLIENT_HEADER
-#define CLIENT_HEADER
+#pragma once
 
-#include "network/connection.h"
 #include "clientenvironment.h"
 #include "irrlichttypes_extrabloated.h"
 #include <ostream>
@@ -37,12 +35,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "mapnode.h"
 #include "tileanimation.h"
 #include "mesh_generator_thread.h"
+#include "network/address.h"
+#include "network/peerhandler.h"
 #include <fstream>
-#include "filesys.h"
 
 #define CLIENT_CHAT_MESSAGE_LIMIT_PER_10S 10.0f
 
 struct MeshMakeData;
+struct ChatMessage;
 class MapBlockMesh;
 class IWritableTextureSource;
 class IWritableShaderSource;
@@ -58,6 +58,9 @@ class Minimap;
 struct MinimapMapblock;
 class Camera;
 class NetworkPacket;
+namespace con {
+class Connection;
+}
 
 enum LocalClientState {
        LC_Created,
@@ -203,9 +206,7 @@ struct ClientEvent
 class PacketCounter
 {
 public:
-       PacketCounter()
-       {
-       }
+       PacketCounter() = default;
 
        void add(u16 command)
        {
@@ -222,23 +223,15 @@ class PacketCounter
 
        void clear()
        {
-               for(std::map<u16, u16>::iterator
-                               i = m_packets.begin();
-                               i != m_packets.end(); ++i)
-               {
-                       i->second = 0;
+               for (auto &m_packet : m_packets) {
+                       m_packet.second = 0;
                }
        }
 
        void print(std::ostream &o)
        {
-               for(std::map<u16, u16>::iterator
-                               i = m_packets.begin();
-                               i != m_packets.end(); ++i)
-               {
-                       o<<"cmd "<<i->first
-                                       <<" count "<<i->second
-                                       <<std::endl;
+               for (const auto &m_packet : m_packets) {
+                       o << "cmd "<< m_packet.first <<" count "<< m_packet.second << std::endl;
                }
        }
 
@@ -328,7 +321,8 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        void handleCommand_BlockData(NetworkPacket* pkt);
        void handleCommand_Inventory(NetworkPacket* pkt);
        void handleCommand_TimeOfDay(NetworkPacket* pkt);
-       void handleCommand_ChatMessage(NetworkPacket* pkt);
+       void handleCommand_ChatMessageOld(NetworkPacket *pkt);
+       void handleCommand_ChatMessage(NetworkPacket *pkt);
        void handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt);
        void handleCommand_ActiveObjectMessages(NetworkPacket* pkt);
        void handleCommand_Movement(NetworkPacket* pkt);
@@ -362,6 +356,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        void handleCommand_EyeOffset(NetworkPacket* pkt);
        void handleCommand_UpdatePlayerList(NetworkPacket* pkt);
        void handleCommand_SrpBytesSandB(NetworkPacket* pkt);
+       void handleCommand_CSMFlavourLimits(NetworkPacket *pkt);
 
        void ProcessData(NetworkPacket *pkt);
 
@@ -394,6 +389,14 @@ 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
+        * Flavour is 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);
        void addNode(v3s16 p, MapNode n, bool remove_metadata = true);
 
@@ -473,8 +476,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        u8 getProtoVersion()
        { return m_proto_ver; }
 
-       bool connectedToServer()
-       { return m_con.Connected(); }
+       bool connectedToServer();
 
        float mediaReceiveProgress();
 
@@ -520,9 +522,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
 
        void makeScreenshot();
 
-       inline void pushToChatQueue(const std::wstring &input)
+       inline void pushToChatQueue(ChatMessage *cec)
        {
-               m_chat_queue.push(input);
+               m_chat_queue.push(cec);
        }
 
        ClientScripting *getScript() { return m_script; }
@@ -533,23 +535,30 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
                m_client_event_queue.push(event);
        }
 
-       void showGameChat(const bool show = true);
-       void showGameHud(const bool show = true);
-       void showMinimap(const bool show = true);
-       void showProfiler(const bool show = true);
-       void showGameFog(const bool show = true);
-       void showGameDebug(const bool show = true);
+       void showGameChat(bool show = true);
+       void showGameHud(bool show = true);
+       void showMinimap(bool show = true);
+       void showProfiler(bool show = true);
+       void showGameFog(bool show = true);
+       void showGameDebug(bool show = true);
 
-       const Address getServerAddress()
-       {
-               return m_con.GetPeerAddress(PEER_ID_SERVER);
-       }
+       const Address getServerAddress();
 
        const std::string &getAddressName() const
        {
                return m_address_name;
        }
 
+       inline bool checkCSMFlavourLimit(CSMFlavourLimit flag) const
+       {
+               return m_csm_flavour_limits & flag;
+       }
+
+       u32 getCSMNodeRangeLimit() const
+       {
+               return m_csm_noderange_limit;
+       }
+
 private:
 
        // Virtual methods from con::PeerHandler
@@ -602,7 +611,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        MeshUpdateThread m_mesh_update_thread;
        ClientEnvironment m_env;
        ParticleManager m_particle_manager;
-       con::Connection m_con;
+       std::unique_ptr<con::Connection> m_con;
        std::string m_address_name;
        Camera *m_camera = nullptr;
        Minimap *m_minimap = nullptr;
@@ -629,10 +638,10 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        // 0 <= m_daynight_i < DAYNIGHT_CACHE_COUNT
        //s32 m_daynight_i;
        //u32 m_daynight_ratio;
-       std::queue<std::wstring> m_chat_queue;
        std::queue<std::wstring> m_out_chat_queue;
        u32 m_last_chat_message_sent;
        float m_chat_message_allowance = 5.0f;
+       std::queue<ChatMessage *> m_chat_queue;
 
        // The authentication methods we can use to enter sudo mode (=change password)
        u32 m_sudo_auth_methods;
@@ -703,6 +712,8 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        GameUIFlags *m_game_ui_flags;
 
        bool m_shutdown = false;
-};
 
-#endif // !CLIENT_HEADER
+       // CSM flavour limits byteflag
+       u64 m_csm_flavour_limits = CSMFlavourLimit::CSM_FL_NONE;
+       u32 m_csm_noderange_limit = 8;
+};