Ejemplo n.º 1
0
        internal virtual void InitPeerBase()
        {
            this.SerializationProtocol = SerializationProtocolFactory.Create(this.photonPeer.SerializationProtocolType);
            this.photonPeer.InitializeTrafficStats();
            this.ByteCountLastOperation   = 0;
            this.ByteCountCurrentDispatch = 0;
            this.bytesIn               = 0L;
            this.bytesOut              = 0L;
            this.packetLossByCrc       = 0;
            this.packetLossByChallenge = 0;
            this.networkSimulationSettings.LostPackagesIn  = 0;
            this.networkSimulationSettings.LostPackagesOut = 0;
            LinkedList <SimulationItem> netSimListOutgoing = this.NetSimListOutgoing;

            lock (netSimListOutgoing)
            {
                this.NetSimListOutgoing.Clear();
            }
            LinkedList <SimulationItem> netSimListIncoming = this.NetSimListIncoming;

            lock (netSimListIncoming)
            {
                this.NetSimListIncoming.Clear();
            }
            this.peerConnectionState         = ConnectionStateValue.Disconnected;
            this.timeBase                    = SupportClass.GetTickCount();
            this.isEncryptionAvailable       = false;
            this.ApplicationIsInitialized    = false;
            this.roundTripTime               = 200;
            this.roundTripTimeVariance       = 5;
            this.serverTimeOffsetIsAvailable = false;
            this.serverTimeOffset            = 0;
        }
Ejemplo n.º 2
0
 internal virtual void InitPeerBase()
 {
     this.TrafficStatsIncoming     = new TrafficStats(this.TrafficPackageHeaderSize);
     this.TrafficStatsOutgoing     = new TrafficStats(this.TrafficPackageHeaderSize);
     this.TrafficStatsGameLevel    = new TrafficStatsGameLevel();
     this.ByteCountLastOperation   = 0;
     this.ByteCountCurrentDispatch = 0;
     this.bytesIn         = 0L;
     this.bytesOut        = 0L;
     this.packetLossByCrc = 0;
     this.networkSimulationSettings.LostPackagesIn  = 0;
     this.networkSimulationSettings.LostPackagesOut = 0;
     lock (this.NetSimListOutgoing)
         this.NetSimListOutgoing.Clear();
     lock (this.NetSimListIncoming)
         this.NetSimListIncoming.Clear();
     this.peerConnectionState         = PeerBase.ConnectionStateValue.Disconnected;
     this.timeBase                    = SupportClass.GetTickCount();
     this.isEncryptionAvailable       = false;
     this.ApplicationIsInitialized    = false;
     this.roundTripTime               = 300;
     this.roundTripTimeVariance       = 0;
     this.packetThrottleInterval      = 5000;
     this.serverTimeOffsetIsAvailable = false;
     this.serverTimeOffset            = 0;
 }
Ejemplo n.º 3
0
        internal override bool SendOutgoingCommands()
        {
            if (base.peerConnectionState == ConnectionStateValue.Disconnected)
            {
                return(false);
            }
            if (!base.PhotonSocket.Connected)
            {
                return(false);
            }
            base.timeInt = SupportClass.GetTickCount() - base.timeBase;
            base.timeLastSendOutgoing = base.timeInt;
            if (base.peerConnectionState == ConnectionStateValue.Connected && Math.Abs(SupportClass.GetTickCount() - this.lastPingResult) > base.timePingInterval)
            {
                this.SendPing();
            }
            List <StreamBuffer> obj = this.outgoingStream;

            lock (obj)
            {
                for (int i = 0; i < this.outgoingStream.Count; i++)
                {
                    StreamBuffer streamBuffer = this.outgoingStream[i];
                    this.SendData(streamBuffer.GetBuffer(), streamBuffer.IntLength);
                    PeerBase.MessageBufferPoolPut(streamBuffer);
                }
                this.outgoingStream.Clear();
                base.outgoingCommandsInStream = 0;
            }
            return(false);
        }
Ejemplo n.º 4
0
 public override void OnConnect()
 {
     this.lastPingResult = SupportClass.GetTickCount();
     byte[] data = base.PrepareConnectData(base.ServerAddress, base.AppId, base.CustomInitData);
     this.EnqueueInit(data);
     this.SendOutgoingCommands();
 }
Ejemplo n.º 5
0
        internal void SendPing()
        {
            int num = this.lastPingResult = SupportClass.GetTickCount();

            if (!this.DoFraming)
            {
                SendOptions sendOptions = new SendOptions()
                {
                    DeliveryMode = DeliveryMode.Reliable
                };
                StreamBuffer streamBuffer = this.SerializeOperationToMessage(PhotonCodes.Ping, new Dictionary <byte, object>
                {
                    {
                        (byte)1,
                        (object)num
                    }
                }, EgMessageType.InternalOperationRequest, sendOptions.Encrypt);
                if (base.TrafficStatsEnabled)
                {
                    base.TrafficStatsOutgoing.CountControlCommand(streamBuffer.IntLength);
                }
                this.SendData(streamBuffer.GetBuffer(), streamBuffer.IntLength);
                PeerBase.MessageBufferPoolPut(streamBuffer);
            }
            else
            {
                int num2 = 1;
                Protocol.Serialize(num, this.pingRequest, ref num2);
                if (base.TrafficStatsEnabled)
                {
                    base.TrafficStatsOutgoing.CountControlCommand(this.pingRequest.Length);
                }
                this.SendData(this.pingRequest, this.pingRequest.Length);
            }
        }
        internal void SendPing()
        {
            this.lastPingResult = SupportClass.GetTickCount();
            bool flag = !this.DoFraming;

            if (flag)
            {
                int tickCount = SupportClass.GetTickCount();
                this.EnqueueOperation(new Dictionary <byte, object>
                {
                    {
                        1,
                        tickCount
                    }
                }, PhotonCodes.Ping, true, 0, false, PeerBase.EgMessageType.InternalOperationRequest);
            }
            else
            {
                int num = 1;
                Protocol.Serialize(SupportClass.GetTickCount(), this.pingRequest, ref num);
                bool trafficStatsEnabled = base.TrafficStatsEnabled;
                if (trafficStatsEnabled)
                {
                    base.TrafficStatsOutgoing.CountControlCommand(this.pingRequest.Length);
                }
                this.SendData(this.pingRequest);
            }
        }
Ejemplo n.º 7
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);
                            }
                        }
                    }
                }
            }
        }
        internal override void ReceiveIncomingCommands(byte[] inbuff, int dataLength)
        {
            bool flag = inbuff == null;

            if (flag)
            {
                bool flag2 = base.debugOut >= DebugLevel.ERROR;
                if (flag2)
                {
                    base.EnqueueDebugReturn(DebugLevel.ERROR, "checkAndQueueIncomingCommands() inBuff: null");
                }
            }
            else
            {
                this.timestampOfLastReceive = SupportClass.GetTickCount();
                this.timeInt  = SupportClass.GetTickCount() - this.timeBase;
                this.bytesIn += (long)(inbuff.Length + 7);
                bool trafficStatsEnabled = base.TrafficStatsEnabled;
                if (trafficStatsEnabled)
                {
                    TrafficStats expr_6F = base.TrafficStatsIncoming;
                    int          num     = expr_6F.TotalPacketCount;
                    expr_6F.TotalPacketCount = num + 1;
                    TrafficStats expr_85 = base.TrafficStatsIncoming;
                    num = expr_85.TotalCommandsInPackets;
                    expr_85.TotalCommandsInPackets = num + 1;
                }
                bool flag3 = inbuff[0] == 243 || inbuff[0] == 244;
                if (flag3)
                {
                    Queue <byte[]> obj = this.incomingList;
                    lock (obj)
                    {
                        this.incomingList.Enqueue(inbuff);
                    }
                }
                else
                {
                    bool flag4 = inbuff[0] == 240;
                    if (flag4)
                    {
                        base.TrafficStatsIncoming.CountControlCommand(inbuff.Length);
                        this.ReadPingResult(inbuff);
                    }
                    else
                    {
                        bool flag5 = base.debugOut >= DebugLevel.ERROR;
                        if (flag5)
                        {
                            base.EnqueueDebugReturn(DebugLevel.ERROR, "receiveIncomingCommands() MagicNumber should be 0xF0, 0xF3 or 0xF4. Is: " + inbuff[0]);
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        internal void SendPing()
        {
            int targetOffset = 1;

            Protocol.Serialize(SupportClass.GetTickCount(), this.pingRequest, ref targetOffset);
            this.lastPingResult = SupportClass.GetTickCount();
            if (this.TrafficStatsEnabled)
            {
                this.TrafficStatsOutgoing.CountControlCommand(this.pingRequest.Length);
            }
            this.SendData(this.pingRequest);
        }
Ejemplo n.º 10
0
        public override PhotonSocketError Send(byte[] data, int length)
        {
            bool flag = this.sock == null || !this.sock.Connected;
            PhotonSocketError result;

            if (flag)
            {
                result = PhotonSocketError.Skipped;
            }
            else
            {
                try
                {
                    this.sock.Send(data, 0, length, SocketFlags.None);
                }
                catch (Exception ex)
                {
                    bool flag2 = base.State != PhotonSocketState.Disconnecting && base.State > PhotonSocketState.Disconnected;
                    if (flag2)
                    {
                        bool flag3 = base.ReportDebugOfLevel(DebugLevel.ERROR);
                        if (flag3)
                        {
                            string text  = "";
                            bool   flag4 = this.sock != null;
                            if (flag4)
                            {
                                text = string.Format(" Local: {0} Remote: {1} ({2}, {3})", new object[]
                                {
                                    this.sock.LocalEndPoint,
                                    this.sock.RemoteEndPoint,
                                    this.sock.Connected ? "connected" : "not connected",
                                    this.sock.IsBound ? "bound" : "not bound"
                                });
                            }
                            base.EnqueueDebugReturn(DebugLevel.ERROR, string.Format("Cannot send to: {0} ({4}). Uptime: {1} ms. {2} {3}", new object[]
                            {
                                base.ServerAddress,
                                SupportClass.GetTickCount() - this.peerBase.timeBase,
                                base.AddressResolvedAsIpv6 ? " IPv6" : string.Empty,
                                text,
                                ex
                            }));
                        }
                        base.HandleException(StatusCode.Exception);
                    }
                    return(PhotonSocketError.Exception);
                }
                result = PhotonSocketError.Success;
            }
            return(result);
        }
 internal void SendOutgoingCommandsCalled()
 {
     if (this.timeOfLastSendCall != 0)
     {
         int num = SupportClass.GetTickCount() - this.timeOfLastSendCall;
         if (num > this.LongestDeltaBetweenSending)
         {
             this.LongestDeltaBetweenSending = num;
         }
     }
     ++this.SendOutgoingCommandsCalls;
     this.timeOfLastSendCall = SupportClass.GetTickCount();
 }
 internal void DispatchIncomingCommandsCalled()
 {
     if (this.timeOfLastDispatchCall != 0)
     {
         int num = SupportClass.GetTickCount() - this.timeOfLastDispatchCall;
         if (num > this.LongestDeltaBetweenDispatching)
         {
             this.LongestDeltaBetweenDispatching = num;
         }
     }
     ++this.DispatchIncomingCommandsCalls;
     this.timeOfLastDispatchCall = SupportClass.GetTickCount();
 }
 internal void DispatchIncomingCommandsCalled()
 {
     if (this.timeOfLastDispatchCall != 0)
     {
         int delta = SupportClass.GetTickCount() - this.timeOfLastDispatchCall;
         if (delta > this.LongestDeltaBetweenDispatching)
         {
             this.LongestDeltaBetweenDispatching = delta;
         }
     }
     this.DispatchIncomingCommandsCalls++;
     this.timeOfLastDispatchCall = SupportClass.GetTickCount();
 }
 internal void SendOutgoingCommandsCalled()
 {
     if (this.timeOfLastSendCall != 0)
     {
         int delta = SupportClass.GetTickCount() - this.timeOfLastSendCall;
         if (delta > this.LongestDeltaBetweenSending)
         {
             this.LongestDeltaBetweenSending = delta;
         }
     }
     this.SendOutgoingCommandsCalls++;
     this.timeOfLastSendCall = SupportClass.GetTickCount();
 }
Ejemplo n.º 15
0
 internal override bool SendAcksOnly()
 {
     if (base.PhotonSocket == null || !base.PhotonSocket.Connected)
     {
         return(false);
     }
     base.timeInt = SupportClass.GetTickCount() - base.timeBase;
     if (base.peerConnectionState == ConnectionStateValue.Connected && SupportClass.GetTickCount() - this.lastPingResult > base.timePingInterval)
     {
         this.SendPing();
     }
     return(false);
 }
Ejemplo n.º 16
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);
                 }
             }
         }
     }
 }
Ejemplo n.º 17
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);
                 }
             }
         }
     }
 }
Ejemplo n.º 18
0
 internal override void ReceiveIncomingCommands(byte[] inbuff, int dataLength)
 {
     if (inbuff == null)
     {
         if (this.debugOut < DebugLevel.ERROR)
         {
             return;
         }
         this.EnqueueDebugReturn(DebugLevel.ERROR, "checkAndQueueIncomingCommands() inBuff: null");
     }
     else
     {
         this.timestampOfLastReceive = SupportClass.GetTickCount();
         this.bytesIn += (long)(inbuff.Length + 7);
         if (this.TrafficStatsEnabled)
         {
             ++this.TrafficStatsIncoming.TotalPacketCount;
             ++this.TrafficStatsIncoming.TotalCommandsInPackets;
         }
         if ((int)inbuff[0] == 243 || (int)inbuff[0] == 244)
         {
             lock (this.incomingList)
             {
                 this.incomingList.Add(inbuff);
                 if (this.incomingList.Count % this.warningSize != 0)
                 {
                     return;
                 }
                 this.EnqueueStatusCallback(StatusCode.QueueIncomingReliableWarning);
             }
         }
         else if ((int)inbuff[0] == 240)
         {
             this.TrafficStatsIncoming.CountControlCommand(inbuff.Length);
             this.ReadPingResult(inbuff);
         }
         else
         {
             if (this.debugOut < DebugLevel.ERROR)
             {
                 return;
             }
             this.EnqueueDebugReturn(DebugLevel.ERROR, "receiveIncomingCommands() MagicNumber should be 0xF0, 0xF3 or 0xF4. Is: " + (object)inbuff[0]);
         }
     }
 }
Ejemplo n.º 19
0
        private void ReadPingResponse(BinaryReader br)
        {
            int num = (int)br.ReadByte() << 24 | (int)br.ReadByte() << 16 | (int)br.ReadByte() << 8 | (int)br.ReadByte();

            this.lastRoundTripTime = SupportClass.GetTickCount() - ((int)br.ReadByte() << 24 | (int)br.ReadByte() << 16 | (int)br.ReadByte() << 8 | (int)br.ReadByte());
            if (!this.serverTimeOffsetIsAvailable)
            {
                this.roundTripTime = this.lastRoundTripTime;
            }
            this.UpdateRoundTripTimeAndVariance(this.lastRoundTripTime);
            if (this.serverTimeOffsetIsAvailable)
            {
                return;
            }
            this.serverTimeOffset            = num + (this.lastRoundTripTime >> 1) - SupportClass.GetTickCount();
            this.serverTimeOffsetIsAvailable = true;
        }
Ejemplo n.º 20
0
        protected internal void ReadPingResult(OperationResponse operationResponse)
        {
            int num  = (int)operationResponse.Parameters[2];
            int num2 = (int)operationResponse.Parameters[1];

            base.lastRoundTripTime = SupportClass.GetTickCount() - num2;
            if (!base.serverTimeOffsetIsAvailable)
            {
                base.roundTripTime = base.lastRoundTripTime;
            }
            base.UpdateRoundTripTimeAndVariance(base.lastRoundTripTime);
            if (!base.serverTimeOffsetIsAvailable)
            {
                base.serverTimeOffset            = num + (base.lastRoundTripTime >> 1) - SupportClass.GetTickCount();
                base.serverTimeOffsetIsAvailable = true;
            }
        }
Ejemplo n.º 21
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);
                 }
             }
         }
     }
 }
Ejemplo n.º 22
0
        internal void SendOutgoingCommandsCalled()
        {
            bool flag = this.timeOfLastSendCall != 0;

            if (flag)
            {
                int  num   = SupportClass.GetTickCount() - this.timeOfLastSendCall;
                bool flag2 = num > this.LongestDeltaBetweenSending;
                if (flag2)
                {
                    this.LongestDeltaBetweenSending = num;
                }
            }
            int sendOutgoingCommandsCalls = this.SendOutgoingCommandsCalls;

            this.SendOutgoingCommandsCalls = sendOutgoingCommandsCalls + 1;
            this.timeOfLastSendCall        = SupportClass.GetTickCount();
        }
Ejemplo n.º 23
0
        internal void DispatchIncomingCommandsCalled()
        {
            bool flag = this.timeOfLastDispatchCall != 0;

            if (flag)
            {
                int  num   = SupportClass.GetTickCount() - this.timeOfLastDispatchCall;
                bool flag2 = num > this.LongestDeltaBetweenDispatching;
                if (flag2)
                {
                    this.LongestDeltaBetweenDispatching = num;
                }
            }
            int dispatchIncomingCommandsCalls = this.DispatchIncomingCommandsCalls;

            this.DispatchIncomingCommandsCalls = dispatchIncomingCommandsCalls + 1;
            this.timeOfLastDispatchCall        = SupportClass.GetTickCount();
        }
Ejemplo n.º 24
0
        private void ReadPingResult(byte[] inbuff)
        {
            int serverSentTime = 0;
            int clientSentTime = 0;
            int offset         = 1;

            Protocol.Deserialize(out serverSentTime, inbuff, ref offset);
            Protocol.Deserialize(out clientSentTime, inbuff, ref offset);
            base.lastRoundTripTime = SupportClass.GetTickCount() - clientSentTime;
            if (!base.serverTimeOffsetIsAvailable)
            {
                base.roundTripTime = base.lastRoundTripTime;
            }
            base.UpdateRoundTripTimeAndVariance(base.lastRoundTripTime);
            if (!base.serverTimeOffsetIsAvailable)
            {
                base.serverTimeOffset            = (serverSentTime + (base.lastRoundTripTime >> 1)) - SupportClass.GetTickCount();
                base.serverTimeOffsetIsAvailable = true;
            }
        }
Ejemplo n.º 25
0
        private void _sendPing()
        {
            if ((long)this.GetLocalMsTimestamp() - this.lastPingTimeStamp > (long)this.timePingInterval)
            {
                this.lastPingTimeStamp = (long)this.GetLocalMsTimestamp();
                int targetOffset = 1;
                Protocol.Serialize(SupportClass.GetTickCount(), HttpBase3.pingData, ref targetOffset);
                this.Request(HttpBase3.pingData, this.UrlParameters, HttpBase3.MessageType.NORMAL);
            }
            int num = this._minConnectionsCount - this._requestCache.Count;

            if (num <= 0)
            {
                return;
            }
            for (int index = 0; index < num; ++index)
            {
                this.Request((byte[])null, this.UrlParameters, HttpBase3.MessageType.NORMAL);
            }
        }
Ejemplo n.º 26
0
        private void ReadPingResult(byte[] inbuff)
        {
            int num  = 0;
            int num2 = 0;
            int num3 = 1;

            Protocol.Deserialize(out num, inbuff, ref num3);
            Protocol.Deserialize(out num2, inbuff, ref num3);
            base.lastRoundTripTime = SupportClass.GetTickCount() - num2;
            if (!base.serverTimeOffsetIsAvailable)
            {
                base.roundTripTime = base.lastRoundTripTime;
            }
            base.UpdateRoundTripTimeAndVariance(base.lastRoundTripTime);
            if (!base.serverTimeOffsetIsAvailable)
            {
                base.serverTimeOffset            = num + (base.lastRoundTripTime >> 1) - SupportClass.GetTickCount();
                base.serverTimeOffsetIsAvailable = true;
            }
        }
        protected internal void ReadPingResult(OperationResponse operationResponse)
        {
            int num  = (int)operationResponse.Parameters[2];
            int num2 = (int)operationResponse.Parameters[1];

            this.lastRoundTripTime = SupportClass.GetTickCount() - num2;
            bool flag = !this.serverTimeOffsetIsAvailable;

            if (flag)
            {
                this.roundTripTime = this.lastRoundTripTime;
            }
            base.UpdateRoundTripTimeAndVariance(this.lastRoundTripTime);
            bool flag2 = !this.serverTimeOffsetIsAvailable;

            if (flag2)
            {
                this.serverTimeOffset            = num + (this.lastRoundTripTime >> 1) - SupportClass.GetTickCount();
                this.serverTimeOffsetIsAvailable = true;
            }
        }
Ejemplo n.º 28
0
        private void ReadPingResult(byte[] inbuff)
        {
            int num1   = 0;
            int num2   = 0;
            int offset = 1;

            Protocol.Deserialize(out num1, inbuff, ref offset);
            Protocol.Deserialize(out num2, inbuff, ref offset);
            this.lastRoundTripTime = SupportClass.GetTickCount() - num2;
            if (!this.serverTimeOffsetIsAvailable)
            {
                this.roundTripTime = this.lastRoundTripTime;
            }
            this.UpdateRoundTripTimeAndVariance(this.lastRoundTripTime);
            if (this.serverTimeOffsetIsAvailable)
            {
                return;
            }
            this.serverTimeOffset            = num1 + (this.lastRoundTripTime >> 1) - SupportClass.GetTickCount();
            this.serverTimeOffsetIsAvailable = true;
        }
        internal override bool SendAcksOnly()
        {
            bool flag = this.rt == null || !this.rt.Connected;
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                this.timeInt = SupportClass.GetTickCount() - this.timeBase;
                bool flag2 = this.peerConnectionState == PeerBase.ConnectionStateValue.Connected && SupportClass.GetTickCount() - this.lastPingResult > base.timePingInterval;
                if (flag2)
                {
                    this.SendPing();
                }
                result = false;
            }
            return(result);
        }
Ejemplo n.º 30
0
 internal override void ReceiveIncomingCommands(byte[] inbuff, int dataLength)
 {
     if (inbuff == null)
     {
         if ((int)base.debugOut >= 1)
         {
             base.EnqueueDebugReturn(DebugLevel.ERROR, "checkAndQueueIncomingCommands() inBuff: null");
         }
     }
     else
     {
         base.timestampOfLastReceive = SupportClass.GetTickCount();
         base.timeInt  = SupportClass.GetTickCount() - base.timeBase;
         base.bytesIn += dataLength + 7;
         if (base.TrafficStatsEnabled)
         {
             base.TrafficStatsIncoming.TotalPacketCount++;
             base.TrafficStatsIncoming.TotalCommandsInPackets++;
         }
         if (inbuff[0] == 243 || inbuff[0] == 244)
         {
             byte[] array = new byte[dataLength];
             Buffer.BlockCopy(inbuff, 0, array, 0, dataLength);
             Queue <byte[]> obj = this.incomingList;
             lock (obj)
             {
                 this.incomingList.Enqueue(array);
             }
         }
         else if (inbuff[0] == 240)
         {
             base.TrafficStatsIncoming.CountControlCommand(inbuff.Length);
             this.ReadPingResult(inbuff);
         }
         else if ((int)base.debugOut >= 1)
         {
             base.EnqueueDebugReturn(DebugLevel.ERROR, "receiveIncomingCommands() MagicNumber should be 0xF0, 0xF3 or 0xF4. Is: " + inbuff[0]);
         }
     }
 }