public void Finalise() { if (type == PacketType.RealmPacket) { strm.Position = 0; //size //Int16 szhs = IPAddress.HostToNetworkOrder((Int16)(strm.Length - 2)); WriteBE((UInt16)(strm.Length - 2)); //don't include the opcode in the size strm.Position = strm.Length; strm.Position = 2; var op = strm.ReadByte() | (strm.ReadByte() << 8); strm.Position = strm.Length; RealmOp lol = (RealmOp)op; Task.Factory.StartNew( () => { Console.WriteLine("Sending Packet {0} Len {1}", lol.ToString(), strm.Length); }); } }
} //shortest is 2 byte size, 4 byte command public override PacketProcessResult ProcessData() { DecryptData(6); int sz = CurrentPacket.ReadUInt16BE(); if ((sz & 0x8000) != 0) //large packet { DataNeeded = 3; //we need 3 byte size to continue if (CurrentPacket.Length < DataNeeded) { return(PacketProcessResult.RequiresData); } DecryptData(7); CurrentPacket.Position = 3; sz = 0; sz |= CurrentPacket.GetBuffer()[0] & 0x7F; sz <<= 8; sz |= CurrentPacket.GetBuffer()[1]; sz <<= 8; sz |= CurrentPacket.GetBuffer()[2]; DataNeeded = 3 + sz; if (CurrentPacket.Length < DataNeeded) { return(PacketProcessResult.RequiresData); } } else { DataNeeded = 2 + sz; if (CurrentPacket.Length < DataNeeded) { return(PacketProcessResult.RequiresData); } } CurrentOpcode = (RealmOp)CurrentPacket.ReadUInt32(); Console.WriteLine("Received Packet {0} Length {1}", CurrentOpcode.ToString(), sz); //ok now we need sz + 2 to continue return(ProcessPacket()); }
} //shortest is 2 byte size, 4 byte command public override PacketProcessResult ProcessData() { DecryptData(6); int sz = CurrentPacket.ReadUInt16BE(); if ((sz & 0x8000) != 0) //large packet { DataNeeded = 3; //we need 3 byte size to continue if (CurrentPacket.Length < DataNeeded) return PacketProcessResult.RequiresData; DecryptData(7); CurrentPacket.Position = 3; sz = 0; sz |= CurrentPacket.GetBuffer()[0] & 0x7F; sz <<= 8; sz |= CurrentPacket.GetBuffer()[1]; sz <<= 8; sz |= CurrentPacket.GetBuffer()[2]; DataNeeded = 3 + sz; if (CurrentPacket.Length < DataNeeded) return PacketProcessResult.RequiresData; } else { DataNeeded = 2 + sz; if (CurrentPacket.Length < DataNeeded) return PacketProcessResult.RequiresData; } CurrentOpcode = (RealmOp) CurrentPacket.ReadUInt32(); Console.WriteLine("Received Packet {0} Length {1}", CurrentOpcode.ToString(), sz); //ok now we need sz + 2 to continue return ProcessPacket(); }