[Bug Fix] Spell Buckets/Globals did not allow string-based values. (#2043)

This commit is contained in:
Kinglykrab 2022-03-09 14:18:24 -05:00 committed by GitHub
parent dbe0591b09
commit e6c8a38ffa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5497,10 +5497,11 @@ uint32 Client::GetHighestScribedSpellinSpellGroup(uint32 spell_group)
}
bool Client::SpellGlobalCheck(uint16 spell_id, uint32 char_id) {
std::string spell_global_name;
int spell_global_value;
int global_value;
std::string query = fmt::format("SELECT qglobal, value FROM spell_globals WHERE spellid = {}", spell_id);
std::string query = fmt::format(
"SELECT qglobal, value FROM spell_globals WHERE spellid = {}",
spell_id
);
auto results = database.QueryDatabase(query);
if (!results.Success()) {
return false; // Query failed, do not allow scribing.
@ -5511,8 +5512,8 @@ bool Client::SpellGlobalCheck(uint16 spell_id, uint32 char_id) {
}
auto row = results.begin();
spell_global_name = row[0];
spell_global_value = std::stoi(row[1]);
std::string spell_global_name = row[0];
std::string spell_global_value = row[1];
if (spell_global_name.empty()) {
return true; // If the entry in the spell_globals table has nothing set for the qglobal name, allow scribing.
@ -5527,50 +5528,57 @@ bool Client::SpellGlobalCheck(uint16 spell_id, uint32 char_id) {
results = database.QueryDatabase(query);
if (!results.Success()) {
LogError(
"Spell ID [{}] query of spell_globals with Name: [{}] Value: [{}] failed",
spell_id,
"Spell global [{}] for spell ID [{}] for character ID [{}] query failed.",
spell_global_name,
spell_global_value
spell_id,
char_id
);
return false;
return false; // Query failed, do not allow scribing.
}
if (results.RowCount() != 1) {
if (!results.RowCount()) {
LogError(
"Char ID: [{}] does not have the Qglobal Name: [{}] for Spell ID [{}]",
char_id,
"Spell global [{}] for spell ID [{}] for character ID [{}] does not exist.",
spell_global_name,
spell_id
spell_id,
char_id
);
return false;
return false; // No rows found, do not allow scribing.
}
row = results.begin();
global_value = std::stoi(row[0]);
if (global_value >= spell_global_value) { // If value is greater than or equal to spell global value, allow scribing.
return true;
std::string global_value = row[0];
if (StringIsNumber(global_value) && StringIsNumber(spell_global_value)) {
if (std::stoi(global_value) >= std::stoi(spell_global_value)) {
return true; // If value is greater than or equal to spell global value, allow scribing.
}
} else {
if (global_value == spell_global_value) {
return true; // If value is equal to spell bucket value, allow scribing.
}
}
// If user's qglobal does not meet requirements, do not allow scribing.
LogError(
"Char ID: [{}] SpellGlobals Name: [{}] Value: [{}] did not match QGlobal Value: [{}] for Spell ID [{}]",
char_id,
"Spell global [{}] for spell ID [{}] for character ID [{}] did not match value [{}] value found was [{}].",
spell_global_name,
spell_id,
char_id,
spell_global_value,
global_value,
spell_id
global_value
);
return false;
}
bool Client::SpellBucketCheck(uint16 spell_id, uint32 char_id) {
std::string spell_bucket_name;
int spell_bucket_value;
int bucket_value;
std::string query = fmt::format("SELECT `key`, value FROM spell_buckets WHERE spellid = {}", spell_id);
auto query = fmt::format(
"SELECT `key`, value FROM spell_buckets WHERE spellid = {}",
spell_id
);
auto results = database.QueryDatabase(query);
if (!results.Success()) {
return false; // Query failed, do not allow scribing.
@ -5581,8 +5589,8 @@ bool Client::SpellBucketCheck(uint16 spell_id, uint32 char_id) {
}
auto row = results.begin();
spell_bucket_name = row[0];
spell_bucket_value = std::stoi(row[1]);
std::string spell_bucket_name = row[0];
std::string spell_bucket_value = row[1];
if (spell_bucket_name.empty()) {
return true; // If the entry in the spell_buckets table has nothing set for the qglobal name, allow scribing.
@ -5597,39 +5605,46 @@ bool Client::SpellBucketCheck(uint16 spell_id, uint32 char_id) {
results = database.QueryDatabase(query);
if (!results.Success()) {
LogError(
"Spell bucket [{}] for spell ID [{}] for char ID [{}] failed",
"Spell bucket [{}] for spell ID [{}] for character ID [{}] query failed.",
spell_bucket_name,
spell_id,
char_id
);
return false;
return false; // Query failed, do not allow scribing.
}
if (results.RowCount() != 1) {
if (!results.RowCount()) {
LogError(
"Spell bucket [{}] does not exist for spell ID [{}] for char ID [{}]",
"Spell bucket [{}] for spell ID [{}] for character ID [{}] does not exist.",
spell_bucket_name,
spell_id,
char_id
);
return false;
return false; // No rows found, do not allow scribing.
}
row = results.begin();
bucket_value = std::stoi(row[0]);
if (bucket_value >= spell_bucket_value) { // If value is greater than or equal to spell bucket value, allow scribing.
return true;
std::string bucket_value = row[0];
if (StringIsNumber(bucket_value) && StringIsNumber(spell_bucket_value)) {
if (std::stoi(bucket_value) >= std::stoi(spell_bucket_value)) {
return true; // If value is greater than or equal to spell bucket value, allow scribing.
}
} else {
if (bucket_value == spell_bucket_value) {
return true; // If value is equal to spell bucket value, allow scribing.
}
}
// If user's data bucket does not meet requirements, do not allow scribing.
LogError(
"Spell bucket [{}] for spell ID [{}] for char ID [{}] did not match value [{}]",
"Spell bucket [{}] for spell ID [{}] for character ID [{}] did not match value [{}] value found was [{}].",
spell_bucket_name,
spell_id,
char_id,
spell_bucket_value
spell_bucket_value,
bucket_value
);
return false;