Delete User

May 1, 2015
470
154
I seen a release from @Hypothesis which was a delete user command which didn't execute everything properly, or delete everything. This should do the trick.
Credits to him for the idea.
I don't know why'd you would need this as retros cant afford to lose any user nowadays.

But, if you want to delete some annoying kid here you go LUL

- This command will check if the user has logged on within the last 3 days, if that happens to be true the user will not be deleted.
- I put a couple sql queries to delete pretty much everything to not keep useless data in your tables.
- I put a query which will give all of the user's rooms to you, never know if he has a sick room or something lmfao.
- Obviously if the user is online it won't delete their account.
- Can't delete anybody higher than rank 4.

so yeah, have fun.

Code:
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.Administrator
{
    class
    DeleteUserCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_delete"; }
        }

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

        public string Description
        {
            get { return "Delete a user."; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if (Params.Length == 1)
            {
                Session.SendWhisper("Oops, you forgot to enter the username! Command Usage: :delete (user)");
                return;
            }

            Habbo User = PlusEnvironment.GetHabboByUsername(Params[1]);

            DateTime Now = DateTime.Now;
            double LastLogin = Convert.ToSingle(Now.AddDays(-3));
            double OnlineNow = Convert.ToSingle(Now);

            if (User.LastOnline == LastLogin)
            {
                Session.SendWhisper("The user " + Params[1] + " has logged on within the last 3 days, therefore it cannot be deleted.");
            }

            if (User.LastOnline == OnlineNow)
            {
                return;
            }

            if (Session.GetHabbo().Username == User.Username)
            {
                return;
            }

            if (User.Rank > 4)
            {
                return;
            }

            using (IQueryAdapter Adapter = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                Adapter.RunQuery("DELETE FROM `users` WHERE username = '" + User + "' LIMIT 1");
                Adapter.RunQuery("DELETE FROM `user_stats` WHERE id = '" + User.Id + "' LIMIT 1");
                Adapter.RunQuery("DELETE FROM `user_info` WHERE user_id = '" + User.Id + "' LIMIT 1");
                Adapter.RunQuery("DELETE FROM `user_relationships` WHERE user_id = '" + User.Id + "' LIMIT 1");
                Adapter.RunQuery("DELETE FROM `user_login_attemps WHERE userid = '" + User.Id + "' LIMIT 1");
                Adapter.RunQuery("UPDATE `rooms` SET owner = '" + Session.GetHabbo().Id + "' WHERE owner = '" + User.Id + "' LIMIT 1");
                Adapter.RunQuery("DELETE FROM `user_achievements` WHERE userid =  '" + User.Id + "' LIMIT 1");
            }
        }
    }
}
 

Joe

Well-Known Member
Jun 10, 2012
4,172
1,955
I seen a release from @Hypothesis which was a delete user command which didn't execute everything properly, or delete everything. This should do the trick.
Credits to him for the idea.
I don't know why'd you would need this as retros cant afford to lose any user nowadays.

But, if you want to delete some annoying kid here you go LUL

- This command will check if the user has logged on within the last 3 days, if that happens to be true the user will not be deleted.
- I put a couple sql queries to delete pretty much everything to not keep useless data in your tables.
- I put a query which will give all of the user's rooms to you, never know if he has a sick room or something lmfao.
- Obviously if the user is online it won't delete their account.
- Can't delete anybody higher than rank 4.

so yeah, have fun.

Code:
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.Administrator
{
    class
    DeleteUserCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_delete"; }
        }

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

        public string Description
        {
            get { return "Delete a user."; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if (Params.Length == 1)
            {
                Session.SendWhisper("Oops, you forgot to enter the username! Command Usage: :delete (user)");
                return;
            }

            Habbo User = PlusEnvironment.GetHabboByUsername(Params[1]);

            DateTime Now = DateTime.Now;
            double LastLogin = Convert.ToSingle(Now.AddDays(-3));
            double OnlineNow = Convert.ToSingle(Now);

            if (User.LastOnline == LastLogin)
            {
                Session.SendWhisper("The user " + Params[1] + " has logged on within the last 3 days, therefore it cannot be deleted.");
            }

            if (User.LastOnline == OnlineNow)
            {
                return;
            }

            if (Session.GetHabbo().Username == User.Username)
            {
                return;
            }

            if (User.Rank > 4)
            {
                return;
            }

            using (IQueryAdapter Adapter = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                Adapter.RunQuery("DELETE FROM `users` WHERE username = '" + User + "' LIMIT 1");
                Adapter.RunQuery("DELETE FROM `user_stats` WHERE id = '" + User.Id + "' LIMIT 1");
                Adapter.RunQuery("DELETE FROM `user_info` WHERE user_id = '" + User.Id + "' LIMIT 1");
                Adapter.RunQuery("DELETE FROM `user_relationships` WHERE user_id = '" + User.Id + "' LIMIT 1");
                Adapter.RunQuery("DELETE FROM `user_login_attemps WHERE userid = '" + User.Id + "' LIMIT 1");
                Adapter.RunQuery("UPDATE `rooms` SET owner = '" + Session.GetHabbo().Id + "' WHERE owner = '" + User.Id + "' LIMIT 1");
                Adapter.RunQuery("DELETE FROM `user_achievements` WHERE userid =  '" + User.Id + "' LIMIT 1");
            }
        }
    }
}
Might be useful to somebody :) Thanks bud.
 

Sledmore

Chaturbate Livestreamer
Staff member
FindRetros Moderator
Jul 24, 2010
5,199
3,934
A hell of a lot missing from this; bots, pets & bot data itself, badges, clothing, effects, favourites, room ratings, rights, vouchers & possibly a lot more.

You also shouldn't be using a limit on a couple of those queries (user achievements, relationships, updating rooms), as these will only be executed once.

Another thing to touch on, you should update the users items - probably delete the ones that are in their inventory, but update the room items.

This will also cause some issues for those of us who use foreign keys, due to the execution order of the command.
 

Joe

Well-Known Member
Jun 10, 2012
4,172
1,955
A hell of a lot missing from this; bots, pets & bot data itself, badges, clothing, effects, favourites, room ratings, rights, vouchers & possibly a lot more.

You also shouldn't be using a limit on a couple of those queries (user achievements, relationships, updating rooms), as these will only be executed once.

Another thing to touch on, you should update the users items - probably delete the ones that are in their inventory, but update the room items.

This will also cause some issues for those of us who use foreign keys, due to the execution order of the command.
Sounds a lot easier to rename the user for an inactive account like Habboon does.
 
May 1, 2015
470
154
A hell of a lot missing from this; bots, pets & bot data itself, badges, clothing, effects, favourites, room ratings, rights, vouchers & possibly a lot more.

You also shouldn't be using a limit on a couple of those queries (user achievements, relationships, updating rooms), as these will only be executed once.

Another thing to touch on, you should update the users items - probably delete the ones that are in their inventory, but update the room items.

This will also cause some issues for those of us who use foreign keys, due to the execution order of the command.

Thanks for the feedback, threw this together rather quickly but that's no excuse.
I'm not the best with SQL queries, definitely a learning curve.
 

Hypothesis

Programmer
Jan 6, 2019
524
361
Thanks for the credit, also that version I had done, was very rushed and honestly I didn't even realize how much I missed, like removing stats of the user, etc, it was a overall bad command, but thanks for these improvements.
 
May 1, 2015
470
154
Thanks for the credit, also that version I had done, was very rushed and honestly I didn't even realize how much I missed, like removing stats of the user, etc, it was a overall bad command, but thanks for these improvements.

Yeah wasn't meaning to diss you at all, would never judge another fellow developer's work.
Really good idea, just thought i'd add some stuff :up:
 

Users who are viewing this thread

Top