Exemplo n.º 1
0
        public override void FromClient(PacketFromClient packet)
        {
            switch (packet.PacketID)
            {
                case UseEntity.ID:
                case PlayerBlockPlacement.ID:
                case PlayerDigging.ID:
                    Back();
                    return;

                case PlayerPositionLookClient.ID:
                    var ppl = (PlayerPositionLookClient)packet;
                    NewPos(ppl.Position);
                    return;
            }
        }
Exemplo n.º 2
0
        public override void FromClient(PacketFromClient packet)
        {
            switch (packet.PacketID)
            {
            #region Block place/break

                case PlayerDigging.ID:
                    PlayerDigging pd = packet as PlayerDigging;
                    if (pd.Status == PlayerDigging.StatusEnum.FinishedDigging)
                        QueueToAll(new BlockChange(pd.Position, BlockID.Air));
                    return;
            /* TODO: fix: crashes with new items such as pot
                case PlayerBlockPlacement.ID:
                    PlayerBlockPlacement pbp = packet as PlayerBlockPlacement;
                    if(pbp.Item == null)
                        return;
                    var bc = new BlockChange(pbp.BlockPosition.Offset(pbp.FaceDirection), pbp.Item.ItemID);
                    bc.Metadata = (byte)pbp.Item.Uses;
                    QueueToAll(bc);
                    return;*/

            #endregion

			#region Moving Looking
			
                case PlayerPositionLookClient.ID:
                    {
                        PlayerPositionLookClient p = (PlayerPositionLookClient)packet;
    			
                        SetPosition(p.Position, true);
                        Pitch = p.Pitch;
                        Yaw = p.Yaw;
    			
                        if (Player.Settings.Cloaked == null)
                        {
                            EntityTeleport et = new EntityTeleport(Player.EntityID, p.Position);
                            et.Yaw = p.Yaw;
                            et.Pitch = p.Pitch;
                            QueueToAllButMe(et);

                            QueueToAllButMe(new EntityHeadYaw(Player.EntityID, Yaw));
                        }
                        CheckPosition();
                        return;
                    }
                
			#endregion
			
                case UseEntity.ID:
                    //UseEntity ue = (UseEntity)packet;
                    //Sender see hurt
                    //New: hurt attacker, old: ue.Target
                    QueueToAll(new EntityStatus(this.Player.EntityID, EntityStatuses.EntityHurt));
                    QueueToAll(new Effect(SoundEffects.MobSpawn, Position.CloneInt()));
                    return;

#if DEBUG
                case PlayerGround.ID:
                case KeepAlivePing.ID://case KeepAlivePong.ID:
                    return;
			
                default:
                    //Console.WriteLine("Unhandled: " + packet);
                    return;
#endif
            }
        }
Exemplo n.º 3
0
        public static void ToServer(PacketFromClient packet)
        {
            #if DEBUG
            if (Show(packet))
                Console.WriteLine(" ->S: " + packet);
            //System.Threading.Thread.Sleep(50);

            #endif
        }
Exemplo n.º 4
0
 public static void FromClient(Client c, PacketFromClient packet)
 {
     #if DEBUG
     if (Show(packet))
         Console.WriteLine("C-> : " + packet);
     #endif
 }
Exemplo n.º 5
0
 public abstract void FromClient(PacketFromClient packet);
Exemplo n.º 6
0
 public override void FromClient(PacketFromClient packet)
 {
 }
Exemplo n.º 7
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(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
        }
Exemplo n.º 8
0
        private void SendToPossessors(PacketFromClient p)
        {
            var pby = PossessedBy;
            if (pby.Length == 0)
                return;
                
            VanillaSession real = Session as VanillaSession;

            PacketFromServer ps = null;

            switch (p.PacketID)
            {
                case PlayerPositionLookClient.ID:
                    {
                        if (real == null)
                            return;

                        var pl = (PlayerPositionLookClient)p;
                        var et = new EntityTeleport(real.EID, pl.Position);
                        et.Yaw = pl.Yaw;
                        et.Pitch = pl.Pitch;

                        EntityHeadYaw hy = new EntityHeadYaw(real.EID, pl.Yaw);
                        foreach (WorldSession s in pby)
                        {
                            s.Player.Queue.Queue(et);
                            s.Player.Queue.Queue(hy);
                        }
                    }
                    return;
            }
            
            if (ps == null)
                return;
                
            foreach (WorldSession s in pby)
                s.Player.Queue.Queue(ps);
        }
Exemplo n.º 9
0
        /// <summary>
        /// What the Client sends to the server.
        /// </summary>
        public override void FromClient(PacketFromClient packet)
        {
            while (phase == Phases.Handshake)
                Thread.Sleep(100);
            //Wait for handshake to complete
            if (phase == Phases.FinalClose)
                throw new SessionClosedException();
    
            if (packet.PacketID == PassThrough.ID)
            {
                SendToBackend(packet);
                return;
            }

            //Fix players eid to what is known for the server
            if (packet is IEntity)
            {
                IEntity ie = (IEntity)packet;
                if (ie.EID == Player.EntityID)
                {
                    ie.EID = EID;
                    packet.SetPacketBuffer(null);
                }
            }

            WorldRegion region = CurrentRegion;

            switch (packet.PacketID)
            {
                case PlayerPosition.ID:
                    if (AttachedEntity > 0)
                    {
                        //Ignore relative movements
                    }
                    else
                    {
                        var pp = ((PlayerPosition)packet);
                        if (pp.Position.Y > -900)
                        {
                            SetPosition(pp.Position, true);
                            OnGround = pp.OnGround != 0;
                        }
                    }
                    break;

                case PlayerPositionLookClient.ID:
                    if (AttachedEntity > 0)
                    {
                        //Ignore relative movements
                    }
                    else
                    {
                        PlayerPositionLookClient pp = ((PlayerPositionLookClient)packet);
                        if (pp.Position.Y > -900)
                        {
                            SetPosition(pp.Position, true);
                            OnGround = pp.OnGround;
                        }
                    }
                    Pitch = ((PlayerPositionLookClient)packet).Pitch;
                    Yaw = ((PlayerPositionLookClient)packet).Yaw;
                    break;

                case PlayerGround.ID:
                    OnGround = ((PlayerGround)packet).OnGround;
                    //Good but a few false positives
                    /*
                    if (Sprinting)//Hacked client: Invalid sprint
                    {
                        Chatting.Parser.TellAdmin(Player.Name + Chat.Gray + " sprinting standing still");
                    }*/
                    break;

                case  EntityAction.ID:
                    EntityAction ea = packet as EntityAction;
                    switch (ea.Action)
                    {
                        case EntityAction.Actions.LeaveBed:
                            Sleeping = false;
                            break;
                        case EntityAction.Actions.Crounch:
                            Crouched = true;
                            break;
                        case EntityAction.Actions.Uncrounch:
                            Crouched = false;
                            break;
                        case EntityAction.Actions.StartSprinting:
                            Sprinting = true;
                            break;
                        case EntityAction.Actions.StopSprinting:
                            Sprinting = false;
                            break;
                    }
                    break;

                case UseEntity.ID:
                    if (Mode == GameMode.Creative && (Player.Admin() == false))
                        return; //Donors can't hurt while in creative mode

                    if (UseEntityFromClient((UseEntity)packet))
                        return;
                    break;
                
                case HeldItemClient.ID:
                    //Active item
                    var hc = (HeldItemClient)packet;
                    if (hc.SlotID >= 0 && hc.SlotID <= 8)
                        ActiveInventoryIndex = hc.SlotID;
                    else
                        Log.Write(
                            new InvalidOperationException("Invalid holding slot id: " + hc.SlotID),
                            this.Player
                        );
                    break;
                        
            //Prevent non admins from getting items in creative
                case CreativeInventory.ID:
                    if (Player.Admin() == false)
                    {
                        Player.SendToClient(new EntityStatus(Player.EntityID, EntityStatuses.EntityHurt));
                        Player.TellSystem(Chat.Yellow, "Creative Inventory Disabled");
                        return;
                    }

                    CreativeInventory ci = (CreativeInventory)packet;
                    if (0 <= ci.Slot && ci.Slot <= Inventory.Length)
                        Inventory[ci.Slot] = ci.Item;
                    break;

            //If block action is done from another region
                case PlayerBlockPlacement.ID:
                    //AfkTime = DateTime.Now;

                    //Non admins can't place block
                    if (Mode == GameMode.Creative && (Player.Admin() == false))
                    {
                        Player.SendToClient(new EntityStatus(Player.EntityID, EntityStatuses.EntityHurt));
                        Player.TellSystem(Chat.Yellow, "Creative Build Disabled");
                        return;
                    }

                    PlayerBlockPlacement pb = (PlayerBlockPlacement)packet;
                    if (pb.BlockPosition.IsNull() == false)
                    {
                        CoordDouble pos = pb.BlockPosition.CloneDouble();
                        region = RegionCrossing.GetRegion(pos, Dimension, World.Regions);
                        //Remember the last position clicked so we can do better chest protection
                        LastClickRegion = region; //this is obsolete since we moved to blocking open across regions
                    }
                    else
                    {
                        if (pb.Item != null)
                            Charge = new ChargeState(pb.Item.ItemID);
                    }

                    if (FilterDirection(pb.BlockPosition))
                        return;

                    if (region == null)
                    {
                        if (Dimension == 0 && FilterLava(pb))
                            return;
                    }
                    if (Protected.ProtectBlockPlace(this, region, pb))
                        return;

                    break;
            
                case PlayerDigging.ID:
                    //AfkTime = DateTime.Now;
                    PlayerDigging pd = (PlayerDigging)packet;
                    if (pd.Status == PlayerDigging.StatusEnum.FinishedDigging || pd.Status == PlayerDigging.StatusEnum.StartedDigging)
                    {
                        CoordDouble pos = pd.Position.CloneDouble();
                        region = RegionCrossing.GetRegion(pos, Dimension, World.Regions);
                    }
                    //Log breaking blocks to determine if they found the diamond
                    if (pd.Status == PlayerDigging.StatusEnum.FinishedDigging)
                        OreTracker.BrokeBlock = DateTime.Now;

                    if (pd.Status == PlayerDigging.StatusEnum.ShootArrow)
                        Charge = null;

                    //Prevent non admin creative from digging
                    if (Mode == GameMode.Creative && Player.Admin() == false)
                        return;
                    if (FilterDirection(pd.Position))
                        return;

                    if (Protected.ProtectBlockBreak(this, region, pd))
                        return;
                    break;
            
                case WindowClick.ID:
                    var wc = packet as WindowClick;
                    if (wc.WindowID == 0)
                    {
                        //TODO: handle
                    }
                    //AfkTime = DateTime.Now;
                    if (Protected.ProtectChestsClick(this, wc))
                        return;

                    ///Workaround bug clicky items duplication
                    if (wc.Item != null)
                    {
                        if (wc.Item.Count > 64)
                            return;
                    }
                    break;

                case WindowCloseClient.ID:
                    WindowClose((WindowCloseClient)packet);
                    break;
            }

            if (region != null)
            {
                if (region.Type == SpawnRegion.Type)
                if (SpawnRegion.FilterClient(Player, packet))
                    return;
                if (region.Type == SpawnTimeRegion.Type)
                if (SpawnTimeRegion.FilterClient(region, Player, packet))
                    return;
            }

            SendToBackend(packet);
        }
Exemplo n.º 10
0
        void SendToBackend(PacketFromClient packet)
        {
            if (phase == Phases.FinalClose)
                return;

            Debug.ToServer(packet);

            //Buffer to memory stream
            if (packet.PacketBuffer == null)
                packet.Prepare();

            lock (serverWriterLock)
            {
                if (maxUncompressed >= 0)
                {
                    Packet.WriteVarInt(serverStream, packet.PacketBuffer.Length + Packet.VarIntSize(packet.PacketBufferUncompressedSize));
                    Packet.WriteVarInt(serverStream, packet.PacketBufferUncompressedSize); //Uncompressed size if compressed
                }
                else
                    Packet.WriteVarInt(serverStream, packet.PacketBuffer.Length);

                //Console.WriteLine("TEST: " + (int)ms.Length + " @ " + packet.PacketID);
                serverStream.Write(packet.PacketBuffer, 0, packet.PacketBuffer.Length);
            }
        }