/// <summary> /// Helper method for creating a hosted network session /// </summary> private void CreateSession() { try { // Create the hosted network session session = NetworkSession.Create( NetworkSessionType.SystemLink, // Session Type 4, // Max Local Gamers 16 // Max Gamers ); // Set ourselves as host isHost = true; // Enable migration and join-in-progress session.AllowHostMigration = true; session.AllowJoinInProgress = true; // Set up the session event handlers HookSessonEvents(); // Update our game state game.GameState = GameState.Gameplay; } catch (Exception e) { // TODO: Report Errors } }
public virtual void CreateSession() { if (Session == null) { Session = NetworkSession.Create(NetworkSessionType.SystemLink, maximumLocalPlayers, maximumGamers); } // If the host goes out, another machine will assume as a new host Session.AllowHostMigration = true; // Allow players to join a game in progress Session.AllowJoinInProgress = true; Session.GamerJoined += new EventHandler <GamerJoinedEventArgs>(session_GamerJoined); Session.GamerLeft += new EventHandler <GamerLeftEventArgs>(session_GamerLeft); Session.GameStarted += new EventHandler <GameStartedEventArgs>(session_GameStarted); Session.GameEnded += new EventHandler <GameEndedEventArgs>(session_GameEnded); Session.SessionEnded += new EventHandler <NetworkSessionEndedEventArgs>(session_SessionEnded); Session.HostChanged += new EventHandler <HostChangedEventArgs>(session_HostChanged); if (OnCreate != null) { OnCreate(); } }
protected void Update_CreateSession() { networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, 1, 2); networkSession.AllowHostMigration = true; networkSession.AllowJoinInProgress = false; WireUpEvents(); currentGameState = GameState.Start; }
/* * Starts the player as hosting a game/network session * */ void CreateGame() { try { networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, maxPlayers, maxPlayers); isHost = true; } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } }
public void HostSession() { if (_netSession != null) { _netSession.Dispose(); } _netSession = null; _netSession = NetworkSession.Create(NetworkSessionType.SystemLink, 1, 10); _netSession.AllowHostMigration = true; _netSession.AllowJoinInProgress = true; _isHost = true; initialiseEventHandlers(); }
/// <summary> /// Starts hosting a new network session. /// </summary> void CreateSession() { DrawMessage("Creating session..."); try { networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, maxLocalGamers, maxGamers); HookSessionEvents(); //networkSession.AddLocalGamer(); } catch (Exception e) { errorMessage = e.Message; } }
public void CreateSession() { if (session == null) { session = NetworkSession.Create(NetworkSessionType.SystemLink, maximumLocalPlayers, maximumGamers); session.AllowHostMigration = true; // Switch hosts if the original goes out session.AllowJoinInProgress = true; // Allow players to join a game in progress session.GamerJoined += new EventHandler <GamerJoinedEventArgs>(session_GamerJoined); session.GamerLeft += new EventHandler <GamerLeftEventArgs>(session_GamerLeft); session.GameStarted += new EventHandler <GameStartedEventArgs>(session_GameStarted); session.GameEnded += new EventHandler <GameEndedEventArgs>(session_GameEnded); session.HostChanged += new EventHandler <HostChangedEventArgs>(session_HostChanged); } }
public void CreateSession(NetworkSessionType networkSessionType) { this.networkSessionType = networkSessionType; try { networkSession = NetworkSession.Create(networkSessionType, maxLocalGamers, maxGamers); networkSession.AllowHostMigration = true; networkSession.AllowJoinInProgress = true; HookSessionEvents(); } catch (Exception e) { errorMessage = e.Message; } }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } if (this.IsActive) { switch (currentGameState) { case GameState.SignIn: { if (Gamer.SignedInGamers.Count < 1) { Guide.ShowSignIn(1, false); log.Add("Opened User SignIn Interface"); } else { currentGameState = GameState.CreateSession; log.Add(Gamer.SignedInGamers[0].Gamertag + " logged in - proceed to CreateSession"); } } break; case GameState.CreateSession: { networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, 4, 16); networkSession.AllowHostMigration = true; networkSession.AllowJoinInProgress = false; log.Add("New session created"); HookSessionEvents(); currentGameState = GameState.InSession; } break; case GameState.InSession: { networkSession.Update(); } break; } } base.Update(gameTime); }
/// <summary> /// Starts hosting a new network session. /// </summary> void CreateSession() { DrawMessage("Creating session..."); try { networkSession = NetworkSession.Create(NetworkSessionType.PlayerMatch, maxLocalGamers, maxGamers); HookSessionEvents(); } catch (Exception error) { errorMessage = error.Message; } }
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(); } }
private void CreateLiveSession() { DrawMessage("Creating Live session..."); try { networkSession = NetworkSession.Create(NetworkSessionType.PlayerMatch, maxLocalGamers, maxGamers); HookSessionEvents(); //networkSession.AddLocalGamer(); } catch (Exception e) { errorMessage = e.Message; } }
public bool createSession() { currentState = CurrentState.Creating; try { networkSession = NetworkSession.Create(sessionType, Global.Constants.MAX_PLAYERS_LOCAL, Global.Constants.MAX_PLAYERS_TOTAL, 0, sessionProperties); hookEvents(); } catch (Exception e) { currentState = CurrentState.CreateFailed; lastErrorMessage = e.Message; return(false); } currentState = CurrentState.Running; return(true); }
/// <summary> /// Starts hosting a new network session. /// </summary> void CreateSession() { DrawMessage("Creating game..."); try { networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, maxLocalGamers, maxGamers); HookSessionEvents(); state = gameState.game; errorMessage = null; } catch (Exception e) { errorMessage = e.Message; } }
void CreateGameHandler(object sender, EventArgs e) { try { Session = NetworkSession.Create(NetworkSessionType.SystemLink, 2, 2); UnhookHomeStateEvents(); GlobalState = new LobbyState(); GlobalState.Initialize(null); GlobalState.LoadContent(Content); HookLobbyStateEvents(); HookSessionEvents(); } catch (Exception exception) { } }
public static void CreateSession() { if (networkSession != null) { networkSession.Dispose(); } SetStatus("Creating Session"); try { networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, 2, 2); HookSessionEvents(); SetStatus("Successfully Created Session"); } catch (Exception e) { Console.WriteLine(e.Message); SetStatus(e.Message); } }
public override void Initialize() { if (IsHost) { commandHost.RegisterEchoListner(this); // Create network session if NetworkSession is not set. if (NetworkSession == null) { GamerServicesDispatcher.WindowHandle = Game.Window.Handle; GamerServicesDispatcher.Initialize(Game.Services); NetworkSession = NetworkSession.Create(NetworkSessionType.SystemLink, 1, 2); OwnsNetworkSession = true; } } base.Initialize(); }
public void CreateSession() { if (_session != null) { _session.Dispose(); } if (Gamer.SignedInGamers.Count == 0) { SignIn(); } else { _session = NetworkSession.Create(NetworkSessionType.SystemLink, 1, 2); _session.GamerJoined += new EventHandler <GamerJoinedEventArgs>(Host_GamerJoined); _session.GamerLeft += new EventHandler <GamerLeftEventArgs>(Host_GamerLeft); GameMain.ChangeState(GameState.WaitingPlayers); IsHost = true; } }
public static void CreateSession() { NetworkSessionType sessionType = (Main.netMode != 0) ? NetworkSessionType.PlayerMatch : NetworkSessionType.Local; try { List <SignedInGamer> list = new List <SignedInGamer>(1); list.Add(UI.main.signedInGamer); NetworkSessionProperties networkSessionProperties = new NetworkSessionProperties(); ulong xuid = UI.main.signedInGamer.GetXuid(); if (UI.main.isInviteOnly) { networkSessionProperties[2] = -559038737; } else { networkSessionProperties[0] = (int)xuid; networkSessionProperties[1] = (int)(xuid >> 32); } int maxGamers = 8; int privateGamerSlots = 0; if (!Main.IsTutorial() && UI.main.isInviteOnly) { privateGamerSlots = 7; } session = NetworkSession.Create(sessionType, list, maxGamers, privateGamerSlots, networkSessionProperties); session.AllowJoinInProgress = true; session.AllowHostMigration = false; hookEvents = true; session.StartGame(); } catch (Exception) { UI.Error(Lang.menu[5], Lang.inter[20]); UI.main.menuType = MenuType.MAIN; Main.netMode = 0; disconnect = true; } }
public void createSession(int maxGamers) { network = NetworkSession.Create(NetworkSessionType.SystemLink, 1, maxGamers); }
protected override void Update(GameTime gameTime) { GamePadState padState = GamePad.GetState(PlayerIndex.One); if (padState.Buttons.Back == ButtonState.Pressed) { this.Exit(); } KeyboardState keybState = Keyboard.GetState(); if (this.IsActive) { switch (currentGameState) { case GameState.SignIn: { if (Gamer.SignedInGamers.Count < 1) { Guide.ShowSignIn(1, false); log.Add("Opened User SignIn Interface"); } else { currentGameState = GameState.SearchSession; log.Add(Gamer.SignedInGamers[0].Gamertag + " logged in - proceed to SearchSession"); } } break; case GameState.SearchSession: { NetworkSessionProperties findProperties = new NetworkSessionProperties(); findProperties[0] = 3; findProperties[1] = 4096; AvailableNetworkSessionCollection activeSessions = NetworkSession.Find(NetworkSessionType.SystemLink, 4, findProperties); if (activeSessions.Count == 0) { currentGameState = GameState.CreateSession; log.Add("No active sessions found - proceed to CreateSession"); } else { AvailableNetworkSession sessionToJoin = activeSessions[0]; networkSession = NetworkSession.Join(sessionToJoin); string myString = "Joined session hosted by " + sessionToJoin.HostGamertag; myString += " with " + sessionToJoin.CurrentGamerCount.ToString() + " players"; myString += " and " + sessionToJoin.OpenPublicGamerSlots.ToString() + " open player slots."; log.Add(myString); HookSessionEvents(); command = "[Press X to signal you're ready]"; currentGameState = GameState.InSession; } } break; case GameState.CreateSession: { NetworkSessionProperties createProperties = new NetworkSessionProperties(); createProperties[0] = 3; createProperties[1] = 4096; networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, 4, 16, 0, createProperties); networkSession.AllowHostMigration = true; networkSession.AllowJoinInProgress = false; log.Add("New session created"); HookSessionEvents(); command = "[Press X to signal you're ready]"; currentGameState = GameState.InSession; } break; case GameState.InSession: { switch (networkSession.SessionState) { case NetworkSessionState.Lobby: { if ((keybState != lastKeybState) || (padState != lastPadState)) { if (keybState.IsKeyDown(Keys.X) || (padState.IsButtonDown(Buttons.X))) { LocalNetworkGamer localGamer = networkSession.LocalGamers[0]; localGamer.IsReady = !localGamer.IsReady; } } if (networkSession.IsHost) { if (networkSession.AllGamers.Count > 1) { if (networkSession.IsEveryoneReady) { networkSession.StartGame(); log.Add("All players ready -- start the game!"); } } } } break; case NetworkSessionState.Playing: { if (networkSession.IsHost) { if ((keybState != lastKeybState) || (padState != lastPadState)) { if (keybState.IsKeyDown(Keys.Y) || (padState.IsButtonDown(Buttons.Y))) { networkSession.EndGame(); } } } } break; } networkSession.Update(); } break; } } lastKeybState = keybState; base.Update(gameTime); }
private void DataCreator() { int SecTimer = 0; while (_mServer.Running) { SecTimer++; try { NetworkPacket packet = new NetworkPacket(); packet.Type = NetworkTypes.SIMULATOR; if (!Telemetry.m.Active_Sim) { List <string> Sims = new List <string>(); Telemetry.m.Sims.Sims.ForEach(x => Sims.Add(x.ProcessName)); NetworkStateReport report = new NetworkStateReport(NetworkAppState.WAITING_SIM, Sims); packet.Data = ByteMethods.SerializeToBytes(report); _mServer.Write(packet); } else if (!Telemetry.m.Active_Session) { NetworkStateReport report = new NetworkStateReport(NetworkAppState.WAITING_SESSION, Telemetry.m.Sim.Name, Telemetry.m.Sim.ProcessName); packet.Data = ByteMethods.SerializeToBytes(report); _mServer.Write(packet); } // TODO: Add packet for game. if (Telemetry.m.Active_Sim && Telemetry.m.Active_Session) { NetworkStateReport report = new NetworkStateReport(NetworkAppState.RUNNING, Telemetry.m.Sim.Name, Telemetry.m.Sim.ProcessName); packet.Data = ByteMethods.SerializeToBytes(report); _mServer.Write(packet); packet.Type = NetworkTypes.SESSION; packet.Data = ByteMethods.SerializeToBytes(NetworkSession.Create(Telemetry.m.Sim.Session)); _mServer.Write(packet); packet.Type = NetworkTypes.DRIVER; packet.Data = ByteMethods.SerializeToBytes(NetworkDrivers.Create(Telemetry.m.Sim.Drivers)); _mServer.Write(packet); packet.Type = NetworkTypes.PLAYER; packet.Data = ByteMethods.SerializeToBytes(NetworkDriverPlayer.Create(Telemetry.m.Sim.Player)); _mServer.Write(packet); if (SecTimer % (5 * Bandwidth) == 0 && Telemetry.m.Track.Route != null) // every 5 seconds { // Send complete track route packet.Type = NetworkTypes.TRACKMAP; packet.Data = ByteMethods.SerializeToBytes(Telemetry.m.Track.Route); _mServer.Write(packet); packet.Type = NetworkTypes.TRACK; NetworkTrackInformation trackInfo = new NetworkTrackInformation(); trackInfo.Type = Telemetry.m.Track.Type; trackInfo.Location = Telemetry.m.Track.Location; trackInfo.Name = Telemetry.m.Track.Name; packet.Data = ByteMethods.SerializeToBytes(trackInfo); _mServer.Write(packet); } } } catch (Exception ex) { } Thread.Sleep(1000 / Bandwidth); } }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } if (this.IsActive) { switch (currentGameState) { case GameState.SignIn: { if (Gamer.SignedInGamers.Count < 1) { Guide.ShowSignIn(1, false); log.Add("Opened User SignIn Interface"); } else { currentGameState = GameState.SearchSession; log.Add(Gamer.SignedInGamers[0].Gamertag + " logged in - proceed to SearchSession"); } } break; case GameState.SearchSession: { AvailableNetworkSessionCollection activeSessions = NetworkSession.Find(NetworkSessionType.SystemLink, 4, null); if (activeSessions.Count == 0) { currentGameState = GameState.CreateSession; log.Add("No active sessions found - proceed to CreateSession"); } else { AvailableNetworkSession sessionToJoin = activeSessions[0]; networkSession = NetworkSession.Join(sessionToJoin); string myString = "Joined session hosted by " + sessionToJoin.HostGamertag; myString += " with " + sessionToJoin.CurrentGamerCount.ToString() + " players"; myString += " and " + sessionToJoin.OpenPublicGamerSlots.ToString() + " open player slots."; log.Add(myString); HookSessionEvents(); currentGameState = GameState.InSession; } } break; case GameState.CreateSession: { networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, 4, 16); networkSession.AllowHostMigration = true; networkSession.AllowJoinInProgress = false; log.Add("New session created"); HookSessionEvents(); currentGameState = GameState.InSession; } break; case GameState.InSession: { //send data to all other players in session writer.Write(gameTime.TotalGameTime.Minutes); writer.Write(gameTime.TotalGameTime.Seconds); LocalNetworkGamer localGamer = networkSession.LocalGamers[0]; localGamer.SendData(writer, SendDataOptions.ReliableInOrder); //receive data from all other players in session while (localGamer.IsDataAvailable) { NetworkGamer sender; localGamer.ReceiveData(reader, out sender); string gamerTime = ""; gamerTime += sender.Gamertag + ": "; gamerTime += reader.ReadInt32() + "m "; gamerTime += reader.ReadInt32() + "s"; gamerTimes[sender.Gamertag] = gamerTime; } networkSession.Update(); } break; } } base.Update(gameTime); }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } if (this.IsActive) { switch (currentGameState) { case GameState.SignIn: { if (Gamer.SignedInGamers.Count < 1) { Guide.ShowSignIn(1, false); log.Add("Opened User SignIn Interface"); } else { currentGameState = GameState.SearchSession; log.Add(Gamer.SignedInGamers[0].Gamertag + " logged in - proceed to SearchSession"); } } break; case GameState.SearchSession: { Gamer.SignedInGamers[0].Presence.PresenceMode = GamerPresenceMode.Level; Gamer.SignedInGamers[0].Presence.PresenceValue = 15; AvailableNetworkSessionCollection activeSessions = NetworkSession.Find(NetworkSessionType.SystemLink, 4, null); if (activeSessions.Count == 0) { currentGameState = GameState.CreateSession; log.Add("No active sessions found - proceed to CreateSession"); } else { AvailableNetworkSession sessionToJoin = activeSessions[0]; networkSession = NetworkSession.Join(sessionToJoin); string myString = "Joined session hosted by " + sessionToJoin.HostGamertag; myString += " with " + sessionToJoin.CurrentGamerCount.ToString() + " players"; myString += " and " + sessionToJoin.OpenPublicGamerSlots.ToString() + " open player slots."; log.Add(myString); HookSessionEvents(); currentGameState = GameState.InSession; } } break; case GameState.CreateSession: { networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, 4, 8); networkSession.AllowHostMigration = true; networkSession.AllowJoinInProgress = false; log.Add("New session created"); HookSessionEvents(); currentGameState = GameState.InSession; } break; case GameState.InSession: { networkSession.Update(); } break; } } base.Update(gameTime); }
private void CreateNetworkSession() { _networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, 1, WorldSettings.MAXGAMERS); _networkSession.GamerJoined += new EventHandler <GamerJoinedEventArgs>(_networkSession_GamerJoined); _networkSession.SessionEnded += new EventHandler <NetworkSessionEndedEventArgs>(_networkSession_SessionEnded); }