[fixed]Ban command

mark1234

Member
Aug 7, 2015
52
1
Hello people. i have a question you know in plusemu you have a ban command like this: :ban %username% %length% %reason% but what i want is that the %lengt% automatic is 24H so you only need to fill :ban %username% %reason% for the one who need it i put the command beneeth here:


Code:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using Plus.Utilities;
using Plus.HabboHotel.Users;
using Plus.HabboHotel.GameClients;


using Plus.HabboHotel.Moderation;

using Plus.Database.Interfaces;

namespace Plus.HabboHotel.Rooms.Chat.Commands.Moderator
{
    class BanCommand : IChatCommand
    {

        public string PermissionRequired
        {
            get { return "command_ban"; }
        }

        public string Parameters
        {
            get { return "%username% %length% %reason% "; }
        }

        public string Description
        {
            get { return "Ban a player."; ; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if (Params.Length == 1)
            {
                Session.SendWhisper("dont forget the username ;).");
                return;
            }

            Habbo Habbo = PlusEnvironment.GetHabboByUsername(Params[1]);
            if (Habbo == null)
            {
                Session.SendWhisper("cant find that user in database.");
                return;
            }

            if (Habbo.GetPermissions().HasRight("mod_soft_ban") && !Session.GetHabbo().GetPermissions().HasRight("mod_ban_any"))
            {
                Session.SendWhisper("Oops, cant ban this user :).");
                return;
            }

            Double Expire = 0;
            string Hours = Params[2];
            if (String.IsNullOrEmpty(Hours) || Hours == "perm")
                Expire = PlusEnvironment.GetUnixTimestamp() + 78892200;
            else
                Expire = (PlusEnvironment.GetUnixTimestamp() + (Convert.ToDouble(Hours) * 3600));

            string Reason = null;
            if (Params.Length >= 4)
                Reason = CommandManager.MergeParams(Params, 3);
            else
                Reason = "er is geen reden ingevoerd.";

            string Username = Habbo.Username;
            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.RunQuery("UPDATE `user_info` SET `bans` = `bans` + '1' WHERE `user_id` = '" + Habbo.Id + "' LIMIT 1");
            }

            PlusEnvironment.GetGame().GetModerationManager().BanUser(Session.GetHabbo().Username, ModerationBanType.USERNAME, Habbo.Username, Reason, Expire);

            GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Username);
            if (TargetClient != null)
                TargetClient.Disconnect();

            Session.SendWhisper("Je hebt '" + Username + "' gebant voor " + Hours + " uur met de reden '" + Reason + "'!");
        }
    }
}
 

Velaski

winner
Aug 4, 2015
562
165
Not sure but:

Code:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using Plus.Utilities;
using Plus.HabboHotel.Users;
using Plus.HabboHotel.GameClients;


using Plus.HabboHotel.Moderation;

using Plus.Database.Interfaces;

namespace Plus.HabboHotel.Rooms.Chat.Commands.Moderator
{
    class BanCommand : IChatCommand
    {

        public string PermissionRequired
        {
            get { return "command_ban"; }
        }

        public string Parameters
        {
            get { return "%username% %reason% "; }
        }

        public string Description
        {
            get { return "Ban a player."; ; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if (Params.Length == 1)
            {
                Session.SendWhisper("dont forget the username ;).");
                return;
            }

            Habbo Habbo = PlusEnvironment.GetHabboByUsername(Params[1]);
            if (Habbo == null)
            {
                Session.SendWhisper("cant find that user in database.");
                return;
            }

            if (Habbo.GetPermissions().HasRight("mod_soft_ban") && !Session.GetHabbo().GetPermissions().HasRight("mod_ban_any"))
            {
                Session.SendWhisper("Oops, cant ban this user :).");
                return;
            }

            Double Expire = 0;
            string Hours = 24;
            if (String.IsNullOrEmpty(Hours) || Hours == "perm")
                Expire = PlusEnvironment.GetUnixTimestamp() + 78892200;
            else
                Expire = (PlusEnvironment.GetUnixTimestamp() + (Convert.ToDouble(Hours) * 3600));

            string Reason = null;
            if (Params.Length >= 4)
                Reason = CommandManager.MergeParams(Params, 3);
            else
                Reason = "er is geen reden ingevoerd.";

            string Username = Habbo.Username;
            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.RunQuery("UPDATE `user_info` SET `bans` = `bans` + '1' WHERE `user_id` = '" + Habbo.Id + "' LIMIT 1");
            }

            PlusEnvironment.GetGame().GetModerationManager().BanUser(Session.GetHabbo().Username, ModerationBanType.USERNAME, Habbo.Username, Reason, Expire);

            GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Username);
            if (TargetClient != null)
                TargetClient.Disconnect();

            Session.SendWhisper("Je hebt '" + Username + "' gebant voor " + Hours + " uur met de reden '" + Reason + "'!");
        }
    }
}
 

JayC

Always Learning
Aug 8, 2013
5,494
1,398
Not sure but:

Code:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using Plus.Utilities;
using Plus.HabboHotel.Users;
using Plus.HabboHotel.GameClients;


using Plus.HabboHotel.Moderation;

using Plus.Database.Interfaces;

namespace Plus.HabboHotel.Rooms.Chat.Commands.Moderator
{
    class BanCommand : IChatCommand
    {

        public string PermissionRequired
        {
            get { return "command_ban"; }
        }

        public string Parameters
        {
            get { return "%username% %reason% "; }
        }

        public string Description
        {
            get { return "Ban a player."; ; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if (Params.Length == 1)
            {
                Session.SendWhisper("dont forget the username ;).");
                return;
            }

            Habbo Habbo = PlusEnvironment.GetHabboByUsername(Params[1]);
            if (Habbo == null)
            {
                Session.SendWhisper("cant find that user in database.");
                return;
            }

            if (Habbo.GetPermissions().HasRight("mod_soft_ban") && !Session.GetHabbo().GetPermissions().HasRight("mod_ban_any"))
            {
                Session.SendWhisper("Oops, cant ban this user :).");
                return;
            }

            Double Expire = 0;
            string Hours = 24;
            if (String.IsNullOrEmpty(Hours) || Hours == "perm")
                Expire = PlusEnvironment.GetUnixTimestamp() + 78892200;
            else
                Expire = (PlusEnvironment.GetUnixTimestamp() + (Convert.ToDouble(Hours) * 3600));

            string Reason = null;
            if (Params.Length >= 4)
                Reason = CommandManager.MergeParams(Params, 3);
            else
                Reason = "er is geen reden ingevoerd.";

            string Username = Habbo.Username;
            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.RunQuery("UPDATE `user_info` SET `bans` = `bans` + '1' WHERE `user_id` = '" + Habbo.Id + "' LIMIT 1");
            }

            PlusEnvironment.GetGame().GetModerationManager().BanUser(Session.GetHabbo().Username, ModerationBanType.USERNAME, Habbo.Username, Reason, Expire);

            GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Username);
            if (TargetClient != null)
                TargetClient.Disconnect();

            Session.SendWhisper("Je hebt '" + Username + "' gebant voor " + Hours + " uur met de reden '" + Reason + "'!");
        }
    }
}
You didn't even clean it up properly you still left the if statement for the length..
Remove:
Code:
if (String.IsNullOrEmpty(Hours) || Hours == "perm")
                Expire = PlusEnvironment.GetUnixTimestamp() + 78892200;
            else
You don't need that
 

mark1234

Member
Aug 7, 2015
52
1
it gives this error: CS0029 Cannot implicity convert type 'int' to 'string' line 57 (this part: string hours = 24; ) so can i just change it to this: string hours = "24"; ?? ore something else?
 

mark1234

Member
Aug 7, 2015
52
1
i have a problen with this part of the command i cant fill in my own reason
Code:
            string Reason = null;
            if (Params.Length >= 4)
                Reason = CommandManager.MergeParams(Params, 3);
            else
                Reason = "er is geen reden ingevoerd.";
 

JayC

Always Learning
Aug 8, 2013
5,494
1,398
i have a problen with this part of the command i cant fill in my own reason
Code:
            string Reason = null;
            if (Params.Length >= 4)
                Reason = CommandManager.MergeParams(Params, 3);
            else
                Reason = "er is geen reden ingevoerd.";
string Reason = null;
if (Params.Length >= 4)
Reason = CommandManager.MergeParams(Params, 2);
else
Reason = "er is geen reden ingevoerd.";

This was answered on another thread by @Jerry_ if this is for your ban page.
 

Users who are viewing this thread

Top