Ejemplo n.º 1
0
        private void UpdateDatabaseUsernames()
        {
            var usersToSend = UnnamedBans.Where(x => UsernameValid(x));

            UnnamedBans.RemoveAll(x => UsernameValid(x));
            if (usersToSend.Count() <= 0)
            {
                Puts("UpdateDatabaseUsernames() no users ready to update!");
                return;
            }
            var query = string.Format(MySqlConstants.ADD_BAN_TO_DATABASE, Settings.Instance.DatabaseName, Settings.Instance.TableName,
                                      string.Join(",", usersToSend.Select(x => $"('{x.SteamID}','{x.Username}','{x.Reason.Replace(";", "").Replace("'", "")}')").ToArray())
                                      );

            try
            {
                PerformDatabaseQuery(query, (responseRows) =>
                {
                });
            }
            catch
            {
                Puts("PushBansToServer() SQL Query failed!");
                Puts(query);
                timer.In(10f, UpdateDatabaseUsernames);
            }
            Puts($"Updated {usersToSend.Count()} usernames in the database!");
        }
Ejemplo n.º 2
0
        private void PushBansToServer()
        {
            var bans = new List <PlayerBan>(BansToSend);

            bans.AddRange(UnnamedBans.Where(x => UsernameValid(x)));
            UnnamedBans.RemoveAll(x => UsernameValid(x));
            bans.AddRange(ServerUsers.GetAll(ServerUsers.UserGroup.Banned).Where(x => !Settings.Instance.databaseBans.ContainsKey(x.steamid)).Select(x => new PlayerBan(x)));
            if (bans.Count() <= 0)
            {
                Puts("All bans have been synced with the database.");
                return;
            }
            var query = string.Format(MySqlConstants.ADD_BAN_TO_DATABASE, Settings.Instance.DatabaseName, Settings.Instance.TableName,
                                      string.Join(",", bans.Select(x => $"('{x.SteamID}','{x.Username}','{x.Reason.Replace(";", "").Replace("'", "")}')").ToArray())
                                      );

            Puts(query);
            try
            {
                PerformDatabaseQuery(query, (responseRows) =>
                {
                    Settings.Instance.PushedAllLocalBansToDatabase = true;
                    Puts($"Bans pushed to the database");
                });
            }
            catch
            {
                Puts("PushBansToServer() SQL Query failed!");
                Puts(query);
                timer.In(10f, () =>
                {
                    PushBansToServer();
                });
            }
            Puts($"Started to send {bans.Count()} bans to database!");
        }