|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0009610||New issues||Synchronization||public||2017-04-29 21:41||2017-05-23 18:56|
|Summary||0009610: Setting player name in an onPlayerConnect event handler results in desync|
|Description||When you change the name of a player attempting to join your server upon the "onPlayerConnect" event fires, the client gets desynchronized.|
getPlayerName() server-side will then return the new name, and on other clients it will also do that. But on the client whose name was changed, getPlayerName(localPlayer) will instead return the name they initially connected with.
|Steps To Reproduce||Execute the following example code:|
local player = getPlayerFromName(playerNick)
local newName = string.format("%04d", math.random(9999))
local result = setPlayerName(player, newName)
if not result then
outputDebugString(string.format("Failed to change %q -> %q", playerNick, newName))
|Tags||No tags attached.|
edited on: 2017-05-18 01:18
Servers cannot permanently change another players name. In your steps to reproduce you've got "Reconnect" so I'm pretty sure this is a false bug report as you're reporting an intentional feature as a bug.
Reconnect so you actually get a chance to trigger that event yourself without the need for any other players on the server.
When you call the (server-sided) `setPlayerName` function at any moment other than just after the "onPlayerConnect" event is triggered, the value returned by subsequent client-side `getPlayerName` calls will be the newly set name.
Only when setting the name inside a "onPlayerConnect" (server-side) event handler occurs the problem I described - values returned by `getPlayerName` will be different if called server-side and if called on the affected client. All the other clients will get the new name of the affected player as well.
To better illustrate the issue, suppose this situation:
- There are 2 players already connected to the server: "A" and "B".
- Third player, nicknamed "C" attempts to join the server as well.
- "onPlayerConnect" is triggered with the string "C" as the `playerNick` argument
- Server-side scripts can obtain the player element by calling `player = getPlayerFromName("C")`
- Server-side script calls `setPlayerName(player, "D")`
What happens after that:
- `getPlayerName(player)` called server-side will correctly return the new name "D"
- `getPlayerName(player)` called client-side on clients "A" and "B" will correctly return the new name "D"
- `getPlayerName(localPlayer)` called client-side on the newly connected (third) client will incorrectly return "C"
- `getPlayerFromName("D")` called client-side on the third client will return `false`, as if there was no player named "D"
Hope this helps.
edited on: 2017-05-23 18:56
Possible relation: https://github.com/multitheftauto/mtasa-blue/blob/master/Client/mods/deathmatch/logic/CPacketHandler.cpp#L1161 [^]
Edit: getPlayerFromName is the culprit in this case, because it returns an element to a player, which didn't finish loading the game
|2017-04-29 21:41||johny46||New Issue|
|2017-04-30 20:21||arranTuna||Note Added: 0025877|
|2017-04-30 20:21||arranTuna||Status||new => feedback|
|2017-04-30 22:42||johny46||Note Added: 0025881|
|2017-04-30 22:42||johny46||Status||feedback => new|
|2017-05-18 00:41||Necktrox||Note Added: 0025960|
|2017-05-18 01:18||qaisjp||Note Edited: 0025877||View Revisions|
|2017-05-23 18:56||Necktrox||Note Edited: 0025960||View Revisions|
|Copyright © 2000 - 2017 MantisBT Team|