2018-03-14 01:35:31 +00:00
|
|
|
#include "name_ban.h"
|
|
|
|
|
2022-05-23 20:55:04 +00:00
|
|
|
CNameBan *IsNameBanned(const char *pName, std::vector<CNameBan> &vNameBans)
|
2018-03-14 01:35:31 +00:00
|
|
|
{
|
|
|
|
char aTrimmed[MAX_NAME_LENGTH];
|
2022-07-09 16:14:56 +00:00
|
|
|
str_copy(aTrimmed, str_utf8_skip_whitespaces(pName));
|
2018-03-14 01:35:31 +00:00
|
|
|
str_utf8_trim_right(aTrimmed);
|
|
|
|
|
|
|
|
int aSkeleton[MAX_NAME_SKELETON_LENGTH];
|
2022-03-30 13:16:19 +00:00
|
|
|
int SkeletonLength = str_utf8_to_skeleton(aTrimmed, aSkeleton, std::size(aSkeleton));
|
2018-03-14 01:35:31 +00:00
|
|
|
int aBuffer[MAX_NAME_SKELETON_LENGTH * 2 + 2];
|
|
|
|
|
2022-05-23 20:55:04 +00:00
|
|
|
CNameBan *pResult = nullptr;
|
|
|
|
for(CNameBan &Ban : vNameBans)
|
2018-03-14 01:35:31 +00:00
|
|
|
{
|
2022-05-23 20:55:04 +00:00
|
|
|
int Distance = str_utf32_dist_buffer(aSkeleton, SkeletonLength, Ban.m_aSkeleton, Ban.m_SkeletonLength, aBuffer, std::size(aBuffer));
|
|
|
|
if(Distance <= Ban.m_Distance || (Ban.m_IsSubstring == 1 && str_utf8_find_nocase(pName, Ban.m_aName)))
|
|
|
|
pResult = &Ban;
|
2018-03-14 01:35:31 +00:00
|
|
|
}
|
|
|
|
return pResult;
|
|
|
|
}
|