2024-09-10 01:13:20 +08:00
|
|
|
|
using PSO2SERVER.Models;
|
2024-12-11 02:24:51 +08:00
|
|
|
|
using System;
|
2024-12-06 19:47:18 +08:00
|
|
|
|
using System.Collections.Generic;
|
2024-09-10 00:31:40 +08:00
|
|
|
|
|
2024-11-27 18:05:53 +08:00
|
|
|
|
namespace PSO2SERVER.Protocol
|
2024-09-10 00:31:40 +08:00
|
|
|
|
{
|
|
|
|
|
public abstract class Packet
|
|
|
|
|
{
|
|
|
|
|
public abstract byte[] Build();
|
|
|
|
|
public abstract PacketHeader GetHeader();
|
2024-12-06 19:47:18 +08:00
|
|
|
|
|
|
|
|
|
// 新增:获取整体数据包字节表示
|
|
|
|
|
public byte[] GetPacketBytes()
|
|
|
|
|
{
|
|
|
|
|
var header = GetHeader(); // 获取包头
|
|
|
|
|
var packetBody = Build(); // 获取包体
|
|
|
|
|
|
|
|
|
|
// 如果包头的大小为0,则重新计算
|
|
|
|
|
if (header.Size == 0)
|
|
|
|
|
{
|
|
|
|
|
// 包头(包括固定的前四个字节)的大小加上包体的大小
|
|
|
|
|
header.Size = (uint)(header.ToBytes().Length + packetBody.Length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将包头与包体合并
|
|
|
|
|
var totalPacket = new List<byte>();
|
|
|
|
|
totalPacket.AddRange(header.ToBytes()); // 包头转换为字节并加入
|
|
|
|
|
totalPacket.AddRange(packetBody); // 包体加入
|
|
|
|
|
|
|
|
|
|
return totalPacket.ToArray(); // 返回整个数据包字节数组
|
|
|
|
|
}
|
2024-09-10 00:31:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|