public int PlaybackEvents(NetFrames frames, int fromFrame, int toFrame) { int num = -1; int count; lock (frames.framesLock) { count = frames.eventQueue.Count; } for (int i = 0; i < count; i++) { FrameState frameState; lock (frames.framesLock) { frameState = frames.eventQueue[i]; } int frameId = frameState.frameId; if (frameId > fromFrame && frameId <= toFrame) { num = Mathf.Max(num, frameId); NetStream stream = frameState.stream; stream.Seek(0); uint num2 = stream.ReadNetId(); NetIdentity value; while (num2 != 0 && (!map.TryGetValue(num2, out value) || value.DeliverEvent(stream))) { num2 = stream.ReadNetId(); } } } return(num); }
public static NetStream AllocStream(byte[] data, int tier = -1, int offsetBits = 0, bool useRefCountOnBuffer = false, bool forceRegister = false) { lock (poolLock) { NetStream netStream = GrabStream(); if (tier >= 0) { netStream.bufferTierAndFlags = ((tier << 1) | (useRefCountOnBuffer ? 1 : 0)); if (useRefCountOnBuffer) { netStream.buffer = ReuseBuffer(data, forceRegister); } else { netStream.buffer = data; } } else { netStream.bufferTierAndFlags = -1; netStream.buffer = data; } netStream.offsetBits = offsetBits; netStream.Seek(0); return(netStream); } }
public static NetStream AllocStream(int sizeBytes = 0) { lock (poolLock) { NetStream netStream = GrabStream(); netStream.Alloc(CalculateTierForSize(sizeBytes)); netStream.offsetBits = 0; netStream.Seek(0); return(netStream); } }
public void FlushBuffer(NetTransport transport, bool skipLock = false) { lock (unreliableStreamLock) { if (unreliableStream.position != 0) { unreliableStream.WriteStream(null); transport.SendUnreliable(this, unreliableStream.GetOriginalBuffer(), unreliableStream.UseBuffedSize()); NetGame.instance.sendBps.ReportBits(unreliableStream.position); unreliableStream.Seek(0); } } }
public static NetStream AllocStream(NetStream baseStream, int offsetBits = 0) { lock (poolLock) { NetStream netStream = GrabStream(); netStream.bufferTierAndFlags = -1; netStream.masterStream = baseStream.AddRef(); netStream.buffer = baseStream.buffer; netStream.offsetBits = offsetBits; netStream.Seek(0); return(netStream); } }
public NetStream GetState(int frameId, bool rewind = false) { for (int i = 0; i < frameQueue.Count; i++) { FrameState frameState = frameQueue[i]; if (frameState.frameId == frameId) { FrameState frameState2 = frameQueue[i]; NetStream stream = frameState2.stream; if (rewind) { stream.Seek(0); } return(stream); } } return(null); }
public void NotifyClients(int serverFrameId, int timeId, NetStream fullMaster, NetHost conn) { NetStream netStream = null; int num = -1; int num2 = -1; try { lock (remoteStates) { if (conn.isDyingForScopes) { Debug.LogFormat("Attempt to send delta to client (id {0}) that is disconnecting - caught and rejected", conn.hostId); return; } RemoteState remoteState = GetRemoteState(conn.hostId); num = remoteState.acknowledgedFrame; if (num > 0) { lock (frames.framesLock) { NetStream state = frames.GetState(num); if (state != null) { netStream = NetStream.AllocStream(state); } } } if (netStream != null) { remoteState.lastFullStateFrame = -1; remoteState.firstFullStateFrame = -1; } else { int num3 = (!(suppressThrottling <= 0f)) ? 1 : 30; if (remoteState.lastFullStateFrame != -1 && timeId - remoteState.lastFullStateFrame < num3) { return; } remoteState.lastFullStateFrame = timeId; if (remoteState.firstFullStateFrame == -1) { remoteState.firstFullStateFrame = serverFrameId; } } } num2 = conn.GetWriteFrameId(serverFrameId); bool flag = true; if (AllowSuspendCollect) { flag = (netStream == null || serverFrameId != num); } if (flag) { NetStream netStream2 = NetStream.AllocStream(fullMaster); try { netStream2.Seek(0); NetStream netStream3 = NetGame.BeginMessage(NetMsgId.Delta); try { netStream3.WriteNetId(netId); netStream3.WriteFrameId((netStream != null) ? num : 0, num2); netStream3.WriteFrameId(serverFrameId, num2); if (num > 0) { NetGame.instance.clientLatency.ReportLatency(serverFrameId - num - 1); } for (int i = 0; i < list.Count; i++) { list[i].CalculateDelta(netStream, netStream2, netStream3); } NetGame.instance.SendUnreliable(conn, netStream3, num2); ReportDeltaBits(netStream3.position); } finally { if (netStream3 != null) { netStream3 = netStream3.Release(); } } } finally { if (netStream2 != null) { netStream2 = netStream2.Release(); } } } } finally { if (netStream != null) { netStream = netStream.Release(); } } num = -1; lock (remoteStates) { if (conn.isDyingForScopes) { Debug.LogFormat("Attempt to send delta to client (id {0}) that is disconnecting - caught and rejected [2]", conn.hostId); return; } num = GetRemoteState(conn.hostId).acknowledgedEvent; } NetStream netStream4 = NetGame.BeginMessage(NetMsgId.Event); try { netStream4.WriteNetId(netId); bool flag2 = false; lock (frames.framesLock) { for (int j = 0; j < frames.eventQueue.Count; j++) { FrameState frameState = frames.eventQueue[j]; if (frameState.frameId > num) { flag2 = true; NetStream netStream5 = netStream4; FrameState frameState2 = frames.eventQueue[j]; netStream5.WriteFrameId(frameState2.frameId, num2); NetStream netStream6 = netStream4; FrameState frameState3 = frames.eventQueue[j]; netStream6.WriteStream(frameState3.stream); } } } if (flag2) { netStream4.WriteFrameId(0, num2); NetGame.instance.SendUnreliable(conn, netStream4, num2); ReportEvenBits(netStream4.position); } } finally { if (netStream4 != null) { netStream4 = netStream4.Release(); } } }