浏览代码
Primary rejection behavior - A host will reject an incoming client if the lobby is already in the in-game state. Clients will now no longer send data until they are approved, but once approved, connection completes as usual.
/main/staging/host_handshake
Primary rejection behavior - A host will reject an incoming client if the lobby is already in the in-game state. Clients will now no longer send data until they are approved, but once approved, connection completes as usual.
/main/staging/host_handshake
nathaniel.buck@unity3d.com
3 年前
当前提交
1fc7440a
共有 9 个文件被更改,包括 164 次插入 和 20 次删除
-
24Assets/Scripts/Game/GameManager.cs
-
1Assets/Scripts/Game/LobbyUser.cs
-
4Assets/Scripts/Infrastructure/Messenger.cs
-
17Assets/Scripts/Lobby/LobbyContentHeartbeat.cs
-
29Assets/Scripts/Relay/RelayUtpClient.cs
-
39Assets/Scripts/Relay/RelayUtpHost.cs
-
2Assets/Scripts/Relay/RelayUtpSetup.cs
-
57Assets/Scripts/Relay/RelayPendingApproval.cs
-
11Assets/Scripts/Relay/RelayPendingApproval.cs.meta
|
|||
using System; |
|||
using Unity.Networking.Transport; |
|||
|
|||
namespace LobbyRelaySample.relay |
|||
{ |
|||
/// <summary>
|
|||
/// The Relay host doesn't need to know what might approve or disapprove of a pending connection, so this will
|
|||
/// broadcast a message that approval is being sought, and if nothing disapproves, the connection will be permitted.
|
|||
/// </summary>
|
|||
public class RelayPendingApproval : IDisposable |
|||
{ |
|||
private NetworkConnection m_pendingConnection; |
|||
private bool m_hasDisposed = false; |
|||
private const float k_waitTime = 0.1f; |
|||
private Action<NetworkConnection, Approval> m_onResult; |
|||
public string ID { get; private set; } |
|||
|
|||
public RelayPendingApproval(NetworkConnection conn, Action<NetworkConnection, Approval> onResult, string id) |
|||
{ |
|||
m_pendingConnection = conn; |
|||
m_onResult = onResult; |
|||
ID = id; |
|||
Locator.Get.UpdateSlow.Subscribe(Approve, k_waitTime); |
|||
Locator.Get.Messenger.OnReceiveMessage(MessageType.ClientUserSeekingDisapproval, (Action<Approval>)Disapprove); |
|||
} |
|||
~RelayPendingApproval() { Dispose(); } |
|||
|
|||
private void Approve(float unused) |
|||
{ |
|||
try |
|||
{ m_onResult?.Invoke(m_pendingConnection, Approval.OK); |
|||
} |
|||
finally |
|||
{ Dispose(); |
|||
} |
|||
} |
|||
|
|||
public void Disapprove(Approval reason) |
|||
{ |
|||
try |
|||
{ m_onResult?.Invoke(m_pendingConnection, reason); |
|||
} |
|||
finally |
|||
{ Dispose(); |
|||
} |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
if (!m_hasDisposed) |
|||
{ |
|||
Locator.Get.UpdateSlow.Unsubscribe(Approve); |
|||
m_hasDisposed = true; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: dbd38eacd3a3f464d8a9a1b69efe37db |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue