[Commands] Cleanup #gmzone Command. (#1836)

- Cleanup messages and logic.
- Add support for Zone ID.
This commit is contained in:
Kinglykrab 2021-11-27 18:19:03 -05:00 committed by GitHub
parent 96cdf1b076
commit 7d1d385418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 118 additions and 48 deletions

View File

@ -197,7 +197,7 @@ int command_init(void)
command_add("globalview", "Lists all qglobals in cache if you were to do a quest with this target.", AccountStatus::QuestTroupe, command_globalview) || command_add("globalview", "Lists all qglobals in cache if you were to do a quest with this target.", AccountStatus::QuestTroupe, command_globalview) ||
command_add("gm", "[On|Off] - Modify your or your target's GM Flag", AccountStatus::QuestTroupe, command_gm) || command_add("gm", "[On|Off] - Modify your or your target's GM Flag", AccountStatus::QuestTroupe, command_gm) ||
command_add("gmspeed", "[On|Off] - Turn GM Speed On or Off for you or your player target", AccountStatus::GMAdmin, command_gmspeed) || command_add("gmspeed", "[On|Off] - Turn GM Speed On or Off for you or your player target", AccountStatus::GMAdmin, command_gmspeed) ||
command_add("gmzone", "[zone_short_name] [zone_version=0] [identifier=gmzone] - Zones to a private GM instance", AccountStatus::GMAdmin, command_gmzone) || command_add("gmzone", "[Zone ID|Zone Short Name] [Version] [Instance Identifier] - Zones to a private GM instance (Version defaults to 0 and Instance Identifier defaults to 'gmzone' if not used)", AccountStatus::GMAdmin, command_gmzone) ||
command_add("goto", "[playername] or [x y z] [h] - Teleport to the provided coordinates or to your target", AccountStatus::Steward, command_goto) || command_add("goto", "[playername] or [x y z] [h] - Teleport to the provided coordinates or to your target", AccountStatus::Steward, command_goto) ||
command_add("grid", "[add/delete] [grid_num] [wandertype] [pausetype] - Create/delete a wandering grid", AccountStatus::GMAreas, command_grid) || command_add("grid", "[add/delete] [grid_num] [wandertype] [pausetype] - Create/delete a wandering grid", AccountStatus::GMAreas, command_grid) ||
command_add("guild", "- Guild manipulation commands. Use argument help for more info.", AccountStatus::Steward, command_guild) || command_add("guild", "- Guild manipulation commands. Use argument help for more info.", AccountStatus::Steward, command_guild) ||

View File

@ -3,86 +3,156 @@
void command_gmzone(Client *c, const Seperator *sep) void command_gmzone(Client *c, const Seperator *sep)
{ {
if (!sep->arg[1]) { int arguments = sep->argnum;
c->Message(Chat::White, "Usage"); if (!arguments) {
c->Message(Chat::White, "-------"); c->Message(Chat::White, "Usage: #gmzone [Zone ID|Zone Short Name] [Version] [Instance Identifier]");
c->Message(Chat::White, "#gmzone [zone_short_name] [zone_version=0]");
return; return;
} }
std::string zone_short_name_string = sep->arg[1]; std::string zone_short_name = str_tolower(
const char *zone_short_name = sep->arg[1]; sep->IsNumber(1) ?
auto zone_version = static_cast<uint32>(sep->arg[2] ? atoi(sep->arg[2]) : 0); ZoneName(std::stoul(sep->arg[1]), true) :
std::string identifier = "gmzone"; sep->arg[1]
uint32 zone_id = ZoneID(zone_short_name); );
uint32 duration = 100000000; bool is_unknown_zone = zone_short_name.find("unknown") != std::string::npos;
uint16 instance_id = 0; if (is_unknown_zone) {
c->Message(
Chat::White,
fmt::format(
"Zone {} could not be found.",
zone_short_name
).c_str()
);
}
if (zone_id == 0) { auto zone_id = ZoneID(zone_short_name);
c->Message(Chat::Red, "Invalid zone specified"); if (!zone_id) {
c->Message(
Chat::White,
fmt::format(
"Zone ID {} could not be found.",
zone_id
).c_str()
);
return; return;
} }
if (sep->arg[3] && sep->arg[3][0]) { std::string zone_long_name = ZoneLongName(zone_id);
identifier = sep->arg[3];
}
std::string bucket_key = StringFormat( auto zone_version = (
"%s-%s-%u-instance", sep->IsNumber(2) ?
std::stoul(sep->arg[2]) :
0
);
std::string instance_identifier = (
sep->arg[3] ?
sep->arg[3] :
"gmzone"
);
auto bucket_key = fmt::format(
"{}-{}-{}-instance",
zone_short_name, zone_short_name,
identifier.c_str(), instance_identifier,
zone_version zone_version
); );
std::string existing_zone_instance = DataBucket::GetData(bucket_key);
if (existing_zone_instance.length() > 0) { auto existing_zone_instance = DataBucket::GetData(bucket_key);
uint16 instance_id = 0;
uint32 duration = 100000000;
if (!existing_zone_instance.empty()) {
instance_id = std::stoi(existing_zone_instance); instance_id = std::stoi(existing_zone_instance);
c->Message(
c->Message(Chat::Yellow, "Found already created instance (%s) (%u)", zone_short_name, instance_id); Chat::White,
fmt::format(
"You already have an Instance ID of {} for Version {} of {} ({}).",
instance_id,
zone_version,
zone_long_name,
zone_short_name
).c_str()
);
} }
if (instance_id == 0) { if (!instance_id) {
if (!database.GetUnusedInstanceID(instance_id)) { if (!database.GetUnusedInstanceID(instance_id)) {
c->Message(Chat::Red, "Server was unable to find a free instance id."); c->Message(Chat::White, "Failed to find an unused Instance ID.");
return; return;
} }
if (!database.CreateInstance(instance_id, zone_id, zone_version, duration)) { if (!database.CreateInstance(instance_id, zone_id, zone_version, duration)) {
c->Message(Chat::Red, "Server was unable to create a new instance."); c->Message(Chat::White, "Failed to create an Instance.");
return; return;
} }
c->Message( c->Message(
Chat::Yellow, Chat::White,
"New private GM instance %s was created with id %lu.", fmt::format(
zone_short_name, "New GM Instance ID {} for Version {} of {} ({}) was created.",
(unsigned long) instance_id instance_id,
zone_version,
zone_long_name,
zone_short_name
).c_str()
);
DataBucket::SetData(
bucket_key,
std::to_string(instance_id)
); );
DataBucket::SetData(bucket_key, std::to_string(instance_id));
} }
if (instance_id > 0) { if (instance_id) {
float target_x = -1, target_y = -1, target_z = -1, target_heading = -1; float target_x = -1, target_y = -1, target_z = -1, target_heading = -1;
int16 min_status = AccountStatus::Player; int16 min_status = AccountStatus::Player;
uint8 min_level = 0; uint8 min_level = 0;
if (!content_db.GetSafePoints( if (
zone_short_name, !content_db.GetSafePoints(
zone_version, zone_short_name.c_str(),
&target_x, zone_version,
&target_y, &target_x,
&target_z, &target_y,
&target_heading, &target_z,
&min_status, &target_heading,
&min_level &min_status,
)) { &min_level
c->Message(Chat::Red, "Failed to find safe coordinates for specified zone"); )
) {
c->Message(
Chat::White,
fmt::format(
"Failed to find the safe coordinates for Version {} of {} ({}).",
zone_version,
zone_long_name,
zone_short_name
).c_str()
);
} }
c->Message(Chat::Yellow, "Zoning to private GM instance (%s) (%u)", zone_short_name, instance_id); c->Message(
Chat::White,
fmt::format(
"Zoning to GM Instance ID {} for Version {} of {} ({}).",
instance_id,
zone_version,
zone_long_name,
zone_short_name
).c_str()
);
c->AssignToInstance(instance_id); c->AssignToInstance(instance_id);
c->MovePC(zone_id, instance_id, target_x, target_y, target_z, target_heading, 1); c->MovePC(
zone_id,
instance_id,
target_x,
target_y,
target_z,
target_heading,
1
);
} }
} }