[Request] Unique ID field for the player object

Post Reply
slay_mithos
Fast Inserter
Fast Inserter
Posts: 204
Joined: Tue Feb 25, 2014 7:22 am
Contact:

[Request] Unique ID field for the player object

Post by slay_mithos »

Hello,

While not personally a modder, it came to my attention that there is no reliable way to identify a player.

The most reliable way I can dig up seems to be the "name" property, but because it can be changed at any time in the option menu, it sounds like a very unreliable way to identify a player.

I am not saying that I have a perfect solution, but a solution that came to mind pretty easily was to give each account an ID, and give it to the client and save it either through a file download or at the first connection.

As I said, it is far from perfect, but it does feel logical to have a clear identifier when targeting multi-player.


If this already exists, and that it only didn't make its way into the Lua/Player wiki page, or is already planned, then do feel free to remove/lock this post.

FishSandwich
Smart Inserter
Smart Inserter
Posts: 1847
Joined: Sun Feb 23, 2014 3:37 pm
Contact:

Re: [Request] Unique ID field for the player object

Post by FishSandwich »

What would this be used for? The only thing I can think of is banning people from your world.

slay_mithos
Fast Inserter
Fast Inserter
Posts: 204
Joined: Tue Feb 25, 2014 7:22 am
Contact:

Re: [Request] Unique ID field for the player object

Post by slay_mithos »

Well, from what I have seen, mods that store additional informations per player in the globals could use it.

The problem rose from CurseEXP, that adds various skills, levels and exp, and is currently using the nickname.

But changing the nickname in turn causes problems when trying to load a game (and join multiplayer worlds?).


It might not be the best way to go about saving things, but I do want to see more mods that add more than just buildings and recipes, and player-bound data (or rather problems related to it) seems to be something that might hinder their development.

A whitelist/blacklist, like pointed out, could also be put together via this, better than with nicknames, but that was not my reason for asking.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13202
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [Request] Unique ID field for the player object

Post by Rseding91 »

It is a known issue at the moment. There's no way to tell if a reference to a player object is actually the same as the player you originally pointed it at.

Take this example:

Player 1 starts a game as player index 1: information about player index 1 is stored in the mod "level: 0, skill: 0, ..."
Player 2 joins the game as player index 2: information about player index 2 is stored in the mod "level: 0, skill: 0, ..."
Player 2 leaves the game
Player 1 starts the game and uses /c game.removeofflineplayers(): player index 2 is no longer a valid player number
Player 3 joins the game as player index 2: mod already has has information about player index 2 but it is actually wrong because this is not real player 2 but a new person

This can partially be solved by using a reference to the player: glob.player2 = game.getplayer(2) and glob.player2.valid will become false as soon as player 2 is removed even if a new player 2 joins it remains false.

But, there's no "glob.player2.equals(game.getplayer(2))" right now so there's no way to tell if your stored reference to a player is actually the same player as the current player 2.

There's also no (good) way to detect if a player is disconnected or not.
If you want to get ahold of me I'm almost always on Discord.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13202
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [Request] Unique ID field for the player object

Post by Rseding91 »

This has been resolved for 0.12. In 0.12 you'll be able to compare player objects to each other to tell if they're identical:

Code: Select all

if glob.player == game.getplayer(1) then ... end
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Implemented mod requests”