[PlayerName]: Display error message to user (#889)

This commit is contained in:
Edo 2023-03-31 16:59:08 +02:00 committed by GitHub
parent aef7d2fb2f
commit a2437c6f48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 30 deletions

View File

@ -6,26 +6,6 @@ namespace Components
{
Dvar::Var PlayerName::sv_allowColoredNames;
bool PlayerName::IsBadChar(int c)
{
if (c == '%')
{
return true;
}
if (c == '~')
{
return true;
}
if (c < 32 || c > 126)
{
return true;
}
return false;
}
void PlayerName::UserInfoCopy(char* buffer, const char* name, const int size)
{
if (!sv_allowColoredNames.get<bool>())
@ -83,6 +63,26 @@ namespace Components
return string;
}
bool PlayerName::IsBadChar(int c)
{
if (c == '%')
{
return true;
}
if (c == '~')
{
return true;
}
if (c < 32 || c > 126)
{
return true;
}
return false;
}
bool PlayerName::CopyClientNameCheck(char* dest, const char* source, int size)
{
Utils::Hook::Call<void(char*, const char*, int)>(0x4D6F80)(dest, source, size); // I_strncpyz
@ -103,10 +103,15 @@ namespace Components
return true;
}
void PlayerName::DropClient(Game::client_t* drop)
{
const auto* reason = "Invalid name detected";
Network::SendCommand(drop->header.netchan.remoteAddress, "error", reason);
Game::SV_DropClient(drop, reason, false);
}
__declspec(naked) void PlayerName::SV_UserinfoChangedStub()
{
using namespace Game;
__asm
{
call CopyClientNameCheck
@ -116,11 +121,9 @@ namespace Components
pushad
push 1 // tellThem
push INVALID_NAME_MSG // reason
push edi // drop
call SV_DropClient
add esp, 0xC
call DropClient
add esp, 0x4
popad

View File

@ -13,15 +13,13 @@ namespace Components
private:
static Dvar::Var sv_allowColoredNames;
// Message used when kicking players
static constexpr auto INVALID_NAME_MSG = "Invalid name detected";
static bool IsBadChar(int c);
static char* CleanStrStub(char* string);
static void ClientCleanName();
static bool IsBadChar(int c);
static bool CopyClientNameCheck(char* dest, const char* source, int size);
static void DropClient(Game::client_t* drop);
static void SV_UserinfoChangedStub();
};
}