From 99449d5d8f8dd83b48ded923ccee9d681028df5a Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 21 May 2015 17:15:47 +1000 Subject: SPIGOT-854: Reset idle timer on disconnect to prevent spam duplicate disconnect. --- nms-patches/PlayerConnection.patch | 90 ++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/nms-patches/PlayerConnection.patch b/nms-patches/PlayerConnection.patch index 9c3331cc..f4ad8906 100644 --- a/nms-patches/PlayerConnection.patch +++ b/nms-patches/PlayerConnection.patch @@ -1,5 +1,5 @@ ---- /home/matt/mc-dev-private//net/minecraft/server/PlayerConnection.java 2015-05-20 16:15:15.756362905 +0100 -+++ src/main/java/net/minecraft/server/PlayerConnection.java 2015-05-20 16:15:15.760362840 +0100 +--- ../work/decompile-c2c33c10/net/minecraft/server/PlayerConnection.java 2015-05-21 17:15:25.666007073 +1000 ++++ src/main/java/net/minecraft/server/PlayerConnection.java 2015-05-21 17:15:25.670007030 +1000 @@ -17,6 +17,48 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -101,7 +101,7 @@ public void c() { this.h = false; ++this.e; -@@ -58,9 +128,14 @@ +@@ -58,15 +128,21 @@ } this.minecraftServer.methodProfiler.b(); @@ -116,7 +116,14 @@ if (this.m > 0) { --this.m; -@@ -77,19 +152,37 @@ + } + + if (this.player.D() > 0L && this.minecraftServer.getIdleTimeout() > 0 && MinecraftServer.az() - this.player.D() > (long) (this.minecraftServer.getIdleTimeout() * 1000 * 60)) { ++ this.player.resetIdleTimer(); // CraftBukkit - SPIGOT-854 + this.disconnect("You have been idle for too long!"); + } + +@@ -77,19 +153,37 @@ } public void disconnect(String s) { @@ -159,7 +166,7 @@ } public void a(PacketPlayInSteerVehicle packetplayinsteervehicle) { -@@ -99,6 +192,17 @@ +@@ -99,6 +193,17 @@ public void a(PacketPlayInFlying packetplayinflying) { PlayerConnectionUtils.ensureMainThread(packetplayinflying, this, this.player.u()); @@ -177,7 +184,7 @@ WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension); this.h = true; -@@ -117,8 +221,66 @@ +@@ -117,8 +222,66 @@ this.checkMovement = true; } } @@ -245,7 +252,7 @@ this.f = this.e; double d7; double d8; -@@ -146,6 +308,7 @@ +@@ -146,6 +309,7 @@ this.minecraftServer.getPlayerList().d(this.player); if (this.player.vehicle != null) { @@ -253,7 +260,7 @@ if (d3 > 4.0D) { Entity entity = this.player.vehicle; -@@ -153,7 +316,7 @@ +@@ -153,7 +317,7 @@ this.a(this.player.locX, this.player.locY, this.player.locZ, this.player.yaw, this.player.pitch); } @@ -262,7 +269,7 @@ } if (this.checkMovement) { -@@ -215,7 +378,7 @@ +@@ -215,7 +379,7 @@ double d14 = this.player.motX * this.player.motX + this.player.motY * this.player.motY + this.player.motZ * this.player.motZ; double d15 = d11 * d11 + d12 * d12 + d13 * d13; @@ -271,7 +278,7 @@ PlayerConnection.c.warn(this.player.getName() + " moved too quickly! " + d11 + "," + d12 + "," + d13 + " (" + d11 + ", " + d12 + ", " + d13 + ")"); this.a(this.o, this.p, this.q, this.player.yaw, this.player.pitch); return; -@@ -284,10 +447,53 @@ +@@ -284,10 +448,53 @@ } public void a(double d0, double d1, double d2, float f, float f1) { @@ -326,7 +333,7 @@ this.checkMovement = false; this.o = d0; this.p = d1; -@@ -321,32 +527,49 @@ +@@ -321,32 +528,49 @@ public void a(PacketPlayInBlockDig packetplayinblockdig) { PlayerConnectionUtils.ensureMainThread(packetplayinblockdig, this, this.player.u()); @@ -382,7 +389,7 @@ double d0 = this.player.locX - ((double) blockposition.getX() + 0.5D); double d1 = this.player.locY - ((double) blockposition.getY() + 0.5D) + 1.5D; double d2 = this.player.locZ - ((double) blockposition.getZ() + 0.5D); -@@ -361,7 +584,15 @@ +@@ -361,7 +585,15 @@ if (!this.minecraftServer.a(worldserver, blockposition, this.player) && worldserver.getWorldBorder().a(blockposition)) { this.player.playerInteractManager.a(blockposition, packetplayinblockdig.b()); } else { @@ -398,7 +405,7 @@ } } else { if (packetplayinblockdig.c() == PacketPlayInBlockDig.EnumPlayerDigType.STOP_DESTROY_BLOCK) { -@@ -381,11 +612,22 @@ +@@ -381,11 +613,22 @@ default: throw new IllegalArgumentException("Invalid player action"); } @@ -421,7 +428,7 @@ ItemStack itemstack = this.player.inventory.getItemInHand(); boolean flag = false; BlockPosition blockposition = packetplayinblockplace.a(); -@@ -397,7 +639,50 @@ +@@ -397,7 +640,50 @@ return; } @@ -473,7 +480,7 @@ } else if (blockposition.getY() >= this.minecraftServer.getMaxBuildHeight() - 1 && (enumdirection == EnumDirection.UP || blockposition.getY() >= this.minecraftServer.getMaxBuildHeight())) { ChatMessage chatmessage = new ChatMessage("build.tooHigh", new Object[] { Integer.valueOf(this.minecraftServer.getMaxBuildHeight())}); -@@ -405,8 +690,19 @@ +@@ -405,8 +691,19 @@ this.player.playerConnection.sendPacket(new PacketPlayOutChat(chatmessage)); flag = true; } else { @@ -494,7 +501,7 @@ } flag = true; -@@ -430,7 +726,8 @@ +@@ -430,7 +727,8 @@ this.player.activeContainer.b(); this.player.g = false; @@ -504,7 +511,7 @@ this.sendPacket(new PacketPlayOutSetSlot(this.player.activeContainer.windowId, slot.rawSlotIndex, this.player.inventory.getItemInHand())); } } -@@ -444,8 +741,8 @@ +@@ -444,8 +742,8 @@ WorldServer[] aworldserver = this.minecraftServer.worldServer; int i = aworldserver.length; @@ -515,7 +522,7 @@ if (worldserver != null) { entity = packetplayinspectate.a(worldserver); -@@ -458,6 +755,8 @@ +@@ -458,6 +756,8 @@ if (entity != null) { this.player.setSpectatorTarget(this.player); this.player.mount((Entity) null); @@ -524,7 +531,7 @@ if (entity.world != this.player.world) { WorldServer worldserver1 = this.player.u(); WorldServer worldserver2 = (WorldServer) entity.world; -@@ -482,6 +781,9 @@ +@@ -482,6 +782,9 @@ } else { this.player.enderTeleportTo(entity.locX, entity.locY, entity.locZ); } @@ -534,11 +541,10 @@ } } -@@ -490,14 +792,29 @@ +@@ -490,14 +793,29 @@ public void a(PacketPlayInResourcePackStatus packetplayinresourcepackstatus) {} public void a(IChatBaseComponent ichatbasecomponent) { -- PlayerConnection.c.info(this.player.getName() + " lost connection: " + ichatbasecomponent); + // CraftBukkit start - Rarely it would send a disconnect line twice + if (this.processedDisconnect) { + return; @@ -546,7 +552,7 @@ + this.processedDisconnect = true; + } + // CraftBukkit end -+ PlayerConnection.c.info(this.player.getName() + " lost connection: " + ichatbasecomponent.c()); // CraftBukkit - Don't toString the component + PlayerConnection.c.info(this.player.getName() + " lost connection: " + ichatbasecomponent); + // CraftBukkit start - Replace vanilla quit message handling with our own. + /* this.minecraftServer.aH(); @@ -566,7 +572,7 @@ if (this.minecraftServer.T() && this.player.getName().equals(this.minecraftServer.S())) { PlayerConnection.c.info("Stopping singleplayer server as player logged out"); this.minecraftServer.safeShutdown(); -@@ -519,6 +836,15 @@ +@@ -519,6 +837,15 @@ } } @@ -582,7 +588,7 @@ try { this.networkManager.handle(packet); } catch (Throwable throwable) { -@@ -539,18 +865,34 @@ +@@ -539,18 +866,34 @@ } public void a(PacketPlayInHeldItemSlot packetplayinhelditemslot) { @@ -619,7 +625,7 @@ ChatMessage chatmessage = new ChatMessage("chat.cannotSend", new Object[0]); chatmessage.getChatModifier().setColor(EnumChatFormat.RED); -@@ -563,39 +905,249 @@ +@@ -563,39 +906,249 @@ for (int i = 0; i < s.length(); ++i) { if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) { @@ -877,7 +883,7 @@ this.player.resetIdleTimer(); switch (PlayerConnection.SyntheticClass_1.b[packetplayinentityaction.b().ordinal()]) { case 1: -@@ -616,7 +1168,7 @@ +@@ -616,7 +1169,7 @@ case 5: this.player.a(false, true, true); @@ -886,7 +892,7 @@ break; case 6: -@@ -638,6 +1190,7 @@ +@@ -638,6 +1191,7 @@ } public void a(PacketPlayInUseEntity packetplayinuseentity) { @@ -894,7 +900,7 @@ PlayerConnectionUtils.ensureMainThread(packetplayinuseentity, this, this.player.u()); WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension); Entity entity = packetplayinuseentity.a((World) worldserver); -@@ -652,18 +1205,67 @@ +@@ -652,18 +1206,67 @@ } if (this.player.h(entity) < d0) { @@ -963,7 +969,7 @@ } } } -@@ -678,7 +1280,8 @@ +@@ -678,7 +1281,8 @@ switch (PlayerConnection.SyntheticClass_1.c[packetplayinclientcommand_enumclientcommand.ordinal()]) { case 1: if (this.player.viewingCredits) { @@ -973,7 +979,7 @@ } else if (this.player.u().getWorldData().isHardcore()) { if (this.minecraftServer.T() && this.player.getName().equals(this.minecraftServer.S())) { this.player.playerConnection.disconnect("You have died. Game over, man, it\'s game over!"); -@@ -709,15 +1312,21 @@ +@@ -709,15 +1313,21 @@ } public void a(PacketPlayInCloseWindow packetplayinclosewindow) { @@ -996,7 +1002,7 @@ ArrayList arraylist = Lists.newArrayList(); for (int i = 0; i < this.player.activeContainer.c.size(); ++i) { -@@ -726,7 +1335,270 @@ +@@ -726,7 +1336,270 @@ this.player.a(this.player.activeContainer, (List) arraylist); } else { @@ -1268,7 +1274,7 @@ if (ItemStack.matches(packetplayinwindowclick.e(), itemstack)) { this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.a(), packetplayinwindowclick.d(), true)); -@@ -787,8 +1659,48 @@ +@@ -787,8 +1660,48 @@ } boolean flag1 = packetplayinsetcreativeslot.a() >= 1 && packetplayinsetcreativeslot.a() < 36 + PlayerInventory.getHotbarSize(); @@ -1318,7 +1324,7 @@ if (flag1 && flag2 && flag3) { if (itemstack == null) { -@@ -811,6 +1723,7 @@ +@@ -811,6 +1724,7 @@ } public void a(PacketPlayInTransaction packetplayintransaction) { @@ -1326,7 +1332,7 @@ PlayerConnectionUtils.ensureMainThread(packetplayintransaction, this, this.player.u()); Short oshort = (Short) this.n.get(this.player.activeContainer.windowId); -@@ -821,6 +1734,7 @@ +@@ -821,6 +1735,7 @@ } public void a(PacketPlayInUpdateSign packetplayinupdatesign) { @@ -1334,7 +1340,7 @@ PlayerConnectionUtils.ensureMainThread(packetplayinupdatesign, this, this.player.u()); this.player.resetIdleTimer(); WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension); -@@ -837,14 +1751,30 @@ +@@ -837,14 +1752,30 @@ if (!tileentitysign.b() || tileentitysign.c() != this.player) { this.minecraftServer.warning("Player " + this.player.getName() + " just tried to change non-editable sign"); @@ -1366,7 +1372,7 @@ tileentitysign.update(); worldserver.notify(blockposition); -@@ -867,11 +1797,27 @@ +@@ -867,11 +1798,27 @@ public void a(PacketPlayInAbilities packetplayinabilities) { PlayerConnectionUtils.ensureMainThread(packetplayinabilities, this, this.player.u()); @@ -1395,7 +1401,7 @@ ArrayList arraylist = Lists.newArrayList(); Iterator iterator = this.minecraftServer.tabCompleteCommand(this.player, packetplayintabcomplete.a(), packetplayintabcomplete.b()).iterator(); -@@ -911,13 +1857,16 @@ +@@ -911,13 +1858,16 @@ itemstack1 = this.player.inventory.getItemInHand(); if (itemstack1 != null) { if (itemstack.getItem() == Items.WRITABLE_BOOK && itemstack.getItem() == itemstack1.getItem()) { @@ -1412,7 +1418,7 @@ return; } finally { packetdataserializer.release(); -@@ -940,16 +1889,21 @@ +@@ -940,16 +1890,21 @@ itemstack1 = this.player.inventory.getItemInHand(); if (itemstack1 != null) { if (itemstack.getItem() == Items.WRITTEN_BOOK && itemstack1.getItem() == Items.WRITABLE_BOOK) { @@ -1434,7 +1440,7 @@ return; } finally { packetdataserializer.release(); -@@ -966,11 +1920,12 @@ +@@ -966,11 +1921,12 @@ } } catch (Exception exception2) { PlayerConnection.c.error("Couldn\'t select trade", exception2); @@ -1448,7 +1454,7 @@ packetdataserializer = packetplayincustompayload.b(); try { -@@ -1006,6 +1961,7 @@ +@@ -1006,6 +1962,7 @@ } } catch (Exception exception3) { PlayerConnection.c.error("Couldn\'t set command block", exception3); @@ -1456,7 +1462,7 @@ } finally { packetdataserializer.release(); } -@@ -1031,6 +1987,7 @@ +@@ -1031,6 +1988,7 @@ } } catch (Exception exception4) { PlayerConnection.c.error("Couldn\'t set beacon", exception4); @@ -1464,7 +1470,7 @@ } } } else if ("MC|ItemName".equals(packetplayincustompayload.a()) && this.player.activeContainer instanceof ContainerAnvil) { -@@ -1046,7 +2003,28 @@ +@@ -1046,7 +2004,28 @@ containeranvil.a(""); } } -- cgit v1.2.3