PSO2SERVER/Server/Protocol/Handlers/11-ClientHandler/11-06-DeleteCharacter.cs

49 lines
1.5 KiB
C#
Raw Normal View History

2024-09-16 02:56:02 +08:00
using System;
using System.IO;
using PSO2SERVER.Protocol.Packets;
2024-09-16 02:56:02 +08:00
using PSO2SERVER.Database;
using static PSO2SERVER.Protocol.Packets.CharacterDeletionPacket;
2024-09-16 02:56:02 +08:00
namespace PSO2SERVER.Protocol.Handlers
2024-09-16 02:56:02 +08:00
{
[PacketHandlerAttr(0x11, 0x06)]
public class DeleteCharacter : PacketHandler
{
#region implemented abstract members of PacketHandler
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
var reader = new PacketReader(data);
var CharacterID = reader.ReadInt32();
2024-09-16 02:56:02 +08:00
Logger.Write("[CHR] {0} 正在删除ID {1} 的角色", context._account.Username, CharacterID);
2024-09-16 02:56:02 +08:00
// Delete Character
using (var db = new ServerEf())
{
foreach (var character in db.Characters)
if (character.CharacterID == CharacterID)
2024-09-16 02:56:02 +08:00
{
db.Characters.Remove(character);
db.ChangeTracker.DetectChanges();
break;
}
// Detect the deletion and save the Database
if (db.ChangeTracker.HasChanges())
2024-09-20 16:10:43 +08:00
{
2024-09-16 02:56:02 +08:00
db.SaveChanges();
2024-09-20 16:10:43 +08:00
}
2024-09-16 02:56:02 +08:00
}
2024-09-20 16:10:43 +08:00
context.SendPacket(new CharacterDeletionPacket(DeletionStatus.Success));
//context.SendPacket(new CharacterDeletionPacket(DeletionStatus.UndeletableItems));
2024-09-16 02:56:02 +08:00
}
#endregion
}
}