Esempio n. 1
0
        private List <GameServerItem> LoadGSList(string path)
        {
            var stream = File.OpenRead(path);
            var xml    = new XmlSerializer(typeof(List <GSSaveList>));
            List <GSSaveList> saveList = (List <GSSaveList>)xml.Deserialize(stream);

            stream.Close();

            List <GameServerItem> gsList = new List <GameServerItem>();

            foreach (GSSaveList slItem in saveList)
            {
                GameServerItem gsi = new GameServerItem
                {
                    ServerName = slItem.ServerName,
                    ServerCode = slItem.ServerCode,
                    IPAddress  = IPAddress.Parse(slItem.IPAddress),
                    Port       = slItem.Port,
                    IsHidden   = slItem.Show
                };

                gsList.Add(gsi);
            }

            return(gsList);
        }
Esempio n. 2
0
        private void addServer_Click(object sender, RoutedEventArgs e)
        {
            if (!editingServer)
            {
                GameServerItem gsitem = new GameServerItem
                {
                    ServerName = serverName.Text,
                    ServerCode = Convert.ToInt32(serverCode.Text),
                    IPAddress  = IPAddress.Parse(serverIp.Text),
                    Port       = Convert.ToInt32(serverPort.Text),
                    IsHidden   = hideServer.IsChecked.Value
                };

                GSList.Add(gsitem);

                serverList.ItemsSource = null;
                serverList.ItemsSource = GSList;

                SaveGSList("ServerList.xml");
            }
            else
            {
                int            srvCode = Convert.ToInt32(serverCode.Text);
                GameServerItem gsitem  = GSList.FirstOrDefault(wr => wr.ServerCode == srvCode);

                if (gsitem == null)
                {
                    addServer.Content     = "Add Server";
                    editingServer         = false;
                    cancelEdit.Visibility = Visibility.Hidden;
                    return;
                }

                int index = GSList.IndexOf(gsitem);


                gsitem.ServerName = serverName.Text;
                gsitem.ServerCode = Convert.ToInt32(serverCode.Text);
                gsitem.IPAddress  = IPAddress.Parse(serverIp.Text);
                gsitem.Port       = Convert.ToInt32(serverPort.Text);
                gsitem.IsHidden   = hideServer.IsChecked.Value;

                GSList.RemoveAt(index);
                GSList.Insert(index, gsitem);

                serverList.ItemsSource = null;
                serverList.ItemsSource = GSList;

                SaveGSList("ServerList.xml");

                addServer.Content     = "Add Server";
                editingServer         = false;
                cancelEdit.Visibility = Visibility.Hidden;
            }

            ClearConfigControls();
        }
Esempio n. 3
0
        private void serverList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (serverList.SelectedItems.Count == 0)
            {
                return;
            }

            GameServerItem gsi = serverList.SelectedItem as GameServerItem;

            tabControl.SelectedIndex = 1;

            serverName.Text      = gsi.ServerName;
            serverCode.Text      = gsi.ServerCode.ToString();
            serverIp.Text        = gsi.IPAddress.ToString();
            serverPort.Text      = gsi.Port.ToString();
            showServer.IsChecked = !gsi.IsHidden;
            hideServer.IsChecked = gsi.IsHidden;

            addServer.Content     = "Save Changes";
            editingServer         = true;
            cancelEdit.Visibility = Visibility.Visible;
        }
Esempio n. 4
0
        private void removeServerMI_Click(object sender, RoutedEventArgs e)
        {
            if (serverList.SelectedItems.Count == 0)
            {
                return;
            }

            GameServerItem gsi = serverList.SelectedItem as GameServerItem;

            if (MessageBox.Show(string.Format("Server [{0}] with Code [{1}] will be removed. Continue ?",
                                              gsi.ServerName, gsi.ServerCode), "Delete GameServer", MessageBoxButton.YesNo,
                                MessageBoxImage.Warning) != MessageBoxResult.Yes)
            {
                return;
            }

            GSList.Remove(gsi);

            serverList.ItemsSource = null;
            serverList.ItemsSource = GSList;

            SaveGSList("ServerList.xml");
        }