[Commands] Cleanup #zonebootup and #zoneshutdown Commands (#3729)

# Notes
- Cleanup messages and logic.
This commit is contained in:
Alex King
2023-12-03 12:40:54 -05:00
committed by GitHub
parent e719aa43cf
commit 11a81d8e8a
6 changed files with 123 additions and 90 deletions
+32 -21
View File
@@ -5,26 +5,37 @@ extern WorldServer worldserver;
void command_zoneshutdown(Client *c, const Seperator *sep)
{
if (!worldserver.Connected()) {
c->Message(Chat::White, "Error: World server disconnected");
const int arguments = sep->argnum;
if (!arguments) {
c->Message(Chat::White, "Usage: #zoneshutdown [Zone ID|Zone Short Name]");
return;
}
else if (sep->arg[1][0] == 0) {
c->Message(Chat::White, "Usage: #zoneshutdown zoneshortname");
}
else {
auto pack = new ServerPacket(
ServerOP_ZoneShutdown,
sizeof(ServerZoneStateChange_struct));
ServerZoneStateChange_struct *s = (ServerZoneStateChange_struct *) pack->pBuffer;
strcpy(s->adminname, c->GetName());
if (sep->arg[1][0] >= '0' && sep->arg[1][0] <= '9') {
s->ZoneServerID = Strings::ToInt(sep->arg[1]);
}
else {
s->zoneid = ZoneID(sep->arg[1]);
}
worldserver.SendPacket(pack);
safe_delete(pack);
}
}
if (!worldserver.Connected()) {
c->Message(Chat::White, "World server disconnected.");
return;
}
const uint32 zone_id = sep->IsNumber(1) ? Strings::ToUnsignedInt(sep->arg[1]) : ZoneID(sep->arg[1]);
if (!zone_id) {
c->Message(
Chat::White,
fmt::format(
"Zone '{}' does not exist.",
sep->arg[1]
).c_str()
);
return;
}
auto pack = new ServerPacket(ServerOP_ZoneShutdown, sizeof(ServerZoneStateChange_Struct));
auto *s = (ServerZoneStateChange_Struct *) pack->pBuffer;
s->zone_id = zone_id;
strn0cpy(s->admin_name, c->GetName(), sizeof(s->admin_name));
worldserver.SendPacket(pack);
safe_delete(pack);
}