Skip to content

Commit

Permalink
feat: pass property filters to the transcribers
Browse files Browse the repository at this point in the history
  • Loading branch information
Z-Kris committed Aug 1, 2024
1 parent 7040319 commit 7b54b38
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 7 deletions.
1 change: 1 addition & 0 deletions proxy/src/main/kotlin/net/rsprox/proxy/ProxyService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ public class ProxyService(
pluginLoader,
properties.getProperty(BINARY_WRITE_INTERVAL_SECONDS),
connections,
filterSetStore,
)
val timeoutSeconds = properties.getProperty(BIND_TIMEOUT_SECONDS).toLong()
serverBootstrap
Expand Down
17 changes: 14 additions & 3 deletions proxy/src/main/kotlin/net/rsprox/proxy/binary/BinaryBlob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import net.rsprox.proxy.transcriber.LiveTranscriberSession
import net.rsprox.proxy.util.NopSessionMonitor
import net.rsprox.shared.SessionMonitor
import net.rsprox.shared.StreamDirection
import net.rsprox.shared.filters.PropertyFilterSetStore
import net.rsprox.transcriber.BaseMessageConsumerContainer
import net.rsprox.transcriber.MessageConsumer
import java.net.URL
Expand All @@ -37,6 +38,7 @@ public data class BinaryBlob(
public val stream: BinaryStream,
public val writeIntervalSeconds: Int,
private val monitor: SessionMonitor<BinaryHeader>,
private val filters: PropertyFilterSetStore,
) {
private var lastWrite = TimeSource.Monotonic.markNow()
private var lastWriteSize = 0
Expand Down Expand Up @@ -189,7 +191,13 @@ public data class BinaryBlob(
val consumers = BaseMessageConsumerContainer(listOf(MessageConsumer.STDOUT_CONSUMER))
val session = Session(header.localPlayerIndex, AttributeMap())
val decodingSession = DecodingSession(this, latestPlugin)
val runner = transcriberProvider.provide(consumers, provider, monitor)
val runner =
transcriberProvider.provide(
consumers,
provider,
monitor,
filters,
)
this.liveSession =
LiveTranscriberSession(
session,
Expand All @@ -207,15 +215,18 @@ public data class BinaryBlob(
private const val PORT: Int = 43_594
private val logger = InlineLogger()

public fun decode(path: Path): BinaryBlob {
public fun decode(
path: Path,
filters: PropertyFilterSetStore,
): BinaryBlob {
val file = path.toFile()
if (!file.isFile) {
throw IllegalArgumentException("Path does not point to a file: $path")
}
val buffer = Unpooled.wrappedBuffer(file.readBytes())
val header = BinaryHeader.decode(buffer.toJagByteBuf())
val stream = BinaryStream(buffer.slice())
return BinaryBlob(header, stream, 0, NopSessionMonitor)
return BinaryBlob(header, stream, 0, NopSessionMonitor, filters)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import net.rsprox.proxy.http.HttpServerHandler
import net.rsprox.proxy.plugin.PluginLoader
import net.rsprox.proxy.server.ServerConnectionInitializer
import net.rsprox.proxy.worlds.WorldListProvider
import net.rsprox.shared.filters.PropertyFilterSetStore
import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters

public class BootstrapFactory(
Expand All @@ -36,6 +37,7 @@ public class BootstrapFactory(
pluginLoader: PluginLoader,
binaryWriteInterval: Int,
connections: ProxyConnectionContainer,
filters: PropertyFilterSetStore,
): ServerBootstrap {
return ServerBootstrap()
.group(group(PARENT_GROUP_THREADS), group(CHILD_GROUP_THREADS))
Expand All @@ -55,6 +57,7 @@ public class BootstrapFactory(
pluginLoader,
binaryWriteInterval,
connections,
filters,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import net.rsprox.cache.resolver.HistoricCacheResolver
import net.rsprox.proxy.binary.BinaryBlob
import net.rsprox.proxy.cache.StatefulCacheProvider
import net.rsprox.proxy.config.BINARY_PATH
import net.rsprox.proxy.config.FILTERS_DIRECTORY
import net.rsprox.proxy.filters.DefaultPropertyFilterSetStore
import net.rsprox.proxy.huffman.HuffmanProvider
import net.rsprox.proxy.plugin.DecodingSession
import net.rsprox.proxy.plugin.PluginLoader
Expand Down Expand Up @@ -53,7 +55,8 @@ public class BinaryToStringCommand : CliktCommand(name = "tostring") {
pluginLoader: PluginLoader,
statefulCacheProvider: StatefulCacheProvider,
) {
val binary = BinaryBlob.decode(binaryPath)
val filters = DefaultPropertyFilterSetStore.load(FILTERS_DIRECTORY)
val binary = BinaryBlob.decode(binaryPath, filters)
statefulCacheProvider.update(
Js5MasterIndex.trimmed(
binary.header.revision,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import net.rsprox.cache.resolver.HistoricCacheResolver
import net.rsprox.proxy.binary.BinaryBlob
import net.rsprox.proxy.cache.StatefulCacheProvider
import net.rsprox.proxy.config.BINARY_PATH
import net.rsprox.proxy.config.FILTERS_DIRECTORY
import net.rsprox.proxy.filters.DefaultPropertyFilterSetStore
import net.rsprox.proxy.huffman.HuffmanProvider
import net.rsprox.proxy.plugin.DecodingSession
import net.rsprox.proxy.plugin.PluginLoader
Expand Down Expand Up @@ -69,7 +71,8 @@ public class TranscribeCommand : CliktCommand(name = "transcribe") {
pluginLoader: PluginLoader,
statefulCacheProvider: StatefulCacheProvider,
) {
val binary = BinaryBlob.decode(binaryPath)
val filters = DefaultPropertyFilterSetStore.load(FILTERS_DIRECTORY)
val binary = BinaryBlob.decode(binaryPath, filters)
statefulCacheProvider.update(
Js5MasterIndex.trimmed(
binary.header.revision,
Expand All @@ -86,6 +89,7 @@ public class TranscribeCommand : CliktCommand(name = "transcribe") {
consumers,
statefulCacheProvider,
NopSessionMonitor,
filters,
)

writer.appendLine("------------------")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import net.rsprox.proxy.server.ServerRelayHandler
import net.rsprox.proxy.server.prot.LoginServerProtId
import net.rsprox.proxy.server.prot.LoginServerProtProvider
import net.rsprox.proxy.worlds.WorldListProvider
import net.rsprox.shared.filters.PropertyFilterSetStore
import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters

public class ClientLoginHandler(
Expand All @@ -44,6 +45,7 @@ public class ClientLoginHandler(
private val worldListProvider: WorldListProvider,
private val pluginLoader: PluginLoader,
private val connections: ProxyConnectionContainer,
private val filters: PropertyFilterSetStore,
) : SimpleChannelInboundHandler<ClientPacket<LoginClientProt>>() {
override fun channelRead0(
ctx: ChannelHandlerContext,
Expand Down Expand Up @@ -232,6 +234,7 @@ public class ClientLoginHandler(
worldListProvider,
pluginLoader,
connections,
filters,
),
)
pipeline.addLastWithName(ServerRelayHandler(ctx.channel()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import net.rsprox.proxy.plugin.PluginLoader
import net.rsprox.proxy.util.ChannelConnectionHandler
import net.rsprox.proxy.worlds.LocalHostAddress
import net.rsprox.proxy.worlds.WorldListProvider
import net.rsprox.shared.filters.PropertyFilterSetStore
import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters
import java.net.Inet4Address
import java.net.InetSocketAddress
Expand All @@ -27,6 +28,7 @@ public class ClientLoginInitializer(
private val pluginLoader: PluginLoader,
private val binaryWriteInterval: Int,
private val connections: ProxyConnectionContainer,
private val filters: PropertyFilterSetStore,
) : ChannelInitializer<Channel>() {
override fun initChannel(clientChannel: Channel) {
val localHostAddress = getLocalHostAddress(clientChannel)
Expand Down Expand Up @@ -70,6 +72,7 @@ public class ClientLoginInitializer(
worldListProvider,
pluginLoader,
connections,
filters,
),
)
clientChannel.pipeline().addLast(ChannelConnectionHandler(serverChannel))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ import net.rsprox.proxy.plugin.PluginLoader
import net.rsprox.proxy.server.prot.GameServerProtProvider
import net.rsprox.proxy.util.UserUid
import net.rsprox.proxy.worlds.WorldListProvider
import net.rsprox.shared.filters.PropertyFilterSetStore

public class ServerGameLoginDecoder(
private val clientChannel: Channel,
private val binaryWriteInterval: Int,
private val worldListProvider: WorldListProvider,
private val pluginLoader: PluginLoader,
private val connections: ProxyConnectionContainer,
private val filters: PropertyFilterSetStore,
) : ByteToMessageDecoder() {
private enum class State {
AWAITING_GAME_CONNECTION_REPLY,
Expand Down Expand Up @@ -247,7 +249,7 @@ public class ServerGameLoginDecoder(
val port = clientChannel.getPort()
val sessionMonitor = connections.getSessionMonitor(port)
sessionMonitor.onLogin(header)
val blob = BinaryBlob(header, stream, binaryWriteInterval, sessionMonitor)
val blob = BinaryBlob(header, stream, binaryWriteInterval, sessionMonitor, filters)
blob.hookLiveTranscriber(key, pluginLoader)
val serverChannel = ctx.channel()
connections.addConnection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package net.rsprox.transcriber

import net.rsprox.cache.api.CacheProvider
import net.rsprox.shared.SessionMonitor
import net.rsprox.shared.filters.PropertyFilterSetStore

public fun interface TranscriberProvider {
public fun provide(
container: BaseMessageConsumerContainer,
cacheProvider: CacheProvider,
monitor: SessionMonitor<*>,
filters: PropertyFilterSetStore,
): TranscriberRunner
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import net.rsprox.cache.api.Cache
import net.rsprox.cache.api.CacheProvider
import net.rsprox.protocol.game.outgoing.decoder.prot.GameServerProt
import net.rsprox.shared.SessionMonitor
import net.rsprox.shared.filters.PropertyFilterSetStore
import net.rsprox.shared.property.PropertyTreeFormatter
import net.rsprox.transcriber.MessageConsumerContainer
import net.rsprox.transcriber.Transcriber
Expand All @@ -24,32 +25,41 @@ public class BaseTranscriber private constructor(
override val monitor: SessionMonitor<*>,
private val consumers: MessageConsumerContainer,
private val formatter: PropertyTreeFormatter,
private val filterSetStore: PropertyFilterSetStore,
) : Transcriber,
ClientPacketTranscriber by BaseClientPacketTranscriber(stateTracker),
ClientPacketTranscriber by BaseClientPacketTranscriber(
stateTracker,
filterSetStore,
),
ServerPacketTranscriber by BaseServerPacketTranscriber(
stateTracker,
cacheProvider.get(),
filterSetStore,
),
PlayerInfoTranscriber by BasePlayerInfoTranscriber(
stateTracker,
monitor,
filterSetStore,
),
NpcInfoTranscriber by BaseNpcInfoTranscriber(
stateTracker,
cacheProvider.get(),
filterSetStore,
) {
public constructor(
cacheProvider: CacheProvider,
monitor: SessionMonitor<*>,
stateTracker: StateTracker,
consumers: MessageConsumerContainer,
formatter: PropertyTreeFormatter,
filters: PropertyFilterSetStore,
) : this(
stateTracker,
cacheProvider,
monitor,
consumers,
formatter,
filters,
)

override val cache: Cache = cacheProvider.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.rsprox.transcriber.base

import net.rsprox.cache.api.CacheProvider
import net.rsprox.shared.SessionMonitor
import net.rsprox.shared.filters.PropertyFilterSetStore
import net.rsprox.shared.property.OmitFilteredPropertyTreeFormatter
import net.rsprox.shared.property.PropertyFormatterCollection
import net.rsprox.shared.property.SymbolDictionary
Expand All @@ -16,6 +17,7 @@ public class BaseTranscriberProvider : TranscriberProvider {
container: BaseMessageConsumerContainer,
cacheProvider: CacheProvider,
monitor: SessionMonitor<*>,
filters: PropertyFilterSetStore,
): TranscriberRunner {
val stateTracker = StateTracker()
val formatter =
Expand All @@ -31,6 +33,7 @@ public class BaseTranscriberProvider : TranscriberProvider {
stateTracker,
container,
formatter,
filters,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import net.rsprox.protocol.game.incoming.model.social.IgnoreListAdd
import net.rsprox.protocol.game.incoming.model.social.IgnoreListDel
import net.rsprox.protocol.reflection.ReflectionCheck
import net.rsprox.shared.ScriptVarType
import net.rsprox.shared.filters.PropertyFilterSet
import net.rsprox.shared.filters.PropertyFilterSetStore
import net.rsprox.shared.property.ChildProperty
import net.rsprox.shared.property.NamedEnum
import net.rsprox.shared.property.Property
Expand Down Expand Up @@ -99,9 +101,12 @@ import java.text.NumberFormat
@Suppress("SpellCheckingInspection", "DuplicatedCode")
public open class BaseClientPacketTranscriber(
private val stateTracker: StateTracker,
private val filterSetStore: PropertyFilterSetStore,
) : ClientPacketTranscriber {
private val root: RootProperty<*>
get() = stateTracker.root
private val filters: PropertyFilterSet
get() = filterSetStore.getActive()

private fun Property.npc(index: Int): ChildProperty<*> {
val npc = stateTracker.getActiveWorld().getNpcOrNull(index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import net.rsprox.protocol.game.outgoing.model.info.shared.extendedinfo.Sequence
import net.rsprox.protocol.game.outgoing.model.info.shared.extendedinfo.SpotanimExtendedInfo
import net.rsprox.protocol.game.outgoing.model.info.shared.extendedinfo.TintingExtendedInfo
import net.rsprox.shared.ScriptVarType
import net.rsprox.shared.filters.PropertyFilterSet
import net.rsprox.shared.filters.PropertyFilterSetStore
import net.rsprox.shared.property.ChildProperty
import net.rsprox.shared.property.NamedEnum
import net.rsprox.shared.property.Property
Expand Down Expand Up @@ -55,9 +57,12 @@ import net.rsprox.transcriber.state.StateTracker
public class BaseNpcInfoTranscriber(
private val stateTracker: StateTracker,
private val cache: Cache,
private val filterSetStore: PropertyFilterSetStore,
) : NpcInfoTranscriber {
private val root: RootProperty<*>
get() = stateTracker.root
private val filters: PropertyFilterSet
get() = filterSetStore.getActive()

private fun Property.entity(ambiguousIndex: Int): ChildProperty<*> {
return if (ambiguousIndex > 0xFFFF) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import net.rsprox.protocol.game.outgoing.model.info.shared.extendedinfo.Spotanim
import net.rsprox.protocol.game.outgoing.model.info.shared.extendedinfo.TintingExtendedInfo
import net.rsprox.shared.ScriptVarType
import net.rsprox.shared.SessionMonitor
import net.rsprox.shared.filters.PropertyFilterSet
import net.rsprox.shared.filters.PropertyFilterSetStore
import net.rsprox.shared.property.ChildProperty
import net.rsprox.shared.property.NamedEnum
import net.rsprox.shared.property.Property
Expand Down Expand Up @@ -49,9 +51,12 @@ import net.rsprox.transcriber.state.StateTracker
public class BasePlayerInfoTranscriber(
private val stateTracker: StateTracker,
private val monitor: SessionMonitor<*>,
private val filterSetStore: PropertyFilterSetStore,
) : PlayerInfoTranscriber {
private val root: RootProperty<*>
get() = stateTracker.root
private val filters: PropertyFilterSet
get() = filterSetStore.getActive()

private fun Property.entity(ambiguousIndex: Int): ChildProperty<*> {
return if (ambiguousIndex > 0xFFFF) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ import net.rsprox.protocol.game.outgoing.model.zone.payload.ObjEnabledOps
import net.rsprox.protocol.game.outgoing.model.zone.payload.SoundArea
import net.rsprox.protocol.reflection.ReflectionCheck
import net.rsprox.shared.ScriptVarType
import net.rsprox.shared.filters.PropertyFilterSet
import net.rsprox.shared.filters.PropertyFilterSetStore
import net.rsprox.shared.property.ChildProperty
import net.rsprox.shared.property.NamedEnum
import net.rsprox.shared.property.Property
Expand Down Expand Up @@ -184,9 +186,12 @@ import java.util.concurrent.TimeUnit
public class BaseServerPacketTranscriber(
private val stateTracker: StateTracker,
private val cache: Cache,
private val filterSetStore: PropertyFilterSetStore,
) : ServerPacketTranscriber {
private val root: RootProperty<*>
get() = stateTracker.root
private val filters: PropertyFilterSet
get() = filterSetStore.getActive()

private fun Property.npc(index: Int): ChildProperty<*> {
val npc = stateTracker.getActiveWorld().getNpcOrNull(index)
Expand Down

0 comments on commit 7b54b38

Please sign in to comment.