Skip to content

Commit

Permalink
Updated to newest API + PoGoProtos 1.5.0. (MobBotTeam#552)
Browse files Browse the repository at this point in the history
Lets do awesome shit
  • Loading branch information
DurtyFree authored Aug 3, 2016
1 parent 65bb1af commit 52e7c7b
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 124 deletions.
14 changes: 4 additions & 10 deletions PoGo.PokeMobBot.CLI/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

<configuration>
<configSections>
<sectionGroup name="userSettings"
type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="PoGo.PokeMobBot.CLI.UserSettings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="PoGo.PokeMobBot.CLI.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="PoGo.PokeMobBot.CLI.UserSettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="PoGo.PokeMobBot.CLI.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
Expand All @@ -32,7 +27,6 @@
</assemblyBinding>
</runtime>
<connectionStrings>
<add name="Pogo"
connectionString="DatasetId = YOUR_DATASET_ID; CertificateFilePath = C:\Path\To\Your\Certificate\File-privatekey.p12; ServiceAccountId = [email protected]; CertificatePassword = notasecret" />
<add name="Pogo" connectionString="DatasetId = YOUR_DATASET_ID; CertificateFilePath = C:\Path\To\Your\Certificate\File-privatekey.p12; ServiceAccountId = [email protected]; CertificatePassword = notasecret" />
</connectionStrings>
</configuration>
8 changes: 5 additions & 3 deletions PoGo.PokeMobBot.CLI/PoGo.PokeMobBot.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="POGOProtos, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\POGOProtos.1.4.0\lib\net45\POGOProtos.dll</HintPath>
<Reference Include="POGOProtos, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\POGOProtos.1.5.0\lib\net45\POGOProtos.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SuperSocket.Common, Version=1.6.6.1, Culture=neutral, PublicKeyToken=6c80000676988ebb, processorArchitecture=MSIL">
Expand Down Expand Up @@ -130,7 +130,9 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="Config\log4net.config" />
<None Include="Config\log4net.unix.config" />
<None Include="cert.pfx">
Expand Down
3 changes: 1 addition & 2 deletions PoGo.PokeMobBot.CLI/packages.config
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>

<packages>
<package id="Costura.Fody" version="1.3.3.0" targetFramework="net45" developmentDependency="true" />
<package id="Fody" version="1.29.4" targetFramework="net45" developmentDependency="true" />
<package id="Google.Protobuf" version="3.0.0-beta4" targetFramework="net45" />
<package id="log4net" version="2.0.5" targetFramework="net45" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="POGOProtos" version="1.4.0" targetFramework="net45" />
<package id="POGOProtos" version="1.5.0" targetFramework="net45" />
<package id="SuperSocket" version="1.6.6.1" targetFramework="net45" />
<package id="SuperSocket.Engine" version="1.6.6.1" targetFramework="net45" />
<package id="SuperSocket.WebSocket" version="1.6.6.1" targetFramework="net45" />
Expand Down
57 changes: 19 additions & 38 deletions PoGo.PokeMobBot.Logic/Common/ApiFailureStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
using System.Threading.Tasks;
using PoGo.PokeMobBot.Logic.Event;
using PoGo.PokeMobBot.Logic.State;
using PokemonGo.RocketAPI.Common;
using PokemonGo.RocketAPI.Enums;
using PokemonGo.RocketAPI.Exceptions;
using PokemonGo.RocketAPI.Extensions;
using POGOProtos.Networking.Envelopes;

#endregion

Expand All @@ -23,7 +22,23 @@ public ApiFailureStrategy(ISession session)
_session = session;
}

public async Task<ApiOperation> HandleApiFailure()
private async void DoLogin()
{
try
{
await _session.Client.Login.DoLogin();
}
catch (AggregateException ae)
{
throw ae.Flatten().InnerException;
}
catch (Exception ex)
{
throw ex.InnerException;
}
}

public async Task<ApiOperation> HandleApiFailure(RequestEnvelope request, ResponseEnvelope response)
{
if (_retryCount == 11)
return ApiOperation.Abort;
Expand Down Expand Up @@ -74,43 +89,9 @@ public async Task<ApiOperation> HandleApiFailure()
return ApiOperation.Retry;
}

public void HandleApiSuccess()
public void HandleApiSuccess(RequestEnvelope request, ResponseEnvelope response)
{
_retryCount = 0;
}

private async void DoLogin()
{
switch (_session.Settings.AuthType)
{
case AuthType.Ptc:
try
{
await
_session.Client.Login.DoPtcLogin(_session.Settings.PtcUsername,
_session.Settings.PtcPassword);
}
catch (AggregateException ae)
{
throw ae.Flatten().InnerException;
}
catch (Exception ex)
{
throw ex.InnerException;
}
break;
case AuthType.Google:
await
_session.Client.Login.DoGoogleLogin(_session.Settings.GoogleUsername,
_session.Settings.GooglePassword);
break;
default:
_session.EventDispatcher.Send(new ErrorEvent
{
Message = _session.Translation.GetTranslation(TranslationString.WrongAuthType)
});
break;
}
}
}
}
2 changes: 1 addition & 1 deletion PoGo.PokeMobBot.Logic/Common/Translations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ public static Translation Load(ILogicSettings logicSettings)
.ToList()
.ForEach(translations._pokemons.Add);
}
catch (Exception e)
catch (Exception)
{
translations = new Translation();
translations.Save(Path.Combine(translationPath, "translation.en.json"));
Expand Down
4 changes: 2 additions & 2 deletions PoGo.PokeMobBot.Logic/PoGo.PokeMobBot.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="POGOProtos, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\POGOProtos.1.4.0\lib\net45\POGOProtos.dll</HintPath>
<Reference Include="POGOProtos, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\POGOProtos.1.5.0\lib\net45\POGOProtos.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
27 changes: 1 addition & 26 deletions PoGo.PokeMobBot.Logic/State/LoginState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,7 @@ public async Task<IState> Execute(ISession session, CancellationToken cancellati

try
{
switch (session.Settings.AuthType)
{
case AuthType.Ptc:
try
{
await
session.Client.Login.DoPtcLogin(session.Settings.PtcUsername,
session.Settings.PtcPassword);
}
catch (AggregateException ae)
{
throw ae.Flatten().InnerException;
}
break;
case AuthType.Google:
await
session.Client.Login.DoGoogleLogin(session.Settings.GoogleUsername,
session.Settings.GooglePassword);
break;
default:
session.EventDispatcher.Send(new ErrorEvent
{
Message = session.Translation.GetTranslation(TranslationString.WrongAuthType)
});
return null;
}
await session.Client.Login.DoLogin();
}
catch (PtcOfflineException)
{
Expand Down
5 changes: 4 additions & 1 deletion PoGo.PokeMobBot.Logic/State/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public Session(ISettings settings, ILogicSettings logicSettings)
{
Settings = settings;
LogicSettings = logicSettings;
ApiFailureStrategy = new ApiFailureStrategy(this);
EventDispatcher = new EventDispatcher();
Translation = Common.Translation.Load(logicSettings);
Reset(settings, LogicSettings);
Expand All @@ -48,9 +49,11 @@ public Session(ISettings settings, ILogicSettings logicSettings)

public IEventDispatcher EventDispatcher { get; }

public ApiFailureStrategy ApiFailureStrategy { get; set; }

public void Reset(ISettings settings, ILogicSettings logicSettings)
{
Client = new Client(Settings) {AuthType = settings.AuthType};
Client = new Client(Settings, ApiFailureStrategy);
// ferox wants us to set this manually
Inventory = new Inventory(Client, logicSettings);
Navigation = new Navigation(Client);
Expand Down
2 changes: 1 addition & 1 deletion PoGo.PokeMobBot.Logic/Tasks/CatchNearbyPokemonsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static async Task<IOrderedEnumerable<MapPokemon>> GetNearbyPokemons(ISes
{
var mapObjects = await session.Client.Map.GetMapObjects();

var pokemons = mapObjects.MapCells.SelectMany(i => i.CatchablePokemons)
var pokemons = mapObjects.Item1.MapCells.SelectMany(i => i.CatchablePokemons)
.OrderBy(
i =>
LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
Expand Down
2 changes: 1 addition & 1 deletion PoGo.PokeMobBot.Logic/Tasks/FarmPokestopsGPXTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private static async Task<List<FortData>> GetPokeStops(ISession session)
var mapObjects = await session.Client.Map.GetMapObjects();

// Wasn't sure how to make this pretty. Edit as needed.
var pokeStops = mapObjects.MapCells.SelectMany(i => i.Forts)
var pokeStops = mapObjects.Item1.MapCells.SelectMany(i => i.Forts)
.Where(
i =>
i.Type == FortType.Checkpoint &&
Expand Down
2 changes: 1 addition & 1 deletion PoGo.PokeMobBot.Logic/Tasks/FarmPokestopsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ private static async Task<List<FortData>> GetPokeStops(ISession session)
{
var mapObjects = await session.Client.Map.GetMapObjects();

var pokeStops = mapObjects.MapCells.SelectMany(i => i.Forts);
var pokeStops = mapObjects.Item1.MapCells.SelectMany(i => i.Forts);

session.EventDispatcher.Send(new PokeStopListEvent { Forts = pokeStops.ToList() });

Expand Down
36 changes: 3 additions & 33 deletions PoGo.PokeMobBot.Logic/Tasks/Login.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,11 @@ public void DoLogin()
{
try
{
if (_session.Client.AuthType == AuthType.Ptc)
{
try
{
_session.Client.Login.DoPtcLogin(_session.Settings.PtcUsername, _session.Settings.PtcPassword)
.Wait();
}
catch (AggregateException ae)
{
throw ae.Flatten().InnerException;
}
}
else
{
_session.Client.Login.DoGoogleLogin(_session.Settings.GoogleUsername,
_session.Settings.GooglePassword).Wait();
}
_session.Client.Login.DoLogin().Wait();
}
catch (PtcOfflineException)
catch (AggregateException ae)
{
_session.EventDispatcher.Send(new ErrorEvent
{
Message = _session.Translation.GetTranslation(TranslationString.PtcOffline)
});
_session.EventDispatcher.Send(new NoticeEvent
{
Message = _session.Translation.GetTranslation(TranslationString.TryingAgainIn, 20)
});
}
catch (AccountNotVerifiedException)
{
_session.EventDispatcher.Send(new ErrorEvent
{
Message = _session.Translation.GetTranslation(TranslationString.AccountNotVerified)
});
throw ae.Flatten().InnerException;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion PoGo.PokeMobBot.Logic/Tasks/SnipePokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private static async Task<bool> Snipe(ISession session, IEnumerable<PokemonId> p

var mapObjects = session.Client.Map.GetMapObjects().Result;
var catchablePokemon =
mapObjects.MapCells.SelectMany(q => q.CatchablePokemons)
mapObjects.Item1.MapCells.SelectMany(q => q.CatchablePokemons)
.Where(q => pokemonIds.Contains(q.PokemonId))
.ToList();

Expand Down
2 changes: 1 addition & 1 deletion PoGo.PokeMobBot.Logic/Tasks/UseNearbyPokestopsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static async Task<List<FortData>> GetPokeStops(ISession session)
var mapObjects = await session.Client.Map.GetMapObjects();

// Wasn't sure how to make this pretty. Edit as needed.
var pokeStops = mapObjects.MapCells.SelectMany(i => i.Forts)
var pokeStops = mapObjects.Item1.MapCells.SelectMany(i => i.Forts)
.Where(
i =>
i.Type == FortType.Checkpoint &&
Expand Down
3 changes: 1 addition & 2 deletions PoGo.PokeMobBot.Logic/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<packages>
<package id="GeoCoordinate" version="1.1.0" targetFramework="net45" />
<package id="Google.Protobuf" version="3.0.0-beta4" targetFramework="net45" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="POGOProtos" version="1.4.0" targetFramework="net45" />
<package id="POGOProtos" version="1.5.0" targetFramework="net45" />
</packages>
2 changes: 1 addition & 1 deletion Pokemon-Go-Rocket-API

0 comments on commit 52e7c7b

Please sign in to comment.