From aa1751071d58b12dbd032ee0155e358bf7eb7f14 Mon Sep 17 00:00:00 2001 From: Brian Choi Date: Sat, 2 May 2020 22:18:46 +0800 Subject: [PATCH] Add interface method for CreateRelayServer --- .../SteamNetworkingSockets.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Facepunch.Steamworks/SteamNetworkingSockets.cs b/Facepunch.Steamworks/SteamNetworkingSockets.cs index 1891309..ea5e983 100644 --- a/Facepunch.Steamworks/SteamNetworkingSockets.cs +++ b/Facepunch.Steamworks/SteamNetworkingSockets.cs @@ -167,6 +167,9 @@ public static ConnectionManager ConnectNormal( NetAddress address, IConnectionMa /// /// Creates a server that will be relayed via Valve's network (hiding the IP and improving ping) + /// + /// To use this derive a class from SocketManager and override as much as you want. + /// /// public static T CreateRelaySocket( int virtualport = 0 ) where T : SocketManager, new() { @@ -178,6 +181,31 @@ public static ConnectionManager ConnectNormal( NetAddress address, IConnectionMa return t; } + /// + /// Creates a server that will be relayed via Valve's network (hiding the IP and improving ping) + /// + /// To use this you should pass a class that inherits ISocketManager. You can use + /// SocketManager to get connections and send messages, but the ISocketManager class + /// will received all the appropriate callbacks. + /// + /// + public static SocketManager CreateRelaySocket( int virtualport, ISocketManager intrface ) + { + var options = Array.Empty(); + var socket = Internal.CreateListenSocketP2P( virtualport, options.Length, options ); + + var t = new SocketManager + { + Socket = socket, + Interface = intrface + }; + + t.Initialize(); + + SetSocketManager( t.Socket.Id, t ); + return t; + } + /// /// Connect to a relay server ///