浏览代码

Adding a few comments for clarification.

/main/staging/relay_disconnect_ping_bug
nathaniel.buck@unity3d.com 3 年前
当前提交
51d51cfa
共有 2 个文件被更改,包括 8 次插入5 次删除
  1. 9
      Assets/Scripts/Relay/RelayUtpClient.cs
  2. 4
      Assets/Scripts/Relay/RelayUtpHost.cs

9
Assets/Scripts/Relay/RelayUtpClient.cs


OnUpdate();
}
/// <summary>
/// Clients need to send any data over UTP periodically, or else Relay will remove them from the allocation.
/// </summary>
// Clients need to send any data over UTP periodically, or else the connection will timeout.
if (!m_IsRelayConnected) // However, if disconnected from Relay for some reason, we want the connection to timeout.
if (!m_IsRelayConnected) // If disconnected from Relay for some reason, we *want* this client to timeout.
return;
foreach (NetworkConnection connection in m_connections)
WriteByte(m_networkDriver, connection, "0", MsgType.Ping, 0); // The ID doesn't matter here, so send a minimal number of bytes.

public virtual void Leave()
{
foreach (NetworkConnection connection in m_connections)
WriteByte(m_networkDriver, connection, m_localUser.ID, MsgType.PlayerDisconnect, 0); // If the client breaks the connection, the host might still maintain it, so message instead.
// 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.
WriteByte(m_networkDriver, connection, m_localUser.ID, MsgType.PlayerDisconnect, 0);
m_localLobby.RelayServer = null;
}
}

4
Assets/Scripts/Relay/RelayUtpHost.cs


protected override void OnUpdate()
{
if (!m_IsRelayConnected) // If Relay was disconnected somehow, stop taking actions that will keep the lobby alive.
if (!m_IsRelayConnected) // If Relay was disconnected somehow, stop taking actions that will keep the allocation alive.
return;
base.OnUpdate();
UpdateConnections();

public override void Leave()
{
foreach (NetworkConnection connection in m_connections)
connection.Disconnect(m_networkDriver);
connection.Disconnect(m_networkDriver); // Note that Lobby won't receive the disconnect immediately, so its auto-disconnect takes 30-40s, if needed.
m_localLobby.RelayServer = null;
}
}
正在加载...
取消
保存