mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 12:41:30 +00:00
[Commands] Add #zonevariable Command (#4882)
* [Commands] Add #zonevariable Command * Update zonevariable.cpp * Argument safety --------- Co-authored-by: Chris Miles <akkadius1@gmail.com>
This commit is contained in:
parent
888a88f966
commit
f29478c105
@ -246,6 +246,7 @@ int command_init(void)
|
||||
command_add("zoneinstance", "[Instance ID] [X] [Y] [Z] - Teleport to specified Instance by ID (coordinates are optional)", AccountStatus::Guide, command_zone_instance) ||
|
||||
command_add("zoneshard", "[zone] [instance_id] - Teleport explicitly to a zone shard", AccountStatus::Player, command_zone_shard) ||
|
||||
command_add("zoneshutdown", "[instance|zone] [Instance ID|Zone ID|Zone Short Name] - Shut down a zone server by Instance ID, Zone ID, or Zone Short Name", AccountStatus::GMLeadAdmin, command_zoneshutdown) ||
|
||||
command_add("zonevariable", "[clear|delete|set|view] - Modify zone variables for your current zone", AccountStatus::GMAdmin, command_zonevariable) ||
|
||||
command_add("zsave", " Saves zheader to the database", AccountStatus::QuestTroupe, command_zsave)
|
||||
) {
|
||||
command_deinit();
|
||||
@ -928,6 +929,7 @@ void command_bot(Client *c, const Seperator *sep)
|
||||
#include "gm_commands/zone.cpp"
|
||||
#include "gm_commands/zonebootup.cpp"
|
||||
#include "gm_commands/zoneshutdown.cpp"
|
||||
#include "gm_commands/zonevariable.cpp"
|
||||
#include "gm_commands/zone_instance.cpp"
|
||||
#include "gm_commands/zone_shard.cpp"
|
||||
#include "gm_commands/zsave.cpp"
|
||||
|
||||
@ -198,6 +198,7 @@ void command_zone_instance(Client *c, const Seperator *sep);
|
||||
void command_zone_shard(Client *c, const Seperator *sep);
|
||||
void command_zonebootup(Client *c, const Seperator *sep);
|
||||
void command_zoneshutdown(Client *c, const Seperator *sep);
|
||||
void command_zonevariable(Client *c, const Seperator *sep);
|
||||
void command_zsave(Client *c, const Seperator *sep);
|
||||
|
||||
#include "bot.h"
|
||||
|
||||
100
zone/gm_commands/zonevariable.cpp
Normal file
100
zone/gm_commands/zonevariable.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
#include "../client.h"
|
||||
|
||||
void command_zonevariable(Client *c, const Seperator *sep)
|
||||
{
|
||||
const uint16 arguments = sep->argnum;
|
||||
|
||||
if (!arguments) {
|
||||
c->Message(Chat::White, "Usage: #zonevariable clear - Clear all zone variables");
|
||||
c->Message(Chat::White, "Usage: #zonevariable delete [Variable Name] - Delete a zone variable");
|
||||
c->Message(Chat::White, "Usage: #zonevariable set [Variable Name] [Variable Value] - Set a zone variable");
|
||||
c->Message(Chat::White, "Usage: #zonevariable view [Variable Name] - View a zone variable");
|
||||
c->Message(Chat::White, "Note: You can have spaces in variable names and values by wrapping in double quotes like this");
|
||||
c->Message(Chat::White, "Example: #zonevariable set \"Test Variable\" \"Test Value\"");
|
||||
c->Message(Chat::White, "Note: Variable Value is optional and can be set to empty by not providing a value");
|
||||
return;
|
||||
}
|
||||
|
||||
const char* action = arguments >= 1 ? sep->arg[1] : "";
|
||||
const bool is_clear = !strcasecmp(action, "clear");
|
||||
const bool is_delete = !strcasecmp(action, "delete");
|
||||
const bool is_set = !strcasecmp(action, "set");
|
||||
const bool is_view = !strcasecmp(action, "view");
|
||||
|
||||
if (!is_clear && !is_delete && !is_set && !is_view) {
|
||||
c->Message(Chat::White, "Usage: #zonevariable clear - Clear all zone variables");
|
||||
c->Message(Chat::White, "Usage: #zonevariable delete [Variable Name] - Delete a zone variable");
|
||||
c->Message(Chat::White, "Usage: #zonevariable set [Variable Name] [Variable Value] - Set a zone variable");
|
||||
c->Message(Chat::White, "Usage: #zonevariable view [Variable Name] - View a zone variable");
|
||||
c->Message(Chat::White, "Note: You can have spaces in variable names and values by wrapping in double quotes like this");
|
||||
c->Message(Chat::White, "Example: #zonevariable set \"Test Variable\" \"Test Value\"");
|
||||
c->Message(Chat::White, "Note: Variable Value is optional and can be set to empty by not providing a value");
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_clear) {
|
||||
const bool cleared = zone->ClearVariables();
|
||||
c->Message(Chat::White, cleared ? "Cleared all zone variables." : "There are no zone variables to clear.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_delete) {
|
||||
const std::string variable_name = arguments >= 2 ? sep->argplus[2] : "";
|
||||
if (variable_name.empty() || !zone->VariableExists(variable_name)) {
|
||||
c->Message(Chat::White, fmt::format("A zone variable named '{}' does not exist.", variable_name).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
zone->DeleteVariable(variable_name);
|
||||
c->Message(Chat::White, fmt::format("Deleted a zone variable named '{}'.", variable_name).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_set) {
|
||||
const std::string variable_name = arguments >= 2 ? sep->arg[2] : "";
|
||||
const std::string variable_value = arguments >= 3 ? sep->arg[3] : "";
|
||||
zone->SetVariable(variable_name, variable_value);
|
||||
c->Message(Chat::White, fmt::format("Set a zone variable named '{}' to a value of '{}'.", variable_name, variable_value).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_view) {
|
||||
const auto& l = zone->GetVariables();
|
||||
const std::string search_criteria = arguments >= 2 ? sep->argplus[2] : "";
|
||||
|
||||
uint32 variable_count = 0;
|
||||
uint32 variable_number = 1;
|
||||
|
||||
for (const auto& e : l) {
|
||||
if (search_criteria.empty() || Strings::Contains(Strings::ToLower(e), Strings::ToLower(search_criteria))) {
|
||||
c->Message(Chat::White, fmt::format(
|
||||
"Variable {} | Name: {} Value: {} | {}",
|
||||
variable_number,
|
||||
e,
|
||||
zone->GetVariable(e),
|
||||
Saylink::Silent(fmt::format("#zonevariable delete {}", e), "Delete")
|
||||
).c_str());
|
||||
|
||||
variable_count++;
|
||||
variable_number++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!variable_count) {
|
||||
c->Message(Chat::White, fmt::format(
|
||||
"There are no zone variables{}.",
|
||||
(!search_criteria.empty() ? fmt::format(" matching '{}'", search_criteria) : "")
|
||||
).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
c->Message(Chat::White, fmt::format(
|
||||
"There {} {} zone variable{}{}, would you like to {} zone variables?",
|
||||
variable_count != 1 ? "are" : "is",
|
||||
variable_count,
|
||||
variable_count != 1 ? "s" : "",
|
||||
(!search_criteria.empty() ? fmt::format(" matching '{}'", search_criteria) : ""),
|
||||
Saylink::Silent("#zonevariable clear", "clear")
|
||||
).c_str());
|
||||
}
|
||||
}
|
||||
@ -727,10 +727,10 @@ std::string Lua_Zone::GetBucketRemaining(const std::string& bucket_name)
|
||||
return self->GetBucketRemaining(bucket_name);
|
||||
}
|
||||
|
||||
void Lua_Zone::ClearVariables()
|
||||
bool Lua_Zone::ClearVariables()
|
||||
{
|
||||
Lua_Safe_Call_Void();
|
||||
self->ClearVariables();
|
||||
Lua_Safe_Call_Bool();
|
||||
return self->ClearVariables();
|
||||
}
|
||||
|
||||
bool Lua_Zone::DeleteVariable(const std::string& variable_name)
|
||||
|
||||
@ -141,7 +141,7 @@ public:
|
||||
void SetInstanceTimeRemaining(uint32 time_remaining);
|
||||
void SetIsHotzone(bool is_hotzone);
|
||||
void ShowZoneGlobalLoot(Lua_Client c);
|
||||
void ClearVariables();
|
||||
bool ClearVariables();
|
||||
bool DeleteVariable(const std::string& variable_name);
|
||||
std::string GetVariable(const std::string& variable_name);
|
||||
luabind::object GetVariables(lua_State* L);
|
||||
|
||||
@ -561,9 +561,9 @@ std::string Perl_Zone_GetBucketRemaining(Zone* self, const std::string bucket_na
|
||||
return self->GetBucketRemaining(bucket_name);
|
||||
}
|
||||
|
||||
void Perl_Zone_ClearVariables(Zone* self)
|
||||
bool Perl_Zone_ClearVariables(Zone* self)
|
||||
{
|
||||
self->ClearVariables();
|
||||
return self->ClearVariables();
|
||||
}
|
||||
|
||||
bool Perl_Zone_DeleteVariable(Zone* self, const std::string variable_name)
|
||||
|
||||
@ -3225,9 +3225,14 @@ void Zone::DisableRespawnTimers()
|
||||
}
|
||||
}
|
||||
|
||||
void Zone::ClearVariables()
|
||||
bool Zone::ClearVariables()
|
||||
{
|
||||
if (m_zone_variables.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_zone_variables.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Zone::DeleteVariable(const std::string& variable_name)
|
||||
|
||||
@ -198,7 +198,7 @@ public:
|
||||
int32 MobsAggroCount() { return aggroedmobs; }
|
||||
DynamicZone *GetDynamicZone();
|
||||
|
||||
void ClearVariables();
|
||||
bool ClearVariables();
|
||||
bool DeleteVariable(const std::string& variable_name);
|
||||
std::string GetVariable(const std::string& variable_name);
|
||||
std::vector<std::string> GetVariables();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user