summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ClientAction.h28
-rw-r--r--src/Protocol/DataSender.h8
-rw-r--r--src/Protocol/LengthenedProtocol.cpp39
-rw-r--r--src/Protocol/LengthenedProtocol.h17
-rw-r--r--src/Protocol/Protocol.h9
-rw-r--r--src/Protocol/Protocol17x.cpp159
-rw-r--r--src/Protocol/Protocol17x.h10
-rw-r--r--src/Protocol/Protocol18x.cpp201
-rw-r--r--src/Protocol/Protocol18x.h68
-rw-r--r--src/Protocol/ProtocolRecognizer.h7
10 files changed, 289 insertions, 257 deletions
diff --git a/src/ClientAction.h b/src/ClientAction.h
index 1844d14c6..33360aaa2 100644
--- a/src/ClientAction.h
+++ b/src/ClientAction.h
@@ -20,7 +20,33 @@ public:
StatsRequest,
Achivement,
CreativeInventory,
- SetProtocolVersion
+ SetProtocolVersion,
+ KeepAlive,
+ UseEntity,
+ PlayerPos,
+ PlayerLook,
+ SlotSelected,
+ EntityCrouch,
+ EntityLeaveBed,
+ EntitySprinting,
+ Unmount,
+ SteerVehicle,
+ WindowClose,
+ WindowClick,
+ EnchantItem,
+ UpdateSign,
+ PlayerAbilities,
+ TabComplete,
+ PluginMessage,
+ CommandBlockChange,
+ UnhandledCommandBlockCommand,
+ SetBrand,
+ BeaconSelection,
+ AnvilItemName,
+ NPCTrade,
+ SetIPString,
+ SetUUID,
+ SetProperties
};
cClientAction(Type a_Type) : m_Type(a_Type) {}
diff --git a/src/Protocol/DataSender.h b/src/Protocol/DataSender.h
new file mode 100644
index 000000000..64d5007ab
--- /dev/null
+++ b/src/Protocol/DataSender.h
@@ -0,0 +1,8 @@
+#pragma once
+
+class cDataSender
+{
+public:
+ virtual ~cDataSender() = default;
+ virtual void SendData(const char * a_DataToSend, size_t a_Size) = 0;
+};
diff --git a/src/Protocol/LengthenedProtocol.cpp b/src/Protocol/LengthenedProtocol.cpp
index 7a6c5918f..8e16b7db2 100644
--- a/src/Protocol/LengthenedProtocol.cpp
+++ b/src/Protocol/LengthenedProtocol.cpp
@@ -1,5 +1,6 @@
#include "Globals.h"
#include "LengthenedProtocol.h"
+#include "ClientAction.h"
cProtocol::cProtocolError cLengthenedProtocol::DataReceived(const char * a_Data, size_t a_Size, std::vector<std::unique_ptr<cClientAction>> & a_Actions)
{
@@ -85,3 +86,41 @@ cProtocol::cProtocolError cLengthenedProtocol::AddReceivedData(const char * a_Da
}
return cProtocolError::Success;
}
+
+#define ADD_SIMPLE_ACTION(Name) a_Action.push_back(cpp14::make_unique<cSimpleAction>(cClientAction::Type::Name));
+
+cProtocol::cProtocolError cLengthenedProtocol::HandleHandshake(cByteBuffer & a_ByteBuffer, std::vector<std::unique_ptr<cClientAction>> & a_Action)
+{
+ // these need to replace the values provided to the constructor in the old version
+ if (!a_ByteBuffer.ReadVarUTF8String(m_ServerAddress))
+ {
+ return cProtocolError::PacketReadError;
+ }
+ if (!a_ByteBuffer.ReadBEUInt16(m_ServerPort))
+ {
+ return cProtocolError::PacketReadError;
+ }
+ if (!a_ByteBuffer.ReadVarInt(m_State))
+ {
+ return cProtocolError::PacketReadError;
+ }
+ a_ByteBuffer.CommitRead();
+
+ // BungeeCord handling:
+ // If BC is setup with ip_forward == true, it sends additional data in the login packet's ServerAddress field:
+ // hostname\00ip-address\00uuid\00profile-properties-as-json
+ AStringVector Params;
+ if (m_ShouldAllowBungeeCord && SplitZeroTerminatedStrings(m_ServerAddress, Params) && (Params.size() == 4))
+ {
+ LOGD("Player at %s connected via BungeeCord", Params[1].c_str());
+ m_ServerAddress = Params[0];
+ //a_Client->SetIPString(Params[1]);
+ //a_Client->SetUUID(cMojangAPI::MakeUUIDShort(Params[2]));
+ //a_Client->SetProperties(Params[3]);
+ ADD_SIMPLE_ACTION(SetIPString);
+ ADD_SIMPLE_ACTION(SetUUID);
+ ADD_SIMPLE_ACTION(SetProperties);
+ }
+ return cProtocolError::Success;
+}
+
diff --git a/src/Protocol/LengthenedProtocol.h b/src/Protocol/LengthenedProtocol.h
index a6e72fe05..3f1a89a66 100644
--- a/src/Protocol/LengthenedProtocol.h
+++ b/src/Protocol/LengthenedProtocol.h
@@ -2,6 +2,8 @@
#pragma once
#include "Protocol.h"
+
+class cDataSender;
extern void undefined();
class cLengthenedProtocol : public cProtocol
@@ -19,11 +21,26 @@ public:
cProtocolError HandleHandshake(cByteBuffer & a_ByteBuffer, std::vector<std::unique_ptr<cClientAction>> & a_Actions) override WARN_UNUSED;
protected:
+
+
+ /** State of the protocol. 1 = status, 2 = login, 3 = game */
+ UInt32 m_State;
+
virtual cProtocolError DataReceived(const char * a_Data, size_t a_Size, std::vector<std::unique_ptr<cClientAction>> & a_Actions) override WARN_UNUSED;
/** This method should append the actions from incoming packets to a_Action */
virtual cProtocolError OnDataAddedToBuffer(cByteBuffer & a_Buffer, std::vector<std::unique_ptr<cClientAction>> & a_Action) WARN_UNUSED = 0;
+ virtual void SendData(const char * a_Data, size_t a_Size) = 0;
+
+ cDataSender * m_Sender;
+
private:
+
+ AString m_ServerAddress;
+
+ UInt16 m_ServerPort;
+
+ bool m_ShouldAllowBungeeCord;
/** Buffer for the received data */
cByteBuffer m_ReceivedData;
diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h
index 303278fcc..22825bd2b 100644
--- a/src/Protocol/Protocol.h
+++ b/src/Protocol/Protocol.h
@@ -73,7 +73,8 @@ public:
// We send a kick packet in response to a process error
PacketProcessError,
NotCompleted,
- UnsupportedProtocol
+ UnsupportedProtocol,
+ BadCompression
};
cProtocol(AString a_LogID) :
@@ -181,6 +182,8 @@ public:
/** Returns the ServerID used for authentication through session.minecraft.net */
virtual AString GetAuthServerID(void) = 0;
+
+ // Handle the initial handshake packets, called by cProtocolRecognizer after recognising the packet
virtual cProtocolError HandleHandshake(cByteBuffer & a_ByteBuffer, std::vector<std::unique_ptr<cClientAction>> & a_Actions) WARN_UNUSED = 0;
protected:
@@ -204,11 +207,11 @@ protected:
/** A generic data-sending routine, all outgoing packet data needs to be routed through this so that descendants may override it. */
- //virtual void SendData(cByteBuffer & a_ByteBuffer, const char * a_Data, size_t a_Size) = 0;
+ //virtual void SendData(const char * a_Data, size_t a_Size) = 0;
/** Sends a single packet contained within the cPacketizer class.
The cPacketizer's destructor calls this to send the contained packet; protocol may transform the data (compression in 1.8 etc). */
- //virtual void SendPacket(cPacketizer & a_Packet) = 0;
+ virtual void SendPacket(cPacketizer & a_Packet) = 0;
/** The logfile where the comm is logged, when g_ShouldLogComm is true */
cFile m_CommLogFile;
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 1ed5a864b..614b20584 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -15,6 +15,7 @@ Implements the 1.7.x protocol classes:
#include "ChunkDataSerializer.h"
#include "PolarSSL++/Sha1Checksum.h"
#include "Packetizer.h"
+#include "DataSender.h"
#include "../ClientHandle.h"
#include "../Root.h"
@@ -52,7 +53,7 @@ Implements the 1.7.x protocol classes:
/** The slot number that the client uses to indicate "outside the window". */
-//static const Int16 SLOT_NUM_OUTSIDE = -999;
+static const Int16 SLOT_NUM_OUTSIDE = -999;
@@ -94,18 +95,6 @@ cProtocol172::cProtocol172(const AString a_LogID) :
m_LastSentDimension(dimNotSet)
{
/*
- // BungeeCord handling:
- // If BC is setup with ip_forward == true, it sends additional data in the login packet's ServerAddress field:
- // hostname\00ip-address\00uuid\00profile-properties-as-json
- AStringVector Params;
- if (cRoot::Get()->GetServer()->ShouldAllowBungeeCord() && SplitZeroTerminatedStrings(a_ServerAddress, Params) && (Params.size() == 4))
- {
- LOGD("Player at %s connected via BungeeCord", Params[1].c_str());
- m_ServerAddress = Params[0];
- a_Client->SetIPString(Params[1]);
- a_Client->SetUUID(cMojangAPI::MakeUUIDShort(Params[2]));
- a_Client->SetProperties(Params[3]);
- }
*/
}
@@ -1991,7 +1980,7 @@ cProtocol::cProtocolError cProtocol172::HandlePacketCreativeInventoryAction(cByt
-/*
+
cProtocol::cProtocolError cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer, ActionList & a_Action)
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt32, UInt32, PlayerID);
@@ -2000,12 +1989,15 @@ cProtocol::cProtocolError cProtocol172::HandlePacketEntityAction(cByteBuffer & a
switch (Action)
{
- case 1: m_Client->HandleEntityCrouch(PlayerID, true); break; // Crouch
- case 2: m_Client->HandleEntityCrouch(PlayerID, false); break; // Uncrouch
- case 3: m_Client->HandleEntityLeaveBed(PlayerID); break; // Leave Bed
- case 4: m_Client->HandleEntitySprinting(PlayerID, true); break; // Start sprinting
- case 5: m_Client->HandleEntitySprinting(PlayerID, false); break; // Stop sprinting
+ case 1: ADD_SIMPLE_ACTION(EntityCrouch); break; //m_Client->HandleEntityCrouch(PlayerID, true); break; // Crouch
+ case 2: ADD_SIMPLE_ACTION(EntityCrouch); break; //m_Client->HandleEntityCrouch(PlayerID, false); break; // Uncrouch
+ case 3: ADD_SIMPLE_ACTION(EntityLeaveBed); break; //m_Client->HandleEntityLeaveBed(PlayerID); break; // Leave Bed
+ case 4: ADD_SIMPLE_ACTION(EntitySprinting) break; //m_Client->HandleEntitySprinting(PlayerID, true); break; // Start sprinting
+ case 5: ADD_SIMPLE_ACTION(EntitySprinting) break; //m_Client->HandleEntitySprinting(PlayerID, false); break; // Stop sprinting
+ default:
+ return cProtocolError::PacketReadError;
}
+ return cProtocolError::Success;
}
@@ -2015,7 +2007,9 @@ cProtocol::cProtocolError cProtocol172::HandlePacketEntityAction(cByteBuffer & a
cProtocol::cProtocolError cProtocol172::HandlePacketKeepAlive(cByteBuffer & a_ByteBuffer, ActionList & a_Action)
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt32, UInt32, KeepAliveID);
- m_Client->HandleKeepAlive(KeepAliveID);
+ //m_Client->HandleKeepAlive(KeepAliveID);
+ ADD_SIMPLE_ACTION(KeepAlive);
+ return cProtocolError::Success;
}
@@ -2026,6 +2020,7 @@ cProtocol::cProtocolError cProtocol172::HandlePacketPlayer(cByteBuffer & a_ByteB
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBool, bool, IsOnGround);
// TODO: m_Client->HandlePlayerOnGround(IsOnGround);
+ return cProtocolError::Success;
}
@@ -2049,7 +2044,9 @@ cProtocol::cProtocolError cProtocol172::HandlePacketPlayerAbilities(cByteBuffer
CanFly = true;
}
- m_Client->HandlePlayerAbilities(CanFly, IsFlying, FlyingSpeed, WalkingSpeed);
+ //m_Client->HandlePlayerAbilities(CanFly, IsFlying, FlyingSpeed, WalkingSpeed);
+ ADD_SIMPLE_ACTION(PlayerAbilities);
+ return cProtocolError::Success;
}
@@ -2061,7 +2058,9 @@ cProtocol::cProtocolError cProtocol172::HandlePacketPlayerLook(cByteBuffer & a_B
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEFloat, float, Yaw);
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEFloat, float, Pitch);
HANDLE_PACKET_READ(a_ByteBuffer, ReadBool, bool, IsOnGround);
- m_Client->HandlePlayerLook(Yaw, Pitch, IsOnGround);
+ //m_Client->HandlePlayerLook(Yaw, Pitch, IsOnGround);
+ ADD_SIMPLE_ACTION(PlayerLook);
+ return cProtocolError::Success;
}
@@ -2075,7 +2074,9 @@ cProtocol::cProtocolError cProtocol172::HandlePacketPlayerPos(cByteBuffer & a_By
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEDouble, double, Stance);
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEDouble, double, PosZ);
HANDLE_PACKET_READ(a_ByteBuffer, ReadBool, bool, IsOnGround);
- m_Client->HandlePlayerPos(PosX, PosY, PosZ, Stance, IsOnGround);
+ //m_Client->HandlePlayerPos(PosX, PosY, PosZ, Stance, IsOnGround);
+ ADD_SIMPLE_ACTION(PlayerPos);
+ return cProtocolError::Success;
}
@@ -2091,7 +2092,10 @@ cProtocol::cProtocolError cProtocol172::HandlePacketPlayerPosLook(cByteBuffer &
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEFloat, float, Yaw);
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEFloat, float, Pitch);
HANDLE_PACKET_READ(a_ByteBuffer, ReadBool, bool, IsOnGround);
- m_Client->HandlePlayerMoveLook(PosX, PosY, PosZ, Stance, Yaw, Pitch, IsOnGround);
+ //m_Client->HandlePlayerMoveLook(PosX, PosY, PosZ, Stance, Yaw, Pitch, IsOnGround);
+ ADD_SIMPLE_ACTION(PlayerPos);
+ ADD_SIMPLE_ACTION(PlayerLook);
+ return cProtocolError::Success;
}
@@ -2107,23 +2111,24 @@ cProtocol::cProtocolError cProtocol172::HandlePacketPluginMessage(cByteBuffer &
LOGD("Invalid plugin message packet, payload length doesn't match packet length (exp %u, got %u)",
static_cast<unsigned>(a_ByteBuffer.GetReadableSpace() - 1), Length
);
- return;
+ return cProtocolError::PacketReadError;
}
// If the plugin channel is recognized vanilla, handle it directly:
if (Channel.substr(0, 3) == "MC|")
{
- HandleVanillaPluginMessage(a_ByteBuffer, Channel, Length);
- return;
+ return HandleVanillaPluginMessage(a_ByteBuffer, Channel, Length, a_Action);
}
// Read the plugin message and relay to clienthandle:
AString Data;
if (!a_ByteBuffer.ReadString(Data, Length))
{
- return;
+ return cProtocolError::PacketReadError;
}
- m_Client->HandlePluginMessage(Channel, Data);
+ //m_Client->HandlePluginMessage(Channel, Data);
+ ADD_SIMPLE_ACTION(PluginMessage);
+ return cProtocolError::Success;
}
@@ -2133,7 +2138,9 @@ cProtocol::cProtocolError cProtocol172::HandlePacketPluginMessage(cByteBuffer &
cProtocol::cProtocolError cProtocol172::HandlePacketSlotSelect(cByteBuffer & a_ByteBuffer, ActionList & a_Action)
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum);
- m_Client->HandleSlotSelected(SlotNum);
+ //m_Client->HandleSlotSelected(SlotNum);
+ ADD_SIMPLE_ACTION(SlotSelected);
+ return cProtocolError::Success;
}
@@ -2148,12 +2155,15 @@ cProtocol::cProtocolError cProtocol172::HandlePacketSteerVehicle(cByteBuffer & a
HANDLE_PACKET_READ(a_ByteBuffer, ReadBool, bool, ShouldUnmount);
if (ShouldUnmount)
{
- m_Client->HandleUnmount();
+ //m_Client->HandleUnmount();
+ ADD_SIMPLE_ACTION(Unmount);
}
else
{
- m_Client->HandleSteerVehicle(Forward, Sideways);
+ //m_Client->HandleSteerVehicle(Forward, Sideways);
+ ADD_SIMPLE_ACTION(SteerVehicle);
}
+ return cProtocolError::Success;
}
@@ -2163,14 +2173,16 @@ cProtocol::cProtocolError cProtocol172::HandlePacketSteerVehicle(cByteBuffer & a
cProtocol::cProtocolError cProtocol172::HandlePacketTabComplete(cByteBuffer & a_ByteBuffer, ActionList & a_Action)
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadVarUTF8String, AString, Text);
- m_Client->HandleTabCompletion(Text);
+ //m_Client->HandleTabCompletion(Text);
+ ADD_SIMPLE_ACTION(TabComplete);
+ return cProtocolError::Success;
}
-cProtocol::cProtocolError cProtocol172::HandlePacketUpdateSign(cByteBuffer & a_ByteBuffer)
+cProtocol::cProtocolError cProtocol172::HandlePacketUpdateSign(cByteBuffer & a_ByteBuffer, ActionList & a_Action)
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX);
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, BlockY);
@@ -2179,37 +2191,43 @@ cProtocol::cProtocolError cProtocol172::HandlePacketUpdateSign(cByteBuffer & a_B
HANDLE_PACKET_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line2);
HANDLE_PACKET_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line3);
HANDLE_PACKET_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line4);
- m_Client->HandleUpdateSign(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4);
+ //m_Client->HandleUpdateSign(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4);
+ ADD_SIMPLE_ACTION(UpdateSign);
+ return cProtocolError::Success;
}
-cProtocol::cProtocolError cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer)
+cProtocol::cProtocolError cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer, ActionList & a_Action)
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt32, UInt32, EntityID);
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, MouseButton);
- m_Client->HandleUseEntity(EntityID, (MouseButton == 1));
+ //m_Client->HandleUseEntity(EntityID, (MouseButton == 1));
+ ADD_SIMPLE_ACTION(UseEntity);
+ return cProtocolError::Success;
}
-cProtocol::cProtocolError cProtocol172::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer)
+cProtocol::cProtocolError cProtocol172::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer, ActionList & a_Action)
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID);
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Enchantment);
- m_Client->HandleEnchantItem(WindowID, Enchantment);
+ //m_Client->HandleEnchantItem(WindowID, Enchantment);
+ ADD_SIMPLE_ACTION(EnchantItem);
+ return cProtocolError::Success;
}
-cProtocol::cProtocolError cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
+cProtocol::cProtocolError cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer, ActionList & a_Action)
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID);
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum);
@@ -2254,24 +2272,28 @@ cProtocol::cProtocolError cProtocol172::HandlePacketWindowClick(cByteBuffer & a_
}
}
- m_Client->HandleWindowClick(WindowID, SlotNum, Action, Item);
+ //m_Client->HandleWindowClick(WindowID, SlotNum, Action, Item);
+ ADD_SIMPLE_ACTION(WindowClick);
+ return cProtocolError::Success;
}
-cProtocol::cProtocolError cProtocol172::HandlePacketWindowClose(cByteBuffer & a_ByteBuffer)
+cProtocol::cProtocolError cProtocol172::HandlePacketWindowClose(cByteBuffer & a_ByteBuffer, ActionList & a_Action)
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID);
- m_Client->HandleWindowClose(WindowID);
+ //m_Client->HandleWindowClose(WindowID);
+ ADD_SIMPLE_ACTION(WindowClose);
+ return cProtocolError::Success;
}
-void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const AString & a_Channel, UInt16 a_PayloadLength)
+cProtocol::cProtocolError cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const AString & a_Channel, UInt16 a_PayloadLength, ActionList & a_Action)
{
if (a_Channel == "MC|AdvCdm")
{
@@ -2286,7 +2308,8 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockY);
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ);
HANDLE_PACKET_READ(a_ByteBuffer, ReadVarUTF8String, AString, Command);
- m_Client->HandleCommandBlockBlockChange(BlockX, BlockY, BlockZ, Command);
+ //m_Client->HandleCommandBlockBlockChange(BlockX, BlockY, BlockZ, Command);
+ ADD_SIMPLE_ACTION(CommandBlockChange);
break;
}
@@ -2294,9 +2317,10 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
default:
{
- m_Client->SendChat(Printf("Failure setting command block command; unhandled mode %d", Mode), mtFailure);
+ //m_Client->SendChat(Printf("Failure setting command block command; unhandled mode %d", Mode), mtFailure);
LOG("Unhandled MC|AdvCdm packet mode.");
- return;
+ ADD_SIMPLE_ACTION(UnhandledCommandBlockCommand);
+ return cProtocolError::Success;
}
} // switch (Mode)
@@ -2309,7 +2333,7 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
);
a_ByteBuffer.SkipRead(a_PayloadLength - BytesRead);
}
- return;
+ return cProtocolError::Success;
}
else if (a_Channel == "MC|Brand")
{
@@ -2317,41 +2341,47 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
AString Brand;
if (a_ByteBuffer.ReadString(Brand, a_PayloadLength))
{
- m_Client->SetClientBrand(Brand);
+ //m_Client->SetClientBrand(Brand);
+ ADD_SIMPLE_ACTION(SetBrand);
}
// Send back our brand:
SendPluginMessage("MC|Brand", "Cuberite");
- return;
+ return cProtocolError::Success;
}
else if (a_Channel == "MC|Beacon")
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect1);
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect2);
- m_Client->HandleBeaconSelection(Effect1, Effect2);
- return;
+ //m_Client->HandleBeaconSelection(Effect1, Effect2);
+ ADD_SIMPLE_ACTION(BeaconSelection);
+ return cProtocolError::Success;
}
else if (a_Channel == "MC|ItemName")
{
AString ItemName;
if (a_ByteBuffer.ReadString(ItemName, a_PayloadLength))
{
- m_Client->HandleAnvilItemName(ItemName);
+ //m_Client->HandleAnvilItemName(ItemName);
+ ADD_SIMPLE_ACTION(AnvilItemName);
}
- return;
+ return cProtocolError::Success;
}
else if (a_Channel == "MC|TrSel")
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, SlotNum);
- m_Client->HandleNPCTrade(SlotNum);
- return;
+ //m_Client->HandleNPCTrade(SlotNum);
+ ADD_SIMPLE_ACTION(NPCTrade);
+ return cProtocolError::Success;
}
LOG("Unhandled vanilla plugin channel: \"%s\".", a_Channel.c_str());
// Read the payload and send it through to the clienthandle:
AString Message;
VERIFY(a_ByteBuffer.ReadString(Message, a_PayloadLength));
- m_Client->HandlePluginMessage(a_Channel, Message);
+ //m_Client->HandlePluginMessage(a_Channel, Message);
+ ADD_SIMPLE_ACTION(PluginMessage);
+ return cProtocolError::Success;
}
@@ -2367,14 +2397,14 @@ void cProtocol172::SendData(const char * a_Data, size_t a_Size)
{
size_t NumBytes = (a_Size > sizeof(Encrypted)) ? sizeof(Encrypted) : a_Size;
m_Encryptor.ProcessData(Encrypted, reinterpret_cast<const Byte *>(a_Data), NumBytes);
- m_Client->SendData(reinterpret_cast<const char *>(Encrypted), NumBytes);
+ m_Sender->SendData(reinterpret_cast<const char *>(Encrypted), NumBytes);
a_Size -= NumBytes;
a_Data += NumBytes;
}
}
else
{
- m_Client->SendData(a_Data, a_Size);
+ m_Sender->SendData(a_Data, a_Size);
}
}
@@ -2391,6 +2421,7 @@ void cProtocol172::SendPacket(cPacketizer & a_Packet)
m_OutPacketLenBuffer.WriteVarInt32(PacketLen);
m_OutPacketLenBuffer.ReadAll(DataToSend);
+ // TODO: Fix this to some how send data to the clients buffers
SendData(DataToSend.data(), DataToSend.size());
m_OutPacketLenBuffer.CommitRead();
@@ -2414,7 +2445,7 @@ void cProtocol172::SendPacket(cPacketizer & a_Packet)
-*/
+
cProtocol::cProtocolError cProtocol172::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item)
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemType);
@@ -2450,7 +2481,7 @@ cProtocol::cProtocolError cProtocol172::ReadItem(cByteBuffer & a_ByteBuffer, cIt
-/*
+
void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata)
{
// Uncompress the GZIPped data:
@@ -2557,7 +2588,7 @@ void cProtocol172::StartEncryption(const Byte * a_Key)
-
+/*
eBlockFace cProtocol172::FaceIntToBlockFace(Int8 a_BlockFace)
{
// Normalize the blockface values returned from the protocol
@@ -2577,7 +2608,7 @@ eBlockFace cProtocol172::FaceIntToBlockFace(Int8 a_BlockFace)
-
+*/
void cProtocol172::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item)
{
short ItemType = a_Item.m_ItemType;
@@ -2753,7 +2784,7 @@ void cProtocol172::WriteBlockEntity(cPacketizer & a_Pkt, const cBlockEntity & a_
a_Pkt.WriteBEUInt16(static_cast<UInt16>(Compressed.size()));
a_Pkt.WriteBuf(Compressed.data(), Compressed.size());
}
-*/
+
diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h
index 8e85880b3..cd7cc22c5 100644
--- a/src/Protocol/Protocol17x.h
+++ b/src/Protocol/Protocol17x.h
@@ -41,6 +41,7 @@ namespace Json
{
class Value;
}
+class cDataSender;
@@ -144,14 +145,9 @@ protected:
typedef std::vector<std::unique_ptr<cClientAction>> ActionList;
- AString m_ServerAddress;
-
- UInt16 m_ServerPort;
AString m_AuthServerID;
- /** State of the protocol. 1 = status, 2 = login, 3 = game */
- UInt32 m_State;
/** The dimension that was last sent to a player in a Respawn or Login packet.
Used to avoid Respawning into the same dimension, which confuses the client. */
@@ -197,10 +193,10 @@ protected:
/** Parses Vanilla plugin messages into specific ClientHandle calls.
The message payload is still in the bytebuffer, to be read by this function. */
- void HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const AString & a_Channel, UInt16 a_PayloadLength);
+ cProtocolError HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const AString & a_Channel, UInt16 a_PayloadLength, ActionList & a_Action) WARN_UNUSED;
/** Sends the data to the client, encrypting them if needed. */
- //virtual void SendData(cByteBuffer & a_Buffer, const char * a_Data, size_t a_Size) override;
+ virtual void SendData(const char * a_Data, size_t a_Size) override;
/** Sends the packet to the client. Called by the cPacketizer's destructor. */
virtual void SendPacket(cPacketizer & a_Packet) override;
diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp
index 8c39d168e..9fe23e88f 100644
--- a/src/Protocol/Protocol18x.cpp
+++ b/src/Protocol/Protocol18x.cpp
@@ -13,7 +13,6 @@ Implements the 1.8.x protocol classes:
#include "json/json.h"
#include "zlib/zlib.h"
#include "Protocol18x.h"
-#if 0
#include "ChunkDataSerializer.h"
#include "PolarSSL++/Sha1Checksum.h"
#include "Packetizer.h"
@@ -49,18 +48,18 @@ Implements the 1.8.x protocol classes:
#include "../BlockEntities/MobSpawnerEntity.h"
#include "../BlockEntities/FlowerPotEntity.h"
#include "Bindings/PluginManager.h"
+#include "DataSender.h"
-
+#if 0
/** The slot number that the client uses to indicate "outside the window". */
static const Int16 SLOT_NUM_OUTSIDE = -999;
-
#define HANDLE_READ(ByteBuf, Proc, Type, Var) \
Type Var; \
if (!ByteBuf.Proc(Var))\
@@ -68,7 +67,7 @@ static const Int16 SLOT_NUM_OUTSIDE = -999;
return;\
}
-
+#endif
@@ -82,8 +81,7 @@ static const Int16 SLOT_NUM_OUTSIDE = -999;
} \
ByteBuf.CheckValid(); \
}
-
-
+#if 0
const int MAX_ENC_LEN = 512; // Maximum size of the encrypted message; should be 128, but who knows...
@@ -93,7 +91,6 @@ const uLongf MAX_COMPRESSED_PACKET_LEN = 200 KiB; // Maximum size of compressed
-
// fwd: main.cpp:
extern bool g_ShouldLogCommIn, g_ShouldLogCommOut;
@@ -142,30 +139,6 @@ cProtocol180::cProtocol180(const AString a_LogID) :
}
#endif
}
-#if 0
-
-
-
-
-void cProtocol180::DataReceived(const char * a_Data, size_t a_Size)
-{
- if (m_IsEncrypted)
- {
- Byte Decrypted[512];
- while (a_Size > 0)
- {
- size_t NumBytes = (a_Size > sizeof(Decrypted)) ? sizeof(Decrypted) : a_Size;
- m_Decryptor.ProcessData(Decrypted, reinterpret_cast<const Byte *>(a_Data), NumBytes);
- AddReceivedData(reinterpret_cast<const char *>(Decrypted), NumBytes);
- a_Size -= NumBytes;
- a_Data += NumBytes;
- }
- }
- else
- {
- AddReceivedData(a_Data, a_Size);
- }
-}
@@ -317,7 +290,7 @@ void cProtocol180::SendDestroyEntity(const cEntity & a_Entity)
-void cProtocol180::SendDisconnect(const AString & a_Reason)
+void cProtocol180::SendDisconnect(AString & a_Buffer, const AString & a_Reason)
{
switch (m_State)
{
@@ -545,10 +518,9 @@ void cProtocol180::SendHealth(int a_Health, int a_FoodLevel, double a_FoodSatura
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, 0x06); // 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()));
+ Pkt.WriteBEFloat(static_cast<float>(a_Health));
+ Pkt.WriteVarInt32(static_cast<UInt32>(a_FoodLevel));
+ Pkt.WriteBEFloat(static_cast<float>(a_FoodSaturationLevel));
}
@@ -627,13 +599,13 @@ void cProtocol180::SendLogin(const cPlayer & a_Player, const cWorld & a_World)
}
// Send player abilities:
- SendPlayerAbilities();
+ SendPlayerAbilities(a_Player);
}
-void cProtocol180::SendLoginSuccess(void)
+void cProtocol180::SendLoginSuccess(const AString & a_UUID, const AString & a_Username)
{
ASSERT(m_State == 2); // State: login?
@@ -647,8 +619,8 @@ void cProtocol180::SendLoginSuccess(void)
{
cPacketizer Pkt(*this, 0x02); // Login success packet
- Pkt.WriteString(cMojangAPI::MakeUUIDDashed(m_Client->GetUUID()));
- Pkt.WriteString(m_Client->GetUsername());
+ Pkt.WriteString(cMojangAPI::MakeUUIDDashed(a_UUID));
+ Pkt.WriteString(a_Username);
}
}
@@ -734,29 +706,28 @@ void cProtocol180::SendPickupSpawn(const cPickup & a_Pickup)
-void cProtocol180::SendPlayerAbilities(const cPlayer const * a_Player)
+void cProtocol180::SendPlayerAbilities(const cPlayer & a_Player)
{
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, 0x39); // Player Abilities packet
Byte Flags = 0;
- cPlayer * Player = m_Client->GetPlayer();
- if (Player->IsGameModeCreative())
+ if (a_Player.IsGameModeCreative())
{
Flags |= 0x01;
Flags |= 0x08; // Godmode, used for creative
}
- if (Player->IsFlying())
+ if (a_Player.IsFlying())
{
Flags |= 0x02;
}
- if (Player->CanFly())
+ if (a_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()));
+ Pkt.WriteBEFloat(static_cast<float>(0.05 * a_Player.GetFlyingMaxSpeed()));
+ Pkt.WriteBEFloat(static_cast<float>(0.1 * a_Player.GetNormalMaxSpeed()));
}
@@ -951,23 +922,22 @@ void cProtocol180::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, con
-void cProtocol180::SendPlayerMaxSpeed(void)
+void cProtocol180::SendPlayerMaxSpeed(const cPlayer & a_Player)
{
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, 0x20); // Entity Properties
- cPlayer * Player = m_Client->GetPlayer();
- Pkt.WriteVarInt32(Player->GetUniqueID());
+ Pkt.WriteVarInt32(a_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.WriteBEDouble(0.1 * a_Player.GetNormalMaxSpeed());
+ if (a_Player.IsSprinting())
{
Pkt.WriteVarInt32(1); // Modifier count
Pkt.WriteBEUInt64(0x662a6b8dda3e4c1c);
Pkt.WriteBEUInt64(0x881396ea6097278d); // UUID of the modifier
- Pkt.WriteBEDouble(Player->GetSprintingMaxSpeed() - Player->GetNormalMaxSpeed());
+ Pkt.WriteBEDouble(a_Player.GetSprintingMaxSpeed() - a_Player.GetNormalMaxSpeed());
Pkt.WriteBEUInt8(2);
}
else
@@ -980,17 +950,16 @@ void cProtocol180::SendPlayerMaxSpeed(void)
-void cProtocol180::SendPlayerMoveLook(void)
+void cProtocol180::SendPlayerMoveLook(const cPlayer & a_Player)
{
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, 0x08); // 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.WriteBEDouble(a_Player.GetPosX());
+ Pkt.WriteBEDouble(a_Player.GetPosY());
+ Pkt.WriteBEDouble(a_Player.GetPosZ());
+ Pkt.WriteBEFloat(static_cast<float>(a_Player.GetYaw()));
+ Pkt.WriteBEFloat(static_cast<float>(a_Player.GetPitch()));
Pkt.WriteBEUInt8(0);
}
@@ -998,10 +967,10 @@ void cProtocol180::SendPlayerMoveLook(void)
-void cProtocol180::SendPlayerPosition(void)
+void cProtocol180::SendPlayerPosition(const cPlayer & a_Player)
{
// There is no dedicated packet for this, send the whole thing:
- SendPlayerMoveLook();
+ SendPlayerMoveLook(a_Player);
}
@@ -1079,10 +1048,9 @@ void cProtocol180::SendRespawn(eGameMode a_GameMode, eDimension a_Dimension, boo
}
cPacketizer Pkt(*this, 0x07); // 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.WriteBEUInt8(static_cast<Byte>(a_GameMode));
Pkt.WriteString("default");
m_LastSentDimension = a_Dimension;
}
@@ -1091,15 +1059,14 @@ void cProtocol180::SendRespawn(eGameMode a_GameMode, eDimension a_Dimension, boo
-void cProtocol180::SendExperience(void)
+void cProtocol180::SendExperience(const cPlayer & a_Player)
{
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, 0x1f); // 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()));
+ Pkt.WriteBEFloat(a_Player.GetXpPercentage());
+ Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetXpLevel()));
+ Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetCurrentXp()));
}
@@ -1552,7 +1519,7 @@ void cProtocol180::SendWeather(eWeather a_Weather)
-void cProtocol180::SendWholeInventory(const cWindow & a_Window)
+void cProtocol180::SendWholeInventory(const cPlayer & a_Player, const cWindow & a_Window)
{
ASSERT(m_State == 3); // In game mode?
@@ -1560,7 +1527,7 @@ void cProtocol180::SendWholeInventory(const cWindow & a_Window)
Pkt.WriteBEInt8(a_Window.GetWindowID());
Pkt.WriteBEInt16(static_cast<Int16>(a_Window.GetNumSlots()));
cItems Slots;
- a_Window.GetSlots(*(m_Client->GetPlayer()), Slots);
+ a_Window.GetSlots(a_Player, Slots);
for (cItems::const_iterator itr = Slots.begin(), end = Slots.end(); itr != end; ++itr)
{
WriteItem(Pkt, *itr);
@@ -1635,7 +1602,6 @@ void cProtocol180::SendWindowProperty(const cWindow & a_Window, short a_Property
}
-#endif
bool cProtocol180::CompressPacket(const AString & a_Packet, AString & a_CompressedData)
@@ -1777,45 +1743,13 @@ void cProtocol180::FixItemFramePositions(int a_ObjectData, double & a_PosX, doub
}
}
}
+#endif
-
-void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size)
+cProtocol::cProtocolError cProtocol180::OnDataAddedToBuffer(cByteBuffer & a_Buffer, ActionList & a_Action)
{
- // Write the incoming data into the comm log file:
- if (g_ShouldLogCommIn && m_CommLogFile.IsOpen())
- {
- if (m_ReceivedData.GetReadableSpace() > 0)
- {
- AString AllData;
- size_t OldReadableSpace = m_ReceivedData.GetReadableSpace();
- m_ReceivedData.ReadAll(AllData);
- m_ReceivedData.ResetRead();
- m_ReceivedData.SkipRead(m_ReceivedData.GetReadableSpace() - OldReadableSpace);
- ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace);
- AString Hex;
- CreateHexDump(Hex, AllData.data(), AllData.size(), 16);
- m_CommLogFile.Printf("Incoming data, " SIZE_T_FMT " (0x" SIZE_T_FMT_HEX ") unparsed bytes already present in buffer:\n%s\n",
- AllData.size(), AllData.size(), Hex.c_str()
- );
- }
- AString Hex;
- CreateHexDump(Hex, a_Data, a_Size, 16);
- m_CommLogFile.Printf("Incoming data: %u (0x%x) bytes: \n%s\n",
- static_cast<unsigned>(a_Size), static_cast<unsigned>(a_Size), Hex.c_str()
- );
- m_CommLogFile.Flush();
- }
-
- if (!m_ReceivedData.Write(a_Data, a_Size))
- {
- // Too much data in the incoming queue, report to caller:
- m_Client->PacketBufferFull();
- return;
- }
-
// Handle all complete packets:
for (;;)
{
@@ -1842,8 +1776,8 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size)
m_ReceivedData.ReadVarInt(CompressedSize);
if (CompressedSize > PacketLen)
{
- m_Client->Kick("Bad compression");
- return;
+ //m_Client->Kick("Bad compression");
+ return cProtocolError::BadCompression;
}
if (CompressedSize > 0)
{
@@ -1851,8 +1785,8 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size)
AString CompressedData;
if (!m_ReceivedData.ReadString(CompressedData, CompressedSize) || (InflateString(CompressedData.data(), CompressedSize, UncompressedData) != Z_OK))
{
- m_Client->Kick("Compression failure");
- return;
+ //m_Client->Kick("Compression failure");
+ return cProtocolError::BadCompression;
}
PacketLen = static_cast<UInt32>(UncompressedData.size());
}
@@ -1926,7 +1860,7 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size)
m_CommLogFile.Printf("^^^^^^ Unhandled packet ^^^^^^\n\n\n");
}
- return;
+ return cProtocolError::Success;
}
// The packet should have 1 byte left in the buffer - the NUL we had added
@@ -1947,32 +1881,16 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size)
}
ASSERT(!"Read wrong number of bytes!");
- m_Client->PacketError(PacketType);
+ //m_Client->PacketError(PacketType);
+ return cProtocolError::PacketError;
}
} // for (ever)
-
- // Log any leftover bytes into the logfile:
- if (g_ShouldLogCommIn && (m_ReceivedData.GetReadableSpace() > 0) && m_CommLogFile.IsOpen())
- {
- AString AllData;
- size_t OldReadableSpace = m_ReceivedData.GetReadableSpace();
- m_ReceivedData.ReadAll(AllData);
- m_ReceivedData.ResetRead();
- m_ReceivedData.SkipRead(m_ReceivedData.GetReadableSpace() - OldReadableSpace);
- ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace);
- AString Hex;
- CreateHexDump(Hex, AllData.data(), AllData.size(), 16);
- m_CommLogFile.Printf("There are " SIZE_T_FMT " (0x" SIZE_T_FMT_HEX ") bytes of non-parse-able data left in the buffer:\n%s",
- m_ReceivedData.GetReadableSpace(), m_ReceivedData.GetReadableSpace(), Hex.c_str()
- );
- m_CommLogFile.Flush();
- }
+ return cProtocolError::Success;
}
-
-bool cProtocol180::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType)
+cProtocol::cProtocolError cProtocol180::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType)
{
switch (m_State)
{
@@ -2050,14 +1968,14 @@ bool cProtocol180::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType)
} // switch (m_State)
// Unknown packet type, report to the ClientHandle:
- m_Client->PacketUnknown(a_PacketType);
- return false;
+ //m_Client->PacketUnknown(a_PacketType);
+ return cProtocolError::PacketUnknown;
}
-
+#if 0
void cProtocol180::HandlePacketStatusPing(cByteBuffer & a_ByteBuffer)
{
HANDLE_READ(a_ByteBuffer, ReadBEInt64, Int64, Timestamp);
@@ -2724,7 +2642,7 @@ void cProtocol180::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
VERIFY(a_ByteBuffer.ReadString(Message, a_ByteBuffer.GetReadableSpace() - 1));
m_Client->HandlePluginMessage(a_Channel, Message);
}
-
+#endif
@@ -2738,21 +2656,20 @@ void cProtocol180::SendData(const char * a_Data, size_t a_Size)
{
size_t NumBytes = (a_Size > sizeof(Encrypted)) ? sizeof(Encrypted) : a_Size;
m_Encryptor.ProcessData(Encrypted, reinterpret_cast<Byte *>(const_cast<char*>(a_Data)), NumBytes);
- m_Client->SendData(reinterpret_cast<const char *>(Encrypted), NumBytes);
+ m_Sender->SendData(reinterpret_cast<const char *>(Encrypted), NumBytes);
a_Size -= NumBytes;
a_Data += NumBytes;
}
}
else
{
- m_Client->SendData(a_Data, a_Size);
+ m_Sender->SendData(a_Data, a_Size);
}
}
-
bool cProtocol180::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes)
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemType);
@@ -2787,7 +2704,6 @@ bool cProtocol180::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a
-
void cProtocol180::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata)
{
// Parse into NBT:
@@ -2862,7 +2778,7 @@ void cProtocol180::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata)
-
+#if 0
void cProtocol180::StartEncryption(const Byte * a_Key)
{
m_Encryptor.Init(a_Key, a_Key);
@@ -2900,7 +2816,7 @@ eBlockFace cProtocol180::FaceIntToBlockFace(Int8 a_BlockFace)
default: return BLOCK_FACE_NONE;
}
}
-
+#endif
@@ -2965,7 +2881,6 @@ void cProtocol180::SendPacket(cPacketizer & a_Pkt)
-
void cProtocol180::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item)
{
short ItemType = a_Item.m_ItemType;
@@ -3053,7 +2968,7 @@ void cProtocol180::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item)
-
+#if 0
void cProtocol180::WriteBlockEntity(cPacketizer & a_Pkt, const cBlockEntity & a_BlockEntity)
{
cFastNBTWriter Writer;
diff --git a/src/Protocol/Protocol18x.h b/src/Protocol/Protocol18x.h
index 5e5ee0cda..e33d79257 100644
--- a/src/Protocol/Protocol18x.h
+++ b/src/Protocol/Protocol18x.h
@@ -52,6 +52,7 @@ class cProtocol180 :
public cLengthenedProtocol
{
typedef cLengthenedProtocol super;
+ typedef std::vector<std::unique_ptr<cClientAction>> ActionList;
public:
@@ -154,15 +155,8 @@ public:
protected:
- AString m_ServerAddress;
-
- UInt16 m_ServerPort;
-
AString m_AuthServerID;
- /** State of the protocol. 1 = status, 2 = login, 3 = game */
- UInt32 m_State;
-
/** Buffer for the received data */
cByteBuffer m_ReceivedData;
@@ -181,40 +175,40 @@ protected:
/** Reads and handles the packet. The packet length and type have already been read.
Returns true if the packet was understood, false if it was an unknown packet
*/
- bool HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType);
+ cProtocolError HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType, ActionList & a_Action) WARN_UNUSED;
// Packet handlers while in the Status state (m_State == 1):
- void HandlePacketStatusPing(cByteBuffer & a_ByteBuffer);
- void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer);
+ cProtocolError HandlePacketStatusPing(cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
// Packet handlers while in the Login state (m_State == 2):
- void HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer);
- void HandlePacketLoginStart(cByteBuffer & a_ByteBuffer);
+ cProtocolError HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketLoginStart(cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
// Packet handlers while in the Game state (m_State == 3):
- void HandlePacketAnimation (cByteBuffer & a_ByteBuffer);
- void HandlePacketBlockDig (cByteBuffer & a_ByteBuffer);
- void HandlePacketBlockPlace (cByteBuffer & a_ByteBuffer);
- void HandlePacketChatMessage (cByteBuffer & a_ByteBuffer);
- void HandlePacketClientSettings (cByteBuffer & a_ByteBuffer);
- void HandlePacketClientStatus (cByteBuffer & a_ByteBuffer);
- void HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffer);
- void HandlePacketEntityAction (cByteBuffer & a_ByteBuffer);
- void HandlePacketKeepAlive (cByteBuffer & a_ByteBuffer);
- void HandlePacketPlayer (cByteBuffer & a_ByteBuffer);
- void HandlePacketPlayerAbilities (cByteBuffer & a_ByteBuffer);
- void HandlePacketPlayerLook (cByteBuffer & a_ByteBuffer);
- void HandlePacketPlayerPos (cByteBuffer & a_ByteBuffer);
- void HandlePacketPlayerPosLook (cByteBuffer & a_ByteBuffer);
- void HandlePacketPluginMessage (cByteBuffer & a_ByteBuffer);
- void HandlePacketSlotSelect (cByteBuffer & a_ByteBuffer);
- void HandlePacketSteerVehicle (cByteBuffer & a_ByteBuffer);
- void HandlePacketTabComplete (cByteBuffer & a_ByteBuffer);
- void HandlePacketUpdateSign (cByteBuffer & a_ByteBuffer);
- void HandlePacketUseEntity (cByteBuffer & a_ByteBuffer);
- void HandlePacketEnchantItem (cByteBuffer & a_ByteBuffer);
- void HandlePacketWindowClick (cByteBuffer & a_ByteBuffer);
- void HandlePacketWindowClose (cByteBuffer & a_ByteBuffer);
+ cProtocolError HandlePacketAnimation (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketBlockDig (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketBlockPlace (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketChatMessage (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketClientSettings (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketClientStatus (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketEntityAction (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketKeepAlive (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketPlayer (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketPlayerAbilities (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketPlayerLook (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketPlayerPos (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketPlayerPosLook (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketPluginMessage (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketSlotSelect (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketSteerVehicle (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketTabComplete (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketUpdateSign (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketUseEntity (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketEnchantItem (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketWindowClick (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
+ cProtocolError HandlePacketWindowClose (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED;
/** Parses Vanilla plugin messages into specific ClientHandle calls.
The message payload is still in the bytebuffer, the handler reads it specifically for each handled channel */
@@ -222,10 +216,10 @@ protected:
/** Sends the data to the client, encrypting them if needed. */
- //virtual void SendData(cByteBuffer & a_ByteBuffer, const char * a_Data, size_t a_Size) override;
+ virtual void SendData(const char * a_Data, size_t a_Size) override;
/** Sends the packet to the client. Called by the cPacketizer's destructor. */
- //virtual void SendPacket(cPacketizer & a_Packet) override;
+ virtual void SendPacket(cPacketizer & a_Packet) override;
void SendCompass(const cWorld & a_World);
diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h
index 7f1758463..744a691ed 100644
--- a/src/Protocol/ProtocolRecognizer.h
+++ b/src/Protocol/ProtocolRecognizer.h
@@ -132,8 +132,11 @@ public:
//virtual void SendData(const char * a_Data, size_t a_Size) override;
- cProtocolError HandleHandshake(cByteBuffer & a_ByteBuffer, std::vector<std::unique_ptr<cClientAction>> & a_Actions) override WARN_UNUSED;
-
+ cProtocolError HandleHandshake(cByteBuffer & a_ByteBuffer, std::vector<std::unique_ptr<cClientAction>> & a_Actions) override WARN_UNUSED
+ {
+ ASSERT(!"cProtocolRecognizer should be decoding the handshake packet");
+ return cProtocolError::PacketError;
+ }
protected:
/** The recognized protocol */
std::unique_ptr<cProtocol> m_Protocol;