/// <summary> /// Whenever the "newuser" command is recieved, this method is called to /// add the new users information into the database /// </summary> /// <param name="Recv">Array of parms sent by the server</param> private void CreateNewUser(Dictionary <string, string> Recv) { // Make sure the user doesnt exist already try { using (GamespyDatabase Database = new GamespyDatabase()) { // Check to see if user exists if (Database.UserExists(Recv["nick"])) { Stream.SendAsync(@"\error\\err\516\fatal\\errmsg\This account name is already in use!\id\1\final\"); Disconnect(DisconnectReason.CreateFailedUsernameExists); return; } // We need to decode the Gamespy specific encoding for the password string Password = GamespyUtils.DecodePassword(Recv["passwordenc"]); string Cc = (RemoteEndPoint.AddressFamily == AddressFamily.InterNetwork) ? GeoIP.GetCountryCode(RemoteEndPoint.Address) : "US"; // Attempt to create account. If Pid is 0, then we couldnt create the account if ((PlayerId = Database.CreateUser(Recv["nick"], Password, Recv["email"], Cc)) == 0) { Stream.SendAsync(@"\error\\err\516\fatal\\errmsg\Error creating account!\id\1\final\"); Disconnect(DisconnectReason.CreateFailedDatabaseError); return; } Stream.SendAsync(@"\nur\\userid\{0}\profileid\{0}\id\1\final\", PlayerId); } } catch (Exception e) { // Check for invalid query params if (e is KeyNotFoundException) { Stream.SendAsync(@"\error\\err\0\fatal\\errmsg\Invalid Query!\id\1\final\"); } else { Stream.SendAsync(@"\error\\err\516\fatal\\errmsg\Error creating account!\id\1\final\"); Program.ErrorLog.Write("ERROR: [GpcmClient.CreateNewUser] An error occured while trying to create a new User account :: " + e.Message); } Disconnect(DisconnectReason.GeneralError); return; } }
/// <summary> /// Program Entry Point /// </summary> /// <param name="args"></param> static void Main(string[] args) { // Create our version string string version = String.Concat(Version.Major, ".", Version.Minor, ".", Version.Build); // Setup the console Console.Title = $"Battlefield2 Statistics Gamespy Login Emulator v{version}"; Console.WriteLine(@"__________ __ __ .__ .__ "); Console.WriteLine(@"\______ \_____ _/ |__/ |_| | ____ | | ____ ____"); Console.WriteLine(@" | | _/\__ \\ __\ __\ | _/ __ \| | / _ \ / ___\"); Console.WriteLine(@" | | \ / __ \| | | | | |_\ ___/| |_( <_> ) /_/ >"); Console.WriteLine(@" |______ /(____ /__| |__| |____/\___ >____/\____/\___ / "); Console.WriteLine(@" \/ \/ \/ /_____/ "); Console.WriteLine(); Console.WriteLine("--------------------------------------------------"); Console.WriteLine($"Battlefield 2 Gamespy Login Emulator v{version}"); Console.WriteLine("Created for BF2Statistics.com by Wilson212"); Console.WriteLine(); // Start login servers try { // Make sure Logs dir is created if (!Directory.Exists(Path.Combine(RootPath, "Logs"))) { Directory.CreateDirectory(Path.Combine(RootPath, "Logs")); } // Wrap error log into a writer ErrorLog = new LogWriter(Path.Combine(RootPath, "Logs", "LoginServer_Error.log"), false); // Setup Exception Handle AppDomain.CurrentDomain.UnhandledException += ExceptionHandler.OnUnhandledException; Application.ThreadException += ExceptionHandler.OnThreadException; // Start the Gamespy Servers ServerManager.StartServers(); Console.WriteLine(); Console.Write("Cmd > "); } catch (Exception e) { // Display error Console.WriteLine(e.Message); Console.WriteLine(" *** An exception will be logged *** "); Console.WriteLine(); Console.Write("Press any key to close..."); // Create exception log and wait for key input ExceptionHandler.GenerateExceptionLog(e); Console.ReadLine(); return; } // Main program loop while (IsRunning) { CheckInput(); } // Shut login servers down Console.WriteLine("Shutting down local Gamespy sockets..."); ServerManager.Shutdown(); GeoIP.Exit(); }