1124 lines
32 KiB
C#
1124 lines
32 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine.Networking.Match;
|
|
using UnityEngine.Networking.NetworkSystem;
|
|
using UnityEngine.Networking.Types;
|
|
|
|
namespace UnityEngine.Networking
|
|
{
|
|
// Token: 0x0200004F RID: 79
|
|
[AddComponentMenu("Network/NetworkMigrationManager")]
|
|
public class NetworkMigrationManager : MonoBehaviour
|
|
{
|
|
// Token: 0x0600033A RID: 826 RVA: 0x00012178 File Offset: 0x00010378
|
|
private void AddPendingPlayer(GameObject obj, int connectionId, NetworkInstanceId netId, short playerControllerId)
|
|
{
|
|
if (!this.m_PendingPlayers.ContainsKey(connectionId))
|
|
{
|
|
NetworkMigrationManager.ConnectionPendingPlayers connectionPendingPlayers = default(NetworkMigrationManager.ConnectionPendingPlayers);
|
|
connectionPendingPlayers.players = new List<NetworkMigrationManager.PendingPlayerInfo>();
|
|
this.m_PendingPlayers[connectionId] = connectionPendingPlayers;
|
|
}
|
|
NetworkMigrationManager.PendingPlayerInfo pendingPlayerInfo = default(NetworkMigrationManager.PendingPlayerInfo);
|
|
pendingPlayerInfo.netId = netId;
|
|
pendingPlayerInfo.playerControllerId = playerControllerId;
|
|
pendingPlayerInfo.obj = obj;
|
|
this.m_PendingPlayers[connectionId].players.Add(pendingPlayerInfo);
|
|
}
|
|
|
|
// Token: 0x0600033B RID: 827 RVA: 0x000121F8 File Offset: 0x000103F8
|
|
private GameObject FindPendingPlayer(int connectionId, NetworkInstanceId netId, short playerControllerId)
|
|
{
|
|
if (this.m_PendingPlayers.ContainsKey(connectionId))
|
|
{
|
|
for (int i = 0; i < this.m_PendingPlayers[connectionId].players.Count; i++)
|
|
{
|
|
NetworkMigrationManager.PendingPlayerInfo pendingPlayerInfo = this.m_PendingPlayers[connectionId].players[i];
|
|
if (pendingPlayerInfo.netId == netId && pendingPlayerInfo.playerControllerId == playerControllerId)
|
|
{
|
|
return pendingPlayerInfo.obj;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// Token: 0x0600033C RID: 828 RVA: 0x00012296 File Offset: 0x00010496
|
|
private void RemovePendingPlayer(int connectionId)
|
|
{
|
|
this.m_PendingPlayers.Remove(connectionId);
|
|
}
|
|
|
|
// Token: 0x1700008A RID: 138
|
|
// (get) Token: 0x0600033D RID: 829 RVA: 0x000122A8 File Offset: 0x000104A8
|
|
// (set) Token: 0x0600033E RID: 830 RVA: 0x000122C3 File Offset: 0x000104C3
|
|
public bool hostMigration
|
|
{
|
|
get
|
|
{
|
|
return this.m_HostMigration;
|
|
}
|
|
set
|
|
{
|
|
this.m_HostMigration = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700008B RID: 139
|
|
// (get) Token: 0x0600033F RID: 831 RVA: 0x000122D0 File Offset: 0x000104D0
|
|
// (set) Token: 0x06000340 RID: 832 RVA: 0x000122EB File Offset: 0x000104EB
|
|
public bool showGUI
|
|
{
|
|
get
|
|
{
|
|
return this.m_ShowGUI;
|
|
}
|
|
set
|
|
{
|
|
this.m_ShowGUI = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700008C RID: 140
|
|
// (get) Token: 0x06000341 RID: 833 RVA: 0x000122F8 File Offset: 0x000104F8
|
|
// (set) Token: 0x06000342 RID: 834 RVA: 0x00012313 File Offset: 0x00010513
|
|
public int offsetX
|
|
{
|
|
get
|
|
{
|
|
return this.m_OffsetX;
|
|
}
|
|
set
|
|
{
|
|
this.m_OffsetX = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700008D RID: 141
|
|
// (get) Token: 0x06000343 RID: 835 RVA: 0x00012320 File Offset: 0x00010520
|
|
// (set) Token: 0x06000344 RID: 836 RVA: 0x0001233B File Offset: 0x0001053B
|
|
public int offsetY
|
|
{
|
|
get
|
|
{
|
|
return this.m_OffsetY;
|
|
}
|
|
set
|
|
{
|
|
this.m_OffsetY = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700008E RID: 142
|
|
// (get) Token: 0x06000345 RID: 837 RVA: 0x00012348 File Offset: 0x00010548
|
|
public NetworkClient client
|
|
{
|
|
get
|
|
{
|
|
return this.m_Client;
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700008F RID: 143
|
|
// (get) Token: 0x06000346 RID: 838 RVA: 0x00012364 File Offset: 0x00010564
|
|
// (set) Token: 0x06000347 RID: 839 RVA: 0x0001237F File Offset: 0x0001057F
|
|
public bool waitingToBecomeNewHost
|
|
{
|
|
get
|
|
{
|
|
return this.m_WaitingToBecomeNewHost;
|
|
}
|
|
set
|
|
{
|
|
this.m_WaitingToBecomeNewHost = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000090 RID: 144
|
|
// (get) Token: 0x06000348 RID: 840 RVA: 0x0001238C File Offset: 0x0001058C
|
|
// (set) Token: 0x06000349 RID: 841 RVA: 0x000123A7 File Offset: 0x000105A7
|
|
public bool waitingReconnectToNewHost
|
|
{
|
|
get
|
|
{
|
|
return this.m_WaitingReconnectToNewHost;
|
|
}
|
|
set
|
|
{
|
|
this.m_WaitingReconnectToNewHost = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000091 RID: 145
|
|
// (get) Token: 0x0600034A RID: 842 RVA: 0x000123B4 File Offset: 0x000105B4
|
|
public bool disconnectedFromHost
|
|
{
|
|
get
|
|
{
|
|
return this.m_DisconnectedFromHost;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000092 RID: 146
|
|
// (get) Token: 0x0600034B RID: 843 RVA: 0x000123D0 File Offset: 0x000105D0
|
|
public bool hostWasShutdown
|
|
{
|
|
get
|
|
{
|
|
return this.m_HostWasShutdown;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000093 RID: 147
|
|
// (get) Token: 0x0600034C RID: 844 RVA: 0x000123EC File Offset: 0x000105EC
|
|
public MatchInfo matchInfo
|
|
{
|
|
get
|
|
{
|
|
return this.m_MatchInfo;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000094 RID: 148
|
|
// (get) Token: 0x0600034D RID: 845 RVA: 0x00012408 File Offset: 0x00010608
|
|
public int oldServerConnectionId
|
|
{
|
|
get
|
|
{
|
|
return this.m_OldServerConnectionId;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000095 RID: 149
|
|
// (get) Token: 0x0600034E RID: 846 RVA: 0x00012424 File Offset: 0x00010624
|
|
// (set) Token: 0x0600034F RID: 847 RVA: 0x0001243F File Offset: 0x0001063F
|
|
public string newHostAddress
|
|
{
|
|
get
|
|
{
|
|
return this.m_NewHostAddress;
|
|
}
|
|
set
|
|
{
|
|
this.m_NewHostAddress = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000096 RID: 150
|
|
// (get) Token: 0x06000350 RID: 848 RVA: 0x0001244C File Offset: 0x0001064C
|
|
public PeerInfoMessage[] peers
|
|
{
|
|
get
|
|
{
|
|
return this.m_Peers;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000097 RID: 151
|
|
// (get) Token: 0x06000351 RID: 849 RVA: 0x00012468 File Offset: 0x00010668
|
|
public Dictionary<int, NetworkMigrationManager.ConnectionPendingPlayers> pendingPlayers
|
|
{
|
|
get
|
|
{
|
|
return this.m_PendingPlayers;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000352 RID: 850 RVA: 0x00012483 File Offset: 0x00010683
|
|
private void Start()
|
|
{
|
|
this.Reset(-1);
|
|
}
|
|
|
|
// Token: 0x06000353 RID: 851 RVA: 0x00012490 File Offset: 0x00010690
|
|
public void Reset(int reconnectId)
|
|
{
|
|
this.m_OldServerConnectionId = -1;
|
|
this.m_WaitingToBecomeNewHost = false;
|
|
this.m_WaitingReconnectToNewHost = false;
|
|
this.m_DisconnectedFromHost = false;
|
|
this.m_HostWasShutdown = false;
|
|
ClientScene.SetReconnectId(reconnectId, this.m_Peers);
|
|
if (NetworkManager.singleton != null)
|
|
{
|
|
NetworkManager.singleton.SetupMigrationManager(this);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000354 RID: 852 RVA: 0x000124EC File Offset: 0x000106EC
|
|
internal void AssignAuthorityCallback(NetworkConnection conn, NetworkIdentity uv, bool authorityState)
|
|
{
|
|
PeerAuthorityMessage peerAuthorityMessage = new PeerAuthorityMessage();
|
|
peerAuthorityMessage.connectionId = conn.connectionId;
|
|
peerAuthorityMessage.netId = uv.netId;
|
|
peerAuthorityMessage.authorityState = authorityState;
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("AssignAuthorityCallback send for netId" + uv.netId);
|
|
}
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null)
|
|
{
|
|
networkConnection.Send(18, peerAuthorityMessage);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000355 RID: 853 RVA: 0x00012580 File Offset: 0x00010780
|
|
public void Initialize(NetworkClient newClient, MatchInfo newMatchInfo)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("NetworkMigrationManager initialize");
|
|
}
|
|
this.m_Client = newClient;
|
|
this.m_MatchInfo = newMatchInfo;
|
|
newClient.RegisterHandlerSafe(11, new NetworkMessageDelegate(this.OnPeerInfo));
|
|
newClient.RegisterHandlerSafe(18, new NetworkMessageDelegate(this.OnPeerClientAuthority));
|
|
NetworkIdentity.clientAuthorityCallback = new NetworkIdentity.ClientAuthorityCallback(this.AssignAuthorityCallback);
|
|
}
|
|
|
|
// Token: 0x06000356 RID: 854 RVA: 0x000125EC File Offset: 0x000107EC
|
|
public void DisablePlayerObjects()
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("NetworkMigrationManager DisablePlayerObjects");
|
|
}
|
|
if (this.m_Peers != null)
|
|
{
|
|
for (int i = 0; i < this.m_Peers.Length; i++)
|
|
{
|
|
PeerInfoMessage peerInfoMessage = this.m_Peers[i];
|
|
if (peerInfoMessage.playerIds != null)
|
|
{
|
|
for (int j = 0; j < peerInfoMessage.playerIds.Length; j++)
|
|
{
|
|
PeerInfoPlayer peerInfoPlayer = peerInfoMessage.playerIds[j];
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log(string.Concat(new object[] { "DisablePlayerObjects disable player for ", peerInfoMessage.address, " netId:", peerInfoPlayer.netId, " control:", peerInfoPlayer.playerControllerId }));
|
|
}
|
|
GameObject gameObject = ClientScene.FindLocalObject(peerInfoPlayer.netId);
|
|
if (gameObject != null)
|
|
{
|
|
gameObject.SetActive(false);
|
|
this.AddPendingPlayer(gameObject, peerInfoMessage.connectionId, peerInfoPlayer.netId, peerInfoPlayer.playerControllerId);
|
|
}
|
|
else if (LogFilter.logWarn)
|
|
{
|
|
Debug.LogWarning(string.Concat(new object[] { "DisablePlayerObjects didnt find player Conn:", peerInfoMessage.connectionId, " NetId:", peerInfoPlayer.netId }));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000357 RID: 855 RVA: 0x0001276C File Offset: 0x0001096C
|
|
public void SendPeerInfo()
|
|
{
|
|
if (this.m_HostMigration)
|
|
{
|
|
PeerListMessage peerListMessage = new PeerListMessage();
|
|
List<PeerInfoMessage> list = new List<PeerInfoMessage>();
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null)
|
|
{
|
|
PeerInfoMessage peerInfoMessage = new PeerInfoMessage();
|
|
string text;
|
|
int num;
|
|
NetworkID networkID;
|
|
NodeID nodeID;
|
|
byte b;
|
|
NetworkTransport.GetConnectionInfo(NetworkServer.serverHostId, networkConnection.connectionId, out text, out num, out networkID, out nodeID, out b);
|
|
peerInfoMessage.connectionId = networkConnection.connectionId;
|
|
peerInfoMessage.port = num;
|
|
if (i == 0)
|
|
{
|
|
peerInfoMessage.port = NetworkServer.listenPort;
|
|
peerInfoMessage.isHost = true;
|
|
peerInfoMessage.address = "<host>";
|
|
}
|
|
else
|
|
{
|
|
peerInfoMessage.address = text;
|
|
peerInfoMessage.isHost = false;
|
|
}
|
|
List<PeerInfoPlayer> list2 = new List<PeerInfoPlayer>();
|
|
for (int j = 0; j < networkConnection.playerControllers.Count; j++)
|
|
{
|
|
PlayerController playerController = networkConnection.playerControllers[j];
|
|
if (playerController != null && playerController.unetView != null)
|
|
{
|
|
PeerInfoPlayer peerInfoPlayer;
|
|
peerInfoPlayer.netId = playerController.unetView.netId;
|
|
peerInfoPlayer.playerControllerId = playerController.unetView.playerControllerId;
|
|
list2.Add(peerInfoPlayer);
|
|
}
|
|
}
|
|
if (networkConnection.clientOwnedObjects != null)
|
|
{
|
|
foreach (NetworkInstanceId networkInstanceId in networkConnection.clientOwnedObjects)
|
|
{
|
|
GameObject gameObject = NetworkServer.FindLocalObject(networkInstanceId);
|
|
if (!(gameObject == null))
|
|
{
|
|
NetworkIdentity component = gameObject.GetComponent<NetworkIdentity>();
|
|
if (component.playerControllerId == -1)
|
|
{
|
|
PeerInfoPlayer peerInfoPlayer2;
|
|
peerInfoPlayer2.netId = networkInstanceId;
|
|
peerInfoPlayer2.playerControllerId = -1;
|
|
list2.Add(peerInfoPlayer2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (list2.Count > 0)
|
|
{
|
|
peerInfoMessage.playerIds = list2.ToArray();
|
|
}
|
|
list.Add(peerInfoMessage);
|
|
}
|
|
}
|
|
peerListMessage.peers = list.ToArray();
|
|
for (int k = 0; k < NetworkServer.connections.Count; k++)
|
|
{
|
|
NetworkConnection networkConnection2 = NetworkServer.connections[k];
|
|
if (networkConnection2 != null)
|
|
{
|
|
peerListMessage.oldServerConnectionId = networkConnection2.connectionId;
|
|
networkConnection2.Send(11, peerListMessage);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000358 RID: 856 RVA: 0x000129EC File Offset: 0x00010BEC
|
|
private void OnPeerClientAuthority(NetworkMessage netMsg)
|
|
{
|
|
PeerAuthorityMessage peerAuthorityMessage = netMsg.ReadMessage<PeerAuthorityMessage>();
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("OnPeerClientAuthority for netId:" + peerAuthorityMessage.netId);
|
|
}
|
|
if (this.m_Peers != null)
|
|
{
|
|
for (int i = 0; i < this.m_Peers.Length; i++)
|
|
{
|
|
PeerInfoMessage peerInfoMessage = this.m_Peers[i];
|
|
if (peerInfoMessage.connectionId == peerAuthorityMessage.connectionId)
|
|
{
|
|
if (peerInfoMessage.playerIds == null)
|
|
{
|
|
peerInfoMessage.playerIds = new PeerInfoPlayer[0];
|
|
}
|
|
if (peerAuthorityMessage.authorityState)
|
|
{
|
|
for (int j = 0; j < peerInfoMessage.playerIds.Length; j++)
|
|
{
|
|
if (peerInfoMessage.playerIds[j].netId == peerAuthorityMessage.netId)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
PeerInfoPlayer peerInfoPlayer = default(PeerInfoPlayer);
|
|
peerInfoPlayer.netId = peerAuthorityMessage.netId;
|
|
peerInfoPlayer.playerControllerId = -1;
|
|
peerInfoMessage.playerIds = new List<PeerInfoPlayer>(peerInfoMessage.playerIds) { peerInfoPlayer }.ToArray();
|
|
}
|
|
else
|
|
{
|
|
for (int k = 0; k < peerInfoMessage.playerIds.Length; k++)
|
|
{
|
|
if (peerInfoMessage.playerIds[k].netId == peerAuthorityMessage.netId)
|
|
{
|
|
List<PeerInfoPlayer> list = new List<PeerInfoPlayer>(peerInfoMessage.playerIds);
|
|
list.RemoveAt(k);
|
|
peerInfoMessage.playerIds = list.ToArray();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
GameObject gameObject = ClientScene.FindLocalObject(peerAuthorityMessage.netId);
|
|
this.OnAuthorityUpdated(gameObject, peerAuthorityMessage.connectionId, peerAuthorityMessage.authorityState);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000359 RID: 857 RVA: 0x00012BAC File Offset: 0x00010DAC
|
|
private void OnPeerInfo(NetworkMessage netMsg)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("OnPeerInfo");
|
|
}
|
|
netMsg.ReadMessage<PeerListMessage>(this.m_PeerListMessage);
|
|
this.m_Peers = this.m_PeerListMessage.peers;
|
|
this.m_OldServerConnectionId = this.m_PeerListMessage.oldServerConnectionId;
|
|
for (int i = 0; i < this.m_Peers.Length; i++)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log(string.Concat(new object[]
|
|
{
|
|
"peer conn ",
|
|
this.m_Peers[i].connectionId,
|
|
" your conn ",
|
|
this.m_PeerListMessage.oldServerConnectionId
|
|
}));
|
|
}
|
|
if (this.m_Peers[i].connectionId == this.m_PeerListMessage.oldServerConnectionId)
|
|
{
|
|
this.m_Peers[i].isYou = true;
|
|
break;
|
|
}
|
|
}
|
|
this.OnPeersUpdated(this.m_PeerListMessage);
|
|
}
|
|
|
|
// Token: 0x0600035A RID: 858 RVA: 0x00012CAC File Offset: 0x00010EAC
|
|
private void OnServerReconnectPlayerMessage(NetworkMessage netMsg)
|
|
{
|
|
ReconnectMessage reconnectMessage = netMsg.ReadMessage<ReconnectMessage>();
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log(string.Concat(new object[] { "OnReconnectMessage: connId=", reconnectMessage.oldConnectionId, " playerControllerId:", reconnectMessage.playerControllerId, " netId:", reconnectMessage.netId }));
|
|
}
|
|
GameObject gameObject = this.FindPendingPlayer(reconnectMessage.oldConnectionId, reconnectMessage.netId, reconnectMessage.playerControllerId);
|
|
if (gameObject == null)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError(string.Concat(new object[] { "OnReconnectMessage connId=", reconnectMessage.oldConnectionId, " player null for netId:", reconnectMessage.netId, " msg.playerControllerId:", reconnectMessage.playerControllerId }));
|
|
}
|
|
}
|
|
else if (gameObject.activeSelf)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("OnReconnectMessage connId=" + reconnectMessage.oldConnectionId + " player already active?");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("OnReconnectMessage: player=" + gameObject);
|
|
}
|
|
NetworkReader networkReader = null;
|
|
if (reconnectMessage.msgSize != 0)
|
|
{
|
|
networkReader = new NetworkReader(reconnectMessage.msgData);
|
|
}
|
|
if (reconnectMessage.playerControllerId != -1)
|
|
{
|
|
if (networkReader == null)
|
|
{
|
|
this.OnServerReconnectPlayer(netMsg.conn, gameObject, reconnectMessage.oldConnectionId, reconnectMessage.playerControllerId);
|
|
}
|
|
else
|
|
{
|
|
this.OnServerReconnectPlayer(netMsg.conn, gameObject, reconnectMessage.oldConnectionId, reconnectMessage.playerControllerId, networkReader);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.OnServerReconnectObject(netMsg.conn, gameObject, reconnectMessage.oldConnectionId);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600035B RID: 859 RVA: 0x00012E88 File Offset: 0x00011088
|
|
public bool ReconnectObjectForConnection(NetworkConnection newConnection, GameObject oldObject, int oldConnectionId)
|
|
{
|
|
bool flag;
|
|
if (!NetworkServer.active)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("ReconnectObjectForConnection must have active server");
|
|
}
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log(string.Concat(new object[] { "ReconnectObjectForConnection: oldConnId=", oldConnectionId, " obj=", oldObject, " conn:", newConnection }));
|
|
}
|
|
if (!this.m_PendingPlayers.ContainsKey(oldConnectionId))
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("ReconnectObjectForConnection oldConnId=" + oldConnectionId + " not found.");
|
|
}
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
oldObject.SetActive(true);
|
|
oldObject.GetComponent<NetworkIdentity>().SetNetworkInstanceId(new NetworkInstanceId(0U));
|
|
if (!NetworkServer.SpawnWithClientAuthority(oldObject, newConnection))
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("ReconnectObjectForConnection oldConnId=" + oldConnectionId + " SpawnWithClientAuthority failed.");
|
|
}
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
flag = true;
|
|
}
|
|
}
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x0600035C RID: 860 RVA: 0x00012F9C File Offset: 0x0001119C
|
|
public bool ReconnectPlayerForConnection(NetworkConnection newConnection, GameObject oldPlayer, int oldConnectionId, short playerControllerId)
|
|
{
|
|
bool flag;
|
|
if (!NetworkServer.active)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("ReconnectPlayerForConnection must have active server");
|
|
}
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log(string.Concat(new object[] { "ReconnectPlayerForConnection: oldConnId=", oldConnectionId, " player=", oldPlayer, " conn:", newConnection }));
|
|
}
|
|
if (!this.m_PendingPlayers.ContainsKey(oldConnectionId))
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("ReconnectPlayerForConnection oldConnId=" + oldConnectionId + " not found.");
|
|
}
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
oldPlayer.SetActive(true);
|
|
NetworkServer.Spawn(oldPlayer);
|
|
if (!NetworkServer.AddPlayerForConnection(newConnection, oldPlayer, playerControllerId))
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("ReconnectPlayerForConnection oldConnId=" + oldConnectionId + " AddPlayerForConnection failed.");
|
|
}
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
if (NetworkServer.localClientActive)
|
|
{
|
|
this.SendPeerInfo();
|
|
}
|
|
flag = true;
|
|
}
|
|
}
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x0600035D RID: 861 RVA: 0x000130BC File Offset: 0x000112BC
|
|
public bool LostHostOnClient(NetworkConnection conn)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("NetworkMigrationManager client OnDisconnectedFromHost");
|
|
}
|
|
bool flag;
|
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("LostHostOnClient: Host migration not supported on WebGL");
|
|
}
|
|
flag = false;
|
|
}
|
|
else if (this.m_Client == null)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("NetworkMigrationManager LostHostOnHost client was never initialized.");
|
|
}
|
|
flag = false;
|
|
}
|
|
else if (!this.m_HostMigration)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("NetworkMigrationManager LostHostOnHost migration not enabled.");
|
|
}
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
this.m_DisconnectedFromHost = true;
|
|
this.DisablePlayerObjects();
|
|
byte b;
|
|
NetworkTransport.Disconnect(this.m_Client.hostId, this.m_Client.connection.connectionId, out b);
|
|
if (this.m_OldServerConnectionId != -1)
|
|
{
|
|
NetworkMigrationManager.SceneChangeOption sceneChangeOption;
|
|
this.OnClientDisconnectedFromHost(conn, out sceneChangeOption);
|
|
flag = sceneChangeOption == NetworkMigrationManager.SceneChangeOption.StayInOnlineScene;
|
|
}
|
|
else
|
|
{
|
|
flag = false;
|
|
}
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x0600035E RID: 862 RVA: 0x000131B4 File Offset: 0x000113B4
|
|
public void LostHostOnHost()
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("NetworkMigrationManager LostHostOnHost");
|
|
}
|
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("LostHostOnHost: Host migration not supported on WebGL");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.OnServerHostShutdown();
|
|
if (this.m_Peers == null)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("NetworkMigrationManager LostHostOnHost no peers");
|
|
}
|
|
}
|
|
else if (this.m_Peers.Length != 1)
|
|
{
|
|
this.m_HostWasShutdown = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600035F RID: 863 RVA: 0x00013244 File Offset: 0x00011444
|
|
public bool BecomeNewHost(int port)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("NetworkMigrationManager BecomeNewHost " + this.m_MatchInfo);
|
|
}
|
|
NetworkServer.RegisterHandler(47, new NetworkMessageDelegate(this.OnServerReconnectPlayerMessage));
|
|
NetworkClient networkClient = NetworkServer.BecomeHost(this.m_Client, port, this.m_MatchInfo, this.oldServerConnectionId, this.peers);
|
|
bool flag;
|
|
if (networkClient != null)
|
|
{
|
|
if (NetworkManager.singleton != null)
|
|
{
|
|
NetworkManager.singleton.RegisterServerMessages();
|
|
NetworkManager.singleton.UseExternalClient(networkClient);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("MigrationManager BecomeNewHost - No NetworkManager.");
|
|
}
|
|
networkClient.RegisterHandlerSafe(11, new NetworkMessageDelegate(this.OnPeerInfo));
|
|
this.RemovePendingPlayer(this.m_OldServerConnectionId);
|
|
this.Reset(-1);
|
|
this.SendPeerInfo();
|
|
flag = true;
|
|
}
|
|
else
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("NetworkServer.BecomeHost failed");
|
|
}
|
|
flag = false;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x06000360 RID: 864 RVA: 0x00013337 File Offset: 0x00011537
|
|
protected virtual void OnClientDisconnectedFromHost(NetworkConnection conn, out NetworkMigrationManager.SceneChangeOption sceneChange)
|
|
{
|
|
sceneChange = NetworkMigrationManager.SceneChangeOption.StayInOnlineScene;
|
|
}
|
|
|
|
// Token: 0x06000361 RID: 865 RVA: 0x0001333D File Offset: 0x0001153D
|
|
protected virtual void OnServerHostShutdown()
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000362 RID: 866 RVA: 0x00013340 File Offset: 0x00011540
|
|
protected virtual void OnServerReconnectPlayer(NetworkConnection newConnection, GameObject oldPlayer, int oldConnectionId, short playerControllerId)
|
|
{
|
|
this.ReconnectPlayerForConnection(newConnection, oldPlayer, oldConnectionId, playerControllerId);
|
|
}
|
|
|
|
// Token: 0x06000363 RID: 867 RVA: 0x0001334F File Offset: 0x0001154F
|
|
protected virtual void OnServerReconnectPlayer(NetworkConnection newConnection, GameObject oldPlayer, int oldConnectionId, short playerControllerId, NetworkReader extraMessageReader)
|
|
{
|
|
this.ReconnectPlayerForConnection(newConnection, oldPlayer, oldConnectionId, playerControllerId);
|
|
}
|
|
|
|
// Token: 0x06000364 RID: 868 RVA: 0x0001335E File Offset: 0x0001155E
|
|
protected virtual void OnServerReconnectObject(NetworkConnection newConnection, GameObject oldObject, int oldConnectionId)
|
|
{
|
|
this.ReconnectObjectForConnection(newConnection, oldObject, oldConnectionId);
|
|
}
|
|
|
|
// Token: 0x06000365 RID: 869 RVA: 0x0001336B File Offset: 0x0001156B
|
|
protected virtual void OnPeersUpdated(PeerListMessage peers)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("NetworkMigrationManager NumPeers " + peers.peers.Length);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000366 RID: 870 RVA: 0x00013398 File Offset: 0x00011598
|
|
protected virtual void OnAuthorityUpdated(GameObject go, int connectionId, bool authorityState)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log(string.Concat(new object[] { "NetworkMigrationManager OnAuthorityUpdated for ", go, " conn:", connectionId, " state:", authorityState }));
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000367 RID: 871 RVA: 0x000133F0 File Offset: 0x000115F0
|
|
public virtual bool FindNewHost(out PeerInfoMessage newHostInfo, out bool youAreNewHost)
|
|
{
|
|
bool flag;
|
|
if (this.m_Peers == null)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("NetworkMigrationManager FindLowestHost no peers");
|
|
}
|
|
newHostInfo = null;
|
|
youAreNewHost = false;
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("NetworkMigrationManager FindLowestHost");
|
|
}
|
|
newHostInfo = new PeerInfoMessage();
|
|
newHostInfo.connectionId = 50000;
|
|
newHostInfo.address = "";
|
|
newHostInfo.port = 0;
|
|
int num = -1;
|
|
youAreNewHost = false;
|
|
if (this.m_Peers == null)
|
|
{
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < this.m_Peers.Length; i++)
|
|
{
|
|
PeerInfoMessage peerInfoMessage = this.m_Peers[i];
|
|
if (peerInfoMessage.connectionId != 0)
|
|
{
|
|
if (!peerInfoMessage.isHost)
|
|
{
|
|
if (peerInfoMessage.isYou)
|
|
{
|
|
num = peerInfoMessage.connectionId;
|
|
}
|
|
if (peerInfoMessage.connectionId < newHostInfo.connectionId)
|
|
{
|
|
newHostInfo = peerInfoMessage;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (newHostInfo.connectionId == 50000)
|
|
{
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
if (newHostInfo.connectionId == num)
|
|
{
|
|
youAreNewHost = true;
|
|
}
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("FindNewHost new host is " + newHostInfo.address);
|
|
}
|
|
flag = true;
|
|
}
|
|
}
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x06000368 RID: 872 RVA: 0x00013548 File Offset: 0x00011748
|
|
private void OnGUIHost()
|
|
{
|
|
int num = this.m_OffsetY;
|
|
GUI.Label(new Rect((float)this.m_OffsetX, (float)num, 200f, 40f), "Host Was Shutdown ID(" + this.m_OldServerConnectionId + ")");
|
|
num += 25;
|
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
|
{
|
|
GUI.Label(new Rect((float)this.m_OffsetX, (float)num, 200f, 40f), "Host Migration not supported for WebGL");
|
|
}
|
|
else
|
|
{
|
|
if (this.m_WaitingReconnectToNewHost)
|
|
{
|
|
if (GUI.Button(new Rect((float)this.m_OffsetX, (float)num, 200f, 20f), "Reconnect as Client"))
|
|
{
|
|
this.Reset(0);
|
|
if (NetworkManager.singleton != null)
|
|
{
|
|
NetworkManager.singleton.networkAddress = GUI.TextField(new Rect((float)(this.m_OffsetX + 100), (float)num, 95f, 20f), NetworkManager.singleton.networkAddress);
|
|
NetworkManager.singleton.StartClient();
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("MigrationManager Old Host Reconnect - No NetworkManager.");
|
|
}
|
|
}
|
|
num += 25;
|
|
}
|
|
else
|
|
{
|
|
if (GUI.Button(new Rect((float)this.m_OffsetX, (float)num, 200f, 20f), "Pick New Host"))
|
|
{
|
|
bool flag;
|
|
if (this.FindNewHost(out this.m_NewHostInfo, out flag))
|
|
{
|
|
this.m_NewHostAddress = this.m_NewHostInfo.address;
|
|
if (flag)
|
|
{
|
|
Debug.LogWarning("MigrationManager FindNewHost - new host is self?");
|
|
}
|
|
else
|
|
{
|
|
this.m_WaitingReconnectToNewHost = true;
|
|
}
|
|
}
|
|
}
|
|
num += 25;
|
|
}
|
|
if (GUI.Button(new Rect((float)this.m_OffsetX, (float)num, 200f, 20f), "Leave Game"))
|
|
{
|
|
if (NetworkManager.singleton != null)
|
|
{
|
|
NetworkManager.singleton.SetupMigrationManager(null);
|
|
NetworkManager.singleton.StopHost();
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("MigrationManager Old Host LeaveGame - No NetworkManager.");
|
|
}
|
|
this.Reset(-1);
|
|
}
|
|
num += 25;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000369 RID: 873 RVA: 0x0001375C File Offset: 0x0001195C
|
|
private void OnGUIClient()
|
|
{
|
|
int num = this.m_OffsetY;
|
|
GUI.Label(new Rect((float)this.m_OffsetX, (float)num, 200f, 40f), "Lost Connection To Host ID(" + this.m_OldServerConnectionId + ")");
|
|
num += 25;
|
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
|
{
|
|
GUI.Label(new Rect((float)this.m_OffsetX, (float)num, 200f, 40f), "Host Migration not supported for WebGL");
|
|
}
|
|
else
|
|
{
|
|
if (this.m_WaitingToBecomeNewHost)
|
|
{
|
|
GUI.Label(new Rect((float)this.m_OffsetX, (float)num, 200f, 40f), "You are the new host");
|
|
num += 25;
|
|
if (GUI.Button(new Rect((float)this.m_OffsetX, (float)num, 200f, 20f), "Start As Host"))
|
|
{
|
|
if (NetworkManager.singleton != null)
|
|
{
|
|
this.BecomeNewHost(NetworkManager.singleton.networkPort);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("MigrationManager Client BecomeNewHost - No NetworkManager.");
|
|
}
|
|
}
|
|
num += 25;
|
|
}
|
|
else if (this.m_WaitingReconnectToNewHost)
|
|
{
|
|
GUI.Label(new Rect((float)this.m_OffsetX, (float)num, 200f, 40f), "New host is " + this.m_NewHostAddress);
|
|
num += 25;
|
|
if (GUI.Button(new Rect((float)this.m_OffsetX, (float)num, 200f, 20f), "Reconnect To New Host"))
|
|
{
|
|
this.Reset(this.m_OldServerConnectionId);
|
|
if (NetworkManager.singleton != null)
|
|
{
|
|
NetworkManager.singleton.networkAddress = this.m_NewHostAddress;
|
|
NetworkManager.singleton.client.ReconnectToNewHost(this.m_NewHostAddress, NetworkManager.singleton.networkPort);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("MigrationManager Client reconnect - No NetworkManager.");
|
|
}
|
|
}
|
|
num += 25;
|
|
}
|
|
else
|
|
{
|
|
if (GUI.Button(new Rect((float)this.m_OffsetX, (float)num, 200f, 20f), "Pick New Host"))
|
|
{
|
|
bool flag;
|
|
if (this.FindNewHost(out this.m_NewHostInfo, out flag))
|
|
{
|
|
this.m_NewHostAddress = this.m_NewHostInfo.address;
|
|
if (flag)
|
|
{
|
|
this.m_WaitingToBecomeNewHost = true;
|
|
}
|
|
else
|
|
{
|
|
this.m_WaitingReconnectToNewHost = true;
|
|
}
|
|
}
|
|
}
|
|
num += 25;
|
|
}
|
|
if (GUI.Button(new Rect((float)this.m_OffsetX, (float)num, 200f, 20f), "Leave Game"))
|
|
{
|
|
if (NetworkManager.singleton != null)
|
|
{
|
|
NetworkManager.singleton.SetupMigrationManager(null);
|
|
NetworkManager.singleton.StopHost();
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("MigrationManager Client LeaveGame - No NetworkManager.");
|
|
}
|
|
this.Reset(-1);
|
|
}
|
|
num += 25;
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600036A RID: 874 RVA: 0x00013A30 File Offset: 0x00011C30
|
|
private void OnGUI()
|
|
{
|
|
if (this.m_ShowGUI)
|
|
{
|
|
if (this.m_HostWasShutdown)
|
|
{
|
|
this.OnGUIHost();
|
|
}
|
|
else if (this.m_DisconnectedFromHost && this.m_OldServerConnectionId != -1)
|
|
{
|
|
this.OnGUIClient();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0400018F RID: 399
|
|
[SerializeField]
|
|
private bool m_HostMigration = true;
|
|
|
|
// Token: 0x04000190 RID: 400
|
|
[SerializeField]
|
|
private bool m_ShowGUI = true;
|
|
|
|
// Token: 0x04000191 RID: 401
|
|
[SerializeField]
|
|
private int m_OffsetX = 10;
|
|
|
|
// Token: 0x04000192 RID: 402
|
|
[SerializeField]
|
|
private int m_OffsetY = 300;
|
|
|
|
// Token: 0x04000193 RID: 403
|
|
private NetworkClient m_Client;
|
|
|
|
// Token: 0x04000194 RID: 404
|
|
private bool m_WaitingToBecomeNewHost;
|
|
|
|
// Token: 0x04000195 RID: 405
|
|
private bool m_WaitingReconnectToNewHost;
|
|
|
|
// Token: 0x04000196 RID: 406
|
|
private bool m_DisconnectedFromHost;
|
|
|
|
// Token: 0x04000197 RID: 407
|
|
private bool m_HostWasShutdown;
|
|
|
|
// Token: 0x04000198 RID: 408
|
|
private MatchInfo m_MatchInfo;
|
|
|
|
// Token: 0x04000199 RID: 409
|
|
private int m_OldServerConnectionId = -1;
|
|
|
|
// Token: 0x0400019A RID: 410
|
|
private string m_NewHostAddress;
|
|
|
|
// Token: 0x0400019B RID: 411
|
|
private PeerInfoMessage m_NewHostInfo = new PeerInfoMessage();
|
|
|
|
// Token: 0x0400019C RID: 412
|
|
private PeerListMessage m_PeerListMessage = new PeerListMessage();
|
|
|
|
// Token: 0x0400019D RID: 413
|
|
private PeerInfoMessage[] m_Peers;
|
|
|
|
// Token: 0x0400019E RID: 414
|
|
private Dictionary<int, NetworkMigrationManager.ConnectionPendingPlayers> m_PendingPlayers = new Dictionary<int, NetworkMigrationManager.ConnectionPendingPlayers>();
|
|
|
|
// Token: 0x02000050 RID: 80
|
|
public enum SceneChangeOption
|
|
{
|
|
// Token: 0x040001A0 RID: 416
|
|
StayInOnlineScene,
|
|
// Token: 0x040001A1 RID: 417
|
|
SwitchToOfflineScene
|
|
}
|
|
|
|
// Token: 0x02000051 RID: 81
|
|
public struct PendingPlayerInfo
|
|
{
|
|
// Token: 0x040001A2 RID: 418
|
|
public NetworkInstanceId netId;
|
|
|
|
// Token: 0x040001A3 RID: 419
|
|
public short playerControllerId;
|
|
|
|
// Token: 0x040001A4 RID: 420
|
|
public GameObject obj;
|
|
}
|
|
|
|
// Token: 0x02000052 RID: 82
|
|
public struct ConnectionPendingPlayers
|
|
{
|
|
// Token: 0x040001A5 RID: 421
|
|
public List<NetworkMigrationManager.PendingPlayerInfo> players;
|
|
}
|
|
}
|
|
}
|