public static void LogIn(Client player, Shared.Schemes.UiLoginSubmitPayload payload) { Dictionary <string, string> errors = ValidateFields(payload); if (errors.Count > 0) { Bus.TriggerUi(player, Shared.Events.LOGIN_SUBMIT_ERROR, errors); return; } Account.Entity account = Account.Service.GetAccountEntityByUsername(payload.Username); if (account == null || !BCrypt.Net.BCrypt.Verify(payload.Password, account.Password)) { errors.Add(nameof(payload.Username), Resources.ERROR_INCORRECT_USERNAME_OR_PASSWORD); Bus.TriggerUi(player, Shared.Events.LOGIN_SUBMIT_ERROR, errors); return; } Account.Attachment attachment = player.GetData(Account.Resources.ATTACHMENT_KEY); attachment.Entity = account; Bus.TriggerClient(player, Shared.Events.LOGIN_SUBMIT_OK, payload); Character.Lobby.Service.Start(player); }
// TODO пройти валидацию // TODO вернуть ответ // TODO если у игрока 1 персонаж, то пропустить выбор персонажа в лобби public static void CreateCharacter(Client player, Shared.Schemes.UiLobbyCreatorSubmit payload) { using (var db = new Database()) { Account.Attachment accountAttachment = player.GetData(Account.Resources.ATTACHMENT_KEY); string fullName = $"{payload.FirstName} {payload.LastName}"; var character = db.Characters.SingleOrDefault( v => $"{v.FirstName} {v.LastName}".ToLower() == fullName.ToLower() ); if (character is Character.Entity) { // TODO notify Console.WriteLine($"{fullName} already existing"); return; } character = new Character.Entity(payload.FirstName, payload.LastName, payload.Sex, payload); character.Account = accountAttachment.Entity; accountAttachment.Entity.Characters.Add(character); db.Accounts.Update(accountAttachment.Entity); db.SaveChanges(); Bus.TriggerUi(player, Shared.Events.LOBBY_CREATOR_SHOW, false); if (Character.Service.GetCharactersCount(accountAttachment.Entity) > 1) { Lobby.Service.Start(player); } else { Lobby.Selector.Service.Play(player, character); } } }