/// <summary>
        /// Event handler called when the system delivers an invite notification.
        /// This can occur when the user accepts an invite that was sent to them by
        /// a friend (pull mode), or if they choose the "Join Session In Progress"
        /// option in their friends screen (push mode). The handler leaves the
        /// current session (if any), then joins the session referred to by the
        /// invite. It is not necessary to prompt the user before doing this, as
        /// the Guide will already have taken care of the necessary confirmations
        /// before the invite was delivered to you.
        /// </summary>
        public static void InviteAccepted(ScreenManager screenManager,
                                          InviteAcceptedEventArgs e)
        {
            // If we are already in a network session, leave it now.
            NetworkSessionComponent self = FindSessionComponent(screenManager.Game);

            if (self != null)
                self.Dispose();

            try
            {
                // Which local profiles should we include in this session?
                IEnumerable<SignedInGamer> localGamers =
                    ChooseGamers(NetworkSessionType.PlayerMatch, e.Gamer.PlayerIndex);

                // Begin an asynchronous join-from-invite operation.
                IAsyncResult asyncResult = NetworkSession.BeginJoinInvited(localGamers,
                                                                           null, null);

                // Use the loading screen to replace whatever screens were previously
                // active. This will completely reset the screen state, regardless of
                // whether we were in the menus or playing a game when the invite was
                // delivered. When the loading screen finishes, it will activate the
                // network busy screen, which displays an animation as it waits for
                // the join operation to complete.
                NetworkBusyScreen busyScreen = new NetworkBusyScreen(asyncResult);

                busyScreen.OperationCompleted += JoinInvitedOperationCompleted;

                LoadingScreen.Load(screenManager, false, null, new BackgroundScreen(),
                                                               busyScreen);
            }
            catch (Exception exception)
            {
                NetworkErrorScreen errorScreen = new NetworkErrorScreen(exception);

                LoadingScreen.Load(screenManager, false, null, new BackgroundScreen(),
                                                               new MainMenuScreen(screenManager.Game as ParentGame),
                                                               errorScreen);
            }
        }
        /// <summary>
        /// Begins the asynchronous process of joining a game from an invitation.
        /// </summary>
        void NetworkSession_InviteAccepted(object sender, InviteAcceptedEventArgs e)
        {
            if (Guide.IsTrialMode)
            {
                screenManager.invited = e.Gamer;

                string message = "Need to unlock full version before you can accept this invite.";
                MessageBoxScreen messageBox = new MessageBoxScreen(message);
                screenManager.AddScreen(messageBox);

                System.Console.WriteLine("Cannot accept invite yet because we're in trial mode");

                return;
            }

            // We will join the game from a method in this screen.
            MainMenuScreen mainMenu = null;

            // Keep the background screen and main menu screen but remove all others
            // to prepare for joining the game we were invited to.
            foreach (GameScreen screen in screenManager.GetScreens())
            {
                if (screen is BackgroundScreen)
                {
                    continue;
                }
                else if (screen is MainMenuScreen)
                {
                    mainMenu = screen as MainMenuScreen;
                }
                else
                {
                    // If there's an active network session, we'll need to end it
                    // before attempting to join a new one.
                    MethodInfo method = screen.GetType().GetMethod("EndSession");
                    if (method != null)
                    {
                        method.Invoke(screen, null);
                    }

                    // Now exit and remove this screen.
                    screen.ExitScreen();
                    screenManager.RemoveScreen(screen);
                }
            }

            // Now attempt to join the game to which we were invited!
            if (mainMenu != null)
                mainMenu.JoinInvitedGame();
        }
Beispiel #3
0
        /// <summary>
        /// This event handler will be called whenever the game recieves an invite
        /// notification. This can occur when the user accepts an invite that was
        /// sent to them by a friend (pull mode), or if they choose the "Join
        /// Session In Progress" option in their friends screen (push mode).
        /// The handler should leave the current session (if any), then join the
        /// session referred to by the invite. It is not necessary to prompt the
        /// user before doing this, as the Guide will already have taken care of
        /// the necessary confirmations before the invite was delivered to you.
        /// </summary>
        void InviteAcceptedEventHandler(object sender, InviteAcceptedEventArgs e)
        {
            DrawMessage("Joining session from invite...");

            // Leave the current network session.
            if (networkSession != null)
            {
                networkSession.Dispose();
                networkSession = null;
            }

            try
            {
                // Join a new session in response to the invite.
                networkSession = NetworkSession.JoinInvited(maxLocalGamers);

                HookSessionEvents();
            }
            catch (Exception error)
            {
                errorMessage = error.Message;
            }
        }
Beispiel #4
0
        void NetworkSession_InviteAccepted(object sender, InviteAcceptedEventArgs e)
        {
            // if this is from a session that other local gamers are already in
            if (e.IsCurrentSession)
            {
                //and that session is still running...
                if (session != null)
                    session.AddLocalGamer(e.Gamer);
            }
            else
            {
                if (session != null)
                {
                    session.Dispose();
                    session = null;
                }
                session = NetworkSession.JoinInvited(1);
                session.GamerJoined += session_GamerJoined;
            }

            //session.GameStarted
        }