/// <summary> /// Event handler for when the Create Session menu entry is selected. /// </summary> void CreateSessionMenuEntrySelected(object sender, PlayerIndexEventArgs e) { 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); } }
void createSession_Pressed(object sender, EventArgs e) { if (!Guide.IsVisible && !allScreens["chatScreen"].Visible) { IAsyncResult beginCrSess = NetworkSession.BeginCreate( NetworkSessionType.SystemLink, maximumLocalPlayers, maximumGamers, null, null); beginCrSess.AsyncWaitHandle.WaitOne(); session = NetworkSession.EndCreate(beginCrSess); session.AllowJoinInProgress = true; session.GamerJoined += new EventHandler <GamerJoinedEventArgs>(session_GamerJoined); session.GameStarted += new EventHandler <GameStartedEventArgs>(session_GameStarted); allScreens["titleScreen"].Visible = false; allScreens["playerList"].Visible = true; Services.AddService(typeof(NetworkSession), session); /* * Texture2D newGamerImage = Texture2D.FromStream(GraphicsDevice, Gamer.SignedInGamers[0].GetProfile().GetGamerPicture()); * Vector2 pos = new Vector2(100, 50); * Sprite gamerIcon = new Sprite(newGamerImage, pos, spriteBatch); * allScreens["playerList"].Sprites.Add(gamerIcon); * TextSprite gamerName = new TextSprite(spriteBatch, new Vector2(pos.X + gamerIcon.Width + 5, pos.Y), font, Gamer.SignedInGamers[0].DisplayName == null ? Gamer.SignedInGamers[0].Gamertag : Gamer.SignedInGamers[0].DisplayName); * allScreens["playerList"].AdditionalSprites.Add(gamerName); */ } }
/// <summary> /// Event handler for when the Create Session menu entry is selected. /// </summary> void CreateSessionMenuEntrySelected(object sender, EventArgs e) { try { // Begin an asynchronous create network session operation. IAsyncResult asyncResult = NetworkSession.BeginCreate(sessionType, NetworkSessionComponent.MaxLocalGamers, NetworkSessionComponent.MaxGamers, 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); } catch (NetworkException exception) { ScreenManager.AddScreen(new NetworkErrorScreen(exception)); } catch (GamerPrivilegeException exception) { ScreenManager.AddScreen(new NetworkErrorScreen(exception)); } }
public void CreateGame() { IsCreating = true; SetString("Creating Game ..."); CreateResult = NetworkSession.BeginCreate(SessionType, 4, game.maxOrbs, null, null); }
/// <summary> /// An event handler invoked when the hostSession TextSprite is pressed (using the mouse or otherwise). /// </summary> void hostSession_Pressed(object sender, EventArgs e) { GLibXNASampleGame.Instance.SetScreen("Loading"); //The SessionManagerComponent does not provide methods for the creation of NetworkSessions //It must me done through the NetworkSession class directly NetworkSession.BeginCreate(NetworkSessionType.SystemLink, 1, 4, onSessionCreation, null); }
public void Host() { if (netPlay.NetSession != null) { netPlay.NetSession.Dispose(); } NetworkSessionProperties props = new NetworkSessionProperties(); createResult = NetworkSession.BeginCreate(NetworkSessionType.SystemLink, 1, 2, 0, props, new AsyncCallback(GotResult), null); PendingHost = true; }
/* Completion of looking for sessions. */ protected virtual void OnSessionsFound(IAsyncResult ar) { findAsync_ = null; AvailableNetworkSessionCollection availableSessions = NetworkSession.EndFind(ar); if (availableSessions.Count != 0) { /* Pick one of the available sessions. */ List <AvailableNetworkSession> toChooseFrom = new List <AvailableNetworkSession>(); Trace.WriteLine(String.Format("Found {0} potential network sessions.", availableSessions.Count)); foreach (AvailableNetworkSession ans in availableSessions) { if (ans.OpenPublicGamerSlots < saveLocalPlayerCount && ans.OpenPublicGamerSlots < SignedInGamer.SignedInGamers.Count) { // full continue; } if (sessionType != SessionType.HighscoresOnly || !previousSessionHosts.Member(ans.HostGamertag)) { // this seems like an OK session, use that! toChooseFrom.Add(ans); } } if (toChooseFrom.Count > 0) { // pick one at random AvailableNetworkSession ans = toChooseFrom[rand.Next(toChooseFrom.Count)]; previousSessionHosts.Add(ans.HostGamertag); Trace.WriteLine(String.Format("Connecting to session hosted by '{0}'", ans.HostGamertag)); ConnectToSession(ans); return; } else { /* I went through all the possible sessions, so now I can re-start looking * at hosts I've previously talked to. */ previousSessionHosts.Clear(); } } // OK, nothing matched -- try to create something for others to find Trace.WriteLine("Creating session because no available session was suitable."); Debug.Assert(createAsync_ == null); createAsync_ = NetworkSession.BeginCreate(netType, saveLocalPlayerCount, saveTotalPlayerCount, 0, saveProps, OnSessionCreated, null); Debug.Assert(createAsync_.CompletedSynchronously == false); }
/// <summary> /// Creates a Single Player Session /// </summary> /// <remarks>No network resources will be used</remarks> public override void CreateSinglePlayerSession() { if (LocalPlayers.Count == 0) { throw new CoreException("No players identified"); } if (CurrentSession != null) { throw new CoreException("A session already exists. Close the previous session first"); } _networkSessionLocker = CreatingSession; NetworkSession.BeginCreate(NetworkSessionType.Local, 1, 1, OnLiveSessionCreated, _networkSessionLocker); }
/// <summary> /// Creates a wide area network session /// </summary> /// <param name="maxPlayers">The total maximum players for this session</param> /// <param name="sessionProperties">The SessionProperties that will be used to find this session on the network. Can be null</param> /// <remarks>it doesn't yet support multiple local players</remarks> public override void CreateWanSession(int maxPlayers, SessionProperties sessionProperties) { if (LocalPlayers.Count > 1) { throw new NotImplementedException(); } if (CurrentSession != null) { throw new CoreException("A session already exists. Close the previous session first"); } _networkSessionLocker = CreatingSession; NetworkSession.BeginCreate(NetworkSessionType.PlayerMatch, 1, maxPlayers, 0, LiveSessionProperties.ConvertToLiveSessionProperties(sessionProperties), OnLiveSessionCreated, _networkSessionLocker); }
/// <summary> /// Start creating a session of the given type. /// </summary> /// <param name="sessionType">The type of session to create.</param> void CreateSession(NetworkSessionType sessionType) { // create the session try { IAsyncResult asyncResult = NetworkSession.BeginCreate(sessionType, 1, World.MaximumPlayers, null, null); // create the busy screen NetworkBusyScreen busyScreen = new NetworkBusyScreen( "Creating a session...", asyncResult); busyScreen.OperationCompleted += SessionCreated; ScreenManager.AddScreen(busyScreen); } catch (NetworkException ne) { const string message = "Failed creating the session."; MessageBoxScreen messageBox = new MessageBoxScreen(message); messageBox.Accepted += FailedMessageBox; messageBox.Cancelled += FailedMessageBox; ScreenManager.AddScreen(messageBox); System.Console.WriteLine("Failed to create session: " + ne.Message); } catch (GamerPrivilegeException gpe) { const string message = "You do not have permission to create a session."; MessageBoxScreen messageBox = new MessageBoxScreen(message); messageBox.Accepted += FailedMessageBox; messageBox.Cancelled += FailedMessageBox; ScreenManager.AddScreen(messageBox); System.Console.WriteLine( "Insufficient privilege to create session: " + gpe.Message); } }