Page 1 of 1
[ANY] Prevent user name changes
Posted: Mon Dec 30, 2019 11:38 pm
by Zeus
I'm creating an plugin to integrate my discord with my TF2 servers; and want to force names to be sync'd. I need to be able to prevent players from changing their name.
This code does not seem to work:
Code: Select all
@PreEvent('player_changename')
def on_changename(event):
return EventAction.BLOCK
Am I missing something?
Re: [ANY] Prevent user name changes
Posted: Tue Dec 31, 2019 3:16 am
by L'In20Cible
Re: [ANY] Prevent user name changes
Posted: Thu Jan 02, 2020 1:31 am
by InvisibleSoldiers
L'In20Cible
Syntax: Select all
@PreHook(get_virtual_function(engine_server, 'ClientCommand'))
def _pre_client_command(args):
"""Block name changes started by the server.
Pre-hook on IVEngineServer::ClientCommand to block the name changes.
"""
if args[2] == 'name "%s"':
return 0
it doesn't work because
name it's client convar which he probably changes after Steam verification, and the server only requests it, the actual name change occurs in
ClientSettingsChanged and call it
pPlayer->SetPlayerName( pszName )Syntax: Select all
ConVar cl_name ( "name","unnamed", FCVAR_ARCHIVE | FCVAR_USERINFO | FCVAR_PRINTABLEONLY | FCVAR_SERVER_CAN_EXECUTE, "Current user name", CL_NameCvarChanged );
Re: [ANY] Prevent user name changes
Posted: Fri Jan 03, 2020 5:57 pm
by Sam
Zeus wrote:I'm creating an plugin to integrate my discord with my TF2 servers; and want to force names to be sync'd. I need to be able to prevent players from changing their name.
This code does not seem to work:
Code: Select all
@PreEvent('player_changename')
def on_changename(event):
return EventAction.BLOCK
Am I missing something?
Code: Select all
@PreEvent('player_changename')
def OnChangeName(args):
client = Player.from_userid(args.get_int('userid'))
client.set_name(args.get_string('oldname'))
return EventAction.BLOCK
I understand correctly?
Re: [ANY] Prevent user name changes
Posted: Fri Jan 03, 2020 6:50 pm
by InvisibleSoldiers
Sam wrote:I understand correctly?
void CBaseClient::SetName:
Syntax: Select all
m_ConVars->SetString( "name", m_Name );
m_Server->UserInfoChanged( m_nClientSlot );
Yes, you are right, didn't notice the simple function

Re: [ANY] Prevent user name changes
Posted: Fri Jan 03, 2020 7:09 pm
by Sam
InvisibleSoldiers wrote:Sam wrote:I understand correctly?
No, this is possible, although I'm not sure, will only block a chat message, and he needs more global preventing.
Syntax: Select all
else if ( Q_strcmp( "player_changename", eventname ) == 0 )
{
if ( !hudChat )
return;
const char *pszOldName = event->GetString("oldname");
if ( PlayerNameNotSetYet(pszOldName) )
return;
wchar_t wszOldName[MAX_PLAYER_NAME_LENGTH];
g_pVGuiLocalize->ConvertANSIToUnicode( pszOldName, wszOldName, sizeof(wszOldName) );
wchar_t wszNewName[MAX_PLAYER_NAME_LENGTH];
g_pVGuiLocalize->ConvertANSIToUnicode( event->GetString( "newname" ), wszNewName, sizeof(wszNewName) );
wchar_t wszLocalized[100];
g_pVGuiLocalize->ConstructString( wszLocalized, sizeof( wszLocalized ), g_pVGuiLocalize->Find( "#game_player_changed_name" ), 2, wszOldName, wszNewName );
char szLocalized[100];
g_pVGuiLocalize->ConvertUnicodeToANSI( wszLocalized, szLocalized, sizeof(szLocalized) );
hudChat->Printf( CHAT_FILTER_NAMECHANGE, "%s", szLocalized );
What the... xD
I realized that he needed to block the player’s nickname change. I wrote test code that I haven’t tested (I have no way to test it)
I wrote code that should hide the change new nickname and return the old nickname. If you want more. What is stopping you? Write, study the code.
Re: [ANY] Prevent user name changes
Posted: Fri Jan 03, 2020 7:18 pm
by Sam
InvisibleSoldiers wrote:Sam wrote:I understand correctly?
void CBaseClient::SetName:
Syntax: Select all
m_ConVars->SetString( "name", m_Name );
m_Server->UserInfoChanged( m_nClientSlot );
Yes, you are right, didn't notice the simple function

Oh my GOD. As I did not see this little function... xDD
Take offsets or signatures. And do not be challenging. I do not compete here, but only offer my own solution to the problem.
"I have the disassemblers and source code on all computers with fast internet xD"
Re: [ANY] Prevent user name changes
Posted: Fri Jan 03, 2020 7:23 pm
by InvisibleSoldiers
Sam wrote:

Re: [ANY] Prevent user name changes
Posted: Fri Jan 03, 2020 7:31 pm
by Ayuto
Sam wrote:"I have the disassemblers and source code on all computers with fast internet xD"
There is a leaked version of the Source Engine 2007, public Source SDK released by Valve and reverse engineered versions of the Source SDK.
Re: [ANY] Prevent user name changes
Posted: Fri Jan 03, 2020 7:35 pm
by Sam
Ayuto wrote:Sam wrote:"I have the disassemblers and source code on all computers with fast internet xD"
There is a leaked version of the Source Engine 2007, public Source SDK released by Valve and reverse engineered versions of the Source SDK.
I know, but my modem in the hills working badly xD
I am not in the city and I can not help with anything other than theoretical knowledge.
Re: [ANY] Prevent user name changes
Posted: Sat Jan 04, 2020 7:31 am
by InvisibleSoldiers
Syntax: Select all
@PreEvent('player_changename')
def pre_player_changename(gevent):
player = Player.from_userid(gevent['userid'])
# Update scoreboard.
player.set_name(gevent['oldname'])
gevent['newname'] = gevent['oldname']
return EventAction.BLOCK