Close This Pls

zakiy

Member
Dec 5, 2011
44
4
Well, if you can code it, that'd be fine, but if not, just give me info on where I could look for the function, I tried using ChangeNameEve t for reference, but it's not working too well.
 

Kodys

lmao
Oct 24, 2016
36
17
You won't learn anything from having someone else do it for you - I'll give you the query; feel free to private message me if you're still struggling.
Code:
"UPDATE `users` SET `username`='" + Params[1] + "' WHERE `username`='" + TargetUser.Username + "'"
Run that query through the IQuery Adapter.
 

Joe

Well-Known Member
Jun 10, 2012
4,090
1,918
You won't learn anything from having someone else do it for you - I'll give you the query; feel free to private message me if you're still struggling.
Code:
"UPDATE `users` SET `username`='" + Params[1] + "' WHERE `username`='" + TargetUser.Username + "'"
Run that query through the IQuery Adapter.
My guess is he needs more help, bump!
 

zakiy

Member
Dec 5, 2011
44
4
I got it coded, but now I have an error with the class.
Error 9 'Plus.HabboHotel.Rooms.Chat.Commands.Moderator.ChangeCommand' does not implement interface member 'Plus.HabboHotel.Rooms.Chat.Commands.IChatCommand.Execute(Plus.HabboHotel.GameClients.GameClient, Plus.HabboHotel.Rooms.Room, string[])' C:\Users\Administrator\Desktop\sss\HabboHotel\Rooms\Chat\Commands\Moderator\ChangeCommand.cs 20 11 Plus Emulator
 
Feb 1, 2014
165
137
Change Flagme to target client and add a IQuery adapter?
The user variables that are cached, automatically are saved upon user disconnect by the emulator.
He just needs to check if the session is in a nullable state, the user rank/permission then set the username.
He can add the fancy stuff once its finished like notifications after the change is done, etc. after he's finished.

shiietttt
I purposely say this to avoid helping people, I work as a professional Software Engineer & Visual Designer.
Sorry, I get waaay to many messages per day and it becomes frustrating now!
 

zakiy

Member
Dec 5, 2011
44
4
Francis, I just need the function of the command, I can add the TargetClient msg lines and notifications myself, the code i'm using is giving me an error about the class.
 

zakiy

Member
Dec 5, 2011
44
4
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, ClientPacket Packet, 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 = Packet.PopString();
string OldName = TargetClient.GetHabbo().Username;

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 = false;

Room.GetRoomUserManager().RemoveUserFromRoom(Session, true, false);
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("INSERT INTO `logs_client_namechange` (`user_id`,`new_name`,`old_name`,`timestamp`) VALUES ('" + TargetClient.GetHabbo().Id + "', @name, '" + OldName + "', '" + PlusEnvironment.GetUnixTimestamp() + "')");
dbClient.AddParameter("name", NewName);
dbClient.RunQuery();
}
}
}
}
 
May 1, 2015
467
152
I have no idea why you're using packets, as it's not needed.
I've fixed it up a bit for you, tested it & it works fine.
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;

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 == 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 = false;

            Room.GetRoomUserManager().RemoveUserFromRoom(Session, true, false);
            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("INSERT INTO `logs_client_namechange` (`user_id`,`new_name`,`old_name`,`timestamp`) VALUES ('" + TargetClient.GetHabbo().Id + "', @name, '" + OldName + "', '" + PlusEnvironment.GetUnixTimestamp() + "')");
                dbClient.AddParameter("name", NewName);
                dbClient.RunQuery();
            }
        }
    }
}
 
May 1, 2015
467
152
I just noticed there was no check for an empty string when changing a username.
Add the following to the code to prevent people from having blank usernames:
Code:
if (NewName == String.Empty)
            {
                Session.SendWhisper("You must enter a new name for the player!");
                return;
            }
 

Users who are viewing this thread

Top