public async Task Run(string[] args) { dynamic tmppoke; if (config.verifypokemon) { Pokemons = new List <PokemonInfoFull>(); tmppoke = new PokemonInfoFull(); } else { Pokemons = new List <PokemonInfo>(); tmppoke = new PokemonInfo(); } tmppoke.PokemonName = "Bellsprout"; tmppoke.Latitude = 23.906291124969709; tmppoke.Longtitude = 120.59261531771575; if (config.verifypokemon) { tmppoke.EncounterId = 13139724800732585298; tmppoke.SpawnpointId = "3469343f3d9"; tmppoke.IV = 10; } tmppoke.expirationdt = DateTime.Now.AddMinutes(config.minutestoexpire); tmppoke.expiration = Convert.ToInt64((tmppoke.expirationdt - DateTime.Parse("1/1/1970")).TotalMilliseconds); AddPokemon(tmppoke); WebServerWrapper.Port = config.webserverport; WebServerWrapper.NameOrIp = config.webserveraddress; new WebServerWrapper().RunServer(args).GetAwaiter().GetResult(); await Task.Delay(-1); //return 0; }
//private static int UpdateCounter=0; public PokemonInfoFull VerifyPokemon(PokemonInfoFull Pokemonl, Config configl) { pokemon = Pokemonl; config = configl; Run().GetAwaiter().GetResult(); return(pokemon); }
public static void AddPokemon(dynamic Pokemon) { string a = JsonConvert.SerializeObject(Pokemons, Formatting.Indented); //Console.WriteLine("Serving pokemons: "); //Console.WriteLine(a); Console.WriteLine("==> adding pokemon"); if (Pokemons.Contains(Pokemon) == false) { if (config.verifypokemon) { if (((Pokemon.EncounterId == 0) | (Pokemon.SpawnpointId == null))) { if (Busy) { Console.WriteLine("====> I'm busy with checking another pokeon now. Skipping"); return; } else { Busy = true; Console.WriteLine(String.Format("====> Checking/getting data (about) pokemon. It will take up to {0} seconds, please wait", config.tryforseconds.ToString())); try { POGOLibCaller libcaller = new POGOLibCaller(); Pokemon = libcaller.VerifyPokemon(Pokemon, config); } catch { Console.WriteLine(String.Format("=======> Exception happened. Search is stopped for this pokemon")); } if (Pokemon.EncounterId == 0) { Console.WriteLine(String.Format("======> Pokemon {0} not discovered at location {1} , {2} ", Pokemon.PokemonName, Pokemon.Latitude, Pokemon.Longtitude)); } } } Busy = false; if (((Pokemon.EncounterId == 0) | (Pokemon.SpawnpointId == null))) { Console.WriteLine("======> Pokemon not added . Encounter and/or SpawnpointId are empty"); return; } } dynamic newlist; if (config.verifypokemon) { newlist = new List <PokemonInfoFull>(); } else { newlist = new List <PokemonInfo>(); } foreach (dynamic poke in Pokemons) { if (poke.expirationdt > DateTime.Now) { newlist.Add(poke); } } Pokemons = newlist; //if ((Pokemon.EncounterId >0 ) & (Pokemon.SpawnpointId != null)) { Pokemon.expirationdt = DateTime.Now.AddMinutes(config.minutestoexpire); Pokemon.expiration = Convert.ToInt64((Pokemon.expirationdt - DateTime.Parse("1/1/1970")).TotalMilliseconds); Pokemons.Add(Pokemon); //Console.WriteLine(string.Format("Added to list: {0}:{1},{2}",Pokemon.PokemonName,Pokemon.Latitude,Pokemon.Longtitude )); Console.WriteLine("======> Added: "); a = JsonConvert.SerializeObject(Pokemon, Formatting.Indented); Console.WriteLine(a); //} else { //Console.WriteLine("======> Pokemon not added . Encounter and/or SpawnpointId are empty"); // } if (Pokemons.Count == 0) { dynamic tmppoke; if (config.verifypokemon) { tmppoke = new PokemonInfoFull(); } else { tmppoke = new PokemonInfo();; } //PokemonInfo tmppoke = new PokemonInfo(); tmppoke.PokemonName = "Bellsprout"; tmppoke.IV = 10; tmppoke.Latitude = 23.906291124969709; tmppoke.Longtitude = 120.59261531771575; if (config.verifypokemon) { tmppoke.EncounterId = 13139724800732585298; tmppoke.SpawnpointId = "3469343f3d9"; } tmppoke.expirationdt = DateTime.Now.AddMinutes(config.minutestoexpire); tmppoke.expiration = Convert.ToInt64((Pokemon.expirationdt - DateTime.Parse("1/1/1970")).TotalMilliseconds); Pokemons.Add(tmppoke); } if (Pokemons.Count == 1) { Pokemons.Add(Pokemons[0]); } //JsonConvert.DeserializeObject<Config>(File.ReadAllText("config.json")); } }
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { //loggerFactory.AddConsole(); var serverAddressesFeature = app.ServerFeatures.Get <IServerAddressesFeature>(); Address = serverAddressesFeature.Addresses.ElementAt(0); app.UseStaticFiles(); app.Run(async(context) => { string path = context.Request.Path; //Console.WriteLine("request received : "+path); if (path == "/") { context.Response.ContentType = "application/json"; string a = JsonConvert.SerializeObject(Program.Pokemons, Formatting.Indented); await context.Response.WriteAsync(a); } if (path.StartsWith("/addpokemon")) { Console.WriteLine("request received : " + path); dynamic Pokemon; if (Program.config.verifypokemon) { Pokemon = new PokemonInfoFull(); } else { Pokemon = new PokemonInfo(); } path = path.Replace(System.Environment.NewLine, ""); string[] strings = Regex.Split(path, "/"); if (strings[2] == "msniper:") { //Console.WriteLine("processing msniper"); CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); culture.NumberFormat.NumberDecimalSeparator = "."; Pokemon.PokemonName = strings[4]; if (Program.config.verifypokemon) { Pokemon.EncounterId = Convert.ToUInt64(strings[5]); Pokemon.SpawnpointId = strings[6]; Pokemon.IV = Convert.ToDouble(strings[8], culture); } Pokemon.Latitude = Convert.ToDouble(Regex.Split(strings[7], ",")[0], culture); Pokemon.Longtitude = Convert.ToDouble(Regex.Split(strings[7], ",")[1], culture); //Console.WriteLine("msniper done"); } if (strings[2] == "pokesniper2:") { //Console.WriteLine("processing pokesniper2"); Pokemon.PokemonName = strings[4]; CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); culture.NumberFormat.NumberDecimalSeparator = "."; Pokemon.Latitude = Convert.ToDouble(Regex.Split(strings[5], ",")[0], culture); Pokemon.Longtitude = Convert.ToDouble(Regex.Split(strings[5], ",")[1], culture); if (strings.Count() == 7) { Pokemon.IV = Convert.ToDouble(strings[6], culture); } //Console.WriteLine("pokesniper2 done"); } if (Pokemon.PokemonName != null) { Program.AddPokemon(Pokemon); } } if (path == "/registerDISABLED") { context.Response.ContentType = "text/html"; string content = $@" <!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01//EN""> <head> <title>Web Protocol Handler Sample - Register</title> <script type=""text/javascript""> window.navigator.registerProtocolHandler( ""msniper3"", """ + Address + "/addpokemon/%s" + @""", 'PSSniper'); </script> </head> </html>"; await context.Response.WriteAsync(content); } if (path == "/test") { context.Response.ContentType = "text/html"; string content = @"<a href=""msniper3://aaaa/bbbbb/cccc"">click</a>"; await context.Response.WriteAsync(content); } }); }