1
0

1.6.2 protocol implemented, both in MCServer and in ProtoProxy

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1669 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2013-07-08 12:59:15 +00:00
parent a40585ec99
commit 791bf732fd
8 changed files with 158 additions and 2 deletions

View File

@ -12,6 +12,16 @@
#ifdef _DEBUG
#define DebugSleep Sleep
#else
#define DebugSleep(X)
#endif // else _DEBUG
#define HANDLE_CLIENT_PACKET_READ(Proc, Type, Var) \
Type Var; \
{ \
@ -47,6 +57,7 @@
{ \
SERVERENCRYPTSEND(ToServer.data(), ToServer.size()); \
} \
DebugSleep(50); \
}
#define COPY_TO_CLIENT() \
@ -61,6 +72,7 @@
{ \
CLIENTENCRYPTSEND(ToClient.data(), ToClient.size()); \
} \
DebugSleep(50); \
}
#define HANDLE_CLIENT_READ(Proc) \
@ -159,6 +171,7 @@ enum
PACKET_INCREMENT_STATISTIC = 0xc8,
PACKET_LOCALE_AND_VIEW = 0xcc,
PACKET_CLIENT_STATUSES = 0xcd,
PACKET_PLUGIN_MESSAGE = 0xfa,
PACKET_ENCRYPTION_KEY_RESPONSE = 0xfc,
PACKET_ENCRYPTION_KEY_REQUEST = 0xfd,
PACKET_PING = 0xfe,
@ -211,6 +224,7 @@ cConnection::cConnection(SOCKET a_ClientSocket, cServer & a_Server) :
fnam.append(".log");
m_LogFile = fopen(fnam.c_str(), "w");
Log("Log file created");
printf("Connection is logged to file \"%s\"\n", fnam.c_str());
}
@ -537,6 +551,7 @@ bool cConnection::DecodeClientsPackets(const char * a_Data, int a_Size)
case PACKET_PLAYER_ON_GROUND: HANDLE_CLIENT_READ(HandleClientPlayerOnGround); break;
case PACKET_PLAYER_POSITION: HANDLE_CLIENT_READ(HandleClientPlayerPosition); break;
case PACKET_PLAYER_POSITION_LOOK: HANDLE_CLIENT_READ(HandleClientPlayerPositionLook); break;
case PACKET_PLUGIN_MESSAGE: HANDLE_CLIENT_READ(HandleClientPluginMessage); break;
case PACKET_SLOT_SELECT: HANDLE_CLIENT_READ(HandleClientSlotSelect); break;
case PACKET_UPDATE_SIGN: HANDLE_CLIENT_READ(HandleClientUpdateSign); break;
case PACKET_USE_ENTITY: HANDLE_CLIENT_READ(HandleClientUseEntity); break;
@ -636,6 +651,7 @@ bool cConnection::DecodeServersPackets(const char * a_Data, int a_Size)
case PACKET_PLAYER_ANIMATION: HANDLE_SERVER_READ(HandleServerPlayerAnimation); break;
case PACKET_PLAYER_LIST_ITEM: HANDLE_SERVER_READ(HandleServerPlayerListItem); break;
case PACKET_PLAYER_POSITION_LOOK: HANDLE_SERVER_READ(HandleServerPlayerPositionLook); break;
case PACKET_PLUGIN_MESSAGE: HANDLE_SERVER_READ(HandleServerPluginMessage); break;
case PACKET_SET_EXPERIENCE: HANDLE_SERVER_READ(HandleServerSetExperience); break;
case PACKET_SET_SLOT: HANDLE_SERVER_READ(HandleServerSetSlot); break;
case PACKET_SLOT_SELECT: HANDLE_SERVER_READ(HandleServerSlotSelect); break;
@ -997,6 +1013,26 @@ bool cConnection::HandleClientPlayerPositionLook(void)
bool cConnection::HandleClientPluginMessage(void)
{
HANDLE_CLIENT_PACKET_READ(ReadBEUTF16String16, AString, ChannelName);
HANDLE_CLIENT_PACKET_READ(ReadBEShort, short, Length);
AString Data;
if (!m_ClientBuffer.ReadString(Data, Length))
{
return false;
}
Log("Received a PACKET_PLUGIN_MESSAGE from the client");
Log(" ChannelName = \"%s\"", ChannelName.c_str());
DataLog(Data.data(), Length, " Data: %d bytes", Length);
COPY_TO_SERVER();
return true;
}
bool cConnection::HandleClientSlotSelect(void)
{
HANDLE_CLIENT_PACKET_READ(ReadBEShort, short, SlotNum);
@ -1351,12 +1387,24 @@ bool cConnection::HandleServerEntityProperties(void)
Log("Received a PACKET_ENTITY_PROPERTIES from the server:");
Log(" EntityID = %d", EntityID);
Log(" Count = %d", Count);
for (int i = 0; i < Count; i++)
{
HANDLE_SERVER_PACKET_READ(ReadBEUTF16String16, AString, Key);
HANDLE_SERVER_PACKET_READ(ReadBEDouble, double, Value);
Log(" \"%s\" = %f", Key.c_str(), Value);
} // for i
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, ListLength);
Log(" ListLength = %d", ListLength);
for (int i = 0; i < ListLength; i++)
{
HANDLE_SERVER_PACKET_READ(ReadBEInt64, Int64, UUIDHi);
HANDLE_SERVER_PACKET_READ(ReadBEInt64, Int64, UUIDLo);
HANDLE_SERVER_PACKET_READ(ReadBEDouble, double, DblVal);
HANDLE_SERVER_PACKET_READ(ReadByte, Byte, ByteVal);
Log(" [%d] = {0x%08llx%08llx, %f, %i}", i, UUIDHi, UUIDLo, DblVal, ByteVal);
} // for i
COPY_TO_CLIENT();
return true;
}
@ -1741,6 +1789,26 @@ bool cConnection::HandleServerPlayerPositionLook(void)
bool cConnection::HandleServerPluginMessage(void)
{
HANDLE_SERVER_PACKET_READ(ReadBEUTF16String16, AString, ChannelName);
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, Length);
AString Data;
if (!m_ServerBuffer.ReadString(Data, Length))
{
return false;
}
Log("Received a PACKET_PLUGIN_MESSAGE from the server");
Log(" ChannelName = \"%s\"", ChannelName.c_str());
DataLog(Data.data(), Length, " Data: %d bytes", Length);
COPY_TO_SERVER();
return true;
}
bool cConnection::HandleServerSetExperience(void)
{
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, ExperienceBar);

View File

@ -122,6 +122,7 @@ protected:
bool HandleClientPlayerOnGround(void);
bool HandleClientPlayerPosition(void);
bool HandleClientPlayerPositionLook(void);
bool HandleClientPluginMessage(void);
bool HandleClientSlotSelect(void);
bool HandleClientUpdateSign(void);
bool HandleClientUseEntity(void);
@ -162,6 +163,7 @@ protected:
bool HandleServerPlayerAnimation(void);
bool HandleServerPlayerListItem(void);
bool HandleServerPlayerPositionLook(void);
bool HandleServerPluginMessage(void);
bool HandleServerSetExperience(void);
bool HandleServerSetSlot(void);
bool HandleServerSlotSelect(void);

View File

@ -86,6 +86,7 @@ enum
PACKET_UPDATE_SIGN = 0x82,
PACKET_PLAYER_LIST_ITEM = 0xC9,
PACKET_PLAYER_ABILITIES = 0xca,
PACKET_PLUGIN_MESSAGE = 0xfa,
PACKET_PING = 0xfe,
PACKET_DISCONNECT = 0xff
} ;
@ -1039,6 +1040,7 @@ int cProtocol125::ParsePacket(unsigned char a_PacketType)
case PACKET_PLAYER_MOVE_LOOK: return ParsePlayerMoveLook();
case PACKET_PLAYER_ON_GROUND: return ParsePlayerOnGround();
case PACKET_PLAYER_POS: return ParsePlayerPosition();
case PACKET_PLUGIN_MESSAGE: return ParsePluginMessage();
case PACKET_RESPAWN: return ParseRespawn();
case PACKET_SLOT_SELECTED: return ParseSlotSelected();
case PACKET_UPDATE_SIGN: return ParseUpdateSign();
@ -1330,6 +1332,28 @@ int cProtocol125::ParsePlayerPosition(void)
int cProtocol125::ParsePluginMessage(void)
{
HANDLE_PACKET_READ(ReadBEUTF16String16, AString, ChannelName);
HANDLE_PACKET_READ(ReadBEShort, short, Length);
AString Data;
if (!m_ReceivedData.ReadString(Data, Length))
{
m_ReceivedData.CheckValid();
return PARSE_INCOMPLETE;
}
m_ReceivedData.CheckValid();
// TODO: Process the data
LOGD("Received %d bytes of plugin data on channel \"%s\".", Length, ChannelName.c_str());
return PARSE_OK;
}
int cProtocol125::ParseRespawn(void)
{
HANDLE_PACKET_READ(ReadBEInt, int, Dimension);

View File

@ -119,6 +119,7 @@ protected:
virtual int ParsePlayerMoveLook (void);
virtual int ParsePlayerOnGround (void);
virtual int ParsePlayerPosition (void);
virtual int ParsePluginMessage (void);
virtual int ParseRespawn (void);
virtual int ParseSlotSelected (void);
virtual int ParseUpdateSign (void);

View File

@ -5,6 +5,8 @@
Implements the 1.6.x protocol classes:
- cProtocol161
- release 1.6.1 protocol (#73)
- cProtocol162
- release 1.6.2 protocol (#74)
(others may be added later in the future for the 1.6 release series)
*/
@ -48,6 +50,8 @@ enum
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cProtocol161:
cProtocol161::cProtocol161(cClientHandle * a_Client) :
super(a_Client)
@ -200,3 +204,31 @@ int cProtocol161::ParsePacket(unsigned char a_PacketType)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cProtocol162:
cProtocol162::cProtocol162(cClientHandle * a_Client) :
super(a_Client)
{
}
void cProtocol162::SendPlayerMaxSpeed(void)
{
cCSLock Lock(m_CSPacket);
WriteByte(PACKET_ENTITY_PROPERTIES);
WriteInt(m_Client->GetPlayer()->GetUniqueID());
WriteInt(1);
WriteString("generic.movementSpeed");
WriteDouble(m_Client->GetPlayer()->GetMaxSpeed());
WriteShort(0);
Flush();
}

View File

@ -5,6 +5,8 @@
Declares the 1.6.x protocol classes:
- cProtocol161
- release 1.6.1 protocol (#73)
- cProtocol162
- release 1.6.2 protocol (#74)
(others may be added later in the future for the 1.6 release series)
*/
@ -28,6 +30,8 @@ class cProtocol161 :
public:
cProtocol161(cClientHandle * a_Client);
protected:
// cProtocol150 overrides:
virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override;
virtual void SendChat (const AString & a_Message) override;
@ -49,3 +53,20 @@ public:
class cProtocol162 :
public cProtocol161
{
typedef cProtocol161 super;
public:
cProtocol162(cClientHandle * a_Client);
protected:
// cProtocol161 overrides:
virtual void SendPlayerMaxSpeed(void) override;
} ;

View File

@ -53,6 +53,7 @@ AString cProtocolRecognizer::GetVersionTextFromInt(int a_ProtocolVersion)
case PROTO_VERSION_1_5_0: return "1.5";
case PROTO_VERSION_1_5_2: return "1.5.2";
case PROTO_VERSION_1_6_1: return "1.6.1";
case PROTO_VERSION_1_6_2: return "1.6.2";
}
ASSERT(!"Unknown protocol version");
return Printf("Unknown protocol (%d)", a_ProtocolVersion);
@ -684,6 +685,11 @@ bool cProtocolRecognizer::TryRecognizeProtocol(void)
m_Protocol = new cProtocol161(m_Client);
return true;
}
case PROTO_VERSION_1_6_2:
{
m_Protocol = new cProtocol162(m_Client);
return true;
}
}
m_Protocol = new cProtocol125(m_Client);
return true;
@ -718,6 +724,7 @@ void cProtocolRecognizer::HandleServerPing(void)
case PROTO_VERSION_1_5_0:
case PROTO_VERSION_1_5_2:
case PROTO_VERSION_1_6_1:
case PROTO_VERSION_1_6_2:
{
// The server list ping now has 1 more byte of "magic". Mojang just loves to complicate stuff.
// http://wiki.vg/wiki/index.php?title=Protocol&oldid=3101#Server_List_Ping_.280xFE.29

View File

@ -18,8 +18,8 @@
// Adjust these if a new protocol is added or an old one is removed:
#define MCS_CLIENT_VERSIONS "1.2.4, 1.2.5, 1.3.1, 1.3.2, 1.4.2, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.5, 1.5.1, 1.5.2, 1.6.1"
#define MCS_PROTOCOL_VERSIONS "29, 39, 47, 49, 51, 60, 61, 73"
#define MCS_CLIENT_VERSIONS "1.2.4, 1.2.5, 1.3.1, 1.3.2, 1.4.2, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.5, 1.5.1, 1.5.2, 1.6.1, 1.6.2"
#define MCS_PROTOCOL_VERSIONS "29, 39, 47, 49, 51, 60, 61, 73, 74"
@ -41,6 +41,7 @@ public:
PROTO_VERSION_1_5_0 = 60,
PROTO_VERSION_1_5_2 = 61,
PROTO_VERSION_1_6_1 = 73,
PROTO_VERSION_1_6_2 = 74,
PROTO_VERSION_NEXT,
PROTO_VERSION_LATEST = PROTO_VERSION_NEXT - 1, ///< Automatically assigned to the last protocol version, this serves as the default for PrimaryServerVersion