private void btnJoinLobby_Click(object sender, EventArgs e) { if (this.joinedLobby == null && this.createdLobby == null && !this.connectingToLobby && this.lstLobbies.SelectedItem != null) { this.joinedLobby = this.network.JoinLobby((LobbyInfo)this.lstLobbies.SelectedItem, this); if (this.joinedLobby != null) { this.connectingToLobby = true; UpdateControls(); } } }
/// <summary> /// Connects to an existing DSS-lobby on the network. /// </summary> /// <param name="dssLobby">The information package of the lobby that contains data for the connection.</param> /// <param name="network">The network interface that is used to connect.</param> /// <param name="simulatorIface">Interface of the local simulator implemented by the client module.</param> /// <param name="setupIface">Interface of the setup manager object implemented by the client module.</param> /// <remarks>The caller thread will be blocked while the peer is connected to the DSS.</remarks> public static void ConnectDSS(LobbyInfo dssLobby, INetwork network, ISimulator simulatorIface, IDssGuestSetup setupIface) { if (dssLobby == null) { throw new ArgumentNullException("dssLobby"); } if (network == null) { throw new ArgumentNullException("network"); } if (simulatorIface == null) { throw new ArgumentNullException("simulatorIface"); } if (setupIface == null) { throw new ArgumentNullException("setupIface"); } //throw new Exception("Test exception"); dssActive.WaitOne(); try { DssGuestRoot guestRoot = new DssGuestRoot(simulatorIface, setupIface); GuestEventHandler eventHdl = new GuestEventHandler(guestRoot); guestRoot.EventQueue.RegisterHandler(eventHdl); ILobbyClient client = network.JoinLobby(dssLobby, guestRoot.EventQueue); if (client == null) { throw new DssException("Cannot join to the lobby under the DSS!"); } guestRoot.Lobby = client; guestRoot.EventQueue.EventLoop(); client.Disconnect(); guestRoot.Dispose(); } catch (Exception ex) { TraceManager.WriteExceptionAllTrace(ex, false); } finally { dssActive.Release(); } }
/// <see cref="ILobbyListener.LobbyLost"/> public void LobbyLost() { if (this.InvokeRequired) { /// Invoke this function from the UI thread. this.Invoke(new LobbyLostCallback(this.LobbyLost)); } else { /// Normal invoke. this.joinedLobby = null; this.createdLobby = null; this.lastKnownLineStates = null; this.lastKnownIdOfThisPeer = -1; this.connectingToLobby = false; UpdateControls(); } }
private void btnShutdownDisconnectLobby_Click(object sender, EventArgs e) { if (this.joinedLobby != null && this.createdLobby == null && !this.connectingToLobby) { this.joinedLobby.Disconnect(); this.connectingToLobby = false; this.joinedLobby = null; this.createdLobby = null; this.lastKnownLineStates = null; this.lastKnownIdOfThisPeer = -1; this.connectingToLobby = false; UpdateControls(); } else if (this.joinedLobby == null && this.createdLobby != null && !this.connectingToLobby) { this.createdLobby.Shutdown(); this.joinedLobby = null; this.createdLobby = null; this.lastKnownLineStates = null; this.lastKnownIdOfThisPeer = -1; this.connectingToLobby = false; UpdateControls(); } }