Skip to content

Commit

Permalink
fix: only count server prots towards PACKET_GROUP_END
Browse files Browse the repository at this point in the history
  • Loading branch information
Z-Kris committed Nov 27, 2024
1 parent 4d21db5 commit f89f826
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions proxy/src/main/kotlin/net/rsprox/proxy/plugin/DecodingSession.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
import net.rsprot.buffer.extensions.toJagByteBuf
import net.rsprot.protocol.Prot
import net.rsprox.protocol.session.*
import net.rsprox.protocol.session.AttributeMap
import net.rsprox.protocol.session.Session
import net.rsprox.protocol.session.getBytesConsumed
import net.rsprox.protocol.session.getRemainingBytesInPacketGroup
import net.rsprox.protocol.session.setBytesConsumed
import net.rsprox.protocol.session.setRemainingBytesInPacketGroup
import net.rsprox.proxy.binary.BinaryBlob
import net.rsprox.proxy.binary.BinaryStream
import net.rsprox.shared.StreamDirection
Expand All @@ -24,10 +29,25 @@ public class DecodingSession(
val session = Session(blob.header.localPlayerIndex, AttributeMap())
return stream.flatMap { binaryPacket ->
try {
if (binaryPacket.direction == StreamDirection.CLIENT_TO_SERVER) {
val packet =
plugin.decodeClientPacket(
binaryPacket.prot.opcode,
binaryPacket.payload.toJagByteBuf(),
session,
)
return@flatMap listOf(
DirectionalPacket(
binaryPacket.direction,
binaryPacket.prot,
packet,
),
)
}
var read = binaryPacket.payload.readableBytes()
val prot = binaryPacket.prot
val opcode = prot.opcode
if (binaryPacket.direction == StreamDirection.CLIENT_TO_SERVER || opcode < 128) {
if (opcode < 128) {
read++
} else {
read += 2
Expand All @@ -39,22 +59,11 @@ public class DecodingSession(
}
val remainingBytesInPacketGroup = session.getRemainingBytesInPacketGroup()
val packet =
when (binaryPacket.direction) {
StreamDirection.CLIENT_TO_SERVER -> {
plugin.decodeClientPacket(
binaryPacket.prot.opcode,
binaryPacket.payload.toJagByteBuf(),
session,
)
}
StreamDirection.SERVER_TO_CLIENT -> {
plugin.decodeServerPacket(
binaryPacket.prot.opcode,
binaryPacket.payload.toJagByteBuf(),
session,
)
}
}
plugin.decodeServerPacket(
binaryPacket.prot.opcode,
binaryPacket.payload.toJagByteBuf(),
session,
)
if (remainingBytesInPacketGroup != null && remainingBytesInPacketGroup > 0) {
session.setBytesConsumed((session.getBytesConsumed() ?: 0) + read)
if (remainingBytesInPacketGroup - read <= 0) {
Expand Down

0 comments on commit f89f826

Please sign in to comment.