Esempio n. 1
0
        public void OnReceiveEvents(NetStream events, int containerFrameId)
        {
            if (!isStarted)
            {
                return;
            }
            for (int num = events.ReadFrameId(containerFrameId); num > 0; num = events.ReadFrameId(containerFrameId))
            {
                NetStream netStream = events.ReadStream(forceIndependent: true);
                if (num > lastReceivedEventFrame)
                {
                    lock (frames.framesLock)
                    {
                        frames.PushEvents(num, netStream);
                    }
                    lastReceivedEventFrame = num;
                }
                else
                {
                    netStream.Release();
                }
            }
            ReportEvenBits(events.position);
            int       writeFrameId = NetGame.instance.server.GetWriteFrameId(containerFrameId);
            NetStream netStream2   = NetGame.BeginMessage(NetMsgId.Event);

            try
            {
                netStream2.WriteNetId(netId);
                netStream2.WriteFrameId(lastReceivedEventFrame, writeFrameId);
                NetGame.instance.SendUnreliableToServer(netStream2, writeFrameId);
                ackBps.ReportBits(netStream2.position);
            }
            finally
            {
                if (netStream2 != null)
                {
                    netStream2 = netStream2.Release();
                }
            }
        }
Esempio n. 2
0
        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();
                }
            }
        }
Esempio n. 3
0
        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();
                }
            }
        }