EFBTracker/Program.cs

64 lines
1.6 KiB
C#
Raw Permalink Normal View History

2022-02-17 16:36:55 +00:00
using System.Net;
using System.Net.Sockets;
using System.Text;
2022-02-17 19:47:22 +00:00
using EFBTracker.Tracking;
using EFBTracker.Mongo;
2022-02-17 16:36:55 +00:00
string email;
while (true)
2022-02-17 16:36:55 +00:00
{
try
2022-02-17 16:36:55 +00:00
{
Console.Write("Please enter your AutoRouter E-Mail: ");
email = Console.ReadLine().Trim().ToLower();
2022-02-17 16:36:55 +00:00
if (email.Count(x => (x == '@')) == 1)
{
break;
}
2022-02-17 16:36:55 +00:00
Console.Clear();
Console.WriteLine("Please enter a valid email!");
}
catch (System.Exception ex)
{
}
}
int listenPort = 49003;
using(UdpClient listener = new UdpClient(listenPort))
{
try
{
IPEndPoint listenEndPoint = new IPEndPoint(2130706433, listenPort);
while(true)
{
Console.WriteLine("Awaiting Simulator conenction...");
byte[] receivedData = listener.Receive(ref listenEndPoint);
Console.Clear();
Console.Write($"Currently logged in as {email} \n \n");
Console.Write("Receiving broadcast message from {0} \n", listenEndPoint.ToString());
Console.Write("Decoded data is: \n");
Packet[]? data = Packet.ReadPackets(receivedData);
if (data != null)
{
SimPosition position = new SimPosition(data);
await Mongo.UploadSimPosition(email, position);
Console.Write($"Latitude: {position.Latitude} Longitude: {position.Longitude} Altitude: {position.Altitude} \n");
}
}
2022-02-17 16:36:55 +00:00
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
2022-02-17 16:36:55 +00:00
}