[Commands] Cleanup #name Command. (#1977)

- Cleanup messages and logic.
This commit is contained in:
Kinglykrab 2022-02-10 16:14:40 -05:00 committed by GitHub
parent 968ae26c99
commit 5396c0c88b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 20 deletions

View File

@ -252,7 +252,7 @@ int command_init(void)
command_add("myskills", "- Show details about your current skill levels", AccountStatus::Player, command_myskills) || command_add("myskills", "- Show details about your current skill levels", AccountStatus::Player, command_myskills) ||
command_add("mysql", "[Help|Query] [SQL Query] - Mysql CLI, see 'Help' for options.", AccountStatus::GMImpossible, command_mysql) || command_add("mysql", "[Help|Query] [SQL Query] - Mysql CLI, see 'Help' for options.", AccountStatus::GMImpossible, command_mysql) ||
command_add("mystats", "- Show details about you or your pet", AccountStatus::Guide, command_mystats) || command_add("mystats", "- Show details about you or your pet", AccountStatus::Guide, command_mystats) ||
command_add("name", "[newname] - Rename your player target", AccountStatus::GMLeadAdmin, command_name) || command_add("name", "[New Name] - Rename your player target", AccountStatus::GMLeadAdmin, command_name) ||
command_add("netstats", "- Gets the network stats for a stream.", AccountStatus::GMMgmt, command_netstats) || command_add("netstats", "- Gets the network stats for a stream.", AccountStatus::GMMgmt, command_netstats) ||
command_add("network", "- Admin commands for the udp network interface.", AccountStatus::GMImpossible, command_network) || command_add("network", "- Admin commands for the udp network interface.", AccountStatus::GMImpossible, command_network) ||
command_add("npccast", "[targetname/entityid] [spellid] - Causes NPC target to cast spellid on targetname/entityid", AccountStatus::QuestTroupe, command_npccast) || command_add("npccast", "[targetname/entityid] [spellid] - Causes NPC target to cast spellid on targetname/entityid", AccountStatus::QuestTroupe, command_npccast) ||

View File

@ -2,29 +2,41 @@
void command_name(Client *c, const Seperator *sep) void command_name(Client *c, const Seperator *sep)
{ {
Client *target; int arguments = sep->argnum;
if (!arguments) {
if ((strlen(sep->arg[1]) == 0) || (!(c->GetTarget() && c->GetTarget()->IsClient()))) { c->Message(Chat::White, "Usage: #name [New Name] - Rename your player target");
c->Message(Chat::White, "Usage: #name newname (requires player target)"); return;
} }
else {
target = c->GetTarget()->CastToClient(); if (c->GetTarget() && c->GetTarget()->IsClient()) {
char *oldname = strdup(target->GetName()); auto target = c->GetTarget()->CastToClient();
if (target->ChangeFirstName(sep->arg[1], c->GetName())) {
c->Message(Chat::White, "Successfully renamed %s to %s", oldname, sep->arg[1]); std::string new_name = sep->arg[1];
// until we get the name packet working right this will work std::string old_name = target->GetCleanName();
c->Message(Chat::White, "Sending player to char select.");
target->Kick("Name was changed"); if (target->ChangeFirstName(new_name.c_str(), c->GetCleanName())) {
}
else {
c->Message( c->Message(
Chat::Red, Chat::White,
"ERROR: Unable to rename %s. Check that the new name '%s' isn't already taken.", fmt::format(
oldname, "Successfully renamed {} to {}",
sep->arg[2] old_name,
new_name
).c_str()
);
c->Message(Chat::White, "Sending player to char select.");
target->Kick("Name was changed");
} else {
c->Message(
Chat::White,
fmt::format(
"Unable to rename {}. Check that the new name '{}' isn't already taken.",
old_name,
new_name
).c_str()
); );
} }
free(oldname);
} }
} }