|
1 | 1 | using System;
|
2 | 2 | using System.Collections;
|
| 3 | +using System.Text; |
3 | 4 | using Unity.Multiplayer.Samples.BossRoom.Shared;
|
4 | 5 | using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
|
5 | 6 | using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Lobbies;
|
@@ -165,25 +166,26 @@ void OnDisconnectOrTimeout(ulong clientID)
|
165 | 166 |
|
166 | 167 | //On a client disconnect we want to take them back to the main menu.
|
167 | 168 | //We have to check here in SceneManager if our active scene is the main menu, as if it is, it means we timed out rather than a raw disconnect;
|
168 |
| - if (SceneManager.GetActiveScene().name != "MainMenu") |
| 169 | + switch (DisconnectReason.Reason) |
169 | 170 | {
|
170 |
| - if (DisconnectReason.Reason == ConnectStatus.UserRequestedDisconnect || DisconnectReason.Reason == ConnectStatus.HostDisconnected || NetworkManager.Singleton.IsHost) |
171 |
| - { |
172 |
| - // simply shut down and go back to main menu |
173 |
| - m_ApplicationController.LeaveSession(); |
174 |
| - } |
175 |
| - else |
176 |
| - { |
| 171 | + case ConnectStatus.UserRequestedDisconnect: |
| 172 | + case ConnectStatus.HostDisconnected: |
| 173 | + case ConnectStatus.LoggedInAgain: |
| 174 | + case ConnectStatus.ServerFull: |
| 175 | + m_ApplicationController.LeaveSession(); // go through the normal leave flow |
| 176 | + break; |
| 177 | + case ConnectStatus.GenericDisconnect: |
| 178 | + case ConnectStatus.Undefined: |
177 | 179 | DisconnectReason.SetDisconnectReason(ConnectStatus.Reconnecting);
|
| 180 | + |
178 | 181 | // load new scene to workaround MTT-2684
|
179 | 182 | SceneManager.LoadScene("Loading");
|
| 183 | + |
180 | 184 | // try reconnecting
|
181 | 185 | m_TryToReconnectCoroutine ??= StartCoroutine(TryToReconnect(lobbyCode));
|
182 |
| - } |
183 |
| - } |
184 |
| - else |
185 |
| - { |
186 |
| - NetworkTimedOut?.Invoke(); |
| 186 | + break; |
| 187 | + default: |
| 188 | + throw new NotImplementedException(DisconnectReason.Reason.ToString()); |
187 | 189 | }
|
188 | 190 |
|
189 | 191 | m_ConnectStatusPub.Publish(DisconnectReason.Reason);
|
@@ -283,11 +285,9 @@ async void ConnectClient(Action<string> onFailure)
|
283 | 285 | {
|
284 | 286 | try
|
285 | 287 | {
|
286 |
| - var clientRelayUtilityTask = UnityRelayUtilities.JoinRelayServerFromJoinCode(m_JoinCode); |
287 |
| - await clientRelayUtilityTask; |
288 |
| - var (ipv4Address, port, allocationIdBytes, connectionData, hostConnectionData, key) = clientRelayUtilityTask.Result; |
| 288 | + var (ipv4Address, port, allocationId, allocationIdBytes, connectionData, hostConnectionData, key) = await UnityRelayUtilities.JoinRelayServerFromJoinCode(m_JoinCode); |
289 | 289 |
|
290 |
| - m_LobbyServiceFacade.UpdatePlayerRelayInfoAsync(allocationIdBytes.ToString(), m_JoinCode, null, null); |
| 290 | + m_LobbyServiceFacade.UpdatePlayerRelayInfoAsync(allocationId.ToString(), m_JoinCode, null, null); |
291 | 291 | var utp = (UnityTransport)NetworkManager.Singleton.NetworkConfig.NetworkTransport;
|
292 | 292 | utp.SetRelayServerData(ipv4Address, port, allocationIdBytes, key, connectionData, hostConnectionData);
|
293 | 293 | }
|
|
0 commit comments