mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-27 15:15:51 +03:00
Cleaning up
This commit is contained in:
parent
ea97de9c02
commit
63b3cae096
@ -20,7 +20,7 @@ internal static ISteamMatchmakingServers Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamMatchmakingServers();
|
||||
_internal.InitClient();
|
||||
_internal.Init();
|
||||
}
|
||||
|
||||
return _internal;
|
||||
|
@ -21,7 +21,7 @@ internal static ISteamApps Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamApps();
|
||||
_internal.InitClient();
|
||||
_internal.Init();
|
||||
}
|
||||
|
||||
return _internal;
|
||||
|
@ -142,7 +142,5 @@ internal static void UnregisterCallback( IntPtr intPtr )
|
||||
/// returns the appID of the current process
|
||||
/// </summary>
|
||||
public static AppId AppId { get; internal set; }
|
||||
|
||||
public static IDisposable Push() => Realm.Client();
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ internal static ISteamFriends Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamFriends();
|
||||
_internal.InitClient();
|
||||
_internal.Init();
|
||||
|
||||
richPresence = new Dictionary<string, string>();
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ internal static ISteamInventory Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamInventory();
|
||||
_internal.InitClient();
|
||||
_internal.Init();
|
||||
}
|
||||
|
||||
return _internal;
|
||||
|
@ -13,6 +13,7 @@ namespace Steamworks
|
||||
public static class SteamMatchmaking
|
||||
{
|
||||
static ISteamMatchmaking _internal;
|
||||
|
||||
internal static ISteamMatchmaking Internal
|
||||
{
|
||||
get
|
||||
@ -20,7 +21,6 @@ internal static ISteamMatchmaking Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamMatchmaking();
|
||||
_internal.InitClient();
|
||||
}
|
||||
|
||||
return _internal;
|
||||
|
@ -23,7 +23,7 @@ internal static ISteamMusic Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamMusic();
|
||||
_internal.InitClient();
|
||||
_internal.Init();
|
||||
}
|
||||
|
||||
return _internal;
|
||||
|
@ -18,7 +18,7 @@ internal static ISteamNetworkingSockets Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamNetworkingSockets();
|
||||
_internal.InitClient();
|
||||
_internal.Init();
|
||||
|
||||
SocketInterfaces = new Dictionary<uint, SocketInterface>();
|
||||
ConnectionInterfaces = new Dictionary<uint, ConnectionInterface>();
|
||||
|
@ -20,7 +20,7 @@ internal static ISteamParentalSettings Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamParentalSettings();
|
||||
_internal.InitClient();
|
||||
_internal.Init();
|
||||
}
|
||||
|
||||
return _internal;
|
||||
|
@ -17,7 +17,7 @@ internal static ISteamParties Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamParties();
|
||||
_internal.InitClient();
|
||||
_internal.Init();
|
||||
}
|
||||
|
||||
return _internal;
|
||||
|
@ -20,7 +20,7 @@ internal static ISteamRemoteStorage Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamRemoteStorage();
|
||||
_internal.InitClient();
|
||||
_internal.Init();
|
||||
}
|
||||
|
||||
return _internal;
|
||||
|
@ -20,7 +20,7 @@ internal static ISteamScreenshots Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamScreenshots();
|
||||
_internal.InitClient();
|
||||
_internal.Init();
|
||||
}
|
||||
|
||||
return _internal;
|
||||
|
@ -75,7 +75,8 @@ public static void Init( AppId appid, SteamServerInit init )
|
||||
DedicatedServer = true;
|
||||
|
||||
InstallEvents();
|
||||
RunCallbacks();
|
||||
|
||||
RunCallbacksAsync();
|
||||
}
|
||||
|
||||
public static void Shutdown()
|
||||
@ -92,16 +93,14 @@ public static void Shutdown()
|
||||
SteamGameServer.Shutdown();
|
||||
}
|
||||
|
||||
|
||||
internal static async void RunCallbacks()
|
||||
internal static async void RunCallbacksAsync()
|
||||
{
|
||||
while ( true )
|
||||
while ( IsValid )
|
||||
{
|
||||
await Task.Delay( 16 );
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Update()
|
||||
{
|
||||
try
|
||||
@ -373,7 +372,5 @@ public static unsafe void HandleIncomingPacket( byte[] data, int size, uint addr
|
||||
Internal.HandleIncomingPacket( (IntPtr)ptr, size, address, port );
|
||||
}
|
||||
}
|
||||
|
||||
public static IDisposable Push() => Realm.Server();
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ internal static ISteamUGC Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamUGC();
|
||||
_internal.InitClient();
|
||||
_internal.Init();
|
||||
}
|
||||
|
||||
return _internal;
|
||||
|
@ -22,7 +22,7 @@ internal static ISteamUser Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamUser();
|
||||
_internal.InitClient();
|
||||
_internal.Init();
|
||||
|
||||
richPresence = new Dictionary<string, string>();
|
||||
|
||||
|
@ -17,7 +17,7 @@ internal static ISteamUserStats Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamUserStats();
|
||||
_internal.InitClient();
|
||||
_internal.Init();
|
||||
|
||||
RequestCurrentStats();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ internal static ISteamUtils Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamUtils();
|
||||
_internal.InitClient();
|
||||
_internal.Init();
|
||||
}
|
||||
|
||||
return _internal;
|
||||
|
@ -20,7 +20,7 @@ internal static ISteamVideo Internal
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamVideo();
|
||||
_internal.InitClient();
|
||||
_internal.Init();
|
||||
}
|
||||
|
||||
return _internal;
|
||||
|
@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace Steamworks
|
||||
{
|
||||
public static class Realm
|
||||
{
|
||||
//
|
||||
// true = serverside
|
||||
//
|
||||
static Stack<bool> _stack = new Stack<bool>();
|
||||
|
||||
public static bool IsServer => _stack.Count > 0 && _stack.Peek();
|
||||
|
||||
public static bool IsClient => _stack.Count == 0 || !_stack.Peek();
|
||||
|
||||
|
||||
static public IDisposable Server()
|
||||
{
|
||||
_stack.Push( true );
|
||||
return new StackPopper();
|
||||
}
|
||||
|
||||
static public IDisposable Client()
|
||||
{
|
||||
_stack.Push( false );
|
||||
return new StackPopper();
|
||||
}
|
||||
|
||||
public struct StackPopper : IDisposable
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
_stack.Pop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -16,7 +16,24 @@ internal abstract class SteamInterface
|
||||
|
||||
public virtual string InterfaceName => null;
|
||||
|
||||
public virtual void InitClient()
|
||||
public void Init()
|
||||
{
|
||||
if ( SteamClient.IsValid )
|
||||
{
|
||||
InitClient();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( SteamServer.IsValid )
|
||||
{
|
||||
InitServer();
|
||||
return;
|
||||
}
|
||||
|
||||
throw new System.Exception( "Trying to initialize Steam Interface but Steam not initialized" );
|
||||
}
|
||||
|
||||
public void InitClient()
|
||||
{
|
||||
var user = SteamAPI.GetHSteamUser();
|
||||
Self = SteamInternal.FindOrCreateUserInterface( user, InterfaceName );
|
||||
@ -31,7 +48,7 @@ public virtual void InitClient()
|
||||
InitInternals();
|
||||
}
|
||||
|
||||
public virtual void InitServer()
|
||||
public void InitServer()
|
||||
{
|
||||
var user = SteamGameServer.GetHSteamUser();
|
||||
Self = SteamInternal.FindOrCreateGameServerInterface( user, InterfaceName );
|
||||
|
Loading…
Reference in New Issue
Block a user