Skip to content

Commit

Permalink
Ignore packets before player has logged in (CloudburstMC#1883)
Browse files Browse the repository at this point in the history
(cherry picked from commit 564da45)
  • Loading branch information
PetteriM1 authored and wode490390 committed Dec 23, 2021
1 parent 03e386e commit fde5630
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
public boolean spawned = false;
public boolean loggedIn = false;
public boolean locallyInitialized = false;
private boolean verified = false;
private int unverifiedPackets;
public int gamemode;
public long lastBreak;
private BlockVector3 lastBreakPosition = new BlockVector3();
Expand Down Expand Up @@ -2049,6 +2051,14 @@ public void handleDataPacket(DataPacket packet) {
return;
}

if (!verified && packet.pid() != ProtocolInfo.LOGIN_PACKET && packet.pid() != ProtocolInfo.BATCH_PACKET) {
server.getLogger().warning("Ignoring " + packet.getClass().getSimpleName() + " from " + getAddress() + " due to player not verified yet");
if (unverifiedPackets++ > 100) {
this.close("", "Too many failed login attempts");
}
return;
}

try (Timing ignored = Timings.getReceiveDataPacketTiming(packet)) {
DataPacketReceiveEvent ev = new DataPacketReceiveEvent(this, packet);
this.server.getPluginManager().callEvent(ev);
Expand Down Expand Up @@ -2165,6 +2175,8 @@ public void handleDataPacket(DataPacket packet) {
}

Player playerInstance = this;
this.verified = true;

this.preLoginEventTask = new AsyncTask() {
private PlayerAsyncPreLoginEvent event;

Expand Down

0 comments on commit fde5630

Please sign in to comment.