Esempio n. 1
0
        /// <summary>
        /// Parses a copied report text
        /// </summary>
        /// <param name="input">The input string</param>
        /// <param name="options">The BBCode output options</param>
        public static Report ParseText(string input, ReportOutputOptions options)
        {
            var x = new Regex(Pattern);

            if (input.IndexOf("Block sender") > -1)
            {
                input = input.Substring(input.IndexOf("Block sender"));
            }
            Match match = x.Match(input + "\r\n");

            if (match.Success)
            {
                return(ReportParser.ParseMatch(match, options));
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the parsing of the document
        /// </summary>
        /// <param name="document">The document Html</param>
        /// <param name="serverTime">Time the page was generated</param>
        public bool Handle(string document, DateTime serverTime)
        {
            int index = document.IndexOf(string.Format("<th width=\"140\">{0}</th>", TWWords.ReportSubject));
            if (index == -1) return false;
            document = document.Substring(index);

            var matches = new Dictionary<string, Group>();
            if (HandleReportCore(matches, document))
            {
                bool testEspionage = HandleReportEspionage(matches, document);
                bool testRest = HandleReportRest(matches, document);

                var options = new ReportOutputOptions();
                Report report = ReportParser.ParseHtmlMatch(matches, options);
                VillageReportCollection.Save(report);
                return true;
            }

            return false;
        }
Esempio n. 3
0
        /// <summary>
        /// Parses the Regex match
        /// </summary>
        /// <remarks>Parses the Html output</remarks>
        public static Report ParseHtmlMatch(Dictionary <string, Group> match, ReportOutputOptions options)
        {
            Report report = new Report();

            report._reportOptions = options;
            report._attacker      = new ReportVillage(match["you"].Value.Trim(), match["attacker"].Value.Replace("</a>", "").Trim());
            report._defender      = new ReportVillage(match["him"].Value.Trim(), match["defender"].Value.Replace("</a>", "").Trim());

            DateTime testDate;

            if (DateTime.TryParse(match["date"].Value.Trim(), out testDate))
            {
                report._dateReport = testDate;
            }
            report._luck   = match["luck"].Value.Trim();
            report._morale = match["morale"].Value.Trim();
            report._winner = match["winner"].Value.Trim();

            if (match.ContainsKey("haul"))
            {
                int.TryParse(match["haul"].Value, out report._resourceHaulGot);
                int.TryParse(match["haulMax"].Value, out report._resourceHaulMax);
            }

            //Hiding place <b>(Level 4)</b><br />
            if (match.ContainsKey("buildings"))
            {
                report._buildings = ReportParser.GetBuildings(match["buildings"], out report._calculatedPoints);
            }
            if (match.ContainsKey("ramBefore"))
            {
                ReportParser.UpdateBuildings(report.Buildings, WorldBuildings.Default[BuildingTypes.Wall].Name, match["ramBefore"], match["ramAfter"]);
            }
            if (match.ContainsKey("catBuilding"))
            {
                ReportParser.UpdateBuildings(report.Buildings, match["catBuilding"].Value, match["catBefore"], match["catAfter"]);
            }

            // html strippen van res en resLeft
            if (match.ContainsKey("res"))
            {
                report._resourcesHaul = ReportParser.GetResources(match["res"]);
            }
            if (match.ContainsKey("resLeft"))
            {
                report._resourcesLeft = ReportParser.GetResources(match["resLeft"]);
            }

            report._attack = ReportParser.GetTroops(match["atforce"], match["atloss"]);
            if (match.ContainsKey("defforce"))
            {
                if (match.ContainsKey("defOut"))
                {
                    report._defense = ReportParser.GetTroops(match["defforce"], match["defloss"], match["defOut"]);
                }
                else
                {
                    report._defense = ReportParser.GetTroops(match["defforce"], match["defloss"]);
                }
            }

            if (match.ContainsKey("loyaltyBegin") && match["loyaltyBegin"].Success)
            {
                report._loyaltyBegin = System.Convert.ToInt32(match["loyaltyBegin"].Value);
                report._loyaltyEnd   = System.Convert.ToInt32(match["loyaltyEnd"].Value);
                if (report._loyaltyEnd <= 0)
                {
                    report._reportFlag |= ReportFlags.Nobled;
                }
            }

            if (match.ContainsKey("defOut") && match["defOut"].Success)
            {
                report._reportFlag |= ReportFlags.SeenOutside;
            }
            if (match.ContainsKey("defforce") && match["defforce"].Success)
            {
                report._reportFlag |= ReportFlags.SeenDefense;
            }

            SetReportType(report);

            return(report);
        }
Esempio n. 4
0
 /// <summary>
 /// Parses a copied report text
 /// </summary>
 /// <param name="input">The input string</param>
 /// <param name="options">The BBCode output options</param>
 public static Report ParseText(string input, ReportOutputOptions options)
 {
     var x = new Regex(Pattern);
     if (input.IndexOf("Block sender") > -1) input = input.Substring(input.IndexOf("Block sender"));
     Match match = x.Match(input + "\r\n");
     if (match.Success)
     {
         return ReportParser.ParseMatch(match, options);
     }
     return null;
 }
Esempio n. 5
0
        /// <summary>
        /// Parses the Regex match
        /// </summary>
        /// <remarks>Parses the copy output</remarks>
        public static Report ParseMatch(Match match, ReportOutputOptions options)
        {
            Report report = new Report();
            report._reportOptions = options;
            report._attacker = new ReportVillage(match.Groups["you"].Value.Trim(), match.Groups["attacker"].Value.Trim());
            report._defender = new ReportVillage(match.Groups["him"].Value.Trim(), match.Groups["defender"].Value.Trim());

            DateTime testDate;
            if (DateTime.TryParse(match.Groups["date"].Value.Trim(), out testDate)) report._dateReport = testDate;
            report._luck = match.Groups["luck"].Value.Trim();
            report._morale = match.Groups["morale"].Value.Trim();
            report._winner = match.Groups["winner"].Value.Trim();

            int.TryParse(match.Groups["haul"].Value, out report._resourceHaulGot);
            int.TryParse(match.Groups["haulmax"].Value, out report._resourceHaulMax);

            report._buildings = ReportParser.GetBuildings(match.Groups["building"], out report._calculatedPoints);
            ReportParser.UpdateBuildings(report.Buildings, WorldBuildings.Default[BuildingTypes.Wall].Name, match.Groups["ramBefore"], match.Groups["ramAfter"]);
            ReportParser.UpdateBuildings(report.Buildings, match.Groups["catBuilding"].Value, match.Groups["catBefore"], match.Groups["catAfter"]);

            // put resources in a different Group when they come from the html parser :(
            report._resourcesHaul = ReportParser.GetResources(match.Groups["res"]);
            report._resourcesLeft = ReportParser.GetResources(match.Groups["resLeft"]);
            report._attack = ReportParser.GetTroops(match.Groups["atforce"], match.Groups["atloss"]);
            report._defense = ReportParser.GetTroops(match.Groups["defforce"], match.Groups["defloss"], match.Groups["defOut"]);

            if (match.Groups["loyaltyBegin"].Success)
            {
                report._loyaltyBegin = System.Convert.ToInt32(match.Groups["loyaltyBegin"].Value);
                report._loyaltyEnd = System.Convert.ToInt32(match.Groups["loyaltyEnd"].Value);
                if (report._loyaltyEnd <= 0) report._reportFlag |= ReportFlags.Nobled;
            }

            if (match.Groups["defOut"].Success) report._reportFlag |= ReportFlags.SeenOutside;
            if (match.Groups["defforce"].Success) report._reportFlag |= ReportFlags.SeenDefense;

            SetReportType(report);

            return report;
        }
Esempio n. 6
0
        /// <summary>
        /// Parses the Regex match
        /// </summary>
        /// <remarks>Parses the Html output</remarks>
        public static Report ParseHtmlMatch(Dictionary<string, Group> match, ReportOutputOptions options)
        {
            Report report = new Report();
            report._reportOptions = options;
            report._attacker = new ReportVillage(match["you"].Value.Trim(), match["attacker"].Value.Replace("</a>", "").Trim());
            report._defender = new ReportVillage(match["him"].Value.Trim(), match["defender"].Value.Replace("</a>", "").Trim());

            DateTime testDate;
            if (DateTime.TryParse(match["date"].Value.Trim(), out testDate)) report._dateReport = testDate;
            report._luck = match["luck"].Value.Trim();
            report._morale = match["morale"].Value.Trim();
            report._winner = match["winner"].Value.Trim();

            if (match.ContainsKey("haul"))
            {
                int.TryParse(match["haul"].Value, out report._resourceHaulGot);
                int.TryParse(match["haulMax"].Value, out report._resourceHaulMax);
            }

            //Hiding place <b>(Level 4)</b><br />
            if (match.ContainsKey("buildings"))
            {
                report._buildings = ReportParser.GetBuildings(match["buildings"], out report._calculatedPoints);
            }
            if (match.ContainsKey("ramBefore")) ReportParser.UpdateBuildings(report.Buildings, WorldBuildings.Default[BuildingTypes.Wall].Name, match["ramBefore"], match["ramAfter"]);
            if (match.ContainsKey("catBuilding")) ReportParser.UpdateBuildings(report.Buildings, match["catBuilding"].Value, match["catBefore"], match["catAfter"]);

            // html strippen van res en resLeft
            if (match.ContainsKey("res"))
            {
                report._resourcesHaul = ReportParser.GetResources(match["res"]);
            }
            if (match.ContainsKey("resLeft"))
            {
                report._resourcesLeft = ReportParser.GetResources(match["resLeft"]);
            }

            report._attack = ReportParser.GetTroops(match["atforce"], match["atloss"]);
            if (match.ContainsKey("defforce"))
            {
                if (match.ContainsKey("defOut")) report._defense = ReportParser.GetTroops(match["defforce"], match["defloss"], match["defOut"]);
                else report._defense = ReportParser.GetTroops(match["defforce"], match["defloss"]);
            }

            if (match.ContainsKey("loyaltyBegin") && match["loyaltyBegin"].Success)
            {
                report._loyaltyBegin = System.Convert.ToInt32(match["loyaltyBegin"].Value);
                report._loyaltyEnd = System.Convert.ToInt32(match["loyaltyEnd"].Value);
                if (report._loyaltyEnd <= 0) report._reportFlag |= ReportFlags.Nobled;
            }

            if (match.ContainsKey("defOut") && match["defOut"].Success) report._reportFlag |= ReportFlags.SeenOutside;
            if (match.ContainsKey("defforce") && match["defforce"].Success) report._reportFlag |= ReportFlags.SeenDefense;

            SetReportType(report);

            return report;
        }