Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the IP on publishing PreLoginEvent. (Bug Fix) #72

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ private void initValidators() throws NoSuchAlgorithmException, IOException, Inva
* @param packet The handshake packet
* @param player The involved player
*/
public void handleHandshake(PacketProvider packet, PlayerProvider player) throws HandshakeException {
public void handleHandshake(PacketProvider packet, PlayerProvider player, boolean ignoreInvalidPayload) throws HandshakeException {
try {
InetAddress inetAddress = InetAddress.getByName(player.getIP());

String extraData = null;
String[] payload = packet.getPayloadString().split("///");

if (payload.length != 4)
if (cidrValidator.validate(inetAddress))
if (cidrValidator.validate(inetAddress) || ignoreInvalidPayload)
return; // Allow connection with no processing
else
throw new InvalidPayloadException("length: " + payload.length + ", payload: " + Arrays.toString(payload) + ", raw payload: " + packet.getPayloadString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void onHandshake(PlayerHandshakeEvent e) {
PaperPlayer player = new PaperPlayer(e);

try {
bukkitProvider.getPlugin().getPacketHandler().handleHandshake(packet, player);
bukkitProvider.getPlugin().getPacketHandler().handleHandshake(packet, player, true);
} catch (HandshakeException exception) {
bukkitProvider.getPlugin().getDebugger().exception(exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void onPacketReceiving(PacketEvent e) {
ProtocolLibPlayer player = new ProtocolLibPlayer(e.getPlayer());

try {
bukkitProvider.getPlugin().getPacketHandler().handleHandshake(packet, player);
bukkitProvider.getPlugin().getPacketHandler().handleHandshake(packet, player, true);
} catch (HandshakeException exception) {
bukkitProvider.getPlugin().getDebugger().exception(exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void onPlayerHandshake(PlayerHandshakeEvent e) {
this.plugin.getDebugger().warn("BungeeCord: Raw player hostname: " + packet.getPayloadString());

try {
plugin.getPacketHandler().handleHandshake(packet, player);
plugin.getPacketHandler().handleHandshake(packet, player, true);
} catch (HandshakeException exception) {
plugin.getDebugger().exception(exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public VelocityHandshakeHandler(TCPShieldPlugin plugin) {
// handleEvent(connection, "onPreLogin");
// }

@Subscribe(order = PostOrder.FIRST)
public void onPreLoginEvent(PreLoginEvent event) {
VelocityPlayer player = new VelocityPlayer(event.getConnection());
VelocityPacket packet = new VelocityPacket(event.getConnection());

plugin.getPacketHandler().handleHandshake(packet, player, true);
}

@Subscribe(order = PostOrder.FIRST)
public void onHandshake(ConnectionHandshakeEvent e) {
InboundConnection connection = e.getConnection();
Expand All @@ -53,7 +61,7 @@ private void handleEvent(InboundConnection connection, String debugSource) {
this.plugin.getDebugger().warn("Velocity: " + debugSource + " Raw player hostname: " + packet.getPayloadString());

try {
plugin.getPacketHandler().handleHandshake(packet, player);
plugin.getPacketHandler().handleHandshake(packet, player, false);
} catch (HandshakeException exception) {
plugin.getDebugger().exception(exception);
}
Expand Down