Skip to content

Commit

Permalink
newparse
Browse files Browse the repository at this point in the history
  • Loading branch information
msx752 committed Sep 11, 2016
1 parent 11a3461 commit ea6fd1f
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 58 deletions.
24 changes: 24 additions & 0 deletions MSniper/EncounterInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MSniper.Enums;

namespace MSniper
{
public class EncounterInfo : IDisposable
{
public short PokemonId { get; set; }
public long EncounterId { get; set; }
public string SpawnPointId { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
//public double Iv { get; set; }

public void Dispose()
{
GC.SuppressFinalize(this);
}
}
}
1 change: 1 addition & 0 deletions MSniper/Enums/PokemonName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public enum PokemonId
{
Missingno = 0,
Bulbasaur = 1,
Ivysaur = 2,
Venusaur = 3,
Expand Down
1 change: 1 addition & 0 deletions MSniper/MSniper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Downloader.cs" />
<Compile Include="EncounterInfo.cs" />
<Compile Include="Enums\PokemonName.cs" />
<Compile Include="Extensions\Extensions.cs" />
<Compile Include="LiveFeed\LiveFeed.cs">
Expand Down
122 changes: 64 additions & 58 deletions MSniper/WFConsole/FWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public Process[] GetNecroBotProcesses()
public void CheckNecroBots(bool shutdownMSniper)
{
if (GetNecroBotProcesses().Any()) return;
Console.WriteLine(string.Empty.PadRight(10)+Culture.GetTranslation(TranslationString.AnyNecroBotNotFound), Config.Error);
Console.WriteLine(string.Empty.PadRight(10) + Culture.GetTranslation(TranslationString.AnyNecroBotNotFound), Config.Error);
Console.WriteLine(string.Empty.PadRight(5) + $" *{Culture.GetTranslation(TranslationString.RunBeforeMSniper)}*", Config.Error);
Console.WriteLine("--------------------------------------------------------");
if (shutdownMSniper)
Expand Down Expand Up @@ -252,7 +252,7 @@ public void ShowActiveBots()
if (string.IsNullOrEmpty(username))
continue;

var btn = new ToolStripMenuItem(username) {Tag = item.MainWindowHandle};
var btn = new ToolStripMenuItem(username) { Tag = item.MainWindowHandle };
btn.Click += delegate (object sender, EventArgs e)
{
var id = int.Parse(btn.Tag.ToString());
Expand Down Expand Up @@ -320,6 +320,7 @@ public void Main()
CheckNecroBots(Console.Arguments.Length != 1);
//args = new string[] { "msniper://Ivysaur/-33.890835,151.223859" };//for debug mode
//args = new string[] { "-registerp" };//for debug mode
//Console.Arguments = new string[] { "msniper://Missingno/2157859740816806781/6b12ae46d31/-33.864635340271498,151.20600957337419" };
if (Console.Arguments.Length == 1)
{
RunningNormally = false;
Expand Down Expand Up @@ -348,18 +349,22 @@ public void Main()
break;

default:
var re0 = "(pokesniper2://|msniper://)"; //protocol
var re0 = "(msniper://)"; //protocol
var re1 = "((?:\\w+))";//pokemon name
var re2 = "(\\/)";//separator
var re3 = "([+-]?\\d*\\.\\d+)(?![-+0-9\\.])";//lat
var re4 = "(,)";//separator
var re5 = "([+-]?\\d*\\.\\d+)(?![-+0-9\\.])";//lon

var r = new Regex(re0 + re1 + re2 + re3 + re4 + re5, RegexOptions.IgnoreCase | RegexOptions.Singleline);
var re3 = "(\\d+)";
var re4 = "(\\/)";//separator
var re5 = "((?:[a-zA-Z0-9]*))";
var re6 = "(\\/)";//separator
var re7 = "([+-]?\\d*\\.\\d+)(?![-+0-9\\.])";//lat
var re8 = "(,)";//separator
var re9 = "([+-]?\\d*\\.\\d+)(?![-+0-9\\.])";//lon

var r = new Regex(re0 + re1 + re2 + re3 + re4 + re5 + re6 + re7 + re8 + re9, RegexOptions.IgnoreCase | RegexOptions.Singleline);
var m = r.Match(Console.Arguments.First());
if (m.Success)
{
Snipe(m.Groups[2].ToString(), m.Groups[4].ToString(), m.Groups[6].ToString());
Snipe(m);
}
else
{
Expand All @@ -370,42 +375,42 @@ public void Main()
}
else if (Console.Arguments.Length == 0)
{
RunningNormally = true;
Console.WriteLine(Culture.GetTranslation(TranslationString.CustomPasteDesc));
Console.WriteLine(Culture.GetTranslation(TranslationString.CustomPasteFormat));
Console.WriteLine("--------------------------------------------------------");
do
{
Console.WriteLine(Culture.GetTranslation(TranslationString.WaitingDataMsg), Config.Highlight);
var snipping = Console.ReadLine();
CheckNecroBots(true);
//snipping = "dragonite 37.766627 , -122.403677";//for debug mode (spaces are ignored)
if (snipping.ToLower() == "e")
break;
var re1 = "((?:\\w+\\s*))";//pokemon name
var re2 = "( )";//separator
var re3 = "([+-]?\\d*\\.\\d+)(?![-+0-9\\.])";//lat
var re4 = "(\\s*,\\s*)";//separator
var re5 = "([+-]?\\d*\\.\\d+)(?![-+0-9\\.])";//lon
var r = new Regex(re1 + re2 + re3 + re4 + re5, RegexOptions.IgnoreCase | RegexOptions.Singleline);

var error = true;
foreach (Match m in r.Matches(snipping))
{
if (!m.Success) continue;
var pokemonN = m.Groups[1].ToString().Replace(" ","");
error = false;
var prkmnm = PokemonId.Abra;
var verified = Enum.TryParse<PokemonId>(pokemonN, true, out prkmnm);
if (verified)
Snipe(pokemonN, m.Groups[3].ToString(), m.Groups[5].ToString());
else
Console.WriteLine(Culture.GetTranslation(TranslationString.WrongPokemonName, pokemonN), Config.Error);
}
if (error)
Console.WriteLine(Culture.GetTranslation(TranslationString.CustomPasteWrongFormat), Config.Error);
}
while (true);
//RunningNormally = true;
//Console.WriteLine(Culture.GetTranslation(TranslationString.CustomPasteDesc));
//Console.WriteLine(Culture.GetTranslation(TranslationString.CustomPasteFormat));
//Console.WriteLine("--------------------------------------------------------");
//do
//{
// Console.WriteLine(Culture.GetTranslation(TranslationString.WaitingDataMsg), Config.Highlight);
// var snipping = Console.ReadLine();
// CheckNecroBots(true);
// //snipping = "dragonite 37.766627 , -122.403677";//for debug mode (spaces are ignored)
// if (snipping.ToLower() == "e")
// break;
// var re1 = "((?:\\w+\\s*))";//pokemon name
// var re2 = "( )";//separator
// var re3 = "([+-]?\\d*\\.\\d+)(?![-+0-9\\.])";//lat
// var re4 = "(\\s*,\\s*)";//separator
// var re5 = "([+-]?\\d*\\.\\d+)(?![-+0-9\\.])";//lon
// var r = new Regex(re1 + re2 + re3 + re4 + re5, RegexOptions.IgnoreCase | RegexOptions.Singleline);

// var error = true;
// foreach (Match m in r.Matches(snipping))
// {
// if (!m.Success) continue;
// var pokemonN = m.Groups[1].ToString().Replace(" ", "");
// error = false;
// var prkmnm = PokemonId.Abra;
// var verified = Enum.TryParse<PokemonId>(pokemonN, true, out prkmnm);
// if (verified)
// Snipe(pokemonN, m.Groups[3].ToString(), m.Groups[5].ToString());
// else
// Console.WriteLine(Culture.GetTranslation(TranslationString.WrongPokemonName, pokemonN), Config.Error);
// }
// if (error)
// Console.WriteLine(Culture.GetTranslation(TranslationString.CustomPasteWrongFormat), Config.Error);
//}
//while (true);
}
Shutdown();
});
Expand Down Expand Up @@ -451,12 +456,10 @@ public void Shutdown(int seconds)
Process.GetCurrentProcess().Kill();
}

public void Snipe(string pokemonName, string latt, string lonn)
public void Snipe(Match m)
{
try
{
var lat = double.Parse(latt, CultureInfo.InvariantCulture);
var lon = double.Parse(lonn, CultureInfo.InvariantCulture);
var pList = GetNecroBotProcesses();
foreach (var t in pList)
{
Expand All @@ -471,19 +474,22 @@ public void Snipe(string pokemonName, string latt, string lonn)
}
var pathRemote = GetSnipeMsPath(Path.GetDirectoryName(t.MainModule.FileName));
var mSniperLocation = ReadSnipeMs(pathRemote);
var newPokemon = new MSniperInfo()
var newPokemon = new EncounterInfo()
{
Latitude = lat,
Longitude = lon,
Id = pokemonName
PokemonId = (short)(PokemonId)Enum.Parse(typeof(PokemonId), m.Groups[2].ToString()),
EncounterId = long.Parse(m.Groups[4].ToString()),
SpawnPointId = m.Groups[6].ToString(),
Latitude = double.Parse(m.Groups[8].Value, CultureInfo.InvariantCulture),
Longitude = double.Parse(m.Groups[10].Value, CultureInfo.InvariantCulture),
};
if (mSniperLocation.FindIndex(p => p.Id == newPokemon.Id && p.Latitude == newPokemon.Latitude && p.Longitude == newPokemon.Longitude) == -1)

if (mSniperLocation.FindIndex(p => p.EncounterId == newPokemon.EncounterId && p.SpawnPointId == newPokemon.SpawnPointId) == -1)
{
mSniperLocation.Add(newPokemon);
if (WriteSnipeMs(mSniperLocation, pathRemote))
{
Console.WriteLine(Culture.GetTranslation(TranslationString.SendingPokemonToNecroBot,
newPokemon.Id.ToLower(),
newPokemon.PokemonId,
newPokemon.Latitude,
newPokemon.Longitude,
username), Config.Success);
Expand Down Expand Up @@ -526,7 +532,7 @@ private static Configs LoadConfigs()
return settings;
}

private static List<MSniperInfo> ReadSnipeMs(string path)
private static List<EncounterInfo> ReadSnipeMs(string path)
{
if (File.Exists(path))
{
Expand All @@ -541,15 +547,15 @@ private static List<MSniperInfo> ReadSnipeMs(string path)
catch { Thread.Sleep(200); }
}
while (true);//waiting access
return JsonConvert.DeserializeObject<List<MSniperInfo>>(jsn);
return JsonConvert.DeserializeObject<List<EncounterInfo>>(jsn);
}
else
{
return new List<MSniperInfo>();
return new List<EncounterInfo>();
}
}

private static bool WriteSnipeMs(List<MSniperInfo> mSniperLocation, string path)
private static bool WriteSnipeMs(List<EncounterInfo> mSniperLocation, string path)
{
do
{
Expand Down

0 comments on commit ea6fd1f

Please sign in to comment.