Example #1
0
        public static void HandleCharacterDelete(WorldSession session, ClientCharacterDelete characterDelete)
        {
            CharacterModel characterToDelete = session.Characters.FirstOrDefault(c => c.Id == characterDelete.CharacterId);

            (CharacterModifyResult, uint) GetResult()
            {
                if (characterToDelete == null)
                {
                    return(CharacterModifyResult.DeleteFailed, 0);
                }

                // TODO: Not sure if this is definitely the case, but put it in for good measure
                if (characterToDelete.Mail.Count > 0)
                {
                    foreach (CharacterMailModel characterMail in characterToDelete.Mail)
                    {
                        if (characterMail.Attachment.Count > 0)
                        {
                            return(CharacterModifyResult.DeleteFailed, 0);
                        }
                    }
                }

                uint leaderCount = (uint)GlobalGuildManager.Instance.GetCharacterGuilds(characterToDelete.Id)
                                   .Count(g => g.LeaderId == characterDelete.CharacterId);

                if (leaderCount > 0)
                {
                    return(CharacterModifyResult.DeleteFailed, leaderCount);
                }

                return(CharacterModifyResult.DeleteOk, 0);
            }

            (CharacterModifyResult result, uint data)deleteCheck = GetResult();
            if (deleteCheck.result != CharacterModifyResult.DeleteOk)
            {
                session.EnqueueMessageEncrypted(new ServerCharacterDeleteResult
                {
                    Result = deleteCheck.result,
                    Data   = deleteCheck.data
                });
                return;
            }

            session.CanProcessPackets = false;

            void Save(CharacterContext context)
            {
                var model = new CharacterModel
                {
                    Id = characterToDelete.Id
                };

                EntityEntry <CharacterModel> entity = context.Attach(model);

                model.DeleteTime = DateTime.UtcNow;
                entity.Property(e => e.DeleteTime).IsModified = true;

                model.OriginalName = characterToDelete.Name;
                entity.Property(e => e.OriginalName).IsModified = true;

                model.Name = null;
                entity.Property(e => e.Name).IsModified = true;
            }

            session.EnqueueEvent(new TaskEvent(DatabaseManager.Instance.CharacterDatabase.Save(Save),
                                               () =>
            {
                session.CanProcessPackets = true;

                ResidenceManager.Instance.RemoveResidence(characterToDelete.Name);
                CharacterManager.Instance.DeleteCharacter(characterToDelete.Id, characterToDelete.Name);

                session.EnqueueMessageEncrypted(new ServerCharacterDeleteResult
                {
                    Result = deleteCheck.result
                });
            }));
        }
Example #2
0
 public static void HandleCreateDelete(WorldSession session, ClientCharacterDelete characterDelete)
 {
 }
Example #3
0
        public static void HandleCharacterDelete(WorldSession session, ClientCharacterDelete characterDelete)
        {
            Character characterToDelete = session.Characters.FirstOrDefault(c => c.Id == characterDelete.CharacterId);

            CharacterModifyResult GetResult()
            {
                if (characterToDelete == null)
                {
                    return(CharacterModifyResult.DeleteFailed);
                }

                // TODO: Not sure if this is definitely the case, but put it in for good measure
                if (characterToDelete.CharacterMail.Count > 0)
                {
                    foreach (CharacterMail characterMail in characterToDelete.CharacterMail)
                    {
                        if (characterMail.CharacterMailAttachment.Count > 0)
                        {
                            return(CharacterModifyResult.DeleteFailed);
                        }
                    }
                }

                // TODO: Ensure character is not a guild master

                return(CharacterModifyResult.DeleteOk);
            }

            CharacterModifyResult result = GetResult();

            if (result != CharacterModifyResult.DeleteOk)
            {
                session.EnqueueMessageEncrypted(new ServerCharacterDeleteResult
                {
                    Result = result
                });
                return;
            }

            session.CanProcessPackets = false;

            void Save(CharacterContextExtended context)
            {
                var model = new Character
                {
                    Id = characterToDelete.Id
                };

                EntityEntry <Character> entity = context.Attach(model);

                model.DeleteTime = DateTime.UtcNow;
                entity.Property(e => e.DeleteTime).IsModified = true;

                model.OriginalName = characterToDelete.Name;
                entity.Property(e => e.OriginalName).IsModified = true;

                model.Name = null;
                entity.Property(e => e.Name).IsModified = true;
            }

            session.EnqueueEvent(new TaskEvent(CharacterDatabase.Save(Save),
                                               () =>
            {
                session.CanProcessPackets = true;

                CharacterManager.Instance.DeleteCharacter(characterToDelete.Id);

                session.EnqueueMessageEncrypted(new ServerCharacterDeleteResult
                {
                    Result = result
                });
            }));
        }