From 5c717e8150aff984cbe5d9dc1207c5d0cad15c6e Mon Sep 17 00:00:00 2001
From: Smart123s <28480228+Smart123s@users.noreply.github.com>
Date: Sat, 28 Aug 2021 12:52:07 +0200
Subject: [PATCH 1/3] Store if low level Floodgate checks were skipped
---
.../fastlogin/bungee/BungeeLoginSession.java | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeLoginSession.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeLoginSession.java
index 5456b3c2b..ca4091a55 100644
--- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeLoginSession.java
+++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeLoginSession.java
@@ -33,8 +33,16 @@ public class BungeeLoginSession extends LoginSession {
private boolean alreadySaved;
private boolean alreadyLogged;
- public BungeeLoginSession(String username, boolean registered, StoredProfile profile) {
+ //this will be true, if the Floodgate name conflict checks were skipped in PreLoginEvent
+ private boolean floodgateCheckSkipped;
+
+ public BungeeLoginSession(String username, boolean registered, StoredProfile profile, boolean floodgateCheckSkipped) {
super(username, registered, profile);
+ this.floodgateCheckSkipped = floodgateCheckSkipped;
+ }
+
+ public BungeeLoginSession(String username, boolean registered, StoredProfile profile) {
+ this(username, registered, profile, false);
}
public synchronized void setRegistered(boolean registered) {
@@ -65,4 +73,12 @@ public synchronized String toString() {
", registered=" + registered +
"} " + super.toString();
}
+
+ public boolean isFloodgateCheckSkipped() {
+ return this.floodgateCheckSkipped;
+ }
+
+ public void setFloodgateCheckSkipped(boolean floodgateCheckSkipped) {
+ this.floodgateCheckSkipped = floodgateCheckSkipped;
+ }
}
From 6fb5afd96dac46ed55295afb6d126dd78e9bfd83 Mon Sep 17 00:00:00 2001
From: Smart123s <28480228+Smart123s@users.noreply.github.com>
Date: Sat, 28 Aug 2021 12:55:17 +0200
Subject: [PATCH 2/3] Skip PreLogin checks for Geyser players (Bungee)
---
bungee/pom.xml | 8 ++++++++
.../fastlogin/bungee/listener/ConnectListener.java | 14 ++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/bungee/pom.xml b/bungee/pom.xml
index 814d7609c..22f445c48 100644
--- a/bungee/pom.xml
+++ b/bungee/pom.xml
@@ -141,6 +141,14 @@
provided
+
+
+ org.geysermc
+ connector
+ 1.2.1-SNAPSHOT
+ provided
+
+
me.vik1395
diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java
index 8777a6086..525e5ced6 100644
--- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java
+++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java
@@ -56,6 +56,8 @@
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
+import org.geysermc.connector.GeyserConnector;
+import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.floodgate.api.FloodgateApi;
import org.geysermc.floodgate.api.player.FloodgatePlayer;
import org.slf4j.Logger;
@@ -117,6 +119,18 @@ public void onPreLogin(PreLoginEvent preLoginEvent) {
String username = connection.getName();
plugin.getLog().info("Incoming login request for {} from {}", username, connection.getSocketAddress());
+ if (plugin.isPluginInstalled("Geyser-BungeeCord")) {
+ for (GeyserSession gSess : GeyserConnector.getInstance().getPlayers()) {
+ if (username.equals(FloodgateApi.getInstance().getPlayerPrefix() + gSess.getName())){
+ //todo: if no Floodgate prefix is set, and there are name conflicts, how will this behave?
+ plugin.getLog().info("Player {} is using Geyser. Name conflict checks will be done later.", username);
+ StoredProfile profile = plugin.getCore().getStorage().loadProfile(username);
+ plugin.getSession().put(connection, new BungeeLoginSession(username, true, profile, true));
+ return;
+ }
+ }
+ }
+
preLoginEvent.registerIntent(plugin);
Runnable asyncPremiumCheck = new AsyncPremiumCheck(plugin, preLoginEvent, connection, username);
plugin.getScheduler().runAsync(asyncPremiumCheck);
From a46a5fb6116e3798689af53ae2ca75af7b1719ae Mon Sep 17 00:00:00 2001
From: Smart123s <28480228+Smart123s@users.noreply.github.com>
Date: Sat, 28 Aug 2021 13:22:05 +0200
Subject: [PATCH 3/3] Run Floodgate name checks at LoginEvent
---
.../bungee/BungeeFloodgateLoginSource.java | 79 +++++++++++++++++++
.../bungee/listener/ConnectListener.java | 19 ++++-
2 files changed, 95 insertions(+), 3 deletions(-)
create mode 100644 bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeFloodgateLoginSource.java
diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeFloodgateLoginSource.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeFloodgateLoginSource.java
new file mode 100644
index 000000000..23a36e0c5
--- /dev/null
+++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeFloodgateLoginSource.java
@@ -0,0 +1,79 @@
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015-2021
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.github.games647.fastlogin.bungee;
+
+import com.github.games647.fastlogin.core.shared.LoginSource;
+
+import java.net.InetSocketAddress;
+
+import net.md_5.bungee.api.ChatColor;
+import net.md_5.bungee.api.chat.ComponentBuilder;
+import net.md_5.bungee.api.chat.TextComponent;
+import net.md_5.bungee.api.connection.PendingConnection;
+import net.md_5.bungee.api.event.LoginEvent;
+
+public class BungeeFloodgateLoginSource implements LoginSource {
+
+ private final PendingConnection connection;
+ private final LoginEvent loginEvent;
+
+ public BungeeFloodgateLoginSource(PendingConnection connection, LoginEvent loginEvent) {
+ this.connection = connection;
+ this.loginEvent = loginEvent;
+ }
+
+ @Override
+ public void enableOnlinemode() {
+ connection.setOnlineMode(true);
+ }
+
+ @Override
+ public void kick(String message) {
+ loginEvent.setCancelled(true);
+
+ if (message == null) {
+ loginEvent.setCancelReason(new ComponentBuilder("Kicked").color(ChatColor.WHITE).create());
+ } else {
+ loginEvent.setCancelReason(TextComponent.fromLegacyText(message));
+ }
+ }
+
+ @Override
+ public InetSocketAddress getAddress() {
+ return connection.getAddress();
+ }
+
+ public PendingConnection getConnection() {
+ return connection;
+ }
+
+ @Override
+ public String toString() {
+ return this.getClass().getSimpleName() + '{' +
+ "connection=" + connection +
+ '}';
+ }
+}
diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java
index 525e5ced6..b43005c07 100644
--- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java
+++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java
@@ -26,14 +26,18 @@
package com.github.games647.fastlogin.bungee.listener;
import com.github.games647.craftapi.UUIDAdapter;
+import com.github.games647.fastlogin.bungee.BungeeFloodgateLoginSource;
import com.github.games647.fastlogin.bungee.BungeeLoginSession;
+import com.github.games647.fastlogin.bungee.BungeeLoginSource;
import com.github.games647.fastlogin.bungee.FastLoginBungee;
import com.github.games647.fastlogin.bungee.task.AsyncPremiumCheck;
import com.github.games647.fastlogin.bungee.task.FloodgateAuthTask;
import com.github.games647.fastlogin.bungee.task.ForceLoginTask;
import com.github.games647.fastlogin.core.RateLimiter;
import com.github.games647.fastlogin.core.StoredProfile;
+import com.github.games647.fastlogin.core.hooks.FloodgateHook;
import com.github.games647.fastlogin.core.shared.LoginSession;
+import com.github.games647.fastlogin.core.shared.LoginSource;
import com.google.common.base.Throwables;
import java.lang.invoke.MethodHandle;
@@ -42,6 +46,7 @@
import java.lang.reflect.Field;
import java.util.UUID;
+import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server;
@@ -71,6 +76,7 @@ public class ConnectListener implements Listener {
private static final String UUID_FIELD_NAME = "uniqueId";
private static final MethodHandle uniqueIdSetter;
+ private final FloodgateHook floodgateHook;
static {
MethodHandle setHandle = null;
@@ -102,6 +108,7 @@ public class ConnectListener implements Listener {
public ConnectListener(FastLoginBungee plugin, RateLimiter rateLimiter) {
this.plugin = plugin;
this.rateLimiter = rateLimiter;
+ this.floodgateHook = new FloodgateHook(plugin.getCore());
}
@EventHandler
@@ -119,7 +126,7 @@ public void onPreLogin(PreLoginEvent preLoginEvent) {
String username = connection.getName();
plugin.getLog().info("Incoming login request for {} from {}", username, connection.getSocketAddress());
- if (plugin.isPluginInstalled("Geyser-BungeeCord")) {
+ if (plugin.isPluginInstalled("Geyser-BungeeCord") && plugin.isPluginInstalled("floodgate")) {
for (GeyserSession gSess : GeyserConnector.getInstance().getPlayers()) {
if (username.equals(FloodgateApi.getInstance().getPlayerPrefix() + gSess.getName())){
//todo: if no Floodgate prefix is set, and there are name conflicts, how will this behave?
@@ -145,9 +152,15 @@ public void onLogin(LoginEvent loginEvent) {
//use the login event instead of the post login event in order to send the login success packet to the client
//with the offline uuid this makes it possible to set the skin then
PendingConnection connection = loginEvent.getConnection();
- if (connection.isOnlineMode()) {
- LoginSession session = plugin.getSession().get(connection);
+ BungeeLoginSession session = plugin.getSession().get(connection);
+
+ if (session.isFloodgateCheckSkipped()) {
+ FloodgatePlayer floodgatePlayer = FloodgateApi.getInstance().getPlayer(connection.getUniqueId());
+ LoginSource source = new BungeeFloodgateLoginSource(connection, loginEvent);
+ floodgateHook.checkFloodgateNameConflict(connection.getName(), source, floodgatePlayer);
+ }
+ if (connection.isOnlineMode()) {
UUID verifiedUUID = connection.getUniqueId();
String verifiedUsername = connection.getName();
session.setUuid(verifiedUUID);