Fix GetAvatar sometimes failing instead of waiting for the avatar to load

This commit is contained in:
Rohan Singh 2018-11-01 08:35:49 -04:00
parent 438127288a
commit 13280cd57c

View File

@ -271,11 +271,21 @@ public void GetAvatar( AvatarSize size, ulong steamid, Action<Image> callback )
// Lets request it from Steam
if (!client.native.friends.RequestUserInformation(steamid, false))
{
// Steam told us to get fucked
callback(null);
// from docs: false means that we already have all the details about that user, and functions that require this information can be used immediately
// but that's probably not true because we just checked the cache
// check again in case it was just a race
image = GetCachedAvatar(size, steamid);
if ( image != null )
{
callback(image);
return;
}
// maybe Steam returns false if it was already requested? just add another callback and hope it comes
// if not it'll time out anyway
}
PersonaCallbacks.Add( new PersonaCallback
{
SteamId = steamid,
@ -326,7 +336,10 @@ internal void Cycle()
{
if ( cb.Callback != null )
{
cb.Callback( null );
// final attempt, will be null unless the callback was missed somehow
var image = GetCachedAvatar( cb.Size, cb.SteamId );
cb.Callback( image );
}
PersonaCallbacks.Remove( cb );