[Commands] Cleanup #lastname Command. (#1802)

- Cleanup message and logic.
This commit is contained in:
Kinglykrab 2021-11-21 10:12:47 -05:00 committed by GitHub
parent 8a27fce3a8
commit 03847fb1ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 10 deletions

View File

@ -229,7 +229,7 @@ int command_init(void)
command_add("kick", "[charname] - Disconnect charname", AccountStatus::GMLeadAdmin, command_kick) ||
command_add("kill", "- Kill your target", AccountStatus::GMAdmin, command_kill) ||
command_add("killallnpcs", " [npc_name] Kills all npcs by search name, leave blank for all attackable NPC's", AccountStatus::GMMgmt, command_killallnpcs) ||
command_add("lastname", "[new lastname] - Set your or your player target's lastname", AccountStatus::Guide, command_lastname) ||
command_add("lastname", "[Last Name] - Set you or your player target's lastname", AccountStatus::Guide, command_lastname) ||
command_add("level", "[level] - Set your or your target's level", AccountStatus::Steward, command_level) ||
command_add("list", "[npcs|players|corpses|doors|objects] [search] - Search entities", AccountStatus::ApprenticeGuide, command_list) ||
command_add("listpetition", "- List petitions", AccountStatus::Guide, command_listpetition) ||

View File

@ -2,18 +2,36 @@
void command_lastname(Client *c, const Seperator *sep)
{
Client *t = c;
Client *target = c;
if (c->GetTarget() && c->GetTarget()->IsClient()) {
t = c->GetTarget()->CastToClient();
target = c->GetTarget()->CastToClient();
}
LogInfo("#lastname request from [{}] for [{}]", c->GetName(), t->GetName());
if (strlen(sep->arg[1]) <= 70) {
t->ChangeLastName(sep->arg[1]);
}
else {
c->Message(Chat::White, "Usage: #lastname <lastname> where <lastname> is less than 70 chars long");
LogInfo("#lastname request from [{}] for [{}]", c->GetCleanName(), target->GetCleanName());
std::string last_name = sep->arg[1];
if (last_name.size() > 64) {
c->Message(Chat::White, "Usage: #lastname [Last Name] (Last Name must be 64 characters or less)");
return;
}
target->ChangeLastName(last_name.c_str());
c->Message(
Chat::White,
fmt::format(
"{} now {} a last name of '{}'.",
(
c == target ?
"You" :
fmt::format(
"{} ({})",
target->GetCleanName(),
target->GetID()
)
),
c == target ? "have" : "has",
last_name
).c_str()
);
}