36 #include "mbedtls/md5.h" 41 #define MAX_EXPLOSIONS_PER_TICK 20 44 #define MAX_BLOCK_CHANGE_INTERACTIONS 20 48 static const std::chrono::milliseconds
PING_TIME_MS = std::chrono::milliseconds(1000);
66 m_ForgeHandshake(this),
67 m_CurrentViewDistance(a_ViewDistance),
68 m_RequestedViewDistance(a_ViewDistance),
69 m_IPString(a_IPString),
71 m_CachedSentChunk(0, 0),
73 m_LastStreamedChunkX(0x7fffffff),
74 m_LastStreamedChunkZ(0x7fffffff),
75 m_TicksSinceLastPacket(0),
78 m_BlockDigAnimStage(-1),
79 m_BlockDigAnimSpeed(0),
83 m_HasStartedDigging(false),
88 m_ShouldCheckDownloaded(false),
89 m_NumExplosionsThisTick(0),
90 m_NumBlockChangeInteractionsThisTick(0),
92 m_HasSentPlayerChunk(false),
94 m_LastPlacedSign(0, -1, 0),
97 m_Protocol = cpp14::make_unique<cProtocolRecognizer>(
this);
103 LOGD(
"New ClientHandle created at %p", static_cast<void *>(
this));
114 LOGD(
"Deleting client \"%s\" at %p",
GetUsername().c_str(), static_cast<void *>(
this));
125 if (World !=
nullptr)
140 LOGD(
"ClientHandle at %p deleted", static_cast<void *>(
this));
155 bool WasAddedToWorld =
false;
162 LOGD(
"%s: client %p, \"%s\" already destroyed, bailing out", __FUNCTION__, static_cast<void *>(
this),
m_Username.c_str());
168 LOGD(
"%s: destroying client %p, \"%s\" @ %s", __FUNCTION__, static_cast<void *>(
this),
m_Username.c_str(),
m_IPString.c_str());
176 if (player !=
nullptr)
181 auto world = player->GetWorld();
182 if (world !=
nullptr)
184 player->StopEveryoneFromTargetingMe();
185 player->SetIsTicking(
false);
201 ASSERT(!world->IsPlayerReferencedInWorldOrChunk(*player));
204 player->RemoveClientHandle();
223 if (ShouldAppendChatPrefixes)
225 return Printf(
"%s[%s] %s", m_Color1.c_str(), a_ChatPrefixS.c_str(), m_Color2.c_str());
229 return Printf(
"%s", m_Color1.c_str());
239 switch (a_ChatPrefix)
252 if (ShouldAppendChatPrefixes)
289 return (a_UUID.
Version() == 4);
378 if (m_Player->GetWorld() ==
nullptr)
381 if (World ==
nullptr)
386 m_Player->SetWorld(World);
390 World = m_Player->GetWorld();
395 if (!
cRoot::Get()->GetPluginManager()->CallHookPlayerJoined(*m_Player))
417 m_Protocol->SendWholeInventory(*m_Player->GetWindow());
420 m_Player->SendHealth();
423 m_Player->SendExperience();
426 m_Player->SendHotbarActiveSlot();
447 m_PingStartTime = std::chrono::steady_clock::now() + std::chrono::seconds(3);
487 int RangeX, RangeZ = 0;
490 for (
int X = 0; X < 7; X++)
492 for (
int Z = 0; Z < 7; Z++)
494 int ChunkX = RangeX + ((X >= 4) ? (3 - X) : X);
495 int ChunkZ = RangeZ + ((Z >= 4) ? (3 - Z) : Z);
499 if ((
Diff(ChunkX, ChunkPosX) > m_CurrentViewDistance) || (
Diff(ChunkZ, ChunkPosZ) > m_CurrentViewDistance))
526 for (
int i = -d; i <= d; ++i)
528 CurcleChunks.push_back(
cChunkCoords(ChunkPosX + d, ChunkPosZ + i));
529 CurcleChunks.push_back(
cChunkCoords(ChunkPosX - d, ChunkPosZ + i));
531 for (
int i = -d + 1; i < d; ++i)
533 CurcleChunks.push_back(
cChunkCoords(ChunkPosX + i, ChunkPosZ + d));
534 CurcleChunks.push_back(
cChunkCoords(ChunkPosX + i, ChunkPosZ - d));
538 for (cChunkCoordsList::iterator itr = CurcleChunks.begin(), end = CurcleChunks.end(); itr != end; ++itr)
578 int DiffX =
Diff((*itr).m_ChunkX, ChunkPosX);
579 int DiffZ =
Diff((*itr).m_ChunkZ, ChunkPosZ);
582 ChunksToRemove.push_back(*itr);
593 int DiffX =
Diff((*itr).m_ChunkX, ChunkPosX);
594 int DiffZ =
Diff((*itr).m_ChunkZ, ChunkPosZ);
606 for (cChunkCoordsList::iterator itr = ChunksToRemove.begin(); itr != ChunksToRemove.end(); ++itr)
635 World->
SendChunkTo(a_ChunkX, a_ChunkZ, a_Priority,
this);
646 if (World !=
nullptr)
672 LOGWARNING(
"%s: Not implemented yet", __FUNCTION__);
700 Printf(Reply,
"%s%s%zu%s%zu",
756 LOGWARNING(
"Got a CreativeInventoryAction packet from user \"%s\" while not in creative mode. Ignoring.",
m_Username.c_str());
761 LOGWARNING(
"Got a CreativeInventoryAction packet from user \"%s\" while not in the inventory window. Ignoring.",
m_Username.c_str());
774 if (a_Enchantment > 2)
776 LOGWARNING(
"%s attempt to crash the server with invalid enchanting selection (%u)!",
GetUsername().c_str(), a_Enchantment);
777 Kick(
"Invalid enchanting!");
840 Vector3d NewPosition(a_PosX, a_PosY, a_PosZ);
845 if ((OldPosition - NewPosition).SqrLength() > 100 * 100)
847 LOGD(
"Too far away (%0.2f), \"repairing\" the client", (OldPosition - NewPosition).Length());
852 if (
cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*
m_Player, OldPosition, NewPosition))
873 if (a_Channel ==
"REGISTER")
883 else if (a_Channel ==
"UNREGISTER")
887 else if (a_Channel ==
"FML|HS")
894 LOGD(
"Player %s sent a plugin message on channel \"%s\", but didn't REGISTER it first",
GetUsername().c_str(), a_Channel.c_str());
910 size_t len = a_PluginChannels.size();
913 for (
size_t i = 0; i < len; i++)
915 if (a_PluginChannels[i] != 0)
921 res.push_back(a_PluginChannels.substr(first, i - first));
927 res.push_back(a_PluginChannels.substr(first, len - first));
938 for (AStringVector::const_iterator itr = a_ChannelList.begin(), end = a_ChannelList.end(); itr != end; ++itr)
950 for (AStringVector::const_iterator itr = a_ChannelList.begin(), end = a_ChannelList.end(); itr != end; ++itr)
1011 if (a_NewCommand.empty())
1013 Kick(
"Command block string unexpectedly empty - hacked client?");
1036 LOGWARNING(
"%s: Not implemented yet", __FUNCTION__);
1050 if (a_ItemName.length() <= 30)
1062 FLOGD(
"HandleLeftClick: {0}; Face: {1}; Stat: {2}",
1063 Vector3i{a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace, a_Status
1070 Kick(
"Too many blocks were destroyed per unit time - hacked client?");
1084 int BlockX = a_BlockX;
1085 int BlockY = a_BlockY;
1086 int BlockZ = a_BlockZ;
1209 ASSERT(!
"Unhandled DIG_STATUS");
1282 Handler->OnDigging(ChunkInterface, *World, *
m_Player, a_BlockX, a_BlockY, a_BlockZ);
1301 FLOGD(
"Prevented a dig / aim bug in the client (finish {0} vs start {1}, HSD: {2})",
1302 Vector3i{a_BlockX, a_BlockY, a_BlockZ},
1315 Kick(
"You can't break a bedrock!");
1320 Kick(
"You can't break a barrier!");
1343 if (
cRoot::Get()->GetPluginManager()->CallHookPlayerBreakingBlock(*
m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_OldBlock, a_OldMeta))
1360 Vector3i absPos(a_BlockX, a_BlockY, a_BlockZ);
1361 blockHandler->OnPlayerBreakingBlock(ChunkInterface, *World, *
m_Player, absPos);
1376 blockHandler->OnPlayerBrokeBlock(ChunkInterface, *World, *
m_Player, absPos, a_OldBlock, a_OldMeta);
1433 FLOGD(
"HandleRightClick: {0}, face {1}, Hand: {2}, HeldItem: {3}; Dist: {4:.02f}",
1440 bool IsWithinReach = (Dist <= MaxDist);
1444 bool Success =
false;
1452 World->
GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
1464 if (BlockHandler->
OnUse(ChunkInterface, *World, *
m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ))
1472 if (!Success && Placeable)
1475 Success = ItemHandler->
OnPlayerPlace(*World, *
m_Player, HeldItem, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ);
1491 Kick(
"Too many blocks were placed / interacted with per unit time - hacked client?");
1495 Success = ItemHandler->
OnPlayerPlace(*World, *
m_Player, HeldItem, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ);
1504 ItemHandler->
OnItemUse(World,
m_Player, PluginInterface, HeldItem, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
1514 for (
int y = a_BlockY - 1; y <= a_BlockY + 1; y++)
1536 if (
cRoot::Get()->GetServer()->Command(*
this, Message))
1544 if (Color.length() == 3)
1546 Color =
AString(
"@") + Color[2];
1651 LOGD(
"WindowClick: WinID %d, SlotNum %d, action: %s, Item %s x %d",
1657 if (Window ==
nullptr)
1663 Window->
Clicked(*
m_Player, a_WindowID, a_SlotNum, a_ClickAction, a_HeldItem);
1671 int a_BlockX,
int a_BlockY,
int a_BlockZ,
1848 if ((
cRoot::Get()->GetServer()->DoesAllowMultiLogin()))
1854 if (
cRoot::Get()->GetServer()->IsPlayerInQueue(a_Username))
1856 Kick(
"A player of the username is already logged in");
1863 Kick(
"A player of the username is already logged in");
1875 if (a_Username.length() > 16)
1877 Kick(
"Your username is too long (>16 characters)");
1881 if (
cRoot::Get()->GetPluginManager()->CallHookHandshake(*
this, a_Username))
1883 Kick(
"Entry denied by plugin");
1958 if (
cRoot::Get()->GetServer()->ShouldAllowMultiWorldTabCompletion())
1969 if (Results.empty())
1975 std::sort(Results.begin(), Results.end());
2008 for (
auto && Chunk : Chunks)
2080 LOGD(
"Client %s @ %s (%p) has been queued for destruction, destroying now.",
2152 for (
int i = 0; i < 4; i++)
2200 LOGD(
"Client %s @ %s (%p) has been queued for destruction, destroying now.",
2236 m_Protocol->SendAttachEntity(a_Entity, a_Vehicle);
2245 m_Protocol->SendLeashEntity(a_Entity, a_EntityLeashedTo);
2263 m_Protocol->SendBlockAction(a_BlockX, a_BlockY, a_BlockZ, a_Byte1, a_Byte2, a_BlockType);
2272 m_Protocol->SendBlockBreakAnim(a_EntityID, a_BlockX, a_BlockY, a_BlockZ, a_Stage);
2281 int ChunkX, ChunkZ = 0;
2290 m_Protocol->SendBlockChange(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
2300 ASSERT(!a_Changes.empty());
2308 m_Protocol->SendBlockChanges(a_ChunkX, a_ChunkZ, a_Changes);
2328 if (World ==
nullptr)
2331 if (World ==
nullptr)
2349 if (World ==
nullptr)
2352 if (World ==
nullptr)
2368 m_Protocol->SendChatRaw(a_MessageRaw, a_Type);
2378 if (World ==
nullptr)
2381 if (World ==
nullptr)
2407 if (World ==
nullptr)
2410 if (World ==
nullptr)
2463 m_Protocol->SendChunkData(a_ChunkX, a_ChunkZ, a_Serializer);
2478 m_Protocol->SendCollectEntity(a_Entity, a_Player, a_Count);
2496 m_Protocol->SendDetachEntity(a_Entity, a_PreviousVehicle);
2526 m_Protocol->SendEditSign(a_BlockX, a_BlockY, a_BlockZ);
2535 m_Protocol->SendEntityEffect(a_Entity, a_EffectID, a_Amplifier, a_Duration);
2544 m_Protocol->SendEntityEquipment(a_Entity, a_SlotNum, a_Item);
2586 m_Protocol->SendEntityRelMove(a_Entity, a_RelX, a_RelY, a_RelZ);
2597 m_Protocol->SendEntityRelMoveLook(a_Entity, a_RelX, a_RelY, a_RelZ);
2606 m_Protocol->SendEntityStatus(a_Entity, a_Status);
2626 LOGD(
"Dropped an explosion!");
2633 m_Protocol->SendExplosion(a_BlockX, a_BlockY, a_BlockZ, a_Radius, a_BlocksAffected, a_PlayerMotion);
2678 m_Protocol->SendInventorySlot(a_WindowID, a_SlotNum, a_Item);
2687 m_Protocol->SendMapData(a_Map, a_DataStartX, a_DataStartY);
2696 m_Protocol->SendParticleEffect(a_ParticleName, a_SrcX, a_SrcY, a_SrcZ, a_OffsetX, a_OffsetY, a_OffsetZ, a_ParticleData, a_ParticleAmount);
2705 m_Protocol->SendParticleEffect(a_ParticleName, a_Src, a_Offset, a_ParticleData, a_ParticleAmount, a_Data);
2732 m_Protocol->SendEntityAnimation(a_Entity, a_Animation);
2750 m_Protocol->SendPlayerListAddPlayer(a_Player);
2759 m_Protocol->SendPlayerListRemovePlayer(a_Player);
2768 m_Protocol->SendPlayerListUpdateGameMode(a_Player);
2777 m_Protocol->SendPlayerListUpdatePing(a_Player);
2786 m_Protocol->SendPlayerListUpdateDisplayName(a_Player, a_CustomName);
2833 LOGD(
"Spawning player \"%s\" on client \"%s\" @ %s",
2846 m_Protocol->SendPluginMessage(a_Channel, a_Message);
2855 m_Protocol->SendRemoveEntityEffect(a_Entity, a_EffectID);
2911 m_Protocol->SendScoreboardObjective(a_Name, a_DisplayName, a_Mode);
2920 m_Protocol->SendScoreUpdate(a_Objective, a_Player, a_Score, a_Mode);
2929 m_Protocol->SendDisplayObjective(a_Objective, a_Display);
2974 LOG(
"SendSoundEffect with double args is deprecated, use version with vector position parameter.");
2984 m_Protocol->SendSoundEffect(a_SoundName, a_Position.
x, a_Position.
y, a_Position.
z, a_Volume, a_Pitch);
2993 m_Protocol->SendSoundParticleEffect(a_EffectID, a_SrcX, a_SrcY, a_SrcZ, a_Data);
3002 m_Protocol->SendSpawnFallingBlock(a_FallingBlock);
3020 m_Protocol->SendSpawnObject(a_Entity, a_ObjectType, a_ObjectData, a_Yaw, a_Pitch);
3029 m_Protocol->SendSpawnVehicle(a_Vehicle, a_VehicleType, a_VehicleSubType);
3047 m_Protocol->SendTabCompletionResults(a_Results);
3065 m_Protocol->SendThunderbolt(a_BlockX, a_BlockY, a_BlockZ);
3074 m_Protocol->SendTitleTimes(a_FadeInTicks, a_DisplayTicks, a_FadeOutTicks);
3083 m_Protocol->SendTimeUpdate(a_WorldAge, a_TimeOfDay, a_DoDaylightCycle);
3098 m_Protocol->SendUnloadChunk(a_ChunkX, a_ChunkZ);
3107 m_Protocol->SendUpdateBlockEntity(a_BlockEntity);
3115 int a_BlockX,
int a_BlockY,
int a_BlockZ,
3120 a_BlockX, a_BlockY, a_BlockZ,
3121 a_Line1, a_Line2, a_Line3, a_Line4
3131 m_Protocol->SendUseBed(a_Entity, a_BlockX, a_BlockY, a_BlockZ);
3176 m_Protocol->SendWindowProperty(a_Window, a_Property, a_Value);
3208 if (world !=
nullptr)
3249 LOGD(
"Adding chunk [%d, %d] to wanted chunks for client %p", a_ChunkX, a_ChunkZ, static_cast<void *>(
this));
3277 Printf(Reason,
"Unknown [C->S] PacketType: 0x%x", a_PacketType);
3287 LOGERROR(
"Protocol error while parsing packet type 0x%02x; disconnecting client \"%s\"", a_PacketType,
m_Username.c_str());
3338 if (!IncomingData.empty())
3340 m_Protocol->DataReceived(IncomingData.data(), IncomingData.size());
3350 if ((link !=
nullptr) && !OutgoingData.empty())
3352 link->Send(OutgoingData.data(), OutgoingData.size());
3403 LOGD(
"An error has occurred on client link for %s @ %s: %d (%s). Client disconnected.",
cCriticalSection m_CSChunkLists
void SetSprint(bool a_IsSprinting)
Starts or stops sprinting, sends the max speed update to the client, if needed.
int GetChunkZ(void) const
void SendSlot(cPlayer &a_Player, cSlotArea *a_SlotArea, int a_RelativeSlotNum)
Used by cSlotAreas to send individual slots to clients, a_RelativeSlotNum is the slot number relative...
virtual bool IsDaylightCycleEnabled(void) const
Is the daylight cycle enabled?
eType
All types of entity effects (numbers correspond to protocol / storage types)
void SetCanFly(bool a_CanFly)
If true the player can fly even when he's not in creative.
void AddTextPart(const AString &a_Message, const AString &a_Style="")
Adds a plain text part, with optional style.
double GetPosY(void) const
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg) override
Called when an error is detected on the connection.
void SetFlying(bool a_IsFlying)
Flags the player as flying.
bool IsValid(void) const
Returns true iff the chunk block data is valid (loaded / generated)
cChunkCoordsList m_SentChunks
void HandleCreativeInventory(Int16 a_SlotNum, const cItem &a_HeldItem, eClickAction a_ClickAction)
Called when the client clicks the creative inventory window.
void HandleWindowClick(UInt8 a_WindowID, Int16 a_SlotNum, eClickAction a_ClickAction, const cItem &a_HeldItem)
cClientHandlePtr m_Self
Shared pointer to self, so that this instance can keep itself alive when needed.
std::atomic< int > m_TicksSinceLastPacket
Number of ticks since the last network packet was received (increased in Tick(), reset in OnReceivedD...
bool DigBlock(Vector3i a_BlockPos)
Replaces the specified block with air, and calls the apropriate block handlers (OnBreaking(), OnBroken()).
The client has been destroyed, the destructor is to be called from the owner thread.
std::unordered_set< cChunkCoords, cChunkCoordsHash > m_LoadedChunks
void UnregisterPluginChannels(const AStringVector &a_ChannelList)
Removes all of the channels from the list of current plugin channels.
void SendSetRawSubTitle(const AString &a_SubTitle)
void SendSetTitle(const cCompositeChat &a_Title)
void SendParticleEffect(const AString &a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount)
virtual void BroadcastEntityAnimation(const cEntity &a_Entity, Int8 a_Animation, const cClientHandle *a_Exclude=nullptr) override
void SendMessage(const AString &a_Message)
double GetPosX(void) const
The client is waiting for chunks, we're waiting for the loader to provide and send them...
eDimension
Dimension of a world.
BLOCKTYPE GetBlock(Vector3i a_BlockPos)
Returns the block type at the specified position.
void PlayerDestroyed()
Notifies the server that a player is being destroyed; the server uses this to adjust the number of pl...
std::chrono::steady_clock::time_point m_PingStartTime
Time of the last ping request sent to the client.
AStringVector BreakApartPluginChannels(const AString &a_PluginChannels)
Converts the protocol-formatted channel list (NUL-separated) into a proper string vector...
void HandleEnchantItem(UInt8 a_WindowID, UInt8 a_Enchantment)
Called when the player enchants an Item in the Enchanting table UI.
void HandleKeepAlive(UInt32 a_KeepAliveID)
cTeam * UpdateTeam(void)
Forces the player to query the scoreboard for his team.
void SendChatSystem(const AString &a_Message, eMessageType a_ChatPrefix, const AString &a_AdditionalData="")
virtual bool IsCrouched(void) const override
void OpenHorseInventory()
Opens the inventory of any tame horse the player is riding.
void SendAttachEntity(const cEntity &a_Entity, const cEntity &a_Vehicle)
void SendEntityVelocity(const cEntity &a_Entity)
void SendMapData(const cMap &a_Map, int a_DataStartX, int a_DataStartY)
void HandleAnimation(int a_Animation)
AString StripColorCodes(const AString &a_Message)
Removes all control codes used by MC for colors and styles.
bool Equals(const Vector3< T > &a_Rhs) const
void BroadcastChat(const AString &a_Message, eMessageType a_ChatPrefix=mtCustom)
Sends a chat message to all connected clients (in all worlds)
virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cBlockPluginInterface &a_PluginInterface, const cItem &a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace)
Called when the player tries to use the item (right mouse button).
bool ShouldUseChatPrefixes(void) const
void SendDisplayObjective(const AString &a_Objective, cScoreboard::eDisplaySlot a_Display)
void HandlePlayerAbilities(bool a_CanFly, bool a_IsFlying, float FlyingSpeed, float WalkingSpeed)
bool CallHookPluginMessage(cClientHandle &a_Client, const AString &a_Channel, const AString &a_Message)
void RemoveClientFromChunkSender(cClientHandle *a_Client)
Removes client from ChunkSender's queue of chunks to be sent.
Class that manages the statistics and achievements of a single player.
bool CallHookDisconnect(cClientHandle &a_Client, const AString &a_Reason)
cChunk * GetParentChunk()
Returns the chunk responsible for ticking this entity.
void SendScoreboardObjective(const AString &a_Name, const AString &a_DisplayName, Byte a_Mode)
bool IsSword(short a_ItemID)
virtual void Clicked(cPlayer &a_Player, int a_WindowID, short a_SlotNum, eClickAction a_ClickAction, const cItem &a_ClickedItem)
Handles a click event from a player.
bool CallHookPlayerUsedItem(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
virtual void BroadcastEntityEquipment(const cEntity &a_Entity, short a_SlotNum, const cItem &a_Item, const cClientHandle *a_Exclude=nullptr) override
int GetEquippedSlotNum(void)
Returns slot number of equiped item.
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 HandleOpenHorseInventory(UInt32 a_EntityID)
Handles a player opening their inventory while riding a horse.
void SendChatRaw(const AString &a_MessageRaw, eChatType a_Type)
virtual void OnItemShoot(cPlayer *, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace)
Called when the client sends the SHOOT status in the lclk packet.
void UnloadOutOfRangeChunks(void)
Remove all loaded chunks that are no longer in range.
int GetWindowType(void) const
AString GetPrefix(void) const
Returns the player name prefix, may contain @ format directives.
unsigned char BLOCKTYPE
The datatype used by blockdata.
void SendEntityLook(const cEntity &a_Entity)
void UnderlineUrls(void)
Adds the "underline" style to each part that is an URL.
Encapsulates an in-game world map.
void ParseText(const AString &a_ParseText)
Parses text into various parts, adds those.
cForgeHandshake m_ForgeHandshake
Forge handshake state machine.
void Tick(float a_Dt)
Called while the client is being ticked from the world via its cPlayer object.
bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4, cPlayer *a_Player=nullptr)
Sets the sign text, asking plugins for permission first.
std::unique_ptr< cPlayer > m_PlayerPtr
bool CallHookPlayerUsingBlock(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
void SocketClosed(void)
Called when the network socket has been closed.
void SendHeldItemChange(int a_ItemIndex)
The client has logged in, waiting for external authentication.
static cBlockHandler * GetHandler(BLOCKTYPE a_Type)
void SendSpawnFallingBlock(const cFallingBlock &a_FallingBlock)
bool CallHookPlayerLeftClick(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status)
static float FASTBREAK_PERCENTAGE
The percentage how much a block has to be broken.
cWindow * GetWindow(void)
void SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ)
void SetPosition(double a_PosX, double a_PosY, double a_PosZ)
virtual void BroadcastBlockBreakAnimation(UInt32 a_EntityID, Vector3i a_BlockPos, Int8 a_Stage, const cClientHandle *a_Exclude=nullptr) override
void StartEating(void)
Starts eating the currently equipped item.
#define FAST_FLOOR_DIV(x, div)
Faster than (int)floorf((float)x / (float)div)
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 SendPlayerSpawn(const cPlayer &a_Player)
void TossEquippedItem(char a_Amount=1)
tosses the item in the selected hotbar slot
void HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, eHand a_Hand)
static bool IsValidHeight(int a_Height)
Validates a height-coordinate.
static AString FormatChatPrefix(bool ShouldAppendChatPrefixes, AString a_ChatPrefixS, AString m_Color1, AString m_Color2)
const cItem & GetEquippedItem(void) const
void SetHeadYaw(double a_HeadYaw)
bool m_HasSentPlayerChunk
Set to true when the chunk where the player is is sent to the client.
void SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem &a_Item)
void SendDetachEntity(const cEntity &a_Entity, const cEntity &a_PreviousVehicle)
void RemoveClientFromChunks(cClientHandle *a_Client)
Removes the client from all chunks it is present in.
int GetMaxViewDistance(void) const
void TabCompleteCommand(const AString &a_Text, AStringVector &a_Results, cPlayer *a_Player)
Appends all commands beginning with a_Text (case-insensitive) into a_Results.
void SendBlockBreakAnim(UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage)
static bool IsUseableBySpectator(BLOCKTYPE a_Type)
virtual void Detach(void) override
Detaches from the currently attached entity, if any.
void SendSpawnObject(const cEntity &a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch)
void SendLeashEntity(const cEntity &a_Entity, const cEntity &a_EntityLeashedTo)
void PacketUnknown(UInt32 a_PacketType)
void HandleSteerVehicle(float Forward, float Sideways)
bool IsPVPEnabled(void) const
static cItemHandler * GetItemHandler(int a_ItemType)
static const char * Delimiter
void SendPlayerListRemovePlayer(const cPlayer &a_Player)
virtual void OnRemoteClosed(void) override
Called when the remote end closes the connection.
void SendWholeInventory(const cWindow &a_Window)
cWorld * GetWorld(const AString &a_WorldName)
Returns a pointer to the world specified.
UInt8 Version() const
Returns the version number of the UUID.
AString GetSuffix(void) const
Returns the player name suffix, may contain @ format directives.
virtual bool OnUse(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
Called if the user right clicks the block and the block is useable returns true if the use was succes...
void HandleWindowClose(UInt8 a_WindowID)
void SendPlayerMaxSpeed(void)
Informs the client of the maximum player speed (1.6.1+)
bool HasPluginChannel(const AString &a_PluginChannel)
void Set(T a_x, T a_y, T a_z)
void SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector &a_Changes)
virtual bool IsOnGround(void) const override
Returns whether the entity is on ground or not.
void SendSoundEffect(const AString &a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch)
static void SetBedOccupationState(cChunkInterface &a_ChunkInterface, Vector3i a_BedPosition, bool a_IsOccupied)
void SetPitch(double a_Pitch)
const AString & GetDescription(void) const
const AString & GetName(void) const
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
void DataReceived(cClientHandle *a_Client, const char *a_Data, size_t a_Size)
Process received data from the client advancing the Forge handshake.
std::vector< Vector3i > cVector3iArray
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 ItemToString(const cItem &a_Item)
Translates a full item into a string.
virtual cItem GetOffHandEquipedItem(void) const override
Returns the currently offhand equipped item; empty item if none.
eWeather GetWeather(void) const
Returns the current weather.
Constants used throughout the code, useful typedefs and utility functions.
Vector3i m_LastPlacedSign
The positions from the last sign that the player placed.
bool HandleHandshake(const AString &a_Username)
Called when the protocol handshake has been received (for protocol versions that support it; otherwis...
void HandleCommandBlockBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, const AString &a_NewCommand)
Called when the protocol receives a MC|AdvCdm plugin message, indicating that the player set a new co...
void SetSelf(cClientHandlePtr a_Self)
Called right after the instance is created to store its SharedPtr inside.
void HandleTabCompletion(const AString &a_Text)
bool DropBlockAsPickups(Vector3i a_BlockPos, const cEntity *a_Digger=nullptr, const cItem *a_Tool=nullptr)
Digs the specified block, and spawns the appropriate pickups for it.
cChannels m_PluginChannels
The plugin channels that the client has registered.
virtual bool OnDiggingBlock(cWorld *a_World, cPlayer *a_Player, const cItem &a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace)
Called while the player digs a block using this item.
void HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround)
Verifies and sets player position, performing relevant checks Calls relevant methods to process movem...
void SendWindowProperty(const cWindow &a_Window, short a_Property, short a_Value)
void SendSoundParticleEffect(const EffectID a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data)
void SendTabCompletionResults(const AStringVector &a_Results)
AString GetColor(void) const
Returns the full color code to use for this player, based on their rank.
static cPluginManager * Get(void)
Returns the instance of the Plugin Manager (there is only ever one)
void SetShieldSlot(const cItem &a_Item)
Sets current item in shield slot.
void SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray &a_BlocksAffected, const Vector3d &a_PlayerMotion)
void RemoveFromAllChunks(void)
Removes the client from all chunks.
void CloseWindowIfID(char a_WindowID, bool a_CanRefuse=true)
Closes the current window if it matches the specified ID, resets current window to m_InventoryWindow...
void LOGERROR(const char *a_Format, fmt::ArgList a_ArgList)
void SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType)
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 SendSpawnMob(const cMonster &a_Mob)
void PacketError(UInt32 a_PacketType)
bool DoWithEntityByID(UInt32 a_UniqueID, cEntityCallback a_Callback)
Calls the callback if the entity with the specified ID is found, with the entity object as the callba...
bool StreamNextChunk()
This function sends a new unloaded chunk to the player.
void SetIsInBed(bool a_Flag)
Sets a player's in-bed state We can't be sure plugins will keep this value updated, so no exporting If value is false (not in bed), will update players of the fact that they have been ejected from the bed.
void HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, float a_Rotation, float a_Pitch, bool a_IsOnGround)
void HandlePlayerLook(float a_Rotation, float a_Pitch, bool a_IsOnGround)
void SendData(const char *a_Data, size_t a_Size)
void SendWeather(eWeather a_Weather)
static const int MIN_VIEW_DISTANCE
const cItem & GetEquippedItem(void) const
Returns current equiped item.
void SendTeleportEntity(const cEntity &a_Entity)
void SetTouchGround(bool a_bTouchGround)
void RemoveFromWorld(void)
Called when the player moves into a different world.
virtual void OnReceivedData(const char *a_Data, size_t a_Length) override
Called when there's data incoming from the remote peer.
void SendCameraSetTo(const cEntity &a_Entity)
void SendExperience(void)
virtual void TeleportToEntity(cEntity &a_Entity)
Teleports to the entity specified.
void SendPlayerLists(cPlayer *a_DestPlayer)
Send playerlist of all worlds to player.
void FinishDigAnimation()
The clients will receive a finished dig animation.
int m_NumBlockChangeInteractionsThisTick
Number of place or break interactions this tick.
void ClientMovedToWorld(const cClientHandle *a_Client)
Don't tick a_Client anymore, it will be ticked from its cPlayer instead.
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
void SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks=false)
eClickAction
Individual actions sent in the WindowClick packet.
void SetStance(const double a_Stance)
void Kick(const AString &a_Reason)
AString m_IncomingData
Queue for the incoming data received on the link until it is processed in Tick(). ...
std::vector< AString > AStringVector
Utilities to allow casting a cWorld to one of its interfaces without including World.h.
cCriticalSection m_CSOutgoingData
Protects m_OutgoingData against multithreaded access.
void StreamChunk(int a_ChunkX, int a_ChunkZ, cChunkSender::eChunkPriority a_Priority)
Adds a single chunk to be streamed to the client; used by StreamChunks()
void SendPlayerListAddPlayer(const cPlayer &a_Player)
cStatManager & GetStatManager()
Return the associated statistic and achievement manager.
bool AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle *a_Client)
Adds client to a chunk, if not already present; returns true if added, false if present.
void HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta)
Handles the DIG_FINISHED dig packet:
void Authenticate(const AString &a_Name, const cUUID &a_UUID, const Json::Value &a_Properties)
Authenticates the specified user, called by cAuthenticator.
bool IsGameModeAdventure(void) const
Returns true if the player is in Adventure mode, either explicitly, or by inheriting from current wor...
virtual void OnLinkCreated(cTCPLinkPtr a_Link) override
Called when the cTCPLink for the connection is created.
int GetUniqueID(void) const
static cUUID GenerateVersion3(const AString &a_Name)
Generates a version 3, variant 1 UUID based on the md5 hash of a_Name.
size_t GetMaxPlayers(void) const
Container for a single chat message composed of multiple functional parts.
void PlayerCreated()
Notifies the server that a player was created; the server uses this to adjust the number of players...
void SendEntityStatus(const cEntity &a_Entity, char a_Status)
void SendScoreUpdate(const AString &a_Objective, const AString &a_Player, cObjective::Score a_Score, Byte a_Mode)
#define MAX_EXPLOSIONS_PER_TICK
Maximum number of explosions to send this tick, server will start dropping if exceeded.
void SendEntityRelMoveLook(const cEntity &a_Entity, char a_RelX, char a_RelY, char a_RelZ)
void AddFaceDirection(int &a_BlockX, int &a_BlockY, int &a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse=false)
void SendUnloadChunk(int a_ChunkX, int a_ChunkZ)
void SendEquippedSlot()
Sends the equipped item slot to the client.
cUUID m_UUID
Contains the UUID used by Mojang to identify the player's account.
void SendPaintingSpawn(const cPainting &a_Painting)
Vector3d GetLookVector(void) const
std::chrono::steady_clock::duration m_Ping
Duration of the last completed client ping.
cChunkCoords m_CachedSentChunk
This is an optimization which saves you an iteration of m_SentChunks if you just want to know whether...
void Authenticate(int a_ClientID, const AString &a_UserName, const AString &a_ServerHash)
Queues a request for authenticating a user.
void SendPlayerListUpdateGameMode(const cPlayer &a_Player)
bool CheckBlockInteractionsRate(void)
Returns true if the rate block interactions is within a reasonable limit (bot protection) ...
double GetSpawnY(void) const
void SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4)
bool GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta)
Retrieves the block type and meta at the specified coords.
UInt32 m_ProtocolVersion
The version of the protocol that the client is talking, or 0 if unknown.
virtual void BroadcastSoundParticleEffect(const EffectID a_EffectID, Vector3i a_SrcPos, int a_Data, const cClientHandle *a_Exclude=nullptr) override
virtual ~cClientHandle() override
bool IsFrozen()
Is the player frozen?
void SendEntityHeadLook(const cEntity &a_Entity)
cPlayer * GetPlayer(void)
const char * ClickActionToString(int a_ClickAction)
bool IsMinecart(void) const
void SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks)
void SendCollectEntity(const cEntity &a_Entity, const cPlayer &a_Player, int a_Count)
void SendSetSubTitle(const cCompositeChat &a_SubTitle)
void InvalidateCachedSentChunk()
void HandleUseItem(eHand a_Hand)
AString m_OutgoingData
Buffer for storing outgoing data from any thread; will get sent in Tick() (to prevent deadlocks)...
Serializes one chunk's data to (possibly multiple) protocol versions.
void SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle)
void SetCrouch(bool a_IsCrouched)
Sets the crouch status, broadcasts to all visible players.
virtual int GetTimeOfDay(void) const override
Vector3< double > Vector3d
void SendUseBed(const cEntity &a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ)
void BroadcastChatJoin(const AString &a_Message)
std::shared_ptr< cTCPLink > cTCPLinkPtr
void ServerTick(float a_Dt)
Called while the client is being ticked from the cServer object.
bool CallHookPlayerRightClick(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
Disconnect packet sent, awaiting connection closure.
void LOGINFO(const char *a_Format, fmt::ArgList a_ArgList)
float GetPlayerRelativeBlockHardness(BLOCKTYPE a_Block)
Returns the relative block hardness for the block a_Block.
AString & Printf(AString &str, const char *format, fmt::ArgList args)
Output the formatted text into the string.
void SetHotbarSlot(int a_HotBarSlotNum, const cItem &a_Item)
Puts a_Item item in a_HotBarSlotNum slot number in hotbar slots.
void SendResetTitle(void)
bool CallHookPlayerTossingItem(cPlayer &a_Player)
int DeltaExperience(int a_Xp_delta)
bool CallHookPlayerSpawned(cPlayer &a_Player)
virtual bool OnPlayerPlace(cWorld &a_World, cPlayer &a_Player, const cItem &a_EquippedItem, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
Called when the player tries to place the item (right mouse button, IsPlaceable() == true)...
virtual Int64 GetWorldAge(void) const override
void SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ)
void SetViewDistance(int a_ViewDistance)
Sets the maximal view distance.
The client is being destroyed, don't queue any more packets / don't add to chunks.
void SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
cScoreboard & GetScoreBoard(void)
Returns the associated scoreboard instance.
void HandleEntitySprinting(UInt32 a_EntityID, bool a_IsSprinting)
virtual void SetProperty(short a_Property, short a_Value, cPlayer &a_Player) override
Updates a numerical property associated with the window.
The client has been authenticated, will start streaming chunks in the next tick.
void LOGWARNING(const char *a_Format, fmt::ArgList a_ArgList)
void SendEntityAnimation(const cEntity &a_Entity, char a_Animation)
void HandleChat(const AString &a_Message)
Called when the protocol detects a chat packet.
cCriticalSection m_CSState
cTCPLinkPtr m_Link
The link that is used for network communication.
void SendUpdateBlockEntity(cBlockEntity &a_BlockEntity)
std::atomic< eState > m_State
The current (networking) state of the client.
virtual eDimension GetDimension(void) const override
void SendChatAboveActionBar(const AString &a_Message, eMessageType a_ChatPrefix, const AString &a_AdditionalData="")
void SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer &a_Serializer)
size_t GetNumPlayers(void) const
void HandleEntityLeaveBed(UInt32 a_EntityID)
void HandlePluginMessage(const AString &a_Channel, const AString &a_Message)
void NotifyNearbyWolves(cPawn *a_Opponent, bool a_IsPlayerInvolved)
Notify nearby wolves that the player or one of the player's wolves took damage or did damage to an en...
void CloseWindow(bool a_CanRefuse=true)
Closes the current window, resets current window to m_InventoryWindow.
static const char * Yellow
void SendEntityEquipment(const cEntity &a_Entity, short a_SlotNum, const cItem &a_Item)
UInt32 m_PingID
ID of the last ping request sent to the client.
void SendRemoveEntityEffect(const cEntity &a_Entity, int a_EffectID)
bool CallHookPlayerShooting(cPlayer &a_Player)
void SendPlayerPosition(void)
void HandleSpectate(const cUUID &a_PlayerUUID)
void SendWindowOpen(const cWindow &a_Window)
void SendChat(const AString &a_Message, eMessageType a_ChatPrefix, const AString &a_AdditionalData="")
cBeaconEntity * GetBeaconEntity(void) const
double GetSpawnZ(void) const
void UpdateMovementStats(const Vector3d &a_DeltaPos, bool a_PreviousIsOnGround)
Update movement-related statistics.
void SendDisconnect(const AString &a_Reason)
void BroadcastPlayerListsAddPlayer(const cPlayer &a_Player, const cClientHandle *a_Exclude=nullptr)
Broadcast playerlist addition through all worlds.
Vector3d m_ConfirmPosition
void SendEntityRelMove(const cEntity &a_Entity, char a_RelX, char a_RelY, char a_RelZ)
void SendPickupSpawn(const cPickup &a_Pickup)
T Clamp(T a_Value, T a_Min, T a_Max)
Clamp X to the specified range.
void HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta)
Handles the DIG_STARTED dig packet:
eDimension m_LastSentDimension
The dimension that was last sent to a player in a Respawn or Login packet.
cBlockHandler * BlockHandler(BLOCKTYPE a_BlockType)
void HandleCommandBlockEntityChange(UInt32 a_EntityID, const AString &a_NewCommand)
Called when the protocol receives a MC|AdvCdm plugin message, indicating that the player set a new co...
virtual void OnRightClicked(cPlayer &a_Player)
Called when the specified player right-clicks this entity.
bool IsSatiated(void) const
Returns true if the player is satiated, i.
cWorld * GetDefaultWorld(void)
cChunkMap * GetChunkMap(void)
void HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, UInt8 a_Status)
void TakeDamage(cEntity &a_Attacker)
Makes this pawn take damage from an attack by a_Attacker.
void GenerateOfflineUUID(void)
Generates an UUID based on the username stored for this client, and stores it in the m_UUID member...
short GetPropertyValue(short a_Property)
Return the value of a property.
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
void BroadcastPlayerListsRemovePlayer(const cPlayer &a_Player, const cClientHandle *a_Exclude=nullptr)
Broadcast playerlist removal through all worlds.
bool CallHookPlayerUsedBlock(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
bool IsPlayer(void) const
bool m_IsForgeClient
True if the client advertised itself as a Forge client.
virtual bool IsUseable(void)
Checks if the block can be placed at this point.
virtual bool IsPlaceable(void)
Blocks simply get placed.
cServer * GetServer(void)
cCriticalSection m_CSIncomingData
Protects m_IncomingData against multithreaded access.
std::unique_ptr< cProtocol > m_Protocol
void SendGameMode(eGameMode a_GameMode)
#define MAX_BLOCK_CHANGE_INTERACTIONS
Maximum number of block change interactions a player can perform per tick - exceeding this causes a k...
static int XpForLevel(int a_Level)
Calculates the amount of XP needed for a given level Ref: https://minecraft.gamepedia.com/XP.
bool SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, const AString &a_Command)
Sets the command block command.
void SendPlayerMoveLook(void)
void SendStatistics(const cStatManager &a_Manager)
virtual void AttachTo(cEntity *a_AttachTo) override
Attaches to the specified entity; detaches from any previous one first.
bool WantsSendChunk(int a_ChunkX, int a_ChunkZ)
Returns true if the client wants the chunk specified to be sent (in m_ChunksToSend) ...
int GetChunkX(void) const
bool CheckMultiLogin(const AString &a_Username)
Kicks the client if the same username is already logged in.
void SendEntityEffect(const cEntity &a_Entity, int a_EffectID, int a_Amplifier, int a_Duration)
void AbortEating(void)
Aborts the current eating operation.
bool IsGameModeSurvival(void) const
Returns true if the player is in Survival mode, either explicitly, or by inheriting from current worl...
bool CallHookPlayerUsingItem(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
void LOG(const char *a_Format, fmt::ArgList a_ArgList)
const AString & GetUsername(void) const
const cItem & GetShieldSlot() const
Returns current item in shield slot.
void SendExperienceOrb(const cExpOrb &a_ExpOrb)
bool HandleLogin(const AString &a_Username)
Called when the protocol has finished logging the user in.
virtual bool IsDrinkable(short a_ItemDamage)
Indicates if this item is drinkable.
Vector3d GetEyePosition(void) const
The client has just connected, waiting for their handshake / login.
void UseEquippedItem(short a_Damage=1)
Damage the player's equipped item by a_Damage, possibly less if the equipped item is enchanted...
void SendUnleashEntity(const cEntity &a_Entity)
std::unordered_set< cChunkCoords, cChunkCoordsHash > m_ChunksToSend
void SendSpawnVehicle(const cEntity &a_Vehicle, char a_VehicleType, char a_VehicleSubType=0)
static const char * Green
static const char * Italic
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.
void SendTo(cClientHandle &a_Client)
Send this scoreboard to the specified client.
void PacketBufferFull(void)
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
void SendSetRawTitle(const AString &a_Title)
void SendWindowClose(const cWindow &a_Window)
bool CallHookPlayerEating(cPlayer &a_Player)
bool DoWithPlayerByUUID(const cUUID &a_PlayerUUID, cPlayerListCallback a_Callback)
Finds the player over his uuid and calls the callback.
void RemoveChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle *a_Client)
Removes client from the chunk specified.
void ProcessProtocolInOut(void)
Processes the data in the network input and output buffers.
void SteerVehicle(float a_Forward, float a_Sideways)
int m_NumExplosionsThisTick
Number of explosions sent this tick.
virtual const cItem * GetSlot(int a_SlotNum, cPlayer &a_Player) const =0
Called to retrieve an item in the specified slot for the specified player.
cAuthenticator & GetAuthenticator(void)
void SendPlayerAbilities(void)
virtual void OnCancelRightClick(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace)
Called when a right click to this block is cancelled.
void HandleBeaconSelection(int a_PrimaryEffect, int a_SecondaryEffect)
Called when the protocol receives a MC|Beacon plugin message, indicating that the player set an effec...
std::list< cChunkCoords > cChunkCoordsList
bool EnchantByXPLevels(int a_NumXPLevels)
Randomly enchants the item using the specified number of XP levels.
void SendChunkTo(int a_ChunkX, int a_ChunkZ, cChunkSender::eChunkPriority a_Priority, cClientHandle *a_Client)
Sends the chunk to the client specified, if the client doesn't have the chunk yet.
void SendPlayerListUpdatePing(const cPlayer &a_Player)
void TabCompleteUserName(const AString &a_Text, AStringVector &a_Results)
Appends all usernames starting with a_Text (case-insensitive) into Results.
double GetPosZ(void) const
AString ItemToFullString(const cItem &a_Item)
Translates a full item into a fully-specified string (including meta and count).
bool IsGameModeCreative(void) const
Returns true if the player is in Creative mode, either explicitly, or by inheriting from current worl...
void HandleEntityCrouch(UInt32 a_EntityID, bool a_IsCrouching)
char GetWindowID(void) const
static bool IsOneHitDig(BLOCKTYPE a_Type)
void RegisterPluginChannels(const AStringVector &a_ChannelList)
Adds all of the channels to the list of current plugin channels.
virtual void SetSlot(int a_SlotNum, cPlayer &a_Player, const cItem &a_Item)=0
Called to set an item in the specified slot for the specified player.
bool SetSecondaryEffect(cEntityEffect::eType a_Effect)
Sets the secondary effect.
void SetYaw(double a_Yaw)
void HandleUseEntity(UInt32 a_TargetEntityID, bool a_IsLeftClick)
bool IsGameModeSpectator(void) const
Returns true if the player is in Spectator mode, either explicitly, or by inheriting from current wor...
void HandleSlotSelected(Int16 a_SlotNum)
const cItem * GetSlot(cPlayer &a_Player, int a_SlotNum) const
Returns the item at the specified slot for the specified player.
int m_CurrentViewDistance
The actual view distance used, the minimum of client's requested view distance and world's max view d...
void FinishAuthenticate(const AString &a_Name, const cUUID &a_UUID, const Json::Value &a_Properties)
Finish logging the user in after authenticating.
static const char * White
bool SetPrimaryEffect(cEntityEffect::eType a_Effect)
Sets the primary effect.
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default)
AStringVector GetPlayerTabCompletionMultiWorld(const AString &a_Text)
Returns the completions for a player name across all worlds.
cInventory & GetInventory(void)
bool m_HasSentDC
True if a Disconnect packet has been sent in either direction.
This class represents the player's inventory The slots are divided into three areas: ...
void SetSlot(cPlayer &a_Player, int a_SlotNum, const cItem &a_Item)
Sets the item to the specified slot for the specified player.
void DestroyNoScheduling(bool a_ShouldBroadcast)
Destroy the entity without scheduling memory freeing.
The client will be destroyed in the next tick (flag set when socket closed)
void SendPluginMessage(const AString &a_Channel, const AString &a_Message)
void HandleAnvilItemName(const AString &a_ItemName)
Called when the protocol receives a MC|ItemName plugin message, indicating that the player named an i...
bool IsNil() const
Returns true if this contains the "nil" UUID with all bits set to 0.
void AddWantedChunk(int a_ChunkX, int a_ChunkZ)
Adds the chunk specified to the list of chunks wanted for sending (m_ChunksToSend) ...
virtual bool IsFood(void)
Indicates if this item is food.
void SetUsername(const AString &a_Username)
void SendEntityMetadata(const cEntity &a_Entity)
bool CallHookPlayerBrokenBlock(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
cItemHandler * ItemHandler(int a_ItemType)
void AddFoodExhaustion(double a_Exhaustion)
Adds the specified exhaustion to m_FoodExhaustion.
void SendPlayerListUpdateDisplayName(const cPlayer &a_Player, const AString &a_CustomName)
cEntityEffect::eType GetPrimaryEffect(void) const
void BeginForgeHandshake(const AString &a_Name, const cUUID &a_UUID, const Json::Value &a_Properties)
Begin the Forge Modloader Handshake (FML|HS) sequence.
std::vector< sSetBlock > sSetBlockVector
std::shared_ptr< cClientHandle > cClientHandlePtr
void SendDestroyEntity(const cEntity &a_Entity)
UInt32 GetUniqueID(void) const
virtual void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer &a_Player) override
Sends the block on those coords to the player.
int m_UniqueID
ID used for identification during authenticating.
cWorld * GetWorld(void) const
bool AreCommandBlocksEnabled(void) const
T Diff(T a_Val1, T a_Val2)
cPluginManager * GetPluginManager(void)
void BroadcastWholeWindow(void)
Sends the contents of the whole window to all clients of this window.
void SetEquippedSlotNum(int a_SlotNum)
Sets equiped item to the a_SlotNum slot number.
const AString & GetIPString(void) const
static const std::chrono::milliseconds PING_TIME_MS
The interval for sending pings to clients.
double GetSpawnX(void) const
void HandleUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4)
int m_RequestedViewDistance
The requested view distance from the player.
virtual bool Initialize(OwnedEntity a_Self, cWorld &a_World) override
Spawns the entity in the world; returns true if spawned, false if not (plugin disallowed).
static const char * LightBlue