16 #include "json/json.h"
119 bool ShouldAppendChatPrefixes,
const AString & a_ChatPrefixS,
140 void Tick(std::chrono::milliseconds a_Dt);
196 void SendMapData (
const cMap & a_Map,
int a_DataStartX,
int a_DataStartY);
224 void SendSoundEffect (
const AString & a_SoundName,
double a_X,
double a_Y,
double a_Z,
float a_Volume,
float a_Pitch);
232 void SendTitleTimes (
int a_FadeInTicks,
int a_DisplayTicks,
int a_FadeOutTicks);
256 inline short GetPing(
void)
const {
return static_cast<short>(std::chrono::duration_cast<std::chrono::milliseconds>(
m_Ping).count()); }
501 std::chrono::steady_clock::duration
m_Ping;
618 virtual void OnReceivedData(
const char * a_Data,
size_t a_Length)
override;
620 virtual void OnError(
int a_ErrorCode,
const AString & a_ErrorMsg)
override;
std::vector< sSetBlock > sSetBlockVector
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
std::list< cChunkCoords > cChunkCoordsList
unsigned char BLOCKTYPE
The datatype used by blockdata.
std::shared_ptr< cClientHandle > cClientHandlePtr
eDimension
Dimension of a world.
eClickAction
Individual actions sent in the WindowClick packet.
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
std::chrono::duration< signed long long int, cTickTime::period > cTickTimeLong
std::basic_string_view< std::byte > ContiguousByteBufferView
std::basic_string< std::byte > ContiguousByteBuffer
std::shared_ptr< cTCPLink > cTCPLinkPtr
std::vector< AString > AStringVector
std::map< AString, AString > AStringMap
A string dictionary, used for key-value pairs.
Wraps the chunk coords into a single structure.
Priority
Tag indicating urgency of chunk to be sent.
std::set< AString > cChannels
The type used for storing the names of registered plugin channels.
void SendSetRawSubTitle(const AString &a_SubTitle)
void FinishAuthenticate()
Finish logging the user in after authenticating.
static const int MAX_VIEW_DISTANCE
const AStringMap & GetForgeMods(void) const
Returns the Forge mods installed on the client.
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
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
int GetUniqueID(void) const
cChannels m_PluginChannels
The plugin channels that the client has registered.
void SendHeldItemChange(int a_ItemIndex)
cPlayer * m_Player
A pointer to a World-owned player object, created in FinishAuthenticate when authentication succeeds.
void SetLocale(const AString &a_Locale)
int m_NumBlockChangeInteractionsThisTick
Number of place or break interactions this tick.
Vector3i m_LastPlacedSign
The positions from the last sign that the player placed.
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...
cForgeHandshake m_ForgeHandshake
Forge handshake state machine.
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)
cCriticalSection m_CSOutgoingData
Protects m_OutgoingData against multithreaded access.
void SocketClosed(void)
Called when the network socket has been closed.
void SendLeashEntity(const cEntity &a_Entity, const cEntity &a_EntityLeashedTo)
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.
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.
void SendEntityHeadLook(const cEntity &a_Entity)
void SetClientBrand(const AString &a_ClientBrand)
Called by the protocol when it receives the MC|Brand plugin message.
void SendPlayerListUpdateDisplayName(const cPlayer &a_Player, const AString &a_CustomName)
UInt32 m_PingID
ID of the last ping request sent to the client.
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
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...
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.
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
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...
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.
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
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
void HandleLeaveBed()
Handles a player exiting his bed.
int m_NumExplosionsThisTick
Number of explosions sent this tick.
float m_BreakProgress
The fraction between 0 and 1 (or above), of how far through mining the currently mined block is.
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.
bool IsDestroyed(void) const
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.
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.
bool IsPlaying(void) const
void PacketError(UInt32 a_PacketType)
cMultiVersionProtocol m_Protocol
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)
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.
std::unordered_set< cChunkCoords, cChunkCoordsHash > m_LoadedChunks
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().
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.
const cUUID & GetUUID(void) const
Returns the player's UUID, as used by the protocol.
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.
void HandleUseEntity(UInt32 a_TargetEntityID, bool a_IsLeftClick)
cCriticalSection m_CSIncomingData
Protects m_IncomingData against multithreaded access.
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
void SetIsForgeClient()
Mark a client connection as using Forge.
void SetProperties(const Json::Value &a_Properties)
Sets the player's properties, such as skin image and signature.
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.
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.
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...
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.
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.
@ csAuthenticating
The client has logged in, waiting for external authentication.
@ csDestroyed
The client has been destroyed, the destructor is to be called from the owner thread.
@ csPlaying
Normal gameplay.
@ csDownloadingWorld
The client is waiting for chunks, we're waiting for the loader to provide and send them.
const AString & GetIPString(void) const
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...
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...
Vector3i m_LastDigBlockPos
void HandleSpectate(const cUUID &a_PlayerUUID)
void HandleBlockDigFinished(Vector3i a_BlockPos, eBlockFace a_BlockFace)
Handles the DIG_FINISHED dig packet:
int GetViewDistance(void) const
Returns the view distance that the player currently have.
void SetIPString(const AString &a_IPString)
Sets the IP string that the client is using.
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...
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.
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.
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
void SendPlayerListAddPlayer(const cPlayer &a_Player)
void SendBossBarUpdateFlags(UInt32 a_UniqueID, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog)
AString GetLocale(void) const
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
void SendDisconnect(const AString &a_Reason)
UInt32 GetProtocolVersion(void) const
Returns the protocol version number of the protocol that the client is talking.
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)
void PacketBufferFull(void)
void HandleSlotSelected(Int16 a_SlotNum)
int m_UniqueID
ID used for identification during authenticating.
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.
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.
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.
void SendExperience(void)
void SendWholeInventory(const cWindow &a_Window)
void FinishDigAnimation()
The clients will receive a finished dig animation.
AString m_Locale
Client Settings.
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
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 HandleCraftRecipe(UInt32 a_RecipeId)
Called when a recipe from the recipe book is selected.
bool HasPluginChannel(const AString &a_PluginChannel)
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.
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
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.
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.
Encapsulates an in-game world map.
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.
bool IsNil() const
Returns true if this contains the "nil" UUID with all bits set to 0.