예제 #1
0
 internal void InitializeTrafficStats()
 {
     this.TrafficStatsIncoming  = new TrafficStats(this.TrafficPackageHeaderSize);
     this.TrafficStatsOutgoing  = new TrafficStats(this.TrafficPackageHeaderSize);
     this.TrafficStatsGameLevel = new TrafficStatsGameLevel();
     this.trafficStatsStopwatch = new Stopwatch();
 }
예제 #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;
 }
        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]);
                        }
                    }
                }
            }
        }
        private void EnqueueInit(byte[] data)
        {
            bool flag = !this.DoFraming;

            if (!flag)
            {
                StreamBuffer streamBuffer = new StreamBuffer(data.Length + 32);
                BinaryWriter binaryWriter = new BinaryWriter(streamBuffer);
                byte[]       array        = new byte[]
                {
                    251,
                    0,
                    0,
                    0,
                    0,
                    0,
                    1
                };
                int num = 1;
                Protocol.Serialize(data.Length + array.Length, array, ref num);
                binaryWriter.Write(array);
                binaryWriter.Write(data);
                byte[] array2 = streamBuffer.ToArray();
                bool   trafficStatsEnabled = base.TrafficStatsEnabled;
                if (trafficStatsEnabled)
                {
                    TrafficStats expr_79 = base.TrafficStatsOutgoing;
                    int          num2    = expr_79.TotalPacketCount;
                    expr_79.TotalPacketCount = num2 + 1;
                    TrafficStats expr_91 = base.TrafficStatsOutgoing;
                    num2 = expr_91.TotalCommandsInPackets;
                    expr_91.TotalCommandsInPackets = num2 + 1;
                    base.TrafficStatsOutgoing.CountControlCommand(array2.Length);
                }
                this.EnqueueMessageAsPayload(true, array2, 0);
            }
        }
 internal void SendData(byte[] data)
 {
     try
     {
         this.bytesOut += (long)data.Length;
         bool trafficStatsEnabled = base.TrafficStatsEnabled;
         if (trafficStatsEnabled)
         {
             TrafficStats expr_3D          = base.TrafficStatsOutgoing;
             int          totalPacketCount = expr_3D.TotalPacketCount;
             expr_3D.TotalPacketCount = totalPacketCount + 1;
             base.TrafficStatsOutgoing.TotalCommandsInPackets += this.outgoingCommandsInStream;
         }
         bool isSimulationEnabled = base.NetworkSimulationSettings.IsSimulationEnabled;
         if (isSimulationEnabled)
         {
             base.SendNetworkSimulated(delegate
             {
                 this.rt.Send(data, data.Length);
             });
         }
         else
         {
             this.rt.Send(data, data.Length);
         }
     }
     catch (Exception ex)
     {
         bool flag = base.debugOut >= DebugLevel.ERROR;
         if (flag)
         {
             base.Listener.DebugReturn(DebugLevel.ERROR, ex.ToString());
         }
         SupportClass.WriteStackTrace(ex);
     }
 }