Add Protocol constants

Signed-off-by: Graham <gpe@openrs2.org>
Graham 4 years ago
parent 484c52af8e
commit a3cca0e6c3
  1. 9
      archive/src/main/kotlin/org/openrs2/archive/cache/Js5ChannelInitializer.kt
  2. 20
      protocol/src/main/kotlin/org/openrs2/protocol/Protocol.kt

@ -6,18 +6,13 @@ import io.netty.handler.timeout.ReadTimeoutHandler
import org.openrs2.protocol.Protocol
import org.openrs2.protocol.Rs2Decoder
import org.openrs2.protocol.Rs2Encoder
import org.openrs2.protocol.login.ClientOutOfDateCodec
import org.openrs2.protocol.login.InitJs5RemoteConnectionCodec
import org.openrs2.protocol.login.IpLimitCodec
import org.openrs2.protocol.login.Js5OkCodec
import org.openrs2.protocol.login.ServerFullCodec
public class Js5ChannelInitializer(private val handler: Js5ChannelHandler) : ChannelInitializer<Channel>() {
override fun initChannel(ch: Channel) {
ch.pipeline().addLast(
ReadTimeoutHandler(30),
Rs2Encoder(Protocol(InitJs5RemoteConnectionCodec)),
Rs2Decoder(Protocol(Js5OkCodec, ClientOutOfDateCodec, IpLimitCodec, ServerFullCodec)),
Rs2Encoder(Protocol.LOGIN_UPSTREAM),
Rs2Decoder(Protocol.LOGIN_DOWNSTREAM),
handler
)
}

@ -1,5 +1,12 @@
package org.openrs2.protocol
import org.openrs2.protocol.login.ClientOutOfDateCodec
import org.openrs2.protocol.login.InitJaggrabConnectionCodec
import org.openrs2.protocol.login.InitJs5RemoteConnectionCodec
import org.openrs2.protocol.login.IpLimitCodec
import org.openrs2.protocol.login.Js5OkCodec
import org.openrs2.protocol.login.ServerFullCodec
public class Protocol(vararg codecs: PacketCodec<*>) {
private val decoders = arrayOfNulls<PacketCodec<*>>(256)
private val encoders = codecs.associateBy(PacketCodec<*>::type)
@ -19,4 +26,17 @@ public class Protocol(vararg codecs: PacketCodec<*>) {
public fun <T : Packet> getEncoder(type: Class<T>): PacketCodec<T>? {
return encoders[type] as PacketCodec<T>?
}
public companion object {
public val LOGIN_UPSTREAM: Protocol = Protocol(
InitJs5RemoteConnectionCodec,
InitJaggrabConnectionCodec
)
public val LOGIN_DOWNSTREAM: Protocol = Protocol(
Js5OkCodec,
ClientOutOfDateCodec,
ServerFullCodec,
IpLimitCodec
)
}
}

Loading…
Cancel
Save