From afbd08bc27433c548f2536f6b9e6be6f91895b8d Mon Sep 17 00:00:00 2001 From: erwan-joly Date: Fri, 24 Apr 2026 13:00:16 +1200 Subject: [PATCH] Expose RemoteAddress on IChannel for session-IP consumers Needed so hosts can correlate a ClientSession to its peer IP without reaching into SuperSocket internals. NetworkChannel resolves it via IPEndPoint.Address; returns null when the underlying session has no routable endpoint. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/NosCore.Networking/IChannel.cs | 6 ++++++ src/NosCore.Networking/NetworkChannel.cs | 7 +++++++ src/NosCore.Networking/NosCore.Networking.csproj | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/NosCore.Networking/IChannel.cs b/src/NosCore.Networking/IChannel.cs index a1d7e15..b41e930 100644 --- a/src/NosCore.Networking/IChannel.cs +++ b/src/NosCore.Networking/IChannel.cs @@ -19,6 +19,12 @@ public interface IChannel /// string Id { get; } + /// + /// Gets the remote peer's IP address as a string, or null if the + /// underlying session has no routable endpoint yet. + /// + string? RemoteAddress { get; } + /// /// Disconnects the channel asynchronously. /// diff --git a/src/NosCore.Networking/NetworkChannel.cs b/src/NosCore.Networking/NetworkChannel.cs index 1e04c18..97c3b9a 100644 --- a/src/NosCore.Networking/NetworkChannel.cs +++ b/src/NosCore.Networking/NetworkChannel.cs @@ -5,6 +5,7 @@ // ----------------------------------- using System; +using System.Net; using System.Threading.Tasks; using SuperSocket.Connection; using SuperSocket.Server.Abstractions.Session; @@ -32,6 +33,12 @@ public NetworkChannel(IAppSession session) /// public string Id => _session.SessionID; + /// + /// Gets the remote peer's IP address as a string, or null if the + /// underlying session has no routable endpoint yet. + /// + public string? RemoteAddress => (_session.RemoteEndPoint as IPEndPoint)?.Address.ToString(); + /// /// Disconnects the channel asynchronously. /// diff --git a/src/NosCore.Networking/NosCore.Networking.csproj b/src/NosCore.Networking/NosCore.Networking.csproj index 1e9a358..ce41266 100644 --- a/src/NosCore.Networking/NosCore.Networking.csproj +++ b/src/NosCore.Networking/NosCore.Networking.csproj @@ -12,7 +12,7 @@ https://github.com/NosCoreIO/NosCore.Networking.git nostale, noscore, nostale private server source, nostale emulator - 7.1.0 + 7.2.0 false NosCore Networking MIT