https://metaplay.io logo
u
I have a question about how to implement a player online system in the best way: A player has a list of other players that it follows (uni-directionally) and when logging in it wants to know which of the players in the list are online. Reversely, any player that is following the player that logs in, should be notified that he is back online. Potentially the following list could contain 100s of players. I have been looking into EntitySubscribe, Guilds and the DailyTen example etc. but not sure what would be the best way of achieving this. Thanks in advance for any help!
h
We don't have Friends/Followed-Players feature yet that would solve exactly this requirement. We also don't (yet?) have efficient way to query this kind of data either. If you just want online players, that can be done with an ephemeral actor that keeps the online players in a list, and playeractors add themseleves there. Essentially a simple in-memory db. Playerdata is quite small, so even a simplest implementation should scale quite ok. But this presence bool is not enough in practice. We also need player avatar data, i.e. their names, "ranks", xp counts etc. As we don't want to query this data from the players (we'd need to ask 100 players to show the playerlist -> slow and uses a lot of resources), we need a Persisted avatar storage the players keep up-to-date. In practice, this can be just a new SQL table that player actors keep up to date. With proper indices, this might scale to a medium scale game fine. But at larger scales, we believe we need more advanced data structures and storages.
u
Got it! Thanks a lot for your input on this. This would solve how to check which of my friends are online when I login. To notify players that follow me that Im back online, I suppose each player could subscribe to changes to this ephemeral actor. However this means that all online players will be notified about all players coming online, unless there is one topic per player (i.e "online:{playerid}") and each player subscribe to one topic per player it follows... Would this scale?
h
Large amount of subscriptions to the single ephemeral entity wouldn't scale well, indeed. For notifying about a friend coming online, that can be distributed easily by mocking the notification to the playeractor itself. First upon player coming online, the playeractor would fetch the online players from the emphemeral actor, and then send a message to all online friends' actors. And conversely, notify all online friends when a playeractor goes offline. In this model, the players only need to ask the global list of friend only once and in particular we don't need to subscribe or poll the central entity. Emphemeral actors are quite easily sharded too, if scale becomes an issue.
u
To make this persisted avatar storage, which would include limited information about each player, would it make sense not to have this table sharded? I.e only in master shard, as when querying this table it would be for potentially 100s of player ids. And if so, how to go about implementing this table in master shard only?
h
Our documentation has an example for implementing a custom database persisted entity https://docs.metaplay.io/game-server-programming/how-to-guides/custom-server-entities.html#overview The sharding settings are defined in step 5: https://docs.metaplay.io/game-server-programming/how-to-guides/custom-server-entities.html#_5-define-the-entity-configuration Also you can check
MetaplaySDK/Backend/Cloud/Sharding/ShardingStrategy.cs
u
Thanks! I understood from our conversation earlier that this probably will not scale well for our use-case but maybe I was wrong. Im checking the example and maybe I can tweak it to work. However, I dont see in the SDK how to select rows from the db for multiple keys. Apart from the `Query.. `with ranges methods.