2012-10-31 16:18:01 -04:00
|
|
|
|
2012-12-24 17:09:01 -05:00
|
|
|
// Protocol14x.cpp
|
|
|
|
|
|
|
|
/*
|
|
|
|
Implements the 1.4.x protocol classes representing these protocols:
|
|
|
|
- cProtocol142:
|
|
|
|
- release 1.4.2 protocol (#47)
|
|
|
|
- release 1.4.4 protocol (#49) - the same protocol class is used, because the only difference is in a packet that MCServer doesn't implement yet (ITEM_DATA)
|
|
|
|
- release 1.4.5 protocol (same as 1.4.4)
|
|
|
|
- cProtocol146:
|
|
|
|
- release 1.4.6 protocol (#51)
|
|
|
|
*/
|
2012-10-31 16:18:01 -04:00
|
|
|
|
|
|
|
#include "Globals.h"
|
2012-12-24 17:09:01 -05:00
|
|
|
#include "Protocol14x.h"
|
2012-10-31 16:18:01 -04:00
|
|
|
#include "../Root.h"
|
|
|
|
#include "../Server.h"
|
|
|
|
#include "../ClientHandle.h"
|
|
|
|
#include "../../CryptoPP/randpool.h"
|
|
|
|
#include "../Item.h"
|
|
|
|
#include "ChunkDataSerializer.h"
|
|
|
|
#include "../Player.h"
|
|
|
|
#include "../Mobs/Monster.h"
|
|
|
|
#include "../UI/Window.h"
|
|
|
|
#include "../Pickup.h"
|
2012-12-26 04:12:00 -05:00
|
|
|
#include "../FallingBlock.h"
|
2012-10-31 16:18:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define HANDLE_PACKET_READ(Proc, Type, Var) \
|
|
|
|
Type Var; \
|
|
|
|
{ \
|
|
|
|
if (!m_ReceivedData.Proc(Var)) \
|
|
|
|
{ \
|
2012-11-20 15:44:47 -05:00
|
|
|
m_ReceivedData.CheckValid(); \
|
2012-10-31 16:18:01 -04:00
|
|
|
return PARSE_INCOMPLETE; \
|
|
|
|
} \
|
2012-11-20 15:44:47 -05:00
|
|
|
m_ReceivedData.CheckValid(); \
|
2012-10-31 16:18:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PACKET_UPDATE_TIME = 0x04,
|
2012-10-31 16:47:09 -04:00
|
|
|
PACKET_PICKUP_SPAWN = 0x15,
|
2012-12-24 17:09:01 -05:00
|
|
|
PACKET_SPAWN_OBJECT = 0x17,
|
|
|
|
PACKET_ENTITY_METADATA = 0x28,
|
2012-10-31 16:18:01 -04:00
|
|
|
PACKET_SOUND_PARTICLE_EFFECT = 0x3d
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// cProtocol142:
|
|
|
|
|
|
|
|
cProtocol142::cProtocol142(cClientHandle * a_Client) :
|
|
|
|
super(a_Client)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-11-10 09:01:07 -05:00
|
|
|
int cProtocol142::ParseLocaleViewDistance(void)
|
2012-10-31 16:18:01 -04:00
|
|
|
{
|
2012-11-10 09:01:07 -05:00
|
|
|
HANDLE_PACKET_READ(ReadBEUTF16String16, AString, Locale);
|
|
|
|
HANDLE_PACKET_READ(ReadChar, char, ViewDistance);
|
|
|
|
HANDLE_PACKET_READ(ReadChar, char, ChatFlags);
|
|
|
|
HANDLE_PACKET_READ(ReadChar, char, ClientDifficulty);
|
|
|
|
HANDLE_PACKET_READ(ReadChar, char, ShouldShowCape); // <-- new in 1.4.2
|
|
|
|
// TODO: m_Client->HandleLocale(Locale);
|
|
|
|
// TODO: m_Client->HandleViewDistance(ViewDistance);
|
|
|
|
// TODO: m_Client->HandleChatFlags(ChatFlags);
|
|
|
|
// Ignoring client difficulty
|
2012-10-31 16:18:01 -04:00
|
|
|
return PARSE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-31 16:47:09 -04:00
|
|
|
void cProtocol142::SendPickupSpawn(const cPickup & a_Pickup)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSPacket);
|
|
|
|
WriteByte (PACKET_PICKUP_SPAWN);
|
|
|
|
WriteInt (a_Pickup.GetUniqueID());
|
2012-12-27 21:45:20 -05:00
|
|
|
WriteItem (a_Pickup.GetItem());
|
2012-10-31 16:47:09 -04:00
|
|
|
WriteVectorI((Vector3i)(a_Pickup.GetPosition() * 32));
|
|
|
|
WriteByte ((char)(a_Pickup.GetSpeed().x * 8));
|
|
|
|
WriteByte ((char)(a_Pickup.GetSpeed().y * 8));
|
|
|
|
WriteByte ((char)(a_Pickup.GetSpeed().z * 8));
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-31 16:18:01 -04:00
|
|
|
void cProtocol142::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSPacket);
|
|
|
|
WriteByte(PACKET_SOUND_PARTICLE_EFFECT);
|
|
|
|
WriteInt (a_EffectID);
|
|
|
|
WriteInt (a_SrcX / 8);
|
|
|
|
WriteByte(a_SrcY / 8);
|
|
|
|
WriteInt (a_SrcZ / 8);
|
|
|
|
WriteInt (a_Data);
|
|
|
|
WriteBool(0);
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-11-01 17:38:20 -04:00
|
|
|
void cProtocol142::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay)
|
2012-10-31 16:18:01 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSPacket);
|
|
|
|
WriteByte (PACKET_UPDATE_TIME);
|
2012-11-01 17:38:20 -04:00
|
|
|
WriteInt64(a_WorldAge);
|
|
|
|
WriteInt64(a_TimeOfDay);
|
2012-10-31 16:18:01 -04:00
|
|
|
Flush();
|
2012-12-24 17:09:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// cProtocol146:
|
|
|
|
|
|
|
|
cProtocol146::cProtocol146(cClientHandle * a_Client) :
|
|
|
|
super(a_Client)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cProtocol146::SendPickupSpawn(const cPickup & a_Pickup)
|
|
|
|
{
|
2012-12-27 21:45:20 -05:00
|
|
|
ASSERT(!a_Pickup.GetItem().IsEmpty());
|
2012-12-24 17:09:01 -05:00
|
|
|
|
|
|
|
cCSLock Lock(m_CSPacket);
|
|
|
|
|
|
|
|
// Send a SPAWN_OBJECT packet for the base entity:
|
|
|
|
WriteByte(PACKET_SPAWN_OBJECT);
|
|
|
|
WriteInt (a_Pickup.GetUniqueID());
|
|
|
|
WriteByte(0x02);
|
|
|
|
WriteInt ((int)(a_Pickup.GetPosX() * 32));
|
|
|
|
WriteInt ((int)(a_Pickup.GetPosY() * 32));
|
|
|
|
WriteInt ((int)(a_Pickup.GetPosZ() * 32));
|
|
|
|
WriteInt (1);
|
|
|
|
WriteShort((short)(a_Pickup.GetSpeed().x * 32));
|
|
|
|
WriteShort((short)(a_Pickup.GetSpeed().y * 32));
|
|
|
|
WriteShort((short)(a_Pickup.GetSpeed().z * 32));
|
|
|
|
WriteByte(0);
|
|
|
|
WriteByte(0);
|
|
|
|
|
|
|
|
// Send a ENTITY_METADATA packet with the slot info:
|
|
|
|
WriteByte(PACKET_ENTITY_METADATA);
|
|
|
|
WriteInt(a_Pickup.GetUniqueID());
|
|
|
|
WriteByte(0xaa); // a slot value at index 10
|
2012-12-27 21:45:20 -05:00
|
|
|
WriteItem(a_Pickup.GetItem());
|
2012-12-26 04:12:00 -05:00
|
|
|
WriteByte(0x7f); // End of metadata
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cProtocol146::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock)
|
|
|
|
{
|
2012-12-27 02:15:26 -05:00
|
|
|
// Send a spawn object / vehicle packet
|
2012-12-26 04:12:00 -05:00
|
|
|
cCSLock Lock(m_CSPacket);
|
|
|
|
|
|
|
|
WriteByte(PACKET_SPAWN_OBJECT);
|
|
|
|
WriteInt (a_FallingBlock.GetUniqueID());
|
|
|
|
WriteByte(70);
|
|
|
|
WriteInt ((int)(a_FallingBlock.GetPosX() * 32));
|
|
|
|
WriteInt ((int)(a_FallingBlock.GetPosY() * 32));
|
|
|
|
WriteInt ((int)(a_FallingBlock.GetPosZ() * 32));
|
2012-12-27 02:15:26 -05:00
|
|
|
WriteByte (0); // Pitch
|
2013-04-28 01:08:29 -04:00
|
|
|
WriteByte (0); // Yaw
|
2012-12-27 02:15:26 -05:00
|
|
|
WriteInt (a_FallingBlock.GetBlockType()); // data indicator = blocktype
|
2013-04-28 01:08:29 -04:00
|
|
|
WriteShort((short)(a_FallingBlock.GetSpeedX() * 400));
|
|
|
|
WriteShort((short)(a_FallingBlock.GetSpeedY() * 400));
|
|
|
|
WriteShort((short)(a_FallingBlock.GetSpeedZ() * 400));
|
2012-12-24 17:09:01 -05:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-26 04:12:00 -05:00
|
|
|
|
2013-02-21 16:55:36 -05:00
|
|
|
void cProtocol146::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch)
|
2012-12-26 04:12:00 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSPacket);
|
|
|
|
WriteByte(PACKET_SPAWN_OBJECT);
|
|
|
|
WriteInt (a_Entity.GetUniqueID());
|
|
|
|
WriteByte(a_ObjectType);
|
|
|
|
WriteInt ((int)(a_Entity.GetPosX() * 32));
|
|
|
|
WriteInt ((int)(a_Entity.GetPosY() * 32));
|
|
|
|
WriteInt ((int)(a_Entity.GetPosZ() * 32));
|
2013-04-28 01:08:29 -04:00
|
|
|
WriteByte(a_Pitch);
|
|
|
|
WriteByte(a_Yaw);
|
2012-12-26 04:12:00 -05:00
|
|
|
WriteInt (a_ObjectData);
|
|
|
|
if (a_ObjectData != 0)
|
|
|
|
{
|
2013-04-28 01:08:29 -04:00
|
|
|
WriteShort((short)(a_Entity.GetSpeedX() * 400));
|
|
|
|
WriteShort((short)(a_Entity.GetSpeedY() * 400));
|
|
|
|
WriteShort((short)(a_Entity.GetSpeedZ() * 400));
|
2012-12-26 04:12:00 -05:00
|
|
|
}
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-18 11:48:50 -05:00
|
|
|
void cProtocol146::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSPacket);
|
|
|
|
WriteByte(PACKET_SPAWN_OBJECT);
|
|
|
|
WriteInt (a_Vehicle.GetUniqueID());
|
|
|
|
WriteByte(a_VehicleType);
|
|
|
|
WriteInt ((int)(a_Vehicle.GetPosX() * 32));
|
|
|
|
WriteInt ((int)(a_Vehicle.GetPosY() * 32));
|
|
|
|
WriteInt ((int)(a_Vehicle.GetPosZ() * 32));
|
2013-04-28 01:08:29 -04:00
|
|
|
WriteByte ((BYTE)((a_Vehicle.GetPitch() / 360.f) * 256));
|
|
|
|
WriteByte ((BYTE)((a_Vehicle.GetRotation() / 360.f) * 256));
|
2013-02-18 11:48:50 -05:00
|
|
|
WriteInt (1);
|
2013-04-28 01:08:29 -04:00
|
|
|
WriteShort((short)(a_Vehicle.GetSpeedX() * 400));
|
|
|
|
WriteShort((short)(a_Vehicle.GetSpeedY() * 400));
|
|
|
|
WriteShort((short)(a_Vehicle.GetSpeedZ() * 400));
|
2013-02-18 11:48:50 -05:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|