Test fixes

This commit is contained in:
Garry Newman 2019-04-15 21:18:03 +01:00
parent 3255135df1
commit c1d611dae7
20 changed files with 85 additions and 62 deletions

View File

@ -14,7 +14,25 @@ public class AppTest
[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()

View File

@ -88,25 +88,25 @@
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Client\AchievementsTest.cs" />
<Compile Include="Client\UserTest.cs" />
<Compile Include="Client\UtilsTest.cs" />
<Compile Include="Client\ClientTest.cs" />
<Compile Include="Client\LobbyTest.cs" />
<Compile Include="Client\LeaderboardTest.cs" />
<Compile Include="Client\AppTest.cs" />
<Compile Include="Client\RemoteStorageTest.cs" />
<Compile Include="Client\InventoryTest.cs" />
<Compile Include="Client\WorkshopTest.cs" />
<Compile Include="Client\NetworkingTest.cs" />
<Compile Include="AchievementsTest.cs" />
<Compile Include="UserTest.cs" />
<Compile Include="UtilsTest.cs" />
<Compile Include="ClientTest.cs" />
<Compile Include="LobbyTest.cs" />
<Compile Include="LeaderboardTest.cs" />
<Compile Include="AppTest.cs" />
<Compile Include="RemoteStorageTest.cs" />
<Compile Include="InventoryTest.cs" />
<Compile Include="WorkshopTest.cs" />
<Compile Include="NetworkingTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Client\FriendsTest.cs" />
<Compile Include="Client\Server\ServerTest.cs" />
<Compile Include="FriendsTest.cs" />
<Compile Include="GameServerTest.cs" />
<Compile Include="Client\Server\StatsTest.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="Client\ServerlistTest.cs" />
<Compile Include="Client\StatsTest.cs" />
<Compile Include="ServerlistTest.cs" />
<Compile Include="StatsTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

View File

@ -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 @@ public void AuthCallback()
Assert.IsTrue( !Authed );
}
}
}*/
}
}
}
*/

View File

@ -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 );

View File

@ -35,7 +35,7 @@ internal static void InstallEvents()
/// </summary>
public static event Action<CSteamID, CSteamID, AuthSessionResponse> 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 @@ public static bool Init( AppId appid, ServerInit init )
//
// 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 @@ public static bool Init( AppId appid, ServerInit init )
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
}
}
}
/// <summary>

View File

@ -20,7 +20,7 @@ public static void Init( uint appid )
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 @@ internal static async void RunCallbacks()
await Task.Delay( 16 );
try
{
SteamApi.RunCallbacks();
SteamApi.SteamAPI_RunCallbacks();
}
catch ( System.Exception )
{
@ -65,7 +65,7 @@ internal static void RegisterCallback( IntPtr intPtr, int callbackId )
public static void Update()
{
SteamApi.RunCallbacks();
SteamApi.SteamAPI_RunCallbacks();
}
internal static void UnregisterCallback( IntPtr intPtr )

View File

@ -25,7 +25,7 @@ public BaseSteamInterface( bool server = false )
if ( server )
{
Self = SteamInternal.FindOrCreateUserInterface( hUser, InterfaceName );
Self = SteamInternal.FindOrCreateGameServerInterface( hUser, InterfaceName );
}
else
{