Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Server authorative persistent data storage

Discussion in 'Game Server Hosting' started by jackward84, Jun 21, 2023.

  1. jackward84

    jackward84

    Joined:
    Jan 26, 2017
    Posts:
    87
    If I want server authorative persistent data storage that clients cannot edit, do unity multiplayer services have any built in solution for that or do I need to use a 3rd party/roll my own?

    My first thought was to fire a state change to cloud code and save the data using Cloud Saves. But I am pretty sure players can execute Cloud Code and Cloud Saves, so I would need to work out some kind of authentication system where only the server can execute that code. Not to mention Cloud Saves can be edited by players (I think) and the pay size of a cloud size is fairly low if you wanted to store a lot of data in a single document (ie: a server-only document).

    Basically what I want:

    Example: A player kills someone, I want to store somewhere that their kills are +1, and that they have killed playerId xyz123, so that I can use it to populate statistics on a tooltip. I want that data to be persistent forever and viewable while connected to any UGS game server. For example if the player then hovered over xyz123, they get a tooltip showing how many times they've killed that player and how many times the player has killed them.
     
    Last edited: Jun 21, 2023
  2. BGagnon_Unity

    BGagnon_Unity

    Unity Technologies

    Joined:
    Mar 9, 2022
    Posts:
    5
    jackward84 likes this.
  3. jackward84

    jackward84

    Joined:
    Jan 26, 2017
    Posts:
    87
    Thank you, that is perfect! Follow on question from that, does the Unity Cloud Save module support the server saving to player cloud saves? How is the server supposed to write to the individual player's Cloud Save? I cannot find any documentation on Cloud Save that talks about the perspective of a non-player writing to the save or reading it.

    Simply I am looking for something that would take the playerId, read the cloud save data on login, and write cloud save data as events occur (from server side).
     
    Last edited: Jun 21, 2023
  4. jackward84

    jackward84

    Joined:
    Jan 26, 2017
    Posts:
    87
    At this point, I have managed to do the above using a service account, but I am directly interacting with APIs rather than using any of the official packages in Unity. If there is an official solution I would much prefer to use that.

    It also doesn't feel right that I am injecting my service account authorization into my server using a config variable, there must be a better way?
     
  5. BGagnon_Unity

    BGagnon_Unity

    Unity Technologies

    Joined:
    Mar 9, 2022
    Posts:
    5
    Unity Game Servers have a built-in identity that can be used to make calls to UGS services that support it, such as Cloud Save. In practice, this means obtaining a token from the localhost agent (called the payload proxy) and using that in the Authorization: Bearer <token> header. WIth this method, no additional secrets or credentials need to be deployed to the game server.

    This is implemented in the com.unity.services.authentication package under the Unity.Services.Authentication.Server namespace.The method is called SignInFromServerAsync.

    I'm not sure this is fully integrated with the Cloud Save SDK at the moment, however. I will check with the team -- hope this helps in the meantime!
     
  6. jackward84

    jackward84

    Joined:
    Jan 26, 2017
    Posts:
    87
    Thank you, that makes it too easy! I am really looking forward to finding out if this is supported by the unity Cloud Save package, for the moment I am making Cloud Code functions to get and set the player saves by passing through the player's access token (which also requires that I request an access token for each player using the service account).

    It would definitely be a lot more simple if I could just call something like
    CloudSave.SaveDataForPlayer(string playerId, object data);
     
  7. jackward84

    jackward84

    Joined:
    Jan 26, 2017
    Posts:
    87
    I hate to be a pain, but I have the Unity.Services.Authentication package installed and the namespace:
    Unity.Services.Authentication.Server
    does not exist. Am I looking in the wrong place? I have 2.4.0 installed.