public Server addServerThread(String ip, int port, Servers serversInstance)
        {
            var s = new Server();

            IPAddress address = NetExtras.HostnameToIP(ip);
            changeCurrThread(-1, true);
            if (address == null)
                return null;

            s.setVariable(Protocol.Protocol.ipAddressSTR, ip);
            s.setVariable(Protocol.Protocol.portSTR, port.ToString());
            string ipport = ip + Server.separator + port;

            if (port > 0 && serversInstance.masterServers.ContainsKey(ipport) == false)
            {
                try
                {
                    serversInstance.masterServers.Add(ipport, s);
                    return s;
                }
                catch
                {
                }
            }
            return null;
        }
        private static void ExtractServers(Servers serversInstance, threads threadsInstance, byte[] data)
        {
            if (data == null)
                return;
            String datastr = Encoding.ASCII.GetString(data);

            var seps = new string[1];
            seps[0] = "\\";
            string[] ips = datastr.Split(seps, StringSplitOptions.RemoveEmptyEntries);

            foreach (var s in ips)
            {
                if (s.Length != 6)
                    continue;

                String ip = "";
                ip += ((int)s[0]).ToString(CultureInfo.InvariantCulture) + ".";
                ip += ((int)s[1]).ToString(CultureInfo.InvariantCulture) + ".";
                ip += ((int)s[2]).ToString(CultureInfo.InvariantCulture) + ".";
                ip += ((int)s[3]).ToString(CultureInfo.InvariantCulture);

                int port = (s[4]) * 256 + (s[5]);

                threadsInstance.addServerThread(ip, port, serversInstance);
            }
        }
        public void addServerCollectionThread(ToolStripLabel toolStripLabel, ref StatusStrip SS, String file,
                                              Servers serversInstance, threads threadsInstance)
        {
            int maxthreads = 90;

            changeCurrThread(0, false);

            var r = new Regex(@"([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+)|([a-zA-Z][a-zA-Z0-9\-\.]+?:[0-9]+)");
            MatchCollection mc;
            try
            {
                mc = r.Matches(file);
            }
            catch
            {
                Controller.ToolStripText(toolStripLabel, ref SS, "Ready");
                return;
            }

            int count = 0;
            foreach (Match m in mc)
            {
            retry:
                if (killThreads)
                    break;

                if (currthreads > maxthreads)
                {
                    Thread.Sleep(100);
                    goto retry;
                }

                Controller.ToolStripText(toolStripLabel, ref SS,
                                         "Verifying/Adding Server:" + count.ToString() + "/" + mc.Count);
                KeyValuePair<String, String> coll = Server.getIpPort(m.ToString());

                changeCurrThread(1, true);
                var t = new Thread(() => addServerThread(coll.Key, int.Parse(coll.Value), serversInstance));
                t.Start();
                count++;
            }

            while (currthreads > 0)
            {
                Thread.Sleep(100);
            }
        }
        public static void MasterServerAdd(ToolStripLabel toolStripLabel, StatusStrip SS, Servers serversInstance,
                                           threads threadsInstance)
        {
            //we need to increase the 15th byte to change the region
            byte[] gs = Protocol.Protocol.cod4getservers;
            for (int region = 0; region < 6; region++)
            {
                ToolStripText(toolStripLabel, ref SS, "Adding region:" + region + "/6");
                byte[] rec =
                    Networking.SendUDPPacketGetBlockingResponse(
                        NetExtras.HostnameToIP(Protocol.Protocol.MasterServer), 20810, gs);
                gs[15]++;

                ExtractServers(serversInstance, threadsInstance, rec);
            }

            ToolStripText(toolStripLabel, ref SS, "Ready");
        }
        public static void DeleteSelected(ListView serverView, Servers serversInstance)
        {
            ListView.SelectedListViewItemCollection slvic = serverView.SelectedItems;

            int count = 0;
            String ips = "";
            foreach (ListViewItem lvi in slvic)
            {
                if (count > 10)
                {
                    ips += "...";
                    break;
                }
                count++;
                ips += lvi.Name + "\n";
            }


            DialogResult dr = MessageBox.Show("Are you sure you want to delete these ips?\n" + ips, "question",
                                              MessageBoxButtons.YesNo);
            if (dr == DialogResult.No)
                return;


            foreach (ListViewItem lvi in slvic)
            {
                serverView.Items.Remove(lvi);
                serversInstance.masterServers.Remove(lvi.Name);
            }
        }
        public static async Task ServersFromUrl(ToolStripLabel toolStripLabel, StatusStrip ss, Servers serversInstance,
                                          threads threadsInstance, ListView serverView, view baseView)
        {
            var sb = new getStringBox();
            sb.label1.Text = "Enter URL to extract ip:ports from";
            sb.ShowDialog();
            String ret = sb.returnvalue;
            if (ret == "")
                return;

            ToolStripText(toolStripLabel, ref ss, "Extracting Web Page Text");
            var page = await NetExtras.DownloadWebPage(ret);

            if (page == null)
            {
                MessageBox.Show("Not a valid webpage");
                return;
            }
            
            threadsInstance.addServerCollectionThread(toolStripLabel, ref ss, page, serversInstance, threadsInstance);

            ToolStripText(toolStripLabel, ref ss, "Ready");
            baseView.allServersToServerView();
        }
        public static void ServersFromFile(ToolStripLabel toolStripLabel, StatusStrip ss, Servers serversInstance,
                                           threads threadsInstance, ListView serverView, view baseView)
        {
            var ofd = new OpenFileDialog();
            ofd.Title = "Select file to extract ip:ports from";
            ofd.ShowDialog();
            if (string.IsNullOrEmpty(ofd.FileName))
                return;

            var fs = new FileStream(ofd.FileName, FileMode.Open);
            var sr = new StreamReader(fs);

            String file = sr.ReadToEnd();
            sr.Close();
            fs.Close();

            threadsInstance.addServerCollectionThread(toolStripLabel, ref ss, file, serversInstance, threadsInstance);

            ToolStripText(toolStripLabel, ref ss, "Ready");
            baseView.allServersToServerView();
        }
        //refresh selected items in listview
        public static void Refreshselected(ListView serverView, Protocol.Protocol protocolInstance,
                                           Servers serversInstance)
        {
            Server serv = serversInstance.masterServers[serverView.SelectedItems[0].Name];

            protocolInstance.updateServerInfo(serv, Protocol.Protocol.basic);

            UpdateServerInServerView(serv, serverView);
        }
 public static void UpdateFavourite(ListView serverView, Servers serversInstance, bool isFavourite)
 {
     foreach (ListViewItem lvi in serverView.SelectedItems)
     {
         Server s = serversInstance.masterServers[lvi.Name];
         s.setVariable(Protocol.Protocol.favouriteSTR, isFavourite.ToString());
         UpdateServerInServerView(s, serverView);
     }
 }
Exemple #10
0
        private void updateListServerViewThread(view baseView, ListView serverView, ToolStripLabel toolStripLabel,
                                                StatusStrip SS, Servers serversInstance,
                                                Protocol.Protocol protocolInstance,
                                                String ipport)
        {
            if (baseView.serversInstance.masterServers.ContainsKey(ipport) == false)
                baseView.serversInstance.masterServers.Add(ipport, new Server());

            Server serv = baseView.serversInstance.masterServers[ipport];
            protocolInstance.updateServerInfo(serv, Protocol.Protocol.basic);
            Controller.UpdateServerInServerView(serv, serverView);
            changeCurrThread(-1, true);
        }
Exemple #11
0
        public void updateAllServersThread(view baseView, ListView serverView, ToolStripLabel toolStripLabel,
                                           StatusStrip SS, Servers serversInstance, Protocol.Protocol protocolInstance,
                                           bool selectedOnly, bool serverViewOnly)
        {
            killThreads = false;

            int maxthreads = 90;

            changeCurrThread(0, false);
            int count = 0;

            var updateList = new List<string>();
            int max = 0;
            //refresh selected in server view
            if (selectedOnly && serverViewOnly)
            {
                ListView.SelectedListViewItemCollection SLVIC = serverView.SelectedItems;
                max = SLVIC.Count;
                foreach (ListViewItem LVI in SLVIC)
                {
                    updateList.Add(LVI.Name);
                }
            }
            //refresh all in server view
            else if (selectedOnly == false && serverViewOnly)
            {
                max = serverView.Items.Count;
                foreach (ListViewItem LVI in serverView.Items)
                {
                    updateList.Add(LVI.Name);
                }
            }
            //otherwise refresh all in database
            else
            {
                max = serversInstance.masterServers.Keys.Count;
                foreach (String s in serversInstance.masterServers.Keys)
                {
                    updateList.Add(s);
                }
            }

            foreach (String s in updateList)
            {
                if (selectedOnly && serverViewOnly == false && serverView.Items.ContainsKey(s) == false)
                    continue;

            retry:
                if (killThreads)
                    break;

                if (currthreads > maxthreads)
                {
                    Thread.Sleep(100);
                    goto retry;
                }

                changeCurrThread(1, true);
                Thread t;

                if (serverViewOnly)
                    t =
                        new Thread(
                            () =>
                            updateListServerViewThread(baseView, serverView, toolStripLabel, SS, serversInstance,
                                                       protocolInstance, s));
                else
                    t =
                        new Thread(
                            () =>
                            updateListBackThread(baseView, serverView, toolStripLabel, SS, serversInstance,
                                                 protocolInstance, s));
                t.Start();

                Controller.ToolStripText(toolStripLabel, ref SS, "Updating " + count.ToString() + "/" + max.ToString());
                count++;
            }

            while (currthreads > 0)
            {
                Thread.Sleep(100);
            }

            Controller.ToolStripText(toolStripLabel, ref SS, "Ready");
            killThreads = false;
        }