Exemplo n.º 1
0
 public static ServerPing DoPing(IPEndPoint endPoint)
 {
     var client = new TcpClient();
     client.Connect(endPoint);
     var stream = new MinecraftStream(client.GetStream());
     var ping = new ServerListPingPacket(1);
     ping.WritePacket(stream);
     var response = PacketReader.ReadPacket(stream);
     client.Close();
     // TODO: Handle old pings
     var pong = (DisconnectPacket)response;
     var parts = pong.Reason.Substring(3).Split('\0');
     var result = new ServerPing();
     result.ProtocolVersion = int.Parse(parts[0]);
     result.ServerVersion = parts[1];
     result.MotD = parts[2];
     result.CurrentPlayers = int.Parse(parts[3]);
     result.MaxPlayers = int.Parse(parts[4]);
     return result;
 }
Exemplo n.º 2
0
        public static ServerPing DoPing(IPEndPoint endPoint)
        {
            var client = new TcpClient();

            client.Connect(endPoint);
            var stream = new MinecraftStream(client.GetStream());
            var ping   = new ServerListPingPacket(1);

            ping.WritePacket(stream);
            var response = PacketReader.ReadPacket(stream);

            client.Close();
            // TODO: Handle old pings
            var pong   = (DisconnectPacket)response;
            var parts  = pong.Reason.Substring(3).Split('\0');
            var result = new ServerPing();

            result.ProtocolVersion = int.Parse(parts[0]);
            result.ServerVersion   = parts[1];
            result.MotD            = parts[2];
            result.CurrentPlayers  = int.Parse(parts[3]);
            result.MaxPlayers      = int.Parse(parts[4]);
            return(result);
        }