[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
+10 -4
View File
@@ -167,15 +167,21 @@ bool BotDatabase::LoadBotSpellCastingChances()
/* Bot functions */
bool BotDatabase::QueryNameAvailablity(const std::string& bot_name, bool& available_flag)
{
if (bot_name.empty() || bot_name.size() > 60 || !database.CheckUsedName(bot_name.c_str()))
if (bot_name.empty() || bot_name.size() > 60 || !database.CheckUsedName(bot_name))
return false;
query = StringFormat("SELECT `id` FROM `vw_bot_character_mobs` WHERE `name` LIKE '%s' LIMIT 1", bot_name.c_str());
query = fmt::format(
"SELECT `id` FROM `vw_bot_character_mobs` WHERE `name` LIKE '{}' LIMIT 1",
bot_name
);
auto results = database.QueryDatabase(query);
if (!results.Success())
if (!results.Success()) {
return false;
if (results.RowCount())
}
if (results.RowCount()) {
return true;
}
available_flag = true;
+1 -1
View File
@@ -6375,7 +6375,7 @@ void Client::Handle_OP_GMNameChange(const EQApplicationPacket *app)
}
Client* client = entity_list.GetClientByName(gmn->oldname);
LogInfo("GM([{}]) changeing players name. Old:[{}] New:[{}]", GetName(), gmn->oldname, gmn->newname);
bool usedname = database.CheckUsedName((const char*)gmn->newname);
bool usedname = database.CheckUsedName(gmn->newname);
if (client == 0) {
Message(Chat::Red, "%s not found for name change. Operation failed!", gmn->oldname);
return;
+16
View File
@@ -8347,6 +8347,21 @@ XS(XS__commify) {
XSRETURN(1);
}
XS(XS__checknamefilter);
XS(XS__checknamefilter) {
dXSARGS;
if (items != 1) {
Perl_croak(aTHX_ "Usage: quest::checknamefilter(std::string name)");
}
dXSTARG;
std::string name = (std::string) SvPV_nolen(ST(0));
bool passes = database.CheckNameFilter(name);
ST(0) = boolSV(passes);
sv_2mortal(ST(0));
XSRETURN(1);
}
/*
This is the callback perl will look for to setup the
quest package's XSUBs
@@ -8434,6 +8449,7 @@ EXTERN_C XS(boot_quest) {
newXS(strcpy(buf, "buryplayercorpse"), XS__buryplayercorpse, file);
newXS(strcpy(buf, "castspell"), XS__castspell, file);
newXS(strcpy(buf, "changedeity"), XS__changedeity, file);
newXS(strcpy(buf, "checknamefilter"), XS__checknamefilter, file);
newXS(strcpy(buf, "checktitle"), XS__checktitle, file);
newXS(strcpy(buf, "clear_npctype_cache"), XS__clear_npctype_cache, file);
newXS(strcpy(buf, "clear_proximity"), XS__clear_proximity, file);
+5
View File
@@ -3392,6 +3392,10 @@ std::string lua_commify(std::string number) {
return commify(number);
}
bool lua_check_name_filter(std::string name) {
return database.CheckNameFilter(name);
}
#define LuaCreateNPCParse(name, c_type, default_value) do { \
cur = table[#name]; \
if(luabind::type(cur) != LUA_TNIL) { \
@@ -3845,6 +3849,7 @@ luabind::scope lua_register_general() {
luabind::def("get_consider_level_name", &lua_get_consider_level_name),
luabind::def("get_environmental_damage_name", &lua_get_environmental_damage_name),
luabind::def("commify", &lua_commify),
luabind::def("check_name_filter", &lua_check_name_filter),
/*
Cross Zone