From 47c928cab7d1ff73e50925bc7ef50586b6ec9821 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 11 Aug 2014 00:20:28 +0200 Subject: Exported daylight cycle flag to the protocol. --- src/Protocol/Protocol17x.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/Protocol/Protocol17x.cpp') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 318342f09..a724133fc 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1286,9 +1286,14 @@ void cProtocol172::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) -void cProtocol172::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay) +void cProtocol172::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) { ASSERT(m_State == 3); // In game mode? + if (!a_DoDaylightCycle) + { + // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration. + a_TimeOfDay = std::min(-a_TimeOfDay, -1LL); + } cPacketizer Pkt(*this, 0x03); Pkt.WriteInt64(a_WorldAge); -- cgit v1.2.3 From 0a52ed6eb97ca5cc08fe255bfd04f78b4ea19a7e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 11 Aug 2014 15:33:20 +0200 Subject: cProtocol172: Check return values. Fixes CID 43489, CID 43490, CID 43491, CID 43493, CID 66410, CID 66411, CID 66416, CID 66417, CID 66418, CID 66419, CID 66420, CID 66421, CID 66422, CID 66423, CID 66424, CID 66425, CID 66429, CID 66430, CID 66431 --- src/Protocol/Protocol17x.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/Protocol/Protocol17x.cpp') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 318342f09..1f8ca00bb 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -48,7 +48,10 @@ Implements the 1.7.x protocol classes: #define HANDLE_READ(ByteBuf, Proc, Type, Var) \ Type Var; \ - ByteBuf.Proc(Var); + if (!ByteBuf.Proc(Var))\ + {\ + return;\ + } @@ -1700,8 +1703,7 @@ bool cProtocol172::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) void cProtocol172::HandlePacketStatusPing(cByteBuffer & a_ByteBuffer) { - Int64 Timestamp; - a_ByteBuffer.ReadBEInt64(Timestamp); + HANDLE_READ(a_ByteBuffer, ReadBEInt64, Int64, Timestamp); cPacketizer Pkt(*this, 0x01); // Ping packet Pkt.WriteInt64(Timestamp); @@ -2054,7 +2056,10 @@ void cProtocol172::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Channel); HANDLE_READ(a_ByteBuffer, ReadBEShort, short, Length); AString Data; - a_ByteBuffer.ReadString(Data, Length); + if (!a_ByteBuffer.ReadString(Data, Length)) + { + return; + } m_Client->HandlePluginMessage(Channel, Data); } -- cgit v1.2.3 From 228dd61995a404b6c59832bf8b0f8375374c8acc Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 20 Aug 2014 16:01:30 +0200 Subject: Added HOOK_SERVER_PING --- src/Protocol/Protocol17x.cpp | 99 +++++++++++++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 28 deletions(-) (limited to 'src/Protocol/Protocol17x.cpp') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 1f8ca00bb..31a140c73 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -41,6 +41,8 @@ Implements the 1.7.x protocol classes: #include "../BlockEntities/CommandBlockEntity.h" #include "../BlockEntities/MobHeadEntity.h" #include "../BlockEntities/FlowerPotEntity.h" +#include "Bindings/PluginManager.h" +#include "lua/src/llex.h" @@ -1715,21 +1717,41 @@ void cProtocol172::HandlePacketStatusPing(cByteBuffer & a_ByteBuffer) void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) { - // Send the response: - AString Response = "{\"version\":{\"name\":\"1.7.2\", \"protocol\":4}, \"players\":{"; cServer * Server = cRoot::Get()->GetServer(); - AppendPrintf(Response, "\"max\":%u, \"online\":%u, \"sample\":[]},", - Server->GetMaxPlayers(), - Server->GetNumPlayers() - ); - AppendPrintf(Response, "\"description\":{\"text\":\"%s\"},", - Server->GetDescription().c_str() - ); - AppendPrintf(Response, "\"favicon\": \"data:image/png;base64,%s\"", - Server->GetFaviconData().c_str() - ); - Response.append("}"); - + AString Motd = Server->GetDescription(); + int NumPlayers = Server->GetNumPlayers(); + int MaxPlayers = Server->GetMaxPlayers(); + AString Favicon = Server->GetFaviconData(); + cRoot::Get()->GetPluginManager()->CallHookServerPing(Motd, NumPlayers, MaxPlayers, Favicon); + + // Version: + Json::Value Version; + Version["name"] = "1.7.2"; + Version["protocol"] = 4; + + // Players: + Json::Value Players; + Players["online"] = NumPlayers; + Players["max"] = MaxPlayers; + // TODO: Add "sample" + + // Description: + Json::Value Description; + Description["text"] = Motd.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()); + } + + Json::StyledWriter Writer; + AString Response = Writer.write(ResponseValue); + cPacketizer Pkt(*this, 0x00); // Response packet Pkt.WriteString(Response); } @@ -3065,20 +3087,41 @@ void cProtocol176::SendPlayerSpawn(const cPlayer & a_Player) void cProtocol176::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) { - // Send the response: - AString Response = "{\"version\": {\"name\": \"1.7.6\", \"protocol\":5}, \"players\": {"; - AppendPrintf(Response, "\"max\": %u, \"online\": %u, \"sample\": []},", - cRoot::Get()->GetServer()->GetMaxPlayers(), - cRoot::Get()->GetServer()->GetNumPlayers() - ); - AppendPrintf(Response, "\"description\": {\"text\": \"%s\"},", - cRoot::Get()->GetServer()->GetDescription().c_str() - ); - AppendPrintf(Response, "\"favicon\": \"data:image/png;base64,%s\"", - cRoot::Get()->GetServer()->GetFaviconData().c_str() - ); - Response.append("}"); - + cServer * Server = cRoot::Get()->GetServer(); + AString Motd = Server->GetDescription(); + int NumPlayers = Server->GetNumPlayers(); + int MaxPlayers = Server->GetMaxPlayers(); + AString Favicon = Server->GetFaviconData(); + cRoot::Get()->GetPluginManager()->CallHookServerPing(Motd, NumPlayers, MaxPlayers, Favicon); + + // Version: + Json::Value Version; + Version["name"] = "1.7.6"; + Version["protocol"] = 5; + + // Players: + Json::Value Players; + Players["online"] = NumPlayers; + Players["max"] = MaxPlayers; + // TODO: Add "sample" + + // Description: + Json::Value Description; + Description["text"] = Motd.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()); + } + + Json::StyledWriter Writer; + AString Response = Writer.write(ResponseValue); + cPacketizer Pkt(*this, 0x00); // Response packet Pkt.WriteString(Response); } -- cgit v1.2.3 From 2cca4d70c8b3908bcd692fffb937c0fa6b5b29a3 Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 20 Aug 2014 16:04:18 +0200 Subject: Cleaned up code. --- src/Protocol/Protocol17x.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/Protocol/Protocol17x.cpp') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 31a140c73..0a9d70bcc 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -42,7 +42,6 @@ Implements the 1.7.x protocol classes: #include "../BlockEntities/MobHeadEntity.h" #include "../BlockEntities/FlowerPotEntity.h" #include "Bindings/PluginManager.h" -#include "lua/src/llex.h" -- cgit v1.2.3 From cf5ab14ca59904e208bf6cb9d87134f01803eeed Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 20 Aug 2014 22:19:50 +0200 Subject: Added a_ClientHandle to the HOOK_SERVER_PING hook. --- src/Protocol/Protocol17x.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Protocol/Protocol17x.cpp') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 0a9d70bcc..565532913 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1721,7 +1721,7 @@ void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) int NumPlayers = Server->GetNumPlayers(); int MaxPlayers = Server->GetMaxPlayers(); AString Favicon = Server->GetFaviconData(); - cRoot::Get()->GetPluginManager()->CallHookServerPing(Motd, NumPlayers, MaxPlayers, Favicon); + cRoot::Get()->GetPluginManager()->CallHookServerPing(*m_Client, Motd, NumPlayers, MaxPlayers, Favicon); // Version: Json::Value Version; @@ -3091,7 +3091,7 @@ void cProtocol176::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) int NumPlayers = Server->GetNumPlayers(); int MaxPlayers = Server->GetMaxPlayers(); AString Favicon = Server->GetFaviconData(); - cRoot::Get()->GetPluginManager()->CallHookServerPing(Motd, NumPlayers, MaxPlayers, Favicon); + cRoot::Get()->GetPluginManager()->CallHookServerPing(*m_Client, Motd, NumPlayers, MaxPlayers, Favicon); // Version: Json::Value Version; -- cgit v1.2.3 From 4da61e67d7638c46dc56fe451e81a5b4b0f134db Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 20 Aug 2014 22:22:38 +0200 Subject: Renamed a_Motd to a_ServerDescription. --- src/Protocol/Protocol17x.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Protocol/Protocol17x.cpp') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 565532913..59db0b7d8 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1717,11 +1717,11 @@ void cProtocol172::HandlePacketStatusPing(cByteBuffer & a_ByteBuffer) void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) { cServer * Server = cRoot::Get()->GetServer(); - AString Motd = Server->GetDescription(); + AString ServerDescription = Server->GetDescription(); int NumPlayers = Server->GetNumPlayers(); int MaxPlayers = Server->GetMaxPlayers(); AString Favicon = Server->GetFaviconData(); - cRoot::Get()->GetPluginManager()->CallHookServerPing(*m_Client, Motd, NumPlayers, MaxPlayers, Favicon); + cRoot::Get()->GetPluginManager()->CallHookServerPing(*m_Client, ServerDescription, NumPlayers, MaxPlayers, Favicon); // Version: Json::Value Version; @@ -1736,7 +1736,7 @@ void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) // Description: Json::Value Description; - Description["text"] = Motd.c_str(); + Description["text"] = ServerDescription.c_str(); // Create the response: Json::Value ResponseValue; -- cgit v1.2.3 From d471ee8a9d93d1c793db316b00dcc8eddcdc2c2a Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 21 Aug 2014 21:38:57 +0200 Subject: Fixed 1.7.2 login packet reading. Fixes #1317. --- src/Protocol/Protocol17x.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/Protocol/Protocol17x.cpp') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index a8df948cd..1091b877f 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1824,7 +1824,11 @@ void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffe void cProtocol172::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer) { AString Username; - a_ByteBuffer.ReadVarUTF8String(Username); + if (!a_ByteBuffer.ReadVarUTF8String(Username)) + { + m_Client->Kick("Bad username"); + return; + } if (!m_Client->HandleHandshake(Username)) { -- cgit v1.2.3