Online multiplayer game using Google Play Games Services in Cocos2D-X

You can use debug.keystore since all android debug key are the same. You can’t use release.keystore since you don’t have our release.keystore and your key own won’t work.

oauthclient id are required for iOS, please refer to documentation

I’ve update SDKbox to v1.0.0.20 and gpg to v2.3.4.2 and googleplayservices to v2.3.4.2 for my Android (on Win7 console build) project based on samples\sdkbox-sample-gpg. Also I’ve merged Cocos official 3.13.1 release with last (updated) files from github.

I did: creating my own app and adding GP services to it (and adding my account=gmail in both app alpha-testers list and service testers list and activated it). At last the connection starts: but not at app start but at Sign In press: appears two pop-ups: my App name and connecting to then Google Play Games and then cursor twists without stop…

The error I dig in log is: I GamesNativeSDK: UI interaction required to connect to Google Play.: org.cocos2dx.Addition - it’s my TBM project based on samples\sdkbox-sample-gpg.

I wanted to get what happend in old good SDKBOX gpg from GP, but its app crashes.

This error is because you haven’t link your debug key with gpg http://stackoverflow.com/questions/17612928/should-i-use-debug-keystore-with-google-play-game-services-during-development

Thanks, but…
For my released for Google Play project org.cocos2dx.Addition (alpha testing) I’ve created two Client-ID and updated SHA-1 for them: from debug and release keystores.
But when I start apk debug version or installed from Google Play (after it really updated) release version - it shows the same error in log, and can’t pass Google Play Games pop-up. Log:

11-01 04:14:26.680 20083 20108 D NativeCrypto: ssl=0x62ef0c60 SSL_connect:error exit in UNKWN SSLv3 read server session ticket A: org.cocos2dx.Addition
…then it passes:
11-01 04:14:26.662 20083 20108 D NativeCrypto: ssl=0x62ef0c60 SSL_connect:3RSC_A SSLv3 read server certificate A: org.cocos2dx.Addition

11-01 04:14:26.664 20083 20118 D NativeCrypto: ssl=0x62ef0a70 SSL_connect:3WCKEA SSLv3 write client key exchange A: org.cocos2dx.Addition

11-01 04:14:26.680 20083 20108 D NativeCrypto: ssl=0x62ef0c60 SSL_connect:error exit in UNKWN SSLv3 read server session ticket A: org.cocos2dx.Addition 11-01 04:14:26.680 20083 20108 D NativeCrypto: ssl=0x62ef0c60 info_callback ignored: org.cocos2dx.Addition 11-01 04:14:26.680 20083 20108 D NativeCrypto: doing handshake -- ret=-1: org.cocos2dx.Addition 11-01 04:14:26.680 20083 20108 D NativeCrypto: ssl=0x62ef0c60 NativeCrypto_SSL_do_handshake ret=-1 errno=11 sslError=2 timeout_millis=0: org.cocos2dx.Addition

11-01 04:14:26.879 20083 20108 D NativeCrypto: ssl=0x62ef0c60 SSL_connect:ok exit in SSLOK SSL negotiation finished successfully: org.cocos2dx.Addition

11-01 04:14:26.967 2887 11228 W GLSActivity: [ClientIdentityHelper] Fraud! Package org.cocos2dx.Addition isn't associated with uid 10882!: com.google.process.gapps 11-01 04:14:26.967 2887 11228 W GLSActivity: drg: Fraud! Package org.cocos2dx.Addition isn't associated with uid 10882!: com.google.process.gapps

11-01 04:14:27.007 3183 3226 E SignInAsyncService: Fraud! Package org.cocos2dx.Addition isn't associated with uid 10882!: com.google.android.gms 11-01 04:14:27.007 3183 3226 E SignInAsyncService: java.lang.SecurityException: Fraud! Package org.cocos2dx.Addition isn't associated with uid 10882!: com.google.android.gms

Any ideas what should I concentrate on?

Never saw this error before, I guess you do the following

  1. make sure your user account is opt-in with alpha testing
  2. search your project and find out where is uid “10882” came from.

Same apk installed and start on another device - have connected to GP (with another account, added as alpha-tester).
But on new device successful connection to GP happend only once - at very first start. On green arrow or Sign In press - Login Failed. Log may be later; very later.
Program data (and cash) clean haven’t help.
Upd: oops, I use old sdkbox_config.json - from the sample; may be that’s a reason.

I worked on multiplayer game using cocos2dx but with our own server written in ROR, you dont need to worry about sdk box, its very easy to use and integrate i used social feature of sdkbox facebook in my game to login logout friend list invite sent and a lot more.It work perfect for me.You should try at least one time might be you learn new things :slight_smile:

At last I’ve connected! :slight_smile:
May be the problem was, what I have not been enabled (any?) API in https://console.developers.google.com/apis/dashboard?project=MyProject

I’ve get it from log, Google+Android nicely pointed me on that:

11-01 23:00:40.146 1672 6754 E ClientConnectionOperation: jpt: Authorization failed: server returned error: Access Not Configured. Drive API has not been used in project 010101010101 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/drive/overview?project=010101010101 then retry.

Q1: Have I missed (to enable) anything else?
Q2: Where can I read about proper mapping of sdkbox_config.json and my (turn-based multiplayer) game?

No sdkbox_config.json option for google play games, since you can control all of them from google play console.

1 Like

I was having similar issues with this, also getting a Not authourizing. No Client and result -3 error. Adding the support-v4 jar to the project fixed it. To add the support jar in eclipse:

  • RIght click the project ex. MyApp.
  • MyApp -> Android Tools -> Add Support Library

Also make sure that if you have linked the project in Google Play Services console that it is the debug version. I was having an issue when I uploaded a Debug version of the APK to GPS and was then building the project using cocos run -p android -m release.

I am successfully integrated GPGS via sdkbox, but i am having one issue in realtime multiplayer game that i my there is two classes inherit by layer and IRealTimeEventListener, in first class i am creating room and match making , player found their match then it goes to second class, in this class both player are communicating via reliable message but the callbacks of IRealTimeEventListener is not invoking of second class second class is also inherit IRealTimeEventListener. Please help me how i can do that.
Thanks

Anyone know why I can receive real time events using the iPhone emulator but when built and run on an Android device the events are ignored.

For example:

OnRoomStatusChanged() works on iPhone emulator but not on Android device.

Any ideas?

Did you setup android app on your google play console?

Yes the application is working fine, rooms being created, peers connected and capable of sending data to each other, the only problem is that the events like OnRoomStatusChanged() are not being called while OnDataReceived() is. No problems on iPhone emulator.

OnP2PDisconnected() is also not being called when the application is run on Android devices. Everything works perfectly on the iPhone emulator.

How did you fixed your error of “Sign in finished with a result of -3”?

After 6 months I was back to my project, but…
When installing then starting 6 months old apk - I still could connect to GooglePlay.
But compiling the same apk I get E TokenRequestor: You have wrong OAuth2 related configurations.

Then I’ve found my debug.keystore file was changed/updated; seems it been auto-updated every 365 days.
(after adding new/updated SHA-1 signing-certificate fingerprint in OAuth 2.0 client IDs I can connect again :slight_smile: )

I would say to have a single realtime event listener class that will pass the data in the callbacks to the appropriate controller classes using events or directly, instead of having two separate real time event listeners. My solution uses a NetworkController class to send and receive any data over the wire and it acts as a service layer to my game engine.

Here is the .h file for my NetworkController, hope it helps.

class NetworkController : public GameServiceInterface, public gpg::IRealTimeEventListener {
public:
  NetworkController();
protected:
  virtual bool IsAuthorized() override;
  virtual void ListGameSaves() override;
  virtual void DeleteGameSave() override;
  virtual void LoadGame(const std::string &filename, gpg::SnapshotConflictPolicy conflict_policy) override;
  virtual void SaveGame(const std::string& filename, const std::string& description, const std::string& content, gpg::SnapshotConflictPolicy conflict_policy) override;
  virtual std::string NetworkUsername() override;
  virtual void SendMessageToParticipants(std::string &message) override;
  virtual void SendMessageToParticipant(std::string &message, gpg::MultiplayerParticipant participant) override;
  virtual gpg::RealTimeRoom *Gameroom() override;
  virtual void CreateRealtimeGameroom(const int minimumPlayersToStart, const int maxParticipants) override;
  virtual void LeaveRealtimeGameroom() override;
  virtual void PlayerStats() override;
  virtual bool IsSignedIn() override;
  virtual bool IsGameRoomValid() override;
  virtual std::vector<gpg::MultiplayerParticipant> GameRoomParticipants() override;
  virtual void OnNotify(GameEvent *event) override;
  virtual std::string GetHostUsername() override;
  virtual bool IsHost() override;
  virtual gpg::MultiplayerParticipant HostParticipant() override;
  virtual void ShowLeaderboard(const std::string &leaderboardId) override;
  virtual void ShowAchievements() override;

private:
  void InitGpg();
  void OnConnect();
  void SetRoom(gpg::RealTimeRoom const &room);
  void ProcessIncomingData();
  void PickHost();
  void SetHost(const std::string &hostUsername);
  std::string FindParticipantWithHighestId();

  //IRealTimeEventListener
  void OnRoomStatusChanged(gpg::RealTimeRoom const &room) override;
  void OnConnectedSetChanged(gpg::RealTimeRoom const &room) override;
  void OnP2PConnected(gpg::RealTimeRoom const &room, gpg::MultiplayerParticipant const &participant) override;
  void OnP2PDisconnected(gpg::RealTimeRoom const &room, gpg::MultiplayerParticipant const &participant) override;
  void OnParticipantStatusChanged(gpg::RealTimeRoom const &room, gpg::MultiplayerParticipant const &participant) override;
  void OnDataReceived(gpg::RealTimeRoom const &room, gpg::MultiplayerParticipant const &from_participant, std::vector<uint8_t> data, bool is_reliable)
      override;

  gpg::GameServices *gameServices;
  gpg::RealTimeRoom realTimeRoom;
  int maxParticipantsInGameroom;
  rapidjson::Document gameConfigurationJsonObject;
  std::string hostUsername;
  bool isHost;
  gpg::MultiplayerParticipant hostParticipant;
};
#endif

Thanks damort