Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit 44ffd7d

Browse files
committed
feat: add client and server properties to improve connection and packet listener integration
- Introduced `client` property in `Connection` and `CommonPacketListener` for enhanced interaction with `NettyClient` instances. - Added `server` property to `NettyClient` implementations for improved reference to `CommonCloudServer`. - Updated relevant constructors in packet listeners to ensure `client` property is overridden for consistency. - Refactored `ConnectionImpl` and `CommonNettyClientImpl` to provide lazy-loaded access to new properties.
1 parent dc339d1 commit 44ffd7d

File tree

9 files changed

+23
-5
lines changed

9 files changed

+23
-5
lines changed

surf-cloud-api/surf-cloud-api-common/src/main/kotlin/dev/slne/surf/cloud/api/common/netty/NettyClient.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import dev.slne.surf.cloud.api.common.netty.packet.DEFAULT_TIMEOUT
55
import dev.slne.surf.cloud.api.common.netty.packet.NettyPacket
66
import dev.slne.surf.cloud.api.common.netty.packet.RespondingNettyPacket
77
import dev.slne.surf.cloud.api.common.netty.packet.ResponseNettyPacket
8+
import dev.slne.surf.cloud.api.common.server.CommonCloudServer
89
import kotlin.time.Duration
910

1011
/**
@@ -18,6 +19,8 @@ interface NettyClient {
1819

1920
val connection: Connection
2021

22+
val server: CommonCloudServer?
23+
2124
/**
2225
* Sends a packet to the server without waiting for a response.
2326
*

surf-cloud-api/surf-cloud-api-common/src/main/kotlin/dev/slne/surf/cloud/api/common/netty/network/Connection.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.slne.surf.cloud.api.common.netty.network
22

3+
import dev.slne.surf.cloud.api.common.netty.NettyClient
34
import dev.slne.surf.cloud.api.common.netty.packet.NettyPacket
45
import kotlinx.coroutines.CompletableDeferred
56
import java.net.InetSocketAddress
@@ -18,6 +19,8 @@ interface Connection {
1819
val hostname: String
1920
val virtualHost: InetSocketAddress
2021

22+
val client: NettyClient?
23+
2124
/**
2225
* Sends a packet to the connection.
2326
*

surf-cloud-core/surf-cloud-core-client/src/main/kotlin/dev/slne/surf/cloud/core/client/netty/network/ClientPreRunningPacketListenerImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import kotlinx.coroutines.CompletableDeferred
1212
import kotlinx.coroutines.launch
1313

1414
class ClientPreRunningPacketListenerImpl(
15-
val client: ClientNettyClientImpl,
15+
override val client: ClientNettyClientImpl,
1616
connection: ConnectionImpl,
1717
val platformExtension: PlatformSpecificPacketListenerExtension,
1818
val statusUpdater: AbstractStatusUpdater,

surf-cloud-core/surf-cloud-core-client/src/main/kotlin/dev/slne/surf/cloud/core/client/netty/network/ClientRunningPacketListenerImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import java.util.concurrent.TimeUnit
4242

4343
class ClientRunningPacketListenerImpl(
4444
connection: ConnectionImpl,
45-
val client: ClientNettyClientImpl,
45+
override val client: ClientNettyClientImpl,
4646
val platformExtension: PlatformSpecificPacketListenerExtension
4747
) : ClientCommonPacketListenerImpl(connection), RunningClientPacketListener {
4848
private val log = logger()

surf-cloud-core/surf-cloud-core-client/src/main/kotlin/dev/slne/surf/cloud/core/client/netty/network/ClientSynchronizingPacketListenerImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import dev.slne.surf.surfapi.core.api.util.logger
2020
import kotlinx.coroutines.launch
2121

2222
class ClientSynchronizingPacketListenerImpl(
23-
val client: ClientNettyClientImpl,
23+
override val client: ClientNettyClientImpl,
2424
connection: ConnectionImpl,
2525
val platformExtension: PlatformSpecificPacketListenerExtension,
2626
val statusUpdater: AbstractStatusUpdater,

surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/CommonNettyClientImpl.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import dev.slne.surf.cloud.api.common.netty.NettyClient
44
import dev.slne.surf.cloud.api.common.netty.packet.NettyPacket
55
import dev.slne.surf.cloud.api.common.netty.packet.RespondingNettyPacket
66
import dev.slne.surf.cloud.api.common.netty.packet.ResponseNettyPacket
7+
import dev.slne.surf.cloud.api.common.server.CloudServer
8+
import dev.slne.surf.cloud.api.common.server.CommonCloudServer
9+
import dev.slne.surf.cloud.core.common.netty.network.ConnectionImpl
710
import dev.slne.surf.surfapi.core.api.util.mutableObject2ObjectMapOf
811
import dev.slne.surf.surfapi.core.api.util.synchronize
9-
import dev.slne.surf.cloud.core.common.netty.network.ConnectionImpl
1012
import kotlinx.coroutines.CompletableDeferred
1113
import java.net.InetSocketAddress
1214
import kotlin.time.Duration
@@ -40,6 +42,9 @@ abstract class CommonNettyClientImpl(
4042
abstract val playAddress: InetSocketAddress
4143
val displayName get() = "$serverName/$serverCategory (${_connection?.getLoggableAddress()})"
4244

45+
override val server: CommonCloudServer?
46+
get() = CloudServer[serverName]
47+
4348
override fun fireAndForget(packet: NettyPacket) {
4449
val connection = _connection
4550
if (connection == null) {

surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/network/ConnectionImpl.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dev.slne.surf.cloud.core.common.netty.network
22

33
import dev.slne.surf.cloud.api.common.exceptions.SkipPacketException
44
import dev.slne.surf.cloud.api.common.meta.SurfNettyPacket
5+
import dev.slne.surf.cloud.api.common.netty.NettyClient
56
import dev.slne.surf.cloud.api.common.netty.network.Connection
67
import dev.slne.surf.cloud.api.common.netty.network.ConnectionProtocol
78
import dev.slne.surf.cloud.api.common.netty.network.protocol.PacketFlow
@@ -133,6 +134,9 @@ class ConnectionImpl(
133134
val connecting get() = _channel == null
134135

135136

137+
override val client: NettyClient?
138+
get() = (_packetListener as? CommonPacketListener)?.client
139+
136140
override fun channelActive(ctx: ChannelHandlerContext) {
137141
super.channelActive(ctx)
138142
_channel = ctx.channel()
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package dev.slne.surf.cloud.core.common.netty.network.protocol.common
22

3+
import dev.slne.surf.cloud.core.common.netty.CommonNettyClientImpl
34
import dev.slne.surf.cloud.core.common.netty.network.PacketListener
45

56
interface CommonPacketListener : PacketListener {
67

8+
val client: CommonNettyClientImpl
9+
710
fun handleKeepAlive(packet: KeepAlivePacket)
811

912
}

surf-cloud-standalone/src/main/kotlin/dev/slne/surf/cloud/standalone/netty/server/network/ServerCommonPacketListenerImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import javax.annotation.OverridingMethodsMustInvokeSuper
2828
*/
2929
abstract class ServerCommonPacketListenerImpl(
3030
val server: NettyServerImpl,
31-
val client: ServerClientImpl,
31+
override val client: ServerClientImpl,
3232
val connection: ConnectionImpl
3333
) : CommonTickablePacketListener(), ServerCommonPacketListener {
3434
private val log = logger()

0 commit comments

Comments
 (0)