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 timer_Tick(object sender, EventArgs e) { timerTicks++; //game starting? if (gameStarting) { if ((timerTicks * timer.Interval - gameStartTime) % GAMESTART_INTERVAL == 0) { if (gameStartCount == 0) { this.DialogResult = DialogResult.OK; this.Close(); } //count down rtxtChatWindow.Text += "\n" + gameStartCount + "..."; rtxtChatWindow.Select(rtxtChatWindow.Text.Length + 1, 2); rtxtChatWindow.ScrollToCaret(); gameStartCount--; } } //update if (lobbyMode == LobbyMode.Hosting) { server.Update(); ProcessServerMessages(); } client.Update(); ProcessClientMessages(); //server management items if (lobbyMode == LobbyMode.Hosting) { // process disconnected ips IPAddress disconIP; while ((disconIP = server.GetDisconnectedIP()) != null) { if (server.IsPlayerConnected(disconIP)) { //Send chat message SpiderMessage message = new SpiderMessage( server.GetPlayerInfoString(disconIP) + " has disconnected.", SpiderMessageType.String, "chat"); server.SendMessage(message, NetChannel.ReliableUnordered); server.RemovePlayer(disconIP); } } // update player list for everyone if ((timer.Interval * timerTicks) % PLAYERLIST_UPDATE_INTERVAL == 0) { //SendPlayerList(); } } }
private void btnHost_Click(object sender, EventArgs e) { //Host a game // create a client and a server for the game lobby to use ymfasServer = new YmfasServer(txtName.Text); ymfasClient = new YmfasClient(txtName.Text); ymfasClient.Update(); ymfasClient.Connect(IPAddress.Loopback); //Enter lobby GameLobby = new frmGameLobby(ymfasClient, ymfasServer); GameLobby.ShowDialog(); // if we actually started a game if (GameLobby.DialogResult == DialogResult.OK) { ymfasClient = GameLobby.Client; ymfasServer = GameLobby.Server; this.DialogResult = DialogResult.OK; this.Close(); } }