예제 #1
0
파일: Club.cs 프로젝트: Lion1616/ProjectP
        public async Task <bool> AddPlayer(ulong target)
        {
            AccountDto account;

            using (var db = AuthDatabase.Open())
            {
                account = (await DbUtil.FindAsync <AccountDto>(db, statement => statement
                                                               .Include <BanDto>(join => join.LeftOuterJoin())
                                                               .Where($"{nameof(AccountDto.Id):C} = @Id")
                                                               .WithParameters(new { Id = target }))
                           ).FirstOrDefault();

                if (account == null)
                {
                    return(false);
                }
            }

            var plrDto = new ClubPlayerDto
            {
                PlayerId = account.Id,
                ClubId   = Id,
                Rank     = (byte)ClubRank.Regular,
                State    = (int)ClubState.Joined
            };

            using (var db = GameDatabase.Open())
            {
                await DbUtil.InsertAsync(db, plrDto);
            }

            var plrInfo = new ClubPlayerInfo
            {
                Account   = account,
                AccountId = (ulong)account.Id,
                State     = ClubState.Joined,
                Rank      = ClubRank.Regular
            };

            Players.TryAdd(target, plrInfo);

            CheckMaster();

            var player = GameServer.Instance.PlayerManager[target];

            if (player != null)
            {
                player.Club = this;
                await player.Session.SendAsync(new ClubMyInfoAckMessage(player.Map <Player, ClubMyInfoDto>()));

                LogOn(player);
            }

            return(true);
        }
예제 #2
0
        public async Task <bool> RemovePlayer(ulong target)
        {
            AccountDto account;

            using (var db = AuthDatabase.Open())
            {
                account = (await DbUtil.FindAsync <AccountDto>(db, statement => statement
                                                               .Include <BanDto>(join => join.LeftOuterJoin())
                                                               .Where($"{nameof(AccountDto.Id):C} = @Id")
                                                               .WithParameters(new { Id = target }))
                           ).FirstOrDefault();

                if (account == null)
                {
                    return(false);
                }
            }

            using (var db = GameDatabase.Open())
            {
                var clubPlrDto = new ClubPlayerDto
                {
                    PlayerId = account.Id,
                    ClubId   = Id
                };

                DbUtil.Delete(db, clubPlrDto);
            }

            var player = GameServer.Instance.PlayerManager[target];

            Players.Remove(target, out _);

            if (player != null)
            {
                LogOff(player);
                player.Club = null;
                await player.Session.SendAsync(new ClubMyInfoAckMessage(player.Map <Player, ClubMyInfoDto>()));
            }

            CheckMaster();
            return(true);
        }
예제 #3
0
파일: Club.cs 프로젝트: Lion1616/ProjectP
        public async Task <bool> ForceChangeMaster(string nickname)
        {
            AccountDto account;

            using (var db = AuthDatabase.Open())
            {
                account = (await DbUtil.FindAsync <AccountDto>(db, statement => statement
                                                               .Include <BanDto>(join => join.LeftOuterJoin())
                                                               .Where($"{nameof(AccountDto.Nickname):C} = @Nickname")
                                                               .WithParameters(new { Nickname = nickname }))
                           ).FirstOrDefault();

                if (account == null)
                {
                    return(false);
                }
            }

            return(await ForceChangeMaster((ulong)account.Id));
        }
예제 #4
0
        public async Task <bool> SendAsync(string receiver, string title, string message, bool isClub = false)
        {
            // ToDo consume pen
            // ToDo check for ignore

            AccountDto account;

            using (var db = AuthDatabase.Open())
            {
                account = (await DbUtil.FindAsync <AccountDto>(db, statement => statement
                                                               .Where($"{nameof(AccountDto.Nickname):C} = @{nameof(receiver)}")
                                                               .WithParameters(new { receiver })))
                          .FirstOrDefault();
            }

            if (account == null)
            {
                return(false);
            }

            using (var db = GameDatabase.Open())
            {
                var mailDto = new PlayerMailDto
                {
                    PlayerId       = account.Id,
                    SenderPlayerId = (int)Player.Account.Id,
                    SentDate       = DateTimeOffset.Now.ToUnixTimeSeconds(),
                    Title          = title,
                    Message        = message,
                    IsMailNew      = true,
                    IsMailDeleted  = false,
                    IsClubMail     = isClub
                };
                await DbUtil.InsertAsync(db, mailDto);

                var plr = GameServer.Instance.PlayerManager.Get(receiver);
                plr?.Mailbox.Add(new Mail(mailDto, isClub));
                plr?.Mailbox.UpdateReminder();
                return(true);
            }
        }