feat(server): add SET_PLAYER_NAME native and onPlayerNameChanged event - #4127
Open
xalva98 wants to merge 1 commit into
Open
feat(server): add SET_PLAYER_NAME native and onPlayerNameChanged event#4127xalva98 wants to merge 1 commit into
xalva98 wants to merge 1 commit into
Conversation
Adds a server native to change a player's name at runtime, usable during playerConnecting and afterwards. The name is normalized the same way connection-time names are (200 byte limit, invalid UTF-8 replaced), which is factored out into fx::NormalizePlayerName. The rename is replicated to clients using an onPlayerNameChanged event that only updates the netId-to-name map, instead of re-sending onPlayerJoining which would also re-create the physical player down the stack.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal of this PR
Make the enhanced
SET_PLAYER_NAMEnative and theonPlayerNameChangedevent available onlegacy GTA5 and RedM.
How is this PR achieving the goal
The native sets the name on
fx::Client, soGET_PLAYER_NAMEand everything built on it changeimmediately. Names are normalized exactly like connection-time names are (200 byte limit, invalid
UTF-8 replaced), factored out of
initConnectintofx::NormalizePlayerNameand shared by bothpaths.
Clients keep their own netId-to-name map that the game's name lookup is hooked into, so the rename
is broadcast as
onPlayerNameChangedandcitizen-playernames-five/-rdr3update just thatname. Re-sending
onPlayerJoiningwould also recreate the physical player, hence the separateevent.
Server-side scripts get
onPlayerNameChanged(source, oldName, newName, resourceName). Native name,event name and arguments match the enhanced API.
This PR applies to the following area(s)
FiveM, RedM, Natives, FxServer
Successfully tested on
Game builds: 3258 (FiveM), 1491 (RedM), FxServer
Platforms: Windows
Tested thoroughly on both games, client and server, with the test resource attached below: renaming
during
playerConnectingand after joining, all return values, the length limit, invalid UTF-8, theevent arguments, and the client-side name matching the server in the player list and overhead tags.
No issues found.
setplayername_test.zip
Checklist