public void Create(NetObject _Parent) { #region Prepare the object to do work. Parent = _Parent; if (Parent.UserObject.IsUtilityUser()) { HostSocket = null; } else { HostSocket = Server.CreateHostMainframe(); } if ((!(Parent.UserObject.IsUtilityUser())) && HostSocket == null) { //NOT a utility user, but the host service is closed. Parent.ClientObject.SendMessage("There was an error connecting you to the server: The host server is offline."); Parent.ClientObject.SendMessage("Please come back later! :D"); Parent.Close(); Logger.Console.WriteLine("&cCONNECTING USER WAS DISCONNECTED BECAUSE THE HOST SERVICE IS UNREACHABLE."); return; } ReceiveThread = new Thread(new ThreadStart(ReceiveLoop)); //Do not start until the parent tells us to by calling ReceiveThread.Start(); #endregion }
public void ReceiveLoop() { #region Receive Packets from the Client and Action Them. //Console.WriteLine("NetObject.Client Ready"); while (ClientSocket.Connected && Parent.HostObject.HostSocket.Connected) { //Console.WriteLine("NetObject.Client is waiting for data from its Client side socket."); //Console.WriteLine("NetObject.Client Listening..."); Network.Packet InPacket = Network.Sockets.GetPacket(ClientSocket); //Console.WriteLine("NetObject.Client Got Some Data."); if (InPacket.Type != 0) { PreviousPackets.Insert(0, InPacket); while (PreviousPackets.Count > 5) { PreviousPackets.RemoveAt(PreviousPackets.Count - 1); } if (!_UnSleep()) { continue; } ProcessPacket(InPacket); } else { //The only time Socket Receive returns 0 is when a remote host disconnects, otherwise, it waits. Parent.Close(); } } #endregion #region The Client Socket has disconnected! List <Network.Packet> PacketsCache = PreviousPackets; foreach (Network.Packet ThisPacket in PacketsCache) { Logger.Log.Packet(ThisPacket); } //Console.WriteLine("Client Socket Closed inside NetObject.Client"); Parent.Close(); //Let the parent handle the client closing action. //Console.WriteLine("CLOSE5"); #endregion }
public static bool Authenticate(NetObject ThisClient) { ThisClient.ClientObject.SendMessage("This Server uses YSFlight Headquarters Authentication."); ThisClient.ClientObject.SendMessage("Now Checking your details against the YSFlight Headquarters Records, please be patient."); ThisClient.ClientObject.ComplexTaskWaiter(); //Logger.Console.WriteLine("&cUSERNAME: "******"&cID: " + ID.ToString()); if (ID == -3) { ThisClient.ClientObject.SendMessage("There was a bug connecting you to YSFlight Headquarters."); ThisClient.ClientObject.SendMessage("A bug report has been made for the Server Owner to investigate."); ThisClient.ClientObject.SendMessage("Sorry!"); Logger.Console.WriteLine("Client " + ThisClient.Username + " disconnected. (YSFHQ Authentication Bug)."); Logger.Log.Bug("Unable to get YSFHQ Information for User: + \"" + ThisClient.Username + "\"."); return(false); } if (ID == -2) { ThisClient.ClientObject.SendMessage("Your supplied username has not matched any records on YSFlight Headquarters."); ThisClient.ClientObject.SendMessage("Please use your YSFlight Headquarters username when logging into this server. (No squadtags etc.)"); Logger.Console.WriteLine("Client " + ThisClient.Username + " disconnected. (YSFHQ Username Mismatch)."); Logger.Log.SystemMessage("No Matching YSFHQ Information for User: + \"" + ThisClient.Username + "\"."); return(false); } if (ID < 0) { ThisClient.ClientObject.SendMessage("There was an error authenticating you. (Service unreachable?)"); ThisClient.ClientObject.SendMessage("Please try again later, sorry for the inconvenience!"); Logger.Console.WriteLine("Client " + ThisClient.Username + " disconnected. (YSFHQ Authentication Unreachable)."); Logger.Log.SystemMessage("Not able to connect to YSFHQ for User: + \"" + ThisClient.Username + "\"."); return(false); } //Logger.Console.WriteLine("&cIP1: " + GetIPAddress.FromID(ID).ToString()); //Logger.Console.WriteLine("&e" + "#" + GetIPAddress.FromID(ID).ToString() + "#"); //Logger.Console.WriteLine("&e" + "$" + ThisClient.ClientObject.PublicIP.ToString() + "$"); if ((ThisClient.ClientObject.ClientSocket.RemoteEndPoint as IPEndPoint).Address.ToString() == "127.0.0.1" && Database.Settings.AlwaysAllowLocalHost) { ThisClient.ClientObject.ComplexTaskComplete.Set(); ThisClient.ClientObject.SendMessage("You are automatically logged in, as you are connecting from LocalHost."); return(true); } else if ((ThisClient.ClientObject.ClientSocket.RemoteEndPoint as IPEndPoint).Address.ToString() == "127.0.0.1" && !Database.Settings.AlwaysAllowLocalHost) { ThisClient.ClientObject.ComplexTaskComplete.Set(); ThisClient.ClientObject.SendMessage("As you are connecting from LocalHost, I need to check with a polling service to check your IP address."); ThisClient.ClientObject.SendMessage("This takes longer then the standard log in, please be patient."); ThisClient.ClientObject.ComplexTaskWaiter(); if (ThisClient.ClientObject.PublicIP == IPAddress.None) { ThisClient.ClientObject.ComplexTaskComplete.Set(); ThisClient.ClientObject.SendMessage("The polling service failed to retreive your IP Address."); ThisClient.ClientObject.SendMessage("Please try again later."); Logger.Console.WriteLine("Client " + ThisClient.Username + " disconnected. (YSFHQ IP Confirmation Failure)."); ThisClient.Close(); return(false); } } if (GetIPAddress.FromID(ID).ToString() == ThisClient.ClientObject.PublicIP.ToString()) { ThisClient.ClientObject.ComplexTaskComplete.Set(); ThisClient.ClientObject.SendMessage("Thanks for your patience, you are now logged in."); if (!ThisClient.UserObject.UsePassword) { ThisClient.ClientObject.SendMessage("You do not have a password fallback for authentication set! Use \"/CHANGEPASSWORD\" to set one!"); } ThisClient.ClientObject.SendMessage("\n\n\n\n\n\n\n\n\n\n"); Logger.Log.SystemMessage("YSFHQ Authentication successful for User: + \"" + ThisClient.Username + "\"."); //Logger.Console.WriteLine("&cIP: " + ThisClient.ClientObject.PublicIP.ToString()); return(true); } else { //Logger.Console.WriteLine("&cIP: " + ThisClient.ClientObject.PublicIP.ToString()); ThisClient.ClientObject.ComplexTaskComplete.Set(); ThisClient.ClientObject.SendMessage("Your records do not appear to match what is on record with YSFlight Headquarters."); try { ThisClient.ClientObject.SendMessage("(You are connecting to Orb from " + ThisClient.ClientObject.PublicIP.ToString() + " but your YSFHQ IP Address is " + GetIPAddress.FromID(ID).Mask() + ")."); } catch { } if (ThisClient.UserObject.UsePassword) { ThisClient.ClientObject.SendMessage("As you have a password on your account, You will now be redirected to the Password Authentication Module."); ThisClient.ClientObject.SendMessage("Alternatively, please log out/in to YSFHQ if necessary to refresh your IP Address!"); if (Server.Password._AuthenticateOnly(ThisClient)) { Logger.Log.SystemMessage("Password Fallback Authentication successful for User: + \"" + ThisClient.Username + "\"."); return(true); } else { return(false); } } if (ThisClient.UserObject.LoginCount < 10) { ThisClient.ClientObject.ComplexTaskComplete.Set(); ThisClient.ClientObject.SendMessage("As you have a low login count, and you have a matching HQ username, you have been allowed into the server."); ThisClient.ClientObject.SendMessage("Please set a fallback password using \"/CHANGEPASSWORD\" so you can login in future if you do not match the YSFHQ records!"); return(true); } ThisClient.ClientObject.SendMessage("Please log out/in to YSFHQ if necessary to refresh your IP Address!"); Logger.Console.WriteLine("Client " + ThisClient.Username + " disconnected. (YSFHQ Authentication Failed) (" + ThisClient.ClientObject.PublicIP.ToString() + ")/(" + GetIPAddress.FromID(ID).ToString() + ")."); Logger.Log.SystemMessage("Authentication Failure in YSFHQ Module for User: + \"" + ThisClient.Username + "\". (" + ThisClient.ClientObject.PublicIP.ToString() + ")/(" + GetIPAddress.FromID(ID).ToString() + ")."); //return true; //DISABLE THIS ONCE TESTING IS COMPLETE!!! return(false); } }