Example #1
0
        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();
                }
            }
        }