public bool AddToRepository(SniperInfo sniperInfo)
        {
            //Ignore this for clients because it could be causing some problems.
            if (GlobalSettings.IsServer)
            {
                if (sniperInfo.ReceivedTimeStamp > DateTime.Now || sniperInfo.VerifiedOn > DateTime.Now ||
                    sniperInfo.ExpirationTimestamp > DateTime.Now.AddMinutes(20))
                {
                    return(false);
                }
            }
            var oldSniperInfo = _sniperInfoRepository.Find(sniperInfo);

            if (oldSniperInfo != null)
            {
                if (sniperInfo.ChannelInfo != null && sniperInfo.ChannelInfo.server == Constants.Bot)
                {
                    if (!ValidateVerifiedSniperInfo(oldSniperInfo))
                    {
                        AddCaptureExisting(oldSniperInfo, sniperInfo);
                    }
                }
                else
                {
                    AddDuplicateDiscovery(oldSniperInfo, sniperInfo);
                }
                return(false);
            }
            else
            {
                AddNew(sniperInfo);
                return(true);
            }
        }
 private static bool Matches(SniperInfo sniperInfo, List <PokemonId> pokemonIds, bool verifiedOnly, List <Channel> channels, LatLngBounds areaBounds, double minimumIV)
 {
     if (!pokemonIds.Contains(sniperInfo.Id))
     {
         Log.Trace($"Skipped {sniperInfo} because not in pokemon list");
         return(false);
     }
     if (verifiedOnly && !sniperInfo.Verified)
     {
         Log.Trace($"Skipped {sniperInfo} because verifiedOnly is on, but this isn't verified");
         return(false);
     }
     if (channels != null && !MatchesChannel(channels, sniperInfo.GetAllChannelInfos()))
     {
         Log.Trace($"Skipped {sniperInfo} because the channel doesn't match the channel list");
         return(false);
     }
     if (areaBounds != null && !areaBounds.Intersects(sniperInfo.Latitude, sniperInfo.Longitude))
     {
         Log.Trace($"Skipped {sniperInfo} because the lat & long isn't the areabounds {areaBounds}");
         return(false);
     }
     if (minimumIV > sniperInfo.IV)
     {
         Log.Trace($"Skipped {sniperInfo} because the IV was lower than {minimumIV}");
         return(false);
     }
     return(true);
 }
Beispiel #3
0
        public List <SniperInfo> parseMessage(string message)
        {
            var snipeList = new List <SniperInfo>();
            var lines     = message.Split(new[] { '\r', '\n' });

            foreach (var input in lines)
            {
                sniperInfo = new SniperInfo();
                GeoCoordinates geoCoordinates = GeoCoordinatesParser.parseGeoCoordinates(input);
                if (geoCoordinates == null)
                {
                    Log.Debug($"Can't get coords from line: {input}");
                    continue;
                }
                else
                {
                    sniperInfo.Latitude  = geoCoordinates.latitude;
                    sniperInfo.Longitude = geoCoordinates.longitude;
                }
                double iv = IVParser.parseIV(input);
                sniperInfo.IV = iv;
                parseTimestamp(input);
                PokemonId pokemon = PokemonParser.parsePokemon(input);
                sniperInfo.Id = pokemon;
                snipeList.Add(sniperInfo);
            }

            return(snipeList);
        }
Beispiel #4
0
        public bool AddToRepository(SniperInfo sniperInfo)
        {
            if (sniperInfo.ReceivedTimeStamp > DateTime.Now || sniperInfo.VerifiedOn > DateTime.Now ||
                sniperInfo.ExpirationTimestamp > DateTime.Now.AddMinutes(20))
            {
                return(false);
            }
            var oldSniperInfo = _sniperInfoRepository.Find(sniperInfo);

            if (oldSniperInfo != null)
            {
                if (sniperInfo.ChannelInfo != null && sniperInfo.ChannelInfo.server == Constants.Bot)
                {
                    if (!ValidateVerifiedSniperInfo(oldSniperInfo))
                    {
                        AddCaptureExisting(oldSniperInfo, sniperInfo);
                    }
                }
                else
                {
                    AddDuplicateDiscovery(oldSniperInfo, sniperInfo);
                }
                return(false);
            }
            else
            {
                AddNew(sniperInfo);
                return(true);
            }
        }
Beispiel #5
0
        private void AddCaptureExisting(SniperInfo oldSniperInfo, SniperInfo sniperInfo)
        {
            if (PokemonId.Missingno.Equals(oldSniperInfo.Id))
            {
                oldSniperInfo.Id = sniperInfo.Id;
            }
            if (oldSniperInfo.IV == 0 && sniperInfo.IV != 0)
            {
                oldSniperInfo.IV = sniperInfo.IV;
            }
            if (!oldSniperInfo.Verified)
            {
                if (sniperInfo.Verified)
                {
                    oldSniperInfo.Verified   = sniperInfo.Verified;
                    oldSniperInfo.VerifiedOn = DateTime.Now;
                    if (oldSniperInfo.ExpirationTimestamp == default(DateTime))
                    {
                        if (sniperInfo.ExpirationTimestamp != default(DateTime))
                        {
                            oldSniperInfo.VerifiedOn = sniperInfo.ExpirationTimestamp;
                        }
                    }
                    if (oldSniperInfo.EncounterId == default(ulong))
                    {
                        if (sniperInfo.EncounterId != default(ulong))
                        {
                            oldSniperInfo.EncounterId = sniperInfo.EncounterId;
                        }
                    }
                    if (oldSniperInfo.Move1 == PokemonMove.MoveUnset)
                    {
                        if (sniperInfo.Move1 != PokemonMove.MoveUnset)
                        {
                            oldSniperInfo.Move1 = sniperInfo.Move1;
                        }
                    }
                    if (oldSniperInfo.Move2 == PokemonMove.MoveUnset)
                    {
                        if (sniperInfo.Move2 != PokemonMove.MoveUnset)
                        {
                            oldSniperInfo.Move2 = sniperInfo.Move2;
                        }
                    }
                    if (oldSniperInfo.SpawnPointId == default(string))
                    {
                        if (sniperInfo.SpawnPointId != default(string))
                        {
                            oldSniperInfo.SpawnPointId = sniperInfo.SpawnPointId;
                        }
                    }
                }
            }

            oldSniperInfo.OtherChannelInfos.Add(sniperInfo.ChannelInfo);
            var captures = _sniperInfoRepository.Increase(oldSniperInfo);

            Log.Pokemon($"Captured existing: {FormatPokemonLog(oldSniperInfo, sniperInfo.ChannelInfo, captures)}");
        }
Beispiel #6
0
        private void AddNew(SniperInfo sniperInfo)
        {
            var captures = _sniperInfoRepository.Update(sniperInfo);

            Log.Pokemon($"Discovered: {FormatPokemonLog(sniperInfo,  sniperInfo.ChannelInfo, captures)}");
            if (GlobalSettings.Output != null)
            {
                GlobalSettings.Output.PrintPokemon(sniperInfo);
            }
        }
 public static bool ValidateVerifiedSniperInfo(SniperInfo sniperInfo)
 {
     return(!PokemonId.Missingno.Equals(sniperInfo.Id) &&
            sniperInfo.Verified &&
            sniperInfo.EncounterId != default(ulong) &&
            sniperInfo.Move1 != PokemonMove.MoveUnset &&
            sniperInfo.Move2 != PokemonMove.MoveUnset &&
            (sniperInfo.SpawnPointId != null && sniperInfo.SpawnPointId != "") &&
            sniperInfo.IV > 0);
 }
Beispiel #8
0
        private bool isSentAlready(SniperInfo sniperInfo)
        {
            String coordinates = getCoordinatesString(sniperInfo);

            if (MemoryCache.Default.Contains(coordinates))
            {
                return(true);
            }
            DateTime expirationDate = sniperInfo.ExpirationTimestamp != default(DateTime) ? sniperInfo.ExpirationTimestamp : DateTime.Now.AddMinutes(15);

            MemoryCache.Default.Add(coordinates, sniperInfo, new DateTimeOffset(expirationDate));
            return(false);
        }
Beispiel #9
0
 private static string FormatPokemonLog(SniperInfo sniperInfo, ChannelInfo channelInfo, int captures)
 {
     return($"{channelInfo}: {sniperInfo.Id} at {sniperInfo.Latitude.ToString("N6", CultureInfo.InvariantCulture)},{sniperInfo.Longitude.ToString("N6", CultureInfo.InvariantCulture)}"
            + " with " +
            (!sniperInfo.IV.Equals(default(double))
                ? $"{sniperInfo.IV}% IV"
                : "unknown IV")
            + (sniperInfo.Move1 != PokemonMove.MoveUnset ? $" Move1: {sniperInfo.Move1.ToString()}" : "")
            + (sniperInfo.Move2 != PokemonMove.MoveUnset ? $" Move2: {sniperInfo.Move2.ToString()}" : "")
            + (sniperInfo.EncounterId != default(ulong) ? $" EncounterId: {sniperInfo.EncounterId.ToString()}" : "")
            + (sniperInfo.ExpirationTimestamp != default(DateTime)
                ? $" until {sniperInfo.ExpirationTimestamp.ToString(timeFormat)}"
                : "") + $", Captures {captures}");
 }
        private void AddNew(SniperInfo sniperInfo)
        {
            if (sniperInfo.ExpirationTimestamp > DateTime.Now.AddHours(2) || sniperInfo.ExpirationTimestamp < DateTime.Now)
            {
                sniperInfo.ExpirationTimestamp = default(DateTime);
            }
            var captures = _sniperInfoRepository.Update(sniperInfo);

            Log.Pokemon($"Discovered: {FormatPokemonLog(sniperInfo,  captures)}");
            if (GlobalSettings.Output != null)
            {
                GlobalSettings.Output.PrintPokemon(sniperInfo);
            }
        }
Beispiel #11
0
        private static string FormatPokemonLog(SniperInfo sniperInfo)
        {
            const string timeFormat = "HH:mm:ss";

            return($"{sniperInfo.ChannelInfo}: {sniperInfo.Id} at {sniperInfo.Latitude.ToString("N6", CultureInfo.InvariantCulture)},{sniperInfo.Longitude.ToString("N6", CultureInfo.InvariantCulture)}"
                   + " with " +
                   (!sniperInfo.IV.Equals(default(double))
                       ? $"{sniperInfo.IV}% IV"
                       : "unknown IV")
                   + (sniperInfo.Move1 != PokemonMove.MoveUnset && sniperInfo.Move1 != null ? $" Move1: {sniperInfo.Move1.ToString()}" : "")
                   + (sniperInfo.Move2 != PokemonMove.MoveUnset && sniperInfo.Move2 != null ? $" Move2: {sniperInfo.Move2.ToString()}" : "")
                   + (sniperInfo.EncounterId != default(ulong) && sniperInfo.EncounterId != null ? $" EncounterId: {sniperInfo.EncounterId.ToString()}" : "")
                   + (sniperInfo.ExpirationTimestamp != default(DateTime)
                       ? $" until {sniperInfo.ExpirationTimestamp.ToString(timeFormat)}"
                       : ""));
        }
Beispiel #12
0
 private static bool SniperInfoEquals(SniperInfo a, SniperInfo b)
 {
     if (Math.Abs(a.Latitude - b.Latitude) <= Constants.CoordinatesOffsetAllowed &&
         Math.Abs(a.Longitude - b.Longitude) <= Constants.CoordinatesOffsetAllowed)
     {
         if (a.Id.Equals(PokemonId.Missingno) || b.Id.Equals(PokemonId.Missingno))
         {
             return(true);
         }
         if (a.Id.Equals(b.Id))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #13
0
        private static bool IsSentAlready(SniperInfo sniperInfo)
        {
            var coordinates = GetCoordinatesString(sniperInfo);

            if (MemoryCache.Default.Contains(coordinates))
            {
                Log.Debug($"Skipping duplicate {sniperInfo}");
                return(true);
            }
            var expirationDate = sniperInfo.ExpirationTimestamp != default(DateTime)
                ? sniperInfo.ExpirationTimestamp
                : DateTime.Now.AddMinutes(15);

            MemoryCache.Default.Add(coordinates, sniperInfo, new DateTimeOffset(expirationDate));
            return(false);
        }
Beispiel #14
0
 private static bool Matches(SniperInfo sniperInfo, List <PokemonId> pokemonIds,
                             bool verifiedOnly, List <Channel> channels, LatLngBounds areaBounds, double minimumIV, bool useUploadedPokemon,
                             bool unverifiedOnly, double pokemonNotInFilterMinimumIV)
 {
     if (!useUploadedPokemon && (Constants.Bot == sniperInfo.ChannelInfo.server ||
                                 Constants.PogoFeeder == sniperInfo.ChannelInfo.server))
     {
         Log.Trace($"Skipped {sniperInfo} because useUploadedPokemon is false.");
         return(false);
     }
     if (verifiedOnly && !sniperInfo.Verified)
     {
         Log.Trace($"Skipped {sniperInfo} because verifiedOnly is on, but this isn't verified");
         return(false);
     }
     if (unverifiedOnly && sniperInfo.Verified)
     {
         Log.Trace($"Skipped {sniperInfo} because unverifiedOnly was true.");
         return(false);
     }
     if (minimumIV > sniperInfo.IV)
     {
         Log.Trace($"Skipped {sniperInfo} because the IV was lower than {minimumIV}");
         return(false);
     }
     if (!pokemonIds.Contains(sniperInfo.Id))
     {
         if (pokemonNotInFilterMinimumIV > sniperInfo.IV)
         {
             Log.Trace($"Skipped {sniperInfo} because not in pokemon list and pokemonNotInFilterMinimumIV is higher than its IV");
             return(false);
         }
     }
     if (channels != null && !MatchesChannel(channels, sniperInfo.GetAllChannelInfos()))
     {
         Log.Trace($"Skipped {sniperInfo} because the channel doesn't match the channel list");
         return(false);
     }
     if (areaBounds != null && !areaBounds.Intersects(sniperInfo.Latitude, sniperInfo.Longitude))
     {
         Log.Trace($"Skipped {sniperInfo} because the lat & long isn't the areabounds {areaBounds}");
         return(false);
     }
     return(true);
 }
Beispiel #15
0
        private static List <SniperInfo> ParseMultiLine(string[] lines)
        {
            var        sniperInfos = new List <SniperInfo>();
            SniperInfo current     = null;

            foreach (var line in lines)
            {
                var pokemon = PokemonParser.ParsePokemon(line);
                if (pokemon != PokemonId.Missingno)
                {
                    if (IsValid(current))
                    {
                        sniperInfos.Add(current);
                    }
                    current    = new SniperInfo();
                    current.Id = pokemon;
                }
                if (current != null)
                {
                    var geoCoordinates = GeoCoordinatesParser.ParseGeoCoordinates(line);
                    if (geoCoordinates != null)
                    {
                        current.Latitude  = Math.Round(geoCoordinates.Latitude, 7);
                        current.Longitude = Math.Round(geoCoordinates.Longitude, 7);
                    }
                    var iv = IVParser.ParseIV(line);
                    current.IV = iv;
                    var timeStamp = ParseTimestamp(line);
                    if (timeStamp != default(DateTime))
                    {
                        current.ExpirationTimestamp = DateTime.Now.AddMinutes(Constants.MaxExpirationInTheFuture) < timeStamp?
                                                      DateTime.Now.AddMinutes(Constants.MaxExpirationInTheFuture) :
                                                          timeStamp;
                    }
                }
            }
            if (IsValid(current))
            {
                sniperInfos.Add(current);
            }
            return(sniperInfos);
        }
Beispiel #16
0
        private void AddDuplicateDiscovery(SniperInfo oldSniperInfo, SniperInfo sniperInfo)
        {
            bool updated = false;

            if (PokemonId.Missingno.Equals(oldSniperInfo.Id) && !PokemonId.Missingno.Equals(sniperInfo.Id))
            {
                oldSniperInfo.Id = sniperInfo.Id;
                updated          = true;
            }
            if (sniperInfo.ChannelInfo != null && !oldSniperInfo.GetAllChannelInfos().Any(ci => object.Equals(ci.server, sniperInfo.ChannelInfo.server) &&
                                                                                          (object.Equals(ci.channel, sniperInfo.ChannelInfo.channel))))
            {
                oldSniperInfo.OtherChannelInfos.Add(sniperInfo.ChannelInfo);
                updated = true;
            }
            if (updated)
            {
                var captures = _sniperInfoRepository.Update(oldSniperInfo);
                Log.Debug($"Discovered (DUP): {FormatPokemonLog(oldSniperInfo, sniperInfo.ChannelInfo, captures)}");
            }
        }
Beispiel #17
0
        public bool AddToRepository(SniperInfo sniperInfo)
        {
            var oldSniperInfo = _sniperInfoRepository.Find(sniperInfo);

            if (oldSniperInfo != null)
            {
                if (sniperInfo.ChannelInfo != null && sniperInfo.ChannelInfo.server == Constants.Bot)
                {
                    AddCaptureExisting(oldSniperInfo, sniperInfo);
                }
                else
                {
                    AddDuplicateDiscovery(oldSniperInfo, sniperInfo);
                }
                return(false);
            }
            else
            {
                AddNew(sniperInfo);
                return(true);
            }
        }
Beispiel #18
0
 private static bool IsValid(SniperInfo current)
 {
     return(current != null && current.Id != PokemonId.Missingno && current.Longitude != default(double) &&
            current.Latitude != default(double));
 }
Beispiel #19
0
 private bool IsSentAlready(SniperInfo sniperInfo)
 {
     return(!_sniperInfoRepositoryManager.AddToRepository(sniperInfo));
 }
Beispiel #20
0
 internal void Add(SniperInfo sniperInfo)
 {
     _sniperInfoRepositoryManager.AddToRepository(sniperInfo);
 }
Beispiel #21
0
 private static String getCoordinatesString(SniperInfo sniperInfo)
 {
     return(messagePrefix + sniperInfo.Latitude + ", " + sniperInfo.Longitude);
 }
        private void AddCaptureExisting(SniperInfo oldSniperInfo, SniperInfo sniperInfo)
        {
            if (PokemonId.Missingno.Equals(oldSniperInfo.Id))
            {
                oldSniperInfo.Id = sniperInfo.Id;
            }
            if (oldSniperInfo.IV <= 0 && sniperInfo.IV > 0)
            {
                oldSniperInfo.IV = sniperInfo.IV;
            }
            if (!oldSniperInfo.Verified)
            {
                if (sniperInfo.Verified)
                {
                    oldSniperInfo.Verified   = sniperInfo.Verified;
                    oldSniperInfo.VerifiedOn = DateTime.Now;
                }
                if (sniperInfo.ChannelInfo != null &&
                    !oldSniperInfo.GetAllChannelInfos()
                    .Any(ci => object.Equals(ci.server, sniperInfo.ChannelInfo.server) &&
                         (object.Equals(ci.channel, sniperInfo.ChannelInfo.channel))))
                {
                    oldSniperInfo.OtherChannelInfos.Add(sniperInfo.ChannelInfo);
                }
            }
            if (oldSniperInfo.Move1 == PokemonMove.MoveUnset)
            {
                if (sniperInfo.Move1 != PokemonMove.MoveUnset)
                {
                    oldSniperInfo.Move1 = sniperInfo.Move1;
                }
            }
            if (oldSniperInfo.Move2 == PokemonMove.MoveUnset)
            {
                if (sniperInfo.Move2 != PokemonMove.MoveUnset)
                {
                    oldSniperInfo.Move2 = sniperInfo.Move2;
                }
            }
            if (oldSniperInfo.EncounterId == default(ulong))
            {
                if (sniperInfo.EncounterId != default(ulong))
                {
                    oldSniperInfo.EncounterId = sniperInfo.EncounterId;
                }
            }

            if (oldSniperInfo.SpawnPointId == default(string))
            {
                if (sniperInfo.SpawnPointId != default(string))
                {
                    oldSniperInfo.SpawnPointId = sniperInfo.SpawnPointId;
                }
            }
            if (oldSniperInfo.ExpirationTimestamp == default(DateTime))
            {
                if (sniperInfo.ExpirationTimestamp != default(DateTime))
                {
                    oldSniperInfo.VerifiedOn = sniperInfo.ExpirationTimestamp;
                }
            }
            var captures = _sniperInfoRepository.Increase(oldSniperInfo);

            Log.Pokemon($"Captured existing: {FormatPokemonLog(oldSniperInfo, captures)}");
        }