Skip to content

Commit

Permalink
Fix PokeSpawns => RareSpawns
Browse files Browse the repository at this point in the history
  • Loading branch information
ExcuseMi committed Aug 10, 2016
1 parent e550462 commit bfc25be
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 28 deletions.
6 changes: 3 additions & 3 deletions PogoLocationFeeder/Config/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class GlobalSettings
public static int Port = 16969;
public static bool UsePokeSnipers = true;
public static bool UseTrackemon = false;
public static bool UsePokeSpawns = true;
public static bool UseRareSpawns = true;
public static bool UsePokewatchers = true;
public static bool UsePokezz = true;

Expand Down Expand Up @@ -58,7 +58,7 @@ public static GlobalSettings Load()
settings = new GlobalSettings();
Port = set.Port;
//UseTrackemon = set.UseTrackemon;
UsePokeSpawns = set.UsePokeSpawns;
UseRareSpawns = set.UseRareSpawns;
UsePokeSnipers = set.UsePokeSnipers;
UsePokewatchers = set.UsePokewatchers;
UsePokezz = set.UsePokezz;
Expand Down Expand Up @@ -149,7 +149,7 @@ public class SettingsToSave {
public bool UsePokeSnipers = GlobalSettings.UsePokeSnipers;
//public bool UseTrackemon = GlobalSettings.UseTrackemon;
public bool UsePokezz = GlobalSettings.UsePokezz;
public bool UsePokeSpawns = GlobalSettings.UsePokeSpawns;
public bool UseRareSpawns = GlobalSettings.UseRareSpawns;
public bool UsePokewatchers = GlobalSettings.UsePokewatchers;
public string PokeSnipers2Exe = GlobalSettings.PokeSnipers2Exe;
public int RemoveAfter = GlobalSettings.RemoveAfter;
Expand Down
18 changes: 13 additions & 5 deletions PogoLocationFeeder/PogoLocationFeeder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<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="Google.Protobuf, Version=3.0.0.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL">
<HintPath>..\packages\Google.Protobuf.3.0.0-beta4\lib\net45\Google.Protobuf.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -87,6 +91,10 @@
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
<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.Core" />
<Reference Include="System.Net" />
Expand All @@ -111,14 +119,15 @@
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.Caching" />
<Reference Include="System.Web" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WebSocket4Net, Version=0.14.0.0, Culture=neutral, PublicKeyToken=eb4e154b696bf72a, processorArchitecture=MSIL">
<HintPath>..\packages\WebSocket4Net.0.14\lib\net45\WebSocket4Net.dll</HintPath>
<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>
<Reference Include="WindowsBase" />
Expand All @@ -141,13 +150,12 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repository\PokeSniperRarePokemonRepository.cs" />
<Compile Include="Repository\PokeSpawnsRarePokemonRepository.cs" />
<Compile Include="Repository\RareSpawnsRarePokemonRepository.cs" />
<Compile Include="Repository\PokezzRarePokemonRepository.cs" />
<Compile Include="Repository\PokewatchersRarePokemonRepository.cs" />
<Compile Include="Repository\IRarePokemonRepository.cs" />
<Compile Include="Repository\RarePokemonRepositoryFactory.cs" />
<Compile Include="Repository\RarePokemonsFactory.cs" />

<Compile Include="Repository\RarePokemonsFactory.cs" />
<Compile Include="Repository\TrackermonRarePokemonRepository.cs" />
<Compile Include="SniperInfo.cs" />
<Compile Include="Writers\ClientWriter.cs" />
Expand Down
4 changes: 2 additions & 2 deletions PogoLocationFeeder/Repository/RarePokemonRepositoryFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public static List<IRarePokemonRepository> CreateRepositories(GlobalSettings glo
{
rarePokemonRepositories.Add(new PokezzRarePokemonRepository());
}
if (GlobalSettings.UsePokeSpawns)
if (GlobalSettings.UseRareSpawns)
{
rarePokemonRepositories.Add(new PokeSpawnsRarePokemonRepository());
rarePokemonRepositories.Add(new RareSpawnsRarePokemonRepository());
}
if (GlobalSettings.UsePokewatchers)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@

namespace PogoLocationFeeder.Repository
{
public class PokeSpawnsRarePokemonRepository : IRarePokemonRepository
public class RareSpawnsRarePokemonRepository : IRarePokemonRepository
{
//private const int timeout = 20000;

private const string URL = "ws://spawns.sebastienvercammen.be:49006/socket.io/?EIO=3&transport=websocket";
private const string Channel = "PokeSpawns";
private const string URL = "ws://188.165.224.208:49001/socket.io/?EIO=3&transport=websocket";
private WebSocket _client;
private ConcurrentQueue<SniperInfo> _snipersInfos = new ConcurrentQueue<SniperInfo>();
private bool _started;

public PokeSpawnsRarePokemonRepository()
public RareSpawnsRarePokemonRepository()
{
}

Expand All @@ -32,7 +31,7 @@ public List<SniperInfo> FindAll()
{
Task.Run(() => StartClient());
_started = true;
Thread.Sleep(10*1000);
Thread.Sleep(1000);
}
var newSniperInfos = new List<SniperInfo>();
lock (_snipersInfos)
Expand All @@ -53,37 +52,42 @@ public string GetChannel()
return Channel;
}

private async Task StartClient()
public async Task StartClient()
{
try
{
_client = new WebSocket(URL, "basic", WebSocketVersion.Rfc6455);
_client = new WebSocket(URL, "", WebSocketVersion.None);
_client.Closed += Client_Closed;
_client.MessageReceived += Client_MessageReceived;
_client.Error += Client_Error;

_client.Open();
}
catch (Exception e)
{
Log.Warn("Received error from PokeSpawns. More info the logs");
Log.Debug("Received error from PokeSpawns: ", e);
try
{
_client.Close();
_client.Dispose();
_client = null;
} catch(Exception) { }
_started = false;
CloseClient();
}
}

private void Client_Closed(object sender, EventArgs e)
{
_started = false;
CloseClient();
}

private void Client_Error(object sender, EventArgs e)
{
CloseClient();
}

private void Client_MessageReceived(object sender, MessageReceivedEventArgs e)
{
var message = e.Message;
if (message == "40")
{
_client.Send("40/pokes");
}
//Log.Debug("Pokezz message: " + message);
var match = Regex.Match(message, @"(1?\d+)\[""helo"",(2?.*)\]");
if (match.Success)
Expand Down Expand Up @@ -149,6 +153,22 @@ private SniperInfo Map(PokeSpawnsPokemon result)
sniperInfo.Longitude = result.lon;
return sniperInfo;
}

private void CloseClient()
{
_started = false;
try
{
try
{
_client.Close();
}
catch (Exception) { }
_client.Dispose();
_client = null;
}
catch (Exception) { }
}
}

internal class PokeSpawnsPokemon
Expand All @@ -162,4 +182,4 @@ internal class PokeSpawnsPokemon
[JsonProperty("lon")]
public double lon { get; set; }
}
}
}
4 changes: 3 additions & 1 deletion PogoLocationFeeder/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
<packages>
<package id="CloudFlareUtilities" version="0.2.1-alpha" targetFramework="net452" />
<package id="Costura.Fody" version="1.3.3.0" targetFramework="net452" developmentDependency="true" />
<package id="EngineIoClientDotNet" version="0.9.22" targetFramework="net452" />
<package id="Fody" version="1.29.4" targetFramework="net452" developmentDependency="true" />
<package id="Google.Protobuf" version="3.0.0-beta4" targetFramework="net452" />
<package id="log4net" version="2.0.5" targetFramework="net452" />
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net452" />
<package id="Nito.AsyncEx" version="3.0.1" targetFramework="net452" />
<package id="POGOProtos" version="1.4.0" targetFramework="net452" />
<package id="SocketIoClientDotNet" version="0.9.13" targetFramework="net452" />
<package id="System.Net.Http" version="2.0.20126.16343" targetFramework="net452" />
<package id="System.Net.Http.Formatting.Extension" version="5.2.3.0" targetFramework="net452" />
<package id="WebSocket4Net" version="0.14" targetFramework="net452" />
<package id="WebSocket4Net" version="0.14.1" targetFramework="net452" />
</packages>
14 changes: 14 additions & 0 deletions PogoLocationFeederTests/PogoLocationFeederTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<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="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
Expand All @@ -44,7 +48,17 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\POGOProtos.1.4.0\lib\net45\POGOProtos.dll</HintPath>
</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.Net.Http" />
<Reference Include="System.Web" />
<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>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading;
using System.Threading.Tasks;

namespace PogoLocationFeeder.Repository.Tests
{
[TestClass()]
public class RareSpawnsRarePokemonRepositoryTests
{

[TestMethod()]
[Ignore]
public void TestRareSpawns()
{
var pokeSpawnsRarePokemonRepository = new RareSpawnsRarePokemonRepository();
Task.Run(() => pokeSpawnsRarePokemonRepository.StartClient());
Thread.Sleep(120* 1000);
}
}
}
4 changes: 3 additions & 1 deletion PogoLocationFeederTests/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<packages>
<package id="EngineIoClientDotNet" version="0.9.22" targetFramework="net461" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
<package id="SocketIoClientDotNet" version="0.9.13" targetFramework="net461" />
<package id="WebSocket4Net" version="0.14.1" targetFramework="net461" />
</packages>

0 comments on commit bfc25be

Please sign in to comment.