[Quest API] Add CheckNameFilter to Perl/Lua. (#2175)

- Add quest::checknamefilter(name) to Perl.
- Add eq.check_name_filter(name) to Lua.
- Allows operators to check strings against the name filter for stuff like setting custom pet names, titles, suffixes, etc in scripts.
This commit is contained in:
Kinglykrab
2022-05-19 20:01:14 -04:00
committed by GitHub
parent 7c1a139991
commit 6398381c44
6 changed files with 65 additions and 62 deletions
+30 -54
View File
@@ -1167,91 +1167,67 @@ uint8 Database::GetPEQZone(uint32 zone_id, uint32 version){
return static_cast<uint8>(std::stoi(row[0]));
}
bool Database::CheckNameFilter(const char* name, bool surname)
bool Database::CheckNameFilter(std::string name, bool surname)
{
std::string str_name = name;
name = str_tolower(name);
// the minimum 4 is enforced by the client too
if (!name || strlen(name) < 4)
{
if (name.empty() || name.size() < 4) {
return false;
}
// Given name length is enforced by the client too
if (!surname && strlen(name) > 15)
{
if (!surname && name.size() > 15) {
return false;
}
for (size_t i = 0; i < str_name.size(); i++)
{
if(!isalpha(str_name[i]))
{
for (size_t i = 0; i < name.size(); i++) {
if (!isalpha(name[i])) {
return false;
}
}
for(size_t x = 0; x < str_name.size(); ++x)
{
str_name[x] = tolower(str_name[x]);
}
char c = '\0';
uint8 num_c = 0;
for(size_t x = 0; x < str_name.size(); ++x)
{
if(str_name[x] == c)
{
for (size_t x = 0; x < name.size(); ++x) {
if (name[x] == c) {
num_c++;
}
else
{
} else {
num_c = 1;
c = str_name[x];
c = name[x];
}
if(num_c > 2)
{
if (num_c > 2) {
return false;
}
}
std::string query("SELECT name FROM name_filter");
std::string query = "SELECT name FROM name_filter";
auto results = QueryDatabase(query);
if (!results.Success())
{
// false through to true? shouldn't it be falls through to false?
if (!results.Success()) {
return true;
}
for (auto row = results.begin();row != results.end();++row)
{
std::string current_row = row[0];
for(size_t x = 0; x < current_row.size(); ++x)
current_row[x] = tolower(current_row[x]);
if(str_name.find(current_row) != std::string::npos)
for (auto row : results) {
std::string current_row = str_tolower(row[0]);
if (name.find(current_row) != std::string::npos) {
return false;
}
}
return true;
}
bool Database::AddToNameFilter(const char* name) {
std::string query = StringFormat("INSERT INTO name_filter (name) values ('%s')", name);
bool Database::AddToNameFilter(std::string name) {
auto query = fmt::format(
"INSERT INTO name_filter (name) values ('{}')",
name
);
auto results = QueryDatabase(query);
if (!results.Success())
{
if (!results.Success() || !results.RowsAffected()) {
return false;
}
if (results.RowsAffected() == 0)
return false;
return true;
}
@@ -1339,16 +1315,16 @@ bool Database::UpdateName(const char* oldname, const char* newname) {
}
// If the name is used or an error occurs, it returns false, otherwise it returns true
bool Database::CheckUsedName(const char* name) {
std::string query = StringFormat("SELECT `id` FROM `character_data` WHERE `name` = '%s'", name);
bool Database::CheckUsedName(std::string name) {
auto query = fmt::format(
"SELECT `id` FROM `character_data` WHERE `name` = '{}'",
name
);
auto results = QueryDatabase(query);
if (!results.Success()) {
if (!results.Success() || results.RowCount()) {
return false;
}
if (results.RowCount() > 0)
return false;
return true;
}
+3 -3
View File
@@ -88,7 +88,6 @@ public:
/* Character Creation */
bool AddToNameFilter(const char *name);
bool CreateCharacter(
uint32 account_id,
char *name,
@@ -122,10 +121,11 @@ public:
/* General Information Queries */
bool AddBannedIP(std::string banned_ip, std::string notes); //Add IP address to the banned_ips table.
bool AddToNameFilter(std::string name);
bool CheckBannedIPs(std::string login_ip); //Check incoming connection against banned IP table.
bool CheckGMIPs(std::string login_ip, uint32 account_id);
bool CheckNameFilter(const char* name, bool surname = false);
bool CheckUsedName(const char* name);
bool CheckNameFilter(std::string name, bool surname = false);
bool CheckUsedName(std::string name);
uint32 GetAccountIDByChar(const char* charname, uint32* oCharID = 0);
uint32 GetAccountIDByChar(uint32 char_id);