internal NativeRealtimeMultiplayerClient(NativeClient nativeClient, RealtimeManager manager)
 {
     mNativeClient    = Misc.CheckNotNull(nativeClient);
     mRealtimeManager = Misc.CheckNotNull(manager);
     mCurrentSession  = GetTerminatedSession();
     PlayGamesHelperObject.AddPauseCallback(HandleAppPausing);
 }
Пример #2
0
 public void Authenticate(Action <bool> callback, bool silent)
 {
     lock (this.AuthStateLock)
     {
         if (this.mAuthState == NativeClient.AuthState.Authenticated)
         {
             NativeClient.InvokeCallbackOnGameThread <bool>(callback, true);
             return;
         }
         if (this.mSilentAuthFailed && silent)
         {
             NativeClient.InvokeCallbackOnGameThread <bool>(callback, false);
             return;
         }
         if (callback != null)
         {
             if (silent)
             {
                 this.mSilentAuthCallbacks += callback;
             }
             else
             {
                 this.mPendingAuthCallbacks += callback;
             }
         }
     }
     this.InitializeGameServices();
     if (silent)
     {
         return;
     }
     this.GameServices().StartAuthorizationUI();
 }
Пример #3
0
        private void HandleAuthTransition(Types.AuthOperation operation, CommonErrorStatus.AuthStatus status)
        {
            Logger.d("Starting Auth Transition. Op: " + (object)operation + " status: " + (object)status);
            lock (this.AuthStateLock)
            {
                switch (operation)
                {
                case Types.AuthOperation.SIGN_IN:
                    if (status == CommonErrorStatus.AuthStatus.VALID)
                    {
                        // ISSUE: object of a compiler-generated type is created
                        // ISSUE: variable of a compiler-generated type
                        NativeClient.\u003CHandleAuthTransition\u003Ec__AnonStorey10E transitionCAnonStorey10E = new NativeClient.\u003CHandleAuthTransition\u003Ec__AnonStorey10E();
                        // ISSUE: reference to a compiler-generated field
                        transitionCAnonStorey10E.\u003C\u003Ef__this = this;
                        if (this.mSilentAuthCallbacks != null)
                        {
                            this.mPendingAuthCallbacks += this.mSilentAuthCallbacks;
                            this.mSilentAuthCallbacks   = (Action <bool>)null;
                        }
                        // ISSUE: reference to a compiler-generated field
                        transitionCAnonStorey10E.currentAuthGeneration = this.mAuthGeneration;
                        // ISSUE: reference to a compiler-generated method
                        this.mServices.AchievementManager().FetchAll(new Action <GooglePlayGames.Native.PInvoke.AchievementManager.FetchAllResponse>(transitionCAnonStorey10E.\u003C\u003Em__20));
                        // ISSUE: reference to a compiler-generated method
                        this.mServices.PlayerManager().FetchSelf(new Action <GooglePlayGames.Native.PInvoke.PlayerManager.FetchSelfResponse>(transitionCAnonStorey10E.\u003C\u003Em__21));
                        break;
                    }
                    if (this.mAuthState == NativeClient.AuthState.SilentPending)
                    {
                        this.mSilentAuthFailed = true;
                        this.mAuthState        = NativeClient.AuthState.Unauthenticated;
                        Action <bool> silentAuthCallbacks = this.mSilentAuthCallbacks;
                        this.mSilentAuthCallbacks = (Action <bool>)null;
                        Debug.Log((object)"Invoking callbacks, AuthState changed from silentPending to Unauthenticated.");
                        NativeClient.InvokeCallbackOnGameThread <bool>(silentAuthCallbacks, false);
                        if (this.mPendingAuthCallbacks == null)
                        {
                            break;
                        }
                        Debug.Log((object)"there are pending auth callbacks - starting AuthUI");
                        this.GameServices().StartAuthorizationUI();
                        break;
                    }
                    Debug.Log((object)("AuthState == " + (object)this.mAuthState + " calling auth callbacks with failure"));
                    Action <bool> pendingAuthCallbacks = this.mPendingAuthCallbacks;
                    this.mPendingAuthCallbacks = (Action <bool>)null;
                    NativeClient.InvokeCallbackOnGameThread <bool>(pendingAuthCallbacks, false);
                    break;

                case Types.AuthOperation.SIGN_OUT:
                    this.ToUnauthenticated();
                    break;

                default:
                    Logger.e("Unknown AuthOperation " + (object)operation);
                    break;
                }
            }
        }
Пример #4
0
 private void PopulateUser(uint authGeneration, GooglePlayGames.Native.PInvoke.PlayerManager.FetchSelfResponse response)
 {
     Logger.d("Populating User");
     if ((int)authGeneration != (int)this.mAuthGeneration)
     {
         Logger.d("Received user callback after signout occurred, ignoring");
     }
     else
     {
         lock (this.AuthStateLock)
         {
             if (response.Status() != CommonErrorStatus.ResponseStatus.VALID && response.Status() != CommonErrorStatus.ResponseStatus.VALID_BUT_STALE)
             {
                 Logger.e("Error retrieving user, signing out");
                 Action <bool> pendingAuthCallbacks = this.mPendingAuthCallbacks;
                 this.mPendingAuthCallbacks = (Action <bool>)null;
                 if (pendingAuthCallbacks != null)
                 {
                     NativeClient.InvokeCallbackOnGameThread <bool>(pendingAuthCallbacks, false);
                 }
                 this.SignOut();
                 return;
             }
             this.mUser    = response.Self().AsPlayer();
             this.mFriends = (List <GooglePlayGames.BasicApi.Multiplayer.Player>)null;
         }
         Logger.d("Found User: "******"Maybe finish for User");
         this.MaybeFinishAuthentication();
     }
 }
Пример #5
0
 private static Action <T> AsOnGameThreadCallback <T>(Action <T> callback)
 {
     if (callback == null)
     {
         return((Action <T>)(_param0 => {}));
     }
     return((Action <T>)(result => NativeClient.InvokeCallbackOnGameThread <T>(callback, result)));
 }
Пример #6
0
 private static Action <T> AsOnGameThreadCallback <T>(Action <T> callback)
 {
     if (callback == null)
     {
         return(delegate
         {
         });
     }
     return(delegate(T result)
     {
         NativeClient.InvokeCallbackOnGameThread <T>(callback, result);
     });
 }
Пример #7
0
        public void ShowAchievementsUI(Action <GooglePlayGames.BasicApi.UIStatus> cb)
        {
            if (!this.IsAuthenticated())
            {
                return;
            }
            Action <CommonErrorStatus.UIStatus> callback = Callbacks.NoopUICallback;

            if (cb != null)
            {
                callback = (Action <CommonErrorStatus.UIStatus>)(result => cb((GooglePlayGames.BasicApi.UIStatus)result));
            }
            this.GameServices().AchievementManager().ShowAllUI(NativeClient.AsOnGameThreadCallback <CommonErrorStatus.UIStatus>(callback));
        }
Пример #8
0
 public void SubmitScore(string leaderboardId, long score, string metadata, Action <bool> callback)
 {
     callback = NativeClient.AsOnGameThreadCallback <bool>(callback);
     if (!this.IsAuthenticated())
     {
         callback(false);
     }
     this.InitializeGameServices();
     if (leaderboardId == null)
     {
         throw new ArgumentNullException(nameof(leaderboardId));
     }
     this.GameServices().LeaderboardManager().SubmitScore(leaderboardId, score, metadata);
     callback(true);
 }
Пример #9
0
        internal static void InitializeFactory()
        {
            // initialize the callback thread processing
            PlayGamesHelperObject.CreateObject();

            //Read the Service ID
            NearbyConnectionsManager.ReadServiceId();

            NearbyConnectionsManagerBuilder sBuilder = new NearbyConnectionsManagerBuilder();

            // The connection manager needs to be initialized before using it, so
            // wait for initialization.
            sBuilder.SetOnInitializationFinished(OnManagerInitialized);
            PlatformConfiguration cfg = NativeClient.CreatePlatformConfiguration();

            Debug.Log("Building manager Now");
            sManager = sBuilder.Build(cfg);
        }
Пример #10
0
 public void SetStepsAtLeast(string achId, int steps, Action <bool> callback)
 {
     Misc.CheckNotNull <string>(achId);
     callback = NativeClient.AsOnGameThreadCallback <bool>(callback);
     this.InitializeGameServices();
     GooglePlayGames.BasicApi.Achievement achievement = this.GetAchievement(achId);
     if (achievement == null)
     {
         Logger.e("Could not increment, no achievement with ID " + achId);
         callback(false);
     }
     else if (!achievement.IsIncremental)
     {
         Logger.e("Could not increment, achievement with ID " + achId + " is not incremental");
         callback(false);
     }
     else if (steps < 0)
     {
         Logger.e("Attempted to increment by negative steps");
         callback(false);
     }
     else
     {
         this.GameServices().AchievementManager().SetStepsAtLeast(achId, Convert.ToUInt32(steps));
         this.GameServices().AchievementManager().Fetch(achId, (Action <GooglePlayGames.Native.PInvoke.AchievementManager.FetchResponse>)(rsp =>
         {
             if (rsp.Status() == CommonErrorStatus.ResponseStatus.VALID)
             {
                 this.mAchievements.Remove(achId);
                 this.mAchievements.Add(achId, rsp.Achievement().AsAchievement());
                 callback(true);
             }
             else
             {
                 Logger.e("Cannot refresh achievement " + achId + ": " + (object)rsp.Status());
                 callback(false);
             }
         }));
     }
 }
Пример #11
0
        private void MaybeFinishAuthentication()
        {
            Action <bool> callback = (Action <bool>)null;

            lock (this.AuthStateLock)
            {
                if (this.mUser == null || this.mAchievements == null)
                {
                    Logger.d("Auth not finished. User="******" achievements=" + (object)this.mAchievements);
                    return;
                }
                Logger.d("Auth finished. Proceeding.");
                callback = this.mPendingAuthCallbacks;
                this.mPendingAuthCallbacks = (Action <bool>)null;
                this.mAuthState            = NativeClient.AuthState.Authenticated;
            }
            if (callback == null)
            {
                return;
            }
            Logger.d("Invoking Callbacks: " + (object)callback);
            NativeClient.InvokeCallbackOnGameThread <bool>(callback, true);
        }
Пример #12
0
        public void ShowLeaderboardUI(string leaderboardId, GooglePlayGames.BasicApi.LeaderboardTimeSpan span, Action <GooglePlayGames.BasicApi.UIStatus> cb)
        {
            if (!this.IsAuthenticated())
            {
                return;
            }
            Action <CommonErrorStatus.UIStatus> callback1 = Callbacks.NoopUICallback;

            if (cb != null)
            {
                callback1 = (Action <CommonErrorStatus.UIStatus>)(result => cb((GooglePlayGames.BasicApi.UIStatus)result));
            }
            Action <CommonErrorStatus.UIStatus> callback2 = NativeClient.AsOnGameThreadCallback <CommonErrorStatus.UIStatus>(callback1);

            if (leaderboardId == null)
            {
                this.GameServices().LeaderboardManager().ShowAllUI(callback2);
            }
            else
            {
                this.GameServices().LeaderboardManager().ShowUI(leaderboardId, span, callback2);
            }
        }
Пример #13
0
 private void UpdateAchievement(string updateType, string achId, Action <bool> callback, Predicate <GooglePlayGames.BasicApi.Achievement> alreadyDone, Action <GooglePlayGames.BasicApi.Achievement> updateAchievment)
 {
     callback = NativeClient.AsOnGameThreadCallback <bool>(callback);
     Misc.CheckNotNull <string>(achId);
     this.InitializeGameServices();
     GooglePlayGames.BasicApi.Achievement achievement = this.GetAchievement(achId);
     if (achievement == null)
     {
         Logger.d("Could not " + updateType + ", no achievement with ID " + achId);
         callback(false);
     }
     else if (alreadyDone(achievement))
     {
         Logger.d("Did not need to perform " + updateType + ": on achievement " + achId);
         callback(true);
     }
     else
     {
         Logger.d("Performing " + updateType + " on " + achId);
         updateAchievment(achievement);
         this.GameServices().AchievementManager().Fetch(achId, (Action <GooglePlayGames.Native.PInvoke.AchievementManager.FetchResponse>)(rsp =>
         {
             if (rsp.Status() == CommonErrorStatus.ResponseStatus.VALID)
             {
                 this.mAchievements.Remove(achId);
                 this.mAchievements.Add(achId, rsp.Achievement().AsAchievement());
                 callback(true);
             }
             else
             {
                 Logger.e("Cannot refresh achievement " + achId + ": " + (object)rsp.Status());
                 callback(false);
             }
         }));
     }
 }
Пример #14
0
 private void PopulateAchievements(uint authGeneration, GooglePlayGames.Native.PInvoke.AchievementManager.FetchAllResponse response)
 {
     if ((int)authGeneration != (int)this.mAuthGeneration)
     {
         Logger.d("Received achievement callback after signout occurred, ignoring");
     }
     else
     {
         Logger.d("Populating Achievements, status = " + (object)response.Status());
         lock (this.AuthStateLock)
         {
             if (response.Status() != CommonErrorStatus.ResponseStatus.VALID && response.Status() != CommonErrorStatus.ResponseStatus.VALID_BUT_STALE)
             {
                 Logger.e("Error retrieving achievements - check the log for more information. Failing signin.");
                 Action <bool> pendingAuthCallbacks = this.mPendingAuthCallbacks;
                 this.mPendingAuthCallbacks = (Action <bool>)null;
                 if (pendingAuthCallbacks != null)
                 {
                     NativeClient.InvokeCallbackOnGameThread <bool>(pendingAuthCallbacks, false);
                 }
                 this.SignOut();
                 return;
             }
             Dictionary <string, GooglePlayGames.BasicApi.Achievement> dictionary = new Dictionary <string, GooglePlayGames.BasicApi.Achievement>();
             foreach (NativeAchievement nativeAchievement in response)
             {
                 using (nativeAchievement)
                     dictionary[nativeAchievement.Id()] = nativeAchievement.AsAchievement();
             }
             Logger.d("Found " + (object)dictionary.Count + " Achievements");
             this.mAchievements = dictionary;
         }
         Logger.d("Maybe finish for Achievements");
         this.MaybeFinishAuthentication();
     }
 }
 internal NativeTurnBasedMultiplayerClient(NativeClient nativeClient, TurnBasedManager manager)
 {
     this.mTurnBasedManager = manager;
     this.mNativeClient = nativeClient;
 }
Пример #16
0
 internal NativeRealtimeMultiplayerClient(NativeClient nativeClient, RealtimeManager manager)
 {
     mNativeClient    = Misc.CheckNotNull(nativeClient);
     mRealtimeManager = Misc.CheckNotNull(manager);
     mCurrentSession  = GetTerminatedSession();
 }
Пример #17
0
 internal NativeTurnBasedMultiplayerClient(NativeClient nativeClient, TurnBasedManager manager)
 {
     this.mTurnBasedManager = manager;
     this.mNativeClient     = nativeClient;
 }