public static bool GetPlayers() { currentLoader = new LoadingForm(); currentLoader.Show(); currentLoader.status.Text = "Querying players..."; Application.DoEvents(); try { using (MySqlDataReader reader = MySqlHelper.ExecuteReader(ConnectionString, "SELECT * FROM players")) { currentLoader.status.Text = "Loading players..."; Application.DoEvents(); while (reader.Read()) { uint databaseRow = 0; string cdKey; string GSID; DateTime firstLogin; DateTime lastLogin; uint logins; bool isDM; bool isBanned; bool is18Plus; bool isMember; try { // First, we gather information about this row. databaseRow = (uint)reader.GetValue(0); cdKey = (string)reader.GetValue(1); GSID = (string)reader.GetValue(2); firstLogin = (DateTime)reader.GetValue(3); lastLogin = (DateTime)reader.GetValue(4); logins = (uint)reader.GetValue(6); isDM = (bool)reader.GetValue(8); isBanned = (bool)reader.GetValue(9); is18Plus = (bool)reader.GetValue(10); isMember = (bool)reader.GetValue(11); } catch { continue; } // Next, we look for if this is a player's duplicate GSID. if (Players.ListByKey.Keys.Contains(cdKey)) { // Yes, yes it is. Player modifiedPlayer = Players.ListByKey[cdKey]; // We'll want to add to the list of Ids. modifiedPlayer.playerIds.Add(databaseRow); modifiedPlayer.CommunityIds.Add(GSID); // We'll want to note an earlier first login, if this one is earlier // and a later last login, if this one is later. if (modifiedPlayer.FirstLogin > firstLogin) { modifiedPlayer.FirstLogin = firstLogin; } if (modifiedPlayer.LastLogin < lastLogin) { modifiedPlayer.LastLogin = lastLogin; } // Total number of logins is additive. modifiedPlayer.Logins += logins; // And if any of these bools are true, update the list to // reflect as much. if (isDM) { modifiedPlayer.IsDM = true; } if (isBanned) { modifiedPlayer.IsBanned = true; } if (is18Plus) { modifiedPlayer.Is18Plus = true; } if (isMember) { modifiedPlayer.IsMember = true; } // And lastly we need to make sure that the new Id is indexed. Players.ListByPlayerId.Add(databaseRow, modifiedPlayer); } else { // It's a new person! Yaaaaay! Player addedPlayer = new Player() { CDKey = cdKey, DMTime = 0.0f, FirstLogin = firstLogin, LastLogin = lastLogin, Is18Plus = is18Plus, IsBanned = isBanned, IsDM = isDM, IsMember = isMember, Logins = logins }; addedPlayer.CommunityIds = new List<string>(); addedPlayer.playerIds = new List<uint>(); addedPlayer.Characters = new List<Character>(); addedPlayer.CommunityIds.Add(GSID); addedPlayer.playerIds.Add(databaseRow); Players.ListByPlayerId.Add(databaseRow, addedPlayer); Players.ListByKey.Add(cdKey, addedPlayer); } } } } catch (Exception e) { MessageBox.Show(e.Message); return false; } return true; }
public static bool GetPlayers() { currentLoader = new LoadingForm(); currentLoader.Show(); currentLoader.status.Text = "Querying players..."; Application.DoEvents(); try { using (MySqlDataReader reader = MySqlHelper.ExecuteReader(ConnectionString, "SELECT * FROM players")) { currentLoader.status.Text = "Loading players..."; Application.DoEvents(); while (reader.Read()) { uint databaseRow = 0; string cdKey; string GSID; DateTime firstLogin; DateTime lastLogin; uint logins; bool isDM; bool isBanned; bool is18Plus; bool isMember; try { // First, we gather information about this row. databaseRow = (uint)reader.GetValue(0); cdKey = (string)reader.GetValue(1); GSID = (string)reader.GetValue(2); firstLogin = (DateTime)reader.GetValue(3); lastLogin = (DateTime)reader.GetValue(4); logins = (uint)reader.GetValue(6); isDM = (bool)reader.GetValue(8); isBanned = (bool)reader.GetValue(9); is18Plus = (bool)reader.GetValue(10); isMember = (bool)reader.GetValue(11); } catch { continue; } // Next, we look for if this is a player's duplicate GSID. if (Players.ListByKey.Keys.Contains(cdKey)) { // Yes, yes it is. Player modifiedPlayer = Players.ListByKey[cdKey]; // We'll want to add to the list of Ids. modifiedPlayer.playerIds.Add(databaseRow); modifiedPlayer.CommunityIds.Add(GSID); // We'll want to note an earlier first login, if this one is earlier // and a later last login, if this one is later. if (modifiedPlayer.FirstLogin > firstLogin) { modifiedPlayer.FirstLogin = firstLogin; } if (modifiedPlayer.LastLogin < lastLogin) { modifiedPlayer.LastLogin = lastLogin; } // Total number of logins is additive. modifiedPlayer.Logins += logins; // And if any of these bools are true, update the list to // reflect as much. if (isDM) { modifiedPlayer.IsDM = true; } if (isBanned) { modifiedPlayer.IsBanned = true; } if (is18Plus) { modifiedPlayer.Is18Plus = true; } if (isMember) { modifiedPlayer.IsMember = true; } // And lastly we need to make sure that the new Id is indexed. Players.ListByPlayerId.Add(databaseRow, modifiedPlayer); } else { // It's a new person! Yaaaaay! Player addedPlayer = new Player() { CDKey = cdKey, DMTime = 0.0f, FirstLogin = firstLogin, LastLogin = lastLogin, Is18Plus = is18Plus, IsBanned = isBanned, IsDM = isDM, IsMember = isMember, Logins = logins }; addedPlayer.CommunityIds = new List <string>(); addedPlayer.playerIds = new List <uint>(); addedPlayer.Characters = new List <Character>(); addedPlayer.CommunityIds.Add(GSID); addedPlayer.playerIds.Add(databaseRow); Players.ListByPlayerId.Add(databaseRow, addedPlayer); Players.ListByKey.Add(cdKey, addedPlayer); } } } } catch (Exception e) { MessageBox.Show(e.Message); return(false); } return(true); }