mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-06 04:42:28 +00:00
Argument safety
This commit is contained in:
parent
3d0c573c83
commit
4742f4fffd
@ -15,17 +15,13 @@ void command_zonevariable(Client *c, const Seperator *sep)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool is_clear = !strcasecmp(sep->arg[1], "clear");
|
const char* action = arguments >= 1 ? sep->arg[1] : "";
|
||||||
const bool is_delete = !strcasecmp(sep->arg[1], "delete");
|
const bool is_clear = !strcasecmp(action, "clear");
|
||||||
const bool is_set = !strcasecmp(sep->arg[1], "set");
|
const bool is_delete = !strcasecmp(action, "delete");
|
||||||
const bool is_view = !strcasecmp(sep->arg[1], "view");
|
const bool is_set = !strcasecmp(action, "set");
|
||||||
|
const bool is_view = !strcasecmp(action, "view");
|
||||||
|
|
||||||
if (
|
if (!is_clear && !is_delete && !is_set && !is_view) {
|
||||||
!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 clear - Clear all zone variables");
|
||||||
c->Message(Chat::White, "Usage: #zonevariable delete [Variable Name] - Delete a zone variable");
|
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 set [Variable Name] [Variable Value] - Set a zone variable");
|
||||||
@ -38,82 +34,46 @@ void command_zonevariable(Client *c, const Seperator *sep)
|
|||||||
|
|
||||||
if (is_clear) {
|
if (is_clear) {
|
||||||
const bool cleared = zone->ClearVariables();
|
const bool cleared = zone->ClearVariables();
|
||||||
|
c->Message(Chat::White, cleared ? "Cleared all zone variables." : "There are no zone variables to clear.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!cleared) {
|
if (is_delete) {
|
||||||
c->Message(Chat::White, "There are no zone variables to clear.");
|
const std::string variable_name = arguments >= 2 ? sep->argplus[2] : "";
|
||||||
return;
|
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());
|
||||||
|
|
||||||
c->Message(Chat::White, "Cleared all zone variables.");
|
|
||||||
} else if (is_delete) {
|
|
||||||
const std::string variable_name = sep->argplus[2];
|
|
||||||
|
|
||||||
if (!zone->VariableExists(variable_name)) {
|
|
||||||
c->Message(
|
|
||||||
Chat::White,
|
|
||||||
fmt::format(
|
|
||||||
"A zone variable named '{}' does not exist.",
|
|
||||||
variable_name
|
|
||||||
).c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
zone->DeleteVariable(variable_name);
|
zone->DeleteVariable(variable_name);
|
||||||
|
c->Message(Chat::White, fmt::format("Deleted a zone variable named '{}'.", variable_name).c_str());
|
||||||
c->Message(
|
|
||||||
Chat::White,
|
|
||||||
fmt::format(
|
|
||||||
"Deleted a zone variable named '{}'.",
|
|
||||||
variable_name
|
|
||||||
).c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else if (is_set) {
|
}
|
||||||
const std::string variable_name = sep->arg[2];
|
|
||||||
const std::string variable_value = sep->arg[3];
|
|
||||||
|
|
||||||
|
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);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
c->Message(
|
if (is_view) {
|
||||||
Chat::White,
|
|
||||||
fmt::format(
|
|
||||||
"Set a zone variable named '{}' to a value of '{}'.",
|
|
||||||
variable_name,
|
|
||||||
variable_value
|
|
||||||
).c_str()
|
|
||||||
);
|
|
||||||
} else if (is_view) {
|
|
||||||
const auto& l = zone->GetVariables();
|
const auto& l = zone->GetVariables();
|
||||||
|
const std::string search_criteria = arguments >= 2 ? sep->argplus[2] : "";
|
||||||
|
|
||||||
uint32 variable_count = 0;
|
uint32 variable_count = 0;
|
||||||
uint32 variable_number = 1;
|
uint32 variable_number = 1;
|
||||||
|
|
||||||
const std::string search_criteria = arguments >= 2 ? sep->argplus[2] : "";
|
|
||||||
|
|
||||||
for (const auto& e : l) {
|
for (const auto& e : l) {
|
||||||
if (
|
if (search_criteria.empty() || Strings::Contains(Strings::ToLower(e), Strings::ToLower(search_criteria))) {
|
||||||
search_criteria.empty() ||
|
c->Message(Chat::White, fmt::format(
|
||||||
Strings::Contains(Strings::ToLower(e), Strings::ToLower(search_criteria))
|
"Variable {} | Name: {} Value: {} | {}",
|
||||||
) {
|
variable_number,
|
||||||
c->Message(
|
e,
|
||||||
Chat::White,
|
zone->GetVariable(e),
|
||||||
fmt::format(
|
Saylink::Silent(fmt::format("#zonevariable delete {}", e), "Delete")
|
||||||
"Variable {} | Name: {} Value: {} | {}",
|
).c_str());
|
||||||
variable_number,
|
|
||||||
e,
|
|
||||||
zone->GetVariable(e),
|
|
||||||
Saylink::Silent(
|
|
||||||
fmt::format(
|
|
||||||
"#zonevariable delete {}",
|
|
||||||
e
|
|
||||||
),
|
|
||||||
"Delete"
|
|
||||||
)
|
|
||||||
).c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
variable_count++;
|
variable_count++;
|
||||||
variable_number++;
|
variable_number++;
|
||||||
@ -121,44 +81,20 @@ void command_zonevariable(Client *c, const Seperator *sep)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!variable_count) {
|
if (!variable_count) {
|
||||||
c->Message(
|
c->Message(Chat::White, fmt::format(
|
||||||
Chat::White,
|
"There are no zone variables{}.",
|
||||||
fmt::format(
|
(!search_criteria.empty() ? fmt::format(" matching '{}'", search_criteria) : "")
|
||||||
"There are no zone variables{}.",
|
).c_str());
|
||||||
(
|
|
||||||
!search_criteria.empty() ?
|
|
||||||
fmt::format(
|
|
||||||
" matching '{}'",
|
|
||||||
search_criteria
|
|
||||||
) :
|
|
||||||
""
|
|
||||||
)
|
|
||||||
).c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
c->Message(
|
c->Message(Chat::White, fmt::format(
|
||||||
Chat::White,
|
"There {} {} zone variable{}{}, would you like to {} zone variables?",
|
||||||
fmt::format(
|
variable_count != 1 ? "are" : "is",
|
||||||
"There {} {} zone variable{}{}, would you like to {} zone variables?",
|
variable_count,
|
||||||
variable_count != 1 ? "are" : "is",
|
variable_count != 1 ? "s" : "",
|
||||||
variable_count,
|
(!search_criteria.empty() ? fmt::format(" matching '{}'", search_criteria) : ""),
|
||||||
variable_count != 1 ? "s" : "",
|
Saylink::Silent("#zonevariable clear", "clear")
|
||||||
(
|
).c_str());
|
||||||
!search_criteria.empty() ?
|
|
||||||
fmt::format(
|
|
||||||
" matching '{}'",
|
|
||||||
search_criteria
|
|
||||||
) :
|
|
||||||
""
|
|
||||||
),
|
|
||||||
Saylink::Silent(
|
|
||||||
"#zonevariable clear",
|
|
||||||
"clear"
|
|
||||||
)
|
|
||||||
).c_str()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user