mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-29 13:04:59 +00:00
Fix 1.7+ server list ping by properly parsing Json
Separate Json and ChatParser classes Use Json parser for retrieving Json fields Will avoid wrong "name" field from being used
This commit is contained in:
parent
a7f0897f09
commit
67affc6270
4 changed files with 202 additions and 159 deletions
|
|
@ -580,18 +580,21 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
if (ComTmp.readNextVarInt() == 0x00) //Read Packet ID
|
||||
{
|
||||
string result = ComTmp.readNextString(); //Get the Json data
|
||||
if (result[0] == '{' && result.Contains("protocol\":") && result.Contains("name\":\""))
|
||||
if (!String.IsNullOrEmpty(result) && result.StartsWith("{") && result.EndsWith("}"))
|
||||
{
|
||||
string[] tmp_ver = result.Split(new string[] { "protocol\":" }, StringSplitOptions.None);
|
||||
string[] tmp_name = result.Split(new string[] { "name\":\"" }, StringSplitOptions.None);
|
||||
|
||||
if (tmp_ver.Length >= 2 && tmp_name.Length >= 2)
|
||||
Json.JSONData jsonData = Json.ParseJson(result);
|
||||
if (jsonData.Type == Json.JSONData.DataType.Object && jsonData.Properties.ContainsKey("version"))
|
||||
{
|
||||
protocolversion = atoi(tmp_ver[1]);
|
||||
jsonData = jsonData.Properties["version"];
|
||||
|
||||
//Retrieve display name of the Minecraft version
|
||||
if (jsonData.Properties.ContainsKey("name"))
|
||||
version = jsonData.Properties["name"].StringValue;
|
||||
|
||||
//Retrieve protocol version number for handling this server
|
||||
if (jsonData.Properties.ContainsKey("protocol"))
|
||||
protocolversion = atoi(jsonData.Properties["protocol"].StringValue);
|
||||
|
||||
//Handle if "name" exists twice, eg when connecting to a server with another user logged in.
|
||||
version = (tmp_name.Length == 2) ? tmp_name[1].Split('"')[0] : tmp_name[2].Split('"')[0];
|
||||
|
||||
//Automatic fix for BungeeCord 1.8 not properly reporting protocol version
|
||||
if (protocolversion < 47 && version.Split(' ').Contains("1.8"))
|
||||
protocolversion = ProtocolHandler.MCVer2ProtocolVersion("1.8.0");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue