Example #1
0
        public async Task CGuildRegisteInfo(GSSession session)
        {
            var siege = Program.EventManager.GetEvent <CastleSiege>();

            var rank      = siege.AttackGuild.OrderByDescending(x => x.Marks).ToList();
            var guildInfo = rank.FirstOrDefault(x => x.Guild == session.Player.Character.Guild);

            var msg = new SGuildRegisteInfo
            {
                Result    = 0,
                GuildName = session.Player.Character.Guild?.Name ?? "",
            };

            if (guildInfo != null)
            {
                msg.Result    = 1;
                msg.RegRank   = (byte)(rank.IndexOf(guildInfo) + 1);
                msg.IsGiveUp  = (byte)(guildInfo.GiveUp ? 1 : 0);
                msg.GuildMark = guildInfo.Marks;
            }

            await session.SendAsync(msg);
        }
Example #2
0
        public async Task CGuildRemoveUser(GSSession session, CGuildRemoveUser message)
        {
            var log   = Logger.ForAccount(session);
            var guild = session.Player.Character.Guild;

            if (guild == null)
            {
                await session.SendAsync(new SGuildRemoveUser(GuildResult.NotExist));

                return;
            }

            if (guild.Master.Player != session.Player)
            {
                await session.SendAsync(new SGuildRemoveUser(GuildResult.NotExistPermission));

                return;
            }

            var memb = guild.Find(message.Name);

            if (memb == null)
            {
                return;
            }

            if (memb.Name == session.Player.Character.Name)
            {
                await session.SendAsync(new SGuildRemoveUser(GuildResult.NotExistPermission));

                return;
            }

            guild.Remove(memb);
            await session.SendAsync(new SGuildRemoveUser(GuildResult.Success));
        }
Example #3
0
        public async Task SRelationShipJoinBreakOff(GSSession session, SRelationShipJoinBreakOff message)
        {
            var       src = session.Player.Character;
            Character dst = null;

            if (message.wzTargetUserIndex.ShufleEnding() != session.Player.ID)
            {
                dst = Program.server.Clients.First(x => x.ID == message.wzTargetUserIndex.ShufleEnding()).Player.Character;
            }
            else if (message.RelationShipType == GuildRelationShipType.Union)
            {
                dst = src.Guild.Union.First().Master.Player?.Character ?? null;
            }
            else if (message.RelationShipType == GuildRelationShipType.Rivals)
            {
                dst = src.Guild.Rival.First().Master.Player?.Character ?? null;
            }

            if (message.Result == 1)
            {
                if (dst != null)
                {
                    src.Guild.ChangeRelation(dst.Guild, message.RequestType, message.RelationShipType);
                }
                else if (message.RelationShipType == GuildRelationShipType.Union)
                {
                    src.Guild.ChangeRelation(src.Guild.Union.First(), message.RequestType, message.RelationShipType);
                }
                else if (message.RelationShipType == GuildRelationShipType.Rivals)
                {
                    src.Guild.ChangeRelation(src.Guild.Rival.First(), message.RequestType, message.RelationShipType);
                }

                message.wzTargetUserIndex = dst.Player.ID.ShufleEnding();
                _ = src.Player.Session.SendAsync(message);

                if (dst != null)
                {
                    message.wzTargetUserIndex = src.Player.ID.ShufleEnding();
                    _ = dst.Player.Session.SendAsync(message);
                    CGuildReqViewport(dst.Player.Session, new MU.Network.Guild.CGuildReqViewport {
                        Guild = dst.Guild.Index
                    });
                    CGuildReqViewport(dst.Player.Session, new MU.Network.Guild.CGuildReqViewport {
                        Guild = src.Guild.Index
                    });
                }
                CGuildReqViewport(src.Player.Session, new MU.Network.Guild.CGuildReqViewport {
                    Guild = dst.Guild.Index
                });
                CGuildReqViewport(src.Player.Session, new MU.Network.Guild.CGuildReqViewport {
                    Guild = src.Guild.Index
                });

                Logger.Information("Relation Changed, {0} now have {1} to {2} as {3}",
                                   dst.Guild.Name,
                                   message.RequestType,
                                   src.Guild.Name,
                                   message.RelationShipType);
            }
            else
            {
                message.wzTargetUserIndex = src.Player.ID.ShufleEnding();
                await dst.Player.Session.SendAsync(message);
            }
        }
Example #4
0
 public void CGuildListAll(GSSession session)
 {
     GuildManager.SendList(session.Player);
 }
Example #5
0
 public void CashInventoryItem(GSSession session, CCashInventoryItem message)
 {
     session.Player.Character.CashShop.SendInventory(message);
 }
Example #6
0
        public async Task CRelationShipJoinBreakOff(GSSession session, CRelationShipJoinBreakOff message)
        {
            var siege = Program.EventManager.GetEvent <CastleSiege>();

            if (siege.State >= SiegeStates.Notify && siege.State <= SiegeStates.StartSiege)
            {
                //MsgOutput(aIndex, Lang.GetText(0, 197));
                await session.SendAsync(new SNotice(NoticeType.Blue, ServerMessages.GetMessage(Messages.Guild_RelationShipCantChange)));

                return;
            }

            Character src, dst;

            src = session.Player.Character;
            if (message.TargetUserIndex == 0)
            {
                dst = GuildManager.Instance.Guilds.FirstOrDefault(x => x.Value.Name == message.Guild).Value.Master?.Player?.Character ?? null;
            }
            else
            {
                dst = Program.server.Clients.FirstOrDefault(x => x.ID == message.TargetUserIndex)?.Player?.Character ?? null;
            }

            if (dst == null)
            {
                await session.SendAsync(new SGuildResult(GuildResult.PlayerOffline));

                return;
            }

            if (src.Guild == null || dst.Guild == null)
            {
                await session.SendAsync(new SGuildResult(GuildResult.HaveGuild));

                return;
            }

            if (src.Guild.Master.Player != src.Player || dst.Guild.Master.Player != dst.Player)
            {
                await session.SendAsync(new SGuildResult(GuildResult.NotGuildMaster));

                return;
            }

            if (src.Player.Window != null || dst.Player.Window != null)
            {
                await session.SendAsync(new SGuildResult(GuildResult.InTransaction));

                return;
            }

            var errmsg = new SRelationShipJoinBreakOff
            {
                RequestType       = message.RequestType,
                Result            = 0,
                RelationShipType  = message.RelationShipType,
                wzTargetUserIndex = message.wzTargetUserIndex,
            };

            switch (message.RequestType)
            {
            case GuildUnionRequestType.Join:
                switch (message.RelationShipType)
                {
                case GuildRelationShipType.Union:
                    break;

                case GuildRelationShipType.Rivals:
                    break;
                }
                break;

            case GuildUnionRequestType.BreakOff:
                switch (message.RelationShipType)
                {
                case GuildRelationShipType.Union:
                    break;

                case GuildRelationShipType.Rivals:
                    break;
                }
                break;
            }

            message.wzTargetUserIndex = ((ushort)session.ID).ShufleEnding();
            await dst.Player.Session.SendAsync(message);
        }
Example #7
0
        public async Task CCharacterCreate(GSSession session, CCharacterCreate message)
        {
            var log = Logger.ForAccount(session);

            using (var db = new GameContext())
            {
                var exists = (from @char in db.Characters
                              where @char.Name.ToLower() == message.Name.ToLower()
                              select @char).Any();

                if (exists)
                {
                    log.Information("Character name {0} is in use", message.Name);
                    await session.SendAsync(new SCharacterCreate(0));

                    return;
                }

                log.Information("Creating character {0} class:{1}", message.Name, message.Class);

                var defaultChar = ResourceCache.Instance.GetDefChar()[message.Class];

                var gate = ResourceCache.Instance.GetGates()
                           .Where(s => s.Value.Map == defaultChar.Map && s.Value.GateType == GateType.Warp)
                           .Select(s => s.Value)
                           .FirstOrDefault();

                var rand = new Random();
                var x    = (byte)rand.Next(gate?.Door.Left ?? 0, gate?.Door.Right ?? 126);
                var y    = (byte)rand.Next(gate?.Door.Top ?? 0, gate?.Door.Bottom ?? 126);

                var newChar = new MU.DataBase.CharacterDto
                {
                    AccountId     = session.Player.Account.ID,
                    Class         = (byte)message.Class,
                    Experience    = 0,
                    GuildId       = null,
                    Level         = defaultChar.Level,
                    LevelUpPoints = 0,
                    Name          = message.Name,
                    Quests        = new List <MU.DataBase.QuestDto>(),
                    Items         = new List <MU.DataBase.ItemDto>(),
                    // Map
                    Map = (byte)defaultChar.Map,
                    X   = x,
                    Y   = y,
                    // Stats
                    Str      = (ushort)defaultChar.Stats.Str,
                    Agility  = (ushort)defaultChar.Stats.Agi,
                    Vitality = (ushort)defaultChar.Stats.Vit,
                    Energy   = (ushort)defaultChar.Stats.Ene,
                    Command  = (ushort)defaultChar.Stats.Cmd,
                    CtlCode  = 0,
                    Life     = (ushort)defaultChar.Attributes.Life,
                    Mana     = (ushort)defaultChar.Attributes.Mana,
                    MaxLife  = (ushort)defaultChar.Attributes.Life,
                    MaxMana  = (ushort)defaultChar.Attributes.Mana,
                    Resets   = 0
                };

                db.Characters.Add(newChar);
                db.SaveChanges();

                var position = (byte)session.Player.Account.Characters.Count();

                session.Player.Account.Characters.Add(position, newChar);

                var items = defaultChar.Equipament.Select(eq => new MU.DataBase.ItemDto
                {
                    AccountId     = session.Player.Account.ID,
                    CharacterId   = newChar.CharacterId,
                    SlotId        = eq.Key,
                    DateCreation  = DateTime.Now,
                    Durability    = eq.Value.Durability,
                    HarmonyOption = eq.Value.Harmony.Option,
                    Luck          = eq.Value.Luck,
                    Number        = eq.Value.Number,
                    Option        = eq.Value.Option28,
                    OptionExe     = (byte)eq.Value.OptionExe,
                    Plus          = eq.Value.Plus,
                    Skill         = eq.Value.Skill,
                    SocketOptions = string.Join(",", eq.Value.Slots.Select(s => s.ToString())),
                });

                db.Items.AddRange(items.ToArray());
                db.SaveChanges();

                await session.SendAsync(new SCharacterCreate(1,
                                                             message.Name,
                                                             position,
                                                             newChar.Level,
                                                             Array.Empty <byte>(),
                                                             Character.GetClientClass(message.Class)
                                                             ));
            }
        }
Example #8
0
        public async Task CServerMove(GSSession session, CServerMove message)
        {
            Logger.ForAccount(session).Information("Server move recv");
            BuxDecode.Decode(message.btAccount);

            if (Program.server.ClientVersion != message.ClientVersion)
            {
                Logger.Error("Bad client version {0} != {1}", Program.server.ClientVersion, message.ClientVersion);
                await session.SendAsync(new SLoginResult(LoginResult.OldVersion));

                session.Disconnect();
                return;
            }

            if (Program.server.ClientSerial != message.ClientSerial)
            {
                Logger.Error("Bad client serial {0} != {1}", Program.server.ClientSerial, message.ClientSerial);
                await session.SendAsync(new SLoginResult(LoginResult.OldVersion));

                session.Disconnect();
                return;
            }

            using (var db = new GameContext())
            {
                var acc = (from account in db.Accounts
                           where string.Equals(account.Account, message.Account, StringComparison.InvariantCultureIgnoreCase)
                           select account)
                          .FirstOrDefault();

                var token = $"{message.AuthCode1:X8}{message.AuthCode2:X8}{message.AuthCode3:X8}{message.AuthCode4:X8}";

                if (acc.AuthToken != token)
                {
                    await session.SendAsync(new SLoginResult(LoginResult.ConnectionError));

                    return;
                }

                session.PreviousCode = (ushort)acc.ServerCode;
                acc.ServerCode       = Program.ServerCode;
                acc.IsConnected      = true;
                acc.LastConnection   = DateTime.Now;
                db.Accounts.Update(acc);
                db.SaveChanges();

                byte y = 0;
                session.Player.SetAccount(acc);
                var _acc = session.Player.Account;
                _acc.Characters = (from @char in db.Characters
                                   where @char.AccountId == acc.AccountId
                                   select @char).ToDictionary(x => y++);

                foreach (var @char in _acc.Characters)
                {
                    @char.Value.Items = (from item in db.Items
                                         where item.CharacterId == @char.Value.CharacterId
                                         select item).ToList();
                }
            }

            await CCharacterMapJoin2(session, new CCharacterMapJoin2 { Name = message.Character });
        }
Example #9
0
 public async Task CQuestEXPComplete(GSSession session, CQuestEXPComplete message)
 {
     var @char = session.Player.Character;
     await @char.Quests.QuestEXPCompleted(message.Index);
 }
Example #10
0
 public void AHCheck(GSSession session, CAHCheck message)
 {
 }
Example #11
0
        public void CKanturuEnterBossMap(GSSession session)
        {
            var kanturu = Program.EventManager.GetEvent <Kanturu>();

            kanturu.TryAdd(session.Player);
        }
Example #12
0
 public void CImperialGuardianEnter(GSSession session)
 {
     Program.EventManager.GetEvent <ImperialGuardian>()
     .TryAdd(session.Player);
 }
Example #13
0
        public void CKanturuStateInfo(GSSession session)
        {
            var kanturu = Program.EventManager.GetEvent <Kanturu>();

            kanturu.NPCTalk(session.Player);
        }
Example #14
0
 public void CCrywolfState(GSSession session)
 {
     Program.EventManager
     .GetEvent <Crywolf>()
     .SendState(session);
 }
Example #15
0
 public void CCrywolfBenefit(GSSession session)
 {
     Program.EventManager
     .GetEvent <Crywolf>()
     .SendBenefit(session);
 }
Example #16
0
 public async Task CQuestEXPProgressList(GSSession session)
 {
     await session.Player.Character.Quests.QuestEXPProgressList();
 }
Example #17
0
        public async Task CCharacterList(GSSession session)
        {
            using (var db = new GameContext())
            {
                var acc = session.Player.Account;

                byte y = 0;
                acc.Characters = (from @char in db.Characters
                                  where @char.AccountId == acc.ID
                                  select @char).ToDictionary(x => y++);

                var resetList = new SResetCharList();


                byte mClass = 0;

                var maxLevel = acc.Characters.Max(x => x.Value.Level);

                if (maxLevel > 200)
                {
                    mClass = 1;
                }
                else if (maxLevel > 210)
                {
                    mClass = 2;
                }
                else if (maxLevel > 220)
                {
                    mClass = 3;
                }
                else if (maxLevel > 250)
                {
                    mClass = 4;
                }


                var charList = VersionSelector.CreateMessage <SCharacterList>(mClass, (byte)0, (byte)5, (byte)3) as CharList;

                foreach (var @char in acc.Characters)
                {
                    @char.Value.Items = (from item in db.Items
                                         where item.CharacterId == @char.Value.CharacterId
                                         select item).ToList();

                    charList.AddChar(
                        @char.Key,
                        @char.Value,
                        Inventory.GetCharset((HeroClass)@char.Value.Class, new Inventory(null, @char.Value), 0),
                        GuildManager.Instance.FindCharacter(@char.Value.Name)?.Rank ?? GuildStatus.NoMember);
                }

                if (Program.Season == ServerSeason.Season9Eng)
                {
                    await session.SendAsync(resetList);
                }

                await session.SendAsync(charList);

                await session.SendAsync(new SEnableCreation {
                    EnableCreation = EnableClassCreation.Summoner | EnableClassCreation.RageFighter | EnableClassCreation.MagicGladiator | EnableClassCreation.GrowLancer | EnableClassCreation.DarkLord
                });
            }
        }
Example #18
0
 public async Task CQuestEXP(GSSession session, CQuestEXP message)
 {
     var @char = session.Player.Character;
     await @char.Quests.QuestEXPInfo(message.Index);
 }
Example #19
0
 public void CashItemBuy(GSSession session, CCashItemBuy message)
 {
     session.Player.Character.CashShop.BuyItem(message);
 }
Example #20
0
        public async Task CNewQuestInfo(GSSession session, CNewQuestInfo message)
        {
            if (message.dwQuestInfoIndexID == 0)
            {
                return;
            }
            var @char  = session.Player.Character;
            var quest2 = ResourceLoader.XmlLoader <QuestEXPDto>("./Data/QuestEXP.xml");

            QuestInfoIndex info = message.dwQuestInfoIndexID;// @char.Quests.GetEpisodeByIndex();

            var result = quest2
                         .QuestList
                         .FirstOrDefault(x => x.QuestInfo.Any(y => y.Episode == info.Episode))?
                         .QuestInfo
                         .FirstOrDefault(x => x.Episode == info.Episode) ?? null;

            if (result == null)
            {
                await session.SendAsync(new SQuestEXP { Result = 1 });

                return;
            }
            var state = result
                        .QuestState
                        .Where(x => x.State == info.Switch && (x.Class == @char.BaseClass || x.Class == HeroClass.End))
                        .FirstOrDefault();

            if (state == null)
            {
                await session.SendAsync(new SQuestEXP { Result = 1 });

                return;
            }

            byte rewardCount = 0;
            var  ask         = new AskInfoDto[5];
            var  reward      = new RewardInfoDto[5];

            for (var i = 0; i < 5; i++)
            {
                ask[i]    = new AskInfoDto();
                reward[i] = new RewardInfoDto();
            }

            if (state.RewardEXP > 0)
            {
                reward[rewardCount].Type  = RewardType.Exp;
                reward[rewardCount].Value = state.RewardEXP;
                rewardCount++;
            }

            if (state.RewardGENS > 0)
            {
                reward[rewardCount].Type  = RewardType.Point;
                reward[rewardCount].Value = state.RewardGENS;
                rewardCount++;
            }

            if (state.RewardZEN > 0)
            {
                reward[rewardCount].Type  = RewardType.Zen;
                reward[rewardCount].Value = state.RewardZEN;
                rewardCount++;
            }

            byte askCount = 0;

            switch (state.Type)
            {
            case AskType.Tutorial:
                ask[askCount].Type = state.Type;
                break;

            case AskType.Item:
                foreach (var it in state.Item)
                {
                    var item = new Item(ItemNumber.FromTypeIndex(it.Type, it.Index), Options: new { Plus = it.Level });

                    var list = @char.Inventory.FindAllItems(ItemNumber.FromTypeIndex(it.Type, it.Index))
                               .Where(x => x.Plus == it.Level && it.Skill == x.Skill && it.Option == x.Option28 && it.Excellent == x.OptionExe);

                    ask[askCount].Type         = state.Type;
                    ask[askCount].ItemInfo     = item.GetBytes();
                    ask[askCount].CurrentValue = (uint)list.Count();
                    ask[askCount].Value        = it.Count;
                    askCount++;
                }
                break;

            case AskType.Monster:
                var infoM = @char.Quests.GetEpisode <QuestInfoMonster>((int)info.Episode, info.Switch);
                infoM.Type = state.Type;
                foreach (var it in state.Monster)
                {
                    ask[askCount].Type         = state.Type;
                    ask[askCount].Index        = it.Index;
                    ask[askCount].CurrentValue = infoM.Current;
                    ask[askCount].Value        = it.Count;
                    infoM.MonsterClass         = it.Index;
                    askCount++;
                }
                break;
            }
            await session.SendAsync(new SSendQuestEXPInfo
            {
                dwQuestInfoIndexID = QuestInfoIndex.FromEpisodeSwitch(info.Episode, info.Switch),
                AskCnt             = askCount,
                RandRewardCnt      = 0,
                RewardCnt          = rewardCount,
                Asks    = ask,
                Rewards = reward,
            });
        }
Example #21
0
 public void AcheronEventEnter(GSSession session)
 {
     Program.EventManager.GetEvent <AcheronGuardian>()
     .TryAdd(session.Player);
 }
Example #22
0
        public async Task CCharacterMapJoin2(GSSession session, CCharacterMapJoin2 Character)
        {
            var charDto = session.Player.Account.Characters
                          .Select(x => x.Value)
                          .FirstOrDefault(x => x.Name == Character.Name);

            if (!MapServerManager.CheckMapServerMove(session, (Maps)charDto.Map))
            {
                return;
            }

            using (var db = new GameContext())
            {
                charDto.Items = (from it in db.Items
                                 where it.CharacterId == charDto.CharacterId
                                 select it).ToList();

                charDto.Spells = (from spell in db.Spells
                                  where spell.CharacterId == charDto.CharacterId
                                  select spell).ToList();

                charDto.Quests = (from quest in db.Quests
                                  where quest.CharacterId == charDto.CharacterId
                                  select quest).ToList();

                charDto.QuestEX = (from quest in db.QuestsEX
                                   where quest.CharacterId == charDto.CharacterId
                                   select quest).ToList();

                charDto.SkillKey = (from config in db.Config
                                    where config.SkillKeyId == charDto.CharacterId
                                    select config).FirstOrDefault();

                charDto.Favorites = (from config in db.Favorites
                                     where config.CharacterId == charDto.CharacterId
                                     select config).FirstOrDefault();

                charDto.Friends = (from friend in db.Friends
                                   where (friend.FriendId == charDto.CharacterId || friend.CharacterId == charDto.CharacterId) && friend.State == 1
                                   select friend).ToList();

                charDto.Memos = (from letter in db.Letters
                                 where letter.CharacterId == charDto.CharacterId
                                 select letter).ToList();

                charDto.MasterInfo = (from mi in db.MasterLevel
                                      where mi.MasterInfoId == charDto.CharacterId
                                      select mi).FirstOrDefault();

                charDto.GremoryCases = (from gc in db.GremoryCase
                                        where gc.CharacterId == charDto.CharacterId && (gc.AccountId == charDto.AccountId && gc.Inventory == 1)
                                        select gc).ToList();
            }

            if (@charDto == null)
            {
                return;
            }

            await session.SendAsync(new SCheckSum { Key = session.Player.CheckSum.GetKey(), Padding = 0xff });

            session.Player.Character = new Character(session.Player, @charDto);
            var @char = session.Player.Character;

            await session.SendAsync(new SPeriodItemCount());

            await session.SendAsync(new SKillCount { KillCount = 1 });

            if (charDto.SkillKey != null)
            {
                var skillKey = new SSkillKey
                {
                    SkillKey   = charDto.SkillKey.SkillKey,
                    ChatWindow = charDto.SkillKey.ChatWindow,
                    E_Key      = charDto.SkillKey.EkeyDefine,
                    GameOption = charDto.SkillKey.GameOption,
                    Q_Key      = charDto.SkillKey.QkeyDefine,
                    R_Key      = charDto.SkillKey.RkeyDefine,
                    W_Key      = charDto.SkillKey.WkeyDefine,
                };
                if (skillKey.SkillKey == null)
                {
                    skillKey.SkillKey = Array.Empty <byte>();
                }
                await session.SendAsync(skillKey);
            }
            if (charDto.Favorites != null)
            {
                var fav = new CFavoritesList
                {
                    Region = new int[]
                    {
                        charDto.Favorites.Fav01,
                        charDto.Favorites.Fav02,
                        charDto.Favorites.Fav03,
                        charDto.Favorites.Fav04,
                        charDto.Favorites.Fav05,
                    }
                };

                await session.SendAsync(fav);
            }
            session.Player.Status = LoginStatus.Playing;

            GuildManager.Instance.AddPlayer(session.Player);

            //await session.SendAsync(new SNewQuestInfo());
            session.Player.Character.Inventory.SendJewelsInfo();

            await session.SendAsync(new SUBFInfo { Result = 1 });

            await session.SendAsync(new SMapMoveCheckSum { key = 0x0010 });

            //ConnectServer dataSend
            Program.client.SendAsync(new SCAdd {
                Server = (byte)Program.ServerCode, btName = @charDto.Name.GetBytes()
            });

            if ((@char.CtlCode & ControlCode.GameMaster) == ControlCode.GameMaster)
            {
                @char.Spells.SetBuff(SkillStates.GameMaster, TimeSpan.FromDays(100));
            }

            @char.DataLoaded = true;
        }
Example #23
0
        public async Task CLuckyCoinsRegistre(GSSession session /*, CLuckyCoinsRegistre message*/)
        {
            var coins = await LuckyCoins.Registre(session.Player);

            await session.SendAsync(new SLuckyCoinsCount(coins));
        }
Example #24
0
        public async Task CIDAndPass(GSSession session, CIDAndPass message)
        {
            BuxDecode.Decode(message.btAccount);
            BuxDecode.Decode(message.btPassword);

            if (session.TryLoginCount > 2)
            {
                await session.SendAsync(new SLoginResult(LoginResult.ConnectionClosed3Fail));

                return;
            }

            if (Program.server.ClientVersion != message.ClientVersion)
            {
                Logger.Error("Bad client version {0} != {1}", Program.server.ClientVersion, message.ClientVersion);
                await session.SendAsync(new SLoginResult(LoginResult.OldVersion));

                session.Disconnect();
                return;
            }

            if (Program.server.ClientSerial != message.ClientSerial)
            {
                Logger.Error("Bad client serial {0} != {1}", Program.server.ClientSerial, message.ClientSerial);
                await session.SendAsync(new SLoginResult(LoginResult.OldVersion));

                session.Disconnect();
                return;
            }

            if (string.IsNullOrWhiteSpace(message.Account) || string.IsNullOrWhiteSpace(message.Password))
            {
                await session.SendAsync(new SLoginResult(LoginResult.AccountError));

                return;
            }

            using (var db = new GameContext())
            {
                var acc = (from account in db.Accounts
                           where account.Account.ToLower() == message.Account.ToLower()
                           select account)
                          .SingleOrDefault();

                if (acc == null)
                {
                    Logger.Information("Account {0} Don't exists", message.Account);
                    if (!Program.AutoRegistre)
                    {
                        await session.SendAsync(new SLoginResult(LoginResult.AccountError));

                        return;
                    }
                    else
                    {
                        acc = new MU.DataBase.AccountDto
                        {
                            Account = message.Account,
                            //Password = Convert.ToBase64String(hash),
                            //Salt = Convert.ToBase64String(newSalt),
                            Characters     = new List <MU.DataBase.CharacterDto>(),
                            VaultCount     = 1,
                            VaultMoney     = 0,
                            LastConnection = DateTime.Now,
                            IsConnected    = false,
                            ServerCode     = 0,
                        };

                        string Salt = "";
                        acc.Password = GetHashPassword(message.Password, ref Salt);
                        acc.Salt     = Salt;
                        db.Accounts.Add(acc);
                        db.SaveChanges();
                        Logger.Information("Account Created");
                    }
                }


                var salt = acc.Salt;
                if (string.IsNullOrEmpty(salt))
                {
                    acc.Password = GetHashPassword(acc.Password, ref salt);
                    acc.Salt     = salt;
                }

                if (acc.Password != GetHashPassword(message.Password, ref salt))
                {
                    await session.SendAsync(new SLoginResult(LoginResult.PasswordError));

                    session.TryLoginCount++;
                    return;
                }

                if (acc.IsConnected == true)
                {
                    await session.SendAsync(new SLoginResult(LoginResult.IsConnected));

                    return;
                }

                session.PreviousCode = 0xffff;
                acc.ServerCode       = Program.ServerCode;
                acc.IsConnected      = true;
                acc.LastConnection   = DateTime.Now;
                db.Accounts.Update(acc);
                db.SaveChanges();

                session.Player.SetAccount(acc);
            }

            await session.SendAsync(new SLoginResult(LoginResult.Ok));
        }
Example #25
0
 public void CGuildInfoSave(GSSession session, CGuildInfoSave message)
 {
     Logger.ForAccount(session).Debug("Create Guild: {0}:{1}", message.Name, message.Type);
     GuildManager.CreateGuild(session.Player, message.Name, message.Mark, message.Type);
 }
Example #26
0
 public void LiveClient(GSSession session, CLiveClient message)
 {
 }
Example #27
0
 public void CashPoints(GSSession session)
 {
     session.Player.Character.CashShop.SendPoints();
 }