BaseSteamInterface open interfaces as server if no client

This commit is contained in:
Garry Newman 2019-04-16 14:52:19 +01:00
parent a4f446d009
commit 28e8f261e2

View File

@ -18,19 +18,22 @@ internal abstract class BaseSteamInterface
public BaseSteamInterface( bool server = false )
{
var hUser = server ? SteamApi.SteamGameServer_GetHSteamUser() : SteamApi.GetHSteamUser();
//
// If teh client isn't initialized but the server is,
// try to open this interface in server mode
//
if ( !SteamClient.IsValid && SteamServer.IsValid ) server = true;
var hUser = server ?
SteamApi.SteamGameServer_GetHSteamUser() :
SteamApi.GetHSteamUser();
if ( hUser == 0 )
throw new System.Exception( "Steamworks is uninitialized" );
if ( server )
{
Self = SteamInternal.FindOrCreateGameServerInterface( hUser, InterfaceName );
}
else
{
Self = SteamInternal.FindOrCreateUserInterface( hUser, InterfaceName );
}
Self = server ?
SteamInternal.FindOrCreateGameServerInterface( hUser, InterfaceName ) :
SteamInternal.FindOrCreateUserInterface( hUser, InterfaceName );
if ( Self == IntPtr.Zero )
throw new System.Exception( $"Couldn't find interface {InterfaceName} (server:{server})" );
@ -45,6 +48,10 @@ public BaseSteamInterface( bool server = false )
public abstract void InitInternals();
//
// Dedicated string conversion buffer
//
static byte[] stringbuffer = new byte[1024 * 128];
internal string GetString( IntPtr p )