public void OnTcpReceived(BitBuffer buffer) { if (buffer.TotalBitsLeft < 8) { return; } byte packet = buffer.ReadByte(); if (packet >= TcpHandlers.Length) { return; } byte[] bytes = buffer.ReadBytes(); // ReSharper disable once ConvertToLocalFunction Action handler = () => { Action <BitBuffer> action = TcpHandlers[packet]; if (action != null) { _handlerBuffer.SetContents(bytes); action(_handlerBuffer); } }; if (!NetworkUtils.SimulateNetworkConditions || NetworkUtils.IsServer) { UnityFixedDispatcher.InvokeNoDelay(handler); } else { UnityFixedDispatcher.InvokeDelayed(NetworkUtils.SimulatedNetDelay, handler); } }
public void OnUdpReceived(IDoubleServerClient client, BitBuffer buffer, ushort packetTimestamp) { NetworkServerClient serverClient = (NetworkServerClient)client.ExtraData; if (serverClient.TakeResetPacketTimestamp()) { serverClient.LastPacketTimestamp = packetTimestamp; } else if (!DoubleProtocol.IsPacketNewest(ref serverClient.LastPacketTimestamp, packetTimestamp)) { return; } byte[] bytes = buffer.ReadBytes(); // ReSharper disable once ConvertToLocalFunction Action handler = () => { if (_server != null) { _handlerBuffer.SetContents(bytes); UdpHandler(serverClient, _handlerBuffer); } }; if (!NetworkUtils.SimulateNetworkConditions || NetworkUtils.IsLocal(serverClient.Id)) { UnityFixedDispatcher.InvokeNoDelay(handler); } else { UnityFixedDispatcher.InvokeDelayed(NetworkUtils.SimulatedNetDelay, handler); } }
public void OnUdpReceived(BitBuffer buffer, ushort packetTimestamp) { bool resetPacketTimestamp; lock (SmallLock) { resetPacketTimestamp = _resetPacketTimestamp; _resetPacketTimestamp = false; } if (resetPacketTimestamp) { _lastPacketTimestamp = packetTimestamp; } else if (!DoubleProtocol.IsPacketNewest(ref _lastPacketTimestamp, packetTimestamp)) { return; } byte[] bytes = buffer.ReadBytes(); // ReSharper disable once ConvertToLocalFunction Action handler = () => { if (_client != null) { _handlerBuffer.SetContents(bytes); UdpHandler(_handlerBuffer); } }; // ReSharper disable once PossibleNullReferenceException int netDelayIncrease = DoubleProtocol.TripTime(_client.ConnectionStartTimestamp, packetTimestamp); if (!NetworkUtils.SimulateNetworkConditions || NetworkUtils.IsServer) { UnityFixedDispatcher.InvokeNoDelay(handler); } else if (!NetworkUtils.SimulateLosingPacket) { int delay = NetworkUtils.SimulatedNetDelay; netDelayIncrease += delay; UnityFixedDispatcher.InvokeDelayed(delay, handler); } else { return; } UdpNetDelay += (netDelayIncrease - UdpNetDelay) * 0.1f; }
private void DamageApply(KeyValuePair <RealLiveBlock, uint>[] damages) { int status = 0; foreach (KeyValuePair <RealLiveBlock, uint> damage in damages) { Health -= damage.Value; if (Health * 100 < MaxHealth * MinHealthPercentage) { status = 1; break; } RealLiveBlock block = damage.Key; if (block.Health == 0) { if (block.Info.Type == BlockType.Mainframe) { status = 1; break; } else { RemoveBlock(block); status = 2; } } } if (status == 1) { Destroy(gameObject); UnityFixedDispatcher.InvokeDelayed(1000, () => LocalPlayingPlayerInitializer.RespawnPlayerStructure(Id)); } else if (status == 2) { RemoveNotConnectedBlocks(); ApplyMass(true); } }
public void OnTcpReceived(IDoubleServerClient client, BitBuffer buffer) { if (buffer.TotalBitsLeft < 8) { return; } byte packet = buffer.ReadByte(); if (packet >= TcpHandlers.Length) { return; } byte[] bytes = buffer.ReadBytes(); NetworkServerClient serverClient = (NetworkServerClient)client.ExtraData; // ReSharper disable once ConvertToLocalFunction Action handler = () => { if (_server != null) { OnPacketReceived action = TcpHandlers[packet]; if (action != null) { _handlerBuffer.SetContents(bytes); action((NetworkServerClient)client.ExtraData, _handlerBuffer); } } }; if (!NetworkUtils.SimulateNetworkConditions || NetworkUtils.IsLocal(serverClient.Id)) { UnityFixedDispatcher.InvokeNoDelay(handler); } else { UnityFixedDispatcher.InvokeDelayed(NetworkUtils.SimulatedNetDelay, handler); } }