2238 lines
65 KiB
C#
2238 lines
65 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using UnityEngine.Networking.Match;
|
|
using UnityEngine.Networking.NetworkSystem;
|
|
using UnityEngine.Networking.Types;
|
|
|
|
namespace UnityEngine.Networking
|
|
{
|
|
// Token: 0x02000058 RID: 88
|
|
public sealed class NetworkServer
|
|
{
|
|
// Token: 0x060003BE RID: 958 RVA: 0x0001565C File Offset: 0x0001385C
|
|
private NetworkServer()
|
|
{
|
|
NetworkTransport.Init();
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("NetworkServer Created version " + Version.Current);
|
|
}
|
|
this.m_RemoveList = new HashSet<NetworkInstanceId>();
|
|
this.m_ExternalConnections = new HashSet<int>();
|
|
this.m_NetworkScene = new NetworkScene();
|
|
this.m_SimpleServerSimple = new NetworkServer.ServerSimpleWrapper(this);
|
|
}
|
|
|
|
// Token: 0x1700009F RID: 159
|
|
// (get) Token: 0x060003BF RID: 959 RVA: 0x000156E0 File Offset: 0x000138E0
|
|
public static List<NetworkConnection> localConnections
|
|
{
|
|
get
|
|
{
|
|
return NetworkServer.instance.m_LocalConnectionsFakeList;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000A0 RID: 160
|
|
// (get) Token: 0x060003C0 RID: 960 RVA: 0x00015700 File Offset: 0x00013900
|
|
public static int listenPort
|
|
{
|
|
get
|
|
{
|
|
return NetworkServer.instance.m_SimpleServerSimple.listenPort;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000A1 RID: 161
|
|
// (get) Token: 0x060003C1 RID: 961 RVA: 0x00015724 File Offset: 0x00013924
|
|
public static int serverHostId
|
|
{
|
|
get
|
|
{
|
|
return NetworkServer.instance.m_SimpleServerSimple.serverHostId;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000A2 RID: 162
|
|
// (get) Token: 0x060003C2 RID: 962 RVA: 0x00015748 File Offset: 0x00013948
|
|
public static ReadOnlyCollection<NetworkConnection> connections
|
|
{
|
|
get
|
|
{
|
|
return NetworkServer.instance.m_SimpleServerSimple.connections;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000A3 RID: 163
|
|
// (get) Token: 0x060003C3 RID: 963 RVA: 0x0001576C File Offset: 0x0001396C
|
|
public static Dictionary<short, NetworkMessageDelegate> handlers
|
|
{
|
|
get
|
|
{
|
|
return NetworkServer.instance.m_SimpleServerSimple.handlers;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000A4 RID: 164
|
|
// (get) Token: 0x060003C4 RID: 964 RVA: 0x00015790 File Offset: 0x00013990
|
|
public static HostTopology hostTopology
|
|
{
|
|
get
|
|
{
|
|
return NetworkServer.instance.m_SimpleServerSimple.hostTopology;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000A5 RID: 165
|
|
// (get) Token: 0x060003C5 RID: 965 RVA: 0x000157B4 File Offset: 0x000139B4
|
|
public static Dictionary<NetworkInstanceId, NetworkIdentity> objects
|
|
{
|
|
get
|
|
{
|
|
return NetworkServer.instance.m_NetworkScene.localObjects;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000A6 RID: 166
|
|
// (get) Token: 0x060003C6 RID: 966 RVA: 0x000157D8 File Offset: 0x000139D8
|
|
// (set) Token: 0x060003C7 RID: 967 RVA: 0x000157EE File Offset: 0x000139EE
|
|
[Obsolete("Moved to NetworkMigrationManager")]
|
|
public static bool sendPeerInfo
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
set
|
|
{
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000A7 RID: 167
|
|
// (get) Token: 0x060003C8 RID: 968 RVA: 0x000157F4 File Offset: 0x000139F4
|
|
// (set) Token: 0x060003C9 RID: 969 RVA: 0x0001580E File Offset: 0x00013A0E
|
|
public static bool dontListen
|
|
{
|
|
get
|
|
{
|
|
return NetworkServer.m_DontListen;
|
|
}
|
|
set
|
|
{
|
|
NetworkServer.m_DontListen = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000A8 RID: 168
|
|
// (get) Token: 0x060003CA RID: 970 RVA: 0x00015818 File Offset: 0x00013A18
|
|
// (set) Token: 0x060003CB RID: 971 RVA: 0x0001583C File Offset: 0x00013A3C
|
|
public static bool useWebSockets
|
|
{
|
|
get
|
|
{
|
|
return NetworkServer.instance.m_SimpleServerSimple.useWebSockets;
|
|
}
|
|
set
|
|
{
|
|
NetworkServer.instance.m_SimpleServerSimple.useWebSockets = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000A9 RID: 169
|
|
// (get) Token: 0x060003CC RID: 972 RVA: 0x00015850 File Offset: 0x00013A50
|
|
internal static NetworkServer instance
|
|
{
|
|
get
|
|
{
|
|
if (NetworkServer.s_Instance == null)
|
|
{
|
|
object obj = NetworkServer.s_Sync;
|
|
lock (obj)
|
|
{
|
|
if (NetworkServer.s_Instance == null)
|
|
{
|
|
NetworkServer.s_Instance = new NetworkServer();
|
|
}
|
|
}
|
|
}
|
|
return NetworkServer.s_Instance;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000AA RID: 170
|
|
// (get) Token: 0x060003CD RID: 973 RVA: 0x000158C0 File Offset: 0x00013AC0
|
|
public static bool active
|
|
{
|
|
get
|
|
{
|
|
return NetworkServer.s_Active;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000AB RID: 171
|
|
// (get) Token: 0x060003CE RID: 974 RVA: 0x000158DC File Offset: 0x00013ADC
|
|
public static bool localClientActive
|
|
{
|
|
get
|
|
{
|
|
return NetworkServer.instance.m_LocalClientActive;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000AC RID: 172
|
|
// (get) Token: 0x060003CF RID: 975 RVA: 0x000158FC File Offset: 0x00013AFC
|
|
public static int numChannels
|
|
{
|
|
get
|
|
{
|
|
return NetworkServer.instance.m_SimpleServerSimple.hostTopology.DefaultConfig.ChannelCount;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000AD RID: 173
|
|
// (get) Token: 0x060003D0 RID: 976 RVA: 0x0001592C File Offset: 0x00013B2C
|
|
// (set) Token: 0x060003D1 RID: 977 RVA: 0x0001594B File Offset: 0x00013B4B
|
|
public static float maxDelay
|
|
{
|
|
get
|
|
{
|
|
return NetworkServer.instance.m_MaxDelay;
|
|
}
|
|
set
|
|
{
|
|
NetworkServer.instance.InternalSetMaxDelay(value);
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000AE RID: 174
|
|
// (get) Token: 0x060003D2 RID: 978 RVA: 0x0001595C File Offset: 0x00013B5C
|
|
public static Type networkConnectionClass
|
|
{
|
|
get
|
|
{
|
|
return NetworkServer.instance.m_SimpleServerSimple.networkConnectionClass;
|
|
}
|
|
}
|
|
|
|
// Token: 0x060003D3 RID: 979 RVA: 0x00015980 File Offset: 0x00013B80
|
|
public static void SetNetworkConnectionClass<T>() where T : NetworkConnection
|
|
{
|
|
NetworkServer.instance.m_SimpleServerSimple.SetNetworkConnectionClass<T>();
|
|
}
|
|
|
|
// Token: 0x060003D4 RID: 980 RVA: 0x00015994 File Offset: 0x00013B94
|
|
public static bool Configure(ConnectionConfig config, int maxConnections)
|
|
{
|
|
return NetworkServer.instance.m_SimpleServerSimple.Configure(config, maxConnections);
|
|
}
|
|
|
|
// Token: 0x060003D5 RID: 981 RVA: 0x000159BC File Offset: 0x00013BBC
|
|
public static bool Configure(HostTopology topology)
|
|
{
|
|
return NetworkServer.instance.m_SimpleServerSimple.Configure(topology);
|
|
}
|
|
|
|
// Token: 0x060003D6 RID: 982 RVA: 0x000159E1 File Offset: 0x00013BE1
|
|
public static void Reset()
|
|
{
|
|
NetworkTransport.Shutdown();
|
|
NetworkTransport.Init();
|
|
NetworkServer.s_Instance = null;
|
|
NetworkServer.s_Active = false;
|
|
}
|
|
|
|
// Token: 0x060003D7 RID: 983 RVA: 0x000159FC File Offset: 0x00013BFC
|
|
public static void Shutdown()
|
|
{
|
|
if (NetworkServer.s_Instance != null)
|
|
{
|
|
NetworkServer.s_Instance.InternalDisconnectAll();
|
|
if (!NetworkServer.m_DontListen)
|
|
{
|
|
NetworkServer.s_Instance.m_SimpleServerSimple.Stop();
|
|
}
|
|
NetworkServer.s_Instance = null;
|
|
}
|
|
NetworkServer.m_DontListen = false;
|
|
NetworkServer.s_Active = false;
|
|
}
|
|
|
|
// Token: 0x060003D8 RID: 984 RVA: 0x00015A5C File Offset: 0x00013C5C
|
|
public static bool Listen(MatchInfo matchInfo, int listenPort)
|
|
{
|
|
bool flag;
|
|
if (!matchInfo.usingRelay)
|
|
{
|
|
flag = NetworkServer.instance.InternalListen(null, listenPort);
|
|
}
|
|
else
|
|
{
|
|
NetworkServer.instance.InternalListenRelay(matchInfo.address, matchInfo.port, matchInfo.networkId, Utility.GetSourceID(), matchInfo.nodeId);
|
|
flag = true;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x060003D9 RID: 985 RVA: 0x00015AB8 File Offset: 0x00013CB8
|
|
internal void RegisterMessageHandlers()
|
|
{
|
|
this.m_SimpleServerSimple.RegisterHandlerSafe(35, new NetworkMessageDelegate(NetworkServer.OnClientReadyMessage));
|
|
this.m_SimpleServerSimple.RegisterHandlerSafe(5, new NetworkMessageDelegate(NetworkServer.OnCommandMessage));
|
|
this.m_SimpleServerSimple.RegisterHandlerSafe(6, new NetworkMessageDelegate(NetworkTransform.HandleTransform));
|
|
this.m_SimpleServerSimple.RegisterHandlerSafe(16, new NetworkMessageDelegate(NetworkTransformChild.HandleChildTransform));
|
|
this.m_SimpleServerSimple.RegisterHandlerSafe(38, new NetworkMessageDelegate(NetworkServer.OnRemovePlayerMessage));
|
|
this.m_SimpleServerSimple.RegisterHandlerSafe(40, new NetworkMessageDelegate(NetworkAnimator.OnAnimationServerMessage));
|
|
this.m_SimpleServerSimple.RegisterHandlerSafe(41, new NetworkMessageDelegate(NetworkAnimator.OnAnimationParametersServerMessage));
|
|
this.m_SimpleServerSimple.RegisterHandlerSafe(42, new NetworkMessageDelegate(NetworkAnimator.OnAnimationTriggerServerMessage));
|
|
this.m_SimpleServerSimple.RegisterHandlerSafe(17, new NetworkMessageDelegate(NetworkConnection.OnFragment));
|
|
NetworkServer.maxPacketSize = NetworkServer.hostTopology.DefaultConfig.PacketSize;
|
|
}
|
|
|
|
// Token: 0x060003DA RID: 986 RVA: 0x00015C52 File Offset: 0x00013E52
|
|
public static void ListenRelay(string relayIp, int relayPort, NetworkID netGuid, SourceID sourceId, NodeID nodeId)
|
|
{
|
|
NetworkServer.instance.InternalListenRelay(relayIp, relayPort, netGuid, sourceId, nodeId);
|
|
}
|
|
|
|
// Token: 0x060003DB RID: 987 RVA: 0x00015C65 File Offset: 0x00013E65
|
|
private void InternalListenRelay(string relayIp, int relayPort, NetworkID netGuid, SourceID sourceId, NodeID nodeId)
|
|
{
|
|
this.m_SimpleServerSimple.ListenRelay(relayIp, relayPort, netGuid, sourceId, nodeId);
|
|
NetworkServer.s_Active = true;
|
|
this.RegisterMessageHandlers();
|
|
}
|
|
|
|
// Token: 0x060003DC RID: 988 RVA: 0x00015C88 File Offset: 0x00013E88
|
|
public static bool Listen(int serverPort)
|
|
{
|
|
return NetworkServer.instance.InternalListen(null, serverPort);
|
|
}
|
|
|
|
// Token: 0x060003DD RID: 989 RVA: 0x00015CAC File Offset: 0x00013EAC
|
|
public static bool Listen(string ipAddress, int serverPort)
|
|
{
|
|
return NetworkServer.instance.InternalListen(ipAddress, serverPort);
|
|
}
|
|
|
|
// Token: 0x060003DE RID: 990 RVA: 0x00015CD0 File Offset: 0x00013ED0
|
|
internal bool InternalListen(string ipAddress, int serverPort)
|
|
{
|
|
if (NetworkServer.m_DontListen)
|
|
{
|
|
this.m_SimpleServerSimple.Initialize();
|
|
}
|
|
else if (!this.m_SimpleServerSimple.Listen(ipAddress, serverPort))
|
|
{
|
|
return false;
|
|
}
|
|
NetworkServer.maxPacketSize = NetworkServer.hostTopology.DefaultConfig.PacketSize;
|
|
NetworkServer.s_Active = true;
|
|
this.RegisterMessageHandlers();
|
|
return true;
|
|
}
|
|
|
|
// Token: 0x060003DF RID: 991 RVA: 0x00015D40 File Offset: 0x00013F40
|
|
public static NetworkClient BecomeHost(NetworkClient oldClient, int port, MatchInfo matchInfo, int oldConnectionId, PeerInfoMessage[] peers)
|
|
{
|
|
return NetworkServer.instance.BecomeHostInternal(oldClient, port, matchInfo, oldConnectionId, peers);
|
|
}
|
|
|
|
// Token: 0x060003E0 RID: 992 RVA: 0x00015D68 File Offset: 0x00013F68
|
|
internal NetworkClient BecomeHostInternal(NetworkClient oldClient, int port, MatchInfo matchInfo, int oldConnectionId, PeerInfoMessage[] peers)
|
|
{
|
|
NetworkClient networkClient;
|
|
if (NetworkServer.s_Active)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("BecomeHost already a server.");
|
|
}
|
|
networkClient = null;
|
|
}
|
|
else if (!NetworkClient.active)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("BecomeHost NetworkClient not active.");
|
|
}
|
|
networkClient = null;
|
|
}
|
|
else
|
|
{
|
|
NetworkServer.Configure(NetworkServer.hostTopology);
|
|
if (matchInfo == null)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("BecomeHost Listen on " + port);
|
|
}
|
|
if (!NetworkServer.Listen(port))
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("BecomeHost bind failed.");
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("BecomeHost match:" + matchInfo.networkId);
|
|
}
|
|
NetworkServer.ListenRelay(matchInfo.address, matchInfo.port, matchInfo.networkId, Utility.GetSourceID(), matchInfo.nodeId);
|
|
}
|
|
foreach (NetworkIdentity networkIdentity in ClientScene.objects.Values)
|
|
{
|
|
if (!(networkIdentity == null) && !(networkIdentity.gameObject == null))
|
|
{
|
|
NetworkIdentity.AddNetworkId(networkIdentity.netId.Value);
|
|
this.m_NetworkScene.SetLocalObject(networkIdentity.netId, networkIdentity.gameObject, false, false);
|
|
networkIdentity.OnStartServer(true);
|
|
}
|
|
}
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("NetworkServer BecomeHost done. oldConnectionId:" + oldConnectionId);
|
|
}
|
|
this.RegisterMessageHandlers();
|
|
if (!NetworkClient.RemoveClient(oldClient))
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("BecomeHost failed to remove client");
|
|
}
|
|
}
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("BecomeHost localClient ready");
|
|
}
|
|
NetworkClient networkClient2 = ClientScene.ReconnectLocalServer();
|
|
ClientScene.Ready(networkClient2.connection);
|
|
ClientScene.SetReconnectId(oldConnectionId, peers);
|
|
ClientScene.AddPlayer(ClientScene.readyConnection, 0);
|
|
networkClient = networkClient2;
|
|
}
|
|
return networkClient;
|
|
}
|
|
|
|
// Token: 0x060003E1 RID: 993 RVA: 0x00015FAC File Offset: 0x000141AC
|
|
private void InternalSetMaxDelay(float seconds)
|
|
{
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null)
|
|
{
|
|
networkConnection.SetMaxDelay(seconds);
|
|
}
|
|
}
|
|
this.m_MaxDelay = seconds;
|
|
}
|
|
|
|
// Token: 0x060003E2 RID: 994 RVA: 0x00015FF8 File Offset: 0x000141F8
|
|
internal int AddLocalClient(LocalClient localClient)
|
|
{
|
|
int num;
|
|
if (this.m_LocalConnectionsFakeList.Count != 0)
|
|
{
|
|
Debug.LogError("Local Connection already exists");
|
|
num = -1;
|
|
}
|
|
else
|
|
{
|
|
this.m_LocalConnection = new ULocalConnectionToClient(localClient);
|
|
this.m_LocalConnection.connectionId = 0;
|
|
this.m_SimpleServerSimple.SetConnectionAtIndex(this.m_LocalConnection);
|
|
this.m_LocalConnectionsFakeList.Add(this.m_LocalConnection);
|
|
this.m_LocalConnection.InvokeHandlerNoData(32);
|
|
num = 0;
|
|
}
|
|
return num;
|
|
}
|
|
|
|
// Token: 0x060003E3 RID: 995 RVA: 0x0001607C File Offset: 0x0001427C
|
|
internal void RemoveLocalClient(NetworkConnection localClientConnection)
|
|
{
|
|
for (int i = 0; i < this.m_LocalConnectionsFakeList.Count; i++)
|
|
{
|
|
if (this.m_LocalConnectionsFakeList[i].connectionId == localClientConnection.connectionId)
|
|
{
|
|
this.m_LocalConnectionsFakeList.RemoveAt(i);
|
|
break;
|
|
}
|
|
}
|
|
if (this.m_LocalConnection != null)
|
|
{
|
|
this.m_LocalConnection.Disconnect();
|
|
this.m_LocalConnection.Dispose();
|
|
this.m_LocalConnection = null;
|
|
}
|
|
this.m_LocalClientActive = false;
|
|
this.m_SimpleServerSimple.RemoveConnectionAtIndex(0);
|
|
}
|
|
|
|
// Token: 0x060003E4 RID: 996 RVA: 0x00016114 File Offset: 0x00014314
|
|
internal void SetLocalObjectOnServer(NetworkInstanceId netId, GameObject obj)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log(string.Concat(new object[] { "SetLocalObjectOnServer ", netId, " ", obj }));
|
|
}
|
|
this.m_NetworkScene.SetLocalObject(netId, obj, false, true);
|
|
}
|
|
|
|
// Token: 0x060003E5 RID: 997 RVA: 0x0001616C File Offset: 0x0001436C
|
|
internal void ActivateLocalClientScene()
|
|
{
|
|
if (!this.m_LocalClientActive)
|
|
{
|
|
this.m_LocalClientActive = true;
|
|
foreach (NetworkIdentity networkIdentity in NetworkServer.objects.Values)
|
|
{
|
|
if (!networkIdentity.isClient)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log(string.Concat(new object[] { "ActivateClientScene ", networkIdentity.netId, " ", networkIdentity.gameObject }));
|
|
}
|
|
ClientScene.SetLocalObject(networkIdentity.netId, networkIdentity.gameObject);
|
|
networkIdentity.OnStartClient();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x060003E6 RID: 998 RVA: 0x00016248 File Offset: 0x00014448
|
|
public static bool SendToAll(short msgType, MessageBase msg)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("Server.SendToAll msgType:" + msgType);
|
|
}
|
|
bool flag = true;
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null)
|
|
{
|
|
flag &= networkConnection.Send(msgType, msg);
|
|
}
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x060003E7 RID: 999 RVA: 0x000162BC File Offset: 0x000144BC
|
|
private static bool SendToObservers(GameObject contextObj, short msgType, MessageBase msg)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("Server.SendToObservers id:" + msgType);
|
|
}
|
|
bool flag = true;
|
|
NetworkIdentity component = contextObj.GetComponent<NetworkIdentity>();
|
|
bool flag2;
|
|
if (component == null || component.observers == null)
|
|
{
|
|
flag2 = false;
|
|
}
|
|
else
|
|
{
|
|
int count = component.observers.Count;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
NetworkConnection networkConnection = component.observers[i];
|
|
flag &= networkConnection.Send(msgType, msg);
|
|
}
|
|
flag2 = flag;
|
|
}
|
|
return flag2;
|
|
}
|
|
|
|
// Token: 0x060003E8 RID: 1000 RVA: 0x0001635C File Offset: 0x0001455C
|
|
public static bool SendToReady(GameObject contextObj, short msgType, MessageBase msg)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("Server.SendToReady id:" + msgType);
|
|
}
|
|
bool flag;
|
|
if (contextObj == null)
|
|
{
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null && networkConnection.isReady)
|
|
{
|
|
networkConnection.Send(msgType, msg);
|
|
}
|
|
}
|
|
flag = true;
|
|
}
|
|
else
|
|
{
|
|
bool flag2 = true;
|
|
NetworkIdentity component = contextObj.GetComponent<NetworkIdentity>();
|
|
if (component == null || component.observers == null)
|
|
{
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
int count = component.observers.Count;
|
|
for (int j = 0; j < count; j++)
|
|
{
|
|
NetworkConnection networkConnection2 = component.observers[j];
|
|
if (networkConnection2.isReady)
|
|
{
|
|
flag2 &= networkConnection2.Send(msgType, msg);
|
|
}
|
|
}
|
|
flag = flag2;
|
|
}
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x060003E9 RID: 1001 RVA: 0x0001646C File Offset: 0x0001466C
|
|
public static void SendWriterToReady(GameObject contextObj, NetworkWriter writer, int channelId)
|
|
{
|
|
if (writer.AsArraySegment().Count > 32767)
|
|
{
|
|
throw new UnityException("NetworkWriter used buffer is too big!");
|
|
}
|
|
NetworkServer.SendBytesToReady(contextObj, writer.AsArraySegment().Array, writer.AsArraySegment().Count, channelId);
|
|
}
|
|
|
|
// Token: 0x060003EA RID: 1002 RVA: 0x000164C4 File Offset: 0x000146C4
|
|
public static void SendBytesToReady(GameObject contextObj, byte[] buffer, int numBytes, int channelId)
|
|
{
|
|
if (contextObj == null)
|
|
{
|
|
bool flag = true;
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null && networkConnection.isReady)
|
|
{
|
|
if (!networkConnection.SendBytes(buffer, numBytes, channelId))
|
|
{
|
|
flag = false;
|
|
}
|
|
}
|
|
}
|
|
if (!flag)
|
|
{
|
|
if (LogFilter.logWarn)
|
|
{
|
|
Debug.LogWarning("SendBytesToReady failed");
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NetworkIdentity component = contextObj.GetComponent<NetworkIdentity>();
|
|
try
|
|
{
|
|
bool flag2 = true;
|
|
int count = component.observers.Count;
|
|
for (int j = 0; j < count; j++)
|
|
{
|
|
NetworkConnection networkConnection2 = component.observers[j];
|
|
if (networkConnection2.isReady)
|
|
{
|
|
if (!networkConnection2.SendBytes(buffer, numBytes, channelId))
|
|
{
|
|
flag2 = false;
|
|
}
|
|
}
|
|
}
|
|
if (!flag2)
|
|
{
|
|
if (LogFilter.logWarn)
|
|
{
|
|
Debug.LogWarning("SendBytesToReady failed for " + contextObj);
|
|
}
|
|
}
|
|
}
|
|
catch (NullReferenceException)
|
|
{
|
|
if (LogFilter.logWarn)
|
|
{
|
|
Debug.LogWarning("SendBytesToReady object " + contextObj + " has not been spawned");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x060003EB RID: 1003 RVA: 0x0001661C File Offset: 0x0001481C
|
|
public static void SendBytesToPlayer(GameObject player, byte[] buffer, int numBytes, int channelId)
|
|
{
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null)
|
|
{
|
|
for (int j = 0; j < networkConnection.playerControllers.Count; j++)
|
|
{
|
|
if (networkConnection.playerControllers[j].IsValid && networkConnection.playerControllers[j].gameObject == player)
|
|
{
|
|
networkConnection.SendBytes(buffer, numBytes, channelId);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x060003EC RID: 1004 RVA: 0x000166C0 File Offset: 0x000148C0
|
|
public static bool SendUnreliableToAll(short msgType, MessageBase msg)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("Server.SendUnreliableToAll msgType:" + msgType);
|
|
}
|
|
bool flag = true;
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null)
|
|
{
|
|
flag &= networkConnection.SendUnreliable(msgType, msg);
|
|
}
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x060003ED RID: 1005 RVA: 0x00016734 File Offset: 0x00014934
|
|
public static bool SendUnreliableToReady(GameObject contextObj, short msgType, MessageBase msg)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("Server.SendUnreliableToReady id:" + msgType);
|
|
}
|
|
bool flag;
|
|
if (contextObj == null)
|
|
{
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null && networkConnection.isReady)
|
|
{
|
|
networkConnection.SendUnreliable(msgType, msg);
|
|
}
|
|
}
|
|
flag = true;
|
|
}
|
|
else
|
|
{
|
|
bool flag2 = true;
|
|
NetworkIdentity component = contextObj.GetComponent<NetworkIdentity>();
|
|
int count = component.observers.Count;
|
|
for (int j = 0; j < count; j++)
|
|
{
|
|
NetworkConnection networkConnection2 = component.observers[j];
|
|
if (networkConnection2.isReady)
|
|
{
|
|
flag2 &= networkConnection2.SendUnreliable(msgType, msg);
|
|
}
|
|
}
|
|
flag = flag2;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x060003EE RID: 1006 RVA: 0x00016824 File Offset: 0x00014A24
|
|
public static bool SendByChannelToAll(short msgType, MessageBase msg, int channelId)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("Server.SendByChannelToAll id:" + msgType);
|
|
}
|
|
bool flag = true;
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null)
|
|
{
|
|
flag &= networkConnection.SendByChannel(msgType, msg, channelId);
|
|
}
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x060003EF RID: 1007 RVA: 0x00016898 File Offset: 0x00014A98
|
|
public static bool SendByChannelToReady(GameObject contextObj, short msgType, MessageBase msg, int channelId)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("Server.SendByChannelToReady msgType:" + msgType);
|
|
}
|
|
bool flag;
|
|
if (contextObj == null)
|
|
{
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null && networkConnection.isReady)
|
|
{
|
|
networkConnection.SendByChannel(msgType, msg, channelId);
|
|
}
|
|
}
|
|
flag = true;
|
|
}
|
|
else
|
|
{
|
|
bool flag2 = true;
|
|
NetworkIdentity component = contextObj.GetComponent<NetworkIdentity>();
|
|
int count = component.observers.Count;
|
|
for (int j = 0; j < count; j++)
|
|
{
|
|
NetworkConnection networkConnection2 = component.observers[j];
|
|
if (networkConnection2.isReady)
|
|
{
|
|
flag2 &= networkConnection2.SendByChannel(msgType, msg, channelId);
|
|
}
|
|
}
|
|
flag = flag2;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x060003F0 RID: 1008 RVA: 0x00016988 File Offset: 0x00014B88
|
|
public static void DisconnectAll()
|
|
{
|
|
NetworkServer.instance.InternalDisconnectAll();
|
|
}
|
|
|
|
// Token: 0x060003F1 RID: 1009 RVA: 0x00016995 File Offset: 0x00014B95
|
|
internal void InternalDisconnectAll()
|
|
{
|
|
this.m_SimpleServerSimple.DisconnectAllConnections();
|
|
if (this.m_LocalConnection != null)
|
|
{
|
|
this.m_LocalConnection.Disconnect();
|
|
this.m_LocalConnection.Dispose();
|
|
this.m_LocalConnection = null;
|
|
}
|
|
this.m_LocalClientActive = false;
|
|
}
|
|
|
|
// Token: 0x060003F2 RID: 1010 RVA: 0x000169D4 File Offset: 0x00014BD4
|
|
internal static void Update()
|
|
{
|
|
if (NetworkServer.s_Instance != null)
|
|
{
|
|
NetworkServer.s_Instance.InternalUpdate();
|
|
}
|
|
}
|
|
|
|
// Token: 0x060003F3 RID: 1011 RVA: 0x000169F0 File Offset: 0x00014BF0
|
|
private void UpdateServerObjects()
|
|
{
|
|
foreach (NetworkIdentity networkIdentity in NetworkServer.objects.Values)
|
|
{
|
|
try
|
|
{
|
|
networkIdentity.UNetUpdate();
|
|
}
|
|
catch (NullReferenceException)
|
|
{
|
|
}
|
|
catch (MissingReferenceException)
|
|
{
|
|
}
|
|
}
|
|
if (this.m_RemoveListCount++ % 100 == 0)
|
|
{
|
|
this.CheckForNullObjects();
|
|
}
|
|
}
|
|
|
|
// Token: 0x060003F4 RID: 1012 RVA: 0x00016AA4 File Offset: 0x00014CA4
|
|
private void CheckForNullObjects()
|
|
{
|
|
foreach (NetworkInstanceId networkInstanceId in NetworkServer.objects.Keys)
|
|
{
|
|
NetworkIdentity networkIdentity = NetworkServer.objects[networkInstanceId];
|
|
if (networkIdentity == null || networkIdentity.gameObject == null)
|
|
{
|
|
this.m_RemoveList.Add(networkInstanceId);
|
|
}
|
|
}
|
|
if (this.m_RemoveList.Count > 0)
|
|
{
|
|
foreach (NetworkInstanceId networkInstanceId2 in this.m_RemoveList)
|
|
{
|
|
NetworkServer.objects.Remove(networkInstanceId2);
|
|
}
|
|
this.m_RemoveList.Clear();
|
|
}
|
|
}
|
|
|
|
// Token: 0x060003F5 RID: 1013 RVA: 0x00016BAC File Offset: 0x00014DAC
|
|
internal void InternalUpdate()
|
|
{
|
|
this.m_SimpleServerSimple.Update();
|
|
if (NetworkServer.m_DontListen)
|
|
{
|
|
this.m_SimpleServerSimple.UpdateConnections();
|
|
}
|
|
this.UpdateServerObjects();
|
|
}
|
|
|
|
// Token: 0x060003F6 RID: 1014 RVA: 0x00016BD8 File Offset: 0x00014DD8
|
|
private void OnConnected(NetworkConnection conn)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("Server accepted client:" + conn.connectionId);
|
|
}
|
|
conn.SetMaxDelay(this.m_MaxDelay);
|
|
conn.InvokeHandlerNoData(32);
|
|
NetworkServer.SendCrc(conn);
|
|
}
|
|
|
|
// Token: 0x060003F7 RID: 1015 RVA: 0x00016C28 File Offset: 0x00014E28
|
|
private void OnDisconnected(NetworkConnection conn)
|
|
{
|
|
conn.InvokeHandlerNoData(33);
|
|
for (int i = 0; i < conn.playerControllers.Count; i++)
|
|
{
|
|
if (conn.playerControllers[i].gameObject != null)
|
|
{
|
|
if (LogFilter.logWarn)
|
|
{
|
|
Debug.LogWarning("Player not destroyed when connection disconnected.");
|
|
}
|
|
}
|
|
}
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("Server lost client:" + conn.connectionId);
|
|
}
|
|
conn.RemoveObservers();
|
|
conn.Dispose();
|
|
}
|
|
|
|
// Token: 0x060003F8 RID: 1016 RVA: 0x00016CC3 File Offset: 0x00014EC3
|
|
private void OnData(NetworkConnection conn, int receivedSize, int channelId)
|
|
{
|
|
conn.TransportReceive(this.m_SimpleServerSimple.messageBuffer, receivedSize, channelId);
|
|
}
|
|
|
|
// Token: 0x060003F9 RID: 1017 RVA: 0x00016CD9 File Offset: 0x00014ED9
|
|
private void GenerateConnectError(int error)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("UNet Server Connect Error: " + error);
|
|
}
|
|
this.GenerateError(null, error);
|
|
}
|
|
|
|
// Token: 0x060003FA RID: 1018 RVA: 0x00016D08 File Offset: 0x00014F08
|
|
private void GenerateDataError(NetworkConnection conn, int error)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("UNet Server Data Error: " + (NetworkError)error);
|
|
}
|
|
this.GenerateError(conn, error);
|
|
}
|
|
|
|
// Token: 0x060003FB RID: 1019 RVA: 0x00016D44 File Offset: 0x00014F44
|
|
private void GenerateDisconnectError(NetworkConnection conn, int error)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError(string.Concat(new object[]
|
|
{
|
|
"UNet Server Disconnect Error: ",
|
|
(NetworkError)error,
|
|
" conn:[",
|
|
conn,
|
|
"]:",
|
|
conn.connectionId
|
|
}));
|
|
}
|
|
this.GenerateError(conn, error);
|
|
}
|
|
|
|
// Token: 0x060003FC RID: 1020 RVA: 0x00016DAC File Offset: 0x00014FAC
|
|
private void GenerateError(NetworkConnection conn, int error)
|
|
{
|
|
if (NetworkServer.handlers.ContainsKey(34))
|
|
{
|
|
ErrorMessage errorMessage = new ErrorMessage();
|
|
errorMessage.errorCode = error;
|
|
NetworkWriter networkWriter = new NetworkWriter();
|
|
errorMessage.Serialize(networkWriter);
|
|
NetworkReader networkReader = new NetworkReader(networkWriter);
|
|
conn.InvokeHandler(34, networkReader, 0);
|
|
}
|
|
}
|
|
|
|
// Token: 0x060003FD RID: 1021 RVA: 0x00016DF9 File Offset: 0x00014FF9
|
|
public static void RegisterHandler(short msgType, NetworkMessageDelegate handler)
|
|
{
|
|
NetworkServer.instance.m_SimpleServerSimple.RegisterHandler(msgType, handler);
|
|
}
|
|
|
|
// Token: 0x060003FE RID: 1022 RVA: 0x00016E0D File Offset: 0x0001500D
|
|
public static void UnregisterHandler(short msgType)
|
|
{
|
|
NetworkServer.instance.m_SimpleServerSimple.UnregisterHandler(msgType);
|
|
}
|
|
|
|
// Token: 0x060003FF RID: 1023 RVA: 0x00016E20 File Offset: 0x00015020
|
|
public static void ClearHandlers()
|
|
{
|
|
NetworkServer.instance.m_SimpleServerSimple.ClearHandlers();
|
|
}
|
|
|
|
// Token: 0x06000400 RID: 1024 RVA: 0x00016E32 File Offset: 0x00015032
|
|
public static void ClearSpawners()
|
|
{
|
|
NetworkScene.ClearSpawners();
|
|
}
|
|
|
|
// Token: 0x06000401 RID: 1025 RVA: 0x00016E3C File Offset: 0x0001503C
|
|
public static void GetStatsOut(out int numMsgs, out int numBufferedMsgs, out int numBytes, out int lastBufferedPerSecond)
|
|
{
|
|
numMsgs = 0;
|
|
numBufferedMsgs = 0;
|
|
numBytes = 0;
|
|
lastBufferedPerSecond = 0;
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null)
|
|
{
|
|
int num;
|
|
int num2;
|
|
int num3;
|
|
int num4;
|
|
networkConnection.GetStatsOut(out num, out num2, out num3, out num4);
|
|
numMsgs += num;
|
|
numBufferedMsgs += num2;
|
|
numBytes += num3;
|
|
lastBufferedPerSecond += num4;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000402 RID: 1026 RVA: 0x00016EB0 File Offset: 0x000150B0
|
|
public static void GetStatsIn(out int numMsgs, out int numBytes)
|
|
{
|
|
numMsgs = 0;
|
|
numBytes = 0;
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null)
|
|
{
|
|
int num;
|
|
int num2;
|
|
networkConnection.GetStatsIn(out num, out num2);
|
|
numMsgs += num;
|
|
numBytes += num2;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000403 RID: 1027 RVA: 0x00016F0C File Offset: 0x0001510C
|
|
public static void SendToClientOfPlayer(GameObject player, short msgType, MessageBase msg)
|
|
{
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null)
|
|
{
|
|
for (int j = 0; j < networkConnection.playerControllers.Count; j++)
|
|
{
|
|
if (networkConnection.playerControllers[j].IsValid && networkConnection.playerControllers[j].gameObject == player)
|
|
{
|
|
networkConnection.Send(msgType, msg);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("Failed to send message to player object '" + player.name + ", not found in connection list");
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000404 RID: 1028 RVA: 0x00016FD0 File Offset: 0x000151D0
|
|
public static void SendToClient(int connectionId, short msgType, MessageBase msg)
|
|
{
|
|
if (connectionId < NetworkServer.connections.Count)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[connectionId];
|
|
if (networkConnection != null)
|
|
{
|
|
networkConnection.Send(msgType, msg);
|
|
return;
|
|
}
|
|
}
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("Failed to send message to connection ID '" + connectionId + ", not found in connection list");
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000405 RID: 1029 RVA: 0x00017038 File Offset: 0x00015238
|
|
public static bool ReplacePlayerForConnection(NetworkConnection conn, GameObject player, short playerControllerId, NetworkHash128 assetId)
|
|
{
|
|
NetworkIdentity networkIdentity;
|
|
if (NetworkServer.GetNetworkIdentity(player, out networkIdentity))
|
|
{
|
|
networkIdentity.SetDynamicAssetId(assetId);
|
|
}
|
|
return NetworkServer.instance.InternalReplacePlayerForConnection(conn, player, playerControllerId);
|
|
}
|
|
|
|
// Token: 0x06000406 RID: 1030 RVA: 0x00017070 File Offset: 0x00015270
|
|
public static bool ReplacePlayerForConnection(NetworkConnection conn, GameObject player, short playerControllerId)
|
|
{
|
|
return NetworkServer.instance.InternalReplacePlayerForConnection(conn, player, playerControllerId);
|
|
}
|
|
|
|
// Token: 0x06000407 RID: 1031 RVA: 0x00017094 File Offset: 0x00015294
|
|
public static bool AddPlayerForConnection(NetworkConnection conn, GameObject player, short playerControllerId, NetworkHash128 assetId)
|
|
{
|
|
NetworkIdentity networkIdentity;
|
|
if (NetworkServer.GetNetworkIdentity(player, out networkIdentity))
|
|
{
|
|
networkIdentity.SetDynamicAssetId(assetId);
|
|
}
|
|
return NetworkServer.instance.InternalAddPlayerForConnection(conn, player, playerControllerId);
|
|
}
|
|
|
|
// Token: 0x06000408 RID: 1032 RVA: 0x000170CC File Offset: 0x000152CC
|
|
public static bool AddPlayerForConnection(NetworkConnection conn, GameObject player, short playerControllerId)
|
|
{
|
|
return NetworkServer.instance.InternalAddPlayerForConnection(conn, player, playerControllerId);
|
|
}
|
|
|
|
// Token: 0x06000409 RID: 1033 RVA: 0x000170F0 File Offset: 0x000152F0
|
|
internal bool InternalAddPlayerForConnection(NetworkConnection conn, GameObject playerGameObject, short playerControllerId)
|
|
{
|
|
NetworkIdentity networkIdentity;
|
|
bool flag;
|
|
if (!NetworkServer.GetNetworkIdentity(playerGameObject, out networkIdentity))
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.Log("AddPlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to " + playerGameObject);
|
|
}
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
networkIdentity.Reset();
|
|
if (!NetworkServer.CheckPlayerControllerIdForConnection(conn, playerControllerId))
|
|
{
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
PlayerController playerController = null;
|
|
GameObject gameObject = null;
|
|
if (conn.GetPlayerController(playerControllerId, out playerController))
|
|
{
|
|
gameObject = playerController.gameObject;
|
|
}
|
|
if (gameObject != null)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.Log("AddPlayer: player object already exists for playerControllerId of " + playerControllerId);
|
|
}
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
PlayerController playerController2 = new PlayerController(playerGameObject, playerControllerId);
|
|
conn.SetPlayerController(playerController2);
|
|
networkIdentity.SetConnectionToClient(conn, playerController2.playerControllerId);
|
|
NetworkServer.SetClientReady(conn);
|
|
if (this.SetupLocalPlayerForConnection(conn, networkIdentity, playerController2))
|
|
{
|
|
flag = true;
|
|
}
|
|
else
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log(string.Concat(new object[]
|
|
{
|
|
"Adding new playerGameObject object netId: ",
|
|
playerGameObject.GetComponent<NetworkIdentity>().netId,
|
|
" asset ID ",
|
|
playerGameObject.GetComponent<NetworkIdentity>().assetId
|
|
}));
|
|
}
|
|
NetworkServer.FinishPlayerForConnection(conn, networkIdentity, playerGameObject);
|
|
if (networkIdentity.localPlayerAuthority)
|
|
{
|
|
networkIdentity.SetClientOwner(conn);
|
|
}
|
|
flag = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x0600040A RID: 1034 RVA: 0x0001724C File Offset: 0x0001544C
|
|
private static bool CheckPlayerControllerIdForConnection(NetworkConnection conn, short playerControllerId)
|
|
{
|
|
bool flag;
|
|
if (playerControllerId < 0)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("AddPlayer: playerControllerId of " + playerControllerId + " is negative");
|
|
}
|
|
flag = false;
|
|
}
|
|
else if (playerControllerId > 32)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.Log(string.Concat(new object[] { "AddPlayer: playerControllerId of ", playerControllerId, " is too high. max is ", 32 }));
|
|
}
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
if (playerControllerId > 16)
|
|
{
|
|
if (LogFilter.logWarn)
|
|
{
|
|
Debug.LogWarning("AddPlayer: playerControllerId of " + playerControllerId + " is unusually high");
|
|
}
|
|
}
|
|
flag = true;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x0600040B RID: 1035 RVA: 0x00017318 File Offset: 0x00015518
|
|
private bool SetupLocalPlayerForConnection(NetworkConnection conn, NetworkIdentity uv, PlayerController newPlayerController)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("NetworkServer SetupLocalPlayerForConnection netID:" + uv.netId);
|
|
}
|
|
ULocalConnectionToClient ulocalConnectionToClient = conn as ULocalConnectionToClient;
|
|
bool flag;
|
|
if (ulocalConnectionToClient != null)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("NetworkServer AddPlayer handling ULocalConnectionToClient");
|
|
}
|
|
if (uv.netId.IsEmpty())
|
|
{
|
|
uv.OnStartServer(true);
|
|
}
|
|
uv.RebuildObservers(true);
|
|
this.SendSpawnMessage(uv, null);
|
|
ulocalConnectionToClient.localClient.AddLocalPlayer(newPlayerController);
|
|
uv.SetClientOwner(conn);
|
|
uv.ForceAuthority(true);
|
|
uv.SetLocalPlayer(newPlayerController.playerControllerId);
|
|
flag = true;
|
|
}
|
|
else
|
|
{
|
|
flag = false;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x0600040C RID: 1036 RVA: 0x000173D0 File Offset: 0x000155D0
|
|
private static void FinishPlayerForConnection(NetworkConnection conn, NetworkIdentity uv, GameObject playerGameObject)
|
|
{
|
|
if (uv.netId.IsEmpty())
|
|
{
|
|
NetworkServer.Spawn(playerGameObject);
|
|
}
|
|
conn.Send(4, new OwnerMessage
|
|
{
|
|
netId = uv.netId,
|
|
playerControllerId = uv.playerControllerId
|
|
});
|
|
}
|
|
|
|
// Token: 0x0600040D RID: 1037 RVA: 0x00017420 File Offset: 0x00015620
|
|
internal bool InternalReplacePlayerForConnection(NetworkConnection conn, GameObject playerGameObject, short playerControllerId)
|
|
{
|
|
NetworkIdentity networkIdentity;
|
|
bool flag;
|
|
if (!NetworkServer.GetNetworkIdentity(playerGameObject, out networkIdentity))
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("ReplacePlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to " + playerGameObject);
|
|
}
|
|
flag = false;
|
|
}
|
|
else if (!NetworkServer.CheckPlayerControllerIdForConnection(conn, playerControllerId))
|
|
{
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("NetworkServer ReplacePlayer");
|
|
}
|
|
PlayerController playerController;
|
|
if (conn.GetPlayerController(playerControllerId, out playerController))
|
|
{
|
|
playerController.unetView.SetNotLocalPlayer();
|
|
playerController.unetView.ClearClientOwner();
|
|
}
|
|
PlayerController playerController2 = new PlayerController(playerGameObject, playerControllerId);
|
|
conn.SetPlayerController(playerController2);
|
|
networkIdentity.SetConnectionToClient(conn, playerController2.playerControllerId);
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("NetworkServer ReplacePlayer setup local");
|
|
}
|
|
if (this.SetupLocalPlayerForConnection(conn, networkIdentity, playerController2))
|
|
{
|
|
flag = true;
|
|
}
|
|
else
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log(string.Concat(new object[]
|
|
{
|
|
"Replacing playerGameObject object netId: ",
|
|
playerGameObject.GetComponent<NetworkIdentity>().netId,
|
|
" asset ID ",
|
|
playerGameObject.GetComponent<NetworkIdentity>().assetId
|
|
}));
|
|
}
|
|
NetworkServer.FinishPlayerForConnection(conn, networkIdentity, playerGameObject);
|
|
if (networkIdentity.localPlayerAuthority)
|
|
{
|
|
networkIdentity.SetClientOwner(conn);
|
|
}
|
|
flag = true;
|
|
}
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x0600040E RID: 1038 RVA: 0x0001756C File Offset: 0x0001576C
|
|
private static bool GetNetworkIdentity(GameObject go, out NetworkIdentity view)
|
|
{
|
|
view = go.GetComponent<NetworkIdentity>();
|
|
bool flag;
|
|
if (view == null)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("UNET failure. GameObject doesn't have NetworkIdentity.");
|
|
}
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
flag = true;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x0600040F RID: 1039 RVA: 0x000175B5 File Offset: 0x000157B5
|
|
public static void SetClientReady(NetworkConnection conn)
|
|
{
|
|
NetworkServer.instance.SetClientReadyInternal(conn);
|
|
}
|
|
|
|
// Token: 0x06000410 RID: 1040 RVA: 0x000175C4 File Offset: 0x000157C4
|
|
internal void SetClientReadyInternal(NetworkConnection conn)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("SetClientReadyInternal for conn:" + conn.connectionId);
|
|
}
|
|
if (conn.isReady)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("SetClientReady conn " + conn.connectionId + " already ready");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (conn.playerControllers.Count == 0)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.LogWarning("Ready with no player object");
|
|
}
|
|
}
|
|
conn.isReady = true;
|
|
ULocalConnectionToClient ulocalConnectionToClient = conn as ULocalConnectionToClient;
|
|
if (ulocalConnectionToClient != null)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("NetworkServer Ready handling ULocalConnectionToClient");
|
|
}
|
|
foreach (NetworkIdentity networkIdentity in NetworkServer.objects.Values)
|
|
{
|
|
if (networkIdentity != null && networkIdentity.gameObject != null)
|
|
{
|
|
bool flag = networkIdentity.OnCheckObserver(conn);
|
|
if (flag)
|
|
{
|
|
networkIdentity.AddObserver(conn);
|
|
}
|
|
if (!networkIdentity.isClient)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("LocalClient.SetSpawnObject calling OnStartClient");
|
|
}
|
|
networkIdentity.OnStartClient();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log(string.Concat(new object[]
|
|
{
|
|
"Spawning ",
|
|
NetworkServer.objects.Count,
|
|
" objects for conn ",
|
|
conn.connectionId
|
|
}));
|
|
}
|
|
ObjectSpawnFinishedMessage objectSpawnFinishedMessage = new ObjectSpawnFinishedMessage();
|
|
objectSpawnFinishedMessage.state = 0U;
|
|
conn.Send(12, objectSpawnFinishedMessage);
|
|
foreach (NetworkIdentity networkIdentity2 in NetworkServer.objects.Values)
|
|
{
|
|
if (networkIdentity2 == null)
|
|
{
|
|
if (LogFilter.logWarn)
|
|
{
|
|
Debug.LogWarning("Invalid object found in server local object list (null NetworkIdentity).");
|
|
}
|
|
}
|
|
else if (networkIdentity2.gameObject.activeSelf)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log(string.Concat(new object[]
|
|
{
|
|
"Sending spawn message for current server objects name='",
|
|
networkIdentity2.gameObject.name,
|
|
"' netId=",
|
|
networkIdentity2.netId
|
|
}));
|
|
}
|
|
bool flag2 = networkIdentity2.OnCheckObserver(conn);
|
|
if (flag2)
|
|
{
|
|
networkIdentity2.AddObserver(conn);
|
|
}
|
|
}
|
|
}
|
|
objectSpawnFinishedMessage.state = 1U;
|
|
conn.Send(12, objectSpawnFinishedMessage);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000411 RID: 1041 RVA: 0x000178A8 File Offset: 0x00015AA8
|
|
internal static void ShowForConnection(NetworkIdentity uv, NetworkConnection conn)
|
|
{
|
|
if (conn.isReady)
|
|
{
|
|
NetworkServer.instance.SendSpawnMessage(uv, conn);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000412 RID: 1042 RVA: 0x000178C4 File Offset: 0x00015AC4
|
|
internal static void HideForConnection(NetworkIdentity uv, NetworkConnection conn)
|
|
{
|
|
conn.Send(13, new ObjectDestroyMessage
|
|
{
|
|
netId = uv.netId
|
|
});
|
|
}
|
|
|
|
// Token: 0x06000413 RID: 1043 RVA: 0x000178F0 File Offset: 0x00015AF0
|
|
public static void SetAllClientsNotReady()
|
|
{
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null)
|
|
{
|
|
NetworkServer.SetClientNotReady(networkConnection);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000414 RID: 1044 RVA: 0x00017935 File Offset: 0x00015B35
|
|
public static void SetClientNotReady(NetworkConnection conn)
|
|
{
|
|
NetworkServer.instance.InternalSetClientNotReady(conn);
|
|
}
|
|
|
|
// Token: 0x06000415 RID: 1045 RVA: 0x00017944 File Offset: 0x00015B44
|
|
internal void InternalSetClientNotReady(NetworkConnection conn)
|
|
{
|
|
if (conn.isReady)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("PlayerNotReady " + conn);
|
|
}
|
|
conn.isReady = false;
|
|
conn.RemoveObservers();
|
|
NotReadyMessage notReadyMessage = new NotReadyMessage();
|
|
conn.Send(36, notReadyMessage);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000416 RID: 1046 RVA: 0x00017998 File Offset: 0x00015B98
|
|
private static void OnClientReadyMessage(NetworkMessage netMsg)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("Default handler for ready message from " + netMsg.conn);
|
|
}
|
|
NetworkServer.SetClientReady(netMsg.conn);
|
|
}
|
|
|
|
// Token: 0x06000417 RID: 1047 RVA: 0x000179C8 File Offset: 0x00015BC8
|
|
private static void OnRemovePlayerMessage(NetworkMessage netMsg)
|
|
{
|
|
netMsg.ReadMessage<RemovePlayerMessage>(NetworkServer.s_RemovePlayerMessage);
|
|
PlayerController playerController = null;
|
|
netMsg.conn.GetPlayerController(NetworkServer.s_RemovePlayerMessage.playerControllerId, out playerController);
|
|
if (playerController != null)
|
|
{
|
|
netMsg.conn.RemovePlayerController(NetworkServer.s_RemovePlayerMessage.playerControllerId);
|
|
NetworkServer.Destroy(playerController.gameObject);
|
|
}
|
|
else if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("Received remove player message but could not find the player ID: " + NetworkServer.s_RemovePlayerMessage.playerControllerId);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000418 RID: 1048 RVA: 0x00017A54 File Offset: 0x00015C54
|
|
private static void OnCommandMessage(NetworkMessage netMsg)
|
|
{
|
|
int num = (int)netMsg.reader.ReadPackedUInt32();
|
|
NetworkInstanceId networkInstanceId = netMsg.reader.ReadNetworkId();
|
|
GameObject gameObject = NetworkServer.FindLocalObject(networkInstanceId);
|
|
if (gameObject == null)
|
|
{
|
|
if (LogFilter.logWarn)
|
|
{
|
|
Debug.LogWarning("Instance not found when handling Command message [netId=" + networkInstanceId + "]");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NetworkIdentity component = gameObject.GetComponent<NetworkIdentity>();
|
|
if (component == null)
|
|
{
|
|
if (LogFilter.logWarn)
|
|
{
|
|
Debug.LogWarning("NetworkIdentity deleted when handling Command message [netId=" + networkInstanceId + "]");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool flag = false;
|
|
for (int i = 0; i < netMsg.conn.playerControllers.Count; i++)
|
|
{
|
|
PlayerController playerController = netMsg.conn.playerControllers[i];
|
|
if (playerController.gameObject != null && playerController.gameObject.GetComponent<NetworkIdentity>().netId == component.netId)
|
|
{
|
|
flag = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!flag)
|
|
{
|
|
if (component.clientAuthorityOwner != netMsg.conn)
|
|
{
|
|
if (LogFilter.logWarn)
|
|
{
|
|
Debug.LogWarning("Command for object without authority [netId=" + networkInstanceId + "]");
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log(string.Concat(new object[] { "OnCommandMessage for netId=", networkInstanceId, " conn=", netMsg.conn }));
|
|
}
|
|
component.HandleCommand(num, netMsg.reader);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000419 RID: 1049 RVA: 0x00017C04 File Offset: 0x00015E04
|
|
internal void SpawnObject(GameObject obj)
|
|
{
|
|
NetworkIdentity networkIdentity;
|
|
if (!NetworkServer.active)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("SpawnObject for " + obj + ", NetworkServer is not active. Cannot spawn objects without an active server.");
|
|
}
|
|
}
|
|
else if (!NetworkServer.GetNetworkIdentity(obj, out networkIdentity))
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError(string.Concat(new object[] { "SpawnObject ", obj, " has no NetworkIdentity. Please add a NetworkIdentity to ", obj }));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
networkIdentity.Reset();
|
|
networkIdentity.OnStartServer(false);
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log(string.Concat(new object[] { "SpawnObject instance ID ", networkIdentity.netId, " asset ID ", networkIdentity.assetId }));
|
|
}
|
|
networkIdentity.RebuildObservers(true);
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600041A RID: 1050 RVA: 0x00017CE8 File Offset: 0x00015EE8
|
|
internal void SendSpawnMessage(NetworkIdentity uv, NetworkConnection conn)
|
|
{
|
|
if (!uv.serverOnly)
|
|
{
|
|
if (uv.sceneId.IsEmpty())
|
|
{
|
|
ObjectSpawnMessage objectSpawnMessage = new ObjectSpawnMessage();
|
|
objectSpawnMessage.netId = uv.netId;
|
|
objectSpawnMessage.assetId = uv.assetId;
|
|
objectSpawnMessage.position = uv.transform.position;
|
|
objectSpawnMessage.rotation = uv.transform.rotation;
|
|
NetworkWriter networkWriter = new NetworkWriter();
|
|
uv.UNetSerializeAllVars(networkWriter);
|
|
if (networkWriter.Position > 0)
|
|
{
|
|
objectSpawnMessage.payload = networkWriter.ToArray();
|
|
}
|
|
if (conn != null)
|
|
{
|
|
conn.Send(3, objectSpawnMessage);
|
|
}
|
|
else
|
|
{
|
|
NetworkServer.SendToReady(uv.gameObject, 3, objectSpawnMessage);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ObjectSpawnSceneMessage objectSpawnSceneMessage = new ObjectSpawnSceneMessage();
|
|
objectSpawnSceneMessage.netId = uv.netId;
|
|
objectSpawnSceneMessage.sceneId = uv.sceneId;
|
|
objectSpawnSceneMessage.position = uv.transform.position;
|
|
NetworkWriter networkWriter2 = new NetworkWriter();
|
|
uv.UNetSerializeAllVars(networkWriter2);
|
|
if (networkWriter2.Position > 0)
|
|
{
|
|
objectSpawnSceneMessage.payload = networkWriter2.ToArray();
|
|
}
|
|
if (conn != null)
|
|
{
|
|
conn.Send(10, objectSpawnSceneMessage);
|
|
}
|
|
else
|
|
{
|
|
NetworkServer.SendToReady(uv.gameObject, 3, objectSpawnSceneMessage);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600041B RID: 1051 RVA: 0x00017E30 File Offset: 0x00016030
|
|
public static void DestroyPlayersForConnection(NetworkConnection conn)
|
|
{
|
|
if (conn.playerControllers.Count == 0)
|
|
{
|
|
if (LogFilter.logWarn)
|
|
{
|
|
Debug.LogWarning("Empty player list given to NetworkServer.Destroy(), nothing to do.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (conn.clientOwnedObjects != null)
|
|
{
|
|
HashSet<NetworkInstanceId> hashSet = new HashSet<NetworkInstanceId>(conn.clientOwnedObjects);
|
|
foreach (NetworkInstanceId networkInstanceId in hashSet)
|
|
{
|
|
GameObject gameObject = NetworkServer.FindLocalObject(networkInstanceId);
|
|
if (gameObject != null)
|
|
{
|
|
NetworkServer.DestroyObject(gameObject);
|
|
}
|
|
}
|
|
}
|
|
for (int i = 0; i < conn.playerControllers.Count; i++)
|
|
{
|
|
PlayerController playerController = conn.playerControllers[i];
|
|
if (playerController.IsValid)
|
|
{
|
|
if (!(playerController.unetView == null))
|
|
{
|
|
NetworkServer.DestroyObject(playerController.unetView, true);
|
|
}
|
|
playerController.gameObject = null;
|
|
}
|
|
}
|
|
conn.playerControllers.Clear();
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600041C RID: 1052 RVA: 0x00017F60 File Offset: 0x00016160
|
|
private static void UnSpawnObject(GameObject obj)
|
|
{
|
|
NetworkIdentity networkIdentity;
|
|
if (obj == null)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("NetworkServer UnspawnObject is null");
|
|
}
|
|
}
|
|
else if (NetworkServer.GetNetworkIdentity(obj, out networkIdentity))
|
|
{
|
|
NetworkServer.UnSpawnObject(networkIdentity);
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600041D RID: 1053 RVA: 0x00017FAE File Offset: 0x000161AE
|
|
private static void UnSpawnObject(NetworkIdentity uv)
|
|
{
|
|
NetworkServer.DestroyObject(uv, false);
|
|
}
|
|
|
|
// Token: 0x0600041E RID: 1054 RVA: 0x00017FB8 File Offset: 0x000161B8
|
|
private static void DestroyObject(GameObject obj)
|
|
{
|
|
NetworkIdentity networkIdentity;
|
|
if (obj == null)
|
|
{
|
|
if (LogFilter.logDev)
|
|
{
|
|
Debug.Log("NetworkServer DestroyObject is null");
|
|
}
|
|
}
|
|
else if (NetworkServer.GetNetworkIdentity(obj, out networkIdentity))
|
|
{
|
|
NetworkServer.DestroyObject(networkIdentity, true);
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600041F RID: 1055 RVA: 0x00018008 File Offset: 0x00016208
|
|
private static void DestroyObject(NetworkIdentity uv, bool destroyServerObject)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("DestroyObject instance:" + uv.netId);
|
|
}
|
|
if (NetworkServer.objects.ContainsKey(uv.netId))
|
|
{
|
|
NetworkServer.objects.Remove(uv.netId);
|
|
}
|
|
if (uv.clientAuthorityOwner != null)
|
|
{
|
|
uv.clientAuthorityOwner.RemoveOwnedObject(uv);
|
|
}
|
|
ObjectDestroyMessage objectDestroyMessage = new ObjectDestroyMessage();
|
|
objectDestroyMessage.netId = uv.netId;
|
|
NetworkServer.SendToObservers(uv.gameObject, 1, objectDestroyMessage);
|
|
uv.ClearObservers();
|
|
if (NetworkClient.active && NetworkServer.instance.m_LocalClientActive)
|
|
{
|
|
uv.OnNetworkDestroy();
|
|
ClientScene.SetLocalObject(objectDestroyMessage.netId, null);
|
|
}
|
|
if (destroyServerObject)
|
|
{
|
|
Object.Destroy(uv.gameObject);
|
|
}
|
|
uv.MarkForReset();
|
|
}
|
|
|
|
// Token: 0x06000420 RID: 1056 RVA: 0x000180E9 File Offset: 0x000162E9
|
|
public static void ClearLocalObjects()
|
|
{
|
|
NetworkServer.objects.Clear();
|
|
}
|
|
|
|
// Token: 0x06000421 RID: 1057 RVA: 0x000180F6 File Offset: 0x000162F6
|
|
public static void Spawn(GameObject obj)
|
|
{
|
|
if (NetworkServer.VerifyCanSpawn(obj))
|
|
{
|
|
NetworkServer.instance.SpawnObject(obj);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000422 RID: 1058 RVA: 0x00018118 File Offset: 0x00016318
|
|
private static bool CheckForPrefab(GameObject obj)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Token: 0x06000423 RID: 1059 RVA: 0x00018130 File Offset: 0x00016330
|
|
private static bool VerifyCanSpawn(GameObject obj)
|
|
{
|
|
bool flag;
|
|
if (NetworkServer.CheckForPrefab(obj))
|
|
{
|
|
Debug.LogErrorFormat("GameObject {0} is a prefab, it can't be spawned. This will cause errors in builds.", new object[] { obj.name });
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
flag = true;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x06000424 RID: 1060 RVA: 0x00018174 File Offset: 0x00016374
|
|
public static bool SpawnWithClientAuthority(GameObject obj, GameObject player)
|
|
{
|
|
NetworkIdentity component = player.GetComponent<NetworkIdentity>();
|
|
bool flag;
|
|
if (component == null)
|
|
{
|
|
Debug.LogError("SpawnWithClientAuthority player object has no NetworkIdentity");
|
|
flag = false;
|
|
}
|
|
else if (component.connectionToClient == null)
|
|
{
|
|
Debug.LogError("SpawnWithClientAuthority player object is not a player.");
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
flag = NetworkServer.SpawnWithClientAuthority(obj, component.connectionToClient);
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x06000425 RID: 1061 RVA: 0x000181D8 File Offset: 0x000163D8
|
|
public static bool SpawnWithClientAuthority(GameObject obj, NetworkConnection conn)
|
|
{
|
|
bool flag;
|
|
if (!conn.isReady)
|
|
{
|
|
Debug.LogError("SpawnWithClientAuthority NetworkConnection is not ready!");
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
NetworkServer.Spawn(obj);
|
|
NetworkIdentity component = obj.GetComponent<NetworkIdentity>();
|
|
flag = !(component == null) && component.isServer && component.AssignClientAuthority(conn);
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x06000426 RID: 1062 RVA: 0x00018240 File Offset: 0x00016440
|
|
public static bool SpawnWithClientAuthority(GameObject obj, NetworkHash128 assetId, NetworkConnection conn)
|
|
{
|
|
NetworkServer.Spawn(obj, assetId);
|
|
NetworkIdentity component = obj.GetComponent<NetworkIdentity>();
|
|
return !(component == null) && component.isServer && component.AssignClientAuthority(conn);
|
|
}
|
|
|
|
// Token: 0x06000427 RID: 1063 RVA: 0x0001828C File Offset: 0x0001648C
|
|
public static void Spawn(GameObject obj, NetworkHash128 assetId)
|
|
{
|
|
if (NetworkServer.VerifyCanSpawn(obj))
|
|
{
|
|
NetworkIdentity networkIdentity;
|
|
if (NetworkServer.GetNetworkIdentity(obj, out networkIdentity))
|
|
{
|
|
networkIdentity.SetDynamicAssetId(assetId);
|
|
}
|
|
NetworkServer.instance.SpawnObject(obj);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000428 RID: 1064 RVA: 0x000182CC File Offset: 0x000164CC
|
|
public static void Destroy(GameObject obj)
|
|
{
|
|
NetworkServer.DestroyObject(obj);
|
|
}
|
|
|
|
// Token: 0x06000429 RID: 1065 RVA: 0x000182D5 File Offset: 0x000164D5
|
|
public static void UnSpawn(GameObject obj)
|
|
{
|
|
NetworkServer.UnSpawnObject(obj);
|
|
}
|
|
|
|
// Token: 0x0600042A RID: 1066 RVA: 0x000182E0 File Offset: 0x000164E0
|
|
internal bool InvokeBytes(ULocalConnectionToServer conn, byte[] buffer, int numBytes, int channelId)
|
|
{
|
|
NetworkReader networkReader = new NetworkReader(buffer);
|
|
networkReader.ReadInt16();
|
|
short num = networkReader.ReadInt16();
|
|
bool flag;
|
|
if (NetworkServer.handlers.ContainsKey(num) && this.m_LocalConnection != null)
|
|
{
|
|
this.m_LocalConnection.InvokeHandler(num, networkReader, channelId);
|
|
flag = true;
|
|
}
|
|
else
|
|
{
|
|
flag = false;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x0600042B RID: 1067 RVA: 0x00018340 File Offset: 0x00016540
|
|
internal bool InvokeHandlerOnServer(ULocalConnectionToServer conn, short msgType, MessageBase msg, int channelId)
|
|
{
|
|
bool flag;
|
|
if (NetworkServer.handlers.ContainsKey(msgType) && this.m_LocalConnection != null)
|
|
{
|
|
NetworkWriter networkWriter = new NetworkWriter();
|
|
msg.Serialize(networkWriter);
|
|
NetworkReader networkReader = new NetworkReader(networkWriter);
|
|
this.m_LocalConnection.InvokeHandler(msgType, networkReader, channelId);
|
|
flag = true;
|
|
}
|
|
else
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError(string.Concat(new object[] { "Local invoke: Failed to find local connection to invoke handler on [connectionId=", conn.connectionId, "] for MsgId:", msgType }));
|
|
}
|
|
flag = false;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x0600042C RID: 1068 RVA: 0x000183E0 File Offset: 0x000165E0
|
|
public static GameObject FindLocalObject(NetworkInstanceId netId)
|
|
{
|
|
return NetworkServer.instance.m_NetworkScene.FindLocalObject(netId);
|
|
}
|
|
|
|
// Token: 0x0600042D RID: 1069 RVA: 0x00018408 File Offset: 0x00016608
|
|
public static Dictionary<short, NetworkConnection.PacketStat> GetConnectionStats()
|
|
{
|
|
Dictionary<short, NetworkConnection.PacketStat> dictionary = new Dictionary<short, NetworkConnection.PacketStat>();
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null)
|
|
{
|
|
foreach (short num in networkConnection.packetStats.Keys)
|
|
{
|
|
if (dictionary.ContainsKey(num))
|
|
{
|
|
NetworkConnection.PacketStat packetStat = dictionary[num];
|
|
packetStat.count += networkConnection.packetStats[num].count;
|
|
packetStat.bytes += networkConnection.packetStats[num].bytes;
|
|
dictionary[num] = packetStat;
|
|
}
|
|
else
|
|
{
|
|
dictionary[num] = new NetworkConnection.PacketStat(networkConnection.packetStats[num]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return dictionary;
|
|
}
|
|
|
|
// Token: 0x0600042E RID: 1070 RVA: 0x00018528 File Offset: 0x00016728
|
|
public static void ResetConnectionStats()
|
|
{
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null)
|
|
{
|
|
networkConnection.ResetStats();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600042F RID: 1071 RVA: 0x00018570 File Offset: 0x00016770
|
|
public static bool AddExternalConnection(NetworkConnection conn)
|
|
{
|
|
return NetworkServer.instance.AddExternalConnectionInternal(conn);
|
|
}
|
|
|
|
// Token: 0x06000430 RID: 1072 RVA: 0x00018590 File Offset: 0x00016790
|
|
private bool AddExternalConnectionInternal(NetworkConnection conn)
|
|
{
|
|
bool flag;
|
|
if (conn.connectionId < 0)
|
|
{
|
|
flag = false;
|
|
}
|
|
else if (conn.connectionId < NetworkServer.connections.Count && NetworkServer.connections[conn.connectionId] != null)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("AddExternalConnection failed, already connection for id:" + conn.connectionId);
|
|
}
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("AddExternalConnection external connection " + conn.connectionId);
|
|
}
|
|
this.m_SimpleServerSimple.SetConnectionAtIndex(conn);
|
|
this.m_ExternalConnections.Add(conn.connectionId);
|
|
conn.InvokeHandlerNoData(32);
|
|
flag = true;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x06000431 RID: 1073 RVA: 0x0001865F File Offset: 0x0001685F
|
|
public static void RemoveExternalConnection(int connectionId)
|
|
{
|
|
NetworkServer.instance.RemoveExternalConnectionInternal(connectionId);
|
|
}
|
|
|
|
// Token: 0x06000432 RID: 1074 RVA: 0x00018670 File Offset: 0x00016870
|
|
private bool RemoveExternalConnectionInternal(int connectionId)
|
|
{
|
|
bool flag;
|
|
if (!this.m_ExternalConnections.Contains(connectionId))
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("RemoveExternalConnection failed, no connection for id:" + connectionId);
|
|
}
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("RemoveExternalConnection external connection " + connectionId);
|
|
}
|
|
NetworkConnection networkConnection = this.m_SimpleServerSimple.FindConnection(connectionId);
|
|
if (networkConnection != null)
|
|
{
|
|
networkConnection.RemoveObservers();
|
|
}
|
|
this.m_SimpleServerSimple.RemoveConnectionAtIndex(connectionId);
|
|
flag = true;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x06000433 RID: 1075 RVA: 0x0001870C File Offset: 0x0001690C
|
|
public static bool SpawnObjects()
|
|
{
|
|
if (NetworkServer.active)
|
|
{
|
|
foreach (NetworkIdentity networkIdentity in Resources.FindObjectsOfTypeAll<NetworkIdentity>())
|
|
{
|
|
if (networkIdentity.gameObject.hideFlags != HideFlags.NotEditable && networkIdentity.gameObject.hideFlags != HideFlags.HideAndDontSave)
|
|
{
|
|
if (!networkIdentity.sceneId.IsEmpty())
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log(string.Concat(new object[]
|
|
{
|
|
"SpawnObjects sceneId:",
|
|
networkIdentity.sceneId,
|
|
" name:",
|
|
networkIdentity.gameObject.name
|
|
}));
|
|
}
|
|
networkIdentity.Reset();
|
|
networkIdentity.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
NetworkIdentity[] array;
|
|
foreach (NetworkIdentity networkIdentity2 in array)
|
|
{
|
|
if (networkIdentity2.gameObject.hideFlags != HideFlags.NotEditable && networkIdentity2.gameObject.hideFlags != HideFlags.HideAndDontSave)
|
|
{
|
|
if (!networkIdentity2.sceneId.IsEmpty())
|
|
{
|
|
if (!networkIdentity2.isServer)
|
|
{
|
|
if (!(networkIdentity2.gameObject == null))
|
|
{
|
|
NetworkServer.Spawn(networkIdentity2.gameObject);
|
|
networkIdentity2.ForceAuthority(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// Token: 0x06000434 RID: 1076 RVA: 0x0001888C File Offset: 0x00016A8C
|
|
private static void SendCrc(NetworkConnection targetConnection)
|
|
{
|
|
if (NetworkCRC.singleton != null)
|
|
{
|
|
if (NetworkCRC.scriptCRCCheck)
|
|
{
|
|
CRCMessage crcmessage = new CRCMessage();
|
|
List<CRCMessageEntry> list = new List<CRCMessageEntry>();
|
|
foreach (string text in NetworkCRC.singleton.scripts.Keys)
|
|
{
|
|
list.Add(new CRCMessageEntry
|
|
{
|
|
name = text,
|
|
channel = (byte)NetworkCRC.singleton.scripts[text]
|
|
});
|
|
}
|
|
crcmessage.scripts = list.ToArray();
|
|
targetConnection.Send(14, crcmessage);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000435 RID: 1077 RVA: 0x00018960 File Offset: 0x00016B60
|
|
[Obsolete("moved to NetworkMigrationManager")]
|
|
public void SendNetworkInfo(NetworkConnection targetConnection)
|
|
{
|
|
}
|
|
|
|
// Token: 0x040001B8 RID: 440
|
|
private static bool s_Active;
|
|
|
|
// Token: 0x040001B9 RID: 441
|
|
private static volatile NetworkServer s_Instance;
|
|
|
|
// Token: 0x040001BA RID: 442
|
|
private static object s_Sync = new Object();
|
|
|
|
// Token: 0x040001BB RID: 443
|
|
private static bool m_DontListen;
|
|
|
|
// Token: 0x040001BC RID: 444
|
|
private bool m_LocalClientActive;
|
|
|
|
// Token: 0x040001BD RID: 445
|
|
private List<NetworkConnection> m_LocalConnectionsFakeList = new List<NetworkConnection>();
|
|
|
|
// Token: 0x040001BE RID: 446
|
|
private ULocalConnectionToClient m_LocalConnection = null;
|
|
|
|
// Token: 0x040001BF RID: 447
|
|
private NetworkScene m_NetworkScene;
|
|
|
|
// Token: 0x040001C0 RID: 448
|
|
private HashSet<int> m_ExternalConnections;
|
|
|
|
// Token: 0x040001C1 RID: 449
|
|
private NetworkServer.ServerSimpleWrapper m_SimpleServerSimple;
|
|
|
|
// Token: 0x040001C2 RID: 450
|
|
private float m_MaxDelay = 0.1f;
|
|
|
|
// Token: 0x040001C3 RID: 451
|
|
private HashSet<NetworkInstanceId> m_RemoveList;
|
|
|
|
// Token: 0x040001C4 RID: 452
|
|
private int m_RemoveListCount;
|
|
|
|
// Token: 0x040001C5 RID: 453
|
|
private const int k_RemoveListInterval = 100;
|
|
|
|
// Token: 0x040001C6 RID: 454
|
|
internal static ushort maxPacketSize;
|
|
|
|
// Token: 0x040001C7 RID: 455
|
|
private static RemovePlayerMessage s_RemovePlayerMessage = new RemovePlayerMessage();
|
|
|
|
// Token: 0x02000059 RID: 89
|
|
private class ServerSimpleWrapper : NetworkServerSimple
|
|
{
|
|
// Token: 0x06000437 RID: 1079 RVA: 0x000194F6 File Offset: 0x000176F6
|
|
public ServerSimpleWrapper(NetworkServer server)
|
|
{
|
|
this.m_Server = server;
|
|
}
|
|
|
|
// Token: 0x06000438 RID: 1080 RVA: 0x00019506 File Offset: 0x00017706
|
|
public override void OnConnectError(int connectionId, byte error)
|
|
{
|
|
this.m_Server.GenerateConnectError((int)error);
|
|
}
|
|
|
|
// Token: 0x06000439 RID: 1081 RVA: 0x00019515 File Offset: 0x00017715
|
|
public override void OnDataError(NetworkConnection conn, byte error)
|
|
{
|
|
this.m_Server.GenerateDataError(conn, (int)error);
|
|
}
|
|
|
|
// Token: 0x0600043A RID: 1082 RVA: 0x00019525 File Offset: 0x00017725
|
|
public override void OnDisconnectError(NetworkConnection conn, byte error)
|
|
{
|
|
this.m_Server.GenerateDisconnectError(conn, (int)error);
|
|
}
|
|
|
|
// Token: 0x0600043B RID: 1083 RVA: 0x00019535 File Offset: 0x00017735
|
|
public override void OnConnected(NetworkConnection conn)
|
|
{
|
|
this.m_Server.OnConnected(conn);
|
|
}
|
|
|
|
// Token: 0x0600043C RID: 1084 RVA: 0x00019544 File Offset: 0x00017744
|
|
public override void OnDisconnected(NetworkConnection conn)
|
|
{
|
|
this.m_Server.OnDisconnected(conn);
|
|
}
|
|
|
|
// Token: 0x0600043D RID: 1085 RVA: 0x00019553 File Offset: 0x00017753
|
|
public override void OnData(NetworkConnection conn, int receivedSize, int channelId)
|
|
{
|
|
this.m_Server.OnData(conn, receivedSize, channelId);
|
|
}
|
|
|
|
// Token: 0x040001D1 RID: 465
|
|
private NetworkServer m_Server;
|
|
}
|
|
}
|
|
}
|