浏览代码

Adding in a special case for a client to detect the host leaving the lobby. Verified that we don't need to do additional cleanup. Verified that the host disconnecting from Relay will cause the lobby to disconnect after 10s as expected; this supplies an error popup with the exception, which is fine?

/main/staging/relay_disconnect_ping_bug
nathaniel.buck@unity3d.com 3 年前
当前提交
d44c2386
共有 3 个文件被更改,包括 17 次插入1 次删除
  1. 2
      Assets/Scripts/Lobby/LobbyAsyncRequests.cs
  2. 13
      Assets/Scripts/Lobby/LobbyContentHeartbeat.cs
  3. 3
      Assets/Scripts/Relay/RelayUtpClient.cs

2
Assets/Scripts/Lobby/LobbyAsyncRequests.cs


void OnGet(Lobby response)
{
onComplete?.Invoke(response);
onComplete?.Invoke(response); // FUTURE: Consider passing in the exception code here (and elsewhere) to, e.g., specifically handle a 404 indicating a Relay auto-disconnect.
}
}

13
Assets/Scripts/Lobby/LobbyContentHeartbeat.cs


var prevState = m_localLobby.State;
lobby.ToLocalLobby.Convert(lobbyRemote, m_localLobby);
m_shouldPushData = prevShouldPush;
// If the host suddenly leaves, the Lobby service will automatically handle disconnects after about 30s, but we can try to do a disconnect sooner if we detect it.
if (!m_localUser.IsHost)
{
foreach (var lobbyUser in m_localLobby.LobbyUsers)
{
if (lobbyUser.Value.IsHost)
return;
}
Locator.Get.Messenger.OnReceiveMessage(MessageType.DisplayErrorPopup, "Host left the lobby! Disconnecting...");
Locator.Get.Messenger.OnReceiveMessage(MessageType.EndGame, null);
Locator.Get.Messenger.OnReceiveMessage(MessageType.ChangeGameState, GameState.JoinMenu);
}
}
}

3
Assets/Scripts/Relay/RelayUtpClient.cs


}
}
/// <summary>
/// Disconnect from Relay, usually while leaving the lobby. (You can also call this elsewhere to see how Lobby will detect a Relay disconnect automatically.)
/// </summary>
public virtual void Leave()
{
foreach (NetworkConnection connection in m_connections)

正在加载...
取消
保存