示例#1
0
文件: Lobby.cs 项目: pnill/T4Browser
        public void UpdateLobby(Packet pack)
        {
            /*
             * We just joined
             * Make sure we grab existing players.
             */

            if (pack.LobbySnapshot.SnapType == TJoin)
            {
                foreach (player player_pack in pack.LobbySnapshot.Players)
                {
                    if (player_pack.Name != player_name)
                    {
                        AddPlayer(player_pack.Name, null, true);
                    }
                }
            }
            else
            {
                AddChatText("Server Notice", "The host has updated game options!");
            }

            /* Whether we're just joining or host changed options, we need to update this */
            frag_text.Text       = pack.LobbySnapshot.FragLimit.ToString();
            time_limit_text.Text = pack.LobbySnapshot.TimeLimit.ToString();
            map_text.Text        = pack.LobbySnapshot.MapName.ToString();
            player_count.Text    = "Players: " + players_in_server + " / 16";
            map_id = pack.LobbySnapshot.MapId;

            foreach (game_option goption in pack.LobbySnapshot.Options)
            {
                switch (goption.OptionType)
                {
                case OGamePlay:
                    GameOptions_List.SetItemChecked(goption.Index, goption.Option);
                    break;

                case OWeaponAvail:
                    WeaponAllowed_List.SetItemChecked(goption.Index, goption.Option);
                    break;

                case OWeaponSpawn:
                    WeaponSpawn_List.SetItemChecked(goption.Index, goption.Option);
                    break;
                }
            }

            switch (pack.LobbySnapshot.GameType)
            {
            case 2:
                type_text.Text = "Death Match";
                break;
            }
        }
示例#2
0
文件: Lobby.cs 项目: pnill/T4Browser
        public void UpdateHostLobby(bool update = true)
        {
            Host_Options_Pack = new Packet();
            Host_Options_Pack.LobbySnapshot = new Google.Protobuf.Pack.host_snap();

            frag_text.Text       = host_form.set_frag_limit.ToString();
            time_limit_text.Text = host_form.set_time_limit.ToString();
            map_text.Text        = host_form.set_map.Text;
            type_text.Text       = host_form.set_gametype.Text;

            // Since the packet gets re-created we need to re-add all the players
            if (lobby_server != null)
            {
                foreach (KeyValuePair <string, player> player_entry in lobby_server.PlayerToPack)
                {
                    Host_Options_Pack.LobbySnapshot.Players.Add(player_entry.Value);
                }
            }

            player player_pack = new player();

            player_pack.Name = player_name;
            Host_Options_Pack.LobbySnapshot.Players.Add(player_pack);


            if (!update)
            {
                players_in_server++;
                playerlist.Items.Add(player_name);
            }


            player_count.Text = "Players: " + (playerlist.Items.Count) + " / " + host_form.set_player_limit;


            Host_Options_Pack.LobbySnapshot.FragLimit = host_form.set_frag_limit;
            Host_Options_Pack.LobbySnapshot.TimeLimit = host_form.set_time_limit;
            Host_Options_Pack.LobbySnapshot.MapName   = map_text.Text;
            Host_Options_Pack.LobbySnapshot.GameType  = 2; // Place holder, we only support death match for now.
            Host_Options_Pack.LobbySnapshot.MapId     = host_form.set_map.SelectedIndex;

            for (int i = 0; i < host_form.game_option.Items.Count; i++)
            {
                game_option goption = new game_option();
                goption.OptionType = OGamePlay;
                goption.Index      = i;

                if (host_form.game_option.GetItemChecked(i))
                {
                    goption.Option = true;
                    GameOptions_List.SetItemChecked(i, true);
                }
                else
                {
                    goption.Option = false;
                    GameOptions_List.SetItemChecked(i, false);
                }

                Host_Options_Pack.LobbySnapshot.Options.Add(goption);
            }

            for (int i = 0; i < host_form.weapon_available.Items.Count; i++)
            {
                game_option goption = new game_option();
                goption.OptionType = OWeaponAvail;
                goption.Index      = i;

                if (host_form.weapon_available.GetItemChecked(i))
                {
                    goption.Option = true;
                    WeaponAllowed_List.SetItemChecked(i, true);
                }
                else
                {
                    goption.Option = false;
                    WeaponAllowed_List.SetItemChecked(i, false);
                }

                Host_Options_Pack.LobbySnapshot.Options.Add(goption);
            }

            for (int i = 0; i < host_form.weapon_spawn.Items.Count; i++)
            {
                game_option goption = new game_option();
                goption.OptionType = OWeaponSpawn;
                goption.Index      = i;

                if (host_form.weapon_spawn.GetItemChecked(i))
                {
                    goption.Option = true;
                    WeaponSpawn_List.SetItemChecked(i, true);
                }
                else
                {
                    goption.Option = false;
                    WeaponSpawn_List.SetItemChecked(i, false);
                }

                Host_Options_Pack.LobbySnapshot.Options.Add(goption);
            }

            if (update)
            {
                Host_Options_Pack.LobbySnapshot.SnapType = TUpdate;
                Host_Options_Pack.Type = HostSnapshot;
                lobby_server.SendPacketToAll(Host_Options_Pack);
            }
        }