예제 #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
        public async static void load_()
        {
            //    await Task.Run(() =>
            //    {
            Realm realmDB;

            realmDB = Realm.GetInstance("server_list.realm");
            var serverList = realmDB.All <server_saved>().ToList();

            foreach (server_saved server_saved in serverList)
            {
                server new_server = new server();
                new_server.Ip   = server_saved.Ip;
                new_server.Port = server_saved.Port;
                server_list.Add(new_server);
            }
            //});

            /*
             * Realm realmDB;
             * realmDB = Realm.GetInstance("server_list.realm");
             * var serverList = realmDB.All<server_saved>().ToList();
             * foreach (server_saved server_saved in serverList)
             * {
             *  server new_server = new server();
             *  new_server.Ip = server_saved.Ip;
             *  new_server.Port = server_saved.Port;
             *  server_list.Add(new_server);
             * }*/
        }
예제 #3
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 = "";
                }
            }
        }
예제 #4
0
        private async void detialsItem_Click(object sender, RoutedEventArgs e)
        {
            if (servers.SelectedItem != null)
            {
                ConnectedAnimation animation = null;
                _storedItem = servers.SelectedItem as server;
                await _storedItem.update_player_list();    //

                game_selected.Text    = _storedItem.Game.TrimEnd('\0');
                name_selected.Text    = _storedItem.Name.TrimEnd('\0');
                map_selected.Text     = _storedItem.Map.TrimEnd('\0');
                players_selected.Text = "Players:" + _storedItem.Players_maxplayers.TrimEnd('\0');
                List <string> Player_list = new List <string>();
                Player_list             = _storedItem.Player_list.Select(x => x.TrimEnd('\0')).ToList <string>();
                player_list.ItemsSource = _storedItem.Player_list;
                animation = servers.PrepareConnectedAnimation("forwardAnimation", _storedItem, "connectedElement");

                SmokeGrid.Visibility = Visibility.Visible;

                animation.TryStart(destinationElement);
            }
        }