MCPcopy Create free account
hub / github.com/cuberite/cuberite / SendLengthlessServerPing

Method SendLengthlessServerPing

src/Protocol/ProtocolRecognizer.cpp:980–1049  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

978
979
980void cProtocolRecognizer::SendLengthlessServerPing(void)
981{
982 AString Reply;
983 switch (cRoot::Get()->GetPrimaryServerVersion())
984 {
985 case PROTO_VERSION_1_2_5:
986 case PROTO_VERSION_1_3_2:
987 {
988 // http://wiki.vg/wiki/index.php?title=Protocol&oldid=3099#Server_List_Ping_.280xFE.29
989 Printf(Reply, "%s%s%i%s%i",
990 cRoot::Get()->GetServer()->GetDescription().c_str(),
991 cChatColor::Delimiter.c_str(),
992 cRoot::Get()->GetServer()->GetNumPlayers(),
993 cChatColor::Delimiter.c_str(),
994 cRoot::Get()->GetServer()->GetMaxPlayers()
995 );
996 break;
997 }
998
999 case PROTO_VERSION_1_4_2:
1000 case PROTO_VERSION_1_4_4:
1001 case PROTO_VERSION_1_4_6:
1002 case PROTO_VERSION_1_5_0:
1003 case PROTO_VERSION_1_5_2:
1004 case PROTO_VERSION_1_6_1:
1005 case PROTO_VERSION_1_6_2:
1006 case PROTO_VERSION_1_6_3:
1007 case PROTO_VERSION_1_6_4:
1008 {
1009 // The server list ping now has 1 more byte of "magic". Mojang just loves to complicate stuff.
1010 // http://wiki.vg/wiki/index.php?title=Protocol&oldid=3101#Server_List_Ping_.280xFE.29
1011 // _X 2012_10_31: I know that this needn't eat the byte, since it still may be in transit.
1012 // Who cares? We're disconnecting anyway.
1013 m_Buffer.ResetRead();
1014 if (m_Buffer.CanReadBytes(2))
1015 {
1016 Byte val;
1017 m_Buffer.ReadByte(val); // Packet type - Serverlist ping
1018 m_Buffer.ReadByte(val); // 0x01 magic value
1019 ASSERT(val == 0x01);
1020 }
1021
1022 // http://wiki.vg/wiki/index.php?title=Server_List_Ping&oldid=3100
1023 AString NumPlayers;
1024 Printf(NumPlayers, "%d", cRoot::Get()->GetServer()->GetNumPlayers());
1025 AString MaxPlayers;
1026 Printf(MaxPlayers, "%d", cRoot::Get()->GetServer()->GetMaxPlayers());
1027
1028 AString ProtocolVersionNum;
1029 Printf(ProtocolVersionNum, "%d", cRoot::Get()->GetPrimaryServerVersion());
1030 AString ProtocolVersionTxt(GetVersionTextFromInt(cRoot::Get()->GetPrimaryServerVersion()));
1031
1032 // Cannot use Printf() because of in-string NUL bytes.
1033 Reply = cChatColor::Delimiter;
1034 Reply.append("1");
1035 Reply.push_back(0);
1036 Reply.append(ProtocolVersionNum);
1037 Reply.push_back(0);

Callers

nothing calls this directly

Calls 10

PrintfFunction · 0.85
c_strMethod · 0.80
GetServerMethod · 0.80
GetMaxPlayersMethod · 0.80
ResetReadMethod · 0.80
CanReadBytesMethod · 0.80
ReadByteMethod · 0.80
KickMethod · 0.80
GetNumPlayersMethod · 0.45

Tested by

no test coverage detected