예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name">Organization name to search for</param>
        /// <param name="botTag">Identify as this bot</param>
        /// <returns></returns>
        public static int GetID(string name, string botTag, int dimension)
        {
            var qb = new UriQueryBuilder();

            qb.Set("type", "orgid");
            qb.Set("d", dimension);
            qb.Set("name", name);
            qb.Set("bot", botTag);
            qb.Set("output", "plain");
            var uri = qb.ToUri(new Uri(apiURI));

            var webClient = new WebClient();
            var result    = webClient.DownloadData(uri.ToString());

            if (result == null || result.Length == 0)
            {
                throw new Exception("Returned data was empty.");
            }

            var result2 = ASCIIEncoding.ASCII.GetString(result);
            int value;

            if (!int.TryParse(result2, out value))
            {
                throw new Exception("Returned data was not a valid integer. Returned data: " + result2);
            }

            return(value);
        }
예제 #2
0
        Uri CreateAnnounceString(AnnounceParameters parameters)
        {
            var b = new UriQueryBuilder(Uri);

            b.Add("info_hash", parameters.InfoHash.UrlEncode())
            .Add("peer_id", parameters.PeerId.UrlEncode())
            .Add("port", parameters.Port)
            .Add("uploaded", parameters.BytesUploaded)
            .Add("downloaded", parameters.BytesDownloaded)
            .Add("left", parameters.BytesLeft)
            .Add("compact", 1)
            .Add("numwant", 100);

            if (parameters.SupportsEncryption)
            {
                b.Add("supportcrypto", 1);
            }
            if (parameters.RequireEncryption)
            {
                b.Add("requirecrypto", 1);
            }
            if (!b.Contains("key") && Key != null)
            {
                b.Add("key", Key.UrlEncode());
            }
            if (!string.IsNullOrEmpty(parameters.IPAddress))
            {
                b.Add("ip", parameters.IPAddress);
            }

            // If we have not successfully sent the started event to this tier, override the passed in started event
            // Otherwise append the event if it is not "none"
            //if (!parameters.Id.Tracker.Tier.SentStartedEvent)
            //{
            //    sb.Append("&event=started");
            //    parameters.Id.Tracker.Tier.SendingStartedEvent = true;
            //}
            if (parameters.ClientEvent != TorrentEvent.None)
            {
                b.Add("event", parameters.ClientEvent.ToString().ToLower());
            }

            if (!BEncodedString.IsNullOrEmpty(TrackerId))
            {
                b.Add("trackerid", TrackerId.UrlEncode());
            }

            return(b.ToUri());
        }
예제 #3
0
        public void TestToString()
        {
            var builder = new UriQueryBuilder("http://mytest.com/announce.aspx?key=1");

            builder.Add("key", 2);
            builder.Add("foo", 2);
            builder.Add("foo", "bar");
            Assert.AreEqual(new Uri("http://mytest.com/announce.aspx?key=2&foo=bar"), builder.ToUri(), "#1");

            builder = new UriQueryBuilder("http://mytest.com/announce.aspx?passkey=1");
            builder.Add("key", 2);
            Assert.AreEqual(new Uri("http://mytest.com/announce.aspx?passkey=1&key=2"), builder.ToUri(), "#2");

            builder = new UriQueryBuilder("http://mytest.com/announce.aspx");
            Assert.AreEqual(new Uri("http://mytest.com/announce.aspx"), builder.ToUri(), "#3");

            builder = new UriQueryBuilder("http://mytest.com/announce.aspx");
            var infoHash = new byte[] { 0x01, 0x47, 0xff, 0xaa, 0xbb, 0xcc };

            builder.Add("key", UriHelper.UrlEncode(infoHash));

            Assert.AreEqual(new Uri("http://mytest.com/announce.aspx?key=%01G%ff%aa%bb%cc"), builder.ToUri(), "#4");
        }
        private MapOverlay GenerateTowerFieldInfo(Dimension dimension)
        {
            var overlay = new MapOverlay
            {
                Name = "LcaInfo",
            };

            // Get tower data.
            var qb = new UriQueryBuilder();
            {
                dynamic q = qb;
                q.d        = (int)dimension;
                q.output   = "xml";
                q.limit    = 300;
                q.minlevel = this.LcaMinLevel;
                q.maxlevel = this.LcaMaxLevel;
            }

            var towerData = API.XmlCache.Get <TowerSites>().Request(
                Demoder.Common.CacheFlags.Default,
                qb.ToUri(new Uri(twTowerDistribution)),
                dimension.ToString(),
                this.LcaMinLevel.ToString(),
                this.LcaMaxLevel.ToString());

            if (towerData == null)
            {
                return(null);
            }
            foreach (var site in towerData.Sites)
            {
                var tex = new MapTexture
                {
                    Position          = new PositionDefinition(site.ZoneID, site.CenterX, site.CenterY),
                    Texture           = new TextureDefinition(TextureType.Content, "TowerTexture"),
                    Size              = new Vector2(8, 8),
                    PositionAlignment = MapItemAlignment.Center | MapItemAlignment.Bottom,
                };

                // Set texture color
                switch (site.Faction)
                {
                case Common.AO.Faction.Neutral:
                    //tex.KeyColor = Color.White;
                    tex.KeyColor = Color.LightGray;
                    break;

                case Common.AO.Faction.Clan:
                    tex.KeyColor = Color.Orange;
                    break;

                case Common.AO.Faction.Omni:
                    tex.KeyColor = Color.SkyBlue;
                    break;

                default:
                    tex.KeyColor = Color.Purple;
                    break;
                }

                MapText text = null;
                if (this.ShowNames)
                {
                    text = new MapText
                    {
                        Font    = API.Content.Fonts.GetFont(this.LcaOwnerFont),
                        Outline = true,
                        Text    = site.Guild
                    };

                    // Set text color
                    switch (site.Faction)
                    {
                    case Common.AO.Faction.Neutral:
                        text.TextColor    = Color.LightGray;
                        text.OutlineColor = Color.Black;
                        break;

                    case Common.AO.Faction.Clan:
                        text.TextColor    = Color.Orange;
                        text.OutlineColor = Color.Black;
                        break;

                    case Common.AO.Faction.Omni:
                        text.TextColor    = Color.SkyBlue;
                        text.OutlineColor = Color.Black;
                        break;

                    default:
                        tex.KeyColor = Color.Purple;
                        break;
                    }
                }



                overlay.MapItems.Add(new MapTextureText(tex, text)
                {
                    PositionAlignment = MapItemAlignment.Bottom
                });
            }
            return(overlay);
        }
        private MapOverlay GenerateRecentAttackInfo(Dimension dimension)
        {
            if (!this.ShowRecentAttacks)
            {
                return(null);
            }
            var overlay = new GuiTableOverlay
            {
                HeaderVisible = false,
                Position      = new Point(5, 5),
                ColumnSpacing = 15,
                RowSpacing    = 0,
            };

            // Get tower data.
            var qb = new UriQueryBuilder();
            {
                dynamic q = qb;
                q.d          = (int)dimension;
                q.output     = "xml";
                q.limit      = 5;
                q.sortorder  = "desc";
                q.chopmethod = "last";
                q.starttime  = Demoder.Common.Misc.Unixtime(DateTime.Now.Subtract(new TimeSpan(6, 0, 0)));
            }

            var towerData = API.XmlCache.Get <TowerAttacks>().Request(
                Common.CacheFlags.Default,
                qb.ToUri(new Uri(twHistorySearch)),
                dimension.ToString());

            if (towerData == null)
            {
                overlay.MapItems.Add(new MapText
                {
                    Position          = new PositionDefinition(5, 5),
                    PositionAlignment = MapItemAlignment.Top | MapItemAlignment.Left,
                    TextColor         = Color.White,
                    OutlineColor      = Color.Black,
                    Outline           = true,
                    Font = API.Content.Fonts.GetFont(this.RecentAttacksFont),
                    Text = "Error fetching recent attacks for " + dimension.ToString()
                });
                if (dimension == Common.AO.Dimension.Unknown)
                {
                    (overlay.MapItems.Last() as MapText).Text = "Please track a character, or select dimension in plugin configuration.";
                }
                return(overlay);
            }
            if (towerData.Attacks.Count == 0)
            {
                overlay.MapItems.Add(new MapText
                {
                    Position          = new PositionDefinition(5, 5),
                    PositionAlignment = MapItemAlignment.Top | MapItemAlignment.Left,
                    TextColor         = Color.White,
                    OutlineColor      = Color.Black,
                    Outline           = true,
                    Font = API.Content.Fonts.GetFont(this.RecentAttacksFont),
                    Text = "No recent attacks on " + dimension.ToString()
                });
                return(overlay);
            }

            // Define headers.
            var headerTexts = new string[] {
                "Time",
                "Zone",
                "#",
                "Nick",
                "Org"
            };

            for (int i = 0; i < 5; i++)
            {
                overlay.Headers[i] = new GuiTableHeader
                {
                    AutoSize  = true,
                    Alignment = MapItemAlignment.Left | MapItemAlignment.Top,
                    Content   = new MapText
                    {
                        Font              = API.Content.Fonts.GetFont(this.RecentAttacksFont),
                        Text              = headerTexts[i],
                        TextColor         = Color.White,
                        Outline           = true,
                        OutlineColor      = Color.Black,
                        PositionAlignment = MapItemAlignment.Center | MapItemAlignment.Top
                    }
                };
            }

            overlay.Title = new MapText
            {
                Position          = new PositionDefinition(5, 5),
                PositionAlignment = MapItemAlignment.Top | MapItemAlignment.Left,
                TextColor         = Color.White,
                OutlineColor      = Color.Black,
                Outline           = true,
                Font = API.Content.Fonts.GetFont(this.RecentAttacksFont),
                Text = "Recent tower attacks on " + dimension.ToString()
            };

            int row  = 0;
            var font = API.Content.Fonts.GetFont(this.RecentAttacksFont);

            foreach (var attack in towerData.Attacks)
            {
                // time
                overlay[row, 0] = new MapText
                {
                    Text         = attack.Time.ToShortTimeString(),
                    Font         = font,
                    TextColor    = Color.White,
                    OutlineColor = Color.Black,
                    Outline      = true,
                };

                // Attacked site ZONE
                overlay[row, 1] = new MapText
                {
                    Text         = attack.ZoneShortName,
                    Font         = font,
                    TextColor    = this.GetFactionColor(attack.DefenderFaction),
                    OutlineColor = Color.Black,
                    Outline      = true,
                };

                // Attacked site ID
                overlay[row, 2] = new MapText
                {
                    Text         = String.Format("x{0}", attack.SiteID),
                    Font         = font,
                    TextColor    = this.GetFactionColor(attack.DefenderFaction),
                    OutlineColor = Color.Black,
                    Outline      = true,
                };


                // Attacker nickname
                overlay[row, 3] = new MapText
                {
                    Text         = attack.AttackerNickName,
                    Font         = font,
                    TextColor    = this.GetFactionColor(attack.AttackerFaction),
                    OutlineColor = Color.Black,
                    Outline      = true,
                };

                // Attacker org
                overlay[row, 4] = new MapText
                {
                    Font         = font,
                    TextColor    = this.GetFactionColor(attack.AttackerFaction),
                    OutlineColor = Color.Black,
                    Outline      = true,
                };

                if (!String.IsNullOrWhiteSpace(attack.AttackerGuildName))
                {
                    (overlay[row, 4] as MapText).Text = attack.AttackerGuildName;
                }
                else
                {
                    (overlay[row, 4] as MapText).Text = "-";
                }

                row++;
            }
            return(overlay.ToGuiOverlay());
        }