コード例 #1
0
 public HttpRequestMessage GetMessagePageRequest(MessageTabType tab, int page)
 {
     return(_client.BuildPost(new Uri("/game/index.php?page=messages", UriKind.Relative), new[]
     {
         KeyValuePair.Create("messageId", "-1"),
         KeyValuePair.Create("tabid", ((int)tab).ToString()),
         KeyValuePair.Create("action", "107"),
         KeyValuePair.Create("pagination", page.ToString()),
         KeyValuePair.Create("ajax", "1")
     }));
 }
コード例 #2
0
 public HttpRequestMessage GetMessagePage(int messageId, MessageTabType tabType)
 {
     return(_client.BuildRequest(new Uri($"/game/index.php?page=messages&messageId={messageId}&tabid={(int)tabType}&ajax=1", UriKind.Relative)));
 }
コード例 #3
0
        public override IEnumerable <DataObject> ProcessInternal(ClientBase client, ResponseContainer container)
        {
            HtmlDocument doc     = container.ResponseHtml.Value;
            HtmlNode     message = doc.DocumentNode.SelectSingleNode("//div[@class='detail_msg']");

            if (message == null)
            {
                yield break;
            }

            OGameClient oClient = (OGameClient)client;

            // Message info
            int            messageId = message.GetAttributeValue("data-msg-id", 0);
            MessageTabType tabType   = MessageTabType.FleetsEspionage;

            string   dateText = message.SelectSingleNode(".//span[contains(@class, 'msg_date')]").InnerText;
            DateTime date     = DateTime.ParseExact(dateText, "dd.MM.yyyy HH:mm:ss", oClient.ServerCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime();

            EspionageReport result = new EspionageReport
            {
                MessageId = messageId,
                TabType   = tabType,
                Sent      = new DateTimeOffset(date).Add(-oClient.Settings.ServerUtcOffset).ToOffset(oClient.Settings.ServerUtcOffset)
            };

            // Establish location
            HtmlNode locationLink = message.SelectSingleNode(".//a[contains(@href, 'page=galaxy')]");
            string   locationType = locationLink.SelectSingleNode("./figure").GetCssClasses(s => s == "moon" || s == "planet").First();

            CoordinateType coordinateType = locationType == "moon" ? CoordinateType.Moon : CoordinateType.Planet;

            result.Coordinate = Coordinate.Parse(locationLink.InnerText, coordinateType);

            // Parts
            HtmlNodeCollection            partsNodesList = message.SelectNodes(".//ul[@data-type and not(./li[@class='detail_list_fail'])]");
            Dictionary <string, HtmlNode> partsNodes     = partsNodesList.ToDictionary(s => s.GetAttributeValue("data-type", ""));

            // Parts - Resources
            HtmlNode details;

            if (partsNodes.TryGetValue("resources", out details))
            {
                HtmlNodeCollection values = details.SelectNodes(".//span[@class='res_value']");
                Debug.Assert(values.Count == 4);

                var oneThousandAdd = oClient.ServerCulture.NumberFormat.NumberGroupSeparator + "000";

                string[] vals = values.Select(s => s.InnerText
                                              .Replace("M", oneThousandAdd)
                                              .Replace("Bn", oneThousandAdd + oneThousandAdd)).ToArray();

                Resources resources = new Resources
                {
                    Metal     = int.Parse(vals[0], NumberStyles.AllowThousands | NumberStyles.Integer, oClient.ServerCulture),
                    Crystal   = int.Parse(vals[1], NumberStyles.AllowThousands | NumberStyles.Integer, oClient.ServerCulture),
                    Deuterium = int.Parse(vals[2], NumberStyles.AllowThousands | NumberStyles.Integer, oClient.ServerCulture),
                    Energy    = int.Parse(vals[3], NumberStyles.AllowThousands | NumberStyles.Integer, oClient.ServerCulture)
                };

                result.Resources = resources;
                result.Details  |= ReportDetails.Resources;
            }

            // Parts - Ships
            if (partsNodes.TryGetValue("ships", out details))
            {
                result.DetectedShips = ParseList <ShipType>(oClient, details);
                result.Details      |= ReportDetails.Ships;
            }

            // Parts - Defense
            if (partsNodes.TryGetValue("defense", out details))
            {
                result.DetectedDefence = ParseList <DefenceType>(oClient, details);
                result.Details        |= ReportDetails.Defense;
            }

            // Parts - Buildings
            if (partsNodes.TryGetValue("buildings", out details))
            {
                result.DetectedBuildings = ParseList <BuildingType>(oClient, details);
                result.Details          |= ReportDetails.Buildings;
            }

            // Parts - Research
            if (partsNodes.TryGetValue("research", out details))
            {
                result.DetectedResearch = ParseList <ResearchType>(oClient, details);
                result.Details         |= ReportDetails.Research;
            }

            // Return
            yield return(result);
        }