Exemplo n.º 1
0
        public void HandleStatusResponse(MinecraftClient client, IPacket packet) {
            string versionName, MOTD; // -- Variables that are enclosed in json.
            int ProtocolVersion, MaxPlayers, OnlinePlayers;
            List<string> Players = null;
            Image favicon = null;

            var Response = (CBResponse)packet;
            var jsonObj = JToken.Parse(Response.JSONResponse);

            versionName = jsonObj["version"]["name"].Value<string>();
            ProtocolVersion = jsonObj["version"]["protocol"].Value<int>();

            MaxPlayers = jsonObj["players"]["max"].Value<int>(); ;
            OnlinePlayers = jsonObj["players"]["online"].Value<int>();

            var tempPlayers = jsonObj["players"]["sample"];

            if (tempPlayers != null) {
                Players = new List<string>();

                foreach (JObject b in tempPlayers) {
                    Players.Add(b.Last.First.ToString());
                }
            }

            MOTD = jsonObj["description"].Value<string>();
            string imageString = jsonObj["favicon"].Value<string>();

            if (imageString != null) {
                try {
                    var imageBytes = Convert.FromBase64String(imageString.Replace("data:image/png;base64,", ""));

                    var ms = new MemoryStream(imageBytes);
                    favicon = Image.FromStream(ms, false, true);
                    ms.Close();
                } catch {
                    favicon = null;
                }
            }

            client.RaisePingResponse(versionName, ProtocolVersion, MaxPlayers, OnlinePlayers, Players.ToArray(), MOTD, favicon);

            var Ping = new SBPing();
            Ping.Time = DateTime.UtcNow.Ticks;
            Ping.Write(client.nh.wSock);
        }
Exemplo n.º 2
0
        public void HandleStatusResponse(MinecraftClient client, IPacket packet) {
            List<string> players = null;
            Image favicon = null;

            var response = (CbResponse)packet;
            var jsonObj = JToken.Parse(response.JsonResponse);

            var versionName = jsonObj["version"]["name"].Value<string>();
            var protocolVersion = jsonObj["version"]["protocol"].Value<int>();

            var maxPlayers = jsonObj["players"]["max"].Value<int>();
            var onlinePlayers = jsonObj["players"]["online"].Value<int>();

            var tempPlayers = jsonObj["players"]["sample"];

            if (tempPlayers != null) {
                players = new List<string>();

                foreach (var jToken in tempPlayers) {
                    var b = (JObject) jToken;
                    players.Add(b.Last.First.ToString());
                }
            }

            var motd = jsonObj["description"].Value<string>();
            var imageString = jsonObj["favicon"].Value<string>();

            if (imageString != null) {
                try {
                    var imageBytes = Convert.FromBase64String(imageString.Replace("data:image/png;base64,", ""));

                    var ms = new MemoryStream(imageBytes);
                    favicon = Image.FromStream(ms, false, true);
                    ms.Close();
                } catch {
                    favicon = null;
                }
            }

            if (players != null)
                client.RaisePingResponse(versionName, protocolVersion, maxPlayers, onlinePlayers, players.ToArray(), motd, favicon);

            var ping = new SbPing {Time = DateTime.UtcNow.Ticks};
            ping.Write(client.Nh.WSock);
        }