Ejemplo n.º 1
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)
                                                         );
                        }
                    }
                }
            }
        }
        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));
                            }
                        }
                    }
                });
            }
        }
 public void CreateQuickGame(uint minOpponents, uint maxOpponents, uint variant, ulong exclusiveBitMask, RealTimeMultiplayerListener listener)
 {
     lock (mSessionLock)
     {
         RoomSession 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();
         }
         else
         {
             mCurrentSession = newSession;
             Logger.d("QuickGame: Setting MinPlayersToStart = " + minOpponents);
             mCurrentSession.MinPlayersToStart = minOpponents;
             using (RealtimeRoomConfigBuilder realtimeRoomConfigBuilder = RealtimeRoomConfigBuilder.Create())
             {
                 RealtimeRoomConfig config = realtimeRoomConfigBuilder.SetMinimumAutomatchingPlayers(minOpponents).SetMaximumAutomatchingPlayers(maxOpponents).SetVariant(variant)
                                             .SetExclusiveBitMask(exclusiveBitMask)
                                             .Build();
                 using (config)
                 {
                     GooglePlayGames.Native.PInvoke.RealTimeEventListenerHelper helper = HelperForSession(newSession);
                     try
                     {
                         newSession.StartRoomCreation(mNativeClient.GetUserId(), delegate
                         {
                             mRealtimeManager.CreateRoom(config, helper, newSession.HandleRoomResponse);
                         });
                     }
                     finally
                     {
                         if (helper != null)
                         {
                             ((IDisposable)helper).Dispose();
                         }
                     }
                 }
             }
         }
     }
 }
 public void CreateWithInvitationScreen(uint minOpponents, uint maxOppponents, uint variant, RealTimeMultiplayerListener listener)
 {
     lock (mSessionLock)
     {
         RoomSession 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();
         }
         else
         {
             mCurrentSession           = newRoom;
             mCurrentSession.ShowingUI = true;
             RealtimeRoomConfig config;
             GooglePlayGames.Native.PInvoke.RealTimeEventListenerHelper helper;
             mRealtimeManager.ShowPlayerSelectUI(minOpponents, maxOppponents, true, delegate(PlayerSelectUIResponse response)
             {
                 mCurrentSession.ShowingUI = false;
                 if (response.Status() != CommonErrorStatus.UIStatus.VALID)
                 {
                     Logger.d("User did not complete invitation screen.");
                     newRoom.LeaveRoom();
                 }
                 else
                 {
                     mCurrentSession.MinPlayersToStart = (uint)((int)response.MinimumAutomatchingPlayers() + response.Count() + 1);
                     using (RealtimeRoomConfigBuilder realtimeRoomConfigBuilder = RealtimeRoomConfigBuilder.Create())
                     {
                         realtimeRoomConfigBuilder.SetVariant(variant);
                         realtimeRoomConfigBuilder.PopulateFromUIResponse(response);
                         config = realtimeRoomConfigBuilder.Build();
                         try
                         {
                             helper = HelperForSession(newRoom);
                             try
                             {
                                 newRoom.StartRoomCreation(mNativeClient.GetUserId(), delegate
                                 {
                                     mRealtimeManager.CreateRoom(config, helper, newRoom.HandleRoomResponse);
                                 });
                             }
                             finally
                             {
                                 if (helper != null)
                                 {
                                     ((IDisposable)helper).Dispose();
                                 }
                             }
                         }
                         finally
                         {
                             if (config != null)
                             {
                                 ((IDisposable)config).Dispose();
                             }
                         }
                     }
                 }
             });
         }
     }
 }