Ejemplo n.º 1
0
        public ServerPlayers GetServerChallengeSync(GetServerInfoSettings settings)
        {
            var localEndpoint = new IPEndPoint(IPAddress.Any, 0);

            using (var client = new UdpClient(localEndpoint))
            {
                client.Client.ReceiveTimeout = settings.ReceiveTimeout;
                client.Client.SendTimeout    = settings.SendTimeout;

                client.Connect(EndPoint);

                var requestPacket = new List <byte>();
                requestPacket.AddRange(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0x55 });
                requestPacket.AddRange(BitConverter.GetBytes(-1));

                client.Send(requestPacket.ToArray(), requestPacket.ToArray().Length);
                var responseData = client.Receive(ref localEndpoint);
                requestPacket.Clear();
                requestPacket.AddRange(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0x55 });
                requestPacket.AddRange(responseData.Skip(5).Take(4));
                client.Send(requestPacket.ToArray(), requestPacket.ToArray().Length);
                responseData = client.Receive(ref localEndpoint);

                return(ServerPlayers.Parse(responseData));
            }
        }
Ejemplo n.º 2
0
        public static ServerPlayers Parse(byte[] data)
        {
            var parser = new ResponseParser(data);

            parser.CurrentPosition += 5; //Header
            var result = new ServerPlayers();


            result.PlayerCount = parser.GetByte();

            result.Players = new PlayerInfo[result.PlayerCount];

            for (var i = 0; i < result.PlayerCount; i++)
            {
                var p = new PlayerInfo();

                p.N     = parser.GetByte();
                p.Name  = parser.GetStringToTermination();
                p.Score = parser.GetLong();
                p.Time  = TimeSpan.FromSeconds(parser.GetDouble());

                //parser.CurrentPosition+=4;

                result.Players[i] = p;


                //break;
            }


            return(result);
        }
Ejemplo n.º 3
0
        public static ServerPlayers Parse(byte[] data)
        {
            var parser = new ResponseParser(data);
            parser.CurrentPosition += 5; //Header
            var result = new ServerPlayers();

            result.PlayerCount = parser.GetByte();

            result.Players = new PlayerInfo[result.PlayerCount];

            for (var i = 0; i < result.PlayerCount; i++)
            {
                var p = new PlayerInfo();

                p.N = parser.GetByte();
                p.Name = parser.GetStringToTermination();
                p.Score = parser.GetLong();
                p.Time = TimeSpan.FromSeconds(parser.GetDouble());

                //parser.CurrentPosition+=4;

                result.Players[i] = p;

                //break;
            }

            return result;
        }
        public ServerMonitorSteamQueryViewModel(string host, int port, ILog log)
        {
            _log = log;
            Host = host;
            Port = port + 1;

            RaisePropertyChanged("Host");
            RaisePropertyChanged("Port");

            ExcecuteCommand = new ActionCommand(() => Task.Run(() =>
            {
                var iphost = IPHelper.GetIPAddress(Host);
                var server = new Server(new IPEndPoint(IPAddress.Parse(iphost), Port));

                var settings = new GetServerInfoSettings();
                var rules = server.GetServerRulesSync(settings);
                _serverRules =
                    rules.Select(
                        x =>
                            new Tuple<string, string>(x.Key,
                                x.Value)).ToList();

                var serverInfo =
                    server.GetServerInfoSync(settings);

                var props = serverInfo.GetType().GetProperties();

                _serverInfo =
                    props.Select(
                        x =>
                            new Tuple<string, string>(x.Name,
                                x.GetValue(serverInfo)
                                    .ToString())).ToList();

                _serverPlayers =
                    server.GetServerChallengeSync(settings);

                RaisePropertyChanged("ServerRules");
                RaisePropertyChanged("ServerInfo");
                RaisePropertyChanged("ServerPlayers");

            }),
                () =>
                {
                    var iphost = IPHelper.GetIPAddress(Host);

                    if (string.IsNullOrEmpty(iphost))
                    {
                        return false;
                    }
                    return true;
                });
        }