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 |
package org.openrs2.protocol |
||||||
|
|
||||||
import io.netty.buffer.ByteBuf |
import io.netty.buffer.ByteBuf |
||||||
|
import org.openrs2.crypto.StreamCipher |
||||||
|
|
||||||
public abstract class EmptyPacketCodec<T : Packet>( |
public abstract class EmptyPacketCodec<T : Packet>( |
||||||
private val packet: T, |
private val packet: T, |
||||||
opcode: Int |
opcode: Int |
||||||
) : PacketCodec<T>(packet.javaClass, opcode, length = 0) { |
) : PacketCodec<T>(packet.javaClass, opcode, length = 0) { |
||||||
override fun decode(input: ByteBuf): T { |
override fun decode(input: ByteBuf, cipher: StreamCipher): T { |
||||||
return packet |
return packet |
||||||
} |
} |
||||||
|
|
||||||
override fun encode(input: T, output: ByteBuf) { |
override fun encode(input: T, output: ByteBuf, cipher: StreamCipher) { |
||||||
// empty |
// empty |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,18 +1,19 @@ |
|||||||
package org.openrs2.protocol |
package org.openrs2.protocol |
||||||
|
|
||||||
import io.netty.buffer.ByteBuf |
import io.netty.buffer.ByteBuf |
||||||
|
import org.openrs2.crypto.StreamCipher |
||||||
|
|
||||||
internal object FixedPacketCodec : PacketCodec<FixedPacket>( |
internal object FixedPacketCodec : PacketCodec<FixedPacket>( |
||||||
type = FixedPacket::class.java, |
type = FixedPacket::class.java, |
||||||
opcode = 0, |
opcode = 0, |
||||||
length = 4 |
length = 4 |
||||||
) { |
) { |
||||||
override fun decode(input: ByteBuf): FixedPacket { |
override fun decode(input: ByteBuf, cipher: StreamCipher): FixedPacket { |
||||||
val value = input.readInt() |
val value = input.readInt() |
||||||
return FixedPacket(value) |
return FixedPacket(value) |
||||||
} |
} |
||||||
|
|
||||||
override fun encode(input: FixedPacket, output: ByteBuf) { |
override fun encode(input: FixedPacket, output: ByteBuf, cipher: StreamCipher) { |
||||||
output.writeInt(input.value) |
output.writeInt(input.value) |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,18 +1,19 @@ |
|||||||
package org.openrs2.protocol |
package org.openrs2.protocol |
||||||
|
|
||||||
import io.netty.buffer.ByteBuf |
import io.netty.buffer.ByteBuf |
||||||
|
import org.openrs2.crypto.StreamCipher |
||||||
|
|
||||||
internal object LengthMismatchPacketCodec : PacketCodec<FixedPacket>( |
internal object LengthMismatchPacketCodec : PacketCodec<FixedPacket>( |
||||||
type = FixedPacket::class.java, |
type = FixedPacket::class.java, |
||||||
opcode = 0, |
opcode = 0, |
||||||
length = 5 |
length = 5 |
||||||
) { |
) { |
||||||
override fun decode(input: ByteBuf): FixedPacket { |
override fun decode(input: ByteBuf, cipher: StreamCipher): FixedPacket { |
||||||
val value = input.readInt() |
val value = input.readInt() |
||||||
return FixedPacket(value) |
return FixedPacket(value) |
||||||
} |
} |
||||||
|
|
||||||
override fun encode(input: FixedPacket, output: ByteBuf) { |
override fun encode(input: FixedPacket, output: ByteBuf, cipher: StreamCipher) { |
||||||
output.writeInt(input.value) |
output.writeInt(input.value) |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,19 +1,20 @@ |
|||||||
package org.openrs2.protocol |
package org.openrs2.protocol |
||||||
|
|
||||||
import io.netty.buffer.ByteBuf |
import io.netty.buffer.ByteBuf |
||||||
|
import org.openrs2.crypto.StreamCipher |
||||||
|
|
||||||
internal object VariableBytePacketCodec : PacketCodec<VariableBytePacket>( |
internal object VariableBytePacketCodec : PacketCodec<VariableBytePacket>( |
||||||
type = VariableBytePacket::class.java, |
type = VariableBytePacket::class.java, |
||||||
opcode = 1, |
opcode = 1, |
||||||
length = PacketLength.VARIABLE_BYTE |
length = PacketLength.VARIABLE_BYTE |
||||||
) { |
) { |
||||||
override fun decode(input: ByteBuf): VariableBytePacket { |
override fun decode(input: ByteBuf, cipher: StreamCipher): VariableBytePacket { |
||||||
val value = ByteArray(input.readableBytes()) |
val value = ByteArray(input.readableBytes()) |
||||||
input.readBytes(value) |
input.readBytes(value) |
||||||
return VariableBytePacket(value) |
return VariableBytePacket(value) |
||||||
} |
} |
||||||
|
|
||||||
override fun encode(input: VariableBytePacket, output: ByteBuf) { |
override fun encode(input: VariableBytePacket, output: ByteBuf, cipher: StreamCipher) { |
||||||
output.writeBytes(input.value) |
output.writeBytes(input.value) |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,19 +1,20 @@ |
|||||||
package org.openrs2.protocol |
package org.openrs2.protocol |
||||||
|
|
||||||
import io.netty.buffer.ByteBuf |
import io.netty.buffer.ByteBuf |
||||||
|
import org.openrs2.crypto.StreamCipher |
||||||
|
|
||||||
internal object VariableShortPacketCodec : PacketCodec<VariableShortPacket>( |
internal object VariableShortPacketCodec : PacketCodec<VariableShortPacket>( |
||||||
type = VariableShortPacket::class.java, |
type = VariableShortPacket::class.java, |
||||||
opcode = 2, |
opcode = 2, |
||||||
length = PacketLength.VARIABLE_SHORT |
length = PacketLength.VARIABLE_SHORT |
||||||
) { |
) { |
||||||
override fun decode(input: ByteBuf): VariableShortPacket { |
override fun decode(input: ByteBuf, cipher: StreamCipher): VariableShortPacket { |
||||||
val value = ByteArray(input.readableBytes()) |
val value = ByteArray(input.readableBytes()) |
||||||
input.readBytes(value) |
input.readBytes(value) |
||||||
return VariableShortPacket(value) |
return VariableShortPacket(value) |
||||||
} |
} |
||||||
|
|
||||||
override fun encode(input: VariableShortPacket, output: ByteBuf) { |
override fun encode(input: VariableShortPacket, output: ByteBuf, cipher: StreamCipher) { |
||||||
output.writeBytes(input.value) |
output.writeBytes(input.value) |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue