forked from openrs2/openrs2
A small number of packets have encrypted payloads. Signed-off-by: Graham <gpe@openrs2.org>
parent
a50e0ea998
commit
55d72dacbe
@ -1,16 +1,17 @@ |
||||
package org.openrs2.protocol |
||||
|
||||
import io.netty.buffer.ByteBuf |
||||
import org.openrs2.crypto.StreamCipher |
||||
|
||||
public abstract class EmptyPacketCodec<T : Packet>( |
||||
private val packet: T, |
||||
opcode: Int |
||||
) : PacketCodec<T>(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 |
||||
} |
||||
} |
||||
|
@ -1,18 +1,19 @@ |
||||
package org.openrs2.protocol |
||||
|
||||
import io.netty.buffer.ByteBuf |
||||
import org.openrs2.crypto.StreamCipher |
||||
|
||||
internal object FixedPacketCodec : PacketCodec<FixedPacket>( |
||||
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) |
||||
} |
||||
} |
||||
|
@ -1,18 +1,19 @@ |
||||
package org.openrs2.protocol |
||||
|
||||
import io.netty.buffer.ByteBuf |
||||
import org.openrs2.crypto.StreamCipher |
||||
|
||||
internal object LengthMismatchPacketCodec : PacketCodec<FixedPacket>( |
||||
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) |
||||
} |
||||
} |
||||
|
@ -1,19 +1,20 @@ |
||||
package org.openrs2.protocol |
||||
|
||||
import io.netty.buffer.ByteBuf |
||||
import org.openrs2.crypto.StreamCipher |
||||
|
||||
internal object VariableBytePacketCodec : PacketCodec<VariableBytePacket>( |
||||
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) |
||||
} |
||||
} |
||||
|
@ -1,19 +1,20 @@ |
||||
package org.openrs2.protocol |
||||
|
||||
import io.netty.buffer.ByteBuf |
||||
import org.openrs2.crypto.StreamCipher |
||||
|
||||
internal object VariableShortPacketCodec : PacketCodec<VariableShortPacket>( |
||||
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) |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue