diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/EmptyPacketCodec.kt b/protocol/src/main/kotlin/org/openrs2/protocol/EmptyPacketCodec.kt index e6a8f8fcc0..1413967bf8 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/EmptyPacketCodec.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/EmptyPacketCodec.kt @@ -1,16 +1,17 @@ package org.openrs2.protocol import io.netty.buffer.ByteBuf +import org.openrs2.crypto.StreamCipher public abstract class EmptyPacketCodec( private val packet: T, opcode: Int ) : PacketCodec(packet.javaClass, opcode, length = 0) { - override fun decode(input: ByteBuf): T { + override fun decode(input: ByteBuf, cipher: StreamCipher): T { return packet } - override fun encode(input: T, output: ByteBuf) { + override fun encode(input: T, output: ByteBuf, cipher: StreamCipher) { // empty } } diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/PacketCodec.kt b/protocol/src/main/kotlin/org/openrs2/protocol/PacketCodec.kt index 5d92818bc5..df1e894b71 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/PacketCodec.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/PacketCodec.kt @@ -2,6 +2,7 @@ package org.openrs2.protocol import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBufAllocator +import org.openrs2.crypto.StreamCipher public abstract class PacketCodec( public val type: Class, @@ -13,8 +14,8 @@ public abstract class PacketCodec( require(length >= PacketLength.VARIABLE_SHORT) } - public abstract fun decode(input: ByteBuf): T - public abstract fun encode(input: T, output: ByteBuf) + public abstract fun decode(input: ByteBuf, cipher: StreamCipher): T + public abstract fun encode(input: T, output: ByteBuf, cipher: StreamCipher) public open fun getLength(input: T): Int { return length diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/Rs2Decoder.kt b/protocol/src/main/kotlin/org/openrs2/protocol/Rs2Decoder.kt index e20a13532f..7783858468 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/Rs2Decoder.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/Rs2Decoder.kt @@ -65,7 +65,7 @@ public class Rs2Decoder(public var protocol: Protocol) : ByteToMessageDecoder() val payload = input.readSlice(length) out += try { - decoder.decode(payload) + decoder.decode(payload, cipher) } catch (ex: NotImplementedError) { // TODO(gpe): remove this catch block when every packet is implemented logger.warn { "Skipping unimplemented packet: ${decoder.javaClass}" } diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/Rs2Encoder.kt b/protocol/src/main/kotlin/org/openrs2/protocol/Rs2Encoder.kt index 813cdada73..806ad25740 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/Rs2Encoder.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/Rs2Encoder.kt @@ -24,7 +24,7 @@ public class Rs2Encoder(public var protocol: Protocol) : MessageToByteEncoder( @@ -8,12 +9,12 @@ public object InitJs5RemoteConnectionCodec : PacketCodec( @@ -8,12 +9,12 @@ public object RequestWorldListCodec : PacketCodec opcode = 23, length = 4 ) { - override fun decode(input: ByteBuf): LoginRequest.RequestWorldList { + override fun decode(input: ByteBuf, cipher: StreamCipher): LoginRequest.RequestWorldList { val checksum = input.readInt() return LoginRequest.RequestWorldList(checksum) } - override fun encode(input: LoginRequest.RequestWorldList, output: ByteBuf) { + override fun encode(input: LoginRequest.RequestWorldList, output: ByteBuf, cipher: StreamCipher) { output.writeInt(input.checksum) } } diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/FixedPacketCodec.kt b/protocol/src/test/kotlin/org/openrs2/protocol/FixedPacketCodec.kt index 0f428c3037..3d9452fd1f 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/FixedPacketCodec.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/FixedPacketCodec.kt @@ -1,18 +1,19 @@ package org.openrs2.protocol import io.netty.buffer.ByteBuf +import org.openrs2.crypto.StreamCipher internal object FixedPacketCodec : PacketCodec( type = FixedPacket::class.java, opcode = 0, length = 4 ) { - override fun decode(input: ByteBuf): FixedPacket { + override fun decode(input: ByteBuf, cipher: StreamCipher): FixedPacket { val value = input.readInt() return FixedPacket(value) } - override fun encode(input: FixedPacket, output: ByteBuf) { + override fun encode(input: FixedPacket, output: ByteBuf, cipher: StreamCipher) { output.writeInt(input.value) } } diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/LengthMismatchPacketCodec.kt b/protocol/src/test/kotlin/org/openrs2/protocol/LengthMismatchPacketCodec.kt index 8a4009eba4..f89d58733c 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/LengthMismatchPacketCodec.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/LengthMismatchPacketCodec.kt @@ -1,18 +1,19 @@ package org.openrs2.protocol import io.netty.buffer.ByteBuf +import org.openrs2.crypto.StreamCipher internal object LengthMismatchPacketCodec : PacketCodec( type = FixedPacket::class.java, opcode = 0, length = 5 ) { - override fun decode(input: ByteBuf): FixedPacket { + override fun decode(input: ByteBuf, cipher: StreamCipher): FixedPacket { val value = input.readInt() return FixedPacket(value) } - override fun encode(input: FixedPacket, output: ByteBuf) { + override fun encode(input: FixedPacket, output: ByteBuf, cipher: StreamCipher) { output.writeInt(input.value) } } diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/VariableByteOptimisedPacketCodec.kt b/protocol/src/test/kotlin/org/openrs2/protocol/VariableByteOptimisedPacketCodec.kt index 0b56e87c61..7ac4085bf2 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/VariableByteOptimisedPacketCodec.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/VariableByteOptimisedPacketCodec.kt @@ -1,19 +1,20 @@ package org.openrs2.protocol import io.netty.buffer.ByteBuf +import org.openrs2.crypto.StreamCipher internal object VariableByteOptimisedPacketCodec : PacketCodec( type = VariableByteOptimisedPacket::class.java, opcode = 3, length = PacketLength.VARIABLE_BYTE ) { - override fun decode(input: ByteBuf): VariableByteOptimisedPacket { + override fun decode(input: ByteBuf, cipher: StreamCipher): VariableByteOptimisedPacket { val value = ByteArray(input.readableBytes()) input.readBytes(value) return VariableByteOptimisedPacket(value) } - override fun encode(input: VariableByteOptimisedPacket, output: ByteBuf) { + override fun encode(input: VariableByteOptimisedPacket, output: ByteBuf, cipher: StreamCipher) { output.writeBytes(input.value) } diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/VariableBytePacketCodec.kt b/protocol/src/test/kotlin/org/openrs2/protocol/VariableBytePacketCodec.kt index 46bc497468..89de81669b 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/VariableBytePacketCodec.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/VariableBytePacketCodec.kt @@ -1,19 +1,20 @@ package org.openrs2.protocol import io.netty.buffer.ByteBuf +import org.openrs2.crypto.StreamCipher internal object VariableBytePacketCodec : PacketCodec( type = VariableBytePacket::class.java, opcode = 1, length = PacketLength.VARIABLE_BYTE ) { - override fun decode(input: ByteBuf): VariableBytePacket { + override fun decode(input: ByteBuf, cipher: StreamCipher): VariableBytePacket { val value = ByteArray(input.readableBytes()) input.readBytes(value) return VariableBytePacket(value) } - override fun encode(input: VariableBytePacket, output: ByteBuf) { + override fun encode(input: VariableBytePacket, output: ByteBuf, cipher: StreamCipher) { output.writeBytes(input.value) } } diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/VariableShortOptimisedPacketCodec.kt b/protocol/src/test/kotlin/org/openrs2/protocol/VariableShortOptimisedPacketCodec.kt index 1f719a2ccf..acb3d5b20d 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/VariableShortOptimisedPacketCodec.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/VariableShortOptimisedPacketCodec.kt @@ -1,19 +1,20 @@ package org.openrs2.protocol import io.netty.buffer.ByteBuf +import org.openrs2.crypto.StreamCipher internal object VariableShortOptimisedPacketCodec : PacketCodec( type = VariableShortOptimisedPacket::class.java, opcode = 4, length = PacketLength.VARIABLE_SHORT ) { - override fun decode(input: ByteBuf): VariableShortOptimisedPacket { + override fun decode(input: ByteBuf, cipher: StreamCipher): VariableShortOptimisedPacket { val value = ByteArray(input.readableBytes()) input.readBytes(value) return VariableShortOptimisedPacket(value) } - override fun encode(input: VariableShortOptimisedPacket, output: ByteBuf) { + override fun encode(input: VariableShortOptimisedPacket, output: ByteBuf, cipher: StreamCipher) { output.writeBytes(input.value) } diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/VariableShortPacketCodec.kt b/protocol/src/test/kotlin/org/openrs2/protocol/VariableShortPacketCodec.kt index 76d7460786..814163d78f 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/VariableShortPacketCodec.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/VariableShortPacketCodec.kt @@ -1,19 +1,20 @@ package org.openrs2.protocol import io.netty.buffer.ByteBuf +import org.openrs2.crypto.StreamCipher internal object VariableShortPacketCodec : PacketCodec( type = VariableShortPacket::class.java, opcode = 2, length = PacketLength.VARIABLE_SHORT ) { - override fun decode(input: ByteBuf): VariableShortPacket { + override fun decode(input: ByteBuf, cipher: StreamCipher): VariableShortPacket { val value = ByteArray(input.readableBytes()) input.readBytes(value) return VariableShortPacket(value) } - override fun encode(input: VariableShortPacket, output: ByteBuf) { + override fun encode(input: VariableShortPacket, output: ByteBuf, cipher: StreamCipher) { output.writeBytes(input.value) } }