forked from TuxCoding/FastLogin
Override packet types until they are registered at ProtocolLib
Related #1202
This commit is contained in:
@ -32,6 +32,7 @@ import com.comphenix.protocol.events.PacketContainer;
|
|||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
import com.comphenix.protocol.injector.PacketFilterManager;
|
import com.comphenix.protocol.injector.PacketFilterManager;
|
||||||
import com.comphenix.protocol.injector.player.PlayerInjectionHandler;
|
import com.comphenix.protocol.injector.player.PlayerInjectionHandler;
|
||||||
|
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||||
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
||||||
@ -112,42 +113,59 @@ public class ProtocolLibListener extends PacketAdapter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getLog().info("New packet {} from {}", packetEvent.getPacketType(), packetEvent.getPlayer());
|
|
||||||
|
|
||||||
Player sender = packetEvent.getPlayer();
|
Player sender = packetEvent.getPlayer();
|
||||||
PacketType packetType = packetEvent.getPacketType();
|
PacketType packetType = packetEvent.getPacketType();
|
||||||
if (packetType == START) {
|
|
||||||
|
|
||||||
if (plugin.getFloodgateService() != null) {
|
plugin.getLog().info("New packet {} from {}", packetType, sender);
|
||||||
boolean success = processFloodgateTasks(packetEvent);
|
try {
|
||||||
// don't continue execution if the player was kicked by Floodgate
|
if (packetType.isDynamic()) {
|
||||||
if (!success) {
|
String vanillaName = packetType.getPacketClass().getName();
|
||||||
return;
|
plugin.getLog().info("Overriding packet type for unregistered packet type to fix ProtocolLib bug");
|
||||||
|
if (vanillaName.endsWith("ServerboundHelloPacket")) {
|
||||||
|
packetType = START;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vanillaName.endsWith("ServerboundKeyPacket")) {
|
||||||
|
packetType = ENCRYPTION_BEGIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketContainer packet = packetEvent.getPacket();
|
if (packetType == START) {
|
||||||
|
if (plugin.getFloodgateService() != null) {
|
||||||
|
boolean success = processFloodgateTasks(packetEvent);
|
||||||
|
// don't continue execution if the player was kicked by Floodgate
|
||||||
|
if (!success) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
InetSocketAddress address = sender.getAddress();
|
PacketContainer packet = packetEvent.getPacket();
|
||||||
String username = getUsername(packet);
|
|
||||||
|
|
||||||
Action action = antiBotService.onIncomingConnection(address, username);
|
InetSocketAddress address = sender.getAddress();
|
||||||
switch (action) {
|
String username = getUsername(packet);
|
||||||
case Ignore:
|
|
||||||
// just ignore
|
Action action = antiBotService.onIncomingConnection(address, username);
|
||||||
return;
|
switch (action) {
|
||||||
case Block:
|
case Ignore:
|
||||||
String message = plugin.getCore().getMessage("kick-antibot");
|
// just ignore
|
||||||
sender.kickPlayer(message);
|
return;
|
||||||
break;
|
case Block:
|
||||||
case Continue:
|
String message = plugin.getCore().getMessage("kick-antibot");
|
||||||
default:
|
sender.kickPlayer(message);
|
||||||
//player.getName() won't work at this state
|
break;
|
||||||
onLoginStart(packetEvent, sender, username);
|
case Continue:
|
||||||
break;
|
default:
|
||||||
|
//player.getName() won't work at this state
|
||||||
|
onLoginStart(packetEvent, sender, username);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (packetType == ENCRYPTION_BEGIN) {
|
||||||
|
onEncryptionBegin(packetEvent, sender);
|
||||||
|
} else {
|
||||||
|
plugin.getLog().warn("Unknown packet type received {}", packetType);
|
||||||
}
|
}
|
||||||
} else {
|
} catch (FieldAccessException fieldAccessEx) {
|
||||||
onEncryptionBegin(packetEvent, sender);
|
plugin.getLog().error("Failed to parse packet {}", packetEvent.getPacketType(), fieldAccessEx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,7 +265,6 @@ public class ProtocolLibListener extends PacketAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
plugin.getLog().trace("GameProfile {} with {} connecting", sessionKey, username);
|
plugin.getLog().trace("GameProfile {} with {} connecting", sessionKey, username);
|
||||||
|
|
||||||
packetEvent.getAsyncMarker().incrementProcessingDelay();
|
packetEvent.getAsyncMarker().incrementProcessingDelay();
|
||||||
|
Reference in New Issue
Block a user