public NetStream BeginEvent(NetIdentity identity) { if (eventStream == null) { eventStream = NetStream.AllocStream(); } eventStream.WriteNetId(identity.sceneId); return(eventStream); }
public bool GetState(int frame, float fraction, out int frame0id, out NetStream frame0, out NetStream frame1, out float mix) { frame0 = null; frame1 = null; frame0id = -1; try { for (int num = frameQueue.Count - 1; num >= 0; num--) { FrameState frameState = frameQueue[num]; if (frameState.frameId <= frame) { FrameState frameState2 = frameQueue[num]; frame0id = frameState2.frameId; if (num < frameQueue.Count - 1) { FrameState frameState3 = frameQueue[num + 1]; int frameId = frameState3.frameId; if (AllowDiscontinuous && frameId >= frame0id + 60) { if ((float)(frameId - frame) <= 0.25f + fraction) { FrameState frameState4 = frameQueue[num + 1]; frame1 = NetStream.AllocStream(frameState4.stream); frame0 = NetStream.AllocStream(frame1); frame0id = frameId; mix = 1f; return(true); } FrameState frameState5 = frameQueue[num]; frame0 = NetStream.AllocStream(frameState5.stream); frame1 = NetStream.AllocStream(frame0); mix = 0f; return(true); } FrameState frameState6 = frameQueue[num]; frame0 = NetStream.AllocStream(frameState6.stream); FrameState frameState7 = frameQueue[num + 1]; frame1 = NetStream.AllocStream(frameState7.stream); mix = ((float)(frame - frame0id) + fraction) / (float)(frameId - frame0id); return(true); } FrameState frameState8 = frameQueue[num]; frame0 = NetStream.AllocStream(frameState8.stream); frame1 = NetStream.AllocStream(frame0); mix = 0f; return(true); } } mix = 0f; return(false); } catch (Exception) { if (frame0 != null) { frame0 = frame0.Release(); } if (frame1 != null) { frame1 = frame1.Release(); } throw; } }
public void OnReceiveDelta(NetStream delta, int containerFrameId) { if (exitingLevel || !isStarted) { return; } int num = delta.ReadFrameId(containerFrameId); int num2 = delta.ReadFrameId(containerFrameId); if (num > 0) { NetGame.instance.clientLatency.ReportLatency(num2 - num - 1 + lagReceiveToRender); } NetGame.instance.clientBuffer.ReportLatency(maxLagFrames); bool flag = true; NetStream netStream; lock (frames.framesLock) { frames.DropOldStates(Mathf.Min(num, lastFrame0idx)); lastBaseFrame = num; if (frames.TestForState(num2) != -1) { frames.LimitHistory(); netStream = null; flag = false; } else { netStream = frames.GetState(num, rewind: true); if (netStream == null && num > 0) { return; } } } if (flag) { NetStream netStream2 = NetStream.AllocStream(); for (int i = 0; i < list.Count; i++) { list[i].AddDelta(netStream, delta, netStream2); } ReportDeltaBits(delta.position); lock (frames.framesLock) { frames.PushState(num2, netStream2); frames.LimitHistory(); } } int writeFrameId = NetGame.instance.server.GetWriteFrameId(num2); NetStream netStream3 = NetGame.BeginMessage(NetMsgId.Delta); try { netStream3.WriteNetId(netId); netStream3.WriteFrameId(num2, writeFrameId); NetGame.instance.SendUnreliableToServer(netStream3, writeFrameId); ackBps.ReportBits(netStream3.position); } finally { if (netStream3 != null) { netStream3 = netStream3.Release(); } } }
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(); } } }
public void Collect() { bool flag = !NetGame.isClient && !ReplayRecorder.isPlaying; if (!isMasterSet || isMaster != flag) { isMasterSet = true; isMaster = flag; for (int i = 0; i < list.Count; i++) { list[i].SetMaster(isMaster); } } if (!exitingLevel && (NetGame.isServer || ReplayRecorder.isRecording)) { bool flag2 = !AllowSuspendCollect || !SuspendCollect || SnapshotCollect || ReplayRecorder.isRecording || !NetGame.isServer; SnapshotCollect = false; NetStream netStream = null; NetStream netStream2 = null; try { if (flag2) { netStream = NetStream.AllocStream(); for (int j = 0; j < list.Count; j++) { list[j].CollectState(netStream); } } if (eventStream != null && eventStream.position > 0) { eventStream.WriteNetId(0u); netStream2 = eventStream; eventStream = null; } if (ReplayRecorder.isRecording) { ReplayRecorder.instance.SubmitFrame(this, netStream, netStream2); } if (NetGame.isServer) { lock (remoteStates) { lock (frames.framesLock) { int num = 0; if (frames.frameQueue.Count > 0) { FrameState frameState = frames.frameQueue[0]; num = frameState.frameId; } int num2 = NetGame.serverFrameId - 60; foreach (KeyValuePair <uint, RemoteState> remoteState in remoteStates) { RemoteState value = remoteState.Value; if (value.acknowledgedFrame > 0) { if (value.acknowledgedFrame < num) { value.acknowledgedFrame = -1; } else { num2 = Mathf.Min(num2, value.acknowledgedFrame); } } if (value.firstFullStateFrame > 0) { if (value.firstFullStateFrame < num) { value.firstFullStateFrame = num; } else { num2 = Mathf.Min(num2, value.firstFullStateFrame); } } } if (frames.frameQueue.Count > 0) { int a = num2; FrameState frameState2 = frames.frameQueue[frames.frameQueue.Count - 1]; num2 = Mathf.Min(a, frameState2.frameId); } frames.DropOldEvents(NetGame.serverFrameId - 10); if (netStream2 != null) { frames.PushEvents(NetGame.serverFrameId, netStream2); } netStream2 = null; frames.DropOldStates(num2); if (netStream != null) { frames.PushState(NetGame.serverFrameId, netStream.AddRef()); } frames.LimitHistory(); if (NetGame.currentLevelInstanceID != 0 || !NetGame.isServer || this is NetPlayer) { bool flag3 = false; try { int frameId = NetGame.serverFrameId; if (netStream == null) { int num3 = frames.frameQueue.Count - 1; if (num3 >= 0) { FrameState frameState3 = frames.frameQueue[num3]; frameId = frameState3.frameId; FrameState frameState4 = frames.frameQueue[num3]; netStream = frameState4.stream.AddRef(); flag3 = true; } } if (netStream != null) { NetGame.instance.NotifyClients(this, frameId, NetGame.serverFrameId, netStream); } } finally { if (flag3 && netStream != null) { netStream = netStream.Release(); } } } } } } } finally { if (netStream != null) { netStream = netStream.Release(); } if (netStream2 != null) { netStream2 = netStream2.Release(); } } } }