// string = name, long = score public static Dictionary <string, PlayerListEntry> GetSearchResults(string search) { var output = new Dictionary <string, PlayerListEntry> { }; if (search != null) { Regex regex = new Regex($@"{search}", RegexOptions.IgnoreCase); var _conn = new DBConnection(); var cmd = _conn.BeginCommand("SELECT players.login_name, players.id, game_stats.score FROM game_stats JOIN players ON (players.id = game_stats.player_id) ORDER BY game_stats.score DESC;"); var rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { string name = rdr.GetString(0); int id = rdr.GetInt32(1); long score = rdr.GetInt64(2); if (!output.ContainsKey(name)) { Match match = regex.Match(name); if (match.Success) { PlayerListEntry newEntry = new PlayerListEntry(id, name, score); output.Add(name, newEntry); } } } _conn.EndCommand(); } return(output); }
public static List <PlayerListEntry> GetFriendList(int profileId) { var output = new List <PlayerListEntry> { }; var keys = new List <int> { }; var _conn = new DBConnection(); var cmd = _conn.BeginCommand("SELECT players.login_name, players.id, game_stats.score FROM players JOIN friends ON (players.id = friends.player_2_id) JOIN game_stats ON (friends.player_2_id = game_stats.player_id) ORDER BY game_stats.score DESC;"); var rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { string name = rdr.GetString(0); int id = rdr.GetInt32(1); long score = rdr.GetInt64(2); if (!keys.Contains(id)) { PlayerListEntry newEntry = new PlayerListEntry(id, name, score); output.Add(newEntry); keys.Add(id); } } _conn.EndCommand(); return(output); }
public override bool Equals(object other) { if (!(other is PlayerListEntry)) { return(false); } else { PlayerListEntry otherPlayerListEntry = (PlayerListEntry)other; return( this.Name == otherPlayerListEntry.Name && this.Score == otherPlayerListEntry.Score ); } }