}
#region Once connected to a lobby, cache the local lobby object so we don't query for it for every lobby operation.
// (This assumes that the player will be actively in just one lobby at a time, though they could passively be in more.)
private string m_currentLobbyId = null ;
private Lobby m_lastKnownLobby ;
#endregion
#region Lobby API calls are rate limited, and some other operations might want an alert when the rate limits have passed.
public enum RequestType { Query = 0 , Join }
public enum RequestType
{
Query = 0 ,
Join
}
public RateLimitCooldown GetRateLimit ( RequestType type )
{
if ( type = = RequestType . Join )
private RateLimitCooldown m_rateLimitQuery = new RateLimitCooldown ( 1.5f ) ; // Used for both the lobby list UI and the in-lobby updating. In the latter case, updates can be cached.
private RateLimitCooldown m_rateLimitJoin = new RateLimitCooldown ( 3f ) ;
private RateLimitCooldown m_rateLimitJoin = new RateLimitCooldown ( 3f ) ;
#endregion
private static Dictionary < string , PlayerDataObject > CreateInitialPlayerData ( LobbyUser player )
( lobbyId = = null & & lobbyCode = = null ) )
{
onFailure ? . Invoke ( ) ;
// TODO: Emit some failure message.
return ;
}
var filters = LobbyColorToFilters ( limitToColor ) ;
string uasId = AuthenticationService . Instance . PlayerId ;
LobbyAPIInterface . QuickJoinLobbyAsync ( uasId , filters , CreateInitialPlayerData ( localUser ) , OnLobbyJoined ) ;
void OnLobbyJoined ( Lobby response )
{
if ( response = = null )
onComplete ? . Invoke ( null ) ;
return ;
}
LobbyAPIInterface . GetLobbyAsync ( lobbyId , OnGet ) ;
void OnGet ( Lobby response )
private bool ShouldUpdateData ( Action caller , Action onComplete , bool shouldRetryIfLobbyNull )
{
if ( m_rateLimitQuery . IsInCooldown )
{ m_rateLimitQuery . EnqueuePendingOperation ( caller ) ;
{
m_rateLimitQuery . EnqueuePendingOperation ( caller ) ;
Lobby lobby = m_lastKnownLobby ;
if ( lobby = = null )
{
return false ;
}
return true ;
}
}
private bool m_isInCooldown = false ;
{ if ( m_isInCooldown ! = value )
{ m_isInCooldown = value ;
{
if ( m_isInCooldown ! = value )
{
m_isInCooldown = value ;
OnChanged ( this ) ;
}
}
}
}
public override void CopyObserved ( RateLimitCooldown oldObserved ) { /* This behavior isn't needed; we're just here for the OnChanged event management. */ }
public override void CopyObserved ( RateLimitCooldown oldObserved )
{
/* This behavior isn't needed; we're just here for the OnChanged event management. */
}
}
}