private void OnGetPlayers(Packet packet)
{
try
{
var players = new List<Player>();
var message = packet.DataAsString();
if (message.Trim() == "No Players Connected")
{
CurrentPlayerCountUpdated(this, new PlayerCountEventArgs() { PlayerCount = players.Count });
PlayersUpdated(this, new PlayersEventArgs() { Players = players });
if (ConsoleLogUpdated != null)
ConsoleLogUpdated(this, new ConsoleLogEventArgs()
{
Message = "Server Response: No Players Connected",
Timestamp = packet.Timestamp
});
return;
}
var str = packet.DataAsString();
string[] lines = str.Split('\n');
string[] cleanLines = lines.Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
foreach (string line in cleanLines)
{
var lineData = line.Replace("...", "");
string[] split1 = lineData.Split(new char[] { '.' }, 2);
string[] split2 = split1[1].Split(new char[] { ',' }, 2);
string playerNumber = split1[0].Trim();
string name = split2[0].Trim();
string steamId = split2[1].Trim();
players.Add(new Player
{
PlayerNumber = int.Parse(playerNumber),
Name = name,
SteamID = UInt64.Parse(steamId)
});
}
CurrentPlayerCountUpdated(this, new PlayerCountEventArgs() { PlayerCount = players.Count });
PlayersUpdated(this, new PlayersEventArgs() { Players = players });
if (ConsoleLogUpdated != null)
ConsoleLogUpdated(this, new ConsoleLogEventArgs()
{
Message = "Server Response: Player List Updated",
Timestamp = packet.Timestamp
});
}
catch (Exception ex)
{
Debug.WriteLine(ex.InnerException);
}
}
#endregion Rcon Handlers