Example #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);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
 protected internal void NetworkSimRun()
 {
     while (true)
     {
         bool             flag = false;
         ManualResetEvent netSimManualResetEvent = this.networkSimulationSettings.NetSimManualResetEvent;
         lock (netSimManualResetEvent)
         {
             flag = this.networkSimulationSettings.IsSimulationEnabled;
         }
         if (!flag)
         {
             this.networkSimulationSettings.NetSimManualResetEvent.WaitOne();
         }
         else
         {
             LinkedList <SimulationItem> netSimListIncoming = this.NetSimListIncoming;
             lock (netSimListIncoming)
             {
                 SimulationItem simulationItem = null;
                 while (this.NetSimListIncoming.First != null)
                 {
                     simulationItem = this.NetSimListIncoming.First.Value;
                     if (simulationItem.stopw.ElapsedMilliseconds < simulationItem.Delay)
                     {
                         break;
                     }
                     this.ReceiveIncomingCommands(simulationItem.DelayedData, simulationItem.DelayedData.Length);
                     this.NetSimListIncoming.RemoveFirst();
                 }
             }
             LinkedList <SimulationItem> netSimListOutgoing = this.NetSimListOutgoing;
             lock (netSimListOutgoing)
             {
                 SimulationItem simulationItem2 = null;
                 while (this.NetSimListOutgoing.First != null)
                 {
                     simulationItem2 = this.NetSimListOutgoing.First.Value;
                     if (simulationItem2.stopw.ElapsedMilliseconds < simulationItem2.Delay)
                     {
                         break;
                     }
                     if (this.PhotonSocket != null && this.PhotonSocket.Connected)
                     {
                         this.PhotonSocket.Send(simulationItem2.DelayedData, simulationItem2.DelayedData.Length);
                     }
                     this.NetSimListOutgoing.RemoveFirst();
                 }
             }
             Thread.Sleep(0);
         }
     }
 }
Example #3
0
 protected internal void NetworkSimRun()
 {
     while (true)
     {
         bool flag = false;
         lock (this.networkSimulationSettings.NetSimManualResetEvent)
             flag = this.networkSimulationSettings.IsSimulationEnabled;
         if (!flag)
         {
             this.networkSimulationSettings.NetSimManualResetEvent.WaitOne();
         }
         else
         {
             SimulationItem simulationItem1;
             lock (this.NetSimListIncoming)
             {
                 simulationItem1 = (SimulationItem)null;
                 while (this.NetSimListIncoming.First != null)
                 {
                     SimulationItem simulationItem2 = this.NetSimListIncoming.First.Value;
                     if (simulationItem2.stopw.ElapsedMilliseconds >= (long)simulationItem2.Delay)
                     {
                         simulationItem2.ActionToExecute();
                         this.NetSimListIncoming.RemoveFirst();
                     }
                     else
                     {
                         break;
                     }
                 }
             }
             lock (this.NetSimListOutgoing)
             {
                 simulationItem1 = (SimulationItem)null;
                 while (this.NetSimListOutgoing.First != null)
                 {
                     SimulationItem simulationItem2 = this.NetSimListOutgoing.First.Value;
                     if (simulationItem2.stopw.ElapsedMilliseconds >= (long)simulationItem2.Delay)
                     {
                         simulationItem2.ActionToExecute();
                         this.NetSimListOutgoing.RemoveFirst();
                     }
                     else
                     {
                         break;
                     }
                 }
             }
             Thread.Sleep(0);
         }
     }
 }
Example #4
0
 protected internal void NetworkSimRun()
 {
     while (true)
     {
         bool             flag = false;
         ManualResetEvent netSimManualResetEvent = this.networkSimulationSettings.NetSimManualResetEvent;
         lock (netSimManualResetEvent)
         {
             flag = this.networkSimulationSettings.IsSimulationEnabled;
         }
         bool flag2 = !flag;
         if (flag2)
         {
             this.networkSimulationSettings.NetSimManualResetEvent.WaitOne();
         }
         else
         {
             LinkedList <SimulationItem> netSimListIncoming = this.NetSimListIncoming;
             lock (netSimListIncoming)
             {
                 while (this.NetSimListIncoming.First != null)
                 {
                     SimulationItem value = this.NetSimListIncoming.First.Value;
                     bool           flag3 = value.stopw.ElapsedMilliseconds < (long)value.Delay;
                     if (flag3)
                     {
                         break;
                     }
                     value.ActionToExecute();
                     this.NetSimListIncoming.RemoveFirst();
                 }
             }
             LinkedList <SimulationItem> netSimListOutgoing = this.NetSimListOutgoing;
             lock (netSimListOutgoing)
             {
                 while (this.NetSimListOutgoing.First != null)
                 {
                     SimulationItem value2 = this.NetSimListOutgoing.First.Value;
                     bool           flag4  = value2.stopw.ElapsedMilliseconds < (long)value2.Delay;
                     if (flag4)
                     {
                         break;
                     }
                     value2.ActionToExecute();
                     this.NetSimListOutgoing.RemoveFirst();
                 }
             }
             Thread.Sleep(0);
         }
     }
 }
Example #5
0
 internal void ReceiveNetworkSimulated(byte[] dataReceived)
 {
     if (!this.networkSimulationSettings.IsSimulationEnabled)
     {
         throw new NotImplementedException("ReceiveNetworkSimulated was called, despite NetworkSimulationSettings.IsSimulationEnabled == false.");
     }
     if (this.usedTransportProtocol == ConnectionProtocol.Udp && this.networkSimulationSettings.IncomingLossPercentage > 0 && this.lagRandomizer.Next(101) < this.networkSimulationSettings.IncomingLossPercentage)
     {
         this.networkSimulationSettings.LostPackagesIn++;
     }
     else
     {
         int            num   = (this.networkSimulationSettings.IncomingJitter > 0) ? (this.lagRandomizer.Next(this.networkSimulationSettings.IncomingJitter * 2) - this.networkSimulationSettings.IncomingJitter) : 0;
         int            num2  = this.networkSimulationSettings.IncomingLag + num;
         int            num3  = SupportClass.GetTickCount() + num2;
         SimulationItem value = new SimulationItem
         {
             DelayedData   = dataReceived,
             TimeToExecute = num3,
             Delay         = num2
         };
         LinkedList <SimulationItem> netSimListIncoming = this.NetSimListIncoming;
         lock (netSimListIncoming)
         {
             if (this.NetSimListIncoming.Count == 0 || this.usedTransportProtocol == ConnectionProtocol.Tcp)
             {
                 this.NetSimListIncoming.AddLast(value);
             }
             else
             {
                 LinkedListNode <SimulationItem> linkedListNode = this.NetSimListIncoming.First;
                 while (linkedListNode != null && linkedListNode.Value.TimeToExecute < num3)
                 {
                     linkedListNode = linkedListNode.Next;
                 }
                 if (linkedListNode == null)
                 {
                     this.NetSimListIncoming.AddLast(value);
                 }
                 else
                 {
                     this.NetSimListIncoming.AddBefore(linkedListNode, value);
                 }
             }
         }
     }
 }
Example #6
0
 internal void SendNetworkSimulated(MyAction sendAction)
 {
     if (!this.NetworkSimulationSettings.IsSimulationEnabled)
     {
         sendAction();
     }
     else if (((this.usedProtocol == ConnectionProtocol.Udp) && (this.NetworkSimulationSettings.OutgoingLossPercentage > 0)) && (this.lagRandomizer.Next(0x65) < this.NetworkSimulationSettings.OutgoingLossPercentage))
     {
         this.networkSimulationSettings.LostPackagesOut++;
     }
     else
     {
         int            jitter        = (this.networkSimulationSettings.OutgoingJitter <= 0) ? 0 : (this.lagRandomizer.Next(this.networkSimulationSettings.OutgoingJitter * 2) - this.networkSimulationSettings.OutgoingJitter);
         int            delay         = this.networkSimulationSettings.OutgoingLag + jitter;
         int            timeToExecute = SupportClass.GetTickCount() + delay;
         SimulationItem simItem       = new SimulationItem()
         {
             ActionToExecute = sendAction,
             TimeToExecute   = timeToExecute,
             Delay           = delay
         };
         lock (this.NetSimListOutgoing)
         {
             if ((this.NetSimListOutgoing.Count == 0) || (this.usedProtocol == ConnectionProtocol.Tcp))
             {
                 this.NetSimListOutgoing.AddLast(simItem);
             }
             else
             {
                 LinkedListNode <SimulationItem> node = this.NetSimListOutgoing.First;
                 while ((node != null) && (node.Value.TimeToExecute < timeToExecute))
                 {
                     node = node.Next;
                 }
                 if (node == null)
                 {
                     this.NetSimListOutgoing.AddLast(simItem);
                 }
                 else
                 {
                     this.NetSimListOutgoing.AddBefore(node, simItem);
                 }
             }
         }
     }
 }
Example #7
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);
                 }
             }
         }
     }
 }