mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-06-09 05:54:50 +02:00
Ported over the network code from the map server. A lot of backedlogged changes are here as well.
This commit is contained in:
parent
af4a0d5546
commit
8c73f6e926
12 changed files with 443 additions and 184 deletions
|
@ -12,24 +12,31 @@ namespace FFXIVClassic_Lobby_Server.packets
|
|||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct SubPacketHeader
|
||||
{
|
||||
public ushort subpacketSize;
|
||||
public ushort unknown0; //Always 0x03
|
||||
public uint sourceId;
|
||||
public uint targetId;
|
||||
public uint unknown1;
|
||||
public ushort unknown4; //Always 0x14
|
||||
public ushort opcode;
|
||||
public uint unknown5;
|
||||
public uint timestamp;
|
||||
public uint unknown6;
|
||||
public ushort subpacketSize;
|
||||
public ushort type;
|
||||
public uint sourceId;
|
||||
public uint targetId;
|
||||
public uint unknown1;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct GameMessageHeader
|
||||
{
|
||||
public ushort unknown4; //Always 0x14
|
||||
public ushort opcode;
|
||||
public uint unknown5;
|
||||
public uint timestamp;
|
||||
public uint unknown6;
|
||||
}
|
||||
|
||||
public class SubPacket
|
||||
{
|
||||
public const int SUBPACKET_SIZE = 0x20;
|
||||
public const int SUBPACKET_SIZE = 0x10;
|
||||
public const int GAMEMESSAGE_SIZE = 0x10;
|
||||
|
||||
public SubPacketHeader header;
|
||||
public byte[] data;
|
||||
public SubPacketHeader header;
|
||||
public GameMessageHeader gameMessage;
|
||||
public byte[] data;
|
||||
|
||||
public unsafe SubPacket(byte[] bytes, ref int offset)
|
||||
{
|
||||
|
@ -41,11 +48,27 @@ namespace FFXIVClassic_Lobby_Server.packets
|
|||
header = (SubPacketHeader)Marshal.PtrToStructure(new IntPtr(pdata), typeof(SubPacketHeader));
|
||||
}
|
||||
|
||||
if (header.type == 0x3)
|
||||
{
|
||||
fixed (byte* pdata = &bytes[offset + SUBPACKET_SIZE])
|
||||
{
|
||||
gameMessage = (GameMessageHeader)Marshal.PtrToStructure(new IntPtr(pdata), typeof(GameMessageHeader));
|
||||
}
|
||||
}
|
||||
|
||||
if (bytes.Length < offset + header.subpacketSize)
|
||||
throw new OverflowException("Packet Error: Subpacket size didn't equal subpacket data");
|
||||
|
||||
data = new byte[header.subpacketSize - SUBPACKET_SIZE];
|
||||
Array.Copy(bytes, offset + SUBPACKET_SIZE, data, 0, data.Length);
|
||||
if (header.type == 0x3)
|
||||
{
|
||||
data = new byte[header.subpacketSize - SUBPACKET_SIZE - GAMEMESSAGE_SIZE];
|
||||
Array.Copy(bytes, offset + SUBPACKET_SIZE + GAMEMESSAGE_SIZE, data, 0, data.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
data = new byte[header.subpacketSize - SUBPACKET_SIZE];
|
||||
Array.Copy(bytes, offset + SUBPACKET_SIZE, data, 0, data.Length);
|
||||
}
|
||||
|
||||
offset += header.subpacketSize;
|
||||
}
|
||||
|
@ -53,22 +76,34 @@ namespace FFXIVClassic_Lobby_Server.packets
|
|||
public SubPacket(ushort opcode, uint sourceId, uint targetId, byte[] data)
|
||||
{
|
||||
this.header = new SubPacketHeader();
|
||||
header.opcode = opcode;
|
||||
this.gameMessage = new GameMessageHeader();
|
||||
|
||||
gameMessage.opcode = opcode;
|
||||
header.sourceId = sourceId;
|
||||
header.targetId = targetId;
|
||||
|
||||
UInt32 unixTimestamp = (UInt32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
header.timestamp = unixTimestamp;
|
||||
gameMessage.timestamp = Utils.UnixTimeStampUTC();
|
||||
|
||||
header.unknown0 = 0x03;
|
||||
header.type = 0x03;
|
||||
header.unknown1 = 0x00;
|
||||
header.unknown4 = 0x14;
|
||||
header.unknown5 = 0x00;
|
||||
header.unknown6 = 0x00;
|
||||
gameMessage.unknown4 = 0x14;
|
||||
gameMessage.unknown5 = 0x00;
|
||||
gameMessage.unknown6 = 0x00;
|
||||
|
||||
this.data = data;
|
||||
|
||||
header.subpacketSize = (ushort)(0x20 + data.Length);
|
||||
header.subpacketSize = (ushort)(SUBPACKET_SIZE + GAMEMESSAGE_SIZE + data.Length);
|
||||
}
|
||||
|
||||
public SubPacket(SubPacket original, uint newTargetId)
|
||||
{
|
||||
this.header = new SubPacketHeader();
|
||||
this.gameMessage = original.gameMessage;
|
||||
header.subpacketSize = original.header.subpacketSize;
|
||||
header.type = original.header.type;
|
||||
header.sourceId = original.header.sourceId;
|
||||
header.targetId = newTargetId;
|
||||
data = original.data;
|
||||
}
|
||||
|
||||
public byte[] getHeaderBytes()
|
||||
|
@ -83,11 +118,27 @@ namespace FFXIVClassic_Lobby_Server.packets
|
|||
return arr;
|
||||
}
|
||||
|
||||
public byte[] getGameMessageBytes()
|
||||
{
|
||||
int size = Marshal.SizeOf(gameMessage);
|
||||
byte[] arr = new byte[size];
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal(size);
|
||||
Marshal.StructureToPtr(gameMessage, ptr, true);
|
||||
Marshal.Copy(ptr, arr, 0, size);
|
||||
Marshal.FreeHGlobal(ptr);
|
||||
return arr;
|
||||
}
|
||||
|
||||
public byte[] getBytes()
|
||||
{
|
||||
byte[] outBytes = new byte[header.subpacketSize];
|
||||
Array.Copy(getHeaderBytes(), 0, outBytes, 0, SUBPACKET_SIZE);
|
||||
Array.Copy(data, 0, outBytes, SUBPACKET_SIZE, data.Length);
|
||||
|
||||
if (header.type == 0x3)
|
||||
Array.Copy(getGameMessageBytes(), 0, outBytes, SUBPACKET_SIZE, GAMEMESSAGE_SIZE);
|
||||
|
||||
Array.Copy(data, 0, outBytes, SUBPACKET_SIZE + (header.type == 0x3 ? GAMEMESSAGE_SIZE : 0), data.Length);
|
||||
return outBytes;
|
||||
}
|
||||
|
||||
|
@ -95,8 +146,12 @@ namespace FFXIVClassic_Lobby_Server.packets
|
|||
{
|
||||
#if DEBUG
|
||||
Console.BackgroundColor = ConsoleColor.DarkRed;
|
||||
Console.WriteLine("Size: 0x{0:X}, Opcode: 0x{1:X}", header.subpacketSize, header.opcode);
|
||||
Console.WriteLine("Size: 0x{0:X}", header.subpacketSize);
|
||||
if (header.type == 0x03)
|
||||
Console.WriteLine("Opcode: 0x{0:X}", gameMessage.opcode);
|
||||
Console.WriteLine("{0}", Utils.ByteArrayToHex(getHeaderBytes()));
|
||||
if (header.type == 0x03)
|
||||
Console.WriteLine("{0}", Utils.ByteArrayToHex(getGameMessageBytes()));
|
||||
Console.BackgroundColor = ConsoleColor.DarkMagenta;
|
||||
Console.WriteLine("{0}", Utils.ByteArrayToHex(data));
|
||||
Console.BackgroundColor = ConsoleColor.Black;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue