Advertisement
Guest User

VAD

a guest
Nov 27th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.96 KB | None | 0 0
  1. [PacketEvent(KnownPacket.ModifyTileList, KnownPacket.DamageTileGroup, KnownPacket.DamageTile, KnownPacket.ConnectWire, KnownPacket.DisconnectAllWires,
  2. KnownPacket.EntityCreate, KnownPacket.SpawnEntity, KnownPacket.TileLiquidUpdate)]
  3. public async Task OnTryBuild(IPacket packet, SharpStarClient client)
  4. {
  5.  
  6. if (_planets == null || _planets.Count == 0)
  7. return;
  8.  
  9. KnownPacket p = (KnownPacket)packet.PacketId;
  10.  
  11. if (client.Server.Player.Coordinates != null && !client.Server.Player.OnShip)
  12. {
  13.  
  14. if (client.Server.Player.UserAccount != null)
  15. {
  16.  
  17. if (client.Server.Player.UserAccount.IsAdmin) //all admins are allowed to build
  18. return;
  19.  
  20. var planets = _planets.SingleOrDefault(x => x.Key.Item1 == client.Server.Player.Coordinates);
  21.  
  22. if (planets.Value == null)
  23. return;
  24.  
  25. Builder builder = planets.Value.SingleOrDefault(w => w.UserId == client.Server.Player.UserAccount.Id && w.Allowed);
  26.  
  27. if (builder == null && planets.Key.Item2 != client.Server.Player.UserAccount.Id)
  28. {
  29.  
  30. if (p == KnownPacket.EntityCreate)
  31. {
  32.  
  33. if (EssentialCommands.Config.ConfigFile.AllowProjectiles)
  34. return;
  35.  
  36. var ec = (EntityCreatePacket)packet;
  37.  
  38. foreach (Entity ent in ec.Entities)
  39. {
  40. if (ent.EntityType == EntityType.Effect && client.Direction == Direction.Server)
  41. {
  42. packet.Ignore = true;
  43.  
  44. break;
  45. }
  46. if (ent.EntityType == EntityType.Projectile)
  47. {
  48.  
  49. ProjectileEntity pent = (ProjectileEntity)ent;
  50.  
  51. if (pent.ThrowerEntityId != client.Server.Player.EntityId)
  52. continue;
  53.  
  54. if (EssentialCommands.Config.ConfigFile.ProjectileWhitelist.Any(x => x.Equals(pent.Projectile, StringComparison.OrdinalIgnoreCase)))
  55. continue;
  56.  
  57. if (string.IsNullOrEmpty(EssentialCommands.Config.ConfigFile.ReplaceProjectileWith))
  58. {
  59. await client.Server.PlayerClient.SendPacket(new EntityDestroyPacket
  60. {
  61. EntityId = ent.EntityId,
  62. Unknown = new byte[0]
  63. });
  64.  
  65. packet.Ignore = true;
  66.  
  67. break;
  68. }
  69.  
  70. pent.Projectile = EssentialCommands.Config.ConfigFile.ReplaceProjectileWith;
  71.  
  72. }
  73. }
  74. }
  75. else if (p == KnownPacket.SpawnEntity)
  76. {
  77. if (EssentialCommands.Config.ConfigFile.AllowProjectiles)
  78. return;
  79.  
  80. var ec = (SpawnEntityPacket)packet;
  81.  
  82. foreach (SpawnedEntity ent in ec.SpawnedEntities)
  83. {
  84. if (ent.EntityType == EntityType.Projectile && ent is SpawnedProjectile)
  85. {
  86. SpawnedProjectile sp = (SpawnedProjectile)ent;
  87.  
  88. if (!EssentialCommands.Config.ConfigFile.ProjectileWhitelist.Any(x => x.Equals(sp.ProjectileKey, StringComparison.OrdinalIgnoreCase)))
  89. {
  90. packet.Ignore = true;
  91.  
  92. break;
  93. }
  94. }
  95. else if (ent.EntityType == EntityType.Object || ent.EntityType == EntityType.Plant || ent.EntityType == EntityType.PlantDrop || ent.EntityType == EntityType.Monster
  96. || ent.EntityType == EntityType.Effect)
  97. {
  98. packet.Ignore = true;
  99.  
  100. break;
  101. }
  102. }
  103.  
  104. }
  105. else
  106. {
  107. packet.Ignore = true;
  108. }
  109.  
  110. }
  111.  
  112. }
  113. else
  114. {
  115.  
  116. var planets = _planets.SingleOrDefault(x => x.Key.Item1 == client.Server.Player.Coordinates);
  117.  
  118. if (planets.Value != null)
  119. {
  120.  
  121. if (p == KnownPacket.EntityCreate)
  122. {
  123.  
  124. if (EssentialCommands.Config.ConfigFile.AllowProjectiles)
  125. return;
  126.  
  127. var ec = (EntityCreatePacket)packet;
  128.  
  129. foreach (Entity ent in ec.Entities)
  130. {
  131. if (ent.EntityType == EntityType.Effect && client.Direction == Direction.Server)
  132. {
  133. packet.Ignore = true;
  134.  
  135. break;
  136. }
  137. if (ent.EntityType == EntityType.Projectile)
  138. {
  139.  
  140. ProjectileEntity pent = (ProjectileEntity)ent;
  141.  
  142. if (pent.ThrowerEntityId != client.Server.Player.EntityId)
  143. continue;
  144.  
  145. if (EssentialCommands.Config.ConfigFile.ProjectileWhitelist.Any(x => x.Equals(pent.Projectile, StringComparison.OrdinalIgnoreCase)))
  146. continue;
  147.  
  148. if (string.IsNullOrEmpty(EssentialCommands.Config.ConfigFile.ReplaceProjectileWith))
  149. {
  150. await client.Server.PlayerClient.SendPacket(new EntityDestroyPacket
  151. {
  152. EntityId = ent.EntityId,
  153. Unknown = new byte[0]
  154. });
  155.  
  156. packet.Ignore = true;
  157.  
  158. break;
  159. }
  160.  
  161. pent.Projectile = EssentialCommands.Config.ConfigFile.ReplaceProjectileWith;
  162.  
  163. }
  164. }
  165. }
  166. else if (p == KnownPacket.SpawnEntity)
  167. {
  168. if (EssentialCommands.Config.ConfigFile.AllowProjectiles)
  169. return;
  170.  
  171. var ec = (SpawnEntityPacket)packet;
  172.  
  173. foreach (SpawnedEntity ent in ec.SpawnedEntities)
  174. {
  175. if (ent.EntityType == EntityType.Projectile && ent is SpawnedProjectile)
  176. {
  177. SpawnedProjectile sp = (SpawnedProjectile)ent;
  178.  
  179. if (!EssentialCommands.Config.ConfigFile.ProjectileWhitelist.Any(x => x.Equals(sp.ProjectileKey, StringComparison.OrdinalIgnoreCase)))
  180. {
  181. packet.Ignore = true;
  182. break;
  183. }
  184. }
  185. else if (ent.EntityType == EntityType.Object || ent.EntityType == EntityType.Plant || ent.EntityType == EntityType.PlantDrop || ent.EntityType == EntityType.Monster
  186. || ent.EntityType == EntityType.Effect)
  187. {
  188. packet.Ignore = true;
  189.  
  190. break;
  191. }
  192. }
  193.  
  194. }
  195. else
  196. {
  197. packet.Ignore = true;
  198. }
  199.  
  200. }
  201.  
  202. }
  203.  
  204. }
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement