question

vasan_routh avatar image
vasan_routh asked

How to sent match results to a disconnected player?

Hello,

The game that I am currently working on has rewards for a win in a match, this happens at the end of every match. If one of the players disconnects at the match end, how can I tell him the last match results when he opens the game again? I tried changing the disconnected player's Player Data from the active player in the game, that is when I realized that I have to enable Admin API to change other player's Player Data. But I know that's not safe, so is there any other easier way to make the active player convey the result to the inactive player?

I saw a General Discussion about the same topic from 2016:

https://community.playfab.com/questions/612/208150798-Save-data-to-other-Player-and-shared-data.html

and it mentioned that more asynchronous game-specific functionality later this year, which will help to simplify these scenarios, is there any easy way now at 2021?

apisdata
4 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.

Sarah Zhang avatar image Sarah Zhang commented ·

Could you please provide more detailed information for our analysis? For example, which matchmaking system are you use now, is it a synchronous matchmaking system? Whether you use an external matchmaking system or the PlayFab multiplayer MatchMaking system? It there any server-side logic in your game? If so, do you host a custom server, or do you use the CloudScript to host some server-side logic? Which types of the player data you want to transfer, do you mean you want to transfer the player read-only data or the player internal data?

0 Likes 0 ·
vasan_routh avatar image vasan_routh Sarah Zhang commented ·

I use Photon Pun for matchmaking, it's a chess game(1v1) and it uses Photon RPC to sent chess moves to another player.

If a player exits the game before the match ends he doesn't know the last match's results, because of this I can't reduce or add trophies if that client opens the game again.

There is no server-side logic. The current game state and the match end results("win" or "lose") must be shared between both players. (Data sharing must occur even if both players are online because I can't find who is offline!)

So another active client in the game must either share or set that match result data to the disconnected client. So what can I use Player Data or Data Shared Groups? Or is there any other way I can do this?

If I can use Player Data then Player1's player read-only data or the player internal data can be changed by Player2?

And photon doesn't offer any API to sent data to a player who already exited the room.

0 Likes 0 ·
vasan_routh avatar image vasan_routh Sarah Zhang commented ·

Read some similar general discussions, seems like Shared data groups do the job! But I can't understand how it works :( I read the documentation, still, I don't have any idea how to implement it here.

Is there any tutorial on this, because I haven't found one.

Tell me how to do the below part in cloud script as a code snippet if possible, I can get a good grasp of the process and I can develop that to my need.

  • how to create shared group data on player first login,
  • After joining a 1v1 match with another player, how to sent data(like "Hello") to other player's shared data group,
  • How to get the received Shared Data Group data to my game.

I'm totally new to the Shared Data Group, please help me get this part done :)

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang vasan_routh commented ·
0 Likes 0 ·

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

>> how to create shared group data on player first login.

We would suggest you create the shared group data when the match starts. You can use CloudScript to create the shared group data. In this case, you can refer to the PlayFab document -- Photon quickstart - PlayFab | Microsoft Docs and Photon document -- PlayFab Integration | Photon Engine to integrate the Photon with PlayFab so that you can use Photon webhook the to trigger the CloudScript function. You can use the RoomCreated handler to trigger the shared group data creation. The main code snippet could be something like this.

/// Triggered automatically when a Photon room is first created
handlers.RoomCreated = function (args) {
    var createSharedGroupRequest = {
        "SharedGroupId": args.GameId
    };
    var createSharedGroupResult = server.CreateSharedGroup(createSharedGroupRequest);
    log.info(createSharedGroupResult);
    if (createSharedGroupResult != null) {
        createSharedGroupRequest.SharedGroupId
        var addMemberRequest = {
            "SharedGroupId": args.GameId,
            "PlayFabIds": [
                args.UserId
            ]
        };
        var addMemberResult = server.AddSharedGroupMembers(addMemberRequest);
        if (addMemberResult != null) {
            return "Success";
        }
    }
    else { return "Fail" }
};

>> After joining a 1v1 match with another player, how to sent data(like "Hello") to other player's shared data group,

The Shared Group Data is not designed for separate player. If you want a player have a K/V pair that can be read by others, you can store a K/V pair in the Read-Only Data and set its permission to Public.

The Shared Group Data is designed to share the data among the players in one shared group. In this case, you should create the Shared Group Data for one match not for every player. After you create a Shared Group Data and add two players in this shared group, the players can call the API GetSharedGroupData to get the data stored in the shared group.

>> How to get the received Shared Data Group data to my game.

If you want to host the game server-side logic to CloudScript and implement the turn-based chess game using Shared Data Group, please check this tutorial -- Using Shared Group Data - PlayFab | Microsoft Docs, and this discussion -- Persistent turn based games? - Playfab Community.

10 |1200

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

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.