Skip to content

Commit

Permalink
Sniper Updated
Browse files Browse the repository at this point in the history
-Fix get sniper info from pokezz.com (Pull request #3253).
-Add sniper source info in snipeScanEvent.
  • Loading branch information
Ryddag1 committed Aug 9, 2016
1 parent 8a99900 commit 4e83534
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 36 deletions.
2 changes: 1 addition & 1 deletion PoGo.NecroBot.CLI/ConsoleEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private static void HandleEvent(SnipeScanEvent snipeScanEvent, ISession session)
Logger.Write(snipeScanEvent.PokemonId == PokemonId.Missingno
? session.Translation.GetTranslation(TranslationString.SnipeScan,
$"{snipeScanEvent.Bounds.Latitude},{snipeScanEvent.Bounds.Longitude}")
: session.Translation.GetTranslation(TranslationString.SnipeScanEx, session.Translation.GetPokemonTranslation(snipeScanEvent.PokemonId),
: ((snipeScanEvent.Source != null) ? "(" + snipeScanEvent.Source + ") " : null) + session.Translation.GetTranslation(TranslationString.SnipeScanEx, session.Translation.GetPokemonTranslation(snipeScanEvent.PokemonId),
snipeScanEvent.Iv > 0 ? snipeScanEvent.Iv.ToString(CultureInfo.InvariantCulture) : session.Translation.GetTranslation(TranslationString.CommonWordUnknown),
$"{snipeScanEvent.Bounds.Latitude},{snipeScanEvent.Bounds.Longitude}"), LogLevel.Sniper);
}
Expand Down
1 change: 1 addition & 0 deletions PoGo.NecroBot.Logic/Event/SnipeScanEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public class SnipeScanEvent : IEvent
public Location Bounds { get; set; }
public PokemonId PokemonId { get; set; }
public double Iv { get; set; }
public string Source { get; set; }
}
}
13 changes: 13 additions & 0 deletions PoGo.NecroBot.Logic/PoGo.NecroBot.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@
<HintPath>..\packages\CloudFlareUtilities.0.2.1-alpha\lib\portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10\CloudFlareUtilities.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EngineIoClientDotNet, Version=0.9.22.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EngineIoClientDotNet.0.9.22\lib\net45\EngineIoClientDotNet.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="S2Geometry, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>$(SolutionDir)\packages\S2Geometry.1.0.1\lib\portable-net45+wp8+win8\S2Geometry.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SocketIoClientDotNet, Version=0.9.13.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SocketIoClientDotNet.0.9.13\lib\net45\SocketIoClientDotNet.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
Expand All @@ -71,6 +79,7 @@
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -90,6 +99,10 @@
<HintPath>..\packages\Telegram.Bot.10.3.1\lib\net45\Telegram.Bot.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="WebSocket4Net, Version=0.14.1.0, Culture=neutral, PublicKeyToken=eb4e154b696bf72a, processorArchitecture=MSIL">
<HintPath>..\packages\WebSocket4Net.0.14.1\lib\net45\WebSocket4Net.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Common\ApiFailureStrategy.cs" />
Expand Down
79 changes: 44 additions & 35 deletions PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
using POGOProtos.Inventory.Item;
using POGOProtos.Map.Pokemon;
using POGOProtos.Networking.Responses;
using Quobject.SocketIoClientDotNet.Client;
using Newtonsoft.Json.Linq;

#endregion

Expand Down Expand Up @@ -248,14 +250,17 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
{
Bounds = new Location(location.Latitude, location.Longitude),
PokemonId = location.Id,
//Iv = location.IV
Source = "Pokezz.com",
Iv = location.IV
});

if (!await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1,
session, cancellationToken))
return;

await Snipe(session, pokemonIds, location.Latitude, location.Longitude, cancellationToken);
if (!LocsVisited.Contains(new PokemonLocation(location.Latitude, location.Longitude)))
LocsVisited.Add(new PokemonLocation(location.Latitude, location.Longitude));
}
}
}
Expand All @@ -272,6 +277,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
{
Bounds = new Location(location.Latitude, location.Longitude),
PokemonId = location.Id,
Source = "PokeSnipers.com",
//Iv = location.IV
});

Expand All @@ -280,7 +286,8 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
return;

await Snipe(session, pokemonIds, location.Latitude, location.Longitude, cancellationToken);
LocsVisited.Add(new PokemonLocation(location.Latitude, location.Longitude));
if (!LocsVisited.Contains(new PokemonLocation(location.Latitude, location.Longitude)))
LocsVisited.Add(new PokemonLocation(location.Latitude, location.Longitude));
}
}
}
Expand Down Expand Up @@ -509,46 +516,45 @@ private static ScanResult SnipeScanForPokemon(ISession session, Location locatio
return scanResult;
}


private static List<SniperInfo> GetSniperInfoFrom_pokezz(ISession session, List<PokemonId> pokemonIds)
{
var options = new IO.Options();
options.Transports = Quobject.Collections.Immutable.ImmutableList.Create<string>("websocket");

var uri = $"http://pokezz.com/pokemons.json";
var socket = IO.Socket("http://pokezz.com", options);

ScanResult_pokezz scanResult_pokezz;
try
{
var request = WebRequest.CreateHttp(uri);
request.Accept = "application/json";
request.UserAgent =
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36\r\n";
request.Method = "GET";
request.Timeout = 15000;
request.ReadWriteTimeout = 32000;
var hasError = false;

var resp = request.GetResponse();
var reader = new StreamReader(resp.GetResponseStream());
var fullresp = "{\"pokemons\": " + reader.ReadToEnd().Replace(" M", "Male").Replace(" F", "Female").Replace("Farfetch'd", "Farfetchd").Replace("Mr.Maleime", "MrMime") +"}";

scanResult_pokezz = JsonConvert.DeserializeObject<ScanResult_pokezz>(fullresp);
}
catch (Exception ex)
{
// most likely System.IO.IOException
session.EventDispatcher.Send(new ErrorEvent { Message = ex.Message });
scanResult_pokezz = new ScanResult_pokezz
ManualResetEventSlim waitforbroadcast = new ManualResetEventSlim(false);

List<PokemonLocation_pokezz> pokemons = new List<PokemonLocation_pokezz>();

socket.On("pokemons", (msg) => {
JArray data = JArray.FromObject(msg);
foreach (var pokeToken in data.Children())
{
Status = "fail",
pokemons = new List<PokemonLocation_pokezz>()
};
return new List<SniperInfo>();
}
if (scanResult_pokezz.pokemons != null)
{
var temp = pokeToken.ToString().Replace(" M", "Male").Replace(" F", "Female").Replace("Farfetch'd", "Farfetchd").Replace("Mr.Maleime", "MrMime");
var fixedToken = JToken.Parse(temp);
pokemons.Add(fixedToken.ToObject<PokemonLocation_pokezz>());
}
SnipeLocations.RemoveAll(x => DateTime.Now > x.TimeStampAdded.AddMinutes(15));
waitforbroadcast.Set();
});

socket.On(Quobject.SocketIoClientDotNet.Client.Socket.EVENT_ERROR, () => {
hasError = true;
waitforbroadcast.Set();
});

foreach (var pokemon in scanResult_pokezz.pokemons)
socket.On(Quobject.SocketIoClientDotNet.Client.Socket.EVENT_CONNECT_ERROR, () => {
hasError = true;
waitforbroadcast.Set();
});

waitforbroadcast.Wait();
if (!hasError)
{
foreach (var pokemon in pokemons)
{
var SnipInfo = new SniperInfo();
SnipInfo.Id = pokemon.name;
Expand Down Expand Up @@ -576,7 +582,10 @@ private static List<SniperInfo> GetSniperInfoFrom_pokezz(ISession session, List<
new List<SniperInfo>();
return locationsToSnipe;
}
return new List<SniperInfo>();
else
{
return new List<SniperInfo>();
}
}

private static List<SniperInfo> GetSniperInfoFrom_pokesnipers(ISession session, List<PokemonId> pokemonIds)
Expand Down
3 changes: 3 additions & 0 deletions PoGo.NecroBot.Logic/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
<packages>
<package id="C5" version="2.2.5073.27396" targetFramework="net452" />
<package id="CloudFlareUtilities" version="0.2.1-alpha" targetFramework="net452" />
<package id="EngineIoClientDotNet" version="0.9.22" targetFramework="net452" />
<package id="GeoCoordinate" version="1.1.0" targetFramework="net45" />
<package id="Google.Protobuf" version="3.0.0-beta4" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="S2Geometry" version="1.0.1" targetFramework="net452" />
<package id="SocketIoClientDotNet" version="0.9.13" targetFramework="net452" />
<package id="Telegram.Bot" version="10.3.1" targetFramework="net452" />
<package id="WebSocket4Net" version="0.14.1" targetFramework="net452" />
</packages>

0 comments on commit 4e83534

Please sign in to comment.