|
Cuberite
A lightweight, fast and extensible game server for Minecraft
|
Go to the documentation of this file.
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;
AStringMap m_ForgeMods
Forge mods and versions installed on this client.
int m_NumBlockChangeInteractionsThisTick
Number of place or break interactions this tick.
bool HandleHandshake(const AString &a_Username)
Called when the protocol handshake has been received (for protocol versions that support it; otherwis...
std::shared_ptr< cClientHandle > cClientHandlePtr
void SendData(ContiguousByteBufferView a_Data)
static float FASTBREAK_PERCENTAGE
The percentage how much a block has to be broken.
void RemoveFromWorld(void)
Called when the player moves into a different world.
void SendUnloadChunk(int a_ChunkX, int a_ChunkZ)
void SendCameraSetTo(const cEntity &a_Entity)
void SendEntityMetadata(const cEntity &a_Entity)
void HandleSlotSelected(Int16 a_SlotNum)
void SendEntityVelocity(const cEntity &a_Entity)
short GetPing(void) const
eClickAction
Individual actions sent in the WindowClick packet.
AString m_Locale
Client Settings.
void HandleCreativeInventory(Int16 a_SlotNum, const cItem &a_HeldItem, eClickAction a_ClickAction)
Called when the client clicks the creative inventory window.
std::vector< sSetBlock > sSetBlockVector
void SendInitRecipes(UInt32 a_RecipeId)
Send already known recipes without notification but visible in the recipe book.
void Tick(std::chrono::milliseconds a_Dt)
Called while the client is being ticked from the world via its cPlayer object.
void HandleCraftRecipe(UInt32 a_RecipeId)
Called when a recipe from the recipe book is selected.
virtual void OnReceivedData(const char *a_Data, size_t a_Length) override
Called when there's data incoming from the remote peer.
void SendGameMode(eGameMode a_GameMode)
Container for a single chat message composed of multiple functional parts.
cMultiVersionProtocol m_Protocol
const AString & GetIPString(void) const
virtual void OnLinkCreated(cTCPLinkPtr a_Link) override
Called when the cTCPLink for the connection is created.
std::basic_string< std::byte > ContiguousByteBuffer
void SendWeather(eWeather a_Weather)
void HandleBlockDigFinished(Vector3i a_BlockPos, eBlockFace a_BlockFace)
Handles the DIG_FINISHED dig packet:
bool IsWithinReach(Vector3i a_Position) const
Returns whether the player could in fact reach the position they're attempting to interact with.
void RegisterPluginChannels(const AStringVector &a_ChannelList)
Adds all of the channels to the list of current plugin channels.
std::map< AString, AString > AStringMap
A string dictionary, used for key-value pairs.
int m_UniqueID
ID used for identification during authenticating.
void SendAttachEntity(const cEntity &a_Entity, const cEntity &a_Vehicle)
void SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector &a_Changes)
void SendChatSystem(const AString &a_Message, eMessageType a_ChatPrefix, const AString &a_AdditionalData="")
Meta-protocol that recognizes multiple protocol versions, creates the specific protocol version insta...
std::atomic< eState > m_State
The current (networking) state of the client.
Class that manages the statistics and achievements of a single player.
void SendPlayerAbilities(void)
void SendLeashEntity(const cEntity &a_Entity, const cEntity &a_EntityLeashedTo)
void SendCollectEntity(const cEntity &a_Collected, const cEntity &a_Collector, unsigned a_Count)
std::unordered_set< cChunkCoords, cChunkCoordsHash > m_LoadedChunks
bool m_HasSentPlayerChunk
Set to true when the chunk where the player is is sent to the client.
cCriticalSection m_CSOutgoingData
Protects m_OutgoingData against multithreaded access.
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...
std::list< cChunkCoords > cChunkCoordsList
void SendTimeUpdate(cTickTimeLong a_WorldAge, cTickTimeLong a_WorldDate, bool a_DoDaylightCycle)
static Vector3i s_IllegalPosition
void SendPlayerPosition(void)
void SocketClosed(void)
Called when the network socket has been closed.
bool IsForgeClient
True if the client advertised itself as a Forge client.
static const int DEFAULT_VIEW_DISTANCE
void PacketUnknown(UInt32 a_PacketType)
void SetUUID(const cUUID &a_UUID)
Sets the player's UUID, as used by the protocol.
void HandleTabCompletion(const AString &a_Text)
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg) override
Called when an error is detected on the connection.
void HandleRightClick(Vector3i a_BlockPos, eBlockFace a_BlockFace, Vector3i a_Cursor, bool a_UsedMainHand)
std::shared_ptr< cTCPLink > cTCPLinkPtr
void SendEntityAnimation(const cEntity &a_Entity, EntityAnimation a_Animation)
void SendPlayerListUpdatePing()
virtual void OnRemoteClosed(void) override
Called when the remote end closes the connection.
int m_NumExplosionsThisTick
Number of explosions sent this tick.
void HandleChat(const AString &a_Message)
Called when the protocol detects a chat packet.
void SendEntityLook(const cEntity &a_Entity)
void HandleUseEntity(UInt32 a_TargetEntityID, bool a_IsLeftClick)
void SendPlayerListAddPlayer(const cPlayer &a_Player)
void SendChunkData(int a_ChunkX, int a_ChunkZ, ContiguousByteBufferView a_ChunkData)
void SendTabCompletionResults(const AStringVector &a_Results)
int GetRequestedViewDistance(void) const
Returns the view distance that the player request, not the used view distance.
void HandleSteerVehicle(float Forward, float Sideways)
void HandleResourcePack(UInt8 a_Status)
void HandleUpdateSign(Vector3i a_BlockPos, const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4)
bool BungeeAuthenticate()
Authenticates the specified user with the bungee proxy server.
void SendWholeInventory(const cWindow &a_Window)
void ForgeAugmentServerListPing(Json::Value &a_Response)
Add the Forge mod list to the server ping response.
void ServerTick(float a_Dt)
Called while the client is being ticked from the cServer object.
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
void SendBlockBreakAnim(UInt32 a_EntityID, Vector3i a_BlockPos, char a_Stage)
void ProcessProtocolOut()
Flushes all buffered outgoing data to the network.
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()
void SendSetRawSubTitle(const AString &a_SubTitle)
void SendEntityProperties(const cEntity &a_Entity)
static const int MIN_VIEW_DISTANCE
void SendSetRawTitle(const AString &a_Title)
cPlayer * GetPlayer(void)
void SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks)
bool IsDestroyed(void) const
void SendBossBarUpdateHealth(UInt32 a_UniqueID, float a_FractionFilled)
void SendPlayerListRemovePlayer(const cPlayer &a_Player)
const cUUID & GetUUID(void) const
Returns the player's UUID, as used by the protocol.
void SendBossBarUpdateStyle(UInt32 a_UniqueID, BossBarColor a_Color, BossBarDivisionType a_DivisionType)
const AString & GetClientBrand(void) const
Returns the client brand received in the MC|Brand plugin message or set by a plugin.
void SendEntityEquipment(const cEntity &a_Entity, short a_SlotNum, const cItem &a_Item)
void HandleSprint(bool a_IsSprinting)
Handles a player sprinting or slowing back down.
void HandleEnchantItem(UInt8 a_WindowID, UInt8 a_Enchantment)
Called when the player enchants an Item in the Enchanting table UI.
void AugmentServerListPing(cClientHandle &a_Client, Json::Value &ResponseValue)
Add the registered Forge mods to the server ping list packet.
int m_CurrentViewDistance
The actual view distance used, the minimum of client's requested view distance and world's max view d...
void SendSoundEffect(const AString &a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch)
void SetUsername(AString &&a_Username)
void SendBossBarRemove(UInt32 a_UniqueID)
void SendScoreboardObjective(const AString &a_Name, const AString &a_DisplayName, Byte a_Mode)
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...
void HandlePluginMessage(const AString &a_Channel, ContiguousByteBufferView a_Message)
UInt32 GetProtocolVersion(void) const
Returns the protocol version number of the protocol that the client is talking.
void SendEntityPosition(const cEntity &a_Entity)
void PacketBufferFull(void)
void SendPaintingSpawn(const cPainting &a_Painting)
void SetLocale(const AString &a_Locale)
void HandleUseItem(bool a_UsedMainHand)
void HandleCrouch(bool a_IsCrouching)
Handles a player sneaking or unsneaking.
bool IsPlaying(void) const
void SendDisconnect(const AString &a_Reason)
std::unordered_set< cChunkCoords, cChunkCoordsHash > m_ChunksToSend
AStringVector BreakApartPluginChannels(ContiguousByteBufferView a_PluginChannels)
Converts the protocol-formatted channel list (NUL-separated) into a proper string vector.
void SendHeldItemChange(int a_ItemIndex)
void SendPlayerListUpdateGameMode(const cPlayer &a_Player)
cChunkCoordsList m_SentChunks
void SendPlayerPermissionLevel(void)
cUUID m_UUID
Contains the UUID used by Mojang to identify the player's account.
void HandleLeftClick(Vector3i a_BlockPos, eBlockFace a_BlockFace, UInt8 a_Status)
void SetProtocolVersion(UInt32 a_ProtocolVersion)
Called by the protocol recognizer when the protocol version is known.
void SendResetTitle(void)
AString m_ClientBrand
The brand identification of the client, as received in the MC|Brand plugin message or set from a plug...
void HandleBlockDigStarted(Vector3i a_BlockPos, eBlockFace a_BlockFace)
Handles the DIG_STARTED dig packet:
bool CheckBlockInteractionsRate(void)
Returns true if the rate block interactions is within a reasonable limit (bot protection)
std::basic_string_view< std::byte > ContiguousByteBufferView
cCriticalSection m_CSChunkLists
Vector3i m_LastPlacedSign
The positions from the last sign that the player placed.
cForgeHandshake m_ForgeHandshake
Forge handshake state machine.
bool IsNil() const
Returns true if this contains the "nil" UUID with all bits set to 0.
void SendPluginMessage(const AString &a_Channel, std::string_view a_Message)
Serializes one chunk's data to (possibly multiple) protocol versions.
void SendPlayerListHeaderFooter(const cCompositeChat &a_Header, const cCompositeChat &a_Footer)
cChannels m_PluginChannels
The plugin channels that the client has registered.
void SetViewDistance(int a_ViewDistance)
Sets the maximal view distance.
void SendScoreUpdate(const AString &a_Objective, const AString &a_Player, cObjective::Score a_Score, Byte a_Mode)
void SendEditSign(Vector3i a_BlockPos)
@ csConnected
The client has just connected, waiting for their handshake / login.
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 ...
cCriticalSection m_CSState
void SendDetachEntity(const cEntity &a_Entity, const cEntity &a_PreviousVehicle)
@ csDestroyed
The client has been destroyed, the destructor is to be called from the owner thread.
void SendResourcePack(const AString &a_ResourcePackUrl)
static const int MAX_VIEW_DISTANCE
cTCPLinkPtr m_Link
The link that is used for network communication.
std::chrono::steady_clock::duration m_Ping
Duration of the last completed client ping.
Vector3i m_BlockDigAnimPos
void SendSetTitle(const cCompositeChat &a_Title)
void SendRemoveEntityEffect(const cEntity &a_Entity, int a_EffectID)
std::chrono::steady_clock::time_point m_PingStartTime
Time of the last ping request sent to the client.
void AddWantedChunk(int a_ChunkX, int a_ChunkZ)
Adds the chunk specified to the list of chunks wanted for sending (m_ChunksToSend)
void SendPlayerMoveLook(void)
void SendSpawnEntity(const cEntity &a_Entity)
void HandleLeaveBed()
Handles a player exiting his bed.
ContiguousByteBuffer m_OutgoingData
Buffer for storing outgoing data from any thread; will get sent in ProcessProtocolOut() at the end of...
void SendExperience(void)
void Kick(const AString &a_Reason)
void SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem &a_Item)
void HandlePlayerLook(float a_Rotation, float a_Pitch, bool a_IsOnGround)
unsigned char BLOCKTYPE
The datatype used by blockdata.
void SetIsForgeClient()
Mark a client connection as using Forge.
void SendWindowOpen(const cWindow &a_Window)
Encapsulates an in-game world map.
void SendDestroyEntity(const cEntity &a_Entity)
eDimension
Dimension of a world.
void SendEntityEffect(const cEntity &a_Entity, int a_EffectID, int a_Amplifier, int a_Duration)
static cUUID GenerateOfflineUUID(const AString &a_Username)
Generates an UUID based on the player name provided.
void SendUnleashEntity(const cEntity &a_Entity)
void SendWindowProperty(const cWindow &a_Window, size_t a_Property, short a_Value)
void StreamNextChunks()
Sends a set number of new chunks to the player on every invocation, until all chunks in the view dist...
Vector3i m_LastDigBlockPos
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...
Priority
Tag indicating urgency of chunk to be sent.
std::atomic< int > m_TicksSinceLastPacket
Number of ticks since the last network packet was received (increased in Tick(), reset in OnReceivedD...
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)
bool m_ProxyConnection
True if player connected from a proxy (Bungee / Velocity)
bool SetState(eState a_NewState)
Called to update m_State.
void SendBossBarUpdateTitle(UInt32 a_UniqueID, const cCompositeChat &a_Title)
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
void HandleKeepAlive(UInt32 a_KeepAliveID)
void HandlePlayerMove(Vector3d a_Pos, bool a_IsOnGround)
Verifies and sets player position, performing relevant checks.
int GetViewDistance(void) const
Returns the view distance that the player currently have.
const AString & GetUsername(void) const
void HandlePlayerMoveLook(Vector3d a_Pos, float a_Rotation, float a_Pitch, bool a_IsOnGround)
void SendPlayerSpawn(const cPlayer &a_Player)
bool IsLoggedIn(void) const
void SendParticleEffect(const AString &a_ParticleName, Vector3f a_Source, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount)
void SendEntityHeadLook(const cEntity &a_Entity)
float m_BreakProgress
The fraction between 0 and 1 (or above), of how far through mining the currently mined block is.
void SetClientBrand(const AString &a_ClientBrand)
Called by the protocol when it receives the MC|Brand plugin message.
void SendSetSubTitle(const cCompositeChat &a_SubTitle)
bool HasPluginChannel(const AString &a_PluginChannel)
void Authenticate(AString &&a_Name, const cUUID &a_UUID, Json::Value &&a_Properties)
Authenticates ourselves, called by cAuthenticator supplying player details from Mojang.
void SendChatRaw(const AString &a_MessageRaw, eChatType a_Type)
void SendSoundParticleEffect(const EffectID a_EffectID, Vector3i a_Source, int a_Data)
void SetIPString(const AString &a_IPString)
Sets the IP string that the client is using.
std::chrono::duration< signed long long int, cTickTime::period > cTickTimeLong
void SetProperties(const Json::Value &a_Properties)
Sets the player's properties, such as skin image and signature.
bool CheckMultiLogin(const AString &a_Username)
Kicks the client if the same username is already logged in.
void HandlePlayerAbilities(bool a_IsFlying, float FlyingSpeed, float WalkingSpeed)
bool HandleLogin()
Called when the protocol has finished logging the user in.
void HandleOpenHorseInventory()
Handles a player opening his inventory while riding a horse.
void SendBlockChange(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
std::set< AString > cChannels
The type used for storing the names of registered plugin channels.
cPlayer * m_Player
A pointer to a World-owned player object, created in FinishAuthenticate when authentication succeeds.
AString GetLocale(void) const
void SendMapData(const cMap &a_Map, int a_DataStartX, int a_DataStartY)
void SendDisplayObjective(const AString &a_Objective, cScoreboard::eDisplaySlot a_Display)
void UnloadOutOfRangeChunks(void)
Remove all loaded chunks that are no longer in range.
const AStringMap & GetForgeMods(void) const
Returns the Forge mods installed on the client.
void SendBossBarUpdateFlags(UInt32 a_UniqueID, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog)
cChunkCoords m_CachedSentChunk
This is an optimization which saves you an iteration of m_SentChunks if you just want to know whether...
static AString FormatChatPrefix(bool ShouldAppendChatPrefixes, const AString &a_ChatPrefixS, const AString &m_Color1, const AString &m_Color2)
cCriticalSection m_CSIncomingData
Protects m_IncomingData against multithreaded access.
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 SendUpdateBlockEntity(cBlockEntity &a_BlockEntity)
void FinishAuthenticate()
Finish logging the user in after authenticating.
void PacketError(UInt32 a_PacketType)
void HandleSpectate(const cUUID &a_PlayerUUID)
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.
@ csAuthenticating
The client has logged in, waiting for external authentication.
std::chrono::milliseconds m_TimeSinceLastUnloadCheck
The time since UnloadOutOfRangeChunks was last called.
int GetUniqueID(void) const
ContiguousByteBuffer m_IncomingData
Queue for the incoming data received on the link until it is processed in ProcessProtocolIn().
void SendUnlockRecipe(UInt32 a_RecipeId)
Send a newly discovered recipe to show the notification and unlock in the recipe book.
const Json::Value & GetProperties(void) const
@ csPlaying
Normal gameplay.
virtual ~cClientHandle() override
void SendThunderbolt(Vector3i a_BlockPos)
void SendStatistics(const StatisticsManager &a_Manager)
UInt32 m_ProtocolVersion
The version of the protocol that the client is talking, or 0 if unknown.
bool IsForgeClient(void) const
Returns true if the client is modded with Forge.
void SendExplosion(Vector3f a_Position, float a_Power)
void HandleWindowClose(UInt8 a_WindowID)
void ProcessProtocolIn(void)
Processes the data in the network input buffer.
bool WantsSendChunk(int a_ChunkX, int a_ChunkZ)
Returns true if the client wants the chunk specified to be sent (in m_ChunksToSend)
@ csDownloadingWorld
The client is waiting for chunks, we're waiting for the loader to provide and send them.
void SendPlayerListUpdateDisplayName(const cPlayer &a_Player, const AString &a_CustomName)
void HandleWindowClick(UInt8 a_WindowID, Int16 a_SlotNum, eClickAction a_ClickAction, const cItem &a_HeldItem)
void HandleNPCTrade(int a_SlotNum)
Called when the protocol receives a MC|TrSel packet, indicating that the player used a trade in the N...
void HandleAnimation(bool a_SwingMainHand)
Called when the protocol receives a (hand swing) animation packet.
void SendRespawn(eDimension a_Dimension, bool a_IsRespawningFromDeath)
void SendBlockAction(Vector3i a_BlockPos, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType)
int m_RequestedViewDistance
The requested view distance from the player.
void HandleAnvilItemName(const AString &a_ItemName)
Called when the protocol receives a MC|ItemName plugin message, indicating that the player named an i...
void SendChat(const AString &a_Message, eMessageType a_ChatPrefix, const AString &a_AdditionalData="")
void SendUpdateSign(Vector3i a_BlockPos, const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4)
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 HandleStartElytraFlight()
Handles a player starting elytra flight while falling.
void SendChatAboveActionBar(const AString &a_Message, eMessageType a_ChatPrefix, const AString &a_AdditionalData="")
void UnregisterPluginChannels(const AStringVector &a_ChannelList)
Removes all of the channels from the list of current plugin channels.
UInt32 m_PingID
ID of the last ping request sent to the client.
void FinishDigAnimation()
The clients will receive a finished dig animation.
bool m_HasSentDC
True if a Disconnect packet has been sent in either direction.
void SendExperienceOrb(const cExpOrb &a_ExpOrb)
std::vector< AString > AStringVector
void SendWindowClose(const cWindow &a_Window)