예제 #1
0
 public void ClubCreateReq2(GameSession session, ClubCreateReq2Message message)
 {
     session.SendAsync(new ServerResultAckMessage(ServerResult.CantReadClanInfo));
     //session.SendAsync(new ClubCreateAck2Message(0));
 }
 public void ClubCreateReq2(GameSession session, ClubCreateReq2Message message)
 {
     session.SendAsync(new ClubCreateAck2Message(0));
 }
예제 #3
0
        public async Task ClubCreateReq2(GameSession session, ClubCreateReq2Message message)
        {
            var plr = session.Player;

            if (plr == null)
            {
                return;
            }

            var ascii = Config.Instance.Game.NickRestrictions.AsciiOnly;

            if (GameServer.Instance.ClubManager.Any(c =>
                                                    c.ClanName == message.Name || c.Players.ContainsKey(plr.Account.Id)) ||
                !Namecheck.IsNameValid(message.Name, true) ||
                ascii && message.Name.Any(c => c > 127) ||
                !ascii && message.Name.Any(c => c > 255))
            {
                Logger.ForAccount(plr).Information($"Couldnt create Clan : {message.Name}");
                await session.SendAsync(new ClubCreateAck2Message(1));
            }
            else
            {
                var clubDto = new ClubDto
                {
                    Name = message.Name,
                    Icon = ""
                };

                using (var db = GameDatabase.Open())
                {
                    try
                    {
                        using (var transaction = DbUtil.BeginTransaction(db))
                        {
                            await DbUtil.InsertAsync(db, clubDto,
                                                     statement => statement.AttachToTransaction(transaction));

                            var clubPlayerInfo = new ClubPlayerInfo
                            {
                                AccountId = session.Player.Account.Id,
                                Account   = session.Player.Account.AccountDto,
                                State     = ClubState.Joined,
                                Rank      = ClubRank.Master
                            };

                            var club = new Club(clubDto, new[] { clubPlayerInfo });
                            GameServer.Instance.ClubManager.Add(club);
                            transaction.Commit();

                            var clubplrdto = new ClubPlayerDto
                            {
                                PlayerId = (int)session.Player.Account.Id,
                                ClubId   = club.Id,
                                Rank     = (byte)ClubRank.Master,
                                State    = (int)ClubState.Joined
                            };
                            await DbUtil.InsertAsync(db, clubplrdto);

                            session.Player.Club = club;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex.ToString());
                        await session.SendAsync(new ClubCreateAck2Message(1));

                        return;
                    }

                    await session.SendAsync(new ClubCreateAck2Message(0));

                    await session.SendAsync(new ClubMyInfoAckMessage(plr.Map <Player, ClubMyInfoDto>()));

                    Club.LogOn(plr);
                }
            }
        }
예제 #4
0
        public void ClubCreateReq2(GameSession session, ClubCreateReq2Message message)
        {
            var plr = session.Player;

            if (plr == null)
            {
                return;
            }

            if (GameServer.Instance.ClubManager.Any(c =>
                                                    c.ClanName == message.Name || c.Players.ContainsKey(plr.Account.Id)))
            {
                Logger.Information($" {plr.Account.Nickname} : Couldnt create Clan : {message.Name}");
                session.SendAsync(new ClubCreateAck2Message(1));
            }
            else
            {
                //using (_sync.Lock())
                {
                    var clubDto = new ClubDto
                    {
                        Name = message.Name,
                        Icon = ""
                    };

                    using (var db = GameDatabase.Open())
                    {
                        try
                        {
                            using (var transaction = db.BeginTransaction())
                            {
                                var playerAcc = db.Find <AccountDto>(statement => statement
                                                                     .Where($"{nameof(AccountDto.Id):C} = @Id")
                                                                     .WithParameters(new { session.Player.Account.Id })).FirstOrDefault();

                                db.Insert(clubDto, statement => statement.AttachToTransaction(transaction));

                                var club = new Club(clubDto, new[]
                                {
                                    new ClubPlayerInfo
                                    {
                                        AccountId = session.Player.Account.Id,
                                        Account   = playerAcc,
                                        State     = ClubState.Member,
                                        Rank      = ClubRank.Master
                                    }
                                });
                                GameServer.Instance.ClubManager.Add(club);
                                transaction.Commit();

                                db.Insert(new ClubPlayerDto
                                {
                                    PlayerId = (int)session.Player.Account.Id,
                                    ClubId   = club.Id,
                                    Rank     = (byte)ClubRank.Normal,
                                    State    = (int)ClubState.Member
                                });

                                session.Player.Club = club;
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex.ToString());
                            session.SendAsync(new ClubCreateAck2Message(1));
                            return;
                        }

                        session.SendAsync(new ClubCreateAck2Message(0));
                        session.SendAsync(new ClubMyInfoAckMessage(plr.Map <Player, ClubMyInfoDto>()));
                        Club.LogOn(plr);
                    }
                }
            }
        }