https://metaplay.io logo
View other Players' profiles
# questions-and-feedback
a
Hey, how to get other players' data for a view-other-players-profile feature? I guess a pair of request-response actions, player actions, but should something then on the Server dig the info directly from the DB, or is it better to use akka messaging to ask it from the entity? I guess it's not necessary to wake up the entity just to read info from the db, so maybe I could just put a db get to the PlayerActor or something. I recently learned finally how to use the DB directly properly so that seems doable 🙂
ah the admin api func to get player info seems like a useful reference the code in [HttpGet("players/{playerIdStr}/raw")]
oh it actually uses akka messaging to get the state
playerStateResponse.SetData(await EntityAskAsync<InternalEntityStateResponse>(playerMetaData.Data.Id, InternalEntityStateRequest.Instance));
n
Yeah, the admin api uses EntityAsk to fetch the state, and that is the recommended way for your use case too. There might be players in the database that have not logged in for a while, and their schema version might be multiple versions behind. Doing schema migrations on the receiving end so that the data is compatible is a pain, so that's why it's better to use an EntityAsk, and let the PlayerActor handle the schema migration when it wakes up. Additionally, instead of fetching the whole player model, it might be a good idea to make some
PlayerProfileData
class that holds just the relevant info that you need for displaying the profile to others. That way you can avoid sending a lot of extra fluff
a
yep i'll only include the necessary data. if a request-response action pair is the right way, then my response action will be the data for the profile view
i was just checking the ask handler in PlayerActorBase and it seems i can reuse that fine and do the same Ask that the dashboard thing does, just don't need much of the other things there, i mean how it checks the metadata etc. [EntityAskHandler] InternalEntityStateResponse HandlePlayerStateRequest(InternalEntityStateRequest _)
so it's all clear now, thanks a lot again! ☺️
n
No worries! One optimization you can do later, but is probably not necessary right now, is to reduce the internal server traffic by creating the profile packet on the player being inspected and only sending that data to the other actor instead of using the InternalEntityStateResponse, which includes the whole Model. But it might not even be an issue if you don't expect the profile data to be sent over very often.
a
yep good point. it's not an urgent worry but a good optimization when there (hopefully) are lots of users. and also with more usage the player models may grow quite a lot, now they are small i'll make an issue about this for later, thanks! btw i did end up making a class, like you said, ended up calling it
PublicPlayerProfile
.. to keep the action and the client listener signatures simple
2 Views