Networking Cleanup

This commit is contained in:
Garry Newman 2020-02-24 08:58:09 +00:00
parent 4871c634fb
commit e7a6a00675
24 changed files with 128 additions and 87 deletions

View File

@ -38,7 +38,7 @@ public async Task LocalPingLocation()
[TestMethod]
public void PingLocationParse()
{
var pl = Data.PingLocation.TryParseFromString( GarrysLocation );
var pl = Data.NetPingLocation.TryParseFromString( GarrysLocation );
Assert.IsTrue( pl.HasValue );
@ -50,7 +50,7 @@ public async Task GetEstimatedPing()
{
await SteamNetworkingUtils.WaitForPingDataAsync();
var garrysping = Data.PingLocation.TryParseFromString( GarrysLocation );
var garrysping = Data.NetPingLocation.TryParseFromString( GarrysLocation );
Assert.IsTrue( garrysping.HasValue );
var ping = SteamNetworkingUtils.EstimatePingTo( garrysping.Value );

View File

@ -448,10 +448,10 @@ internal bool ReceivedP2PCustomSignal( IntPtr pMsg, int cbMsg, IntPtr pContext )
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamNetworkingSockets_GetCertificateRequest", CallingConvention = Platform.CC)]
[return: MarshalAs( UnmanagedType.I1 )]
private static extern bool _GetCertificateRequest( IntPtr self, ref int pcbBlob, IntPtr pBlob, ref SteamNetworkingErrMsg errMsg );
private static extern bool _GetCertificateRequest( IntPtr self, ref int pcbBlob, IntPtr pBlob, ref NetErrorMessage errMsg );
#endregion
internal bool GetCertificateRequest( ref int pcbBlob, IntPtr pBlob, ref SteamNetworkingErrMsg errMsg )
internal bool GetCertificateRequest( ref int pcbBlob, IntPtr pBlob, ref NetErrorMessage errMsg )
{
var returnValue = _GetCertificateRequest( Self, ref pcbBlob, pBlob, ref errMsg );
return returnValue;
@ -460,10 +460,10 @@ internal bool GetCertificateRequest( ref int pcbBlob, IntPtr pBlob, ref SteamNet
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamNetworkingSockets_SetCertificate", CallingConvention = Platform.CC)]
[return: MarshalAs( UnmanagedType.I1 )]
private static extern bool _SetCertificate( IntPtr self, IntPtr pCertificate, int cbCertificate, ref SteamNetworkingErrMsg errMsg );
private static extern bool _SetCertificate( IntPtr self, IntPtr pCertificate, int cbCertificate, ref NetErrorMessage errMsg );
#endregion
internal bool SetCertificate( IntPtr pCertificate, int cbCertificate, ref SteamNetworkingErrMsg errMsg )
internal bool SetCertificate( IntPtr pCertificate, int cbCertificate, ref NetErrorMessage errMsg )
{
var returnValue = _SetCertificate( Self, pCertificate, cbCertificate, ref errMsg );
return returnValue;

View File

@ -54,10 +54,10 @@ internal SteamNetworkingAvailability GetRelayNetworkStatus( ref SteamRelayNetwor
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamNetworkingUtils_GetLocalPingLocation", CallingConvention = Platform.CC)]
private static extern float _GetLocalPingLocation( IntPtr self, ref PingLocation result );
private static extern float _GetLocalPingLocation( IntPtr self, ref NetPingLocation result );
#endregion
internal float GetLocalPingLocation( ref PingLocation result )
internal float GetLocalPingLocation( ref NetPingLocation result )
{
var returnValue = _GetLocalPingLocation( Self, ref result );
return returnValue;
@ -65,10 +65,10 @@ internal float GetLocalPingLocation( ref PingLocation result )
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamNetworkingUtils_EstimatePingTimeBetweenTwoLocations", CallingConvention = Platform.CC)]
private static extern int _EstimatePingTimeBetweenTwoLocations( IntPtr self, ref PingLocation location1, ref PingLocation location2 );
private static extern int _EstimatePingTimeBetweenTwoLocations( IntPtr self, ref NetPingLocation location1, ref NetPingLocation location2 );
#endregion
internal int EstimatePingTimeBetweenTwoLocations( ref PingLocation location1, ref PingLocation location2 )
internal int EstimatePingTimeBetweenTwoLocations( ref NetPingLocation location1, ref NetPingLocation location2 )
{
var returnValue = _EstimatePingTimeBetweenTwoLocations( Self, ref location1, ref location2 );
return returnValue;
@ -76,10 +76,10 @@ internal int EstimatePingTimeBetweenTwoLocations( ref PingLocation location1, re
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamNetworkingUtils_EstimatePingTimeFromLocalHost", CallingConvention = Platform.CC)]
private static extern int _EstimatePingTimeFromLocalHost( IntPtr self, ref PingLocation remoteLocation );
private static extern int _EstimatePingTimeFromLocalHost( IntPtr self, ref NetPingLocation remoteLocation );
#endregion
internal int EstimatePingTimeFromLocalHost( ref PingLocation remoteLocation )
internal int EstimatePingTimeFromLocalHost( ref NetPingLocation remoteLocation )
{
var returnValue = _EstimatePingTimeFromLocalHost( Self, ref remoteLocation );
return returnValue;
@ -87,10 +87,10 @@ internal int EstimatePingTimeFromLocalHost( ref PingLocation remoteLocation )
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamNetworkingUtils_ConvertPingLocationToString", CallingConvention = Platform.CC)]
private static extern void _ConvertPingLocationToString( IntPtr self, ref PingLocation location, IntPtr pszBuf, int cchBufSize );
private static extern void _ConvertPingLocationToString( IntPtr self, ref NetPingLocation location, IntPtr pszBuf, int cchBufSize );
#endregion
internal void ConvertPingLocationToString( ref PingLocation location, out string pszBuf )
internal void ConvertPingLocationToString( ref NetPingLocation location, out string pszBuf )
{
IntPtr mempszBuf = Helpers.TakeMemory();
_ConvertPingLocationToString( Self, ref location, mempszBuf, (1024 * 32) );
@ -100,10 +100,10 @@ internal void ConvertPingLocationToString( ref PingLocation location, out string
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamNetworkingUtils_ParsePingLocationString", CallingConvention = Platform.CC)]
[return: MarshalAs( UnmanagedType.I1 )]
private static extern bool _ParsePingLocationString( IntPtr self, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string pszString, ref PingLocation result );
private static extern bool _ParsePingLocationString( IntPtr self, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string pszString, ref NetPingLocation result );
#endregion
internal bool ParsePingLocationString( [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string pszString, ref PingLocation result )
internal bool ParsePingLocationString( [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string pszString, ref NetPingLocation result )
{
var returnValue = _ParsePingLocationString( Self, pszString, ref result );
return returnValue;
@ -178,10 +178,10 @@ internal long GetLocalTimestamp()
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamNetworkingUtils_SetDebugOutputFunction", CallingConvention = Platform.CC)]
private static extern void _SetDebugOutputFunction( IntPtr self, DebugOutputType eDetailLevel, FSteamNetworkingSocketsDebugOutput pfnFunc );
private static extern void _SetDebugOutputFunction( IntPtr self, DebugOutputType eDetailLevel, NetDebugFunc pfnFunc );
#endregion
internal void SetDebugOutputFunction( DebugOutputType eDetailLevel, FSteamNetworkingSocketsDebugOutput pfnFunc )
internal void SetDebugOutputFunction( DebugOutputType eDetailLevel, NetDebugFunc pfnFunc )
{
_SetDebugOutputFunction( Self, eDetailLevel, pfnFunc );
}

View File

@ -526,7 +526,7 @@ internal enum MarketNotAllowedReasonFlags : int
//
// EDurationControlProgress
//
internal enum DurationControlProgress : int
public enum DurationControlProgress : int
{
Progress_Full = 0,
Progress_Half = 1,
@ -1988,7 +1988,7 @@ public enum ConnectionState : int
//
// ESteamNetConnectionEnd
//
internal enum SteamNetConnectionEnd : int
public enum NetConnectionEnd : int
{
Invalid = 0,
App_Min = 1000,

View File

@ -178,6 +178,27 @@ internal struct SteamTVRegion_t
}
[StructLayout( LayoutKind.Sequential, Pack = Platform.StructPlatformPackSize )]
internal struct SteamNetworkingQuickConnectionStatus
{
internal ConnectionState State; // m_eState ESteamNetworkingConnectionState
internal int Ping; // m_nPing int
internal float ConnectionQualityLocal; // m_flConnectionQualityLocal float
internal float ConnectionQualityRemote; // m_flConnectionQualityRemote float
internal float OutPacketsPerSec; // m_flOutPacketsPerSec float
internal float OutBytesPerSec; // m_flOutBytesPerSec float
internal float InPacketsPerSec; // m_flInPacketsPerSec float
internal float InBytesPerSec; // m_flInBytesPerSec float
internal int SendRateBytesPerSecond; // m_nSendRateBytesPerSecond int
internal int CbPendingUnreliable; // m_cbPendingUnreliable int
internal int CbPendingReliable; // m_cbPendingReliable int
internal int CbSentUnackedReliable; // m_cbSentUnackedReliable int
internal long EcQueueTime; // m_usecQueueTime SteamNetworkingMicroseconds
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16, ArraySubType = UnmanagedType.U4)]
internal uint[] Reserved; // reserved uint32 [16]
}
[StructLayout( LayoutKind.Sequential, Pack = Platform.StructPlatformPackSize )]
internal struct SteamDatagramHostedAddress
{

View File

@ -3,6 +3,14 @@
namespace Steamworks.Data
{
/// <summary>
/// Used as a base to create your client connection. This creates a socket
/// to a single connection.
///
/// You can override all the virtual functions to turn it into what you
/// want it to do.
/// </summary>
public struct Connection
{
public uint Id { get; set; }
@ -83,10 +91,16 @@ public unsafe Result SendMessage( string str, SendType sendType = SendType.Relia
}
/// <summary>
/// Flush any messages waiting on the Nagle timer and send them at the next transmission opportunity (often that means right now).
/// Flush any messages waiting on the Nagle timer and send them at the next transmission
/// opportunity (often that means right now).
/// </summary>
public Result Flush() => SteamNetworkingSockets.Internal.FlushMessagesOnConnection( this );
/// <summary>
/// Returns detailed connection stats in text format. Useful
/// for dumping to a log, etc.
/// </summary>
/// <returns>Plain text connection info</returns>
public string DetailedStatus()
{
if ( SteamNetworkingSockets.Internal.GetDetailedConnectionStatus( this, out var strVal ) != 0 )

View File

@ -2,6 +2,9 @@
namespace Steamworks.Data
{
/// <summary>
/// Describe the state of a connection
/// </summary>
[StructLayout( LayoutKind.Sequential, Size = 696 )]
public struct ConnectionInfo
{
@ -19,8 +22,19 @@ public struct ConnectionInfo
[MarshalAs( UnmanagedType.ByValTStr, SizeConst = 128 )]
internal string connectionDescription;
/// <summary>
/// High level state of the connection
/// </summary>
public ConnectionState State => state;
/// <summary>
/// Who is on the other end? Depending on the connection type and phase of the connection, we might not know
/// </summary>
public SteamId SteamId => identity.steamID;
public int EndReason => endReason;
/// <summary>
/// Basic cause of the connection termination or problem.
/// </summary>
public NetConnectionEnd EndReason => (NetConnectionEnd)endReason;
}
}

View File

@ -0,0 +1,8 @@
using Steamworks.Data;
using System;
using System.Runtime.InteropServices;
namespace Steamworks.Data
{
delegate void NetDebugFunc( DebugOutputType nType, string pszMsg );
}

View File

@ -3,8 +3,7 @@
namespace Steamworks.Data
{
internal unsafe struct SteamNetworkingErrMsg
internal unsafe struct NetErrorMessage
{
public fixed char Value[1024];
}

View File

@ -20,11 +20,11 @@ namespace Steamworks.Data
///
/// </summary>
[StructLayout( LayoutKind.Explicit, Size = 512 )]
public struct PingLocation
public struct NetPingLocation
{
public static PingLocation? TryParseFromString( string str )
public static NetPingLocation? TryParseFromString( string str )
{
var result = default( PingLocation );
var result = default( NetPingLocation );
if ( !SteamNetworkingUtils.Internal.ParsePingLocationString( str, ref result ) )
return null;
@ -59,7 +59,7 @@ public override string ToString()
///
/// Do you need to be able to do this from a backend/matchmaking server?
/// You are looking for the "ticketgen" library.
public int EstimatePingTo( PingLocation target )
public int EstimatePingTo( NetPingLocation target )
{
return SteamNetworkingUtils.Internal.EstimatePingTimeBetweenTwoLocations( ref this, ref target );
}

View File

@ -5,6 +5,13 @@
namespace Steamworks
{
/// <summary>
/// Used as a base to create your networking server. This creates a socket
/// and listens/communicates with multiple queries.
///
/// You can override all the virtual functions to turn it into what you
/// want it to do.
/// </summary>
public class SocketInterface
{
public List<Connection> Connecting = new List<Connection>();
@ -87,7 +94,6 @@ public void Receive( int bufferSize = 32 )
int processed = 0;
IntPtr messageBuffer = Marshal.AllocHGlobal( IntPtr.Size * bufferSize );
try
{
processed = SteamNetworkingSockets.Internal.ReceiveMessagesOnPollGroup( pollGroup, messageBuffer, bufferSize );

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace Steamworks.Data
{
struct SteamDatagramRelayAuthTicket
{
// Not implemented, not used
};
}

View File

@ -66,11 +66,11 @@ public static void InitRelayNetworkAccess()
/// This always return the most up-to-date information we have available
/// right now, even if we are in the middle of re-calculating ping times.
/// </summary>
public static PingLocation? LocalPingLocation
public static NetPingLocation? LocalPingLocation
{
get
{
PingLocation location = default;
NetPingLocation location = default;
var age = Internal.GetLocalPingLocation( ref location );
if ( age < 0 )
return null;
@ -84,7 +84,7 @@ public static PingLocation? LocalPingLocation
/// This is a bit faster, especially if you need to calculate a bunch of
/// these in a loop to find the fastest one.
/// </summary>
public static int EstimatePingTo( PingLocation target )
public static int EstimatePingTo( NetPingLocation target )
{
return Internal.EstimatePingTimeFromLocalHost( ref target );
}

View File

@ -7,6 +7,12 @@
namespace Steamworks
{
/// <summary>
/// This API can be used to selectively advertise your multiplayer game session in a Steam chat room group.
/// Tell Steam the number of player spots that are available for your party, and a join-game string, and it
/// will show a beacon in the selected group and allow that many users to “follow” the beacon to your party.
/// Adjust the number of open slots if other players join through alternate matchmaking methods.
/// </summary>
public class SteamParties : SteamClientClass<SteamParties>
{
internal static ISteamParties Internal => Interface as ISteamParties;
@ -17,7 +23,7 @@ internal override void InitializeInterface( bool server )
InstallEvents( server );
}
internal static void InstallEvents( bool server )
internal void InstallEvents( bool server )
{
Dispatch.Install<AvailableBeaconLocationsUpdated_t>( x => OnBeaconLocationsUpdated?.Invoke(), server );
Dispatch.Install<ActiveBeaconsUpdated_t>( x => OnActiveBeaconsUpdated?.Invoke(), server );
@ -49,18 +55,5 @@ public static IEnumerable<PartyBeacon> ActiveBeacons
}
}
}
/// <summary>
/// Create a new party beacon and activate it in the selected location.
/// When people begin responding to your beacon, Steam will send you
/// OnPartyReservation callbacks to let you know who is on the way.
/// </summary>
//public async Task<PartyBeacon?> CreateBeacon( int slots, string connectString, string meta )
//{
// var result = await Internal.CreateBeacon( (uint)slots, null, connectString, meta );
// if ( !result.HasValue ) return null;
//}
// TODO - is this useful to anyone, or is it a load of shit?
}
}

View File

@ -1,35 +0,0 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace Steamworks.Data
{
delegate void FSteamNetworkingSocketsDebugOutput (DebugOutputType nType, string pszMsg );
[StructLayout( LayoutKind.Sequential )]
public struct SteamNetworkingQuickConnectionStatus
{
public ConnectionState state;
public int ping;
public float connectionQualityLocal;
public float connectionQualityRemote;
public float outPacketsPerSecond;
public float outBytesPerSecond;
public float inPacketsPerSecond;
public float inBytesPerSecond;
public int sendRateBytesPerSecond;
public int pendingUnreliable;
public int pendingReliable;
public int sentUnackedReliable;
public long queueTime;
[MarshalAs( UnmanagedType.ByValArray, SizeConst = 16 )]
uint[] reserved;
}
struct SteamDatagramRelayAuthTicket
{
// Not implemented
};
}

View File

@ -1,9 +1,13 @@
using System.Linq;
#pragma warning disable 649
namespace Steamworks.Data
{
public struct Ugc
{
internal UGCHandle_t Handle;
}
}
}
#pragma warning restore 649

View File

@ -44,7 +44,9 @@ public IntPtr MarshalManagedToNative(object managedObj)
internal struct Utf8StringPointer
{
#pragma warning disable 649
internal IntPtr ptr;
#pragma warning restore 649
public unsafe static implicit operator string( Utf8StringPointer p )
{

View File

@ -32,11 +32,14 @@ public static string ConvertType( string type )
type = type.Replace( "SteamItemInstanceID_t", "InventoryItemId" );
type = type.Replace( "SteamItemDef_t", "InventoryDefId" );
type = type.Replace( "ChatRoomEnterResponse", "RoomEnter" );
type = type.Replace( "SteamNetworkPingLocation_t", "PingLocation" );
type = type.Replace( "SteamNetworkPingLocation_t", "NetPingLocation" );
type = type.Replace( "SteamNetworkingConfigValue_t", "NetKeyValue" );
type = type.Replace( "SteamNetworkingConfigValue", "NetConfig" );
type = type.Replace( "SteamNetworkingConfigScope", "NetConfigScope" );
type = type.Replace( "SteamNetworkingConfigDataType", "NetConfigType" );
type = type.Replace( "FSteamNetworkingSocketsDebugOutput", "NetDebugFunc" );
type = type.Replace( "SteamNetworkingErrMsg", "NetErrorMessage" );
type = type.Replace( "SteamNetConnectionEnd", "NetConnectionEnd" );
type = type.Replace( "HSteamNetConnection", "Connection" );
type = type.Replace( "HSteamListenSocket", "Socket" );
type = type.Replace( "SteamNetworkingIPAddr", "NetAddress" );
@ -77,18 +80,17 @@ public static bool ShouldCreate( string type )
if ( type == "Connection" ) return false;
if ( type == "Socket" ) return false;
if ( type == "SteamNetworkingMicroseconds" ) return false;
if ( type == "FSteamNetworkingSocketsDebugOutput" ) return false;
if ( type == "NetDebugFunc" ) return false;
if ( type == "NetMsg" ) return false;
if ( type == "SteamDatagramErrMsg" ) return false;
if ( type == "ConnectionInfo" ) return false;
if ( type == "SteamNetworkingIPAddr" ) return false;
if ( type == "NetAddress" ) return false;
if ( type == "NetIdentity" ) return false;
if ( type == "SteamNetworkingQuickConnectionStatus" ) return false;
if ( type == "SteamNetworkingErrMsg" ) return false;
if ( type == "NetKeyValue" ) return false;
if ( type == "SteamIPAddress" ) return false;
if ( type == "PingLocation" ) return false;
if ( type == "NetPingLocation" ) return false;
if ( type == "CSteamID" ) return false;
if ( type == "CSteamAPIContext" ) return false;
if ( type == "CCallResult" ) return false;
@ -126,11 +128,12 @@ internal static string Expose( string name )
if ( name == "InputType" ) return "public";
if ( name == "InputSourceMode" ) return "public";
if ( name == "UserHasLicenseForAppResult" ) return "public";
if ( name == "PingLocation" ) return "public";
if ( name == "NetPingLocation" ) return "public";
if ( name == "ConnectionState" ) return "public";
if ( name == "SteamNetworkingAvailability" ) return "public";
if ( name == "SteamDeviceFormFactor" ) return "public";
if ( name == "DurationControlProgress" ) return "public";
if ( name == "NetConnectionEnd" ) return "public";
return "internal";
}