private void FromMessage(byte[] msg) { int i = 4; byte first = msg[i]; if (first == (byte)PacketType.A2S_PLAYER) // Skip first byte if you haven't already. { first = msg[++i]; } this.NumPlayers = first; this.players = new List <IPlayer> (this.NumPlayers); for (int p = 0; p < this.NumPlayers; ++p) { var player = new SourcePlayer(); player.Index = msg[++i]; player.Name = ByteExtensions.GetString(msg, ++i, ref i); player.Score = ByteExtensions.GetInt32(msg, i, ref i); player.TimeConnected = ByteExtensions.GetSingle(msg, i, ref i); this.players.Add(player); } }
private void FromMessage(byte[] msg) { int i = 4; byte first = msg[i]; if (first == (byte)PacketType.A2S_INFO) // Skip first byte if you haven't already. { first = msg[++i]; } this.Version = first; this.ServerName = ByteExtensions.GetString(msg, ++i, ref i); this.MapName = ByteExtensions.GetString(msg, i, ref i); this.GameDirectory = ByteExtensions.GetString(msg, i, ref i); this.GameDescription = ByteExtensions.GetString(msg, i, ref i); this.Application = (SteamApplication)ByteExtensions.GetShort(msg, i, ref i); this.NumPlayers = msg[i]; this.MaxPlayers = msg[++i]; this.NumBots = msg[++i]; this.Dedicated = (Dedicated)msg[++i]; this.HostOS = (HostOS)msg[++i]; this.IsPassworded = (msg[++i] == 0x01); this.IsSecure = (msg[++i] == 0x01); this.GameVersion = ByteExtensions.GetString(msg, i, ref i); var edf = (ExtraDataFlag)msg[i]; if ((edf & ExtraDataFlag.GamePort) == ExtraDataFlag.GamePort) { this.GameServerPort = ByteExtensions.GetShort(msg, i, ref i); } if ((edf & ExtraDataFlag.Spectator) == ExtraDataFlag.Spectator) { this.SpectatorPort = ByteExtensions.GetShort(msg, i, ref i); this.SpectatorServerName = ByteExtensions.GetString(msg, i, ref i); } if ((edf & ExtraDataFlag.GameTagData) == ExtraDataFlag.GameTagData) { this.GameTagData = ByteExtensions.GetString(msg, i, ref i); } }
private void QueryServer() { try { if (this.lastInfo != null && (DateTime.Now.Subtract(this.lastQuery)).TotalSeconds < 5) { return; } this.lastQuery = DateTime.Now; byte[] header = BitConverter.GetBytes(-1); byte[] status = Encoding.ASCII.GetBytes("getstatus"); byte[] msg = new byte[header.Length + status.Length]; for (int n = 0; n < header.Length; ++n) { msg[n] = header[n]; } for (int n = 0; n < status.Length; ++n) { msg[header.Length + n] = status[n]; } this.sock.Send(msg); byte[] buffer = new byte[1500]; this.sock.Receive(buffer); int i = 4; string type = ByteExtensions.GetString(buffer, i, ref i, '\n'); string results = ByteExtensions.GetString(buffer, i, ref i); var propMatches = PropertyMatcher.Matches(results); var properties = new Dictionary <string, string> (); foreach (Match property in propMatches) { properties.Add(property.Groups["key"].Value, property.Groups["value"].Value); } var players = new List <IPlayer> (); var matches = PlayerMatcher.Matches(results); foreach (Match m in matches) { players.Add(new Player { Name = m.Groups["name"].Value, Score = int.Parse(m.Groups["score"].Value) }); } //^0 black // IRC 1,0 //^1 red // IRC 4 //^2 green // IRC 3 //^3 yellow // IRC 8 //^4 blue // IRC 2 //^5 cyan // IRC 11 //^6 magenta // IRC 6 //^7 white // IRC 0,1 this.lastPlayers = players; this.lastInfo = new ServerInfo() { ServerName = properties["sv_hostname"], MapName = properties["mapname"], NumPlayers = players.Count, MaxPlayers = int.Parse(properties["sv_maxclients"]) }; } catch (SocketException ex) { throw new GameServerException(ex); } }
public void ConvertEmptyByteArrayToString() { string actual = ByteExtensions.GetString(new byte[] { }); Assert.IsNull(actual); }
public void ConvertNullByteArrayToString() { string actual = ByteExtensions.GetString(null); Assert.IsNull(actual); }