1
0

Merge pull request #777 from jfhumann/issue317

Issue 317: Split cClientHandle::HandleEntityAction() into seperate functions
This commit is contained in:
Mattes D 2014-03-09 15:13:27 +01:00
commit d3c38c40e4
5 changed files with 62 additions and 32 deletions

View File

@ -1466,7 +1466,7 @@ bool cClientHandle::HandleHandshake(const AString & a_Username)
void cClientHandle::HandleEntityAction(int a_EntityID, char a_ActionID) void cClientHandle::HandleEntityCrouch(int a_EntityID, bool a_IsCrouching)
{ {
if (a_EntityID != m_Player->GetUniqueID()) if (a_EntityID != m_Player->GetUniqueID())
{ {
@ -1474,35 +1474,37 @@ void cClientHandle::HandleEntityAction(int a_EntityID, char a_ActionID)
return; return;
} }
switch (a_ActionID) m_Player->SetCrouch(a_IsCrouching);
{
case 1: // Crouch
{
m_Player->SetCrouch(true);
break;
} }
case 2: // Uncrouch
void cClientHandle::HandleEntityLeaveBed(int a_EntityID)
{ {
m_Player->SetCrouch(false); if (a_EntityID != m_Player->GetUniqueID())
break; {
// We should only receive entity actions from the entity that is performing the action
return;
} }
case 3: // Leave bed
{
m_Player->GetWorld()->BroadcastEntityAnimation(*m_Player, 2); m_Player->GetWorld()->BroadcastEntityAnimation(*m_Player, 2);
break;
} }
case 4: // Start sprinting
void cClientHandle::HandleEntitySprinting(int a_EntityID, bool a_IsSprinting)
{ {
m_Player->SetSprint(true); if (a_EntityID != m_Player->GetUniqueID())
break;
}
case 5: // Stop sprinting
{ {
m_Player->SetSprint(false); // We should only receive entity actions from the entity that is performing the action
SendPlayerMaxSpeed(); return;
break;
}
} }
m_Player->SetSprint(a_IsSprinting);
} }

View File

@ -188,7 +188,9 @@ public:
void HandleChat (const AString & a_Message); void HandleChat (const AString & a_Message);
void HandleCreativeInventory(short a_SlotNum, const cItem & a_HeldItem); void HandleCreativeInventory(short a_SlotNum, const cItem & a_HeldItem);
void HandleDisconnect (const AString & a_Reason); 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; /** Called when the protocol handshake has been received (for protocol versions that support it;
otherwise the first instant when a username is received). otherwise the first instant when a username is received).

View File

@ -1375,7 +1375,16 @@ int cProtocol125::ParseEntityAction(void)
{ {
HANDLE_PACKET_READ(ReadBEInt, int, EntityID); HANDLE_PACKET_READ(ReadBEInt, int, EntityID);
HANDLE_PACKET_READ(ReadChar, char, ActionID); HANDLE_PACKET_READ(ReadChar, char, ActionID);
m_Client->HandleEntityAction(EntityID, ActionID);
switch (ActionID)
{
case 1: m_Client->HandleEntityCrouch(EntityID, true); break; // Crouch
case 2: m_Client->HandleEntityCrouch(EntityID, false); break; // Uncrouch
case 3: m_Client->HandleEntityLeaveBed(EntityID); break; // Leave Bed
case 4: m_Client->HandleEntitySprinting(EntityID, true); break; // Start sprinting
case 5: m_Client->HandleEntitySprinting(EntityID, false); break; // Stop sprinting
}
return PARSE_OK; return PARSE_OK;
} }

View File

@ -184,7 +184,16 @@ int cProtocol161::ParseEntityAction(void)
HANDLE_PACKET_READ(ReadBEInt, int, EntityID); HANDLE_PACKET_READ(ReadBEInt, int, EntityID);
HANDLE_PACKET_READ(ReadChar, char, ActionID); HANDLE_PACKET_READ(ReadChar, char, ActionID);
HANDLE_PACKET_READ(ReadBEInt, int, UnknownHorseVal); HANDLE_PACKET_READ(ReadBEInt, int, UnknownHorseVal);
m_Client->HandleEntityAction(EntityID, ActionID);
switch (ActionID)
{
case 1: m_Client->HandleEntityCrouch(EntityID, true); break; // Crouch
case 2: m_Client->HandleEntityCrouch(EntityID, false); break; // Uncrouch
case 3: m_Client->HandleEntityLeaveBed(EntityID); break; // Leave Bed
case 4: m_Client->HandleEntitySprinting(EntityID, true); break; // Start sprinting
case 5: m_Client->HandleEntitySprinting(EntityID, false); break; // Stop sprinting
}
return PARSE_OK; return PARSE_OK;
} }

View File

@ -1732,7 +1732,15 @@ void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer)
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, PlayerID); HANDLE_READ(a_ByteBuffer, ReadBEInt, int, PlayerID);
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Action); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Action);
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, JumpBoost); HANDLE_READ(a_ByteBuffer, ReadBEInt, int, JumpBoost);
m_Client->HandleEntityAction(PlayerID, Action);
switch (Action)
{
case 1: m_Client->HandleEntityCrouch(PlayerID, true); break; // Crouch
case 2: m_Client->HandleEntityCrouch(PlayerID, false); break; // Uncrouch
case 3: m_Client->HandleEntityLeaveBed(PlayerID); break; // Leave Bed
case 4: m_Client->HandleEntitySprinting(PlayerID, true); break; // Start sprinting
case 5: m_Client->HandleEntitySprinting(PlayerID, false); break; // Stop sprinting
}
} }