diff --git a/Facepunch.Steamworks.Test/Client/AchievementsTest.cs b/Facepunch.Steamworks.Test/AchievementsTest.cs similarity index 100% rename from Facepunch.Steamworks.Test/Client/AchievementsTest.cs rename to Facepunch.Steamworks.Test/AchievementsTest.cs diff --git a/Facepunch.Steamworks.Test/Client/AppTest.cs b/Facepunch.Steamworks.Test/AppTest.cs similarity index 86% rename from Facepunch.Steamworks.Test/Client/AppTest.cs rename to Facepunch.Steamworks.Test/AppTest.cs index f9bc8ce..b85c669 100644 --- a/Facepunch.Steamworks.Test/Client/AppTest.cs +++ b/Facepunch.Steamworks.Test/AppTest.cs @@ -14,7 +14,25 @@ namespace Steamworks [AssemblyInitialize] public static void AssemblyInit( TestContext context ) { + // + // Init Client + // Steamworks.Steam.Init( 4000 ); + + // + // Init Server + // + var serverInit = new ServerInit( "gmod", "Garry Mode" ) + { + GamePort = 28015, + Secure = true, + QueryPort = 28016 + }; + + Steamworks.GameServer.Init( 4000, serverInit ); + + GameServer.LogOnAnonymous(); + } static void OnNewUrlLaunchParameters() diff --git a/Facepunch.Steamworks.Test/Client/ClientTest.cs b/Facepunch.Steamworks.Test/ClientTest.cs similarity index 100% rename from Facepunch.Steamworks.Test/Client/ClientTest.cs rename to Facepunch.Steamworks.Test/ClientTest.cs diff --git a/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj b/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj index 87aceb5..b02e7d7 100644 --- a/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj +++ b/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj @@ -88,25 +88,25 @@ - - - - - - - - - - - + + + + + + + + + + + - - + + - - + + diff --git a/Facepunch.Steamworks.Test/Client/FriendsTest.cs b/Facepunch.Steamworks.Test/FriendsTest.cs similarity index 100% rename from Facepunch.Steamworks.Test/Client/FriendsTest.cs rename to Facepunch.Steamworks.Test/FriendsTest.cs diff --git a/Facepunch.Steamworks.Test/Client/Server/ServerTest.cs b/Facepunch.Steamworks.Test/GameServerTest.cs similarity index 74% rename from Facepunch.Steamworks.Test/Client/Server/ServerTest.cs rename to Facepunch.Steamworks.Test/GameServerTest.cs index 2bddda0..54ff909 100644 --- a/Facepunch.Steamworks.Test/Client/Server/ServerTest.cs +++ b/Facepunch.Steamworks.Test/GameServerTest.cs @@ -1,63 +1,46 @@ using System; +using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; -/* -namespace Facepunch.Steamworks.Test + +namespace Steamworks { [DeploymentItem( "steam_api64.dll" )] [DeploymentItem( "tier0_s64.dll" )] [DeploymentItem( "vstdlib_s64.dll" )] [DeploymentItem( "steamclient64.dll" )] [TestClass] - public partial class Server + public partial class GameServerTest { [TestMethod] public void Init() { - var serverInit = new ServerInit( "rust", "Rust" ); - serverInit.GamePort = 28015; - serverInit.Secure = true; - serverInit.QueryPort = 28016; - - using ( var server = new Facepunch.Steamworks.Server( 252490, serverInit ) ) - { - server.ServerName = "My Test Server"; - server.LogOnAnonymous(); - - Assert.IsTrue( server.IsValid ); - } - } + GameServer.DedicatedServer = true; + GameServer.DedicatedServer = false; + } [TestMethod] - public void PublicIp() + public async Task PublicIp() { - using ( var server = new Facepunch.Steamworks.Server( 252490, new ServerInit( "rust", "Rust" ) ) ) + while ( true ) { - server.LogOnAnonymous(); + var ip = GameServer.PublicIp; - Assert.IsTrue( server.IsValid ); - - while ( true ) + if ( ip == null ) { - var ip = server.PublicIp; - - if ( ip == null ) - { - System.Threading.Thread.Sleep( 100 ); - server.Update(); - continue; - } - - Assert.IsNotNull( ip ); - Console.WriteLine( ip.ToString() ); - break; + await Task.Delay( 10 ); + continue; } + Assert.IsNotNull( ip ); + Console.WriteLine( ip.ToString() ); + break; } } [TestMethod] public void AuthCallback() { + /* using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) { Assert.IsTrue( client.IsValid ); @@ -144,8 +127,7 @@ namespace Facepunch.Steamworks.Test Assert.IsTrue( !Authed ); } - } + }*/ } } } -*/ \ No newline at end of file diff --git a/Facepunch.Steamworks.Test/Client/InventoryTest.cs b/Facepunch.Steamworks.Test/InventoryTest.cs similarity index 100% rename from Facepunch.Steamworks.Test/Client/InventoryTest.cs rename to Facepunch.Steamworks.Test/InventoryTest.cs diff --git a/Facepunch.Steamworks.Test/Client/LeaderboardTest.cs b/Facepunch.Steamworks.Test/LeaderboardTest.cs similarity index 100% rename from Facepunch.Steamworks.Test/Client/LeaderboardTest.cs rename to Facepunch.Steamworks.Test/LeaderboardTest.cs diff --git a/Facepunch.Steamworks.Test/Client/LobbyTest.cs b/Facepunch.Steamworks.Test/LobbyTest.cs similarity index 100% rename from Facepunch.Steamworks.Test/Client/LobbyTest.cs rename to Facepunch.Steamworks.Test/LobbyTest.cs diff --git a/Facepunch.Steamworks.Test/Client/NetworkingTest.cs b/Facepunch.Steamworks.Test/NetworkingTest.cs similarity index 100% rename from Facepunch.Steamworks.Test/Client/NetworkingTest.cs rename to Facepunch.Steamworks.Test/NetworkingTest.cs diff --git a/Facepunch.Steamworks.Test/Client/RemoteStorageTest.cs b/Facepunch.Steamworks.Test/RemoteStorageTest.cs similarity index 100% rename from Facepunch.Steamworks.Test/Client/RemoteStorageTest.cs rename to Facepunch.Steamworks.Test/RemoteStorageTest.cs diff --git a/Facepunch.Steamworks.Test/Client/ServerlistTest.cs b/Facepunch.Steamworks.Test/ServerlistTest.cs similarity index 100% rename from Facepunch.Steamworks.Test/Client/ServerlistTest.cs rename to Facepunch.Steamworks.Test/ServerlistTest.cs diff --git a/Facepunch.Steamworks.Test/Client/StatsTest.cs b/Facepunch.Steamworks.Test/StatsTest.cs similarity index 100% rename from Facepunch.Steamworks.Test/Client/StatsTest.cs rename to Facepunch.Steamworks.Test/StatsTest.cs diff --git a/Facepunch.Steamworks.Test/Client/UserTest.cs b/Facepunch.Steamworks.Test/UserTest.cs similarity index 100% rename from Facepunch.Steamworks.Test/Client/UserTest.cs rename to Facepunch.Steamworks.Test/UserTest.cs diff --git a/Facepunch.Steamworks.Test/Client/UtilsTest.cs b/Facepunch.Steamworks.Test/UtilsTest.cs similarity index 100% rename from Facepunch.Steamworks.Test/Client/UtilsTest.cs rename to Facepunch.Steamworks.Test/UtilsTest.cs diff --git a/Facepunch.Steamworks.Test/Client/WorkshopTest.cs b/Facepunch.Steamworks.Test/WorkshopTest.cs similarity index 100% rename from Facepunch.Steamworks.Test/Client/WorkshopTest.cs rename to Facepunch.Steamworks.Test/WorkshopTest.cs diff --git a/Facepunch.Steamworks/Generated/SteamApi.cs b/Facepunch.Steamworks/Generated/SteamApi.cs index c544a2f..669709c 100644 --- a/Facepunch.Steamworks/Generated/SteamApi.cs +++ b/Facepunch.Steamworks/Generated/SteamApi.cs @@ -8,7 +8,15 @@ public static class SteamApi { [DllImport( "Steam_api64", EntryPoint = "SteamAPI_Init", CallingConvention = CallingConvention.Cdecl )] [return: MarshalAs( UnmanagedType.U1 )] - public static extern bool Init(); + public static extern bool SteamAPI_Init(); + + [DllImport( "Steam_api64", EntryPoint = "SteamAPI_Shutdown", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.U1 )] + public static extern bool SteamAPI_Shutdown(); + + [DllImport( "Steam_api64", EntryPoint = "SteamInternal_GameServer_Init", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.U1 )] + public static extern bool SteamInternal_GameServer_Init( uint unIP, ushort usSteamPort, ushort usGamePort, ushort usQueryPort, int eServerMode, string pchVersionString); [DllImport( "Steam_api64", EntryPoint = "SteamAPI_GetHSteamUser", CallingConvention = CallingConvention.Cdecl )] public static extern int GetHSteamUser(); @@ -17,7 +25,7 @@ public static class SteamApi public static extern int SteamGameServer_GetHSteamUser(); [DllImport( "Steam_api64", EntryPoint = "SteamAPI_RunCallbacks", CallingConvention = CallingConvention.Cdecl )] - public static extern int RunCallbacks(); + public static extern int SteamAPI_RunCallbacks(); [DllImport( "Steam_api64", EntryPoint = "SteamAPI_RegisterCallback", CallingConvention = CallingConvention.Cdecl )] public static extern int RegisterCallback( IntPtr pCallback, int callback ); diff --git a/Facepunch.Steamworks/Redux/GameServer.cs b/Facepunch.Steamworks/Redux/GameServer.cs index e6b4070..a871f6f 100644 --- a/Facepunch.Steamworks/Redux/GameServer.cs +++ b/Facepunch.Steamworks/Redux/GameServer.cs @@ -35,7 +35,7 @@ namespace Steamworks /// public static event Action OnValidateAuthTicketResponse; - public static bool Init( AppId appid, ServerInit init ) + public static void Init( AppId appid, ServerInit init ) { uint ipaddress = 0; // Any Port @@ -48,9 +48,9 @@ namespace Steamworks // // Get other interfaces // - if ( !Internal.InitGameServer( ipaddress, init.GamePort, init.QueryPort, (uint)( init.Secure ? 3 : 2 ), appid.Value, init.VersionString ) ) + if ( !global::SteamApi.SteamInternal_GameServer_Init( ipaddress, init.SteamPort, init.GamePort, init.QueryPort, (int)( init.Secure ? 3 : 2 ), init.VersionString ) ) { - return false; + throw new System.Exception( "InitGameServer returned false" ); } // @@ -65,10 +65,25 @@ namespace Steamworks Passworded = false; DedicatedServer = true; - InstallEvents(); + RunCallbacks(); + } - return true; + + internal static async void RunCallbacks() + { + while ( true ) + { + await Task.Delay( 16 ); + try + { + SteamApi.SteamAPI_RunCallbacks(); + } + catch ( System.Exception ) + { + // TODO - error outputs + } + } } /// diff --git a/Facepunch.Steamworks/Redux/Steam.cs b/Facepunch.Steamworks/Redux/Steam.cs index 89fbec9..4431322 100644 --- a/Facepunch.Steamworks/Redux/Steam.cs +++ b/Facepunch.Steamworks/Redux/Steam.cs @@ -20,7 +20,7 @@ namespace Steamworks System.Environment.SetEnvironmentVariable( "SteamAppId", appid.ToString() ); System.Environment.SetEnvironmentVariable( "SteamGameId", appid.ToString() ); - if ( !SteamApi.Init() ) + if ( !SteamApi.SteamAPI_Init() ) { throw new System.Exception( "SteamApi_Init returned false. Steam isn't running, couldn't find Steam, AppId is ureleased, Don't own AppId." ); } @@ -49,7 +49,7 @@ namespace Steamworks await Task.Delay( 16 ); try { - SteamApi.RunCallbacks(); + SteamApi.SteamAPI_RunCallbacks(); } catch ( System.Exception ) { @@ -65,7 +65,7 @@ namespace Steamworks public static void Update() { - SteamApi.RunCallbacks(); + SteamApi.SteamAPI_RunCallbacks(); } internal static void UnregisterCallback( IntPtr intPtr ) diff --git a/Facepunch.Steamworks/Utility/BaseSteamInterface.cs b/Facepunch.Steamworks/Utility/BaseSteamInterface.cs index 970148d..752ee24 100644 --- a/Facepunch.Steamworks/Utility/BaseSteamInterface.cs +++ b/Facepunch.Steamworks/Utility/BaseSteamInterface.cs @@ -25,7 +25,7 @@ namespace Steamworks.Internal if ( server ) { - Self = SteamInternal.FindOrCreateUserInterface( hUser, InterfaceName ); + Self = SteamInternal.FindOrCreateGameServerInterface( hUser, InterfaceName ); } else {