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.
// 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(varlobbyUserinm_localLobby.LobbyUsers)
{
if(lobbyUser.Value.IsHost)
return;
}
Locator.Get.Messenger.OnReceiveMessage(MessageType.DisplayErrorPopup,"Host left the lobby! Disconnecting...");
/// 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>
publicvirtualvoidLeave()
connection.Disconnect(m_networkDriver);
// If the client calls Disconnect, the host might not become aware right away (depending on when the PubSub messages get pumped), so send a message over UTP instead.
if(!m_IsRelayConnected)// If Relay was disconnected somehow, stop taking actions that will keep the allocation alive.
return;
DoHeartbeat();
UpdateConnections();
}
/// <summary>
}
elseif(msgType==MsgType.NewPlayer)// This ensures clients in builds are sent player state once they establish that they can send (and receive) events.
OnNewConnection(conn);
elseif(msgType==MsgType.PlayerDisconnect)// Clients message the host when they intend to disconnect, or else the host ends up keeping the connection open.
{
conn.Disconnect(m_networkDriver);
UnityEngine.Debug.LogWarning("Disconnecting a client due to a disconnect message.");
return;
}
// If a client has changed state, check if this changes whether all players have readied.
if(msgType==MsgType.ReadyState)
/// <summary>
/// Clean out destroyed connections, and accept all new ones.
/// </summary>
privatevoidDoHeartbeat()
privatevoidUpdateConnections()
{
for(intc=m_connections.Count-1;c>=0;c--)
{
m_connections.Add(conn);
OnNewConnection(conn);// This ensures that clients in editors are sent player state once they establish a connection. The timing differs slightly from builds.