Пример #1
0
        public bool Login()
        {
            if (!this.isLogin)
            {
                try
                {
                    string responseText = string.Empty;
                    string content      = "Continue=http%3A%2F%2Fcivitas.soobb.com%2F&Language=zh-cn&Email="
                                          + System.Uri.EscapeDataString(this.emailAddress)
                                          + "&Password="******"&RememberMe=on";
                    byte[]         byteContent = Encoding.Default.GetBytes(content);
                    StreamReader   streamReader;
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(LOGIN);
                    request.Accept    = @"text/plain, */*; q=0.01";
                    request.UserAgent = "Mozilla/5.0";
                    request.Headers.Add("Accept-Encoding", "utf-8");
                    request.Headers.Add("Accept-Language", "zh-CN");
                    request.Headers["x-requested-with"] = "XMLHttpRequest";
                    request.Headers["Accept-Language"]  = "zh-cn";
                    request.Headers["Accept-Encoding"]  = "gzip, deflate";
                    request.UserAgent         = "Mozilla/4.0 ";
                    request.Headers["Pragma"] = "no-cache";
                    request.Method            = "POST";
                    request.KeepAlive         = true;
                    request.Referer           = UrlHelpers.REFERER;
                    request.ContentLength     = byteContent.Length;
                    request.ContentType       = "application/x-www-form-urlencoded";
                    request.GetRequestStream().Write(byteContent, 0, byteContent.Length);
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    streamReader = new StreamReader(response.GetResponseStream());
                    responseText = streamReader.ReadToEnd();
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        string cookieString = response.Headers.Get("Set-Cookie");

                        foreach (string s in cookieString.Split(';'))
                        {
                            if (s.Contains("CIVITAS-Authentication"))
                            {
                                string name  = "CIVITAS-Authentication";
                                string value = UrlHelpers.CutHead(s, "CIVITAS-Authentication=");
                                this.cookieContainer = name + "=" + value;
                                this.isLogin         = true;
                                return(true);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                this.isLogin = false;
                return(false);
            }

            return(true);
        }
Пример #2
0
        public static string CutBetween(string source, string begin, string end)
        {
            string result = UrlHelpers.CutHead(source, begin);

            result = UrlHelpers.CutTail(result, end);
            return(result);
        }
Пример #3
0
        public void FindNeighbor()
        {
            new Thread(delegate()
            {
                string text = string.Empty;
                this.neighbors.Clear();
                if (UrlHelpers.GetHtml("http://civitas.soobb.com/Forums/", ref text, this.cookieContainer) == 1)
                {
                    this.city   = UrlHelpers.CutBetween(text, "<title>", "的广场");
                    string temp = UrlHelpers.CutHead(text, "<h4>街区排行</h4>");
                    while (temp.Contains("<a href=\"/Districts/"))
                    {
                        int id        = Convert.ToInt32(UrlHelpers.CutBetween(temp, "<a href=\"/Districts/", "/"));
                        string name   = UrlHelpers.CutBetween(temp, "<a href=\"/Districts/" + id + "/\">", "</a>");
                        bool contains = false;
                        foreach (Neighbor nei in this.neighbors)
                        {
                            if (nei.Id == id)
                            {
                                contains = true;
                            }
                        }

                        if (!contains)
                        {
                            this.neighbors.Add(new Neighbor(id, name, this));
                        }

                        temp = UrlHelpers.CutHead(temp, "<a href=\"/Districts/");
                    }

                    this.ready = true;
                }
            }).Start();
        }
Пример #4
0
        /// <summary>
        /// The the speech page count
        /// </summary>
        /// <param name="speechType">The speech type</param>
        /// <param name="cookieContainer">The user connection cookie container</param>
        /// <returns>The speech page count</returns>
        private static int GetSpeechPageCount(int speechType, string cookieContainer)
        {
            string text = string.Empty;

            if (UrlHelpers.GetHtml("http://civitas.soobb.com/Forums/Speeches/?SpeechType=" + speechType, ref text, cookieContainer) == 1)
            {
                text = UrlHelpers.CutBetween(text, "<li class=\"Break\">...</li>", "</ul>");
                text = UrlHelpers.CutHead(text, "<li><a");
                text = UrlHelpers.CutHead(text, "<li><a");
                text = UrlHelpers.CutHead(text, "<li><a");
                text = UrlHelpers.CutBetween(text, ">", "</a>");
                return(Convert.ToInt32(text));
            }

            return(0);
        }
Пример #5
0
        /// <summary>
        /// The thread method of speech
        /// </summary>
        /// <param name="speechList">The reference speech list</param>
        /// <param name="cookieContainer">The user connection cookie container</param>
        /// <param name="number">The speech page number</param>
        /// <param name="finish">The reference finish count</param>
        /// <param name="current">The reference current working speech count</param>
        private static void MethodSpeech(ref List <Speech> speechList, string cookieContainer, int number, ref int finish, ref int current)
        {
            string text = string.Empty;

            if (UrlHelpers.GetHtml("http://civitas.soobb.com/Forums/Speeches/?SpeechType=1&Page=" + number, ref text, cookieContainer) == 1)
            {
                text = UrlHelpers.CutBetween(text, "<div class=\"Speeches\"", "<h4>系统消息");
                while (text.Contains("<div class=\"Speech\""))
                {
                    text = UrlHelpers.CutHead(text, "<div class=\"Speech\"");
                    int    id      = Convert.ToInt32(UrlHelpers.CutBetween(text, "speechid=\"", "\""));
                    string name    = UrlHelpers.CutHead(UrlHelpers.CutBetween(text, "<p class=\"Name\"><a href", "</a>:"), "\">");
                    string t       = UrlHelpers.CutTail(UrlHelpers.CutHead(text, ":</p>\r\n\t\t\t<p>"), "</p>");
                    int    like    = Convert.ToInt32(UrlHelpers.CutBetween(text, "class=\"Normal\">欢呼</a><span type=\"1\" class=\"Number\">(", ")</span>"));
                    int    watch   = Convert.ToInt32(UrlHelpers.CutBetween(text, "class=\"Normal\">关注</a><span type=\"3\" class=\"Number\">(", ")</span>"));
                    int    dislike = Convert.ToInt32(UrlHelpers.CutBetween(text, "class=\"Normal\">倒彩</a><span type=\"2\" class=\"Number\">(", ")</span>"));
                    string time    = UrlHelpers.CutBetween(text, "演讲,第", "</p>");
                    int    day     = -1;
                    int    hour    = 0;
                    int    min     = 0;
                    try
                    {
                        day  = Convert.ToInt32(UrlHelpers.CutTail(time, "天"));
                        hour = Convert.ToInt32(UrlHelpers.CutBetween(time, "天 ", ":"));
                        min  = Convert.ToInt32(UrlHelpers.CutHead(time, ":"));
                    }
                    catch
                    {
                        Console.WriteLine("\n时间有个错误,可能是BOSS发言,不带天数和时间");
                    }

                    speechList.Add(new Speech(id, name, t, like, watch, dislike, new CivitasTime(day, hour, min)));
                }
            }

            finish++;
            current--;
        }
Пример #6
0
        public void SeeNeighbor(User user)
        {
            if (user.IsLogin)
            {
                new Thread(delegate()
                {
                    if (this.Id < 0)
                    {
                        return;
                    }

                    string text = string.Empty;
                    if (UrlHelpers.GetHtml(
                            "http://civitas.soobb.com/Districts/" + this.Id,
                            ref text,
                            user.CookieContainer) == 1)
                    {
                        this.health = Convert.ToDouble(UrlHelpers.CutHead(
                                                           UrlHelpers.CutBetween(text, "<div class=\"Subject\">卫生</div>", "%</div>"),
                                                           "ive\">"));
                        this.prosperity = Convert.ToDouble(UrlHelpers.CutHead(
                                                               UrlHelpers.CutBetween(text, "<div class=\"Subject\">繁荣</div>", "%</div>"),
                                                               "ive\">"));
                        this.industry = Convert.ToDouble(UrlHelpers.CutHead(
                                                             UrlHelpers.CutBetween(text, "<div class=\"Subject\">产业</div>", "%</div>"),
                                                             "ive\">"));
                    }

                    text = string.Empty;
                    if (UrlHelpers.GetHtml(
                            "http://civitas.soobb.com/Districts/" + this.Id + "/Estates/",
                            ref text,
                            user.CookieContainer) == 1)
                    {
                        string strCount = UrlHelpers.CutBetween(text, "<span class=\"Count\">(共 ", "条)</span>");
                        int count       = Convert.ToInt32(strCount);
                        int pageCount   = (count / 20) + 1;
                        for (int i = 1, j = 0; i <= pageCount; i++)
                        {
                            if (UrlHelpers.GetHtml(
                                    "http://civitas.soobb.com/Districts/" + this.Id + "/Estates/?Action=Search&Page=" + i,
                                    ref text,
                                    user.CookieContainer) == 1)
                            {
                                string temp = UrlHelpers.CutHead(text, "<div class=\"Estate StatisticsRow\">");
                                for (int k = 0; k < 20 & j < count; k++, j++)
                                {
                                    string tempt1     = UrlHelpers.CutTail(temp, "<div class=\"Text\">");
                                    string name       = UrlHelpers.CutBetween(UrlHelpers.CutHead(tempt1, "<h5>"), "Details/\">", "</a>");
                                    string typestr    = UrlHelpers.CutBetween(tempt1, "</a>的", "</div>");
                                    string owner      = UrlHelpers.CutHead(UrlHelpers.CutBetween(tempt1, " entityid=\"", "</a>的" + typestr), ">");
                                    string ownerPath  = UrlHelpers.CutBetween(tempt1, "<div><a href=\"", "\" class=\"WithEntityCard\" entityid=\"");
                                    string estatePath = UrlHelpers.CutBetween(tempt1, "<h5><a href=\"", "\">" + name);
                                    double area       = Convert.ToDouble(UrlHelpers.CutBetween(UrlHelpers.CutBetween(tempt1, "<div class=\"Text Text2\">", "占地面积"), "Number\">", "</p>"));
                                    EstateType type   = EstateType.GetEstateType(typestr);
                                    if (null == type)
                                    {
                                        type = new EstateType(typestr);
                                    }

                                    this.Estates.Add(new Estate(name, type, area, estatePath, owner, ownerPath));
                                    temp = UrlHelpers.CutHead(temp, "<div class=\"Estate StatisticsRow\">");
                                }

                                Console.Write("[" + this.Name[0] + "]");
                            }

                            if (j == count)
                            {
                                break;
                            }
                        }
                    }

                    Console.WriteLine("\n窥探【" + this.Name + "】完毕,有种放学别走!");
                    this.ready = true;
                }).Start();
            }
        }
Пример #7
0
        public List <Commodity> SeeCommodities(string cookieContainer)
        {
            Console.WriteLine("目前不支持翻页,如果商家超过一页。。。你懂的");
            string text = string.Empty;

            this.commodities.Clear();
            if (UrlHelpers.GetHtml("http://civitas.soobb.com/Markets/Commodities/?SupplyID=" + this.SupplyId + "&SupplyLevel=" + this.SupplyLevel, ref text, cookieContainer) == 1)
            {
                string temp1 = UrlHelpers.CutBetween(text, "所需货物", "所需等级");
                do
                {
                    string temp2 = UrlHelpers.CutBetween(temp1, "class=\"Item\"", "</div>");
                    int    id    = Convert.ToInt32(UrlHelpers.CutBetween(temp2, "DemandID=", "&SupplyLevel"));
                    string name  = UrlHelpers.CutBetween(temp2, "\">", "</a>");
                    this.commodities.Add(new Commodity(id, name, 1));
                    this.commodities.Add(new Commodity(id, name, 2));
                    temp1 = UrlHelpers.CutHead(temp1, "<div class=\"Item\"><a href=\"/Markets/Commodities/");
                }while (temp1.Contains("<div class=\"Item\"><a href=\"/Markets/Commodities/"));
            }

            foreach (Commodity c in this.commodities)
            {
                // Console.WriteLine("\n" + c.Name + c.Level);
                text = string.Empty;

                // 暂不支持翻页
                if (UrlHelpers.GetHtml(
                        "http://m.civitas.soobb.com/Markets/Commodities/?InventoryID=20708&SupplyID=" + this.SupplyId + "&DemandID=" + c.ID + "&SupplyLevel=" + this.SupplyLevel + "&DemandLevel=" + c.Level,
                        ref text,
                        cookieContainer) == 1)
                {
                    if (!text.Contains("<div class=\"Column Item1\">"))
                    {
                        continue;
                    }

                    string temp = UrlHelpers.CutKeepHead(text, "<div class=\"Column Item1\">");
                    while (temp.Contains("<div class=\"Column Item1\">"))
                    {
                        temp = UrlHelpers.CutHead(temp, "<div class=\"Column Item1\">");
                        string sellerName = UrlHelpers.CutHead(
                            UrlHelpers.CutHead(
                                UrlHelpers.CutBetween(temp, "<div class=\"Content\">", "</a>"),
                                "<h4>"),
                            ">");
                        double count = Convert.ToDouble(UrlHelpers.CutBetween(temp, "<span class=\"Price1\">", "</span>"));
                        double price = Convert.ToDouble(UrlHelpers.CutBetween(temp, "<span class=\"Price2\">", "</span>"));

                        // Console.WriteLine(sellerName + count + "*" + price);
                        new Business(sellerName, c, c.Level, count, price);
                    }
                }
            }

            // clear
            for (int i = 0, j = this.commodities.Count; i < j; i++)
            {
                if (this.commodities[i].BusinessCount() == 0)
                {
                    this.commodities.RemoveAt(i);
                    i--;
                    j--;
                }
            }

            this.commodities.Sort();
            return(this.commodities);
        }