using FFXIVClassic.Common; using FFXIVClassic_World_Server.DataObjects; using FFXIVClassic_World_Server.Packets.Receive; using FFXIVClassic_World_Server.Packets.Send.Login; using System; using System.Collections.Generic; using System.IO; using System.Text; namespace FFXIVClassic_World_Server { class PacketProcessor { /* Session Creation: Get 0x1 from server Send 0x7 Send 0x2 Zone Change: Send 0x7 Get 0x8 - Wait?? Send 0x2 */ Server mServer; List mConnections; public PacketProcessor(Server server) { mServer = server; } public void ProcessPacket(ClientConnection client, BasePacket packet) { //if (packet.header.isCompressed == 0x01) // BasePacket.DecryptPacket(client.blowfish, ref packet); List subPackets = packet.GetSubpackets(); foreach (SubPacket subpacket in subPackets) { //Initial Connect Packet, Create session if (subpacket.header.type == 0x01) { #region Hardcoded replies packet.DebugPrintPacket(); byte[] reply1Data = { 0x01, 0x00, 0x00, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFD, 0xFF, 0xFF, 0xE5, 0x6E, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x0 }; byte[] reply2Data = { 0x01, 0x00, 0x00, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x2B, 0x5F, 0x26, 0x66, 0x00, 0x00, 0x00, 0xC8, 0xD6, 0xAF, 0x2B, 0x38, 0x2B, 0x5F, 0x26, 0xB8, 0x8D, 0xF0, 0x2B, 0xC8, 0xFD, 0x85, 0xFE, 0xA8, 0x7C, 0x5B, 0x09, 0x38, 0x2B, 0x5F, 0x26, 0xC8, 0xD6, 0xAF, 0x2B, 0xB8, 0x8D, 0xF0, 0x2B, 0x88, 0xAF, 0x5E, 0x26 }; BasePacket reply1 = new BasePacket(reply1Data); BasePacket reply2 = new BasePacket(reply2Data); //Write Timestamp into Reply1 using (MemoryStream mem = new MemoryStream(reply1.data)) { using (BinaryWriter binReader = new BinaryWriter(mem)) { binReader.BaseStream.Seek(0x14, SeekOrigin.Begin); binReader.Write((UInt32)Utils.UnixTimeStampUTC()); } } #endregion HelloPacket hello = new HelloPacket(packet.data); if (packet.header.connectionType == BasePacket.TYPE_ZONE) mServer.AddSession(client, Session.Channel.ZONE, hello.sessionId); else if (packet.header.connectionType == BasePacket.TYPE_CHAT) mServer.AddSession(client, Session.Channel.CHAT, hello.sessionId); } //Ping from World Server else if (subpacket.header.type == 0x07) { SubPacket init = Login0x7ResponsePacket.BuildPacket(0x50); client.QueuePacket(BasePacket.CreatePacket(init, true, false)); } //Zoning Related else if (subpacket.header.type == 0x08) { //Response, client's current [actorID][time] //BasePacket init = Login0x7ResponsePacket.BuildPacket(BitConverter.ToUInt32(packet.data, 0x10), Utils.UnixTimeStampUTC(), 0x07); //client.QueuePacket(init); packet.DebugPrintPacket(); } //Game Message else if (subpacket.header.type == 0x03) { //Send to the correct zone server uint targetSession = subpacket.header.targetId; if (mServer.GetSession(targetSession).routing1 != null) mServer.GetSession(targetSession).routing1.SendPacket(subpacket); if (mServer.GetSession(targetSession).routing2 != null) mServer.GetSession(targetSession).routing2.SendPacket(subpacket); } else packet.DebugPrintPacket(); } } } }