summaryrefslogtreecommitdiffstats
path: root/src/Protocol/Protocol17x.cpp
diff options
context:
space:
mode:
authorSTRWarrior <STRWarrior@users.noreply.github.com>2014-08-20 22:57:48 +0200
committerSTRWarrior <STRWarrior@users.noreply.github.com>2014-08-20 22:57:48 +0200
commit3a113e3a75bb345d008e13bbecae5f78ed9d9aae (patch)
treed2d17b4c0091905cb55245305292ada6dcb11d71 /src/Protocol/Protocol17x.cpp
parentMerge pull request #1335 from mc-server/CodeFixes (diff)
parentRenamed a_Motd to a_ServerDescription. (diff)
downloadcuberite-3a113e3a75bb345d008e13bbecae5f78ed9d9aae.tar
cuberite-3a113e3a75bb345d008e13bbecae5f78ed9d9aae.tar.gz
cuberite-3a113e3a75bb345d008e13bbecae5f78ed9d9aae.tar.bz2
cuberite-3a113e3a75bb345d008e13bbecae5f78ed9d9aae.tar.lz
cuberite-3a113e3a75bb345d008e13bbecae5f78ed9d9aae.tar.xz
cuberite-3a113e3a75bb345d008e13bbecae5f78ed9d9aae.tar.zst
cuberite-3a113e3a75bb345d008e13bbecae5f78ed9d9aae.zip
Diffstat (limited to 'src/Protocol/Protocol17x.cpp')
-rw-r--r--src/Protocol/Protocol17x.cpp98
1 files changed, 70 insertions, 28 deletions
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 56e73c1c1..a8df948cd 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -41,6 +41,7 @@ Implements the 1.7.x protocol classes:
#include "../BlockEntities/CommandBlockEntity.h"
#include "../BlockEntities/MobHeadEntity.h"
#include "../BlockEntities/FlowerPotEntity.h"
+#include "Bindings/PluginManager.h"
@@ -1720,21 +1721,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 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"] = "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"] = 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());
+ }
+
+ Json::StyledWriter Writer;
+ AString Response = Writer.write(ResponseValue);
+
cPacketizer Pkt(*this, 0x00); // Response packet
Pkt.WriteString(Response);
}
@@ -3070,20 +3091,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(*m_Client, 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);
}