Update playername cleaning to clean fonticons and enforce 3 character minimum serverside
This commit is contained in:
parent
ccefbeb885
commit
967eeb2989
@ -162,7 +162,7 @@ namespace Components
|
|||||||
// Don't perform any checks if name didn't change
|
// Don't perform any checks if name didn't change
|
||||||
if (name == lastValidName) return;
|
if (name == lastValidName) return;
|
||||||
|
|
||||||
std::string saneName = TextRenderer::StripColors(Utils::String::Trim(name));
|
std::string saneName = TextRenderer::StripAllTextIcons(TextRenderer::StripColors(Utils::String::Trim(name)));
|
||||||
if (saneName.size() < 3 || (saneName[0] == '[' && saneName[1] == '{'))
|
if (saneName.size() < 3 || (saneName[0] == '[' && saneName[1] == '{'))
|
||||||
{
|
{
|
||||||
Logger::Print("Username '%s' is invalid. It must at least be 3 characters long and not appear empty!\n", name.data());
|
Logger::Print("Username '%s' is invalid. It must at least be 3 characters long and not appear empty!\n", name.data());
|
||||||
|
@ -650,12 +650,12 @@ namespace Components
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextRenderer::StripColors(const char* in, char* out, int max)
|
void TextRenderer::StripColors(const char* in, char* out, size_t max)
|
||||||
{
|
{
|
||||||
if (!in || !out) return;
|
if (!in || !out) return;
|
||||||
|
|
||||||
max--;
|
max--;
|
||||||
int current = 0;
|
size_t current = 0;
|
||||||
while (*in != 0 && current < max)
|
while (*in != 0 && current < max)
|
||||||
{
|
{
|
||||||
const char index = *(in + 1);
|
const char index = *(in + 1);
|
||||||
@ -682,17 +682,129 @@ namespace Components
|
|||||||
return std::string(buffer);
|
return std::string(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextRenderer::UserInfoCopy(char* buffer, const char* name, size_t size)
|
void TextRenderer::StripMaterialTextIcons(const char* in, char* out, size_t max)
|
||||||
{
|
{
|
||||||
Utils::Memory::Allocator allocator;
|
if (!in || !out) return;
|
||||||
|
|
||||||
if (!sv_allowColoredNames.get<bool>())
|
max--;
|
||||||
|
size_t current = 0;
|
||||||
|
while (*in != 0 && current < max)
|
||||||
{
|
{
|
||||||
StripColors(name, buffer, size);
|
if (*in == '^' && (in[1] == '\x01' || in[1] == '\x02'))
|
||||||
|
{
|
||||||
|
in += 2;
|
||||||
|
|
||||||
|
if (*in) // width
|
||||||
|
in++;
|
||||||
|
if (*in) // height
|
||||||
|
in++;
|
||||||
|
|
||||||
|
if(*in) // material name length + material name characters
|
||||||
|
{
|
||||||
|
const auto materialNameLength = *in;
|
||||||
|
in++;
|
||||||
|
for(auto i = 0; i < materialNameLength; i++)
|
||||||
|
{
|
||||||
|
if (*in)
|
||||||
|
in++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strncpy_s(buffer, size, name, _TRUNCATE);
|
*out = *in;
|
||||||
|
++out;
|
||||||
|
++current;
|
||||||
|
++in;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
*out = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TextRenderer::StripMaterialTextIcons(const std::string& in)
|
||||||
|
{
|
||||||
|
char buffer[1000] = { 0 }; // Should be more than enough
|
||||||
|
StripAllTextIcons(in.data(), buffer, sizeof(buffer));
|
||||||
|
return std::string(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextRenderer::StripAllTextIcons(const char* in, char* out, size_t max)
|
||||||
|
{
|
||||||
|
if (!in || !out) return;
|
||||||
|
|
||||||
|
max--;
|
||||||
|
size_t current = 0;
|
||||||
|
while (*in != 0 && current < max)
|
||||||
|
{
|
||||||
|
if (*in == '^' && (in[1] == '\x01' || in[1] == '\x02'))
|
||||||
|
{
|
||||||
|
in += 2;
|
||||||
|
|
||||||
|
if (*in) // width
|
||||||
|
in++;
|
||||||
|
if (*in) // height
|
||||||
|
in++;
|
||||||
|
|
||||||
|
if(*in) // material name length + material name characters
|
||||||
|
{
|
||||||
|
const auto materialNameLength = *in;
|
||||||
|
in++;
|
||||||
|
for(auto i = 0; i < materialNameLength; i++)
|
||||||
|
{
|
||||||
|
if (*in)
|
||||||
|
in++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(*in == ':')
|
||||||
|
{
|
||||||
|
const auto* fontIconEndPos = &in[1];
|
||||||
|
FontIconInfo fontIcon{};
|
||||||
|
if(IsFontIcon(fontIconEndPos, fontIcon))
|
||||||
|
{
|
||||||
|
in = fontIconEndPos;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = *in;
|
||||||
|
++out;
|
||||||
|
++current;
|
||||||
|
++in;
|
||||||
|
}
|
||||||
|
*out = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TextRenderer::StripAllTextIcons(const std::string& in)
|
||||||
|
{
|
||||||
|
char buffer[1000] = { 0 }; // Should be more than enough
|
||||||
|
StripAllTextIcons(in.data(), buffer, sizeof(buffer));
|
||||||
|
return std::string(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextRenderer::UserInfoCopy(char* buffer, const char* name, const size_t size)
|
||||||
|
{
|
||||||
|
if (!sv_allowColoredNames.get<bool>())
|
||||||
|
{
|
||||||
|
char nameBuffer[64] = {0};
|
||||||
|
StripColors(name, nameBuffer, sizeof(nameBuffer));
|
||||||
|
StripAllTextIcons(nameBuffer, buffer, size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
StripAllTextIcons(name, buffer, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string readablePlayerName(buffer);
|
||||||
|
readablePlayerName = Utils::String::Trim(readablePlayerName);
|
||||||
|
|
||||||
|
if(readablePlayerName.size() < 3)
|
||||||
|
{
|
||||||
|
strncpy(buffer, "Unknown Soldier", size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,8 +83,12 @@ namespace Components
|
|||||||
static void DrawText2D(const char* text, float x, float y, Game::Font_s* font, float xScale, float yScale, float sinAngle, float cosAngle, Game::GfxColor color, int maxLength, int renderFlags, int cursorPos, char cursorLetter, float padding, Game::GfxColor glowForcedColor, int fxBirthTime, int fxLetterTime, int fxDecayStartTime, int fxDecayDuration, Game::Material* fxMaterial, Game::Material* fxMaterialGlow);
|
static void DrawText2D(const char* text, float x, float y, Game::Font_s* font, float xScale, float yScale, float sinAngle, float cosAngle, Game::GfxColor color, int maxLength, int renderFlags, int cursorPos, char cursorLetter, float padding, Game::GfxColor glowForcedColor, int fxBirthTime, int fxLetterTime, int fxDecayStartTime, int fxDecayDuration, Game::Material* fxMaterial, Game::Material* fxMaterialGlow);
|
||||||
static int R_TextWidth_Hk(const char* text, int maxChars, Game::Font_s* font);
|
static int R_TextWidth_Hk(const char* text, int maxChars, Game::Font_s* font);
|
||||||
static unsigned int ColorIndex(char index);
|
static unsigned int ColorIndex(char index);
|
||||||
static void StripColors(const char* in, char* out, int max);
|
static void StripColors(const char* in, char* out, size_t max);
|
||||||
static std::string StripColors(const std::string& in);
|
static std::string StripColors(const std::string& in);
|
||||||
|
static void StripMaterialTextIcons(const char* in, char* out, size_t max);
|
||||||
|
static std::string StripMaterialTextIcons(const std::string& in);
|
||||||
|
static void StripAllTextIcons(const char* in, char* out, size_t max);
|
||||||
|
static std::string StripAllTextIcons(const std::string& in);
|
||||||
static void UserInfoCopy(char* buffer, const char* name, size_t size);
|
static void UserInfoCopy(char* buffer, const char* name, size_t size);
|
||||||
|
|
||||||
TextRenderer();
|
TextRenderer();
|
||||||
|
Loading…
Reference in New Issue
Block a user