Ejemplo n.º 1
0
        static void retriever_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                var serverList = new List<KMPServer>();

                string[] lines = e.Result.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);//Split file into lines

                foreach (string s in lines)
                {
                    var server = new KMPServer();

                    string[] splitServer = s.Split(':');

                    server.IP = splitServer[0];

                    server.IsGlobal = true;

                    server.HTTPPort = int.Parse(splitServer[1]);

                    serverList.Add(server);

                }

                Retrieved(serverList);
            }
        }
        public void RetrieveAsync(KMPServer s,int HTTPPort)
        {
            var retriever = new WebClient();

            retriever.DownloadStringCompleted += retriever_DownloadStringCompleted;

            var url = new Uri("http://" + s.IP + ":" + HTTPPort + "/");//Make a nice URL out of the IP and Port

            retriever.DownloadStringAsync(url,s);//Parse the server along when sending
        }
Ejemplo n.º 3
0
        private void AddNewServer_Click(object sender, EventArgs e)
        {
            if (PlayerServers.Exists(ser => ser.Address == textBoxAddress.Text))
            {
                MessageBox.Show("Server already exists.");
                return;
            }
            var server = new KMPServer {Name = textBoxName.Text, Address = textBoxAddress.Text};

            PlayerServers.Add(server);

            FillServerList();
        }
Ejemplo n.º 4
0
        public static void JoinKMPServer(KMPServer server)
        {
            if (server.Version == UpdaterSettings.CurrentKMPUpdate | !server.HasHTTPConnection)
            {
                if (UpdaterSettings.KSPExists & UpdaterSettings.KMPExists)
                {
                    if (!File.Exists(UpdaterSettings.KMPDirectory + @"\PluginData\KerbalMultiPlayer\KMPClientConfig.xml"))
                    {
                        if (!Directory.Exists(UpdaterSettings.KMPDirectory + @"\PluginData\"))
                        {
                            Directory.CreateDirectory(UpdaterSettings.KMPDirectory + @"\PluginData\");
                        }
                        if (!Directory.Exists(UpdaterSettings.KMPDirectory + @"\PluginData\KerbalMultiPlayer\"))
                        {
                            Directory.CreateDirectory(UpdaterSettings.KMPDirectory + @"\PluginData\KerbalMultiPlayer\");
                        }

                        FileStream file = File.Create(UpdaterSettings.KMPDirectory + @"\PluginData\KerbalMultiPlayer\KMPClientConfig.xml");
                        file.Close();
                    }

                    var clientConfig = new XmlDocument();

                    clientConfig.Load(UpdaterSettings.KMPDirectory + @"\PluginData\KerbalMultiPlayer\KMPClientConfig.xml");

                    XmlNode username = clientConfig.DocumentElement.SelectSingleNode("//global/@username");
                    XmlNode hostname = clientConfig.DocumentElement.SelectSingleNode("//favourite/@hostname");

                    username.Value = UpdaterSettings.Username;
                    hostname.Value = server.Address;

                    clientConfig.Save(UpdaterSettings.KMPDirectory + @"\PluginData\KerbalMultiPlayer\KMPClientConfig.xml");

                    var startInfo = new ProcessStartInfo
                                        {
                                            WorkingDirectory = UpdaterSettings.KSPDirectory,
                                            FileName = UpdaterSettings.KSPExecutable
                                        };

                    Process.Start(startInfo);
                }
                else
                {
                    MessageBox.Show("Please check directory settings. KSP or KMP not found.");
                }
            }
            else
            {
                MessageBox.Show("Version mis-match between server and client. \nServer Version: " + server.Version + "\nClient Version: " + UpdaterSettings.CurrentKMPUpdate);
            }
        }
Ejemplo n.º 5
0
        private void ServerInformationListBox_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            LastSelectedListViewItem.BackColor = SystemColors.Window;//Remove highlight from last selection

            e.Item.BackColor = SystemColors.Highlight;//Add highlight to new selection

            LastSelectedListViewItem = e.Item;//Make this 'last selection'

            LastSelectedServer = new KMPServer();
            if (LastSelectedListViewItem.Group == PlayerServerGroup)
            {
                foreach (KMPServer s in PlayerServers.Where(s => s.Address == e.Item.SubItems[1].Text))
                {
                    LastSelectedServer = s;
                    break;
                }
            }
            else if (LastSelectedListViewItem.Group == GlobalServerGroup)
            {
                foreach (KMPServer s in GlobalServers.Where(s => s.Address == e.Item.SubItems[1].Text))
                {
                    LastSelectedServer = s;
                    break;
                }
            }
            else
            {
                return;//dont bother if a server isn't found
            }

            textBoxName.Text = LastSelectedServer.Name;
            textBoxAddress.Text = LastSelectedServer.Address;

            textBoxAddress.ForeColor = SystemColors.WindowText;
            textBoxName.ForeColor = SystemColors.WindowText;

            ServerInformationListBox.Items.Clear();

            ServerInformationListBox.Items.Add("Whitelist: " + LastSelectedServer.Whitelisted.ToString().ToLower());
            ServerInformationListBox.Items.Add("Screenshots Save: " + LastSelectedServer.Screenshots.ToString().ToLower());
            ServerInformationListBox.Items.Add("Screenshot Height: " + LastSelectedServer.ScreenshotHeight);
            ServerInformationListBox.Items.Add("Update Rate: " + LastSelectedServer.UpdateRate);
            ServerInformationListBox.Items.Add("Inactive Ship Limit: " + LastSelectedServer.InactiveShipLimit);

            PlayerListBox.Items.Clear();
            foreach (string s in LastSelectedServer.PlayerList)
            {
                PlayerListBox.Items.Add(s);
            }
        }
Ejemplo n.º 6
0
        private void retriever_EditServerRetrieved(KMPServer s)
        {
            LastSelectedServer = s;

            LastSelectedListViewItem.SubItems.Clear();

            LastSelectedListViewItem.Text = LastSelectedServer.Name;

            LastSelectedListViewItem.SubItems.Add(LastSelectedServer.IP + ":" + LastSelectedServer.Port);
            LastSelectedListViewItem.SubItems.Add(LastSelectedServer.Version);
            LastSelectedListViewItem.SubItems.Add(LastSelectedServer.Players + "/" + LastSelectedServer.MaxPlayers);
            LastSelectedListViewItem.SubItems.Add(LastSelectedServer.Information);

            if (!LastSelectedServer.HasHTTPConnection)
            {
                LastSelectedListViewItem.ForeColor = Color.DarkRed;
            }
        }
Ejemplo n.º 7
0
        void retrieverLocal_ServerRetrieved(KMPServer s)
        {
            var serveritem = new ListViewItem(s.Name);
            serveritem.SubItems.Add(s.IP + ":" + s.Port);
            serveritem.SubItems.Add(s.Version);
            serveritem.SubItems.Add(s.Players + "/" + s.MaxPlayers);
            serveritem.SubItems.Add(s.Information);

            if (!s.HasHTTPConnection)
            {
                serveritem.ForeColor = Color.DarkRed;
            }

            serveritem.Group = PlayerServerGroup;

            listView1.Groups.Add(PlayerServerGroup);
            listView1.Items.Add(serveritem);
        }
Ejemplo n.º 8
0
        private void retrieverGlobal_ServerRetrieved(KMPServer s)
        {
            if (!s.HasHTTPConnection)
            {
                return;//Dont even bother if no http connection.
            }

            var serveritem = new ListViewItem(s.Name);
            serveritem.SubItems.Add(s.IP + ":" + s.Port);
            serveritem.SubItems.Add(s.Version);
            serveritem.SubItems.Add(s.Players + "/" + s.MaxPlayers);
            serveritem.SubItems.Add(s.Information);

            serveritem.Group = GlobalServerGroup;

            listView1.Groups.Add(GlobalServerGroup);
            listView1.Items.Add(serveritem);
        }
Ejemplo n.º 9
0
        private void LoadServers()
        {
            if (!File.Exists(UpdaterSettings.LAUNCHER_FOLDER + UpdaterSettings.SERVER_FILE))
            {
                FileStream file = File.Create(UpdaterSettings.LAUNCHER_FOLDER + UpdaterSettings.SERVER_FILE);
                file.Close();
            }
            var reader = new StreamReader(UpdaterSettings.LAUNCHER_FOLDER + UpdaterSettings.SERVER_FILE);
            while (reader.ReadLine() == SERVER_CONST)
            {
                var server = new KMPServer
                                 {Name = reader.ReadLine(), IP = reader.ReadLine(), Port = int.Parse(reader.ReadLine())};
                if (!String.IsNullOrEmpty(server.IP))
                {
                    PlayerServers.Add(server);
                }
            }

            reader.Close();
        }