Beispiel #1
0
 public void NotifyClients(NetScope scope, int frameId, int timeId, NetStream full)
 {
     lock (notifyQueueLock)
     {
         frameCapacity = clients.Count * NetScope.all.Count;
         for (int i = 0; i < clients.Count; i++)
         {
             if (clients[i].isReady)
             {
                 full.AddRef();
                 notifyQueue.Enqueue(new NotifyClientTask
                 {
                     frameID = frameId,
                     timeID  = timeId,
                     full    = full,
                     client  = clients[i],
                     scope   = scope
                 });
             }
         }
     }
     if (!threaded)
     {
         HandleNotifyQueue();
     }
 }
Beispiel #2
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);
     }
 }
Beispiel #3
0
        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();
                    }
                }
            }
        }