Generalize references from Bungee to proxies

This commit is contained in:
games647
2021-03-17 11:24:16 +01:00
parent 804a0aec4b
commit c21c7eaeec
16 changed files with 64 additions and 62 deletions

View File

@ -1,5 +1,6 @@
package com.github.games647.fastlogin.bukkit;
import com.github.games647.fastlogin.bukkit.auth.BukkitLoginSession;
import com.github.games647.fastlogin.core.SessionManager;
import java.net.InetSocketAddress;

View File

@ -1,6 +1,6 @@
package com.github.games647.fastlogin.bukkit;
import com.github.games647.fastlogin.bukkit.auth.bungee.BungeeManager;
import com.github.games647.fastlogin.bukkit.auth.proxy.ProxyManager;
import com.github.games647.fastlogin.bukkit.auth.protocollib.ProtocolLibListener;
import com.github.games647.fastlogin.bukkit.auth.protocolsupport.ProtocolSupportListener;
import com.github.games647.fastlogin.bukkit.command.CrackedCommand;
@ -40,7 +40,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
private final Logger logger;
private final BukkitScheduler scheduler;
private BungeeManager bungeeManager;
private ProxyManager proxyManager;
private PremiumPlaceholder premiumPlaceholder;
@ -60,11 +60,11 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
return;
}
bungeeManager = new BungeeManager(this);
bungeeManager.initialize();
proxyManager = new ProxyManager(this);
proxyManager.initialize();
PluginManager pluginManager = getServer().getPluginManager();
if (!bungeeManager.isEnabled()) {
if (!proxyManager.isEnabled()) {
if (!core.setupDatabase()) {
setEnabled(false);
return;
@ -75,7 +75,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
} else if (pluginManager.isPluginEnabled("ProtocolLib")) {
ProtocolLibListener.register(this, core.getRateLimiter());
} else {
logger.warn("Either ProtocolLib or ProtocolSupport have to be installed if you don't use BungeeCord");
logger.warn("Either ProtocolLib or ProtocolSupport have to be installed if you don't use proxies");
}
}
@ -104,7 +104,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
premiumPlayers.clear();
core.close();
bungeeManager.cleanup();
proxyManager.cleanup();
if (getServer().getPluginManager().isPluginEnabled("PlaceholderAPI") && premiumPlaceholder != null) {
premiumPlaceholder.unregister();
}
@ -118,7 +118,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
* Fetches the premium status of an online player.
*
* @param onlinePlayer
* @return the online status or unknown if an error happened, the player isn't online or BungeeCord doesn't send
* @return the online status or unknown if an error happened, the player isn't online or a proxy doesn't send
* us the status message yet (This means you cannot check the login status on the PlayerJoinEvent).
* @deprecated this method could be removed in future versions and exists only as a temporarily solution
*/
@ -146,8 +146,8 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
return premiumPlayers;
}
public BungeeManager getBungeeManager() {
return bungeeManager;
public ProxyManager getProxyManager() {
return proxyManager;
}
@Override

View File

@ -1,5 +1,6 @@
package com.github.games647.fastlogin.bukkit;
import com.github.games647.fastlogin.bukkit.auth.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.event.BukkitFastLoginAutoLoginEvent;
import com.github.games647.fastlogin.core.PremiumStatus;
import com.github.games647.fastlogin.core.storage.StoredProfile;
@ -25,7 +26,7 @@ public class ForceLoginTask extends ForceLoginManagement<Player, CommandSender,
@Override
public void run() {
// block this target player for BungeeCord ID brute force attacks
// block this target player for proxy ID brute force attacks
FastLoginBukkit plugin = core.getPlugin();
player.setMetadata(core.getPlugin().getName(), new FixedMetadataValue(plugin, true));
@ -54,8 +55,8 @@ public class ForceLoginTask extends ForceLoginManagement<Player, CommandSender,
@Override
public void onForceActionSuccess(LoginSession session) {
if (core.getPlugin().getBungeeManager().isEnabled()) {
core.getPlugin().getBungeeManager().sendPluginMessage(player, new SuccessMessage());
if (core.getPlugin().getProxyManager().isEnabled()) {
core.getPlugin().getProxyManager().sendPluginMessage(player, new SuccessMessage());
}
}

View File

@ -1,4 +1,4 @@
package com.github.games647.fastlogin.bukkit;
package com.github.games647.fastlogin.bukkit.auth;
import com.github.games647.craftapi.model.skin.SkinProperty;
import com.github.games647.fastlogin.core.storage.StoredProfile;
@ -30,7 +30,7 @@ public class BukkitLoginSession extends LoginSession {
this.verifyToken = verifyToken.clone();
}
//available for BungeeCord
// available for proxies
public BukkitLoginSession(String username, boolean registered) {
this(username, "", EMPTY_ARRAY, registered, null);
}
@ -48,7 +48,7 @@ public class BukkitLoginSession extends LoginSession {
/**
* Gets the verify token the server sent to the client.
*
* Empty if it's a BungeeCord connection
* Empty if it's a proxy connection
*
* @return the verify token from the server
*/

View File

@ -2,7 +2,7 @@ package com.github.games647.fastlogin.bukkit.auth.protocollib;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketEvent;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.auth.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent;
import com.github.games647.fastlogin.core.storage.StoredProfile;

View File

@ -6,7 +6,7 @@ import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
import com.github.games647.craftapi.model.skin.Textures;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.auth.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import org.bukkit.entity.Player;

View File

@ -12,7 +12,7 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.github.games647.craftapi.model.auth.Verification;
import com.github.games647.craftapi.model.skin.SkinProperty;
import com.github.games647.craftapi.resolver.MojangResolver;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.auth.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import java.io.IOException;

View File

@ -1,7 +1,7 @@
package com.github.games647.fastlogin.bukkit.auth.protocolsupport;
import com.github.games647.craftapi.UUIDAdapter;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.auth.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent;
import com.github.games647.fastlogin.core.auth.RateLimiter;

View File

@ -1,4 +1,4 @@
package com.github.games647.fastlogin.bukkit.auth.bungee;
package com.github.games647.fastlogin.bukkit.auth.proxy;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.message.ChannelMessage;
@ -25,12 +25,12 @@ import static com.github.games647.fastlogin.core.message.ChangePremiumMessage.CH
import static com.github.games647.fastlogin.core.message.SuccessMessage.SUCCESS_CHANNEL;
import static java.util.stream.Collectors.toSet;
public class BungeeManager {
public class ProxyManager {
private static final String LEGACY_FILE_NAME = "proxy-whitelist.txt";
private static final String FILE_NAME = "allowed-proxies.txt";
//null if proxies allowed list is empty so bungeecord support is disabled
//null if proxies allowed list is empty so proxy support is disabled
private Set<UUID> proxyIds;
private final FastLoginBukkit plugin;
@ -38,7 +38,7 @@ public class BungeeManager {
private final Set<UUID> firedJoinEvents = new HashSet<>();
public BungeeManager(FastLoginBukkit plugin) {
public ProxyManager(FastLoginBukkit plugin) {
this.plugin = plugin;
}
@ -63,23 +63,23 @@ public class BungeeManager {
public void initialize() {
try {
enabled = detectBungeeCord();
enabled = detectProxy();
} catch (Exception ex) {
plugin.getLog().warn("Cannot check bungeecord support. Fallback to non-bungee mode", ex);
plugin.getLog().warn("Cannot check proxy support. Fallback to non-proxy mode", ex);
}
if (enabled) {
proxyIds = loadBungeeCordIds();
proxyIds = loadProxyIds();
registerPluginChannels();
}
}
private boolean detectBungeeCord() throws Exception {
private boolean detectProxy() throws Exception {
try {
enabled = Class.forName("org.spigotmc.SpigotConfig").getDeclaredField("bungee").getBoolean(null);
return enabled;
} catch (ClassNotFoundException notFoundEx) {
//ignore server has no bungee support
//ignore server has no proxy support
return false;
} catch (Exception ex) {
throw ex;
@ -89,10 +89,10 @@ public class BungeeManager {
private void registerPluginChannels() {
Server server = Bukkit.getServer();
// check for incoming messages from the bungeecord version of this plugin
// check for incoming messages from the proxy version of this plugin
String groupId = plugin.getName();
String forceChannel = NamespaceKey.getCombined(groupId, LoginActionMessage.FORCE_CHANNEL);
server.getMessenger().registerIncomingPluginChannel(plugin, forceChannel, new BungeeMessagingListener(plugin));
server.getMessenger().registerIncomingPluginChannel(plugin, forceChannel, new ProxyMessagingListener(plugin));
// outgoing
String successChannel = new NamespaceKey(groupId, SUCCESS_CHANNEL).getCombinedName();
@ -101,7 +101,7 @@ public class BungeeManager {
server.getMessenger().registerOutgoingPluginChannel(plugin, changeChannel);
}
private Set<UUID> loadBungeeCordIds() {
private Set<UUID> loadProxyIds() {
Path proxiesFile = plugin.getPluginFolder().resolve(FILE_NAME);
Path legacyFile = plugin.getPluginFolder().resolve(LEGACY_FILE_NAME);
try {
@ -124,7 +124,7 @@ public class BungeeManager {
} catch (IOException ex) {
plugin.getLog().error("Failed to read proxies", ex);
} catch (Exception ex) {
plugin.getLog().error("Failed to retrieve proxy Id. Disabling BungeeCord support", ex);
plugin.getLog().error("Failed to retrieve proxy Id. Disabling proxy support", ex);
}
return Collections.emptySet();
@ -145,7 +145,7 @@ public class BungeeManager {
/**
* Check if the event fired including with the task delay. This necessary to restore the order of processing the
* BungeeCord messages after the PlayerJoinEvent fires including the delay.
* proxy messages after the PlayerJoinEvent fires including the delay.
*
* If the join event fired, the delay exceeded, but it ran earlier and couldn't find the recently started login
* session. If not fired, we can start a new force login task. This will still match the requirement that we wait

View File

@ -1,6 +1,6 @@
package com.github.games647.fastlogin.bukkit.auth.bungee;
package com.github.games647.fastlogin.bukkit.auth.proxy;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.auth.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.ForceLoginTask;
import com.github.games647.fastlogin.core.PremiumStatus;
@ -18,16 +18,16 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
/**
* Responsible for receiving messages from a BungeeCord instance.
* Responsible for receiving messages from a proxy instance.
*
* This class also receives the plugin message from the bungeecord version of this plugin in order to get notified if
* This class also receives the plugin message from the proxy version of this plugin in order to get notified if
* the connection is in online mode.
*/
public class BungeeMessagingListener implements PluginMessageListener {
public class ProxyMessagingListener implements PluginMessageListener {
private final FastLoginBukkit plugin;
protected BungeeMessagingListener(FastLoginBukkit plugin) {
protected ProxyMessagingListener(FastLoginBukkit plugin) {
this.plugin = plugin;
}
@ -50,12 +50,12 @@ public class BungeeMessagingListener implements PluginMessageListener {
return;
}
// fail if target player is blocked because already authenticated or wrong bungeecord id
// fail if target player is blocked because already authenticated or wrong proxy id
if (targetPlayer.hasMetadata(plugin.getName())) {
plugin.getLog().warn("Received message {} from a blocked player {}", loginMessage, targetPlayer);
} else {
UUID sourceId = loginMessage.getProxyId();
if (plugin.getBungeeManager().isProxyAllowed(sourceId)) {
if (plugin.getProxyManager().isProxyAllowed(sourceId)) {
readMessage(targetPlayer, loginMessage);
} else {
plugin.getLog().warn("Received proxy id: {} that doesn't exist in the proxy file", sourceId);
@ -104,7 +104,7 @@ public class BungeeMessagingListener implements PluginMessageListener {
plugin.getSessionManager().startLoginSession(player.getAddress(), session);
// only start a new login task if the join event fired earlier. This event then didn
boolean result = plugin.getBungeeManager().didJoinEventFired(player);
boolean result = plugin.getProxyManager().didJoinEventFired(player);
plugin.getLog().info("Delaying force login until join event fired?: {}", result);
if (result) {
Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session);

View File

@ -35,8 +35,8 @@ public class CrackedCommand extends ToggleCommand {
return;
}
if (plugin.getBungeeManager().isEnabled()) {
sendBungeeActivateMessage(sender, sender.getName(), false);
if (plugin.getProxyManager().isEnabled()) {
sendProxyActivateMessage(sender, sender.getName(), false);
plugin.getCore().sendLocaleMessage("wait-on-proxy", sender);
} else {
//todo: load async if
@ -89,6 +89,6 @@ public class CrackedCommand extends ToggleCommand {
}
private boolean forwardCrackedCommand(CommandSender sender, String target) {
return forwardBungeeCommand(sender, target, false);
return forwardProxyCommand(sender, target, false);
}
}

View File

@ -2,11 +2,11 @@ package com.github.games647.fastlogin.bukkit.command;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPremiumToggleEvent;
import com.github.games647.fastlogin.core.shared.event.FastLoginPremiumToggleEvent.PremiumToggleReason;
import com.github.games647.fastlogin.core.storage.StoredProfile;
import java.util.UUID;
import com.github.games647.fastlogin.core.shared.event.FastLoginPremiumToggleEvent.PremiumToggleReason;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -99,6 +99,6 @@ public class PremiumCommand extends ToggleCommand {
}
private boolean forwardPremiumCommand(CommandSender sender, String target) {
return forwardBungeeCommand(sender, target, true);
return forwardProxyCommand(sender, target, true);
}
}

View File

@ -30,9 +30,9 @@ public abstract class ToggleCommand implements CommandExecutor {
return true;
}
protected boolean forwardBungeeCommand(CommandSender sender, String target, boolean activate) {
if (plugin.getBungeeManager().isEnabled()) {
sendBungeeActivateMessage(sender, target, activate);
protected boolean forwardProxyCommand(CommandSender sender, String target, boolean activate) {
if (plugin.getProxyManager().isEnabled()) {
sendProxyActivateMessage(sender, target, activate);
plugin.getCore().sendLocaleMessage("wait-on-proxy", sender);
return true;
}
@ -50,10 +50,10 @@ public abstract class ToggleCommand implements CommandExecutor {
return true;
}
protected void sendBungeeActivateMessage(CommandSender invoker, String target, boolean activate) {
protected void sendProxyActivateMessage(CommandSender invoker, String target, boolean activate) {
if (invoker instanceof PluginMessageRecipient) {
ChannelMessage message = new ChangePremiumMessage(target, activate, true);
plugin.getBungeeManager().sendPluginMessage((PluginMessageRecipient) invoker, message);
plugin.getProxyManager().sendPluginMessage((PluginMessageRecipient) invoker, message);
} else {
Optional<? extends Player> optPlayer = Bukkit.getServer().getOnlinePlayers().stream().findFirst();
if (!optPlayer.isPresent()) {
@ -63,7 +63,7 @@ public abstract class ToggleCommand implements CommandExecutor {
Player sender = optPlayer.get();
ChannelMessage message = new ChangePremiumMessage(target, activate, false);
plugin.getBungeeManager().sendPluginMessage(sender, message);
plugin.getProxyManager().sendPluginMessage(sender, message);
}
}
}

View File

@ -22,12 +22,12 @@ public class DelayedAuthHook implements Runnable {
@Override
public void run() {
boolean hookFound = isHookFound();
if (plugin.getBungeeManager().isEnabled()) {
plugin.getLog().info("BungeeCord setting detected. No auth plugin is required");
if (plugin.getProxyManager().isEnabled()) {
plugin.getLog().info("Proxy setting detected. No auth plugin is required");
} else if (!hookFound) {
plugin.getLog().warn("No auth plugin were found by this plugin "
+ "(other plugins could hook into this after the initialization of this plugin)"
+ "and BungeeCord is deactivated. "
+ "and BungeeCord (or similar proxies) is deactivated. "
+ "Either one or both of the checks have to pass in order to use this plugin");
}
}

View File

@ -1,6 +1,6 @@
package com.github.games647.fastlogin.bukkit.listener;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.auth.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.ForceLoginTask;
@ -38,7 +38,7 @@ public class ConnectionListener implements Listener {
Bukkit.getScheduler().runTaskLater(plugin, () -> {
// session exists so the player is ready for force login
// cases: Paper (firing BungeeCord message before PlayerJoinEvent) or not running BungeeCord and already
// cases: Paper (firing proxy message before PlayerJoinEvent) or not running proxy and already
// having the login session from the login process
BukkitLoginSession session = plugin.getSessionManager().getLoginSession(player.getAddress());
if (session != null) {
@ -46,7 +46,7 @@ public class ConnectionListener implements Listener {
Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask);
}
plugin.getBungeeManager().markJoinEventFired(player);
plugin.getProxyManager().markJoinEventFired(player);
// delay the login process to let auth plugins initialize the player
// Magic number however as there is no direct event from those plugins
}, DELAY_LOGIN);
@ -59,7 +59,7 @@ public class ConnectionListener implements Listener {
removeBlockedStatus(player);
plugin.getCore().getPendingConfirms().remove(player.getUniqueId());
plugin.getPremiumPlayers().remove(player.getUniqueId());
plugin.getBungeeManager().cleanup(player);
plugin.getProxyManager().cleanup(player);
}
private void removeBlockedStatus(Player player) {

View File

@ -2,7 +2,7 @@ package com.github.games647.fastlogin.bukkit.listener;
import com.destroystokyo.paper.profile.ProfileProperty;
import com.github.games647.craftapi.model.skin.Textures;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.auth.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import org.bukkit.event.EventHandler;