private void OnStateConflict(int stateKey, string resolvedVersion, byte[] localData, byte[] serverData) { GooglePlayGames.OurUtils.Logger.d("OnStateResultProxy.onStateConflict called, stateKey=" + stateKey + ", resolvedVersion=" + resolvedVersion); debugLogData("localData", localData); debugLogData("serverData", serverData); if (mListener != null) { GooglePlayGames.OurUtils.Logger.d("OnStateResultProxy.onStateConflict invoking conflict callback."); PlayGamesHelperObject.RunOnGameThread(() => { byte[] resolvedData = mListener.OnStateConflict(stateKey, localData, serverData); ResolveState(stateKey, resolvedVersion, resolvedData, mListener); }); } else { GooglePlayGames.OurUtils.Logger.w("No conflict callback specified! Cannot resolve cloud save conflict."); } }
private void OnInvitationReceived(AndroidJavaObject invitationObj) { Logger.d("AndroidClient.OnInvitationReceived. Converting invitation..."); Invitation inv = ConvertInvitation(invitationObj); Logger.d("Invitation: " + inv.ToString()); if (mInvitationDelegate != null) { Logger.d("Delivering invitation to invitation received delegate."); PlayGamesHelperObject.RunOnGameThread(() => { if (mInvitationDelegate != null) { mInvitationDelegate.Invoke(inv, false); } }); } else { Logger.w("AndroidClient.OnInvitationReceived discarding invitation because " + " delegate is null."); } }
private void OnInvitationInboxResult(bool success, string invitationId, Action <bool, TurnBasedMatch> callback) { Logger.d("AndroidTbmpClient.OnInvitationInboxResult, success=" + success + ", " + "invitationId=" + invitationId); if (!success) { Logger.w("Tbmp invitation inbox returned failure result."); if (callback != null) { Logger.d("Reporting tbmp invitation inbox failure to callback."); PlayGamesHelperObject.RunOnGameThread(() => { callback.Invoke(false, null); }); } return; } Logger.d("Accepting invite received from inbox: " + invitationId); TbmpApiCall("accept invite returned from inbox", "acceptInvitation", null, callback, invitationId); }
/// <summary> /// Asynchronously retrieves the server auth code for this client. /// </summary> /// <remarks>Note: This function is currently only implemented for Android.</remarks> /// <param name="serverClientId">The Client ID.</param> /// <param name="callback">Callback for response.</param> public void GetServerAuthCode(string serverClientId, Action <CommonStatusCodes, string> callback) { mServices.FetchServerAuthCode(serverClientId, (serverAuthCodeResponse) => { // Translate native errors into CommonStatusCodes. CommonStatusCodes responseCode = ConversionUtils.ConvertResponseStatusToCommonStatus(serverAuthCodeResponse.Status()); // Log errors. if (responseCode != CommonStatusCodes.Success && responseCode != CommonStatusCodes.SuccessCached) { OurUtils.Logger.e("Error loading server auth code: " + serverAuthCodeResponse.Status().ToString()); } // Fill in the code & call the callback. if (callback != null) { // copy the auth code into managed memory before posting // the callback. string authCode = serverAuthCodeResponse.Code(); PlayGamesHelperObject.RunOnGameThread(() => callback(responseCode, authCode)); } }); }
public void LoadFriends(Action <bool> callback) { if (!IsAuthenticated()) { GooglePlayGames.OurUtils.Logger.d("Cannot loadFriends when not authenticated"); PlayGamesHelperObject.RunOnGameThread(() => callback(false)); return; } // avoid calling excessively if (mFriends != null) { PlayGamesHelperObject.RunOnGameThread(() => callback(true)); return; } mServices.PlayerManager().FetchFriends((status, players) => { if (status == ResponseStatus.Success || status == ResponseStatus.SuccessWithStale) { mFriends = players; PlayGamesHelperObject.RunOnGameThread(() => callback(true)); } else { mFriends = new List <Player>(); GooglePlayGames.OurUtils.Logger.e( "Got " + status + " loading friends"); PlayGamesHelperObject.RunOnGameThread(() => callback(false)); } }); }
public PlatformConfiguration CreatePlatformConfiguration(PlayGamesClientConfiguration clientConfig) { var config = AndroidPlatformConfiguration.Create(); using (var activity = AndroidTokenClient.GetActivity()) { config.SetActivity(activity.GetRawObject()); config.SetOptionalIntentHandlerForUI((intent) => { // Capture a global reference to the intent we are to show. This is required // since we are launching the intent from the game thread, and this callback // will return before this happens. If we do not hold onto a durable reference, // the code calling us will clean up the intent before we have a chance to display // it. IntPtr intentRef = AndroidJNI.NewGlobalRef(intent); PlayGamesHelperObject.RunOnGameThread(() => { try { LaunchBridgeIntent(intentRef); } finally { // Now that we've launched the intent, release the global reference. AndroidJNI.DeleteGlobalRef(intentRef); } }); }); if (clientConfig.IsHidingPopups) { config.SetOptionalViewForPopups(AndroidTokenClient.CreateInvisibleView().GetRawObject()); } } return(config); }
/// <summary> /// Fetches the user specific information. /// </summary> /// <remarks>Fetches the email or tokens as needed. This is one /// method in the Java support library to make the JNI more simple. /// </remarks> /// <param name="scope">Scope for the id token.</param> /// <param name="fetchEmail">If set to <c>true</c> fetch email.</param> /// <param name="fetchAccessToken">If set to <c>true</c> fetch access token.</param> /// <param name="fetchIdToken">If set to <c>true</c> fetch identifier token.</param> /// <param name="doneCallback">Invoked when the call is complete /// passing back the status code of the request.</param> internal void Fetch(string scope, bool fetchEmail, bool fetchAccessToken, bool fetchIdToken, Action <CommonStatusCodes> doneCallback) { if (apiAccessDenied) { //don't spam the log, only do this every so often if (apiWarningCount++ % apiWarningFreq == 0) { GooglePlayGames.OurUtils.Logger.w("Access to API denied"); // avoid int overflow apiWarningCount = (apiWarningCount / apiWarningFreq) + 1; } doneCallback(CommonStatusCodes.AuthApiAccessForbidden); return; } // Java needs to be called from the game thread. PlayGamesHelperObject.RunOnGameThread(() => FetchToken(scope, playerId, rationale, fetchEmail, fetchAccessToken, fetchIdToken, (rc, access, id, email) => { if (rc != (int)CommonStatusCodes.Success) { apiAccessDenied = rc == (int)CommonStatusCodes.AuthApiAccessForbidden || rc == (int)CommonStatusCodes.Canceled; GooglePlayGames.OurUtils.Logger.w("Non-success returned from fetch: " + rc); doneCallback(CommonStatusCodes.AuthApiAccessForbidden); return; } if (fetchAccessToken) { GooglePlayGames.OurUtils.Logger.d("a = " + access); } if (fetchEmail) { GooglePlayGames.OurUtils.Logger.d("email = " + email); } if (fetchIdToken) { GooglePlayGames.OurUtils.Logger.d("idt = " + id); } if (fetchAccessToken && !string.IsNullOrEmpty(access)) { accessToken = access; } if (fetchIdToken && !string.IsNullOrEmpty(id)) { idToken = id; idTokenCb(idToken); } if (fetchEmail && !string.IsNullOrEmpty(email)) { this.accountName = email; } doneCallback(CommonStatusCodes.Success); })); }
public void OnEndpointLost(string lostEndpointId) { PlayGamesHelperObject.RunOnGameThread(() => mListener.OnEndpointLost(lostEndpointId)); }
public void OnRemoteEndpointDisconnected(string remoteEndpointId) { PlayGamesHelperObject.RunOnGameThread( () => mListener.OnRemoteEndpointDisconnected(remoteEndpointId)); }
/// <summary> /// Gets another server auth code. /// </summary> /// <remarks>This method should be called after authenticating, and exchanging /// the initial server auth code for a token. This is implemented by signing in /// silently, which if successful returns almost immediately and with a new /// server auth code. /// </remarks> /// <param name="reAuthenticateIfNeeded">Calls Authenticate if needed when /// retrieving another auth code. </param> /// <param name="callback">Callback.</param> public void GetAnotherServerAuthCode(bool reAuthenticateIfNeeded, Action <string> callback) { PlayGamesHelperObject.RunOnGameThread(() => DoGetAnotherServerAuthCode(reAuthenticateIfNeeded, callback)); }
public void OnParticipantLeft(Participant participant) { PlayGamesHelperObject.RunOnGameThread( () => mListener.OnParticipantLeft(participant)); }
public void OnPeersDisconnected(string[] participantIds) { PlayGamesHelperObject.RunOnGameThread( () => mListener.OnPeersDisconnected(participantIds)); }
static Action <T> ToOnGameThread <T>(Action <T> toConvert) { return(val => PlayGamesHelperObject.RunOnGameThread(() => toConvert(val))); }
public PlatformConfiguration CreatePlatformConfiguration() { AndroidPlatformConfiguration platformConfiguration = AndroidPlatformConfiguration.Create(); platformConfiguration.EnableAppState(); using (AndroidJavaObject activity = AndroidTokenClient.GetActivity()) { platformConfiguration.SetActivity(activity.GetRawObject()); // ISSUE: object of a compiler-generated type is created // ISSUE: reference to a compiler-generated method platformConfiguration.SetOptionalIntentHandlerForUI((Action <IntPtr>)(intent => PlayGamesHelperObject.RunOnGameThread(new Action(new AndroidClient.\u003CCreatePlatformConfiguration\u003Ec__AnonStorey100() { intentRef = AndroidJNI.NewGlobalRef(intent) }.\u003C\u003Em__D)))); } return((PlatformConfiguration)platformConfiguration); }
public void OnRoomConnected(bool success) { PlayGamesHelperObject.RunOnGameThread(() => mListener.OnRoomConnected(success)); }
public void OnLeftRoom() { PlayGamesHelperObject.RunOnGameThread(() => mListener.OnLeftRoom()); }
public void FetchTokens(Action callback) { PlayGamesHelperObject.RunOnGameThread(() => DoFetchToken(callback)); }
public void OnRealTimeMessageReceived(bool isReliable, string senderId, byte[] data) { PlayGamesHelperObject.RunOnGameThread( () => mListener.OnRealTimeMessageReceived(isReliable, senderId, data)); }
private void CheckForConnectionExtras() { Logger.d("AndroidClient: CheckInvitationFromNotification."); Logger.d("AndroidClient: looking for invitation in our GameHelper."); Invitation invFromNotif = null; AndroidJavaObject invitation = this.mGHManager.GetInvitation(); AndroidJavaObject turnBasedMatch = this.mGHManager.GetTurnBasedMatch(); this.mGHManager.ClearInvitationAndTurnBasedMatch(); if (invitation != null) { Logger.d("Found invitation in GameHelper. Converting."); invFromNotif = this.ConvertInvitation(invitation); Logger.d("Found invitation in our GameHelper: " + invFromNotif); } else { Logger.d("No invitation in our GameHelper. Trying SignInHelperManager."); AndroidJavaClass @class = JavaUtil.GetClass("com.google.example.games.pluginsupport.SignInHelperManager"); using (AndroidJavaObject androidJavaObject = @class.CallStatic <AndroidJavaObject>("getInstance", new object[0])) { if (androidJavaObject.Call <bool>("hasInvitation", new object[0])) { invFromNotif = this.ConvertInvitation(androidJavaObject.Call <AndroidJavaObject>("getInvitation", new object[0])); Logger.d("Found invitation in SignInHelperManager: " + invFromNotif); androidJavaObject.Call("forgetInvitation", new object[0]); } else { Logger.d("No invitation in SignInHelperManager either."); } } } TurnBasedMatch turnBasedMatch2 = null; if (turnBasedMatch != null) { Logger.d("Found match in GameHelper. Converting."); turnBasedMatch2 = JavaUtil.ConvertMatch(this.mUserId, turnBasedMatch); Logger.d("Match from GameHelper: " + turnBasedMatch2); } else { Logger.d("No match in our GameHelper. Trying SignInHelperManager."); AndroidJavaClass class2 = JavaUtil.GetClass("com.google.example.games.pluginsupport.SignInHelperManager"); using (AndroidJavaObject androidJavaObject2 = class2.CallStatic <AndroidJavaObject>("getInstance", new object[0])) { if (androidJavaObject2.Call <bool>("hasTurnBasedMatch", new object[0])) { turnBasedMatch2 = JavaUtil.ConvertMatch(this.mUserId, androidJavaObject2.Call <AndroidJavaObject>("getTurnBasedMatch", new object[0])); Logger.d("Found match in SignInHelperManager: " + turnBasedMatch2); androidJavaObject2.Call("forgetTurnBasedMatch", new object[0]); } else { Logger.d("No match in SignInHelperManager either."); } } } if (invFromNotif != null) { if (this.mInvitationDelegate != null) { Logger.d("Invoking invitation received delegate to deal with invitation from notification."); PlayGamesHelperObject.RunOnGameThread(delegate { if (this.mInvitationDelegate != null) { this.mInvitationDelegate(invFromNotif, true); } }); } else { Logger.d("No delegate to handle invitation from notification; queueing."); this.mInvitationFromNotification = invFromNotif; } } if (turnBasedMatch2 != null) { this.mTbmpClient.HandleMatchFromNotification(turnBasedMatch2); } }
public void FetchTokens(bool silent, Action <int> callback) { PlayGamesHelperObject.RunOnGameThread(() => DoFetchToken(silent, callback)); }
private void CheckForConnectionExtras() { // check to see if we have a pending invitation in our gamehelper Logger.d("AndroidClient: CheckInvitationFromNotification."); Logger.d("AndroidClient: looking for invitation in our GameHelper."); Invitation invFromNotif = null; AndroidJavaObject invObj = mGHManager.GetInvitation(); AndroidJavaObject matchObj = mGHManager.GetTurnBasedMatch(); mGHManager.ClearInvitationAndTurnBasedMatch(); if (invObj != null) { Logger.d("Found invitation in GameHelper. Converting."); invFromNotif = ConvertInvitation(invObj); Logger.d("Found invitation in our GameHelper: " + invFromNotif); } else { Logger.d("No invitation in our GameHelper. Trying SignInHelperManager."); AndroidJavaClass cls = JavaUtil.GetClass(JavaConsts.SignInHelperManagerClass); using (AndroidJavaObject inst = cls.CallStatic <AndroidJavaObject>("getInstance")) { if (inst.Call <bool>("hasInvitation")) { invFromNotif = ConvertInvitation(inst.Call <AndroidJavaObject>("getInvitation")); Logger.d("Found invitation in SignInHelperManager: " + invFromNotif); inst.Call("forgetInvitation"); } else { Logger.d("No invitation in SignInHelperManager either."); } } } TurnBasedMatch match = null; if (matchObj != null) { Logger.d("Found match in GameHelper. Converting."); match = JavaUtil.ConvertMatch(mUserId, matchObj); Logger.d("Match from GameHelper: " + match); } else { Logger.d("No match in our GameHelper. Trying SignInHelperManager."); AndroidJavaClass cls = JavaUtil.GetClass(JavaConsts.SignInHelperManagerClass); using (AndroidJavaObject inst = cls.CallStatic <AndroidJavaObject>("getInstance")) { if (inst.Call <bool>("hasTurnBasedMatch")) { match = JavaUtil.ConvertMatch(mUserId, inst.Call <AndroidJavaObject>("getTurnBasedMatch")); Logger.d("Found match in SignInHelperManager: " + match); inst.Call("forgetTurnBasedMatch"); } else { Logger.d("No match in SignInHelperManager either."); } } } // if we got an invitation from the notification, invoke the delegate if (invFromNotif != null) { if (mInvitationDelegate != null) { Logger.d("Invoking invitation received delegate to deal with invitation " + " from notification."); PlayGamesHelperObject.RunOnGameThread(() => { if (mInvitationDelegate != null) { mInvitationDelegate.Invoke(invFromNotif, true); } }); } else { Logger.d("No delegate to handle invitation from notification; queueing."); mInvitationFromNotification = invFromNotif; } } // if we got a turn-based match, hand it over to the TBMP client who will know // better what to do with it if (match != null) { mTbmpClient.HandleMatchFromNotification(match); } }
public void OnMessageReceived(string remoteEndpointId, byte[] data, bool isReliableMessage) { PlayGamesHelperObject.RunOnGameThread(() => mListener.OnMessageReceived( remoteEndpointId, data, isReliableMessage)); }
public void onCaptureOverlayStateChanged(int overlayState) { PlayGamesHelperObject.RunOnGameThread(() => mListener.OnCaptureOverlayStateChanged(FromVideoCaptureOverlayState(overlayState)) ); }
public void OnEndpointFound(EndpointDetails discoveredEndpoint) { PlayGamesHelperObject.RunOnGameThread(() => mListener.OnEndpointFound(discoveredEndpoint)); }
private void OnStateLoaded(int statusCode, int stateKey, byte[] localData) { // ISSUE: object of a compiler-generated type is created // ISSUE: variable of a compiler-generated type AndroidAppStateClient.OnStateResultProxy.\u003COnStateLoaded\u003Ec__AnonStorey104 loadedCAnonStorey104 = new AndroidAppStateClient.OnStateResultProxy.\u003COnStateLoaded\u003Ec__AnonStorey104(); // ISSUE: reference to a compiler-generated field loadedCAnonStorey104.stateKey = stateKey; // ISSUE: reference to a compiler-generated field loadedCAnonStorey104.localData = localData; // ISSUE: reference to a compiler-generated field loadedCAnonStorey104.\u003C\u003Ef__this = this; // ISSUE: reference to a compiler-generated field Logger.d("OnStateResultProxy.onStateLoaded called, status " + (object)statusCode + ", stateKey=" + (object)loadedCAnonStorey104.stateKey); // ISSUE: reference to a compiler-generated field this.debugLogData(nameof(localData), loadedCAnonStorey104.localData); // ISSUE: reference to a compiler-generated field loadedCAnonStorey104.success = false; int num = statusCode; switch (num) { case 0: Logger.d("Status is OK, so success."); // ISSUE: reference to a compiler-generated field loadedCAnonStorey104.success = true; break; case 3: Logger.d("Status is STALE DATA, so considering as success."); // ISSUE: reference to a compiler-generated field loadedCAnonStorey104.success = true; break; case 4: Logger.d("Status is NO DATA (no network?), so it's a failure."); // ISSUE: reference to a compiler-generated field loadedCAnonStorey104.success = false; // ISSUE: reference to a compiler-generated field loadedCAnonStorey104.localData = (byte[])null; break; default: if (num == 2002) { Logger.d("Status is KEY NOT FOUND, which is a success, but with no data."); // ISSUE: reference to a compiler-generated field loadedCAnonStorey104.success = true; // ISSUE: reference to a compiler-generated field loadedCAnonStorey104.localData = (byte[])null; break; } Logger.e("Cloud load failed with status code " + (object)statusCode); // ISSUE: reference to a compiler-generated field loadedCAnonStorey104.success = false; // ISSUE: reference to a compiler-generated field loadedCAnonStorey104.localData = (byte[])null; break; } if (this.mListener != null) { Logger.d("OnStateResultProxy.onStateLoaded invoking load callback."); // ISSUE: reference to a compiler-generated method PlayGamesHelperObject.RunOnGameThread(new Action(loadedCAnonStorey104.\u003C\u003Em__10)); } else { Logger.w("No load callback specified!"); } }
private static Action <T1, T2> ToOnGameThread <T1, T2>(Action <T1, T2> toConvert) { return((val1, val2) => PlayGamesHelperObject.RunOnGameThread(() => toConvert(val1, val2))); }
public void OnRoomSetupProgress(float percent) { PlayGamesHelperObject.RunOnGameThread(() => mListener.OnRoomSetupProgress(percent)); }
public void SetGravityForPopups(Gravity gravity) { PlayGamesHelperObject.RunOnGameThread(() => clientImpl.SetGravityForPopups(GetApiClient(), gravity)); }
public void onResult(AndroidJavaObject result) { Logger.d("ResultProxy got result for method: " + this.mMethod); int statusCode = JavaUtil.GetStatusCode(result); bool isSuccess = this.mSuccessCodes.Contains(statusCode); TurnBasedMatch match = null; if (isSuccess) { Logger.d(string.Concat(new object[] { "SUCCESS result from method ", this.mMethod, ": ", statusCode })); if (this.mMatchCallback != null) { Logger.d("Attempting to get match from result of " + this.mMethod); AndroidJavaObject androidJavaObject = JavaUtil.CallNullSafeObjectMethod(result, "getMatch", new object[0]); if (androidJavaObject != null) { Logger.d("Successfully got match from result of " + this.mMethod); match = JavaUtil.ConvertMatch(this.mOwner.mClient.PlayerId, androidJavaObject); androidJavaObject.Dispose(); } else { Logger.w("Got a NULL match from result of " + this.mMethod); } } } else { Logger.w(string.Concat(new object[] { "ERROR result from ", this.mMethod, ": ", statusCode })); } if (this.mSuccessCallback != null) { Logger.d(string.Concat(new object[] { "Invoking success callback (success=", isSuccess, ") for result of method ", this.mMethod })); PlayGamesHelperObject.RunOnGameThread(delegate { this.mSuccessCallback(isSuccess); }); } if (this.mMatchCallback != null) { Logger.d(string.Concat(new object[] { "Invoking match callback for result of method ", this.mMethod, ": (success=", isSuccess, ", match=", (match != null) ? match.ToString() : "(null)" })); PlayGamesHelperObject.RunOnGameThread(delegate { this.mMatchCallback(isSuccess, match); }); } }