Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 11:00:06 +01:00
IllegalPacketEvent - Resolves #419
Fire an event when an illegal packet is received to let plugins handle it Lets plugins change the kick message and if it should kick or not.
Dieser Commit ist enthalten in:
Ursprung
a4152b2ad1
Commit
23236ef8aa
81
Spigot-API-Patches/0046-IllegalPacketEvent.patch
Normale Datei
81
Spigot-API-Patches/0046-IllegalPacketEvent.patch
Normale Datei
@ -0,0 +1,81 @@
|
||||
From d43e5b5b743c67c8b6f20af80421241adf160562 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Sun, 4 Dec 2016 01:19:14 -0500
|
||||
Subject: [PATCH] IllegalPacketEvent
|
||||
|
||||
Fire an event when an illegal packet is received to let plugins handle it
|
||||
|
||||
Lets plugins change the kick message and if it should kick or not.
|
||||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/event/player/IllegalPacketEvent.java b/src/main/java/com/destroystokyo/paper/event/player/IllegalPacketEvent.java
|
||||
new file mode 100644
|
||||
index 00000000..e11f74fc
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/com/destroystokyo/paper/event/player/IllegalPacketEvent.java
|
||||
@@ -0,0 +1,63 @@
|
||||
+package com.destroystokyo.paper.event.player;
|
||||
+
|
||||
+import org.bukkit.Bukkit;
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.bukkit.event.player.PlayerEvent;
|
||||
+
|
||||
+public class IllegalPacketEvent extends PlayerEvent {
|
||||
+ private final String type;
|
||||
+ private final String ex;
|
||||
+ private String kickMessage;
|
||||
+ private boolean shouldKick = true;
|
||||
+
|
||||
+ public IllegalPacketEvent(Player player, String type, String kickMessage, Exception e) {
|
||||
+ super(player);
|
||||
+ this.type = type;
|
||||
+ this.kickMessage = kickMessage;
|
||||
+ this.ex = e.getMessage();
|
||||
+ }
|
||||
+
|
||||
+ public boolean isShouldKick() {
|
||||
+ return shouldKick;
|
||||
+ }
|
||||
+
|
||||
+ public void setShouldKick(boolean shouldKick) {
|
||||
+ this.shouldKick = shouldKick;
|
||||
+ }
|
||||
+
|
||||
+ public String getKickMessage() {
|
||||
+ return kickMessage;
|
||||
+ }
|
||||
+
|
||||
+ public void setKickMessage(String kickMessage) {
|
||||
+ this.kickMessage = kickMessage;
|
||||
+ }
|
||||
+
|
||||
+ public String getType() {
|
||||
+ return type;
|
||||
+ }
|
||||
+
|
||||
+ public String getExceptionMessage() {
|
||||
+ return ex;
|
||||
+ }
|
||||
+
|
||||
+ private static final HandlerList handlers = new HandlerList();
|
||||
+
|
||||
+ public HandlerList getHandlers() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+
|
||||
+ public static HandlerList getHandlerList() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+
|
||||
+ public static void process(Player player, String type, String kickMessage, Exception exception) {
|
||||
+ IllegalPacketEvent event = new IllegalPacketEvent(player, type, kickMessage, exception);
|
||||
+ event.callEvent();
|
||||
+ if (event.shouldKick) {
|
||||
+ player.kickPlayer(kickMessage);
|
||||
+ }
|
||||
+ Bukkit.getLogger().severe(player.getName() + "/" + type + ": " + exception.getMessage());
|
||||
+ }
|
||||
+}
|
||||
--
|
||||
2.11.0
|
||||
|
71
Spigot-Server-Patches/0192-IllegalPacketEvent.patch
Normale Datei
71
Spigot-Server-Patches/0192-IllegalPacketEvent.patch
Normale Datei
@ -0,0 +1,71 @@
|
||||
From af7039820f33212e53e66eae30be55733bdb8197 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Thu, 23 Jun 2016 23:33:57 -0400
|
||||
Subject: [PATCH] IllegalPacketEvent
|
||||
|
||||
Fired for invalid data from players that represents hacking attempts
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||
index c57ab1a9c..06f85c46f 100644
|
||||
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||
@@ -56,6 +56,7 @@ import org.bukkit.inventory.CraftingInventory;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
+import com.destroystokyo.paper.event.player.IllegalPacketEvent; // Paper
|
||||
import co.aikar.timings.MinecraftTimings; // Paper
|
||||
// CraftBukkit end
|
||||
|
||||
@@ -2225,8 +2226,7 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
|
||||
CraftEventFactory.handleEditBookEvent(player, itemstack1); // CraftBukkit
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
- PlayerConnection.LOGGER.error("Couldn\'t handle book info", exception);
|
||||
- this.disconnect("Invalid book data!"); // CraftBukkit
|
||||
+ IllegalPacketEvent.process(player.getBukkitEntity(), "InvalidBookEdit", "Invalid book data!", exception); // Paper
|
||||
}
|
||||
} else {
|
||||
String s1;
|
||||
@@ -2268,8 +2268,7 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
|
||||
CraftEventFactory.handleEditBookEvent(player, itemstack2); // CraftBukkit
|
||||
}
|
||||
} catch (Exception exception1) {
|
||||
- PlayerConnection.LOGGER.error("Couldn\'t sign book", exception1);
|
||||
- this.disconnect("Invalid book data!"); // CraftBukkit
|
||||
+ IllegalPacketEvent.process(player.getBukkitEntity(), "InvalidBookSign", "Invalid book data!", exception1); // Paper
|
||||
}
|
||||
} else if ("MC|TrSel".equals(s)) {
|
||||
try {
|
||||
@@ -2280,8 +2279,7 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
|
||||
((ContainerMerchant) container).d(j);
|
||||
}
|
||||
} catch (Exception exception2) {
|
||||
- PlayerConnection.LOGGER.error("Couldn\'t select trade", exception2);
|
||||
- this.disconnect("Invalid trade data!"); // CraftBukkit
|
||||
+ IllegalPacketEvent.process(player.getBukkitEntity(), "InvalidTrade", "Invalid trade data!", exception2); // Paper
|
||||
}
|
||||
} else {
|
||||
TileEntity tileentity;
|
||||
@@ -2422,8 +2420,7 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
|
||||
iinventory.update();
|
||||
}
|
||||
} catch (Exception exception5) {
|
||||
- PlayerConnection.LOGGER.error("Couldn\'t set beacon", exception5);
|
||||
- this.disconnect("Invalid beacon data!"); // CraftBukkit
|
||||
+ IllegalPacketEvent.process(player.getBukkitEntity(), "InvalidBeacon", "Invalid beacon data!", exception5); // Paper
|
||||
}
|
||||
}
|
||||
} else if ("MC|ItemName".equals(s)) {
|
||||
@@ -2522,7 +2519,7 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
|
||||
this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(-2, k, this.player.inventory.getItem(k)));
|
||||
this.player.playerConnection.sendPacket(new PacketPlayOutHeldItemSlot(this.player.inventory.itemInHandIndex));
|
||||
} catch (Exception exception7) {
|
||||
- PlayerConnection.LOGGER.error("Couldn\'t pick item", exception7);
|
||||
+ IllegalPacketEvent.process(player.getBukkitEntity(), "InvalidPickItem", "Invalid PickItem", exception7); // Paper
|
||||
}
|
||||
}
|
||||
// CraftBukkit start
|
||||
--
|
||||
2.11.0
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren