public static void AddPlayer(Player player) { if (_loggedInPlayers == null) { _loggedInPlayers = new List<Player>(); } _loggedInPlayers.Add(player); }
private static string Login(string request) { string[] parts = request.Split(Delimiters); string username = parts[1].Split(InnerDelimiters)[1]; string ip = parts[2].Split(InnerDelimiters)[1]; bool alreadyExists = false; try { foreach (var existingPlayer in Settings.Settings.GetPlayers()) { if (existingPlayer.ToString() == username) { alreadyExists = true; } } } catch (NullReferenceException exc) { Settings.Settings.AddPlayer(new Player(username, ip)); alreadyExists = false; } List<Player> allPlayers; if (alreadyExists) { allPlayers = new List<Player>(); } else { Player player = new Player(username, ip); Settings.Settings.AddPlayer(player); allPlayers = Settings.Settings.GetPlayers(); } MemoryStream stream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, allPlayers); byte[] byteCode = stream.ToArray(); string response = Convert.ToBase64String(byteCode); return response; }