Beispiel #1
0
        private bool?CheckLocation(JsonClasses.SystemName rSystem, JsonZKill.Killmail kill, string groupName, string filterName)
        {
            if (rSystem == null)
            {
                LogHelper.LogError($"System not found: {kill.solar_system_id}!", Category).GetAwaiter().GetResult();
                return(false);
            }
            //System
            var fSystems = GetTier2SystemIds(ParsedLocationLists, groupName, filterName);

            if (fSystems.Any() && fSystems.Contains(kill.solar_system_id))
            {
                return(true);
            }
            //Constellation
            var fConsts = GetTier2ConstellationIds(ParsedLocationLists, groupName, filterName);

            if (fConsts.Any() && fConsts.Contains(rSystem.constellation_id))
            {
                return(true);
            }
            //Region
            var fRegions = GetTier2RegionIds(ParsedLocationLists, groupName, filterName);

            if (fRegions.Any() && rSystem.DB_RegionId.HasValue && fRegions.Contains(rSystem.DB_RegionId.Value))
            {
                return(true);
            }

            return(fSystems.Any() || fConsts.Any() || fRegions.Any() ? false : (bool?)null);
        }
        public override async Task Run(object prm)
        {
            if (IsRunning || Queryables.Count == 0)
            {
                return;
            }
            IsRunning = true;
            try
            {
                if (TickManager.IsNoConnection || !Queryables.Any())
                {
                    return;
                }
                JsonZKill.Killmail entry = null;

                if (Settings.Config.UseSocketsForZKillboard)
                {
                    var currentEntry = await APIHelper.ZKillAPI.GetSocketResponce();

                    if (currentEntry == null)
                    {
                        return;
                    }
                    if (!IsUniqueId(currentEntry.killmail_id))
                    {
                        return;
                    }
                    entry = currentEntry;
                }
                else
                {
                    var currentEntry = await APIHelper.ZKillAPI.GetRedisqResponce();

                    if (currentEntry?.package == null)
                    {
                        return;
                    }
                    if (!IsUniqueId(currentEntry.package.killID))
                    {
                        return;
                    }
                    currentEntry.package.killmail.zkb = currentEntry.package.zkb;
                    entry = currentEntry.package.killmail;
                }

                foreach (var q in Queryables)
                {
                    await q(entry).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                await LogHelper.LogEx(ex.Message, ex, Category);
            }
            finally
            {
                IsRunning = false;
            }
        }
        private async Task ProcessKill(JsonZKill.Killmail kill)
        {
            try
            {
                foreach (var groupPair in Settings.RadiusKillFeedModule.GroupsConfig)
                {
                    var groupName = groupPair.Key;
                    var group     = groupPair.Value;
                    if (!_lastPosted.ContainsKey(groupName))
                    {
                        _lastPosted.Add(groupName, 0);
                    }

                    if (_lastPosted[groupName] == kill.killmail_id)
                    {
                        continue;
                    }
                    _lastPosted[groupName] = kill.killmail_id;

                    var isNPCKill = kill.zkb.npc;
                    if ((!group.FeedPveKills && isNPCKill) || (!group.FeedPvpKills && !isNPCKill))
                    {
                        continue;
                    }
                    if (!ParsedGroups.ContainsKey(groupName))
                    {
                        continue;
                    }

                    if (!group.RadiusChannels.Any())
                    {
                        await LogHelper.LogWarning($"Group {groupName} has no 'radiusChannel' specified! Kills will be skipped.", Category);

                        continue;
                    }

                    foreach (var radiusSystemId in GetParsedSolarSystems(groupName))
                    {
                        await ProcessLocation(radiusSystemId, RadiusMode.Range, kill, group, groupName);
                    }
                    foreach (var radiusSystemId in GetParsedConstellations(groupName))
                    {
                        await ProcessLocation(radiusSystemId, RadiusMode.Constellation, kill, group, groupName);
                    }
                    foreach (var radiusSystemId in GetParsedRegions(groupName))
                    {
                        await ProcessLocation(radiusSystemId, RadiusMode.Region, kill, group, groupName);
                    }
                }
            }
            catch (Exception ex)
            {
                await LogHelper.LogEx(ex.Message, ex, Category);

                await LogHelper.LogWarning($"Error processing kill ID {kill?.killmail_id} ! Msg: {ex.Message}", Category);
            }
        }
Beispiel #4
0
        private bool?CheckLocation(JsonClasses.SystemName rSystem, JsonZKill.Killmail kill, KillMailFilter filter, string groupName, string filterName)
        {
            if (rSystem == null)
            {
                LogHelper.LogError($"System not found: {kill.solar_system_id}!", Category).GetAwaiter().GetResult();
                return(false);
            }

            if (!filter.ShowHighsecSystem && rSystem.security_status >= .5f)
            {
                return(false);
            }
            if (!filter.ShowLowsecSystem && rSystem.security_status >= .1f)
            {
                return(false);
            }
            if (!filter.ShowWormholeSystem && rSystem.IsWormhole())
            {
                return(false);
            }
            if (!filter.ShowAbyssSystem && rSystem.IsAbyss())
            {
                return(false);
            }
            if (!filter.ShowNullsecSystem && rSystem.security_status <= 0f)
            {
                return(false);
            }

            //Region
            var fRegions = GetTier2RegionIds(ParsedLocationLists, groupName, filterName);

            if (fRegions.Any() && rSystem.DB_RegionId.HasValue && fRegions.Contains(rSystem.DB_RegionId.Value))
            {
                return(true);
            }
            //Constellation
            var fConsts = GetTier2ConstellationIds(ParsedLocationLists, groupName, filterName);

            if (fConsts.Any() && fConsts.Contains(rSystem.constellation_id))
            {
                return(true);
            }
            //System
            var fSystems = GetTier2SystemIds(ParsedLocationLists, groupName, filterName);

            if (fSystems.Any() && fSystems.Contains(kill.solar_system_id))
            {
                return(true);
            }

            return(fSystems.Any() || fConsts.Any() || fRegions.Any() ? false : (bool?)null);
        }
Beispiel #5
0
        public async Task <bool> RefreshRadius(string reason, JsonZKill.Killmail kill)
        {
            if (killmailID > 0)
            {
                return(true);
            }
            try
            {
                killmailID = kill.killmail_id;
                value      = kill.zkb.totalValue;
                systemId   = kill.solar_system_id;
                rSystem    = await APIHelper.ESIAPI.GetSystemData(reason, systemId);

                isUnreachableSystem = systemId == 31000005;
                if (rSystem != null)
                {
                    sysName             = rSystem.name == rSystem.system_id.ToString() ? "Abyss" : (rSystem.name ?? "J");
                    isUnreachableSystem = rSystem.IsUnreachable();
                }
                else
                {
                    sysName = "?";
                }

                victimCharacterID       = kill.victim.character_id;
                victimCorpID            = kill.victim.corporation_id;
                victimAllianceID        = kill.victim.alliance_id;
                attackers               = kill.attackers;
                finalBlowAttacker       = attackers.FirstOrDefault(a => a.final_blow);
                finalBlowAttackerCorpId = finalBlowAttacker?.corporation_id ?? 0;
                finalBlowAttackerAllyId = finalBlowAttacker?.alliance_id ?? 0;
                shipID   = kill.victim.ship_type_id;
                killTime = kill.killmail_time.ToString(SettingsManager.Settings.Config.ShortTimeFormat);

                rVictimCorp = await APIHelper.ESIAPI.GetCorporationData(reason, victimCorpID);

                rAttackerCorp = finalBlowAttackerCorpId > 0
                        ? await APIHelper.ESIAPI.GetCorporationData(reason, finalBlowAttackerCorpId)
                        : null;

                rVictimAlliance = victimAllianceID != 0 ? await APIHelper.ESIAPI.GetAllianceData(reason, victimAllianceID) : null;

                rAttackerAlliance = finalBlowAttackerAllyId > 0
                        ? await APIHelper.ESIAPI.GetAllianceData(reason, finalBlowAttackerAllyId)
                        : null;

                rShipType = await APIHelper.ESIAPI.GetTypeId(reason, shipID);

                rVictimCharacter = await APIHelper.ESIAPI.GetCharacterData(reason, victimCharacterID);

                rAttackerCharacter = await APIHelper.ESIAPI.GetCharacterData(reason, finalBlowAttacker?.character_id);

                systemSecurityStatus = Math.Round(rSystem.security_status, 1).ToString("0.0");

                dic = new Dictionary <string, string>
                {
                    { "{shipID}", shipID.ToString() },
                    { "{shipType}", rShipType?.name },
                    { "{iskValue}", value.ToString("n0") },
                    { "{systemName}", sysName },
                    { "{systemSec}", systemSecurityStatus },
                    { "{victimName}", rVictimCharacter?.name },
                    { "{victimCorpName}", rVictimCorp?.name },
                    { "{victimCorpTicker}", rVictimCorp?.ticker },
                    { "{victimAllyName}", rVictimAlliance?.name },
                    { "{victimAllyTicker}", rVictimAlliance == null ? null : $"<{rVictimAlliance.ticker}>" },
                    { "{attackerName}", rAttackerCharacter?.name },
                    { "{attackerCorpName}", rAttackerCorp?.name },
                    { "{attackerCorpTicker}", rAttackerCorp?.ticker },
                    { "{attackerAllyTicker}", rAttackerAlliance == null ? null : $"<{rAttackerAlliance.ticker}>" },
                    { "{attackerAllyName}", rAttackerAlliance?.name },
                    { "{attackersCount}", attackers?.Length.ToString() },
                    { "{kmId}", killmailID.ToString() },
                    { "{isNpcKill}", isNPCKill.ToString() },
                    { "{timestamp}", killTime }
                };


                return(true);
            }
            catch (Exception ex)
            {
                killmailID = 0;
                await LogHelper.LogEx("refresh ex", ex, LogCat.RadiusKill);

                return(false);
            }
        }
Beispiel #6
0
        private bool?CheckLocation(JsonClasses.SystemName rSystem, JsonZKill.Killmail kill, bool isInclusive, string groupName, string filterName)
        {
            var isPassed = false;

            if (rSystem == null)
            {
                LogHelper.LogError($"System not found: {kill.solar_system_id}!", Category).GetAwaiter().GetResult();
                return(false);
            }

            var fCount = 0;
            //System
            var fLocs = GetTier2SystemIds(ParsedLocationLists, groupName, filterName);

            if (fLocs.Any())
            {
                if (isInclusive && !fLocs.Contains(kill.solar_system_id))
                {
                    return(false);
                }
                if (!isInclusive && fLocs.Contains(kill.solar_system_id))
                {
                    return(false);
                }
                if (isInclusive)
                {
                    isPassed = true;
                }
            }
            else
            {
                fCount++;
            }

            //Constellation
            if (!isPassed)
            {
                fLocs = GetTier2ConstellationIds(ParsedLocationLists, groupName, filterName);
                if (fLocs.Any())
                {
                    if (isInclusive && !fLocs.Contains(rSystem.constellation_id))
                    {
                        return(false);
                    }
                    if (!isInclusive && fLocs.Contains(rSystem.constellation_id))
                    {
                        return(false);
                    }
                    if (isInclusive)
                    {
                        isPassed = true;
                    }
                }
                else
                {
                    fCount++;
                }
            }

            //Region
            if (!isPassed)
            {
                fLocs = GetTier2RegionIds(ParsedLocationLists, groupName, filterName);
                if (fLocs.Any() && rSystem.DB_RegionId.HasValue)
                {
                    if (isInclusive && !fLocs.Contains(rSystem.DB_RegionId.Value))
                    {
                        return(false);
                    }
                    if (!isInclusive && fLocs.Contains(rSystem.DB_RegionId.Value))
                    {
                        return(false);
                    }
                    if (isInclusive)
                    {
                        isPassed = true;
                    }
                }
                else
                {
                    fCount++;
                }
            }

            return(fCount == 3 ? (bool?)null : true);
        }
Beispiel #7
0
        private async Task <bool> ProcessLocation(long radiusId, JsonZKill.Killmail kill, KillFeedGroup @group, KillMailFilter filter, string groupName)
        {
            var mode      = RadiusMode.Range;
            var isUrlOnly = group.FeedUrlsOnly;
            var radius    = filter.Radius;

            if (radiusId <= 0)
            {
                await LogHelper.LogError("Radius feed must have systemId!", Category);

                return(false);
            }

            var km = new KillDataEntry();
            await km.Refresh(Reason, kill);

            var routeLength = 0;

            JsonClasses.ConstellationData rConst = null;
            JsonClasses.RegionData        rRegion;
            var srcSystem = mode == RadiusMode.Range ? await APIHelper.ESIAPI.GetSystemData(Reason, radiusId) : null;

            if (radiusId == km.systemId)
            {
                //right there
                rConst = km.rSystem.constellation_id == 0 ? null : await APIHelper.ESIAPI.GetConstellationData(Reason, km.rSystem.constellation_id);

                rRegion = rConst?.region_id == null || rConst.region_id == 0 ? null : await APIHelper.ESIAPI.GetRegionData(Reason, rConst.region_id);
            }
            else
            {
                switch (mode)
                {
                case RadiusMode.Range:

                    if (radius == 0 || km.isUnreachableSystem || (srcSystem?.IsUnreachable() ?? true))     //Thera WH Abyss
                    {
                        return(false);
                    }

                    var route = await APIHelper.ESIAPI.GetRawRoute(Reason, radiusId, km.systemId);

                    if (string.IsNullOrEmpty(route))
                    {
                        return(false);
                    }
                    JArray data;
                    try
                    {
                        data = JArray.Parse(route);
                    }
                    catch (Exception ex)
                    {
                        await LogHelper.LogEx("Route parse: " + ex.Message, ex, Category);

                        return(false);
                    }

                    routeLength = data.Count - 1;
                    //not in range
                    if (routeLength > radius)
                    {
                        return(false);
                    }

                    var rSystemName = radiusId > 0 ? srcSystem?.name ?? LM.Get("Unknown") : LM.Get("Unknown");
                    km.dic.Add("{radiusSystem}", rSystemName);
                    km.dic.Add("{radiusJumps}", routeLength.ToString());

                    break;

                case RadiusMode.Constellation:
                    if (km.rSystem.constellation_id != radiusId)
                    {
                        return(false);
                    }
                    break;

                case RadiusMode.Region:
                    if (km.rSystem.DB_RegionId > 0)
                    {
                        if (km.rSystem.DB_RegionId != radiusId)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        rConst = await APIHelper.ESIAPI.GetConstellationData(Reason, km.rSystem.constellation_id);

                        if (rConst == null || rConst.region_id != radiusId)
                        {
                            return(false);
                        }
                    }

                    break;
                }
                rConst = rConst ?? await APIHelper.ESIAPI.GetConstellationData(Reason, km.rSystem.constellation_id);

                rRegion = await APIHelper.ESIAPI.GetRegionData(Reason, rConst.region_id);
            }

            //var rSystemName = rSystem?.name ?? LM.Get("Unknown");

            km.dic.Add("{isRangeMode}", (mode == RadiusMode.Range).ToString());
            km.dic.Add("{isConstMode}", (mode == RadiusMode.Constellation).ToString());
            km.dic.Add("{isRegionMode}", (mode == RadiusMode.Region).ToString());
            km.dic.AddOrUpdateEx("{constName}", rConst?.name);
            km.dic.AddOrUpdateEx("{regionName}", rRegion?.name);

            var template = isUrlOnly ? null : await TemplateHelper.GetTemplatedMessage(MessageTemplateType.KillMailRadius, km.dic);

            var channels = filter.DiscordChannels.Any() ? filter.DiscordChannels : group.DiscordChannels;

            foreach (var channel in channels)
            {
                if (isUrlOnly)
                {
                    await APIHelper.DiscordAPI.SendMessageAsync(channel, kill.zkb.url);
                }
                else
                {
                    if (template != null)
                    {
                        await APIHelper.DiscordAPI.SendMessageAsync(channel, group.ShowGroupName?groupName : " ", template).ConfigureAwait(false);
                    }
                    else
                    {
                        var jumpsText = routeLength > 0 ? $"{routeLength} {LM.Get("From")} {srcSystem?.name}" : $"{LM.Get("InSmall")} {km.sysName} ({km.systemSecurityStatus})";
                        await APIHelper.DiscordAPI.SendEmbedKillMessage(new List <ulong> {
                            channel
                        }, new Color(0x989898), km, string.IsNullOrEmpty(jumpsText)? "-" : jumpsText, group.ShowGroupName?groupName : " ");
                    }
                }
            }

            return(true);
        }
Beispiel #8
0
        private async Task ProcessKill(JsonZKill.Killmail kill)
        {
            try
            {
                // kill = JsonConvert.DeserializeObject<JsonZKill.Killmail>(File.ReadAllText("testkm.txt"));

                var hasBeenPosted = false;
                foreach (var(groupName, group) in Settings.LiveKillFeedModule.Groups)
                {
                    if (Settings.ZKBSettingsModule.AvoidDupesAcrossAllFeeds && ZKillLiveFeedModule.IsInSharedPool(kill.killmail_id))
                    {
                        return;
                    }

                    if (hasBeenPosted && Settings.LiveKillFeedModule.StopOnFirstGroupMatch)
                    {
                        break;
                    }

                    if (UpdateLastPosted(groupName, kill.killmail_id))
                    {
                        continue;
                    }

                    var isPveKill = kill.zkb.npc;
                    var isPvpKill = !kill.zkb.npc;

                    if ([email protected] && isPveKill || [email protected] && isPvpKill)
                    {
                        continue;
                    }
                    if (!group.FeedAwoxKills && kill.zkb.awox)
                    {
                        continue;
                    }
                    if (!group.FeedNotAwoxKills && !kill.zkb.awox)
                    {
                        continue;
                    }
                    if (!group.FeedSoloKills && kill.zkb.solo)
                    {
                        continue;
                    }
                    if (!group.FeedGroupKills && !kill.zkb.solo)
                    {
                        continue;
                    }

                    foreach (var(filterName, filter) in group.Filters)
                    {
                        var isInclusive       = filter.Inclusive;
                        var isLoss            = false;
                        var isPassed          = false;
                        var isFirstMatchOnly  = !filter.AllMustMatch;
                        var isCertifiedToFeed = false;

                        #region Person checks
                        //exclusions
                        var exList = GetTier2CharacterIds(ParsedExcludeAttackersLists, groupName, filterName);
                        if (exList.ContainsAnyFromList(kill.attackers.Select(a => a.character_id).Distinct()))
                        {
                            continue;
                        }
                        exList = GetTier2CorporationIds(ParsedExcludeAttackersLists, groupName, filterName);
                        if (exList.ContainsAnyFromList(kill.attackers.Select(a => a.corporation_id).Distinct()))
                        {
                            continue;
                        }
                        exList = GetTier2AllianceIds(ParsedExcludeAttackersLists, groupName, filterName);
                        if (exList.ContainsAnyFromList(kill.attackers.Where(a => a.alliance_id > 0).Select(a => a.alliance_id).Distinct()))
                        {
                            continue;
                        }

                        exList = GetTier2CharacterIds(ParsedExcludeVictimsLists, groupName, filterName);
                        if (exList.Contains(kill.victim.character_id))
                        {
                            continue;
                        }
                        exList = GetTier2CorporationIds(ParsedExcludeVictimsLists, groupName, filterName);
                        if (exList.Contains(kill.victim.corporation_id))
                        {
                            continue;
                        }
                        if (kill.victim.alliance_id > 0)
                        {
                            exList = GetTier2AllianceIds(ParsedExcludeVictimsLists, groupName, filterName);
                            if (exList.Contains(kill.victim.alliance_id))
                            {
                                continue;
                            }
                        }

                        exList = GetTier2SystemIds(ParsedExcludeLocationLists, groupName, filterName);
                        if (exList.Contains(kill.solar_system_id))
                        {
                            continue;
                        }

                        var rSystem = await APIHelper.ESIAPI.GetSystemData(Reason, kill.solar_system_id);

                        exList = GetTier2ConstellationIds(ParsedExcludeLocationLists, groupName, filterName);
                        if (rSystem != null && exList.Contains(rSystem.constellation_id))
                        {
                            continue;
                        }
                        exList = GetTier2RegionIds(ParsedExcludeLocationLists, groupName, filterName);
                        if (rSystem?.DB_RegionId != null && exList.Contains(rSystem.DB_RegionId.Value))
                        {
                            continue;
                        }

                        exList = GetTier2TypeIds(ParsedExcludeShipsLists, groupName, filterName);
                        if (exList.Contains(kill.victim.ship_type_id))
                        {
                            continue;
                        }

                        //character check
                        var fChars = GetTier2CharacterIds(ParsedAttackersLists, groupName, filterName);
                        if (fChars.Any())
                        {
                            var attackers = kill.attackers.Select(a => a.character_id);
                            if (isInclusive)
                            {
                                if (!fChars.ContainsAnyFromList(attackers))
                                {
                                    if (!isFirstMatchOnly)
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    isPassed          = true;
                                    isCertifiedToFeed = isFirstMatchOnly;
                                }
                            }
                            if (!isInclusive && fChars.ContainsAnyFromList(attackers))
                            {
                                continue;
                            }
                        }

                        if (!isCertifiedToFeed)
                        {
                            fChars = GetTier2CharacterIds(ParsedVictimsLists, groupName, filterName);
                            if (fChars.Any())
                            {
                                if (isInclusive)
                                {
                                    if (!fChars.Contains(kill.victim.character_id))
                                    {
                                        if (!isFirstMatchOnly)
                                        {
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        isLoss            = true;
                                        isPassed          = true;
                                        isCertifiedToFeed = isFirstMatchOnly;
                                    }
                                }
                                if (!isInclusive && fChars.Contains(kill.victim.character_id))
                                {
                                    continue;
                                }
                            }
                        }


                        //corp check
                        if (!isPassed && !isCertifiedToFeed)
                        {
                            fChars = GetTier2CorporationIds(ParsedAttackersLists, groupName, filterName);
                            if (fChars.Any())
                            {
                                var attackers = kill.attackers.Select(a => a.corporation_id);
                                if (isInclusive)
                                {
                                    if (!fChars.ContainsAnyFromList(attackers))
                                    {
                                        if (!isFirstMatchOnly)
                                        {
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        isPassed          = true;
                                        isCertifiedToFeed = isFirstMatchOnly;
                                    }
                                }
                                if (!isInclusive && fChars.ContainsAnyFromList(attackers))
                                {
                                    continue;
                                }
                            }

                            if (!isCertifiedToFeed)
                            {
                                fChars = GetTier2CorporationIds(ParsedVictimsLists, groupName, filterName);
                                if (fChars.Any())
                                {
                                    if (isInclusive)
                                    {
                                        if (!fChars.Contains(kill.victim.corporation_id))
                                        {
                                            if (!isFirstMatchOnly)
                                            {
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            isLoss            = true;
                                            isPassed          = true;
                                            isCertifiedToFeed = isFirstMatchOnly;
                                        }
                                    }
                                    if (!isInclusive && fChars.Contains(kill.victim.corporation_id))
                                    {
                                        continue;
                                    }
                                }
                            }
                        }

                        //alliance check
                        if (!isPassed && !isCertifiedToFeed)
                        {
                            fChars = GetTier2AllianceIds(ParsedAttackersLists, groupName, filterName);
                            if (fChars.Any())
                            {
                                var attackers = kill.attackers.Where(a => a.alliance_id > 0).Select(a => a.alliance_id);
                                if (isInclusive)
                                {
                                    if (!fChars.ContainsAnyFromList(attackers))
                                    {
                                        if (!isFirstMatchOnly)
                                        {
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        isPassed          = true;
                                        isCertifiedToFeed = isFirstMatchOnly;
                                    }
                                }

                                if (!isInclusive && fChars.ContainsAnyFromList(attackers))
                                {
                                    continue;
                                }
                            }

                            if (!isCertifiedToFeed)
                            {
                                fChars = GetTier2AllianceIds(ParsedVictimsLists, groupName, filterName);
                                if (fChars.Any())
                                {
                                    if (isInclusive)
                                    {
                                        if (!isFirstMatchOnly && kill.victim.alliance_id == 0)
                                        {
                                            continue;
                                        }
                                        if (kill.victim.alliance_id > 0)
                                        {
                                            if (!fChars.Contains(kill.victim.alliance_id))
                                            {
                                                if (!isFirstMatchOnly)
                                                {
                                                    continue;
                                                }
                                            }
                                            else
                                            {
                                                isLoss            = true;
                                                isPassed          = true;
                                                isCertifiedToFeed = isFirstMatchOnly;
                                            }
                                        }
                                    }

                                    if (!isInclusive && fChars.Contains(kill.victim.alliance_id))
                                    {
                                        continue;
                                    }
                                }
                            }
                        }

                        isPassed = false;
                        #endregion

                        //value checks
                        if (!isCertifiedToFeed)
                        {
                            if (isLoss && filter.MinimumLossValue >= kill.zkb.totalValue)
                            {
                                continue;
                            }
                            if (filter.MaximumLossValue > 0 && isLoss && filter.MaximumLossValue <= kill.zkb.totalValue)
                            {
                                continue;
                            }
                            if (!isLoss && filter.MinimumKillValue >= kill.zkb.totalValue)
                            {
                                continue;
                            }
                            if (filter.MaximumKillValue > 0 && !isLoss && filter.MaximumKillValue <= kill.zkb.totalValue)
                            {
                                continue;
                            }

                            if (isFirstMatchOnly && (filter.MinimumKillValue > 0 || filter.MinimumLossValue > 0 || filter.MaximumLossValue > 0 || filter.MaximumKillValue > 0))
                            {
                                isCertifiedToFeed = true;
                            }
                        }

                        #region Location checks (except system radius)

                        if (!isCertifiedToFeed)
                        {
                            var check = CheckLocation(rSystem, kill, isInclusive, groupName, filterName);
                            //if have some location criteria
                            if (check != null)
                            {
                                if (check == false)
                                {
                                    if (filter.Radius == 0 && !isFirstMatchOnly)
                                    {
                                        continue;
                                    }
                                }
                                else if (isInclusive && isFirstMatchOnly)
                                {
                                    isCertifiedToFeed = true;
                                }
                            }
                        }

                        #endregion

                        #region Type checks

                        var types = GetTier2TypeIds(ParsedShipsLists, groupName, filterName);
                        if (types.Any() && !isCertifiedToFeed)
                        {
                            if (isInclusive && !types.Contains(kill.victim.ship_type_id))
                            {
                                if (!isFirstMatchOnly)
                                {
                                    continue;
                                }
                            }
                            if (!isInclusive && types.Contains(kill.victim.ship_type_id))
                            {
                                continue;
                            }
                            if (isInclusive && isFirstMatchOnly)
                            {
                                isCertifiedToFeed = true;
                            }
                        }
                        #endregion

                        //haven't hit any criteria for 1-hit mode
                        if (!isCertifiedToFeed && isFirstMatchOnly)
                        {
                            continue;
                        }

                        var discordChannels = filter.DiscordChannels.Any() ? filter.DiscordChannels : group.DiscordChannels;

                        if (filter.Radius > 0)
                        {
                            #region Process system radius check

                            var msgType = MessageTemplateType.KillMailRadius;
                            var isDone  = false;
                            foreach (var radiusSystemId in GetTier2SystemIds(ParsedLocationLists, groupName, filterName))
                            {
                                if (await ProcessLocation(radiusSystemId, kill, group, filter, groupName))
                                {
                                    isDone        = true;
                                    hasBeenPosted = true;
                                    if (Settings.ZKBSettingsModule.AvoidDupesAcrossAllFeeds)
                                    {
                                        ZKillLiveFeedModule.UpdateSharedIdPool(kill.killmail_id);
                                    }
                                    await LogHelper.LogInfo($"Posting     {(isLoss ? "RLoss" : "RKill")}: {kill.killmail_id}  Value: {kill.zkb.totalValue:n0} ISK", Category);

                                    break;
                                }
                            }

                            if (isDone && group.StopOnFirstFilterMatch)
                            {
                                break;                                         //goto next group
                            }
                            #endregion
                        }
                        else
                        {
                            if (group.FeedUrlsOnly)
                            {
                                foreach (var channel in discordChannels)
                                {
                                    await APIHelper.DiscordAPI.SendMessageAsync(channel, kill.zkb.url);
                                }
                            }
                            else
                            {
                                var hasTemplate = !string.IsNullOrWhiteSpace(group.MessageTemplateFileName);
                                var msgColor    = isLoss ? new Color(0xD00000) : new Color(0x00FF00);
                                var msgType     = !hasTemplate ? MessageTemplateType.KillMailGeneral : MessageTemplateType.Custom;
                                var km          = new KillDataEntry();

                                if (await km.Refresh(Reason, kill))
                                {
                                    km.dic["{isLoss}"] = isLoss ? "true" : "false";
                                    var isDone = hasTemplate
                                        ? await TemplateHelper.PostTemplatedMessage(group.MessageTemplateFileName, km.dic, discordChannels, group.ShowGroupName?groupName : " ")
                                                 : await TemplateHelper.PostTemplatedMessage(msgType, km.dic, discordChannels,
                                                                                             group.ShowGroupName?groupName : " ");

                                    if (!isDone)
                                    {
                                        await APIHelper.DiscordAPI.SendEmbedKillMessage(discordChannels, msgColor, km, null);
                                    }
                                }
                            }

                            if (Settings.ZKBSettingsModule.AvoidDupesAcrossAllFeeds)
                            {
                                ZKillLiveFeedModule.UpdateSharedIdPool(kill.killmail_id);
                            }
                            await LogHelper.LogInfo($"Posting     {(isLoss ? "Loss" : "Kill")}: {kill.killmail_id}  Value: {kill.zkb.totalValue:n0} ISK", Category);

                            hasBeenPosted = true;
                            if (group.StopOnFirstFilterMatch)
                            {
                                break;                              //goto next group
                            }
                        }

                        continue; //goto next filter
                    }
                }
            }
            catch (Exception ex)
            {
                await LogHelper.LogEx(ex.Message, ex, Category);

                await LogHelper.LogWarning($"Error processing kill ID {kill?.killmail_id} ! Msg: {ex.Message}", Category);
            }
        }
        private async Task ProcessLocation(long radiusId, RadiusMode mode, JsonZKill.Killmail kill, RadiusGroup @group, string groupName)
        {
            var isUrlOnly    = group.FeedUrlsOnly;
            var radius       = group.Radius;
            var minimumValue = group.MinimumValue;

            if (radiusId <= 0)
            {
                await LogHelper.LogError("Radius feed must have systemId, constId or regionId defined!", Category);

                return;
            }

            var km = new KillDataEntry();
            await km.Refresh(Reason, kill);

            //validity check
            if (minimumValue > 0 && km.value < minimumValue)
            {
                return;
            }

            var routeLength = 0;

            JsonClasses.ConstellationData rConst = null;
            JsonClasses.RegionData        rRegion;
            var srcSystem = mode == RadiusMode.Range ? await APIHelper.ESIAPI.GetSystemData(Reason, radiusId) : null;

            if (radiusId == km.systemId)
            {
                //right there
                rConst = km.rSystem.constellation_id == 0 ? null : await APIHelper.ESIAPI.GetConstellationData(Reason, km.rSystem.constellation_id);

                rRegion = rConst?.region_id == null || rConst.region_id == 0 ? null : await APIHelper.ESIAPI.GetRegionData(Reason, rConst.region_id);
            }
            else
            {
                if (radius == 0 || km.isUnreachableSystem || (srcSystem?.IsUnreachable() ?? false)) //Thera WH Abyss
                {
                    return;
                }

                switch (mode)
                {
                case RadiusMode.Range:

                    var route = await APIHelper.ESIAPI.GetRawRoute(Reason, radiusId, km.systemId);

                    if (string.IsNullOrEmpty(route))
                    {
                        return;
                    }
                    JArray data;
                    try
                    {
                        data = JArray.Parse(route);
                    }
                    catch (Exception ex)
                    {
                        await LogHelper.LogEx("Route parse: " + ex.Message, ex, Category);

                        return;
                    }

                    routeLength = data.Count - 1;
                    //not in range
                    if (routeLength > radius)
                    {
                        return;
                    }

                    var rSystemName = radiusId > 0 ? srcSystem?.name ?? LM.Get("Unknown") : LM.Get("Unknown");
                    km.dic.Add("{radiusSystem}", rSystemName);
                    km.dic.Add("{radiusJumps}", routeLength.ToString());

                    break;

                case RadiusMode.Constellation:
                    if (km.rSystem.constellation_id != radiusId)
                    {
                        return;
                    }
                    break;

                case RadiusMode.Region:
                    rConst = await APIHelper.ESIAPI.GetConstellationData(Reason, km.rSystem.constellation_id);

                    if (rConst == null || rConst.region_id != radiusId)
                    {
                        return;
                    }
                    break;
                }
                rConst = rConst ?? await APIHelper.ESIAPI.GetConstellationData(Reason, km.rSystem.constellation_id);

                rRegion = await APIHelper.ESIAPI.GetRegionData(Reason, rConst.region_id);
            }

            //var rSystemName = rSystem?.name ?? LM.Get("Unknown");

            km.dic.Add("{isRangeMode}", (mode == RadiusMode.Range).ToString());
            km.dic.Add("{isConstMode}", (mode == RadiusMode.Constellation).ToString());
            km.dic.Add("{isRegionMode}", (mode == RadiusMode.Region).ToString());
            km.dic.Add("{constName}", rConst?.name);
            km.dic.Add("{regionName}", rRegion?.name);

            var template = isUrlOnly ? null : await TemplateHelper.GetTemplatedMessage(MessageTemplateType.KillMailRadius, km.dic);

            foreach (var channel in group.RadiusChannels)
            {
                if (isUrlOnly)
                {
                    await APIHelper.DiscordAPI.SendMessageAsync(channel, kill.zkb.url);
                }
                else
                {
                    if (template != null)
                    {
                        await APIHelper.DiscordAPI.SendMessageAsync(channel, group.ShowGroupName?groupName : " ", template).ConfigureAwait(false);
                    }
                    else
                    {
                        var jumpsText = routeLength > 0 ? $"{routeLength} {LM.Get("From")} {srcSystem?.name}" : $"{LM.Get("InSmall")} {km.sysName} ({km.systemSecurityStatus})";
                        await APIHelper.DiscordAPI.SendEmbedKillMessage(channel, new Color(0x989898), km, jumpsText, group.ShowGroupName?groupName : " ");
                    }
                }
            }

            await LogHelper.LogInfo($"Posting  Radius Kill: {kill.killmail_id}  Value: {km.value:n0} ISK", Category);
        }
Beispiel #10
0
        public override async Task Run(object prm)
        {
            if (IsRunning || Queryables.Count == 0 || Program.IsClosing || !APIHelper.IsDiscordAvailable)
            {
                return;
            }
            if (!Settings.Config.ModuleLiveKillFeed)
            {
                return;
            }

            var minus = Settings.ZKBSettingsModule.OldKMDaysThreshold == 0 ? DateTime.Now : DateTime.Now.Subtract(TimeSpan.FromDays(Settings.ZKBSettingsModule.OldKMDaysThreshold));

            try
            {
                IsRunning = true;
                if (TickManager.IsNoConnection || !Queryables.Any())
                {
                    return;
                }
                JsonZKill.Killmail entry = null;

                if (Settings.ZKBSettingsModule.UseSocketsForZKillboard)
                {
                    var currentEntry = await APIHelper.ZKillAPI.GetSocketResponce();

                    if (currentEntry == null)
                    {
                        return;
                    }
                    if (!IsUniqueId(currentEntry.killmail_id))
                    {
                        return;
                    }
                    entry = currentEntry;
                }
                else
                {
                    var currentEntry = await APIHelper.ZKillAPI.GetRedisqResponce();

                    if (currentEntry?.package == null)
                    {
                        return;
                    }
                    if (!IsUniqueId(currentEntry.package.killID))
                    {
                        return;
                    }
                    currentEntry.package.killmail.zkb = currentEntry.package.zkb;
                    entry = currentEntry.package.killmail;
                }

                //do the minus days check
                if (entry.killmail_time < minus)
                {
                    return;
                }

                foreach (var q in Queryables)
                {
                    await q(entry).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                await LogHelper.LogEx(ex.Message, ex, Category);
            }
            finally
            {
                IsRunning = false;
            }
        }
Beispiel #11
0
        public async Task <bool> Refresh(string reason, JsonZKill.Killmail kill)
        {
            if (killmailID > 0)
            {
                return(true);
            }
            try
            {
                killmailID                   = kill.killmail_id;
                killTime                     = kill.killmail_time.ToString(SettingsManager.Settings.Config.ShortTimeFormat);
                victimShipID                 = kill.victim.ship_type_id;
                value                        = kill.zkb.totalValue;
                victimCharacterID            = kill.victim.character_id;
                victimCorpID                 = kill.victim.corporation_id;
                victimAllianceID             = kill.victim.alliance_id;
                attackers                    = kill.attackers;
                finalBlowAttacker            = attackers.FirstOrDefault(a => a.final_blow);
                finalBlowAttackerCharacterId = finalBlowAttacker.character_id;
                attackerShipID               = finalBlowAttacker?.ship_type_id ?? 0;
                finalBlowAttackerCorpId      = finalBlowAttacker?.corporation_id ?? 0;
                finalBlowAttackerAllyId      = finalBlowAttacker?.alliance_id ?? 0;
                isNPCKill                    = kill.zkb.npc;
                systemId                     = kill.solar_system_id;
                rSystem                      = await APIHelper.ESIAPI.GetSystemData(reason, systemId);

                if (rSystem == null)
                {
                    //ESI fail - check back later
                    return(false);
                }

                rVictimCorp = await APIHelper.ESIAPI.GetCorporationData(reason, victimCorpID);

                rAttackerCorp = finalBlowAttackerCorpId > 0
                    ? await APIHelper.ESIAPI.GetCorporationData(reason, finalBlowAttackerCorpId)
                    : null;

                rVictimAlliance = victimAllianceID != 0 ? await APIHelper.ESIAPI.GetAllianceData(reason, victimAllianceID) : null;

                rAttackerAlliance = finalBlowAttackerAllyId > 0
                    ? await APIHelper.ESIAPI.GetAllianceData(reason, finalBlowAttackerAllyId)
                    : null;

                sysName = rSystem.name == rSystem.system_id.ToString() ? "Abyss" : rSystem.name;
                var rConst = rSystem != null ? await APIHelper.ESIAPI.GetConstellationData(reason, rSystem.constellation_id) : null;

                var rRegion = rConst != null ? await APIHelper.ESIAPI.GetRegionData(reason, rConst.region_id) : null;

                rVictimShipType = await APIHelper.ESIAPI.GetTypeId(reason, victimShipID);

                rAttackerShipType = await APIHelper.ESIAPI.GetTypeId(reason, attackerShipID);

                rVictimCharacter = await APIHelper.ESIAPI.GetCharacterData(reason, victimCharacterID);

                rAttackerCharacter = await APIHelper.ESIAPI.GetCharacterData(reason, finalBlowAttacker?.character_id);

                systemSecurityStatus = Math.Round(rSystem.security_status, 1).ToString("0.0");

                dic = new Dictionary <string, string>
                {
                    { "{shipID}", victimShipID.ToString() },
                    { "{shipType}", rVictimShipType?.name },
                    { "{attackerShipID}", attackerShipID.ToString() },
                    { "{attackerShipType}", rAttackerShipType?.name },
                    { "{iskValue}", value.ToString("n0") },
                    { "{iskFittedValue}", kill?.zkb?.fittedValue.ToString("n0") ?? "0" },
                    { "{systemName}", sysName },
                    { "{constName}", rConst?.name },
                    { "{regionName}", rRegion?.name },
                    { "{systemSec}", systemSecurityStatus },
                    { "{victimName}", rVictimCharacter?.name },
                    { "{victimCorpName}", rVictimCorp?.name },
                    { "{victimCorpTicker}", rVictimCorp?.ticker },
                    { "{victimAllyName}", rVictimAlliance?.name },
                    { "{victimAllyTicker}", rVictimAlliance == null ? null : $"<{rVictimAlliance.ticker}>" },
                    { "{victimAllyOrCorpName}", rVictimAlliance?.name ?? rVictimCorp?.name },
                    { "{victimAllyOrCorpTicker}", rVictimAlliance?.ticker ?? rVictimCorp?.ticker },
                    { "{attackerName}", rAttackerCharacter?.name },
                    { "{attackerCorpName}", rAttackerCorp?.name },
                    { "{attackerCorpTicker}", rAttackerCorp?.ticker },
                    { "{attackerAllyTicker}", rAttackerAlliance == null ? null : $"<{rAttackerAlliance.ticker}>" },
                    { "{attackerAllyName}", rAttackerAlliance?.name },
                    { "{attackerAllyOrCorpName}", rAttackerAlliance?.name ?? rAttackerCorp?.name },
                    { "{attackerAllyOrCorpTicker}", rAttackerAlliance?.ticker ?? rAttackerCorp?.ticker },
                    { "{attackersCount}", attackers.Length.ToString() },
                    { "{kmId}", killmailID.ToString() },
                    { "{timestamp}", killTime },
                    { "{isLoss}", "false" },
                    { "{isNpcKill}", isNPCKill.ToString() ?? "false" },
                    { "{isSoloKill}", kill?.zkb?.solo.ToString() ?? "false" },
                    { "{isAwoxKill}", kill?.zkb?.awox.ToString() ?? "false" },
                };

                return(true);
            }
            catch (Exception ex)
            {
                killmailID = 0;
                await LogHelper.LogEx("refresh ex", ex, LogCat.KillFeed);

                return(false);
            }
        }
Beispiel #12
0
        private async Task ProcessKill(JsonZKill.Killmail kill)
        {
            try
            {
                RunningRequestCount++;
                // var text = JsonConvert.SerializeObject(kill);
                //kill = JsonConvert.DeserializeObject<JsonZKill.Killmail>(File.ReadAllText("testkm_pvp.txt"));

                var hasBeenPosted = false;
                foreach (var(groupName, group) in Settings.LiveKillFeedModule.GetEnabledGroups())
                {
                    if (Settings.ZKBSettingsModule.AvoidDupesAcrossAllFeeds &&
                        ZKillLiveFeedModule.IsInSharedPool(kill.killmail_id))
                    {
                        return;
                    }

                    if (hasBeenPosted && Settings.LiveKillFeedModule.StopOnFirstGroupMatch)
                    {
                        break;
                    }

                    if (UpdateLastPosted(groupName, kill.killmail_id))
                    {
                        continue;
                    }

                    var isPveKill = kill.zkb.npc;
                    var isPvpKill = !kill.zkb.npc;

                    if ([email protected] && isPveKill || [email protected] && isPvpKill)
                    {
                        continue;
                    }
                    if (!group.FeedAwoxKills && kill.zkb.awox)
                    {
                        continue;
                    }
                    if (!group.FeedNotAwoxKills && !kill.zkb.awox)
                    {
                        continue;
                    }
                    if (!group.FeedSoloKills && kill.zkb.solo)
                    {
                        continue;
                    }
                    if (!group.FeedGroupKills && !kill.zkb.solo)
                    {
                        continue;
                    }

                    foreach (var(filterName, filter) in group.Filters)
                    {
                        var isLoss            = false;
                        var isCertifiedToFeed = false;

                        #region Person & Value checks

                        #region Exclusions

                        var exList = GetTier2CharacterIds(ParsedExcludeAttackersLists, groupName, filterName);
                        if (exList.ContainsAnyFromList(kill.attackers.Select(a => a.character_id).Distinct()))
                        {
                            continue;
                        }
                        exList = GetTier2CorporationIds(ParsedExcludeAttackersLists, groupName, filterName);
                        if (exList.ContainsAnyFromList(kill.attackers.Select(a => a.corporation_id).Distinct()))
                        {
                            continue;
                        }
                        exList = GetTier2AllianceIds(ParsedExcludeAttackersLists, groupName, filterName);
                        if (exList.ContainsAnyFromList(kill.attackers.Where(a => a.alliance_id > 0)
                                                       .Select(a => a.alliance_id).Distinct()))
                        {
                            continue;
                        }

                        exList = GetTier2CharacterIds(ParsedExcludeVictimsLists, groupName, filterName);
                        if (exList.Contains(kill.victim.character_id))
                        {
                            continue;
                        }
                        exList = GetTier2CorporationIds(ParsedExcludeVictimsLists, groupName, filterName);
                        if (exList.Contains(kill.victim.corporation_id))
                        {
                            continue;
                        }
                        if (kill.victim.alliance_id > 0)
                        {
                            exList = GetTier2AllianceIds(ParsedExcludeVictimsLists, groupName, filterName);
                            if (exList.Contains(kill.victim.alliance_id))
                            {
                                continue;
                            }
                        }

                        exList = GetTier2SystemIds(ParsedExcludeLocationLists, groupName, filterName);
                        if (exList.Contains(kill.solar_system_id))
                        {
                            continue;
                        }

                        var rSystem = await APIHelper.ESIAPI.GetSystemData(Reason, kill.solar_system_id);

                        exList = GetTier2ConstellationIds(ParsedExcludeLocationLists, groupName, filterName);
                        if (rSystem != null && exList.Contains(rSystem.constellation_id))
                        {
                            continue;
                        }
                        exList = GetTier2RegionIds(ParsedExcludeLocationLists, groupName, filterName);
                        if (rSystem?.DB_RegionId != null && exList.Contains(rSystem.DB_RegionId.Value))
                        {
                            continue;
                        }

                        exList = GetTier2TypeIds(ParsedExcludeVictimShipsLists, groupName, filterName);
                        if (exList.Contains(kill.victim.ship_type_id))
                        {
                            continue;
                        }
                        exList = GetTier2TypeIds(ParsedExcludeAttackerShipsLists, groupName, filterName);
                        if (kill.attackers.Select(a => a.ship_type_id).ContainsAnyFromList(exList))
                        {
                            continue;
                        }


                        #endregion

                        //value checks
                        if (filter.MinimumIskValue > kill.zkb.totalValue)
                        {
                            continue;
                        }
                        if (filter.MaximumIskValue > 0 && filter.MaximumIskValue < kill.zkb.totalValue)
                        {
                            continue;
                        }

                        //if (filter.EnableMatchOnFirstConditionMet && (filter.MinimumIskValue > 0 || filter.MaximumIskValue > 0 ))
                        //    isCertifiedToFeed = true;

                        //character check
                        var         hasAttackerMatch = false;
                        var         hasPartyCheck    = false;
                        List <long> entityIds;
                        if (!isCertifiedToFeed)
                        {
                            entityIds = GetTier2CharacterIds(ParsedAttackersLists, groupName, filterName);
                            if (entityIds.Any())
                            {
                                hasPartyCheck = true;
                                var attackers = kill.attackers.Select(a => a.character_id);
                                if (entityIds.ContainsAnyFromList(attackers))
                                {
                                    if (filter.EnableMatchOnFirstConditionMet)
                                    {
                                        isCertifiedToFeed = true;
                                    }
                                    hasAttackerMatch = true;
                                }
                            }
                        }

                        var hasVictimMatch = false;
                        if (!isCertifiedToFeed)
                        {
                            entityIds = GetTier2CharacterIds(ParsedVictimsLists, groupName, filterName);
                            if (entityIds.Any())
                            {
                                hasPartyCheck = true;
                                if (entityIds.Contains(kill.victim.character_id))
                                {
                                    if (filter.EnableMatchOnFirstConditionMet)
                                    {
                                        isCertifiedToFeed = true;
                                    }
                                    hasVictimMatch = true;
                                    isLoss         = true;
                                }
                            }
                        }

                        //corp check
                        if ((!hasVictimMatch || !hasAttackerMatch) && !isCertifiedToFeed)
                        {
                            if (!hasAttackerMatch)
                            {
                                entityIds = GetTier2CorporationIds(ParsedAttackersLists, groupName, filterName);
                                if (entityIds.Any())
                                {
                                    hasPartyCheck = true;
                                    var attackers = kill.attackers.Select(a => a.corporation_id);
                                    if (entityIds.ContainsAnyFromList(attackers))
                                    {
                                        if (filter.EnableMatchOnFirstConditionMet)
                                        {
                                            isCertifiedToFeed = true;
                                        }
                                        hasAttackerMatch = true;
                                    }
                                }
                            }

                            if (!isCertifiedToFeed && !hasVictimMatch)
                            {
                                entityIds = GetTier2CorporationIds(ParsedVictimsLists, groupName, filterName);
                                if (entityIds.Any())
                                {
                                    hasPartyCheck = true;
                                    if (entityIds.Contains(kill.victim.corporation_id))
                                    {
                                        if (filter.EnableMatchOnFirstConditionMet)
                                        {
                                            isCertifiedToFeed = true;
                                        }
                                        hasVictimMatch = true;
                                        isLoss         = true;
                                    }
                                }
                            }
                        }

                        //alliance check
                        if ((!hasVictimMatch || !hasAttackerMatch) && !isCertifiedToFeed)
                        {
                            if (!hasAttackerMatch)
                            {
                                entityIds = GetTier2AllianceIds(ParsedAttackersLists, groupName, filterName);
                                if (entityIds.Any())
                                {
                                    hasPartyCheck = true;
                                    var attackers = kill.attackers.Where(a => a.alliance_id > 0)
                                                    .Select(a => a.alliance_id);
                                    if (entityIds.ContainsAnyFromList(attackers))
                                    {
                                        if (filter.EnableMatchOnFirstConditionMet)
                                        {
                                            isCertifiedToFeed = true;
                                        }
                                        hasAttackerMatch = true;
                                    }
                                }
                            }

                            if (!isCertifiedToFeed && !hasVictimMatch)
                            {
                                entityIds = GetTier2AllianceIds(ParsedVictimsLists, groupName, filterName);
                                if (entityIds.Any())
                                {
                                    hasPartyCheck = true;
                                    if (entityIds.Contains(kill.victim.alliance_id))
                                    {
                                        if (filter.EnableMatchOnFirstConditionMet)
                                        {
                                            isCertifiedToFeed = true;
                                        }
                                        hasVictimMatch = true;
                                        isLoss         = true;
                                    }
                                }
                            }
                        }

                        //has no strict match = continue
                        if (hasPartyCheck && !isCertifiedToFeed && filter.EnableStrictPartiesCheck &&
                            (!hasAttackerMatch || !hasVictimMatch))
                        {
                            continue;
                        }

                        //has no party match on check
                        if (hasPartyCheck && !isCertifiedToFeed && !filter.EnableStrictPartiesCheck &&
                            !hasAttackerMatch && !hasVictimMatch)
                        {
                            continue;
                        }

                        #endregion

                        #region Location checks (except system radius)

                        if (!isCertifiedToFeed)
                        {
                            var check = CheckLocation(rSystem, kill, filter, groupName, filterName);
                            //if have some location criteria
                            if (check != null)
                            {
                                if (check.Value) //match
                                {
                                    if (filter.EnableMatchOnFirstConditionMet)
                                    {
                                        isCertifiedToFeed = true;
                                    }
                                }
                                else //no match
                                {
                                    //no radius checks planned
                                    if (filter.Radius == 0)
                                    {
                                        continue;
                                    }
                                }
                            }
                        }

                        #endregion

                        #region Type checks

                        bool hasTypesCheck        = false;
                        bool hasVictimTypeMatch   = false;
                        bool hasAttackerTypeMatch = false;
                        var  types = GetTier2TypeIds(ParsedVictimShipsLists, groupName, filterName);
                        if (types.Any() && !isCertifiedToFeed)
                        {
                            hasTypesCheck = true;
                            if (types.Contains(kill.victim.ship_type_id))
                            {
                                hasVictimTypeMatch = true;
                                if (filter.EnableMatchOnFirstConditionMet)
                                {
                                    isCertifiedToFeed = true;
                                }
                            }
                        }

                        types = GetTier2TypeIds(ParsedAttackerShipsLists, groupName, filterName);
                        if (types.Any() && !isCertifiedToFeed)
                        {
                            hasTypesCheck = true;
                            if (types.ContainsAnyFromList(kill.attackers.Select(a => a.ship_type_id)))
                            {
                                hasAttackerTypeMatch = true;
                                if (filter.EnableMatchOnFirstConditionMet)
                                {
                                    isCertifiedToFeed = true;
                                }
                            }
                        }

                        if (hasTypesCheck && !isCertifiedToFeed && filter.EnableStrictShipTypesCheck && (!hasAttackerTypeMatch || !hasVictimTypeMatch))
                        {
                            continue;
                        }

                        if (hasTypesCheck && !isCertifiedToFeed && !filter.EnableStrictShipTypesCheck && !hasAttackerTypeMatch && !hasVictimTypeMatch)
                        {
                            continue;
                        }

                        #endregion

                        //haven't hit any criteria for 1-hit mode
                        // if(!isCertifiedToFeed && filter.EnableMatchOnFirstConditionMet) continue;

                        var discordChannels = filter.DiscordChannels.Any()
                            ? filter.DiscordChannels
                            : group.DiscordChannels;

                        if (filter.Radius > 0)
                        {
                            #region Process system radius check

                            //var msgType = MessageTemplateType.KillMailRadius;
                            var isDone = false;
                            foreach (var radiusSystemId in GetTier2SystemIds(ParsedLocationLists, groupName, filterName))
                            {
                                if (await ProcessLocation(radiusSystemId, kill, group, filter, groupName))
                                {
                                    isDone        = true;
                                    hasBeenPosted = true;
                                    if (Settings.ZKBSettingsModule.AvoidDupesAcrossAllFeeds)
                                    {
                                        ZKillLiveFeedModule.UpdateSharedIdPool(kill.killmail_id);
                                    }
                                    await LogHelper.LogInfo(
                                        $"Posting     {(isLoss ? "RLoss" : "RKill")}: {kill.killmail_id}  Value: {kill.zkb.totalValue:n0} ISK",
                                        Category);

                                    break;
                                }
                            }

                            if (isDone && group.StopOnFirstFilterMatch)
                            {
                                break;                                         //goto next group
                            }
                            #endregion
                        }
                        else
                        {
                            if (group.FeedUrlsOnly)
                            {
                                foreach (var channel in discordChannels)
                                {
                                    await APIHelper.DiscordAPI.SendMessageAsync(channel, kill.zkb.url);
                                }
                                await LogHelper.LogInfo(
                                    $"U.Posted     {(isLoss ? "Loss" : "Kill")}: {kill.killmail_id}  Value: {kill.zkb.totalValue:n0} ISK",
                                    Category);
                            }
                            else
                            {
                                var hasTemplate = !string.IsNullOrWhiteSpace(group.MessageTemplateFileName);
                                var msgColor    = isLoss ? new Color(0xD00000) : new Color(0x00FF00);
                                var km          = new KillDataEntry();

                                if (await km.Refresh(Reason, kill))
                                {
                                    km.dic["{isLoss}"] = isLoss ? "true" : "false";
                                    if (hasTemplate)
                                    {
                                        hasBeenPosted = await TemplateHelper.PostTemplatedMessage(
                                            group.MessageTemplateFileName, km.dic, discordChannels,
                                            group.ShowGroupName?groupName : " ");

                                        if (hasBeenPosted)
                                        {
                                            await LogHelper.LogInfo(
                                                $"T.Posted     {(isLoss ? "Loss" : "Kill")}: {kill.killmail_id}  Value: {kill.zkb.totalValue:n0} ISK",
                                                Category);
                                        }
                                    }
                                    else
                                    {
                                        await SendEmbedKillMessage(discordChannels, msgColor, km,
                                                                   group.ShowGroupName?groupName : " ");

                                        hasBeenPosted = true;
                                        await LogHelper.LogInfo(
                                            $"N.Posted     {(isLoss ? "Loss" : "Kill")}: {kill.killmail_id}  Value: {kill.zkb.totalValue:n0} ISK",
                                            Category);
                                    }
                                }
                            }

                            if (Settings.ZKBSettingsModule.AvoidDupesAcrossAllFeeds)
                            {
                                ZKillLiveFeedModule.UpdateSharedIdPool(kill.killmail_id);
                            }

                            if (group.StopOnFirstFilterMatch)
                            {
                                break;                               //goto next group
                            }
                        }

                        continue; //goto next filter
                    }
                }
            }
            catch (Exception ex)
            {
                await LogHelper.LogEx(ex.Message, ex, Category);

                await LogHelper.LogWarning($"Error processing kill ID {kill?.killmail_id} ! Msg: {ex.Message}",
                                           Category);
            }
            finally
            {
                RunningRequestCount--;
            }
        }
Beispiel #13
0
        private async Task ProcessKill(JsonZKill.Killmail kill)
        {
            try
            {
                if (_lastPosted == kill.killmail_id)
                {
                    return;
                }
                var postedGlobalBigKill = false;
                var bigKillGlobalValue  = SettingsManager.Settings.LiveKillFeedModule.BigKill;
                var bigKillGlobalChan   = SettingsManager.Settings.LiveKillFeedModule.BigKillChannel;
                var isNPCKill           = kill.zkb.npc;

                var km = new KillDataEntry();

                foreach (var groupPair in Settings.LiveKillFeedModule.GroupsConfig)
                {
                    var group = groupPair.Value;
                    if ((!group.FeedPveKills && isNPCKill) || (!group.FeedPvpKills && !isNPCKill))
                    {
                        continue;
                    }

                    var minimumValue     = group.MinimumValue;
                    var minimumLossValue = group.MinimumLossValue;
                    var allianceIdList   = group.AllianceID;
                    var corpIdList       = group.CorpID;
                    var bigKillValue     = group.BigKillValue;
                    var c = group.DiscordChannel;
                    var sendBigToGeneral = group.BigKillSendToGeneralToo;
                    var bigKillChannel   = group.BigKillChannel;
                    var discordGroupName = groupPair.Key;
                    var isUrlOnly        = group.FeedUrlsOnly;

                    if (c == 0)
                    {
                        await LogHelper.LogWarning($"Group {groupPair.Key} has no 'discordChannel' specified! Kills will be skipped.", Category);

                        continue;
                    }

                    var value = kill.zkb.totalValue;


                    if (bigKillGlobalChan != 0 && bigKillGlobalValue != 0 && value >= bigKillGlobalValue && !postedGlobalBigKill)
                    {
                        postedGlobalBigKill = true;

                        if (isUrlOnly)
                        {
                            await APIHelper.DiscordAPI.SendMessageAsync(bigKillGlobalChan, kill.zkb.url);
                        }
                        else
                        {
                            if (await km.Refresh(Reason, kill) && !await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailBig, km.dic, bigKillGlobalChan, discordGroupName))
                            {
                                await APIHelper.DiscordAPI.SendEmbedKillMessage(bigKillGlobalChan, new Color(0xFA2FF4), km, null);
                            }
                        }

                        await LogHelper.LogInfo($"Posting Global Big Kill: {kill.killmail_id}  Value: {value:n0} ISK", Category);
                    }

                    if (!allianceIdList.Any() && !corpIdList.Any())
                    {
                        if (value >= minimumValue)
                        {
                            if (isUrlOnly)
                            {
                                await APIHelper.DiscordAPI.SendMessageAsync(c, kill.zkb.url);
                            }
                            else if (await km.Refresh(Reason, kill) && !await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailGeneral, km.dic, c, discordGroupName))
                            {
                                await APIHelper.DiscordAPI.SendEmbedKillMessage(c, new Color(0x00FF00), km, null);
                            }

                            await LogHelper.LogInfo($"Posting Global Kills: {kill.killmail_id}  Value: {value:n0} ISK", Category);
                        }
                    }
                    else
                    {
                        //ally & corp

                        //Losses
                        //Big
                        if (bigKillChannel != 0 && bigKillValue != 0 && value >= bigKillValue)
                        {
                            if (kill.victim.alliance_id != 0 && allianceIdList.Contains(kill.victim.alliance_id) || corpIdList.Contains(kill.victim.corporation_id))
                            {
                                if (isUrlOnly)
                                {
                                    await APIHelper.DiscordAPI.SendMessageAsync(bigKillChannel, kill.zkb.url);

                                    if (sendBigToGeneral && c != bigKillChannel)
                                    {
                                        await APIHelper.DiscordAPI.SendMessageAsync(c, kill.zkb.url);
                                    }
                                }
                                else if (await km.Refresh(Reason, kill))
                                {
                                    km.dic["{isLoss}"] = "true";
                                    try
                                    {
                                        if (!await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailBig, km.dic, bigKillChannel, discordGroupName))
                                        {
                                            await APIHelper.DiscordAPI.SendEmbedKillMessage(bigKillChannel, new Color(0xD00000), km, null,
                                                                                            groupPair.Value.ShowGroupName?discordGroupName : " ");

                                            if (sendBigToGeneral && c != bigKillChannel)
                                            {
                                                if (!await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailBig, km.dic, c, discordGroupName))
                                                {
                                                    await APIHelper.DiscordAPI.SendEmbedKillMessage(c, new Color(0xD00000), km, null,
                                                                                                    groupPair.Value.ShowGroupName?discordGroupName : " ");
                                                }
                                            }
                                        }
                                    }
                                    finally
                                    {
                                        km.dic.Remove("{isLoss}");
                                    }
                                }

                                await LogHelper.LogInfo($"Posting     Big Loss: {kill.killmail_id}  Value: {value:n0} ISK", Category);

                                continue;
                            }
                        }

                        //Common
                        if (minimumLossValue == 0 || minimumLossValue <= value)
                        {
                            if (kill.victim.alliance_id != 0 && allianceIdList.Contains(kill.victim.alliance_id) || corpIdList.Contains(kill.victim.corporation_id))
                            {
                                if (isUrlOnly)
                                {
                                    await APIHelper.DiscordAPI.SendMessageAsync(c, kill.zkb.url);
                                }
                                else if (await km.Refresh(Reason, kill))
                                {
                                    km.dic["{isLoss}"] = "true";
                                    try
                                    {
                                        if (!await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailGeneral, km.dic, c, discordGroupName))
                                        {
                                            await APIHelper.DiscordAPI.SendEmbedKillMessage(c, new Color(0xFF0000), km, null,
                                                                                            groupPair.Value.ShowGroupName?discordGroupName : " ");
                                        }
                                    }
                                    finally
                                    {
                                        km.dic.Remove("{isLoss}");
                                    }
                                }

                                await LogHelper.LogInfo($"Posting         Loss: {kill.killmail_id}  Value: {value:n0} ISK", Category);

                                continue;
                            }
                        }

                        //Kills
                        foreach (var attacker in kill.attackers.ToList())
                        {
                            if (bigKillChannel != 0 && bigKillValue != 0 && value >= bigKillValue && !isNPCKill)
                            {
                                if ((attacker.alliance_id != 0 && allianceIdList.Contains(attacker.alliance_id)) ||
                                    (!allianceIdList.Any() && corpIdList.Contains(attacker.corporation_id)))
                                {
                                    if (isUrlOnly)
                                    {
                                        await APIHelper.DiscordAPI.SendMessageAsync(bigKillChannel, kill.zkb.url);

                                        if (sendBigToGeneral && c != bigKillChannel)
                                        {
                                            await APIHelper.DiscordAPI.SendMessageAsync(c, kill.zkb.url);
                                        }
                                    }
                                    else if (await km.Refresh(Reason, kill))
                                    {
                                        km.dic["{isLoss}"] = "false";
                                        try
                                        {
                                            if (!await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailBig, km.dic, bigKillChannel, discordGroupName))
                                            {
                                                await APIHelper.DiscordAPI.SendEmbedKillMessage(bigKillChannel, new Color(0x00D000), km, null,
                                                                                                groupPair.Value.ShowGroupName?discordGroupName : " ");

                                                if (sendBigToGeneral && c != bigKillChannel)
                                                {
                                                    if (!await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailBig, km.dic, c, discordGroupName))
                                                    {
                                                        await APIHelper.DiscordAPI.SendEmbedKillMessage(c, new Color(0x00D000), km, null,
                                                                                                        groupPair.Value.ShowGroupName?discordGroupName : " ");
                                                    }
                                                }

                                                await LogHelper.LogInfo($"Posting     Big Kill: {kill.killmail_id}  Value: {value:#,##0} ISK", Category);
                                            }
                                        }
                                        finally
                                        {
                                            km.dic.Remove("{isLoss}");
                                        }
                                    }

                                    break;
                                }
                            }
                            else if (!isNPCKill && attacker.alliance_id != 0 && allianceIdList.Any() && allianceIdList.Contains(attacker.alliance_id) ||
                                     !isNPCKill && !allianceIdList.Any() && corpIdList.Contains(attacker.corporation_id))
                            {
                                if (isUrlOnly)
                                {
                                    await APIHelper.DiscordAPI.SendMessageAsync(c, kill.zkb.url);
                                }
                                else if (await km.Refresh(Reason, kill))
                                {
                                    km.dic["{isLoss}"] = "false";
                                    try
                                    {
                                        if (!await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailGeneral, km.dic, c, discordGroupName))
                                        {
                                            await APIHelper.DiscordAPI.SendEmbedKillMessage(c, new Color(0x00FF00), km, null,
                                                                                            groupPair.Value.ShowGroupName?discordGroupName : " ");
                                        }
                                    }
                                    finally
                                    {
                                        km.dic.Remove("{isLoss}");
                                    }
                                }

                                await LogHelper.LogInfo($"Posting         Kill: {kill.killmail_id}  Value: {value:#,##0} ISK", Category);

                                break;
                            }
                        }
                    }
                }

                _lastPosted = kill.killmail_id;
            }
            catch (Exception ex)
            {
                await LogHelper.LogEx(ex.Message, ex, Category);

                await LogHelper.LogWarning($"Error processing kill ID {kill?.killmail_id} ! Msg: {ex.Message}", Category);
            }
        }