-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientConnectedState.cs
43 lines (39 loc) · 1.41 KB
/
ClientConnectedState.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
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))
{
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);
}
}
}
}