Example #1
0
        internal void LoadBans(IQueryAdapter dbClient)
        {
            bannedUsernames.Clear();
            bannedIPs.Clear();

            dbClient.setQuery("SELECT bantype,value,reason,expire FROM bans");
            DataTable BanData = dbClient.getTable();

            double timestmp = ButterflyEnvironment.GetUnixTimestamp();

            string value;
            string reason;
            string type;
            double expires;

            foreach (DataRow dRow in BanData.Rows)
            {
                value   = (string)dRow["value"];
                reason  = (string)dRow["reason"];
                expires = (double)dRow["expire"];
                type    = (string)dRow["bantype"];


                ModerationBanType banType;
                if (type == "user")
                {
                    banType = ModerationBanType.USERNAME;
                }
                else
                {
                    banType = ModerationBanType.IP;
                }


                ModerationBan ban = new ModerationBan(banType, value, reason, expires);

                if (expires > timestmp)
                {
                    if (ban.Type == ModerationBanType.USERNAME)
                    {
                        if (!bannedUsernames.ContainsKey(value))
                        {
                            bannedUsernames.Add(value, ban);
                        }
                        else
                        if (!bannedIPs.ContainsKey(value))
                        {
                            bannedIPs.Add(value, ban);
                        }
                    }
                }
            }
        }
Example #2
0
        internal void LoadBans(IQueryAdapter dbClient)
        {
            bannedUsernames.Clear();
            bannedIPs.Clear();

            dbClient.setQuery("SELECT bantype,value,reason,expire FROM bans");
            DataTable BanData = dbClient.getTable();


            double timestmp = ButterflyEnvironment.GetUnixTimestamp();

            string value;
            string reason;
            string type;
            double expires;
            
            foreach (DataRow dRow in BanData.Rows)
            {
                value = (string)dRow["value"];
                reason = (string)dRow["reason"];
                expires = (double)dRow["expire"];
                type = (string)dRow["bantype"];


                ModerationBanType banType;
                if (type == "user")
                    banType = ModerationBanType.USERNAME;
                else
                    banType = ModerationBanType.IP;


                ModerationBan ban = new ModerationBan(banType, value, reason, expires);

                if (expires > timestmp)
                {
                    if (ban.Type == ModerationBanType.USERNAME)
                    {
                        if (!bannedUsernames.ContainsKey(value))
                        {
                            bannedUsernames.Add(value, ban);
                        }
                    }
                    else if (!bannedIPs.ContainsKey(value))
                    {
                        bannedIPs.Add(value, ban);
                    }
                }
            
            }
        }
Example #3
0
        internal string GetBanReason(string username, string ip)
        {
            if (bannedUsernames.ContainsKey(username))
            {
                ModerationBan ban = (ModerationBan)bannedUsernames[username];
                if (!ban.Expired)
                {
                    return(ban.ReasonMessage);
                }
            }
            else if (bannedIPs.ContainsKey(ip))
            {
                ModerationBan ban = (ModerationBan)bannedIPs[username];
                if (!ban.Expired)
                {
                    return(ban.ReasonMessage);
                }
            }

            return(string.Empty);
        }
Example #4
0
        // PENDING REWRITE
        internal void BanUser(GameClient Client, string Moderator, Double LengthSeconds, string Reason, Boolean IpBan)
        {
            ModerationBanType Type = ModerationBanType.USERNAME;
            string Var = Client.GetHabbo().Username;
            string RawVar = "user";
            Double Expire = ButterflyEnvironment.GetUnixTimestamp() + LengthSeconds;

            if (IpBan)
            {
                Type = ModerationBanType.IP;

                using (IQueryAdapter adapter = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    adapter.setQuery("SELECT ip_last FROM users WHERE username = '******' LIMIT 1");
                    Var = adapter.getString();
                }

                RawVar = "ip";
            }

            ModerationBan ban = new ModerationBan(Type, Var, Reason, Expire);

            if (ban.Type == ModerationBanType.IP)
            {
                if (bannedIPs.ContainsKey(Var))
                    bannedIPs[Var] = ban;
                else
                    bannedIPs.Add(Var, ban);
            }
            else
            {
                if (bannedUsernames.ContainsKey(Var))
                    bannedUsernames[Var] = ban;
                else
                    bannedUsernames.Add(Var, ban);
            }

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("INSERT INTO bans (bantype,value,reason,expire,added_by,added_date) VALUES (@rawvar,@var,@reason,'" + Expire + "',@mod,'" + DateTime.Now.ToLongDateString() + "')");
                dbClient.addParameter("rawvar", RawVar);
                dbClient.addParameter("var", Var);
                dbClient.addParameter("reason", Reason);
                dbClient.addParameter("mod", Moderator);
                dbClient.runQuery();                
            }

            if (IpBan)
            {
                DataTable UsersAffected = null;

                using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.setQuery("SELECT id FROM users WHERE ip_last = @var");
                    dbClient.addParameter("var", Var);
                    UsersAffected = dbClient.getTable();
                }

                if (UsersAffected != null)
                {
                    using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        foreach (DataRow Row in UsersAffected.Rows)
                        {
                            dbClient.runFastQuery("UPDATE user_info SET bans = bans + 1 WHERE user_id = " + Convert.ToUInt32(Row["id"]));
                        }
                    }
                }

                Client.Disconnect();
            }
            else
            {
                using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.runFastQuery("UPDATE user_info SET bans = bans + 1 WHERE user_id = " + Client.GetHabbo().Id);
                }

               
                Client.Disconnect();
            }
        }
Example #5
0
        // PENDING REWRITE
        internal void BanUser(GameClient Client, string Moderator, Double LengthSeconds, string Reason, Boolean IpBan)
        {
            ModerationBanType Type   = ModerationBanType.USERNAME;
            string            Var    = Client.GetHabbo().Username;
            string            RawVar = "user";
            Double            Expire = ButterflyEnvironment.GetUnixTimestamp() + LengthSeconds;

            if (Reason == null)
            {
                Reason = "The moderator didn't specify a reason";
            }
            if (IpBan)
            {
                Type   = ModerationBanType.IP;
                Var    = Client.GetConnection().getIp();
                RawVar = "ip";
            }

            ModerationBan ban = new ModerationBan(Type, Var, Reason, Expire);

            if (ban.Type == ModerationBanType.IP)
            {
                if (bannedIPs.ContainsKey(Var))
                {
                    bannedIPs[Var] = ban;
                }
                else
                {
                    bannedIPs.Add(Var, ban);
                }
            }
            else
            {
                if (bannedUsernames.ContainsKey(Var))
                {
                    bannedUsernames[Var] = ban;
                }
                else
                {
                    bannedUsernames.Add(Var, ban);
                }
            }

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("INSERT INTO bans (bantype,value,reason,expire,added_by,added_date) VALUES (@rawvar,@var,@reason,'" + Expire + "',@mod,'" + DateTime.Now.ToLongDateString() + "')");
                dbClient.addParameter("rawvar", RawVar);
                dbClient.addParameter("var", Var);
                dbClient.addParameter("reason", Reason);
                dbClient.addParameter("mod", Moderator);
                dbClient.runQuery();
            }

            if (IpBan)
            {
                DataTable UsersAffected = null;

                using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.setQuery("SELECT id FROM users WHERE ip_last = @var");
                    dbClient.addParameter("var", Var);
                    UsersAffected = dbClient.getTable();
                }

                if (UsersAffected != null)
                {
                    using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        foreach (DataRow Row in UsersAffected.Rows)
                        {
                            dbClient.runFastQuery("UPDATE user_info SET bans = bans + 1 WHERE user_id = " + Convert.ToUInt32(Row["id"]));
                        }
                    }
                }


                BanUser(Client, Moderator, LengthSeconds, Reason, false);
            }
            else
            {
                using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.runFastQuery("UPDATE user_info SET bans = bans + 1 WHERE user_id = " + Client.GetHabbo().Id);
                }

                Client.SendBanMessage(LanguageLocale.GetValue("moderation.banned") + " " + Reason);
                Client.Disconnect();
            }
        }