I currently got a problem with RCon.
I am basically sending a request to receive a list of all players.
The server answers with a list of all players like this:
# IP:Port Ping ID Name
0 127.0.0.1 0 3523523 Bob
12 192.168.0.1 120 342525523 Anna
320 192.168.0.2 240 63463634634 Chuck Norris
^^^ ^^ ^^^^^ ^
The problem is, I do not know how many spaces are between the different tags, it depends on how long the #/IP/ping and ID is.
The spaces can differ from 1 space to 5 spaces.
Also there can be spaces in the name so I can't just split with one space.
I want to read the IP, ping, id and name from the list.
I currently try to do some messy replace & split stuff but it just doesn't work out when the spaces are different.
I thought about doing something with regex but I am not so good with regex.
I already split the lines to cut it down to 1 line.
The class Player can store all the informations
Here is what should happen:
// List to store all the players
List<Player> players = new List<Player>();
// Using a StringReader to split up every line
StringReader reader = new StringReader(result);
string line;
int row = 0;
// Processing every line one after another
while ((line = reader.ReadLine()) != null)
{
row++;
// Doing some filtering to prevent empty lines and other stuff
if (row > 3 && !line.StartsWith("(") && line.Length > 0)
{
// Getting all the stuff I need here
// Then adding a player object to save the informations, ignore status
players.Add(new Player(ip, ping, id, name, status));
}
}
Anyone got an idea that could solve this?