internal static void Send(byte messageType, string channelName, BitStream messageStream, SecuritySendFlags flags) { bool encrypted = ((flags & SecuritySendFlags.Encrypted) == SecuritySendFlags.Encrypted) && netManager.NetworkConfig.EnableEncryption; bool authenticated = ((flags & SecuritySendFlags.Authenticated) == SecuritySendFlags.Authenticated) && netManager.NetworkConfig.EnableEncryption; if (authenticated || encrypted) { for (int i = 0; i < netManager.ConnectedClientsList.Count; i++) { Send(netManager.ConnectedClientsList[i].ClientId, messageType, channelName, messageStream, flags); } } else { messageStream.PadStream(); using (BitStream stream = MessageManager.WrapMessage(messageType, 0, messageStream, flags)) { NetworkProfiler.StartEvent(TickType.Send, (uint)stream.Length, channelName, MLAPIConstants.MESSAGE_NAMES[messageType]); for (int i = 0; i < netManager.ConnectedClientsList.Count; i++) { if (NetworkingManager.singleton.isServer && netManager.ConnectedClientsList[i].ClientId == NetworkingManager.singleton.ServerClientId) { continue; } byte error; netManager.NetworkConfig.NetworkTransport.QueueMessageForSending(netManager.ConnectedClientsList[i].ClientId, stream.GetBuffer(), (int)stream.Length, MessageManager.channels[channelName], false, out error); } NetworkProfiler.EndEvent(); } } }
virtual public void Connect(string ip, int port) { Debug.Log("Network.Connect " + m_strName); if (m_profiler == null) { m_profiler = new NetworkProfiler(this); } if (m_client == null) { Debug.Log("New TcpClient " + m_strName); m_client = new TcpClient(); m_client.ReceiveTimeout = m_iReceiveTimeout * 1000; // m_client.Client.ReceiveTimeout = m_iReceiveTimeout*1000; m_client.NoDelay = true; m_client.Client.NoDelay = true; } if (m_client.Connected) { Debug.Log("server: " + m_strName + " already connected."); return; } Debug.Log("Queue _Connect " + m_strName); if (!ThreadPool.QueueUserWorkItem(_Connect, new object[2] { ip, port })) { Debug.LogError("Queue _Connect failed, " + m_strName); } }
internal static void PassthroughSend(uint targetId, uint sourceId, ushort messageType, int channelId, BitReader reader, uint?networkId = null, ushort?orderId = null) { if (netManager.isHost && targetId == netManager.NetworkConfig.NetworkTransport.HostDummyId) { //Host trying to send data to it's own client return; } using (BitWriter writer = BitWriter.Get()) { writer.WriteGenericMessageHeader(messageType, networkId != null, networkId.GetValueOrDefault(), orderId.GetValueOrDefault(), true, null, sourceId); #if !DISABLE_CRYPTOGRAPHY if (netManager.NetworkConfig.EncryptedChannelsHashSet.Contains(MessageManager.reverseChannels[channelId])) { writer.WriteByteArray(CryptographyHelper.Encrypt(reader.ReadByteArray(), netManager.connectedClients[targetId].AesKey)); } else #endif writer.WriteByteArray(reader.ReadByteArray()); writer.Finalize(ref FinalMessageBuffer); byte error; int byteCount = (int)writer.GetFinalizeSize(); NetworkProfiler.addBytesSent((uint)byteCount); netManager.NetworkConfig.NetworkTransport.QueueMessageForSending(targetId, ref FinalMessageBuffer, byteCount, channelId, false, out error); } }
internal static void Send(byte messageType, NetworkChannel networkChannel, ulong clientIdToIgnore, NetworkBuffer messageBuffer) { messageBuffer.PadBuffer(); using (var buffer = MessagePacker.WrapMessage(messageType, messageBuffer)) { #if !UNITY_2020_2_OR_NEWER NetworkProfiler.StartEvent(TickType.Send, (uint)buffer.Length, networkChannel, NetworkConstants.MESSAGE_NAMES[messageType]); #endif for (int i = 0; i < NetworkManager.Singleton.ConnectedClientsList.Count; i++) { if (NetworkManager.Singleton.ConnectedClientsList[i].ClientId == clientIdToIgnore || (NetworkManager.Singleton.IsServer && NetworkManager.Singleton.ConnectedClientsList[i].ClientId == NetworkManager.Singleton.ServerClientId)) { continue; } NetworkManager.Singleton.NetworkConfig.NetworkTransport.Send(NetworkManager.Singleton.ConnectedClientsList[i].ClientId, new ArraySegment <byte>(buffer.GetBuffer(), 0, (int)buffer.Length), networkChannel); ProfilerStatManager.BytesSent.Record((int)buffer.Length); PerformanceDataManager.Increment(ProfilerConstants.ByteSent, (int)buffer.Length); } #if !UNITY_2020_2_OR_NEWER NetworkProfiler.EndEvent(); #endif } }
internal void Send(byte messageType, NetworkChannel networkChannel, List <ulong> clientIds, NetworkBuffer messageBuffer) { if (clientIds == null) { Send(messageType, networkChannel, messageBuffer); return; } messageBuffer.PadBuffer(); using (var buffer = MessagePacker.WrapMessage(messageType, messageBuffer)) { #if !UNITY_2020_2_OR_NEWER NetworkProfiler.StartEvent(TickType.Send, (uint)buffer.Length, networkChannel, NetworkConstants.MESSAGE_NAMES[messageType]); #endif for (int i = 0; i < clientIds.Count; i++) { if (m_NetworkManager.IsServer && clientIds[i] == m_NetworkManager.ServerClientId) { continue; } m_NetworkManager.NetworkConfig.NetworkTransport.Send(clientIds[i], new ArraySegment <byte>(buffer.GetBuffer(), 0, (int)buffer.Length), networkChannel); ProfilerStatManager.BytesSent.Record((int)buffer.Length); PerformanceDataManager.Increment(ProfilerConstants.ByteSent, (int)buffer.Length); } #if !UNITY_2020_2_OR_NEWER NetworkProfiler.EndEvent(); #endif } }
internal static void Send(uint clientId, byte messageType, string channelName, Stream messageStream, bool skipQueue = false) { if (NetworkingManager.singleton.isServer && clientId == NetworkingManager.singleton.ServerClientId) { return; } using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteByte(messageType); stream.CopyFrom(messageStream); NetworkProfiler.StartEvent(TickType.Send, (uint)stream.Length, channelName, MLAPIConstants.MESSAGE_NAMES[messageType]); byte error; if (skipQueue) { netManager.NetworkConfig.NetworkTransport.QueueMessageForSending(clientId, stream.GetBuffer(), (int)stream.Length, MessageManager.channels[channelName], true, out error); } else { netManager.NetworkConfig.NetworkTransport.QueueMessageForSending(clientId, stream.GetBuffer(), (int)stream.Length, MessageManager.channels[channelName], false, out error); } NetworkProfiler.EndEvent(); } } }
internal static void Send(byte messageType, string channelName, uint clientIdToIgnore, Stream messageStream) { using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteByte(messageType); stream.CopyFrom(messageStream); NetworkProfiler.StartEvent(TickType.Send, (uint)stream.Length, channelName, MLAPIConstants.MESSAGE_NAMES[messageType]); for (int i = 0; i < netManager.ConnectedClientsList.Count; i++) { if (netManager.ConnectedClientsList[i].ClientId == clientIdToIgnore || (NetworkingManager.singleton.isServer && netManager.ConnectedClientsList[i].ClientId == NetworkingManager.singleton.ServerClientId)) { continue; } byte error; netManager.NetworkConfig.NetworkTransport.QueueMessageForSending(netManager.ConnectedClientsList[i].ClientId, stream.GetBuffer(), (int)stream.Length, MessageManager.channels[channelName], false, out error); } NetworkProfiler.EndEvent(); } } }
internal static void Send(ulong clientId, byte messageType, string channelName, BitStream messageStream, SecuritySendFlags flags, NetworkedObject targetObject, bool skipQueue = false) { messageStream.PadStream(); if (NetworkingManager.Singleton.IsServer && clientId == NetworkingManager.Singleton.ServerClientId) { return; } if (targetObject != null && !targetObject.observers.Contains(clientId)) { if (LogHelper.CurrentLogLevel <= LogLevel.Developer) { LogHelper.LogWarning("Silently suppressed send call because it was directed to an object without visibility"); } return; } using (BitStream stream = MessageManager.WrapMessage(messageType, clientId, messageStream, flags)) { NetworkProfiler.StartEvent(TickType.Send, (uint)stream.Length, channelName, MLAPIConstants.MESSAGE_NAMES[messageType]); NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(clientId, new ArraySegment <byte>(stream.GetBuffer(), 0, (int)stream.Length), channelName, skipQueue); NetworkProfiler.EndEvent(); } }
static int EndRecordDataUsage(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); NetworkProfiler obj = (NetworkProfiler)LuaScriptMgr.GetNetObjectSelf(L, 1, "NetworkProfiler"); obj.EndRecordDataUsage(); return(0); }
void ProfilerOutgoingMessage(ushort msgType) { #if NETWORK_PROFILER_ENABLED && UNITY_EDITOR var profilerName = new StringBuilder(DEBUGGING_NAME); profilerName.Append(msgType); NetworkProfiler.RecordMessageOutgoing(profilerName.ToString(), m_NetworkWriter.FilledLength); #endif }
static int Init(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); NetworkProfiler obj = (NetworkProfiler)LuaScriptMgr.GetNetObjectSelf(L, 1, "NetworkProfiler"); obj.Init(); return(0); }
static int RecvDataCount(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 2); NetworkProfiler obj = (NetworkProfiler)LuaScriptMgr.GetNetObjectSelf(L, 1, "NetworkProfiler"); long arg0 = (long)LuaScriptMgr.GetNumber(L, 2); obj.RecvDataCount(arg0); return(0); }
static int FixedUpdate(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 2); NetworkProfiler obj = (NetworkProfiler)LuaScriptMgr.GetNetObjectSelf(L, 1, "NetworkProfiler"); float arg0 = (float)LuaScriptMgr.GetNumber(L, 2); obj.FixedUpdate(arg0); return(0); }
//RETURNS THE CLIENTIDS WHICH WAS NOT BEING OBSERVED internal static ref List <uint> Send(string messageType, string channelName, BitWriter messageWriter, uint clientIdToIgnore, uint?fromNetId, uint?networkId = null, ushort?orderId = null) { failedObservers.Clear(); if (netManager.NetworkConfig.EncryptedChannels.Contains(channelName)) { if (LogHelper.CurrentLogLevel <= LogLevel.Normal) { LogHelper.LogWarning("Cannot send messages over encrypted channel to multiple clients"); } return(ref failedObservers); } using (BitWriter writer = BitWriter.Get()) { writer.WriteGenericMessageHeader(MessageManager.messageTypes[messageType], networkId != null, networkId.GetValueOrDefault(), orderId.GetValueOrDefault(), false, 0, 0); writer.WriteWriter(messageWriter); int channel = MessageManager.channels[channelName]; foreach (KeyValuePair <uint, NetworkedClient> pair in netManager.connectedClients) { if (pair.Key == clientIdToIgnore) { continue; } uint targetClientId = pair.Key; if (netManager.isHost && targetClientId == netManager.NetworkConfig.NetworkTransport.HostDummyId) { //Don't invoke the message on our own machine. Instant stack overflow. continue; } else if (targetClientId == netManager.NetworkConfig.NetworkTransport.HostDummyId) { //Client trying to send data to host targetClientId = netManager.NetworkConfig.NetworkTransport.ServerNetId; } //If we respect the observers, and the message is targeted (networkId != null) and the targetedNetworkId isnt observing the receiver. Then we continue if (netManager.isServer && fromNetId != null && !SpawnManager.spawnedObjects[fromNetId.Value].observers.Contains(pair.Key)) { failedObservers.Add(pair.Key); continue; } writer.Finalize(ref FinalMessageBuffer); NetworkProfiler.StartEvent(TickType.Send, (uint)messageWriter.GetFinalizeSize(), channelName, messageType); byte error; int byteCount = (int)writer.GetFinalizeSize(); NetworkProfiler.addBytesSent((uint)byteCount); netManager.NetworkConfig.NetworkTransport.QueueMessageForSending(targetClientId, ref FinalMessageBuffer, byteCount, channel, false, out error); NetworkProfiler.EndEvent(); } return(ref failedObservers); } }
void HandleDataEvent(int channelId, int receivedSize) { #if NETWORK_DEBUGGER_ENABLED UnityEngine.Debug.Log($"ClientPeer Incoming : ChannelId:{channelId} Size:{receivedSize}"); #endif #if NETWORK_PROFILER_ENABLED && UNITY_EDITOR var profilerName = new StringBuilder(PROFILER_CATEGORY_PREFIX); profilerName.Append(channelId); NetworkProfiler.RecordChannelIncoming(profilerName.ToString(), (ushort)receivedSize); #endif DataEvent?.Invoke(channelId, m_RecievedBuffer, receivedSize); }
internal static void Send(byte messageType, string channelName, ulong clientIdToIgnore, BitStream messageStream, SecuritySendFlags flags, NetworkedObject targetObject) { bool encrypted = ((flags & SecuritySendFlags.Encrypted) == SecuritySendFlags.Encrypted) && NetworkingManager.Singleton.NetworkConfig.EnableEncryption; bool authenticated = ((flags & SecuritySendFlags.Authenticated) == SecuritySendFlags.Authenticated) && NetworkingManager.Singleton.NetworkConfig.EnableEncryption; if (encrypted || authenticated) { for (int i = 0; i < NetworkingManager.Singleton.ConnectedClientsList.Count; i++) { if (NetworkingManager.Singleton.ConnectedClientsList[i].ClientId == clientIdToIgnore) { continue; } Send(NetworkingManager.Singleton.ConnectedClientsList[i].ClientId, messageType, channelName, messageStream, flags, targetObject); } } else { messageStream.PadStream(); using (BitStream stream = MessageManager.WrapMessage(messageType, 0, messageStream, flags)) { NetworkProfiler.StartEvent(TickType.Send, (uint)stream.Length, channelName, MLAPIConstants.MESSAGE_NAMES[messageType]); for (int i = 0; i < NetworkingManager.Singleton.ConnectedClientsList.Count; i++) { if (NetworkingManager.Singleton.ConnectedClientsList[i].ClientId == clientIdToIgnore || (NetworkingManager.Singleton.IsServer && NetworkingManager.Singleton.ConnectedClientsList[i].ClientId == NetworkingManager.Singleton.ServerClientId)) { continue; } if (targetObject != null && !targetObject.observers.Contains(NetworkingManager.Singleton.ConnectedClientsList[i].ClientId)) { if (LogHelper.CurrentLogLevel <= LogLevel.Developer) { LogHelper.LogWarning("Silently suppressed send(ignore) call because it was directed to an object without visibility"); } continue; } NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(NetworkingManager.Singleton.ConnectedClientsList[i].ClientId, new ArraySegment <byte>(stream.GetBuffer(), 0, (int)stream.Length), channelName, false); } NetworkProfiler.EndEvent(); } } }
internal static void Send(uint[] clientIds, string messageType, string channelName, BitWriter messageWriter, uint?fromNetId, uint?networkId = null, ushort?orderId = null) { if (netManager.NetworkConfig.EncryptedChannelsHashSet.Contains(channelName)) { if (LogHelper.CurrentLogLevel <= LogLevel.Normal) { LogHelper.LogWarning("Cannot send messages over encrypted channel to multiple clients"); } return; } using (BitWriter writer = BitWriter.Get()) { writer.WriteGenericMessageHeader(MessageManager.messageTypes[messageType], networkId != null, networkId.GetValueOrDefault(), orderId.GetValueOrDefault(), false, 0, 0); writer.WriteWriter(messageWriter); int channel = MessageManager.channels[channelName]; for (int i = 0; i < clientIds.Length; i++) { uint targetClientId = clientIds[i]; if (netManager.isHost && targetClientId == netManager.NetworkConfig.NetworkTransport.HostDummyId) { //Don't invoke the message on our own machine. Instant stack overflow. continue; } else if (targetClientId == netManager.NetworkConfig.NetworkTransport.HostDummyId) { //Client trying to send data to host targetClientId = netManager.NetworkConfig.NetworkTransport.ServerNetId; } //If we respect the observers, and the message is targeted (networkId != null) and the targetedNetworkId isnt observing the receiver. Then we continue if (netManager.isServer && fromNetId != null && !SpawnManager.spawnedObjects[fromNetId.Value].observers.Contains(clientIds[i])) { continue; } writer.Finalize(ref FinalMessageBuffer); NetworkProfiler.StartEvent(TickType.Send, (uint)messageWriter.GetFinalizeSize(), channelName, messageType); byte error; netManager.NetworkConfig.NetworkTransport.QueueMessageForSending(targetClientId, ref FinalMessageBuffer, (int)writer.GetFinalizeSize(), channel, false, out error); NetworkProfiler.EndEvent(); } } }
static int _CreateNetworkProfiler(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 1) { NetworkConn arg0 = (NetworkConn)LuaScriptMgr.GetNetObject(L, 1, typeof(NetworkConn)); NetworkProfiler obj = new NetworkProfiler(arg0); LuaScriptMgr.PushObject(L, obj); return(1); } else { LuaDLL.luaL_error(L, "invalid arguments to method: NetworkProfiler.New"); } return(0); }
public bool Send(int channelId, byte[] buffer, int length) { #if NETWORK_DEBUGGER_ENABLED UnityEngine.Debug.Log($"ClientPeer Outgoing : ChannelId:{channelId} Size:{length}"); #endif byte error; UNET.NetworkTransport.Send(m_Connection.SocketId, m_Connection.ConnectionId, channelId, buffer, length, out error); #if NETWORK_PROFILER_ENABLED && UNITY_EDITOR var profilerName = new StringBuilder(PROFILER_CATEGORY_PREFIX); profilerName.Append(channelId); NetworkProfiler.RecordChannelOutgoing(profilerName.ToString(), (ushort)length); #endif m_Connection.LastError = (NetworkError)error; return(m_Connection.LastError == NetworkError.None); }
private void StartRecording() { if (NetworkProfiler.IsRunning) { StopRecording(); } if (NetworkProfiler.Ticks != null && NetworkProfiler.Ticks.Count >= 2) { m_Curve = AnimationCurve.Constant(NetworkProfiler.Ticks.ElementAt(0).Frame, NetworkProfiler.Ticks.ElementAt(NetworkProfiler.Ticks.Count - 1).Frame, 0); } else { m_Curve = AnimationCurve.Constant(0, 1, 0); } m_LastDrawn = 0; NetworkProfiler.Start(m_CaptureCount); }
virtual public void Close() { Debug.Log("Close conn:" + m_strName); if (m_stream == null) { return; } if (m_client == null) { return; } m_readTimeCounter = 0.0f; m_beginRead = false; m_profiler = null; m_serverDisconnectedFlag_Initiative = true; if (IsConnected() && IsSocketConnected()) { try { m_client.Client.Shutdown(SocketShutdown.Both); } catch (SocketException ex) { Debug.LogWarning("Shutdown socket, " + ex.Message); } } if (m_type == Type.eVirtualServer) { if (m_recvMsgThread != null) { m_recvMsgThread.Join(); } } //m_client.GetStream().Close(); m_client.Close(); NotifyAllListener(NetworkEvent.disconnected); }
void HandleDataEvent(int channelId, byte[] buffer, int length) { var lastIndex = length - 1; m_NetworkReader.SeekZero(); MessageHandlerDelegate handler; while (m_NetworkReader.Position < lastIndex) { m_NetworkReader.Lock(HEADER_BYTE_COUNT); // the reader passed to user code has a copy of bytes from the real stream. user code never touches the real stream. // this ensures it can never get out of sync if user code reads less or more than the real amount. ushort msgSize = m_NetworkReader.ReadUInt16(); ushort msgType = m_NetworkReader.ReadUInt16(); #if NETWORK_DEBUGGER_ENABLED UnityEngine.Debug.Log($"{DEBUGGING_NAME} Incoming : MsgType:{msgType}, ChannelId:{channelId} Size:{msgSize}"); #endif #if NETWORK_PROFILER_ENABLED && UNITY_EDITOR var profilerName = new StringBuilder(DEBUGGING_NAME); profilerName.Append(msgType); NetworkProfiler.RecordMessageIncoming(profilerName.ToString(), msgSize); #endif m_NetworkReader.Lock((ushort)(msgSize - HEADER_BYTE_COUNT)); if (m_Handlers.TryGetValue(msgType, out handler)) { handler.Invoke(m_ClientPeer.Connection, m_NetworkReader); } else { UnityEngine.Debug.LogWarning($"Unknown message ID {msgType} from channel:{channelId}"); } m_NetworkReader.CheckReading(); } }
internal static void Send(ulong clientId, byte messageType, NetworkChannel networkChannel, NetworkBuffer messageBuffer) { messageBuffer.PadBuffer(); if (NetworkManager.Singleton.IsServer && clientId == NetworkManager.Singleton.ServerClientId) { return; } using (var buffer = MessagePacker.WrapMessage(messageType, messageBuffer)) { NetworkProfiler.StartEvent(TickType.Send, (uint)buffer.Length, networkChannel, NetworkConstants.MESSAGE_NAMES[messageType]); NetworkManager.Singleton.NetworkConfig.NetworkTransport.Send(clientId, new ArraySegment <byte>(buffer.GetBuffer(), 0, (int)buffer.Length), networkChannel); ProfilerStatManager.BytesSent.Record((int)buffer.Length); PerformanceDataManager.Increment(ProfilerConstants.ByteSent, (int)buffer.Length); #if !UNITY_2020_2_OR_NEWER NetworkProfiler.EndEvent(); #endif } }
static int get_m_dataUsage(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); NetworkProfiler obj = (NetworkProfiler)o; if (obj == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name m_dataUsage"); } else { LuaDLL.luaL_error(L, "attempt to index m_dataUsage on a nil value"); } } LuaScriptMgr.Push(L, obj.m_dataUsage); return(1); }
void HandleData(int connectionId, int channelId, int receivedSize, NetworkError error) { var client = FindConnection(connectionId); if (client == null) { return; } client.LastError = error; #if NETWORK_DEBUGGER_ENABLED UnityEngine.Debug.Log($"ServerPeer Incoming : ConnectionId:{connectionId}, Size:{receivedSize}"); #endif #if NETWORK_PROFILER_ENABLED && UNITY_EDITOR var profilerName = new StringBuilder(PROFILER_CATEGORY_PREFIX); profilerName.Append(channelId); NetworkProfiler.RecordChannelIncoming(profilerName.ToString(), (ushort)receivedSize); #endif DataEvent?.Invoke(client, channelId, m_RecievedBuffer, receivedSize); }
internal static void Send(uint clientId, byte messageType, string channelName, BitStream messageStream, SecuritySendFlags flags, bool skipQueue = false) { messageStream.PadStream(); if (NetworkingManager.singleton.isServer && clientId == NetworkingManager.singleton.ServerClientId) { return; } using (BitStream stream = MessageManager.WrapMessage(messageType, clientId, messageStream, flags)) { NetworkProfiler.StartEvent(TickType.Send, (uint)stream.Length, channelName, MLAPIConstants.MESSAGE_NAMES[messageType]); byte error; if (skipQueue) { netManager.NetworkConfig.NetworkTransport.QueueMessageForSending(clientId, stream.GetBuffer(), (int)stream.Length, MessageManager.channels[channelName], true, out error); } else { netManager.NetworkConfig.NetworkTransport.QueueMessageForSending(clientId, stream.GetBuffer(), (int)stream.Length, MessageManager.channels[channelName], false, out error); } NetworkProfiler.EndEvent(); } }
//RETURNS IF IT SUCCEDED OR FAILED BECAUSE OF NON-OBSERVER. ANY OTHER FAIL WILL RETURN TRUE internal static bool Send(uint clientId, string messageType, string channelName, BitWriter messageWriter, uint?fromNetId, uint?networkId = null, ushort?orderId = null, bool skipQueue = false) { uint targetClientId = clientId; if (netManager.isHost && targetClientId == netManager.NetworkConfig.NetworkTransport.HostDummyId) { //Don't invoke the message on our own machine. Instant stack overflow. return(true); } else if (targetClientId == netManager.NetworkConfig.NetworkTransport.HostDummyId) { //Client trying to send data to host targetClientId = netManager.NetworkConfig.NetworkTransport.ServerNetId; } //If we respect the observers, and the message is targeted (networkId != null) and the targetedNetworkId isnt observing the receiver. Then we return if (netManager.isServer && fromNetId != null && !SpawnManager.spawnedObjects[fromNetId.Value].observers.Contains(clientId)) { return(false); } bool isPassthrough = (!netManager.isServer && clientId != netManager.NetworkConfig.NetworkTransport.ServerNetId && netManager.NetworkConfig.AllowPassthroughMessages); if (isPassthrough && !netManager.NetworkConfig.PassthroughMessageHashSet.Contains(MessageManager.messageTypes[messageType])) { if (LogHelper.CurrentLogLevel <= LogLevel.Normal) { LogHelper.LogWarning("The The MessageType " + messageType + " is not registered as an allowed passthrough message type"); } return(true); } using (BitWriter writer = BitWriter.Get()) { writer.WriteGenericMessageHeader(MessageManager.messageTypes[messageType], networkId != null, networkId.GetValueOrDefault(), orderId.GetValueOrDefault(), isPassthrough, clientId, null); #if !DISABLE_CRYPTOGRAPHY if (netManager.NetworkConfig.EncryptedChannelsHashSet.Contains(channelName)) { //This is an encrypted message. byte[] encrypted; if (netManager.isServer) { encrypted = CryptographyHelper.Encrypt(messageWriter.Finalize(), netManager.ConnectedClients[clientId].AesKey); } else { encrypted = CryptographyHelper.Encrypt(messageWriter.Finalize(), netManager.clientAesKey); } writer.WriteByteArray(encrypted); } else #endif writer.WriteWriter(messageWriter); if (isPassthrough) { targetClientId = netManager.NetworkConfig.NetworkTransport.ServerNetId; } writer.Finalize(ref FinalMessageBuffer); NetworkProfiler.StartEvent(TickType.Send, (uint)messageWriter.GetFinalizeSize(), channelName, messageType); byte error; if (skipQueue) { netManager.NetworkConfig.NetworkTransport.QueueMessageForSending(targetClientId, ref FinalMessageBuffer, (int)writer.GetFinalizeSize(), MessageManager.channels[channelName], true, out error); } else { netManager.NetworkConfig.NetworkTransport.QueueMessageForSending(targetClientId, ref FinalMessageBuffer, (int)writer.GetFinalizeSize(), MessageManager.channels[channelName], false, out error); } NetworkProfiler.EndEvent(); return(true); } }
private void StopRecording() { NetworkProfiler.Stop(); }