Exemplo n.º 1
0
 public void AcceptInvitation(string invitationId, RealTimeMultiplayerListener listener)
 {
     Logger.d("AndroidRtmpClient.AcceptInvitation " + invitationId);
     if (!this.PrepareToCreateRoom("AcceptInvitation", listener))
     {
         return;
     }
     this.mRtmpListener = listener;
     this.mClient.ClearInvitationIfFromNotification(invitationId);
     this.mClient.CallClientApi("rtmp accept invitation", delegate
     {
         Logger.d("Accepting invite via support lib.");
         AndroidJavaClass @class = JavaUtil.GetClass("com.google.example.games.pluginsupport.RtmpUtils");
         @class.CallStatic("accept", new object[]
         {
             this.mClient.GHManager.GetApiClient(),
             invitationId,
             new AndroidRtmpClient.RoomUpdateProxy(this),
             new AndroidRtmpClient.RoomStatusUpdateProxy(this),
             new AndroidRtmpClient.RealTimeMessageReceivedProxy(this)
         });
     }, delegate(bool success)
     {
         if (!success)
         {
             this.FailRoomSetup("Failed to accept invitation because GoogleApiClient was disconnected");
         }
     });
 }
Exemplo n.º 2
0
 public void AcceptFromInbox(RealTimeMultiplayerListener listener)
 {
     Logger.d("AndroidRtmpClient.AcceptFromInbox.");
     if (!this.PrepareToCreateRoom("AcceptFromInbox", listener))
     {
         return;
     }
     this.mRtmpListener = listener;
     this.mClient.CallClientApi("rtmp accept with inbox screen", delegate
     {
         AndroidJavaClass @class        = JavaUtil.GetClass("com.google.example.games.pluginsupport.InvitationInboxHelperActivity");
         this.mLaunchedExternalActivity = true;
         @class.CallStatic("launch", new object[]
         {
             true,
             this.mClient.GetActivity(),
             new AndroidRtmpClient.InvitationInboxProxy(this),
             Logger.DebugLogEnabled
         });
     }, delegate(bool success)
     {
         if (!success)
         {
             this.FailRoomSetup("Failed to accept from inbox because GoogleApiClient was disconnected");
         }
     });
 }
Exemplo n.º 3
0
        public static void Clear()
        {
            // call the OnLeftRoom() callback if needed
            if (sDeliveredRoomConnected)
            {
                Logger.d("iOSRtmpClear: looks like we must call the OnLeftRoom() callback.");
                if (sRtmpListener != null)
                {
                    Logger.d("Calling OnLeftRoom() callback.");
                    sRtmpListener.OnLeftRoom();
                }
            }
            else
            {
                Logger.d("iOSRtmpClear: no need to call OnLeftRoom() callback.");
            }

            sDeliveredRoomConnected = false;
            mConnectedParticipants  = null;
            mAllParticipants        = null;
            sRtmpListener           = null;
            sRtmpActive             = false;
            mAccumulatedProgress    = 0.0f;
            Logger.d("iOSRtmpClear: RTMP cleared.");
        }
Exemplo n.º 4
0
 public void CreateQuickGame(int minOpponents, int maxOpponents, int variant, RealTimeMultiplayerListener listener)
 {
     Logger.d(string.Format("AndroidRtmpClient.CreateQuickGame, opponents={0}-{1}, variant={2}", minOpponents, maxOpponents, variant));
     if (!this.PrepareToCreateRoom("CreateQuickGame", listener))
     {
         return;
     }
     this.mRtmpListener = listener;
     this.mVariant      = variant;
     this.mClient.CallClientApi("rtmp create quick game", delegate
     {
         AndroidJavaClass @class = JavaUtil.GetClass("com.google.example.games.pluginsupport.RtmpUtils");
         @class.CallStatic("createQuickGame", new object[]
         {
             this.mClient.GHManager.GetApiClient(),
             minOpponents,
             maxOpponents,
             variant,
             new AndroidRtmpClient.RoomUpdateProxy(this),
             new AndroidRtmpClient.RoomStatusUpdateProxy(this),
             new AndroidRtmpClient.RealTimeMessageReceivedProxy(this)
         });
     }, delegate(bool success)
     {
         if (!success)
         {
             this.FailRoomSetup("Failed to create game because GoogleApiClient was disconnected");
         }
     });
 }
Exemplo n.º 5
0
 public void CreateQuickGame(uint minOpponents, uint maxOpponents, uint variant, ulong exclusiveBitMask, RealTimeMultiplayerListener listener)
 {
     Assert.IsTrue(this.listener == null || this.listener == listener);
     this.listener = listener;
     Assert.IsFalse(roomConnecting);
     Assert.IsFalse(roomConnected);
     SceneMaster.instance.Async(() => {
         roomConnecting = !Input.GetKey(KeyCode.F);
         listener.OnRoomSetupProgress(roomConnecting ? 20 : 0);
     }, Utils.DUMMY_PLAY_GAMES_REAL_TIME_ASYNC_DELAY);
     SceneMaster.instance.Async(() => {
         if (!roomConnecting || roomConnected)
         {
             return;
         }
         roomConnected = !Input.GetKey(KeyCode.F);
         if (roomConnected)
         {
             participants = new List <Participant> ();
             participants.Add(new Participant("me", "me42", Participant.ParticipantStatus.Joined, new Player("me player", "player42", null), true));
             participants.Add(new Participant("other", "other43", Participant.ParticipantStatus.Joined, new Player("other player", "player43", null), true));
         }
         listener.OnRoomConnected(roomConnected);
     }, 2f * Utils.DUMMY_PLAY_GAMES_REAL_TIME_ASYNC_DELAY);
 }
Exemplo n.º 6
0
        // called from game thread
        public void CreateQuickGame(int minOpponents, int maxOpponents, int variant,
                                    RealTimeMultiplayerListener listener)
        {
            Logger.d(string.Format("AndroidRtmpClient.CreateQuickGame, opponents={0}-{1}, " +
                                   "variant={2}", minOpponents, maxOpponents, variant));

            if (!PrepareToCreateRoom("CreateQuickGame", listener))
            {
                return;
            }

            mRtmpListener = listener;
            mVariant      = variant;
            mClient.CallClientApi("rtmp create quick game", () => {
                AndroidJavaClass rtmpUtil = JavaUtil.GetClass(JavaConsts.SupportRtmpUtilsClass);
                rtmpUtil.CallStatic("createQuickGame", mClient.GHManager.GetApiClient(),
                                    minOpponents, maxOpponents, variant,
                                    new RoomUpdateProxy(this), new RoomStatusUpdateProxy(this),
                                    new RealTimeMessageReceivedProxy(this));
            }, (bool success) => {
                if (!success)
                {
                    FailRoomSetup("Failed to create game because GoogleApiClient was disconnected");
                }
            });
        }
Exemplo n.º 7
0
 public RoomStatusUpdateCallbackProxy(AndroidRealTimeMultiplayerClient parent,
                                      RealTimeMultiplayerListener listener) : base(
         "com/google/games/bridge/RoomStatusUpdateCallbackProxy$Callback")
 {
     mListener = listener;
     mParent   = parent;
 }
Exemplo n.º 8
0
        public void AcceptFromInbox(RealTimeMultiplayerListener listener)
        {
            lock (mSessionLock)
            {
                if (GetRoomStatus() == RoomStatus.Active)
                {
                    OurUtils.Logger.e("Received attempt to accept invitation without cleaning up " +
                                      "active session.");
                    listener.OnRoomConnected(false);
                    return;
                }

                AndroidHelperFragment.ShowInvitationInboxUI((status, invitation) =>
                {
                    if (status != UIStatus.Valid)
                    {
                        OurUtils.Logger.d("User did not complete invitation screen.");
                        listener.OnRoomConnected(false);
                        return;
                    }

                    mInvitation = invitation;

                    AcceptInvitation(mInvitation.InvitationId, listener);
                });
            }
        }
Exemplo n.º 9
0
        // called from game thread
        public void CreateWithInvitationScreen(int minOpponents, int maxOpponents, int variant,
                                               RealTimeMultiplayerListener listener)
        {
            Logger.d(string.Format("AndroidRtmpClient.CreateWithInvitationScreen, " +
                                   "opponents={0}-{1}, variant={2}", minOpponents, maxOpponents, variant));

            if (!PrepareToCreateRoom("CreateWithInvitationScreen", listener))
            {
                return;
            }

            mRtmpListener = listener;
            mVariant      = variant;
            mClient.CallClientApi("rtmp create with invitation screen", () => {
                AndroidJavaClass klass = JavaUtil.GetClass(
                    JavaConsts.SupportSelectOpponentsHelperActivity);
                mLaunchedExternalActivity = true;
                klass.CallStatic("launch", true, mClient.GetActivity(),
                                 new SelectOpponentsProxy(this), Logger.DebugLogEnabled,
                                 minOpponents, maxOpponents);
            }, (bool success) => {
                if (!success)
                {
                    FailRoomSetup("Failed to create game because GoogleApiClient was disconnected");
                }
            });
        }
Exemplo n.º 10
0
        private void OnRealTimeMessageReceived(AndroidJavaObject message)
        {
            Logger.d("AndroidClient.OnRealTimeMessageReceived.");

            if (!CheckRtmpActive("OnRealTimeMessageReceived"))
            {
                return;
            }

            RealTimeMultiplayerListener listener = mRtmpListener;

            if (listener != null)
            {
                byte[] messageData;
                using (AndroidJavaObject messageBytes = message.Call <AndroidJavaObject>("getMessageData")) {
                    messageData = JavaUtil.ConvertByteArray(messageBytes);
                }
                bool   isReliable = message.Call <bool>("isReliable");
                string senderId   = message.Call <string>("getSenderParticipantId");

                PlayGamesHelperObject.RunOnGameThread(() => {
                    listener.OnRealTimeMessageReceived(isReliable, senderId, messageData);
                });
            }
            message.Dispose();
        }
Exemplo n.º 11
0
        public void AcceptFromInbox(RealTimeMultiplayerListener listener)
        {
            var listenerOnGameThread = new OnGameThreadForwardingListener(listener);

            lock (mSessionLock)
            {
                if (GetRoomStatus() == RoomStatus.Active)
                {
                    OurUtils.Logger.e("Received attempt to accept invitation without cleaning up " +
                                      "active session.");
                    listenerOnGameThread.OnRoomConnected(false);
                    return;
                }

                AndroidHelperFragment.ShowInvitationInboxUI((status, invitation) =>
                {
                    if (status == UIStatus.NotAuthorized)
                    {
                        mAndroidClient.SignOut((() => listenerOnGameThread.OnRoomConnected(false)));
                        return;
                    }

                    if (status != UIStatus.Valid)
                    {
                        OurUtils.Logger.d("User did not complete invitation screen.");
                        listenerOnGameThread.OnRoomConnected(false);
                        return;
                    }

                    mInvitation = invitation;

                    AcceptInvitation(mInvitation.InvitationId, listener);
                });
            }
        }
 internal RoomSession(RealtimeManager manager, RealTimeMultiplayerListener listener)
 {
     mManager  = Misc.CheckNotNull(manager);
     mListener = new OnGameThreadForwardingListener(listener);
     EnterState(new BeforeRoomCreateStartedState(this), false);
     mStillPreRoomCreation = true;
 }
Exemplo n.º 13
0
 public void CreateWithInvitationScreen(int minOpponents, int maxOpponents, int variant, RealTimeMultiplayerListener listener)
 {
     Logger.d(string.Format("AndroidRtmpClient.CreateWithInvitationScreen, opponents={0}-{1}, variant={2}", minOpponents, maxOpponents, variant));
     if (!this.PrepareToCreateRoom("CreateWithInvitationScreen", listener))
     {
         return;
     }
     this.mRtmpListener = listener;
     this.mVariant      = variant;
     this.mClient.CallClientApi("rtmp create with invitation screen", delegate
     {
         AndroidJavaClass @class        = JavaUtil.GetClass("com.google.example.games.pluginsupport.SelectOpponentsHelperActivity");
         this.mLaunchedExternalActivity = true;
         @class.CallStatic("launch", new object[]
         {
             true,
             this.mClient.GetActivity(),
             new AndroidRtmpClient.SelectOpponentsProxy(this),
             Logger.DebugLogEnabled,
             minOpponents,
             maxOpponents
         });
     }, delegate(bool success)
     {
         if (!success)
         {
             this.FailRoomSetup("Failed to create game because GoogleApiClient was disconnected");
         }
     });
 }
Exemplo n.º 14
0
        private void OnRoomConnected(int statusCode, AndroidJavaObject room)
        {
            Logger.d("AndroidClient.OnRoomConnected, status " + statusCode);

            if (!CheckRtmpActive("OnRoomConnected"))
            {
                return;
            }

            mRoom = room;
            UpdateRoom();
            if (statusCode != 0)
            {
                FailRoomSetup("OnRoomConnected error code " + statusCode);
            }
            else
            {
                Logger.d("AndroidClient.OnRoomConnected: room setup succeeded!");
                RealTimeMultiplayerListener listener = mRtmpListener;
                if (listener != null)
                {
                    Logger.d("Invoking callback OnRoomConnected(true) to report success.");
                    PlayGamesHelperObject.RunOnGameThread(() => {
                        mDeliveredRoomConnected = true;
                        listener.OnRoomConnected(true);
                    });
                }
            }
        }
Exemplo n.º 15
0
        public void CreateQuickGame(uint minOpponents, uint maxOpponents, uint variant,
                                    RealTimeMultiplayerListener listener)
        {
            lock (mSessionLock) {
                var newSession = new RoomSession(mRealtimeManager, listener);
                if (mCurrentSession.IsActive())
                {
                    Logger.e("Received attempt to create a new room without cleaning up the old one.");
                    newSession.LeaveRoom();
                    return;
                }

                mCurrentSession = newSession;

                // We're holding the session lock, so no other threads could have torn down the session
                // in the meantime.

                using (var configBuilder = RealtimeRoomConfigBuilder.Create()) {
                    var config = configBuilder.SetMinimumAutomatchingPlayers(minOpponents)
                                 .SetMaximumAutomatchingPlayers(maxOpponents)
                                 .SetVariant(variant)
                                 .Build();

                    using (config) {
                        using (var helper = HelperForSession(newSession)) {
                            newSession.StartRoomCreation(mNativeClient.GetUserId(),
                                                         () => mRealtimeManager.CreateRoom(config, helper,
                                                                                           newSession.HandleRoomResponse)
                                                         );
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
        // called from UI thread
        private void Clear(string reason)
        {
            Logger.d("RtmpClear: clearing RTMP (reason: " + reason + ").");

            // leave the room, if we have one
            if (mRoom != null)
            {
                Logger.d("RtmpClear: Room still active, so leaving room.");
                string roomId = mRoom.Call <string>("getRoomId");
                Logger.d("RtmpClear: room id to leave is " + roomId);

                // TODO: we are not specifying the callback from this API call to get
                // notified of when we *actually* leave the room. Perhaps we should do that,
                // in order to prevent the case where the developer tries to create a room
                // too soon after leaving the previous room, resulting in errors.
                mClient.GHManager.CallGmsApi("games.Games", "RealTimeMultiplayer", "leave",
                                             new NoopProxy(JavaConsts.RoomUpdateListenerClass), roomId);
                Logger.d("RtmpClear: left room.");
                mRoom = null;
            }
            else
            {
                Logger.d("RtmpClear: no room active.");
            }

            // call the OnLeftRoom() callback if needed
            if (mDeliveredRoomConnected)
            {
                Logger.d("RtmpClear: looks like we must call the OnLeftRoom() callback.");
                RealTimeMultiplayerListener listener = mRtmpListener;
                if (listener != null)
                {
                    Logger.d("Calling OnLeftRoom() callback.");
                    PlayGamesHelperObject.RunOnGameThread(() => {
                        listener.OnLeftRoom();
                    });
                }
            }
            else
            {
                Logger.d("RtmpClear: no need to call OnLeftRoom() callback.");
            }

            mLeaveRoomRequested     = false;
            mDeliveredRoomConnected = false;
            mRoom = null;
            mConnectedParticipants = null;
            mAllParticipants       = null;
            mSelf                     = null;
            mRtmpListener             = null;
            mVariant                  = 0;
            mRtmpActive               = false;
            mAccumulatedProgress      = 0.0f;
            mLastReportedProgress     = 0.0f;
            mLaunchedExternalActivity = false;
            Logger.d("RtmpClear: RTMP cleared.");
        }
Exemplo n.º 17
0
        public void AcceptInvitation(string invitationId, RealTimeMultiplayerListener listener)
        {
            var listenerOnGameThread = new OnGameThreadForwardingListener(listener);

            lock (mSessionLock)
            {
                if (GetRoomStatus() == RoomStatus.Active)
                {
                    OurUtils.Logger.e("Received attempt to accept invitation without cleaning up " +
                                      "active session.");
                    listenerOnGameThread.OnRoomConnected(false);
                    return;
                }

                FindInvitation(invitationId, fail => listenerOnGameThread.OnRoomConnected(false),
                               invitation =>
                {
                    mInvitation = invitation;

                    using (var roomConfigClass =
                               new AndroidJavaClass("com.google.android.gms.games.multiplayer.realtime.RoomConfig"))
                        using (var roomUpdateCallback = new AndroidJavaObject(
                                   "com.google.games.bridge.RoomUpdateCallbackProxy",
                                   new RoomUpdateCallbackProxy(/* parent= */ this, listenerOnGameThread)))
                            using (var roomConfigBuilder =
                                       roomConfigClass.CallStatic <AndroidJavaObject>("builder", roomUpdateCallback))
                                using (var messageReceivedListener =
                                           new AndroidJavaObject(
                                               "com.google.games.bridge.RealTimeMessageReceivedListenerProxy",
                                               new MessageReceivedListenerProxy(listenerOnGameThread)))
                                    using (roomConfigBuilder.Call <AndroidJavaObject>("setOnMessageReceivedListener",
                                                                                      messageReceivedListener))
                                        using (var roomStatusUpdateCallback =
                                                   new AndroidJavaObject("com.google.games.bridge.RoomStatusUpdateCallbackProxy",
                                                                         new RoomStatusUpdateCallbackProxy(this, listenerOnGameThread)))
                                            using (roomConfigBuilder.Call <AndroidJavaObject>("setRoomStatusUpdateCallback",
                                                                                              roomStatusUpdateCallback))
                                                using (roomConfigBuilder.Call <AndroidJavaObject>("setInvitationIdToAccept", invitationId))
                                                {
                                                    mRoomConfig = roomConfigBuilder.Call <AndroidJavaObject>("build");
                                                    mListener   = listenerOnGameThread;

                                                    using (var task = mRtmpClient.Call <AndroidJavaObject>("join", mRoomConfig))
                                                    {
                                                        AndroidTaskUtils.AddOnFailureListener(
                                                            task,
                                                            e =>
                                                        {
                                                            listenerOnGameThread.OnRoomConnected(false);
                                                            CleanSession();
                                                        });
                                                    }
                                                }
                });
            }
        }
Exemplo n.º 18
0
 public void AcceptFromInbox(RealTimeMultiplayerListener listener)
 {
     Logger.d(string.Format("iOSRtmpClient.AcceptFromInbox"));
     if (!PrepareToCreateRoom("CreateWithInvitationScreen", listener))
     {
         return;
     }
     GPGSRtmpShowAllInvitations(RtmpRoomStatusChangedCallback,
                                RtmpParticipantListChangedCallback, RtmpDataReceivedCallback, RtmpRoomErrorCallback);
 }
Exemplo n.º 19
0
        /**
         *
         * Creating rooms
         *
         */

        public void CreateQuickGame(int minOpponents, int maxOpponents, int variant, RealTimeMultiplayerListener listener)
        {
            Logger.d(string.Format("iOSRtmpClient.CreateQuickGame, opponents = {0}-{1}, variant = {2}",
                                   minOpponents, maxOpponents, variant));
            if (!PrepareToCreateRoom("CreateQuickGame", listener))
            {
                return;
            }
            GPGSRtmpCreateQuickGame(minOpponents, maxOpponents, variant, RtmpRoomStatusChangedCallback,
                                    RtmpParticipantListChangedCallback, RtmpDataReceivedCallback, RtmpRoomErrorCallback);
        }
Exemplo n.º 20
0
        public void AcceptInvitation(string invitationId, RealTimeMultiplayerListener listener)
        {
            Logger.d(string.Format("iOSRtmpClient.AcceptInvitation, id= " + invitationId));

            if (!PrepareToCreateRoom("CreateWithInvitationScreen", listener))
            {
                return;
            }
            GPGSRtmpAcceptRoomWithId(invitationId, RtmpRoomStatusChangedCallback,
                                     RtmpParticipantListChangedCallback, RtmpDataReceivedCallback, RtmpRoomErrorCallback);
        }
Exemplo n.º 21
0
 private void CleanSession()
 {
     lock (mSessionLock)
     {
         mRoom              = null;
         mRoomConfig        = null;
         mListener          = null;
         mInvitation        = null;
         mMinPlayersToStart = 0;
     }
 }
 public void AcceptFromInbox(RealTimeMultiplayerListener listener)
 {
     lock (mSessionLock)
     {
         RoomSession newRoom = new RoomSession(mRealtimeManager, listener);
         if (mCurrentSession.IsActive())
         {
             Logger.e("Received attempt to accept invitation without cleaning up active session.");
             newRoom.LeaveRoom();
         }
         else
         {
             mCurrentSession           = newRoom;
             mCurrentSession.ShowingUI = true;
             mRealtimeManager.ShowRoomInboxUI(delegate(RealtimeManager.RoomInboxUIResponse response)
             {
                 mCurrentSession.ShowingUI = false;
                 if (response.ResponseStatus() != CommonErrorStatus.UIStatus.VALID)
                 {
                     Logger.d("User did not complete invitation screen.");
                     newRoom.LeaveRoom();
                 }
                 else
                 {
                     GooglePlayGames.Native.PInvoke.MultiplayerInvitation invitation   = response.Invitation();
                     GooglePlayGames.Native.PInvoke.RealTimeEventListenerHelper helper = HelperForSession(newRoom);
                     try
                     {
                         Logger.d("About to accept invitation " + invitation.Id());
                         newRoom.StartRoomCreation(mNativeClient.GetUserId(), delegate
                         {
                             mRealtimeManager.AcceptInvitation(invitation, helper, delegate(RealtimeManager.RealTimeRoomResponse acceptResponse)
                             {
                                 using (invitation)
                                 {
                                     newRoom.HandleRoomResponse(acceptResponse);
                                     newRoom.SetInvitation(invitation.AsInvitation());
                                 }
                             });
                         });
                     }
                     finally
                     {
                         if (helper != null)
                         {
                             ((IDisposable)helper).Dispose();
                         }
                     }
                 }
             });
         }
     }
 }
Exemplo n.º 23
0
 private void Clear(string reason)
 {
     Logger.d("RtmpClear: clearing RTMP (reason: " + reason + ").");
     if (this.mRoom != null)
     {
         Logger.d("RtmpClear: Room still active, so leaving room.");
         string text = this.mRoom.Call <string>("getRoomId", new object[0]);
         Logger.d("RtmpClear: room id to leave is " + text);
         this.mClient.GHManager.CallGmsApi("games.Games", "RealTimeMultiplayer", "leave", new object[]
         {
             new NoopProxy("com.google.android.gms.games.multiplayer.realtime.RoomUpdateListener"),
             text
         });
         Logger.d("RtmpClear: left room.");
         this.mRoom = null;
     }
     else
     {
         Logger.d("RtmpClear: no room active.");
     }
     if (this.mDeliveredRoomConnected)
     {
         Logger.d("RtmpClear: looks like we must call the OnLeftRoom() callback.");
         RealTimeMultiplayerListener listener = this.mRtmpListener;
         if (listener != null)
         {
             Logger.d("Calling OnLeftRoom() callback.");
             PlayGamesHelperObject.RunOnGameThread(delegate
             {
                 listener.OnLeftRoom();
             });
         }
     }
     else
     {
         Logger.d("RtmpClear: no need to call OnLeftRoom() callback.");
     }
     this.mLeaveRoomRequested     = false;
     this.mDeliveredRoomConnected = false;
     this.mRoom = null;
     this.mConnectedParticipants = null;
     this.mAllParticipants       = null;
     this.mSelf                     = null;
     this.mRtmpListener             = null;
     this.mVariant                  = 0;
     this.mRtmpActive               = false;
     this.mAccumulatedProgress      = 0f;
     this.mLastReportedProgress     = 0f;
     this.mLaunchedExternalActivity = false;
     Logger.d("RtmpClear: RTMP cleared.");
 }
Exemplo n.º 24
0
        // called from UI thread
        private void FailRoomSetup(string reason)
        {
            Logger.d("Failing room setup: " + reason);
            RealTimeMultiplayerListener listener = mRtmpListener;

            Clear("Room setup failed: " + reason);

            if (listener != null)
            {
                Logger.d("Invoking callback OnRoomConnected(false) to signal failure.");
                PlayGamesHelperObject.RunOnGameThread(() => {
                    listener.OnRoomConnected(false);
                });
            }
        }
        public void AcceptFromInbox(RealTimeMultiplayerListener listener)
        {
            lock (mSessionLock)
            {
                var newRoom = new RoomSession(mRealtimeManager, listener);
                if (mCurrentSession.IsActive())
                {
                    Logger.e("Received attempt to accept invitation without cleaning up " +
                             "active session.");
                    newRoom.LeaveRoom();
                    return;
                }

                // The user accepted an invitation from the inbox, this is now the current room.
                mCurrentSession = newRoom;

                mRealtimeManager.ShowRoomInboxUI(
                    response =>
                {
                    if (response.ResponseStatus() != Status.UIStatus.VALID)
                    {
                        Logger.d("User did not complete invitation screen.");
                        newRoom.LeaveRoom();
                        return;
                    }

                    // We are not cleaning up the invitation here to workaround a bug in the
                    // C++ SDK where it holds a reference to un-owned memory rather than making a
                    // copy. This is cleaned up after the callback comes back instead.
                    var invitation = response.Invitation();

                    using (var helper = HelperForSession(newRoom))
                    {
                        Logger.d("About to accept invitation " + invitation.Id());
                        newRoom.StartRoomCreation(mNativeClient.GetUserId(),
                                                  () => mRealtimeManager.AcceptInvitation(invitation, helper,
                                                                                          acceptResponse =>
                        {
                            // Clean up the invitation here (see above comment).
                            using (invitation)
                            {
                                newRoom.HandleRoomResponse(acceptResponse);
                            }
                        }));
                    }
                });
            }
        }
        public void AcceptInvitation(string invitationId, RealTimeMultiplayerListener listener)
        {
            lock (mSessionLock)
            {
                var newRoom = new RoomSession(mRealtimeManager, listener);
                if (mCurrentSession.IsActive())
                {
                    Logger.e("Received attempt to accept invitation without cleaning up " +
                             "active session.");
                    newRoom.LeaveRoom();
                    return;
                }

                mCurrentSession = newRoom;

                mRealtimeManager.FetchInvitations(response =>
                {
                    if (!response.RequestSucceeded())
                    {
                        Logger.e("Couldn't load invitations.");
                        newRoom.LeaveRoom();
                        return;
                    }

                    foreach (var invitation in response.Invitations())
                    {
                        using (invitation)
                        {
                            if (invitation.Id().Equals(invitationId))
                            {
                                using (var helper = HelperForSession(newRoom))
                                {
                                    newRoom.StartRoomCreation(mNativeClient.GetUserId(),
                                                              () => mRealtimeManager.AcceptInvitation(
                                                                  invitation, helper, newRoom.HandleRoomResponse));
                                    return;
                                }
                            }
                        }
                    }

                    Logger.e("Room creation failed since we could not find invitation with ID "
                             + invitationId);
                    newRoom.LeaveRoom();
                });
            }
        }
        public void CreateWithInvitationScreen(uint minOpponents, uint maxOppponents, uint variant,
                                               RealTimeMultiplayerListener listener)
        {
            lock (mSessionLock)
            {
                var newRoom = new RoomSession(mRealtimeManager, listener);

                if (mCurrentSession.IsActive())
                {
                    Logger.e("Received attempt to create a new room without cleaning up the old one.");
                    newRoom.LeaveRoom();
                    return;
                }

                // The user attempted to create a room via the invitation screen, this is now the new
                // current room.
                mCurrentSession = newRoom;

                mRealtimeManager.ShowPlayerSelectUI(minOpponents, maxOppponents, true,
                                                    response =>
                {
                    if (response.Status() != Status.UIStatus.VALID)
                    {
                        Logger.d("User did not complete invitation screen.");
                        newRoom.LeaveRoom();
                        return;
                    }

                    using (var configBuilder = RealtimeRoomConfigBuilder.Create())
                    {
                        configBuilder.SetVariant(variant);
                        configBuilder.PopulateFromUIResponse(response);
                        using (var config = configBuilder.Build())
                        {
                            using (var helper = HelperForSession(newRoom))
                            {
                                newRoom.StartRoomCreation(mNativeClient.GetUserId(),
                                                          () => mRealtimeManager.CreateRoom(config, helper,
                                                                                            newRoom.HandleRoomResponse));
                            }
                        }
                    }
                });
            }
        }
Exemplo n.º 28
0
        // prepares to create a room
        private bool PrepareToCreateRoom(string method, RealTimeMultiplayerListener listener)
        {
            if (sRtmpActive)
            {
                Logger.e("Cannot call " + method + " while a real-time game is active.");
                if (listener != null)
                {
                    Logger.d("Notifying listener of failure to create room.");
                    listener.OnRoomConnected(false);
                }
                return(false);
            }

            mAccumulatedProgress = 0.0f;
            sRtmpListener        = listener;
            sRtmpActive          = true;
            return(true);
        }
Exemplo n.º 29
0
        public void CreateQuickGame(int minOpponents, int maxOpponents, IList <string> playersToInvite, int variant,
                                    RealTimeMultiplayerListener listener)
        {
            Logger.d(string.Format("AndroidRtmpClient.CreateQuickGame, opponents={0}-{1}, player={2}" +
                                   "variant={3}", minOpponents, maxOpponents, playersToInvite, variant));

            if (!PrepareToCreateRoom("CreateQuickGame", listener))
            {
                return;
            }

            mRtmpListener = listener;
            mVariant      = variant;
            mClient.CallClientApi("rtmp create quick game", () =>
            {
                AndroidJavaClass rtmpUtil = JavaUtil.GetClass(JavaConsts.SupportRtmpUtilsClass);

                // Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(minOpponents, maxOpponents, 0);
                AndroidJavaClass RoomConfig         = new AndroidJavaClass("com.google.android.gms.games.multiplayer.realtime.RoomConfig");
                AndroidJavaObject autoMatchCriteria = RoomConfig.CallStatic <AndroidJavaObject>("createAutoMatchCriteria", minOpponents, maxOpponents, 0);

                //  IList<string> to java.util.ArrayList<String>
                AndroidJavaObject javaUtilArrayList = new AndroidJavaClass("java.utils.ArrayList");
                foreach (var player in playersToInvite)
                {
                    javaUtilArrayList.Call("add", player);
                }

                // public static void create(GoogleApiClient apiClient, ArrayList<String> playersToInvite, int variant, Bundle autoMatchCriteria,
                //              RoomUpdateListener roomUpdateListener, RoomStatusUpdateListener roomStatusUpdateListener, RealTimeMessageReceivedListener messageReceivedListener)
                rtmpUtil.CallStatic("create", mClient.GHManager.GetApiClient(), javaUtilArrayList, variant, autoMatchCriteria,
                                    new RoomUpdateProxy(this), new RoomStatusUpdateProxy(this),
                                    new RealTimeMessageReceivedProxy(this));
            }, (bool success) =>
            {
                if (!success)
                {
                    FailRoomSetup("Failed to create game because GoogleApiClient was disconnected");
                }
            });
        }
Exemplo n.º 30
0
        // called from game thread
        public void AcceptFromInbox(RealTimeMultiplayerListener listener)
        {
            Logger.d("AndroidRtmpClient.AcceptFromInbox.");
            if (!PrepareToCreateRoom("AcceptFromInbox", listener))
            {
                return;
            }

            mRtmpListener = listener;
            mClient.CallClientApi("rtmp accept with inbox screen", () => {
                AndroidJavaClass klass = JavaUtil.GetClass(
                    JavaConsts.SupportInvitationInboxHelperActivity);
                mLaunchedExternalActivity = true;
                klass.CallStatic("launch", true, mClient.GetActivity(),
                                 new InvitationInboxProxy(this), Logger.DebugLogEnabled);
            }, (bool success) => {
                if (!success)
                {
                    FailRoomSetup("Failed to accept from inbox because GoogleApiClient was disconnected");
                }
            });
        }
 // called from game thread
 public void CreateQuickGame(int minOpponents, int maxOpponents, int variant,
                                 RealTimeMultiplayerListener listener) {
     Logger.d(string.Format("AndroidRtmpClient.CreateQuickGame, opponents={0}-{1}, " + 
                            "variant={2}", minOpponents, maxOpponents, variant));
                            
     if (!PrepareToCreateRoom("CreateQuickGame", listener)) {
         return;
     }
     
     mRtmpListener = listener;
     mVariant = variant;
     mClient.CallClientApi("rtmp create quick game", () => {
         AndroidJavaClass rtmpUtil = JavaUtil.GetClass(JavaConsts.SupportRtmpUtilsClass);
         rtmpUtil.CallStatic("createQuickGame", mClient.GHManager.GetApiClient(),
                             minOpponents, maxOpponents, variant,
                             new RoomUpdateProxy(this), new RoomStatusUpdateProxy(this),
                             new RealTimeMessageReceivedProxy(this));
     }, (bool success) => {
         if (!success) {
             FailRoomSetup("Failed to create game because GoogleApiClient was disconnected");
         }
     });
 }
        public void CreateWithInvitationScreen(int minOpponents, int maxOppponents, int variant,
                                        RealTimeMultiplayerListener listener) {
            Logger.d(string.Format("iOSRtmpClient.CreateWithInvitationScreen, " +
                                   "opponents={0}-{1}, variant = {2}", minOpponents, maxOppponents, variant));
            if (!PrepareToCreateRoom("CreateWithInvitationScreen", listener)) {
                return;
            }

            GPGSRtmpCreateWithInviteScreen(minOpponents, maxOppponents, variant, RtmpRoomStatusChangedCallback, 
                                           RtmpParticipantListChangedCallback, RtmpDataReceivedCallback, RtmpRoomErrorCallback);
        }
		public void AcceptInvitation (string invitationId, RealTimeMultiplayerListener listener)
		{
			Logger.d(string.Format("iOSRtmpClient.AcceptInvitation, id= " + invitationId));

			if (!PrepareToCreateRoom("CreateWithInvitationScreen", listener)) {
				return;
			}
			GPGSRtmpAcceptRoomWithId(invitationId, RtmpRoomStatusChangedCallback, 
			                     RtmpParticipantListChangedCallback, RtmpDataReceivedCallback, RtmpRoomErrorCallback);
		}
        public void CreateQuickGame(int minOpponents, int maxOpponents, IList<string> playersToInvite, int variant,
                                RealTimeMultiplayerListener listener)
        {
            Logger.d(string.Format("AndroidRtmpClient.CreateQuickGame, opponents={0}-{1}, player={2}" +
                                   "variant={3}", minOpponents, maxOpponents, playersToInvite, variant));

            if (!PrepareToCreateRoom("CreateQuickGame", listener))
            {
                return;
            }

            mRtmpListener = listener;
            mVariant = variant;
            mClient.CallClientApi("rtmp create quick game", () =>
            {
                AndroidJavaClass rtmpUtil = JavaUtil.GetClass(JavaConsts.SupportRtmpUtilsClass);

                // Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(minOpponents, maxOpponents, 0);
                AndroidJavaClass RoomConfig = new AndroidJavaClass("com.google.android.gms.games.multiplayer.realtime.RoomConfig");
                AndroidJavaObject autoMatchCriteria = RoomConfig.CallStatic<AndroidJavaObject>("createAutoMatchCriteria", minOpponents, maxOpponents, 0);

                //  IList<string> to java.util.ArrayList<String>
                AndroidJavaObject javaUtilArrayList = new AndroidJavaClass("java.utils.ArrayList");
                foreach (var player in playersToInvite)
                {
                    javaUtilArrayList.Call("add", player);
                }

                // public static void create(GoogleApiClient apiClient, ArrayList<String> playersToInvite, int variant, Bundle autoMatchCriteria, 
                //              RoomUpdateListener roomUpdateListener, RoomStatusUpdateListener roomStatusUpdateListener, RealTimeMessageReceivedListener messageReceivedListener)
                rtmpUtil.CallStatic("create", mClient.GHManager.GetApiClient(), javaUtilArrayList, variant, autoMatchCriteria,  
                                    new RoomUpdateProxy(this), new RoomStatusUpdateProxy(this),
                                    new RealTimeMessageReceivedProxy(this));
            }, (bool success) =>
            {
                if (!success)
                {
                    FailRoomSetup("Failed to create game because GoogleApiClient was disconnected");
                }
            });
        }
 // called from UI thread
 private void Clear(string reason) {
     Logger.d("RtmpClear: clearing RTMP (reason: " + reason + ").");
     
     // leave the room, if we have one
     if (mRoom != null) {
         Logger.d("RtmpClear: Room still active, so leaving room.");
         string roomId = mRoom.Call<string>("getRoomId");
         Logger.d("RtmpClear: room id to leave is " + roomId);
         
         // TODO: we are not specifying the callback from this API call to get
         // notified of when we *actually* leave the room. Perhaps we should do that,
         // in order to prevent the case where the developer tries to create a room
         // too soon after leaving the previous room, resulting in errors.
         mClient.GHManager.CallGmsApi("games.Games" , "RealTimeMultiplayer", "leave",
                               new NoopProxy(JavaConsts.RoomUpdateListenerClass), roomId);
         Logger.d("RtmpClear: left room.");
         mRoom = null;
     } else {
         Logger.d("RtmpClear: no room active.");
     }
     
     // call the OnLeftRoom() callback if needed
     if (mDeliveredRoomConnected) {
         Logger.d("RtmpClear: looks like we must call the OnLeftRoom() callback.");
         RealTimeMultiplayerListener listener = mRtmpListener;
         if (listener != null) {
             Logger.d("Calling OnLeftRoom() callback.");
             PlayGamesHelperObject.RunOnGameThread(() => {
                 listener.OnLeftRoom();
             });
         }
     } else {
         Logger.d("RtmpClear: no need to call OnLeftRoom() callback.");
     }
     
     mLeaveRoomRequested = false;
     mDeliveredRoomConnected = false;
     mRoom = null;
     mConnectedParticipants = null;
     mAllParticipants = null;
     mSelf = null;            
     mRtmpListener = null;
     mVariant = 0;
     mRtmpActive = false;
     mAccumulatedProgress = 0.0f;
     mLastReportedProgress = 0.0f;
     mLaunchedExternalActivity = false;
     Logger.d("RtmpClear: RTMP cleared.");
 }
 // prepares to create a room
 private bool PrepareToCreateRoom(string method, RealTimeMultiplayerListener listener) {
     if (mRtmpActive) {
         Logger.e("Cannot call " + method + " while a real-time game is active.");
         if (listener != null) {
             Logger.d("Notifying listener of failure to create room.");
             listener.OnRoomConnected(false);
         }
         return false;
     }
     
     mAccumulatedProgress = 0.0f;
     mLastReportedProgress = 0.0f;
     mRtmpListener = listener;
     mRtmpActive = true;
     return true;        
 }
 // called from the game thread
 public void AcceptInvitation(string invitationId, RealTimeMultiplayerListener listener) {
     Logger.d("AndroidRtmpClient.AcceptInvitation " + invitationId);
     if (!PrepareToCreateRoom("AcceptInvitation", listener)) {
         return;
     }
     
     mRtmpListener = listener;
     mClient.ClearInvitationIfFromNotification(invitationId);
     mClient.CallClientApi("rtmp accept invitation", () => {
         Logger.d("Accepting invite via support lib.");
         AndroidJavaClass rtmpUtil = JavaUtil.GetClass(JavaConsts.SupportRtmpUtilsClass);
         rtmpUtil.CallStatic("accept", mClient.GHManager.GetApiClient(), invitationId,
                             new RoomUpdateProxy(this), new RoomStatusUpdateProxy(this),
                             new RealTimeMessageReceivedProxy(this));
     }, (bool success) => {
         if (!success) {
             FailRoomSetup("Failed to accept invitation because GoogleApiClient was disconnected");
         }
     });
 }
 // called from game thread
 public void AcceptFromInbox(RealTimeMultiplayerListener listener) {
     Logger.d("AndroidRtmpClient.AcceptFromInbox.");
     if (!PrepareToCreateRoom("AcceptFromInbox", listener)) {
         return;
     }
     
     mRtmpListener = listener;
     mClient.CallClientApi("rtmp accept with inbox screen", () => {
         AndroidJavaClass klass = JavaUtil.GetClass(
             JavaConsts.SupportInvitationInboxHelperActivity);
         mLaunchedExternalActivity = true;
         klass.CallStatic("launch", true, mClient.GetActivity(),
                          new InvitationInboxProxy(this), Logger.DebugLogEnabled);
     }, (bool success) => {
         if (!success) {
             FailRoomSetup("Failed to accept from inbox because GoogleApiClient was disconnected");
         }
     });
 }
 // called from game thread
 public void CreateWithInvitationScreen(int minOpponents, int maxOpponents, int variant,
         RealTimeMultiplayerListener listener) {
     Logger.d(string.Format("AndroidRtmpClient.CreateWithInvitationScreen, " + 
             "opponents={0}-{1}, variant={2}", minOpponents, maxOpponents, variant));
     
     if (!PrepareToCreateRoom("CreateWithInvitationScreen", listener)) {
         return;
     }
     
     mRtmpListener = listener;
     mVariant = variant;
     mClient.CallClientApi("rtmp create with invitation screen", () => {
         AndroidJavaClass klass = JavaUtil.GetClass(
                 JavaConsts.SupportSelectOpponentsHelperActivity);
         mLaunchedExternalActivity = true;
         klass.CallStatic("launch", true, mClient.GetActivity(),
                 new SelectOpponentsProxy(this), Logger.DebugLogEnabled,
                 minOpponents, maxOpponents);
     }, (bool success) => {
         if (!success) {
             FailRoomSetup("Failed to create game because GoogleApiClient was disconnected");
         }
     });
 }
		public void AcceptFromInbox (RealTimeMultiplayerListener listener)
		{
			Logger.d(string.Format("iOSRtmpClient.AcceptFromInbox"));
			if (!PrepareToCreateRoom("CreateWithInvitationScreen", listener)) {
				return;
			}
			GPGSRtmpShowAllInvitations (RtmpRoomStatusChangedCallback, 
			                           RtmpParticipantListChangedCallback, RtmpDataReceivedCallback, RtmpRoomErrorCallback);
		}
        public static void Clear() {

            // call the OnLeftRoom() callback if needed
            if (sDeliveredRoomConnected) {
                Logger.d("iOSRtmpClear: looks like we must call the OnLeftRoom() callback.");
                if (sRtmpListener != null) {
                    Logger.d("Calling OnLeftRoom() callback.");
                    sRtmpListener.OnLeftRoom();
                }
            } else {
                Logger.d("iOSRtmpClear: no need to call OnLeftRoom() callback.");
            }

            sDeliveredRoomConnected = false;
            mConnectedParticipants = null;
            mAllParticipants = null;
            sRtmpListener = null;
            sRtmpActive = false;
            mAccumulatedProgress = 0.0f;
            Logger.d("iOSRtmpClear: RTMP cleared.");


        }