MrStahlfelge / gdx-gamesvcs

Easy integration of gameservices in your libGDX game: Google Play Games, Apple Game Center, Amazon GameCircle and more
Apache License 2.0
113 stars 20 forks source link

Getting a unique User ID #43

Open Trurl101 opened 3 years ago

Trurl101 commented 3 years ago

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 commented 3 years ago

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 commented 2 years ago

@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.