[ANY] Prevent user name changes

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Zeus
Member
Posts: 52
Joined: Sat Mar 24, 2018 5:25 pm
Location: Chicago
Contact:

[ANY] Prevent user name changes

Postby Zeus » Mon Dec 30, 2019 11:38 pm

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?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [ANY] Prevent user name changes

Postby L'In20Cible » Tue Dec 31, 2019 3:16 am

Try something similar to what is being done in: https://github.com/Source-Python-Dev-Te ... cstrike.py
InvisibleSoldiers
Senior Member
Posts: 114
Joined: Fri Mar 15, 2019 6:08 am

Re: [ANY] Prevent user name changes

Postby InvisibleSoldiers » Thu Jan 02, 2020 1:31 am

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 );
Last edited by InvisibleSoldiers on Fri Jan 03, 2020 7:02 pm, edited 2 times in total.
Sam
Senior Member
Posts: 100
Joined: Tue Jul 03, 2018 3:00 pm
Location: *DELETED*
Contact:

Re: [ANY] Prevent user name changes

Postby Sam » Fri Jan 03, 2020 5:57 pm

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?
Last edited by Sam on Fri Jan 03, 2020 5:57 pm, edited 1 time in total.
Reason: Original post version
InvisibleSoldiers
Senior Member
Posts: 114
Joined: Fri Mar 15, 2019 6:08 am

Re: [ANY] Prevent user name changes

Postby InvisibleSoldiers » Fri Jan 03, 2020 6:50 pm

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 :rolleyes:
Sam
Senior Member
Posts: 100
Joined: Tue Jul 03, 2018 3:00 pm
Location: *DELETED*
Contact:

Re: [ANY] Prevent user name changes

Postby Sam » Fri Jan 03, 2020 7:09 pm

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.
Last edited by Sam on Fri Jan 03, 2020 7:09 pm, edited 1 time in total.
Reason: Original post version
Sam
Senior Member
Posts: 100
Joined: Tue Jul 03, 2018 3:00 pm
Location: *DELETED*
Contact:

Re: [ANY] Prevent user name changes

Postby Sam » Fri Jan 03, 2020 7:18 pm

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 :rolleyes:


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"
Last edited by Sam on Fri Jan 03, 2020 7:18 pm, edited 1 time in total.
Reason: Original post version
InvisibleSoldiers
Senior Member
Posts: 114
Joined: Fri Mar 15, 2019 6:08 am

Re: [ANY] Prevent user name changes

Postby InvisibleSoldiers » Fri Jan 03, 2020 7:23 pm

Sam wrote:

Image
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [ANY] Prevent user name changes

Postby Ayuto » Fri Jan 03, 2020 7:31 pm

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.
Sam
Senior Member
Posts: 100
Joined: Tue Jul 03, 2018 3:00 pm
Location: *DELETED*
Contact:

Re: [ANY] Prevent user name changes

Postby Sam » Fri Jan 03, 2020 7:35 pm

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.
Last edited by Sam on Fri Jan 03, 2020 7:35 pm, edited 1 time in total.
Reason: Original post version
InvisibleSoldiers
Senior Member
Posts: 114
Joined: Fri Mar 15, 2019 6:08 am

Re: [ANY] Prevent user name changes

Postby InvisibleSoldiers » Sat Jan 04, 2020 7:31 am

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

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 34 guests