public static void LogPlayerIn(NetworkClient Client, Account Account) { bool newSession = false; if (Account.LoggedInCharacter != null) { //Connect to the existing session if (Account.LoggedInCharacter.ConnectedClient != null) { Account.LoggedInCharacter.ConnectedClient.Player = null; Account.LoggedInCharacter.ConnectedClient.Send("You are being disconnected because you have logged into this account from another connection.\r\n"); Account.LoggedInCharacter.ConnectedClient.Disconnect(); } Client.Send("You were already logged in. You are being connected to that session.\r\n"); Client.Player = Account.LoggedInCharacter; } else { //Start a new session Client.Player = Accounts.GetAccountCharacter(Account); newSession = true; } Client.Player.SetProperty("account", Account); Client.IsLoggedOn = true; Client.Player.CommandHandler = Core.ParserCommandHandler; Account.LoggedInCharacter = Client.Player; Core.TiePlayerToClient(Client, Client.Player); if (newSession) Core.AddPlayer(Client.Player); }
public static Player GetAccountCharacter(Account Account) { Core.CommandTimeoutEnabled = false; var playerObject = Core.Database.GetObject(Core.SettingsObject.PlayerBaseObject + "@" + Account.UserName) as Player; playerObject.Short = Account.UserName; playerObject.Nouns.Add(Account.UserName.ToUpper()); MudObject.PersistInstance(playerObject); return playerObject; }
internal static void SaveAccount(Account account) { try { var directory = AccountsPath + account.UserName; var filename = directory + "/account.txt"; var json = JsonConvert.SerializeObject(account, Formatting.Indented); System.IO.Directory.CreateDirectory(directory); File.WriteAllText(filename, json); } catch (Exception e) { Core.LogError(String.Format("While saving account {0} - {1}", account.UserName, e.Message)); } }
internal static Account CreateAccount(String UserName, String Password) { if (LoadAccount(UserName) != null) { throw new InvalidOperationException("Account already exists"); } if (String.IsNullOrWhiteSpace(Password)) { throw new InvalidOperationException("A password must be specified when creating an account"); } var salt = GenerateRandomSalt(); var hash = HashPassword(Password, salt); var newAccount = new Account { UserName = UserName, HashedPassword = hash, Salt = salt }; SaveAccount(newAccount); return newAccount; }
internal static bool VerifyAccount(Account Account, String Password) { var hashedPassword = HashPassword(Password, Account.Salt); return Account.HashedPassword == hashedPassword; }