Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [PacketEvent(KnownPacket.ModifyTileList, KnownPacket.DamageTileGroup, KnownPacket.DamageTile, KnownPacket.ConnectWire, KnownPacket.DisconnectAllWires,
- KnownPacket.EntityCreate, KnownPacket.SpawnEntity, KnownPacket.TileLiquidUpdate)]
- public async Task OnTryBuild(IPacket packet, SharpStarClient client)
- {
- if (_planets == null || _planets.Count == 0)
- return;
- KnownPacket p = (KnownPacket)packet.PacketId;
- if (client.Server.Player.Coordinates != null && !client.Server.Player.OnShip)
- {
- if (client.Server.Player.UserAccount != null)
- {
- if (client.Server.Player.UserAccount.IsAdmin) //all admins are allowed to build
- return;
- var planets = _planets.SingleOrDefault(x => x.Key.Item1 == client.Server.Player.Coordinates);
- if (planets.Value == null)
- return;
- Builder builder = planets.Value.SingleOrDefault(w => w.UserId == client.Server.Player.UserAccount.Id && w.Allowed);
- if (builder == null && planets.Key.Item2 != client.Server.Player.UserAccount.Id)
- {
- if (p == KnownPacket.EntityCreate)
- {
- if (EssentialCommands.Config.ConfigFile.AllowProjectiles)
- return;
- var ec = (EntityCreatePacket)packet;
- foreach (Entity ent in ec.Entities)
- {
- if (ent.EntityType == EntityType.Effect && client.Direction == Direction.Server)
- {
- packet.Ignore = true;
- break;
- }
- if (ent.EntityType == EntityType.Projectile)
- {
- ProjectileEntity pent = (ProjectileEntity)ent;
- if (pent.ThrowerEntityId != client.Server.Player.EntityId)
- continue;
- if (EssentialCommands.Config.ConfigFile.ProjectileWhitelist.Any(x => x.Equals(pent.Projectile, StringComparison.OrdinalIgnoreCase)))
- continue;
- if (string.IsNullOrEmpty(EssentialCommands.Config.ConfigFile.ReplaceProjectileWith))
- {
- await client.Server.PlayerClient.SendPacket(new EntityDestroyPacket
- {
- EntityId = ent.EntityId,
- Unknown = new byte[0]
- });
- packet.Ignore = true;
- break;
- }
- pent.Projectile = EssentialCommands.Config.ConfigFile.ReplaceProjectileWith;
- }
- }
- }
- else if (p == KnownPacket.SpawnEntity)
- {
- if (EssentialCommands.Config.ConfigFile.AllowProjectiles)
- return;
- var ec = (SpawnEntityPacket)packet;
- foreach (SpawnedEntity ent in ec.SpawnedEntities)
- {
- if (ent.EntityType == EntityType.Projectile && ent is SpawnedProjectile)
- {
- SpawnedProjectile sp = (SpawnedProjectile)ent;
- if (!EssentialCommands.Config.ConfigFile.ProjectileWhitelist.Any(x => x.Equals(sp.ProjectileKey, StringComparison.OrdinalIgnoreCase)))
- {
- packet.Ignore = true;
- break;
- }
- }
- else if (ent.EntityType == EntityType.Object || ent.EntityType == EntityType.Plant || ent.EntityType == EntityType.PlantDrop || ent.EntityType == EntityType.Monster
- || ent.EntityType == EntityType.Effect)
- {
- packet.Ignore = true;
- break;
- }
- }
- }
- else
- {
- packet.Ignore = true;
- }
- }
- }
- else
- {
- var planets = _planets.SingleOrDefault(x => x.Key.Item1 == client.Server.Player.Coordinates);
- if (planets.Value != null)
- {
- if (p == KnownPacket.EntityCreate)
- {
- if (EssentialCommands.Config.ConfigFile.AllowProjectiles)
- return;
- var ec = (EntityCreatePacket)packet;
- foreach (Entity ent in ec.Entities)
- {
- if (ent.EntityType == EntityType.Effect && client.Direction == Direction.Server)
- {
- packet.Ignore = true;
- break;
- }
- if (ent.EntityType == EntityType.Projectile)
- {
- ProjectileEntity pent = (ProjectileEntity)ent;
- if (pent.ThrowerEntityId != client.Server.Player.EntityId)
- continue;
- if (EssentialCommands.Config.ConfigFile.ProjectileWhitelist.Any(x => x.Equals(pent.Projectile, StringComparison.OrdinalIgnoreCase)))
- continue;
- if (string.IsNullOrEmpty(EssentialCommands.Config.ConfigFile.ReplaceProjectileWith))
- {
- await client.Server.PlayerClient.SendPacket(new EntityDestroyPacket
- {
- EntityId = ent.EntityId,
- Unknown = new byte[0]
- });
- packet.Ignore = true;
- break;
- }
- pent.Projectile = EssentialCommands.Config.ConfigFile.ReplaceProjectileWith;
- }
- }
- }
- else if (p == KnownPacket.SpawnEntity)
- {
- if (EssentialCommands.Config.ConfigFile.AllowProjectiles)
- return;
- var ec = (SpawnEntityPacket)packet;
- foreach (SpawnedEntity ent in ec.SpawnedEntities)
- {
- if (ent.EntityType == EntityType.Projectile && ent is SpawnedProjectile)
- {
- SpawnedProjectile sp = (SpawnedProjectile)ent;
- if (!EssentialCommands.Config.ConfigFile.ProjectileWhitelist.Any(x => x.Equals(sp.ProjectileKey, StringComparison.OrdinalIgnoreCase)))
- {
- packet.Ignore = true;
- break;
- }
- }
- else if (ent.EntityType == EntityType.Object || ent.EntityType == EntityType.Plant || ent.EntityType == EntityType.PlantDrop || ent.EntityType == EntityType.Monster
- || ent.EntityType == EntityType.Effect)
- {
- packet.Ignore = true;
- break;
- }
- }
- }
- else
- {
- packet.Ignore = true;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement