diff options
Diffstat (limited to 'src/ClientHandle.h')
-rw-r--r-- | src/ClientHandle.h | 389 |
1 files changed, 228 insertions, 161 deletions
diff --git a/src/ClientHandle.h b/src/ClientHandle.h index a452d765a..f4cd87ec8 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -1,7 +1,8 @@ // cClientHandle.h -// Interfaces to the cClientHandle class representing a client connected to this server. The client need not be a player yet +// Interfaces to the cClientHandle class representing a client connected to this server. The client need not be a player +// yet @@ -47,15 +48,15 @@ typedef std::shared_ptr<cClientHandle> cClientHandlePtr; class cClientHandle // tolua_export - : public cTCPLink::cCallbacks, public std::enable_shared_from_this<cClientHandle> + : public cTCPLink::cCallbacks, + public std::enable_shared_from_this<cClientHandle> { // tolua_export -public: // tolua_export - - #if defined(ANDROID) - static const int DEFAULT_VIEW_DISTANCE = 4; // The default ViewDistance (used when no value is set in Settings.ini) - #else - static const int DEFAULT_VIEW_DISTANCE = 10; - #endif + public: // tolua_export +#if defined(ANDROID) + static const int DEFAULT_VIEW_DISTANCE = 4; // The default ViewDistance (used when no value is set in Settings.ini) +#else + static const int DEFAULT_VIEW_DISTANCE = 10; +#endif static const int MAX_VIEW_DISTANCE = 32; static const int MIN_VIEW_DISTANCE = 1; @@ -64,7 +65,8 @@ public: // tolua_export Can be set in settings.ini [AntiCheat] FastBreakPercentage=(from 0 to 100) */ static float FASTBREAK_PERCENTAGE; - /** Creates a new client with the specified IP address in its description and the specified initial view distance. */ + /** Creates a new client with the specified IP address in its description and the specified initial view distance. + */ cClientHandle(const AString & a_IPString, int a_ViewDistance); virtual ~cClientHandle() override; @@ -83,7 +85,11 @@ public: // tolua_export /** Sets the player's UUID, as used by the protocol. Used mainly by BungeeCord compatibility code - when authenticating is done on the BungeeCord server and the results are passed to MCS running in offline mode. */ - void SetUUID(const cUUID & a_UUID) { ASSERT(!a_UUID.IsNil()); m_UUID = a_UUID; } + void SetUUID(const cUUID & a_UUID) + { + ASSERT(!a_UUID.IsNil()); + m_UUID = a_UUID; + } const Json::Value & GetProperties(void) const { return m_Properties; } @@ -94,7 +100,8 @@ public: // tolua_export /** Generates an UUID based on the player name provided. This is used for the offline (non-auth) mode, when there's no UUID source. - Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their UUID is the same. */ + Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their + UUID is the same. */ static cUUID GenerateOfflineUUID(const AString & a_Username); // Exported in ManualBindings.cpp /** Returns true if the UUID is generated by online auth, false if it is an offline-generated UUID. @@ -113,11 +120,17 @@ public: // tolua_export void ProcessProtocolOut(); /** Formats the type of message with the proper color and prefix for sending to the client. */ - static AString FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString & a_AdditionalData); + static AString FormatMessageType( + bool ShouldAppendChatPrefixes, + eMessageType a_ChatPrefix, + const AString & a_AdditionalData + ); static AString FormatChatPrefix( - bool ShouldAppendChatPrefixes, const AString & a_ChatPrefixS, - const AString & m_Color1, const AString & m_Color2 + bool ShouldAppendChatPrefixes, + const AString & a_ChatPrefixS, + const AString & m_Color1, + const AString & m_Color2 ); void Kick(const AString & a_Reason); // tolua_export @@ -128,7 +141,8 @@ public: // tolua_export /** Authenticates ourselves, called by cAuthenticator supplying player details from Mojang. */ void Authenticate(AString && a_Name, const cUUID & a_UUID, Json::Value && a_Properties); - /** Sends a set number of new chunks to the player on every invocation, until all chunks in the view distance have been sent. */ + /** Sends a set number of new chunks to the player on every invocation, until all chunks in the view distance have + * been sent. */ void StreamNextChunks(); /** Remove all loaded chunks that are no longer in range */ @@ -144,116 +158,166 @@ public: // tolua_export void Destroy(void); - bool IsPlaying (void) const { return (m_State == csPlaying); } - bool IsDestroyed (void) const { return (m_State == csDestroyed); } + bool IsPlaying(void) const { return (m_State == csPlaying); } + bool IsDestroyed(void) const { return (m_State == csDestroyed); } // The following functions send the various packets: // (Please keep these alpha-sorted) - void SendAttachEntity (const cEntity & a_Entity, const cEntity & a_Vehicle); - void SendBlockAction (Vector3i a_BlockPos, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType); - void SendBlockBreakAnim (UInt32 a_EntityID, Vector3i a_BlockPos, char a_Stage); // tolua_export - void SendBlockChange (Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); // tolua_export - void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes); - void SendBossBarAdd (UInt32 a_UniqueID, const cCompositeChat & a_Title, float a_FractionFilled, BossBarColor a_Color, BossBarDivisionType a_DivisionType, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog); // tolua_export - void SendBossBarUpdateFlags (UInt32 a_UniqueID, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog); // tolua_export - void SendBossBarUpdateStyle (UInt32 a_UniqueID, BossBarColor a_Color, BossBarDivisionType a_DivisionType); // tolua_export - void SendBossBarUpdateTitle (UInt32 a_UniqueID, const cCompositeChat & a_Title); // tolua_export - void SendBossBarRemove (UInt32 a_UniqueID); // tolua_export - void SendBossBarUpdateHealth (UInt32 a_UniqueID, float a_FractionFilled); // tolua_export - void SendCameraSetTo (const cEntity & a_Entity); - void SendChat (const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData = ""); - void SendChat (const cCompositeChat & a_Message); - void SendChatRaw (const AString & a_MessageRaw, eChatType a_Type); - void SendChatAboveActionBar (const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData = ""); - void SendChatAboveActionBar (const cCompositeChat & a_Message); - void SendChatSystem (const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData = ""); - void SendChatSystem (const cCompositeChat & a_Message); - void SendChunkData (int a_ChunkX, int a_ChunkZ, ContiguousByteBufferView a_ChunkData); - void SendCollectEntity (const cEntity & a_Collected, const cEntity & a_Collector, unsigned a_Count); // tolua_export - void SendDestroyEntity (const cEntity & a_Entity); // tolua_export - void SendDetachEntity (const cEntity & a_Entity, const cEntity & a_PreviousVehicle); // tolua_export - void SendDisconnect (const AString & a_Reason); - void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display); - void SendEditSign (Vector3i a_BlockPos); // tolua_export - void SendEntityAnimation (const cEntity & a_Entity, EntityAnimation a_Animation); // tolua_export - void SendEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, int a_Duration); - void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item); - void SendEntityHeadLook (const cEntity & a_Entity); - void SendEntityLook (const cEntity & a_Entity); - void SendEntityMetadata (const cEntity & a_Entity); - void SendEntityPosition (const cEntity & a_Entity); - void SendEntityProperties (const cEntity & a_Entity); - void SendEntityVelocity (const cEntity & a_Entity); - void SendExperience (void); - void SendExperienceOrb (const cExpOrb & a_ExpOrb); - void SendExplosion (Vector3f a_Position, float a_Power); - void SendGameMode (eGameMode a_GameMode); - void SendHealth (void); - void SendHeldItemChange (int a_ItemIndex); - void SendHideTitle (void); // tolua_export - void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item); - void SendLeashEntity (const cEntity & a_Entity, const cEntity & a_EntityLeashedTo); // tolua_export - void SendMapData (const cMap & a_Map, int a_DataStartX, int a_DataStartY); - void SendPaintingSpawn (const cPainting & a_Painting); - void SendParticleEffect (const AString & a_ParticleName, Vector3f a_Source, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount); - void SendParticleEffect (const AString & a_ParticleName, const Vector3f a_Src, const Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> a_Data); - void SendPlayerAbilities (void); - void SendPlayerListAddPlayer (const cPlayer & a_Player); - void SendPlayerListHeaderFooter (const cCompositeChat & a_Header, const cCompositeChat & a_Footer); // tolua_export - void SendPlayerListRemovePlayer (const cPlayer & a_Player); + void SendAttachEntity(const cEntity & a_Entity, const cEntity & a_Vehicle); + void SendBlockAction(Vector3i a_BlockPos, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType); + void SendBlockBreakAnim(UInt32 a_EntityID, Vector3i a_BlockPos, char a_Stage); // tolua_export + void SendBlockChange(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); // tolua_export + void SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes); + // tolua_begin + void SendBossBarAdd( + UInt32 a_UniqueID, + const cCompositeChat & a_Title, + float a_FractionFilled, + BossBarColor a_Color, + BossBarDivisionType a_DivisionType, + bool a_DarkenSky, + bool a_PlayEndMusic, + bool a_CreateFog + ); + // tolua_end + // tolua_begin + void SendBossBarUpdateFlags(UInt32 a_UniqueID, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog); + // tolua_end + // tolua_begin + void SendBossBarUpdateStyle(UInt32 a_UniqueID, BossBarColor a_Color, BossBarDivisionType a_DivisionType); + // tolua_end + void SendBossBarUpdateTitle(UInt32 a_UniqueID, const cCompositeChat & a_Title); // tolua_export + void SendBossBarRemove(UInt32 a_UniqueID); // tolua_export + void SendBossBarUpdateHealth(UInt32 a_UniqueID, float a_FractionFilled); // tolua_export + void SendCameraSetTo(const cEntity & a_Entity); + void SendChat(const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData = ""); + void SendChat(const cCompositeChat & a_Message); + void SendChatRaw(const AString & a_MessageRaw, eChatType a_Type); + void SendChatAboveActionBar( + const AString & a_Message, + eMessageType a_ChatPrefix, + const AString & a_AdditionalData = "" + ); + void SendChatAboveActionBar(const cCompositeChat & a_Message); + void SendChatSystem(const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData = ""); + void SendChatSystem(const cCompositeChat & a_Message); + void SendChunkData(int a_ChunkX, int a_ChunkZ, ContiguousByteBufferView a_ChunkData); + void SendCollectEntity(const cEntity & a_Collected, const cEntity & a_Collector, unsigned a_Count); // tolua_export + void SendDestroyEntity(const cEntity & a_Entity); // tolua_export + void SendDetachEntity(const cEntity & a_Entity, const cEntity & a_PreviousVehicle); // tolua_export + void SendDisconnect(const AString & a_Reason); + void SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display); + void SendEditSign(Vector3i a_BlockPos); // tolua_export + void SendEntityAnimation(const cEntity & a_Entity, EntityAnimation a_Animation); // tolua_export + void SendEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, int a_Duration); + void SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item); + void SendEntityHeadLook(const cEntity & a_Entity); + void SendEntityLook(const cEntity & a_Entity); + void SendEntityMetadata(const cEntity & a_Entity); + void SendEntityPosition(const cEntity & a_Entity); + void SendEntityProperties(const cEntity & a_Entity); + void SendEntityVelocity(const cEntity & a_Entity); + void SendExperience(void); + void SendExperienceOrb(const cExpOrb & a_ExpOrb); + void SendExplosion(Vector3f a_Position, float a_Power); + void SendGameMode(eGameMode a_GameMode); + void SendHealth(void); + void SendHeldItemChange(int a_ItemIndex); + void SendHideTitle(void); // tolua_export + void SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item); + void SendLeashEntity(const cEntity & a_Entity, const cEntity & a_EntityLeashedTo); // tolua_export + void SendMapData(const cMap & a_Map, int a_DataStartX, int a_DataStartY); + void SendPaintingSpawn(const cPainting & a_Painting); + void SendParticleEffect( + const AString & a_ParticleName, + Vector3f a_Source, + Vector3f a_Offset, + float a_ParticleData, + int a_ParticleAmount + ); + void SendParticleEffect( + const AString & a_ParticleName, + const Vector3f a_Src, + const Vector3f a_Offset, + float a_ParticleData, + int a_ParticleAmount, + std::array<int, 2> a_Data + ); + void SendPlayerAbilities(void); + void SendPlayerListAddPlayer(const cPlayer & a_Player); + void SendPlayerListHeaderFooter(const cCompositeChat & a_Header, const cCompositeChat & a_Footer); // tolua_export + void SendPlayerListRemovePlayer(const cPlayer & a_Player); void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName); - void SendPlayerListUpdateGameMode (const cPlayer & a_Player); - void SendPlayerListUpdatePing (); - void SendPlayerMoveLook (Vector3d a_Pos, float a_Yaw, float a_Pitch, bool a_IsRelative); - void SendPlayerMoveLook (void); - void SendPlayerPermissionLevel (void); - void SendPlayerPosition (void); - void SendPlayerSpawn (const cPlayer & a_Player); - void SendPluginMessage (const AString & a_Channel, std::string_view a_Message); // Exported in ManualBindings.cpp - void SendPluginMessage (const AString & a_Channel, ContiguousByteBufferView a_Message); - void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID); - void SendResourcePack (const AString & a_ResourcePackUrl); // tolua_export - void SendResetTitle (void); // tolua_export - void SendRespawn (eDimension a_Dimension, bool a_IsRespawningFromDeath); - void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode); - void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode); - void SendSetSubTitle (const cCompositeChat & a_SubTitle); // tolua_export - void SendSetRawSubTitle (const AString & a_SubTitle); // tolua_export - void SendSetTitle (const cCompositeChat & a_Title); // tolua_export - void SendSetRawTitle (const AString & a_Title); // tolua_export - void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch); // tolua_export - void SendSoundEffect (const AString & a_SoundName, Vector3d a_Position, float a_Volume, float a_Pitch); // tolua_export - void SendSoundParticleEffect (const EffectID a_EffectID, Vector3i a_Source, int a_Data); - void SendSpawnEntity (const cEntity & a_Entity); - void SendSpawnMob (const cMonster & a_Mob); - void SendStatistics (const StatisticsManager & a_Manager); - void SendTabCompletionResults (const AStringVector & a_Results); - void SendThunderbolt (Vector3i a_BlockPos); // tolua_export - void SendTitleTimes (int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks); // tolua_export - void SendTimeUpdate (cTickTimeLong a_WorldAge, cTickTimeLong a_WorldDate, bool a_DoDaylightCycle); - void SendUnleashEntity (const cEntity & a_Entity); // tolua_export - void SendUnloadChunk (int a_ChunkX, int a_ChunkZ); - void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity); - void SendUpdateSign (Vector3i a_BlockPos, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4); + void SendPlayerListUpdateGameMode(const cPlayer & a_Player); + void SendPlayerListUpdatePing(); + void SendPlayerMoveLook(Vector3d a_Pos, float a_Yaw, float a_Pitch, bool a_IsRelative); + void SendPlayerMoveLook(void); + void SendPlayerPermissionLevel(void); + void SendPlayerPosition(void); + void SendPlayerSpawn(const cPlayer & a_Player); + void SendPluginMessage(const AString & a_Channel, std::string_view a_Message); // Exported in ManualBindings.cpp + void SendPluginMessage(const AString & a_Channel, ContiguousByteBufferView a_Message); + void SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID); + void SendResourcePack(const AString & a_ResourcePackUrl); // tolua_export + void SendResetTitle(void); // tolua_export + void SendRespawn(eDimension a_Dimension, bool a_IsRespawningFromDeath); + void SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode); + void SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode); + void SendSetSubTitle(const cCompositeChat & a_SubTitle); // tolua_export + void SendSetRawSubTitle(const AString & a_SubTitle); // tolua_export + void SendSetTitle(const cCompositeChat & a_Title); // tolua_export + void SendSetRawTitle(const AString & a_Title); // tolua_export + // tolua_begin + void SendSoundEffect( + const AString & a_SoundName, + double a_X, + double a_Y, + double a_Z, + float a_Volume, + float a_Pitch + ); + void SendSoundEffect(const AString & a_SoundName, Vector3d a_Position, float a_Volume, float a_Pitch); + // tolua_end + void SendSoundParticleEffect(const EffectID a_EffectID, Vector3i a_Source, int a_Data); + void SendSpawnEntity(const cEntity & a_Entity); + void SendSpawnMob(const cMonster & a_Mob); + void SendStatistics(const StatisticsManager & a_Manager); + void SendTabCompletionResults(const AStringVector & a_Results); + void SendThunderbolt(Vector3i a_BlockPos); // tolua_export + void SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks); // tolua_export + void SendTimeUpdate(cTickTimeLong a_WorldAge, cTickTimeLong a_WorldDate, bool a_DoDaylightCycle); + void SendUnleashEntity(const cEntity & a_Entity); // tolua_export + void SendUnloadChunk(int a_ChunkX, int a_ChunkZ); + void SendUpdateBlockEntity(cBlockEntity & a_BlockEntity); + void SendUpdateSign( + Vector3i a_BlockPos, + const AString & a_Line1, + const AString & a_Line2, + const AString & a_Line3, + const AString & a_Line4 + ); /** Send a newly discovered recipe to show the notification and unlock in the recipe book */ - void SendUnlockRecipe (UInt32 a_RecipeId); + void SendUnlockRecipe(UInt32 a_RecipeId); /** Send already known recipes without notification but visible in the recipe book */ - void SendInitRecipes (UInt32 a_RecipeId); + void SendInitRecipes(UInt32 a_RecipeId); - void SendWeather (eWeather a_Weather); - void SendWholeInventory (const cWindow & a_Window); - void SendWindowClose (const cWindow & a_Window); - void SendWindowOpen (const cWindow & a_Window); - void SendWindowProperty (const cWindow & a_Window, size_t a_Property, short a_Value); + void SendWeather(eWeather a_Weather); + void SendWholeInventory(const cWindow & a_Window); + void SendWindowClose(const cWindow & a_Window); + void SendWindowOpen(const cWindow & a_Window); + void SendWindowProperty(const cWindow & a_Window, size_t a_Property, short a_Value); const AString & GetUsername(void) const; // tolua_export void SetUsername(AString && a_Username); // tolua_begin - inline short GetPing(void) const { return static_cast<short>(std::chrono::duration_cast<std::chrono::milliseconds>(m_Ping).count()); } + inline short GetPing(void) const + { + return static_cast<short>(std::chrono::duration_cast<std::chrono::milliseconds>(m_Ping).count()); + } /** Sets the maximal view distance. */ void SetViewDistance(int a_ViewDistance); @@ -293,10 +357,7 @@ public: // tolua_export } /** Mark a client connection as using Forge. Set by the protocol. */ - void SetIsForgeClient() - { - m_ForgeHandshake.IsForgeClient = true; - } + void SetIsForgeClient() { m_ForgeHandshake.IsForgeClient = true; } /** Returns true if the client wants the chunk specified to be sent (in m_ChunksToSend) */ bool WantsSendChunk(int a_ChunkX, int a_ChunkZ); @@ -349,13 +410,13 @@ public: // tolua_export otherwise the first instant when a username is received). Returns true if the player is to be let in, false if they were disconnected */ - bool HandleHandshake (const AString & a_Username); + bool HandleHandshake(const AString & a_Username); /** Handles a player exiting his bed. */ void HandleLeaveBed(); - void HandleKeepAlive (UInt32 a_KeepAliveID); - void HandleLeftClick (Vector3i a_BlockPos, eBlockFace a_BlockFace, UInt8 a_Status); + void HandleKeepAlive(UInt32 a_KeepAliveID); + void HandleLeftClick(Vector3i a_BlockPos, eBlockFace a_BlockFace, UInt8 a_Status); /** Called when the protocol receives a MC|TrSel packet, indicating that the player used a trade in the NPC UI. */ @@ -364,9 +425,9 @@ public: // tolua_export /** Handles a player opening his inventory while riding a horse. */ void HandleOpenHorseInventory(); - void HandlePing (void); - void HandlePlayerAbilities (bool a_IsFlying, float FlyingSpeed, float WalkingSpeed); - void HandlePlayerLook (float a_Rotation, float a_Pitch, bool a_IsOnGround); + void HandlePing(void); + void HandlePlayerAbilities(bool a_IsFlying, float FlyingSpeed, float WalkingSpeed); + void HandlePlayerLook(float a_Rotation, float a_Pitch, bool a_IsOnGround); /** Verifies and sets player position, performing relevant checks. Calls relevant methods to process movement related statistics. @@ -376,12 +437,12 @@ public: // tolua_export void HandlePlayerMoveLook(Vector3d a_Pos, float a_Rotation, float a_Pitch, bool a_IsOnGround); - void HandlePluginMessage (const AString & a_Channel, ContiguousByteBufferView a_Message); - void HandleResourcePack (UInt8 a_Status); - void HandleRespawn (void); - void HandleRightClick (Vector3i a_BlockPos, eBlockFace a_BlockFace, Vector3i a_Cursor, bool a_UsedMainHand); - void HandleSlotSelected (Int16 a_SlotNum); - void HandleSpectate (const cUUID & a_PlayerUUID); + void HandlePluginMessage(const AString & a_Channel, ContiguousByteBufferView a_Message); + void HandleResourcePack(UInt8 a_Status); + void HandleRespawn(void); + void HandleRightClick(Vector3i a_BlockPos, eBlockFace a_BlockFace, Vector3i a_Cursor, bool a_UsedMainHand); + void HandleSlotSelected(Int16 a_SlotNum); + void HandleSpectate(const cUUID & a_PlayerUUID); /** Handles a player sprinting or slowing back down. */ void HandleSprint(bool a_IsSprinting); @@ -389,21 +450,23 @@ public: // tolua_export /** Handles a player starting elytra flight while falling. */ void HandleStartElytraFlight(); - void HandleSteerVehicle (float Forward, float Sideways); - void HandleTabCompletion (const AString & a_Text); - void HandleUpdateSign ( + void HandleSteerVehicle(float Forward, float Sideways); + void HandleTabCompletion(const AString & a_Text); + void HandleUpdateSign( Vector3i a_BlockPos, - const AString & a_Line1, const AString & a_Line2, - const AString & a_Line3, const AString & a_Line4 + const AString & a_Line1, + const AString & a_Line2, + const AString & a_Line3, + const AString & a_Line4 ); - void HandleUnmount (void); - void HandleUseEntity (UInt32 a_TargetEntityID, bool a_IsLeftClick); - void HandleUseItem (bool a_UsedMainHand); - void HandleWindowClick (UInt8 a_WindowID, Int16 a_SlotNum, eClickAction a_ClickAction, const cItem & a_HeldItem); - void HandleWindowClose (UInt8 a_WindowID); + void HandleUnmount(void); + void HandleUseEntity(UInt32 a_TargetEntityID, bool a_IsLeftClick); + void HandleUseItem(bool a_UsedMainHand); + void HandleWindowClick(UInt8 a_WindowID, Int16 a_SlotNum, eClickAction a_ClickAction, const cItem & a_HeldItem); + void HandleWindowClose(UInt8 a_WindowID); /** Called when a recipe from the recipe book is selected */ - void HandleCraftRecipe (UInt32 a_RecipeId); + void HandleCraftRecipe(UInt32 a_RecipeId); /** Called when the protocol has finished logging the user in. Return true to allow the user in; false to kick them. */ @@ -418,14 +481,14 @@ public: // tolua_export /** Called by the protocol recognizer when the protocol version is known. */ void SetProtocolVersion(UInt32 a_ProtocolVersion) { m_ProtocolVersion = a_ProtocolVersion; } - /** Returns the protocol version number of the protocol that the client is talking. Returns zero if the protocol version is not (yet) known. */ + /** Returns the protocol version number of the protocol that the client is talking. Returns zero if the protocol + * version is not (yet) known. */ UInt32 GetProtocolVersion(void) const { return m_ProtocolVersion; } // tolua_export bool IsPlayerChunkSent(); -private: - - friend class cForgeHandshake; // Needs access to FinishAuthenticate() + private: + friend class cForgeHandshake; // Needs access to FinishAuthenticate() /** The type used for storing the names of registered plugin channels. */ typedef std::set<AString> cChannels; @@ -448,10 +511,12 @@ private: AString m_Password; Json::Value m_Properties; - cCriticalSection m_CSChunkLists; + cCriticalSection m_CSChunkLists; std::unordered_set<cChunkCoords, cChunkCoordsHash> m_LoadedChunks; // Chunks that the player belongs to - std::unordered_set<cChunkCoords, cChunkCoordsHash> m_ChunksToSend; // Chunks that need to be sent to the player (queued because they weren't generated yet or there's not enough time to send them) - cChunkCoordsList m_SentChunks; // Chunks that are currently sent to the client + std::unordered_set<cChunkCoords, cChunkCoordsHash> + m_ChunksToSend; // Chunks that need to be sent to the player (queued because they weren't generated yet or + // there's not enough time to send them) + cChunkCoordsList m_SentChunks; // Chunks that are currently sent to the client cMultiVersionProtocol m_Protocol; @@ -471,16 +536,16 @@ private: /** A pointer to a World-owned player object, created in FinishAuthenticate when authentication succeeds. The player should only be accessed from the tick thread of the World that owns him. - After the player object is handed off to the World, its lifetime is managed automatically, and strongly owns this client handle. - The player self-destructs some time after the client handle enters the Destroyed state. - We are therefore guaranteed that while m_State < Destroyed, that is when when we need to access m_Player, m_Player is valid. */ + After the player object is handed off to the World, its lifetime is managed automatically, and strongly owns this + client handle. The player self-destructs some time after the client handle enters the Destroyed state. We are + therefore guaranteed that while m_State < Destroyed, that is when when we need to access m_Player, m_Player is + valid. */ cPlayer * m_Player; /** This is an optimization which saves you an iteration of m_SentChunks if you just want to know whether or not the player is standing at a sent chunk. - If this is equal to the coordinates of the chunk the player is currrently standing at, then this must be a sent chunk - and a member of m_SentChunks. - Otherwise, this contains an arbitrary value which should not be used. */ + If this is equal to the coordinates of the chunk the player is currrently standing at, then this must be a sent + chunk and a member of m_SentChunks. Otherwise, this contains an arbitrary value which should not be used. */ cChunkCoords m_CachedSentChunk; bool m_ProxyConnection; ///< True if player connected from a proxy (Bungee / Velocity) @@ -511,18 +576,20 @@ private: int m_BlockDigAnimSpeed; // Current speed of the animation (units ???) Vector3i m_BlockDigAnimPos; - // To avoid dig / aim bug in the client, store the last position given in a DIG_START packet and compare to that when processing the DIG_FINISH packet: + // To avoid dig / aim bug in the client, store the last position given in a DIG_START packet and compare to that + // when processing the DIG_FINISH packet: bool m_HasStartedDigging; Vector3i m_LastDigBlockPos; enum eState { - csConnected, ///< The client has just connected, waiting for their handshake / login - csAuthenticating, ///< The client has logged in, waiting for external authentication - csDownloadingWorld, ///< The client is waiting for chunks, we're waiting for the loader to provide and send them - csPlaying, ///< Normal gameplay - csDestroyed, ///< The client has been destroyed, the destructor is to be called from the owner thread - } ; + csConnected, ///< The client has just connected, waiting for their handshake / login + csAuthenticating, ///< The client has logged in, waiting for external authentication + csDownloadingWorld, ///< The client is waiting for chunks, we're waiting for the loader to provide and send + ///< them + csPlaying, ///< Normal gameplay + csDestroyed, ///< The client has been destroyed, the destructor is to be called from the owner thread + }; /* Mutex protecting m_State from concurrent writes. */ cCriticalSection m_CSState; @@ -530,8 +597,8 @@ private: /** The current (networking) state of the client. Protected from concurrent writes by m_CSState; but may be read by other threads concurrently. If a function depends on m_State or wants to change m_State, it needs to lock m_CSState. - However, if it only uses m_State for a quick bail out, or it doesn't break if the client disconnects in the middle of it, - it may just read m_State without locking m_CSState. */ + However, if it only uses m_State for a quick bail out, or it doesn't break if the client disconnects in the middle + of it, it may just read m_State without locking m_CSState. */ std::atomic<eState> m_State; /** Number of explosions sent this tick */ @@ -589,7 +656,7 @@ private: void StreamChunk(int a_ChunkX, int a_ChunkZ, cChunkSender::Priority a_Priority); /** Handles the DIG_STARTED dig packet: */ - void HandleBlockDigStarted (Vector3i a_BlockPos, eBlockFace a_BlockFace); + void HandleBlockDigStarted(Vector3i a_BlockPos, eBlockFace a_BlockFace); /** Handles the DIG_FINISHED dig packet: */ void HandleBlockDigFinished(Vector3i a_BlockPos, eBlockFace a_BlockFace); |