From e883aa828c304600fcd707b50df9515011311db8 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Thu, 21 Sep 2017 14:12:43 +0100 Subject: Add support for release 1.12.2 (#4041) --- src/Protocol/Protocol_1_12.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'src/Protocol/Protocol_1_12.cpp') 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::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(KeepAliveID)); + } +} + + + + + +void cProtocol_1_12_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) +{ + cServer * Server = cRoot::Get()->GetServer(); + AString ServerDescription = Server->GetDescription(); + auto NumPlayers = static_cast(Server->GetNumPlayers()); + auto MaxPlayers = static_cast(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); +} -- cgit v1.2.3