PSO2SERVER/Server/Protocol/Handlers/21-PaletteHandler/21-0A-SetDefaultPAs.cs
2024-12-10 21:54:32 +08:00

52 lines
1.9 KiB
C#

using System;
using PSO2SERVER.Models;
using PSO2SERVER.Protocol.Packets;
namespace PSO2SERVER.Protocol.Handlers
{
[PacketHandlerAttr(0x21, 0x0A)]
public class SetDefaultPAs : PacketHandler
{
public class SetDefaultPAsPacket
{
public FixedList<uint> Default { get; set; } = new FixedList<uint>(0x1A0, 0);
// 从数据流中读取数据并填充到 Default 列表
public static SetDefaultPAsPacket ReadFromStream(PacketReader reader)
{
// 假设 Default 是该类的静态字段,因此直接访问
SetDefaultPAsPacket packet = new SetDefaultPAsPacket();
// 从流中读取 uint 类型的数据并填充到 Default 列表
for (var i = 0; i < (int)packet.Default.Capacity; i++)
{
packet.Default[i] = reader.ReadUInt32(); // 读取 uint 值并存入 Default 列表
}
return packet;
}
// 将 Default 列表的数据写入到数据流
public void WriteToStream(PacketWriter writer)
{
// 将 Default 列表中的每个 uint 元素写入数据流
for (var i = 0; i < (int)Default.Capacity; i++)
{
writer.Write(Default[i]); // 写入 uint 值
}
}
}
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
var info = string.Format("[<--] 接收到的数据 (hex): {0} 字节", data.Length);
Logger.WriteHex(info, data);
var reader = new PacketReader(data, position, size);
var packet = SetDefaultPAsPacket.ReadFromStream(reader);
context.SendPacket(new NewDefaultPAsPacket(packet.Default));
}
}
}