X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fclient.h;h=f5929e0553d8b003ba5fa2f058a87b6d9be0aaf6;hb=b4df0d67dd9fca20df632f0247b97f8370757a3c;hp=29cbe9c100d887518556af5338ba3d130cca169a;hpb=bdac12761cd92960c3df83c932aa610f2322215f;p=minetest.git diff --git a/src/client.h b/src/client.h index 29cbe9c10..f5929e055 100644 --- a/src/client.h +++ b/src/client.h @@ -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 @@ -37,10 +35,15 @@ 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 -#include "filesys.h" +#define CLIENT_CHAT_MESSAGE_LIMIT_PER_10S 10.0f + +struct ClientEvent; struct MeshMakeData; +struct ChatMessage; class MapBlockMesh; class IWritableTextureSource; class IWritableShaderSource; @@ -49,6 +52,7 @@ class IWritableNodeDefManager; //class IWritableCraftDefManager; class ClientMediaDownloader; struct MapDrawControl; +class ModChannelMgr; class MtEventManager; struct PointedThing; class MapDatabase; @@ -56,6 +60,9 @@ class Minimap; struct MinimapMapblock; class Camera; class NetworkPacket; +namespace con { +class Connection; +} enum LocalClientState { LC_Created, @@ -63,137 +70,6 @@ enum LocalClientState { LC_Ready }; -enum ClientEventType -{ - CE_NONE, - CE_PLAYER_DAMAGE, - CE_PLAYER_FORCE_MOVE, - CE_DEATHSCREEN, - CE_SHOW_FORMSPEC, - CE_SHOW_LOCAL_FORMSPEC, - CE_SPAWN_PARTICLE, - CE_ADD_PARTICLESPAWNER, - CE_DELETE_PARTICLESPAWNER, - CE_HUDADD, - CE_HUDRM, - CE_HUDCHANGE, - CE_SET_SKY, - CE_OVERRIDE_DAY_NIGHT_RATIO, - CE_CLOUD_PARAMS, -}; - -struct ClientEvent -{ - ClientEventType type; - union{ - //struct{ - //} none; - struct{ - u8 amount; - } player_damage; - struct{ - f32 pitch; - f32 yaw; - } player_force_move; - struct{ - bool set_camera_point_target; - f32 camera_point_target_x; - f32 camera_point_target_y; - f32 camera_point_target_z; - } deathscreen; - struct{ - std::string *formspec; - std::string *formname; - } show_formspec; - //struct{ - //} textures_updated; - struct{ - v3f *pos; - v3f *vel; - v3f *acc; - f32 expirationtime; - f32 size; - bool collisiondetection; - bool collision_removal; - bool vertical; - std::string *texture; - struct TileAnimationParams animation; - u8 glow; - } spawn_particle; - struct{ - u16 amount; - f32 spawntime; - v3f *minpos; - v3f *maxpos; - v3f *minvel; - v3f *maxvel; - v3f *minacc; - v3f *maxacc; - f32 minexptime; - f32 maxexptime; - f32 minsize; - f32 maxsize; - bool collisiondetection; - bool collision_removal; - u16 attached_id; - bool vertical; - std::string *texture; - u32 id; - struct TileAnimationParams animation; - u8 glow; - } add_particlespawner; - struct{ - u32 id; - } delete_particlespawner; - struct{ - u32 id; - u8 type; - v2f *pos; - std::string *name; - v2f *scale; - std::string *text; - u32 number; - u32 item; - u32 dir; - v2f *align; - v2f *offset; - v3f *world_pos; - v2s32 * size; - } hudadd; - struct{ - u32 id; - } hudrm; - struct{ - u32 id; - HudElementStat stat; - v2f *v2fdata; - std::string *sdata; - u32 data; - v3f *v3fdata; - v2s32 * v2s32data; - } hudchange; - struct{ - video::SColor *bgcolor; - std::string *type; - std::vector *params; - bool clouds; - } set_sky; - struct{ - bool do_override; - float ratio_f; - } override_day_night_ratio; - struct { - f32 density; - u32 color_bright; - u32 color_ambient; - f32 height; - f32 thickness; - f32 speed_x; - f32 speed_y; - } cloud_params; - }; -}; - /* Packet counter */ @@ -201,9 +77,7 @@ struct ClientEvent class PacketCounter { public: - PacketCounter() - { - } + PacketCounter() = default; void add(u16 command) { @@ -220,23 +94,15 @@ class PacketCounter void clear() { - for(std::map::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::iterator - i = m_packets.begin(); - i != m_packets.end(); ++i) - { - o<<"cmd "<first - <<" count "<second - < &blocks); @@ -579,11 +457,12 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef inline std::string getPlayerName() { return m_env.getLocalPlayer()->getName(); } + bool canSendChatMessage() const; + float m_packetcounter_timer = 0.0f; float m_connection_reinit_timer = 0.1f; float m_avg_rtt_timer = 0.0f; float m_playerpos_send_timer = 0.0f; - float m_ignore_damage_timer = 0.0f; // Used after server moves player IntervalLimiter m_map_timer_and_unload_interval; IWritableTextureSource *m_tsrc; @@ -597,7 +476,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 m_con; std::string m_address_name; Camera *m_camera = nullptr; Minimap *m_minimap = nullptr; @@ -624,7 +503,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 m_chat_queue; + std::queue m_out_chat_queue; + u32 m_last_chat_message_sent; + float m_chat_message_allowance = 5.0f; + std::queue m_chat_queue; // The authentication methods we can use to enter sudo mode (=change password) u32 m_sudo_auth_methods; @@ -645,9 +527,10 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef bool m_access_denied = false; bool m_access_denied_reconnect = false; std::string m_access_denied_reason = ""; - std::queue m_client_event_queue; + std::queue m_client_event_queue; bool m_itemdef_received = false; bool m_nodedef_received = false; + bool m_mods_loaded = false; ClientMediaDownloader *m_media_downloader; // time_of_day speed approximation for old protocol @@ -682,6 +565,8 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef // own state LocalClientState m_state; + GameUI *m_game_ui; + // Used for saving server map to disk client-side MapDatabase *m_localdb = nullptr; IntervalLimiter m_localdb_save_interval; @@ -692,9 +577,12 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef std::unordered_map m_mod_storages; float m_mod_storage_save_timer = 10.0f; std::vector m_mods; - 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; + + std::unique_ptr m_modchannel_mgr; +};