Exemplo n.º 1
0
        public async Task <SteamServerInfo> GetServerInfoAsync()
        {
            var response = await GetServerResponseAsync(QueryMsg.InfoQuery).ConfigureAwait(false);

            return(SteamServerInfo.Parse(response)); // Skip header
        }
Exemplo n.º 2
0
        public static SteamServerInfo Parse(byte[] data)
        {
            SteamServerInfo serverInfo = null;
            Parser          parser     = new Parser(data);

            if (parser.ReadByte() != (byte)ResponseMsgHeader.A2S_INFO)
            {
                throw new Exception("A2S_INFO message header is not valid");
            }
            serverInfo = new SteamServerInfo
            {
                Protocol    = parser.ReadByte(),
                Name        = parser.ReadString(),
                Map         = parser.ReadString(),
                Directory   = parser.ReadString(),
                Description = parser.ReadString(),
                Id          = parser.ReadUShort(),
                Players     = parser.ReadByte(),
                MaxPlayers  = parser.ReadByte(),
                Bots        = parser.ReadByte(),
                ServerType  = new Func <GameServertype>(() =>
                {
                    switch ((char)parser.ReadByte())
                    {
                    case 'l': return(GameServertype.Listen);

                    case 'd': return(GameServertype.Dedicated);

                    case 'p': return(GameServertype.SourceTV);
                    }
                    return(GameServertype.Invalid);
                })(),
                Environment = new Func <GameEnvironment>(() =>
                {
                    switch ((char)parser.ReadByte())
                    {
                    case 'l': return(GameEnvironment.Linux);

                    case 'w': return(GameEnvironment.Windows);

                    case 'm': return(GameEnvironment.Mac);

                    case 'o': return(GameEnvironment.Mac);
                    }
                    return(GameEnvironment.Invalid);
                })(),
                IsPrivate = parser.ReadByte() > 0,
                IsSecure  = parser.ReadByte() > 0,

                GameVersion = parser.ReadString()
            };

            if (parser.HasUnParsedBytes)
            {
                byte edf = parser.ReadByte();
                serverInfo.Port    = (edf & 0x80) > 0 ? parser.ReadUShort() : (ushort)0;
                serverInfo.SteamId = (edf & 0x10) > 0 ? parser.ReadULong() : 0;
                if ((edf & 0x40) > 0)
                {
                    serverInfo.SourceTVPort = parser.ReadUShort();
                    serverInfo.SourceTVName = parser.ReadString();
                }
                serverInfo.Keywords = (edf & 0x20) > 0 ? parser.ReadString() : string.Empty;
                serverInfo.GameId   = (edf & 0x10) > 0 ? parser.ReadULong() : 0;
            }
            //serverInfo.Address = UdpSocket.Address.ToString();
            //serverInfo.Ping = Latency;

            return(serverInfo);
        }