summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-07-05 21:40:19 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-07-05 21:40:19 +0200
commitde5cec741985a7c2be52d0629a79b616921b6d57 (patch)
tree4ba655ce0e642c39e0c29cdca971af2b15ba8634
parentFixed a crash when moving a player to a non-existent world (reported by tonibm19) (diff)
downloadcuberite-de5cec741985a7c2be52d0629a79b616921b6d57.tar
cuberite-de5cec741985a7c2be52d0629a79b616921b6d57.tar.gz
cuberite-de5cec741985a7c2be52d0629a79b616921b6d57.tar.bz2
cuberite-de5cec741985a7c2be52d0629a79b616921b6d57.tar.lz
cuberite-de5cec741985a7c2be52d0629a79b616921b6d57.tar.xz
cuberite-de5cec741985a7c2be52d0629a79b616921b6d57.tar.zst
cuberite-de5cec741985a7c2be52d0629a79b616921b6d57.zip
-rw-r--r--VC2008/MCServer.vcproj8
-rw-r--r--source/Protocol/Protocol15x.cpp1
-rw-r--r--source/Protocol/Protocol16x.cpp143
-rw-r--r--source/Protocol/Protocol16x.h43
-rw-r--r--source/Protocol/ProtocolRecognizer.cpp8
-rw-r--r--source/Protocol/ProtocolRecognizer.h1
6 files changed, 203 insertions, 1 deletions
diff --git a/VC2008/MCServer.vcproj b/VC2008/MCServer.vcproj
index d1c82d8c4..699fa1354 100644
--- a/VC2008/MCServer.vcproj
+++ b/VC2008/MCServer.vcproj
@@ -2213,6 +2213,14 @@
>
</File>
<File
+ RelativePath="..\source\Protocol\Protocol16x.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\source\Protocol\Protocol16x.h"
+ >
+ </File>
+ <File
RelativePath="..\source\Protocol\ProtocolRecognizer.cpp"
>
</File>
diff --git a/source/Protocol/Protocol15x.cpp b/source/Protocol/Protocol15x.cpp
index d5ab05ea6..cb7fc9fb6 100644
--- a/source/Protocol/Protocol15x.cpp
+++ b/source/Protocol/Protocol15x.cpp
@@ -6,7 +6,6 @@ Implements the 1.5.x protocol classes:
- cProtocol150
- release 1.5 protocol (#60)
- release 1.5.2 protocol (#61, no relevant changes found)
-(others may be added later in the future for the 1.5 release series)
*/
#include "Globals.h"
diff --git a/source/Protocol/Protocol16x.cpp b/source/Protocol/Protocol16x.cpp
new file mode 100644
index 000000000..d9cec5345
--- /dev/null
+++ b/source/Protocol/Protocol16x.cpp
@@ -0,0 +1,143 @@
+
+// Protocol16x.cpp
+
+/*
+Implements the 1.6.x protocol classes:
+ - cProtocol161
+ - release 1.6.1 protocol (#73)
+(others may be added later in the future for the 1.6 release series)
+*/
+
+#include "Globals.h"
+#include "Protocol16x.h"
+#include "../ClientHandle.h"
+#include "../Entity.h"
+#include "../Player.h"
+
+
+
+
+
+#define HANDLE_PACKET_READ(Proc, Type, Var) \
+ Type Var; \
+ { \
+ if (!m_ReceivedData.Proc(Var)) \
+ { \
+ m_ReceivedData.CheckValid(); \
+ return PARSE_INCOMPLETE; \
+ } \
+ m_ReceivedData.CheckValid(); \
+ }
+
+
+
+
+
+enum
+{
+ PACKET_CHAT = 0x03,
+ PACKET_UPDATE_HEALTH = 0x08,
+ PACKET_ATTACH_ENTITY = 0x27,
+ PACKET_WINDOW_OPEN = 0x64,
+} ;
+
+
+
+
+
+
+cProtocol161::cProtocol161(cClientHandle * a_Client) :
+ super(a_Client)
+{
+}
+
+
+
+
+
+void cProtocol161::SendAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle)
+{
+ cCSLock Lock(m_CSPacket);
+ WriteByte(PACKET_ATTACH_ENTITY);
+ WriteInt(a_Entity.GetUniqueID());
+ WriteInt((a_Vehicle == NULL) ? -1 : a_Vehicle->GetUniqueID());
+ WriteBool(false); // TODO: "Should use leash?" -> no
+ Flush();
+}
+
+
+
+
+
+void cProtocol161::SendChat(const AString & a_Message)
+{
+ super::SendChat(Printf("{\"text\":\"%s\"}", a_Message.c_str()));
+}
+
+
+
+
+void cProtocol161::SendHealth(void)
+{
+ cCSLock Lock(m_CSPacket);
+ WriteByte (PACKET_UPDATE_HEALTH);
+ WriteFloat((float)m_Client->GetPlayer()->GetHealth());
+ WriteShort(m_Client->GetPlayer()->GetFoodLevel());
+ WriteFloat(m_Client->GetPlayer()->GetFoodSaturationLevel());
+ Flush();
+}
+
+
+
+
+
+void cProtocol161::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots)
+{
+ if (a_WindowType < 0)
+ {
+ // Do not send for inventory windows
+ return;
+ }
+ cCSLock Lock(m_CSPacket);
+ WriteByte (PACKET_WINDOW_OPEN);
+ WriteByte (a_WindowID);
+ WriteByte (a_WindowType);
+ WriteString(a_WindowTitle);
+ WriteByte (a_NumSlots);
+ WriteByte (1); // Use title
+ if (a_WindowType == 11) // horse / donkey
+ {
+ WriteInt(0); // Unknown value sent only when window type is 11 (horse / donkey)
+ }
+ Flush();
+}
+
+
+
+
+
+int cProtocol161::ParseEntityAction(void)
+{
+ HANDLE_PACKET_READ(ReadBEInt, int, EntityID);
+ HANDLE_PACKET_READ(ReadChar, char, ActionID);
+ HANDLE_PACKET_READ(ReadBEInt, int, UnknownHorseVal);
+ m_Client->HandleEntityAction(EntityID, ActionID);
+ return PARSE_OK;
+}
+
+
+
+
+
+int cProtocol161::ParsePlayerAbilities(void)
+{
+ HANDLE_PACKET_READ(ReadByte, Byte, Flags);
+ HANDLE_PACKET_READ(ReadBEFloat, float, FlyingSpeed);
+ HANDLE_PACKET_READ(ReadBEFloat, float, WalkingSpeed);
+ // TODO: m_Client->HandlePlayerAbilities(...);
+ return PARSE_OK;
+}
+
+
+
+
diff --git a/source/Protocol/Protocol16x.h b/source/Protocol/Protocol16x.h
new file mode 100644
index 000000000..60e3d1360
--- /dev/null
+++ b/source/Protocol/Protocol16x.h
@@ -0,0 +1,43 @@
+
+// Protocol16x.h
+
+/*
+Declares the 1.6.x protocol classes:
+ - cProtocol161
+ - release 1.6.1 protocol (#73)
+(others may be added later in the future for the 1.6 release series)
+*/
+
+
+
+
+
+#pragma once
+
+#include "Protocol15x.h"
+
+
+
+
+
+class cProtocol161 :
+ public cProtocol150
+{
+ typedef cProtocol150 super;
+
+public:
+ cProtocol161(cClientHandle * a_Client);
+
+ // cProtocol150 overrides:
+ virtual void SendAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle) override;
+ virtual void SendChat (const AString & a_Message) override;
+ virtual void SendHealth (void) override;
+ virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) override;
+
+ virtual int ParseEntityAction (void) override;
+ virtual int ParsePlayerAbilities(void) override;
+} ;
+
+
+
+
diff --git a/source/Protocol/ProtocolRecognizer.cpp b/source/Protocol/ProtocolRecognizer.cpp
index 518d03058..f7c3a1670 100644
--- a/source/Protocol/ProtocolRecognizer.cpp
+++ b/source/Protocol/ProtocolRecognizer.cpp
@@ -11,6 +11,7 @@
#include "Protocol132.h"
#include "Protocol14x.h"
#include "Protocol15x.h"
+#include "Protocol16x.h"
#include "../ClientHandle.h"
#include "../Root.h"
#include "../World.h"
@@ -51,6 +52,7 @@ AString cProtocolRecognizer::GetVersionTextFromInt(int a_ProtocolVersion)
case PROTO_VERSION_1_4_6: return "1.4.6";
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";
}
ASSERT(!"Unknown protocol version");
return Printf("Unknown protocol (%d)", a_ProtocolVersion);
@@ -656,6 +658,11 @@ bool cProtocolRecognizer::TryRecognizeProtocol(void)
m_Protocol = new cProtocol150(m_Client);
return true;
}
+ case PROTO_VERSION_1_6_1:
+ {
+ m_Protocol = new cProtocol161(m_Client);
+ return true;
+ }
}
m_Protocol = new cProtocol125(m_Client);
return true;
@@ -689,6 +696,7 @@ void cProtocolRecognizer::HandleServerPing(void)
case PROTO_VERSION_1_4_6:
case PROTO_VERSION_1_5_0:
case PROTO_VERSION_1_5_2:
+ case PROTO_VERSION_1_6_1:
{
// 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
diff --git a/source/Protocol/ProtocolRecognizer.h b/source/Protocol/ProtocolRecognizer.h
index 75a4d828a..e22a45a2a 100644
--- a/source/Protocol/ProtocolRecognizer.h
+++ b/source/Protocol/ProtocolRecognizer.h
@@ -40,6 +40,7 @@ public:
PROTO_VERSION_1_4_6 = 51,
PROTO_VERSION_1_5_0 = 60,
PROTO_VERSION_1_5_2 = 61,
+ PROTO_VERSION_1_6_1 = 73,
PROTO_VERSION_NEXT,
PROTO_VERSION_LATEST = PROTO_VERSION_NEXT - 1, ///< Automatically assigned to the last protocol version, this serves as the default for PrimaryServerVersion