From 29f16a4d1e2125ef5dcd009035933a6daed54bdb Mon Sep 17 00:00:00 2001 From: Luke Else Date: Fri, 18 Feb 2022 12:03:23 +0000 Subject: [PATCH] Added user signup and improved error handling --- Program.cs | 67 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/Program.cs b/Program.cs index 0960cd3..9cf8b16 100644 --- a/Program.cs +++ b/Program.cs @@ -4,27 +4,58 @@ using System.Text; using EFBTracker.Tracking; using EFBTracker.Mongo; -bool done = false; -int listenPort = 49003; -using(UdpClient listener = new UdpClient(listenPort)) +string email; + +while (true) { - IPEndPoint listenEndPoint = new IPEndPoint(2130706433, listenPort); - while(!done) + try { - byte[] receivedData = listener.Receive(ref listenEndPoint); + Console.Write("Please enter your AutoRouter E-Mail: "); + email = Console.ReadLine().Trim().ToLower(); + + if (email.Count(x => (x == '@')) == 1) + { + break; + } Console.Clear(); - Console.WriteLine("Received broadcast message from client {0}", listenEndPoint.ToString()); - - Console.WriteLine("Decoded data is:"); - - Packet[]? data = Packet.ReadPackets(receivedData); - - if (data != null) - { - SimPosition position = new SimPosition(data); - Console.WriteLine($"Latitude: {position.Latitude} Longitude: {position.Longitude} Altitude: {position.Altitude}"); - await Mongo.UploadSimPosition("example@example.com", position); - } + 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) + { + 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"); + } + } + } + catch (System.Exception ex) + { + Console.WriteLine(ex.Message); + Console.ReadLine(); } }