Save player data before OnPhotonPlayerDisconnected

Options
Hi

I need to save the player data on the server.
The client normally send requests to the server to save its data from time to time or when a regular exit of the game happens the client sends the request the server saves that data then the client quits and is destroyed.
Problem is when the compute crashes, internet goes down or something like that the player latest data is not saved on the server.
I am using OnPhotonPlayerDisconnected but when I get that call in the player is destroyed and I have no way to save that data.
Is there any other way to save that data before the player is destroyed?
Is there any way to get a OnPhotonPlayerDisconnected but not to destroy the object that still on the server?

Thanks for any help

Comments

  • vadim
    Options
    Hi,

    Where do you handle OnPhotonPlayerDisconnected? On disconnected client, on other clients or on master client?
    Server is separated persistent service? Who saves the data? Each clients saves its own data? If so I can't imagine how it can save something after crash or internet failure. Data shared between clients can be saved in OnPhotonPlayerDisconnected of other client (master?) which is still online.
  • Hi Vadim

    Thanks for the answer.
    I handle OnPhotonPlayerDisconnected on the server.
    Server is a persistent service.
    Server saves all data.
    When I client click exit to close the program (regular way) the client sends a RPC to the server, the server saves the client data and send back a RPC to the client that it is free to disconnect.
    Please, let me know if you need more information.

    Thanks

    Carlos



    Where do you handle OnPhotonPlayerDisconnected? On disconnected client, on other clients or on master client?
    Server is separated persistent service? Who saves the data? Each clients saves its own data? If so I can't imagine how it can save something after crash or internet failure. Data shared between clients can be saved in OnPhotonPlayerDisconnected of other client (master?) which is still online.
  • vadim
    Options
    I handle OnPhotonPlayerDisconnected on the server.
    What is that server? How does PUN client communicate with that server?
    When I client click exit to close the program (regular way) the client sends a RPC to the server
    RPC in PUN terms is operation sent from one client to others. OnPhotonPlayerDisconnected is handler also used in PUN client. So i'm little bit confused when you use these concepts in server context. Especially considering that the topic is in PUN forum.
  • Hi Vadim

    OK, let me make easier.

    I get a callback on OnPhotonPlayerDisconnected when a player gets disconnected, at the same time that happens that player is destroyed on my side and I cannot access it anymore.

    I do have access to that player data all the time and can save that data but not when the player loses internet connection or crashes.

    Is the a way using OnPhotonPlayerDisconnected to save that data before the object get destroyed on my side?
    Is there any other way to o it?

    Thanks

    Carlos
  • Tobias
    Options
    OnPhotonPlayerDisconnected is a callback that is only used in the PUN clients. When you say you use that in the "server", we get confused.

    PUN removes the player from the player-list and cleans up objects owned by that user before it does the callback.
    The callback itself gets a reference to the PhotonPlayer instance, so you should be able to access this player's name and custom properties still. You have to implement it as: public void OnPhotonPlayerDisconnected(PhotonPlayer otherPlayer) and use otherPlayer.

    This seems to work OK for most games. I am not sure if we should change the order in which we do things. Maybe you convince me?

    In worst case, you can find where the callback is done and modify the PUN code for your needs.
    Obviously you would need to apply this change after each update of PUN you do.
  • Hi Tobias

    Thanks.
    I did find the RemovePlayer(actorID, player) inside handleEventLeave just before the SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerDisconnected, player), I can add code on it to save the data right there.

    Would be nice to give the opportunity for that user to be able to have access to that data before is destroyed.
    Maybe you guys should have a message OnPhotonPlayerIsDisconnecting(player) before the OnPhotonPlayerDisconnected(player) then on OnPhotonPlayerIsDisconnecting we still be able to access that data.

    On what you wrote "When you say you use that in the "server", we get confused." I am confuse.
    Maybe I am doing something complete wrong.
    I am trying to create a server where all information of the game and players is saved, the clients will have the actual players.
    I am doing something wrong? Any reference I can read to understand that better on PUN?

    Thanks for the help.

    Carlos
  • Tobias
    Options
    Which data do you need to access in a player who leaves? I think you should get all player-related values from the PhotonPlayer instance and that is handed to you in OnPhotonPlayerDisconnected.
    What are you missing in your case?

    Unlike Unity's built-in networking, none of the clients in a room is the actual host. The Master Client is what comes closest to this: It's the player who is in the room for the longest time but it might switch (when that client leaves).
    It's simply uncommon to consider one of the PUN clients as server.

    If you want to create a game that can be continued later on, maybe Photon Turnbased is more suitable for you. In it, the server will take care of saving cached events and custom properties for all players and the room. Games can be continued at any time by any player that didn't abandon the room.

    What type of game do you do?