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.
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.
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!
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!");
}
}
}
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();
}
}
}
}