Пример #1
0
 void OnReceiveProjectile(ref HookContext ctx, ref HookArgs.ProjectileReceived args)
 {
     if (!explosivesAllowed && args.Type.IsExplosive())
     {
         Log("Cancelled Explosive usage of Player: " + ctx.Player.Name);
         ctx.SetResult(HookResult.ERASE);
     }
 }
        void OnProjectile(ref HookContext ctx, ref HookArgs.ProjectileReceived args)
        {
            var player = ctx.Player;

            if (player == null && ctx.Sender is Projectile)
            {
                player = (ctx.Sender as Projectile).Creator as Player;
            }

            if (player == null || player.Name == null)
            {
                ProgramLog.Error.Log("<Restrict> Invalid player in OnProjectile.");
                ctx.SetResult(HookResult.IGNORE);
                return;
            }

            if (!restrictGuests)
            {
                return;
            }

            //if (player.AuthenticatedAs == null)
            {
                switch (args.Type)
                {
                case ProjectileType.N10_PURIFICATION_POWDER:
                case ProjectileType.N11_VILE_POWDER:
                case ProjectileType.N28_BOMB:
                case ProjectileType.N37_STICKY_BOMB:
                case ProjectileType.N29_DYNAMITE:
                case ProjectileType.N30_GRENADE:
                case ProjectileType.N31_SAND_BALL:
                case ProjectileType.N39_MUD_BALL:
                case ProjectileType.N40_ASH_BALL:
                case ProjectileType.N42_SAND_BALL:
                case ProjectileType.N43_TOMBSTONE:
                case ProjectileType.N50_GLOWSTICK:
                case ProjectileType.N53_STICKY_GLOWSTICK:
                    ctx.SetResult(HookResult.ERASE);
                    if (player.AuthenticatedAs == null)
                    {
                        player.sendMessage("<Restrict> You are not allowed to use this projectile as a guest.");
                        player.sendMessage("<Restrict> Type \"/reg password\" to request registration.");
                    }
                    else if (IsRestrictedForUser(ctx.Player, ProjectileUse))
                    {
                        player.sendMessage("<Restrict> You are not allowed to use this projectile without permissions.");
                    }

                    return;

                default:
                    break;
                }
            }

            return;
        }
 void OnReceiveProjectile(ref HookContext ctx, ref HookArgs.ProjectileReceived args)
 {
     if (!explosivesAllowed)
     {
         int type = (int)args.Type;
         if (type == (int)ProjectileType.N28_BOMB /* 28 */ ||
             type == (int)ProjectileType.N29_DYNAMITE /* 29 */ ||
             type == (int)ProjectileType.N37_STICKY_BOMB /* 37 */)
         {
             Log("Cancelled Explosive usage of Player: " + ctx.Player.Name);
             ctx.SetResult(HookResult.ERASE);
         }
     }
 }
Пример #4
0
        void OnProjectileReceived(ref HookContext ctx, ref HookArgs.ProjectileReceived args)
        {
            Vector2 Position = new Vector2(args.X, args.Y);

            foreach (Region rgn in regionManager.Regions)
            {
                if (rgn.HasPoint(Position / 16))
                {
                    if (rgn.ProjectileList.Contains("*") ||
                        rgn.ProjectileList.Contains(args.Type.ToString()))    // ||
                    //rgn.ProjectileList.Contains(args.Projectile.Name.ToLower().Replace(" ", "")))
                    {
                        if (IsRestrictedForUser(ctx.Player, rgn, ProjectileUse))
                        {
                            ctx.SetResult(HookResult.ERASE);
                            ctx.Player.sendMessage("You cannot edit this area!", ChatColor.Red);
                            return;
                        }
                    }
                }
            }
        }
        public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            short projectileIdentity = BitConverter.ToInt16(readBuffer, num);

            num += 2;
            float x = BitConverter.ToSingle(readBuffer, num);

            num += 4;
            float y = BitConverter.ToSingle(readBuffer, num);

            num += 4;
            float vX = BitConverter.ToSingle(readBuffer, num);

            num += 4;
            float vY = BitConverter.ToSingle(readBuffer, num);

            num += 4;
            float knockBack = BitConverter.ToSingle(readBuffer, num);

            num += 4;
            short damage = BitConverter.ToInt16(readBuffer, num);

            num += 2;

            byte projectileOwner = readBuffer[num++];
            byte type            = readBuffer[num++];

            if (projectileOwner != whoAmI)
            {
#if DEBUG_PROJECTILES
                ProgramLog.Debug.Log("Ignoring unowned projectile from {0} ({1})", whoAmI, projectileOwner);
#endif
                return;
            }

            if (Projectile.MAX_AI != 2)
            {
                throw new Exception("Projectile receiving code hasn't been updated!");
            }

            var ai0 = BitConverter.ToSingle(readBuffer, num); num += 4;
            var ai1 = BitConverter.ToSingle(readBuffer, num);

            var player = Main.players[whoAmI];

            var projectileIndex = Projectile.FindExisting(projectileIdentity, projectileOwner);

            var ctx = new HookContext
            {
                Connection = player.Connection,
                Player     = player,
                Sender     = player,
            };

            var args = new HookArgs.ProjectileReceived
            {
                X             = x, Y = y, VX = vX, VY = vY,
                Id            = projectileIdentity,
                Owner         = projectileOwner,
                Knockback     = knockBack,
                Damage        = damage,
                TypeByte      = type,
                AI_0          = ai0, AI_1 = ai1,
                ExistingIndex = projectileIndex < 1000 ? projectileIndex : -1,
            };

            if (projectileIndex == 1000 && args.Type.IsHighExplosive() && ai0 > 0.0)
            {
                // probably a lagged update from a repossessed projectile
#if DEBUG_PROJECTILES
                ProgramLog.Debug.Log("Ignoring old update for repossessed projectile.");
#endif

                var msg = NetMessage.PrepareThreadInstance();
                msg.EraseProjectile(projectileIdentity, projectileOwner);
                msg.Send(whoAmI);
                return;
            }

            HookPoints.ProjectileReceived.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
            {
                args.CleanupProjectile();
                return;
            }

            if (ctx.Result == HookResult.IGNORE)
            {
                args.CleanupProjectile();
                return;
            }

            if (ctx.Result == HookResult.RECTIFY)
            {
                args.CleanupProjectile();

                if (projectileIndex < 1000)
                {
                    var msg = NetMessage.PrepareThreadInstance();
                    msg.Projectile(Main.projectile[projectileIndex]);
                    msg.Send(whoAmI);
                    return;
                }
                else
                {
                    ctx.SetResult(HookResult.ERASE);
                }
            }

            if (ctx.Result == HookResult.ERASE)
            {
                args.CleanupProjectile();

                var msg = NetMessage.PrepareThreadInstance();
                msg.EraseProjectile(projectileIdentity, projectileOwner);
                msg.Send(whoAmI);
                return;
            }

            if (ctx.Result != HookResult.CONTINUE)
            {
                if (type > Projectile.MAX_PROJECTILES)
                {
                    args.CleanupProjectile();
                    NetPlay.slots[whoAmI].Kick("Invalid projectile.");
                    return;
                }
                else if (type == (int)ProjectileType.N38_HARPY_FEATHER ||
                         type == (int)ProjectileType.N55_STINGER ||
                         type == (int)ProjectileType.N44_DEMON_SICKLE)
                {
                    args.CleanupProjectile();
                    NetPlay.slots[whoAmI].Kick("Projectile cheat detected.");
                    return;
                }
                else if (type == (int)ProjectileType.N23_HARPOON)
                {
                    args.CleanupProjectile();
                    if (Math.Abs(vX) + Math.Abs(vY) < 1e-4)                       // ideally, we'd want to figure out all projectiles that never have 0 velocity
                    {
                        NetPlay.slots[whoAmI].Kick("Harpoon cheat detected.");
                        return;
                    }
                }
            }

            Projectile projectile;

            if (args.ExistingIndex >= 0)
            {
#if DEBUG_PROJECTILES
                ProgramLog.Debug.Log("Updated projectile {0} ({1}/{2}/{3}) ({4}/{5})", projectileIndex, projectileOwner, projectileIdentity, args.Type, ai0, ai1);
#endif
                args.CleanupProjectile();
                projectile = Main.projectile[args.ExistingIndex];
                args.Apply(projectile);
            }
            else
            {
                projectile = args.CreateProjectile();

                if (projectile == null)
                {
                    //ProgramLog.Debug.Log ("No slots left for projectile ({1}/{2}/{3})", projectileOwner, projectileIdentity, args.Type);
                    return;
                }

                projectileIndex = projectile.whoAmI;
#if DEBUG_PROJECTILES
                ProgramLog.Debug.Log("Created projectile {0} ({1}/{2}/{3}) ({4}/{5})", projectileIndex, projectileOwner, projectileIdentity, args.Type, ai0, ai1);
#endif
            }

            if (args.Type.IsHighExplosive())
            {
#if DEBUG_PROJECTILES
                ProgramLog.Debug.Log("Repossessing projectile ({0}, {1}, {2}, {3}).", vX, vY, ai0, ai1);
#endif
                // transfer ownership
                //var msg = NetMessage.PrepareThreadInstance ();
                //msg.EraseProjectile (projectileIdentity, projectileOwner);
                //projectile.Repossess ();
                //msg.Projectile (projectile);
                //msg.Send (whoAmI);

                /* temp, Until Repossessing is complete, At the moment if killed by a repossessed projectile
                 * the client wont be killed, the death text will fire once, thereafter they cannot
                 * be killed via explosives. */
                if (Server.RejectedItems.Contains(args.TypeByte.ToString()) ||
                    Server.RejectedItems.Contains(projectile.Name) ||
                    !Program.properties.AllowExplosions)
                {
                    var msg = NetMessage.PrepareThreadInstance();
                    msg.EraseProjectile(projectileIdentity, projectileOwner);
                    msg.Send(whoAmI);
                }
            }

//            int projectileIndex = getProjectileIndex(projectileOwner, projectileIdentity);
//            Projectile oldProjectile = Main.projectile[projectileIndex];
//            if (!oldProjectile.Active || projectile.type != oldProjectile.type)
//            {
//                NetPlay.slots[whoAmI].spamProjectile += 1f;
//            }

//            if (playerEvent.Cancelled || (!Program.properties.AllowExplosions &&
//                (   type == (int)ProjectileType.BOMB        /* 28 */ ||
//                    type == (int)ProjectileType.DYNAMITE    /* 29 */ ||
//                    type == (int)ProjectileType.BOMB_STICKY /* 37 */
//                ) && !Main.players[whoAmI].Op))
//            {
//                // erase the projectile client-side
//                projectile.Position.X = -1000;
//                projectile.Position.Y = -1000;
//                projectile.type = ProjectileType.UNKNOWN;
//
//                var msg = NetMessage.PrepareThreadInstance ();
//                msg.Projectile (projectile);
//                msg.Send (whoAmI);
//
//                return;
//            }

            Main.projectile[projectileIndex] = projectile;

            NetMessage.SendData(27, -1, whoAmI, "", projectileIndex);
        }
        private static void ProcessProjectile(int bufferId)
        {
            var buffer = NetMessage.buffer[bufferId];

            int      identity  = (int)buffer.reader.ReadInt16();
            Vector2  position  = buffer.reader.ReadVector2();
            Vector2  velocity  = buffer.reader.ReadVector2();
            float    knockBack = buffer.reader.ReadSingle();
            int      damage    = (int)buffer.reader.ReadInt16();
            int      owner     = (int)buffer.reader.ReadByte();
            int      type      = (int)buffer.reader.ReadInt16();
            BitsByte flags     = buffer.reader.ReadByte();

            float[] ai = new float[Projectile.maxAI];

            for (int i = 0; i < Projectile.maxAI; i++)
            {
                if (flags[i])
                {
                    ai[i] = buffer.reader.ReadSingle();
                }
                else
                {
                    ai[i] = 0;
                }
            }
            if (Main.netMode == 2)
            {
                owner = bufferId;
                if (Main.projHostile[type])
                {
                    return;
                }
            }
            int index = 1000;

            for (int i = 0; i < 1000; i++)
            {
                if (Main.projectile[i].owner == owner && Main.projectile[i].identity == identity && Main.projectile[i].active)
                {
                    index = i;
                    break;
                }
            }
            if (index == 1000)
            {
                for (int i = 0; i < 1000; i++)
                {
                    if (!Main.projectile[i].active)
                    {
                        index = i;
                        break;
                    }
                }
            }

            var player = Main.player[bufferId];
            var ctx    = new HookContext
            {
                Connection = player.Connection,
                Player     = player,
                Sender     = player,
            };

            var args = new HookArgs.ProjectileReceived
            {
                Position      = position,
                Velocity      = velocity,
                Id            = identity,
                Owner         = bufferId,
                Knockback     = knockBack,
                Damage        = damage,
                Type          = type,
                AI            = ai,
                ExistingIndex = index < 1000 ? index : -1
            };

            HookPoints.ProjectileReceived.Invoke(ref ctx, ref args);

            if (ctx.Result == HookResult.DEFAULT)
            {
                if (index > -1 && index < 1000)
                {
                    Projectile projectile = Main.projectile[index];
                    if (!projectile.active || projectile.type != type)
                    {
                        projectile.SetDefaults(type);
                        if (Main.netMode == 2)
                        {
                            Netplay.Clients[bufferId].SpamProjectile += 1;
                        }
                    }
                    projectile.identity  = identity;
                    projectile.position  = position;
                    projectile.velocity  = velocity;
                    projectile.type      = type;
                    projectile.damage    = damage;
                    projectile.knockBack = knockBack;
                    projectile.owner     = owner;
                    for (int num85 = 0; num85 < Projectile.maxAI; num85++)
                    {
                        projectile.ai[num85] = ai[num85];
                    }
                    projectile.ProjectileFixDesperation(owner);
                    if (Main.netMode == 2)
                    {
                        NetMessage.SendData(27, -1, bufferId, "", index, 0, 0, 0, 0, 0, 0);
                    }
                }
            }
        }
        public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            //TODO [ProjectileReceived]

            var identity  = (int)ReadInt16(readBuffer);
            var position  = ReadVector2(readBuffer);
            var velocity  = ReadVector2(readBuffer);
            var knockBack = ReadSingle(readBuffer);
            var damage    = (int)ReadInt16(readBuffer);

            /*var targetOwner =*/
            ReadByte(readBuffer);
            var type  = (int)ReadInt16(readBuffer);
            var flags = (BitsByte)ReadByte(readBuffer);
            var ai    = new float[Projectile.maxAI];

            for (var i = 0; i < Projectile.maxAI; i++)
            {
                if (flags[i])
                {
                    ai[i] = ReadSingle(readBuffer);
                }
                else
                {
                    ai[i] = 0f;
                }
            }

            if (Main.projHostile[type])
            {
                return;
            }

            var index = 1000;

            //Attempt to find the existing projectile.
            for (var i = 0; i < 1000; i++)
            {
                if (Main.projectile[i].owner == whoAmI && Main.projectile[i].identity == identity && Main.projectile[i].active)
                {
                    index = i;
                    break;
                }
            }

            if (index == 1000)
            {
                //Find the next slot since there was no existing projectile.
                for (var i = 0; i < 1000; i++)
                {
                    if (!Main.projectile[i].active)
                    {
                        index = i;
                        break;
                    }
                }
            }

            var player = Main.player[whoAmI];
            var ctx    = new HookContext
            {
                Connection = player.Connection,
                Player     = player,
                Sender     = player,
            };

            var args = new HookArgs.ProjectileReceived
            {
                Position      = position,
                Velocity      = velocity,
                Id            = identity,
                Owner         = whoAmI,
                Knockback     = knockBack,
                Damage        = damage,
                Type          = type,
                AI            = ai,
                ExistingIndex = index < 1000 ? index : -1
            };

            HookPoints.ProjectileReceived.Invoke(ref ctx, ref args);

            if (ctx.Result == HookResult.DEFAULT)
            {
                if (index > -1 && index < 1000)
                {
                    var projectile = Main.projectile[index];
                    if (!projectile.active || projectile.type != type)
                    {
                        projectile.SetDefaults(type);
                        Terraria.Netplay.Clients[whoAmI].SpamProjectile += 1f;
                    }

                    projectile.identity  = identity;
                    projectile.position  = position;
                    projectile.velocity  = velocity;
                    projectile.type      = type;
                    projectile.damage    = damage;
                    projectile.knockBack = knockBack;
                    projectile.owner     = whoAmI;

                    for (var i = 0; i < Projectile.maxAI; i++)
                    {
                        projectile.ai[i] = ai[i];
                    }

                    NewNetMessage.SendData(Packet.PROJECTILE, -1, whoAmI, String.Empty, index);
                }
            }
        }