1
0
Fork 0

Initial support for the 1.11 protocol.

This commit is contained in:
Mattes D 2016-12-15 20:21:43 +01:00
parent 506ce33101
commit 0e3b3be766
23 changed files with 682 additions and 455 deletions

View File

@ -2909,7 +2909,7 @@ void cChunk::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cons
void cChunk::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude)
void cChunk::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, int a_Count, const cClientHandle * a_Exclude)
{
for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
@ -2917,7 +2917,7 @@ void cChunk::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_
{
continue;
}
(*itr)->SendCollectEntity(a_Entity, a_Player);
(*itr)->SendCollectEntity(a_Entity, a_Player, a_Count);
} // for itr - LoadedByClient[]
}

View File

@ -348,7 +348,7 @@ public:
void BroadcastBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude = nullptr);
void BroadcastBlockBreakAnimation(UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude = nullptr);
void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = nullptr);
void BroadcastCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude = nullptr);
void BroadcastCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player, int a_Count, const cClientHandle * a_Exclude = nullptr);
void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = nullptr);
void BroadcastDetachEntity (const cEntity & a_Entity, const cEntity & a_PreviousVehicle);
void BroadcastEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude = nullptr);

View File

@ -332,7 +332,7 @@ void cChunkMap::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, c
void cChunkMap::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude)
void cChunkMap::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, int a_Count, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
@ -341,7 +341,7 @@ void cChunkMap::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer &
return;
}
// It's perfectly legal to broadcast packets even to invalid chunks!
Chunk->BroadcastCollectEntity(a_Entity, a_Player, a_Exclude);
Chunk->BroadcastCollectEntity(a_Entity, a_Player, a_Count, a_Exclude);
}

View File

@ -75,7 +75,7 @@ public:
void BroadcastBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude = nullptr);
void BroadcastBlockBreakAnimation(UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude = nullptr);
void BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude);
void BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude = nullptr);
void BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, int a_Count, const cClientHandle * a_Exclude = nullptr);
void BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHandle * a_Exclude = nullptr);
void BroadcastDetachEntity(const cEntity & a_Entity, const cEntity & a_PreviousVehicle);
void BroadcastEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude = nullptr);

View File

@ -2426,9 +2426,9 @@ void cClientHandle::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializ
void cClientHandle::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player)
void cClientHandle::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, int a_Count)
{
m_Protocol->SendCollectEntity(a_Entity, a_Player);
m_Protocol->SendCollectEntity(a_Entity, a_Player, a_Count);
}

View File

@ -164,7 +164,7 @@ public: // tolua_export
void SendChatSystem (const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData = "");
void SendChatSystem (const cCompositeChat & a_Message);
void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer);
void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player);
void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player, int a_Count);
void SendDestroyEntity (const cEntity & a_Entity);
void SendDetachEntity (const cEntity & a_Entity, const cEntity & a_PreviousVehicle);
void SendDisconnect (const AString & a_Reason);

View File

@ -167,7 +167,7 @@ void cArrowEntity::CollectedBy(cPlayer & a_Dest)
}
}
GetWorld()->BroadcastCollectEntity(*this, a_Dest);
GetWorld()->BroadcastCollectEntity(*this, a_Dest, 1);
GetWorld()->BroadcastSoundEffect("random.pop", GetPosX(), GetPosY(), GetPosZ(), 0.5, static_cast<float>(0.75 + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
m_bIsCollected = true;
}

View File

@ -234,7 +234,7 @@ bool cPickup::CollectedBy(cPlayer & a_Dest)
}
m_Item.m_ItemCount -= NumAdded;
m_World->BroadcastCollectEntity(*this, a_Dest);
m_World->BroadcastCollectEntity(*this, a_Dest, NumAdded);
// Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;)
m_World->BroadcastSoundEffect("random.pop", GetPosX(), GetPosY(), GetPosZ(), 0.5, (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));

View File

@ -7,9 +7,10 @@ SET (SRCS
ChunkDataSerializer.cpp
MojangAPI.cpp
Packetizer.cpp
Protocol18x.cpp
Protocol19x.cpp
Protocol110x.cpp
Protocol_1_8.cpp
Protocol_1_9.cpp
Protocol_1_10.cpp
Protocol_1_11.cpp
ProtocolRecognizer.cpp
)
@ -19,16 +20,17 @@ SET (HDRS
MojangAPI.h
Packetizer.h
Protocol.h
Protocol18x.h
Protocol19x.h
Protocol110x.h
Protocol_1_8.h
Protocol_1_9.h
Protocol_1_10.h
Protocol_1_11.h
ProtocolRecognizer.h
)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set_source_files_properties(Protocol19x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch")
set_source_files_properties(Protocol18x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch")
set_source_files_properties(Protocol110x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch")
set_source_files_properties(Protocol_1_9.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch")
set_source_files_properties(Protocol_1_8.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch")
set_source_files_properties(Protocol_1_10.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch")
endif()
if (NOT MSVC)

View File

@ -9,8 +9,8 @@
#include "ChunkDataSerializer.h"
#include "zlib/zlib.h"
#include "ByteBuffer.h"
#include "Protocol18x.h"
#include "Protocol19x.h"
#include "Protocol_1_8.h"
#include "Protocol_1_9.h"
@ -111,7 +111,7 @@ void cChunkDataSerializer::Serialize47(AString & a_Data, int a_ChunkX, int a_Chu
cByteBuffer Buffer(20);
if (PacketData.size() >= 256)
{
if (!cProtocol180::CompressPacket(PacketData, a_Data))
if (!cProtocol_1_8_0::CompressPacket(PacketData, a_Data))
{
ASSERT(!"Packet compression failed.");
a_Data.clear();
@ -254,7 +254,7 @@ void cChunkDataSerializer::Serialize107(AString & a_Data, int a_ChunkX, int a_Ch
cByteBuffer Buffer(20);
if (PacketData.size() >= 256)
{
if (!cProtocol190::CompressPacket(PacketData, a_Data))
if (!cProtocol_1_9_0::CompressPacket(PacketData, a_Data))
{
ASSERT(!"Packet compression failed.");
a_Data.clear();
@ -400,7 +400,7 @@ void cChunkDataSerializer::Serialize110(AString & a_Data, int a_ChunkX, int a_Ch
cByteBuffer Buffer(20);
if (PacketData.size() >= 256)
{
if (!cProtocol190::CompressPacket(PacketData, a_Data))
if (!cProtocol_1_9_0::CompressPacket(PacketData, a_Data))
{
ASSERT(!"Packet compression failed.");
a_Data.clear();

View File

@ -74,7 +74,7 @@ public:
virtual void SendChat (const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes) = 0;
virtual void SendChatRaw (const AString & a_MessageRaw, eChatType a_Type) = 0;
virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) = 0;
virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) = 0;
virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player, int a_Count) = 0;
virtual void SendDestroyEntity (const cEntity & a_Entity) = 0;
virtual void SendDetachEntity (const cEntity & a_Entity, const cEntity & a_PreviousVehicle) = 0;
virtual void SendDisconnect (const AString & a_Reason) = 0;

View File

@ -7,9 +7,10 @@
#include "Globals.h"
#include "ProtocolRecognizer.h"
#include "Protocol18x.h"
#include "Protocol19x.h"
#include "Protocol110x.h"
#include "Protocol_1_8.h"
#include "Protocol_1_9.h"
#include "Protocol_1_10.h"
#include "Protocol_1_11.h"
#include "Packetizer.h"
#include "../ClientHandle.h"
#include "../Root.h"
@ -53,7 +54,8 @@ AString cProtocolRecognizer::GetVersionTextFromInt(int a_ProtocolVersion)
case PROTO_VERSION_1_9_1: return "1.9.1";
case PROTO_VERSION_1_9_2: return "1.9.2";
case PROTO_VERSION_1_9_4: return "1.9.4";
case PROTO_VERSION_1_10_0: return "1.10";
case PROTO_VERSION_1_10_0: return "1.10";
case PROTO_VERSION_1_11_0: return "1.11";
}
ASSERT(!"Unknown protocol version");
return Printf("Unknown protocol (%d)", a_ProtocolVersion);
@ -220,10 +222,10 @@ void cProtocolRecognizer::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSe
void cProtocolRecognizer::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player)
void cProtocolRecognizer::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, int a_Count)
{
ASSERT(m_Protocol != nullptr);
m_Protocol->SendCollectEntity(a_Entity, a_Player);
m_Protocol->SendCollectEntity(a_Entity, a_Player, a_Count);
}
@ -978,8 +980,7 @@ void cProtocolRecognizer::SendData(const char * a_Data, size_t a_Size)
bool cProtocolRecognizer::TryRecognizeProtocol(void)
{
// NOTE: If a new protocol is added or an old one is removed, adjust MCS_CLIENT_VERSIONS and
// MCS_PROTOCOL_VERSIONS macros in the header file, as well as PROTO_VERSION_LATEST macro
// NOTE: If a new protocol is added or an old one is removed, adjust MCS_CLIENT_VERSIONS and MCS_PROTOCOL_VERSIONS macros in the header file
// Lengthed protocol, try if it has the entire initial handshake packet:
UInt32 PacketLen;
@ -1045,37 +1046,42 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema
case PROTO_VERSION_1_8_0:
{
m_Buffer.CommitRead();
m_Protocol = new cProtocol180(m_Client, ServerAddress, ServerPort, NextState);
m_Protocol = new cProtocol_1_8_0(m_Client, ServerAddress, ServerPort, NextState);
return true;
}
case PROTO_VERSION_1_9_0:
{
m_Protocol = new cProtocol190(m_Client, ServerAddress, ServerPort, NextState);
m_Protocol = new cProtocol_1_9_0(m_Client, ServerAddress, ServerPort, NextState);
return true;
}
case PROTO_VERSION_1_9_1:
{
m_Protocol = new cProtocol191(m_Client, ServerAddress, ServerPort, NextState);
m_Protocol = new cProtocol_1_9_1(m_Client, ServerAddress, ServerPort, NextState);
return true;
}
case PROTO_VERSION_1_9_2:
{
m_Protocol = new cProtocol192(m_Client, ServerAddress, ServerPort, NextState);
m_Protocol = new cProtocol_1_9_2(m_Client, ServerAddress, ServerPort, NextState);
return true;
}
case PROTO_VERSION_1_9_4:
{
m_Protocol = new cProtocol194(m_Client, ServerAddress, ServerPort, NextState);
m_Protocol = new cProtocol_1_9_4(m_Client, ServerAddress, ServerPort, NextState);
return true;
}
case PROTO_VERSION_1_10_0:
{
m_Protocol = new cProtocol1100(m_Client, ServerAddress, ServerPort, NextState);
m_Protocol = new cProtocol_1_10_0(m_Client, ServerAddress, ServerPort, NextState);
return true;
}
case PROTO_VERSION_1_11_0:
{
m_Protocol = new cProtocol_1_11_0(m_Client, ServerAddress, ServerPort, NextState);
return true;
}
default:
{
LOGINFO("Client \"%s\" uses an unsupported protocol (lengthed, version %u (0x%x))",
LOGD("Client \"%s\" uses an unsupported protocol (lengthed, version %u (0x%x))",
m_Client->GetIPString().c_str(), ProtocolVersion, ProtocolVersion
);
if (NextState != 1)

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.8.x, 1.9.x, 1.10.x"
#define MCS_PROTOCOL_VERSIONS "47, 107, 108, 109, 110, 210"
#define MCS_CLIENT_VERSIONS "1.8.x, 1.9.x, 1.10.x, 1.11"
#define MCS_PROTOCOL_VERSIONS "47, 107, 108, 109, 110, 210, 315"
@ -39,6 +39,7 @@ public:
PROTO_VERSION_1_9_2 = 109,
PROTO_VERSION_1_9_4 = 110,
PROTO_VERSION_1_10_0 = 210,
PROTO_VERSION_1_11_0 = 315,
} ;
cProtocolRecognizer(cClientHandle * a_Client);
@ -61,7 +62,7 @@ public:
virtual void SendChat (const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes) override;
virtual void SendChatRaw (const AString & a_MessageRaw, eChatType a_Type) override;
virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) 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 SendDisconnect (const AString & a_Reason) override;

View File

@ -1,15 +1,14 @@
// Protocol110x.cpp
// Protocol_1_10.cpp
/*
Implements the 1.10.x protocol classes:
- cProtocol1100
- release 1.10.0 protocol (#210)
(others may be added later in the future for the 1.10 release series)
Implements the 1.10 protocol classes:
- cProtocol_1_10_0
- release 1.10 protocol (#210), also used by 1.10.1 and 1.10.2
*/
#include "Globals.h"
#include "Protocol110x.h"
#include "Protocol_1_10.h"
#include "Packetizer.h"
#include "json/json.h"
@ -283,7 +282,7 @@ namespace Metadata
cProtocol1100::cProtocol1100(cClientHandle * a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) :
cProtocol_1_10_0::cProtocol_1_10_0(cClientHandle * a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) :
super(a_Client, a_ServerAddress, a_ServerPort, a_State)
{
}
@ -292,7 +291,7 @@ cProtocol1100::cProtocol1100(cClientHandle * a_Client, const AString &a_ServerAd
void cProtocol1100::SendSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch)
void cProtocol_1_10_0::SendSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch)
{
ASSERT(m_State == 3); // In game mode?
@ -310,7 +309,7 @@ void cProtocol1100::SendSoundEffect(const AString & a_SoundName, double a_X, dou
void cProtocol1100::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
void cProtocol_1_10_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
{
cServer * Server = cRoot::Get()->GetServer();
AString ServerDescription = Server->GetDescription();
@ -355,7 +354,7 @@ void cProtocol1100::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
void cProtocol1100::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_Entity)
void cProtocol_1_10_0::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_Entity)
{
using namespace Metadata;
@ -552,7 +551,7 @@ void cProtocol1100::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_E
void cProtocol1100::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob)
void cProtocol_1_10_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob)
{
using namespace Metadata;

View File

@ -1,11 +1,10 @@
// Protocol110x.h
// Protocol_1_10.h
/*
Declares the 1.10.x protocol classes:
- cProtocol1100
- release 1.10.0 protocol (#210)
(others may be added later in the future for the 1.10 release series)
Declares the 1.10 protocol classes:
- cProtocol_1_10
- release 1.10 protocol (#210), also used by 1.10.1 and 1.10.2
*/
@ -14,15 +13,19 @@ Declares the 1.10.x protocol classes:
#pragma once
#include "Protocol19x.h"
#include "Protocol_1_9.h"
class cProtocol1100 :
public cProtocol194
class cProtocol_1_10_0 :
public cProtocol_1_9_4
{
typedef cProtocol194 super;
typedef cProtocol_1_9_4 super;
public:
cProtocol1100(cClientHandle * a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
cProtocol_1_10_0(cClientHandle * a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
virtual void SendSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override;

View File

@ -0,0 +1,189 @@
// Protocol_1_11.cpp
/*
Implements the 1.11 protocol classes:
- cProtocol_1_11_0
- release 1.11 protocol (#315)
(others may be added later in the future for the 1.11 release series)
*/
#include "Globals.h"
#include "Protocol_1_11.h"
#include "ProtocolRecognizer.h"
#include "Packetizer.h"
#include "../Root.h"
#include "../Server.h"
#include "../ClientHandle.h"
#include "../CompositeChat.h"
#include "../Bindings/PluginManager.h"
#include "../Entities/Player.h"
#include "../Mobs/Monster.h"
#define HANDLE_READ(ByteBuf, Proc, Type, Var) \
Type Var; \
if (!ByteBuf.Proc(Var))\
{\
return;\
}
cProtocol_1_11_0::cProtocol_1_11_0(cClientHandle * a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) :
super(a_Client, a_ServerAddress, a_ServerPort, a_State)
{
}
void cProtocol_1_11_0::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, int a_Count)
{
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, 0x0d); // Collect Item packet
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
Pkt.WriteVarInt32(a_Player.GetUniqueID());
Pkt.WriteVarInt32(static_cast<UInt32>(a_Count));
}
void cProtocol_1_11_0::SendHideTitle(void)
{
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, 0x45); // Title packet
Pkt.WriteVarInt32(4); // Hide title
}
void cProtocol_1_11_0::SendResetTitle(void)
{
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, 0x45); // Title packet
Pkt.WriteVarInt32(5); // Reset title
}
void cProtocol_1_11_0::SendSpawnMob(const cMonster & a_Mob)
{
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, 0x0f); // Spawn Mob packet
Pkt.WriteVarInt32(a_Mob.GetUniqueID());
Pkt.WriteVarInt32(static_cast<UInt32>(a_Mob.GetMobType()));
Pkt.WriteFPInt(a_Mob.GetPosX());
Pkt.WriteFPInt(a_Mob.GetPosY());
Pkt.WriteFPInt(a_Mob.GetPosZ());
Pkt.WriteByteAngle(a_Mob.GetPitch());
Pkt.WriteByteAngle(a_Mob.GetHeadYaw());
Pkt.WriteByteAngle(a_Mob.GetYaw());
Pkt.WriteBEInt16(static_cast<Int16>(a_Mob.GetSpeedX() * 400));
Pkt.WriteBEInt16(static_cast<Int16>(a_Mob.GetSpeedY() * 400));
Pkt.WriteBEInt16(static_cast<Int16>(a_Mob.GetSpeedZ() * 400));
WriteEntityMetadata(Pkt, a_Mob);
Pkt.WriteBEUInt8(0x7f); // Metadata terminator
}
void cProtocol_1_11_0::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks)
{
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, 0x45); // Title packet
Pkt.WriteVarInt32(3); // Set title display times
Pkt.WriteBEInt32(a_FadeInTicks);
Pkt.WriteBEInt32(a_DisplayTicks);
Pkt.WriteBEInt32(a_FadeOutTicks);
}
void cProtocol_1_11_0::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer)
{
int BlockX, BlockY, BlockZ;
if (!a_ByteBuffer.ReadPosition64(BlockX, BlockY, BlockZ))
{
return;
}
HANDLE_READ(a_ByteBuffer, ReadVarInt, Int32, Face);
HANDLE_READ(a_ByteBuffer, ReadVarInt, Int32, Hand);
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, CursorX);
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, CursorY);
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, CursorZ);
m_Client->HandleRightClick(BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), FloorC(CursorX * 16), FloorC(CursorY * 16), FloorC(CursorZ * 16), m_Client->GetPlayer()->GetEquippedItem());
}
void cProtocol_1_11_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
{
cServer * Server = cRoot::Get()->GetServer();
AString ServerDescription = Server->GetDescription();
int NumPlayers = Server->GetNumPlayers();
int MaxPlayers = Server->GetMaxPlayers();
AString Favicon = Server->GetFaviconData();
cRoot::Get()->GetPluginManager()->CallHookServerPing(*m_Client, ServerDescription, NumPlayers, MaxPlayers, Favicon);
// Version:
Json::Value Version;
Version["name"] = "Cuberite 1.11";
Version["protocol"] = cProtocolRecognizer::PROTO_VERSION_1_11_0;
// Players:
Json::Value Players;
Players["online"] = NumPlayers;
Players["max"] = MaxPlayers;
// TODO: Add "sample"
// Description:
Json::Value Description;
Description["text"] = ServerDescription.c_str();
// Create the response:
Json::Value ResponseValue;
ResponseValue["version"] = Version;
ResponseValue["players"] = Players;
ResponseValue["description"] = Description;
if (!Favicon.empty())
{
ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str());
}
// Serialize the response into a packet:
Json::FastWriter Writer;
cPacketizer Pkt(*this, 0x00); // Response packet
Pkt.WriteString(Writer.write(ResponseValue));
}

View File

@ -0,0 +1,41 @@
// Protocol_1_11.h
/*
Declares the 1.11 protocol classes:
- cProtocol_1_11_0
- release 1.11 protocol (#315)
(others may be added later in the future for the 1.11 release series)
*/
#pragma once
#include "Protocol_1_10.h"
class cProtocol_1_11_0 :
public cProtocol_1_10_0
{
typedef cProtocol_1_10_0 super;
public:
cProtocol_1_11_0(cClientHandle * a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
virtual void SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, int a_Count) override;
virtual void SendHideTitle (void) override;
virtual void SendResetTitle (void) override;
virtual void SendSpawnMob (const cMonster & a_Mob) override;
virtual void SendTitleTimes (int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) override;
protected:
virtual void HandlePacketBlockPlace (cByteBuffer & a_ByteBuffer) override;
virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) override;
};

View File

@ -1,11 +1,10 @@
// Protocol18x.h
// Protocol_1_8.h
/*
Declares the 1.8.x protocol classes:
- cProtocol180
- release 1.8.0 protocol (#47)
(others may be added later in the future for the 1.8 release series)
Declares the 1.8 protocol classes:
- cProtocol_1_8_0
- release 1.8 protocol (#47)
*/
@ -47,14 +46,14 @@ namespace Json
class cProtocol180 :
class cProtocol_1_8_0 :
public cProtocol
{
typedef cProtocol super;
public:
cProtocol180(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
cProtocol_1_8_0(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
/** Called when client sends some data: */
virtual void DataReceived(const char * a_Data, size_t a_Size) override;
@ -70,7 +69,7 @@ public:
virtual void SendChat (const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes) override;
virtual void SendChatRaw (const AString & a_MessageRaw, eChatType a_Type) override;
virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) 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 SendDisconnect (const AString & a_Reason) override;

View File

@ -1,17 +1,16 @@
// Protocol19x.h
// Protocol_1_9.h
/*
Declares the 1.9.x protocol classes:
- cProtocol190
- release 1.9.0 protocol (#107)
- cProtocol191
Declares the 1.9 protocol classes:
- cProtocol_1_9_0
- release 1.9 protocol (#107)
- cProtocol_1_9_1
- release 1.9.1 protocol (#108)
- cProtocol192
- cProtocol_1_9_2
- release 1.9.2 protocol (#109)
- cProtocol194
- cProtocol_1_9_4
- release 1.9.4 protocol (#110)
(others may be added later in the future for the 1.9 release series)
*/
@ -53,14 +52,14 @@ namespace Json
class cProtocol190 :
class cProtocol_1_9_0 :
public cProtocol
{
typedef cProtocol super;
public:
cProtocol190(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
/** Called when client sends some data: */
virtual void DataReceived(const char * a_Data, size_t a_Size) override;
@ -76,7 +75,7 @@ public:
virtual void SendChat (const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes) override;
virtual void SendChatRaw (const AString & a_MessageRaw, eChatType a_Type) override;
virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) 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 SendDisconnect (const AString & a_Reason) override;
@ -189,51 +188,50 @@ protected:
void AddReceivedData(const char * a_Data, size_t a_Size);
/** 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);
Returns true if the packet was understood, false if it was an unknown packet. */
virtual bool HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType);
// Packet handlers while in the Status state (m_State == 1):
virtual void HandlePacketStatusPing(cByteBuffer & a_ByteBuffer);
virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer);
// Packet handlers while in the Login state (m_State == 2):
void HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer);
void HandlePacketLoginStart(cByteBuffer & a_ByteBuffer);
virtual void HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer);
virtual void HandlePacketLoginStart(cByteBuffer & a_ByteBuffer);
// 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 HandlePacketBoatSteer (cByteBuffer & a_ByteBuffer);
void HandlePacketChatMessage (cByteBuffer & a_ByteBuffer);
void HandlePacketClientSettings (cByteBuffer & a_ByteBuffer);
void HandlePacketClientStatus (cByteBuffer & a_ByteBuffer);
void HandleConfirmTeleport (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 HandlePacketSpectate (cByteBuffer & a_ByteBuffer);
void HandlePacketTabComplete (cByteBuffer & a_ByteBuffer);
void HandlePacketUpdateSign (cByteBuffer & a_ByteBuffer);
void HandlePacketUseEntity (cByteBuffer & a_ByteBuffer);
void HandlePacketUseItem (cByteBuffer & a_ByteBuffer);
void HandlePacketEnchantItem (cByteBuffer & a_ByteBuffer);
void HandlePacketVehicleMove (cByteBuffer & a_ByteBuffer);
void HandlePacketWindowClick (cByteBuffer & a_ByteBuffer);
void HandlePacketWindowClose (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketAnimation (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketBlockDig (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketBlockPlace (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketBoatSteer (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketChatMessage (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketClientSettings (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketClientStatus (cByteBuffer & a_ByteBuffer);
virtual void HandleConfirmTeleport (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffer);
virtual void HandlePacketEntityAction (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketKeepAlive (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketPlayer (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketPlayerAbilities (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketPlayerLook (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketPlayerPos (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketPlayerPosLook (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketPluginMessage (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketSlotSelect (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketSteerVehicle (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketSpectate (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketTabComplete (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketUpdateSign (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketUseEntity (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketUseItem (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketEnchantItem (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketVehicleMove (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketWindowClick (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketWindowClose (cByteBuffer & a_ByteBuffer);
/** 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 */
void HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const AString & a_Channel);
virtual void HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const AString & a_Channel);
/** Sends the data to the client, encrypting them if needed. */
@ -297,15 +295,15 @@ protected:
/** The version 108 protocol, used by 1.9.1. Uses an int rather than a byte for dimension in join game. */
class cProtocol191 :
public cProtocol190
class cProtocol_1_9_1 :
public cProtocol_1_9_0
{
typedef cProtocol190 super;
typedef cProtocol_1_9_0 super;
public:
cProtocol191(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
cProtocol_1_9_1(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
// cProtocol190 overrides:
// cProtocol_1_9_0 overrides:
virtual void SendLogin(const cPlayer & a_Player, const cWorld & a_World) override;
virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) override;
@ -316,15 +314,15 @@ public:
/** The version 109 protocol, used by 1.9.2. Same as 1.9.1, except the server list ping version number changed with the protocol number. */
class cProtocol192 :
public cProtocol191
class cProtocol_1_9_2 :
public cProtocol_1_9_1
{
typedef cProtocol191 super;
typedef cProtocol_1_9_1 super;
public:
cProtocol192(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
cProtocol_1_9_2(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
// cProtocol190 overrides:
// cProtocol_1_9_1 overrides:
virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) override;
} ;
@ -334,16 +332,16 @@ public:
/** The version 110 protocol, used by 1.9.3 and 1.9.4. */
class cProtocol194 :
public cProtocol192
class cProtocol_1_9_4 :
public cProtocol_1_9_2
{
typedef cProtocol192 super;
typedef cProtocol_1_9_2 super;
public:
cProtocol194(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
cProtocol_1_9_4(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
// cProtocol190 overrides:
virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) 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;

View File

@ -2446,9 +2446,9 @@ void cWorld::BroadcastChat(const cCompositeChat & a_Message, const cClientHandle
void cWorld::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude)
void cWorld::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, int a_Count, const cClientHandle * a_Exclude)
{
m_ChunkMap->BroadcastCollectEntity(a_Entity, a_Player, a_Exclude);
m_ChunkMap->BroadcastCollectEntity(a_Entity, a_Player, a_Count, a_Exclude);
}

View File

@ -192,7 +192,7 @@ public:
void BroadcastChat (const cCompositeChat & a_Message, const cClientHandle * a_Exclude = nullptr);
// tolua_end
void BroadcastCollectEntity (const cEntity & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = nullptr);
void BroadcastCollectEntity (const cEntity & a_Pickup, const cPlayer & a_Player, int a_Count, const cClientHandle * a_Exclude = nullptr);
void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = nullptr);
void BroadcastDetachEntity (const cEntity & a_Entity, const cEntity & a_PreviousVehicle);
void BroadcastEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude = nullptr);