mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-12 14:48:02 +03:00
Fix serverlist query allocating a large amount of memory when a large amount of servers are pending
This commit is contained in:
parent
4463739be5
commit
d18086a1b8
@ -107,6 +107,23 @@ namespace Steamworks
|
||||
return returnValue.ToType<gameserveritem_t>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read gameserveritem_t.m_bHadSuccessfulResponse without allocating the struct on the heap
|
||||
/// </summary>
|
||||
/// <param name="hRequest"></param>
|
||||
/// <param name="iServer"></param>
|
||||
/// <returns></returns>
|
||||
internal bool HasServerResponded( HServerListRequest hRequest, int iServer )
|
||||
{
|
||||
IntPtr returnValue = _GetServerDetails( Self, hRequest, iServer );
|
||||
|
||||
// Return false if steam returned null
|
||||
if ( returnValue == IntPtr.Zero ) return false;
|
||||
|
||||
// first 8 bytes is IPAddress, next 4 bytes is ping, next 1 byte is m_bHadSuccessfulResponse
|
||||
return Marshal.ReadByte( IntPtr.Add( returnValue, 12 ) ) == 1;
|
||||
}
|
||||
|
||||
#region FunctionMeta
|
||||
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamMatchmakingServers_CancelQuery", CallingConvention = Platform.CC)]
|
||||
private static extern void _CancelQuery( IntPtr self, HServerListRequest hRequest );
|
||||
|
@ -31,8 +31,11 @@ namespace Steamworks.Data
|
||||
{
|
||||
internal servernetadr_t NetAdr; // m_NetAdr servernetadr_t
|
||||
internal int Ping; // m_nPing int
|
||||
|
||||
// NOTE: If you add fields above this you must change offset inISteamMatchmakingServers.HasServerResponded()
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
internal bool HadSuccessfulResponse; // m_bHadSuccessfulResponse bool
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
internal bool DoNotRefresh; // m_bDoNotRefresh bool
|
||||
internal string GameDirUTF8() => System.Text.Encoding.UTF8.GetString( GameDir, 0, System.Array.IndexOf<byte>( GameDir, 0 ) );
|
||||
|
@ -161,12 +161,18 @@ namespace Steamworks.ServerList
|
||||
{
|
||||
watchList.RemoveAll( x =>
|
||||
{
|
||||
// First check if the server has responded without allocating server info
|
||||
bool hasResponded = Internal.HasServerResponded( request, x );
|
||||
if ( hasResponded )
|
||||
{
|
||||
// Now get all server info
|
||||
var info = Internal.GetServerDetails( request, x );
|
||||
if ( info.HadSuccessfulResponse )
|
||||
{
|
||||
OnServer( ServerInfo.From( info ), info.HadSuccessfulResponse );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} );
|
||||
|
Loading…
x
Reference in New Issue
Block a user