private static void OnSyncEventMessage(NetworkMessage netMsg) { int cmdHash = (int)netMsg.reader.ReadPackedUInt32(); NetworkInstanceId netId = netMsg.reader.ReadNetworkId(); if (LogFilter.logDebug) { Debug.Log((object)("ClientScene::OnSyncEventMessage " + (object)netId)); } NetworkIdentity uv; if (ClientScene.s_NetworkScene.GetNetworkIdentity(netId, out uv)) { uv.HandleSyncEvent(cmdHash, netMsg.reader); } else if (LogFilter.logWarn) { Debug.LogWarning((object)("Did not find target for SyncEvent message for " + (object)netId)); } NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, (short)7, NetworkBehaviour.GetCmdHashHandlerName(cmdHash), 1); }
internal void HandleSyncList(int cmdHash, NetworkReader reader) { if (base.gameObject == null) { if (LogFilter.logWarn) { Debug.LogWarning(string.Concat(new object[] { "SyncList [", NetworkBehaviour.GetCmdHashHandlerName(cmdHash), "] received for deleted object ", this.netId })); } } else { for (int i = 0; i < this.m_NetworkBehaviours.Length; i++) { NetworkBehaviour behaviour = this.m_NetworkBehaviours[i]; if (behaviour.InvokeSyncList(cmdHash, reader)) { NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, 9, NetworkBehaviour.GetCmdHashListName(cmdHash), 1); break; } } } }
internal void HandleRPC(int cmdHash, NetworkReader reader) { if (base.gameObject == null) { if (LogFilter.logWarn) { Debug.LogWarning(string.Concat(new object[] { "ClientRpc [", NetworkBehaviour.GetCmdHashHandlerName(cmdHash), "] received for deleted object ", this.netId })); } } else if (this.m_NetworkBehaviours.Length == 0) { if (LogFilter.logWarn) { Debug.LogWarning("No receiver found for ClientRpc [" + NetworkBehaviour.GetCmdHashHandlerName(cmdHash) + "]. Does the script with the function inherit NetworkBehaviour?"); } } else { for (int i = 0; i < this.m_NetworkBehaviours.Length; i++) { NetworkBehaviour behaviour = this.m_NetworkBehaviours[i]; if (behaviour.InvokeRPC(cmdHash, reader)) { NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, 2, NetworkBehaviour.GetCmdHashRpcName(cmdHash), 1); return; } } string invoker = NetworkBehaviour.GetInvoker(cmdHash); if (invoker == null) { invoker = "[unknown:" + cmdHash + "]"; } if (LogFilter.logWarn) { Debug.LogWarning(string.Concat(new object[] { "Failed to invoke RPC ", invoker, "(", cmdHash, ") on netID ", this.netId })); } NetworkBehaviour.DumpInvokers(); } }
private void SendMsg(Operation <T> op, int itemIndex, T item) { if (this.m_Behaviour == null) { if (LogFilter.logError) { Debug.LogError("SyncList not initialized"); } } else { NetworkIdentity component = this.m_Behaviour.GetComponent <NetworkIdentity>(); if (component == null) { if (LogFilter.logError) { Debug.LogError("SyncList no NetworkIdentity"); } } else { NetworkWriter writer = new NetworkWriter(); writer.StartMessage(9); writer.Write(component.netId); writer.WritePackedUInt32((uint)this.m_CmdHash); writer.Write((byte)op); writer.WritePackedUInt32((uint)itemIndex); this.SerializeItem(writer, item); writer.FinishMessage(); NetworkServer.SendWriterToReady(component.gameObject, writer, 0); NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, 9, op.ToString(), 1); if ((this.m_Behaviour.isServer && this.m_Behaviour.isClient) && (this.m_Callback != null)) { this.m_Callback(op, itemIndex); } } } }
protected void SendCommandInternal(NetworkWriter writer, int channelId, string cmdName) { if (!this.isLocalPlayer && !this.hasAuthority) { if (LogFilter.logWarn) { Debug.LogWarning("Trying to send command for object without authority."); } } else if (ClientScene.readyConnection == null) { if (LogFilter.logError) { Debug.LogError("Send command attempted with no client running [client=" + this.connectionToServer + "]."); } } else { writer.FinishMessage(); ClientScene.readyConnection.SendWriter(writer, channelId); NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, 5, cmdName, 1); } }
private static void OnObjectDestroy(NetworkMessage netMsg) { netMsg.ReadMessage <ObjectDestroyMessage>(ClientScene.s_ObjectDestroyMessage); if (LogFilter.logDebug) { Debug.Log((object)("ClientScene::OnObjDestroy netId:" + (object)ClientScene.s_ObjectDestroyMessage.netId)); } NetworkIdentity uv; if (ClientScene.s_NetworkScene.GetNetworkIdentity(ClientScene.s_ObjectDestroyMessage.netId, out uv)) { NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, (short)1, ClientScene.GetStringForAssetId(uv.assetId), 1); uv.OnNetworkDestroy(); if (!NetworkScene.InvokeUnSpawnHandler(uv.assetId, uv.gameObject)) { if (uv.sceneId.IsEmpty()) { Object.Destroy((Object)uv.gameObject); } else { uv.gameObject.SetActive(false); ClientScene.s_SpawnableObjects[uv.sceneId] = uv; } } ClientScene.s_NetworkScene.RemoveLocalObject(ClientScene.s_ObjectDestroyMessage.netId); } else { if (!LogFilter.logDebug) { return; } Debug.LogWarning((object)("Did not find target for destroy message for " + (object)ClientScene.s_ObjectDestroyMessage.netId)); } }
internal static void HandleChildTransform(NetworkMessage netMsg) { NetworkInstanceId netId = netMsg.reader.ReadNetworkId(); uint index = netMsg.reader.ReadPackedUInt32(); NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, 0x10, "16:LocalChildTransform", 1); GameObject obj2 = NetworkServer.FindLocalObject(netId); if (obj2 == null) { if (LogFilter.logError) { Debug.LogError("HandleChildTransform no gameObject"); } } else { NetworkTransformChild[] components = obj2.GetComponents <NetworkTransformChild>(); if ((components == null) || (components.Length == 0)) { if (LogFilter.logError) { Debug.LogError("HandleChildTransform no children"); } } else if (index >= components.Length) { if (LogFilter.logError) { Debug.LogError("HandleChildTransform childIndex invalid"); } } else { NetworkTransformChild child = components[index]; if (child == null) { if (LogFilter.logError) { Debug.LogError("HandleChildTransform null target"); } } else if (!child.localPlayerAuthority) { if (LogFilter.logError) { Debug.LogError("HandleChildTransform no localPlayerAuthority"); } } else if (!netMsg.conn.clientOwnedObjects.Contains(netId)) { if (LogFilter.logWarn) { Debug.LogWarning("NetworkTransformChild netId:" + netId + " is not for a valid player"); } } else { child.UnserializeModeTransform(netMsg.reader, false); child.m_LastClientSyncTime = Time.time; if (!child.isClient) { child.m_Target.localPosition = child.m_TargetSyncPosition; child.m_Target.localRotation = child.m_TargetSyncRotation3D; } } } } }
internal virtual void Update() { int num; int num2; int num3; byte num4; int num5; if (this.m_ClientId == -1) { return; } switch (this.m_AsyncConnect) { case ConnectState.None: case ConnectState.Resolving: case ConnectState.Disconnected: return; case ConnectState.Resolved: this.m_AsyncConnect = ConnectState.Connecting; this.ContinueConnect(); return; case ConnectState.Failed: this.GenerateConnectError(11); this.m_AsyncConnect = ConnectState.Disconnected; return; default: if ((this.m_Connection != null) && (((int)Time.time) != this.m_StatResetTime)) { this.m_Connection.ResetStats(); this.m_StatResetTime = (int)Time.time; } break; } Label_0094: num5 = 0; NetworkEventType type = NetworkTransport.ReceiveFromHost(this.m_ClientId, out num, out num2, this.m_MsgBuffer, (ushort)this.m_MsgBuffer.Length, out num3, out num4); if ((type != NetworkEventType.Nothing) && LogFilter.logDev) { Debug.Log(string.Concat(new object[] { "Client event: host=", this.m_ClientId, " event=", type, " error=", num4 })); } switch (type) { case NetworkEventType.DataEvent: if (num4 == 0) { NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, 0x1d, "msg", 1); this.m_MsgReader.SeekZero(); this.m_Connection.TransportRecieve(this.m_MsgBuffer, num3, num2); break; } this.GenerateDataError(num4); return; case NetworkEventType.ConnectEvent: if (LogFilter.logDebug) { Debug.Log("Client connected"); } if (num4 != 0) { this.GenerateConnectError(num4); return; } this.m_AsyncConnect = ConnectState.Connected; this.m_Connection.InvokeHandlerNoData(0x20); break; case NetworkEventType.DisconnectEvent: if (LogFilter.logDebug) { Debug.Log("Client disconnected"); } this.m_AsyncConnect = ConnectState.Disconnected; if (num4 != 0) { this.GenerateDisconnectError(num4); } ClientScene.HandleClientDisconnect(this.m_Connection); this.m_Connection.InvokeHandlerNoData(0x21); break; case NetworkEventType.Nothing: break; default: if (LogFilter.logError) { Debug.LogError("Unknown network message type received: " + type); } break; } if (++num5 >= 500) { if (LogFilter.logDebug) { Debug.Log("MaxEventsPerFrame hit (" + 500 + ")"); } } else if ((this.m_ClientId != -1) && (type != NetworkEventType.Nothing)) { goto Label_0094; } if ((this.m_Connection != null) && (this.m_AsyncConnect == ConnectState.Connected)) { this.m_Connection.FlushChannels(); } }
internal bool SendBytes(byte[] bytes, int bytesToSend) { NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, (short)28, "msg", 1); if (bytesToSend <= 0) { if (LogFilter.logError) { Debug.LogError((object)"ChannelBuffer:SendBytes cannot send zero bytes"); } return(false); } if (bytesToSend > this.m_MaxPacketSize) { if (LogFilter.logError) { Debug.LogError((object)("Failed to send big message of " + (object)bytesToSend + " bytes. The maximum is " + (object)this.m_MaxPacketSize + " bytes on this channel.")); } return(false); } if (!this.m_CurrentPacket.HasSpace(bytesToSend)) { if (this.m_IsReliable) { if (this.m_PendingPackets.Count == 0) { if (!this.m_CurrentPacket.SendToTransport(this.m_Connection, (int)this.m_ChannelId)) { this.QueuePacket(); } this.m_CurrentPacket.Write(bytes, bytesToSend); return(true); } if (this.m_PendingPackets.Count >= this.m_MaxPendingPacketCount) { if (!this.m_IsBroken && LogFilter.logError) { Debug.LogError((object)("ChannelBuffer buffer limit of " + (object)this.m_PendingPackets.Count + " packets reached.")); } this.m_IsBroken = true; return(false); } this.QueuePacket(); this.m_CurrentPacket.Write(bytes, bytesToSend); return(true); } if (!this.m_CurrentPacket.SendToTransport(this.m_Connection, (int)this.m_ChannelId)) { if (LogFilter.logError) { Debug.Log((object)("ChannelBuffer SendBytes no space on unreliable channel " + (object)this.m_ChannelId)); } return(false); } this.m_CurrentPacket.Write(bytes, bytesToSend); return(true); } this.m_CurrentPacket.Write(bytes, bytesToSend); if ((double)this.maxDelay == 0.0) { return(this.SendInternalBuffer()); } return(true); }
/// <summary> /// <para>This makes the connection process the data contained in the stream, and call handler functions.</para> /// </summary> /// <param name="reader">Stream that contains data.</param> /// <param name="receivedSize">Size of the data.</param> /// <param name="channelId">Channel the data was received on.</param> protected void HandleReader(NetworkReader reader, int receivedSize, int channelId) { while (reader.Position < receivedSize) { ushort count = reader.ReadUInt16(); short key = reader.ReadInt16(); byte[] buffer = reader.ReadBytes(count); NetworkReader reader2 = new NetworkReader(buffer); if (this.logNetworkMessages) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < count; i++) { builder.AppendFormat("{0:X2}", buffer[i]); if (i > 150) { break; } } Debug.Log(string.Concat(new object[] { "ConnectionRecv con:", this.connectionId, " bytes:", count, " msgId:", key, " ", builder })); } NetworkMessageDelegate delegate2 = null; if (this.m_MessageHandlersDict.ContainsKey(key)) { delegate2 = this.m_MessageHandlersDict[key]; } if (delegate2 != null) { this.m_NetMsg.msgType = key; this.m_NetMsg.reader = reader2; this.m_NetMsg.conn = this; this.m_NetMsg.channelId = channelId; delegate2(this.m_NetMsg); this.lastMessageTime = Time.time; NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, 0x1c, "msg", 1); if (key > 0x2f) { NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, 0, key.ToString() + ":" + key.GetType().Name, 1); } if (this.m_PacketStats.ContainsKey(key)) { PacketStat stat = this.m_PacketStats[key]; stat.count++; stat.bytes += count; } else { PacketStat stat2 = new PacketStat { msgType = key }; stat2.count++; stat2.bytes += count; this.m_PacketStats[key] = stat2; } } else { if (LogFilter.logError) { Debug.LogError(string.Concat(new object[] { "Unknown message ID ", key, " connId:", this.connectionId })); } break; } } }
/// <summary> /// <para>This makes the connection process the data contained in the stream, and call handler functions.</para> /// </summary> /// <param name="reader">Stream that contains data.</param> /// <param name="receivedSize">Size of the data.</param> /// <param name="channelId">Channel the data was received on.</param> protected void HandleReader(NetworkReader reader, int receivedSize, int channelId) { while ((long)reader.Position < (long)receivedSize) { ushort num = reader.ReadUInt16(); short key = reader.ReadInt16(); byte[] buffer = reader.ReadBytes((int)num); NetworkReader networkReader = new NetworkReader(buffer); if (this.logNetworkMessages) { StringBuilder stringBuilder = new StringBuilder(); for (int index = 0; index < (int)num; ++index) { stringBuilder.AppendFormat("{0:X2}", (object)buffer[index]); if (index > 150) { break; } } Debug.Log((object)("ConnectionRecv con:" + (object)this.connectionId + " bytes:" + (object)num + " msgId:" + (object)key + " " + (object)stringBuilder)); } NetworkMessageDelegate networkMessageDelegate = (NetworkMessageDelegate)null; if (this.m_MessageHandlersDict.ContainsKey(key)) { networkMessageDelegate = this.m_MessageHandlersDict[key]; } if (networkMessageDelegate != null) { this.m_NetMsg.msgType = key; this.m_NetMsg.reader = networkReader; this.m_NetMsg.conn = this; this.m_NetMsg.channelId = channelId; networkMessageDelegate(this.m_NetMsg); this.lastMessageTime = Time.time; NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, (short)28, "msg", 1); if ((int)key > 47) { NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, (short)0, key.ToString() + ":" + key.GetType().Name, 1); } if (this.m_PacketStats.ContainsKey(key)) { NetworkConnection.PacketStat packetStat = this.m_PacketStats[key]; ++packetStat.count; packetStat.bytes += (int)num; } else { NetworkConnection.PacketStat packetStat = new NetworkConnection.PacketStat(); packetStat.msgType = key; ++packetStat.count; packetStat.bytes += (int)num; this.m_PacketStats[key] = packetStat; } } else { if (!LogFilter.logError) { break; } Debug.LogError((object)("Unknown message ID " + (object)key + " connId:" + (object)this.connectionId)); break; } } }
internal static void HandleChildTransform(NetworkMessage netMsg) { NetworkInstanceId netId = netMsg.reader.ReadNetworkId(); uint num = netMsg.reader.ReadPackedUInt32(); NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, (short)16, "16:LocalChildTransform", 1); GameObject localObject = NetworkServer.FindLocalObject(netId); if ((UnityEngine.Object)localObject == (UnityEngine.Object)null) { if (!LogFilter.logError) { return; } Debug.LogError((object)"HandleChildTransform no gameObject"); } else { NetworkTransformChild[] components = localObject.GetComponents <NetworkTransformChild>(); if (components == null || components.Length == 0) { if (!LogFilter.logError) { return; } Debug.LogError((object)"HandleChildTransform no children"); } else if ((long)num >= (long)components.Length) { if (!LogFilter.logError) { return; } Debug.LogError((object)"HandleChildTransform childIndex invalid"); } else { NetworkTransformChild networkTransformChild = components[(IntPtr)num]; if ((UnityEngine.Object)networkTransformChild == (UnityEngine.Object)null) { if (!LogFilter.logError) { return; } Debug.LogError((object)"HandleChildTransform null target"); } else if (!networkTransformChild.localPlayerAuthority) { if (!LogFilter.logError) { return; } Debug.LogError((object)"HandleChildTransform no localPlayerAuthority"); } else if (!netMsg.conn.clientOwnedObjects.Contains(netId)) { if (!LogFilter.logWarn) { return; } Debug.LogWarning((object)("NetworkTransformChild netId:" + (object)netId + " is not for a valid player")); } else { networkTransformChild.UnserializeModeTransform(netMsg.reader, false); networkTransformChild.m_LastClientSyncTime = Time.time; if (networkTransformChild.isClient) { return; } networkTransformChild.m_Target.localPosition = networkTransformChild.m_TargetSyncPosition; networkTransformChild.m_Target.localRotation = networkTransformChild.m_TargetSyncRotation3D; } } } }
private static void OnObjectSpawn(NetworkMessage netMsg) { netMsg.ReadMessage <ObjectSpawnMessage>(s_ObjectSpawnMessage); if (!s_ObjectSpawnMessage.assetId.IsValid()) { if (LogFilter.logError) { Debug.LogError("OnObjSpawn netId: " + s_ObjectSpawnMessage.netId + " has invalid asset Id"); } } else { NetworkIdentity component; if (LogFilter.logDebug) { Debug.Log(string.Concat(new object[] { "Client spawn handler instantiating [netId:", s_ObjectSpawnMessage.netId, " asset ID:", s_ObjectSpawnMessage.assetId, " pos:", s_ObjectSpawnMessage.position, "]" })); } NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, 3, GetStringForAssetId(s_ObjectSpawnMessage.assetId), 1); if (s_NetworkScene.GetNetworkIdentity(s_ObjectSpawnMessage.netId, out component)) { ApplySpawnPayload(component, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.payload, s_ObjectSpawnMessage.netId, null); } else { GameObject obj2; if (NetworkScene.GetPrefab(s_ObjectSpawnMessage.assetId, out obj2)) { GameObject newGameObject = UnityEngine.Object.Instantiate <GameObject>(obj2, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.rotation); if (LogFilter.logDebug) { Debug.Log(string.Concat(new object[] { "Client spawn handler instantiating [netId:", s_ObjectSpawnMessage.netId, " asset ID:", s_ObjectSpawnMessage.assetId, " pos:", s_ObjectSpawnMessage.position, " rotation: ", s_ObjectSpawnMessage.rotation, "]" })); } component = newGameObject.GetComponent <NetworkIdentity>(); if (component == null) { if (LogFilter.logError) { Debug.LogError("Client object spawned for " + s_ObjectSpawnMessage.assetId + " does not have a NetworkIdentity"); } } else { component.Reset(); ApplySpawnPayload(component, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.payload, s_ObjectSpawnMessage.netId, newGameObject); } } else { SpawnDelegate delegate2; if (NetworkScene.GetSpawnHandler(s_ObjectSpawnMessage.assetId, out delegate2)) { GameObject obj4 = delegate2(s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.assetId); if (obj4 == null) { if (LogFilter.logWarn) { Debug.LogWarning("Client spawn handler for " + s_ObjectSpawnMessage.assetId + " returned null"); } } else { component = obj4.GetComponent <NetworkIdentity>(); if (component == null) { if (LogFilter.logError) { Debug.LogError("Client object spawned for " + s_ObjectSpawnMessage.assetId + " does not have a network identity"); } } else { component.Reset(); component.SetDynamicAssetId(s_ObjectSpawnMessage.assetId); ApplySpawnPayload(component, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.payload, s_ObjectSpawnMessage.netId, obj4); } } } else if (LogFilter.logError) { Debug.LogError(string.Concat(new object[] { "Failed to spawn server object, assetId=", s_ObjectSpawnMessage.assetId, " netId=", s_ObjectSpawnMessage.netId })); } } } } }
internal virtual void Update() { if (this.m_ClientId == -1) { return; } switch (this.m_AsyncConnect) { case NetworkClient.ConnectState.None: break; case NetworkClient.ConnectState.Resolving: break; case NetworkClient.ConnectState.Resolved: this.m_AsyncConnect = NetworkClient.ConnectState.Connecting; this.ContinueConnect(); break; case NetworkClient.ConnectState.Disconnected: break; case NetworkClient.ConnectState.Failed: this.GenerateConnectError(11); this.m_AsyncConnect = NetworkClient.ConnectState.Disconnected; break; default: if (this.m_Connection != null && (int)Time.time != this.m_StatResetTime) { this.m_Connection.ResetStats(); this.m_StatResetTime = (int)Time.time; } NetworkEventType fromHost; do { int num1 = 0; int connectionId; int channelId; int receivedSize; byte error; fromHost = NetworkTransport.ReceiveFromHost(this.m_ClientId, out connectionId, out channelId, this.m_MsgBuffer, (int)(ushort)this.m_MsgBuffer.Length, out receivedSize, out error); if (fromHost != NetworkEventType.Nothing && LogFilter.logDev) { Debug.Log((object)("Client event: host=" + (object)this.m_ClientId + " event=" + (object)fromHost + " error=" + (object)error)); } switch (fromHost) { case NetworkEventType.DataEvent: if ((int)error != 0) { this.GenerateDataError((int)error); return; } NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, (short)29, "msg", 1); this.m_MsgReader.SeekZero(); this.m_Connection.TransportRecieve(this.m_MsgBuffer, receivedSize, channelId); goto case NetworkEventType.Nothing; case NetworkEventType.ConnectEvent: if (LogFilter.logDebug) { Debug.Log((object)"Client connected"); } if ((int)error != 0) { this.GenerateConnectError((int)error); return; } this.m_AsyncConnect = NetworkClient.ConnectState.Connected; this.m_Connection.InvokeHandlerNoData((short)32); goto case NetworkEventType.Nothing; case NetworkEventType.DisconnectEvent: if (LogFilter.logDebug) { Debug.Log((object)"Client disconnected"); } this.m_AsyncConnect = NetworkClient.ConnectState.Disconnected; if ((int)error != 0 && (int)error != 6) { this.GenerateDisconnectError((int)error); } ClientScene.HandleClientDisconnect(this.m_Connection); if (this.m_Connection != null) { this.m_Connection.InvokeHandlerNoData((short)33); goto case NetworkEventType.Nothing; } else { goto case NetworkEventType.Nothing; } case NetworkEventType.Nothing: int num2; if ((num2 = num1 + 1) >= 500) { if (LogFilter.logDebug) { Debug.Log((object)("MaxEventsPerFrame hit (" + (object)500 + ")")); goto label_34; } else { goto label_34; } } else { continue; } default: if (LogFilter.logError) { Debug.LogError((object)("Unknown network message type received: " + (object)fromHost)); goto case NetworkEventType.Nothing; } else { goto case NetworkEventType.Nothing; } } }while (this.m_ClientId != -1 && fromHost != NetworkEventType.Nothing); label_34: if (this.m_Connection == null || this.m_AsyncConnect != NetworkClient.ConnectState.Connected) { break; } this.m_Connection.FlushChannels(); break; } }
private static void OnObjectSpawn(NetworkMessage netMsg) { netMsg.ReadMessage <ObjectSpawnMessage>(ClientScene.s_ObjectSpawnMessage); if (!ClientScene.s_ObjectSpawnMessage.assetId.IsValid()) { if (!LogFilter.logError) { return; } Debug.LogError((object)("OnObjSpawn netId: " + (object)ClientScene.s_ObjectSpawnMessage.netId + " has invalid asset Id")); } else { if (LogFilter.logDebug) { Debug.Log((object)("Client spawn handler instantiating [netId:" + (object)ClientScene.s_ObjectSpawnMessage.netId + " asset ID:" + (object)ClientScene.s_ObjectSpawnMessage.assetId + " pos:" + (object)ClientScene.s_ObjectSpawnMessage.position + "]")); } NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, (short)3, ClientScene.GetStringForAssetId(ClientScene.s_ObjectSpawnMessage.assetId), 1); NetworkIdentity uv; if (ClientScene.s_NetworkScene.GetNetworkIdentity(ClientScene.s_ObjectSpawnMessage.netId, out uv)) { ClientScene.ApplySpawnPayload(uv, ClientScene.s_ObjectSpawnMessage.position, ClientScene.s_ObjectSpawnMessage.payload, ClientScene.s_ObjectSpawnMessage.netId, (GameObject)null); } else { GameObject prefab; if (NetworkScene.GetPrefab(ClientScene.s_ObjectSpawnMessage.assetId, out prefab)) { GameObject newGameObject = (GameObject)Object.Instantiate((Object)prefab, ClientScene.s_ObjectSpawnMessage.position, Quaternion.identity); uv = newGameObject.GetComponent <NetworkIdentity>(); if ((Object)uv == (Object)null) { if (!LogFilter.logError) { return; } Debug.LogError((object)("Client object spawned for " + (object)ClientScene.s_ObjectSpawnMessage.assetId + " does not have a NetworkIdentity")); } else { ClientScene.ApplySpawnPayload(uv, ClientScene.s_ObjectSpawnMessage.position, ClientScene.s_ObjectSpawnMessage.payload, ClientScene.s_ObjectSpawnMessage.netId, newGameObject); } } else { SpawnDelegate handler; if (NetworkScene.GetSpawnHandler(ClientScene.s_ObjectSpawnMessage.assetId, out handler)) { GameObject newGameObject = handler(ClientScene.s_ObjectSpawnMessage.position, ClientScene.s_ObjectSpawnMessage.assetId); if ((Object)newGameObject == (Object)null) { if (!LogFilter.logWarn) { return; } Debug.LogWarning((object)("Client spawn handler for " + (object)ClientScene.s_ObjectSpawnMessage.assetId + " returned null")); } else { uv = newGameObject.GetComponent <NetworkIdentity>(); if ((Object)uv == (Object)null) { if (!LogFilter.logError) { return; } Debug.LogError((object)("Client object spawned for " + (object)ClientScene.s_ObjectSpawnMessage.assetId + " does not have a network identity")); } else { uv.SetDynamicAssetId(ClientScene.s_ObjectSpawnMessage.assetId); ClientScene.ApplySpawnPayload(uv, ClientScene.s_ObjectSpawnMessage.position, ClientScene.s_ObjectSpawnMessage.payload, ClientScene.s_ObjectSpawnMessage.netId, newGameObject); } } } else { if (!LogFilter.logError) { return; } Debug.LogError((object)("Failed to spawn server object, assetId=" + (object)ClientScene.s_ObjectSpawnMessage.assetId + " netId=" + (object)ClientScene.s_ObjectSpawnMessage.netId)); } } } } }
internal bool SendBytes(byte[] bytes, int bytesToSend) { NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, 0x1c, "msg", 1); if (bytesToSend > this.m_MaxPacketSize) { byte num; if (LogFilter.logDebug) { Debug.Log(string.Concat(new object[] { "SendBytes large packet: ", bytesToSend, "channel ", this.m_ChannelId })); } if (this.m_Connection.TransportSend(bytes, bytesToSend, this.m_ChannelId, out num)) { return(true); } if (LogFilter.logError) { Debug.LogError("Failed to send big message"); } return(false); } if (!this.m_CurrentPacket.HasSpace(bytesToSend)) { if (this.m_IsReliable) { if (this.m_PendingPackets.Count == 0) { if (!this.m_CurrentPacket.SendToTransport(this.m_Connection, this.m_ChannelId)) { this.QueuePacket(); } this.m_CurrentPacket.Write(bytes, bytesToSend); return(true); } if (this.m_PendingPackets.Count >= this.m_MaxPendingPacketCount) { if (!this.m_IsBroken && LogFilter.logError) { Debug.LogError("ChannelBuffer buffer limit of " + this.m_PendingPackets.Count + " packets reached."); } this.m_IsBroken = true; return(false); } this.QueuePacket(); this.m_CurrentPacket.Write(bytes, bytesToSend); return(true); } if (!this.m_CurrentPacket.SendToTransport(this.m_Connection, this.m_ChannelId)) { if (LogFilter.logError) { Debug.Log("ChannelBuffer SendBytes no space on unreliable channel " + this.m_ChannelId); } return(false); } this.m_CurrentPacket.Write(bytes, bytesToSend); return(true); } this.m_CurrentPacket.Write(bytes, bytesToSend); if (this.maxDelay == 0f) { return(this.SendInternalBuffer()); } return(true); }