コード例 #1
0
        /// <summary>
        /// Load Characters, this is the Entrypoint for the Client, Wait for 3 Packets.
        /// </summary>
        /// <param name="packet"></param>
        /// <returns></returns>
        public void LoadCharacters(EntryPointPacket packet)
        {
            if (Session.Account == null)
            {
                AccountDTO account = null;

                string name = packet.Name;
                account = DAOFactory.AccountDAO.FirstOrDefault(s => s.Name == name);

                if (account != null)
                {
                    if (account.Password.ToLower().Equals(EncryptionHelper.Sha512(packet.Password).ToLower()))
                    {
                        AccountDTO accountobject = new AccountDTO
                        {
                            AccountId = account.AccountId,
                            Name      = account.Name,
                            Password  = account.Password.ToLower(),
                            Authority = account.Authority
                        };
                        accountobject.Initialize();
                        Session.InitializeAccount(accountobject);
                        //Send Account Connected
                    }
                    else
                    {
                        Logger.Log.ErrorFormat(LogLanguage.Instance.GetMessageFromKey("INVALID_PASSWORD"));
                        Session.Disconnect();
                        return;
                    }
                }
                else
                {
                    Logger.Log.ErrorFormat(LogLanguage.Instance.GetMessageFromKey("INVALID_ACCOUNT"));
                    Session.Disconnect();
                    return;
                }
            }


            if (Session.Account == null)
            {
                return;
            }

            IEnumerable <CharacterDTO> characters = DAOFactory.CharacterDAO.Where(s => s.AccountId == Session.Account.AccountId && s.State == CharacterState.Active);

            Logger.Log.InfoFormat(LogLanguage.Instance.GetMessageFromKey("ACCOUNT_ARRIVED"), Session.Account.Name);

            // load characterlist packet for each character in Character
            Session.SendPacket(new ClistStartPacket()
            {
                Type = 0
            });
            foreach (Character character in characters)
            {
                WearableInstance[] equipment = new WearableInstance[16];

                /* IEnumerable<ItemInstanceDTO> inventory = DAOFactory.IteminstanceDAO.Where(s => s.CharacterId == character.CharacterId && s.Type == (byte)InventoryType.Wear);
                 *
                 *
                 * foreach (ItemInstanceDTO equipmentEntry in inventory)
                 * {
                 *   // explicit load of iteminstance
                 *   WearableInstance currentInstance = equipmentEntry as WearableInstance;
                 *   equipment[(short)currentInstance.Item.EquipmentSlot] = currentInstance;
                 *
                 * }
                 */
                List <short?>  petlist = new List <short?>();
                List <MateDTO> mates   = DAOFactory.MateDAO.Where(s => s.CharacterId == character.CharacterId).ToList();
                for (int i = 0; i < 26; i++)
                {
                    if (mates.Count > i)
                    {
                        petlist.Add(mates.ElementAt(i).Skin);
                        petlist.Add(mates.ElementAt(i).VNum);
                    }
                    else
                    {
                        petlist.Add(-1);
                    }
                }

                // 1 1 before long string of -1.-1 = act completion
                Session.SendPacket(new ClistPacket()
                {
                    Slot       = character.Slot,
                    Name       = character.Name,
                    Unknown    = 0,
                    Gender     = (byte)character.Gender,
                    HairStyle  = (byte)character.HairStyle,
                    HairColor  = (byte)character.HairColor,
                    Unknown1   = 0,
                    Class      = (CharacterClassType)character.Class,
                    Level      = character.Level,
                    HeroLevel  = character.HeroLevel,
                    Equipments = new List <short?>()
                    {
                        { equipment[(byte)EquipmentType.Hat]?.VNum ?? -1 },
                        { equipment[(byte)EquipmentType.Armor]?.VNum ?? -1 },
                        { equipment[(byte)EquipmentType.WeaponSkin]?.VNum ?? (equipment[(byte)EquipmentType.MainWeapon]?.VNum ?? -1) },
                        { equipment[(byte)EquipmentType.SecondaryWeapon]?.VNum ?? -1 },
                        { equipment[(byte)EquipmentType.Mask]?.VNum ?? -1 },
                        { equipment[(byte)EquipmentType.Fairy]?.VNum ?? -1 },
                        { equipment[(byte)EquipmentType.CostumeSuit]?.VNum ?? -1 },
                        { equipment[(byte)EquipmentType.CostumeHat]?.VNum ?? -1 }
                    },
                    JobLevel        = character.JobLevel,
                    QuestCompletion = 1,
                    QuestPart       = 1,
                    Pets            = petlist,
                    Design          = (equipment[(byte)EquipmentType.Hat] != null && equipment[(byte)EquipmentType.Hat].Item.IsColored ? equipment[(byte)EquipmentType.Hat].Design : 0),
                    Unknown3        = 0
                });
            }
            Session.SendPacket(new ClistEndPacket());
        }