Esempio n. 1
0
        public void FromClient(PacketFromClient packet)
        {
            if (packet.PacketID == PassThrough.ID)
            {
                Session.FromClient(packet);
                return;
            }

            //Ping update
            if (packet.PacketID == KeepAlivePong.ID)
            {
                var ka = packet as KeepAlivePong;
                lock (pings)
                {
                    if (pings.ContainsKey(ka.KeepAliveID))
                    {
                        Ping = (DateTime.Now - pings[ka.KeepAliveID]).TotalMilliseconds;
                        pings.Remove(ka.KeepAliveID);
                    }
                }
            }

            //Send possessed packets
            SendToPossessors(packet);

            //Check for invalid data, hacked clients(Derp)
            double pitch = 0;

            if (packet.PacketID == PlayerPositionLookClient.ID)
            {
                pitch = ((PlayerPositionLookClient)packet).Pitch;
            }
            if (pitch > 91 || pitch < -91)
            {
                //this.Ban (null, DateTime.Now.AddMinutes (42), "Modified client");
                if (Banned.CheckBanned(MinecraftUsername) == null)
                {
                    Chatting.Parser.TellAdmin(Permissions.Ban, Name + Chat.Gray + " crazy head angle " + pitch.ToString("0.0"));
                }
                SendToClient(new EntityStatus(EntityID, MineProxy.Data.EntityStatuses.EntityHurt));
            }

            if (packet.PacketID == Packets.ClientSettings.ID)
            {
                var vd = (Packets.ClientSettings)packet;
                this.Locale       = vd.Locale;
                this.ViewDistance = vd.ViewDistance;
            }

            //Check for book signatures
            if (packet.PacketID == MCBook.ID && packet is MCBook)
            {
                var b = packet as MCBook;
                if (b != null)
                {
                    Log.WriteBook(this, b);
                    Debug.WriteLine("Book: " + b);

                    //Check for signatures
                    RuleBook.Rules.Verify(this, b);
                }
            }

            WorldSession s = Session;

            try
            {
                switch (packet.PacketID)
                {
                case ChatMessageClient.ID:
                    Parser.ParseClient(this, (ChatMessageClient)packet);
                    //AfkTime = DateTime.Now;
                    return;

                case TabCompleteClient.ID:
                    Parser.ParseClient(this, (TabCompleteClient)packet);
                    return;

                default:
                    s.FromClient(packet);
                    break;
                }
            }
            catch (SessionClosedException sc)
            {
                SessionClosed(s, sc);
            }
            catch (IOException sc)
            {
                SessionClosed(s, sc);
            }
#if !DEBUG
            catch (Exception e)
            {
                Log.Write(e, this);
                SessionClosed(s, e);
            }
#endif
        }