Beispiel #1
0
        internal void SendNetworkSimulated(PeerBase.MyAction sendAction)
        {
            bool flag = !this.NetworkSimulationSettings.IsSimulationEnabled;

            if (flag)
            {
                sendAction();
            }
            else
            {
                bool flag2 = this.usedProtocol == ConnectionProtocol.Udp && this.NetworkSimulationSettings.OutgoingLossPercentage > 0 && this.lagRandomizer.Next(101) < this.NetworkSimulationSettings.OutgoingLossPercentage;
                if (flag2)
                {
                    NetworkSimulationSet expr_62 = this.networkSimulationSettings;
                    int lostPackagesOut          = expr_62.LostPackagesOut;
                    expr_62.LostPackagesOut = lostPackagesOut + 1;
                }
                else
                {
                    int            num   = (this.networkSimulationSettings.OutgoingJitter <= 0) ? 0 : (this.lagRandomizer.Next(this.networkSimulationSettings.OutgoingJitter * 2) - this.networkSimulationSettings.OutgoingJitter);
                    int            num2  = this.networkSimulationSettings.OutgoingLag + num;
                    int            num3  = SupportClass.GetTickCount() + num2;
                    SimulationItem value = new SimulationItem
                    {
                        ActionToExecute = sendAction,
                        TimeToExecute   = num3,
                        Delay           = num2
                    };
                    LinkedList <SimulationItem> netSimListOutgoing = this.NetSimListOutgoing;
                    lock (netSimListOutgoing)
                    {
                        bool flag3 = this.NetSimListOutgoing.Count == 0 || this.usedProtocol == ConnectionProtocol.Tcp;
                        if (flag3)
                        {
                            this.NetSimListOutgoing.AddLast(value);
                        }
                        else
                        {
                            LinkedListNode <SimulationItem> linkedListNode = this.NetSimListOutgoing.First;
                            while (linkedListNode != null && linkedListNode.Value.TimeToExecute < num3)
                            {
                                linkedListNode = linkedListNode.Next;
                            }
                            bool flag4 = linkedListNode == null;
                            if (flag4)
                            {
                                this.NetSimListOutgoing.AddLast(value);
                            }
                            else
                            {
                                this.NetSimListOutgoing.AddBefore(linkedListNode, value);
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        internal void EnqueueActionForDispatch(PeerBase.MyAction action)
        {
            Queue <PeerBase.MyAction> actionQueue = this.ActionQueue;

            lock (actionQueue)
            {
                this.ActionQueue.Enqueue(action);
            }
        }
Beispiel #3
0
 internal void ReceiveNetworkSimulated(PeerBase.MyAction receiveAction)
 {
     if (!this.networkSimulationSettings.IsSimulationEnabled)
     {
         receiveAction();
     }
     else if (this.usedProtocol == ConnectionProtocol.Udp && this.networkSimulationSettings.IncomingLossPercentage > 0 && this.lagRandomizer.Next(101) < this.networkSimulationSettings.IncomingLossPercentage)
     {
         ++this.networkSimulationSettings.LostPackagesIn;
     }
     else
     {
         int            num1           = this.networkSimulationSettings.IncomingLag + (this.networkSimulationSettings.IncomingJitter <= 0 ? 0 : this.lagRandomizer.Next(this.networkSimulationSettings.IncomingJitter * 2) - this.networkSimulationSettings.IncomingJitter);
         int            num2           = SupportClass.GetTickCount() + num1;
         SimulationItem simulationItem = new SimulationItem()
         {
             ActionToExecute = receiveAction,
             TimeToExecute   = num2,
             Delay           = num1
         };
         lock (this.NetSimListIncoming)
         {
             if (this.NetSimListIncoming.Count == 0 || this.usedProtocol == ConnectionProtocol.Tcp)
             {
                 this.NetSimListIncoming.AddLast(simulationItem);
             }
             else
             {
                 LinkedListNode <SimulationItem> node = this.NetSimListIncoming.First;
                 while (node != null && node.Value.TimeToExecute < num2)
                 {
                     node = node.Next;
                 }
                 if (node == null)
                 {
                     this.NetSimListIncoming.AddLast(simulationItem);
                 }
                 else
                 {
                     this.NetSimListIncoming.AddBefore(node, simulationItem);
                 }
             }
         }
     }
 }
Beispiel #4
0
 internal void EnqueueActionForDispatch(PeerBase.MyAction action)
 {
     lock (this.ActionQueue)
         this.ActionQueue.Enqueue(action);
 }