Exemplo n.º 1
0
        public static IAsyncResult BeginCreate(
            NetworkSessionType sessionType,
            int maxLocalGamers,
            int maxGamers,
            AsyncCallback callback,
            Object asyncState
            )
        {
            if (maxLocalGamers != 1)
            {
                throw new ArgumentOutOfRangeException("Maximum local players can only be 1 on the iPhone.");
            }
            if (maxGamers < 2 || maxGamers > 8)
            {
                throw new ArgumentOutOfRangeException("Maximum number of gamers must be between 2 and 8.");
            }

            try
            {
                NetworkSessionAsynchronousCreate AsynchronousCreate = new NetworkSessionAsynchronousCreate(Create);
                return(AsynchronousCreate.BeginInvoke(sessionType, maxLocalGamers, maxGamers, callback, asyncState));
            }
            finally
            {
            }
        }
Exemplo n.º 2
0
 public static AvailableNetworkSessionCollection Find(
     NetworkSessionType sessionType,
     int maxLocalGamers,
     NetworkSessionProperties searchProperties)
 {
     return(EndFind(BeginFind(sessionType, -1, maxLocalGamers, searchProperties, null, null)));
 }
Exemplo n.º 3
0
        public void FindSession(NetworkSessionType sessionType, int maxLocalPlayers, NetworkSessionProperties properties)
        {
            // all sessions found
            AvailableNetworkSessionCollection availableSessions;
            // The session we'll join
            AvailableNetworkSession availableSession = null;

            availableSessions = NetworkSession.Find(sessionType, maxLocalPlayers, properties);

            // Get a session with available gamer slots
            foreach (AvailableNetworkSession curSession in availableSessions)
            {
                int TotalSessionSlots = curSession.OpenPublicGamerSlots + curSession.OpenPrivateGamerSlots;
                if (TotalSessionSlots > curSession.CurrentGamerCount)
                {
                    availableSession = curSession;
                }
            }

            // if a session was found, connect to it
            if (availableSession != null)
            {
                networkHelper.session = NetworkSession.Join(availableSession);
            }
        }
Exemplo n.º 4
0
        //Audio audioHelper, Cue mystery)
        /// <summary>
        /// Constructor fills in the menu contents.
        /// </summary>
        public CreateOrFindSessionScreen(ScreenManager screenManager, NetworkSessionType sessionType, AudioManager audioManager)
            : base(GetMenuTitle(sessionType), false)
        {
            networkHelper = new NetworkHelper();
            networkInterface = new NetworkInterface();
            networkInterface.InitNetwork(screenManager.Game);
            this.audioManager = audioManager;
            //this.audioHelper = audioHelper;
            //this.mystery = mystery;
            this.sessionType = sessionType;

            // Create our menu entries.
            MenuEntry createSessionMenuEntry = new MenuEntry(Resources.CreateSession);
            MenuEntry findSessionsMenuEntry = new MenuEntry(Resources.FindSessions);
            MenuEntry backMenuEntry = new MenuEntry(Resources.Back);

            // Hook up menu event handlers.
            createSessionMenuEntry.Selected += CreateSessionMenuEntrySelected;
            findSessionsMenuEntry.Selected += FindSessionsMenuEntrySelected;
            backMenuEntry.Selected += OnCancel;

            // Add entries to the menu.
            MenuEntries.Add(createSessionMenuEntry);
            MenuEntries.Add(findSessionsMenuEntry);
            MenuEntries.Add(backMenuEntry);
        }
Exemplo n.º 5
0
        public static NetworkSession Create(
            NetworkSessionType sessionType,
            IEnumerable <SignedInGamer> localGamers,
            int maxGamers,
            int privateGamerSlots,
            NetworkSessionProperties sessionProperties
            )
        {
            IAsyncResult result = BeginCreate(
                sessionType,
                localGamers,
                maxGamers,
                privateGamerSlots,
                sessionProperties,
                null,
                null
                );

            while (!result.IsCompleted)
            {
                if (!GamerServicesDispatcher.UpdateAsync())
                {
                    activeAction.IsCompleted = true;
                }
            }
            return(EndCreate(result));
        }
Exemplo n.º 6
0
 private static AvailableNetworkSessionCollection Find(NetworkSessionType sessionType, int hostGamer, int maxLocalGamers, NetworkSessionProperties searchProperties)
 {
   if (maxLocalGamers < 1 || maxLocalGamers > 4)
     throw new ArgumentOutOfRangeException("maxLocalGamers must be between 1 and 4.");
   else
     return new AvailableNetworkSessionCollection((IList<AvailableNetworkSession>) new List<AvailableNetworkSession>());
 }
Exemplo n.º 7
0
        /// <summary>
        /// Constructor fills in the menu contents.
        /// </summary>
        public CreateOrFindSessionScreen(ScreenManager screenManager, NetworkSessionType sessionType, AudioManager audioManager)//Audio audioHelper, Cue mystery)
            : base(GetMenuTitle(sessionType), false)
        {
            networkHelper    = new NetworkHelper();
            networkInterface = new NetworkInterface();
            networkInterface.InitNetwork(screenManager.Game);
            this.audioManager = audioManager;
            //this.audioHelper = audioHelper;
            //this.mystery = mystery;
            this.sessionType = sessionType;

            // Create our menu entries.
            MenuEntry createSessionMenuEntry = new MenuEntry(Resources.CreateSession);
            MenuEntry findSessionsMenuEntry  = new MenuEntry(Resources.FindSessions);
            MenuEntry backMenuEntry          = new MenuEntry(Resources.Back);

            // Hook up menu event handlers.
            createSessionMenuEntry.Selected += CreateSessionMenuEntrySelected;
            findSessionsMenuEntry.Selected  += FindSessionsMenuEntrySelected;
            backMenuEntry.Selected          += OnCancel;

            // Add entries to the menu.
            MenuEntries.Add(createSessionMenuEntry);
            MenuEntries.Add(findSessionsMenuEntry);
            MenuEntries.Add(backMenuEntry);
        }
Exemplo n.º 8
0
 private NetworkSession(NetworkSessionType sessionType, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties, bool isHost, int hostGamer, AvailableNetworkSession availableSession)
     : this()
 {
     if (sessionProperties == null)
     {
         throw new ArgumentNullException("sessionProperties");
     }
     this._allGamers        = new GamerCollection <NetworkGamer>();
     this._localGamers      = new GamerCollection <LocalNetworkGamer>();
     this._remoteGamers     = new GamerCollection <NetworkGamer>();
     this._previousGamers   = new GamerCollection <NetworkGamer>();
     this.hostingGamer      = (NetworkGamer)null;
     this.commandQueue      = new Queue <CommandEvent>();
     this.sessionType       = sessionType;
     this.maxGamers         = maxGamers;
     this.privateGamerSlots = privateGamerSlots;
     this.sessionProperties = sessionProperties;
     this.isHost            = isHost;
     this.hostGamerIndex    = hostGamer;
     if (isHost)
     {
         this.networkPeer = new MonoGamerPeer(this, (AvailableNetworkSession)null);
     }
     else if (this.networkPeer == null)
     {
         this.networkPeer = new MonoGamerPeer(this, availableSession);
     }
     this.commandQueue.Enqueue(new CommandEvent((ICommand) new CommandGamerJoined(hostGamer, this.isHost, true)));
 }
        public static NetworkSession Create(
            NetworkSessionType sessionType,            // Type of session being hosted.
            IEnumerable <SignedInGamer> localGamers,   // Maximum number of local players on the same gaming machine in this network session.
            int maxGamers,                             // Maximum number of players allowed in this network session.  For Zune-based games, this value must be between 2 and 8; 8 is the maximum number of players supported in the session.
            int privateGamerSlots,                     // Number of reserved private session slots created for the session. This value must be less than maximumGamers.
            NetworkSessionProperties sessionProperties // Properties of the session being created.
            )
        {
            try
            {
                if (maxGamers < 2 || maxGamers > 8)
                {
                    throw new ArgumentOutOfRangeException("Maximum number of gamers must be between 2 and 8.");
                }
                if (privateGamerSlots < 0 || privateGamerSlots > maxGamers)
                {
                    throw new ArgumentOutOfRangeException("Private session slots must be between 0 and maximum number of gamers.");
                }

                networkSessionType = sessionType;

                throw new NotImplementedException();
            }
            finally
            {
            }
        }
Exemplo n.º 10
0
        public void FindSession(NetworkSessionType sessionType, int maxLocalPlayers, NetworkSessionProperties properties)
        {
            // all sessions found
            AvailableNetworkSessionCollection availableSessions;
            // The session we'll join
            AvailableNetworkSession availableSession = null;

            availableSessions = NetworkSession.Find(sessionType, maxLocalPlayers, properties);

            // Get a session with available gamer slots
            foreach (AvailableNetworkSession  curSession in availableSessions)
            {
                int TotalSessionSlots = curSession.OpenPublicGamerSlots + curSession.OpenPrivateGamerSlots;
                if (TotalSessionSlots > curSession.CurrentGamerCount)
                {
                    availableSession = curSession;
                }
            }

            // if a session was found, connect to it
            if (availableSession != null)
            {
                networkHelper.session = NetworkSession.Join(availableSession);
            }
        }
Exemplo n.º 11
0
        public static IAsyncResult BeginFind(
            NetworkSessionType sessionType,
            int maxLocalGamers,
            NetworkSessionProperties searchProperties,
            AsyncCallback callback,
            Object asyncState
            )
        {
            if (sessionType == NetworkSessionType.Local)
            {
                throw new ArgumentException("NetworkSessionType cannot be NetworkSessionType.Local");
            }
            if (maxLocalGamers < 1 || maxLocalGamers > 4)
            {
                throw new ArgumentOutOfRangeException("maxLocalGamers must be between 1 and 4.");
            }

            try
            {
                NetworkSessionAsynchronousFind AsynchronousFind = new NetworkSessionAsynchronousFind(Find);
                return(AsynchronousFind.BeginInvoke(sessionType, maxLocalGamers, searchProperties, callback, asyncState));
            }
            finally
            {
            }
        }
Exemplo n.º 12
0
        public static NetworkSession Create(
            NetworkSessionType sessionType, // Type of session being hosted.
            int maxLocalGamers,             // Maximum number of local players on the same gaming machine in this network session.
            int maxGamers                   // Maximum number of players allowed in this network session.  For Zune-based games, this value must be between 2 and 8; 8 is the maximum number of players supported in the session.
            )
        {
            try
            {
                if (maxLocalGamers > 2)
                {
                    throw new ArgumentOutOfRangeException("Maximum local players can only be 2 on the iPhone.");
                }
                if (maxGamers < 2 || maxGamers > 8)
                {
                    throw new ArgumentOutOfRangeException("Maximum number of gamers must be between 2 and 8.");
                }

                networkSessionType = sessionType;

                throw new NotImplementedException();
            }
            finally
            {
            }
        }
Exemplo n.º 13
0
        public static AvailableNetworkSessionCollection Find(
            NetworkSessionType sessionType,
            int maxLocalGamers,
            NetworkSessionProperties searchProperties
            )
        {
            try
            {
                if (maxLocalGamers < 1 || maxLocalGamers > 4)
                {
                    throw new ArgumentOutOfRangeException("maxLocalGamers must be between 1 and 4.");
                }

                networkSessionType = sessionType;

                GKPeerPickerController peerPickerController = new GKPeerPickerController();
                peerPickerController.Delegate = new MonoGamePeerPickerControllerDelegate(gkSession, ReceiveData);
                if (sessionType == NetworkSessionType.SystemLink)
                {
                    peerPickerController.ConnectionTypesMask = GKPeerPickerConnectionType.Nearby;
                }
                else if (sessionType == NetworkSessionType.PlayerMatch)
                {
                    peerPickerController.ConnectionTypesMask = GKPeerPickerConnectionType.Nearby | GKPeerPickerConnectionType.Online;
                }
                peerPickerController.Show();
                List <AvailableNetworkSession> availableNetworkSessions = new List <AvailableNetworkSession>();

                return(new AvailableNetworkSessionCollection(availableNetworkSessions));
            }
            finally
            {
            }
        }
Exemplo n.º 14
0
        public static IAsyncResult BeginFind(
            NetworkSessionType sessionType,
            int maxLocalGamers,
            NetworkSessionProperties searchProperties,
            AsyncCallback callback,
            object asyncState
            )
        {
            if (sessionType == NetworkSessionType.Local)
            {
                throw new ArgumentException("sessionType");
            }
            if (maxLocalGamers < 1 || maxLocalGamers > 4)
            {
                throw new ArgumentOutOfRangeException("maxLocalGamers");
            }
            if (activeAction != null || activeSession != null)
            {
                throw new InvalidOperationException();
            }

            activeAction = new NetworkSessionAction(
                asyncState,
                callback,
                maxLocalGamers,
                null,
                0,
                searchProperties,
                sessionType
                );
            return(activeAction);
        }
Exemplo n.º 15
0
        public static IAsyncResult BeginCreate(
            NetworkSessionType sessionType,
            IEnumerable <SignedInGamer> localGamers,
            int maxGamers,
            int privateGamerSlots,
            NetworkSessionProperties sessionProperties,
            AsyncCallback callback,
            object asyncState
            )
        {
            if (privateGamerSlots < 0 || privateGamerSlots > maxGamers)
            {
                throw new ArgumentOutOfRangeException("privateGamerSlots");
            }
            if (activeAction != null || activeSession != null)
            {
                throw new InvalidOperationException();
            }

            activeAction = new NetworkSessionAction(
                asyncState,
                callback,
                0,
                localGamers,
                privateGamerSlots,
                sessionProperties,
                sessionType
                );
            return(activeAction);
        }
Exemplo n.º 16
0
        public static NetworkSession Create(
            NetworkSessionType sessionType,
            int maxLocalGamers,
            int maxGamers,
            int privateGamerSlots,
            NetworkSessionProperties sessionProperties
            )
        {
            try
            {
                if (maxLocalGamers != 1)
                {
                    throw new ArgumentOutOfRangeException("Maximum local players can only be 1 on the iPhone.");
                }
                if (maxGamers < 2 || maxGamers > 8)
                {
                    throw new ArgumentOutOfRangeException("Maximum number of gamers must be between 2 and 8.");
                }
                if (privateGamerSlots < 0 || privateGamerSlots > maxGamers)
                {
                    throw new ArgumentOutOfRangeException("Private session slots must be between 0 and maximum number of gamers.");
                }


                networkSessionType = sessionType;
                throw new NotImplementedException();
            }
            finally
            {
            }
        }
Exemplo n.º 17
0
        public static IAsyncResult BeginCreate(
            NetworkSessionType sessionType,
            IEnumerable <SignedInGamer> localGamers,
            int maxGamers,
            int privateGamerSlots,
            NetworkSessionProperties sessionProperties,
            AsyncCallback callback,
            Object asyncState)
        {
            if (maxGamers < 2 || maxGamers > 8)
            {
                throw new ArgumentOutOfRangeException("Maximum number of gamers must be between 2 and 8.");
            }
            if (privateGamerSlots < 0 || privateGamerSlots > maxGamers)
            {
                throw new ArgumentOutOfRangeException("Private session slots must be between 0 and maximum number of gamers.");
            }

            try
            {
                throw new NotImplementedException();
            }
            finally
            {
            }
        }
Exemplo n.º 18
0
        public static IAsyncResult BeginFind(
            NetworkSessionType sessionType,
            IEnumerable <SignedInGamer> localGamers,
            NetworkSessionProperties searchProperties,
            AsyncCallback callback,
            object asyncState
            )
        {
            if (sessionType == NetworkSessionType.Local)
            {
                throw new ArgumentException("sessionType");
            }
            if (activeAction != null || activeSession != null)
            {
                throw new InvalidOperationException();
            }

            int locals = 0;

            foreach (SignedInGamer gamer in localGamers)
            {
                locals += 1;
            }

            activeAction = new NetworkSessionAction(
                asyncState,
                callback,
                locals,
                localGamers,
                0,
                searchProperties,
                sessionType
                );
            return(activeAction);
        }
Exemplo n.º 19
0
 public static void BeginCreateNetworkSession(NetworkSessionType networkSessionType, int maxLocalPlayers, int maxTotalGamers)
 {
     SceneManager.IsNetworkOwner = true;
     IAsyncResult result = Microsoft.Xna.Framework.Net.NetworkSession.BeginCreate(networkSessionType,
                                                                                  maxLocalPlayers,
                                                                                  maxTotalGamers,
                                                                                  new AsyncCallback(CreateSessionComplete), null);
 }
Exemplo n.º 20
0
 private static IAsyncResult BeginFind(NetworkSessionType sessionType, int hostGamer, int maxLocalGamers, NetworkSessionProperties searchProperties, AsyncCallback callback, object asyncState)
 {
   if (sessionType == NetworkSessionType.Local)
     throw new ArgumentException("NetworkSessionType cannot be NetworkSessionType.Local");
   if (maxLocalGamers < 1 || maxLocalGamers > 4)
     throw new ArgumentOutOfRangeException("maxLocalGamers must be between 1 and 4.");
   else
     return new NetworkSessionAsynchronousFind(NetworkSession.Find).BeginInvoke(sessionType, hostGamer, maxLocalGamers, searchProperties, callback, asyncState);
 }
Exemplo n.º 21
0
 public static IAsyncResult BeginFind(
     NetworkSessionType sessionType,
     int maxLocalGamers,
     NetworkSessionProperties searchProperties,
     AsyncCallback callback,
     Object asyncState)
 {
     return(BeginFind(sessionType, -1, 4, searchProperties, callback, asyncState));
 }
Exemplo n.º 22
0
        /// <summary>
        /// Constructor fills in the menu contents.
        /// </summary>
        /// <param name="sessionType">The type of session searched for.</param>
        public SearchResultsScreen(NetworkSessionType sessionType) : base()
        {
            // apply the parameters
            this.sessionType = sessionType;

            // set the transition times
            TransitionOnTime = TimeSpan.FromSeconds(1.0);
            TransitionOffTime = TimeSpan.FromSeconds(0.0);
        }
Exemplo n.º 23
0
 public static IAsyncResult BeginCreate(
     NetworkSessionType sessionType,
     int maxLocalGamers,
     int maxGamers,
     AsyncCallback callback,
     Object asyncState)
 {
     return(BeginCreate(sessionType, -1, maxLocalGamers, maxGamers, 0, null, callback, asyncState));
 }
Exemplo n.º 24
0
        /// <summary>
        /// Constructor fills in the menu contents.
        /// </summary>
        /// <param name="sessionType">The type of session searched for.</param>
        public SearchResultsScreen(NetworkSessionType sessionType) : base()
        {
            // apply the parameters
            this.sessionType = sessionType;

            // set the transition times
            TransitionOnTime  = TimeSpan.FromSeconds(1.0);
            TransitionOffTime = TimeSpan.FromSeconds(0.0);
        }
Exemplo n.º 25
0
 private static IAsyncResult BeginCreate(NetworkSessionType sessionType, int hostGamer, int maxLocalGamers, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties, AsyncCallback callback, object asyncState)
 {
   if (maxLocalGamers < 1 || maxLocalGamers > 4)
     throw new ArgumentOutOfRangeException("Maximum local players must be between 1 and 4.");
   if (maxGamers < 2 || maxGamers > 32)
     throw new ArgumentOutOfRangeException("Maximum number of gamers must be between 2 and 32.");
   else
     return new NetworkSessionAsynchronousCreate(NetworkSession.Create).BeginInvoke(sessionType, maxLocalGamers, maxGamers, privateGamerSlots, sessionProperties, hostGamer, true, callback, asyncState);
 }
Exemplo n.º 26
0
 public NetworkManager()
 {
     sessionType     = NetworkSessionType.SystemLink;
     hostSessionType = HostSessionType.Client;
     reader          = new PacketReader();
     writer          = new PacketWriter();
     background      = Global.game.Content.Load <Texture2D>(@"Textures\menubackground");
     consolas        = Global.game.Content.Load <SpriteFont>(@"Fonts\Consolas");
 }
Exemplo n.º 27
0
        /// <summary>
        /// Begins the process of asynchronously finding <see cref="AvailableNetworkSession"/>s.
        /// </summary>
        /// <param name="type">The type of the <see cref="NetworkSession"/> to find.</param>
        /// <param name="gamers">The maximum number of local gamers to allow within the <see cref="NetworkSession"/>.</param>
        /// <param name="reqProps">The <see cref="NetworkSessionProperties"/> that must be present on the found <see cref="NetworkSession"/>, or null if none.</param>
        public void FindSessions(NetworkSessionType type, int gamers, NetworkSessionProperties reqProps)
        {
            if (_asyncSessionOperationsInProgress > 0)
            {
                throw new InvalidOperationException("An asynchronous session operation is already in progress.");
            }
            _asyncSessionOperationsInProgress++;

            NetworkSession.BeginFind(type, gamers, reqProps, NetSessionsFound, null);
        }
Exemplo n.º 28
0
 public static NetworkSession Create(NetworkSessionType sessionType, int maxLocalGamers, int maxGamers)
 {
     try
     {
         return(NetworkSession.EndCreate(NetworkSession.BeginCreate(sessionType, maxLocalGamers, maxGamers, (AsyncCallback)null, (object)null)));
     }
     finally
     {
     }
 }
Exemplo n.º 29
0
 public static NetworkSession Create(NetworkSessionType sessionType, int maxLocalGamers, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties)
 {
     try
     {
         return(NetworkSession.EndCreate(NetworkSession.BeginCreate(sessionType, maxLocalGamers, maxGamers, privateGamerSlots, sessionProperties, (AsyncCallback)null, (object)null)));
     }
     finally
     {
     }
 }
Exemplo n.º 30
0
        public static AvailableNetworkSessionCollection Find(
            NetworkSessionType sessionType,
            IEnumerable <SignedInGamer> localGamers,
            NetworkSessionProperties searchProperties)
        {
            int hostGamer = -1;

            hostGamer = GetHostingGamerIndex(localGamers);
            return(EndFind(BeginFind(sessionType, hostGamer, 4, searchProperties, null, null)));
        }
Exemplo n.º 31
0
        /// <summary>
        ///
        /// </summary>
        public IAsyncResult CreateSession(NetworkSessionType sessionType, int maxLocalGamers,
                                          int maxGamers, int PrivateGamerSlots, NetworkSessionProperties sessionProperties)
        {
            IAsyncResult asyncResult = Microsoft.Xna.Framework.Net.NetworkSession.BeginCreate(sessionType, maxLocalGamers, maxGamers, PrivateGamerSlots, sessionProperties, null, null);

            //networkHelper.NetworkGameSession = Microsoft.Xna.Framework.Net.NetworkSession.Create(
            //sessionType, maxLocalGamers, maxGamers, PrivateGamerSlots, sessionProperties);

            return(asyncResult);
        }
Exemplo n.º 32
0
 private static NetworkSession JoinSession(AvailableNetworkSession availableSession)
 {
   NetworkSessionType sessionType = availableSession.SessionType;
   int maxGamers = 32;
   int privateGamerSlots = 0;
   bool isHost = false;
   int hostGamer = -1;
   NetworkSessionProperties sessionProperties = availableSession.SessionProperties ?? new NetworkSessionProperties();
   return new NetworkSession(sessionType, maxGamers, privateGamerSlots, sessionProperties, isHost, hostGamer, availableSession);
 }
Exemplo n.º 33
0
        /// <summary>
        /// Constructor fills in the menu contents.
        /// </summary>
        /// <param name="sessionType">The type of session searched for.</param>
        public SearchResultsScreen(NetworkSessionType sessionType)
            : base(new Viewport(), null, null)
        {
            throw new NotImplementedException();
            // apply the parameters
            this.sessionType = sessionType;

            // set the transition times
            TransitionOnTime = TimeSpan.FromSeconds(1.0);
            TransitionOffTime = TimeSpan.FromSeconds(0.0);
        }
Exemplo n.º 34
0
 public static IAsyncResult BeginCreate(
     NetworkSessionType sessionType,
     int maxLocalGamers,
     int maxGamers,
     int privateGamerSlots,
     NetworkSessionProperties sessionProperties,
     AsyncCallback callback,
     Object asyncState)
 {
     return(BeginCreate(sessionType, -1, maxLocalGamers, maxGamers, privateGamerSlots, sessionProperties, callback, asyncState));
 }
		/// <summary>
		/// Helper chooses an appropriate menu title for the specified session type.
		/// </summary>
		static string GetMenuTitle (NetworkSessionType sessionType)
		{
			switch (sessionType) {
			case NetworkSessionType.PlayerMatch:
				return Resources.PlayerMatch;

			case NetworkSessionType.SystemLink:
				return Resources.SystemLink;

			default:
				throw new NotSupportedException ();
			}
		}
        /// <summary>
        /// Decides which local gamer profiles should be included in a network session.
        /// This is passed the index of the primary gamer (the profile who selected the
        /// relevant menu option, or who is responding to an invite). The primary gamer
        /// will always be included in the session. Other gamers may also be added if
        /// there are suitable profiles signed in. To control how many gamers can be
        /// returned by this method, adjust the MaxLocalGamers constant.
        /// </summary>
        public static IEnumerable<SignedInGamer> ChooseGamers(
                                                        NetworkSessionType sessionType,
                                                        PlayerIndex playerIndex)
        {
            List<SignedInGamer> gamers = new List<SignedInGamer>();

            // Look up the primary gamer, and make sure they are signed in.
            SignedInGamer primaryGamer = Gamer.SignedInGamers[playerIndex];

            if (primaryGamer == null)
                throw new GamerPrivilegeException();

            gamers.Add(primaryGamer);

            // Check whether any other profiles should also be included.
            foreach (SignedInGamer gamer in Gamer.SignedInGamers)
            {
                // Never include more profiles than the MaxLocalGamers constant.
                if (gamers.Count >= MaxLocalGamers)
                    break;

                // Don't want two copies of the primary gamer!
                if (gamer == primaryGamer)
                    continue;

                // If this is an online session, make sure the profile is signed
                // in to Live, and that it has the privilege for online gameplay.
                if (IsOnlineSessionType(sessionType))
                {
                    if (!gamer.IsSignedInToLive)
                        continue;

                    if (!gamer.Privileges.AllowOnlineSessions)
                        continue;
                }

                if (primaryGamer.IsGuest && !gamer.IsGuest && gamers[0] == primaryGamer)
                {
                    // Special case: if the primary gamer is a guest profile,
                    // we should insert some other non-guest at the start of the
                    // output list, because guests aren't allowed to host sessions.
                    gamers.Insert(0, gamer);
                }
                else
                {
                    gamers.Add(gamer);
                }
            }

            return gamers;
        }
Exemplo n.º 37
0
        public void CreateSession(NetworkSessionType sessionType, int maxLocalPlayers, int maxGamers, 
            int privateSlots, NetworkSessionProperties properties)
        {
            if (networkHelper.session == null)
            {
                networkHelper.session = NetworkSession.Create(sessionType, maxLocalPlayers,
                    maxGamers, privateSlots, properties);

                // If the host goes out, another machine will asume as a new host
                networkHelper.session.AllowHostMigration = true;
                // Allow players to join a game in progress
                networkHelper.session.AllowJoinInProgress = true;

                eventHandler.HookSessionEvents();
            }
        }
        /// <summary>
        /// Helper method shared by the Live and System Link menu event handlers.
        /// </summary>
        void CreateOrFindSession(NetworkSessionType sessionType,
                                 PlayerIndex playerIndex)
        {
            // First, we need to make sure a suitable gamer profile is signed in.
            ProfileSignInScreen profileSignIn = new ProfileSignInScreen(sessionType);

            // Hook up an event so once the ProfileSignInScreen is happy,
            // it will activate the CreateOrFindSessionScreen.
            profileSignIn.ProfileSignedIn += delegate
            {
                GameScreen createOrFind = new CreateOrFindSessionScreen(sessionType);

                ScreenManager.AddScreen(createOrFind, playerIndex);
            };

            // Activate the ProfileSignInScreen.
            ScreenManager.AddScreen(profileSignIn, playerIndex);
        }
        /// <summary>
        /// Constructor fills in the menu contents.
        /// </summary>
        public CreateOrFindSessionScreen(NetworkSessionType sessionType)
            : base(GetMenuTitle(sessionType))
        {
            this.sessionType = sessionType;

            // Create our menu entries.
            MenuEntry createSessionMenuEntry = new MenuEntry(Resources.CreateSession);
            MenuEntry findSessionsMenuEntry = new MenuEntry(Resources.FindSessions);
            MenuEntry backMenuEntry = new MenuEntry(Resources.Back);

            // Hook up menu event handlers.
            createSessionMenuEntry.Selected += CreateSessionMenuEntrySelected;
            findSessionsMenuEntry.Selected += FindSessionsMenuEntrySelected;
            backMenuEntry.Selected += OnCancel;

            // Add entries to the menu.
            MenuEntries.Add(createSessionMenuEntry);
            MenuEntries.Add(findSessionsMenuEntry);
            MenuEntries.Add(backMenuEntry);
        }
Exemplo n.º 40
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IAsyncResult CreateNetwork(Game game, NetworkSessionType sessionType, int maxLocalGamers, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties, bool AllowHostMigration, bool AllowJoinInProgress)
        {
            SessionManager sessionManager = new SessionManager(game);

            IAsyncResult asyncResult = sessionManager.CreateSession(sessionType, maxLocalGamers, maxGamers, privateGamerSlots, sessionProperties);
            /*
            if (networkHelper.NetworkGameSession != null)
            {
                if (AllowHostMigration == true)
                    networkHelper.NetworkGameSession.AllowHostMigration = true;

                if (AllowJoinInProgress == true)
                    networkHelper.NetworkGameSession.AllowJoinInProgress = true;
                return asyncResult;
            }
            else
            {
                //throw new Exception("Session was not Created");
                return asyncResult;

            }*/
            return asyncResult;
        }
Exemplo n.º 41
0
		public static NetworkSession Create (
         NetworkSessionType sessionType,			// Type of session being hosted.
         IEnumerable<SignedInGamer> localGamers,	// Maximum number of local players on the same gaming machine in this network session.
         int maxGamers,								// Maximum number of players allowed in this network session.  For Zune-based games, this value must be between 2 and 8; 8 is the maximum number of players supported in the session.
         int privateGamerSlots,						// Number of reserved private session slots created for the session. This value must be less than maximumGamers. 
         NetworkSessionProperties sessionProperties // Properties of the session being created.
		)
		{
			try
			{
				if ( maxGamers < 2 || maxGamers > 8 ) 
					throw new ArgumentOutOfRangeException( "Maximum number of gamers must be between 2 and 8."  );
				if ( privateGamerSlots < 0 || privateGamerSlots > maxGamers ) 
					throw new ArgumentOutOfRangeException( "Private session slots must be between 0 and maximum number of gamers."  );
			
				networkSessionType = sessionType;
			
				throw new NotImplementedException();
			}
			finally
			{
			}
		} 
Exemplo n.º 42
0
 public static IAsyncResult BeginFind(NetworkSessionType sessionType, int maxLocalGamers, NetworkSessionProperties searchProperties, AsyncCallback callback, object asyncState)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 43
0
 public static NetworkSession Create(NetworkSessionType sessionType, int maxLocalGamers, int maxGamers)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 44
0
 public static AvailableNetworkSessionCollection Find(NetworkSessionType sessionType, int maxLocalGamers, NetworkSessionProperties searchProperties)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 45
0
 public static IAsyncResult BeginCreate(NetworkSessionType sessionType, int maxLocalGamers, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties, AsyncCallback callback, object asyncState)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 46
0
 public static IAsyncResult BeginFind(NetworkSessionType sessionType, IEnumerable<SignedInGamer> localGamers, NetworkSessionProperties searchProperties, AsyncCallback callback, object asyncState)
 {
   int hostingGamerIndex = NetworkSession.GetHostingGamerIndex(localGamers);
   return NetworkSession.BeginFind(sessionType, hostingGamerIndex, 4, searchProperties, callback, asyncState);
 }
Exemplo n.º 47
0
 public static AvailableNetworkSessionCollection Find(NetworkSessionType sessionType, IEnumerable<SignedInGamer> localGamers, NetworkSessionProperties searchProperties)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 48
0
 public static AvailableNetworkSessionCollection Find(NetworkSessionType sessionType, IEnumerable<SignedInGamer> localGamers, NetworkSessionProperties searchProperties)
 {
   int hostingGamerIndex = NetworkSession.GetHostingGamerIndex(localGamers);
   return NetworkSession.EndFind(NetworkSession.BeginFind(sessionType, hostingGamerIndex, 4, searchProperties, (AsyncCallback) null, (object) null));
 }
Exemplo n.º 49
0
		/// <summary>
		/// Joins an existing network session.
		/// </summary>
		void JoinSession (NetworkSessionType type)
		{
			DrawMessage ("Joining session...");

			try {
				// Search for sessions.
				using (AvailableNetworkSessionCollection availableSessions =
				NetworkSession.Find (type, 
						maxLocalGamers, null)) {
					if (availableSessions.Count == 0) {
						errorMessage = "No network sessions found.";
						return;
					}

					// Join the first session we found.
					networkSession = NetworkSession.Join (availableSessions [0]);

					HookSessionEvents ();
				}
			} catch (Exception e) {
				errorMessage = e.Message;
			}
		}
Exemplo n.º 50
0
        /// <summary>
        /// Start searching for a session of the given type.
        /// </summary>
        /// <param name="sessionType">The type of session to look for.</param>
        void FindSession(NetworkSessionType sessionType)
        {
            throw new System.NotImplementedException(); // TODO: delete if not gonna use
            // create the new screen
            /*
            SearchResultsScreen searchResultsScreen =
               new SearchResultsScreen(sessionType);
            searchResultsScreen.ScreenManager = this.ScreenManager;
            ScreenManager.AddScreen(searchResultsScreen);

            // start the search
            try
            {
                IAsyncResult asyncResult = Microsoft.Xna.Framework.Net.NetworkSession.BeginFind(sessionType, 1, null,
                    null, null);

                // create the busy screen
                NetworkBusyScreen busyScreen = new NetworkBusyScreen(
                    "Searching for a session...", asyncResult);
                busyScreen.OperationCompleted += searchResultsScreen.SessionsFound;
                ScreenManager.AddScreen(busyScreen);
            }
            catch (NetworkException ne)
            {
                const string message = "Failed searching for the session.";
                MessageBoxScreen messageBox = new MessageBoxScreen(message);
                messageBox.Accepted += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine("Failed to search for session:  " +
                    ne.Message);
            }
            catch (GamerPrivilegeException gpe)
            {
                const string message =
                    "You do not have permission to search for a session.";
                MessageBoxScreen messageBox = new MessageBoxScreen(message);
                messageBox.Accepted += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine(
                    "Insufficient privilege to search for session:  " + gpe.Message);
            }
             */
        }
Exemplo n.º 51
0
 public static AvailableNetworkSessionCollection Find(NetworkSessionType sessionType, int maxLocalGamers, NetworkSessionProperties searchProperties)
 {
   return NetworkSession.EndFind(NetworkSession.BeginFind(sessionType, -1, maxLocalGamers, searchProperties, (AsyncCallback) null, (object) null));
 }
        /// <summary>
        /// Checks whether the specified session type is online.
        /// Online sessions cannot be used by local profiles, or if
        /// parental controls are enabled, or when running in trial mode.
        /// </summary>
        public static bool IsOnlineSessionType(NetworkSessionType sessionType)
        {
            switch (sessionType)
            {
                case NetworkSessionType.Local:
                case NetworkSessionType.SystemLink:
                    return false;

                case NetworkSessionType.PlayerMatch:
                case NetworkSessionType.Ranked:
                    return true;

                default:
                    throw new NotSupportedException();
            }
        }
Exemplo n.º 53
0
 public static void BeginCreateNetworkSession(NetworkSessionType networkSessionType, int maxLocalPlayers, int maxTotalGamers)
 {
     SceneManager.IsNetworkOwner = true;
     IAsyncResult result = Microsoft.Xna.Framework.Net.NetworkSession.BeginCreate(networkSessionType,
         maxLocalPlayers,
         maxTotalGamers,
         new AsyncCallback(CreateSessionComplete), null);
 }
Exemplo n.º 54
0
 public static void BeginFindSessions(NetworkSessionType networkSessionType, int p, FindSessionCompleteHandler callback)
 {
     IAsyncResult asyncResult = NetworkSession.BeginFind(networkSessionType,
                                       p,
                                       null, new AsyncCallback(FindSessionsComplete), callback);
 }
Exemplo n.º 55
0
 public static NetworkSession Create(NetworkSessionType sessionType, int maxLocalGamers, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 56
0
 public static IAsyncResult BeginFind(NetworkSessionType sessionType, int maxLocalGamers, NetworkSessionProperties searchProperties, AsyncCallback callback, object asyncState)
 {
   return NetworkSession.BeginFind(sessionType, -1, 4, searchProperties, callback, asyncState);
 }
Exemplo n.º 57
0
		internal static void Find (NetworkSessionType sessionType)
		{
			NetPeerConfiguration config = new NetPeerConfiguration (applicationIdentifier);			
			if (sessionType == NetworkSessionType.PlayerMatch) {
				config.EnableMessageType (NetIncomingMessageType.UnconnectedData);
				config.EnableMessageType (NetIncomingMessageType.NatIntroductionSuccess);
			} else {
				config.EnableMessageType (NetIncomingMessageType.DiscoveryRequest);
			}
            if (MonoGameNetworkConfiguration.Broadcast != IPAddress.None)
            {
                config.BroadcastAddress = MonoGameNetworkConfiguration.Broadcast;
            }
			netPeer = new NetPeer (config);
			netPeer.Start ();

			if (sessionType == NetworkSessionType.PlayerMatch) {
				GetServerList (netPeer);
			} else {
				netPeer.DiscoverLocalPeers (port);
			}

			DateTime now = DateTime.Now;

			discoveryMsgs = new List<NetIncomingMessage> ();

			do {
				NetIncomingMessage msg;
				while ((msg = netPeer.ReadMessage ()) != null) {
					switch (msg.MessageType) {
					case NetIncomingMessageType.DiscoveryResponse:
						discoveryMsgs.Add (msg);
						break;
					case NetIncomingMessageType.UnconnectedData:
						if (msg.SenderEndpoint.Equals (m_masterServer)) {
							discoveryMsgs.Add (msg);
							/*
				* // it's from the master server - must be a host
				IPEndPoint hostInternal = msg.ReadIPEndpoint();
				IPEndPoint hostExternal = msg.ReadIPEndpoint();

				m_hostList.Add(new IPEndPoint[] { hostInternal, hostExternal });                            
				*/
						}
						break;
					case NetIncomingMessageType.VerboseDebugMessage:
					case NetIncomingMessageType.DebugMessage:
					case NetIncomingMessageType.WarningMessage:
					case NetIncomingMessageType.ErrorMessage:
						//
						// Just print diagnostic messages to console
						//
#if DEBUG
						Console.WriteLine ("Find: " + msg.ReadString ());
#endif
						break;
					}
				}
			} while ((DateTime.Now - now).Seconds <= 2);

			netPeer.Shutdown ("Find shutting down");
		}
Exemplo n.º 58
0
        /// <summary>
        /// Constructs a new profile sign in screen.
        /// </summary>
        public ProfileSignInScreen(NetworkSessionType sessionType)
        {
            this.sessionType = sessionType;

            IsPopup = true;
        }