Search Unity

Question Client-Server link, understanding authentication

Discussion in 'Authentication' started by Corva-Nocta, Nov 13, 2022.

  1. Corva-Nocta

    Corva-Nocta

    Joined:
    Feb 7, 2013
    Posts:
    801
    Hey all! Still working to wrap my head completely around the new system, gotten a lot of help and hoping for just a tiny bit more! This one is more of a concept question, and I honestly might just be looking in the wrong place for the answer, so any help here would be great!

    OK so I've got my server and I've got my clients, let's say John, Jason, and Jessie. Clients all log in anonymously (for now!) Which creates a player on the server for each of them. So far so good! Now I want to be able to save inventory items on the cloud save, which I can do but from code that is on the client side, and I would like it to be on the server side. And this is where I'm trying to understand better.

    If a player, let's say John, logins in from the client, is the authentication info sent to the server player object as well? That way I know I am sending items to the right player and not sending John's items to Jessie.

    Like if John's account info on the Economy service is: XQJ2; when John logs in with the account XQJ2 is that sent to the server? If I want the server to be the one adding items to the Economy back end, how do I link John's XQJ2 account name to his server player? Does this happen automatically and I just can't find it, or do I need to send this information somehow? Is there a place in the docs I should be looking?

    Thanks for any of the help!
     
  2. Laurie-Unity

    Laurie-Unity

    Unity Technologies

    Joined:
    Mar 5, 2020
    Posts:
    220
    Hey @Corva-Nocta

    When a player signs in with the Authentication service they are issued a
    PlayerId
    that is used across all the Unity Gaming Services.

    You can retrieve the
    PlayerId
    in your client code from
    AuthenticationService.Instance.PlayerId


    You can paste the
    PlayerId
    in to the Dashboard > Live Ops > Player Management tool to check their saved Currency, Inventory and Cloud Save data

    upload_2022-11-14_12-45-10.png

    You can also use the PlayerId in Cloud Code scripts and many of the UGS Service APIs to work with a specific player's data.
     
  3. Corva-Nocta

    Corva-Nocta

    Joined:
    Feb 7, 2013
    Posts:
    801
    Does that PlayerId number get sent to the server as well or do I need to do that manually?

    For instance if I log in and check on the client side that my PlayerId is JXQ2, does that mean my player on the server will also have the same PlayerId? Or do I need to send that information over to the server and manually set the player on the server to have that PlayerId?
     
  4. Laurie-Unity

    Laurie-Unity

    Unity Technologies

    Joined:
    Mar 5, 2020
    Posts:
    220
    It depends on the use case.

    When you refer to 'the server', if you are refering to the Unity Gaming Services backend, then NO, you don't explicitly need to send the
    PlayerId
    . When you call any Cloud Save or Economy methods in your game client code, the
    PlayerId
    will be communicated to the UGS Backend by the client side Cloud Save or Economy SDK.

    If however, you are building your own sever backend and using our Service API to communicate with the UGS Backend, then YES you will need to make sure you use the
    PlayerId 
    assigned to the client. So, in that case you would need to send the
    PlayerId 
    to your server.
     
  5. Corva-Nocta

    Corva-Nocta

    Joined:
    Feb 7, 2013
    Posts:
    801
    Gotcha! I'm still working on using proper terminology, but I believe you answered what I was asking. I've got a build of the game that can be set as server or client, which is what I'll need to synch the playerId up with. Sounds like I'll need to manually send that info from client to server after logging in.

    oh small question: If I cam going to send that PlayerId, is it just a string or is it something else?

    Thanks for the answers!
     
  6. kChamp

    kChamp

    Joined:
    Dec 21, 2013
    Posts:
    14
    Is there currently a way for the game server to verify that the client is sending the valid authenticated PlayerId and not pretending to be another player?