Add small throttle to book edits.

Dieser Commit ist enthalten in:
md_5 2017-04-20 22:10:31 +10:00
Ursprung 4acd0f49e0
Commit 1c3428e534

Datei anzeigen

@ -70,7 +70,7 @@
public PlayerConnection(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer) {
this.minecraftServer = minecraftserver;
@@ -57,7 +104,32 @@
@@ -57,7 +104,33 @@
networkmanager.setPacketListener(this);
this.player = entityplayer;
entityplayer.playerConnection = this;
@ -83,6 +83,7 @@
+ private int lastTick = MinecraftServer.currentTick;
+ private int allowedPlayerTicks = 1;
+ private int lastDropTick = MinecraftServer.currentTick;
+ private int lastBookTick = MinecraftServer.currentTick;
+ private int dropCount = 0;
+ private static final int SURVIVAL_PLACE_DISTANCE_SQUARED = 6 * 6;
+ private static final int CREATIVE_PLACE_DISTANCE_SQUARED = 7 * 7;
@ -103,7 +104,7 @@
public void F_() {
this.syncPosition();
@@ -109,15 +181,21 @@
@@ -109,15 +182,21 @@
}
this.minecraftServer.methodProfiler.b();
@ -125,7 +126,7 @@
this.disconnect("You have been idle for too long!");
}
@@ -137,19 +215,40 @@
@@ -137,19 +216,40 @@
}
public void disconnect(String s) {
@ -169,7 +170,7 @@
}
public void a(PacketPlayInSteerVehicle packetplayinsteervehicle) {
@@ -158,7 +257,7 @@
@@ -158,7 +258,7 @@
}
private static boolean b(PacketPlayInFlying packetplayinflying) {
@ -178,7 +179,7 @@
}
private static boolean b(PacketPlayInVehicleMove packetplayinvehiclemove) {
@@ -188,7 +287,34 @@
@@ -188,7 +288,34 @@
double d9 = entity.motX * entity.motX + entity.motY * entity.motY + entity.motZ * entity.motZ;
double d10 = d6 * d6 + d7 * d7 + d8 * d8;
@ -214,7 +215,7 @@
PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", new Object[] { entity.getName(), this.player.getName(), Double.valueOf(d6), Double.valueOf(d7), Double.valueOf(d8)});
this.networkManager.sendPacket(new PacketPlayOutVehicleMove(entity));
return;
@@ -226,6 +352,62 @@
@@ -226,6 +353,62 @@
return;
}
@ -277,7 +278,7 @@
this.minecraftServer.getPlayerList().d(this.player);
this.player.checkMovement(this.player.locX - d0, this.player.locY - d1, this.player.locZ - d2);
this.D = d11 >= -0.03125D && !this.minecraftServer.getAllowFlight() && !worldserver.c(entity.getBoundingBox().g(0.0625D).b(0.0D, -0.55D, 0.0D));
@@ -260,7 +442,7 @@
@@ -260,7 +443,7 @@
} else {
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
@ -286,7 +287,7 @@
if (this.e == 0) {
this.syncPosition();
}
@@ -270,13 +452,21 @@
@@ -270,13 +453,21 @@
this.A = this.e;
this.a(this.teleportPos.x, this.teleportPos.y, this.teleportPos.z, this.player.yaw, this.player.pitch);
}
@ -309,7 +310,7 @@
double d0 = this.player.locX;
double d1 = this.player.locY;
double d2 = this.player.locZ;
@@ -301,15 +491,33 @@
@@ -301,15 +492,33 @@
++this.receivedMovePackets;
int i = this.receivedMovePackets - this.processedMovePackets;
@ -345,7 +346,7 @@
PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", new Object[] { this.player.getName(), Double.valueOf(d7), Double.valueOf(d8), Double.valueOf(d9)});
this.a(this.player.locX, this.player.locY, this.player.locZ, this.player.yaw, this.player.pitch);
return;
@@ -355,6 +563,69 @@
@@ -355,6 +564,69 @@
}
}
@ -415,7 +416,7 @@
this.B = d12 >= -0.03125D;
this.B &= !this.minecraftServer.getAllowFlight() && !this.player.abilities.canFly;
this.B &= !this.player.hasEffect(MobEffects.LEVITATION) && !this.player.cH() && !worldserver.c(this.player.getBoundingBox().g(0.0625D).b(0.0D, -0.55D, 0.0D));
@@ -372,10 +643,76 @@
@@ -372,10 +644,76 @@
}
public void a(double d0, double d1, double d2, float f, float f1) {
@ -493,7 +494,7 @@
double d3 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.X) ? this.player.locX : 0.0D;
double d4 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Y) ? this.player.locY : 0.0D;
double d5 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Z) ? this.player.locZ : 0.0D;
@@ -392,6 +729,14 @@
@@ -392,6 +730,14 @@
f3 = f1 + this.player.pitch;
}
@ -508,7 +509,7 @@
if (++this.teleportAwait == Integer.MAX_VALUE) {
this.teleportAwait = 0;
}
@@ -403,6 +748,7 @@
@@ -403,6 +749,7 @@
public void a(PacketPlayInBlockDig packetplayinblockdig) {
PlayerConnectionUtils.ensureMainThread(packetplayinblockdig, this, this.player.x());
@ -516,7 +517,7 @@
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
BlockPosition blockposition = packetplayinblockdig.a();
@@ -412,7 +758,15 @@
@@ -412,7 +759,15 @@
if (!this.player.isSpectator()) {
ItemStack itemstack = this.player.b(EnumHand.OFF_HAND);
@ -533,7 +534,7 @@
this.player.a(EnumHand.MAIN_HAND, itemstack);
}
@@ -420,6 +774,21 @@
@@ -420,6 +775,21 @@
case DROP_ITEM:
if (!this.player.isSpectator()) {
@ -555,7 +556,7 @@
this.player.a(false);
}
@@ -453,7 +822,15 @@
@@ -453,7 +823,15 @@
if (!this.minecraftServer.a(worldserver, blockposition, this.player) && worldserver.getWorldBorder().a(blockposition)) {
this.player.playerInteractManager.a(blockposition, packetplayinblockdig.b());
} else {
@ -571,7 +572,7 @@
}
} else {
if (packetplayinblockdig.c() == PacketPlayInBlockDig.EnumPlayerDigType.STOP_DESTROY_BLOCK) {
@@ -473,10 +850,12 @@
@@ -473,10 +851,12 @@
default:
throw new IllegalArgumentException("Invalid player action");
}
@ -584,7 +585,7 @@
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
EnumHand enumhand = packetplayinuseitem.c();
ItemStack itemstack = this.player.b(enumhand);
@@ -490,6 +869,13 @@
@@ -490,6 +870,13 @@
chatmessage.getChatModifier().setColor(EnumChatFormat.RED);
this.player.playerConnection.sendPacket(new PacketPlayOutChat(chatmessage, (byte) 2));
} else if (this.teleportPos == null && this.player.d((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && !this.minecraftServer.a(worldserver, blockposition, this.player) && worldserver.getWorldBorder().a(blockposition)) {
@ -598,7 +599,7 @@
this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand, blockposition, enumdirection, packetplayinuseitem.d(), packetplayinuseitem.e(), packetplayinuseitem.f());
}
@@ -499,13 +885,52 @@
@@ -499,13 +886,52 @@
public void a(PacketPlayInBlockPlace packetplayinblockplace) {
PlayerConnectionUtils.ensureMainThread(packetplayinblockplace, this, this.player.x());
@ -652,7 +653,7 @@
}
}
@@ -516,8 +941,8 @@
@@ -516,8 +942,8 @@
WorldServer[] aworldserver = this.minecraftServer.worldServer;
int i = aworldserver.length;
@ -663,7 +664,7 @@
if (worldserver != null) {
entity = packetplayinspectate.a(worldserver);
@@ -530,6 +955,8 @@
@@ -530,6 +956,8 @@
if (entity != null) {
this.player.setSpectatorTarget(this.player);
this.player.stopRiding();
@ -672,7 +673,7 @@
if (entity.world == this.player.world) {
this.player.enderTeleportTo(entity.locX, entity.locY, entity.locZ);
} else {
@@ -555,12 +982,20 @@
@@ -555,12 +983,20 @@
this.minecraftServer.getPlayerList().b(this.player, worldserver2);
this.minecraftServer.getPlayerList().updateClient(this.player);
}
@ -694,7 +695,7 @@
public void a(PacketPlayInBoatMove packetplayinboatmove) {
PlayerConnectionUtils.ensureMainThread(packetplayinboatmove, this, this.player.x());
@@ -573,14 +1008,29 @@
@@ -573,14 +1009,29 @@
}
public void a(IChatBaseComponent ichatbasecomponent) {
@ -726,7 +727,7 @@
if (this.minecraftServer.R() && this.player.getName().equals(this.minecraftServer.Q())) {
PlayerConnection.LOGGER.info("Stopping singleplayer server as player logged out");
this.minecraftServer.safeShutdown();
@@ -602,6 +1052,15 @@
@@ -602,6 +1053,15 @@
}
}
@ -742,7 +743,7 @@
try {
this.networkManager.sendPacket(packet);
} catch (Throwable throwable) {
@@ -623,17 +1082,32 @@
@@ -623,17 +1083,32 @@
public void a(PacketPlayInHeldItemSlot packetplayinhelditemslot) {
PlayerConnectionUtils.ensureMainThread(packetplayinhelditemslot, this, this.player.x());
@ -777,7 +778,7 @@
ChatMessage chatmessage = new ChatMessage("chat.cannotSend", new Object[0]);
chatmessage.getChatModifier().setColor(EnumChatFormat.RED);
@@ -646,39 +1120,249 @@
@@ -646,39 +1121,249 @@
for (int i = 0; i < s.length(); ++i) {
if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) {
@ -1035,7 +1036,7 @@
this.player.resetIdleTimer();
IJumpable ijumpable;
@@ -750,6 +1434,7 @@
@@ -750,6 +1435,7 @@
public void a(PacketPlayInUseEntity packetplayinuseentity) {
PlayerConnectionUtils.ensureMainThread(packetplayinuseentity, this, this.player.x());
@ -1043,7 +1044,7 @@
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
Entity entity = packetplayinuseentity.a((World) worldserver);
@@ -765,20 +1450,68 @@
@@ -765,20 +1451,68 @@
if (this.player.h(entity) < d0) {
EnumHand enumhand;
@ -1113,7 +1114,7 @@
}
}
}
@@ -794,7 +1527,8 @@
@@ -794,7 +1528,8 @@
case PERFORM_RESPAWN:
if (this.player.viewingCredits) {
this.player.viewingCredits = false;
@ -1123,7 +1124,7 @@
} else {
if (this.player.getHealth() > 0.0F) {
return;
@@ -820,14 +1554,20 @@
@@ -820,14 +1555,20 @@
public void a(PacketPlayInCloseWindow packetplayinclosewindow) {
PlayerConnectionUtils.ensureMainThread(packetplayinclosewindow, this, this.player.x());
@ -1146,7 +1147,7 @@
NonNullList nonnulllist = NonNullList.a();
for (int i = 0; i < this.player.activeContainer.c.size(); ++i) {
@@ -836,8 +1576,274 @@
@@ -836,8 +1577,274 @@
this.player.a(this.player.activeContainer, nonnulllist);
} else {
@ -1155,10 +1156,10 @@
+ if (packetplayinwindowclick.b() < -1 && packetplayinwindowclick.b() != -999) {
+ return;
+ }
+
+ InventoryView inventory = this.player.activeContainer.getBukkitView();
+ SlotType type = CraftInventoryView.getSlotType(inventory, packetplayinwindowclick.b());
+
+ InventoryClickEvent event;
+ ClickType click = ClickType.UNKNOWN;
+ InventoryAction action = InventoryAction.UNKNOWN;
@ -1422,7 +1423,7 @@
if (ItemStack.matches(packetplayinwindowclick.e(), itemstack)) {
this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.a(), packetplayinwindowclick.d(), true));
this.player.f = true;
@@ -866,6 +1872,7 @@
@@ -866,6 +1873,7 @@
public void a(PacketPlayInEnchantItem packetplayinenchantitem) {
PlayerConnectionUtils.ensureMainThread(packetplayinenchantitem, this, this.player.x());
@ -1430,7 +1431,7 @@
this.player.resetIdleTimer();
if (this.player.activeContainer.windowId == packetplayinenchantitem.a() && this.player.activeContainer.c(this.player) && !this.player.isSpectator()) {
this.player.activeContainer.a(this.player, packetplayinenchantitem.b());
@@ -899,7 +1906,46 @@
@@ -899,7 +1907,46 @@
}
boolean flag1 = packetplayinsetcreativeslot.a() >= 1 && packetplayinsetcreativeslot.a() <= 45;
@ -1478,7 +1479,7 @@
if (flag1 && flag2) {
if (itemstack.isEmpty()) {
@@ -923,6 +1969,7 @@
@@ -923,6 +1970,7 @@
public void a(PacketPlayInTransaction packetplayintransaction) {
PlayerConnectionUtils.ensureMainThread(packetplayintransaction, this, this.player.x());
@ -1486,7 +1487,7 @@
Short oshort = (Short) this.k.get(this.player.activeContainer.windowId);
if (oshort != null && packetplayintransaction.b() == oshort.shortValue() && this.player.activeContainer.windowId == packetplayintransaction.a() && !this.player.activeContainer.c(this.player) && !this.player.isSpectator()) {
@@ -933,6 +1980,7 @@
@@ -933,6 +1981,7 @@
public void a(PacketPlayInUpdateSign packetplayinupdatesign) {
PlayerConnectionUtils.ensureMainThread(packetplayinupdatesign, this, this.player.x());
@ -1494,7 +1495,7 @@
this.player.resetIdleTimer();
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
BlockPosition blockposition = packetplayinupdatesign.a();
@@ -949,14 +1997,30 @@
@@ -949,14 +1998,30 @@
if (!tileentitysign.a() || tileentitysign.e() != this.player) {
this.minecraftServer.warning("Player " + this.player.getName() + " just tried to change non-editable sign");
@ -1526,7 +1527,7 @@
tileentitysign.update();
worldserver.notify(blockposition, iblockdata, iblockdata, 3);
@@ -979,11 +2043,27 @@
@@ -979,11 +2044,27 @@
public void a(PacketPlayInAbilities packetplayinabilities) {
PlayerConnectionUtils.ensureMainThread(packetplayinabilities, this, this.player.x());
@ -1555,7 +1556,21 @@
ArrayList arraylist = Lists.newArrayList();
Iterator iterator = this.minecraftServer.tabCompleteCommand(this.player, packetplayintabcomplete.a(), packetplayintabcomplete.b(), packetplayintabcomplete.c()).iterator();
@@ -1027,10 +2107,13 @@
@@ -1009,6 +2090,13 @@
ItemStack itemstack1;
if ("MC|BEdit".equals(s)) {
+ // CraftBukkit start
+ if (this.lastBookTick + 20 > MinecraftServer.currentTick) {
+ this.disconnect("Book edited too quickly!");
+ return;
+ }
+ this.lastBookTick = MinecraftServer.currentTick;
+ // CraftBukkit end
packetdataserializer = packetplayincustompayload.b();
try {
@@ -1027,15 +2115,25 @@
}
if (itemstack.getItem() == Items.WRITABLE_BOOK && itemstack.getItem() == itemstack1.getItem()) {
@ -1569,7 +1584,19 @@
}
} else {
String s1;
@@ -1069,10 +2152,11 @@
if ("MC|BSign".equals(s)) {
+ // CraftBukkit start
+ if (this.lastBookTick + 20 > MinecraftServer.currentTick) {
+ this.disconnect("Book edited too quickly!");
+ return;
+ }
+ this.lastBookTick = MinecraftServer.currentTick;
+ // CraftBukkit end
packetdataserializer = packetplayincustompayload.b();
try {
@@ -1069,10 +2167,11 @@
}
itemstack2.a("pages", (NBTBase) nbttaglist);
@ -1582,7 +1609,7 @@
}
} else if ("MC|TrSel".equals(s)) {
try {
@@ -1084,6 +2168,7 @@
@@ -1084,6 +2183,7 @@
}
} catch (Exception exception2) {
PlayerConnection.LOGGER.error("Couldn\'t select trade", exception2);
@ -1590,7 +1617,7 @@
}
} else {
TileEntity tileentity;
@@ -1133,6 +2218,7 @@
@@ -1133,6 +2233,7 @@
}
} catch (Exception exception3) {
PlayerConnection.LOGGER.error("Couldn\'t set command block", exception3);
@ -1598,7 +1625,7 @@
}
} else if ("MC|AutoCmd".equals(s)) {
if (!this.minecraftServer.getEnableCommandBlock()) {
@@ -1200,6 +2286,7 @@
@@ -1200,6 +2301,7 @@
}
} catch (Exception exception4) {
PlayerConnection.LOGGER.error("Couldn\'t set command block", exception4);
@ -1606,7 +1633,7 @@
}
} else {
int k;
@@ -1223,6 +2310,7 @@
@@ -1223,6 +2325,7 @@
}
} catch (Exception exception5) {
PlayerConnection.LOGGER.error("Couldn\'t set beacon", exception5);
@ -1614,7 +1641,7 @@
}
}
} else if ("MC|ItemName".equals(s)) {
@@ -1309,6 +2397,7 @@
@@ -1309,6 +2412,7 @@
}
} catch (Exception exception6) {
PlayerConnection.LOGGER.error("Couldn\'t set structure block", exception6);
@ -1622,7 +1649,7 @@
}
} else if ("MC|PickItem".equals(s)) {
packetdataserializer = packetplayincustompayload.b();
@@ -1323,9 +2412,31 @@
@@ -1323,9 +2427,31 @@
PlayerConnection.LOGGER.error("Couldn\'t pick item", exception7);
}
}