Player querying

The main way to deal with player information is through the PlayerCollection and Player classes.


PlayerCollection is an implementation of IPlayerCollection, which deals with IPlayers. While it is unsafe and a mistake to treat all IPlayers as Players, it is safe to do so in this case, if you desire.

RconClient client;

//PlayerCollection needs an ISynchronousRconClient to interact with the server
PlayerCollection players = new PlayerCollection(client);

Console.WriteLine("Players in server: {0}", players.Count);

//PlayerCollection's indexer returns Player
//unsafe to do this if there are no players :D
Player player1 = players[0];

//supports foreach loop
foreach (Player p in players)


The Player class contains the data of a player. There are a few ways to access this data, as seen below. Note that other implementations of IPlayer may not support all features.

PlayerCollection players;
Player player1;

Console.WriteLine("Name of player 1: {0}", player1.Name);

//Player's indexer takes a property (as indicated in protocol documentation) and returns its value as a string
//Player also supports TryGetProperty
Console.WriteLine("Score of player 1: {0}", player1["score"]);

foreach (dynamic player in players)
    //when cast to a dynamic, the Player class will get the property this way, as well as attempt to convert it to its proper type
    int score = player.Score;

Last edited Dec 8, 2013 at 12:26 AM by Timiz0r, version 1