Beispiel #1
0
        private ServerInfo Current(byte[] data)
        {
            var parser = new Parser(data);

            if (parser.ReadByte() != (byte)ResponseMsgHeader.A2S_INFO)
            {
                throw new InvalidHeaderException("A2S_INFO message header is not valid");
            }
            var server = new ServerInfo();

            server.IsObsolete  = false;
            server.Protocol    = parser.ReadByte();
            server.Name        = parser.ReadString();
            server.Map         = parser.ReadString();
            server.Directory   = parser.ReadString();
            server.Description = parser.ReadString();
            server.Id          = parser.ReadShort();
            server.Players     = parser.ReadByte();
            server.MaxPlayers  = parser.ReadByte();
            server.Bots        = parser.ReadByte();
            server.ServerType  = (new Func <string>(() =>
            {
                switch ((char)parser.ReadByte())
                {
                case 'l': return("Listen");

                case 'd': return("Dedicated");

                case 'p': return("SourceTV");
                }
                return("");
            }))();
            server.Environment = (new Func <string>(() =>
            {
                switch ((char)parser.ReadByte())
                {
                case 'l': return("Linux");

                case 'w': return("Windows");

                case 'm': return("Mac");
                }
                return("");
            }))();
            server.IsPrivate = Convert.ToBoolean(parser.ReadByte());
            server.IsSecure  = Convert.ToBoolean(parser.ReadByte());
            if (server.Id >= 2400 && server.Id <= 2412)
            {
                var ship = new TheShip();
                switch (parser.ReadByte())
                {
                case 0: ship.Mode = "Hunt"; break;

                case 1: ship.Mode = "Elimination"; break;

                case 2: ship.Mode = "Duel"; break;

                case 3: ship.Mode = "Deathmatch"; break;

                case 4: ship.Mode = "VIP Team"; break;

                case 5: ship.Mode = "Team Elimination"; break;

                default: ship.Mode = ""; break;
                }
                ship.Witnesses  = parser.ReadByte();
                ship.Duration   = parser.ReadByte();
                server.ShipInfo = ship;
            }

            server.GameVersion = parser.ReadString();
            if (parser.HasMore)
            {
                var edf  = parser.ReadByte();
                var info = new ExtraInfo();
                info.Port    = (edf & 0x80) > 0 ? parser.ReadShort() : (ushort)0;
                info.SteamID = (edf & 0x10) > 0 ? parser.ReadLong() : 0;
                if ((edf & 0x40) > 0)
                {
                    info.SpecInfo = new SourceTVInfo {
                        Port = parser.ReadShort(), Name = parser.ReadString()
                    }
                }
                ;
                info.Keywords = (edf & 0x20) > 0 ? parser.ReadString() : string.Empty;
                info.GameId   = (edf & 0x01) > 0 ? parser.ReadLong() : 0;
                server.Extra  = info;
            }
            server.Address = socket.Address.Address + ":" + socket.Address.Port;
            server.Ping    = Latency;
            return(server);
        }
Beispiel #2
0
        private ServerInfo Current(byte[] data)
        {
            var parser = new Parser(data);
              if (parser.ReadByte() != (byte) ResponseMsgHeader.A2S_INFO)
            throw new InvalidHeaderException("A2S_INFO message header is not valid");
              var server = new ServerInfo();
              server.IsObsolete = false;
              server.Protocol = parser.ReadByte();
              server.Name = parser.ReadString();
              server.Map = parser.ReadString();
              server.Directory = parser.ReadString();
              server.Description = parser.ReadString();
              server.Id = parser.ReadShort();
              server.Players = parser.ReadByte();
              server.MaxPlayers = parser.ReadByte();
              server.Bots = parser.ReadByte();
              server.ServerType = (new Func<string>(() =>
              {
            switch ((char) parser.ReadByte())
            {
              case 'l': return "Listen";
              case 'd': return "Dedicated";
              case 'p': return "SourceTV";
            }
            return "";
              }))();
              server.Environment = (new Func<string>(() =>
              {
            switch ((char) parser.ReadByte())
            {
              case 'l': return "Linux";
              case 'w': return "Windows";
              case 'm': return "Mac";
            }
            return "";
              }))();
              server.IsPrivate = Convert.ToBoolean(parser.ReadByte());
              server.IsSecure = Convert.ToBoolean(parser.ReadByte());
              if (server.Id >= 2400 && server.Id <= 2412)
              {
            var ship = new TheShip();
            switch (parser.ReadByte())
            {
              case 0: ship.Mode = "Hunt"; break;
              case 1: ship.Mode = "Elimination"; break;
              case 2: ship.Mode = "Duel"; break;
              case 3: ship.Mode = "Deathmatch"; break;
              case 4: ship.Mode = "VIP Team"; break;
              case 5: ship.Mode = "Team Elimination"; break;
              default: ship.Mode = ""; break;
            }
            ship.Witnesses = parser.ReadByte();
            ship.Duration = parser.ReadByte();
            server.ShipInfo = ship;
              }

              server.GameVersion = parser.ReadString();
              if (parser.HasMore)
              {
            var edf = parser.ReadByte();
            var info = new ExtraInfo();
            info.Port = (edf & 0x80) > 0 ? parser.ReadShort() : (ushort)0;
            info.SteamID = (edf & 0x10) > 0 ? parser.ReadLong() : 0;
            if ((edf & 0x40) > 0)
              info.SpecInfo = new SourceTVInfo {Port = parser.ReadShort(), Name = parser.ReadString()};
            info.Keywords = (edf & 0x20) > 0 ? parser.ReadString() : string.Empty;
            info.GameId = (edf & 0x01) > 0 ? parser.ReadLong() : 0;
            server.Extra = info;
              }
              server.Address = socket.Address.Address + ":" + socket.Address.Port;
              server.Ping = Latency;
              return server;
        }
Beispiel #3
0
 public ServerInfo()
 {
     Extra = new ExtraInfo();
 }