// Used for actually generating objects of this class - // these interface with the private constructor above. #region Public/Static accessible constructors public static CharacterResponse Create(Account account, string name, Class cls, Race race, Faction faction) { Character character = null; string failedMessage = Validation.Instance.TestName(name); if (failedMessage == string.Empty) { cls.Validate(race); string raceTest = race.Validate(faction); if (raceTest != string.Empty) { if (failedMessage != string.Empty) { failedMessage = failedMessage + Environment.NewLine; } failedMessage += raceTest; } if (failedMessage == string.Empty) { byte level = 1; if (cls == Class.DeathKnight) { level = 55; } // Final test - pulls each character for a given user. If user has a non-deleted character of the opposing faction, Create returns with failedMessage and null Character. foreach (string characterName in account.CharacterNames) { Character existingCharacter = Store.Get(characterName); if (existingCharacter.Faction != faction && !existingCharacter.Deleted) { failedMessage = "Error: You already have at least one active character of the opposing faction. You cannot create a " + faction.ToString() + " character without deleting that character.)"; } } if (failedMessage == string.Empty) { character = new Character(account.Name, name, level, cls, race, faction); failedMessage = Store.Add(character); if (failedMessage == string.Empty) { account.AddCharacterName(character.Name); } } } } if (failedMessage != string.Empty) { character = null; } return(new CharacterResponse(failedMessage, character)); }
/// <summary> /// Used for accessing existing accounts, requires password. /// </summary> /// <param name="name"></param> /// <param name="pass"></param> /// <returns></returns> public static Account Login(string name, string pass) { Account account = Store.Get(name); if (account != null) { if (account.Check(pass)) { return(account); } } return(null); }