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();
                         }
                     }
                 }
             });
         }
     }
 }
        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);
                            }
                        }));
                    }
                });
            }
        }