diff --git a/Facepunch.Steamworks.Test/Client/Client.cs b/Facepunch.Steamworks.Test/Client/Client.cs index aaa2161..995ed21 100644 --- a/Facepunch.Steamworks.Test/Client/Client.cs +++ b/Facepunch.Steamworks.Test/Client/Client.cs @@ -14,7 +14,7 @@ namespace Facepunch.Steamworks.Test { using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) { - Assert.IsTrue( client.Valid ); + Assert.IsTrue( client.IsValid ); } } @@ -25,7 +25,7 @@ namespace Facepunch.Steamworks.Test { var username = client.Username; Console.WriteLine( username ); - Assert.IsTrue( client.Valid ); + Assert.IsTrue( client.IsValid ); Assert.IsNotNull( username ); } } @@ -37,7 +37,7 @@ namespace Facepunch.Steamworks.Test { var steamid = client.SteamId; Console.WriteLine( steamid ); - Assert.IsTrue( client.Valid ); + Assert.IsTrue( client.IsValid ); Assert.AreNotEqual( 0, steamid ); } } diff --git a/Facepunch.Steamworks.Test/Client/Friends.cs b/Facepunch.Steamworks.Test/Client/Friends.cs index fd16517..e46ffb8 100644 --- a/Facepunch.Steamworks.Test/Client/Friends.cs +++ b/Facepunch.Steamworks.Test/Client/Friends.cs @@ -14,7 +14,7 @@ namespace Facepunch.Steamworks.Test { using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) { - Assert.IsTrue( client.Valid ); + Assert.IsTrue( client.IsValid ); client.Friends.Refresh(); @@ -32,7 +32,7 @@ namespace Facepunch.Steamworks.Test { using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) { - Assert.IsTrue( client.Valid ); + Assert.IsTrue( client.IsValid ); foreach ( var friend in client.Friends.All ) { @@ -46,7 +46,7 @@ namespace Facepunch.Steamworks.Test { using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) { - Assert.IsTrue( client.Valid ); + Assert.IsTrue( client.IsValid ); var friend = client.Friends.All.First(); diff --git a/Facepunch.Steamworks.Test/Server/Inventory.cs b/Facepunch.Steamworks.Test/Server/Inventory.cs index fd71916..9d8445c 100644 --- a/Facepunch.Steamworks.Test/Server/Inventory.cs +++ b/Facepunch.Steamworks.Test/Server/Inventory.cs @@ -13,7 +13,7 @@ namespace Facepunch.Steamworks.Test { using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) { - Assert.IsTrue( client.Valid ); + Assert.IsTrue( client.IsValid ); Assert.IsNull( client.Inventory.SerializedItems ); @@ -33,7 +33,7 @@ namespace Facepunch.Steamworks.Test using ( var server = new Facepunch.Steamworks.Server( 252490, 0, 30002, true, "VersionString" ) ) { server.LogOnAnonymous(); - Assert.IsTrue( server.Valid ); + Assert.IsTrue( server.IsValid ); var result = server.Inventory.Deserialize( client.Inventory.SerializedItems ); diff --git a/Facepunch.Steamworks.Test/Server/Server.cs b/Facepunch.Steamworks.Test/Server/Server.cs index 05369f8..bc8b964 100644 --- a/Facepunch.Steamworks.Test/Server/Server.cs +++ b/Facepunch.Steamworks.Test/Server/Server.cs @@ -16,7 +16,7 @@ namespace Facepunch.Steamworks.Test { using ( var server = new Facepunch.Steamworks.Server( 252490, 30001, 30002, 30003, false, "VersionString" ) ) { - Assert.IsTrue( server.Valid ); + Assert.IsTrue( server.IsValid ); } } @@ -25,7 +25,7 @@ namespace Facepunch.Steamworks.Test { using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) { - Assert.IsTrue( client.Valid ); + Assert.IsTrue( client.IsValid ); var ticket = client.Auth.GetAuthSessionTicket(); var ticketBinary = ticket.Data; @@ -33,7 +33,7 @@ namespace Facepunch.Steamworks.Test { server.LogOnAnonymous(); - Assert.IsTrue( server.Valid ); + Assert.IsTrue( server.IsValid ); var auth = server.Auth; diff --git a/Facepunch.Steamworks.Test/Server/Stats.cs b/Facepunch.Steamworks.Test/Server/Stats.cs index 5bb69e1..441fad2 100644 --- a/Facepunch.Steamworks.Test/Server/Stats.cs +++ b/Facepunch.Steamworks.Test/Server/Stats.cs @@ -12,7 +12,7 @@ namespace Facepunch.Steamworks.Test { using ( var server = new Facepunch.Steamworks.Server( 252490, 0, 30002, true, "VersionString" ) ) { - Assert.IsTrue( server.Valid ); + Assert.IsTrue( server.IsValid ); server.LogOnAnonymous(); ulong MySteamId = 76561197960279927; diff --git a/Facepunch.Steamworks/BaseSteamworks.cs b/Facepunch.Steamworks/BaseSteamworks.cs index 1f39970..5940335 100644 --- a/Facepunch.Steamworks/BaseSteamworks.cs +++ b/Facepunch.Steamworks/BaseSteamworks.cs @@ -22,6 +22,20 @@ namespace Facepunch.Steamworks } } + public void SetupCommonInterfaces() + { + Networking = new Steamworks.Networking( this, native.networking ); + Inventory = new Steamworks.Inventory( native.inventory, IsGameServer ); + } + + public bool IsValid + { + get { return native != null; } + } + + public Networking Networking { get; internal set; } + public Inventory Inventory { get; internal set; } + internal Interop.NativeInterface native; internal virtual bool IsGameServer { get { return false; } } @@ -43,5 +57,17 @@ namespace Facepunch.Steamworks var callback = new Facepunch.Steamworks.Interop.Callback( IsGameServer, id, Callback ); Disposables.Add( callback ); } + + public Action OnUpdate; + + + public virtual void Update() + { + Inventory.Update(); + Networking.Update(); + + if ( OnUpdate != null ) + OnUpdate(); + } } } \ No newline at end of file diff --git a/Facepunch.Steamworks/Client.cs b/Facepunch.Steamworks/Client.cs index 145ba22..052940c 100644 --- a/Facepunch.Steamworks/Client.cs +++ b/Facepunch.Steamworks/Client.cs @@ -46,14 +46,17 @@ namespace Facepunch.Steamworks return; } - Networking = new Steamworks.Networking( this, native.networking ); - // // Set up warning hook callback // SteamAPIWarningMessageHook ptr = InternalOnWarning; native.client.SetWarningMessageHook( Marshal.GetFunctionPointerForDelegate( ptr ) ); + // + // Setup interfaces that client and server both have + // + SetupCommonInterfaces(); + // // Cache common, unchanging info // @@ -68,17 +71,6 @@ namespace Facepunch.Steamworks Update(); } - public override void Dispose() - { - if ( native != null) - { - native.Dispose(); - native = null; - } - - base.Dispose(); - } - [UnmanagedFunctionPointer( CallingConvention.Cdecl )] public delegate void SteamAPIWarningMessageHook( int nSeverity, System.Text.StringBuilder pchDebugText ); @@ -90,43 +82,20 @@ namespace Facepunch.Steamworks } } - internal event Action OnUpdate; - /// /// Should be called at least once every frame /// - public void Update() + public override void Update() { - if ( native == null ) + if ( !IsValid ) return; Valve.Steamworks.SteamAPI.RunCallbacks(); + Voice.Update(); - Inventory.Update(); - Networking.Update(); - if ( OnUpdate != null ) - OnUpdate(); + base.Update(); } - public bool Valid - { - get { return native != null; } - } - - internal Action InstallCallback( int type, Delegate 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; - } - - public Networking Networking { get; internal set; } } } diff --git a/Facepunch.Steamworks/Client/Auth.cs b/Facepunch.Steamworks/Client/Auth.cs index c1c3e98..b36c28e 100644 --- a/Facepunch.Steamworks/Client/Auth.cs +++ b/Facepunch.Steamworks/Client/Auth.cs @@ -38,7 +38,7 @@ namespace Facepunch.Steamworks /// public void Cancel() { - if ( client.Valid && Handle != 0 ) + if ( client.IsValid && Handle != 0 ) { client.native.user.CancelAuthTicket( Handle ); Handle = 0; diff --git a/Facepunch.Steamworks/Client/ServerList.Request.cs b/Facepunch.Steamworks/Client/ServerList.Request.cs index 47b6952..5f0463e 100644 --- a/Facepunch.Steamworks/Client/ServerList.Request.cs +++ b/Facepunch.Steamworks/Client/ServerList.Request.cs @@ -182,7 +182,7 @@ namespace Facepunch.Steamworks // if ( Id != IntPtr.Zero ) { - if ( client.Valid ) + if ( client.IsValid ) client.native.servers.CancelQuery( Id ); Id = IntPtr.Zero; diff --git a/Facepunch.Steamworks/Facepunch.Steamworks.csproj b/Facepunch.Steamworks/Facepunch.Steamworks.csproj index 3eebcb8..da4a3a7 100644 --- a/Facepunch.Steamworks/Facepunch.Steamworks.csproj +++ b/Facepunch.Steamworks/Facepunch.Steamworks.csproj @@ -116,8 +116,8 @@ - - + + @@ -128,10 +128,10 @@ - + - + @@ -142,7 +142,6 @@ - diff --git a/Facepunch.Steamworks/Client/Inventory.Definition.cs b/Facepunch.Steamworks/Interfaces/Inventory.Definition.cs similarity index 100% rename from Facepunch.Steamworks/Client/Inventory.Definition.cs rename to Facepunch.Steamworks/Interfaces/Inventory.Definition.cs diff --git a/Facepunch.Steamworks/Client/Inventory.Item.cs b/Facepunch.Steamworks/Interfaces/Inventory.Item.cs similarity index 100% rename from Facepunch.Steamworks/Client/Inventory.Item.cs rename to Facepunch.Steamworks/Interfaces/Inventory.Item.cs diff --git a/Facepunch.Steamworks/Client/Inventory.Result.cs b/Facepunch.Steamworks/Interfaces/Inventory.Result.cs similarity index 100% rename from Facepunch.Steamworks/Client/Inventory.Result.cs rename to Facepunch.Steamworks/Interfaces/Inventory.Result.cs diff --git a/Facepunch.Steamworks/Client/Inventory.cs b/Facepunch.Steamworks/Interfaces/Inventory.cs similarity index 94% rename from Facepunch.Steamworks/Client/Inventory.cs rename to Facepunch.Steamworks/Interfaces/Inventory.cs index 64d9c1c..cc9dbb1 100644 --- a/Facepunch.Steamworks/Client/Inventory.cs +++ b/Facepunch.Steamworks/Interfaces/Inventory.cs @@ -6,22 +6,6 @@ using System.Text; namespace Facepunch.Steamworks { - public partial class Client : IDisposable - { - Inventory _inv; - - public Inventory Inventory - { - get - { - if ( _inv == null ) - _inv = new Inventory( native.inventory, false ); - - return _inv; - } - } - } - public partial class Inventory { /// @@ -125,7 +109,7 @@ namespace Facepunch.Steamworks d.SetupCommonProperties(); return d; - } ).ToArray(); + } ).ToArray(); } /// @@ -133,7 +117,7 @@ namespace Facepunch.Steamworks /// internal void Update() { - if ( Definitions == null ) + if ( Definitions == null && !IsServer ) FetchItemDefinitions(); UpdateLocalRequest(); @@ -222,6 +206,5 @@ namespace Facepunch.Steamworks return new Result( this, resultHandle ); } } - } } diff --git a/Facepunch.Steamworks/Server.cs b/Facepunch.Steamworks/Server.cs index 726a30c..b641141 100644 --- a/Facepunch.Steamworks/Server.cs +++ b/Facepunch.Steamworks/Server.cs @@ -49,6 +49,11 @@ namespace Facepunch.Steamworks var rr = GCHandle.Alloc( d ); native.utils.SetWarningMessageHook( d ); + // + // Setup interfaces that client and server both have + // + SetupCommonInterfaces(); + // // Cache common, unchanging info // @@ -89,29 +94,17 @@ namespace Facepunch.Steamworks Console.WriteLine( "STEAM: {0}", text ); } - internal event Action OnUpdate; - /// /// Should be called at least once every frame /// - public void Update() + public override void Update() { - if ( native == null ) + if ( !IsValid ) return; Valve.Interop.NativeEntrypoints.Extended.SteamGameServer_RunCallbacks(); - Valve.Steamworks.SteamAPI.RunCallbacks(); - // Voice.Update(); - // Inventory.Update(); - // Networking.Update(); - if ( OnUpdate != null ) - OnUpdate(); - } - - public bool Valid - { - get { return native != null; } + base.Update(); } /// diff --git a/Facepunch.Steamworks/Server/Inventory.cs b/Facepunch.Steamworks/Server/Inventory.cs deleted file mode 100644 index cea256b..0000000 --- a/Facepunch.Steamworks/Server/Inventory.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; - -namespace Facepunch.Steamworks -{ - public partial class Server - { - Inventory _inv; - - public Inventory Inventory - { - get - { - if ( _inv == null ) - _inv = new Inventory( native.inventory, true ); - - return _inv; - } - } - } - -}