summaryrefslogtreecommitdiffstats
path: root/src/Protocol/Protocol_1_12.cpp
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2017-09-21 15:12:43 +0200
committerAlexander Harkness <me@bearbin.net>2017-09-21 15:12:43 +0200
commite883aa828c304600fcd707b50df9515011311db8 (patch)
treed2a14af47bf001df1fb2705278fad8a75682f883 /src/Protocol/Protocol_1_12.cpp
parentOnly allow snow to be placed where valid. Fixes #2920. (diff)
downloadcuberite-e883aa828c304600fcd707b50df9515011311db8.tar
cuberite-e883aa828c304600fcd707b50df9515011311db8.tar.gz
cuberite-e883aa828c304600fcd707b50df9515011311db8.tar.bz2
cuberite-e883aa828c304600fcd707b50df9515011311db8.tar.lz
cuberite-e883aa828c304600fcd707b50df9515011311db8.tar.xz
cuberite-e883aa828c304600fcd707b50df9515011311db8.tar.zst
cuberite-e883aa828c304600fcd707b50df9515011311db8.zip
Diffstat (limited to '')
-rw-r--r--src/Protocol/Protocol_1_12.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp
index 627131576..b804dd351 100644
--- a/src/Protocol/Protocol_1_12.cpp
+++ b/src/Protocol/Protocol_1_12.cpp
@@ -1332,3 +1332,79 @@ bool cProtocol_1_12_1::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketT
+////////////////////////////////////////////////////////////////////////////////
+// cProtocol_1_12_2:
+
+void cProtocol_1_12_2::HandlePacketKeepAlive(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadBEInt64, Int64, KeepAliveID);
+ if (
+ (KeepAliveID <= std::numeric_limits<UInt32>::max()) &&
+ (KeepAliveID >= 0)
+ )
+ {
+ // The server will only send a UInt32 so any value out of that range shouldn't keep the client alive.
+ m_Client->HandleKeepAlive(static_cast<UInt32>(KeepAliveID));
+ }
+}
+
+
+
+
+
+void cProtocol_1_12_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
+{
+ cServer * Server = cRoot::Get()->GetServer();
+ AString ServerDescription = Server->GetDescription();
+ auto NumPlayers = static_cast<signed>(Server->GetNumPlayers());
+ auto MaxPlayers = static_cast<signed>(Server->GetMaxPlayers());
+ AString Favicon = Server->GetFaviconData();
+ cRoot::Get()->GetPluginManager()->CallHookServerPing(*m_Client, ServerDescription, NumPlayers, MaxPlayers, Favicon);
+
+ // Version:
+ Json::Value Version;
+ Version["name"] = "Cuberite 1.12.2";
+ Version["protocol"] = cProtocolRecognizer::PROTO_VERSION_1_12_2;
+
+ // 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));
+}
+
+
+
+
+
+void cProtocol_1_12_2::SendKeepAlive(UInt32 a_PingID)
+{
+ // Drop the packet if the protocol is not in the Game state yet (caused a client crash):
+ if (m_State != 3)
+ {
+ LOGWARNING("Trying to send a KeepAlive packet to a player who's not yet fully logged in (%d). The protocol class prevented the packet.", m_State);
+ return;
+ }
+
+ cPacketizer Pkt(*this, GetPacketId(sendKeepAlive)); // Keep Alive packet
+ Pkt.WriteBEInt64(a_PingID);
+}