(965c31410a) Unstable v0.10.4.0

This commit is contained in:
Juan Pablo Arce
2020-07-21 08:57:50 -03:00
parent 4f8bd39789
commit 33d3a41104
546 changed files with 45952 additions and 25762 deletions
+67 -77
View File
@@ -10,40 +10,25 @@ namespace Steamworks
/// <summary>
/// Provides the core of the Steam Game Servers API
/// </summary>
public static partial class SteamServer
public partial class SteamServer : SteamServerClass<SteamServer>
{
static bool initialized;
internal static ISteamGameServer Internal => Interface as ISteamGameServer;
static ISteamGameServer _internal;
internal static ISteamGameServer Internal
internal override void InitializeInterface( bool server )
{
get
{
if ( _internal == null )
{
_internal = new ISteamGameServer( );
_internal.InitServer();
}
return _internal;
}
SetInterface( server, new ISteamGameServer( server ) );
InstallEvents();
}
public static bool IsValid => initialized;
public static Action<Exception> OnCallbackException;
public static bool IsValid => Internal != null && Internal.IsValid;
internal static void InstallEvents()
{
SteamInventory.InstallEvents();
SteamNetworkingSockets.InstallEvents(true);
SteamUGC.InstallEvents(true);
ValidateAuthTicketResponse_t.Install( x => OnValidateAuthTicketResponse?.Invoke( x.SteamID, x.OwnerSteamID, x.AuthSessionResponse ), true );
SteamServersConnected_t.Install( x => OnSteamServersConnected?.Invoke(), true );
SteamServerConnectFailure_t.Install( x => OnSteamServerConnectFailure?.Invoke( x.Result, x.StillRetrying ), true );
SteamServersDisconnected_t.Install( x => OnSteamServersDisconnected?.Invoke( x.Result ), true );
Dispatch.Install<ValidateAuthTicketResponse_t>( x => OnValidateAuthTicketResponse?.Invoke( x.SteamID, x.OwnerSteamID, x.AuthSessionResponse ), true );
Dispatch.Install<SteamServersConnected_t>( x => OnSteamServersConnected?.Invoke(), true );
Dispatch.Install<SteamServerConnectFailure_t>( x => OnSteamServerConnectFailure?.Invoke( x.Result, x.StillRetrying ), true );
Dispatch.Install<SteamServersDisconnected_t>( x => OnSteamServersDisconnected?.Invoke( x.Result ), true );
Dispatch.Install<SteamNetAuthenticationStatus_t>(x => OnSteamNetAuthenticationStatus?.Invoke(x.Avail), true);
}
/// <summary>
@@ -67,6 +52,11 @@ namespace Steamworks
/// </summary>
public static event Action<Result> OnSteamServersDisconnected;
/// <summary>
/// Called when authentication status changes, useful for grabbing SteamId once aavailability is current
/// </summary>
public static event Action<SteamNetworkingAvailability> OnSteamNetAuthenticationStatus;
/// <summary>
/// Initialize the steam server.
@@ -74,6 +64,9 @@ namespace Steamworks
/// </summary>
public static void Init( AppId appid, SteamServerInit init, bool asyncCallbacks = true )
{
if ( IsValid )
throw new System.Exception( "Calling SteamServer.Init but is already initialized" );
uint ipaddress = 0; // Any Port
if ( init.SteamPort == 0 )
@@ -94,7 +87,24 @@ namespace Steamworks
throw new System.Exception( $"InitGameServer returned false ({ipaddress},{init.SteamPort},{init.GamePort},{init.QueryPort},{secure},\"{init.VersionString}\")" );
}
initialized = true;
//
// Dispatch is responsible for pumping the
// event loop.
//
Dispatch.Init();
Dispatch.ServerPipe = SteamGameServer.GetHSteamPipe();
AddInterface<SteamServer>();
AddInterface<SteamUtils>();
AddInterface<SteamNetworking>();
AddInterface<SteamServerStats>();
//AddInterface<ISteamHTTP>();
AddInterface<SteamInventory>();
AddInterface<SteamUGC>();
AddInterface<SteamApps>();
AddInterface<SteamNetworkingUtils>();
AddInterface<SteamNetworkingSockets>();
//
// Initial settings
@@ -108,73 +118,52 @@ namespace Steamworks
Passworded = false;
DedicatedServer = init.DedicatedServer;
InstallEvents();
if ( asyncCallbacks )
{
RunCallbacksAsync();
//
// This will keep looping in the background every 16 ms
// until we shut down.
//
Dispatch.LoopServerAsync();
}
}
static List<SteamInterface> openIterfaces = new List<SteamInterface>();
internal static void WatchInterface( SteamInterface steamInterface )
internal static void AddInterface<T>() where T : SteamClass, new()
{
if ( openIterfaces.Contains( steamInterface ) )
throw new System.Exception( "openIterfaces already contains interface!" );
openIterfaces.Add( steamInterface );
var t = new T();
t.InitializeInterface( true );
openInterfaces.Add( t );
}
static readonly List<SteamClass> openInterfaces = new List<SteamClass>();
internal static void ShutdownInterfaces()
{
foreach ( var e in openIterfaces )
foreach ( var e in openInterfaces )
{
e.Shutdown();
e.DestroyInterface( true );
}
openIterfaces.Clear();
openInterfaces.Clear();
}
public static void Shutdown()
{
Event.DisposeAllServer();
initialized = false;
_internal = null;
Dispatch.ShutdownServer();
ShutdownInterfaces();
SteamNetworkingUtils.Shutdown();
SteamNetworkingSockets.Shutdown();
SteamInventory.Shutdown();
SteamGameServer.Shutdown();
}
internal static async void RunCallbacksAsync()
{
while ( IsValid )
{
try
{
RunCallbacks();
}
catch ( System.Exception e )
{
OnCallbackException?.Invoke( e );
}
await Task.Delay( 16 );
}
}
/// <summary>
/// Run the callbacks. This is also called in Async callbacks.
/// </summary>
public static void RunCallbacks()
{
SteamGameServer.RunCallbacks();
if ( Dispatch.ServerPipe != 0 )
{
Dispatch.Frame( Dispatch.ServerPipe );
}
}
/// <summary>
@@ -286,6 +275,8 @@ namespace Steamworks
}
private static string _gametags = "";
public static SteamId SteamId => Internal.GetSteamID();
/// <summary>
/// Log onto Steam anonymously.
/// </summary>
@@ -314,16 +305,7 @@ namespace Steamworks
/// current public ip address. Be aware that this is likely to return
/// null for the first few seconds after initialization.
/// </summary>
public static System.Net.IPAddress PublicIp
{
get
{
var ip = Internal.GetPublicIP();
if ( ip == 0 ) return null;
return Utility.Int32ToIp( ip );
}
}
public static System.Net.IPAddress PublicIp => Internal.GetPublicIP();
/// <summary>
/// Enable or disable heartbeats, which are sent regularly to the master server.
@@ -462,6 +444,14 @@ namespace Steamworks
public static unsafe void HandleIncomingPacket( IntPtr ptr, int size, uint address, ushort port )
{
Internal.HandleIncomingPacket( ptr, size, address, port );
}
/// <summary>
/// Does the user own this app (which could be DLC)
/// </summary>
public static UserHasLicenseForAppResult UserHasLicenseForApp( SteamId steamid, AppId appid )
{
return Internal.UserHasLicenseForApp( steamid, appid );
}
}
}