Skip to content

Commit

Permalink
Merge pull request Necrobot-Private#86 from Necrobot-Private/master
Browse files Browse the repository at this point in the history
v1.0.0.97
  • Loading branch information
Furtif committed Feb 9, 2017
2 parents cab48c6 + e9f34a2 commit ddb3f32
Show file tree
Hide file tree
Showing 16 changed files with 525 additions and 208 deletions.
63 changes: 45 additions & 18 deletions PoGo.NecroBot.CLI/BotDataSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ private static string Serialize(dynamic evt)
return json;
}

private static int retries = 0;
static List<EncounteredEvent> processing = new List<EncounteredEvent>();

public static String SHA256Hash(String value)
Expand All @@ -102,22 +101,33 @@ public static String SHA256Hash(String value)

public static async Task Start(Session session, CancellationToken cancellationToken)
{

await Task.Delay(30000, cancellationToken); //delay running 30s

ServicePointManager.Expect100Continue = false;

cancellationToken.ThrowIfCancellationRequested();

var socketURL = session.LogicSettings.DataSharingDataUrl;

if (!string.IsNullOrEmpty(session.LogicSettings.SnipeDataAccessKey))
while(true)
{
var socketURL = servers.Dequeue();
Logger.Write($"Connecting to {socketURL}....");
await ConnectToServer(session, socketURL);
servers.Enqueue(socketURL);
}

}
public static async Task ConnectToServer(ISession session, string socketURL)
{
if (!string.IsNullOrEmpty(session.LogicSettings.DataSharingConfig.SnipeDataAccessKey))
{
socketURL += "&access_key=" + session.LogicSettings.SnipeDataAccessKey;
socketURL += "&access_key=" + session.LogicSettings.DataSharingConfig.SnipeDataAccessKey;
}

int retries = 0;
using (var ws = new WebSocket(socketURL))
{
ws.Log.Level = LogLevel.Fatal;
ws.Log.Level = LogLevel.Fatal; ;
ws.Log.Output = (logData, message) =>
{
//silenly, no log exception message to screen that scare people :)
Expand All @@ -128,17 +138,20 @@ public static async Task Start(Session session, CancellationToken cancellationTo
ws.Connect();
while (true)
{
cancellationToken.ThrowIfCancellationRequested();
try
{
if (retries == 5)
if (retries == 3)
{
//failed to make connection to server times contiuing, temporary stop for 10 mins.
session.EventDispatcher.Send(new WarnEvent()
{
Message = "Couldn't establish the connection to necro socket server, Bot will re-connect after 10 mins"
Message = $"Couldn't establish the connection to necro socket server : {socketURL}"
});
await Task.Delay(1 * 60 * 1000, cancellationToken);
if(session.LogicSettings.DataSharingConfig.EnableFailoverDataServers && servers.Count > 1)
{
break;
}
await Task.Delay(1 * 60 * 1000);
retries = 0;
}

Expand Down Expand Up @@ -170,7 +183,7 @@ public static async Task Start(Session session, CancellationToken cancellationTo
var actualMessage = JsonConvert.SerializeObject(message);
ws.Send($"42[\"pokemons-update\",{actualMessage}]");
}
await Task.Delay(POLLING_INTERVAL, cancellationToken);
await Task.Delay(POLLING_INTERVAL);
}

if (processing.Count > 0 && ws.IsAlive)
Expand All @@ -181,7 +194,7 @@ public static async Task Start(Session session, CancellationToken cancellationTo
ws.Send($"42[\"pokemons-secure\",{actualMessage}]");
}

await Task.Delay(POLLING_INTERVAL, cancellationToken);
await Task.Delay(POLLING_INTERVAL);
ws.Ping();
}
}
Expand All @@ -198,8 +211,7 @@ public static async Task Start(Session session, CancellationToken cancellationTo
finally
{
//everytime disconnected with server bot wil reconnect after 15 sec
await Task.Delay(POLLING_INTERVAL, cancellationToken);

await Task.Delay(POLLING_INTERVAL);
}
}
}
Expand Down Expand Up @@ -293,7 +305,7 @@ private static void OnPokemonData(ISession session, string message)
}

session.EventDispatcher.Send(data);
if (session.LogicSettings.AllowAutoSnipe)
if (session.LogicSettings.DataSharingConfig.AutoSnipe)
{
var move1 = PokemonMove.MoveUnset;
var move2 = PokemonMove.MoveUnset;
Expand Down Expand Up @@ -334,9 +346,9 @@ private static void OnSnipePokemon(ISession session, string message)
var data = JsonConvert.DeserializeObject<EncounteredEvent>(match.Groups[1].Value);

//not your snipe item, return need more encrypt here and configuration to allow catch others item
if (string.IsNullOrEmpty(session.LogicSettings.DataSharingIdentifiation) ||
if (string.IsNullOrEmpty(session.LogicSettings.DataSharingConfig.DataServiceIdentification) ||
string.IsNullOrEmpty(data.RecieverId) ||
data.RecieverId.ToLower() != session.LogicSettings.DataSharingIdentifiation.ToLower()) return;
data.RecieverId.ToLower() != session.LogicSettings.DataSharingConfig.DataServiceIdentification.ToLower()) return;

var move1 = PokemonMove.Absorb;
var move2 = PokemonMove.Absorb;
Expand Down Expand Up @@ -369,10 +381,25 @@ private static void OnSnipePokemon(ISession session, string message)
}, true);
}
}

private static Queue<string> servers = new Queue<string>();
internal static Task StartAsync(Session session,
CancellationToken cancellationToken = default(CancellationToken))
{
var config = session.LogicSettings.DataSharingConfig;

if (config.EnableSyncData)
{
servers.Enqueue(config.DataRecieverURL);

if(config.EnableFailoverDataServers)
{
foreach (var item in config.FailoverDataServers.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
servers.Enqueue(item);
}
}
}

return Task.Run(() => Start(session, cancellationToken), cancellationToken);
}

Expand Down
2 changes: 1 addition & 1 deletion PoGo.NecroBot.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public static void RunBotWithParameters(Action<ISession, StatisticsAggregator> o
#pragma warning restore 4014
}

if (_session.LogicSettings.DataSharingEnable)
if (_session.LogicSettings.DataSharingConfig.EnableSyncData)
{
BotDataSocketClient.StartAsync(_session);
_session.EventDispatcher.EventReceived += evt => BotDataSocketClient.Listen(evt, _session);
Expand Down
4 changes: 2 additions & 2 deletions PoGo.NecroBot.CLI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// [assembly: AssemblyVersion1("0.9.9.5")]


[assembly: AssemblyVersion("1.0.0.96")]
[assembly: AssemblyVersion("1.0.0.97")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("v1.0.0.96")]
[assembly: AssemblyInformationalVersion("v1.0.0.97")]

6 changes: 3 additions & 3 deletions PoGo.NecroBot.GUI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.0.96")]
// [assembly: AssemblyVersion("1.0.0.97")]


[assembly: AssemblyVersion("1.0.0.96")]
[assembly: AssemblyVersion("1.0.0.97")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("v1.0.0.96")]
[assembly: AssemblyInformationalVersion("v1.0.0.97")]
18 changes: 7 additions & 11 deletions PoGo.NecroBot.Logic/Captcha/Anti-Captcha/AntiCaptchaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ namespace PoGo.NecroBot.Logic.Captcha.Anti_Captcha
{
public class AntiCaptchaClient
{

private const string Host = "api.anti-captcha.com";
private const string ClientKey = "xxxxxxx";
private string ClientKey = "xxxxxxx";
private const string ProxyHost = "xx.xx.xx.xx";
private const int ProxyPort = 8282;
private const string ProxyLogin = "";
Expand All @@ -20,29 +21,24 @@ public class AntiCaptchaClient
public static async Task<string> SolveCaptcha(string captchaURL, string apiKey, string googleSiteKey,
string proxyHost, int proxyPort, string proxyAccount = "", string proxyPassword = "")
{
var task1 = AnticaptchaApiWrapper.CreateNoCaptchaTask(
var task1 = AnticaptchaApiWrapper.CreateNoCaptchaTaskProxyless(
Host,
apiKey,
captchaURL, //target website address
googleSiteKey, //target website Recaptcha key
AnticaptchaApiWrapper.ProxyType.http,
proxyHost, //ipv4 or ipv6 proxy address
proxyPort, //proxy port
"", //proxy login
"", //proxy password
googleSiteKey,
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36"
);

return await ProcessTask(task1);
return await ProcessTask(task1, apiKey);
}

private static async Task<string> ProcessTask(AnticaptchaTask task)
private static async Task<string> ProcessTask(AnticaptchaTask task, string apikey)
{
AnticaptchaResult response;

do
{
response = AnticaptchaApiWrapper.GetTaskResult(Host, ClientKey, task);
response = AnticaptchaApiWrapper.GetTaskResult(Host, apikey, task);

if (response.GetStatus().Equals(AnticaptchaResult.Status.ready))
{
Expand Down
40 changes: 20 additions & 20 deletions PoGo.NecroBot.Logic/Captcha/CaptchaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ public static async Task<bool> SolveCaptcha(ISession session, string captchaUrl)
}
}

//Anti captcha - Havent test it, temporary comment until has key to test
//if (!resolved && session.LogicSettings.CaptchaConfig.EnableAntiCaptcha && !string.IsNullOrEmpty(session.LogicSettings.CaptchaConfig.AntiCaptchaAPIKey))
//{
// if (needGetNewCaptcha)
// {
// captchaUrl = await GetNewCaptchaURL(session);
// }
// if (string.IsNullOrEmpty(captchaUrl)) return true;

// Logger.Write("Auto resolving captcha by using anti captcha service");
// captchaResponse = await GetCaptchaResposeByAntiCaptcha(session, captchaUrl);
// needGetNewCaptcha = true;
// if (!string.IsNullOrEmpty(captchaResponse))
// {
// resolved = await Resolve(session, captchaResponse);
// }

//}
//Anti captcha -Havent test it, temporary comment until has key to test
if (!resolved && session.LogicSettings.CaptchaConfig.EnableAntiCaptcha && !string.IsNullOrEmpty(session.LogicSettings.CaptchaConfig.AntiCaptchaAPIKey))
{
if (needGetNewCaptcha)
{
captchaUrl = await GetNewCaptchaURL(session);
}
if (string.IsNullOrEmpty(captchaUrl)) return true;

Logger.Write("Auto resolving captcha by using anti captcha service");
captchaResponse = await GetCaptchaResposeByAntiCaptcha(session, captchaUrl);
needGetNewCaptcha = true;
if (!string.IsNullOrEmpty(captchaResponse))
{
resolved = await Resolve(session, captchaResponse);
}

}

//use 2 captcha
if (!resolved && session.LogicSettings.CaptchaConfig.Enable2Captcha &&
Expand Down Expand Up @@ -179,15 +179,15 @@ private static async Task<string> GetCaptchaResposeByAntiCaptcha(ISession sessio

{
result = await AntiCaptchaClient.SolveCaptcha(captchaUrl,
POKEMON_GO_GOOGLE_KEY,
session.LogicSettings.CaptchaConfig.AntiCaptchaAPIKey,
POKEMON_GO_GOOGLE_KEY,
session.LogicSettings.CaptchaConfig.ProxyHost,
session.LogicSettings.CaptchaConfig.ProxyPort);
solved = !string.IsNullOrEmpty(result);
}
if (solved)
{
Logger.Write("Captcha has been resolved automatically by 2Captcha ");
Logger.Write("Captcha has been resolved automatically by Anti-Captcha ");
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,7 @@ public interface ILogicSettings
int RenamePokemonActionDelay { get; }

GymConfig GymConfig { get; }
string DataSharingIdentifiation { get; }
bool DataSharingEnable { get; }
string DataSharingDataUrl { get; }
string SnipeDataAccessKey { get; }
bool AllowAutoSnipe { get; }
DataSharingConfig DataSharingConfig { get; }
MultipleBotConfig MultipleBotConfig { get; }
List<AuthConfig> Bots { get; }
bool AllowMultipleBot { get; }
Expand Down
9 changes: 4 additions & 5 deletions PoGo.NecroBot.Logic/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public IEnumerable<AppliedItems> GetAppliedItems()
if (familyCandy != null)
{
// Calculate the number of evolutions possible (taking into account +1 candy for evolve and +1 candy for transfer)
var evolutionCalcs = CalcuatePokemonEvolution(canBeRemoved, familyCandy.Candy_, settings.CandyToEvolve);
var evolutionCalcs = CalculatePokemonEvolution(canBeRemoved, familyCandy.Candy_, settings.CandyToEvolve, 1); // 1 for candy gain after evolution

// Subtract the number of evolutions possible from the number that can be transferred.
canBeRemoved -= evolutionCalcs.Evolves;
Expand Down Expand Up @@ -278,10 +278,9 @@ public class EvolutionCalculations

// Calculates the number of pokemon evolutions possible given number of pokemon, candies, and candies to evolve.
// Implementation is taken from https://www.pidgeycalc.com and double-checked with calculator at https://pokeassistant.com/main/pidgeyspam
public EvolutionCalculations CalcuatePokemonEvolution(int pokemonLeft, int candiesLeft, int candiesToEvolve)
public EvolutionCalculations CalculatePokemonEvolution(int pokemonLeft, int candiesLeft, int candiesToEvolve, int candiesGainedOnEvolve)
{
int transferCandiesGained = 1;
int candiesGainedOnEvolve = candiesToEvolve;
int evolveCount = 0;
int transferCount = 0;

Expand Down Expand Up @@ -692,7 +691,7 @@ public IEnumerable<PokemonData> GetPokemonToEvolve(IEnumerable<PokemonId> filter
int pokemonLeft = group.Count();

// Calculate the number of evolutions possible (taking into account +1 candy for evolve and +1 candy for transfer)
EvolutionCalculations evolutionInfo = CalcuatePokemonEvolution(pokemonLeft, candiesLeft, settings.CandyToEvolve);
EvolutionCalculations evolutionInfo = CalculatePokemonEvolution(pokemonLeft, candiesLeft, settings.CandyToEvolve, 1);

if (evolutionInfo.Evolves > 0)
{
Expand Down Expand Up @@ -831,4 +830,4 @@ public async Task<UpgradePokemonResponse> UpgradePokemon(ulong pokemonid)
return await _client.Inventory.UpgradePokemon(pokemonid);
}
}
}
}
1 change: 1 addition & 0 deletions PoGo.NecroBot.Logic/Model/Settings/CaptchaConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@ public CaptchaConfig() : base()
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 4)]
[NecrobotConfig(Position = 15, Description = "Timeout for auto captcha solving")]
public int AutoCaptchaTimeout { get; set; }

}
}
11 changes: 11 additions & 0 deletions PoGo.NecroBot.Logic/Model/Settings/DataSharingConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,16 @@ public bool EnableSyncData
[DefaultValue("")]
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 1)]
public string SnipeDataAccessKey { get; set; }

[NecrobotConfig(Description = "Enable failover data servers", Position = 5)]
[DefaultValue(true)]
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 1)]
public bool EnableFailoverDataServers { get; set; }

[NecrobotConfig(Description = "List of servers that bot will connect when primary server down or can't connect", Position = 6)]
[DefaultValue("ws://s1.mypogosnipers.com/socket.io/?EIO=3&transport=websocket;ws://s2.mypogosnipers.com/socket.io/?EIO=3&transport=websocket")]
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 1)]
public string FailoverDataServers { get; set; }

}
}
8 changes: 2 additions & 6 deletions PoGo.NecroBot.Logic/Model/Settings/LogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,9 @@ public float GenRandom(float val)
public bool HumanWalkingSnipeAllowTransferWhileWalking => _settings.HumanWalkSnipeConfig.AllowTransferWhileWalking;
public GymConfig GymConfig => _settings.GymConfig;

public bool DataSharingEnable => _settings.DataSharingConfig.EnableSyncData;
public string DataSharingIdentifiation => _settings.DataSharingConfig.DataServiceIdentification;
public bool AllowAutoSnipe => _settings.DataSharingConfig.AutoSnipe;

public string SnipeDataAccessKey => _settings.DataSharingConfig.SnipeDataAccessKey;
public DataSharingConfig DataSharingConfig => _settings.DataSharingConfig;
public int SnipePauseOnOutOfBallTime => GenRandom(_settings.SnipeConfig.SnipePauseOnOutOfBallTime);
public string DataSharingDataUrl => _settings.DataSharingConfig.DataRecieverURL;

public bool UseTransferFilterToCatch => _settings.CustomCatchConfig.UseTransferFilterToCatch;
public MultipleBotConfig MultipleBotConfig => _settings.MultipleBotConfig;
public List<AuthConfig> Bots => _settings.Auth.Bots;
Expand Down
4 changes: 2 additions & 2 deletions PoGo.NecroBot.Logic/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
// [assembly: AssemblyVersion1("0.9.9.5")]
//

[assembly: AssemblyVersion("1.0.0.96")]
[assembly: AssemblyVersion("1.0.0.97")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("v1.0.0.96")]
[assembly: AssemblyInformationalVersion("v1.0.0.97")]

0 comments on commit ddb3f32

Please sign in to comment.