mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-04-02 19:42:05 -04:00
Fixed bugs on how subpackets handled. Reorganized subpackets and split header with game header.
This commit is contained in:
parent
1d20f8b8b8
commit
235a5adae3
@ -89,15 +89,13 @@ namespace FFXIVClassic_Lobby_Server
|
|||||||
if (packet.header.isEncrypted == 0x01)
|
if (packet.header.isEncrypted == 0x01)
|
||||||
BasePacket.decryptPacket(client.blowfish, ref packet);
|
BasePacket.decryptPacket(client.blowfish, ref packet);
|
||||||
|
|
||||||
|
packet.debugPrintPacket();
|
||||||
|
|
||||||
List<SubPacket> subPackets = packet.getSubpackets();
|
List<SubPacket> subPackets = packet.getSubpackets();
|
||||||
foreach (SubPacket subpacket in subPackets)
|
foreach (SubPacket subpacket in subPackets)
|
||||||
{
|
{
|
||||||
//Console.WriteLine(client.getAddress());
|
if (subpacket.header.type == 0x01)
|
||||||
switch (subpacket.header.opcode)
|
|
||||||
{
|
{
|
||||||
//Initial
|
|
||||||
case 0x0000:
|
|
||||||
BasePacket init = InitPacket.buildPacket(0, Utils.UnixTimeStampUTC());
|
BasePacket init = InitPacket.buildPacket(0, Utils.UnixTimeStampUTC());
|
||||||
BasePacket reply2 = new BasePacket("./packets/login/login2.bin");
|
BasePacket reply2 = new BasePacket("./packets/login/login2.bin");
|
||||||
|
|
||||||
@ -173,6 +171,15 @@ namespace FFXIVClassic_Lobby_Server
|
|||||||
client.queuePacket(init);
|
client.queuePacket(init);
|
||||||
client.queuePacket(reply2);
|
client.queuePacket(reply2);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
else if (subpacket.header.type == 0x08)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (subpacket.header.type == 0x03)
|
||||||
|
{
|
||||||
|
switch (subpacket.gameMessage.opcode)
|
||||||
|
{
|
||||||
//Ping
|
//Ping
|
||||||
case 0x0001:
|
case 0x0001:
|
||||||
//subpacket.debugPrintSubPacket();
|
//subpacket.debugPrintSubPacket();
|
||||||
@ -210,8 +217,8 @@ namespace FFXIVClassic_Lobby_Server
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
client.queuePacket(BasePacket.createPacket(SetMapPacket.buildPacket(player.actorID, 0xD1), true, false));
|
client.queuePacket(BasePacket.createPacket(SetMapPacket.buildPacket(player.actorID, 0xD1), true, false));
|
||||||
client.queuePacket(BasePacket.createPacket(SetMusicPacket.buildPacket(player.actorID, 0x3D, 0x01), true, false));
|
|
||||||
client.queuePacket(BasePacket.createPacket(_0x2Packet.buildPacket(player.actorID), true, false));
|
client.queuePacket(BasePacket.createPacket(_0x2Packet.buildPacket(player.actorID), true, false));
|
||||||
|
client.queuePacket(BasePacket.createPacket(SetMusicPacket.buildPacket(player.actorID, 0x3D, 0x01), true, false));
|
||||||
|
|
||||||
client.queuePacket(reply5);
|
client.queuePacket(reply5);
|
||||||
|
|
||||||
@ -348,12 +355,13 @@ namespace FFXIVClassic_Lobby_Server
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log.debug(String.Format("Unknown command 0x{0:X} received.", subpacket.header.opcode));
|
Log.debug(String.Format("Unknown command 0x{0:X} received.", subpacket.gameMessage.opcode));
|
||||||
subpacket.debugPrintSubPacket();
|
subpacket.debugPrintSubPacket();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void sendPacket(string path, int conn)
|
public void sendPacket(string path, int conn)
|
||||||
|
@ -13,10 +13,15 @@ namespace FFXIVClassic_Lobby_Server.packets
|
|||||||
public struct SubPacketHeader
|
public struct SubPacketHeader
|
||||||
{
|
{
|
||||||
public ushort subpacketSize;
|
public ushort subpacketSize;
|
||||||
public ushort unknown0; //Always 0x03
|
public ushort type;
|
||||||
public uint sourceId;
|
public uint sourceId;
|
||||||
public uint targetId;
|
public uint targetId;
|
||||||
public uint unknown1;
|
public uint unknown1;
|
||||||
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct GameMessageHeader
|
||||||
|
{
|
||||||
public ushort unknown4; //Always 0x14
|
public ushort unknown4; //Always 0x14
|
||||||
public ushort opcode;
|
public ushort opcode;
|
||||||
public uint unknown5;
|
public uint unknown5;
|
||||||
@ -26,9 +31,11 @@ namespace FFXIVClassic_Lobby_Server.packets
|
|||||||
|
|
||||||
public class SubPacket
|
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 SubPacketHeader header;
|
||||||
|
public GameMessageHeader gameMessage;
|
||||||
public byte[] data;
|
public byte[] data;
|
||||||
|
|
||||||
public unsafe SubPacket(byte[] bytes, ref int offset)
|
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));
|
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)
|
if (bytes.Length < offset + header.subpacketSize)
|
||||||
throw new OverflowException("Packet Error: Subpacket size didn't equal subpacket data");
|
throw new OverflowException("Packet Error: Subpacket size didn't equal subpacket data");
|
||||||
|
|
||||||
|
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];
|
data = new byte[header.subpacketSize - SUBPACKET_SIZE];
|
||||||
Array.Copy(bytes, offset + SUBPACKET_SIZE, data, 0, data.Length);
|
Array.Copy(bytes, offset + SUBPACKET_SIZE, data, 0, data.Length);
|
||||||
|
}
|
||||||
|
|
||||||
offset += header.subpacketSize;
|
offset += header.subpacketSize;
|
||||||
}
|
}
|
||||||
@ -53,21 +76,23 @@ namespace FFXIVClassic_Lobby_Server.packets
|
|||||||
public SubPacket(ushort opcode, uint sourceId, uint targetId, byte[] data)
|
public SubPacket(ushort opcode, uint sourceId, uint targetId, byte[] data)
|
||||||
{
|
{
|
||||||
this.header = new SubPacketHeader();
|
this.header = new SubPacketHeader();
|
||||||
header.opcode = opcode;
|
this.gameMessage = new GameMessageHeader();
|
||||||
|
|
||||||
|
gameMessage.opcode = opcode;
|
||||||
header.sourceId = sourceId;
|
header.sourceId = sourceId;
|
||||||
header.targetId = targetId;
|
header.targetId = targetId;
|
||||||
|
|
||||||
header.timestamp = Utils.UnixTimeStampUTC();
|
gameMessage.timestamp = Utils.UnixTimeStampUTC();
|
||||||
|
|
||||||
header.unknown0 = 0x03;
|
header.type = 0x03;
|
||||||
header.unknown1 = 0x00;
|
header.unknown1 = 0x00;
|
||||||
header.unknown4 = 0x14;
|
gameMessage.unknown4 = 0x14;
|
||||||
header.unknown5 = 0x00;
|
gameMessage.unknown5 = 0x00;
|
||||||
header.unknown6 = 0x00;
|
gameMessage.unknown6 = 0x00;
|
||||||
|
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
|
||||||
header.subpacketSize = (ushort)(0x20 + data.Length);
|
header.subpacketSize = (ushort)(SUBPACKET_SIZE + GAMEMESSAGE_SIZE + data.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getHeaderBytes()
|
public byte[] getHeaderBytes()
|
||||||
@ -82,11 +107,27 @@ namespace FFXIVClassic_Lobby_Server.packets
|
|||||||
return arr;
|
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()
|
public byte[] getBytes()
|
||||||
{
|
{
|
||||||
byte[] outBytes = new byte[header.subpacketSize];
|
byte[] outBytes = new byte[header.subpacketSize];
|
||||||
Array.Copy(getHeaderBytes(), 0, outBytes, 0, SUBPACKET_SIZE);
|
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;
|
return outBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,8 +135,12 @@ namespace FFXIVClassic_Lobby_Server.packets
|
|||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Console.BackgroundColor = ConsoleColor.DarkRed;
|
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()));
|
Console.WriteLine("{0}", Utils.ByteArrayToHex(getHeaderBytes()));
|
||||||
|
if (header.type == 0x03)
|
||||||
|
Console.WriteLine("{0}", Utils.ByteArrayToHex(getGameMessageBytes()));
|
||||||
Console.BackgroundColor = ConsoleColor.DarkMagenta;
|
Console.BackgroundColor = ConsoleColor.DarkMagenta;
|
||||||
Console.WriteLine("{0}", Utils.ByteArrayToHex(data));
|
Console.WriteLine("{0}", Utils.ByteArrayToHex(data));
|
||||||
Console.BackgroundColor = ConsoleColor.Black;
|
Console.BackgroundColor = ConsoleColor.Black;
|
||||||
|
@ -12,7 +12,7 @@ namespace FFXIVClassic_Map_Server.packets.send.login
|
|||||||
{
|
{
|
||||||
public static BasePacket buildPacket(uint unknown, uint time)
|
public static BasePacket buildPacket(uint unknown, uint time)
|
||||||
{
|
{
|
||||||
byte[] data = new byte[18];
|
byte[] data = new byte[0x18];
|
||||||
|
|
||||||
using (MemoryStream mem = new MemoryStream(data))
|
using (MemoryStream mem = new MemoryStream(data))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user