浏览代码

Quick change to have the lobby list refresh upon returning from a lobby, as though entering from the main menu. Since we constantly query while in the lobby, the rate limit could interfere, so there's now logic to wait if needed.

/main/staging/rate_limit_data
nathaniel.buck@unity3d.com 3 年前
当前提交
20603d75
共有 3 个文件被更改,包括 7 次插入6 次删除
  1. 2
      Assets/Scripts/Game/GameManager.cs
  2. 9
      Assets/Scripts/Lobby/LobbyAsyncRequests.cs
  3. 2
      Assets/Scripts/UI/JoinMenuUI.cs

2
Assets/Scripts/Game/GameManager.cs


qr => {
if (qr != null)
OnLobbiesQueried(lobby.ToLocalLobby.Convert(qr));
else
m_lobbyServiceData.State = LobbyQueryState.Error;
},
er => {
long errorLong = 0;

9
Assets/Scripts/Lobby/LobbyAsyncRequests.cs


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);
// TODO: Shift to using this to do rate limiting for all API calls? E.g. the
// TODO: Shift to using this to do rate limiting for all API calls? E.g. the lobby data pushing is on its own loop.
#endregion
private static Dictionary<string, PlayerDataObject> CreateInitialPlayerData(LobbyUser player)

{
if (!m_rateLimitQuery.CanCall())
{
// We assume this can only occur when leaving a lobby and returning to the join menu; the refresh button is rate-limited, but we might have recently queried while still in the lobby.
m_pendingOperations.Enqueue(() => { RetrieveLobbyListAsync(onListRetrieved, onError, limitToColor); }); // With that assumption, retry the refresh after the limit, as though entering the join menu from the main menu.
return;
}

public bool IsInCooldown
{
get => m_isInCooldown;
set
private set
{ if (m_isInCooldown != value)
{ m_isInCooldown = value;
OnChanged(this);

if (m_timeSinceLastCall >= m_cooldownTime)
{
IsInCooldown = false;
Locator.Get.UpdateSlow.Unsubscribe(OnUpdate); // Note that this is after IsInCooldown is set, to prevent an Observer from kicking off CanCall again immediately.
if (!m_isInCooldown) // It's possible that by setting IsInCooldown, something called CanCall immediately, in which case we want to stay on UpdateSlow.
Locator.Get.UpdateSlow.Unsubscribe(OnUpdate); // Note that this is after IsInCooldown is set, to prevent an Observer from kicking off CanCall again immediately.
}
}

2
Assets/Scripts/UI/JoinMenuUI.cs


m_LocalLobbySelected = lobby.Data;
}
public void OnJoinCodeInputFieldChanged(string newCode)
public void OnJoinCodeInputFieldChanged(string newCode) // TODO: LobbyCode or JoinCode?
{
if (!string.IsNullOrEmpty(newCode))
m_LocalLobbySelected = new LocalLobby.LobbyData(newCode.ToUpper());

正在加载...
取消
保存