PSO2SERVER/Server/Packets/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.Packets.PSOPackets;
using PSO2SERVER.Database;
2024-09-20 16:10:43 +08:00
using static PSO2SERVER.Packets.PSOPackets.CharacterDeletionPacket;
2024-09-16 02:56:02 +08:00
namespace PSO2SERVER.Packets.Handlers
{
[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 id = reader.ReadInt32();
2024-09-20 21:58:37 +08:00
Logger.Write("[CHR] {0} 正在删除ID {1} 的角色", context._account.Username, id);
2024-09-16 02:56:02 +08:00
// Delete Character
using (var db = new ServerEf())
{
foreach (var character in db.Characters)
2024-09-20 16:10:43 +08:00
if (character.Character_ID == id)
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
}
}