You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.5 KiB
C#
44 lines
1.5 KiB
C#
1 week ago
|
using Unity.BossRoom.UnityServices.Lobbies;
|
||
|
using UnityEngine;
|
||
|
using VContainer;
|
||
|
|
||
|
namespace Unity.BossRoom.ConnectionManagement
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Connection state corresponding to a connected client. When being disconnected, transitions to the
|
||
|
/// ClientReconnecting state if no reason is given, or to the Offline state.
|
||
|
/// </summary>
|
||
|
class ClientConnectedState : OnlineState
|
||
|
{
|
||
|
[Inject]
|
||
|
protected LobbyServiceFacade m_LobbyServiceFacade;
|
||
|
|
||
|
public override void Enter()
|
||
|
{
|
||
|
if (m_LobbyServiceFacade.CurrentUnityLobby != null)
|
||
|
{
|
||
|
m_LobbyServiceFacade.BeginTracking();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public override void Exit() { }
|
||
|
|
||
|
public override void OnClientDisconnect(ulong _)
|
||
|
{
|
||
|
var disconnectReason = m_ConnectionManager.NetworkManager.DisconnectReason;
|
||
|
if (string.IsNullOrEmpty(disconnectReason) ||
|
||
|
disconnectReason == "Disconnected due to host shutting down.")
|
||
|
{
|
||
|
m_ConnectStatusPublisher.Publish(ConnectStatus.Reconnecting);
|
||
|
m_ConnectionManager.ChangeState(m_ConnectionManager.m_ClientReconnecting);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
var connectStatus = JsonUtility.FromJson<ConnectStatus>(disconnectReason);
|
||
|
m_ConnectStatusPublisher.Publish(connectStatus);
|
||
|
m_ConnectionManager.ChangeState(m_ConnectionManager.m_Offline);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|