question

Mohamed AbdAllah avatar image
Mohamed AbdAllah asked

How to save player messages (mail system)?

Hi everyone,

I am trying to create an in game mail system using PlayFab. But this has a twist; the receiver of the mail is random (you can't choose who) and multiple people may receive the same mail.

So far I have been successful in getting a list of players (using Leaderboards) and selecting a random player from that list. Easy stuff.

However, one of my issues is how to store said message for each of the selected users. So far I have resorted to using user data and save a "key:value". But that doesn't really work. Since the key would need to be unique and the player pulling the data (to get their messages) needs to know that unique key. So doesn't really work. Moreover, I saw in another post that the user data is limited to 100 keys.

The second issue is storing the sender's PlayFabID so that the mail receiver would be able to reply back. I don't exactly need to show the receiver who the sender was, but this is just to deliver the reply to the correct person.

Another idea I thought of is Player Inventory; basically treat each mail as an "item" of type "Mail" and the item description acts as the contents of the message.

Any ideas on how I can approach this?

Player DatadataContent
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

First, please allow me to paraphrase your question based on my understanding: you want to store said messages for the receiver so that they are able to reply back however you also don’t want the receiver know who the sender is, by not exposing PlayFabId to the receivers, is that correct?

7 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Mohamed AbdAllah avatar image Mohamed AbdAllah commented ·

That is correct.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Mohamed AbdAllah commented ·

In that case, you can consider using Internal Player Data (can only accessed by server side) to store the messages. And, instead of using multiple key/value pairs to store the data, you can use a single key/value pair, the key being "PlayerMessages" and the value is a JSON that store all the messages from other players. So now, since we're using Internal Player Data, therefore the client side cannot directly access it, we can use CloudScript to access such data, strip out the PlayFabId, and return it back to the client side. In cases where players need to reply back the message, you can apply a unique message id for each message so that CloudScript can use it to find out who (PlayFabId) sent the message.

0 Likes 0 ·
Mohamed AbdAllah avatar image Mohamed AbdAllah Citrus Yan commented ·

So what you're saying is that store all messages a single user receives into a single key called PlayerMessage?

If I am not mistaken, I read somewhere that PlayFab has a limit on this. 10 keys (which not a problem in this solution since we are just using one) but the value can't exceed 30,000 or such (can't recall) but I am not sure what the 30,000 entails. Is that size? Characters? What exactly.

0 Likes 0 ·
Show more comments
Mohamed AbdAllah avatar image Mohamed AbdAllah commented ·

@citrus Yan,

Can't reply to your last reply. No such button, seems there is a limit to number of replies.

Wouldn't I hit that limit (300kb) after say a few hundred mails going back and forth? Since I am modifying the same value and adding to it, with time the size will increase and reach that. Unless I am over estimating this. Any comments on that?

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Mohamed AbdAllah commented ·

Yes, if the overall size is too big it will hit the limit (300kb). And, the fact is that we don't have a built-in feature that is 100% suited to your scenario therefore the approach I mentioned above is more like a workaround. I think the best solution for your scenario would be hosting an external database that stores all the messages between players, and use the server-side logic to do send/reply operations for the players without they knowing who the sender/receiver is.

0 Likes 0 ·
Mohamed AbdAllah avatar image Mohamed AbdAllah Citrus Yan commented ·

I see. Thank you very much for elaborating :)

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.