Re-identifying entities

User avatar
Wuzzy
Member
 
Posts: 3627
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re-identifying entities

by Wuzzy » Fri Feb 22, 2019 02:53

Challenge: Let's suppose I want to implement a mod that adds a health regeneration effect for players. Let's say there is a health potion that regenerates 1 HP per second, for a total of 60 seconds. Now this is a fairly long time, so it must be persisted between server restarts. The challenge is to come up with a way to persist the regeneration effect. So when the server restarts, the player still has regeneration.

The solution is fairly-straight forward: When server shuts down, or the player leaves, the effect data can be serialized and be saved either in player attribute or a file or some other storage. The player name will used as an identifier, so when a player re-joins, the server knows exactly which effects to apply.

Now I will alter the challenge only slightly.
What if I want to do that not for players, but for non-player entities? They have health, too.
The problem I see is that there is nothing to uniquely identify the entities.
The only thing I have is the entity handler, but this will be invalidated when the entity unloads or the server restarts. The entity handler is useless for serialization.

So, to uniquely identify a player, I have the player name.
For non-player entities, I have … nothing, apparently.

I think solving the problem with non-player entities is impossible without access to some kind of globally unique entity ID. Or am I mistaken? Maybe I have overlooked a solution. Please enlighten me.
My creations. I gladly accept bitcoins: 17fsUywHxeMHKG41UFfu34F1rAxZcrVoqH
 

User avatar
GreenDimond
Member
 
Posts: 1272
Joined: Wed Oct 28, 2015 01:26
Location: SCP-3008
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Re-identifying entities

by GreenDimond » Fri Feb 22, 2019 03:08

staticdata
You can carry self values over unloads. Make an on_activate function track value of self.healing or whatever. You don't necessarily need to control the entity definition, either. If you are applying this effect to some unknown entity, you can give the entity the function and data when you apply the effect.
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenDimond#3232

Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.
 

ShadMOrdre
Member
 
Posts: 534
Joined: Mon Dec 29, 2014 08:07
Location: USA
GitHub: ShadMOrdre
In-game: shadmordre

Re: Re-identifying entities

by ShadMOrdre » Fri Feb 22, 2019 04:02

Wuzzy,

I would assume, as you do with doc, that you could add an self._entity_id or some variable like this to uniquely identify each entity.
MY MODS: lib_ecology lib_materials lib_clouds lib_node_shapes ---- Inspired By: Open Source Virtual World Simulator Opensimulator.
 

Skulls
Member
 
Posts: 108
Joined: Thu Dec 21, 2017 17:41
In-game: Skulls

Re: Re-identifying entities

by Skulls » Fri Feb 22, 2019 04:10

An in-game entity is a collection of states (health being one of them, position another), controller logic, and a 3d representation. The only thing you need to persist is the state. You don't really need to give the entity a unique ID that will persist through server restarts unless you want a way to link it to something else like a pointer.

You can just write things out and then create things in as they are read. All you really care about is that there is an entity of type X at position Y with health Z and boom, create that entity, set those values, boom, play on.
 

neoh4x0r
Member
 
Posts: 64
Joined: Wed Aug 29, 2018 20:16
GitHub: neoh4x0r

Re: Re-identifying entities

by neoh4x0r » Sat Feb 23, 2019 08:28

Wuzzy wrote:So, to uniquely identify a player, I have the player name.


Unfortunately, the player's name is not a unique identifier.

Consider what would happen if a player named xyz had your effect applied.
Later, another player joins and their name was xyz (unless there was a check that the name was in-use), then
the effect would be applied to a different player and not the intended one.

I know that the various methods take the player name as a parameter, but that is technically only unique per game session, to have a truly unique id that persisted between sessions a guid or uuid would be necessary.

PS: to quote the wiki: https://wiki.minetest.net/Server
"Player names need to be unique on a per-sever basis."

Which means that the name being unique entirely depends on the server setup (and shouldn't be relied upon)
 

wziard
Member
 
Posts: 126
Joined: Mon Oct 29, 2018 19:12

Re: Re-identifying entities

by wziard » Sat Feb 23, 2019 11:29

No. A player name is unique on a given server. Unless some admin or mod actively deletes the account.

> Which means that the name being unique entirely depends on the server setup (and shouldn't be relied upon)
But that's not what it means. And not what it sais???
 

User avatar
texmex
Member
 
Posts: 1588
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: texmex

Re: Re-identifying entities

by texmex » Sat Feb 23, 2019 20:43

If I'm not mistaken this is exactly the problem LATE mod solves as it works equal on players and non-player entities alike.
 

User avatar
Pyrollo
Member
 
Posts: 324
Joined: Mon Jan 08, 2018 15:14
Location: Paris
GitHub: pyrollo
In-game: Naj

Re: Re-identifying entities

by Pyrollo » Sun Feb 24, 2019 09:23

Hi Wuzzy,

Have a look at LATE, it's purpose was to treat mobs and players the same way (as far as possible). If I remember correctly, mechanisms for effect persistance for mobs are not yet implemented but conception has been made to make it possible.

I have less time to work on it these times but the bases are build. I'm very open to any contribution. I started to work on LATE because I think we really miss something to manage effects on players and mobs.
[ Display Modpack ] - [ Digiterms ] - [ Crater MG ] - [ LATE ]
 

neoh4x0r
Member
 
Posts: 64
Joined: Wed Aug 29, 2018 20:16
GitHub: neoh4x0r

Re: Re-identifying entities

by neoh4x0r » Tue Feb 26, 2019 15:40

wziard wrote:No. A player name is unique on a given server. Unless some admin or mod actively deletes the account.

> Which means that the name being unique entirely depends on the server setup (and shouldn't be relied upon)
But that's not what it means. And not what it sais???


I bed to differ with that....

https://wiki.minetest.net/Server#Connecting_to_a_server wrote:"You also need to choose a player name.
Player names need to be unique on a per-sever basis.
You can choose a password but this can be empty on some servers."


What that means is that if the server allows users to register accounts without passwords, then another person could use the same username without having to enter a password.

So it does very much depend on the server setup for whether or not a username means one and only one player.

Creating a useraccount and leaving the password blank creates a situation where that account is not unique, since anyone that logins with that username would be granted access (they don't need to know the password).
 

User avatar
GreenDimond
Member
 
Posts: 1272
Joined: Wed Oct 28, 2015 01:26
Location: SCP-3008
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Re-identifying entities

by GreenDimond » Tue Feb 26, 2019 15:50

neoh4x0r wrote:
wziard wrote:No. A player name is unique on a given server. Unless some admin or mod actively deletes the account.

> Which means that the name being unique entirely depends on the server setup (and shouldn't be relied upon)
But that's not what it means. And not what it sais???


I bed to differ with that....

https://wiki.minetest.net/Server#Connecting_to_a_server wrote:"You also need to choose a player name.
Player names need to be unique on a per-sever basis.
You can choose a password but this can be empty on some servers."


What that means is that if the server allows users to register accounts without passwords, then another person could use the same username without having to enter a password.

So it does very much depend on the server setup for whether or not a username means one and only one player.

Creating a useraccount and leaving the password blank creates a situation where that account is not unique, since anyone that logins with that username would be granted access (they don't need to know the password).

If a user logs in to an already created account then they will play as the character already created by the original user. A new account isn't created. Names are 100% unique identifiers, there is no two ways around it, sorry.
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenDimond#3232

Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.
 

neoh4x0r
Member
 
Posts: 64
Joined: Wed Aug 29, 2018 20:16
GitHub: neoh4x0r

Re: Re-identifying entities

by neoh4x0r » Thu Feb 28, 2019 22:28

GreenDimond wrote:If a user logs in to an already created account then they will play as the character already created by the original user. A new account isn't created. Names are 100% unique identifiers, there is no two ways around it, sorry.


It is unique to an account but not to individual users.

If more than one person uses an account, then it requires something more than just the username to differentiate between them (this could be done with a per-user sid that is sent to the server per-session that would uniquely identify each player attached to a single account).

This is what I meant by it not being unique: when multiple users are masquerading behind a single account.
As such it would become more difficult to know whether an effect should be applied--to the current user of the account --or not.
Last edited by neoh4x0r on Thu Feb 28, 2019 22:57, edited 1 time in total.
 

User avatar
GreenDimond
Member
 
Posts: 1272
Joined: Wed Oct 28, 2015 01:26
Location: SCP-3008
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Re-identifying entities

by GreenDimond » Thu Feb 28, 2019 22:56

neoh4x0r wrote:It is unique to an account but not to individual users.
<snip>
In the case, it becomes more difficult to know whether an effect applies to the current user of the account or not.

We don't care about the identity behind the account. The player is the player and that is that. Wuzzy has the name as the identifier; he is correct. You are making this way more complex than it needs to be.
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenDimond#3232

Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.
 

User avatar
Wuzzy
Member
 
Posts: 3627
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: Re-identifying entities

by Wuzzy » Thu Feb 28, 2019 23:01

That's what I meant about it not being unique -- it doesn't distinguish between individual users using the same account (account masquerading); to handle a situation like this would require another identifier besides the username to represent a specific user.

Gosh. I should be more specific: Same name = same player object. This really is an 1:1 relationship. This is good enough for me. Yes, I meant the player object, not the real world player.

It's true that this identity is not neccessarily true for real worlds players (=whoever sits at the computer screen).
If 2 players end up using the same player name, they share the same player object anyway. There's not really much you can do about it and I don't think it's even that big of a deal. If a player doesn't use a password: Their fault. If 2 players agreed to share a player name: Well, they agreed to, so also no big deal.

I am against in introducing yet another “identifier” on top of the player name, it's not needed. The player name alone is definitely enough to identify the player character, which is the only thing I really care about.






As for all the solutions presented to me so far: Thank you so far, but I'm afraid none of them were very convincing to me. Or I didn't understand it really. Maybe it would help to show minimal real-world examples?
LATE is a mob API as far I know, so sadly not generic enough.

But I think that entities in Minetest are just really horrible. They are kind of a more generic version of players that reminds me a bit of OOP, but there are also many, many annoying differences between players and entities.
Players have features that entities haven't although said features would be benefitial for both entities and players. Many callback functions are player-only, although they would make sense for both players AND entities. And, of course, player objects can be uniquely identified while entities (apparently) can't.
My creations. I gladly accept bitcoins: 17fsUywHxeMHKG41UFfu34F1rAxZcrVoqH
 

User avatar
texmex
Member
 
Posts: 1588
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: texmex

Re: Re-identifying entities

by texmex » Fri Mar 01, 2019 03:38

LATE is a mob API as far I know

What? Its effects may be applied to non-player entities as well as player ones. Have you checked out the demo?
Last edited by texmex on Fri Mar 01, 2019 09:00, edited 1 time in total.
 

ShadMOrdre
Member
 
Posts: 534
Joined: Mon Dec 29, 2014 08:07
Location: USA
GitHub: ShadMOrdre
In-game: shadmordre

Re: Re-identifying entities

by ShadMOrdre » Fri Mar 01, 2019 05:59

Wuzzy,

Since an entity is not necessarily a mob, take a look at how orwell retains entity knowledge between restarts in advtrains. The trains are moving entities, with routing info, owner and driver info, and they persist beyond restarts. This might be a more appropriate way to look at the problem you've specified, instead of only considering player or mob based solutions.

For that matter, pipeworks might also be a worthy consideration, in that the entities that are moved through the pipes, and are also persisted between restarts.

Shad
MY MODS: lib_ecology lib_materials lib_clouds lib_node_shapes ---- Inspired By: Open Source Virtual World Simulator Opensimulator.
 


Return to Modding Discussion



Who is online

Users browsing this forum: ThorfinnS and 1 guest