Example #1
0
        private void onUpdateServer()
        {
            String playerName;
            if (server.NumPlayers > 0)
            {
                // reset all current players stillconnected to false
                for (int i = 0; i < players.Count; i++)
                {
                    this.players[i].StillConnected = false;
                }

                this.listBox1.AllowDrop = true;
                for (int i = 0; i < server.NumPlayers; i++)
                {
                    playerName = server.Players[i].Name;
                    int playerIndex = getPlayerIndex(playerName);
                    // only add to list if it isn't already, if is in list, reset stillconnected flag
                    if (playerIndex == -1)
                    {
                        // create Player class and add to players list
                        Server_Browser.Player player = new Server_Browser.Player();
                        player.Name = playerName;
                        player.StillConnected = true;
                        this.players.Add(player);
                    }
                    else
                    {
                        // if already in list, reset stillconnected to true
                        this.players[playerIndex].StillConnected = true;
                    }
                }
                // clear list before we repopulate it
                this.listBox1.Items.Clear();
                // Only re-add players who are still connected
                for (int i = 0; i < this.players.Count; i++)
                {
                    if (this.players[i].StillConnected == true)
                    {
                        this.listBox1.Items.Add(players[i].Name);
                        // if class/team assigned already add class info to list
                        if (!(String.IsNullOrEmpty(players[i].Class) || String.IsNullOrEmpty(players[i].Team)))
                        {
                            int lastItem = this.listBox1.Items.Count - 1;
                            // System.Diagnostics.Debug.WriteLine("items: " + this.listBox1.Items.Count);
                            addClassText(lastItem);
                        }
                    }
                }

                // Loop over player list again to clean up any players who have disconnected
                // In separate loop to above otherwise if we loop over say 12 players and we remove one then we will get an index out of bounds exception at the end of the loop
                for (int i = 0; i < this.players.Count; i++)
                {
                    if (this.players[i].StillConnected == false)
                    {
                        if (!(String.IsNullOrEmpty(players[i].Class) || String.IsNullOrEmpty(players[i].Team)))
                        {
                            // reset icon if player was assigned
                            displayActiveIcon(players[i].IconIndex);
                        }
                        this.players.RemoveAt(i);
                    }
                }

                //initPictureBoxes();
            }
        }
Example #2
0
        private void onNewServer()
        {
            this.Tip.Text = server.Title;
            this.listBox1.Items.Clear();
            String playerName;
            if (server.NumPlayers > 0)
            {
                this.listBox1.AllowDrop = true;
                for (int i = 0; i < server.NumPlayers; i++)
                {
                    // get player name
                    playerName = server.Players[i].Name;

                    // create Player class and add to players list
                    Server_Browser.Player player = new Server_Browser.Player();
                    player.Name = playerName;
                    player.StillConnected = true;
                    players.Add(player);
                    this.listBox1.Items.Add(playerName);
                }
                initPictureBoxes();
            }
        }