diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-07-07 15:06:06 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-07-07 15:06:06 +0200 |
commit | b1d05b0f57e03261eaf776c9bb9b81cfa05a13f5 (patch) | |
tree | 7684b48d5aa7b37cdaa6fdd12fb27ca46a9ed241 /source/ClientHandle.cpp | |
parent | AnvilStats: moved into the Tools folder (diff) | |
download | cuberite-b1d05b0f57e03261eaf776c9bb9b81cfa05a13f5.tar cuberite-b1d05b0f57e03261eaf776c9bb9b81cfa05a13f5.tar.gz cuberite-b1d05b0f57e03261eaf776c9bb9b81cfa05a13f5.tar.bz2 cuberite-b1d05b0f57e03261eaf776c9bb9b81cfa05a13f5.tar.lz cuberite-b1d05b0f57e03261eaf776c9bb9b81cfa05a13f5.tar.xz cuberite-b1d05b0f57e03261eaf776c9bb9b81cfa05a13f5.tar.zst cuberite-b1d05b0f57e03261eaf776c9bb9b81cfa05a13f5.zip |
Diffstat (limited to '')
-rw-r--r-- | source/ClientHandle.cpp | 305 |
1 files changed, 157 insertions, 148 deletions
diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index 4d4f40745..f8bfa5b15 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -262,7 +262,7 @@ void cClientHandle::Authenticate(void) m_State = csDownloadingWorld; // Broadcast this player's spawning to all other players in the same chunk - m_Player->GetWorld()->BroadcastSpawn(*m_Player, this); + m_Player->GetWorld()->BroadcastSpawnEntity(*m_Player, this); cRoot::Get()->GetPluginManager()->CallHookPlayerSpawned(*m_Player); } @@ -1347,186 +1347,235 @@ void cClientHandle::Tick(float a_Dt) -void cClientHandle::SendDisconnect(const AString & a_Reason) +void cClientHandle::SendAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle) { - if (!m_HasSentDC) - { - LOGD("Sending a DC: \"%s\"", a_Reason.c_str()); - m_Protocol->SendDisconnect(a_Reason); - m_HasSentDC = true; - } + m_Protocol->SendAttachEntity(a_Entity, a_Vehicle); } -void cClientHandle::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item) +void cClientHandle::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) { - m_Protocol->SendInventorySlot(a_WindowID, a_SlotNum, a_Item); + m_Protocol->SendBlockAction(a_BlockX, a_BlockY, a_BlockZ, a_Byte1, a_Byte2, a_BlockType); } -void cClientHandle::SendChat(const AString & a_Message) +void cClientHandle::SendBlockBreakAnim(int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) { - m_Protocol->SendChat(a_Message); + m_Protocol->SendBlockBreakAnim(a_EntityID, a_BlockX, a_BlockY, a_BlockZ, a_Stage); } -void cClientHandle::SendPlayerAnimation(const cPlayer & a_Player, char a_Animation) +void cClientHandle::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { - m_Protocol->SendPlayerAnimation(a_Player, a_Animation); + m_Protocol->SendBlockChange(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); } -void cClientHandle::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) +void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) { - m_Protocol->SendEntityEquipment(a_Entity, a_SlotNum, a_Item); + m_Protocol->SendBlockChanges(a_ChunkX, a_ChunkZ, a_Changes); } -void cClientHandle::SendWindowClose(const cWindow & a_Window) +void cClientHandle::SendChat(const AString & a_Message) { - m_Protocol->SendWindowClose(a_Window); + m_Protocol->SendChat(a_Message); } -void cClientHandle::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) +void cClientHandle::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) { - m_Protocol->SendWindowOpen(a_WindowID, a_WindowType, a_WindowTitle, a_NumSlots); + // Check chunks being sent, erase them from m_ChunksToSend: + bool Found = false; + { + cCSLock Lock(m_CSChunkLists); + for (cChunkCoordsList::iterator itr = m_ChunksToSend.begin(); itr != m_ChunksToSend.end(); ++itr) + { + if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ)) + { + m_ChunksToSend.erase(itr); + + // Make the tick thread check if all the needed chunks have been downloaded + // -- needed to offload this from here due to a deadlock possibility + m_ShouldCheckDownloaded = true; + + Found = true; + break; + } + } // for itr - m_ChunksToSend[] + } + if (!Found) + { + // This just sometimes happens. If you have a reliably replicatable situation for this, go ahead and fix it + // It's not a big issue anyway, just means that some chunks may be compressed several times + // LOGD("Refusing to send chunk [%d, %d] to client \"%s\" at [%d, %d].", ChunkX, ChunkZ, m_Username.c_str(), m_Player->GetChunkX(), m_Player->GetChunkZ()); + return; + } + + m_Protocol->SendChunkData(a_ChunkX, a_ChunkZ, a_Serializer); } -void cClientHandle::SendWholeInventory(const cInventory & a_Inventory) +void cClientHandle::SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player) { - m_Protocol->SendWholeInventory(a_Inventory); + m_Protocol->SendCollectPickup(a_Pickup, a_Player); } -void cClientHandle::SendWholeInventory(const cWindow & a_Window) +void cClientHandle::SendDestroyEntity(const cEntity & a_Entity) { - m_Protocol->SendWholeInventory(a_Window); + m_Protocol->SendDestroyEntity(a_Entity); } -void cClientHandle::SendTeleportEntity(const cEntity & a_Entity) +void cClientHandle::SendDisconnect(const AString & a_Reason) { - m_Protocol->SendTeleportEntity(a_Entity); + if (!m_HasSentDC) + { + LOGD("Sending a DC: \"%s\"", a_Reason.c_str()); + m_Protocol->SendDisconnect(a_Reason); + m_HasSentDC = true; + } } -void cClientHandle::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) +void cClientHandle::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) { - m_Protocol->SendPlayerListItem(a_Player, a_IsOnline); + m_Protocol->SendEntityEquipment(a_Entity, a_SlotNum, a_Item); } -void cClientHandle::SendPlayerPosition(void) +void cClientHandle::SendEntityHeadLook(const cEntity & a_Entity) { - m_Protocol->SendPlayerPosition(); + ASSERT(a_Entity.GetUniqueID() != m_Player->GetUniqueID()); // Must not send for self + + m_Protocol->SendEntityHeadLook(a_Entity); } -void cClientHandle::SendEntRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) +void cClientHandle::SendEntityLook(const cEntity & a_Entity) { ASSERT(a_Entity.GetUniqueID() != m_Player->GetUniqueID()); // Must not send for self - m_Protocol->SendEntRelMoveLook(a_Entity, a_RelX, a_RelY, a_RelZ); + m_Protocol->SendEntityLook(a_Entity); } -void cClientHandle::SendEntRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) +void cClientHandle::SendEntityMetadata(const cEntity & a_Entity) { - ASSERT(a_Entity.GetUniqueID() != m_Player->GetUniqueID()); // Must not send for self - - m_Protocol->SendEntRelMove(a_Entity, a_RelX, a_RelY, a_RelZ); + m_Protocol->SendEntityMetadata(a_Entity); } -void cClientHandle::SendEntLook(const cEntity & a_Entity) +void cClientHandle::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) { ASSERT(a_Entity.GetUniqueID() != m_Player->GetUniqueID()); // Must not send for self - m_Protocol->SendEntLook(a_Entity); + m_Protocol->SendEntityRelMove(a_Entity, a_RelX, a_RelY, a_RelZ); } -void cClientHandle::SendEntVelocity(const cEntity & a_Entity) +void cClientHandle::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) { ASSERT(a_Entity.GetUniqueID() != m_Player->GetUniqueID()); // Must not send for self - m_Protocol->SendEntVelocity(a_Entity); + m_Protocol->SendEntityRelMoveLook(a_Entity, a_RelX, a_RelY, a_RelZ); +} + + + + + +void cClientHandle::SendEntityStatus(const cEntity & a_Entity, char a_Status) +{ + m_Protocol->SendEntityStatus(a_Entity, a_Status); } -void cClientHandle::SendEntHeadLook(const cEntity & a_Entity) +void cClientHandle::SendEntityVelocity(const cEntity & a_Entity) { ASSERT(a_Entity.GetUniqueID() != m_Player->GetUniqueID()); // Must not send for self - m_Protocol->SendEntHeadLook(a_Entity); + m_Protocol->SendEntityVelocity(a_Entity); } -void cClientHandle::SendAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle) +void cClientHandle::SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) { - m_Protocol->SendAttachEntity(a_Entity, a_Vehicle); + if ( + (m_NumExplosionsPerTick[m_CurrentExplosionTick] > MAX_EXPLOSIONS_PER_TICK) || // Too many explosions in this tick + (m_RunningSumExplosions > MAX_RUNNING_SUM_EXPLOSIONS) // Too many explosions in the recent history + ) + { + LOGD("Dropped %u explosions", a_BlocksAffected.size()); + return; + } + + // Update the statistics: + m_NumExplosionsPerTick[m_CurrentExplosionTick] += a_BlocksAffected.size(); + m_RunningSumExplosions += a_BlocksAffected.size(); + + m_Protocol->SendExplosion(a_BlockX, a_BlockY, a_BlockZ, a_Radius, a_BlocksAffected, a_PlayerMotion); } -void cClientHandle::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) +void cClientHandle::SendGameMode(eGameMode a_GameMode) { - m_Protocol->SendBlockAction(a_BlockX, a_BlockY, a_BlockZ, a_Byte1, a_Byte2, a_BlockType); + m_Protocol->SendGameMode(a_GameMode); } @@ -1542,90 +1591,77 @@ void cClientHandle::SendHealth(void) -void cClientHandle::SendRespawn(void) +void cClientHandle::SendInventoryProgress(char a_WindowID, short a_ProgressBar, short a_Value) { - m_Protocol->SendRespawn(); + m_Protocol->SendInventoryProgress(a_WindowID, a_ProgressBar, a_Value); } -void cClientHandle::SendGameMode(eGameMode a_GameMode) +void cClientHandle::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item) { - m_Protocol->SendGameMode(a_GameMode); + m_Protocol->SendInventorySlot(a_WindowID, a_SlotNum, a_Item); } -void cClientHandle::SendDestroyEntity(const cEntity & a_Entity) +void cClientHandle::SendPickupSpawn(const cPickup & a_Pickup) { - m_Protocol->SendDestroyEntity(a_Entity); + m_Protocol->SendPickupSpawn(a_Pickup); } -void cClientHandle::SendPlayerMoveLook(void) +void cClientHandle::SendPlayerAnimation(const cPlayer & a_Player, char a_Animation) { - /* - LOGD("Sending PlayerMoveLook: {%0.2f, %0.2f, %0.2f}, stance %0.2f, OnGround: %d", - m_Player->GetPosX(), m_Player->GetPosY(), m_Player->GetPosZ(), m_Player->GetStance(), m_Player->IsOnGround() ? 1 : 0 - ); - */ - m_Protocol->SendPlayerMoveLook(); + m_Protocol->SendPlayerAnimation(a_Player, a_Animation); } -void cClientHandle::SendEntityStatus(const cEntity & a_Entity, char a_Status) +void cClientHandle::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) { - m_Protocol->SendEntityStatus(a_Entity, a_Status); + m_Protocol->SendPlayerListItem(a_Player, a_IsOnline); } -void cClientHandle::SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) +void cClientHandle::SendPlayerMaxSpeed(void) { - if ( - (m_NumExplosionsPerTick[m_CurrentExplosionTick] > MAX_EXPLOSIONS_PER_TICK) || // Too many explosions in this tick - (m_RunningSumExplosions > MAX_RUNNING_SUM_EXPLOSIONS) // Too many explosions in the recent history - ) - { - LOGD("Dropped %u explosions", a_BlocksAffected.size()); - return; - } - - // Update the statistics: - m_NumExplosionsPerTick[m_CurrentExplosionTick] += a_BlocksAffected.size(); - m_RunningSumExplosions += a_BlocksAffected.size(); - - m_Protocol->SendExplosion(a_BlockX, a_BlockY, a_BlockZ, a_Radius, a_BlocksAffected, a_PlayerMotion); + m_Protocol->SendPlayerMaxSpeed(); } -void cClientHandle::SendMetadata(const cEntity & a_Entity) +void cClientHandle::SendPlayerMoveLook(void) { - m_Protocol->SendMetadata(a_Entity); + /* + LOGD("Sending PlayerMoveLook: {%0.2f, %0.2f, %0.2f}, stance %0.2f, OnGround: %d", + m_Player->GetPosX(), m_Player->GetPosY(), m_Player->GetPosZ(), m_Player->GetStance(), m_Player->IsOnGround() ? 1 : 0 + ); + */ + m_Protocol->SendPlayerMoveLook(); } -void cClientHandle::SendInventoryProgress(char a_WindowID, short a_ProgressBar, short a_Value) +void cClientHandle::SendPlayerPosition(void) { - m_Protocol->SendInventoryProgress(a_WindowID, a_ProgressBar, a_Value); + m_Protocol->SendPlayerPosition(); } @@ -1651,87 +1687,81 @@ void cClientHandle::SendPlayerSpawn(const cPlayer & a_Player) -void cClientHandle::SendPickupSpawn(const cPickup & a_Pickup) +void cClientHandle::SendRespawn(void) { - m_Protocol->SendPickupSpawn(a_Pickup); + m_Protocol->SendRespawn(); } -void cClientHandle::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock) +void cClientHandle::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) { - m_Protocol->SendSpawnFallingBlock(a_FallingBlock); + m_Protocol->SendSoundEffect(a_SoundName, a_SrcX, a_SrcY, a_SrcZ, a_Volume, a_Pitch); } -void cClientHandle::SendSpawnMob(const cMonster & a_Mob) +void cClientHandle::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) { - m_Protocol->SendSpawnMob(a_Mob); + m_Protocol->SendSoundParticleEffect(a_EffectID, a_SrcX, a_SrcY, a_SrcZ, a_Data); } -void cClientHandle::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 -) +void cClientHandle::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock) { - m_Protocol->SendUpdateSign( - a_BlockX, a_BlockY, a_BlockZ, - a_Line1, a_Line2, a_Line3, a_Line4 - ); + m_Protocol->SendSpawnFallingBlock(a_FallingBlock); } -void cClientHandle::SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player) +void cClientHandle::SendSpawnMob(const cMonster & a_Mob) { - m_Protocol->SendCollectPickup(a_Pickup, a_Player); + m_Protocol->SendSpawnMob(a_Mob); } -void cClientHandle::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) +void cClientHandle::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) { - m_Protocol->SendBlockChange(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); + m_Protocol->SendSpawnObject(a_Entity, a_ObjectType, a_ObjectData, a_Yaw, a_Pitch); } -void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) +void cClientHandle::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType) { - m_Protocol->SendBlockChanges(a_ChunkX, a_ChunkZ, a_Changes); + m_Protocol->SendSpawnVehicle(a_Vehicle, a_VehicleType); } -void cClientHandle::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) +void cClientHandle::SendTeleportEntity(const cEntity & a_Entity) { - m_Protocol->SendUnloadChunk(a_ChunkX, a_ChunkZ); + m_Protocol->SendTeleportEntity(a_Entity); } -void cClientHandle::SendWeather(eWeather a_Weather) +void cClientHandle::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) { - m_Protocol->SendWeather(a_Weather); + m_Protocol->SendThunderbolt(a_BlockX, a_BlockY, a_BlockZ); } @@ -1747,98 +1777,77 @@ void cClientHandle::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay) -void cClientHandle::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) +void cClientHandle::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) { - m_Protocol->SendThunderbolt(a_BlockX, a_BlockY, a_BlockZ); + m_Protocol->SendUnloadChunk(a_ChunkX, a_ChunkZ); } -void cClientHandle::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) +void cClientHandle::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 +) { - m_Protocol->SendSoundEffect(a_SoundName, a_SrcX, a_SrcY, a_SrcZ, a_Volume, a_Pitch); + m_Protocol->SendUpdateSign( + a_BlockX, a_BlockY, a_BlockZ, + a_Line1, a_Line2, a_Line3, a_Line4 + ); } -void cClientHandle::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) +void cClientHandle::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) { - m_Protocol->SendSoundParticleEffect(a_EffectID, a_SrcX, a_SrcY, a_SrcZ, a_Data); + m_Protocol->SendUseBed(a_Entity, a_BlockX, a_BlockY, a_BlockZ); } - -void cClientHandle::SendBlockBreakAnim(int a_entityID, int a_blockX, int a_blockY, int a_blockZ, char a_stage) +void cClientHandle::SendWeather(eWeather a_Weather) { - m_Protocol->SendBlockBreakAnim(a_entityID, a_blockX, a_blockY, a_blockZ, a_stage); + m_Protocol->SendWeather(a_Weather); } -void cClientHandle::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) +void cClientHandle::SendWindowClose(const cWindow & a_Window) { - m_Protocol->SendUseBed(a_Entity, a_BlockX, a_BlockY, a_BlockZ); + m_Protocol->SendWindowClose(a_Window); } -void cClientHandle::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) + +void cClientHandle::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) { - m_Protocol->SendSpawnObject(a_Entity, a_ObjectType, a_ObjectData, a_Yaw, a_Pitch); + m_Protocol->SendWindowOpen(a_WindowID, a_WindowType, a_WindowTitle, a_NumSlots); } -void cClientHandle::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType) +void cClientHandle::SendWholeInventory(const cInventory & a_Inventory) { - m_Protocol->SendSpawnVehicle(a_Vehicle, a_VehicleType); + m_Protocol->SendWholeInventory(a_Inventory); } -void cClientHandle::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) +void cClientHandle::SendWholeInventory(const cWindow & a_Window) { - // Check chunks being sent, erase them from m_ChunksToSend: - bool Found = false; - { - cCSLock Lock(m_CSChunkLists); - for (cChunkCoordsList::iterator itr = m_ChunksToSend.begin(); itr != m_ChunksToSend.end(); ++itr) - { - if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ)) - { - m_ChunksToSend.erase(itr); - - // Make the tick thread check if all the needed chunks have been downloaded - // -- needed to offload this from here due to a deadlock possibility - m_ShouldCheckDownloaded = true; - - Found = true; - break; - } - } // for itr - m_ChunksToSend[] - } - if (!Found) - { - // This just sometimes happens. If you have a reliably replicatable situation for this, go ahead and fix it - // It's not a big issue anyway, just means that some chunks may be compressed several times - // LOGD("Refusing to send chunk [%d, %d] to client \"%s\" at [%d, %d].", ChunkX, ChunkZ, m_Username.c_str(), m_Player->GetChunkX(), m_Player->GetChunkZ()); - return; - } - - m_Protocol->SendChunkData(a_ChunkX, a_ChunkZ, a_Serializer); + m_Protocol->SendWholeInventory(a_Window); } |