Ejemplo n.º 1
0
        protected void HandleMessage()
        {
            this.read.Start(base.Connection);
            byte b = this.read.PacketID();

            if (this.HandleRaknetPacket(b))
            {
                return;
            }
            b -= 140;
            if (b > 22)
            {
                ConsoleSystem.LogWarning("Invalid Packet (higher than " + Message.Type.EAC + ")");
                this.Disconnect(string.Concat(new object[]
                {
                    "Invalid Packet (",
                    b,
                    ") ",
                    this.peer.incomingBytes,
                    "b"
                }), true);
                return;
            }
            Message message = base.StartMessage((Message.Type)b, base.Connection);

            if (this.onMessage != null)
            {
                try
                {
                    using (TimeWarning.New("onMessage", 0.1f))
                    {
                        this.onMessage(message);
                    }
                }
                catch (Exception ex)
                {
                    ConsoleSystem.LogError(ex.Message);
                }
            }
            message.Clear();
            Pool.Free <Message>(ref message);
        }
Ejemplo n.º 2
0
        public override void Cycle()
        {
            base.Cycle();
            if (!IsConnected())
            {
                return;
            }

            var stopwatch = Pool.Get <Stopwatch>();

            stopwatch.Reset();
            stopwatch.Start();
            do
            {
                if (!_peer.Receive())
                {
                    break;
                }

                var connection = FindConnection(_peer.IncomingGuid);
                if (connection != null)
                {
                    using (var timeWarning = TimeWarning.New("ConnectedPacket", 20))
                    {
                        ConnectedPacket(connection);
                    }
                }
                else
                {
                    using (var timeWarning = TimeWarning.New("UnconnectedPacket", 20))
                    {
                        UnconnectedPacket();
                    }
                }
            } while (stopwatch.Elapsed.TotalMilliseconds <= MaxReceiveTime);

            Pool.Free(ref stopwatch);
        }
Ejemplo n.º 3
0
        protected void HandleMessage()
        {
            read.Start(Connection);
            var b = read.PacketId();

            if (HandleRaknetPacket(b))
            {
                return;
            }

            b -= 140;
            if (b > 23)
            {
                ConsoleSystem.LogWarning("Invalid Packet (higher than " + Message.Type.EAC + ")");
                Disconnect(string.Concat("Invalid Packet (", b, ") ", _peer.IncomingBytes, "b"), true);
                return;
            }

            var message = StartMessage((Message.Type)b, Connection);

            if (OnMessage != null)
            {
                try
                {
                    using (TimeWarning.New("onMessage", 0.1f))
                    {
                        OnMessage(message);
                    }
                }
                catch (Exception ex)
                {
                    ConsoleSystem.LogError(ex.Message);
                }
            }

            message.Clear();
            Pool.Free(ref message);
        }
Ejemplo n.º 4
0
        void System.IDisposable.Dispose()
        {
            if (this.disposed)
            {
                return;
            }
            this.disposed = true;
            if (TimeWarning.OnEnd != null)
            {
                TimeWarning.OnEnd();
            }
            if (TimeWarning.Enabled && this.stopwatch.Elapsed.TotalMilliseconds > this.warningMS)
            {
                bool     flag         = this.gcCount != GC.CollectionCount(0);
                object[] totalSeconds = new object[] { this.warningName, null, null, null };
                totalSeconds[1] = this.stopwatch.Elapsed.TotalSeconds;
                totalSeconds[2] = this.stopwatch.Elapsed.TotalMilliseconds;
                totalSeconds[3] = (!flag ? string.Empty : " [GARBAGE COLLECT]");
                ConsoleSystem.LogWarning(String.Format("TimeWarning: {0} took {1:0.00} seconds ({2:0} ms){3}", totalSeconds));
            }
            TimeWarning timeWarning = this;

            Pool.Free <TimeWarning>(ref timeWarning);
        }