diff --git a/Facepunch.Steamworks.Test/Client/Networking.cs b/Facepunch.Steamworks.Test/Client/Networking.cs index c8f872d..c9206ad 100644 --- a/Facepunch.Steamworks.Test/Client/Networking.cs +++ b/Facepunch.Steamworks.Test/Client/Networking.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Text; using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -27,6 +28,17 @@ namespace Facepunch.Steamworks.Test OutputReceived = true; }; + client.Networking.OnIncomingConnection = ( steamid ) => + { + Console.WriteLine( "Incoming P2P Connection: " + steamid ); + return true; + }; + + client.Networking.OnConnectionFailed = ( steamid, error ) => + { + Console.WriteLine( "Connection Error: " + steamid + " - " + error ); + }; + client.Networking.SendP2PPacket( client.SteamId, data, data.Length ); while( true ) @@ -39,5 +51,58 @@ namespace Facepunch.Steamworks.Test } } } + + [TestMethod] + public void PeerToPeerFailure() + { + using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) + { + var TestString = "This string will be transformed to bytes, sent over the Steam P2P network, then converted back to a string."; + var TimeoutReceived = false; + var data = Encoding.UTF8.GetBytes( TestString ); + + client.Networking.OnIncomingConnection = ( steamid ) => + { + Console.WriteLine( "Incoming P2P Connection: " + steamid ); + + return true; + }; + + client.Networking.OnConnectionFailed = ( steamid, error ) => + { + Console.WriteLine( "Connection Error: " + steamid + " - " + error ); + TimeoutReceived = true; + }; + + ulong rand = (ulong) new Random().Next( 1024 * 16 ); + + // Send to an invalid, not listening steamid + if ( !client.Networking.SendP2PPacket( client.SteamId + rand, data, data.Length ) ) + { + Console.WriteLine( "Couldn't send packet" ); + return; + } + + var sw = Stopwatch.StartNew(); + + while ( true ) + { + Thread.Sleep( 10 ); + client.Update(); + + // + // Timout is usually around 15 seconds + // + if ( TimeoutReceived ) + break; + + if ( sw.Elapsed.TotalSeconds > 30 ) + { + Assert.Fail( "Didn't time out" ); + } + } + } + } + } } diff --git a/Facepunch.Steamworks.Test/Server/Server.cs b/Facepunch.Steamworks.Test/Server/Server.cs index 6e10391..ca228d9 100644 --- a/Facepunch.Steamworks.Test/Server/Server.cs +++ b/Facepunch.Steamworks.Test/Server/Server.cs @@ -31,12 +31,8 @@ namespace Facepunch.Steamworks.Test using ( var server = new Facepunch.Steamworks.Server( 252490, 30001, 30002, 30003, true, "VersionString" ) ) { - - server.LogOnAnonymous(); - - Assert.IsTrue( server.Valid ); var auth = server.Auth; diff --git a/Facepunch.Steamworks/BaseSteamworks.cs b/Facepunch.Steamworks/BaseSteamworks.cs new file mode 100644 index 0000000..1f39970 --- /dev/null +++ b/Facepunch.Steamworks/BaseSteamworks.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Facepunch.Steamworks +{ + public class BaseSteamworks : IDisposable + { + public virtual void Dispose() + { + foreach ( var d in Disposables ) + { + d.Dispose(); + } + Disposables.Clear(); + + if ( native != null ) + { + native.Dispose(); + native = null; + } + } + + internal Interop.NativeInterface native; + internal virtual bool IsGameServer { get { return false; } } + + private List Disposables = new List(); + + public enum MessageType : int + { + Message = 0, + Warning = 1 + } + + /// + /// Called with a message from Steam + /// + public Action OnMessage; + + internal void AddCallback( Action Callback, int id ) + { + var callback = new Facepunch.Steamworks.Interop.Callback( IsGameServer, id, Callback ); + Disposables.Add( callback ); + } + } +} \ No newline at end of file diff --git a/Facepunch.Steamworks/Callbacks/Index.cs b/Facepunch.Steamworks/Callbacks/Index.cs new file mode 100644 index 0000000..01209b5 --- /dev/null +++ b/Facepunch.Steamworks/Callbacks/Index.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Facepunch.Steamworks.Callbacks +{ + internal static class Index + { + internal const int User = 100; + internal const int Networking = 1200; + internal const int RemoteStorage = 1300; + } +} diff --git a/Facepunch.Steamworks/Callbacks/Networking.cs b/Facepunch.Steamworks/Callbacks/Networking.cs new file mode 100644 index 0000000..1f7add2 --- /dev/null +++ b/Facepunch.Steamworks/Callbacks/Networking.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; + +namespace Facepunch.Steamworks.Callbacks.Networking +{ + [StructLayout( LayoutKind.Sequential )] + internal class P2PSessionRequest + { + public ulong SteamID; + + public const int CallbackId = Index.Networking + 2; + }; + + [StructLayout( LayoutKind.Sequential )] + internal class P2PSessionConnectFail + { + public ulong SteamID; + public Steamworks.Networking.SessionError Error; + + public const int CallbackId = Index.Networking + 3; + }; + + +} diff --git a/Facepunch.Steamworks/Callbacks/User.cs b/Facepunch.Steamworks/Callbacks/User.cs index b5768e0..a005722 100644 --- a/Facepunch.Steamworks/Callbacks/User.cs +++ b/Facepunch.Steamworks/Callbacks/User.cs @@ -30,8 +30,5 @@ namespace Facepunch.Steamworks.Callbacks.User public const int CallbackId = Index.User + 43; }; - internal static class Index - { - internal const int User = 100; - } + } diff --git a/Facepunch.Steamworks/Client.cs b/Facepunch.Steamworks/Client.cs index 8c41e3e..145ba22 100644 --- a/Facepunch.Steamworks/Client.cs +++ b/Facepunch.Steamworks/Client.cs @@ -5,86 +5,8 @@ using System.Runtime.InteropServices; namespace Facepunch.Steamworks { - public partial class Client : IDisposable + public partial class Client : BaseSteamworks { - internal class Internal : IDisposable - { - private int _hpipe; - private int _huser; - - internal Valve.Steamworks.ISteamClient client; - internal Valve.Steamworks.ISteamUser user; - internal Valve.Steamworks.ISteamApps apps; - internal Valve.Steamworks.ISteamFriends friends; - internal Valve.Steamworks.ISteamMatchmakingServers servers; - internal Valve.Steamworks.ISteamInventory inventory; - internal Valve.Steamworks.ISteamNetworking networking; - internal Valve.Steamworks.ISteamUserStats userstats; - internal Valve.Steamworks.ISteamUtils utils; - internal Valve.Steamworks.ISteamScreenshots screenshots; - - internal bool Init() - { - _huser = Valve.Interop.NativeEntrypoints.Extended.SteamAPI_GetHSteamUser(); - _hpipe = Valve.Interop.NativeEntrypoints.Extended.SteamAPI_GetHSteamPipe(); - if ( _hpipe == 0 ) - throw new System.Exception( "Couldn't get Steam Pipe" ); - - var clientPtr = Valve.Interop.NativeEntrypoints.Extended.SteamInternal_CreateInterface( "SteamClient017" ); - if ( clientPtr == IntPtr.Zero ) - { - throw new System.Exception( "Steam Client: Couldn't load SteamClient017" ); - } - - client = new Valve.Steamworks.CSteamClient( clientPtr ); - - if ( client.GetIntPtr() == IntPtr.Zero ) - { - client = null; - return false; - } - - friends = client.GetISteamFriends( _huser, _hpipe, "SteamFriends015" ); - if ( friends.GetIntPtr() == IntPtr.Zero ) throw new System.Exception( "Couldn't load SteamFriends015" ); - - user = client.GetISteamUser( _huser, _hpipe, "SteamUser019" ); - servers = client.GetISteamMatchmakingServers( _huser, _hpipe, "SteamMatchMakingServers002" ); - inventory = client.GetISteamInventory( _huser, _hpipe, "STEAMINVENTORY_INTERFACE_V001" ); - networking = client.GetISteamNetworking( _huser, _hpipe, "SteamNetworking005" ); - apps = client.GetISteamApps( _huser, _hpipe, "STEAMAPPS_INTERFACE_VERSION008" ); - userstats = client.GetISteamUserStats( _huser, _hpipe, "STEAMUSERSTATS_INTERFACE_VERSION011" ); - screenshots = client.GetISteamScreenshots( _huser, _hpipe, "STEAMSCREENSHOTS_INTERFACE_VERSION002" ); - - utils = client.GetISteamUtils( _hpipe, "SteamUtils008" ); - - return true; - } - - public void Dispose() - { - if ( _hpipe > 0 && client != null ) - { - // if ( _huser > 0 ) - // client.ReleaseUser( _hpipe, _huser ); - - // client.BReleaseSteamPipe( _hpipe ); - - _huser = 0; - _hpipe = 0; - } - - if ( client != null ) - { - client.BShutdownIfAllPipesClosed(); - client = null; - } - - Valve.Interop.NativeEntrypoints.Extended.SteamAPI_Shutdown(); - } - } - - internal Internal native; - /// /// Current running program's AppId /// @@ -105,33 +27,27 @@ namespace Facepunch.Steamworks /// public string BetaName { get; private set; } - public enum MessageType : int - { - Message = 0, - Warning = 1 - } - /// - /// Called with a message from Steam - /// - public Action OnMessage; + public Client( uint appId ) { Valve.Steamworks.SteamAPIInterop.SteamAPI_Init(); - native = new Internal(); + native = new Interop.NativeInterface(); // // Get other interfaces // - if ( !native.Init() ) + if ( !native.InitClient() ) { native.Dispose(); native = null; return; } + Networking = new Steamworks.Networking( this, native.networking ); + // // Set up warning hook callback // @@ -152,13 +68,15 @@ namespace Facepunch.Steamworks Update(); } - public void Dispose() + public override void Dispose() { if ( native != null) { native.Dispose(); native = null; } + + base.Dispose(); } [UnmanagedFunctionPointer( CallingConvention.Cdecl )] @@ -208,5 +126,7 @@ namespace Facepunch.Steamworks //return () => Valve.Steamworks.SteamAPI.UnregisterCallback( ptr ); return null; } + + public Networking Networking { get; internal set; } } } diff --git a/Facepunch.Steamworks/Facepunch.Steamworks.csproj b/Facepunch.Steamworks/Facepunch.Steamworks.csproj index c785f0b..3eebcb8 100644 --- a/Facepunch.Steamworks/Facepunch.Steamworks.csproj +++ b/Facepunch.Steamworks/Facepunch.Steamworks.csproj @@ -113,10 +113,12 @@ + + - + @@ -132,7 +134,9 @@ + + diff --git a/Facepunch.Steamworks/Client/Networking.cs b/Facepunch.Steamworks/Interfaces/Networking.cs similarity index 59% rename from Facepunch.Steamworks/Client/Networking.cs rename to Facepunch.Steamworks/Interfaces/Networking.cs index 35ee8fa..bf2f898 100644 --- a/Facepunch.Steamworks/Client/Networking.cs +++ b/Facepunch.Steamworks/Interfaces/Networking.cs @@ -3,51 +3,25 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using Facepunch.Steamworks.Callbacks.Networking; using Valve.Steamworks; namespace Facepunch.Steamworks { - public partial class Client : IDisposable - { - private Networking _net; - - public Networking Networking - { - get - { - if ( _net == null ) - _net = new Networking( this ); - - return _net; - } - } - } - public class Networking { public Action OnP2PData; + public Func OnIncomingConnection; + public Action OnConnectionFailed; - internal Client client; + internal ISteamNetworking networking; - internal class Callback + internal Networking( BaseSteamworks sw, ISteamNetworking networking ) { - internal delegate void P2PSessionRequest( P2PSessionRequest_t a ); - internal delegate void P2PSessionConnectFail( P2PSessionConnectFail_t a ); - } + this.networking = networking; - internal Networking( Client c ) - { - client = c; - - { - Callback.P2PSessionRequest cb = onP2PConnectionRequest; - client.InstallCallback( Valve.Steamworks.SteamAPI.k_iSteamNetworkingCallbacks + 2, cb ); - } - - { - Callback.P2PSessionConnectFail cb = onP2PConnectionFailed; - client.InstallCallback( Valve.Steamworks.SteamAPI.k_iSteamNetworkingCallbacks + 2, cb ); - } + sw.AddCallback( onP2PConnectionRequest, P2PSessionRequest.CallbackId ); + sw.AddCallback( onP2PConnectionFailed, P2PSessionConnectFail.CallbackId ); } internal void Update() @@ -65,17 +39,51 @@ namespace Facepunch.Steamworks } } - private void onP2PConnectionRequest( P2PSessionRequest_t o ) + private void onP2PConnectionRequest( P2PSessionRequest o ) { - Console.WriteLine( "onP2PConnectionRequest " + o.m_steamIDRemote ); + if ( OnIncomingConnection != null ) + { + var accept = OnIncomingConnection( o.SteamID ); + + if ( accept ) + { + networking.AcceptP2PSessionWithUser( o.SteamID ); + } + else + { + networking.CloseP2PSessionWithUser( o.SteamID ); + } + + return; + } + + // + // Default is to reject the session + // + networking.CloseP2PSessionWithUser( o.SteamID ); } - private void onP2PConnectionFailed( P2PSessionConnectFail_t o ) + public enum SessionError : byte { - Console.WriteLine( "onP2PConnectionFailed " + o.m_steamIDRemote ); + None = 0, + NotRunningApp = 1, // target is not running the same game + NoRightsToApp = 2, // local user doesn't own the app that is running + DestinationNotLoggedIn = 3, // target user isn't connected to Steam + Timeout = 4, // target isn't responding, perhaps not calling AcceptP2PSessionWithUser() + // corporate firewalls can also block this (NAT traversal is not firewall traversal) + // make sure that UDP ports 3478, 4379, and 4380 are open in an outbound direction + Max = 5 + }; + + private void onP2PConnectionFailed( P2PSessionConnectFail o ) + { + if ( OnConnectionFailed != null ) + { + OnConnectionFailed( o.SteamID, o.Error ); + } } - public enum EP2PSend : int + public enum SendType : int { /// /// Basic UDP send. Packets can't be bigger than 1200 bytes (your typical MTU size). Can be lost, or arrive out of order (rare). @@ -109,11 +117,11 @@ namespace Facepunch.Steamworks } - public unsafe bool SendP2PPacket( ulong steamid, byte[] data, int length, EP2PSend eP2PSendType = EP2PSend.Reliable, int nChannel = 0 ) + public unsafe bool SendP2PPacket( ulong steamid, byte[] data, int length, SendType eP2PSendType = SendType.Reliable, int nChannel = 0 ) { fixed ( byte* p = data ) { - return client.native.networking.SendP2PPacket( steamid, (IntPtr) p, (uint)length, (uint)eP2PSendType, nChannel ); + return networking.SendP2PPacket( steamid, (IntPtr) p, (uint)length, (uint)eP2PSendType, nChannel ); } } @@ -121,7 +129,7 @@ namespace Facepunch.Steamworks { uint DataAvailable = 0; - if ( !client.native.networking.IsP2PPacketAvailable( ref DataAvailable, channel ) || DataAvailable == 0 ) + if ( !networking.IsP2PPacketAvailable( ref DataAvailable, channel ) || DataAvailable == 0 ) return false; if ( ms.Capacity < DataAvailable ) @@ -133,7 +141,7 @@ namespace Facepunch.Steamworks fixed ( byte* p = ms.GetBuffer() ) { ulong steamid = 1; - if ( !client.native.networking.ReadP2PPacket( (IntPtr)p, (uint)DataAvailable, ref DataAvailable, ref steamid, channel ) || DataAvailable == 0 ) + if ( !networking.ReadP2PPacket( (IntPtr)p, (uint)DataAvailable, ref DataAvailable, ref steamid, channel ) || DataAvailable == 0 ) return false; ms.SetLength( DataAvailable ); diff --git a/Facepunch.Steamworks/Interop/Callback.cs b/Facepunch.Steamworks/Interop/Callback.cs index f75bb73..d99d376 100644 --- a/Facepunch.Steamworks/Interop/Callback.cs +++ b/Facepunch.Steamworks/Interop/Callback.cs @@ -99,7 +99,7 @@ namespace Facepunch.Steamworks.Interop return; } - //vTablePtr = VTable.CDecl.Callback.Get( OnRunCallback, GetSize ); + throw new System.NotImplementedException(); } } diff --git a/Facepunch.Steamworks/Interop/Native.cs b/Facepunch.Steamworks/Interop/Native.cs new file mode 100644 index 0000000..b0196d4 --- /dev/null +++ b/Facepunch.Steamworks/Interop/Native.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Facepunch.Steamworks.Interop +{ + internal class NativeInterface : IDisposable + { + internal Valve.Steamworks.ISteamClient client; + internal Valve.Steamworks.ISteamUser user; + internal Valve.Steamworks.ISteamApps apps; + internal Valve.Steamworks.ISteamFriends friends; + internal Valve.Steamworks.ISteamMatchmakingServers servers; + internal Valve.Steamworks.ISteamInventory inventory; + internal Valve.Steamworks.ISteamNetworking networking; + internal Valve.Steamworks.ISteamUserStats userstats; + internal Valve.Steamworks.ISteamUtils utils; + internal Valve.Steamworks.ISteamScreenshots screenshots; + internal Valve.Steamworks.ISteamHTTP http; + internal Valve.Steamworks.ISteamUGC ugc; + internal Valve.Steamworks.ISteamGameServer gameServer; + internal Valve.Steamworks.ISteamGameServerStats gameServerStats; + + internal bool InitClient() + { + var user = Valve.Interop.NativeEntrypoints.Extended.SteamAPI_GetHSteamUser(); + var pipe = Valve.Interop.NativeEntrypoints.Extended.SteamAPI_GetHSteamPipe(); + if ( pipe == 0 ) + return false; + + FillInterfaces( user, pipe ); + + return true; + } + + internal bool InitServer() + { + var user = Valve.Interop.NativeEntrypoints.Extended.SteamGameServer_GetHSteamUser(); + var pipe = Valve.Interop.NativeEntrypoints.Extended.SteamGameServer_GetHSteamPipe(); + if ( pipe == 0 ) + return false; + + FillInterfaces( pipe, user ); + + if ( gameServer.GetIntPtr() == IntPtr.Zero ) + { + gameServer = null; + throw new System.Exception( "Steam Server: Couldn't load SteamGameServer012" ); + } + + return true; + } + + public void FillInterfaces( int hpipe, int huser ) + { + var clientPtr = Valve.Interop.NativeEntrypoints.Extended.SteamInternal_CreateInterface( "SteamClient017" ); + if ( clientPtr == IntPtr.Zero ) + { + throw new System.Exception( "Steam Server: Couldn't load SteamClient017" ); + } + + client = new Valve.Steamworks.CSteamClient( clientPtr ); + + user = client.GetISteamUser( huser, hpipe, "SteamUser019" ); + utils = client.GetISteamUtils( hpipe, "SteamUtils008" ); + networking = client.GetISteamNetworking( huser, hpipe, "SteamNetworking005" ); + gameServerStats = client.GetISteamGameServerStats( huser, hpipe, "SteamGameServerStats001" ); + http = client.GetISteamHTTP( huser, hpipe, "STEAMHTTP_INTERFACE_VERSION002" ); + inventory = client.GetISteamInventory( huser, hpipe, "STEAMINVENTORY_INTERFACE_V001" ); + ugc = client.GetISteamUGC( huser, hpipe, "STEAMUGC_INTERFACE_VERSION008" ); + apps = client.GetISteamApps( huser, hpipe, "STEAMAPPS_INTERFACE_VERSION008" ); + gameServer = client.GetISteamGameServer( huser, hpipe, "SteamGameServer012" ); + friends = client.GetISteamFriends( huser, hpipe, "SteamFriends015" ); + servers = client.GetISteamMatchmakingServers( huser, hpipe, "SteamMatchMakingServers002" ); + userstats = client.GetISteamUserStats( huser, hpipe, "STEAMUSERSTATS_INTERFACE_VERSION011" ); + screenshots = client.GetISteamScreenshots( huser, hpipe, "STEAMSCREENSHOTS_INTERFACE_VERSION002" ); + } + + public void Dispose() + { + if ( client != null ) + { + client.BShutdownIfAllPipesClosed(); + client = null; + } + + Valve.Interop.NativeEntrypoints.Extended.SteamAPI_Shutdown(); + } + } +} diff --git a/Facepunch.Steamworks/Server.cs b/Facepunch.Steamworks/Server.cs index fa63085..726a30c 100644 --- a/Facepunch.Steamworks/Server.cs +++ b/Facepunch.Steamworks/Server.cs @@ -6,76 +6,8 @@ using System.Runtime.InteropServices; namespace Facepunch.Steamworks { - public partial class Server : IDisposable + public partial class Server : BaseSteamworks { - internal class Internal : IDisposable - { - internal Valve.Steamworks.ISteamClient client; - internal Valve.Steamworks.ISteamGameServer gameServer; - internal Valve.Steamworks.ISteamUtils utils; - internal Valve.Steamworks.ISteamNetworking networking; - internal Valve.Steamworks.ISteamGameServerStats stats; - internal Valve.Steamworks.ISteamHTTP http; - internal Valve.Steamworks.ISteamInventory inventory; - internal Valve.Steamworks.ISteamUGC ugc; - internal Valve.Steamworks.ISteamApps apps; - - internal bool Init() - { - var user = Valve.Interop.NativeEntrypoints.Extended.SteamGameServer_GetHSteamUser(); - var pipe = Valve.Interop.NativeEntrypoints.Extended.SteamGameServer_GetHSteamPipe(); - if ( pipe == 0 ) - return false; - - var clientPtr = Valve.Interop.NativeEntrypoints.Extended.SteamInternal_CreateInterface( "SteamClient017" ); - if ( clientPtr == IntPtr.Zero ) - { - throw new System.Exception( "Steam Server: Couldn't load SteamClient017" ); - } - - client = new Valve.Steamworks.CSteamClient( clientPtr ); - - - gameServer = client.GetISteamGameServer( user, pipe, "SteamGameServer012" ); - - if ( gameServer.GetIntPtr() == IntPtr.Zero ) - { - gameServer = null; - throw new System.Exception( "Steam Server: Couldn't load SteamGameServer012" ); - } - - utils = client.GetISteamUtils( pipe, "SteamUtils008" ); - networking = client.GetISteamNetworking( user, pipe, "SteamNetworking005" ); - stats = client.GetISteamGameServerStats( user, pipe, "SteamGameServerStats001" ); - http = client.GetISteamHTTP( user, pipe, "STEAMHTTP_INTERFACE_VERSION002" ); - inventory = client.GetISteamInventory( user, pipe, "STEAMINVENTORY_INTERFACE_V001" ); - ugc = client.GetISteamUGC( user, pipe, "STEAMUGC_INTERFACE_VERSION008" ); - apps = client.GetISteamApps( user, pipe, "STEAMAPPS_INTERFACE_VERSION008" ); - - if ( ugc.GetIntPtr() == IntPtr.Zero ) - throw new System.Exception( "Steam Server: Couldn't load STEAMUGC_INTERFACE_VERSION008" ); - - if ( apps.GetIntPtr() == IntPtr.Zero ) - throw new System.Exception( "Steam Server: Couldn't load STEAMAPPS_INTERFACE_VERSION008" ); - - if ( inventory.GetIntPtr() == IntPtr.Zero ) - throw new System.Exception( "Steam Server: Couldn't load STEAMINVENTORY_INTERFACE_V001" ); - - return true; - } - - public void Dispose() - { - if ( client != null ) - { - client.BShutdownIfAllPipesClosed(); - client = null; - } - } - } - - internal Internal native; - /// /// Current running program's AppId /// @@ -91,27 +23,18 @@ namespace Facepunch.Steamworks /// public ulong SteamId { get; private set; } - public enum MessageType : int - { - Message = 0, - Warning = 1 - } - - /// - /// Called with a message from Steam - /// - public Action OnMessage; + internal override bool IsGameServer { get { return true; } } public Server( uint appId, uint IpAddress, ushort GamePort, ushort QueryPort, bool Secure, string VersionString ) { Valve.Interop.NativeEntrypoints.Extended.SteamInternal_GameServer_Init( IpAddress, 0, GamePort, QueryPort, Secure ? 3 : 2, VersionString ); - native = new Internal(); + native = new Interop.NativeInterface(); // // Get other interfaces // - if ( !native.Init() ) + if ( !native.InitServer() ) { native.Dispose(); native = null; @@ -153,21 +76,6 @@ namespace Facepunch.Steamworks } - public void Dispose() - { - if ( native != null) - { - native.Dispose(); - native = null; - } - - foreach ( var d in Disposables ) - { - d.Dispose(); - } - Disposables.Clear(); - } - [UnmanagedFunctionPointer( CallingConvention.Cdecl )] public delegate void SteamAPIWarningMessageHook( int nSeverity, string pchDebugText ); @@ -206,28 +114,6 @@ namespace Facepunch.Steamworks get { return native != null; } } - internal Action InstallCallback( Action action ) - { - // var del = Marshal.GetFunctionPointerForDelegate( action ); - - // var ptr = Marshal.GetFunctionPointerForDelegate( action ); - // Valve.Steamworks.SteamAPI.RegisterCallback( del, type ); - - // Valve.Steamworks.SteamAPI.UnregisterCallback( del ); - - //return () => Valve.Steamworks.SteamAPI.UnregisterCallback( ptr ); - return null; - } - - List Disposables = new List(); - - internal void CallResult( Action Callback, int id ) - { - var callback = new Facepunch.Steamworks.Interop.Callback( true, id, Callback ); - Disposables.Add( callback ); - } - - /// /// Gets or sets the current MaxPlayers. /// This doesn't enforce any kind of limit, it just updates the master server. diff --git a/Facepunch.Steamworks/Server/Auth.cs b/Facepunch.Steamworks/Server/Auth.cs index e4af02b..96e64a5 100644 --- a/Facepunch.Steamworks/Server/Auth.cs +++ b/Facepunch.Steamworks/Server/Auth.cs @@ -55,7 +55,7 @@ namespace Facepunch.Steamworks { server = s; - server.CallResult( OnAuthTicketValidate, ValidateAuthTicketResponse.CallbackId ); + server.AddCallback( OnAuthTicketValidate, ValidateAuthTicketResponse.CallbackId ); } void OnAuthTicketValidate( ValidateAuthTicketResponse data ) diff --git a/Facepunch.Steamworks/Server/Stats.cs b/Facepunch.Steamworks/Server/Stats.cs index 36db54c..35a4234 100644 --- a/Facepunch.Steamworks/Server/Stats.cs +++ b/Facepunch.Steamworks/Server/Stats.cs @@ -43,12 +43,12 @@ namespace Facepunch.Steamworks /// public void Refresh( ulong steamid ) { - var handle = server.native.stats.RequestUserStats( steamid ); + var handle = server.native.gameServerStats.RequestUserStats( steamid ); } public void Commit( ulong steamid ) { - server.native.stats.StoreUserStats( steamid ); + server.native.gameServerStats.StoreUserStats( steamid ); } /// @@ -56,7 +56,7 @@ namespace Facepunch.Steamworks /// public bool Set( ulong steamid, string name, int stat ) { - return server.native.stats.SetUserStat( steamid, name, stat ); + return server.native.gameServerStats.SetUserStat( steamid, name, stat ); } /// @@ -64,7 +64,7 @@ namespace Facepunch.Steamworks /// public bool Set( ulong steamid, string name, float stat ) { - return server.native.stats.SetUserStat0( steamid, name, stat ); + return server.native.gameServerStats.SetUserStat0( steamid, name, stat ); } /// @@ -74,7 +74,7 @@ namespace Facepunch.Steamworks { int data = defaultValue; - if ( !server.native.stats.GetUserStat( steamid, name, ref data ) ) + if ( !server.native.gameServerStats.GetUserStat( steamid, name, ref data ) ) return defaultValue; return data; @@ -87,7 +87,7 @@ namespace Facepunch.Steamworks { float data = defaultValue; - if ( !server.native.stats.GetUserStat0( steamid, name, ref data ) ) + if ( !server.native.gameServerStats.GetUserStat0( steamid, name, ref data ) ) return defaultValue; return data;