/// <summary>
        /// Event handler for when the asynchronous create network session
        /// operation has completed.
        /// </summary>
        void CreateSessionOperationCompleted(object sender,
                                             OperationCompletedEventArgs e)
        {
            try
            {
                // End the asynchronous create network session operation.
                NetworkSession networkSession;
                try
                {
                    networkSession = NetworkSession.EndCreate(e.AsyncResult);
                    NetworkSessionComponent.Create(ScreenManager, networkSession);
                    // Go to the lobby screen. We pass null as the controlling player,
                    // because the lobby screen accepts input from all local players
                    // who are in the session, not just a single controlling player.
                    ScreenManager.AddScreen(new LobbyScreen(networkSession), null);
                }
                catch
                {
                    try
                    {
                        Game game = this.ScreenManager.Game;
                        game.Services.RemoveService(typeof(NetworkSession));
                        //game.Services.AddService(typeof(NetworkSession), networkSession);
                        LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(),
                                           new MainMenuScreen());
                    }
                    catch { }
                }

                // Create a component that will manage the session we just created.
            }
            catch (Exception exception)
            {
                NetworkErrorScreen errorScreen = new NetworkErrorScreen(exception);

                ScreenManager.AddScreen(errorScreen, ControllingPlayer);
            }
        }
Exemple #2
0
        /// <summary>
        /// Event handler for when the asynchronous join-from-invite
        /// operation has completed.
        /// </summary>
        static void JoinInvitedOperationCompleted(object sender,
                                                  OperationCompletedEventArgs e)
        {
            ScreenManager screenManager = ((GameScreen)sender).ScreenManager;

            try
            {
                // End the asynchronous join-from-invite operation.
                NetworkSession networkSession =
                    NetworkSession.EndJoinInvited(e.AsyncResult);

                // Create a component that will manage the session we just created.
                NetworkSessionComponent.Create(screenManager, networkSession);

                // Go to the lobby screen.
                screenManager.AddScreen(new LobbyScreen(networkSession), null);
            }
            catch (Exception exception)
            {
                screenManager.AddScreen(new MainMenuScreen(), null);
                screenManager.AddScreen(new NetworkErrorScreen(exception), null);
            }
        }
        /// <summary>
        /// Event handler for when the Create Session menu entry is selected.
        /// </summary>
        void CreateSessionMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            try
            {
                //  NetworkSessionComponent.LeaveSession(ScreenManager, e.PlayerIndex);
                NetworkSessionComponent.LeaveSessionWithoutAsking(ScreenManager, e.PlayerIndex);
            }
            catch { }

            try
            {
                // Which local profiles should we include in this session?
                IEnumerable <SignedInGamer> localGamers =
                    NetworkSessionComponent.ChooseGamers(sessionType,
                                                         ControllingPlayer.Value);

                // Begin an asynchronous create network session operation.
                IAsyncResult asyncResult = NetworkSession.BeginCreate(
                    sessionType, localGamers,
                    NetworkSessionComponent.MaxGamers,
                    0, null, null, null);

                // Activate the network busy screen, which will display
                // an animation until this operation has completed.
                NetworkBusyScreen busyScreen = new NetworkBusyScreen(asyncResult);

                busyScreen.OperationCompleted += CreateSessionOperationCompleted;

                ScreenManager.AddScreen(busyScreen, ControllingPlayer);
            }
            catch (Exception exception)
            {
                NetworkErrorScreen errorScreen = new NetworkErrorScreen(exception);

                ScreenManager.AddScreen(errorScreen, ControllingPlayer);
            }
        }
        /// <summary>
        /// Event handler for when the asynchronous join network session
        /// operation has completed.
        /// </summary>
        void JoinSessionOperationCompleted(object sender, OperationCompletedEventArgs e)
        {
            try
            {
                // End the asynchronous join network session operation.
                NetworkSession networkSession = NetworkSession.EndJoin(e.AsyncResult);

                // Create a component that will manage the session we just joined.
                NetworkSessionComponent.Create(ScreenManager, networkSession);

                // Go to the lobby screen. We pass null as the controlling player,
                // because the lobby screen accepts input from all local players
                // who are in the session, not just a single controlling player.
                ScreenManager.AddScreen(new LobbyScreen(networkSession), null);

                availableSessions.Dispose();
            }
            catch (Exception exception)
            {
                NetworkErrorScreen errorScreen = new NetworkErrorScreen(exception);

                ScreenManager.AddScreen(errorScreen, ControllingPlayer);
            }
        }
Exemple #5
0
 /// <summary>
 /// Event handler for when the End/Leave Session menu entry is selected.
 /// </summary>
 void LeaveSessionMenuEntrySelected(object sender, PlayerIndexEventArgs e)
 {
     NetworkSessionComponent.LeaveSession(ScreenManager, e.PlayerIndex);
 }