예제 #1
0
 /// <summary>
 /// Creates new ResourcesClient instance
 /// </summary>
 /// <param name="resourceManagementClient">The IResourceManagementClient instance</param>
 /// <param name="galleryTemplatesClient">The IGalleryClient instance</param>
 /// <param name="eventsClient">The IEventsClient instance</param>
 public ResourcesClient(
     IResourceManagementClient resourceManagementClient,
     GalleryTemplatesClient galleryTemplatesClient,
     IEventsClient eventsClient,
     IAuthorizationManagementClient authorizationManagementClient)
 {
     ResourceManagementClient = resourceManagementClient;
     GalleryTemplatesClient = galleryTemplatesClient;
     EventsClient = eventsClient;
     AuthorizationManagementClient = authorizationManagementClient;
 }
예제 #2
0
 /// <summary>
 /// Creates new ResourcesClient instance
 /// </summary>
 /// <param name="resourceManagementClient">The IResourceManagementClient instance</param>
 /// <param name="storageClientWrapper">The IStorageClientWrapper instance</param>
 /// <param name="galleryTemplatesClient">The IGalleryClient instance</param>
 /// <param name="eventsClient">The IEventsClient instance</param>
 public ResourcesClient(
     IResourceManagementClient resourceManagementClient,
     IStorageClientWrapper storageClientWrapper,
     GalleryTemplatesClient galleryTemplatesClient,
     IEventsClient eventsClient)
 {
     ResourceManagementClient = resourceManagementClient;
     StorageClientWrapper = storageClientWrapper;
     GalleryTemplatesClient = galleryTemplatesClient;
     EventsClient = eventsClient;
 }
        private void InitializeGameServices()
        {
            lock (GameServicesLock)
            {
                if (mServices != null)
                {
                    return;
                }

                using (var builder = GameServicesBuilder.Create())
                {
                    using (var config = clientImpl.CreatePlatformConfiguration(mConfiguration))
                    {
                        // We need to make sure that the invitation delegate
                        // is registered before the services object is
                        // initialized - otherwise we might miss a callback if
                        // the game was opened because of a user accepting an
                        // invitation through a system notification.
                        RegisterInvitationDelegate(mConfiguration.InvitationDelegate);
                        builder.SetOnAuthFinishedCallback(HandleAuthTransition);
                        builder.SetOnTurnBasedMatchEventCallback(
                            (eventType, matchId, match) =>
                            mTurnBasedClient.HandleMatchEvent(
                                eventType, matchId, match));
                        builder.SetOnMultiplayerInvitationEventCallback(
                            HandleInvitation);
                        if (mConfiguration.EnableSavedGames)
                        {
                            builder.EnableSnapshots();
                        }

                        string[] scopes = mConfiguration.Scopes;
                        for (int i = 0; i < scopes.Length; i++)
                        {
                            builder.AddOauthScope(scopes[i]);
                        }

                        if (mConfiguration.IsHidingPopups)
                        {
                            builder.SetShowConnectingPopup(false);
                        }

                        Debug.Log("Building GPG services, implicitly attempts silent auth");
                        mServices        = builder.Build(config);
                        mEventsClient    = new NativeEventClient(new EventManager(mServices));
                        mVideoClient     = new NativeVideoClient(new VideoManager(mServices));
                        mTurnBasedClient =
                            new NativeTurnBasedMultiplayerClient(this, new TurnBasedManager(mServices));

                        mTurnBasedClient.RegisterMatchDelegate(mConfiguration.MatchDelegate);

                        mRealTimeClient =
                            new NativeRealtimeMultiplayerClient(this, new RealtimeManager(mServices));

                        if (mConfiguration.EnableSavedGames)
                        {
                            mSavedGameClient =
                                new NativeSavedGameClient(new SnapshotManager(mServices));
                        }
                        else
                        {
                            mSavedGameClient = new UnsupportedSavedGamesClient(
                                "You must enable saved games before it can be used. " +
                                "See PlayGamesClientConfiguration.Builder.EnableSavedGames.");
                        }

                        InitializeTokenClient();
                    }
                }
            }
        }
예제 #4
0
        private void InitializeGameServices()
        {
            lock (GameServicesLock)
            {
                if (mServices != null)
                {
                    return;
                }

                using (var builder = GameServicesBuilder.Create())
                {
                    using (var config = clientImpl.CreatePlatformConfiguration(mConfiguration))
                    {
                        // We need to make sure that the invitation delegate
                        // is registered before the services object is
                        // initialized - otherwise we might miss a callback if
                        // the game was opened because of a user accepting an
                        // invitation through a system notification.
                        RegisterInvitationDelegate(mConfiguration.InvitationDelegate);
                        builder.SetOnAuthFinishedCallback(HandleAuthTransition);
                        builder.SetOnTurnBasedMatchEventCallback(
                            (eventType, matchId, match) =>
                            mTurnBasedClient.HandleMatchEvent(
                                eventType, matchId, match));
                        builder.SetOnMultiplayerInvitationEventCallback(
                            HandleInvitation);
                        if (mConfiguration.EnableSavedGames)
                        {
                            builder.EnableSnapshots();
                        }

                        string[] scopes = mConfiguration.Scopes;
                        for (int i = 0; i < scopes.Length; i++)
                        {
                            builder.AddOauthScope(scopes[i]);
                        }

                        if (mConfiguration.IsHidingPopups)
                        {
                            builder.SetShowConnectingPopup(false);
                        }

                        Debug.Log("Building GPG services, implicitly attempts silent auth");
                        mAuthState       = AuthState.SilentPending;
                        mServices        = builder.Build(config);
                        mEventsClient    = new NativeEventClient(new EventManager(mServices));
                        mQuestsClient    = new NativeQuestClient(new QuestManager(mServices));
                        mVideoClient     = new NativeVideoClient(new VideoManager(mServices));
                        mTurnBasedClient =
                            new NativeTurnBasedMultiplayerClient(this, new TurnBasedManager(mServices));

                        mTurnBasedClient.RegisterMatchDelegate(mConfiguration.MatchDelegate);

                        mRealTimeClient =
                            new NativeRealtimeMultiplayerClient(this, new RealtimeManager(mServices));

                        if (mConfiguration.EnableSavedGames)
                        {
                            mSavedGameClient =
                                new NativeSavedGameClient(new SnapshotManager(mServices));
                        }
                        else
                        {
                            mSavedGameClient = new UnsupportedSavedGamesClient(
                                "You must enable saved games before it can be used. " +
                                "See PlayGamesClientConfiguration.Builder.EnableSavedGames.");
                        }

                        mAuthState   = AuthState.SilentPending;
                        mTokenClient = clientImpl.CreateTokenClient(true);

                        if (!GameInfo.WebClientIdInitialized() &&
                            (mConfiguration.IsRequestingIdToken || mConfiguration.IsRequestingAuthCode))
                        {
                            OurUtils.Logger.e("Server Auth Code and ID Token require web clientId to configured.");
                        }
                        // Set the auth flags in the token client.
                        mTokenClient.SetWebClientId(GameInfo.WebClientId);
                        mTokenClient.SetRequestAuthCode(mConfiguration.IsRequestingAuthCode, mConfiguration.IsForcingRefresh);
                        mTokenClient.SetRequestEmail(mConfiguration.IsRequestingEmail);
                        mTokenClient.SetRequestIdToken(mConfiguration.IsRequestingIdToken);
                        mTokenClient.SetHidePopups(mConfiguration.IsHidingPopups);
                        mTokenClient.AddOauthScopes(scopes);
                        mTokenClient.SetAccountName(mConfiguration.AccountName);
                    }
                }
            }
        }
예제 #5
0
        private void InitializeGameServices()
        {
            lock (GameServicesLock)
            {
                if (mServices != null)
                {
                    return;
                }

                using (var builder = GameServicesBuilder.Create())
                {
                    using (var config = CreatePlatformConfiguration())
                    {
                        // We need to make sure that the invitation delegate is registered before the
                        // services object is initialized - otherwise we might miss a callback if
                        // the game was opened because of a user accepting an invitation through
                        // a system notification.
                        RegisterInvitationDelegate(mConfiguration.InvitationDelegate);

                        builder.SetOnAuthFinishedCallback(HandleAuthTransition);
                        builder.SetOnTurnBasedMatchEventCallback((eventType, matchId, match) => mTurnBasedClient.HandleMatchEvent(eventType, matchId, match));
                        builder.SetOnMultiplayerInvitationEventCallback(HandleInvitation);
                        if (mConfiguration.EnableSavedGames)
                        {
                            builder.EnableSnapshots();
                        }
                        mServices = builder.Build(config);
                        mEventsClient = new NativeEventClient(new EventManager(mServices));
                        mQuestsClient = new NativeQuestClient(new QuestManager(mServices));
                        mTurnBasedClient =
                        new NativeTurnBasedMultiplayerClient(this, new TurnBasedManager(mServices));

                        mTurnBasedClient.RegisterMatchDelegate(mConfiguration.MatchDelegate);

                        mRealTimeClient =
                        new NativeRealtimeMultiplayerClient(this, new RealtimeManager(mServices));

                        if (mConfiguration.EnableSavedGames)
                        {
                            mSavedGameClient =
                            new NativeSavedGameClient(new SnapshotManager(mServices));
                        }
                        else
                        {
                            mSavedGameClient = new UnsupportedSavedGamesClient(
                                "You must enable saved games before it can be used. " +
                                "See PlayGamesClientConfiguration.Builder.EnableSavedGames.");
                        }

                        mAppStateClient = CreateAppStateClient();
                        mAuthState = AuthState.SilentPending;
                    }
                }
            }
        }
예제 #6
0
        ///<summary></summary>
        /// <seealso cref="GooglePlayGames.BasicApi.IPlayGamesClient.Authenticate"/>
        public void Authenticate(Action <bool, string> callback, bool silent)
        {
            lock (AuthStateLock)
            {
                // If the user is already authenticated, just fire the callback, we don't need
                // any additional work.
                if (mAuthState == AuthState.Authenticated)
                {
                    InvokeCallbackOnGameThread(callback, true, null);
                    return;
                }
            }

            InitializeTokenClient();

            Debug.Log("Starting Auth with token client.");
            mTokenClient.FetchTokens(silent, (int result) =>
            {
                bool succeed = result == 0 /* CommonStatusCodes.SUCCEED */;
                InitializeGameServices();
                if (succeed)
                {
                    using (var signInTasks = new AndroidJavaObject("java.util.ArrayList"))
                    {
                        if (mInvitationDelegate != null)
                        {
                            mInvitationCallback = new AndroidJavaObject(
                                "com.google.games.bridge.InvitationCallbackProxy",
                                new InvitationCallbackProxy(mInvitationDelegate));
                            using (var invitationsClient = getInvitationsClient())
                                using (var taskRegisterCallback =
                                           invitationsClient.Call <AndroidJavaObject>("registerInvitationCallback",
                                                                                      mInvitationCallback))
                                {
                                    signInTasks.Call <bool>("add", taskRegisterCallback);
                                }
                        }

                        AndroidJavaObject taskGetPlayer =
                            getPlayersClient().Call <AndroidJavaObject>("getCurrentPlayer");
                        AndroidJavaObject taskGetActivationHint =
                            getGamesClient().Call <AndroidJavaObject>("getActivationHint");
                        AndroidJavaObject taskIsCaptureSupported =
                            getVideosClient().Call <AndroidJavaObject>("isCaptureSupported");

                        if (!mConfiguration.IsHidingPopups)
                        {
                            AndroidJavaObject taskSetViewForPopups;
                            using (var popupView = AndroidHelperFragment.GetDefaultPopupView())
                            {
                                taskSetViewForPopups =
                                    getGamesClient().Call <AndroidJavaObject>("setViewForPopups", popupView);
                            }

                            signInTasks.Call <bool>("add", taskSetViewForPopups);
                        }

                        signInTasks.Call <bool>("add", taskGetPlayer);
                        signInTasks.Call <bool>("add", taskGetActivationHint);
                        signInTasks.Call <bool>("add", taskIsCaptureSupported);

                        using (var tasks = new AndroidJavaClass(TasksClassName))
                            using (var allTask = tasks.CallStatic <AndroidJavaObject>("whenAll", signInTasks))
                            {
                                AndroidTaskUtils.AddOnCompleteListener <AndroidJavaObject>(
                                    allTask,
                                    completeTask =>
                                {
                                    if (completeTask.Call <bool>("isSuccessful"))
                                    {
                                        using (var resultObject = taskGetPlayer.Call <AndroidJavaObject>("getResult"))
                                        {
                                            mUser = AndroidJavaConverter.ToPlayer(resultObject);
                                        }

                                        var account = mTokenClient.GetAccount();
                                        lock (GameServicesLock)
                                        {
                                            mSavedGameClient = new AndroidSavedGameClient(account);
                                            mEventsClient    = new AndroidEventsClient(account);
                                            bool isCaptureSupported;
                                            using (var resultObject =
                                                       taskIsCaptureSupported.Call <AndroidJavaObject>("getResult"))
                                            {
                                                isCaptureSupported = resultObject.Call <bool>("booleanValue");
                                            }

                                            mVideoClient     = new AndroidVideoClient(isCaptureSupported, account);
                                            mRealTimeClient  = new AndroidRealTimeMultiplayerClient(this, account);
                                            mTurnBasedClient = new AndroidTurnBasedMultiplayerClient(this, account);
                                            mTurnBasedClient.RegisterMatchDelegate(mConfiguration.MatchDelegate);
                                        }

                                        mAuthState = AuthState.Authenticated;
                                        InvokeCallbackOnGameThread(callback, true, "Authentication succeed");
                                        try
                                        {
                                            using (var activationHint =
                                                       taskGetActivationHint.Call <AndroidJavaObject>("getResult"))
                                            {
                                                if (mInvitationDelegate != null)
                                                {
                                                    try
                                                    {
                                                        using (var invitationObject =
                                                                   activationHint.Call <AndroidJavaObject>("getParcelable",
                                                                                                           "invitation" /* Multiplayer.EXTRA_INVITATION */))
                                                        {
                                                            Invitation invitation =
                                                                AndroidJavaConverter.ToInvitation(invitationObject);
                                                            mInvitationDelegate(invitation, /* shouldAutoAccept= */
                                                                                true);
                                                        }
                                                    }
                                                    catch (Exception)
                                                    {
                                                        // handle null return
                                                    }
                                                }


                                                if (mTurnBasedClient.MatchDelegate != null)
                                                {
                                                    try
                                                    {
                                                        using (var matchObject =
                                                                   activationHint.Call <AndroidJavaObject>("getParcelable",
                                                                                                           "turn_based_match" /* Multiplayer#EXTRA_TURN_BASED_MATCH */)
                                                               )
                                                        {
                                                            TurnBasedMatch turnBasedMatch =
                                                                AndroidJavaConverter.ToTurnBasedMatch(matchObject);
                                                            mTurnBasedClient.MatchDelegate(
                                                                turnBasedMatch, /* shouldAutoLaunch= */ true);
                                                        }
                                                    }
                                                    catch (Exception)
                                                    {
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception)
                                        {
                                            // handle null return
                                        }

                                        LoadAchievements(ignore => { });
                                    }
                                    else
                                    {
                                        SignOut();
                                        InvokeCallbackOnGameThread(callback, false, "Authentication failed");
                                    }
                                }
                                    );
                            }
                    }
                }
                else
                {
                    lock (AuthStateLock)
                    {
                        if (result == 16 /* CommonStatusCodes.CANCELED */)
                        {
                            InvokeCallbackOnGameThread(callback, false, "Authentication canceled");
                        }
                        else if (result == 8 /* CommonStatusCodes.DEVELOPER_ERROR */)
                        {
                            InvokeCallbackOnGameThread(callback, false, "Authentication failed - developer error");
                        }
                        else
                        {
                            InvokeCallbackOnGameThread(callback, false, "Authentication failed");
                        }
                    }
                }
            });
        }
        private void InitializeGameServices()
        {
            lock (GameServicesLock)
            {
                if (mServices != null)
                {
                    return;
                }

                using (var builder = GameServicesBuilder.Create())
                {
                    using (var config = clientImpl.CreatePlatformConfiguration())
                    {
                        // We need to make sure that the invitation delegate is registered before the
                        // services object is initialized - otherwise we might miss a callback if
                        // the game was opened because of a user accepting an invitation through
                        // a system notification.
                        RegisterInvitationDelegate(mConfiguration.InvitationDelegate);
                        builder.SetOnAuthFinishedCallback(HandleAuthTransition);
                        builder.SetOnTurnBasedMatchEventCallback((eventType, matchId, match) => mTurnBasedClient.HandleMatchEvent(eventType, matchId, match));
                        builder.SetOnMultiplayerInvitationEventCallback(HandleInvitation);
                        if (mConfiguration.EnableSavedGames)
                        {
                            builder.EnableSnapshots();
                        }
                        if (mConfiguration.RequireGooglePlus)
                        {
                            builder.RequireGooglePlus();
                        }
                        Debug.Log("Building GPG services, implicitly attempts silent auth");
                        mAuthState       = AuthState.SilentPending;
                        mServices        = builder.Build(config);
                        mEventsClient    = new NativeEventClient(new EventManager(mServices));
                        mQuestsClient    = new NativeQuestClient(new QuestManager(mServices));
                        mTurnBasedClient =
                            new NativeTurnBasedMultiplayerClient(this, new TurnBasedManager(mServices));

                        mTurnBasedClient.RegisterMatchDelegate(mConfiguration.MatchDelegate);

                        mRealTimeClient =
                            new NativeRealtimeMultiplayerClient(this, new RealtimeManager(mServices));

                        if (mConfiguration.EnableSavedGames)
                        {
                            mSavedGameClient =
                                new NativeSavedGameClient(new SnapshotManager(mServices));
                        }
                        else
                        {
                            mSavedGameClient = new UnsupportedSavedGamesClient(
                                "You must enable saved games before it can be used. " +
                                "See PlayGamesClientConfiguration.Builder.EnableSavedGames.");
                        }

                        mAuthState   = AuthState.SilentPending;
                        mTokenClient = clientImpl.CreateTokenClient(
                            (mUser == null) ? null : mUser.id, false);
                    }
                }
            }
        }
예제 #8
0
 private void InitializeGameServices()
 {
     lock (GameServicesLock)
     {
         if (mServices == null)
         {
             using (GameServicesBuilder gameServicesBuilder = GameServicesBuilder.Create())
             {
                 using (PlatformConfiguration configRef = clientImpl.CreatePlatformConfiguration(mConfiguration))
                 {
                     RegisterInvitationDelegate(mConfiguration.InvitationDelegate);
                     gameServicesBuilder.SetOnAuthFinishedCallback(HandleAuthTransition);
                     gameServicesBuilder.SetOnTurnBasedMatchEventCallback(delegate(Types.MultiplayerEvent eventType, string matchId, NativeTurnBasedMatch match)
                     {
                         mTurnBasedClient.HandleMatchEvent(eventType, matchId, match);
                     });
                     gameServicesBuilder.SetOnMultiplayerInvitationEventCallback(HandleInvitation);
                     if (mConfiguration.EnableSavedGames)
                     {
                         gameServicesBuilder.EnableSnapshots();
                     }
                     string[] scopes = mConfiguration.Scopes;
                     for (int i = 0; i < scopes.Length; i++)
                     {
                         gameServicesBuilder.AddOauthScope(scopes[i]);
                     }
                     if (mConfiguration.IsHidingPopups)
                     {
                         gameServicesBuilder.SetShowConnectingPopup(false);
                     }
                     Debug.Log((object)"Building GPG services, implicitly attempts silent auth");
                     mAuthState       = AuthState.SilentPending;
                     mServices        = gameServicesBuilder.Build(configRef);
                     mEventsClient    = new NativeEventClient(new GooglePlayGames.Native.PInvoke.EventManager(mServices));
                     mQuestsClient    = new NativeQuestClient(new GooglePlayGames.Native.PInvoke.QuestManager(mServices));
                     mVideoClient     = new NativeVideoClient(new GooglePlayGames.Native.PInvoke.VideoManager(mServices));
                     mTurnBasedClient = new NativeTurnBasedMultiplayerClient(this, new TurnBasedManager(mServices));
                     mTurnBasedClient.RegisterMatchDelegate(mConfiguration.MatchDelegate);
                     mRealTimeClient = new NativeRealtimeMultiplayerClient(this, new RealtimeManager(mServices));
                     if (mConfiguration.EnableSavedGames)
                     {
                         mSavedGameClient = new NativeSavedGameClient(new GooglePlayGames.Native.PInvoke.SnapshotManager(mServices));
                     }
                     else
                     {
                         mSavedGameClient = new UnsupportedSavedGamesClient("You must enable saved games before it can be used. See PlayGamesClientConfiguration.Builder.EnableSavedGames.");
                     }
                     mAuthState   = AuthState.SilentPending;
                     mTokenClient = clientImpl.CreateTokenClient(true);
                     if (!GameInfo.WebClientIdInitialized() && (mConfiguration.IsRequestingIdToken || mConfiguration.IsRequestingAuthCode))
                     {
                         Logger.e("Server Auth Code and ID Token require web clientId to configured.");
                     }
                     mTokenClient.SetWebClientId("683498632423-6p90updcgm6b67r4ucmhs82nkq1dc1mi.apps.googleusercontent.com");
                     mTokenClient.SetRequestAuthCode(mConfiguration.IsRequestingAuthCode, mConfiguration.IsForcingRefresh);
                     mTokenClient.SetRequestEmail(mConfiguration.IsRequestingEmail);
                     mTokenClient.SetRequestIdToken(mConfiguration.IsRequestingIdToken);
                     mTokenClient.SetHidePopups(mConfiguration.IsHidingPopups);
                     mTokenClient.AddOauthScopes(scopes);
                     mTokenClient.SetAccountName(mConfiguration.AccountName);
                 }
             }
         }
     }
 }
예제 #9
0
 public EventsClientTests()
 {
     EventsClient = Helper.GetAuthClient().Events;
 }
예제 #10
0
 public void SetUp()
 {
     eventsClient = new EventsClient();
 }