private void timer_Tick(object sender, EventArgs e) { //looking for servers if (splashState == MainSplashState.Searching) { Console.Out.WriteLine("searching..."); //update the engine state ymfasClient.Update(); //attempt to find a new server Lidgren.Library.Network.NetServerInfo session = ymfasClient.GetLocalSession(); if (session != null) { String hostname = ymfasClient.GetHostNameFromIP(session.RemoteEndpoint.Address.ToString()); lstServers.Items.Add(hostname + " - " + session.RemoteEndpoint.Address.ToString()); } } //connecting to a server if (splashState == MainSplashState.Connecting) { // update the engine state ymfasClient.Update(); //time out if too long if (ticksConnecting * timer.Interval >= MAX_CONNECT_TIME) { splashState = MainSplashState.Searching; ymfasClient.Dispose(); ymfasClient = null; MessageBox.Show("Connection attempt failed."); } else { ticksConnecting++; //check for successful connection if (ymfasClient.Status == NetConnectionStatus.Connected) { splashState = MainSplashState.None; // join lobby GameLobby = new frmGameLobby(ymfasClient); GameLobby.ShowDialog(); if (GameLobby.DialogResult == DialogResult.OK) { ymfasClient = GameLobby.Client; this.DialogResult = DialogResult.OK; this.Close(); } } } } }
private void frmGameLobby_FormClosing(object sender, FormClosingEventArgs e) { if (!gameStarting) { client.Dispose(); if (lobbyMode == LobbyMode.Hosting) { server.Dispose(); } } }
public void Dispose() { // destroy all scene instance-specific information DisposeScene(); netClient.Dispose(); netClient = null; if (world != null) { world.Dispose(); world = null; } if (root != null) { root.Dispose(); root = null; } }