Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions surf-cloud-api/surf-cloud-api-common/api/surf-cloud-api-common.api
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,7 @@ public abstract interface annotation class dev/slne/surf/cloud/api/common/meta/S
}

public abstract interface annotation class dev/slne/surf/cloud/api/common/meta/SurfNettyPacketHandler : java/lang/annotation/Annotation {
public abstract fun classes ()[Ljava/lang/Class;
public abstract fun condition ()Ljava/lang/String;
public abstract fun id ()Ljava/lang/String;
public abstract fun value ()[Ljava/lang/Class;
}

public abstract interface class dev/slne/surf/cloud/api/common/netty/NettyClient {
Expand Down Expand Up @@ -1237,17 +1234,14 @@ public final class dev/slne/surf/cloud/api/common/netty/packet/NettyPacket$Compa
}

public final class dev/slne/surf/cloud/api/common/netty/packet/NettyPacketInfo {
public static final synthetic fun box-impl (Ldev/slne/surf/cloud/api/common/netty/network/Connection;)Ldev/slne/surf/cloud/api/common/netty/packet/NettyPacketInfo;
public static fun constructor-impl (Ldev/slne/surf/cloud/api/common/netty/network/Connection;)Ldev/slne/surf/cloud/api/common/netty/network/Connection;
public fun <init> (Ldev/slne/surf/cloud/api/common/netty/network/Connection;)V
public final fun component1 ()Ldev/slne/surf/cloud/api/common/netty/network/Connection;
public final fun copy (Ldev/slne/surf/cloud/api/common/netty/network/Connection;)Ldev/slne/surf/cloud/api/common/netty/packet/NettyPacketInfo;
public static synthetic fun copy$default (Ldev/slne/surf/cloud/api/common/netty/packet/NettyPacketInfo;Ldev/slne/surf/cloud/api/common/netty/network/Connection;ILjava/lang/Object;)Ldev/slne/surf/cloud/api/common/netty/packet/NettyPacketInfo;
public fun equals (Ljava/lang/Object;)Z
public static fun equals-impl (Ldev/slne/surf/cloud/api/common/netty/network/Connection;Ljava/lang/Object;)Z
public static final fun equals-impl0 (Ldev/slne/surf/cloud/api/common/netty/network/Connection;Ldev/slne/surf/cloud/api/common/netty/network/Connection;)Z
public final fun getOrigin ()Ldev/slne/surf/cloud/api/common/netty/network/Connection;
public fun hashCode ()I
public static fun hashCode-impl (Ldev/slne/surf/cloud/api/common/netty/network/Connection;)I
public fun toString ()Ljava/lang/String;
public static fun toString-impl (Ldev/slne/surf/cloud/api/common/netty/network/Connection;)Ljava/lang/String;
public final synthetic fun unbox-impl ()Ldev/slne/surf/cloud/api/common/netty/network/Connection;
}

public final class dev/slne/surf/cloud/api/common/netty/packet/Packet_extensionKt {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package dev.slne.surf.cloud.api.common.meta

import org.springframework.aot.hint.annotation.Reflective
import org.springframework.core.annotation.AliasFor
import kotlin.reflect.KClass

/**
* Annotation for marking methods in a component as packet handlers.
Expand All @@ -17,8 +15,5 @@ import kotlin.reflect.KClass
)
@Reflective
annotation class SurfNettyPacketHandler(
@get:AliasFor("classes") val value: Array<KClass<*>> = [],
@get:AliasFor("values") val classes: Array<KClass<*>> = [],
val condition: String = "",
val id: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ package dev.slne.surf.cloud.api.common.netty.packet

import dev.slne.surf.cloud.api.common.netty.network.Connection

@JvmInline
value class NettyPacketInfo(val origin: Connection)
data class NettyPacketInfo(val origin: Connection)
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import dev.slne.surf.cloud.api.common.netty.packet.NettyPacketInfo
import dev.slne.surf.cloud.api.common.util.isSuspending
import dev.slne.surf.cloud.api.common.util.mutableObject2ObjectMapOf
import it.unimi.dsi.fastutil.objects.Object2ObjectFunction
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
import it.unimi.dsi.fastutil.objects.ObjectSet
import java.lang.reflect.Method
import java.lang.reflect.Modifier
import kotlin.coroutines.Continuation
import kotlin.jvm.java
import kotlin.reflect.jvm.kotlinFunction

object NettyListenerRegistry {
private val listeners =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package dev.slne.surf.cloud.core.common.netty.registry.listener
import dev.slne.surf.cloud.api.common.netty.exception.SurfNettyListenerRegistrationException
import dev.slne.surf.cloud.api.common.netty.packet.NettyPacket
import dev.slne.surf.cloud.api.common.netty.packet.NettyPacketInfo
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import tech.hiddenproject.aide.reflection.LambdaWrapperHolder
import tech.hiddenproject.aide.reflection.annotation.Invoker
import java.lang.reflect.Method
Expand Down Expand Up @@ -49,35 +47,32 @@ class RegisteredListener(
}
}

suspend fun handle(packet: NettyPacket, info: NettyPacketInfo) =
withContext(Dispatchers.IO) {
when (invokerType) {
InvokerType.ONE_PARAM -> {
if (suspending) {
(invoker as RegisteredListenerSuspendInvoker1).handle(bean, packet)
} else {
(invoker as RegisteredListenerInvoker1).handle(bean, packet)
}
}

InvokerType.TWO_PARAMS -> {
if (suspending) {
(invoker as RegisteredListenerSuspendInvoker2).handle(bean, packet, info)
} else {
(invoker as RegisteredListenerInvoker2).handle(bean, packet, info)
}
}

InvokerType.TWO_PARAMS_REVERSED -> {
if (suspending) {
(invoker as RegisteredListenerSuspendInvoker2Rev).handle(bean, info, packet)
} else {
(invoker as RegisteredListenerInvoker2Rev).handle(bean, info, packet)
}
}
suspend fun handle(packet: NettyPacket, info: NettyPacketInfo) = when (invokerType) {
InvokerType.ONE_PARAM -> {
if (suspending) {
(invoker as RegisteredListenerSuspendInvoker1).handle(bean, packet)
} else {
(invoker as RegisteredListenerInvoker1).handle(bean, packet)
}
}

InvokerType.TWO_PARAMS -> {
if (suspending) {
(invoker as RegisteredListenerSuspendInvoker2).handle(bean, packet, info)
} else {
(invoker as RegisteredListenerInvoker2).handle(bean, packet, info)
}
}

InvokerType.TWO_PARAMS_REVERSED -> {
if (suspending) {
(invoker as RegisteredListenerSuspendInvoker2Rev).handle(bean, info, packet)
} else {
(invoker as RegisteredListenerInvoker2Rev).handle(bean, info, packet)
}
}
}

private enum class InvokerType {
ONE_PARAM,
TWO_PARAMS,
Expand Down
Loading