public void Update() { // Query query port this.queryport = RconQuery.QueryServerInfo(hostname, Steam.CONAN_EXILES_APP_ID).ToString(); RconQuery query = new RconQuery(hostname, queryport); SourceServerInfo info = query.QueryInfo(); Dictionary <string, string> rules = query.QueryRules(); if (rules != null) { // Modlist is stored in a variable called S17_s // it contains as first line a number of mods enabled, and then // a list of workshop IDs string modlist = rules.GetValueOrDefault("S17_s", "0:0\n"); string[] mods = modlist.Split("\n", StringSplitOptions.RemoveEmptyEntries); if (mods.Length > 1) { // we have some mods, not just a list mods = mods.Skip(1).ToArray(); this.modlist.Clear(); this.modlist.AddRange(mods); } } if (info != null) { this.name = info.Name; } }
public SourceServerInfo QueryInfo() { byte[] data = SendQuery(RconQuery.A2S_INFO, Encoding.ASCII.GetBytes("Source Engine Query\0")); if (data == null || data.Length == 0) { throw new ApplicationException("no query information returned"); } MemoryStream stream = new MemoryStream(data); BinaryReader reader = new BinaryReader(stream); SourceServerInfo info = new SourceServerInfo(); // discard header reader.ReadUInt32(); if (reader.ReadByte() != A2S_INFO_REPLY) { throw new ApplicationException("invalid reply to INFO query"); } info.ProtocolVersion = reader.ReadByte(); info.Name = ReadCString(reader); info.Map = ReadCString(reader); info.Folder = ReadCString(reader); info.Game = ReadCString(reader); info.GameID = reader.ReadUInt16(); info.Players = reader.ReadByte(); info.MaxPlayers = reader.ReadByte(); info.Bots = reader.ReadByte(); info.ServerType = reader.ReadByte(); info.Environment = reader.ReadByte(); info.Visibility = reader.ReadByte(); info.VAC = reader.ReadByte(); info.Version = ReadCString(reader); byte extradata = reader.ReadByte(); if ((extradata & 0x80) == 0x80) { info.GamePort = reader.ReadUInt16(); } if ((extradata & 0x10) == 0x10) { info.ServerID = reader.ReadUInt64(); } info.ServerVersion = ReadCString(reader); return(info); }