summaryrefslogtreecommitdiffstats
path: root/src/Protocol
diff options
context:
space:
mode:
authorLane Kolbly <lane@rscheme.org>2017-09-02 18:46:57 +0200
committerAlexander Harkness <me@bearbin.net>2017-09-02 18:46:57 +0200
commitaebfbfb8c8d623ded8d409d29983a5e871a475bc (patch)
tree7c2d46d7c4dceb1aa11bdd905739a54f3846a167 /src/Protocol
parentRevert "Replace ItemCallbacks with lambdas (#3948)" (diff)
downloadcuberite-aebfbfb8c8d623ded8d409d29983a5e871a475bc.tar
cuberite-aebfbfb8c8d623ded8d409d29983a5e871a475bc.tar.gz
cuberite-aebfbfb8c8d623ded8d409d29983a5e871a475bc.tar.bz2
cuberite-aebfbfb8c8d623ded8d409d29983a5e871a475bc.tar.lz
cuberite-aebfbfb8c8d623ded8d409d29983a5e871a475bc.tar.xz
cuberite-aebfbfb8c8d623ded8d409d29983a5e871a475bc.tar.zst
cuberite-aebfbfb8c8d623ded8d409d29983a5e871a475bc.zip
Diffstat (limited to 'src/Protocol')
-rw-r--r--src/Protocol/CMakeLists.txt1
-rw-r--r--src/Protocol/PacketID.cpp182
-rw-r--r--src/Protocol/Protocol.h75
-rw-r--r--src/Protocol/ProtocolRecognizer.h3
-rw-r--r--src/Protocol/Protocol_1_10.cpp2
-rw-r--r--src/Protocol/Protocol_1_11.cpp8
-rw-r--r--src/Protocol/Protocol_1_12.cpp1111
-rw-r--r--src/Protocol/Protocol_1_12.h69
-rw-r--r--src/Protocol/Protocol_1_8.h3
-rw-r--r--src/Protocol/Protocol_1_9.cpp261
-rw-r--r--src/Protocol/Protocol_1_9.h10
11 files changed, 366 insertions, 1359 deletions
diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt
index 00ffeb255..f4f266963 100644
--- a/src/Protocol/CMakeLists.txt
+++ b/src/Protocol/CMakeLists.txt
@@ -7,6 +7,7 @@ SET (SRCS
ChunkDataSerializer.cpp
ForgeHandshake.cpp
MojangAPI.cpp
+ PacketID.cpp
Packetizer.cpp
Protocol_1_8.cpp
Protocol_1_9.cpp
diff --git a/src/Protocol/PacketID.cpp b/src/Protocol/PacketID.cpp
new file mode 100644
index 000000000..6bb8379dd
--- /dev/null
+++ b/src/Protocol/PacketID.cpp
@@ -0,0 +1,182 @@
+#include "Globals.h"
+
+#include "Protocol_1_9.h"
+#include "Protocol_1_12.h"
+
+
+
+
+
+UInt32 cProtocol_1_9_0::GetPacketId(eOutgoingPackets a_Packet)
+{
+ switch (a_Packet)
+ {
+ case sendAttachEntity: return 0x40;
+ case sendBlockAction: return 0x0a;
+ case sendBlockBreakAnim: return 0x08;
+ case sendBlockChange: return 0x0b;
+ case sendBlockChanges: return 0x10;
+ case sendCameraSetTo: return 0x36;
+ case sendChatRaw: return 0x0f;
+ case sendCollectEntity: return 0x49;
+ case sendDestroyEntity: return 0x30;
+ case sendDifficulty: return 0x0d;
+ case sendDisconnectDuringGame: return 0x1a;
+ case sendDisconnectDuringLogin: return 0x0;
+ case sendDisplayObjective: return 0x38;
+ case sendEditSign: return 0x2a;
+ case sendEntityAnimation: return 0x06;
+ case sendEntityEffect: return 0x4c;
+ case sendEntityEquipment: return 0x3c;
+ case sendEntityHeadLook: return 0x34;
+ case sendEntityLook: return 0x27;
+ case sendEntityMeta: return 0x39;
+ case sendEntityProperties: return 0x4b;
+ case sendEntityRelMove: return 0x25;
+ case sendEntityRelMoveLook: return 0x26;
+ case sendEntityStatus: return 0x1b;
+ case sendEntityVelocity: return 0x3b;
+ case sendExperience: return 0x3d;
+ case sendExperienceOrb: return 0x01;
+ case sendExplosion: return 0x1c;
+ case sendGameMode: return 0x1e;
+ case sendHealth: return 0x3e;
+ case sendInventorySlot: return 0x16;
+ case sendJoinGame: return 0x23;
+ case sendKeepAlive: return 0x1f;
+ case sendLeashEntity: return 0x3a;
+ case sendMapData: return 0x24;
+ case sendPaintingSpawn: return 0x04;
+ case sendParticleEffect: return 0x22;
+ case sendPlayerAbilities: return 0x2b;
+ case sendPlayerList: return 0x2d;
+ case sendPlayerMaxSpeed: return 0x4b;
+ case sendPlayerMoveLook: return 0x2e;
+ case sendPlayerSpawn: return 0x05;
+ case sendPluginMessage: return 0x18;
+ case sendRemoveEntityEffect: return 0x31;
+ case sendRespawn: return 0x33;
+ case sendScoreboardObjective: return 0x3f;
+ case sendScoreUpdate: return 0x42;
+ case sendSpawnGlobalEntity: return 0x02;
+ case sendSpawnObject: return 0x00;
+ case sendSpawnPosition: return 0x43;
+ case sendSoundEffect: return 0x19;
+ case sendSoundParticleEffect: return 0x21;
+ case sendSpawnMob: return 0x03;
+ case sendStatistics: return 0x07;
+ case sendTabCompletion: return 0x0e;
+ case sendTeleportEntity: return 0x4a;
+ case sendTimeUpdate: return 0x44;
+ case sendTitle: return 0x45;
+ case sendUnloadChunk: return 0x1d;
+ case sendUpdateBlockEntity: return 0x09;
+ case sendUpdateSign: return 0x46;
+ case sendUseBed: return 0x2f;
+ case sendWeather: return 0x1e;
+ case sendWindowClose: return 0x12;
+ case sendWindowItems: return 0x14;
+ case sendWindowOpen: return 0x13;
+ case sendWindowProperty: return 0x15;
+ }
+ LOGWARNING("Retrieving packet ID for unknown packet type %d!", a_Packet);
+ return 0;
+}
+
+
+
+
+
+UInt32 cProtocol_1_9_4::GetPacketId(eOutgoingPackets a_Packet)
+{
+ switch (a_Packet)
+ {
+ case sendCollectEntity: return 0x48;
+ case sendEntityEffect: return 0x4b;
+ case sendEntityProperties: return 0x4a;
+ case sendPlayerMaxSpeed: return 0x4a;
+ case sendTeleportEntity: return 0x49;
+
+ default: return super::GetPacketId(a_Packet);
+ }
+}
+
+
+
+
+
+UInt32 cProtocol_1_12::GetPacketId(eOutgoingPackets a_Packet)
+{
+ switch (a_Packet)
+ {
+ case sendAttachEntity: return 0x42;
+ case sendCameraSetTo: return 0x38;
+ case sendCollectEntity: return 0x4a;
+ case sendDestroyEntity: return 0x31;
+ case sendDisplayObjective: return 0x3a;
+ case sendEntityEffect: return 0x4e;
+ case sendEntityEquipment: return 0x3e;
+ case sendEntityHeadLook: return 0x35;
+ case sendEntityLook: return 0x28;
+ case sendEntityMeta: return 0x3b;
+ case sendEntityProperties: return 0x4d;
+ case sendEntityRelMove: return 0x26;
+ case sendEntityRelMoveLook: return 0x27;
+ case sendEntityVelocity: return 0x3d;
+ case sendExperience: return 0x3f;
+ case sendHealth: return 0x40;
+ case sendLeashEntity: return 0x3c;
+ case sendPlayerMaxSpeed: return 0x4d;
+ case sendRemoveEntityEffect: return 0x32;
+ case sendRespawn: return 0x34;
+ case sendScoreboardObjective: return 0x41;
+ case sendScoreUpdate: return 0x44;
+ case sendSpawnPosition: return 0x45;
+ case sendTeleportEntity: return 0x4b;
+ case sendTimeUpdate: return 0x46;
+ case sendTitle: return 0x47;
+ case sendUpdateBlockEntity: return 0x09;
+
+ default: return super::GetPacketId(a_Packet);
+ }
+}
+
+
+
+
+
+UInt32 cProtocol_1_12_1::GetPacketId(eOutgoingPackets a_Packet)
+{
+ switch (a_Packet)
+ {
+ case sendAttachEntity: return 0x43;
+ case sendCameraSetTo: return 0x39;
+ case sendCollectEntity: return 0x4b;
+ case sendDestroyEntity: return 0x32;
+ case sendDisplayObjective: return 0x3b;
+ case sendEntityEffect: return 0x4f;
+ case sendEntityEquipment: return 0x3f;
+ case sendEntityHeadLook: return 0x36;
+ case sendEntityMeta: return 0x3c;
+ case sendEntityProperties: return 0x4e;
+ case sendEntityVelocity: return 0x3e;
+ case sendExperience: return 0x40;
+ case sendHealth: return 0x41;
+ case sendLeashEntity: return 0x3d;
+ case sendPlayerList: return 0x2e;
+ case sendPlayerAbilities: return 0x2c;
+ case sendPlayerMaxSpeed: return 0x4e;
+ case sendPlayerMoveLook: return 0x2f;
+ case sendRemoveEntityEffect: return 0x33;
+ case sendRespawn: return 0x35;
+ case sendScoreboardObjective: return 0x42;
+ case sendScoreUpdate: return 0x45;
+ case sendSpawnPosition: return 0x46;
+ case sendUseBed: return 0x30;
+ case sendTeleportEntity: return 0x4c;
+ case sendTimeUpdate: return 0x47;
+ case sendTitle: return 0x48;
+
+ default: return super::GetPacketId(a_Packet);
+ }
+}
diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h
index 54c5b7223..9c4ee5e71 100644
--- a/src/Protocol/Protocol.h
+++ b/src/Protocol/Protocol.h
@@ -56,9 +56,84 @@ public:
virtual ~cProtocol() {}
+ /** A list of all outgoing packets */
+ enum eOutgoingPackets
+ {
+ sendAttachEntity = 0,
+ sendBlockAction,
+ sendBlockBreakAnim,
+ sendBlockChange,
+ sendBlockChanges,
+ sendCameraSetTo,
+ sendChatRaw,
+ sendCollectEntity,
+ sendDestroyEntity,
+ sendDifficulty,
+ sendDisconnectDuringLogin,
+ sendDisconnectDuringGame,
+ sendDisplayObjective,
+ sendEditSign,
+ sendEntityAnimation,
+ sendEntityEffect,
+ sendEntityEquipment,
+ sendEntityHeadLook,
+ sendEntityLook,
+ sendEntityMeta,
+ sendEntityProperties,
+ sendEntityRelMove,
+ sendEntityRelMoveLook,
+ sendEntityStatus,
+ sendEntityVelocity,
+ sendExperience,
+ sendExperienceOrb,
+ sendExplosion,
+ sendGameMode,
+ sendHealth,
+ sendInventorySlot,
+ sendJoinGame,
+ sendKeepAlive,
+ sendLeashEntity,
+ sendMapData,
+ sendPaintingSpawn,
+ sendParticleEffect,
+ sendPlayerAbilities,
+ sendPlayerList,
+ sendPlayerMaxSpeed,
+ sendPlayerMoveLook,
+ sendPlayerSpawn,
+ sendPluginMessage,
+ sendRemoveEntityEffect,
+ sendRespawn,
+ sendScoreboardObjective,
+ sendScoreUpdate,
+ sendSpawnObject,
+ sendSoundEffect,
+ sendSoundParticleEffect,
+ sendSpawnGlobalEntity,
+ sendSpawnMob,
+ sendSpawnPosition,
+ sendStatistics,
+ sendTabCompletion,
+ sendTeleportEntity,
+ sendTimeUpdate,
+ sendTitle,
+ sendUnloadChunk,
+ sendUpdateBlockEntity,
+ sendUpdateSign,
+ sendUseBed,
+ sendWeather,
+ sendWindowItems,
+ sendWindowClose,
+ sendWindowOpen,
+ sendWindowProperty
+ };
+
/** Called when client sends some data */
virtual void DataReceived(const char * a_Data, size_t a_Size) = 0;
+ /** Returns the protocol-specific packet ID given the protocol-agnostic packet enum (see PacketID.cpp for implementations) */
+ virtual UInt32 GetPacketId(eOutgoingPackets a_Packet) = 0;
+
// Sending stuff to clients (alphabetically sorted):
virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity & a_Vehicle) = 0;
virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) = 0;
diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h
index 295c6db16..f96d5aa77 100644
--- a/src/Protocol/ProtocolRecognizer.h
+++ b/src/Protocol/ProtocolRecognizer.h
@@ -52,6 +52,9 @@ public:
/** Translates protocol version number into protocol version text: 49 -> "1.4.4" */
static AString GetVersionTextFromInt(int a_ProtocolVersion);
+ /** GetPacketId is implemented in each protocol version class */
+ virtual UInt32 GetPacketId(eOutgoingPackets a_Packet) override { return 0; }
+
/** Called when client sends some data: */
virtual void DataReceived(const char * a_Data, size_t a_Size) override;
diff --git a/src/Protocol/Protocol_1_10.cpp b/src/Protocol/Protocol_1_10.cpp
index 7f86d4bdc..bb29c58ce 100644
--- a/src/Protocol/Protocol_1_10.cpp
+++ b/src/Protocol/Protocol_1_10.cpp
@@ -304,7 +304,7 @@ void cProtocol_1_10_0::SendSoundEffect(const AString & a_SoundName, double a_X,
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x19); // Named sound effect packet
+ cPacketizer Pkt(*this, GetPacketId(sendSoundEffect)); // Named sound effect packet
Pkt.WriteString(a_SoundName);
Pkt.WriteVarInt32(0); // Master sound category (may want to be changed to a parameter later)
Pkt.WriteBEInt32(FloorC(a_X * 8.0));
diff --git a/src/Protocol/Protocol_1_11.cpp b/src/Protocol/Protocol_1_11.cpp
index b9b6e9ac3..ba7742493 100644
--- a/src/Protocol/Protocol_1_11.cpp
+++ b/src/Protocol/Protocol_1_11.cpp
@@ -342,7 +342,7 @@ void cProtocol_1_11_0::SendCollectEntity(const cEntity & a_Entity, const cPlayer
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x48); // Collect Item packet
+ cPacketizer Pkt(*this, GetPacketId(sendCollectEntity)); // Collect Item packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
Pkt.WriteVarInt32(a_Player.GetUniqueID());
Pkt.WriteVarInt32(static_cast<UInt32>(a_Count));
@@ -356,7 +356,7 @@ void cProtocol_1_11_0::SendHideTitle(void)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x45); // Title packet
+ cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet
Pkt.WriteVarInt32(4); // Hide title
}
@@ -368,7 +368,7 @@ void cProtocol_1_11_0::SendResetTitle(void)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x45); // Title packet
+ cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet
Pkt.WriteVarInt32(5); // Reset title
}
@@ -380,7 +380,7 @@ void cProtocol_1_11_0::SendSpawnMob(const cMonster & a_Mob)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x03); // Spawn Mob packet
+ cPacketizer Pkt(*this, GetPacketId(sendSpawnMob)); // Spawn Mob packet
Pkt.WriteVarInt32(a_Mob.GetUniqueID());
// TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now.
Pkt.WriteBEUInt64(0);
diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp
index a8e38a4e0..166078aef 100644
--- a/src/Protocol/Protocol_1_12.cpp
+++ b/src/Protocol/Protocol_1_12.cpp
@@ -985,360 +985,6 @@ void cProtocol_1_12::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mo
-void cProtocol_1_12::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x26); // Entity Relative Move packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- // TODO: 1.9 changed these from chars to shorts, meaning that there can be more percision and data. Other code needs to be updated for that.
- Pkt.WriteBEInt16(a_RelX * 128);
- Pkt.WriteBEInt16(a_RelY * 128);
- Pkt.WriteBEInt16(a_RelZ * 128);
- Pkt.WriteBool(a_Entity.IsOnGround());
-}
-
-
-
-
-
-void cProtocol_1_12::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x27); // Entity Look And Relative Move packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- // TODO: 1.9 changed these from chars to shorts, meaning that there can be more percision and data. Other code needs to be updated for that.
- Pkt.WriteBEInt16(a_RelX * 128);
- Pkt.WriteBEInt16(a_RelY * 128);
- Pkt.WriteBEInt16(a_RelZ * 128);
- Pkt.WriteByteAngle(a_Entity.GetYaw());
- Pkt.WriteByteAngle(a_Entity.GetPitch());
- Pkt.WriteBool(a_Entity.IsOnGround());
-}
-
-
-
-
-
-void cProtocol_1_12::SendEntityLook(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x28); // Entity Look packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- Pkt.WriteByteAngle(a_Entity.GetYaw());
- Pkt.WriteByteAngle(a_Entity.GetPitch());
- Pkt.WriteBool(a_Entity.IsOnGround());
-}
-
-
-
-
-
-void cProtocol_1_12::SendDestroyEntity(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x31); // Destroy Entities packet
- Pkt.WriteVarInt32(1);
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
-}
-
-
-
-
-
-void cProtocol_1_12::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x32); // Remove entity effect packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- Pkt.WriteBEUInt8(static_cast<UInt8>(a_EffectID));
-}
-
-
-
-
-
-void cProtocol_1_12::SendRespawn(eDimension a_Dimension)
-{
- cPacketizer Pkt(*this, 0x34); // Respawn packet
- cPlayer * Player = m_Client->GetPlayer();
- Pkt.WriteBEInt32(static_cast<Int32>(a_Dimension));
- Pkt.WriteBEUInt8(2); // TODO: Difficulty (set to Normal)
- Pkt.WriteBEUInt8(static_cast<Byte>(Player->GetEffectiveGameMode()));
- Pkt.WriteString("default");
-}
-
-
-
-
-
-void cProtocol_1_12::SendEntityHeadLook(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x35); // Entity Head Look packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- Pkt.WriteByteAngle(a_Entity.GetHeadYaw());
-}
-
-
-
-
-
-void cProtocol_1_12::SendCameraSetTo(const cEntity & a_Entity)
-{
- cPacketizer Pkt(*this, 0x38); // Camera Packet (Attach the camera of a player at another entity in spectator mode)
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
-}
-
-
-
-
-
-void cProtocol_1_12::SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x3a); // Display scoreboard packet
- Pkt.WriteBEUInt8(static_cast<UInt8>(a_Display));
- Pkt.WriteString(a_Objective);
-}
-
-
-
-
-
-void cProtocol_1_12::SendEntityMetadata(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x3b); // Entity Metadata packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- WriteEntityMetadata(Pkt, a_Entity);
- Pkt.WriteBEUInt8(0xff); // The termination byte
-}
-
-
-
-
-
-void cProtocol_1_12::SendLeashEntity(const cEntity & a_Entity, const cEntity & a_EntityLeashedTo)
-{
- ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x3c); // Set Attach Entity packet
- Pkt.WriteBEUInt32(a_Entity.GetUniqueID());
- Pkt.WriteBEUInt32(a_EntityLeashedTo.GetUniqueID());
-}
-
-
-
-
-
-void cProtocol_1_12::SendUnleashEntity(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x3c); // Set Attach Entity packet
- Pkt.WriteBEUInt32(a_Entity.GetUniqueID());
- Pkt.WriteBEInt32(-1); // Unleash a_Entity
-}
-
-
-
-
-
-void cProtocol_1_12::SendEntityVelocity(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x3d); // Entity Velocity packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- // 400 = 8000 / 20 ... Conversion from our speed in m / s to 8000 m / tick
- Pkt.WriteBEInt16(static_cast<Int16>(a_Entity.GetSpeedX() * 400));
- Pkt.WriteBEInt16(static_cast<Int16>(a_Entity.GetSpeedY() * 400));
- Pkt.WriteBEInt16(static_cast<Int16>(a_Entity.GetSpeedZ() * 400));
-}
-
-
-
-
-
-void cProtocol_1_12::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x3e); // Entity Equipment packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- // Needs to be adjusted due to the insertion of offhand at slot 1
- if (a_SlotNum > 0)
- {
- a_SlotNum++;
- }
- Pkt.WriteVarInt32(static_cast<UInt32>(a_SlotNum));
- WriteItem(Pkt, a_Item);
-}
-
-
-
-
-
-void cProtocol_1_12::SendExperience(void)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x3f); // Set Experience Packet
- cPlayer * Player = m_Client->GetPlayer();
- Pkt.WriteBEFloat(Player->GetXpPercentage());
- Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetXpLevel()));
- Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetCurrentXp()));
-}
-
-
-
-
-
-void cProtocol_1_12::SendHealth(void)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x40); // Update Health packet
- cPlayer * Player = m_Client->GetPlayer();
- Pkt.WriteBEFloat(static_cast<float>(Player->GetHealth()));
- Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetFoodLevel()));
- Pkt.WriteBEFloat(static_cast<float>(Player->GetFoodSaturationLevel()));
-}
-
-
-
-
-
-void cProtocol_1_12::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x41); // Scoreboard objective packet
- Pkt.WriteString(a_Name);
- Pkt.WriteBEUInt8(a_Mode);
- if ((a_Mode == 0) || (a_Mode == 2))
- {
- Pkt.WriteString(a_DisplayName);
- Pkt.WriteString("integer");
- }
-}
-
-
-
-
-
-void cProtocol_1_12::SendAttachEntity(const cEntity & a_Entity, const cEntity & a_Vehicle)
-{
- ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x42); // Set Passengers packet
- Pkt.WriteVarInt32(a_Vehicle.GetUniqueID());
- Pkt.WriteVarInt32(1); // 1 passenger
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
-}
-
-
-
-
-
-void cProtocol_1_12::SendDetachEntity(const cEntity & a_Entity, const cEntity & a_PreviousVehicle)
-{
- ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x42); // Set Passengers packet
- Pkt.WriteVarInt32(a_PreviousVehicle.GetUniqueID());
- Pkt.WriteVarInt32(0); // No passangers
-}
-
-
-
-
-
-void cProtocol_1_12::SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x44); // Update score packet
- Pkt.WriteString(a_Player);
- Pkt.WriteBEUInt8(a_Mode);
- Pkt.WriteString(a_Objective);
-
- if (a_Mode != 1)
- {
- Pkt.WriteVarInt32(static_cast<UInt32>(a_Score));
- }
-}
-
-
-
-
-
-void cProtocol_1_12::SendLogin(const cPlayer & a_Player, const cWorld & a_World)
-{
- // Send the Join Game packet:
- {
- cServer * Server = cRoot::Get()->GetServer();
- cPacketizer Pkt(*this, 0x23); // Join Game packet
- Pkt.WriteBEUInt32(a_Player.GetUniqueID());
- Pkt.WriteBEUInt8(static_cast<UInt8>(a_Player.GetEffectiveGameMode()) | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4
- Pkt.WriteBEInt32(static_cast<Int32>(a_World.GetDimension()));
- Pkt.WriteBEUInt8(2); // TODO: Difficulty (set to Normal)
- Pkt.WriteBEUInt8(static_cast<UInt8>(Clamp<size_t>(Server->GetMaxPlayers(), 0, 255)));
- Pkt.WriteString("default"); // Level type - wtf?
- Pkt.WriteBool(false); // Reduced Debug Info - wtf?
- }
-
- // Send the spawn position:
- {
- cPacketizer Pkt(*this, 0x45); // Spawn Position packet
- Pkt.WritePosition64(FloorC(a_World.GetSpawnX()), FloorC(a_World.GetSpawnY()), FloorC(a_World.GetSpawnZ()));
- }
-
- // Send the server difficulty:
- {
- cPacketizer Pkt(*this, 0x0d); // Server difficulty packet
- Pkt.WriteBEInt8(1);
- }
-
- // Send player abilities:
- SendPlayerAbilities();
-}
-
-
-
-
-
-void cProtocol_1_12::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x09); // Update tile entity packet
- Pkt.WritePosition64(a_BlockEntity.GetPosX(), a_BlockEntity.GetPosY(), a_BlockEntity.GetPosZ());
-
- Byte Action = 0;
- switch (a_BlockEntity.GetBlockType())
- {
- case E_BLOCK_MOB_SPAWNER: Action = 1; break; // Update mob spawner spinny mob thing
- case E_BLOCK_COMMAND_BLOCK: Action = 2; break; // Update command block text
- case E_BLOCK_BEACON: Action = 3; break; // Update beacon entity
- case E_BLOCK_HEAD: Action = 4; break; // Update Mobhead entity
- case E_BLOCK_FLOWER_POT: Action = 5; break; // Update flower pot
- case E_BLOCK_BED: Action = 11; break; // Update bed color
- default: ASSERT(!"Unhandled or unimplemented BlockEntity update request!"); break;
- }
- Pkt.WriteBEUInt8(Action);
-
- WriteBlockEntity(Pkt, a_BlockEntity);
-}
-
-
-
-
-
void cProtocol_1_12::HandlePacketCraftingBookData(cByteBuffer & a_ByteBuffer)
{
a_ByteBuffer.SkipRead(a_ByteBuffer.GetReadableSpace() - 1);
@@ -1359,57 +1005,11 @@ void cProtocol_1_12::HandlePacketAdvancementTab(cByteBuffer & a_ByteBuffer)
-void cProtocol_1_12::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle)
-{
- ASSERT(m_State == 3); // In game mode?
- if (!a_DoDaylightCycle)
- {
- // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration.
- a_TimeOfDay = std::min(-a_TimeOfDay, -1LL);
- }
-
- cPacketizer Pkt(*this, 0x46); // Time update packet
- Pkt.WriteBEInt64(a_WorldAge);
- Pkt.WriteBEInt64(a_TimeOfDay);
-}
-
-
-
-
-
-void cProtocol_1_12::SendSetRawTitle(const AString & a_Title)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x47); // Title packet
- Pkt.WriteVarInt32(0); // Set title
-
- Pkt.WriteString(a_Title);
-}
-
-
-
-
-
-void cProtocol_1_12::SendSetRawSubTitle(const AString & a_SubTitle)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x47); // Title packet
- Pkt.WriteVarInt32(1); // Set subtitle
-
- Pkt.WriteString(a_SubTitle);
-}
-
-
-
-
-
void cProtocol_1_12::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x47); // Title packet
+ cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet
Pkt.WriteVarInt32(3); // Set title display times
Pkt.WriteBEInt32(a_FadeInTicks);
Pkt.WriteBEInt32(a_DisplayTicks);
@@ -1424,7 +1024,7 @@ void cProtocol_1_12::SendHideTitle(void)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x47); // Title packet
+ cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet
Pkt.WriteVarInt32(4); // Hide title
}
@@ -1436,7 +1036,7 @@ void cProtocol_1_12::SendResetTitle(void)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x47); // Title packet
+ cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet
Pkt.WriteVarInt32(5); // Reset title
}
@@ -1448,7 +1048,7 @@ void cProtocol_1_12::SendCollectEntity(const cEntity & a_Entity, const cPlayer &
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x4a); // Collect Item packet
+ cPacketizer Pkt(*this, GetPacketId(sendCollectEntity)); // Collect Item packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
Pkt.WriteVarInt32(a_Player.GetUniqueID());
Pkt.WriteVarInt32(static_cast<UInt32>(a_Count));
@@ -1458,83 +1058,6 @@ void cProtocol_1_12::SendCollectEntity(const cEntity & a_Entity, const cPlayer &
-void cProtocol_1_12::SendTeleportEntity(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x4b); // Entity teleport packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- Pkt.WriteBEDouble(a_Entity.GetPosX());
- Pkt.WriteBEDouble(a_Entity.GetPosY());
- Pkt.WriteBEDouble(a_Entity.GetPosZ());
- Pkt.WriteByteAngle(a_Entity.GetYaw());
- Pkt.WriteByteAngle(a_Entity.GetPitch());
- Pkt.WriteBool(a_Entity.IsOnGround());
-}
-
-
-
-
-
-void cProtocol_1_12::SendEntityProperties(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
-
-
- cPacketizer Pkt(*this, 0x4d); // Entity Properties packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- WriteEntityProperties(Pkt, a_Entity);
-}
-
-
-
-
-
-void cProtocol_1_12::SendPlayerMaxSpeed(void)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x4d); // Entity Properties
- cPlayer * Player = m_Client->GetPlayer();
- Pkt.WriteVarInt32(Player->GetUniqueID());
- Pkt.WriteBEInt32(1); // Count
- Pkt.WriteString("generic.movementSpeed");
- // The default game speed is 0.1, multiply that value by the relative speed:
- Pkt.WriteBEDouble(0.1 * Player->GetNormalMaxSpeed());
- if (Player->IsSprinting())
- {
- Pkt.WriteVarInt32(1); // Modifier count
- Pkt.WriteBEUInt64(0x662a6b8dda3e4c1c);
- Pkt.WriteBEUInt64(0x881396ea6097278d); // UUID of the modifier
- Pkt.WriteBEDouble(Player->GetSprintingMaxSpeed() - Player->GetNormalMaxSpeed());
- Pkt.WriteBEUInt8(2);
- }
- else
- {
- Pkt.WriteVarInt32(0); // Modifier count
- }
-}
-
-
-
-
-
-void cProtocol_1_12::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x4e); // Entity Effect packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- Pkt.WriteBEUInt8(static_cast<UInt8>(a_EffectID));
- Pkt.WriteBEUInt8(static_cast<UInt8>(a_Amplifier));
- Pkt.WriteVarInt32(static_cast<UInt32>(a_Duration));
- Pkt.WriteBool(false); // Hide particles
-}
-
-
-
-
-
bool cProtocol_1_12::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType)
{
switch (m_State)
@@ -1668,7 +1191,6 @@ void cProtocol_1_12_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
ResponseValue["version"] = Version;
ResponseValue["players"] = Players;
ResponseValue["description"] = Description;
- m_Client->ForgeAugmentServerListPing(ResponseValue);
if (!Favicon.empty())
{
ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str());
@@ -1684,631 +1206,6 @@ void cProtocol_1_12_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
-void cProtocol_1_12_1::SendRespawn(eDimension a_Dimension)
-{
- cPacketizer Pkt(*this, 0x35); // Respawn packet
- cPlayer * Player = m_Client->GetPlayer();
- Pkt.WriteBEInt32(static_cast<Int32>(a_Dimension));
- Pkt.WriteBEUInt8(2); // TODO: Difficulty (set to Normal)
- Pkt.WriteBEUInt8(static_cast<Byte>(Player->GetEffectiveGameMode()));
- Pkt.WriteString("default");
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendPlayerListAddPlayer(const cPlayer & a_Player)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x2e); // Player List Item packet
- Pkt.WriteVarInt32(0);
- Pkt.WriteVarInt32(1);
- Pkt.WriteUUID(a_Player.GetUUID());
- Pkt.WriteString(a_Player.GetPlayerListName());
-
- const Json::Value & Properties = a_Player.GetClientHandle()->GetProperties();
- Pkt.WriteVarInt32(Properties.size());
- for (auto & Node : Properties)
- {
- Pkt.WriteString(Node.get("name", "").asString());
- Pkt.WriteString(Node.get("value", "").asString());
- AString Signature = Node.get("signature", "").asString();
- if (Signature.empty())
- {
- Pkt.WriteBool(false);
- }
- else
- {
- Pkt.WriteBool(true);
- Pkt.WriteString(Signature);
- }
- }
-
- Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetGameMode()));
- Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetClientHandle()->GetPing()));
- Pkt.WriteBool(false);
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendPlayerListRemovePlayer(const cPlayer & a_Player)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x2e); // Player List Item packet
- Pkt.WriteVarInt32(4);
- Pkt.WriteVarInt32(1);
- Pkt.WriteUUID(a_Player.GetUUID());
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendPlayerListUpdateGameMode(const cPlayer & a_Player)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x2e); // Player List Item packet
- Pkt.WriteVarInt32(1);
- Pkt.WriteVarInt32(1);
- Pkt.WriteUUID(a_Player.GetUUID());
- Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetGameMode()));
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendPlayerListUpdatePing(const cPlayer & a_Player)
-{
- ASSERT(m_State == 3); // In game mode?
-
- auto ClientHandle = a_Player.GetClientHandlePtr();
- if (ClientHandle != nullptr)
- {
- cPacketizer Pkt(*this, 0x2e); // Player List Item packet
- Pkt.WriteVarInt32(2);
- Pkt.WriteVarInt32(1);
- Pkt.WriteUUID(a_Player.GetUUID());
- Pkt.WriteVarInt32(static_cast<UInt32>(ClientHandle->GetPing()));
- }
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x2e); // Player List Item packet
- Pkt.WriteVarInt32(3);
- Pkt.WriteVarInt32(1);
- Pkt.WriteUUID(a_Player.GetUUID());
-
- if (a_CustomName.empty())
- {
- Pkt.WriteBool(false);
- }
- else
- {
- Pkt.WriteBool(true);
- Pkt.WriteString(Printf("{\"text\":\"%s\"}", a_CustomName.c_str()));
- }
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendPlayerAbilities(void)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x2c); // Player Abilities packet
- Byte Flags = 0;
- cPlayer * Player = m_Client->GetPlayer();
- if (Player->IsGameModeCreative())
- {
- Flags |= 0x01;
- Flags |= 0x08; // Godmode, used for creative
- }
- if (Player->IsFlying())
- {
- Flags |= 0x02;
- }
- if (Player->CanFly())
- {
- Flags |= 0x04;
- }
- Pkt.WriteBEUInt8(Flags);
- Pkt.WriteBEFloat(static_cast<float>(0.05 * Player->GetFlyingMaxSpeed()));
- Pkt.WriteBEFloat(static_cast<float>(0.1 * Player->GetNormalMaxSpeed()));
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendPlayerMoveLook(void)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x2f); // Player Position And Look packet
- cPlayer * Player = m_Client->GetPlayer();
- Pkt.WriteBEDouble(Player->GetPosX());
- Pkt.WriteBEDouble(Player->GetPosY());
- Pkt.WriteBEDouble(Player->GetPosZ());
- Pkt.WriteBEFloat(static_cast<float>(Player->GetYaw()));
- Pkt.WriteBEFloat(static_cast<float>(Player->GetPitch()));
- Pkt.WriteBEUInt8(0);
- Pkt.WriteVarInt32(++m_OutstandingTeleportId);
-
- // This teleport ID hasn't been confirmed yet
- m_IsTeleportIdConfirmed = false;
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x30); // Use bed
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ);
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendDestroyEntity(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x32); // Destroy Entities packet
- Pkt.WriteVarInt32(1);
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x33); // Remove entity effect packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- Pkt.WriteBEUInt8(static_cast<UInt8>(a_EffectID));
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendEntityHeadLook(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x36); // Entity Head Look packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- Pkt.WriteByteAngle(a_Entity.GetHeadYaw());
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendCameraSetTo(const cEntity & a_Entity)
-{
- cPacketizer Pkt(*this, 0x39); // Camera packet (Attach the camera of a player at another entity in spectator mode)
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x3b); // Display Scoreboard packet
- Pkt.WriteBEUInt8(static_cast<UInt8>(a_Display));
- Pkt.WriteString(a_Objective);
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendEntityMetadata(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x3c); // Entity Metadata packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- WriteEntityMetadata(Pkt, a_Entity);
- Pkt.WriteBEUInt8(0xff); // The termination byte
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendLeashEntity(const cEntity & a_Entity, const cEntity & a_EntityLeashedTo)
-{
- ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x3d); // Set Attach Entity packet
- Pkt.WriteBEUInt32(a_Entity.GetUniqueID());
- Pkt.WriteBEUInt32(a_EntityLeashedTo.GetUniqueID());
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendUnleashEntity(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x3d); // Set Attach Entity packet
- Pkt.WriteBEUInt32(a_Entity.GetUniqueID());
- Pkt.WriteBEInt32(-1); // Unleash a_Entity
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendEntityVelocity(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x3e); // Entity Velocity packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- // 400 = 8000 / 20 ... Conversion from our speed in m / s to 8000 m / tick
- Pkt.WriteBEInt16(static_cast<Int16>(a_Entity.GetSpeedX() * 400));
- Pkt.WriteBEInt16(static_cast<Int16>(a_Entity.GetSpeedY() * 400));
- Pkt.WriteBEInt16(static_cast<Int16>(a_Entity.GetSpeedZ() * 400));
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x3f); // Entity Equipment packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- // Needs to be adjusted due to the insertion of offhand at slot 1
- if (a_SlotNum > 0)
- {
- a_SlotNum++;
- }
- Pkt.WriteVarInt32(static_cast<UInt32>(a_SlotNum));
- WriteItem(Pkt, a_Item);
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendExperience(void)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x40); // Set Experience packet
- cPlayer * Player = m_Client->GetPlayer();
- Pkt.WriteBEFloat(Player->GetXpPercentage());
- Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetXpLevel()));
- Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetCurrentXp()));
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendHealth(void)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x41); // Update Health packet
- cPlayer * Player = m_Client->GetPlayer();
- Pkt.WriteBEFloat(static_cast<float>(Player->GetHealth()));
- Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetFoodLevel()));
- Pkt.WriteBEFloat(static_cast<float>(Player->GetFoodSaturationLevel()));
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x42); // Scoreboard Objective packet
- Pkt.WriteString(a_Name);
- Pkt.WriteBEUInt8(a_Mode);
- if ((a_Mode == 0) || (a_Mode == 2))
- {
- Pkt.WriteString(a_DisplayName);
- Pkt.WriteString("integer");
- }
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendAttachEntity(const cEntity & a_Entity, const cEntity & a_Vehicle)
-{
- ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x43); // Set Passengers packet
- Pkt.WriteVarInt32(a_Vehicle.GetUniqueID());
- Pkt.WriteVarInt32(1); // 1 passenger
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendDetachEntity(const cEntity & a_Entity, const cEntity & a_PreviousVehicle)
-{
- ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x43); // Set Passengers packet
- Pkt.WriteVarInt32(a_PreviousVehicle.GetUniqueID());
- Pkt.WriteVarInt32(0); // No passangers
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x45); // Update Score packet
- Pkt.WriteString(a_Player);
- Pkt.WriteBEUInt8(a_Mode);
- Pkt.WriteString(a_Objective);
-
- if (a_Mode != 1)
- {
- Pkt.WriteVarInt32(static_cast<UInt32>(a_Score));
- }
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendLogin(const cPlayer & a_Player, const cWorld & a_World)
-{
- // Send the Join Game packet:
- {
- cServer * Server = cRoot::Get()->GetServer();
- cPacketizer Pkt(*this, 0x23); // Join Game packet
- Pkt.WriteBEUInt32(a_Player.GetUniqueID());
- Pkt.WriteBEUInt8(static_cast<UInt8>(a_Player.GetEffectiveGameMode()) | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4
- Pkt.WriteBEInt32(static_cast<Int32>(a_World.GetDimension()));
- Pkt.WriteBEUInt8(2); // TODO: Difficulty (set to Normal)
- Pkt.WriteBEUInt8(static_cast<UInt8>(Clamp<size_t>(Server->GetMaxPlayers(), 0, 255)));
- Pkt.WriteString("default"); // Level type - wtf?
- Pkt.WriteBool(false); // Reduced Debug Info - wtf?
- }
-
- // Send the spawn position:
- {
- cPacketizer Pkt(*this, 0x46); // Spawn Position packet
- Pkt.WritePosition64(FloorC(a_World.GetSpawnX()), FloorC(a_World.GetSpawnY()), FloorC(a_World.GetSpawnZ()));
- }
-
- // Send the server difficulty:
- {
- cPacketizer Pkt(*this, 0x0d); // Server difficulty packet
- Pkt.WriteBEInt8(1);
- }
-
- // Send player abilities:
- SendPlayerAbilities();
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle)
-{
- ASSERT(m_State == 3); // In game mode?
- if (!a_DoDaylightCycle)
- {
- // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration.
- a_TimeOfDay = std::min(-a_TimeOfDay, -1LL);
- }
-
- cPacketizer Pkt(*this, 0x47); // Time update packet
- Pkt.WriteBEInt64(a_WorldAge);
- Pkt.WriteBEInt64(a_TimeOfDay);
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendSetRawTitle(const AString & a_Title)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x48); // Title packet
- Pkt.WriteVarInt32(0); // Set title
-
- Pkt.WriteString(a_Title);
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendSetRawSubTitle(const AString & a_SubTitle)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x48); // Title packet
- Pkt.WriteVarInt32(1); // Set subtitle
-
- Pkt.WriteString(a_SubTitle);
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x48); // Title packet
- Pkt.WriteVarInt32(3); // Set title display times
- Pkt.WriteBEInt32(a_FadeInTicks);
- Pkt.WriteBEInt32(a_DisplayTicks);
- Pkt.WriteBEInt32(a_FadeOutTicks);
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendHideTitle(void)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x48); // Title packet
- Pkt.WriteVarInt32(4); // Hide title
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendResetTitle(void)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x48); // Title packet
- Pkt.WriteVarInt32(5); // Reset title
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, int a_Count)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x4b); // Collect Item packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- Pkt.WriteVarInt32(a_Player.GetUniqueID());
- Pkt.WriteVarInt32(static_cast<UInt32>(a_Count));
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendTeleportEntity(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x4c); // Entity teleport packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- Pkt.WriteBEDouble(a_Entity.GetPosX());
- Pkt.WriteBEDouble(a_Entity.GetPosY());
- Pkt.WriteBEDouble(a_Entity.GetPosZ());
- Pkt.WriteByteAngle(a_Entity.GetYaw());
- Pkt.WriteByteAngle(a_Entity.GetPitch());
- Pkt.WriteBool(a_Entity.IsOnGround());
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendEntityProperties(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
-
-
- cPacketizer Pkt(*this, 0x4e); // Entity Properties packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- WriteEntityProperties(Pkt, a_Entity);
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x4f); // Entity Effect packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- Pkt.WriteBEUInt8(static_cast<UInt8>(a_EffectID));
- Pkt.WriteBEUInt8(static_cast<UInt8>(a_Amplifier));
- Pkt.WriteVarInt32(static_cast<UInt32>(a_Duration));
- Pkt.WriteBool(false); // Hide particles
-}
-
-
-
-
-
-void cProtocol_1_12_1::SendPlayerMaxSpeed(void)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x4e); // Entity Properties
- cPlayer * Player = m_Client->GetPlayer();
- Pkt.WriteVarInt32(Player->GetUniqueID());
- Pkt.WriteBEInt32(1); // Count
- Pkt.WriteString("generic.movementSpeed");
- // The default game speed is 0.1, multiply that value by the relative speed:
- Pkt.WriteBEDouble(0.1 * Player->GetNormalMaxSpeed());
- if (Player->IsSprinting())
- {
- Pkt.WriteVarInt32(1); // Modifier count
- Pkt.WriteBEUInt64(0x662a6b8dda3e4c1c);
- Pkt.WriteBEUInt64(0x881396ea6097278d); // UUID of the modifier
- Pkt.WriteBEDouble(Player->GetSprintingMaxSpeed() - Player->GetNormalMaxSpeed());
- Pkt.WriteBEUInt8(2);
- }
- else
- {
- Pkt.WriteVarInt32(0); // Modifier count
- }
-}
-
-
-
-
-
bool cProtocol_1_12_1::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType)
{
switch (m_State)
diff --git a/src/Protocol/Protocol_1_12.h b/src/Protocol/Protocol_1_12.h
index 17d7d4e86..ed47f7ef2 100644
--- a/src/Protocol/Protocol_1_12.h
+++ b/src/Protocol/Protocol_1_12.h
@@ -30,40 +30,13 @@ class cProtocol_1_12 :
public:
cProtocol_1_12(cClientHandle * a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
- virtual void SendAttachEntity(const cEntity & a_Entity, const cEntity & a_Vehicle) override;
- virtual void SendCameraSetTo(const cEntity & a_Entity) override;
+ virtual UInt32 GetPacketId(eOutgoingPackets a_Packet) override;
+
virtual void SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, int a_Count) override;
- virtual void SendDestroyEntity(const cEntity & a_Entity) override;
- virtual void SendDetachEntity(const cEntity & a_Entity, const cEntity & a_PreviousVehicle) override;
- virtual void SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override;
- virtual void SendEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) override;
- virtual void SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override;
- virtual void SendEntityHeadLook(const cEntity & a_Entity) override;
- virtual void SendEntityLook(const cEntity & a_Entity) override;
- virtual void SendEntityMetadata(const cEntity & a_Entity) override;
- virtual void SendEntityProperties(const cEntity & a_Entity) override;
- virtual void SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
- virtual void SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
- virtual void SendEntityVelocity(const cEntity & a_Entity) override;
- virtual void SendExperience(void) override;
- virtual void SendHealth(void) override;
virtual void SendHideTitle(void) override;
- virtual void SendLeashEntity(const cEntity & a_Entity, const cEntity & a_EntityLeashedTo) override;
- virtual void SendLogin(const cPlayer & a_Player, const cWorld & a_World) override;
- virtual void SendPlayerMaxSpeed(void) override;
- virtual void SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID) override;
virtual void SendResetTitle(void) override;
- virtual void SendRespawn(eDimension a_Dimension) override;
- virtual void SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override;
- virtual void SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override;
- virtual void SendSetRawSubTitle(const AString & a_SubTitle) override;
- virtual void SendSetRawTitle(const AString & a_Title) override;
virtual void SendSpawnMob(const cMonster & a_Mob) override;
- virtual void SendTeleportEntity(const cEntity & a_Entity) override;
- virtual void SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override;
virtual void SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) override;
- virtual void SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) override;
- virtual void SendUnleashEntity(const cEntity & a_Entity) override;
protected:
virtual bool HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) override;
virtual void HandlePacketAdvancementTab(cByteBuffer & a_ByteBuffer);
@@ -86,43 +59,7 @@ class cProtocol_1_12_1 :
public:
cProtocol_1_12_1(cClientHandle * a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
- virtual void SendRespawn(eDimension a_Dimension) override;
- virtual void SendPlayerListAddPlayer(const cPlayer & a_Player) override;
- virtual void SendPlayerListRemovePlayer(const cPlayer & a_Player) override;
- virtual void SendPlayerListUpdateGameMode(const cPlayer & a_Player) override;
- virtual void SendPlayerListUpdatePing(const cPlayer & a_Player) override;
- virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName) override;
- virtual void SendPlayerAbilities(void) override;
- virtual void SendPlayerMoveLook(void) override;
- virtual void SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override;
- virtual void SendDestroyEntity(const cEntity & a_Entity) override;
- virtual void SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID) override;
- virtual void SendEntityHeadLook(const cEntity & a_Entity) override;
- virtual void SendCameraSetTo(const cEntity & a_Entity) override;
- virtual void SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override;
- virtual void SendEntityMetadata(const cEntity & a_Entity) override;
- virtual void SendLeashEntity(const cEntity & a_Entity, const cEntity & a_EntityLeashedTo) override;
- virtual void SendUnleashEntity(const cEntity & a_Entity) override;
- virtual void SendEntityVelocity(const cEntity & a_Entity) override;
- virtual void SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override;
- virtual void SendExperience(void) override;
- virtual void SendHealth(void) override;
- virtual void SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override;
- virtual void SendAttachEntity(const cEntity & a_Entity, const cEntity & a_Vehicle) override;
- virtual void SendDetachEntity(const cEntity & a_Entity, const cEntity & a_PreviousVehicle) override;
- virtual void SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override;
- virtual void SendLogin(const cPlayer & a_Player, const cWorld & a_World) override;
- virtual void SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override;
- virtual void SendHideTitle(void) override;
- virtual void SendResetTitle(void) override;
- virtual void SendSetRawSubTitle(const AString & a_SubTitle) override;
- virtual void SendSetRawTitle(const AString & a_Title) override;
- virtual void SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) override;
- virtual void SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, int a_Count) override;
- virtual void SendTeleportEntity(const cEntity & a_Entity) override;
- virtual void SendEntityProperties(const cEntity & a_Entity) override;
- virtual void SendEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) override;
- virtual void SendPlayerMaxSpeed(void) override;
+ virtual UInt32 GetPacketId(eOutgoingPackets a_Packet) override;
protected:
virtual bool HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) override;
diff --git a/src/Protocol/Protocol_1_8.h b/src/Protocol/Protocol_1_8.h
index d3d0daf0a..472538d60 100644
--- a/src/Protocol/Protocol_1_8.h
+++ b/src/Protocol/Protocol_1_8.h
@@ -45,6 +45,9 @@ public:
cProtocol_1_8_0(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
+ /** Nobody inherits 1.8, so it doesn't use this method */
+ virtual UInt32 GetPacketId(eOutgoingPackets a_Packet) override { return 0; }
+
/** Called when client sends some data: */
virtual void DataReceived(const char * a_Data, size_t a_Size) override;
diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp
index 475047417..90eedf91e 100644
--- a/src/Protocol/Protocol_1_9.cpp
+++ b/src/Protocol/Protocol_1_9.cpp
@@ -216,7 +216,7 @@ void cProtocol_1_9_0::DataReceived(const char * a_Data, size_t a_Size)
void cProtocol_1_9_0::SendAttachEntity(const cEntity & a_Entity, const cEntity & a_Vehicle)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x40); // Set passangers packet
+ cPacketizer Pkt(*this, GetPacketId(sendAttachEntity)); // Set passangers packet
Pkt.WriteVarInt32(a_Vehicle.GetUniqueID());
Pkt.WriteVarInt32(1); // 1 passenger
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
@@ -230,7 +230,7 @@ void cProtocol_1_9_0::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ,
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x0a); // Block Action packet
+ cPacketizer Pkt(*this, GetPacketId(sendBlockAction)); // Block Action packet
Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ);
Pkt.WriteBEInt8(a_Byte1);
Pkt.WriteBEInt8(a_Byte2);
@@ -245,7 +245,7 @@ void cProtocol_1_9_0::SendBlockBreakAnim(UInt32 a_EntityID, int a_BlockX, int a_
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x08); // Block Break Animation packet
+ cPacketizer Pkt(*this, GetPacketId(sendBlockBreakAnim)); // Block Break Animation packet
Pkt.WriteVarInt32(a_EntityID);
Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ);
Pkt.WriteBEInt8(a_Stage);
@@ -259,7 +259,7 @@ void cProtocol_1_9_0::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ,
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x0b); // Block Change packet
+ cPacketizer Pkt(*this, GetPacketId(sendBlockChange)); // Block Change packet
Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ);
Pkt.WriteVarInt32((static_cast<UInt32>(a_BlockType) << 4) | (static_cast<UInt32>(a_BlockMeta) & 15));
}
@@ -272,7 +272,7 @@ void cProtocol_1_9_0::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlo
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x10); // Multi Block Change packet
+ cPacketizer Pkt(*this, GetPacketId(sendBlockChanges)); // Multi Block Change packet
Pkt.WriteBEInt32(a_ChunkX);
Pkt.WriteBEInt32(a_ChunkZ);
Pkt.WriteVarInt32(static_cast<UInt32>(a_Changes.size()));
@@ -290,7 +290,7 @@ void cProtocol_1_9_0::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlo
void cProtocol_1_9_0::SendCameraSetTo(const cEntity & a_Entity)
{
- cPacketizer Pkt(*this, 0x36); // Camera Packet (Attach the camera of a player at another entity in spectator mode)
+ cPacketizer Pkt(*this, GetPacketId(sendCameraSetTo)); // Camera Packet (Attach the camera of a player at another entity in spectator mode)
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
}
@@ -325,7 +325,7 @@ void cProtocol_1_9_0::SendChatRaw(const AString & a_MessageRaw, eChatType a_Type
ASSERT(m_State == 3); // In game mode?
// Send the json string to the client:
- cPacketizer Pkt(*this, 0x0f); // Chat Message packet
+ cPacketizer Pkt(*this, GetPacketId(sendChatRaw)); // Chat Message packet
Pkt.WriteString(a_MessageRaw);
Pkt.WriteBEInt8(a_Type);
}
@@ -355,7 +355,7 @@ void cProtocol_1_9_0::SendCollectEntity(const cEntity & a_Entity, const cPlayer
UNUSED(a_Count);
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x49); // Collect Item packet
+ cPacketizer Pkt(*this, GetPacketId(sendCollectEntity)); // Collect Item packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
Pkt.WriteVarInt32(a_Player.GetUniqueID());
}
@@ -368,7 +368,7 @@ void cProtocol_1_9_0::SendDestroyEntity(const cEntity & a_Entity)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x30); // Destroy Entities packet
+ cPacketizer Pkt(*this, GetPacketId(sendDestroyEntity)); // Destroy Entities packet
Pkt.WriteVarInt32(1);
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
}
@@ -380,7 +380,7 @@ void cProtocol_1_9_0::SendDestroyEntity(const cEntity & a_Entity)
void cProtocol_1_9_0::SendDetachEntity(const cEntity & a_Entity, const cEntity & a_PreviousVehicle)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x40); // Set passangers packet
+ cPacketizer Pkt(*this, GetPacketId(sendAttachEntity)); // Set passangers packet
Pkt.WriteVarInt32(a_PreviousVehicle.GetUniqueID());
Pkt.WriteVarInt32(0); // No passangers
}
@@ -396,14 +396,14 @@ void cProtocol_1_9_0::SendDisconnect(const AString & a_Reason)
case 2:
{
// During login:
- cPacketizer Pkt(*this, 0);
+ cPacketizer Pkt(*this, GetPacketId(sendDisconnectDuringLogin));
Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Reason).c_str()));
break;
}
case 3:
{
// In-game:
- cPacketizer Pkt(*this, 0x1a);
+ cPacketizer Pkt(*this, GetPacketId(sendDisconnectDuringGame));
Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Reason).c_str()));
break;
}
@@ -418,7 +418,7 @@ void cProtocol_1_9_0::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x2a); // Sign Editor Open packet
+ cPacketizer Pkt(*this, GetPacketId(sendEditSign)); // Sign Editor Open packet
Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ);
}
@@ -430,7 +430,7 @@ void cProtocol_1_9_0::SendEntityEffect(const cEntity & a_Entity, int a_EffectID,
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x4c); // Entity Effect packet
+ cPacketizer Pkt(*this, GetPacketId(sendEntityEffect)); // Entity Effect packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
Pkt.WriteBEUInt8(static_cast<UInt8>(a_EffectID));
Pkt.WriteBEUInt8(static_cast<UInt8>(a_Amplifier));
@@ -446,7 +446,7 @@ void cProtocol_1_9_0::SendEntityEquipment(const cEntity & a_Entity, short a_Slot
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x3c); // Entity Equipment packet
+ cPacketizer Pkt(*this, GetPacketId(sendEntityEquipment)); // Entity Equipment packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
// Needs to be adjusted due to the insertion of offhand at slot 1
if (a_SlotNum > 0)
@@ -465,7 +465,7 @@ void cProtocol_1_9_0::SendEntityHeadLook(const cEntity & a_Entity)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x34); // Entity Head Look packet
+ cPacketizer Pkt(*this, GetPacketId(sendEntityHeadLook)); // Entity Head Look packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
Pkt.WriteByteAngle(a_Entity.GetHeadYaw());
}
@@ -478,7 +478,7 @@ void cProtocol_1_9_0::SendEntityLook(const cEntity & a_Entity)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x27); // Entity Look packet
+ cPacketizer Pkt(*this, GetPacketId(sendEntityLook)); // Entity Look packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
Pkt.WriteByteAngle(a_Entity.GetYaw());
Pkt.WriteByteAngle(a_Entity.GetPitch());
@@ -493,7 +493,7 @@ void cProtocol_1_9_0::SendEntityMetadata(const cEntity & a_Entity)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x39); // Entity Metadata packet
+ cPacketizer Pkt(*this, GetPacketId(sendEntityMeta)); // Entity Metadata packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
WriteEntityMetadata(Pkt, a_Entity);
Pkt.WriteBEUInt8(0xff); // The termination byte
@@ -507,7 +507,7 @@ void cProtocol_1_9_0::SendEntityProperties(const cEntity & a_Entity)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x4b); // Entity Properties packet
+ cPacketizer Pkt(*this, GetPacketId(sendEntityProperties)); // Entity Properties packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
WriteEntityProperties(Pkt, a_Entity);
}
@@ -520,7 +520,7 @@ void cProtocol_1_9_0::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, c
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x25); // Entity Relative Move packet
+ cPacketizer Pkt(*this, GetPacketId(sendEntityRelMove)); // Entity Relative Move packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
// TODO: 1.9 changed these from chars to shorts, meaning that there can be more percision and data. Other code needs to be updated for that.
Pkt.WriteBEInt16(a_RelX * 128);
@@ -537,7 +537,7 @@ void cProtocol_1_9_0::SendEntityRelMoveLook(const cEntity & a_Entity, char a_Rel
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x26); // Entity Look And Relative Move packet
+ cPacketizer Pkt(*this, GetPacketId(sendEntityRelMoveLook)); // Entity Look And Relative Move packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
// TODO: 1.9 changed these from chars to shorts, meaning that there can be more percision and data. Other code needs to be updated for that.
Pkt.WriteBEInt16(a_RelX * 128);
@@ -556,7 +556,7 @@ void cProtocol_1_9_0::SendEntityStatus(const cEntity & a_Entity, char a_Status)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x1b); // Entity Status packet
+ cPacketizer Pkt(*this, GetPacketId(sendEntityStatus)); // Entity Status packet
Pkt.WriteBEUInt32(a_Entity.GetUniqueID());
Pkt.WriteBEInt8(a_Status);
}
@@ -569,7 +569,7 @@ void cProtocol_1_9_0::SendEntityVelocity(const cEntity & a_Entity)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x3b); // Entity Velocity packet
+ cPacketizer Pkt(*this, GetPacketId(sendEntityVelocity)); // Entity Velocity packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
// 400 = 8000 / 20 ... Conversion from our speed in m / s to 8000 m / tick
Pkt.WriteBEInt16(static_cast<Int16>(a_Entity.GetSpeedX() * 400));
@@ -585,7 +585,7 @@ void cProtocol_1_9_0::SendExplosion(double a_BlockX, double a_BlockY, double a_B
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x1c); // Explosion packet
+ cPacketizer Pkt(*this, GetPacketId(sendExplosion)); // Explosion packet
Pkt.WriteBEFloat(static_cast<float>(a_BlockX));
Pkt.WriteBEFloat(static_cast<float>(a_BlockY));
Pkt.WriteBEFloat(static_cast<float>(a_BlockZ));
@@ -610,7 +610,7 @@ void cProtocol_1_9_0::SendGameMode(eGameMode a_GameMode)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x1e); // Change Game State packet
+ cPacketizer Pkt(*this, GetPacketId(sendGameMode)); // Change Game State packet
Pkt.WriteBEUInt8(3); // Reason: Change game mode
Pkt.WriteBEFloat(static_cast<float>(a_GameMode)); // The protocol really represents the value with a float!
}
@@ -623,7 +623,7 @@ void cProtocol_1_9_0::SendHealth(void)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x3e); // Update Health packet
+ cPacketizer Pkt(*this, GetPacketId(sendHealth)); // Update Health packet
cPlayer * Player = m_Client->GetPlayer();
Pkt.WriteBEFloat(static_cast<float>(Player->GetHealth()));
Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetFoodLevel()));
@@ -638,7 +638,7 @@ void cProtocol_1_9_0::SendHideTitle(void)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x45); // Title packet
+ cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet
Pkt.WriteVarInt32(3); // Hide title
}
@@ -650,7 +650,7 @@ void cProtocol_1_9_0::SendInventorySlot(char a_WindowID, short a_SlotNum, const
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x16); // Set Slot packet
+ cPacketizer Pkt(*this, GetPacketId(sendInventorySlot)); // Set Slot packet
Pkt.WriteBEInt8(a_WindowID);
Pkt.WriteBEInt16(a_SlotNum);
WriteItem(Pkt, a_Item);
@@ -669,7 +669,7 @@ void cProtocol_1_9_0::SendKeepAlive(UInt32 a_PingID)
return;
}
- cPacketizer Pkt(*this, 0x1f); // Keep Alive packet
+ cPacketizer Pkt(*this, GetPacketId(sendKeepAlive)); // Keep Alive packet
Pkt.WriteVarInt32(a_PingID);
}
@@ -680,7 +680,7 @@ void cProtocol_1_9_0::SendKeepAlive(UInt32 a_PingID)
void cProtocol_1_9_0::SendLeashEntity(const cEntity & a_Entity, const cEntity & a_EntityLeashedTo)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x3a); // Set Attach Entity packet
+ cPacketizer Pkt(*this, GetPacketId(sendLeashEntity)); // Set Attach Entity packet
Pkt.WriteBEUInt32(a_Entity.GetUniqueID());
Pkt.WriteBEUInt32(a_EntityLeashedTo.GetUniqueID());
}
@@ -692,7 +692,7 @@ void cProtocol_1_9_0::SendLeashEntity(const cEntity & a_Entity, const cEntity &
void cProtocol_1_9_0::SendUnleashEntity(const cEntity & a_Entity)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x3a); // Set Attach Entity packet
+ cPacketizer Pkt(*this, GetPacketId(sendLeashEntity)); // Set Attach Entity packet
Pkt.WriteBEUInt32(a_Entity.GetUniqueID());
Pkt.WriteBEInt32(-1); // Unleash a_Entity
}
@@ -706,7 +706,7 @@ void cProtocol_1_9_0::SendLogin(const cPlayer & a_Player, const cWorld & a_World
// Send the Join Game packet:
{
cServer * Server = cRoot::Get()->GetServer();
- cPacketizer Pkt(*this, 0x23); // Join Game packet
+ cPacketizer Pkt(*this, GetPacketId(sendJoinGame)); // Join Game packet
Pkt.WriteBEUInt32(a_Player.GetUniqueID());
Pkt.WriteBEUInt8(static_cast<UInt8>(a_Player.GetEffectiveGameMode()) | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4
Pkt.WriteBEInt8(static_cast<Int8>(a_World.GetDimension()));
@@ -718,13 +718,13 @@ void cProtocol_1_9_0::SendLogin(const cPlayer & a_Player, const cWorld & a_World
// Send the spawn position:
{
- cPacketizer Pkt(*this, 0x43); // Spawn Position packet
+ cPacketizer Pkt(*this, GetPacketId(sendSpawnPosition)); // Spawn Position packet
Pkt.WritePosition64(FloorC(a_World.GetSpawnX()), FloorC(a_World.GetSpawnY()), FloorC(a_World.GetSpawnZ()));
}
// Send the server difficulty:
{
- cPacketizer Pkt(*this, 0x0d); // Server difficulty packet
+ cPacketizer Pkt(*this, GetPacketId(sendDifficulty)); // Server difficulty packet
Pkt.WriteBEInt8(1);
}
@@ -765,7 +765,7 @@ void cProtocol_1_9_0::SendPaintingSpawn(const cPainting & a_Painting)
double PosY = a_Painting.GetPosY();
double PosZ = a_Painting.GetPosZ();
- cPacketizer Pkt(*this, 0x04); // Spawn Painting packet
+ cPacketizer Pkt(*this, GetPacketId(sendPaintingSpawn)); // Spawn Painting packet
Pkt.WriteVarInt32(a_Painting.GetUniqueID());
// TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now.
Pkt.WriteBEUInt64(0);
@@ -783,7 +783,7 @@ void cProtocol_1_9_0::SendMapData(const cMap & a_Map, int a_DataStartX, int a_Da
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x24); // Map packet
+ cPacketizer Pkt(*this, GetPacketId(sendMapData)); // Map packet
Pkt.WriteVarInt32(a_Map.GetID());
Pkt.WriteBEUInt8(static_cast<UInt8>(a_Map.GetScale()));
@@ -816,7 +816,7 @@ void cProtocol_1_9_0::SendPickupSpawn(const cPickup & a_Pickup)
ASSERT(m_State == 3); // In game mode?
{ // TODO Use SendSpawnObject
- cPacketizer Pkt(*this, 0x00); // Spawn Object packet
+ cPacketizer Pkt(*this, GetPacketId(sendSpawnObject)); // Spawn Object packet
Pkt.WriteVarInt32(a_Pickup.GetUniqueID());
// TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now.
Pkt.WriteBEUInt64(0);
@@ -844,7 +844,7 @@ void cProtocol_1_9_0::SendPlayerAbilities(void)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x2b); // Player Abilities packet
+ cPacketizer Pkt(*this, GetPacketId(sendPlayerAbilities)); // Player Abilities packet
Byte Flags = 0;
cPlayer * Player = m_Client->GetPlayer();
if (Player->IsGameModeCreative())
@@ -873,7 +873,7 @@ void cProtocol_1_9_0::SendEntityAnimation(const cEntity & a_Entity, char a_Anima
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x06); // Animation packet
+ cPacketizer Pkt(*this, GetPacketId(sendEntityAnimation)); // Animation packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
Pkt.WriteBEInt8(a_Animation);
}
@@ -887,7 +887,7 @@ void cProtocol_1_9_0::SendParticleEffect(const AString & a_ParticleName, float a
ASSERT(m_State == 3); // In game mode?
int ParticleID = GetParticleID(a_ParticleName);
- cPacketizer Pkt(*this, 0x22); // Particle effect packet
+ cPacketizer Pkt(*this, GetPacketId(sendParticleEffect)); // Particle effect packet
Pkt.WriteBEInt32(ParticleID);
Pkt.WriteBool(false);
Pkt.WriteBEFloat(a_SrcX);
@@ -909,7 +909,7 @@ void cProtocol_1_9_0::SendParticleEffect(const AString & a_ParticleName, Vector3
ASSERT(m_State == 3); // In game mode?
int ParticleID = GetParticleID(a_ParticleName);
- cPacketizer Pkt(*this, 0x22); // Particle effect packet
+ cPacketizer Pkt(*this, GetPacketId(sendParticleEffect)); // Particle effect packet
Pkt.WriteBEInt32(ParticleID);
Pkt.WriteBool(false);
Pkt.WriteBEFloat(a_Src.x);
@@ -952,7 +952,7 @@ void cProtocol_1_9_0::SendPlayerListAddPlayer(const cPlayer & a_Player)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x2d); // Playerlist Item packet
+ cPacketizer Pkt(*this, GetPacketId(sendPlayerList)); // Playerlist Item packet
Pkt.WriteVarInt32(0);
Pkt.WriteVarInt32(1);
Pkt.WriteUUID(a_Player.GetUUID());
@@ -989,7 +989,7 @@ void cProtocol_1_9_0::SendPlayerListRemovePlayer(const cPlayer & a_Player)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x2d); // Playerlist Item packet
+ cPacketizer Pkt(*this, GetPacketId(sendPlayerList)); // Playerlist Item packet
Pkt.WriteVarInt32(4);
Pkt.WriteVarInt32(1);
Pkt.WriteUUID(a_Player.GetUUID());
@@ -1003,7 +1003,7 @@ void cProtocol_1_9_0::SendPlayerListUpdateGameMode(const cPlayer & a_Player)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x2d); // Playerlist Item packet
+ cPacketizer Pkt(*this, GetPacketId(sendPlayerList)); // Playerlist Item packet
Pkt.WriteVarInt32(1);
Pkt.WriteVarInt32(1);
Pkt.WriteUUID(a_Player.GetUUID());
@@ -1021,7 +1021,7 @@ void cProtocol_1_9_0::SendPlayerListUpdatePing(const cPlayer & a_Player)
auto ClientHandle = a_Player.GetClientHandlePtr();
if (ClientHandle != nullptr)
{
- cPacketizer Pkt(*this, 0x2d); // Playerlist Item packet
+ cPacketizer Pkt(*this, GetPacketId(sendPlayerList)); // Playerlist Item packet
Pkt.WriteVarInt32(2);
Pkt.WriteVarInt32(1);
Pkt.WriteUUID(a_Player.GetUUID());
@@ -1037,7 +1037,7 @@ void cProtocol_1_9_0::SendPlayerListUpdateDisplayName(const cPlayer & a_Player,
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x2d); // Playerlist Item packet
+ cPacketizer Pkt(*this, GetPacketId(sendPlayerList)); // Playerlist Item packet
Pkt.WriteVarInt32(3);
Pkt.WriteVarInt32(1);
Pkt.WriteUUID(a_Player.GetUUID());
@@ -1061,7 +1061,7 @@ void cProtocol_1_9_0::SendPlayerMaxSpeed(void)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x4b); // Entity Properties
+ cPacketizer Pkt(*this, GetPacketId(sendPlayerMaxSpeed)); // Entity Properties
cPlayer * Player = m_Client->GetPlayer();
Pkt.WriteVarInt32(Player->GetUniqueID());
Pkt.WriteBEInt32(1); // Count
@@ -1090,7 +1090,7 @@ void cProtocol_1_9_0::SendPlayerMoveLook(void)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x2e); // Player Position And Look packet
+ cPacketizer Pkt(*this, GetPacketId(sendPlayerMoveLook)); // Player Position And Look packet
cPlayer * Player = m_Client->GetPlayer();
Pkt.WriteBEDouble(Player->GetPosX());
Pkt.WriteBEDouble(Player->GetPosY());
@@ -1121,7 +1121,7 @@ void cProtocol_1_9_0::SendPlayerPosition(void)
void cProtocol_1_9_0::SendPlayerSpawn(const cPlayer & a_Player)
{
// Called to spawn another player for the client
- cPacketizer Pkt(*this, 0x05); // Spawn Player packet
+ cPacketizer Pkt(*this, GetPacketId(sendPlayerSpawn)); // Spawn Player packet
Pkt.WriteVarInt32(a_Player.GetUniqueID());
Pkt.WriteUUID(a_Player.GetUUID());
Vector3d LastSentPos = a_Player.GetLastSentPos();
@@ -1142,7 +1142,7 @@ void cProtocol_1_9_0::SendPluginMessage(const AString & a_Channel, const AString
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x18); // Plugin message packet
+ cPacketizer Pkt(*this, GetPacketId(sendPluginMessage)); // Plugin message packet
Pkt.WriteString(a_Channel);
Pkt.WriteBuf(a_Message.data(), a_Message.size());
}
@@ -1155,7 +1155,7 @@ void cProtocol_1_9_0::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Eff
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x31); // Remove entity effect packet
+ cPacketizer Pkt(*this, GetPacketId(sendRemoveEntityEffect)); // Remove entity effect packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
Pkt.WriteBEUInt8(static_cast<UInt8>(a_EffectID));
}
@@ -1168,7 +1168,7 @@ void cProtocol_1_9_0::SendResetTitle(void)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x45); // Title packet
+ cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet
Pkt.WriteVarInt32(4); // Reset title
}
@@ -1178,7 +1178,7 @@ void cProtocol_1_9_0::SendResetTitle(void)
void cProtocol_1_9_0::SendRespawn(eDimension a_Dimension)
{
- cPacketizer Pkt(*this, 0x33); // Respawn packet
+ cPacketizer Pkt(*this, GetPacketId(sendRespawn)); // Respawn packet
cPlayer * Player = m_Client->GetPlayer();
Pkt.WriteBEInt32(static_cast<Int32>(a_Dimension));
Pkt.WriteBEUInt8(2); // TODO: Difficulty (set to Normal)
@@ -1194,7 +1194,7 @@ void cProtocol_1_9_0::SendExperience(void)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x3d); // Experience Packet
+ cPacketizer Pkt(*this, GetPacketId(sendExperience)); // Experience Packet
cPlayer * Player = m_Client->GetPlayer();
Pkt.WriteBEFloat(Player->GetXpPercentage());
Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetXpLevel()));
@@ -1209,7 +1209,7 @@ void cProtocol_1_9_0::SendExperienceOrb(const cExpOrb & a_ExpOrb)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x01); // Spawn experience orb packet
+ cPacketizer Pkt(*this, GetPacketId(sendExperienceOrb)); // Spawn experience orb packet
Pkt.WriteVarInt32(a_ExpOrb.GetUniqueID());
Pkt.WriteBEDouble(a_ExpOrb.GetPosX());
Pkt.WriteBEDouble(a_ExpOrb.GetPosY());
@@ -1225,7 +1225,7 @@ void cProtocol_1_9_0::SendScoreboardObjective(const AString & a_Name, const AStr
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x3f); // Scoreboard objective packet
+ cPacketizer Pkt(*this, GetPacketId(sendScoreboardObjective)); // Scoreboard objective packet
Pkt.WriteString(a_Name);
Pkt.WriteBEUInt8(a_Mode);
if ((a_Mode == 0) || (a_Mode == 2))
@@ -1243,7 +1243,7 @@ void cProtocol_1_9_0::SendScoreUpdate(const AString & a_Objective, const AString
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x42); // Update score packet
+ cPacketizer Pkt(*this, GetPacketId(sendScoreUpdate)); // Update score packet
Pkt.WriteString(a_Player);
Pkt.WriteBEUInt8(a_Mode);
Pkt.WriteString(a_Objective);
@@ -1262,7 +1262,7 @@ void cProtocol_1_9_0::SendDisplayObjective(const AString & a_Objective, cScorebo
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x38); // Display scoreboard packet
+ cPacketizer Pkt(*this, GetPacketId(sendDisplayObjective)); // Display scoreboard packet
Pkt.WriteBEUInt8(static_cast<UInt8>(a_Display));
Pkt.WriteString(a_Objective);
}
@@ -1284,7 +1284,7 @@ void cProtocol_1_9_0::SendSetRawSubTitle(const AString & a_SubTitle)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x45); // Title packet
+ cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet
Pkt.WriteVarInt32(1); // Set subtitle
Pkt.WriteString(a_SubTitle);
@@ -1307,7 +1307,7 @@ void cProtocol_1_9_0::SendSetRawTitle(const AString & a_Title)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x45); // Title packet
+ cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet
Pkt.WriteVarInt32(0); // Set title
Pkt.WriteString(a_Title);
@@ -1321,7 +1321,7 @@ void cProtocol_1_9_0::SendSoundEffect(const AString & a_SoundName, double a_X, d
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x19); // Named sound effect packet
+ cPacketizer Pkt(*this, GetPacketId(sendSoundEffect)); // Named sound effect packet
Pkt.WriteString(a_SoundName);
Pkt.WriteVarInt32(0); // Master sound category (may want to be changed to a parameter later)
Pkt.WriteBEInt32(static_cast<Int32>(a_X * 8.0));
@@ -1339,7 +1339,7 @@ void cProtocol_1_9_0::SendSoundParticleEffect(const EffectID a_EffectID, int a_S
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x21); // Effect packet
+ cPacketizer Pkt(*this, GetPacketId(sendSoundParticleEffect)); // Effect packet
Pkt.WriteBEInt32(static_cast<int>(a_EffectID));
Pkt.WritePosition64(a_SrcX, a_SrcY, a_SrcZ);
Pkt.WriteBEInt32(a_Data);
@@ -1354,7 +1354,7 @@ void cProtocol_1_9_0::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x00); // Spawn Object packet
+ cPacketizer Pkt(*this, GetPacketId(sendSpawnObject)); // Spawn Object packet
Pkt.WriteVarInt32(a_FallingBlock.GetUniqueID());
// TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now.
Pkt.WriteBEUInt64(0);
@@ -1380,7 +1380,7 @@ void cProtocol_1_9_0::SendSpawnMob(const cMonster & a_Mob)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x03); // Spawn Mob packet
+ cPacketizer Pkt(*this, GetPacketId(sendSpawnMob)); // Spawn Mob packet
Pkt.WriteVarInt32(a_Mob.GetUniqueID());
// TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now.
Pkt.WriteBEUInt64(0);
@@ -1415,7 +1415,7 @@ void cProtocol_1_9_0::SendSpawnObject(const cEntity & a_Entity, char a_ObjectTyp
FixItemFramePositions(a_ObjectData, PosX, PosZ, Yaw);
}
- cPacketizer Pkt(*this, 0x00); // Spawn Object packet
+ cPacketizer Pkt(*this, GetPacketId(sendSpawnObject)); // Spawn Object packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
// TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now.
Pkt.WriteBEUInt64(0);
@@ -1440,7 +1440,7 @@ void cProtocol_1_9_0::SendSpawnVehicle(const cEntity & a_Vehicle, char a_Vehicle
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x00); // Spawn Object packet
+ cPacketizer Pkt(*this, GetPacketId(sendSpawnObject)); // Spawn Object packet
Pkt.WriteVarInt32(a_Vehicle.GetUniqueID());
// TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now.
Pkt.WriteBEUInt64(0);
@@ -1466,7 +1466,7 @@ void cProtocol_1_9_0::SendStatistics(const cStatManager & a_Manager)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x07); // Statistics packet
+ cPacketizer Pkt(*this, GetPacketId(sendStatistics)); // Statistics packet
Pkt.WriteVarInt32(statCount); // TODO 2014-05-11 xdot: Optimization: Send "dirty" statistics only
size_t Count = static_cast<size_t>(statCount);
@@ -1488,7 +1488,7 @@ void cProtocol_1_9_0::SendTabCompletionResults(const AStringVector & a_Results)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x0e); // Tab-Complete packet
+ cPacketizer Pkt(*this, GetPacketId(sendTabCompletion)); // Tab-Complete packet
Pkt.WriteVarInt32(static_cast<UInt32>(a_Results.size()));
for (AStringVector::const_iterator itr = a_Results.begin(), end = a_Results.end(); itr != end; ++itr)
@@ -1505,7 +1505,7 @@ void cProtocol_1_9_0::SendTeleportEntity(const cEntity & a_Entity)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x4a); // Entity teleport packet
+ cPacketizer Pkt(*this, GetPacketId(sendTeleportEntity)); // Entity teleport packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
Pkt.WriteBEDouble(a_Entity.GetPosX());
Pkt.WriteBEDouble(a_Entity.GetPosY());
@@ -1523,7 +1523,7 @@ void cProtocol_1_9_0::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x02); // Spawn Global Entity packet
+ cPacketizer Pkt(*this, GetPacketId(sendSpawnGlobalEntity)); // Spawn Global Entity packet
Pkt.WriteVarInt32(0); // EntityID = 0, always
Pkt.WriteBEUInt8(1); // Type = Thunderbolt
Pkt.WriteBEDouble(a_BlockX);
@@ -1539,7 +1539,7 @@ void cProtocol_1_9_0::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x45); // Title packet
+ cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet
Pkt.WriteVarInt32(2); // Set title display times
Pkt.WriteBEInt32(a_FadeInTicks);
@@ -1560,7 +1560,7 @@ void cProtocol_1_9_0::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a
a_TimeOfDay = std::min(-a_TimeOfDay, -1LL);
}
- cPacketizer Pkt(*this, 0x44); // Time update packet
+ cPacketizer Pkt(*this, GetPacketId(sendTimeUpdate)); // Time update packet
Pkt.WriteBEInt64(a_WorldAge);
Pkt.WriteBEInt64(a_TimeOfDay);
}
@@ -1573,7 +1573,7 @@ void cProtocol_1_9_0::SendUnloadChunk(int a_ChunkX, int a_ChunkZ)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x1d); // Unload chunk packet
+ cPacketizer Pkt(*this, GetPacketId(sendUnloadChunk)); // Unload chunk packet
Pkt.WriteBEInt32(a_ChunkX);
Pkt.WriteBEInt32(a_ChunkZ);
}
@@ -1585,7 +1585,7 @@ void cProtocol_1_9_0::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x09); // Update tile entity packet
+ cPacketizer Pkt(*this, GetPacketId(sendUpdateBlockEntity)); // Update tile entity packet
Pkt.WritePosition64(a_BlockEntity.GetPosX(), a_BlockEntity.GetPosY(), a_BlockEntity.GetPosZ());
Byte Action = 0;
@@ -1612,7 +1612,7 @@ void cProtocol_1_9_0::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, c
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x46); // Update sign packet
+ cPacketizer Pkt(*this, GetPacketId(sendUpdateSign)); // Update sign packet
Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ);
Json::StyledWriter JsonWriter;
@@ -1633,7 +1633,7 @@ void cProtocol_1_9_0::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_B
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x2f); // Use bed
+ cPacketizer Pkt(*this, GetPacketId(sendUseBed)); // Use bed
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ);
}
@@ -1647,7 +1647,7 @@ void cProtocol_1_9_0::SendWeather(eWeather a_Weather)
ASSERT(m_State == 3); // In game mode?
{
- cPacketizer Pkt(*this, 0x1e); // Change Game State packet
+ cPacketizer Pkt(*this, GetPacketId(sendWeather)); // Change Game State packet
Pkt.WriteBEUInt8((a_Weather == wSunny) ? 1 : 2); // End rain / begin rain
Pkt.WriteBEFloat(0); // Unused for weather
}
@@ -1663,7 +1663,7 @@ void cProtocol_1_9_0::SendWholeInventory(const cWindow & a_Window)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x14); // Window Items packet
+ cPacketizer Pkt(*this, GetPacketId(sendWindowItems)); // Window Items packet
Pkt.WriteBEInt8(a_Window.GetWindowID());
Pkt.WriteBEInt16(static_cast<Int16>(a_Window.GetNumSlots()));
cItems Slots;
@@ -1682,7 +1682,7 @@ void cProtocol_1_9_0::SendWindowClose(const cWindow & a_Window)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x12); // Close window packet
+ cPacketizer Pkt(*this, GetPacketId(sendWindowClose)); // Close window packet
Pkt.WriteBEInt8(a_Window.GetWindowID());
}
@@ -1700,7 +1700,7 @@ void cProtocol_1_9_0::SendWindowOpen(const cWindow & a_Window)
return;
}
- cPacketizer Pkt(*this, 0x13); // Open window packet
+ cPacketizer Pkt(*this, GetPacketId(sendWindowOpen)); // Open window packet
Pkt.WriteBEInt8(a_Window.GetWindowID());
Pkt.WriteString(a_Window.GetWindowTypeName());
Pkt.WriteString(Printf("{\"text\":\"%s\"}", a_Window.GetWindowTitle().c_str()));
@@ -1735,7 +1735,7 @@ void cProtocol_1_9_0::SendWindowProperty(const cWindow & a_Window, short a_Prope
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x15); // Window Property packet
+ cPacketizer Pkt(*this, GetPacketId(sendWindowProperty)); // Window Property packet
Pkt.WriteBEInt8(a_Window.GetWindowID());
Pkt.WriteBEInt16(a_Property);
Pkt.WriteBEInt16(a_Value);
@@ -4175,10 +4175,10 @@ void cProtocol_1_9_1::SendLogin(const cPlayer & a_Player, const cWorld & a_World
// Send the Join Game packet:
{
cServer * Server = cRoot::Get()->GetServer();
- cPacketizer Pkt(*this, 0x23); // Join Game packet
+ cPacketizer Pkt(*this, GetPacketId(sendJoinGame)); // Join Game packet
Pkt.WriteBEUInt32(a_Player.GetUniqueID());
Pkt.WriteBEUInt8(static_cast<UInt8>(a_Player.GetEffectiveGameMode()) | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4
- Pkt.WriteBEInt32(static_cast<Int32>(a_World.GetDimension()));
+ Pkt.WriteBEInt32(static_cast<Int32>(a_World.GetDimension())); // This is the change from 1.9.0 (Int8 to Int32)
Pkt.WriteBEUInt8(2); // TODO: Difficulty (set to Normal)
Pkt.WriteBEUInt8(static_cast<UInt8>(Clamp<size_t>(Server->GetMaxPlayers(), 0, 255)));
Pkt.WriteString("default"); // Level type - wtf?
@@ -4187,13 +4187,13 @@ void cProtocol_1_9_1::SendLogin(const cPlayer & a_Player, const cWorld & a_World
// Send the spawn position:
{
- cPacketizer Pkt(*this, 0x43); // Spawn Position packet
+ cPacketizer Pkt(*this, GetPacketId(sendSpawnPosition)); // Spawn Position packet
Pkt.WritePosition64(FloorC(a_World.GetSpawnX()), FloorC(a_World.GetSpawnY()), FloorC(a_World.GetSpawnZ()));
}
// Send the server difficulty:
{
- cPacketizer Pkt(*this, 0x0d); // Server difficulty packet
+ cPacketizer Pkt(*this, GetPacketId(sendDifficulty)); // Server difficulty packet
Pkt.WriteBEInt8(1);
}
@@ -4367,20 +4367,6 @@ void cProtocol_1_9_4::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
-void cProtocol_1_9_4::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, int a_Count)
-{
- UNUSED(a_Count);
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x48); // Collect Item packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- Pkt.WriteVarInt32(a_Player.GetUniqueID());
-}
-
-
-
-
-
void cProtocol_1_9_4::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer)
{
ASSERT(m_State == 3); // In game mode?
@@ -4397,83 +4383,6 @@ void cProtocol_1_9_4::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerial
-void cProtocol_1_9_4::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x4b); // Entity Effect packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- Pkt.WriteBEUInt8(static_cast<UInt8>(a_EffectID));
- Pkt.WriteBEUInt8(static_cast<UInt8>(a_Amplifier));
- Pkt.WriteVarInt32(static_cast<UInt32>(a_Duration));
- Pkt.WriteBool(false); // Hide particles
-}
-
-
-
-
-
-void cProtocol_1_9_4::SendEntityProperties(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
-
-
- cPacketizer Pkt(*this, 0x4a); // Entity Properties packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- WriteEntityProperties(Pkt, a_Entity);
-}
-
-
-
-
-
-void cProtocol_1_9_4::SendPlayerMaxSpeed(void)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x4a); // Entity Properties
- cPlayer * Player = m_Client->GetPlayer();
- Pkt.WriteVarInt32(Player->GetUniqueID());
- Pkt.WriteBEInt32(1); // Count
- Pkt.WriteString("generic.movementSpeed");
- // The default game speed is 0.1, multiply that value by the relative speed:
- Pkt.WriteBEDouble(0.1 * Player->GetNormalMaxSpeed());
- if (Player->IsSprinting())
- {
- Pkt.WriteVarInt32(1); // Modifier count
- Pkt.WriteBEUInt64(0x662a6b8dda3e4c1c);
- Pkt.WriteBEUInt64(0x881396ea6097278d); // UUID of the modifier
- Pkt.WriteBEDouble(Player->GetSprintingMaxSpeed() - Player->GetNormalMaxSpeed());
- Pkt.WriteBEUInt8(2);
- }
- else
- {
- Pkt.WriteVarInt32(0); // Modifier count
- }
-}
-
-
-
-
-
-void cProtocol_1_9_4::SendTeleportEntity(const cEntity & a_Entity)
-{
- ASSERT(m_State == 3); // In game mode?
-
- cPacketizer Pkt(*this, 0x49); // Entity teleport packet
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- Pkt.WriteBEDouble(a_Entity.GetPosX());
- Pkt.WriteBEDouble(a_Entity.GetPosY());
- Pkt.WriteBEDouble(a_Entity.GetPosZ());
- Pkt.WriteByteAngle(a_Entity.GetYaw());
- Pkt.WriteByteAngle(a_Entity.GetPitch());
- Pkt.WriteBool(a_Entity.IsOnGround());
-}
-
-
-
-
-
void cProtocol_1_9_4::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)
{
ASSERT(m_State == 3); // In game mode?
diff --git a/src/Protocol/Protocol_1_9.h b/src/Protocol/Protocol_1_9.h
index 3fbbe86da..200f10004 100644
--- a/src/Protocol/Protocol_1_9.h
+++ b/src/Protocol/Protocol_1_9.h
@@ -51,6 +51,9 @@ public:
cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
+ /** Get the packet ID for a given packet */
+ virtual UInt32 GetPacketId(eOutgoingPackets a_Packet) override;
+
/** Called when client sends some data: */
virtual void DataReceived(const char * a_Data, size_t a_Size) override;
@@ -336,13 +339,10 @@ class cProtocol_1_9_4 :
public:
cProtocol_1_9_4(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
+ virtual UInt32 GetPacketId(eOutgoingPackets a_Packet) override;
+
// cProtocol_1_9_2 overrides:
- virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player, int a_Count) override;
virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
- virtual void SendEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) override;
- virtual void SendEntityProperties(const cEntity & a_Entity) override;
- virtual void SendPlayerMaxSpeed (void) override;
- virtual void SendTeleportEntity (const cEntity & a_Entity) override;
virtual void 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) override;
virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) override;