From 2b48f586aac6f15cb4e2c80bcf3a8eaeb8abda75 Mon Sep 17 00:00:00 2001 From: tycho Date: Sun, 8 Nov 2015 21:19:20 +0000 Subject: More Networking reffacor --- src/Protocol/LengthenedProtocol.cpp | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/Protocol/LengthenedProtocol.cpp') 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> & 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(cClientAction::Type::Name)); + +cProtocol::cProtocolError cLengthenedProtocol::HandleHandshake(cByteBuffer & a_ByteBuffer, std::vector> & 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; +} + -- cgit v1.2.3