mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-04-24 05:37:46 +00:00
Merge branch 'fix_connection' into multiplayer
This commit is contained in:
commit
d21bbf9b48
5 changed files with 348 additions and 328 deletions
|
@ -20,22 +20,12 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
public Blowfish blowfish;
|
public Blowfish blowfish;
|
||||||
public Socket socket;
|
public Socket socket;
|
||||||
public byte[] buffer = new byte[0xffff];
|
public byte[] buffer = new byte[0xffff];
|
||||||
public CircularBuffer<byte> incomingStream = new CircularBuffer<byte>(1024);
|
private BlockingCollection<BasePacket> sendPacketQueue = new BlockingCollection<BasePacket>(1000);
|
||||||
private BlockingCollection<BasePacket> sendPacketQueue = new BlockingCollection<BasePacket>(100);
|
|
||||||
|
|
||||||
//Instance Stuff
|
//Instance Stuff
|
||||||
public uint owner = 0;
|
public uint owner = 0;
|
||||||
public uint connType = 0;
|
public uint connType = 0;
|
||||||
|
|
||||||
|
|
||||||
public void processIncoming(int bytesIn)
|
|
||||||
{
|
|
||||||
if (bytesIn == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
incomingStream.Put(buffer, 0, bytesIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void queuePacket(BasePacket packet)
|
public void queuePacket(BasePacket packet)
|
||||||
{
|
{
|
||||||
sendPacketQueue.Add(packet);
|
sendPacketQueue.Add(packet);
|
||||||
|
|
|
@ -25,7 +25,6 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
{
|
{
|
||||||
Dictionary<uint, Player> mPlayers;
|
Dictionary<uint, Player> mPlayers;
|
||||||
List<ClientConnection> mConnections;
|
List<ClientConnection> mConnections;
|
||||||
Boolean isAlive = true;
|
|
||||||
|
|
||||||
Zone inn = new Zone();
|
Zone inn = new Zone();
|
||||||
|
|
||||||
|
@ -35,52 +34,7 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
mConnections = connectionList;
|
mConnections = connectionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update()
|
public void processPacket(ClientConnection client, BasePacket packet)
|
||||||
{
|
|
||||||
Console.WriteLine("Packet processing thread has started");
|
|
||||||
while (isAlive)
|
|
||||||
{
|
|
||||||
lock (mConnections)
|
|
||||||
{
|
|
||||||
foreach (ClientConnection conn in mConnections)
|
|
||||||
{
|
|
||||||
//Receive conn1 packets
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (conn == null || conn.incomingStream.Size < BasePacket.BASEPACKET_SIZE)
|
|
||||||
break;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (conn.incomingStream.Size < BasePacket.BASEPACKET_SIZE)
|
|
||||||
break;
|
|
||||||
BasePacketHeader header = BasePacket.getHeader(conn.incomingStream.Peek(BasePacket.BASEPACKET_SIZE));
|
|
||||||
|
|
||||||
if (conn.incomingStream.Size < header.packetSize)
|
|
||||||
break;
|
|
||||||
|
|
||||||
BasePacket packet = new BasePacket(conn.incomingStream.Get(header.packetSize));
|
|
||||||
processPacket(conn, packet);
|
|
||||||
|
|
||||||
}
|
|
||||||
catch(OverflowException)
|
|
||||||
{ break; }
|
|
||||||
}
|
|
||||||
|
|
||||||
//Send packets
|
|
||||||
if (conn != null)
|
|
||||||
conn.flushQueuedSendPackets();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Don't waste CPU if isn't needed
|
|
||||||
if (mConnections.Count == 0)
|
|
||||||
Thread.Sleep(2000);
|
|
||||||
else
|
|
||||||
Thread.Sleep(100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processPacket(ClientConnection client, BasePacket packet)
|
|
||||||
{
|
{
|
||||||
Player player = null;
|
Player player = null;
|
||||||
if (client.owner != 0 && mPlayers.ContainsKey(client.owner))
|
if (client.owner != 0 && mPlayers.ContainsKey(client.owner))
|
||||||
|
@ -89,16 +43,11 @@ 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);
|
||||||
|
|
||||||
|
|
||||||
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 reply2 = new BasePacket("./packets/login/login2.bin");
|
BasePacket reply2 = new BasePacket("./packets/login/login2.bin");
|
||||||
|
|
||||||
//Already Handshaked
|
//Already Handshaked
|
||||||
|
@ -113,7 +62,7 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client.queuePacket(init);
|
|
||||||
client.queuePacket(reply2);
|
client.queuePacket(reply2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -131,7 +80,7 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
actorID = UInt32.Parse(Encoding.ASCII.GetString(readIn));
|
actorID = UInt32.Parse(Encoding.ASCII.GetString(readIn));
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{}
|
{ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,8 +100,6 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.debug(String.Format("Got actorID {0} for conn {1}.", actorID, client.getAddress()));
|
|
||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
player = new Player(actorID);
|
player = new Player(actorID);
|
||||||
|
@ -160,6 +107,7 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
client.owner = actorID;
|
client.owner = actorID;
|
||||||
client.connType = 0;
|
client.connType = 0;
|
||||||
player.setConnection1(client);
|
player.setConnection1(client);
|
||||||
|
Log.debug(String.Format("Got actorID {0} for conn {1}.", actorID, client.getAddress()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -170,9 +118,18 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
|
|
||||||
//Get Character info
|
//Get Character info
|
||||||
//Create player actor
|
//Create player actor
|
||||||
client.queuePacket(init);
|
|
||||||
client.queuePacket(reply2);
|
client.queuePacket(reply2);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
else if (subpacket.header.type == 0x07)
|
||||||
|
{
|
||||||
|
BasePacket init = InitPacket.buildPacket(BitConverter.ToUInt32(packet.data, 0x10), Utils.UnixTimeStampUTC());
|
||||||
|
client.queuePacket(init);
|
||||||
|
}
|
||||||
|
else if (subpacket.header.type == 0x03)
|
||||||
|
{
|
||||||
|
switch (subpacket.gameMessage.opcode)
|
||||||
|
{
|
||||||
//Ping
|
//Ping
|
||||||
case 0x0001:
|
case 0x0001:
|
||||||
//subpacket.debugPrintSubPacket();
|
//subpacket.debugPrintSubPacket();
|
||||||
|
@ -195,7 +152,7 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
BasePacket keyitems = new BasePacket("./packets/login/keyitems.bin");
|
BasePacket keyitems = new BasePacket("./packets/login/keyitems.bin");
|
||||||
BasePacket currancy = new BasePacket("./packets/login/currancy.bin");
|
BasePacket currancy = new BasePacket("./packets/login/currancy.bin");
|
||||||
|
|
||||||
#region replaceid
|
#region replaceid
|
||||||
currancy.replaceActorID(player.actorID);
|
currancy.replaceActorID(player.actorID);
|
||||||
keyitems.replaceActorID(player.actorID);
|
keyitems.replaceActorID(player.actorID);
|
||||||
|
|
||||||
|
@ -207,11 +164,11 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
reply10.replaceActorID(player.actorID);
|
reply10.replaceActorID(player.actorID);
|
||||||
reply11.replaceActorID(player.actorID);
|
reply11.replaceActorID(player.actorID);
|
||||||
reply12.replaceActorID(player.actorID);
|
reply12.replaceActorID(player.actorID);
|
||||||
#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);
|
||||||
|
|
||||||
|
@ -229,7 +186,7 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
////////ITEMS////////
|
////////ITEMS////////
|
||||||
client.queuePacket(BasePacket.createPacket(InventoryBeginChangePacket.buildPacket(player.actorID), true, false));
|
client.queuePacket(BasePacket.createPacket(InventoryBeginChangePacket.buildPacket(player.actorID), true, false));
|
||||||
|
|
||||||
#region itemsetup
|
#region itemsetup
|
||||||
|
|
||||||
//TEST
|
//TEST
|
||||||
List<Item> items = new List<Item>();
|
List<Item> items = new List<Item>();
|
||||||
|
@ -266,14 +223,14 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
setinvPackets.Add(beginInventory);
|
setinvPackets.Add(beginInventory);
|
||||||
setinvPackets.Add(setInventory);
|
setinvPackets.Add(setInventory);
|
||||||
setinvPackets.Add(endInventory);
|
setinvPackets.Add(endInventory);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
client.queuePacket(BasePacket.createPacket(setinvPackets, true, false));
|
client.queuePacket(BasePacket.createPacket(setinvPackets, true, false));
|
||||||
|
|
||||||
//client.queuePacket(currancy);
|
//client.queuePacket(currancy);
|
||||||
//client.queuePacket(keyitems);
|
//client.queuePacket(keyitems);
|
||||||
|
|
||||||
#region equipsetup
|
#region equipsetup
|
||||||
EquipmentSetupPacket initialEqupmentPacket = new EquipmentSetupPacket();
|
EquipmentSetupPacket initialEqupmentPacket = new EquipmentSetupPacket();
|
||||||
initialEqupmentPacket.setItem(EquipmentSetupPacket.SLOT_BODY, 5);
|
initialEqupmentPacket.setItem(EquipmentSetupPacket.SLOT_BODY, 5);
|
||||||
initialEqupmentPacket.setItem(EquipmentSetupPacket.SLOT_HEAD, 3);
|
initialEqupmentPacket.setItem(EquipmentSetupPacket.SLOT_HEAD, 3);
|
||||||
|
@ -281,7 +238,7 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
initialEqupmentPacket.setItem(EquipmentSetupPacket.SLOT_UNDERGARMENT, 7);
|
initialEqupmentPacket.setItem(EquipmentSetupPacket.SLOT_UNDERGARMENT, 7);
|
||||||
initialEqupmentPacket.setItem(EquipmentSetupPacket.SLOT_MAINHAND, 2);
|
initialEqupmentPacket.setItem(EquipmentSetupPacket.SLOT_MAINHAND, 2);
|
||||||
initialEqupmentPacket.setItem(EquipmentSetupPacket.SLOT_LEGS, 8);
|
initialEqupmentPacket.setItem(EquipmentSetupPacket.SLOT_LEGS, 8);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//Equip Init
|
//Equip Init
|
||||||
client.queuePacket(BasePacket.createPacket(InventorySetBeginPacket.buildPacket(player.actorID, 0x23, InventorySetBeginPacket.CODE_EQUIPMENT), true, false));
|
client.queuePacket(BasePacket.createPacket(InventorySetBeginPacket.buildPacket(player.actorID, 0x23, InventorySetBeginPacket.CODE_EQUIPMENT), true, false));
|
||||||
|
@ -320,7 +277,7 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
break;
|
break;
|
||||||
//Set Target
|
//Set Target
|
||||||
case 0x00CD:
|
case 0x00CD:
|
||||||
subpacket.debugPrintSubPacket();
|
//subpacket.debugPrintSubPacket();
|
||||||
|
|
||||||
SetTargetPacket setTarget = new SetTargetPacket(subpacket.data);
|
SetTargetPacket setTarget = new SetTargetPacket(subpacket.data);
|
||||||
player.getActor().currentTarget = setTarget.actorID;
|
player.getActor().currentTarget = setTarget.actorID;
|
||||||
|
@ -348,12 +305,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)
|
||||||
|
|
|
@ -9,6 +9,7 @@ using System.Threading;
|
||||||
using FFXIVClassic_Lobby_Server.common;
|
using FFXIVClassic_Lobby_Server.common;
|
||||||
using FFXIVClassic_Map_Server.dataobjects;
|
using FFXIVClassic_Map_Server.dataobjects;
|
||||||
using FFXIVClassic_Lobby_Server.packets;
|
using FFXIVClassic_Lobby_Server.packets;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace FFXIVClassic_Lobby_Server
|
namespace FFXIVClassic_Lobby_Server
|
||||||
{
|
{
|
||||||
|
@ -62,8 +63,7 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
|
|
||||||
mProcessor = new PacketProcessor(mConnectedPlayerList, mConnectionList);
|
mProcessor = new PacketProcessor(mConnectedPlayerList, mConnectionList);
|
||||||
mProcessorThread = new Thread(new ThreadStart(mProcessor.update));
|
|
||||||
mProcessorThread.Start();
|
|
||||||
//mGameThread = new Thread(new ThreadStart(mProcessor.update));
|
//mGameThread = new Thread(new ThreadStart(mProcessor.update));
|
||||||
//mGameThread.Start();
|
//mGameThread.Start();
|
||||||
return true;
|
return true;
|
||||||
|
@ -117,32 +117,10 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Player findPlayerBySocket(Socket s)
|
/// <summary>
|
||||||
{
|
/// Receive Callback. Reads in incoming data, converting them to base packets. Base packets are sent to be parsed. If not enough data at the end to build a basepacket, move to the beginning and prepend.
|
||||||
lock (mConnectedPlayerList)
|
/// </summary>
|
||||||
{
|
/// <param name="result"></param>
|
||||||
foreach (KeyValuePair<uint,Player> p in mConnectedPlayerList)
|
|
||||||
{
|
|
||||||
if ((p.Value.getConnection1().socket.RemoteEndPoint as IPEndPoint).Address.Equals((s.RemoteEndPoint as IPEndPoint).Address))
|
|
||||||
{
|
|
||||||
return p.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((p.Value.getConnection2().socket.RemoteEndPoint as IPEndPoint).Address.Equals((s.RemoteEndPoint as IPEndPoint).Address))
|
|
||||||
{
|
|
||||||
return p.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Player findPlayerByClientConnection(ClientConnection conn)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void receiveCallback(IAsyncResult result)
|
private void receiveCallback(IAsyncResult result)
|
||||||
{
|
{
|
||||||
ClientConnection conn = (ClientConnection)result.AsyncState;
|
ClientConnection conn = (ClientConnection)result.AsyncState;
|
||||||
|
@ -152,9 +130,31 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
int bytesRead = conn.socket.EndReceive(result);
|
int bytesRead = conn.socket.EndReceive(result);
|
||||||
if (bytesRead > 0)
|
if (bytesRead > 0)
|
||||||
{
|
{
|
||||||
conn.processIncoming(bytesRead);
|
int offset = 0;
|
||||||
|
|
||||||
//Queue the next receive
|
//Build packets until can no longer or out of data
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
BasePacket basePacket = buildPacket(ref offset, conn.buffer, bytesRead);
|
||||||
|
//If can't build packet, break, else process another
|
||||||
|
if (basePacket == null)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
mProcessor.processPacket(conn, basePacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Not all bytes consumed, transfer leftover to beginning
|
||||||
|
if (offset < bytesRead)
|
||||||
|
Array.Copy(conn.buffer, offset, conn.buffer, 0, bytesRead - offset);
|
||||||
|
|
||||||
|
//Build any queued subpackets into basepackets and send
|
||||||
|
conn.flushQueuedSendPackets();
|
||||||
|
|
||||||
|
if (offset < bytesRead)
|
||||||
|
//Need offset since not all bytes consumed
|
||||||
|
conn.socket.BeginReceive(conn.buffer, bytesRead - offset, conn.buffer.Length - (bytesRead - offset), SocketFlags.None, new AsyncCallback(receiveCallback), conn);
|
||||||
|
else
|
||||||
|
//All bytes consumed, full buffer available
|
||||||
conn.socket.BeginReceive(conn.buffer, 0, conn.buffer.Length, SocketFlags.None, new AsyncCallback(receiveCallback), conn);
|
conn.socket.BeginReceive(conn.buffer, 0, conn.buffer.Length, SocketFlags.None, new AsyncCallback(receiveCallback), conn);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -181,8 +181,35 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
/// <summary>
|
||||||
|
/// Builds a packet from the incoming buffer + offset. If a packet can be built, it is returned else null.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="offset">Current offset in buffer.</param>
|
||||||
|
/// <param name="buffer">Incoming buffer.</param>
|
||||||
|
/// <returns>Returns either a BasePacket or null if not enough data.</returns>
|
||||||
|
public BasePacket buildPacket(ref int offset, byte[] buffer, int bytesRead)
|
||||||
|
{
|
||||||
|
BasePacket newPacket = null;
|
||||||
|
|
||||||
|
//Too small to even get length
|
||||||
|
if (bytesRead <= offset)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
ushort packetSize = BitConverter.ToUInt16(buffer, offset);
|
||||||
|
|
||||||
|
//Too small to whole packet
|
||||||
|
if (bytesRead < offset + packetSize)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (buffer.Length < offset + packetSize)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
newPacket = new BasePacket(buffer, ref offset);
|
||||||
|
|
||||||
|
return newPacket;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
@ -10,9 +10,9 @@ namespace FFXIVClassic_Map_Server.packets.send.login
|
||||||
{
|
{
|
||||||
class InitPacket
|
class InitPacket
|
||||||
{
|
{
|
||||||
public static BasePacket buildPacket(uint unknown, uint time)
|
public static BasePacket buildPacket(uint actorID, uint time)
|
||||||
{
|
{
|
||||||
byte[] data = new byte[18];
|
byte[] data = new byte[0x18];
|
||||||
|
|
||||||
using (MemoryStream mem = new MemoryStream(data))
|
using (MemoryStream mem = new MemoryStream(data))
|
||||||
{
|
{
|
||||||
|
@ -26,7 +26,7 @@ namespace FFXIVClassic_Map_Server.packets.send.login
|
||||||
binWriter.Write((uint)0);
|
binWriter.Write((uint)0);
|
||||||
binWriter.Write((uint)0xFFFFFD7F);
|
binWriter.Write((uint)0xFFFFFD7F);
|
||||||
|
|
||||||
binWriter.Write((uint)unknown);
|
binWriter.Write((uint)actorID);
|
||||||
binWriter.Write((uint)time);
|
binWriter.Write((uint)time);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
|
Loading…
Add table
Reference in a new issue