Exemplo n.º 1
0
        public bool IsBanned(int userId, string ip, ref string banReason)
        {
            Database db = new Database();

            db.sqlexecute.Parameters.AddWithValue("@userid", userId);
            db.sqlexecute.Parameters.AddWithValue("@expires", DateTime.Now);
            db.sqlexecute.Parameters.AddWithValue("@ip", ip);

            int res = db.getInt("SELECT COUNT(*) FROM UserBans WHERE UserBanned = @userid  AND BanExpires > @expires;");

            if (res > 0)
            {
                banReason = db.getStringValue("SELECT TOP 1 BanMessage FROM UserBans WHERE UserBanned = @userid ORDER BY BanExpires DESC;");
            }

            if (res == 0)
            {
                res = db.getInt("SELECT COUNT(*) FROM UserBans WHERE UserBanned IN (SELECT UserID From Users WHERE LastIP = @ip)  AND BanExpires > @expires AND BanIP = 1;");
                if (res > 0)
                {
                    banReason =  db.getStringValue("SELECT TOP 1 BanMessage FROM UserBans WHERE UserBanned IN (SELECT UserID From Users WHERE LastIP = @ip) ORDER BY BanExpires DESC;");
                }
            }

            db.sqlexecute.Parameters.Clear();

            return (res > 0);
        }