Delete User & Change Name Commands

Hypothesis

Programmer
Jan 6, 2019
524
361
Hi there DevBest, I'd like to release these two pretty useful commands, they were actually quite useful to me and others I have worked with that actually requested these commands be added, and I thought they were pretty good ideas.
Delete User
Basically this command checks the user table for the username provided and it automatically sets the username of that user to contain random characters, thus not actually deleting the user, but just changing the username to something else, this command was a lot of use to moderators of my hotels, etc.
C#:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using Plus.Communication.Packets.Incoming;
using Plus.Communication.Packets.Outgoing.Rooms.Engine;
using Plus.Communication.Packets.Outgoing.Users;
using Plus.Database.Interfaces;
using Plus.HabboHotel.GameClients;
using Plus.Communication.Packets.Outgoing.Rooms.Chat;
using Plus.Utilities;
using Plus.HabboHotel.Users;

namespace Plus.HabboHotel.Rooms.Chat.Commands.Moderator
{
    class
    DeleteUserCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_del_user"; }
        }

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

        public string Description
        {
            get { return "Allow you to delete a user!"; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if (Params.Length == 1)
            {
                Session.SendWhisper("Please enter the username of the user to delete!");
                return;
            }
            Habbo Habbo = PlusEnvironment.GetHabboByUsername(Params[1]);
            if (Habbo == null)
            {
                Session.SendWhisper("An error occoured whilst finding that user in the database.");
                return;
            }
            if (Session.GetHabbo().Username == Habbo.Username)
            {
                Session.SendWhisper("You cannot delete your own user.", 3);
                return;
            }

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("UPDATE `users` SET `username` = '" + Habbo.Username + PlusEnvironment.GetUnixTimestamp() + "' WHERE username ='" + Habbo.Username + "' LIMIT 1");
                dbClient.RunQuery();
            }
            Session.SendWhisper(Habbo.Username + " has been removed from the database!");

        }
    }
}
Change Name
Another very useful command, on my hotel I had flagme for normal players disabled for various reasons, anyways my housekeeping was set to set data by the player's username, so I noticed when changing the username on the user editor, it wouldn't change it properly, because it updated by the username. rather than recoding this to use the user ID, I decided to just create a command in-game for moderators to change a player's name if they did not have the ability to change their name since they didn't have access to the database.
C#:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using Plus.Communication.Packets.Incoming;
using Plus.Communication.Packets.Outgoing.Rooms.Engine;
using Plus.Communication.Packets.Outgoing.Users;
using Plus.Database.Interfaces;
using Plus.HabboHotel.GameClients;

namespace Plus.HabboHotel.Rooms.Chat.Commands.Moderator
{
    class
    ChangeNameCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_change"; }
        }

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

        public string Description
        {
            get { return "Change a users name."; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if (Params.Length == 1)
            {
                Session.SendWhisper("Please enter the username of the user you wish to change their name.");
                return;
            }

            GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]);
            if (TargetClient == null)
            {
                Session.SendWhisper("An error occoured whilst finding that user, maybe they're not online.");
                return;
            }

            if (TargetClient.GetHabbo() == null)
            {
                Session.SendWhisper("An error occoured whilst finding that user, maybe they're not online.");
                return;
            }


            Room = Session.GetHabbo().CurrentRoom;
            if (Room == null)
                return;

            RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(TargetClient.GetHabbo().Username);
            if (User == null)
                return;

            string NewName = CommandManager.MergeParams(Params, 2);
            string OldName = TargetClient.GetHabbo().Username;

            if (NewName == String.Empty)
            {
                Session.SendWhisper("You must enter a new name for the player!");
                return;
            }

            if (NewName == OldName)
            {
                TargetClient.GetHabbo().ChangeName(OldName);
                TargetClient.SendMessage(new UpdateUsernameComposer(NewName));
                return;
            }

            bool InUse = false;
            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT COUNT(0) FROM `users` WHERE `username` = @name LIMIT 1");
                dbClient.AddParameter("name", NewName);
                InUse = dbClient.getInteger() == 1;
            }
            if (!PlusEnvironment.GetGame().GetClientManager().UpdateClientUsername(Session, OldName, NewName))
            {
                Session.SendNotification("Oops! An issue occoured whilst updating that users name.");
                return;
            }

            TargetClient.GetHabbo().ChangingName = true;

            Session.SendWhisper("You have updated " + TargetClient.GetHabbo().Username + "'s username");
            TargetClient.GetHabbo().ChangeName(NewName);
            TargetClient.GetHabbo().GetMessenger().OnStatusChanged(true);

            TargetClient.SendMessage(new UpdateUsernameComposer(NewName));
            Room.SendMessage(new UserNameChangeComposer(Room.Id, User.VirtualId, NewName));

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("UPDATE `users` SET `username`='" + NewName + "' WHERE `id`='" + TargetClient.GetHabbo().Id + "'");
                dbClient.SetQuery("INSERT INTO `logs_client_namechange` (`user_id`,`new_name`,`old_name`,`timestamp`, `changedby`) VALUES ('" + TargetClient.GetHabbo().Id + "','" + NewName + "','" + OldName + "', '" + PlusEnvironment.GetUnixTimestamp() + "', '" + Session.GetHabbo().Username + "')");
                dbClient.AddParameter("name", NewName);
                dbClient.RunQuery();
                TargetClient.GetConnection().Dispose();
            }
        }
    }
}
That's all from me folks! Hopefully these commands will have use to you, and P.S please try to be positive, no negativity such as, "oh this is already on my hotel," or any of that, if you do give criticism, at least back it up with some type of praise, as I really just wanted to give to the smaller developers who can't make such commands, thanks for reading my post!
 

Menkz

Member
Jul 9, 2010
374
167
imo delete user command is useless as it doesnt delete that users stats & other info such as rooms etc.
the changename would be nice, but you should add the ability to take another name if its > 3 months inactive or more
 

Platinum

Hello!
Sep 2, 2012
295
281
The first command is atrocious and the second command is useless since :flaguser (username) exists. What could be done to make the second command beneficial is if you made it so that you could change anyone’s username without them needing to be online!
 

Hypothesis

Programmer
Jan 6, 2019
524
361
@Platinum Thanks for the input, but as stated before, at my previous hotels, the system was different, there was no flaguser, and flaguser does not change the player's name, it allows them to change their name, with the alphabetical format, meaning you can't use any special characterizing, at my hotels we allowed special characters for VIP members, so moderators would be able to change their name if needed and no developer or anyone with database was online. As for the second command, honestly great idea, how about you do that and re-release it? That could be helpful :p
 

Joe

Well-Known Member
Jun 10, 2012
4,088
1,915
The first command would work if the items, rooms, stats, credits etc were reset I guess?

Not a great release but thanks :)
 

Users who are viewing this thread

Top