private void ExecuteRemoteCommand(IDebugCommandHost host, string command, IList <string> arguments) { if (NetworkSession == null) { try { GamerServicesDispatcher.WindowHandle = Game.Window.Handle; GamerServicesDispatcher.Initialize(Game.Services); } catch { } if (SignedInGamer.SignedInGamers.Count > 0) { commandHost.Echo("Finding available sessions..."); asyncResult = NetworkSession.BeginFind( NetworkSessionType.SystemLink, 1, null, null, null); phase = ConnectionPahse.FindSessions; } else { host.Echo("Please signed in."); phase = ConnectionPahse.EnsureSignedIn; } } else { ConnectedToRemote(); } }
private void ExecuteRemoteCommand(IDebugCommandHost host, string command, IList<string> arguments) { if (NetworkSession == null) { try { GamerServicesDispatcher.WindowHandle = Game.Window.Handle; GamerServicesDispatcher.Initialize(Game.Services); } catch { } if (SignedInGamer.SignedInGamers.Count > 0) { commandHost.Echo("Finding available sessions..."); asyncResult = NetworkSession.BeginFind( NetworkSessionType.SystemLink, 1, null, null, null); phase = ConnectionPahse.FindSessions; } else { host.Echo("Please signed in."); phase = ConnectionPahse.EnsureSignedIn; } } else { ConnectedToRemote(); } }
/// <summary> /// Update /// </summary> public override void Update(GameTime gameTime) { // Process different phases. switch (phase) { case ConnectionPahse.EnsureSignedIn: GamerServicesDispatcher.Update(); break; case ConnectionPahse.FindSessions: GamerServicesDispatcher.Update(); if (asyncResult.IsCompleted) { AvailableNetworkSessionCollection sessions = NetworkSession.EndFind(asyncResult); if (sessions.Count > 0) { asyncResult = NetworkSession.BeginJoin( sessions[0], null, null ); commandHost.EchoError("Connecting to the host..."); phase = ConnectionPahse.Joining; } else { commandHost.EchoError("Couldn't find a session."); phase = ConnectionPahse.None; } } break; case ConnectionPahse.Joining: GamerServicesDispatcher.Update(); if (asyncResult.IsCompleted) { NetworkSession = NetworkSession.EndJoin(asyncResult); NetworkSession.SessionEnded += new EventHandler<NetworkSessionEndedEventArgs>( NetworkSession_SessionEnded); OwnsNetworkSession = true; commandHost.EchoError("Connected to the host."); phase = ConnectionPahse.None; asyncResult = null; ConnectedToRemote(); } break; } // Update Network session. if (OwnsNetworkSession) { GamerServicesDispatcher.Update(); NetworkSession.Update(); if (NetworkSession != null) { // Process received packets. foreach (LocalNetworkGamer gamer in NetworkSession.LocalGamers) { while (gamer.IsDataAvailable) { NetworkGamer sender; gamer.ReceiveData(packetReader, out sender); if (!sender.IsLocal) ProcessRecievedPacket(packetReader.ReadString()); } } } } base.Update(gameTime); }
/// <summary> /// Update /// </summary> public override void Update(GameTime gameTime) { // Process different phases. switch (phase) { case ConnectionPahse.EnsureSignedIn: GamerServicesDispatcher.Update(); break; case ConnectionPahse.FindSessions: GamerServicesDispatcher.Update(); if (asyncResult.IsCompleted) { AvailableNetworkSessionCollection sessions = NetworkSession.EndFind(asyncResult); if (sessions.Count > 0) { asyncResult = NetworkSession.BeginJoin(sessions[0], null, null); commandHost.EchoError("Connecting to the host..."); phase = ConnectionPahse.Joining; } else { commandHost.EchoError("Couldn't find a session."); phase = ConnectionPahse.None; } } break; case ConnectionPahse.Joining: GamerServicesDispatcher.Update(); if (asyncResult.IsCompleted) { NetworkSession = NetworkSession.EndJoin(asyncResult); NetworkSession.SessionEnded += new EventHandler <NetworkSessionEndedEventArgs>( NetworkSession_SessionEnded); OwnsNetworkSession = true; commandHost.EchoError("Connected to the host."); phase = ConnectionPahse.None; asyncResult = null; ConnectedToRemote(); } break; } // Update Network session. if (OwnsNetworkSession) { GamerServicesDispatcher.Update(); NetworkSession.Update(); if (NetworkSession != null) { // Process received packets. foreach (LocalNetworkGamer gamer in NetworkSession.LocalGamers) { while (gamer.IsDataAvailable) { NetworkGamer sender; gamer.ReceiveData(packetReader, out sender); if (!sender.IsLocal) { ProcessRecievedPacket(packetReader.ReadString()); } } } } } base.Update(gameTime); }