summaryrefslogtreecommitdiffstats
path: root/src/ClientHandle.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/ClientHandle.h')
-rw-r--r--src/ClientHandle.h124
1 files changed, 78 insertions, 46 deletions
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 4add022a6..0c367ec7d 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -12,10 +12,12 @@
#define CCLIENTHANDLE_H_INCLUDED
#include "Defines.h"
-#include "Vector3d.h"
+#include "Vector3.h"
#include "OSSupport/SocketThreads.h"
#include "ChunkDef.h"
#include "ByteBuffer.h"
+#include "Scoreboard.h"
+#include "Map.h"
@@ -26,6 +28,7 @@ class cInventory;
class cMonster;
class cPawn;
class cExpOrb;
+class cPainting;
class cPickup;
class cPlayer;
class cProtocol;
@@ -33,6 +36,7 @@ class cWindow;
class cFallingBlock;
class cItemHandler;
class cWorld;
+class cCompositeChat;
@@ -42,7 +46,6 @@ class cClientHandle : // tolua_export
public cSocketThreads::cCallback
{ // tolua_export
public:
- static const int MAXBLOCKCHANGEINTERACTIONS = 20; // 5 didn't help, 10 still doesn't work in Creative, 20 seems to have done the trick
#if defined(ANDROID_NDK)
static const int DEFAULT_VIEW_DISTANCE = 4; // The default ViewDistance (used when no value is set in Settings.ini)
@@ -52,9 +55,6 @@ public:
static const int MAX_VIEW_DISTANCE = 15;
static const int MIN_VIEW_DISTANCE = 3;
- /// How many ticks should be checked for a running average of explosions, for limiting purposes
- static const int NUM_CHECK_EXPLOSIONS_TICKS = 20;
-
cClientHandle(const cSocket * a_Socket, int a_ViewDistance);
virtual ~cClientHandle();
@@ -72,10 +72,10 @@ public:
inline bool IsLoggedIn(void) const { return (m_State >= csAuthenticating); }
- /// Called while the client is being ticked from the world via its cPlayer object
+ /** Called while the client is being ticked from the world via its cPlayer object */
void Tick(float a_Dt);
- /// Called while the client is being ticked from the cServer object
+ /** Called while the client is being ticked from the cServer object */
void ServerTick(float a_Dt);
void Destroy(void);
@@ -91,7 +91,8 @@ public:
void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage);
void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); // tolua_export
void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes);
- void SendChat (const AString & a_Message);
+ void SendChat (const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData = "");
+ void SendChat (const cCompositeChat & a_Message);
void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer);
void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player);
void SendDestroyEntity (const cEntity & a_Entity);
@@ -111,6 +112,10 @@ public:
void SendGameMode (eGameMode a_GameMode);
void SendHealth (void);
void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item);
+ void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length);
+ void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators);
+ void SendMapInfo (int a_ID, unsigned int a_Scale);
+ void SendPaintingSpawn (const cPainting & a_Painting);
void SendPickupSpawn (const cPickup & a_Pickup);
void SendEntityAnimation (const cEntity & a_Entity, char a_Animation);
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_ParticleAmmount);
@@ -125,6 +130,9 @@ public:
void SendRespawn (void);
void SendExperience (void);
void SendExperienceOrb (const cExpOrb & a_ExpOrb);
+ void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode);
+ void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode);
+ void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display);
void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch); // a_Src coords are Block * 8
void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data);
void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock);
@@ -145,20 +153,28 @@ public:
void SendWindowOpen (const cWindow & a_Window);
void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value);
- const AString & GetUsername(void) const; // tolua_export
- void SetUsername( const AString & a_Username ); // tolua_export
+ // tolua_begin
+ const AString & GetUsername(void) const;
+ void SetUsername( const AString & a_Username );
+
+ inline short GetPing(void) const { return m_Ping; }
- inline short GetPing(void) const { return m_Ping; } // tolua_export
+ void SetViewDistance(int a_ViewDistance);
+ int GetViewDistance(void) const { return m_ViewDistance; }
- void SetViewDistance(int a_ViewDistance); // tolua_export
- int GetViewDistance(void) const { return m_ViewDistance; } // tolua_export
+ void SetLocale(AString & a_Locale) { m_Locale = a_Locale; }
+ AString GetLocale(void) const { return m_Locale; }
- int GetUniqueID() const { return m_UniqueID; } // tolua_export
+ int GetUniqueID(void) const { return m_UniqueID; }
+
+ bool HasPluginChannel(const AString & a_PluginChannel);
+
+ // tolua_end
- /// Returns true if the client wants the chunk specified to be sent (in m_ChunksToSend)
+ /** Returns true if the client wants the chunk specified to be sent (in m_ChunksToSend) */
bool WantsSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
- /// Adds the chunk specified to the list of chunks wanted for sending (m_ChunksToSend)
+ /** Adds the chunk specified to the list of chunks wanted for sending (m_ChunksToSend) */
void AddWantedChunk(int a_ChunkX, int a_ChunkZ);
// Calls that cProtocol descendants use to report state:
@@ -171,7 +187,9 @@ public:
void HandleChat (const AString & a_Message);
void HandleCreativeInventory(short a_SlotNum, const cItem & a_HeldItem);
void HandleDisconnect (const AString & a_Reason);
- void HandleEntityAction (int a_EntityID, char a_ActionID);
+ void HandleEntityCrouch (int a_EntityID, bool a_IsCrouching);
+ void HandleEntityLeaveBed (int a_EntityID);
+ void HandleEntitySprinting (int a_EntityID, bool a_IsSprinting);
/** Called when the protocol handshake has been received (for protocol versions that support it;
otherwise the first instant when a username is received).
@@ -180,7 +198,7 @@ public:
bool HandleHandshake (const AString & a_Username);
void HandleKeepAlive (int a_KeepAliveID);
- void HandleLeftClick (int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status);
+ void HandleLeftClick (int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, char a_Status);
void HandlePing (void);
void HandlePlayerAbilities (bool a_CanFly, bool a_IsFlying, float FlyingSpeed, float WalkingSpeed);
void HandlePlayerLook (float a_Rotation, float a_Pitch, bool a_IsOnGround);
@@ -188,7 +206,7 @@ public:
void HandlePlayerPos (double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround);
void HandlePluginMessage (const AString & a_Channel, const AString & a_Message);
void HandleRespawn (void);
- void HandleRightClick (int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, const cItem & a_HeldItem);
+ void HandleRightClick (int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, const cItem & a_HeldItem);
void HandleSlotSelected (short a_SlotNum);
void HandleSteerVehicle (float Forward, float Sideways);
void HandleTabCompletion (const AString & a_Text);
@@ -207,16 +225,19 @@ public:
*/
bool HandleLogin(int a_ProtocolVersion, const AString & a_Username);
- void SendData(const char * a_Data, int a_Size);
+ void SendData(const char * a_Data, size_t a_Size);
- /// Called when the player moves into a different world; queues sreaming the new chunks
+ /** Called when the player moves into a different world; queues sreaming the new chunks */
void MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket);
- /// Handles the block placing packet when it is a real block placement (not block-using, item-using or eating)
- void HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler);
-
private:
+ /** Handles the block placing packet when it is a real block placement (not block-using, item-using or eating) */
+ void HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler);
+
+ /** The type used for storing the names of registered plugin channels. */
+ typedef std::set<AString> cChannels;
+
int m_ViewDistance; // Number of chunks the player can see in each direction; 4 is the minimum ( http://wiki.vg/Protocol_FAQ#.E2.80.A6all_connecting_clients_spasm_and_jerk_uncontrollably.21 )
static const int GENERATEDISTANCE = 2; // Server generates this many chunks AHEAD of player sight. 2 is the minimum, since foliage is generated 1 step behind chunk terrain generation
@@ -249,7 +270,7 @@ private:
int m_LastStreamedChunkX;
int m_LastStreamedChunkZ;
- /// Seconds since the last packet data was received (updated in Tick(), reset in DataReceived())
+ /** Seconds since the last packet data was received (updated in Tick(), reset in DataReceived()) */
float m_TimeSinceLastPacket;
short m_Ping;
@@ -271,7 +292,7 @@ private:
int m_LastDigBlockY;
int m_LastDigBlockZ;
- /// Used while csDestroyedWaiting for counting the ticks until the connection is closed
+ /** Used while csDestroyedWaiting for counting the ticks until the connection is closed */
int m_TicksSinceDestruction;
enum eState
@@ -291,46 +312,57 @@ private:
eState m_State;
- /// m_State needs to be locked in the Destroy() function so that the destruction code doesn't run twice on two different threads
+ /** m_State needs to be locked in the Destroy() function so that the destruction code doesn't run twice on two different threads */
cCriticalSection m_CSDestroyingState;
- /// If set to true during csDownloadingWorld, the tick thread calls CheckIfWorldDownloaded()
+ /** If set to true during csDownloadingWorld, the tick thread calls CheckIfWorldDownloaded() */
bool m_ShouldCheckDownloaded;
- /// Stores the recent history of the number of explosions per tick
- int m_NumExplosionsPerTick[NUM_CHECK_EXPLOSIONS_TICKS];
-
- /// Points to the current tick in the m_NumExplosionsPerTick[] array
- int m_CurrentExplosionTick;
-
- /// Running sum of m_NumExplosionsPerTick[]
- int m_RunningSumExplosions;
+ /** Number of explosions sent this tick */
+ int m_NumExplosionsThisTick;
+
+ /** Number of place or break interactions this tick */
+ int m_NumBlockChangeInteractionsThisTick;
static int s_ClientCount;
int m_UniqueID;
- /// Set to true when the chunk where the player is is sent to the client. Used for spawning the player
+ /** Set to true when the chunk where the player is is sent to the client. Used for spawning the player */
bool m_HasSentPlayerChunk;
+
+ /** Client Settings */
+ AString m_Locale;
+ /** The plugin channels that the client has registered. */
+ cChannels m_PluginChannels;
- /// Returns true if the rate block interactions is within a reasonable limit (bot protection)
+ /** Returns true if the rate block interactions is within a reasonable limit (bot protection) */
bool CheckBlockInteractionsRate(void);
- /// Adds a single chunk to be streamed to the client; used by StreamChunks()
+ /** Adds a single chunk to be streamed to the client; used by StreamChunks() */
void StreamChunk(int a_ChunkX, int a_ChunkZ);
- /// Handles the DIG_STARTED dig packet:
- void HandleBlockDigStarted (int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta);
+ /** Handles the DIG_STARTED dig packet: */
+ void HandleBlockDigStarted (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 HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta);
+ /** Handles the DIG_FINISHED dig packet: */
+ void HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta);
- /// Handles the "MC|AdvCdm" plugin message
- void HandleCommandBlockMessage(const char* a_Data, unsigned int a_Length);
+ /** Converts the protocol-formatted channel list (NUL-separated) into a proper string vector. */
+ AStringVector BreakApartPluginChannels(const AString & a_PluginChannels);
+
+ /** Adds all of the channels to the list of current plugin channels. Handles duplicates gracefully. */
+ void RegisterPluginChannels(const AStringVector & a_ChannelList);
+
+ /** Removes all of the channels from the list of current plugin channels. Ignores channels that are not found. */
+ void UnregisterPluginChannels(const AStringVector & a_ChannelList);
+
+ /** Handles the "MC|AdvCdm" plugin message */
+ void HandleCommandBlockMessage(const char * a_Data, unsigned int a_Length);
// cSocketThreads::cCallback overrides:
- virtual void DataReceived (const char * a_Data, int a_Size) override; // Data is received from the client
+ virtual void DataReceived (const char * a_Data, size_t a_Size) override; // Data is received from the client
virtual void GetOutgoingData(AString & a_Data) override; // Data can be sent to client
virtual void SocketClosed (void) override; // The socket has been closed for any reason
}; // tolua_export