Cuberite
A lightweight, fast and extensible game server for Minecraft
ClientHandle.h
Go to the documentation of this file.
1 
2 // cClientHandle.h
3 
4 // Interfaces to the cClientHandle class representing a client connected to this server. The client need not be a player yet
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "OSSupport/Network.h"
13 #include "Defines.h"
14 #include "Scoreboard.h"
15 #include "UI/SlotArea.h"
16 #include "json/json.h"
17 #include "ChunkSender.h"
18 #include "EffectID.h"
21 #include "UUID.h"
22 
23 
24 
25 
26 
27 // fwd:
29 class cMonster;
30 class cExpOrb;
31 class cPainting;
32 class cPickup;
33 class cPlayer;
34 class cProtocol;
35 class cWindow;
36 class cFallingBlock;
37 class cCompositeChat;
38 class cMap;
39 class cClientHandle;
40 
41 struct StatisticsManager;
42 
43 typedef std::shared_ptr<cClientHandle> cClientHandlePtr;
44 
45 
46 
47 
48 
49 class cClientHandle // tolua_export
50  : public cTCPLink::cCallbacks, public std::enable_shared_from_this<cClientHandle>
51 { // tolua_export
52 public: // tolua_export
53 
54  #if defined(ANDROID)
55  static const int DEFAULT_VIEW_DISTANCE = 4; // The default ViewDistance (used when no value is set in Settings.ini)
56  #else
57  static const int DEFAULT_VIEW_DISTANCE = 10;
58  #endif
59  static const int MAX_VIEW_DISTANCE = 32;
60  static const int MIN_VIEW_DISTANCE = 1;
61 
65  static float FASTBREAK_PERCENTAGE;
66 
68  cClientHandle(const AString & a_IPString, int a_ViewDistance);
69 
70  virtual ~cClientHandle() override;
71 
72  const AString & GetIPString(void) const { return m_IPString; } // tolua_export
73 
76  void SetIPString(const AString & a_IPString) { m_IPString = a_IPString; }
77 
78  cPlayer * GetPlayer(void) { return m_Player; } // tolua_export
79 
81  const cUUID & GetUUID(void) const { return m_UUID; } // Exported in ManualBindings.cpp
82 
86  void SetUUID(const cUUID & a_UUID) { ASSERT(!a_UUID.IsNil()); m_UUID = a_UUID; }
87 
88  const Json::Value & GetProperties(void) const { return m_Properties; }
89 
93  void SetProperties(const Json::Value & a_Properties) { m_Properties = a_Properties; }
94 
98  static cUUID GenerateOfflineUUID(const AString & a_Username); // Exported in ManualBindings.cpp
99 
102  static bool IsUUIDOnline(const cUUID & a_UUID); // Exported in ManualBindings.cpp
103 
105  void ProxyInit(const AString & a_IPString, const cUUID & a_UUID);
106  void ProxyInit(const AString & a_IPString, const cUUID & a_UUID, const Json::Value & a_Properties);
107 
110  void ProcessProtocolIn(void);
111 
113  void ProcessProtocolOut();
114 
116  static AString FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString & a_AdditionalData);
117 
118  static AString FormatChatPrefix(
119  bool ShouldAppendChatPrefixes, const AString & a_ChatPrefixS,
120  const AString & m_Color1, const AString & m_Color2
121  );
122 
123  void Kick(const AString & a_Reason); // tolua_export
124 
126  bool BungeeAuthenticate();
127 
129  void Authenticate(AString && a_Name, const cUUID & a_UUID, Json::Value && a_Properties);
130 
132  void StreamNextChunks();
133 
135  void UnloadOutOfRangeChunks(void);
136 
137  inline bool IsLoggedIn(void) const { return (m_State >= csAuthenticating); }
138 
140  void Tick(std::chrono::milliseconds a_Dt);
141 
143  void ServerTick(float a_Dt);
144 
145  void Destroy(void);
146 
147  bool IsPlaying (void) const { return (m_State == csPlaying); }
148  bool IsDestroyed (void) const { return (m_State == csDestroyed); }
149 
150  // The following functions send the various packets:
151  // (Please keep these alpha-sorted)
152  void SendAttachEntity (const cEntity & a_Entity, const cEntity & a_Vehicle);
153  void SendBlockAction (Vector3i a_BlockPos, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType);
154  void SendBlockBreakAnim (UInt32 a_EntityID, Vector3i a_BlockPos, char a_Stage); // tolua_export
155  void SendBlockChange (Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); // tolua_export
156  void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes);
157  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
158  void SendBossBarUpdateFlags (UInt32 a_UniqueID, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog); // tolua_export
159  void SendBossBarUpdateStyle (UInt32 a_UniqueID, BossBarColor a_Color, BossBarDivisionType a_DivisionType); // tolua_export
160  void SendBossBarUpdateTitle (UInt32 a_UniqueID, const cCompositeChat & a_Title); // tolua_export
161  void SendBossBarRemove (UInt32 a_UniqueID); // tolua_export
162  void SendBossBarUpdateHealth (UInt32 a_UniqueID, float a_FractionFilled); // tolua_export
163  void SendCameraSetTo (const cEntity & a_Entity);
164  void SendChat (const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData = "");
165  void SendChat (const cCompositeChat & a_Message);
166  void SendChatRaw (const AString & a_MessageRaw, eChatType a_Type);
167  void SendChatAboveActionBar (const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData = "");
168  void SendChatAboveActionBar (const cCompositeChat & a_Message);
169  void SendChatSystem (const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData = "");
170  void SendChatSystem (const cCompositeChat & a_Message);
171  void SendChunkData (int a_ChunkX, int a_ChunkZ, ContiguousByteBufferView a_ChunkData);
172  void SendCollectEntity (const cEntity & a_Collected, const cEntity & a_Collector, unsigned a_Count); // tolua_export
173  void SendDestroyEntity (const cEntity & a_Entity); // tolua_export
174  void SendDetachEntity (const cEntity & a_Entity, const cEntity & a_PreviousVehicle); // tolua_export
175  void SendDisconnect (const AString & a_Reason);
176  void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display);
177  void SendEditSign (Vector3i a_BlockPos); // tolua_export
178  void SendEntityAnimation (const cEntity & a_Entity, EntityAnimation a_Animation); // tolua_export
179  void SendEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, int a_Duration);
180  void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item);
181  void SendEntityHeadLook (const cEntity & a_Entity);
182  void SendEntityLook (const cEntity & a_Entity);
183  void SendEntityMetadata (const cEntity & a_Entity);
184  void SendEntityPosition (const cEntity & a_Entity);
185  void SendEntityProperties (const cEntity & a_Entity);
186  void SendEntityVelocity (const cEntity & a_Entity);
187  void SendExperience (void);
188  void SendExperienceOrb (const cExpOrb & a_ExpOrb);
189  void SendExplosion (Vector3f a_Position, float a_Power);
190  void SendGameMode (eGameMode a_GameMode);
191  void SendHealth (void);
192  void SendHeldItemChange (int a_ItemIndex);
193  void SendHideTitle (void); // tolua_export
194  void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item);
195  void SendLeashEntity (const cEntity & a_Entity, const cEntity & a_EntityLeashedTo); // tolua_export
196  void SendMapData (const cMap & a_Map, int a_DataStartX, int a_DataStartY);
197  void SendPaintingSpawn (const cPainting & a_Painting);
198  void SendParticleEffect (const AString & a_ParticleName, Vector3f a_Source, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount);
199  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);
200  void SendPlayerAbilities (void);
201  void SendPlayerListAddPlayer (const cPlayer & a_Player);
202  void SendPlayerListHeaderFooter (const cCompositeChat & a_Header, const cCompositeChat & a_Footer); // tolua_export
203  void SendPlayerListRemovePlayer (const cPlayer & a_Player);
204  void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName);
205  void SendPlayerListUpdateGameMode (const cPlayer & a_Player);
206  void SendPlayerListUpdatePing ();
207  void SendPlayerMoveLook (Vector3d a_Pos, float a_Yaw, float a_Pitch, bool a_IsRelative);
208  void SendPlayerMoveLook (void);
209  void SendPlayerPermissionLevel (void);
210  void SendPlayerPosition (void);
211  void SendPlayerSpawn (const cPlayer & a_Player);
212  void SendPluginMessage (const AString & a_Channel, std::string_view a_Message); // Exported in ManualBindings.cpp
213  void SendPluginMessage (const AString & a_Channel, ContiguousByteBufferView a_Message);
214  void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID);
215  void SendResourcePack (const AString & a_ResourcePackUrl); // tolua_export
216  void SendResetTitle (void); // tolua_export
217  void SendRespawn (eDimension a_Dimension, bool a_IsRespawningFromDeath);
218  void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode);
219  void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode);
220  void SendSetSubTitle (const cCompositeChat & a_SubTitle); // tolua_export
221  void SendSetRawSubTitle (const AString & a_SubTitle); // tolua_export
222  void SendSetTitle (const cCompositeChat & a_Title); // tolua_export
223  void SendSetRawTitle (const AString & a_Title); // tolua_export
224  void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch); // tolua_export
225  void SendSoundEffect (const AString & a_SoundName, Vector3d a_Position, float a_Volume, float a_Pitch); // tolua_export
226  void SendSoundParticleEffect (const EffectID a_EffectID, Vector3i a_Source, int a_Data);
227  void SendSpawnEntity (const cEntity & a_Entity);
228  void SendSpawnMob (const cMonster & a_Mob);
229  void SendStatistics (const StatisticsManager & a_Manager);
230  void SendTabCompletionResults (const AStringVector & a_Results);
231  void SendThunderbolt (Vector3i a_BlockPos); // tolua_export
232  void SendTitleTimes (int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks); // tolua_export
233  void SendTimeUpdate (cTickTimeLong a_WorldAge, cTickTimeLong a_WorldDate, bool a_DoDaylightCycle);
234  void SendUnleashEntity (const cEntity & a_Entity); // tolua_export
235  void SendUnloadChunk (int a_ChunkX, int a_ChunkZ);
236  void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity);
237  void SendUpdateSign (Vector3i a_BlockPos, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
238 
240  void SendUnlockRecipe (UInt32 a_RecipeId);
241 
243  void SendInitRecipes (UInt32 a_RecipeId);
244 
245  void SendWeather (eWeather a_Weather);
246  void SendWholeInventory (const cWindow & a_Window);
247  void SendWindowClose (const cWindow & a_Window);
248  void SendWindowOpen (const cWindow & a_Window);
249  void SendWindowProperty (const cWindow & a_Window, size_t a_Property, short a_Value);
250 
251  const AString & GetUsername(void) const; // tolua_export
252  void SetUsername(AString && a_Username);
253 
254  // tolua_begin
255 
256  inline short GetPing(void) const { return static_cast<short>(std::chrono::duration_cast<std::chrono::milliseconds>(m_Ping).count()); }
257 
259  void SetViewDistance(int a_ViewDistance);
260 
262  int GetViewDistance(void) const { return m_CurrentViewDistance; }
263 
266 
267  void SetLocale(const AString & a_Locale) { m_Locale = a_Locale; }
268  AString GetLocale(void) const { return m_Locale; }
269 
270  int GetUniqueID(void) const { return m_UniqueID; }
271 
272  bool HasPluginChannel(const AString & a_PluginChannel);
273 
276  void SetClientBrand(const AString & a_ClientBrand) { m_ClientBrand = a_ClientBrand; }
277 
279  const AString & GetClientBrand(void) const { return m_ClientBrand; }
280 
282  const AStringMap & GetForgeMods(void) const { return m_ForgeMods; }
283 
285  bool IsForgeClient(void) const { return m_ForgeHandshake.IsForgeClient; }
286 
287  // tolua_end
288 
290  void ForgeAugmentServerListPing(Json::Value & a_Response)
291  {
292  m_ForgeHandshake.AugmentServerListPing(*this, a_Response);
293  }
294 
297  {
299  }
300 
302  bool WantsSendChunk(int a_ChunkX, int a_ChunkZ);
303 
305  void AddWantedChunk(int a_ChunkX, int a_ChunkZ);
306 
307  // Calls that cProtocol descendants use to report state:
308  void PacketBufferFull(void);
309  void PacketUnknown(UInt32 a_PacketType);
310  void PacketError(UInt32 a_PacketType);
311 
313  void HandleAnimation(bool a_SwingMainHand);
314 
317  void HandleAnvilItemName(const AString & a_ItemName);
318 
321  void HandleBeaconSelection(unsigned a_PrimaryEffect, unsigned a_SecondaryEffect);
322 
324  void HandleChat(const AString & a_Message);
325 
328  void HandleCommandBlockBlockChange(Vector3i a_BlockPos, const AString & a_NewCommand);
329 
332  void HandleCommandBlockEntityChange(UInt32 a_EntityID, const AString & a_NewCommand);
333 
336  void HandleCreativeInventory(Int16 a_SlotNum, const cItem & a_HeldItem, eClickAction a_ClickAction);
337 
339  void HandleCrouch(bool a_IsCrouching);
340 
342  void HandleEnchantItem(UInt8 a_WindowID, UInt8 a_Enchantment);
343 
346  bool CheckMultiLogin(const AString & a_Username);
347 
352  bool HandleHandshake (const AString & a_Username);
353 
355  void HandleLeaveBed();
356 
357  void HandleKeepAlive (UInt32 a_KeepAliveID);
358  void HandleLeftClick (Vector3i a_BlockPos, eBlockFace a_BlockFace, UInt8 a_Status);
359 
362  void HandleNPCTrade(int a_SlotNum);
363 
366 
367  void HandlePing (void);
368  void HandlePlayerAbilities (bool a_IsFlying, float FlyingSpeed, float WalkingSpeed);
369  void HandlePlayerLook (float a_Rotation, float a_Pitch, bool a_IsOnGround);
370 
374  void HandlePlayerMove(Vector3d a_Pos, bool a_IsOnGround);
375 
376  void HandlePlayerMoveLook(Vector3d a_Pos, float a_Rotation, float a_Pitch, bool a_IsOnGround);
377 
378 
379  void HandlePluginMessage (const AString & a_Channel, ContiguousByteBufferView a_Message);
380  void HandleResourcePack (UInt8 a_Status);
381  void HandleRespawn (void);
382  void HandleRightClick (Vector3i a_BlockPos, eBlockFace a_BlockFace, Vector3i a_Cursor, bool a_UsedMainHand);
383  void HandleSlotSelected (Int16 a_SlotNum);
384  void HandleSpectate (const cUUID & a_PlayerUUID);
385 
387  void HandleSprint(bool a_IsSprinting);
388 
391 
392  void HandleSteerVehicle (float Forward, float Sideways);
393  void HandleTabCompletion (const AString & a_Text);
394  void HandleUpdateSign (
395  Vector3i a_BlockPos,
396  const AString & a_Line1, const AString & a_Line2,
397  const AString & a_Line3, const AString & a_Line4
398  );
399  void HandleUnmount (void);
400  void HandleUseEntity (UInt32 a_TargetEntityID, bool a_IsLeftClick);
401  void HandleUseItem (bool a_UsedMainHand);
402  void HandleWindowClick (UInt8 a_WindowID, Int16 a_SlotNum, eClickAction a_ClickAction, const cItem & a_HeldItem);
403  void HandleWindowClose (UInt8 a_WindowID);
404 
406  void HandleCraftRecipe (UInt32 a_RecipeId);
407 
410  bool HandleLogin();
411 
412  void SendData(ContiguousByteBufferView a_Data);
413 
416  void RemoveFromWorld(void);
417 
419  void SetProtocolVersion(UInt32 a_ProtocolVersion) { m_ProtocolVersion = a_ProtocolVersion; }
420 
422  UInt32 GetProtocolVersion(void) const { return m_ProtocolVersion; } // tolua_export
423 
424  bool IsPlayerChunkSent();
425 
426 private:
427 
428  friend class cForgeHandshake; // Needs access to FinishAuthenticate()
429 
431  typedef std::set<AString> cChannels;
432 
435 
438 
441 
444 
446 
449  Json::Value m_Properties;
450 
452  std::unordered_set<cChunkCoords, cChunkCoordsHash> m_LoadedChunks; // Chunks that the player belongs to
453  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)
454  cChunkCoordsList m_SentChunks; // Chunks that are currently sent to the client
455 
457 
460 
464 
467 
471 
478 
485 
487 
488  bool m_HasSentDC;
489 
490  // Chunk position when the last StreamChunks() was called; used to avoid re-streaming while in the same chunk
493 
495  std::atomic<int> m_TicksSinceLastPacket;
496 
498  std::chrono::milliseconds m_TimeSinceLastUnloadCheck;
499 
501  std::chrono::steady_clock::duration m_Ping;
502 
505 
507  std::chrono::steady_clock::time_point m_PingStartTime;
508 
509  // Values required for block dig animation
510  int m_BlockDigAnimStage; // Current stage of the animation; -1 if not digging
511  int m_BlockDigAnimSpeed; // Current speed of the animation (units ???)
513 
514  // 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:
517 
518  enum eState
519  {
525  } ;
526 
527  /* Mutex protecting m_State from concurrent writes. */
529 
535  std::atomic<eState> m_State;
536 
539 
542 
543  static int s_ClientCount;
544 
546 
549 
552 
555 
558 
561 
564 
567 
570 
574 
578 
580  void FinishAuthenticate();
581 
583  bool CheckBlockInteractionsRate(void);
584 
586  bool IsWithinReach(Vector3i a_Position) const;
587 
589  void StreamChunk(int a_ChunkX, int a_ChunkZ, cChunkSender::Priority a_Priority);
590 
592  void HandleBlockDigStarted (Vector3i a_BlockPos, eBlockFace a_BlockFace);
593 
595  void HandleBlockDigFinished(Vector3i a_BlockPos, eBlockFace a_BlockFace);
596 
598  void FinishDigAnimation();
599 
602 
604  void RegisterPluginChannels(const AStringVector & a_ChannelList);
605 
607  void UnregisterPluginChannels(const AStringVector & a_ChannelList);
608 
610  void SocketClosed(void);
611 
614  bool SetState(eState a_NewState);
615 
616  // cTCPLink::cCallbacks overrides:
617  virtual void OnLinkCreated(cTCPLinkPtr a_Link) override;
618  virtual void OnReceivedData(const char * a_Data, size_t a_Length) override;
619  virtual void OnRemoteClosed(void) override;
620  virtual void OnError(int a_ErrorCode, const AString & a_ErrorMsg) override;
621 }; // tolua_export
std::vector< sSetBlock > sSetBlockVector
Definition: ChunkDef.h:441
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
std::list< cChunkCoords > cChunkCoordsList
Definition: ChunkDef.h:443
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
std::shared_ptr< cClientHandle > cClientHandlePtr
Definition: ClientHandle.h:41
eWeather
Definition: Defines.h:160
BossBarDivisionType
Definition: Defines.h:443
EntityAnimation
Definition: Defines.h:458
eChatType
Definition: Defines.h:149
eDimension
Dimension of a world.
Definition: Defines.h:231
eGameMode
Definition: Defines.h:125
eClickAction
Individual actions sent in the WindowClick packet.
Definition: Defines.h:82
eMessageType
Definition: Defines.h:352
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
BossBarColor
Definition: Defines.h:428
EffectID
Definition: EffectID.h:6
std::chrono::duration< signed long long int, cTickTime::period > cTickTimeLong
Definition: Globals.h:367
unsigned int UInt32
Definition: Globals.h:157
signed short Int16
Definition: Globals.h:153
std::basic_string_view< std::byte > ContiguousByteBufferView
Definition: Globals.h:376
unsigned char UInt8
Definition: Globals.h:159
#define ASSERT(x)
Definition: Globals.h:276
std::basic_string< std::byte > ContiguousByteBuffer
Definition: Globals.h:375
unsigned char Byte
Definition: Globals.h:161
std::shared_ptr< cTCPLink > cTCPLinkPtr
Definition: Network.h:25
std::vector< AString > AStringVector
Definition: StringUtils.h:12
std::string AString
Definition: StringUtils.h:11
std::map< AString, AString > AStringMap
A string dictionary, used for key-value pairs.
Definition: StringUtils.h:16
Wraps the chunk coords into a single structure.
Definition: ChunkDef.h:57
Priority
Tag indicating urgency of chunk to be sent.
Definition: ChunkSender.h:64
std::set< AString > cChannels
The type used for storing the names of registered plugin channels.
Definition: ClientHandle.h:431
void SendSetRawSubTitle(const AString &a_SubTitle)
void FinishAuthenticate()
Finish logging the user in after authenticating.
static const int MAX_VIEW_DISTANCE
Definition: ClientHandle.h:59
const AStringMap & GetForgeMods(void) const
Returns the Forge mods installed on the client.
Definition: ClientHandle.h:282
void HandleUnmount(void)
void SendHideTitle(void)
bool CheckBlockInteractionsRate(void)
Returns true if the rate block interactions is within a reasonable limit (bot protection)
void StreamNextChunks()
Sends a set number of new chunks to the player on every invocation, until all chunks in the view dist...
static Vector3i s_IllegalPosition
Definition: ClientHandle.h:545
void SendSetSubTitle(const cCompositeChat &a_SubTitle)
void HandleCommandBlockBlockChange(Vector3i a_BlockPos, const AString &a_NewCommand)
Called when the protocol receives a message, indicating that the player set a new command in the comm...
bool IsLoggedIn(void) const
Definition: ClientHandle.h:137
int GetUniqueID(void) const
Definition: ClientHandle.h:270
cChannels m_PluginChannels
The plugin channels that the client has registered.
Definition: ClientHandle.h:563
void SendHeldItemChange(int a_ItemIndex)
cPlayer * m_Player
A pointer to a World-owned player object, created in FinishAuthenticate when authentication succeeds.
Definition: ClientHandle.h:477
void SetLocale(const AString &a_Locale)
Definition: ClientHandle.h:267
int m_NumBlockChangeInteractionsThisTick
Number of place or break interactions this tick.
Definition: ClientHandle.h:541
Vector3i m_LastPlacedSign
The positions from the last sign that the player placed.
Definition: ClientHandle.h:560
void HandleLeftClick(Vector3i a_BlockPos, eBlockFace a_BlockFace, UInt8 a_Status)
void HandleCommandBlockEntityChange(UInt32 a_EntityID, const AString &a_NewCommand)
Called when the protocol receives a message, indicating that the player set a new command in the comm...
void HandleRespawn(void)
cForgeHandshake m_ForgeHandshake
Forge handshake state machine.
Definition: ClientHandle.h:434
void SendSetTitle(const cCompositeChat &a_Title)
void SetViewDistance(int a_ViewDistance)
Sets the maximal view distance.
void SetUsername(AString &&a_Username)
void HandleEnchantItem(UInt8 a_WindowID, UInt8 a_Enchantment)
Called when the player enchants an Item in the Enchanting table UI.
void SendParticleEffect(const AString &a_ParticleName, Vector3f a_Source, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount)
AString m_Password
Definition: ClientHandle.h:448
cCriticalSection m_CSOutgoingData
Protects m_OutgoingData against multithreaded access.
Definition: ClientHandle.h:466
void SocketClosed(void)
Called when the network socket has been closed.
void SendLeashEntity(const cEntity &a_Entity, const cEntity &a_EntityLeashedTo)
AString m_Username
Definition: ClientHandle.h:447
int m_LastStreamedChunkX
Definition: ClientHandle.h:491
Json::Value m_Properties
Definition: ClientHandle.h:449
void Kick(const AString &a_Reason)
void SendChatRaw(const AString &a_MessageRaw, eChatType a_Type)
void HandleChat(const AString &a_Message)
Called when the protocol detects a chat packet.
bool IsForgeClient(void) const
Returns true if the client is modded with Forge.
Definition: ClientHandle.h:285
void UnregisterPluginChannels(const AStringVector &a_ChannelList)
Removes all of the channels from the list of current plugin channels.
void SendEntityProperties(const cEntity &a_Entity)
void ForgeAugmentServerListPing(Json::Value &a_Response)
Add the Forge mod list to the server ping response.
Definition: ClientHandle.h:290
void SendEntityHeadLook(const cEntity &a_Entity)
void SetClientBrand(const AString &a_ClientBrand)
Called by the protocol when it receives the MC|Brand plugin message.
Definition: ClientHandle.h:276
void SendPlayerListUpdateDisplayName(const cPlayer &a_Player, const AString &a_CustomName)
UInt32 m_PingID
ID of the last ping request sent to the client.
Definition: ClientHandle.h:504
static AString FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString &a_AdditionalData)
Formats the type of message with the proper color and prefix for sending to the client.
void SendDestroyEntity(const cEntity &a_Entity)
void SendScoreboardObjective(const AString &a_Name, const AString &a_DisplayName, Byte a_Mode)
Vector3i m_BlockDigAnimPos
Definition: ClientHandle.h:512
void HandleResourcePack(UInt8 a_Status)
void HandleAnvilItemName(const AString &a_ItemName)
Called when the protocol receives a MC|ItemName plugin message, indicating that the player named an i...
int m_CurrentViewDistance
The actual view distance used, the minimum of client's requested view distance and world's max view d...
Definition: ClientHandle.h:440
void SendChatAboveActionBar(const AString &a_Message, eMessageType a_ChatPrefix, const AString &a_AdditionalData="")
void SendWindowProperty(const cWindow &a_Window, size_t a_Property, short a_Value)
static float FASTBREAK_PERCENTAGE
The percentage how much a block has to be broken.
Definition: ClientHandle.h:65
void SendThunderbolt(Vector3i a_BlockPos)
void SendInitRecipes(UInt32 a_RecipeId)
Send already known recipes without notification but visible in the recipe book.
cCriticalSection m_CSState
Definition: ClientHandle.h:528
void SendPlayerListUpdateGameMode(const cPlayer &a_Player)
void SendEntityPosition(const cEntity &a_Entity)
std::atomic< int > m_TicksSinceLastPacket
Number of ticks since the last network packet was received (increased in Tick(), reset in OnReceivedD...
Definition: ClientHandle.h:495
void SendUnloadChunk(int a_ChunkX, int a_ChunkZ)
void SendSpawnMob(const cMonster &a_Mob)
void SetProtocolVersion(UInt32 a_ProtocolVersion)
Called by the protocol recognizer when the protocol version is known.
Definition: ClientHandle.h:419
void RegisterPluginChannels(const AStringVector &a_ChannelList)
Adds all of the channels to the list of current plugin channels.
void SendSoundParticleEffect(const EffectID a_EffectID, Vector3i a_Source, int a_Data)
virtual void OnLinkCreated(cTCPLinkPtr a_Link) override
Called when the cTCPLink for the connection is created.
void SendPlayerPermissionLevel(void)
std::unordered_set< cChunkCoords, cChunkCoordsHash > m_ChunksToSend
Definition: ClientHandle.h:453
void PacketUnknown(UInt32 a_PacketType)
void SendBlockChange(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
void SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem &a_Item)
void SendCameraSetTo(const cEntity &a_Entity)
void HandleWindowClick(UInt8 a_WindowID, Int16 a_SlotNum, eClickAction a_ClickAction, const cItem &a_HeldItem)
void SendScoreUpdate(const AString &a_Objective, const AString &a_Player, cObjective::Score a_Score, Byte a_Mode)
short GetPing(void) const
Definition: ClientHandle.h:256
void HandleLeaveBed()
Handles a player exiting his bed.
int m_NumExplosionsThisTick
Number of explosions sent this tick.
Definition: ClientHandle.h:538
float m_BreakProgress
The fraction between 0 and 1 (or above), of how far through mining the currently mined block is.
Definition: ClientHandle.h:577
void SendTimeUpdate(cTickTimeLong a_WorldAge, cTickTimeLong a_WorldDate, bool a_DoDaylightCycle)
void ServerTick(float a_Dt)
Called while the client is being ticked from the cServer object.
void HandlePing(void)
bool IsDestroyed(void) const
Definition: ClientHandle.h:148
void SendUpdateSign(Vector3i a_BlockPos, const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4)
void StreamChunk(int a_ChunkX, int a_ChunkZ, cChunkSender::Priority a_Priority)
Adds a single chunk to be streamed to the client; used by StreamChunks()
UInt32 m_ProtocolVersion
The version of the protocol that the client is talking, or 0 if unknown.
Definition: ClientHandle.h:569
void SendBossBarRemove(UInt32 a_UniqueID)
void HandleKeepAlive(UInt32 a_KeepAliveID)
const AString & GetClientBrand(void) const
Returns the client brand received in the MC|Brand plugin message or set by a plugin.
Definition: ClientHandle.h:279
bool IsPlaying(void) const
Definition: ClientHandle.h:147
void PacketError(UInt32 a_PacketType)
cMultiVersionProtocol m_Protocol
Definition: ClientHandle.h:456
void SendPluginMessage(const AString &a_Channel, std::string_view a_Message)
void HandleBlockDigStarted(Vector3i a_BlockPos, eBlockFace a_BlockFace)
Handles the DIG_STARTED dig packet:
void SendUnleashEntity(const cEntity &a_Entity)
AStringVector BreakApartPluginChannels(ContiguousByteBufferView a_PluginChannels)
Converts the protocol-formatted channel list (NUL-separated) into a proper string vector.
bool m_ProxyConnection
True if player connected from a proxy (Bungee / Velocity)
Definition: ClientHandle.h:486
void SendPlayerAbilities(void)
void HandlePlayerLook(float a_Rotation, float a_Pitch, bool a_IsOnGround)
int GetRequestedViewDistance(void) const
Returns the view distance that the player request, not the used view distance.
Definition: ClientHandle.h:265
std::unordered_set< cChunkCoords, cChunkCoordsHash > m_LoadedChunks
Definition: ClientHandle.h:452
void HandleRightClick(Vector3i a_BlockPos, eBlockFace a_BlockFace, Vector3i a_Cursor, bool a_UsedMainHand)
void SendSpawnEntity(const cEntity &a_Entity)
void HandlePluginMessage(const AString &a_Channel, ContiguousByteBufferView a_Message)
ContiguousByteBuffer m_IncomingData
Queue for the incoming data received on the link until it is processed in ProcessProtocolIn().
Definition: ClientHandle.h:463
bool HandleHandshake(const AString &a_Username)
Called when the protocol handshake has been received (for protocol versions that support it; otherwis...
void SendResetTitle(void)
void SendWindowOpen(const cWindow &a_Window)
std::atomic< eState > m_State
The current (networking) state of the client.
Definition: ClientHandle.h:535
int m_LastStreamedChunkZ
Definition: ClientHandle.h:492
const cUUID & GetUUID(void) const
Returns the player's UUID, as used by the protocol.
Definition: ClientHandle.h:81
void ProxyInit(const AString &a_IPString, const cUUID &a_UUID)
Function to mark bungee / proxy connection on this client, and to add proxy-related data.
void SendWeather(eWeather a_Weather)
void SendPlayerListHeaderFooter(const cCompositeChat &a_Header, const cCompositeChat &a_Footer)
cTCPLinkPtr m_Link
The link that is used for network communication.
Definition: ClientHandle.h:573
void HandleUseEntity(UInt32 a_TargetEntityID, bool a_IsLeftClick)
cCriticalSection m_CSIncomingData
Protects m_IncomingData against multithreaded access.
Definition: ClientHandle.h:459
void SendGameMode(eGameMode a_GameMode)
virtual void OnRemoteClosed(void) override
Called when the remote end closes the connection.
void HandleUpdateSign(Vector3i a_BlockPos, const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4)
static const int MIN_VIEW_DISTANCE
Definition: ClientHandle.h:60
void SetIsForgeClient()
Mark a client connection as using Forge.
Definition: ClientHandle.h:296
void SetProperties(const Json::Value &a_Properties)
Sets the player's properties, such as skin image and signature.
Definition: ClientHandle.h:93
static bool IsUUIDOnline(const cUUID &a_UUID)
Returns true if the UUID is generated by online auth, false if it is an offline-generated UUID.
void SendWindowClose(const cWindow &a_Window)
std::chrono::milliseconds m_TimeSinceLastUnloadCheck
The time since UnloadOutOfRangeChunks was last called.
Definition: ClientHandle.h:498
bool IsWithinReach(Vector3i a_Position) const
Returns whether the player could in fact reach the position they're attempting to interact with.
void SendBlockBreakAnim(UInt32 a_EntityID, Vector3i a_BlockPos, char a_Stage)
std::chrono::steady_clock::duration m_Ping
Duration of the last completed client ping.
Definition: ClientHandle.h:501
void HandleSteerVehicle(float Forward, float Sideways)
void SendSoundEffect(const AString &a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch)
void SendEntityMetadata(const cEntity &a_Entity)
void SendPaintingSpawn(const cPainting &a_Painting)
void SendRemoveEntityEffect(const cEntity &a_Entity, int a_EffectID)
void UnloadOutOfRangeChunks(void)
Remove all loaded chunks that are no longer in range.
AString m_ClientBrand
The brand identification of the client, as received in the MC|Brand plugin message or set from a plug...
Definition: ClientHandle.h:566
void HandleStartElytraFlight()
Handles a player starting elytra flight while falling.
void HandleUseItem(bool a_UsedMainHand)
void HandleSprint(bool a_IsSprinting)
Handles a player sprinting or slowing back down.
cClientHandle(const AString &a_IPString, int a_ViewDistance)
Creates a new client with the specified IP address in its description and the specified initial view ...
void SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks)
void ProcessProtocolIn(void)
Processes the data in the network input buffer.
void SendPlayerListUpdatePing()
void SendPlayerSpawn(const cPlayer &a_Player)
const AString & GetUsername(void) const
AStringMap m_ForgeMods
Forge mods and versions installed on this client.
Definition: ClientHandle.h:437
void SendTabCompletionResults(const AStringVector &a_Results)
void HandlePlayerMove(Vector3d a_Pos, bool a_IsOnGround)
Verifies and sets player position, performing relevant checks.
void ProcessProtocolOut()
Flushes all buffered outgoing data to the network.
void SendPlayerMoveLook(void)
void SendEntityVelocity(const cEntity &a_Entity)
@ csConnected
The client has just connected, waiting for their handshake / login.
Definition: ClientHandle.h:520
@ csAuthenticating
The client has logged in, waiting for external authentication.
Definition: ClientHandle.h:521
@ csDestroyed
The client has been destroyed, the destructor is to be called from the owner thread.
Definition: ClientHandle.h:524
@ csPlaying
Normal gameplay.
Definition: ClientHandle.h:523
@ csDownloadingWorld
The client is waiting for chunks, we're waiting for the loader to provide and send them.
Definition: ClientHandle.h:522
const AString & GetIPString(void) const
Definition: ClientHandle.h:72
static cUUID GenerateOfflineUUID(const AString &a_Username)
Generates an UUID based on the player name provided.
void SendStatistics(const StatisticsManager &a_Manager)
void HandleTabCompletion(const AString &a_Text)
void SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector &a_Changes)
ContiguousByteBuffer m_OutgoingData
Buffer for storing outgoing data from any thread; will get sent in ProcessProtocolOut() at the end of...
Definition: ClientHandle.h:470
void SendBossBarUpdateStyle(UInt32 a_UniqueID, BossBarColor a_Color, BossBarDivisionType a_DivisionType)
void SendEntityEquipment(const cEntity &a_Entity, short a_SlotNum, const cItem &a_Item)
void HandlePlayerAbilities(bool a_IsFlying, float FlyingSpeed, float WalkingSpeed)
void HandleNPCTrade(int a_SlotNum)
Called when the protocol receives a MC|TrSel packet, indicating that the player used a trade in the N...
AString m_IPString
Definition: ClientHandle.h:445
Vector3i m_LastDigBlockPos
Definition: ClientHandle.h:516
void HandleSpectate(const cUUID &a_PlayerUUID)
void HandleBlockDigFinished(Vector3i a_BlockPos, eBlockFace a_BlockFace)
Handles the DIG_FINISHED dig packet:
bool m_HasStartedDigging
Definition: ClientHandle.h:515
int GetViewDistance(void) const
Returns the view distance that the player currently have.
Definition: ClientHandle.h:262
void SetIPString(const AString &a_IPString)
Sets the IP string that the client is using.
Definition: ClientHandle.h:76
void SendEntityEffect(const cEntity &a_Entity, int a_EffectID, int a_Amplifier, int a_Duration)
cChunkCoords m_CachedSentChunk
This is an optimization which saves you an iteration of m_SentChunks if you just want to know whether...
Definition: ClientHandle.h:484
void SendBlockAction(Vector3i a_BlockPos, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType)
void SendBossBarUpdateHealth(UInt32 a_UniqueID, float a_FractionFilled)
void HandleBeaconSelection(unsigned a_PrimaryEffect, unsigned a_SecondaryEffect)
Called when the protocol receives a MC|Beacon plugin message, indicating that the player set an effec...
int m_RequestedViewDistance
The requested view distance from the player.
Definition: ClientHandle.h:443
bool CheckMultiLogin(const AString &a_Username)
Kicks the client if the same username is already logged in.
cUUID m_UUID
Contains the UUID used by Mojang to identify the player's account.
Definition: ClientHandle.h:551
void Destroy(void)
void RemoveFromWorld(void)
Called when the player moves into a different world.
void SendDetachEntity(const cEntity &a_Entity, const cEntity &a_PreviousVehicle)
cChunkCoordsList m_SentChunks
Definition: ClientHandle.h:454
void SendPlayerListAddPlayer(const cPlayer &a_Player)
void SendBossBarUpdateFlags(UInt32 a_UniqueID, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog)
AString GetLocale(void) const
Definition: ClientHandle.h:268
void SendExplosion(Vector3f a_Position, float a_Power)
void SendMapData(const cMap &a_Map, int a_DataStartX, int a_DataStartY)
void HandleWindowClose(UInt8 a_WindowID)
cCriticalSection m_CSChunkLists
Definition: ClientHandle.h:451
void SendDisconnect(const AString &a_Reason)
UInt32 GetProtocolVersion(void) const
Returns the protocol version number of the protocol that the client is talking.
Definition: ClientHandle.h:422
void SendRespawn(eDimension a_Dimension, bool a_IsRespawningFromDeath)
virtual ~cClientHandle() override
void SendEntityLook(const cEntity &a_Entity)
static AString FormatChatPrefix(bool ShouldAppendChatPrefixes, const AString &a_ChatPrefixS, const AString &m_Color1, const AString &m_Color2)
void HandleCrouch(bool a_IsCrouching)
Handles a player sneaking or unsneaking.
cPlayer * GetPlayer(void)
Definition: ClientHandle.h:78
bool IsPlayerChunkSent()
void PacketBufferFull(void)
void HandleSlotSelected(Int16 a_SlotNum)
int m_UniqueID
ID used for identification during authenticating.
Definition: ClientHandle.h:548
void HandlePlayerMoveLook(Vector3d a_Pos, float a_Rotation, float a_Pitch, bool a_IsOnGround)
void SendExperienceOrb(const cExpOrb &a_ExpOrb)
bool m_HasSentPlayerChunk
Set to true when the chunk where the player is is sent to the client.
Definition: ClientHandle.h:554
void SendCollectEntity(const cEntity &a_Collected, const cEntity &a_Collector, unsigned a_Count)
bool HandleLogin()
Called when the protocol has finished logging the user in.
virtual void OnReceivedData(const char *a_Data, size_t a_Length) override
Called when there's data incoming from the remote peer.
void SendEditSign(Vector3i a_BlockPos)
bool m_HasSentDC
True if a Disconnect packet has been sent in either direction.
Definition: ClientHandle.h:488
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)
void SendResourcePack(const AString &a_ResourcePackUrl)
void SendPlayerPosition(void)
void SetUUID(const cUUID &a_UUID)
Sets the player's UUID, as used by the protocol.
Definition: ClientHandle.h:86
void SendExperience(void)
void SendWholeInventory(const cWindow &a_Window)
void FinishDigAnimation()
The clients will receive a finished dig animation.
AString m_Locale
Client Settings.
Definition: ClientHandle.h:557
void Tick(std::chrono::milliseconds a_Dt)
Called while the client is being ticked from the world via its cPlayer object.
static const int DEFAULT_VIEW_DISTANCE
Definition: ClientHandle.h:57
static int s_ClientCount
Definition: ClientHandle.h:543
void SendUnlockRecipe(UInt32 a_RecipeId)
Send a newly discovered recipe to show the notification and unlock in the recipe book.
void SendDisplayObjective(const AString &a_Objective, cScoreboard::eDisplaySlot a_Display)
void SendChat(const AString &a_Message, eMessageType a_ChatPrefix, const AString &a_AdditionalData="")
void SendSetRawTitle(const AString &a_Title)
void SendHealth(void)
void HandleCraftRecipe(UInt32 a_RecipeId)
Called when a recipe from the recipe book is selected.
bool HasPluginChannel(const AString &a_PluginChannel)
int m_BlockDigAnimSpeed
Definition: ClientHandle.h:511
bool BungeeAuthenticate()
Authenticates the specified user with the bungee proxy server.
bool SetState(eState a_NewState)
Called to update m_State.
void HandleOpenHorseInventory()
Handles a player opening his inventory while riding a horse.
void SendPlayerListRemovePlayer(const cPlayer &a_Player)
void SendData(ContiguousByteBufferView a_Data)
void SendChunkData(int a_ChunkX, int a_ChunkZ, ContiguousByteBufferView a_ChunkData)
void SendUpdateBlockEntity(cBlockEntity &a_BlockEntity)
void HandleAnimation(bool a_SwingMainHand)
Called when the protocol receives a (hand swing) animation packet.
int m_BlockDigAnimStage
Definition: ClientHandle.h:510
void SendChatSystem(const AString &a_Message, eMessageType a_ChatPrefix, const AString &a_AdditionalData="")
void SendEntityAnimation(const cEntity &a_Entity, EntityAnimation a_Animation)
bool WantsSendChunk(int a_ChunkX, int a_ChunkZ)
Returns true if the client wants the chunk specified to be sent (in m_ChunksToSend)
const Json::Value & GetProperties(void) const
Definition: ClientHandle.h:88
void SendAttachEntity(const cEntity &a_Entity, const cEntity &a_Vehicle)
void Authenticate(AString &&a_Name, const cUUID &a_UUID, Json::Value &&a_Properties)
Authenticates ourselves, called by cAuthenticator supplying player details from Mojang.
void HandleCreativeInventory(Int16 a_SlotNum, const cItem &a_HeldItem, eClickAction a_ClickAction)
Called when the client clicks the creative inventory window.
std::chrono::steady_clock::time_point m_PingStartTime
Time of the last ping request sent to the client.
Definition: ClientHandle.h:507
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg) override
Called when an error is detected on the connection.
void AddWantedChunk(int a_ChunkX, int a_ChunkZ)
Adds the chunk specified to the list of chunks wanted for sending (m_ChunksToSend)
void SendBossBarUpdateTitle(UInt32 a_UniqueID, const cCompositeChat &a_Title)
Container for a single chat message composed of multiple functional parts.
Definition: CompositeChat.h:34
Definition: Entity.h:76
Definition: ExpOrb.h:13
Definition: Pickup.h:20
Definition: Player.h:29
Definition: Item.h:37
Encapsulates an in-game world map.
Definition: Map.h:83
Serializes one chunk's data to (possibly multiple) protocol versions.
void AugmentServerListPing(cClientHandle &a_Client, Json::Value &ResponseValue)
Add the registered Forge mods to the server ping list packet.
bool IsForgeClient
True if the client advertised itself as a Forge client.
Meta-protocol that recognizes multiple protocol versions, creates the specific protocol version insta...
Class that manages the statistics and achievements of a single player.
Represents a UI window.
Definition: Window.h:54
Definition: UUID.h:11
bool IsNil() const
Returns true if this contains the "nil" UUID with all bits set to 0.
Definition: UUID.h:30