public async Task ClubCloseReq2(GameSession session, ClubCloseReq2Message message) { var plr = session.Player; if (plr?.Club == null || plr.Club.Id != message.ClanId) { await session.SendAsync(new ClubCloseAck2Message(1)); return; } if (plr.Club.Players.Any(x => x.Key == plr.Account.Id && x.Value.Rank == ClubRank.Master)) { using (var db = GameDatabase.Open()) { var club = (await DbUtil.FindAsync <ClubDto>(db, statement => statement .Where($"{nameof(ClubDto.Id):C} = @Id") .WithParameters(new { plr.Club.Id }))).FirstOrDefault(); if (club != null) { var players = await DbUtil.FindAsync <ClubPlayerDto>(db, statement => statement .Where($"{nameof(ClubPlayerDto.ClubId):C} = @Id") .WithParameters(new { plr.Club.Id })); foreach (var member in players) { await DbUtil.DeleteAsync(db, member); } DbUtil.Delete(db, club); foreach (var member in plr.Club.Players) { plr.Club.Players.TryRemove(member.Key, out _); } GameServer.Instance.ClubManager.Remove(plr.Club); await session.SendAsync(new ClubCloseAck2Message()); foreach (var member in GameServer.Instance.PlayerManager.Where(x => x.Club?.Id == club.Id)) { Club.LogOff(member); member.Club = null; member.Session?.SendAsync(new ClubMyInfoAckMessage(member.Map <Player, ClubMyInfoDto>())); } } } } }
public static async Task <bool> ChangeNickname(Player plr, NicknameHistoryDto nicknameHistory, bool restore) { var toNickname = nicknameHistory.NewNickname; try { using (var db = AuthDatabase.Open()) { var account = (await DbUtil.FindAsync <AccountDto>(db, statement => statement .Where($"{nameof(AccountDto.Nickname):C} = @Nickname") .WithParameters(new { plr.Account.Nickname }))).FirstOrDefault(); if (account == null) { await plr.Session.SendAsync(new ServerResultAckMessage(ServerResult.FailedToRequestTask)); return(false); } if (restore) { var nicknameHistory1 = await DbUtil.FindAsync <NicknameHistoryDto>(db, statement => statement .Where($"{nameof(NicknameHistoryDto.AccountId):C} = @Id") .WithParameters(new { plr.Account.Id })); var firstchange = nicknameHistory1.FirstOrDefault(); if (firstchange == null) { await plr.Session.SendAsync(new ServerResultAckMessage(ServerResult.NicknameUnavailable)); return(false); } account.Nickname = firstchange.OldName; plr.Account.Nickname = firstchange.OldName; foreach (var history in nicknameHistory1) { await DbUtil.DeleteAsync(db, history); } await plr.Session.SendAsync(new ItemUseChangeNickCancelAckMessage(0)); } else { if (!await AuthService.IsNickAvailableAsync(toNickname)) { await plr.Session.SendAsync(new ServerResultAckMessage(ServerResult.NicknameUnavailable)); return(false); } account.Nickname = toNickname; plr.Account.Nickname = toNickname; DbUtil.Insert(db, nicknameHistory); await plr.Session.SendAsync(new ItemUseChangeNickAckMessage { Result = 0, Unk2 = 0, Unk3 = toNickname }); } DbUtil.Update(db, account); return(true); } } catch (Exception e) { Logger.Error(e.ToString()); await plr.Session.SendAsync(new ServerResultAckMessage(ServerResult.FailedToRequestTask)); return(false); } }