mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 22:58:34 +00:00
[Quest API] Add getcleannpcnamebyid(npc_id) to Perl/Lua. (#1383)
* [Quest API] Add optional clean name parameter to getnpcnamebyid in Perl/Lua. - Allows Server Operators to grab the clean name without having to clean it up in their Perl/Lua. * Convert from a parameter to a method. * Add safer method. * Convert to proper type.
This commit is contained in:
@@ -906,6 +906,26 @@ std::string Database::GetNPCNameByID(uint32 npc_id) {
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string Database::GetCleanNPCNameByID(uint32 npc_id) {
|
||||
std::string query = fmt::format("SELECT `name` FROM `npc_types` WHERE id = {}", npc_id);
|
||||
auto results = QueryDatabase(query);
|
||||
std::string res;
|
||||
std::string mob_name;
|
||||
|
||||
if (!results.Success()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if (results.RowCount() == 0) {
|
||||
return res;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
mob_name = row[0];
|
||||
CleanMobName(mob_name.begin(), mob_name.end(), std::back_inserter(res));
|
||||
return res;
|
||||
}
|
||||
|
||||
bool Database::LoadVariables() {
|
||||
auto results = QueryDatabase(StringFormat("SELECT varname, value, unix_timestamp() FROM variables where unix_timestamp(ts) >= %d", varcache.last_update));
|
||||
|
||||
|
||||
@@ -140,6 +140,7 @@ public:
|
||||
void GetCharName(uint32 char_id, char* name);
|
||||
std::string GetCharNameByID(uint32 char_id);
|
||||
std::string GetNPCNameByID(uint32 npc_id);
|
||||
std::string GetCleanNPCNameByID(uint32 npc_id);
|
||||
void LoginIP(uint32 AccountID, const char* LoginIP);
|
||||
|
||||
/* Instancing */
|
||||
|
||||
@@ -206,4 +206,17 @@ std::string convert2digit(int n, std::string suffix);
|
||||
std::string numberToWords(unsigned long long int n);
|
||||
std::string FormatName(const std::string& char_name);
|
||||
|
||||
template<typename InputIterator, typename OutputIterator>
|
||||
auto CleanMobName(InputIterator first, InputIterator last, OutputIterator result)
|
||||
{
|
||||
for (; first != last; ++first) {
|
||||
if(*first == '_') {
|
||||
*result = ' ';
|
||||
} else if (isalpha(*first) || *first == '`') {
|
||||
*result = *first;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user