AdvancedLogParser.InfoGather.GetPlayers C# (CSharp) Method

GetPlayers() public static method

public static GetPlayers ( ) : bool
return bool
        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;
        }

Usage Example

Beispiel #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            InfoGather.DatabasePassword = ConfigurationSettings.AppSettings["DatabasePassword"];
            InfoGather.DatabaseSchema   = ConfigurationSettings.AppSettings["DatabaseSchema"];
            InfoGather.DatabaseServer   = ConfigurationSettings.AppSettings["DatabaseServer"];
            InfoGather.DatabasePort     = ConfigurationSettings.AppSettings["DatabasePort"];
            InfoGather.DatabaseUser     = ConfigurationSettings.AppSettings["DatabaseUser"];
            InfoGather.BuildConnectionString();
            Players.ListByPlayerId = new Dictionary <uint, Player>();
            Players.ListByKey      = new Dictionary <string, Player>();
            Characters.List        = new Dictionary <uint, Character>();
            Logs.AdvancementAlerts = new Dictionary <uint, Log>();
            Logs.DeathAlerts       = new Dictionary <uint, Log>();
            Logs.EnforcementAlerts = new Dictionary <uint, Log>();
            Logs.RecentLogins      = new Dictionary <uint, Log>();
            Servers.List           = new Dictionary <uint, Server>();
            if (InfoGather.GetPlayers())
            {
                InfoGather.GetCharacters();
                InfoGather.CountBankValue();
                InfoGather.CountpChestValue();
                InfoGather.GetAlerts();
                InfoGather.GetLogins();
                InfoGather.IdentifyLogins();
                InfoGather.GetDMTime();
                InfoGather.currentLoader.Close();
                InfoGather.currentLoader.Dispose();
                if (ServerFocus >= 0)
                {
                    foreach (Server srv in Servers.List.Values)
                    {
                        if (srv.ServerId == Math.Abs(ServerFocus))
                        {
                            Application.Run(new ServerView(srv));
                        }
                    }
                }
                else
                {
                    foreach (Server srv in Servers.List.Values)
                    {
                        new ServerView(srv).Show();
                    }
                    new ServerView(null).Show();
                    Application.Run(new PrimaryDisplay());
                }
            }
        }