Shutdown server properly

This commit is contained in:
Garry Newman 2016-10-28 11:02:48 +01:00
parent 1b4f5b91aa
commit f048730edd
12 changed files with 66 additions and 7 deletions

View File

@ -18,7 +18,7 @@ public partial class Server
[TestMethod]
public void Init()
{
using ( var server = new Facepunch.Steamworks.Server( 252490, 30001, 30002, 30003, false, "VersionString" ) )
using ( var server = new Facepunch.Steamworks.Server( 252490, 30002, 30003, false, "VersionString" ) )
{
Assert.IsTrue( server.IsValid );
}
@ -33,7 +33,7 @@ public void AuthCallback()
var ticket = client.Auth.GetAuthSessionTicket();
var ticketBinary = ticket.Data;
using ( var server = new Facepunch.Steamworks.Server( 252490, 30001, 30002, 30003, true, "VersionString" ) )
using ( var server = new Facepunch.Steamworks.Server( 252490, 30002, 30003, true, "VersionString" ) )
{
server.LogOnAnonymous();

View File

@ -91,8 +91,9 @@ public override void Update()
native.api.SteamAPI_RunCallbacks();
Voice.Update();
base.Update();
native.api.SteamAPI_RunCallbacks();
}
public override void Dispose()
@ -105,6 +106,5 @@ public override void Dispose()
base.Dispose();
}
}
}

View File

@ -24,8 +24,12 @@ internal class NativeInterface : IDisposable
internal SteamNative.SteamGameServerStats gameServerStats;
internal SteamNative.SteamRemoteStorage remoteStorage;
private bool isServer;
internal bool InitClient()
{
isServer = false;
api = new SteamNative.SteamApi( (IntPtr) 1 );
if ( !api.SteamAPI_Init() )
@ -48,6 +52,8 @@ internal bool InitClient()
internal bool InitServer( uint IpAddress /*uint32*/, ushort usPort /*uint16*/, ushort GamePort /*uint16*/, ushort QueryPort /*uint16*/, int eServerMode /*int*/, string pchVersionString /*const char **/)
{
isServer = true;
api = new SteamNative.SteamApi( (IntPtr)1 );
if ( !api.SteamInternal_GameServer_Init( IpAddress, usPort, GamePort, QueryPort, eServerMode, pchVersionString ) )
@ -155,6 +161,11 @@ public void Dispose()
if ( gameServer != null )
{
//
// Calling this can cause the process to hang
//
//gameServer.LogOff();
gameServer.Dispose();
gameServer = null;
}
@ -191,7 +202,11 @@ public void Dispose()
if ( api != null )
{
api.SteamAPI_Shutdown();
if ( isServer )
api.SteamGameServer_Shutdown();
else
api.SteamAPI_Shutdown();
api.Dispose();
api = null;
}

View File

@ -98,6 +98,8 @@ public override void Update()
native.api.SteamGameServer_RunCallbacks();
base.Update();
native.api.SteamGameServer_RunCallbacks();
}
/// <summary>

View File

@ -663,6 +663,7 @@ public interface Interface : IDisposable
void /*void*/ SteamApi_SteamAPI_UnregisterCallback( IntPtr /*void **/ pCallback );
bool /*bool*/ SteamApi_SteamInternal_GameServer_Init( uint /*uint32*/ unIP, ushort /*uint16*/ usPort, ushort /*uint16*/ usGamePort, ushort /*uint16*/ usQueryPort, int /*int*/ eServerMode, string /*const char **/ pchVersionString );
void /*void*/ SteamApi_SteamAPI_Shutdown();
void /*void*/ SteamApi_SteamGameServer_Shutdown();
HSteamUser /*(HSteamUser)*/ SteamApi_SteamAPI_GetHSteamUser();
HSteamPipe /*(HSteamPipe)*/ SteamApi_SteamAPI_GetHSteamPipe();
HSteamUser /*(HSteamUser)*/ SteamApi_SteamGameServer_GetHSteamUser();

View File

@ -3986,6 +3986,10 @@ public virtual IntPtr ISteamApps_GetLaunchQueryParam( string /*const char **/ pc
{
Native.SteamApi.SteamAPI_Shutdown();
}
public virtual void /*void*/ SteamApi_SteamGameServer_Shutdown()
{
Native.SteamApi.SteamGameServer_Shutdown();
}
public virtual HSteamUser /*(HSteamUser)*/ SteamApi_SteamAPI_GetHSteamUser()
{
return Native.SteamApi.SteamAPI_GetHSteamUser();
@ -5409,6 +5413,8 @@ internal static unsafe class SteamApi
internal static extern bool /*bool*/ SteamInternal_GameServer_Init( uint /*uint32*/ unIP, ushort /*uint16*/ usPort, ushort /*uint16*/ usGamePort, ushort /*uint16*/ usQueryPort, int /*int*/ eServerMode, string /*const char **/ pchVersionString );
[DllImportAttribute( "libsteam_api.so", EntryPoint = "SteamAPI_Shutdown" )]
internal static extern void /*void*/ SteamAPI_Shutdown();
[DllImportAttribute( "libsteam_api.so", EntryPoint = "SteamGameServer_Shutdown" )]
internal static extern void /*void*/ SteamGameServer_Shutdown();
[DllImportAttribute( "libsteam_api.so", EntryPoint = "SteamAPI_GetHSteamUser" )]
internal static extern HSteamUser /*(HSteamUser)*/ SteamAPI_GetHSteamUser();
[DllImportAttribute( "libsteam_api.so", EntryPoint = "SteamAPI_GetHSteamPipe" )]

View File

@ -3986,6 +3986,10 @@ public virtual IntPtr ISteamApps_GetLaunchQueryParam( string /*const char **/ pc
{
Native.SteamApi.SteamAPI_Shutdown();
}
public virtual void /*void*/ SteamApi_SteamGameServer_Shutdown()
{
Native.SteamApi.SteamGameServer_Shutdown();
}
public virtual HSteamUser /*(HSteamUser)*/ SteamApi_SteamAPI_GetHSteamUser()
{
return Native.SteamApi.SteamAPI_GetHSteamUser();
@ -5409,6 +5413,8 @@ internal static unsafe class SteamApi
internal static extern bool /*bool*/ SteamInternal_GameServer_Init( uint /*uint32*/ unIP, ushort /*uint16*/ usPort, ushort /*uint16*/ usGamePort, ushort /*uint16*/ usQueryPort, int /*int*/ eServerMode, string /*const char **/ pchVersionString );
[DllImportAttribute( "libsteam_api64.so", EntryPoint = "SteamAPI_Shutdown" )]
internal static extern void /*void*/ SteamAPI_Shutdown();
[DllImportAttribute( "libsteam_api64.so", EntryPoint = "SteamGameServer_Shutdown" )]
internal static extern void /*void*/ SteamGameServer_Shutdown();
[DllImportAttribute( "libsteam_api64.so", EntryPoint = "SteamAPI_GetHSteamUser" )]
internal static extern HSteamUser /*(HSteamUser)*/ SteamAPI_GetHSteamUser();
[DllImportAttribute( "libsteam_api64.so", EntryPoint = "SteamAPI_GetHSteamPipe" )]

View File

@ -3986,6 +3986,10 @@ public virtual IntPtr ISteamApps_GetLaunchQueryParam( string /*const char **/ pc
{
Native.SteamApi.SteamAPI_Shutdown();
}
public virtual void /*void*/ SteamApi_SteamGameServer_Shutdown()
{
Native.SteamApi.SteamGameServer_Shutdown();
}
public virtual HSteamUser /*(HSteamUser)*/ SteamApi_SteamAPI_GetHSteamUser()
{
return Native.SteamApi.SteamAPI_GetHSteamUser();
@ -5409,6 +5413,8 @@ internal static unsafe class SteamApi
internal static extern bool /*bool*/ SteamInternal_GameServer_Init( uint /*uint32*/ unIP, ushort /*uint16*/ usPort, ushort /*uint16*/ usGamePort, ushort /*uint16*/ usQueryPort, int /*int*/ eServerMode, string /*const char **/ pchVersionString );
[DllImportAttribute( "libsteam_api.dylib", EntryPoint = "SteamAPI_Shutdown" )]
internal static extern void /*void*/ SteamAPI_Shutdown();
[DllImportAttribute( "libsteam_api.dylib", EntryPoint = "SteamGameServer_Shutdown" )]
internal static extern void /*void*/ SteamGameServer_Shutdown();
[DllImportAttribute( "libsteam_api.dylib", EntryPoint = "SteamAPI_GetHSteamUser" )]
internal static extern HSteamUser /*(HSteamUser)*/ SteamAPI_GetHSteamUser();
[DllImportAttribute( "libsteam_api.dylib", EntryPoint = "SteamAPI_GetHSteamPipe" )]

View File

@ -3952,6 +3952,10 @@ public virtual IntPtr ISteamApps_GetLaunchQueryParam( string /*const char **/ pc
{
Native.SteamApi.SteamAPI_Shutdown();
}
public virtual void /*void*/ SteamApi_SteamGameServer_Shutdown()
{
Native.SteamApi.SteamGameServer_Shutdown();
}
public virtual HSteamUser /*(HSteamUser)*/ SteamApi_SteamAPI_GetHSteamUser()
{
return Native.SteamApi.SteamAPI_GetHSteamUser();
@ -5375,6 +5379,8 @@ internal static unsafe class SteamApi
internal static extern bool /*bool*/ SteamInternal_GameServer_Init( uint /*uint32*/ unIP, ushort /*uint16*/ usPort, ushort /*uint16*/ usGamePort, ushort /*uint16*/ usQueryPort, int /*int*/ eServerMode, string /*const char **/ pchVersionString );
[DllImportAttribute( "steam_api.dll", EntryPoint = "SteamAPI_Shutdown" )]
internal static extern void /*void*/ SteamAPI_Shutdown();
[DllImportAttribute( "steam_api.dll", EntryPoint = "SteamGameServer_Shutdown" )]
internal static extern void /*void*/ SteamGameServer_Shutdown();
[DllImportAttribute( "steam_api.dll", EntryPoint = "SteamAPI_GetHSteamUser" )]
internal static extern HSteamUser /*(HSteamUser)*/ SteamAPI_GetHSteamUser();
[DllImportAttribute( "steam_api.dll", EntryPoint = "SteamAPI_GetHSteamPipe" )]

View File

@ -3952,6 +3952,10 @@ public virtual IntPtr ISteamApps_GetLaunchQueryParam( string /*const char **/ pc
{
Native.SteamApi.SteamAPI_Shutdown();
}
public virtual void /*void*/ SteamApi_SteamGameServer_Shutdown()
{
Native.SteamApi.SteamGameServer_Shutdown();
}
public virtual HSteamUser /*(HSteamUser)*/ SteamApi_SteamAPI_GetHSteamUser()
{
return Native.SteamApi.SteamAPI_GetHSteamUser();
@ -5375,6 +5379,8 @@ internal static unsafe class SteamApi
internal static extern bool /*bool*/ SteamInternal_GameServer_Init( uint /*uint32*/ unIP, ushort /*uint16*/ usPort, ushort /*uint16*/ usGamePort, ushort /*uint16*/ usQueryPort, int /*int*/ eServerMode, string /*const char **/ pchVersionString );
[DllImportAttribute( "steam_api64.dll", EntryPoint = "SteamAPI_Shutdown" )]
internal static extern void /*void*/ SteamAPI_Shutdown();
[DllImportAttribute( "steam_api64.dll", EntryPoint = "SteamGameServer_Shutdown" )]
internal static extern void /*void*/ SteamGameServer_Shutdown();
[DllImportAttribute( "steam_api64.dll", EntryPoint = "SteamAPI_GetHSteamUser" )]
internal static extern HSteamUser /*(HSteamUser)*/ SteamAPI_GetHSteamUser();
[DllImportAttribute( "steam_api64.dll", EntryPoint = "SteamAPI_GetHSteamPipe" )]

View File

@ -99,6 +99,12 @@ public void SteamGameServer_RunCallbacks()
_pi.SteamApi_SteamGameServer_RunCallbacks();
}
// void
public void SteamGameServer_Shutdown()
{
_pi.SteamApi_SteamGameServer_Shutdown();
}
// IntPtr
public IntPtr SteamInternal_CreateInterface( string version /*const char **/ )
{

View File

@ -129,8 +129,13 @@ public CodeWriter( SteamApiDefinition def )
NeedsSelfPointer = false
} );
def.methods.Add( new SteamApiDefinition.MethodDef()
{
ClassName = "SteamApi",
Name = "SteamGameServer_Shutdown",
ReturnType = "void",
NeedsSelfPointer = false
} );
def.methods.Add( new SteamApiDefinition.MethodDef()
{