コード例 #1
0
ファイル: Form1.cs プロジェクト: bangush/csharp
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Control)
     {
         if (e.KeyCode == Keys.V)
         {
             if (Clipboard.ContainsText())
             {
                 string tr = Clipboard.GetText();
                 tr = tr.Trim();
                 troop s = new troop()
                 {
                     Name = tr
                 };
                 if (!list.Any(x => x.Name.Equals(tr)))
                 {
                     list.Add(s);
                     ListViewItem lvi = listView1.Items.Add(s.Name);
                     lvi.Tag = s;
                     lvi.SubItems.Add("");
                     lvi.SubItems.Add(s.Money);
                     lvi.SubItems.Add(s.Power);
                     lvi.SubItems.Add(0);
                     lvi.SubItems.Add(1);
                     lvi.SubItems.Add(0);
                     lvi.SubItems.Add("-1");//Raid
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: bangush/csharp
        private void Battle(object state)
        {
            string strChk = "";
            string army   = state.ToString();
            troop  t      = list.FirstOrDefault(x => x.Name.Equals(army));

            using (WebClient wc = new WebClient())
            {
                string strHtml = "";
                try
                {
                    strHtml = wc.DownloadString(string.Format(hqbase, army.Replace(" ", "-")));
                    if (strHtml.Contains("<form method=\"POST\" action=\"/login\">"))
                    {
                        if (wc.ResponseHeaders["Set-Cookie"] != null)
                        {
                            var c = wc.ResponseHeaders["Set-Cookie"];
                            wc.Headers.Add("Cookie", c.ToString());
                        }
                        HttpWebRequest wrq = WebRequest.Create(string.Format(loginbase, army.Replace(" ", "-"))) as HttpWebRequest;
                        wrq.Headers.Add(wc.Headers);
                        wrq.AllowAutoRedirect = false;
                        wrq.Method            = "POST";
                        byte[] b = Encoding.Default.GetBytes(string.Format("login={0}&pass={1}", army.Replace(" ", "+"), army.Replace(" ", "")));
                        wrq.GetRequestStream().Write(b, 0, b.Length);
                        HttpWebResponse wrs = wrq.GetResponse() as HttpWebResponse;
                        if (wrs.GetResponseHeader("Set-Cookie") != null)
                        {
                            var c = wrs.GetResponseHeader("Set-Cookie");
                            wc.Headers.Clear();
                            wc.Headers.Add("Cookie", c.ToString());
                        }
                    }

                    strHtml = wc.DownloadString(string.Format(oppbase, army.Replace(" ", "-")));
                    if (wc.ResponseHeaders["Set-Cookie"] != null)
                    {
                        var c = wc.ResponseHeaders["Set-Cookie"];
                        wc.Headers.Clear();
                        wc.Headers.Add("Cookie", c.ToString());
                    }
                    if (strHtml.Contains("<input name=\"chk\""))
                    {
                        string find1  = "<input name=\"chk\" type=\"hidden\" value=\"";
                        string find2  = "\"/>";
                        int    istart = strHtml.IndexOf(find1) + find1.Length;
                        int    iend   = strHtml.IndexOf(find2, istart);
                        if (iend > istart)
                        {
                            string chk = strHtml.Substring(istart, iend - istart);
                            strChk = chk;
                        }
                    }
                }
                catch (Exception ex)
                { }
                this.Invoke((MethodInvoker) delegate { UpdateDone(army, "M"); });
                try
                {
                    if (!string.IsNullOrEmpty(strChk))
                    {
                        foreach (var friend in list.OrderBy(x => x.Power).Take(4))
                        {
                            if (!friend.Name.Equals(army, StringComparison.InvariantCultureIgnoreCase))
                            {
                                string ssdf = wc.UploadString(string.Format(battlebase, army.Replace(" ", "-")), "post", string.Format("chk={0}&friend={1}", strChk, friend.Name));
                            }
                        }
                        for (int n = 0; n < 3; n++)
                        {
                            wc.DownloadString(string.Format(missionbase, army.Replace(" ", "-"), strChk));
                        }
                    }
                }
                catch (WebException te)
                {}
                if (!string.IsNullOrEmpty(strChk))
                {
                    this.Invoke((MethodInvoker) delegate { UpdateDone(army, "R"); });
                    bool braid  = true;
                    int  iretry = 0;

                    while (braid && iretry < 3)
                    {
                        HttpWebRequest wrq = WebRequest.Create(string.Format(raidbase, army.Replace(" ", "-"), strChk)) as HttpWebRequest;
                        wrq.Headers.Add(wc.Headers);
                        wrq.Timeout           = 60000;
                        wrq.ReadWriteTimeout  = 60000;
                        wrq.AllowAutoRedirect = false;
                        try
                        {
                            HttpWebResponse wrs = wrq.GetResponse() as HttpWebResponse;

                            if (wrs.GetResponseHeader("Set-Cookie") != null)
                            {
                                var c = wrs.GetResponseHeader("Set-Cookie");
                                if (c.ToString().Contains("failed"))
                                {
                                    braid = false;
                                }
                            }
                            else
                            {
                                braid = false;
                            }
                            iretry = 0;
                        }
                        catch (WebException te)
                        {
                            Thread.Sleep(5000);
                            iretry++;
                            this.Invoke((MethodInvoker) delegate { UpdateDone(army, iretry.ToString()); });
                        }
                    }

                    //if (!army.Equals(strRikets))
                    {
                        this.Invoke((MethodInvoker) delegate { UpdateDone(army, "L"); });
                        try
                        {
                            string strTrooper = t.Troops.Count > 0 ? (t.Troops.OrderBy(x => x.Power).First() as troop).Id.ToString() : "0";
                            string strT       = (army.Equals(strRikets) || army.Equals("lorenjupanu") ? strTrooper : "0");
                            strHtml = wc.DownloadString(string.Format(levelupbase, army.Replace(" ", "-"), strChk, strT));
                            if (strHtml.Contains("document.location = '/levelup/" + strT + "?skill="))
                            {
                                string find1  = "document.location = '/levelup/" + strT + "?skill=";
                                string find2  = "&chk=" + strChk;
                                int    istart = strHtml.IndexOf(find1) + find1.Length;
                                int    iend   = strHtml.IndexOf(find2, istart);
                                if (iend > istart)
                                {
                                    string skill = strHtml.Substring(istart, iend - istart);
                                    wc.DownloadString(string.Format(skillbase, army.Replace(" ", "-"), skill, strChk, strT));
                                }
                            }
                        }
                        catch (WebException te)
                        { }
                    }
                }
            }
            GetMoneyAndPower(army);
            this.Invoke((MethodInvoker) delegate { UpdateDone(army, "X"); });
            icntdone++;
            if (icntarmies == icntdone + 1)
            {
                Battle(strRikets);
            }
            else if (icntarmies == icntdone)
            {
                this.Invoke((MethodInvoker) delegate { Application.Exit(); });
            }
        }