浏览代码

Removing the use of Relay to transmit the NGO relay code.

/main/staging/ngo_minigame_cleanup
nathaniel.buck@unity3d.com 3 年前
当前提交
3aca367d
共有 6 个文件被更改,包括 12 次插入19 次删除
  1. 15
      Assets/Scripts/Game/InGame/InGameRunner.cs
  2. 1
      Assets/Scripts/Game/InGame/SetupInGame.cs
  3. 1
      Assets/Scripts/Infrastructure/Messenger.cs
  4. 8
      Assets/Scripts/Relay/RelayUtpClient.cs
  5. 5
      Assets/Scripts/Relay/RelayUtpHost.cs
  6. 1
      Assets/Scripts/Relay/RelayUtpSetup.cs

15
Assets/Scripts/Game/InGame/InGameRunner.cs


private void VerifyConnection_ServerRpc(ulong clientId)
{
VerifyConnection_ClientRpc(clientId);
// If not spawning things in the background, start doing so.
m_canSpawnInGameObjects = true;
// While we could start pooling symbol objects now, incoming clients would be flooded with the Spawn calls.
// This could lead to dropped packets (which would mean data loss), so wait until connections have completed.
}
[ClientRpc]
private void VerifyConnection_ClientRpc(ulong clientId)

if (shouldStartImmediately)
{
m_timeout = -1;
Locator.Get.Messenger.OnReceiveMessage(MessageType.GameBeginning, null); // TODO: Might need to delay this a frame to ensure the client finished initializing (since I sometimes hit the "failed to join" message even when joining).
BeginGame();
}
private void BeginGame()
{
m_canSpawnInGameObjects = true;
Locator.Get.Messenger.OnReceiveMessage(MessageType.GameBeginning, null); // TODO: Might need to delay this a frame to ensure the client finished initializing (since I sometimes hit the "failed to join" message even when joining).
}
public void Update()

{
m_timeout -= Time.deltaTime;
if (m_timeout < 0)
Locator.Get.Messenger.OnReceiveMessage(MessageType.GameBeginning, null);
BeginGame();
}
// TODO: BSP for choosing symbol spawn positions?

1
Assets/Scripts/Game/InGame/SetupInGame.cs


{
GameObject.Destroy(m_inGameManagerObj); // Since this destroys the NetworkManager, that will kick off cleaning up networked objects.
SetMenuVisibility(true);
m_lobby.RelayNGOCode = null;
m_doesNeedCleanup = false;
}
}

1
Assets/Scripts/Infrastructure/Messenger.cs


CancelCountdown = 201,
CompleteCountdown = 202,
GameBeginning = 203,
NGORelayCode = 204,
DisplayErrorPopup = 300,
}

8
Assets/Scripts/Relay/RelayUtpClient.cs


protected bool m_hasSentInitialMessage = false;
private const float k_heartbeatPeriod = 5;
protected enum MsgType { Ping = 0, NewPlayer, PlayerApprovalState, ReadyState, PlayerName, Emote, StartCountdown, CancelCountdown, ConfirmInGame, EndInGame, PlayerDisconnect, NGORelayCode }
protected enum MsgType { Ping = 0, NewPlayer, PlayerApprovalState, ReadyState, PlayerName, Emote, StartCountdown, CancelCountdown, ConfirmInGame, EndInGame, PlayerDisconnect }
public virtual void Initialize(NetworkDriver networkDriver, List<NetworkConnection> connections, LobbyUser localUser, LocalLobby localLobby)
{

{
UserStatus status = (UserStatus)msgContents[0];
m_localLobby.LobbyUsers[id].UserStatus = status;
}
else if (msgType == MsgType.NGORelayCode)
{
int codeLength = msgContents[0];
string code = System.Text.Encoding.UTF8.GetString(msgContents.GetRange(1, codeLength).ToArray());
m_localLobby.RelayNGOCode = code;
}
else if (msgType == MsgType.StartCountdown)
Locator.Get.Messenger.OnReceiveMessage(MessageType.StartCountdown, null);

5
Assets/Scripts/Relay/RelayUtpHost.cs


foreach (NetworkConnection connection in m_connections)
WriteByte(m_networkDriver, connection, m_localUser.ID, MsgType.EndInGame, 0);
}
else if (type == MessageType.NGORelayCode)
{
foreach (NetworkConnection connection in m_connections)
WriteString(m_networkDriver, connection, m_localUser.ID, MsgType.NGORelayCode, (string)msg);
}
}
private void CheckIfAllUsersReady()

1
Assets/Scripts/Relay/RelayUtpSetup.cs


private void OnRelayCode(string relayCode)
{
Locator.Get.Messenger.OnReceiveMessage(MessageType.NGORelayCode, relayCode);
m_localLobby.RelayNGOCode = relayCode;
}

正在加载...
取消
保存