Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting a unique User ID #43

Open
Trurl101 opened this issue Mar 2, 2021 · 2 comments
Open

Getting a unique User ID #43

Trurl101 opened this issue Mar 2, 2021 · 2 comments

Comments

@Trurl101
Copy link

Trurl101 commented Mar 2, 2021

It seems not possible to identify an user with his login, for example to store game data in an external database?

There is the function "getPlayerDisplayName()" but the display name is not unique.

A function like "getPlayerID()" would be useful and should be easily to implement, for example for google:
String getPlayerID() { return Games.Players.getCurrentPlayerId(mGoogleApiClient); }

for Apple Gamecenter:
public String getPlayerID() { return isSessionActive() ? GKLocalPlayer.getLocalPlayer().gamePlayerID() : null; }

@MrStahlfelge
Copy link
Owner

I didn't have the need for this and the usefulness in practice is a bit limited because not all users on a platform will use a game service. So you'll need a fallback mechanism anyway, and if you have it, you can use that one in any case.

But if it is important for you, I am open and accepting PRs.

@theshoeshiner
Copy link

theshoeshiner commented Dec 22, 2021

@Trurl101

Edit: I missed the part of your comment where you already solved your issue :). Carry on 👍

One quick way around this is to extend the GpgsClient and directly access the Google Api Client:

public class CustomGpgsClient extends GpgsClient {
    public GoogleApiClient getGoogleApiClient() {
        return mGoogleApiClient;
    }
}

Then elsewhere in your code (Mine below is in the listener) you can access the Player object manually via the google api client:

@Override
public void gsOnSessionActive() {

  LOGGER.info("Player: {}",gamesClient.getPlayerDisplayName());
  LOGGER.info("serviceid: {}",gamesClient.getGameServiceId());
  
//get google player object
 Player gpgPlayer = Games.Players.getCurrentPlayer(gamesClient.getGoogleApiClient());
  
//access google specific props
  LOGGER.info("details: {}",gpgPlayer.getPlayerId());
  LOGGER.info("details: {}",gpgPlayer.getName());
  LOGGER.info("details: {}",gpgPlayer.getBannerImageLandscapeUri());
  LOGGER.info("details: {}",gpgPlayer.getBannerImagePortraitUri());
  LOGGER.info("details: {}",gpgPlayer.getIconImageUri());
}

Obviously this is specific to the google api, so you'll have to handle skipping it if youre using multiple, or coming up with your own interface for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants