Skip to content

Commit

Permalink
bypass permission for idle kick (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oharass authored Sep 16, 2021
1 parent 1f63db3 commit 161dcf0
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 28 deletions.
33 changes: 27 additions & 6 deletions patches/server/0013-AFK-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,44 @@ index d2d2e3c58bd3d08f4e7f6257502ce8c2bca19825..04d2e4e641c12fb259ee7758db81b354
return this.stats;
}
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 88227a0882b4a667206891b2a26ad5764fd33590..1ba2155e353b390cff90605f3158b8f61d531cb3 100644
index 88227a0882b4a667206891b2a26ad5764fd33590..ecd0fa7daa11cd9f27b2e48cf935a5e92ee5b2f4 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -390,6 +390,12 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -294,6 +294,20 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
private boolean justTeleported = false;
private boolean hasMoved; // Spigot

+ // Purpur start
+ private final com.google.common.cache.LoadingCache<CraftPlayer, Boolean> kickPermissionCache = com.google.common.cache.CacheBuilder.newBuilder()
+ .maximumSize(1000)
+ .expireAfterWrite(1, java.util.concurrent.TimeUnit.MINUTES)
+ .build(
+ new com.google.common.cache.CacheLoader<>() {
+ @Override
+ public Boolean load(CraftPlayer player) {
+ return player.hasPermission("purpur.bypassIdleKick");
+ }
+ }
+ );
+ // Purpur end
+
public CraftPlayer getCraftPlayer() {
return (this.player == null) ? null : (CraftPlayer) this.player.getBukkitEntity();
}
@@ -390,6 +404,12 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
}

if (this.player.getLastActionTime() > 0L && this.server.getPlayerIdleTimeout() > 0 && Util.getMillis() - this.player.getLastActionTime() > (long) (this.server.getPlayerIdleTimeout() * 1000 * 60) && !this.player.wonGame) { // Paper - Prevent AFK kick while watching end credits.
+ // Purpur start
+ this.player.setAfk(true);
+ if (!this.player.level.purpurConfig.idleTimeoutKick) {
+ if (!this.player.level.purpurConfig.idleTimeoutKick || kickPermissionCache.getUnchecked(this.player.getBukkitEntity())) {
+ return;
+ }
+ // Purpur end
this.player.resetLastActionTime(); // CraftBukkit - SPIGOT-854
this.disconnect(new TranslatableComponent("multiplayer.disconnect.idling"), org.bukkit.event.player.PlayerKickEvent.Cause.IDLING); // Paper - kick event cause
}
@@ -662,6 +668,8 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -662,6 +682,8 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
this.lastYaw = to.getYaw();
this.lastPitch = to.getPitch();

Expand All @@ -93,7 +114,7 @@ index 88227a0882b4a667206891b2a26ad5764fd33590..1ba2155e353b390cff90605f3158b8f6
// Skip the first time we do this
if (true) { // Spigot - don't skip any move events
Location oldTo = to.clone();
@@ -1420,7 +1428,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1420,7 +1442,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser

if (!this.player.isChangingDimension() && d11 > org.spigotmc.SpigotConfig.movedWronglyThreshold && !this.player.isSleeping() && !this.player.gameMode.isCreative() && this.player.gameMode.getGameModeForPlayer() != GameType.SPECTATOR) { // Spigot
flag1 = true; // Paper - diff on change, this should be moved wrongly
Expand All @@ -102,7 +123,7 @@ index 88227a0882b4a667206891b2a26ad5764fd33590..1ba2155e353b390cff90605f3158b8f6
}

this.player.absMoveTo(d0, d1, d2, f, f1);
@@ -1470,6 +1478,8 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1470,6 +1492,8 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
this.lastYaw = to.getYaw();
this.lastPitch = to.getPitch();

Expand Down
4 changes: 2 additions & 2 deletions patches/server/0021-Player-invulnerabilities.patch
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ index 04d2e4e641c12fb259ee7758db81b3544193a2df..dafb9dcb3199f217e910a0cd969b863d
public Scoreboard getScoreboard() {
return this.getBukkitEntity().getScoreboard().getHandle();
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 1ba2155e353b390cff90605f3158b8f61d531cb3..b81e796625ebd7cccc66212bb92b5a3bd2e3813e 100644
index ecd0fa7daa11cd9f27b2e48cf935a5e92ee5b2f4..c69c663d9f569cf15381ed63031a34a5e2ffac7d 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1921,12 +1921,21 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1935,12 +1935,21 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@Override
public void handleResourcePackResponse(ServerboundResourcePackPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
Expand Down
6 changes: 3 additions & 3 deletions patches/server/0024-Alternative-Keepalive-Handling.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Alternative Keepalive Handling


diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index b81e796625ebd7cccc66212bb92b5a3bd2e3813e..6b560dce7779092bee5173d271beaaf53f239777 100644
index c69c663d9f569cf15381ed63031a34a5e2ffac7d..94d526fd0c1e8c68638fdeadf088b70889452d5f 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -228,6 +228,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
Expand All @@ -16,7 +16,7 @@ index b81e796625ebd7cccc66212bb92b5a3bd2e3813e..6b560dce7779092bee5173d271beaaf5
// CraftBukkit start - multithreaded fields
private AtomicInteger chatSpamTickCount = new AtomicInteger();
private final java.util.concurrent.atomic.AtomicInteger tabSpamLimiter = new java.util.concurrent.atomic.AtomicInteger(); // Paper - configurable tab spam limits
@@ -358,6 +359,21 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -372,6 +373,21 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
long currentTime = Util.getMillis();
long elapsedTime = currentTime - this.keepAliveTime;

Expand All @@ -38,7 +38,7 @@ index b81e796625ebd7cccc66212bb92b5a3bd2e3813e..6b560dce7779092bee5173d271beaaf5
if (this.keepAlivePending) {
if (!this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // check keepalive limit, don't fire if already disconnected
ServerGamePacketListenerImpl.LOGGER.warn("{} was kicked due to keepalive timeout!", this.player.getScoreboardName()); // more info
@@ -3092,6 +3108,16 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -3106,6 +3122,16 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser

@Override
public void handleKeepAlive(ServerboundKeepAlivePacket packet) {
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0048-Signs-allow-color-codes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ index dafb9dcb3199f217e910a0cd969b863da1df6127..b1e1ea0ec16f3fc9b83b8d000024e731
this.connection.send(new ClientboundBlockUpdatePacket(this.level, sign.getBlockPos()));
this.connection.send(new ClientboundOpenSignEditorPacket(sign.getBlockPos()));
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 6b560dce7779092bee5173d271beaaf53f239777..a1ac31899b1b4c5365447a0f90151e3bf3382b7d 100644
index 94d526fd0c1e8c68638fdeadf088b70889452d5f..26da5b619dd06f1713da172b6545af289f79cdd9 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -3082,11 +3082,16 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -3096,11 +3096,16 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
}
}
// Paper end
Expand Down
10 changes: 5 additions & 5 deletions patches/server/0083-Allow-color-codes-in-books.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Allow color codes in books


diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 1efc3021619d4ddc5c1c305ee29730438fdf6858..f4d8b168671d8008ba47324468f0aa4a5ff89bf9 100644
index 26da5b619dd06f1713da172b6545af289f79cdd9..5835d6f1603bbe1ba2490c9393e90908e31812f9 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1200,13 +1200,16 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1214,13 +1214,16 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
itemstack1.setTag(nbttagcompound.copy());
}

Expand All @@ -28,7 +28,7 @@ index 1efc3021619d4ddc5c1c305ee29730438fdf6858..f4d8b168671d8008ba47324468f0aa4a

this.a(pages, (s) -> {
return Component.Serializer.toJson((Component) (new TextComponent(s)));
@@ -1218,10 +1221,13 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1232,10 +1235,13 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
private void a(List<TextFilter.FilteredText> list, UnaryOperator<String> unaryoperator, ItemStack itemstack, int slot, ItemStack handItem) { // CraftBukkit
ListTag nbttaglist = new ListTag();

Expand All @@ -44,7 +44,7 @@ index 1efc3021619d4ddc5c1c305ee29730438fdf6858..f4d8b168671d8008ba47324468f0aa4a

Objects.requireNonNull(nbttaglist);
stream.forEach(nbttaglist::add);
@@ -1231,10 +1237,10 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1245,10 +1251,10 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser

for (int j = list.size(); i < j; ++i) {
TextFilter.FilteredText itextfilter_a = (TextFilter.FilteredText) list.get(i);
Expand All @@ -57,7 +57,7 @@ index 1efc3021619d4ddc5c1c305ee29730438fdf6858..f4d8b168671d8008ba47324468f0aa4a

if (!s.equals(s1)) {
nbttagcompound.putString(String.valueOf(i), (String) unaryoperator.apply(s1));
@@ -1250,6 +1256,16 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1264,6 +1270,16 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
this.player.getInventory().setItem(slot, CraftEventFactory.handleEditBookEvent(player, slot, handItem, itemstack)); // CraftBukkit // Paper - Don't ignore result (see other callsite for handleEditBookEvent)
}

Expand Down
6 changes: 3 additions & 3 deletions patches/server/0143-PlayerBookTooLargeEvent.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] PlayerBookTooLargeEvent


diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index f4d8b168671d8008ba47324468f0aa4a5ff89bf9..3d73f44edca1b13a98f858ae0c1fd0bc79055a12 100644
index 5835d6f1603bbe1ba2490c9393e90908e31812f9..94fc95f79e74f6b3e7d9cd666788cc105b4e24cb 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1122,10 +1122,12 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1136,10 +1136,12 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
int maxBookPageSize = com.destroystokyo.paper.PaperConfig.maxBookPageSize;
double multiplier = Math.max(0.3D, Math.min(1D, com.destroystokyo.paper.PaperConfig.maxBookTotalSizeMultiplier));
long byteAllowed = maxBookPageSize;
Expand All @@ -21,7 +21,7 @@ index f4d8b168671d8008ba47324468f0aa4a5ff89bf9..3d73f44edca1b13a98f858ae0c1fd0bc
server.scheduleOnMain(() -> this.disconnect("Book too large!", org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_ACTION)); // Paper - kick event cause
return;
}
@@ -1149,6 +1151,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1163,6 +1165,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser

if (byteTotal > byteAllowed) {
ServerGamePacketListenerImpl.LOGGER.warn(this.player.getScoreboardName() + " tried to send too large of a book. Book Size: " + byteTotal + " - Allowed: "+ byteAllowed + " - Pages: " + pageList.size());
Expand Down
10 changes: 5 additions & 5 deletions patches/server/0158-Dont-run-with-scissors.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Dont run with scissors!


diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 3d73f44edca1b13a98f858ae0c1fd0bc79055a12..c0ab928ecff6aea1544406576e689979a2e474e9 100644
index 94fc95f79e74f6b3e7d9cd666788cc105b4e24cb..11b9ba2bb00a9bb198cd82aca37cd4201c184e66 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1555,6 +1555,13 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1569,6 +1569,13 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
this.player.fallDistance = 0.0F;
}

Expand All @@ -22,7 +22,7 @@ index 3d73f44edca1b13a98f858ae0c1fd0bc79055a12..c0ab928ecff6aea1544406576e689979
this.player.checkMovementStatistics(this.player.getX() - d3, this.player.getY() - d4, this.player.getZ() - d5);
this.lastGoodX = this.player.getX();
this.lastGoodY = this.player.getY();
@@ -1567,6 +1574,12 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1581,6 +1588,12 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
}
}

Expand All @@ -36,7 +36,7 @@ index 3d73f44edca1b13a98f858ae0c1fd0bc79055a12..c0ab928ecff6aea1544406576e689979
private boolean hasNewCollision(final ServerLevel world, final Entity entity, final AABB oldBox, final AABB newBox) {
final List<AABB> collisions = io.papermc.paper.util.CachedLists.getTempCollisionList();
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
index 16a7808f0ad010240db8a33eccc61b623ccd3d76..e1ad567510edd0818c0faf71bfbb33c31694f8ff 100644
index 039c5e6d98228837f7818803641656d566e416f5..1e09dc436ce147d42035d48918b811eb7e898c12 100644
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
@@ -165,6 +165,7 @@ public class PurpurConfig {
Expand All @@ -56,7 +56,7 @@ index 16a7808f0ad010240db8a33eccc61b623ccd3d76..e1ad567510edd0818c0faf71bfbb33c3

public static String serverModName = "Purpur";
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 8f7fb9cf88562637fc27d00351f5ed34ba10dfa5..86832a2171a57cb4d28ca3fe267579bd5a036104 100644
index ae8fe8d635acad84e79498fb5bf6db6469fbb7dd..198536d8f06f52623ae7492d2e0a6d428d4f72d1 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -157,6 +157,8 @@ public class PurpurWorldConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ index a61c0ca02b085d1ab2587d54c9fcdc76a726cc4e..a11a7deefb7fdf7ca9b23f85f5ae5f7c
+ // Purpur end
}
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 44389f03d02cdd0224fd0b91d6780cca89171df7..e27d5dd0eaf164eb2a33ae0410a0b1c02e4e56ab 100644
index 11b9ba2bb00a9bb198cd82aca37cd4201c184e66..ddd685d0a0e23e4dcd0cd2e7a9269f431235d3af 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1917,6 +1917,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1931,6 +1931,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser

boolean cancelled;
if (movingobjectposition == null || movingobjectposition.getType() != HitResult.Type.BLOCK) {
Expand Down

0 comments on commit 161dcf0

Please sign in to comment.