Skip to content

Commit

Permalink
Add changes for 0.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
ExcuseMi committed Aug 30, 2016
1 parent 9830ed8 commit 478cbeb
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 55 deletions.
2 changes: 2 additions & 0 deletions PogoLocationFeeder/Client/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class Filter
public bool VerifiedOnly { get; set; }
public string Version { get; set; }
public LatLngBounds AreaBounds;
public double PokemonNotInFilterMinimumIV { get; set; } = 101;

public double MinimumIV { get; set; } = 0.0;
public bool UseUploadedPokemon { get; set; } = true;
public bool UnverifiedOnly { get; set; } = false;
Expand Down
1 change: 1 addition & 0 deletions PogoLocationFeeder/Client/FilterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public static Filter Create(List<DiscordChannels> discordChannels = null)
filter.MinimumIV = GlobalSettings.MinimumIV;
filter.UnverifiedOnly = GlobalSettings.UnverifiedOnly;
filter.UseUploadedPokemon = GlobalSettings.UseUploadedPokemon;
filter.PokemonNotInFilterMinimumIV = GlobalSettings.PokemonNotInFilterMinimumIV;
return filter;
}
}
Expand Down
11 changes: 9 additions & 2 deletions PogoLocationFeeder/Client/PogoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,15 @@ public void Start(List<ChannelParser.DiscordChannels> discordChannels )
{
if (serverUploadFilter == null || serverUploadFilter.Matches(sniperInfo))
{
newSniperInfos.Add(sniperInfo);
Log.Info($"Uploading bot pokemon: {sniperInfo.ToString()}");
if (GlobalSettings.IsManaged)
{
SniperInfo oldSniperInfo = MessageCache.Instance._clientRepository.Find(sniperInfo);
if (oldSniperInfo == null || oldSniperInfo.NeedVerification)
{
newSniperInfos.Add(sniperInfo);
Log.Info($"Uploading bot pokemon: {sniperInfo}");
}
}
}
else
{
Expand Down
7 changes: 5 additions & 2 deletions PogoLocationFeeder/Config/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class GlobalSettings
public static bool VerifiedOnly = true;
public static bool UseUploadedPokemon = true;
public static bool UnverifiedOnly = false;

public static double PokemonNotInFilterMinimumIV = 101;
public static List<string> PokekomsToFeedFilter;
public static List<int> BotWebSocketPorts = new List<int>() { 14251 };

Expand Down Expand Up @@ -116,6 +116,7 @@ public static GlobalSettings Load()
MinimumIV = set.MinimumIV;
UnverifiedOnly = set.UnverifedOnly;
UseUploadedPokemon = set.UseUploadedPokemon;
PokemonNotInFilterMinimumIV = set.PokemonNotInFilterMinimumIV;
}
else
{
Expand Down Expand Up @@ -284,6 +285,8 @@ public class SettingsToSave
[DefaultValue(true)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public bool UseUploadedPokemon = GlobalSettings.UseUploadedPokemon;

[DefaultValue(101)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public double PokemonNotInFilterMinimumIV = GlobalSettings.PokemonNotInFilterMinimumIV;
}
}
11 changes: 7 additions & 4 deletions PogoLocationFeeder/Helper/SniperInfoFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ internal static List<SniperInfo> FilterUnmanaged(List<SniperInfo> sniperInfos, F
var minimumIV = filter.MinimumIV;
var useUploadedPokemon = filter.UseUploadedPokemon;
var unverifiedOnly = filter.UnverifiedOnly;
var pokemonNotInFilterMinimumIV = filter.PokemonNotInFilterMinimumIV;
return sniperInfos.Where(
s => Matches(s, pokemonIds, verifiedOnly, channels, areaBounds, minimumIV, useUploadedPokemon, unverifiedOnly)).ToList();
s => Matches(s, pokemonIds, verifiedOnly, channels, areaBounds, minimumIV, useUploadedPokemon, unverifiedOnly, pokemonNotInFilterMinimumIV)).ToList();
}

private static bool Matches(SniperInfo sniperInfo, List<PokemonId> pokemonIds,
bool verifiedOnly, List<Channel> channels, LatLngBounds areaBounds, double minimumIV, bool useUploadedPokemon,
bool unverifiedOnly)
bool unverifiedOnly, double pokemonNotInFilterMinimumIV)
{

if (!useUploadedPokemon && (Constants.Bot == sniperInfo.ChannelInfo.server
Expand All @@ -68,8 +69,10 @@ private static bool Matches(SniperInfo sniperInfo, List<PokemonId> pokemonIds,
}
if (!pokemonIds.Contains(sniperInfo.Id))
{
Log.Trace($"Skipped {sniperInfo} because not in pokemon list");
return false;
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()))
{
Expand Down
75 changes: 39 additions & 36 deletions PogoLocationFeeder/Helper/SniperInfoRepositoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,41 +81,8 @@ private void AddCaptureExisting(SniperInfo oldSniperInfo, SniperInfo sniperInfo)
{
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;
}
}


}
if (sniperInfo.ChannelInfo != null &&
!oldSniperInfo.GetAllChannelInfos()
Expand All @@ -125,11 +92,47 @@ private void AddCaptureExisting(SniperInfo oldSniperInfo, SniperInfo sniperInfo)
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)}");
}

private bool ValidateVerifiedSniperInfo(SniperInfo sniperInfo)
public static bool ValidateVerifiedSniperInfo(SniperInfo sniperInfo)
{
return !PokemonId.Missingno.Equals(sniperInfo.Id)
&& sniperInfo.Verified
Expand Down
4 changes: 2 additions & 2 deletions PogoLocationFeeder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ You should have received a copy of the GNU Affero General Public License
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("0.1.9.0")]
[assembly: AssemblyFileVersion("0.1.9.0")]
[assembly: AssemblyVersion("0.1.10.0")]
[assembly: AssemblyFileVersion("0.1.10.0")]
9 changes: 7 additions & 2 deletions PogoLocationFeeder/Server/PogoServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ private void socketServer_NewMessageReceived(WebSocketSession session, string va
else if (matchRequest.Success)
{
List<SniperInfo> sniperInfoToSend = FilterOnRequest(matchRequest);
sniperInfoToSend.ForEach(s=>s.NeedVerification = !SniperInfoRepositoryManager.ValidateVerifiedSniperInfo(s));
session.Send($"{GetEpoch()}:Hear my words that I might teach you:" +
JsonConvert.SerializeObject(sniperInfoToSend));
}
Expand Down Expand Up @@ -158,7 +159,11 @@ protected virtual void OnReceivedViaClients(SniperInfo sniperInfo)
if(Constants.Bot == sniperInfo.ChannelInfo?.server ||
Constants.PogoFeeder == sniperInfo.ChannelInfo?.server)
{
PogoClient.sniperInfosToSend.Enqueue(sniperInfo);
var oldSniperInfo = _serverRepository.Find(sniperInfo);
if (oldSniperInfo == null || oldSniperInfo.NeedVerification)
{
PogoClient.sniperInfosToSend.Enqueue(sniperInfo);
}
}
}
ReceivedViaClients?.Invoke(this, sniperInfo);
Expand Down Expand Up @@ -194,7 +199,7 @@ private List<SniperInfo> FilterOnRequest(Match match)

var lastReceived = Convert.ToInt64(match.Groups[1].Value);
var sniperInfos = _serverRepository.FindAllNew(lastReceived, filter.VerifiedOnly);

return SniperInfoFilter.FilterUnmanaged(sniperInfos, filter);
}
}
Expand Down
14 changes: 7 additions & 7 deletions PogoLocationFeeder/Server/ServerUploadFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using PogoLocationFeeder.Common;
using PogoLocationFeeder.Helper;

Expand All @@ -31,13 +25,18 @@ public class ServerUploadFilter
public string Pokemon { get; set; }
public LatLngBounds AreaBounds { get; set; }
public double MinimumIV { get; set; } = 0.0;
public double PokemonNotInFilterMinimumIV { get; set; } = 101;

public bool Matches(SniperInfo sniperInfo)
{
var pokemonIds = PokemonFilterParser.ParseBinary(Pokemon);

if (pokemonIds != null && !pokemonIds.Contains(sniperInfo.Id))
{
return false;
if (PokemonNotInFilterMinimumIV > sniperInfo.IV)
{
return false;
}
}
if (AreaBounds != null && !AreaBounds.Intersects(sniperInfo.Latitude, sniperInfo.Longitude))
{
Expand All @@ -47,6 +46,7 @@ public bool Matches(SniperInfo sniperInfo)
{
return false;
}

return true;
}
}
Expand Down
1 change: 1 addition & 0 deletions PogoLocationFeeder/SniperInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class SniperInfo
[JsonIgnore]
public List<ChannelInfo> OtherChannelInfos { get; set; } = new List<ChannelInfo>();
public DateTime ReceivedTimeStamp { get; set; } = DateTime.Now;
public bool NeedVerification { get; set; }

public override string ToString()
{
Expand Down

0 comments on commit 478cbeb

Please sign in to comment.