View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0009610New issuesSynchronizationpublic2017-04-29 21:412017-05-23 18:56
Assigned To 
PlatformOSOS Version
Summary0009610: Setting player name in an onPlayerConnect event handler results in desync
DescriptionWhen 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 ReproduceExecute the following example code:

addEventHandler("onPlayerConnect", root,
        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))

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
arranTuna (manager)
2017-04-30 20:21
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.

johny46 (viewer)
2017-04-30 22:42

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.
Necktrox (developer)
2017-05-18 00:41
edited on: 2017-05-23 18:56

Possible relation: [^]

Edit: getPlayerFromName is the culprit in this case, because it returns an element to a player, which didn't finish loading the game

- Issue History
Date Modified Username Field Change
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
Powered by Mantis Bugtracker