예제 #1
0
        private async void refresh_button_Click(object sender, RoutedEventArgs e)
        {
            server = (server_list.SelectedItem as query_server.Server);
            int port_index = server.addr.IndexOf(':');

            port = server.addr.Remove(0, port_index + 1);
            server select_server = new server(ip, port);

            if (await select_server.connect_server())
            {
                game.Text                 = select_server.Game.TrimEnd('\0');
                name.Text                 = select_server.Name.TrimEnd('\0');
                map.Text                  = select_server.Map.TrimEnd('\0');
                players.Text              = select_server.Players_maxplayers.TrimEnd('\0');
                add_button.Visibility     = Visibility.Visible;
                refresh_button.Visibility = Visibility.Visible;
                await select_server.update_player_list();

                player_list.ItemsSource = select_server.Player_list.Select(x => x.TrimEnd('\0')).ToList <string>();
            }
            else
            {
                game.Text             = "连接失败";
                name.Text             = "";
                map.Text              = "";
                players.Text          = "";
                add_button.Visibility = Visibility.Collapsed;
            }
        }
예제 #2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            this.RegisterBackgroundTask();

            servers.ItemsSource = data_trans.server_list;
            foreach (server server in data_trans.server_list)
            {
                await server.connect_server();   //这里要等待每个udp完成连接 否则每个list中的server都会同时占据一个udp端口
            }
            if (e.Parameter is List <string> )
            {
                List <string> info = (e.Parameter as List <string>);
                if (info.Count != 0)
                {
                    server new_server = new server();
                    new_server.ip   = IPAddress.Parse(info[0]);
                    new_server.port = info[1];
                    new_server.connect_server();
                    //重复的不添加
                    if (data_trans.server_list.Any(s => s.Ip == new_server.Ip && s.Port == new_server.Port) == false)
                    {
                        data_trans.server_list.Add(new_server);
                    }
                    ip.Text = "";
                }
            }
        }