summaryrefslogtreecommitdiffstats
path: root/src/Protocol/Protocol18x.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-03-22 19:46:08 +0100
committerMattes D <github@xoft.cz>2015-03-22 19:46:08 +0100
commitc6268483934eb2bfdcb76ae621a0be40f76209f5 (patch)
tree9cf896200c8eaf94ca0f6c90bee3bf9c37dbce5b /src/Protocol/Protocol18x.cpp
parentProtoProxy: Fixed connection and logging. (diff)
downloadcuberite-c6268483934eb2bfdcb76ae621a0be40f76209f5.tar
cuberite-c6268483934eb2bfdcb76ae621a0be40f76209f5.tar.gz
cuberite-c6268483934eb2bfdcb76ae621a0be40f76209f5.tar.bz2
cuberite-c6268483934eb2bfdcb76ae621a0be40f76209f5.tar.lz
cuberite-c6268483934eb2bfdcb76ae621a0be40f76209f5.tar.xz
cuberite-c6268483934eb2bfdcb76ae621a0be40f76209f5.tar.zst
cuberite-c6268483934eb2bfdcb76ae621a0be40f76209f5.zip
Diffstat (limited to '')
-rw-r--r--src/Protocol/Protocol18x.cpp532
1 files changed, 257 insertions, 275 deletions
diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp
index e35ec249b..c48ab14ad 100644
--- a/src/Protocol/Protocol18x.cpp
+++ b/src/Protocol/Protocol18x.cpp
@@ -13,6 +13,7 @@ Implements the 1.8.x protocol classes:
#include "Protocol18x.h"
#include "ChunkDataSerializer.h"
#include "PolarSSL++/Sha1Checksum.h"
+#include "Packetizer.h"
#include "../ClientHandle.h"
#include "../Root.h"
@@ -105,8 +106,6 @@ cProtocol180::cProtocol180(cClientHandle * a_Client, const AString & a_ServerAdd
m_ServerPort(a_ServerPort),
m_State(a_State),
m_ReceivedData(32 KiB),
- m_OutPacketBuffer(64 KiB),
- m_OutPacketLenBuffer(20), // 20 bytes is more than enough for one VarInt
m_IsEncrypted(false),
m_LastSentDimension(dimNotSet)
{
@@ -365,7 +364,7 @@ void cProtocol180::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum
cPacketizer Pkt(*this, 0x04); // Entity Equipment packet
Pkt.WriteVarInt(a_Entity.GetUniqueID());
Pkt.WriteShort(a_SlotNum);
- Pkt.WriteItem(a_Item);
+ WriteItem(Pkt, a_Item);
}
@@ -406,7 +405,7 @@ void cProtocol180::SendEntityMetadata(const cEntity & a_Entity)
cPacketizer Pkt(*this, 0x1c); // Entity Metadata packet
Pkt.WriteVarInt(a_Entity.GetUniqueID());
- Pkt.WriteEntityMetadata(a_Entity);
+ WriteEntityMetadata(Pkt, a_Entity);
Pkt.WriteByte(0x7f); // The termination byte
}
@@ -420,7 +419,7 @@ void cProtocol180::SendEntityProperties(const cEntity & a_Entity)
cPacketizer Pkt(*this, 0x20); // Entity Properties packet
Pkt.WriteVarInt(a_Entity.GetUniqueID());
- Pkt.WriteEntityProperties(a_Entity);
+ WriteEntityProperties(Pkt, a_Entity);
}
@@ -550,7 +549,7 @@ void cProtocol180::SendInventorySlot(char a_WindowID, short a_SlotNum, const cIt
cPacketizer Pkt(*this, 0x2f); // Set Slot packet
Pkt.WriteChar(a_WindowID);
Pkt.WriteShort(a_SlotNum);
- Pkt.WriteItem(a_Item);
+ WriteItem(Pkt, a_Item);
}
@@ -730,7 +729,7 @@ void cProtocol180::SendPickupSpawn(const cPickup & a_Pickup)
cPacketizer Pkt(*this, 0x1c); // Entity Metadata packet
Pkt.WriteVarInt(a_Pickup.GetUniqueID());
Pkt.WriteByte((0x05 << 5) | 10); // Slot type + index 10
- Pkt.WriteItem(a_Pickup.GetItem());
+ WriteItem(Pkt, a_Pickup.GetItem());
Pkt.WriteByte(0x7f); // End of metadata
}
}
@@ -1194,7 +1193,7 @@ void cProtocol180::SendSpawnMob(const cMonster & a_Mob)
Pkt.WriteShort((short)(a_Mob.GetSpeedX() * 400));
Pkt.WriteShort((short)(a_Mob.GetSpeedY() * 400));
Pkt.WriteShort((short)(a_Mob.GetSpeedZ() * 400));
- Pkt.WriteEntityMetadata(a_Mob);
+ WriteEntityMetadata(Pkt, a_Mob);
Pkt.WriteByte(0x7f); // Metadata terminator
}
@@ -1383,7 +1382,7 @@ void cProtocol180::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity)
}
Pkt.WriteByte(Action);
- Pkt.WriteBlockEntity(a_BlockEntity);
+ WriteBlockEntity(Pkt, a_BlockEntity);
}
@@ -1452,7 +1451,7 @@ void cProtocol180::SendWholeInventory(const cWindow & a_Window)
a_Window.GetSlots(*(m_Client->GetPlayer()), Slots);
for (cItems::const_iterator itr = Slots.begin(), end = Slots.end(); itr != end; ++itr)
{
- Pkt.WriteItem(*itr);
+ WriteItem(Pkt, *itr);
} // for itr - Slots[]
}
@@ -2782,56 +2781,58 @@ eBlockFace cProtocol180::FaceIntToBlockFace(Int8 a_BlockFace)
////////////////////////////////////////////////////////////////////////////////
// cProtocol180::cPacketizer:
-cProtocol180::cPacketizer::~cPacketizer()
+void cProtocol180::SendPacket(cPacketizer & a_Pkt)
{
- UInt32 PacketLen = (UInt32)m_Out.GetUsedSpace();
+ UInt32 PacketLen = static_cast<UInt32>(m_OutPacketBuffer.GetUsedSpace());
AString PacketData, CompressedPacket;
- m_Out.ReadAll(PacketData);
- m_Out.CommitRead();
+ m_OutPacketBuffer.ReadAll(PacketData);
+ m_OutPacketBuffer.CommitRead();
- if ((m_Protocol.m_State == 3) && (PacketLen >= 256))
+ if ((m_State == 3) && (PacketLen >= 256))
{
+ // Compress the packet payload:
if (!cProtocol180::CompressPacket(PacketData, CompressedPacket))
{
return;
}
}
- else if (m_Protocol.m_State == 3)
+ else if (m_State == 3)
{
- m_Protocol.m_OutPacketLenBuffer.WriteVarInt(PacketLen + 1);
- m_Protocol.m_OutPacketLenBuffer.WriteVarInt(0);
-
+ // The packet is not compressed, indicate this in the packet header:
+ m_OutPacketLenBuffer.WriteVarInt(PacketLen + 1);
+ m_OutPacketLenBuffer.WriteVarInt(0);
AString LengthData;
- m_Protocol.m_OutPacketLenBuffer.ReadAll(LengthData);
- m_Protocol.SendData(LengthData.data(), LengthData.size());
+ m_OutPacketLenBuffer.ReadAll(LengthData);
+ SendData(LengthData.data(), LengthData.size());
}
else
{
- m_Protocol.m_OutPacketLenBuffer.WriteVarInt(PacketLen);
-
+ // Compression doesn't apply to this state, send raw data:
+ m_OutPacketLenBuffer.WriteVarInt(PacketLen);
AString LengthData;
- m_Protocol.m_OutPacketLenBuffer.ReadAll(LengthData);
- m_Protocol.SendData(LengthData.data(), LengthData.size());
+ m_OutPacketLenBuffer.ReadAll(LengthData);
+ SendData(LengthData.data(), LengthData.size());
}
+ // Send the packet's payload, either direct or compressed:
if (CompressedPacket.empty())
{
- m_Protocol.m_OutPacketLenBuffer.CommitRead();
- m_Protocol.SendData(PacketData.data(), PacketData.size());
+ m_OutPacketLenBuffer.CommitRead();
+ SendData(PacketData.data(), PacketData.size());
}
else
{
- m_Protocol.SendData(CompressedPacket.data(), CompressedPacket.size());
+ SendData(CompressedPacket.data(), CompressedPacket.size());
}
// Log the comm into logfile:
- if (g_ShouldLogCommOut && m_Protocol.m_CommLogFile.IsOpen())
+ if (g_ShouldLogCommOut && m_CommLogFile.IsOpen())
{
AString Hex;
ASSERT(PacketData.size() > 0);
- CreateHexDump(Hex, PacketData.data() + 1, PacketData.size() - 1, 16);
- m_Protocol.m_CommLogFile.Printf("Outgoing packet: type %d (0x%x), length %u (0x%x), state %d. Payload:\n%s\n",
- PacketData[0], PacketData[0], PacketLen, PacketLen, m_Protocol.m_State, Hex.c_str()
+ CreateHexDump(Hex, PacketData.data(), PacketData.size(), 16);
+ m_CommLogFile.Printf("Outgoing packet: type %d (0x%x), length %u (0x%x), state %d. Payload (incl. type):\n%s\n",
+ a_Pkt.GetPacketType(), a_Pkt.GetPacketType(), PacketLen, PacketLen, m_State, Hex.c_str()
);
}
}
@@ -2840,30 +2841,7 @@ cProtocol180::cPacketizer::~cPacketizer()
-void cProtocol180::cPacketizer::WriteUUID(const AString & a_UUID)
-{
- if (a_UUID.length() != 32)
- {
- LOGWARNING("Attempt to send a bad uuid (length isn't 32): %s", a_UUID.c_str());
- ASSERT(!"Wrong uuid length!");
- return;
- }
- AString UUID_1 = a_UUID.substr(0, 16);
- AString UUID_2 = a_UUID.substr(16);
-
- Int64 Value_1, Value_2;
- sscanf(UUID_1.c_str(), "%llx", &Value_1);
- sscanf(UUID_2.c_str(), "%llx", &Value_2);
-
- WriteInt64(Value_1);
- WriteInt64(Value_2);
-}
-
-
-
-
-
-void cProtocol180::cPacketizer::WriteItem(const cItem & a_Item)
+void cProtocol180::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item)
{
short ItemType = a_Item.m_ItemType;
ASSERT(ItemType >= -1); // Check validity of packets in debug runtime
@@ -2875,17 +2853,17 @@ void cProtocol180::cPacketizer::WriteItem(const cItem & a_Item)
if (a_Item.IsEmpty())
{
- WriteShort(-1);
+ a_Pkt.WriteShort(-1);
return;
}
- WriteShort(ItemType);
- WriteByte (a_Item.m_ItemCount);
- WriteShort(a_Item.m_ItemDamage);
+ a_Pkt.WriteShort(ItemType);
+ a_Pkt.WriteByte (a_Item.m_ItemCount);
+ a_Pkt.WriteShort(a_Item.m_ItemDamage);
if (a_Item.m_Enchantments.IsEmpty() && a_Item.IsBothNameAndLoreEmpty() && (a_Item.m_ItemType != E_ITEM_FIREWORK_ROCKET) && (a_Item.m_ItemType != E_ITEM_FIREWORK_STAR))
{
- WriteChar(0);
+ a_Pkt.WriteChar(0);
return;
}
@@ -2928,24 +2906,24 @@ void cProtocol180::cPacketizer::WriteItem(const cItem & a_Item)
}
if ((a_Item.m_ItemType == E_ITEM_FIREWORK_ROCKET) || (a_Item.m_ItemType == E_ITEM_FIREWORK_STAR))
{
- cFireworkItem::WriteToNBTCompound(a_Item.m_FireworkItem, Writer, (ENUM_ITEM_ID)a_Item.m_ItemType);
+ cFireworkItem::WriteToNBTCompound(a_Item.m_FireworkItem, Writer, static_cast<ENUM_ITEM_ID>(a_Item.m_ItemType));
}
Writer.Finish();
AString Result = Writer.GetResult();
if (Result.size() == 0)
{
- WriteChar(0);
+ a_Pkt.WriteChar(0);
return;
}
- WriteBuf(Result.data(), Result.size());
+ a_Pkt.WriteBuf(Result.data(), Result.size());
}
-void cProtocol180::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEntity)
+void cProtocol180::WriteBlockEntity(cPacketizer & a_Pkt, const cBlockEntity & a_BlockEntity)
{
cFastNBTWriter Writer;
@@ -2953,21 +2931,20 @@ void cProtocol180::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt
{
case E_BLOCK_BEACON:
{
- cBeaconEntity & BeaconEntity = (cBeaconEntity &)a_BlockEntity;
-
- Writer.AddInt("x", BeaconEntity.GetPosX());
- Writer.AddInt("y", BeaconEntity.GetPosY());
- Writer.AddInt("z", BeaconEntity.GetPosZ());
- Writer.AddInt("Primary", BeaconEntity.GetPrimaryEffect());
+ auto & BeaconEntity = reinterpret_cast<const cBeaconEntity &>(a_BlockEntity);
+ Writer.AddInt("x", BeaconEntity.GetPosX());
+ Writer.AddInt("y", BeaconEntity.GetPosY());
+ Writer.AddInt("z", BeaconEntity.GetPosZ());
+ Writer.AddInt("Primary", BeaconEntity.GetPrimaryEffect());
Writer.AddInt("Secondary", BeaconEntity.GetSecondaryEffect());
- Writer.AddInt("Levels", BeaconEntity.GetBeaconLevel());
+ Writer.AddInt("Levels", BeaconEntity.GetBeaconLevel());
Writer.AddString("id", "Beacon"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
break;
}
+
case E_BLOCK_COMMAND_BLOCK:
{
- cCommandBlockEntity & CommandBlockEntity = (cCommandBlockEntity &)a_BlockEntity;
-
+ auto & CommandBlockEntity = reinterpret_cast<const cCommandBlockEntity &>(a_BlockEntity);
Writer.AddByte("TrackOutput", 1); // Neither I nor the MC wiki has any idea about this
Writer.AddInt("SuccessCount", CommandBlockEntity.GetResult());
Writer.AddInt("x", CommandBlockEntity.GetPosX());
@@ -2979,20 +2956,16 @@ void cProtocol180::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt
// MCS doesn't have this, so just leave it @ '@'. (geddit?)
Writer.AddString("CustomName", "@");
Writer.AddString("id", "Control"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
-
if (!CommandBlockEntity.GetLastOutput().empty())
{
- AString Output;
- Printf(Output, "{\"text\":\"%s\"}", CommandBlockEntity.GetLastOutput().c_str());
-
- Writer.AddString("LastOutput", Output.c_str());
+ Writer.AddString("LastOutput", Printf("{\"text\":\"%s\"}", CommandBlockEntity.GetLastOutput().c_str()));
}
break;
}
+
case E_BLOCK_HEAD:
{
- cMobHeadEntity & MobHeadEntity = (cMobHeadEntity &)a_BlockEntity;
-
+ auto & MobHeadEntity = reinterpret_cast<const cMobHeadEntity &>(a_BlockEntity);
Writer.AddInt("x", MobHeadEntity.GetPosX());
Writer.AddInt("y", MobHeadEntity.GetPosY());
Writer.AddInt("z", MobHeadEntity.GetPosZ());
@@ -3002,10 +2975,10 @@ void cProtocol180::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt
Writer.AddString("id", "Skull"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
break;
}
+
case E_BLOCK_FLOWER_POT:
{
- cFlowerPotEntity & FlowerPotEntity = (cFlowerPotEntity &)a_BlockEntity;
-
+ auto & FlowerPotEntity = reinterpret_cast<const cFlowerPotEntity &>(a_BlockEntity);
Writer.AddInt("x", FlowerPotEntity.GetPosX());
Writer.AddInt("y", FlowerPotEntity.GetPosY());
Writer.AddInt("z", FlowerPotEntity.GetPosZ());
@@ -3014,10 +2987,10 @@ void cProtocol180::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt
Writer.AddString("id", "FlowerPot"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
break;
}
+
case E_BLOCK_MOB_SPAWNER:
{
- cMobSpawnerEntity & MobSpawnerEntity = (cMobSpawnerEntity &)a_BlockEntity;
-
+ auto & MobSpawnerEntity = reinterpret_cast<const cMobSpawnerEntity &>(a_BlockEntity);
Writer.AddInt("x", MobSpawnerEntity.GetPosX());
Writer.AddInt("y", MobSpawnerEntity.GetPosY());
Writer.AddInt("z", MobSpawnerEntity.GetPosZ());
@@ -3026,37 +2999,22 @@ void cProtocol180::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt
Writer.AddString("id", "MobSpawner");
break;
}
- default: break;
+
+ default:
+ {
+ break;
+ }
}
Writer.Finish();
- WriteBuf(Writer.GetResult().data(), Writer.GetResult().size());
-}
-
-
-
-
-
-void cProtocol180::cPacketizer::WriteByteAngle(double a_Angle)
-{
- WriteByte((char)(255 * a_Angle / 360));
+ a_Pkt.WriteBuf(Writer.GetResult().data(), Writer.GetResult().size());
}
-void cProtocol180::cPacketizer::WriteFPInt(double a_Value)
-{
- int Value = (int)(a_Value * 32);
- WriteInt(Value);
-}
-
-
-
-
-
-void cProtocol180::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity)
+void cProtocol180::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_Entity)
{
// Common metadata:
Byte Flags = 0;
@@ -3080,21 +3038,21 @@ void cProtocol180::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity)
{
Flags |= 0x20;
}
- WriteByte(0); // Byte(0) + index 0
- WriteByte(Flags);
+ a_Pkt.WriteByte(0); // Byte(0) + index 0
+ a_Pkt.WriteByte(Flags);
switch (a_Entity.GetEntityType())
{
case cEntity::etPlayer: break; // TODO?
case cEntity::etPickup:
{
- WriteByte((5 << 5) | 10); // Slot(5) + index 10
- WriteItem(((const cPickup &)a_Entity).GetItem());
+ a_Pkt.WriteByte((5 << 5) | 10); // Slot(5) + index 10
+ WriteItem(a_Pkt, reinterpret_cast<const cPickup &>(a_Entity).GetItem());
break;
}
case cEntity::etMinecart:
{
- WriteByte(0x51);
+ a_Pkt.WriteByte(0x51);
// The following expression makes Minecarts shake more with less health or higher damage taken
// It gets half the maximum health, and takes it away from the current health minus the half health:
@@ -3103,71 +3061,82 @@ void cProtocol180::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity)
Health: 3 | 3 - (3 - 3) = 3
Health: 1 | 3 - (1 - 3) = 5
*/
- WriteInt((((a_Entity.GetMaxHealth() / 2) - (a_Entity.GetHealth() - (a_Entity.GetMaxHealth() / 2))) * ((const cMinecart &)a_Entity).LastDamage()) * 4);
- WriteByte(0x52);
- WriteInt(1); // Shaking direction, doesn't seem to affect anything
- WriteByte(0x73);
- WriteFloat((float)(((const cMinecart &)a_Entity).LastDamage() + 10)); // Damage taken / shake effect multiplyer
+ auto & Minecart = reinterpret_cast<const cMinecart &>(a_Entity);
+ a_Pkt.WriteInt((((a_Entity.GetMaxHealth() / 2) - (a_Entity.GetHealth() - (a_Entity.GetMaxHealth() / 2))) * Minecart.LastDamage()) * 4);
+ a_Pkt.WriteByte(0x52);
+ a_Pkt.WriteInt(1); // Shaking direction, doesn't seem to affect anything
+ a_Pkt.WriteByte(0x73);
+ a_Pkt.WriteFloat(static_cast<float>(Minecart.LastDamage() + 10)); // Damage taken / shake effect multiplyer
- if (((cMinecart &)a_Entity).GetPayload() == cMinecart::mpNone)
+ if (Minecart.GetPayload() == cMinecart::mpNone)
{
- cRideableMinecart & RideableMinecart = ((cRideableMinecart &)a_Entity);
+ auto & RideableMinecart = reinterpret_cast<const cRideableMinecart &>(Minecart);
const cItem & MinecartContent = RideableMinecart.GetContent();
if (!MinecartContent.IsEmpty())
{
- WriteByte(0x54);
+ a_Pkt.WriteByte(0x54);
int Content = MinecartContent.m_ItemType;
Content |= MinecartContent.m_ItemDamage << 8;
- WriteInt(Content);
- WriteByte(0x55);
- WriteInt(RideableMinecart.GetBlockHeight());
- WriteByte(0x56);
- WriteByte(1);
+ a_Pkt.WriteInt(Content);
+ a_Pkt.WriteByte(0x55);
+ a_Pkt.WriteInt(RideableMinecart.GetBlockHeight());
+ a_Pkt.WriteByte(0x56);
+ a_Pkt.WriteByte(1);
}
}
- else if (((cMinecart &)a_Entity).GetPayload() == cMinecart::mpFurnace)
+ else if (Minecart.GetPayload() == cMinecart::mpFurnace)
{
- WriteByte(0x10);
- WriteByte(((const cMinecartWithFurnace &)a_Entity).IsFueled() ? 1 : 0);
+ a_Pkt.WriteByte(0x10);
+ a_Pkt.WriteByte(reinterpret_cast<const cMinecartWithFurnace &>(Minecart).IsFueled() ? 1 : 0);
}
break;
- }
+ } // case etMinecart
+
case cEntity::etProjectile:
{
- cProjectileEntity & Projectile = (cProjectileEntity &)a_Entity;
+ auto & Projectile = reinterpret_cast<const cProjectileEntity &>(a_Entity);
switch (Projectile.GetProjectileKind())
{
case cProjectileEntity::pkArrow:
{
- WriteByte(0x10);
- WriteByte(((const cArrowEntity &)a_Entity).IsCritical() ? 1 : 0);
+ a_Pkt.WriteByte(0x10);
+ a_Pkt.WriteByte(reinterpret_cast<const cArrowEntity &>(Projectile).IsCritical() ? 1 : 0);
break;
}
case cProjectileEntity::pkFirework:
{
- WriteByte(0xA8);
- WriteItem(((const cFireworkEntity &)a_Entity).GetItem());
+ a_Pkt.WriteByte(0xa8);
+ WriteItem(a_Pkt, reinterpret_cast<const cFireworkEntity &>(Projectile).GetItem());
+ break;
+ }
+ default:
+ {
break;
}
- default: break;
}
break;
- }
+ } // case etProjectile
+
case cEntity::etMonster:
{
- WriteMobMetadata((const cMonster &)a_Entity);
+ WriteMobMetadata(a_Pkt, reinterpret_cast<const cMonster &>(a_Entity));
break;
}
+
case cEntity::etItemFrame:
{
- cItemFrame & Frame = (cItemFrame &)a_Entity;
- WriteByte(0xA8);
- WriteItem(Frame.GetItem());
- WriteByte(0x09);
- WriteByte(Frame.GetItemRotation());
+ auto & Frame = reinterpret_cast<const cItemFrame &>(a_Entity);
+ a_Pkt.WriteByte(0xa8);
+ WriteItem(a_Pkt, Frame.GetItem());
+ a_Pkt.WriteByte(0x09);
+ a_Pkt.WriteByte(Frame.GetItemRotation());
+ break;
+ } // case etItemFrame
+
+ default:
+ {
break;
}
- default: break;
}
}
@@ -3175,192 +3144,205 @@ void cProtocol180::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity)
-void cProtocol180::cPacketizer::WriteMobMetadata(const cMonster & a_Mob)
+void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob)
{
switch (a_Mob.GetMobType())
{
- case mtCreeper:
- {
- WriteByte(0x10);
- WriteByte(((const cCreeper &)a_Mob).IsBlowing() ? 1 : -1);
- WriteByte(0x11);
- WriteByte(((const cCreeper &)a_Mob).IsCharged() ? 1 : 0);
- break;
- }
-
case mtBat:
{
- WriteByte(0x10);
- WriteByte(((const cBat &)a_Mob).IsHanging() ? 1 : 0);
+ auto & Bat = reinterpret_cast<const cBat &>(a_Mob);
+ a_Pkt.WriteByte(0x10);
+ a_Pkt.WriteByte(Bat.IsHanging() ? 1 : 0);
break;
- }
+ } // case mtBat
- case mtPig:
- {
- WriteByte(0x10);
- WriteByte(((const cPig &)a_Mob).IsSaddled() ? 1 : 0);
- break;
- }
-
- case mtVillager:
+ case mtCreeper:
{
- WriteByte(0x50);
- WriteInt(((const cVillager &)a_Mob).GetVilType());
+ auto & Creeper = reinterpret_cast<const cCreeper &>(a_Mob);
+ a_Pkt.WriteByte(0x10);
+ a_Pkt.WriteByte(Creeper.IsBlowing() ? 1 : -1);
+ a_Pkt.WriteByte(0x11);
+ a_Pkt.WriteByte(Creeper.IsCharged() ? 1 : 0);
break;
- }
+ } // case mtCreeper
- case mtZombie:
+ case mtEnderman:
{
- WriteByte(0x0c);
- WriteByte(((const cZombie &)a_Mob).IsBaby() ? 1 : 0);
- WriteByte(0x0d);
- WriteByte(((const cZombie &)a_Mob).IsVillagerZombie() ? 1 : 0);
- WriteByte(0x0e);
- WriteByte(((const cZombie &)a_Mob).IsConverting() ? 1 : 0);
+ auto & Enderman = reinterpret_cast<const cEnderman &>(a_Mob);
+ a_Pkt.WriteByte(0x30);
+ a_Pkt.WriteShort(static_cast<Byte>(Enderman.GetCarriedBlock()));
+ a_Pkt.WriteByte(0x11);
+ a_Pkt.WriteByte(static_cast<Byte>(Enderman.GetCarriedMeta()));
+ a_Pkt.WriteByte(0x12);
+ a_Pkt.WriteByte(Enderman.IsScreaming() ? 1 : 0);
break;
- }
+ } // case mtEnderman
case mtGhast:
{
- WriteByte(0x10);
- WriteByte(((const cGhast &)a_Mob).IsCharging());
+ auto & Ghast = reinterpret_cast<const cGhast &>(a_Mob);
+ a_Pkt.WriteByte(0x10);
+ a_Pkt.WriteByte(Ghast.IsCharging());
break;
- }
+ } // case mtGhast
- case mtWolf:
+ case mtHorse:
{
- const cWolf & Wolf = (const cWolf &)a_Mob;
- Byte WolfStatus = 0;
- if (Wolf.IsSitting())
+ auto & Horse = reinterpret_cast<const cHorse &>(a_Mob);
+ int Flags = 0;
+ if (Horse.IsTame())
{
- WolfStatus |= 0x1;
+ Flags |= 0x02;
}
- if (Wolf.IsAngry())
+ if (Horse.IsSaddled())
{
- WolfStatus |= 0x2;
+ Flags |= 0x04;
}
- if (Wolf.IsTame())
+ if (Horse.IsChested())
{
- WolfStatus |= 0x4;
+ Flags |= 0x08;
}
- WriteByte(0x10);
- WriteByte(WolfStatus);
-
- WriteByte(0x72);
- WriteFloat((float)(a_Mob.GetHealth()));
- WriteByte(0x13);
- WriteByte(Wolf.IsBegging() ? 1 : 0);
- WriteByte(0x14);
- WriteByte(Wolf.GetCollarColor());
+ if (Horse.IsBaby())
+ {
+ Flags |= 0x10;
+ }
+ if (Horse.IsEating())
+ {
+ Flags |= 0x20;
+ }
+ if (Horse.IsRearing())
+ {
+ Flags |= 0x40;
+ }
+ if (Horse.IsMthOpen())
+ {
+ Flags |= 0x80;
+ }
+ a_Pkt.WriteByte(0x50); // Int at index 16
+ a_Pkt.WriteInt(Flags);
+ a_Pkt.WriteByte(0x13); // Byte at index 19
+ a_Pkt.WriteByte(Horse.GetHorseType());
+ a_Pkt.WriteByte(0x54); // Int at index 20
+ int Appearance = 0;
+ Appearance = Horse.GetHorseColor();
+ Appearance |= Horse.GetHorseStyle() << 8;
+ a_Pkt.WriteInt(Appearance);
+ a_Pkt.WriteByte(0x56); // Int at index 22
+ a_Pkt.WriteInt(Horse.GetHorseArmour());
break;
- }
+ } // case mtHorse
+
+ case mtMagmaCube:
+ {
+ auto & MagmaCube = reinterpret_cast<const cMagmaCube &>(a_Mob);
+ a_Pkt.WriteByte(0x10);
+ a_Pkt.WriteByte(MagmaCube.GetSize());
+ break;
+ } // case mtMagmaCube
+
+ case mtPig:
+ {
+ auto & Pig = reinterpret_cast<const cPig &>(a_Mob);
+ a_Pkt.WriteByte(0x10);
+ a_Pkt.WriteByte(Pig.IsSaddled() ? 1 : 0);
+ break;
+ } // case mtPig
case mtSheep:
{
- WriteByte(0x10);
+ auto & Sheep = reinterpret_cast<const cSheep &>(a_Mob);
+ a_Pkt.WriteByte(0x10);
Byte SheepMetadata = 0;
- SheepMetadata = ((const cSheep &)a_Mob).GetFurColor();
- if (((const cSheep &)a_Mob).IsSheared())
+ SheepMetadata = Sheep.GetFurColor();
+ if (Sheep.IsSheared())
{
SheepMetadata |= 0x10;
}
- WriteByte(SheepMetadata);
+ a_Pkt.WriteByte(SheepMetadata);
break;
- }
-
- case mtEnderman:
- {
- WriteByte(0x30);
- WriteShort((Byte)(((const cEnderman &)a_Mob).GetCarriedBlock()));
- WriteByte(0x11);
- WriteByte((Byte)(((const cEnderman &)a_Mob).GetCarriedMeta()));
- WriteByte(0x12);
- WriteByte(((const cEnderman &)a_Mob).IsScreaming() ? 1 : 0);
- break;
- }
+ } // case mtSheep
case mtSkeleton:
{
- WriteByte(0x0d);
- WriteByte(((const cSkeleton &)a_Mob).IsWither() ? 1 : 0);
+ auto & Skeleton = reinterpret_cast<const cSkeleton &>(a_Mob);
+ a_Pkt.WriteByte(0x0d);
+ a_Pkt.WriteByte(Skeleton.IsWither() ? 1 : 0);
break;
- }
+ } // case mtSkeleton
- case mtWitch:
+ case mtSlime:
{
- WriteByte(0x15);
- WriteByte(((const cWitch &)a_Mob).IsAngry() ? 1 : 0);
+ auto & Slime = reinterpret_cast<const cSlime &>(a_Mob);
+ a_Pkt.WriteByte(0x10);
+ a_Pkt.WriteByte(Slime.GetSize());
break;
- }
+ } // case mtSlime
- case mtWither:
+ case mtVillager:
{
- WriteByte(0x54); // Int at index 20
- WriteInt(((const cWither &)a_Mob).GetWitherInvulnerableTicks());
- WriteByte(0x66); // Float at index 6
- WriteFloat((float)(a_Mob.GetHealth()));
+ auto & Villager = reinterpret_cast<const cVillager &>(a_Mob);
+ a_Pkt.WriteByte(0x50);
+ a_Pkt.WriteInt(Villager.GetVilType());
break;
- }
+ } // case mtVillager
- case mtSlime:
+ case mtWitch:
{
- WriteByte(0x10);
- WriteByte(((const cSlime &)a_Mob).GetSize());
+ auto & Witch = reinterpret_cast<const cWitch &>(a_Mob);
+ a_Pkt.WriteByte(0x15);
+ a_Pkt.WriteByte(Witch.IsAngry() ? 1 : 0);
break;
- }
-
- case mtMagmaCube:
+ } // case mtWitch
+
+ case mtWither:
{
- WriteByte(0x10);
- WriteByte(((const cMagmaCube &)a_Mob).GetSize());
+ auto & Wither = reinterpret_cast<const cWither &>(a_Mob);
+ a_Pkt.WriteByte(0x54); // Int at index 20
+ a_Pkt.WriteInt(Wither.GetWitherInvulnerableTicks());
+ a_Pkt.WriteByte(0x66); // Float at index 6
+ a_Pkt.WriteFloat(static_cast<float>(a_Mob.GetHealth()));
break;
- }
+ } // case mtWither
- case mtHorse:
+ case mtWolf:
{
- const cHorse & Horse = (const cHorse &)a_Mob;
- int Flags = 0;
- if (Horse.IsTame())
- {
- Flags |= 0x02;
- }
- if (Horse.IsSaddled())
- {
- Flags |= 0x04;
- }
- if (Horse.IsChested())
- {
- Flags |= 0x08;
- }
- if (Horse.IsBaby())
- {
- Flags |= 0x10;
- }
- if (Horse.IsEating())
+ auto & Wolf = reinterpret_cast<const cWolf &>(a_Mob);
+ Byte WolfStatus = 0;
+ if (Wolf.IsSitting())
{
- Flags |= 0x20;
+ WolfStatus |= 0x1;
}
- if (Horse.IsRearing())
+ if (Wolf.IsAngry())
{
- Flags |= 0x40;
+ WolfStatus |= 0x2;
}
- if (Horse.IsMthOpen())
+ if (Wolf.IsTame())
{
- Flags |= 0x80;
+ WolfStatus |= 0x4;
}
- WriteByte(0x50); // Int at index 16
- WriteInt(Flags);
- WriteByte(0x13); // Byte at index 19
- WriteByte(Horse.GetHorseType());
- WriteByte(0x54); // Int at index 20
- int Appearance = 0;
- Appearance = Horse.GetHorseColor();
- Appearance |= Horse.GetHorseStyle() << 8;
- WriteInt(Appearance);
- WriteByte(0x56); // Int at index 22
- WriteInt(Horse.GetHorseArmour());
+ a_Pkt.WriteByte(0x10);
+ a_Pkt.WriteByte(WolfStatus);
+
+ a_Pkt.WriteByte(0x72);
+ a_Pkt.WriteFloat(static_cast<float>(a_Mob.GetHealth()));
+ a_Pkt.WriteByte(0x13);
+ a_Pkt.WriteByte(Wolf.IsBegging() ? 1 : 0);
+ a_Pkt.WriteByte(0x14);
+ a_Pkt.WriteByte(Wolf.GetCollarColor());
break;
- }
+ } // case mtWolf
+
+ case mtZombie:
+ {
+ auto & Zombie = reinterpret_cast<const cZombie &>(a_Mob);
+ a_Pkt.WriteByte(0x0c);
+ a_Pkt.WriteByte(Zombie.IsBaby() ? 1 : 0);
+ a_Pkt.WriteByte(0x0d);
+ a_Pkt.WriteByte(Zombie.IsVillagerZombie() ? 1 : 0);
+ a_Pkt.WriteByte(0x0e);
+ a_Pkt.WriteByte(Zombie.IsConverting() ? 1 : 0);
+ break;
+ } // case mtZombie
} // switch (a_Mob.GetType())
}
@@ -3368,12 +3350,12 @@ void cProtocol180::cPacketizer::WriteMobMetadata(const cMonster & a_Mob)
-void cProtocol180::cPacketizer::WriteEntityProperties(const cEntity & a_Entity)
+void cProtocol180::WriteEntityProperties(cPacketizer & a_Pkt, const cEntity & a_Entity)
{
if (!a_Entity.IsMob())
{
// No properties for anything else than mobs
- WriteInt(0);
+ a_Pkt.WriteInt(0);
return;
}
@@ -3381,7 +3363,7 @@ void cProtocol180::cPacketizer::WriteEntityProperties(const cEntity & a_Entity)
// TODO: Send properties and modifiers based on the mob type
- WriteInt(0); // NumProperties
+ a_Pkt.WriteInt(0); // NumProperties
}