mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-26 13:38:06 +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
@ -106,7 +106,24 @@ namespace Steamworks
|
|||||||
var returnValue = _GetServerDetails( Self, hRequest, iServer );
|
var returnValue = _GetServerDetails( Self, hRequest, iServer );
|
||||||
return returnValue.ToType<gameserveritem_t>();
|
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
|
#region FunctionMeta
|
||||||
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamMatchmakingServers_CancelQuery", CallingConvention = Platform.CC)]
|
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamMatchmakingServers_CancelQuery", CallingConvention = Platform.CC)]
|
||||||
private static extern void _CancelQuery( IntPtr self, HServerListRequest hRequest );
|
private static extern void _CancelQuery( IntPtr self, HServerListRequest hRequest );
|
||||||
|
@ -25,14 +25,17 @@ namespace Steamworks.Data
|
|||||||
internal uint IP; // m_unIP uint32
|
internal uint IP; // m_unIP uint32
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout( LayoutKind.Sequential, Pack = Platform.StructPackSize )]
|
[StructLayout( LayoutKind.Sequential, Pack = Platform.StructPackSize )]
|
||||||
internal partial struct gameserveritem_t
|
internal partial struct gameserveritem_t
|
||||||
{
|
{
|
||||||
internal servernetadr_t NetAdr; // m_NetAdr servernetadr_t
|
internal servernetadr_t NetAdr; // m_NetAdr servernetadr_t
|
||||||
internal int Ping; // m_nPing int
|
internal int Ping; // m_nPing int
|
||||||
|
|
||||||
|
// NOTE: If you add fields above this you must change offset inISteamMatchmakingServers.HasServerResponded()
|
||||||
[MarshalAs(UnmanagedType.I1)]
|
[MarshalAs(UnmanagedType.I1)]
|
||||||
internal bool HadSuccessfulResponse; // m_bHadSuccessfulResponse bool
|
internal bool HadSuccessfulResponse; // m_bHadSuccessfulResponse bool
|
||||||
|
|
||||||
[MarshalAs(UnmanagedType.I1)]
|
[MarshalAs(UnmanagedType.I1)]
|
||||||
internal bool DoNotRefresh; // m_bDoNotRefresh bool
|
internal bool DoNotRefresh; // m_bDoNotRefresh bool
|
||||||
internal string GameDirUTF8() => System.Text.Encoding.UTF8.GetString( GameDir, 0, System.Array.IndexOf<byte>( GameDir, 0 ) );
|
internal string GameDirUTF8() => System.Text.Encoding.UTF8.GetString( GameDir, 0, System.Array.IndexOf<byte>( GameDir, 0 ) );
|
||||||
|
@ -161,11 +161,17 @@ namespace Steamworks.ServerList
|
|||||||
{
|
{
|
||||||
watchList.RemoveAll( x =>
|
watchList.RemoveAll( x =>
|
||||||
{
|
{
|
||||||
var info = Internal.GetServerDetails( request, x );
|
// First check if the server has responded without allocating server info
|
||||||
if ( info.HadSuccessfulResponse )
|
bool hasResponded = Internal.HasServerResponded( request, x );
|
||||||
|
if ( hasResponded )
|
||||||
{
|
{
|
||||||
OnServer( ServerInfo.From( info ), info.HadSuccessfulResponse );
|
// Now get all server info
|
||||||
return true;
|
var info = Internal.GetServerDetails( request, x );
|
||||||
|
if ( info.HadSuccessfulResponse )
|
||||||
|
{
|
||||||
|
OnServer( ServerInfo.From( info ), info.HadSuccessfulResponse );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -194,4 +200,4 @@ namespace Steamworks.ServerList
|
|||||||
Unresponsive.Add( serverInfo );
|
Unresponsive.Add( serverInfo );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user