Added user signup and improved error handling

This commit is contained in:
Luke Else 2022-02-18 12:03:23 +00:00
parent a6b6d139a0
commit 29f16a4d1e

View File

@ -4,27 +4,58 @@ using System.Text;
using EFBTracker.Tracking; using EFBTracker.Tracking;
using EFBTracker.Mongo; using EFBTracker.Mongo;
bool done = false; string email;
while (true)
{
try
{
Console.Write("Please enter your AutoRouter E-Mail: ");
email = Console.ReadLine().Trim().ToLower();
if (email.Count(x => (x == '@')) == 1)
{
break;
}
Console.Clear();
Console.WriteLine("Please enter a valid email!");
}
catch (System.Exception ex)
{
}
}
int listenPort = 49003; int listenPort = 49003;
using(UdpClient listener = new UdpClient(listenPort)) using(UdpClient listener = new UdpClient(listenPort))
{ {
try
{
IPEndPoint listenEndPoint = new IPEndPoint(2130706433, listenPort); IPEndPoint listenEndPoint = new IPEndPoint(2130706433, listenPort);
while(!done) while(true)
{ {
byte[] receivedData = listener.Receive(ref listenEndPoint); byte[] receivedData = listener.Receive(ref listenEndPoint);
Console.Clear(); Console.Clear();
Console.WriteLine("Received broadcast message from client {0}", listenEndPoint.ToString()); Console.Write($"Currently logged in as {email} \n \n");
Console.Write("Receiving broadcast message from {0} \n", listenEndPoint.ToString());
Console.WriteLine("Decoded data is:"); Console.Write("Decoded data is: \n");
Packet[]? data = Packet.ReadPackets(receivedData); Packet[]? data = Packet.ReadPackets(receivedData);
if (data != null) if (data != null)
{ {
SimPosition position = new SimPosition(data); SimPosition position = new SimPosition(data);
Console.WriteLine($"Latitude: {position.Latitude} Longitude: {position.Longitude} Altitude: {position.Altitude}"); await Mongo.UploadSimPosition(email, position);
await Mongo.UploadSimPosition("example@example.com", position); Console.Write($"Latitude: {position.Latitude} Longitude: {position.Longitude} Altitude: {position.Altitude} \n");
} }
} }
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
} }