Fix code formatting according to checkstyle config

This commit is contained in:
games647
2022-07-11 12:03:41 +02:00
parent cf53ecacdf
commit 752600f0e2
44 changed files with 274 additions and 203 deletions

View File

@ -51,8 +51,8 @@ public class BukkitLoginSession extends LoginSession {
private SkinProperty skinProperty; private SkinProperty skinProperty;
public BukkitLoginSession(String username, byte[] verifyToken, ClientPublicKey publicKey, boolean registered public BukkitLoginSession(String username, byte[] verifyToken, ClientPublicKey publicKey, boolean registered,
, StoredProfile profile) { StoredProfile profile) {
super(username, registered, profile); super(username, registered, profile);
this.clientPublicKey = publicKey; this.clientPublicKey = publicKey;

View File

@ -33,6 +33,7 @@ import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -113,7 +114,9 @@ public class BungeeManager {
Class<?> globalConfig = Class.forName("io.papermc.paper.configuration.GlobalConfiguration"); Class<?> globalConfig = Class.forName("io.papermc.paper.configuration.GlobalConfiguration");
Object global = globalConfig.getDeclaredMethod("get").invoke(null); Object global = globalConfig.getDeclaredMethod("get").invoke(null);
Object proxiesConfiguration = global.getClass().getDeclaredField("proxies").get(global); Object proxiesConfiguration = global.getClass().getDeclaredField("proxies").get(global);
Object velocityConfig = proxiesConfiguration.getClass().getDeclaredField("velocity").get(proxiesConfiguration);
Field velocitySectionField = proxiesConfiguration.getClass().getDeclaredField("velocity");
Object velocityConfig = velocitySectionField.get(proxiesConfiguration);
return velocityConfig.getClass().getDeclaredField("enabled").getBoolean(velocityConfig); return velocityConfig.getClass().getDeclaredField("enabled").getBoolean(velocityConfig);
} catch (ClassNotFoundException classNotFoundException) { } catch (ClassNotFoundException classNotFoundException) {
@ -128,7 +131,9 @@ public class BungeeManager {
private boolean detectProxy() { private boolean detectProxy() {
try { try {
if (isProxySupported("org.spigotmc.SpigotConfig", "bungee")) return true; if (isProxySupported("org.spigotmc.SpigotConfig", "bungee")) {
return true;
}
} catch (ClassNotFoundException classNotFoundException) { } catch (ClassNotFoundException classNotFoundException) {
// leave stacktrace for class not found out // leave stacktrace for class not found out
plugin.getLog().warn("Cannot check for BungeeCord support: {}", classNotFoundException.getMessage()); plugin.getLog().warn("Cannot check for BungeeCord support: {}", classNotFoundException.getMessage());

View File

@ -120,18 +120,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
ProtocolLibListener.register(this, core.getAntiBot(), core.getConfig().getBoolean("verifyClientKeys")); ProtocolLibListener.register(this, core.getAntiBot(), core.getConfig().getBoolean("verifyClientKeys"));
if (isPluginInstalled("floodgate")) { if (isPluginInstalled("floodgate")) {
if (getConfig().getBoolean("floodgatePrefixWorkaround")){ printFloodgateWarning();
ManualNameChange.register(this, floodgateService);
logger.info("Floodgate prefix injection workaround has been enabled.");
logger.info("If you have problems joining the server, try disabling it in the configuration.");
} else {
logger.warn("We have detected that you are running FastLogin alongside Floodgate and ProtocolLib.");
logger.warn("Currently there is an issue with FastLogin that prevents Floodgate name prefixes from showing up "
+ "when it is together used with ProtocolLib.");
logger.warn("If you would like to use Floodgate name prefixes, you can enable an experimental workaround by changing "
+ "the value 'floodgatePrefixWorkaround' to true in config.yml.");
logger.warn("For more information visit https://github.com/games647/FastLogin/issues/493");
}
} }
//if server is using paper - we need to set the skin at pre login anyway, so no need for this listener //if server is using paper - we need to set the skin at pre login anyway, so no need for this listener
@ -167,6 +156,21 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
dependencyWarnings(); dependencyWarnings();
} }
private void printFloodgateWarning() {
if (getConfig().getBoolean("floodgatePrefixWorkaround")) {
ManualNameChange.register(this, floodgateService);
logger.info("Floodgate prefix injection workaround has been enabled.");
logger.info("If you have problems joining the server, try disabling it in the configuration.");
} else {
logger.warn("We have detected that you are running FastLogin alongside Floodgate and ProtocolLib.");
logger.warn("Currently there is an issue with FastLogin that prevents Floodgate name prefixes from "
+ "showing up when it is together used with ProtocolLib.");
logger.warn("If you would like to use Floodgate name prefixes, you can enable an experimental "
+ "workaround by changing the value 'floodgatePrefixWorkaround' to true in config.yml.");
logger.warn("For more information visit https://github.com/games647/FastLogin/issues/493");
}
}
private boolean initializeFloodgate() { private boolean initializeFloodgate() {
if (getServer().getPluginManager().getPlugin("Geyser-Spigot") != null) { if (getServer().getPluginManager().getPlugin("Geyser-Spigot") != null) {
geyserService = new GeyserService(GeyserImpl.getInstance(), core); geyserService = new GeyserService(GeyserImpl.getInstance(), core);
@ -295,16 +299,17 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
receiver.sendMessage(message); receiver.sendMessage(message);
} }
/** /**
* Checks if a plugin is installed on the server * Checks if a plugin is installed on the server
* @param name the name of the plugin *
* @return true if the plugin is installed * @param name the name of the plugin
*/ * @return true if the plugin is installed
@Override */
public boolean isPluginInstalled(String name) { @Override
// the plugin may be enabled after FastLogin, so isPluginEnabled() won't work here public boolean isPluginInstalled(String name) {
return Bukkit.getServer().getPluginManager().getPlugin(name) != null; // the plugin may be enabled after FastLogin, so isPluginEnabled() won't work here
} return Bukkit.getServer().getPluginManager().getPlugin(name) != null;
}
public FloodgateService getFloodgateService() { public FloodgateService getFloodgateService() {
return floodgateService; return floodgateService;
@ -333,6 +338,6 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
+ "Floodgate 2.0 from https://ci.opencollab.dev/job/GeyserMC/job/Floodgate/job/dev%252F2.0/"); + "Floodgate 2.0 from https://ci.opencollab.dev/job/GeyserMC/job/Floodgate/job/dev%252F2.0/");
logger.warn("Don't forget to update Geyser to a supported version as well from " logger.warn("Don't forget to update Geyser to a supported version as well from "
+ "https://ci.opencollab.dev/job/GeyserMC/job/Geyser/job/floodgate-2.0/"); + "https://ci.opencollab.dev/job/GeyserMC/job/Geyser/job/floodgate-2.0/");
} }
} }
} }

View File

@ -42,7 +42,8 @@ public class CrackedCommand extends ToggleCommand {
} }
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
String[] args) {
if (args.length == 0) { if (args.length == 0) {
onCrackedSelf(sender); onCrackedSelf(sender);
} else { } else {

View File

@ -49,7 +49,8 @@ public class PremiumCommand extends ToggleCommand {
} }
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
String[] args) {
if (args.length == 0) { if (args.length == 0) {
onPremiumSelf(sender); onPremiumSelf(sender);
} else { } else {

View File

@ -36,7 +36,7 @@ import org.jetbrains.annotations.NotNull;
public class BukkitFastLoginAutoLoginEvent extends Event implements FastLoginAutoLoginEvent, Cancellable { public class BukkitFastLoginAutoLoginEvent extends Event implements FastLoginAutoLoginEvent, Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList HANDLERS = new HandlerList();
private final LoginSession session; private final LoginSession session;
private final StoredProfile profile; private final StoredProfile profile;
private boolean cancelled; private boolean cancelled;
@ -70,10 +70,10 @@ public class BukkitFastLoginAutoLoginEvent extends Event implements FastLoginAut
@Override @Override
public @NotNull HandlerList getHandlers() { public @NotNull HandlerList getHandlers() {
return handlers; return HANDLERS;
} }
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return HANDLERS;
} }
} }

View File

@ -35,7 +35,7 @@ import org.jetbrains.annotations.NotNull;
public class BukkitFastLoginPreLoginEvent extends Event implements FastLoginPreLoginEvent { public class BukkitFastLoginPreLoginEvent extends Event implements FastLoginPreLoginEvent {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList HANDLERS = new HandlerList();
private final String username; private final String username;
private final LoginSource source; private final LoginSource source;
private final StoredProfile profile; private final StoredProfile profile;
@ -65,10 +65,10 @@ public class BukkitFastLoginPreLoginEvent extends Event implements FastLoginPreL
@Override @Override
public @NotNull HandlerList getHandlers() { public @NotNull HandlerList getHandlers() {
return handlers; return HANDLERS;
} }
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return HANDLERS;
} }
} }

View File

@ -34,7 +34,7 @@ import org.jetbrains.annotations.NotNull;
public class BukkitFastLoginPremiumToggleEvent extends Event implements FastLoginPremiumToggleEvent { public class BukkitFastLoginPremiumToggleEvent extends Event implements FastLoginPremiumToggleEvent {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList HANDLERS = new HandlerList();
private final StoredProfile profile; private final StoredProfile profile;
private final PremiumToggleReason reason; private final PremiumToggleReason reason;
@ -56,10 +56,10 @@ public class BukkitFastLoginPremiumToggleEvent extends Event implements FastLogi
@Override @Override
public @NotNull HandlerList getHandlers() { public @NotNull HandlerList getHandlers() {
return handlers; return HANDLERS;
} }
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return HANDLERS;
} }
} }

View File

@ -44,12 +44,12 @@ import org.bukkit.entity.Player;
* <p> * <p>
* Bukkit: <a href="https://dev.bukkit.org/bukkit-plugins/xauth/">...</a> * Bukkit: <a href="https://dev.bukkit.org/bukkit-plugins/xauth/">...</a>
*/ */
public class xAuthHook implements AuthPlugin<Player> { public class XAuthHook implements AuthPlugin<Player> {
private final xAuth xAuthPlugin = xAuth.getPlugin(); private final xAuth xAuthPlugin = xAuth.getPlugin();
private final FastLoginBukkit plugin; private final FastLoginBukkit plugin;
public xAuthHook(FastLoginBukkit plugin) { public XAuthHook(FastLoginBukkit plugin) {
this.plugin = plugin; this.plugin = plugin;
} }

View File

@ -97,8 +97,8 @@ public class ConnectionListener implements Listener {
String sessionId = plugin.getSessionId(player.getAddress()); String sessionId = plugin.getSessionId(player.getAddress());
plugin.getLog().info("No on-going login session for player: {} with ID {}. ", player, sessionId); plugin.getLog().info("No on-going login session for player: {} with ID {}. ", player, sessionId);
plugin.getLog().info("Setups using Minecraft proxies will start delayed " + plugin.getLog().info("Setups using Minecraft proxies will start delayed "
"when the command from the proxy is received"); + "when the command from the proxy is received");
} else { } else {
Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session); Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session);
Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask); Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask);

View File

@ -34,7 +34,6 @@ import com.google.common.primitives.Longs;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.KeyFactory; import java.security.KeyFactory;
import java.security.KeyPair; import java.security.KeyPair;
@ -63,20 +62,22 @@ import javax.crypto.spec.SecretKeySpec;
* Encryption and decryption minecraft util for connection between servers * Encryption and decryption minecraft util for connection between servers
* and paid Minecraft account clients. * and paid Minecraft account clients.
*/ */
class EncryptionUtil { final class EncryptionUtil {
public static final int VERIFY_TOKEN_LENGTH = 4; public static final int VERIFY_TOKEN_LENGTH = 4;
public static final String KEY_PAIR_ALGORITHM = "RSA"; public static final String KEY_PAIR_ALGORITHM = "RSA";
private static final int RSA_LENGTH = 1_024; private static final int RSA_LENGTH = 1_024;
private static final PublicKey mojangSessionKey; private static final PublicKey MOJANG_SESSION_KEY;
private static final int LINE_LENGTH = 76; private static final int LINE_LENGTH = 76;
private static final Encoder KEY_ENCODER = Base64.getMimeEncoder(LINE_LENGTH, "\n".getBytes(StandardCharsets.UTF_8)); private static final Encoder KEY_ENCODER = Base64.getMimeEncoder(
LINE_LENGTH, "\n".getBytes(StandardCharsets.UTF_8)
);
static { static {
try { try {
mojangSessionKey = loadMojangSessionKey(); MOJANG_SESSION_KEY = loadMojangSessionKey();
} catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException ex) { } catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException ex) {
throw new RuntimeException("Failed to load Mojang session key", ex); throw new RuntimeException("Failed to load Mojang session key", ex);
} }
@ -119,7 +120,7 @@ class EncryptionUtil {
/** /**
* Generate the server id based on client and server data. * Generate the server id based on client and server data.
* *
* @param serverId session for the current login attempt * @param serverId session for the current login attempt
* @param sharedSecret shared secret between the client and the server * @param sharedSecret shared secret between the client and the server
* @param publicKey public key of the server * @param publicKey public key of the server
* @return the server id formatted as a hexadecimal string. * @return the server id formatted as a hexadecimal string.
@ -135,7 +136,6 @@ class EncryptionUtil {
* @param privateKey private server key * @param privateKey private server key
* @param sharedKey the encrypted shared key * @param sharedKey the encrypted shared key
* @return shared secret key * @return shared secret key
* @throws GeneralSecurityException if it fails to decrypt the data
*/ */
public static SecretKey decryptSharedKey(PrivateKey privateKey, byte[] sharedKey) public static SecretKey decryptSharedKey(PrivateKey privateKey, byte[] sharedKey)
throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException,
@ -151,7 +151,7 @@ class EncryptionUtil {
Signature verifier = Signature.getInstance("SHA1withRSA"); Signature verifier = Signature.getInstance("SHA1withRSA");
// key of the signer // key of the signer
verifier.initVerify(mojangSessionKey); verifier.initVerify(MOJANG_SESSION_KEY);
verifier.update(toSignable(clientKey).getBytes(StandardCharsets.US_ASCII)); verifier.update(toSignable(clientKey).getBytes(StandardCharsets.US_ASCII));
return verifier.verify(clientKey.signature()); return verifier.verify(clientKey.signature());
} }

View File

@ -88,8 +88,8 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
//Minecraft server implementation //Minecraft server implementation
//https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/LoginListener.java#L161 //https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/LoginListener.java#L161
@Override @Override
public void requestPremiumLogin(ProtocolLibLoginSource source, StoredProfile profile public void requestPremiumLogin(ProtocolLibLoginSource source, StoredProfile profile,
, String username, boolean registered) { String username, boolean registered) {
try { try {
source.enableOnlinemode(); source.enableOnlinemode();
} catch (Exception ex) { } catch (Exception ex) {

View File

@ -147,13 +147,16 @@ public class ProtocolLibListener extends PacketAdapter {
BukkitLoginSession session = plugin.getSession(sender.getAddress()); BukkitLoginSession session = plugin.getSession(sender.getAddress());
if (session == null) { if (session == null) {
plugin.getLog().warn("GameProfile {} tried to send encryption response at invalid state", sender.getAddress()); plugin.getLog().warn("Profile {} tried to send encryption response at invalid state", sender.getAddress());
sender.kickPlayer(plugin.getCore().getMessage("invalid-request")); sender.kickPlayer(plugin.getCore().getMessage("invalid-request"));
} else { } else {
byte[] expectedVerifyToken = session.getVerifyToken(); byte[] expectedVerifyToken = session.getVerifyToken();
if (verifyNonce(sender, packetEvent.getPacket(), session.getClientPublicKey(), expectedVerifyToken)) { if (verifyNonce(sender, packetEvent.getPacket(), session.getClientPublicKey(), expectedVerifyToken)) {
packetEvent.getAsyncMarker().incrementProcessingDelay(); packetEvent.getAsyncMarker().incrementProcessingDelay();
Runnable verifyTask = new VerifyResponseTask(plugin, packetEvent, sender, session, sharedSecret, keyPair);
Runnable verifyTask = new VerifyResponseTask(
plugin, packetEvent, sender, session, sharedSecret, keyPair
);
plugin.getScheduler().runAsync(verifyTask); plugin.getScheduler().runAsync(verifyTask);
} else { } else {
sender.kickPlayer(plugin.getCore().getMessage("invalid-verify-token")); sender.kickPlayer(plugin.getCore().getMessage("invalid-verify-token"));
@ -192,8 +195,8 @@ public class ProtocolLibListener extends PacketAdapter {
byte[] nonce = packet.getByteArrays().read(1); byte[] nonce = packet.getByteArrays().read(1);
return EncryptionUtil.verifyNonce(expectedToken, keyPair.getPrivate(), nonce); return EncryptionUtil.verifyNonce(expectedToken, keyPair.getPrivate(), nonce);
} }
} catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException | NoSuchPaddingException | } catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException | NoSuchPaddingException
IllegalBlockSizeException | BadPaddingException signatureEx) { | IllegalBlockSizeException | BadPaddingException signatureEx) {
plugin.getLog().error("Invalid signature from player {}", sender, signatureEx); plugin.getLog().error("Invalid signature from player {}", sender, signatureEx);
return false; return false;
} }
@ -227,7 +230,9 @@ 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();
Runnable nameCheckTask = new NameCheckTask(plugin, random, player, packetEvent, username, clientKey.orElse(null), keyPair.getPublic()); Runnable nameCheckTask = new NameCheckTask(
plugin, random, player, packetEvent, username, clientKey.orElse(null), keyPair.getPublic()
);
plugin.getScheduler().runAsync(nameCheckTask); plugin.getScheduler().runAsync(nameCheckTask);
} }

View File

@ -55,7 +55,7 @@ class ProtocolLibLoginSource implements LoginSource {
private final String serverId = ""; private final String serverId = "";
private byte[] verifyToken; private byte[] verifyToken;
public ProtocolLibLoginSource(Player player, Random random, PublicKey serverPublicKey, ClientPublicKey clientKey) { ProtocolLibLoginSource(Player player, Random random, PublicKey serverPublicKey, ClientPublicKey clientKey) {
this.player = player; this.player = player;
this.random = random; this.random = random;
this.publicKey = serverPublicKey; this.publicKey = serverPublicKey;
@ -126,11 +126,11 @@ class ProtocolLibLoginSource implements LoginSource {
@Override @Override
public String toString() { public String toString() {
return this.getClass().getSimpleName() + '{' + return this.getClass().getSimpleName() + '{'
"player=" + player + + "player=" + player
", random=" + random + + ", random=" + random
", serverId='" + serverId + '\'' + + ", serverId='" + serverId + '\''
", verifyToken=" + Arrays.toString(verifyToken) + + ", verifyToken=" + Arrays.toString(verifyToken)
'}'; + '}';
} }
} }

View File

@ -71,7 +71,9 @@ public class VerifyResponseTask implements Runnable {
private static final Class<?> ENCRYPTION_CLASS; private static final Class<?> ENCRYPTION_CLASS;
static { static {
ENCRYPTION_CLASS = MinecraftReflection.getMinecraftClass("util." + ENCRYPTION_CLASS_NAME, ENCRYPTION_CLASS_NAME); ENCRYPTION_CLASS = MinecraftReflection.getMinecraftClass(
"util." + ENCRYPTION_CLASS_NAME, ENCRYPTION_CLASS_NAME
);
} }
private final FastLoginBukkit plugin; private final FastLoginBukkit plugin;
@ -144,7 +146,11 @@ public class VerifyResponseTask implements Runnable {
encryptConnection(session, requestedUsername, response.get()); encryptConnection(session, requestedUsername, response.get());
} else { } else {
//user tried to fake an authentication //user tried to fake an authentication
disconnect("invalid-session", "GameProfile {} ({}) tried to log in with an invalid session. ServerId: {}", session.getRequestUsername(), socketAddress, serverId); disconnect(
"invalid-session",
"GameProfile {} ({}) tried to log in with an invalid session. ServerId: {}",
session.getRequestUsername(), socketAddress, serverId
);
} }
} catch (IOException ioEx) { } catch (IOException ioEx) {
disconnect("error-kick", "Failed to connect to session server", ioEx); disconnect("error-kick", "Failed to connect to session server", ioEx);

View File

@ -60,8 +60,8 @@ public class ProtocolLoginSource implements LoginSource {
@Override @Override
public String toString() { public String toString() {
return this.getClass().getSimpleName() + '{' + return this.getClass().getSimpleName() + '{'
"loginStartEvent=" + loginStartEvent + + "loginStartEvent=" + loginStartEvent
'}'; + '}';
} }
} }

View File

@ -112,15 +112,16 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
} }
@Override @Override
public FastLoginPreLoginEvent callFastLoginPreLoginEvent(String username, ProtocolLoginSource source, StoredProfile profile) { public FastLoginPreLoginEvent callFastLoginPreLoginEvent(String username, ProtocolLoginSource source,
StoredProfile profile) {
BukkitFastLoginPreLoginEvent event = new BukkitFastLoginPreLoginEvent(username, source, profile); BukkitFastLoginPreLoginEvent event = new BukkitFastLoginPreLoginEvent(username, source, profile);
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
return event; return event;
} }
@Override @Override
public void requestPremiumLogin(ProtocolLoginSource source, StoredProfile profile, String username public void requestPremiumLogin(ProtocolLoginSource source, StoredProfile profile, String username,
, boolean registered) { boolean registered) {
source.enableOnlinemode(); source.enableOnlinemode();
String ip = source.getAddress().getAddress().getHostAddress(); String ip = source.getAddress().getAddress().getHostAddress();

View File

@ -31,7 +31,7 @@ import com.github.games647.fastlogin.bukkit.hook.CrazyLoginHook;
import com.github.games647.fastlogin.bukkit.hook.LogItHook; import com.github.games647.fastlogin.bukkit.hook.LogItHook;
import com.github.games647.fastlogin.bukkit.hook.LoginSecurityHook; import com.github.games647.fastlogin.bukkit.hook.LoginSecurityHook;
import com.github.games647.fastlogin.bukkit.hook.UltraAuthHook; import com.github.games647.fastlogin.bukkit.hook.UltraAuthHook;
import com.github.games647.fastlogin.bukkit.hook.xAuthHook; import com.github.games647.fastlogin.bukkit.hook.XAuthHook;
import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -95,7 +95,7 @@ public class DelayedAuthHook implements Runnable {
try { try {
List<Class<? extends AuthPlugin<Player>>> hooks = Arrays.asList(AuthMeHook.class, List<Class<? extends AuthPlugin<Player>>> hooks = Arrays.asList(AuthMeHook.class,
CrazyLoginHook.class, LogItHook.class, LoginSecurityHook.class, UltraAuthHook.class, CrazyLoginHook.class, LogItHook.class, LoginSecurityHook.class, UltraAuthHook.class,
xAuthHook.class); XAuthHook.class);
for (Class<? extends AuthPlugin<Player>> clazz : hooks) { for (Class<? extends AuthPlugin<Player>> clazz : hooks) {
String pluginName = clazz.getSimpleName(); String pluginName = clazz.getSimpleName();

View File

@ -40,7 +40,8 @@ import org.geysermc.floodgate.api.player.FloodgatePlayer;
public class FloodgateAuthTask extends FloodgateManagement<Player, CommandSender, BukkitLoginSession, FastLoginBukkit> { public class FloodgateAuthTask extends FloodgateManagement<Player, CommandSender, BukkitLoginSession, FastLoginBukkit> {
public FloodgateAuthTask(FastLoginCore<Player, CommandSender, FastLoginBukkit> core, Player player, FloodgatePlayer floodgatePlayer) { public FloodgateAuthTask(FastLoginCore<Player, CommandSender, FastLoginBukkit> core, Player player,
FloodgatePlayer floodgatePlayer) {
super(core, player, floodgatePlayer); super(core, player, floodgatePlayer);
} }

View File

@ -59,10 +59,10 @@ public class BungeeLoginSession extends LoginSession {
@Override @Override
public synchronized String toString() { public synchronized String toString() {
return this.getClass().getSimpleName() + '{' + return this.getClass().getSimpleName() + '{'
"alreadySaved=" + alreadySaved + + "alreadySaved=" + alreadySaved
", alreadyLogged=" + alreadyLogged + + ", alreadyLogged=" + alreadyLogged
", registered=" + registered + + ", registered=" + registered
"} " + super.toString(); + "} " + super.toString();
} }
} }

View File

@ -72,8 +72,8 @@ public class BungeeLoginSource implements LoginSource {
@Override @Override
public String toString() { public String toString() {
return this.getClass().getSimpleName() + '{' + return this.getClass().getSimpleName() + '{'
"connection=" + connection + + "connection=" + connection
'}'; + '}';
} }
} }

View File

@ -71,7 +71,7 @@ import org.slf4j.LoggerFactory;
public class ConnectListener implements Listener { public class ConnectListener implements Listener {
private static final String UUID_FIELD_NAME = "uniqueId"; private static final String UUID_FIELD_NAME = "uniqueId";
private static final MethodHandle uniqueIdSetter; private static final MethodHandle UNIQUE_ID_SETTER;
static { static {
MethodHandle setHandle = null; MethodHandle setHandle = null;
@ -91,7 +91,7 @@ public class ConnectListener implements Listener {
); );
} }
uniqueIdSetter = setHandle; UNIQUE_ID_SETTER = setHandle;
} }
private final FastLoginBungee plugin; private final FastLoginBungee plugin;
@ -155,7 +155,7 @@ public class ConnectListener implements Listener {
playerProfile.setId(verifiedUUID); playerProfile.setId(verifiedUUID);
// BungeeCord will do this automatically so override it on disabled option // BungeeCord will do this automatically so override it on disabled option
if (uniqueIdSetter != null) { if (UNIQUE_ID_SETTER != null) {
InitialHandler initialHandler = (InitialHandler) connection; InitialHandler initialHandler = (InitialHandler) connection;
if (!plugin.getCore().getConfig().get("premiumUuid", true)) { if (!plugin.getCore().getConfig().get("premiumUuid", true)) {
@ -179,7 +179,7 @@ public class ConnectListener implements Listener {
// BungeeCord only allows setting the UUID in PreLogin events and before requesting online mode // BungeeCord only allows setting the UUID in PreLogin events and before requesting online mode
// However if online mode is requested, it will override previous values // However if online mode is requested, it will override previous values
// So we have to do it with reflection // So we have to do it with reflection
uniqueIdSetter.invokeExact(connection, offlineUUID); UNIQUE_ID_SETTER.invokeExact(connection, offlineUUID);
String format = "Overridden UUID from {} to {} (based of {}) on {}"; String format = "Overridden UUID from {} to {} (based of {}) on {}";
plugin.getLog().info(format, oldPremiumId, offlineUUID, username, connection); plugin.getLog().info(format, oldPremiumId, offlineUUID, username, connection);

View File

@ -73,8 +73,8 @@ public class AsyncToggleMessage implements Runnable {
playerProfile.setPremium(false); playerProfile.setPremium(false);
playerProfile.setId(null); playerProfile.setId(null);
core.getStorage().save(playerProfile); core.getStorage().save(playerProfile);
PremiumToggleReason reason = (!isPlayerSender || !sender.getName().equalsIgnoreCase(playerProfile.getName())) ? PremiumToggleReason reason = (!isPlayerSender || !sender.getName().equalsIgnoreCase(playerProfile.getName()))
PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF; ? PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF;
core.getPlugin().getProxy().getPluginManager().callEvent( core.getPlugin().getProxy().getPluginManager().callEvent(
new BungeeFastLoginPremiumToggleEvent(playerProfile, reason)); new BungeeFastLoginPremiumToggleEvent(playerProfile, reason));
sendMessage("remove-premium"); sendMessage("remove-premium");
@ -89,8 +89,8 @@ public class AsyncToggleMessage implements Runnable {
playerProfile.setPremium(true); playerProfile.setPremium(true);
core.getStorage().save(playerProfile); core.getStorage().save(playerProfile);
PremiumToggleReason reason = (!isPlayerSender || !sender.getName().equalsIgnoreCase(playerProfile.getName())) ? PremiumToggleReason reason = (!isPlayerSender || !sender.getName().equalsIgnoreCase(playerProfile.getName()))
PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF; ? PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF;
core.getPlugin().getProxy().getPluginManager().callEvent( core.getPlugin().getProxy().getPluginManager().callEvent(
new BungeeFastLoginPremiumToggleEvent(playerProfile, reason)); new BungeeFastLoginPremiumToggleEvent(playerProfile, reason));
sendMessage("add-premium"); sendMessage("add-premium");

View File

@ -209,7 +209,7 @@
<!-- See https://checkstyle.org/config_misc.html --> <!-- See https://checkstyle.org/config_misc.html -->
<module name="ArrayTypeStyle"/> <module name="ArrayTypeStyle"/>
<!--<module name="FinalParameters"/>--> <!--<module name="FinalParameters"/>-->
<module name="TodoComment"/> <!-- <module name="TodoComment"/>-->
<module name="UpperEll"/> <module name="UpperEll"/>
<!-- https://checkstyle.org/config_filters.html#SuppressionXpathFilter --> <!-- https://checkstyle.org/config_filters.html#SuppressionXpathFilter -->

View File

@ -37,7 +37,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.slf4j.jul.JDK14LoggerAdapter; import org.slf4j.jul.JDK14LoggerAdapter;
public class CommonUtil { public final class CommonUtil {
private static final char COLOR_CHAR = '&'; private static final char COLOR_CHAR = '&';
private static final char TRANSLATED_CHAR = '§'; private static final char TRANSLATED_CHAR = '§';

View File

@ -114,11 +114,20 @@ public class StoredProfile extends Profile {
@Override @Override
public synchronized boolean equals(Object o) { public synchronized boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (!(o instanceof StoredProfile that)) return false; return true;
if (!super.equals(o)) return false; }
if (!(o instanceof StoredProfile that)) {
return false;
}
if (!super.equals(o)) {
return false;
}
return rowId == that.rowId && premium == that.premium return rowId == that.rowId && premium == that.premium
&& Objects.equals(lastIp, that.lastIp) && lastLogin.equals(that.lastLogin); && Objects.equals(lastIp, that.lastIp) && lastLogin.equals(that.lastLogin);
} }
@Override @Override
@ -128,11 +137,11 @@ public class StoredProfile extends Profile {
@Override @Override
public synchronized String toString() { public synchronized String toString() {
return this.getClass().getSimpleName() + '{' + return this.getClass().getSimpleName() + '{'
"rowId=" + rowId + + "rowId=" + rowId
", premium=" + premium + + ", premium=" + premium
", lastIp='" + lastIp + '\'' + + ", lastIp='" + lastIp + '\''
", lastLogin=" + lastLogin + + ", lastLogin=" + lastLogin
"} " + super.toString(); + "} " + super.toString();
} }
} }

View File

@ -36,42 +36,46 @@ import java.util.Optional;
/** /**
* An extension to {@link MojangResolver} which allows connection using transparent reverse proxies. * An extension to {@link MojangResolver} which allows connection using transparent reverse proxies.
* The significant difference is that unlike MojangResolver from the CraftAPI implementation, which sends the "ip" parameter * The significant difference is that unlike MojangResolver from the CraftAPI implementation, which sends the
* when the hostIp parameter is an IPv4 address, but skips it for IPv6, this implementation leaves out the "ip" parameter * "ip" parameter when the hostIp parameter is an IPv4 address, but skips it for IPv6, this implementation leaves out
* also for IPv4, effectively enabling transparent proxies to work. * the "ip" parameter also for IPv4, effectively enabling transparent proxies to work.
*
* @author games647, Enginecrafter77 * @author games647, Enginecrafter77
*/ */
public class ProxyAgnosticMojangResolver extends MojangResolver { public class ProxyAgnosticMojangResolver extends MojangResolver {
/**
* A formatting string containing a URL used to call the {@code hasJoined} method on mojang session servers.
*
* Formatting parameters:
* 1. The username of the player in question
* 2. The serverId of this server
*/
public static final String MOJANG_SESSIONSERVER_HASJOINED_CALL_URLFMT = "https://sessionserver.mojang.com/session/minecraft/hasJoined?username=%s&serverId=%s";
@Override private static final String HOST = "sessionserver.mojang.com";
public Optional<Verification> hasJoined(String username, String serverHash, InetAddress hostIp) throws IOException
{
String url = String.format(MOJANG_SESSIONSERVER_HASJOINED_CALL_URLFMT, username, serverHash);
HttpURLConnection conn = this.getConnection(url); /**
int responseCode = conn.getResponseCode(); * A formatting string containing a URL used to call the {@code hasJoined} method on mojang session servers.
* <p>
* Formatting parameters:
* 1. The username of the player in question
* 2. The serverId of this server
*/
public static final String ENDPOINT = "https://" + HOST + "/session/minecraft/hasJoined?username=%s&serverId=%s";
Verification verification = null; @Override
public Optional<Verification> hasJoined(String username, String serverHash, InetAddress hostIp)
throws IOException {
String url = String.format(ENDPOINT, username, serverHash);
// Mojang session servers send HTTP 204 (NO CONTENT) when the authentication seems invalid HttpURLConnection conn = this.getConnection(url);
// If that's not our case, the authentication is valid, and so we can parse the response. int responseCode = conn.getResponseCode();
if(responseCode != HttpURLConnection.HTTP_NO_CONTENT)
verification = this.parseRequest(conn, this::parseVerification);
return Optional.ofNullable(verification); Verification verification = null;
}
// Functional implementation of InputStreamAction, used in hasJoined method in parseRequest call // Mojang session servers send HTTP 204 (NO CONTENT) when the authentication seems invalid
protected Verification parseVerification(InputStream input) throws IOException // If that's not our case, the authentication is valid, and so we can parse the response.
{ if (responseCode != HttpURLConnection.HTTP_NO_CONTENT) {
return this.readJson(input, Verification.class); verification = this.parseRequest(conn, this::parseVerification);
} }
return Optional.ofNullable(verification);
}
// Functional implementation of InputStreamAction, used in hasJoined method in parseRequest call
protected Verification parseVerification(InputStream input) throws IOException {
return this.readJson(input, Verification.class);
}
} }

View File

@ -113,7 +113,7 @@ public class TickingRateLimiter implements RateLimiter {
private final long expireTime; private final long expireTime;
private int count; private int count;
public TimeRecord(long firstMinuteRecord, long expireTime) { TimeRecord(long firstMinuteRecord, long expireTime) {
this.firstMinuteRecord = firstMinuteRecord; this.firstMinuteRecord = firstMinuteRecord;
this.expireTime = expireTime; this.expireTime = expireTime;
this.count = 1; this.count = 1;

View File

@ -74,12 +74,12 @@ public abstract class BedrockService<B> {
"Could not check whether Bedrock Player {}'s name conflicts a premium Java player's name.", "Could not check whether Bedrock Player {}'s name conflicts a premium Java player's name.",
username); username);
kickPlayer(source, username, "Could not check if your name conflicts an existing " + kickPlayer(source, username, "Could not check if your name conflicts an existing "
"premium Java account's name. This is usually a serverside error."); + "premium Java account's name. This is usually a serverside error.");
} catch (RateLimitException rateLimitException) { } catch (RateLimitException rateLimitException) {
core.getPlugin().getLog().warn("Mojang API rate limit hit"); core.getPlugin().getLog().warn("Mojang API rate limit hit");
kickPlayer(source, username, "Could not check if your name conflicts an existing premium " + kickPlayer(source, username, "Could not check if your name conflicts an existing premium "
"Java account's name. Try again in a few minutes"); + "Java account's name. Try again in a few minutes");
} }
if (premiumUUID.isPresent()) { if (premiumUUID.isPresent()) {

View File

@ -60,12 +60,16 @@ public class FloodgateService extends BedrockService<FloodgatePlayer> {
*/ */
public boolean isValidFloodgateConfigString(String key) { public boolean isValidFloodgateConfigString(String key) {
String value = core.getConfig().get(key).toString().toLowerCase(Locale.ENGLISH); String value = core.getConfig().get(key).toString().toLowerCase(Locale.ENGLISH);
if (!"true".equals(value) && !"linked".equals(value) && !"false".equals(value) && !"no-conflict".equals(value)) { switch (value) {
core.getPlugin().getLog().error("Invalid value detected for {} in FastLogin/config.yml.", key); case "true":
return false; case "linked":
case "false":
case "no-conflict":
return true;
default:
core.getPlugin().getLog().error("Invalid value detected for {} in FastLogin/config.yml.", key);
return false;
} }
return true;
} }
@Override @Override
@ -82,7 +86,7 @@ public class FloodgateService extends BedrockService<FloodgatePlayer> {
if ("false".equals(allowConflict) if ("false".equals(allowConflict)
|| "linked".equals(allowConflict) && !isLinked) { || "linked".equals(allowConflict) && !isLinked) {
super.checkNameConflict(username, source); super.checkNameConflict(username, source);
} else { } else {
core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username); core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username);
} }

View File

@ -79,10 +79,10 @@ public class ChangePremiumMessage implements ChannelMessage {
@Override @Override
public String toString() { public String toString() {
return this.getClass().getSimpleName() + '{' + return this.getClass().getSimpleName() + '{'
"playerName='" + playerName + '\'' + + "playerName='" + playerName + '\''
", shouldEnable=" + willEnable + + ", shouldEnable=" + willEnable
", isSourceInvoker=" + isSourceInvoker + + ", isSourceInvoker=" + isSourceInvoker
'}'; + '}';
} }
} }

View File

@ -92,11 +92,11 @@ public class LoginActionMessage implements ChannelMessage {
@Override @Override
public String toString() { public String toString() {
return this.getClass().getSimpleName() + '{' + return this.getClass().getSimpleName() + '{'
"type='" + type + '\'' + + "type='" + type + '\''
", playerName='" + playerName + '\'' + + ", playerName='" + playerName + '\''
", proxyId=" + proxyId + + ", proxyId=" + proxyId
'}'; + '}';
} }
public enum Type { public enum Type {

View File

@ -122,7 +122,8 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
} }
// Initialize the resolver based on the config parameter // Initialize the resolver based on the config parameter
this.resolver = this.config.getBoolean("useProxyAgnosticResolver", false) ? new ProxyAgnosticMojangResolver() : new MojangResolver(); this.resolver = this.config.getBoolean("useProxyAgnosticResolver", false)
? new ProxyAgnosticMojangResolver() : new MojangResolver();
antiBot = createAntiBotService(config.getSection("anti-bot")); antiBot = createAntiBotService(config.getSection("anti-bot"));
Set<Proxy> proxies = config.getStringList("proxies") Set<Proxy> proxies = config.getStringList("proxies")
@ -191,7 +192,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
config = configProvider.load(reader, defaults); config = configProvider.load(reader, defaults);
} }
// explicitly add keys here, because Configuration.getKeys doesn't return the keys from the default configuration // explicitly add keys here, because Configuration.getKeys doesn't return the keys from the default config
for (String key : defaults.getKeys()) { for (String key : defaults.getKeys()) {
config.set(key, config.get(key)); config.set(key, config.get(key));
} }
@ -244,9 +245,13 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
boolean useSSL = config.get("useSSL", false); boolean useSSL = config.get("useSSL", false);
if (useSSL) { if (useSSL) {
databaseConfig.addDataSourceProperty("allowPublicKeyRetrieval", config.getBoolean("allowPublicKeyRetrieval", false)); boolean publicKeyRetrieval = config.getBoolean("allowPublicKeyRetrieval", false);
databaseConfig.addDataSourceProperty("serverRSAPublicKeyFile", config.getString("ServerRSAPublicKeyFile")); String rsaPublicKeyFile = config.getString("ServerRSAPublicKeyFile");
databaseConfig.addDataSourceProperty("sslMode", config.getString("sslMode", "Required")); String sslMode = config.getString("sslMode", "Required");
databaseConfig.addDataSourceProperty("allowPublicKeyRetrieval", publicKeyRetrieval);
databaseConfig.addDataSourceProperty("serverRSAPublicKeyFile", rsaPublicKeyFile);
databaseConfig.addDataSourceProperty("sslMode", sslMode);
} }
databaseConfig.setUsername(config.get("username", "")); databaseConfig.setUsername(config.get("username", ""));
@ -270,8 +275,8 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
} catch (ClassNotFoundException notFoundEx) { } catch (ClassNotFoundException notFoundEx) {
Logger log = plugin.getLog(); Logger log = plugin.getLog();
log.warn("This driver {} is not supported on this platform", className); log.warn("This driver {} is not supported on this platform", className);
log.warn("Please choose either MySQL (Spigot, BungeeCord), SQLite (Spigot, Sponge) or " + log.warn("Please choose either MySQL (Spigot, BungeeCord), SQLite (Spigot, Sponge) or "
"MariaDB (Sponge, Velocity)", notFoundEx); + "MariaDB (Sponge, Velocity)", notFoundEx);
} }
return false; return false;

View File

@ -106,9 +106,9 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
} }
} }
} catch (RateLimitException rateLimitEx) { } catch (RateLimitException rateLimitEx) {
core.getPlugin().getLog().error("Mojang's rate limit reached for {}. The public IPv4 address of this" + core.getPlugin().getLog().error("Mojang's rate limit reached for {}. The public IPv4 address of this"
" server issued more than 600 Name -> UUID requests within 10 minutes. After those 10" + + " server issued more than 600 Name -> UUID requests within 10 minutes. After those 10"
" minutes we can make requests again.", username); + " minutes we can make requests again.", username);
} catch (Exception ex) { } catch (Exception ex) {
core.getPlugin().getLog().error("Failed to check premium state for {}", username, ex); core.getPlugin().getLog().error("Failed to check premium state for {}", username, ex);
core.getPlugin().getLog().error("Failed to check premium state of {}", username, ex); core.getPlugin().getLog().error("Failed to check premium state of {}", username, ex);

View File

@ -31,7 +31,7 @@ import com.zaxxer.hikari.HikariConfig;
public class MySQLStorage extends SQLStorage { public class MySQLStorage extends SQLStorage {
public MySQLStorage(FastLoginCore<?, ?, ?> core, String driver, String host, int port, String database, public MySQLStorage(FastLoginCore<?, ?, ?> core, String driver, String host, int port, String database,
HikariConfig config,boolean useSSL) { HikariConfig config, boolean useSSL) {
super(core, super(core,
buildJDBCUrl(driver, host, port, database), buildJDBCUrl(driver, host, port, database),
setParams(config, useSSL)); setParams(config, useSSL));

10
pom.xml
View File

@ -131,11 +131,17 @@
<version>3.1.2</version> <version>3.1.2</version>
<configuration> <configuration>
<configLocation>checkstyle.xml</configLocation> <configLocation>checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput> <consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError> <failsOnError>false</failsOnError>
<linkXRef>false</linkXRef> <linkXRef>false</linkXRef>
</configuration> </configuration>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.3.1</version>
</dependency>
</dependencies>
<executions> <executions>
<execution> <execution>
<id>validate</id> <id>validate</id>

View File

@ -46,6 +46,7 @@ import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.messages.ChannelRegistrar;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
@ -73,7 +74,7 @@ public class FastLoginVelocity implements PlatformPlugin<CommandSource> {
private final Path dataDirectory; private final Path dataDirectory;
private final Logger logger; private final Logger logger;
private final ConcurrentMap<InetSocketAddress, VelocityLoginSession> session = new MapMaker().weakKeys().makeMap(); private final ConcurrentMap<InetSocketAddress, VelocityLoginSession> session = new MapMaker().weakKeys().makeMap();
private static final String PROXY_ID_fILE = "proxyId.txt"; private static final String PROXY_ID_FILE = "proxyId.txt";
private FastLoginCore<Player, CommandSource, FastLoginVelocity> core; private FastLoginCore<Player, CommandSource, FastLoginVelocity> core;
private AsyncScheduler scheduler; private AsyncScheduler scheduler;
@ -98,8 +99,10 @@ public class FastLoginVelocity implements PlatformPlugin<CommandSource> {
server.getEventManager().register(this, new ConnectListener(this, core.getAntiBot())); server.getEventManager().register(this, new ConnectListener(this, core.getAntiBot()));
server.getEventManager().register(this, new PluginMessageListener(this)); server.getEventManager().register(this, new PluginMessageListener(this));
server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), ChangePremiumMessage.CHANGE_CHANNEL));
server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), SuccessMessage.SUCCESS_CHANNEL)); ChannelRegistrar channelRegistry = server.getChannelRegistrar();
channelRegistry.register(MinecraftChannelIdentifier.create(getName(), ChangePremiumMessage.CHANGE_CHANNEL));
channelRegistry.register(MinecraftChannelIdentifier.create(getName(), SuccessMessage.SUCCESS_CHANNEL));
} }
@Subscribe @Subscribe
@ -167,7 +170,7 @@ public class FastLoginVelocity implements PlatformPlugin<CommandSource> {
} }
private void loadOrGenerateProxyId() { private void loadOrGenerateProxyId() {
Path idFile = dataDirectory.resolve(PROXY_ID_fILE); Path idFile = dataDirectory.resolve(PROXY_ID_FILE);
boolean shouldGenerate = false; boolean shouldGenerate = false;
if (Files.exists(idFile)) { if (Files.exists(idFile)) {
@ -182,7 +185,8 @@ public class FastLoginVelocity implements PlatformPlugin<CommandSource> {
logger.error("Unable to load proxy id from '{}'", idFile.toAbsolutePath()); logger.error("Unable to load proxy id from '{}'", idFile.toAbsolutePath());
logger.error("Detailed exception:", e); logger.error("Detailed exception:", e);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
logger.error("'{}' contains an invalid uuid! FastLogin will not work without a valid id.", idFile.toAbsolutePath()); Path filePath = idFile.toAbsolutePath();
logger.error("'{}' contains an invalid uuid! FastLogin will not work without a valid id.", filePath);
} }
} else { } else {
shouldGenerate = true; shouldGenerate = true;

View File

@ -58,10 +58,10 @@ public class VelocityLoginSession extends LoginSession {
@Override @Override
public synchronized String toString() { public synchronized String toString() {
return this.getClass().getSimpleName() + '{' + return this.getClass().getSimpleName() + '{'
"alreadySaved=" + alreadySaved + + "alreadySaved=" + alreadySaved
", alreadyLogged=" + alreadyLogged + + ", alreadyLogged=" + alreadyLogged
", registered=" + registered + + ", registered=" + registered
"} " + super.toString(); + "} " + super.toString();
} }
} }

View File

@ -33,7 +33,7 @@ import com.velocitypowered.api.event.ResultedEvent;
import java.util.Objects; import java.util.Objects;
public class VelocityFastLoginAutoLoginEvent public class VelocityFastLoginAutoLoginEvent
implements FastLoginAutoLoginEvent, ResultedEvent<ResultedEvent.GenericResult> { implements FastLoginAutoLoginEvent, ResultedEvent<ResultedEvent.GenericResult> {
private final LoginSession session; private final LoginSession session;
private final StoredProfile profile; private final StoredProfile profile;
@ -67,11 +67,11 @@ public class VelocityFastLoginAutoLoginEvent
@Override @Override
public GenericResult getResult() { public GenericResult getResult() {
return cancelled ? GenericResult.denied(): GenericResult.allowed(); return cancelled ? GenericResult.denied() : GenericResult.allowed();
} }
@Override @Override
public void setResult(GenericResult result) { public void setResult(GenericResult result) {
cancelled = Objects.requireNonNull(result) != GenericResult.allowed(); cancelled = Objects.requireNonNull(result) != GenericResult.allowed();
} }
} }

View File

@ -92,7 +92,9 @@ public class ConnectListener {
break; break;
case Continue: case Continue:
default: default:
Runnable asyncPremiumCheck = new AsyncPremiumCheck(plugin, connection, username, continuation, preLoginEvent); Runnable asyncPremiumCheck = new AsyncPremiumCheck(
plugin, connection, username, continuation, preLoginEvent
);
plugin.getScheduler().runAsync(asyncPremiumCheck); plugin.getScheduler().runAsync(asyncPremiumCheck);
break; break;
} }
@ -118,8 +120,8 @@ public class ConnectListener {
} }
if (!plugin.getCore().getConfig().get("forwardSkin", true)) { if (!plugin.getCore().getConfig().get("forwardSkin", true)) {
List<Property> skinFreeProp = removeSkin(event.getGameProfile().getProperties()); List<Property> newProp = removeSkin(event.getGameProfile().getProperties());
event.setGameProfile(event.getGameProfile().withProperties(skinFreeProp)); event.setGameProfile(event.getGameProfile().withProperties(newProp));
} }
} }
} }
@ -127,8 +129,9 @@ public class ConnectListener {
private List<GameProfile.Property> removeSkin(Collection<Property> oldProperties) { private List<GameProfile.Property> removeSkin(Collection<Property> oldProperties) {
List<GameProfile.Property> newProperties = new ArrayList<>(oldProperties.size()); List<GameProfile.Property> newProperties = new ArrayList<>(oldProperties.size());
for (GameProfile.Property property : oldProperties) { for (GameProfile.Property property : oldProperties) {
if (!"textures".equals(property.getName())) if (!"textures".equals(property.getName())) {
newProperties.add(property); newProperties.add(property);
}
} }
return newProperties; return newProperties;

View File

@ -55,8 +55,9 @@ public class PluginMessageListener {
public PluginMessageListener(FastLoginVelocity plugin) { public PluginMessageListener(FastLoginVelocity plugin) {
this.plugin = plugin; this.plugin = plugin;
this.successChannel = MinecraftChannelIdentifier.create(plugin.getName(), SuccessMessage.SUCCESS_CHANNEL).getId(); String prefix = plugin.getName();
this.changeChannel = MinecraftChannelIdentifier.create(plugin.getName(), ChangePremiumMessage.CHANGE_CHANNEL).getId(); this.successChannel = MinecraftChannelIdentifier.create(prefix, SuccessMessage.SUCCESS_CHANNEL).getId();
this.changeChannel = MinecraftChannelIdentifier.create(prefix, ChangePremiumMessage.CHANGE_CHANNEL).getId();
} }
@Subscribe @Subscribe
@ -95,8 +96,9 @@ public class PluginMessageListener {
String playerName = changeMessage.getPlayerName(); String playerName = changeMessage.getPlayerName();
boolean isSourceInvoker = changeMessage.isSourceInvoker(); boolean isSourceInvoker = changeMessage.isSourceInvoker();
if (changeMessage.shouldEnable()) { if (changeMessage.shouldEnable()) {
if (playerName.equals(forPlayer.getUsername()) && plugin.getCore().getConfig().get("premium-warning", true) Boolean premiumWarning = plugin.getCore().getConfig().get("premium-warning", true);
&& !core.getPendingConfirms().contains(forPlayer.getUniqueId())) { if (playerName.equals(forPlayer.getUsername()) && premiumWarning
&& !core.getPendingConfirms().contains(forPlayer.getUniqueId())) {
String message = core.getMessage("premium-warning"); String message = core.getMessage("premium-warning");
forPlayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); forPlayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message));
core.getPendingConfirms().add(forPlayer.getUniqueId()); core.getPendingConfirms().add(forPlayer.getUniqueId());
@ -114,7 +116,7 @@ public class PluginMessageListener {
} }
private void onSuccessMessage(Player forPlayer) { private void onSuccessMessage(Player forPlayer) {
if (forPlayer.isOnlineMode()){ if (forPlayer.isOnlineMode()) {
//bukkit module successfully received and force logged in the user //bukkit module successfully received and force logged in the user
//update only on success to prevent corrupt data //update only on success to prevent corrupt data
VelocityLoginSession loginSession = plugin.getSession().get(forPlayer.getRemoteAddress()); VelocityLoginSession loginSession = plugin.getSession().get(forPlayer.getRemoteAddress());

View File

@ -49,7 +49,8 @@ public class AsyncPremiumCheck extends JoinManagement<Player, CommandSource, Vel
private final PreLoginEvent preLoginEvent; private final PreLoginEvent preLoginEvent;
private final InboundConnection connection; private final InboundConnection connection;
public AsyncPremiumCheck(FastLoginVelocity plugin, InboundConnection connection, String username, Continuation continuation, PreLoginEvent preLoginEvent) { public AsyncPremiumCheck(FastLoginVelocity plugin, InboundConnection connection, String username,
Continuation continuation, PreLoginEvent preLoginEvent) {
super(plugin.getCore(), plugin.getCore().getAuthPluginHook(), plugin.getBedrockService()); super(plugin.getCore(), plugin.getCore().getAuthPluginHook(), plugin.getBedrockService());
this.plugin = plugin; this.plugin = plugin;
this.connection = connection; this.connection = connection;
@ -69,7 +70,8 @@ public class AsyncPremiumCheck extends JoinManagement<Player, CommandSource, Vel
} }
@Override @Override
public FastLoginPreLoginEvent callFastLoginPreLoginEvent(String username, VelocityLoginSource source, StoredProfile profile) { public FastLoginPreLoginEvent callFastLoginPreLoginEvent(String username, VelocityLoginSource source,
StoredProfile profile) {
VelocityFastLoginPreLoginEvent event = new VelocityFastLoginPreLoginEvent(username, source, profile); VelocityFastLoginPreLoginEvent event = new VelocityFastLoginPreLoginEvent(username, source, profile);
try { try {
return plugin.getProxy().getEventManager().fire(event).get(); return plugin.getProxy().getEventManager().fire(event).get();
@ -86,7 +88,8 @@ public class AsyncPremiumCheck extends JoinManagement<Player, CommandSource, Vel
public void requestPremiumLogin(VelocityLoginSource source, StoredProfile profile, public void requestPremiumLogin(VelocityLoginSource source, StoredProfile profile,
String username, boolean registered) { String username, boolean registered) {
source.enableOnlinemode(); source.enableOnlinemode();
plugin.getSession().put(source.getConnection().getRemoteAddress(), new VelocityLoginSession(username, registered, profile)); VelocityLoginSession session = new VelocityLoginSession(username, registered, profile);
plugin.getSession().put(source.getConnection().getRemoteAddress(), session);
String ip = source.getAddress().getAddress().getHostAddress(); String ip = source.getAddress().getAddress().getHostAddress();
plugin.getCore().getPendingLogin().put(ip + username, new Object()); plugin.getCore().getPendingLogin().put(ip + username, new Object());
@ -94,6 +97,7 @@ public class AsyncPremiumCheck extends JoinManagement<Player, CommandSource, Vel
@Override @Override
public void startCrackedSession(VelocityLoginSource source, StoredProfile profile, String username) { public void startCrackedSession(VelocityLoginSource source, StoredProfile profile, String username) {
plugin.getSession().put(source.getConnection().getRemoteAddress(), new VelocityLoginSession(username, false, profile)); VelocityLoginSession session = new VelocityLoginSession(username, false, profile);
plugin.getSession().put(source.getConnection().getRemoteAddress(), session);
} }
} }

View File

@ -31,6 +31,7 @@ import com.github.games647.fastlogin.core.shared.event.FastLoginPremiumToggleEve
import com.github.games647.fastlogin.velocity.FastLoginVelocity; import com.github.games647.fastlogin.velocity.FastLoginVelocity;
import com.github.games647.fastlogin.velocity.event.VelocityFastLoginPremiumToggleEvent; import com.github.games647.fastlogin.velocity.event.VelocityFastLoginPremiumToggleEvent;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.ConsoleCommandSource;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
@ -45,16 +46,17 @@ public class AsyncToggleMessage implements Runnable {
private final boolean isPlayerSender; private final boolean isPlayerSender;
public AsyncToggleMessage(FastLoginCore<Player, CommandSource, FastLoginVelocity> core, public AsyncToggleMessage(FastLoginCore<Player, CommandSource, FastLoginVelocity> core,
CommandSource sender, String playerName, boolean toPremium, boolean playerSender) { CommandSource sender, String playerName, boolean toPremium, boolean playerSender) {
this.core = core; this.core = core;
this.sender = sender; this.sender = sender;
this.targetPlayer = playerName; this.targetPlayer = playerName;
this.toPremium = toPremium; this.toPremium = toPremium;
this.isPlayerSender = playerSender; this.isPlayerSender = playerSender;
if (sender instanceof Player) if (sender instanceof Player) {
senderName = ((Player) sender).getUsername(); senderName = ((Player) sender).getUsername();
else } else {
senderName = ""; senderName = "";
}
} }
@Override @Override
@ -77,10 +79,10 @@ public class AsyncToggleMessage implements Runnable {
playerProfile.setPremium(false); playerProfile.setPremium(false);
playerProfile.setId(null); playerProfile.setId(null);
core.getStorage().save(playerProfile); core.getStorage().save(playerProfile);
PremiumToggleReason reason = (!isPlayerSender || !senderName.equalsIgnoreCase(playerProfile.getName())) ? PremiumToggleReason reason = (!isPlayerSender || !senderName.equalsIgnoreCase(playerProfile.getName()))
PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF; ? PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF;
core.getPlugin().getProxy().getEventManager().fire( core.getPlugin().getProxy().getEventManager().fire(
new VelocityFastLoginPremiumToggleEvent(playerProfile, reason)); new VelocityFastLoginPremiumToggleEvent(playerProfile, reason));
sendMessage("remove-premium"); sendMessage("remove-premium");
} }
@ -93,10 +95,11 @@ public class AsyncToggleMessage implements Runnable {
playerProfile.setPremium(true); playerProfile.setPremium(true);
core.getStorage().save(playerProfile); core.getStorage().save(playerProfile);
PremiumToggleReason reason = (!isPlayerSender || !senderName.equalsIgnoreCase(playerProfile.getName())) ? PremiumToggleReason reason = (!isPlayerSender || !senderName.equalsIgnoreCase(playerProfile.getName()))
PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF; ?
PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF;
core.getPlugin().getProxy().getEventManager().fire( core.getPlugin().getProxy().getEventManager().fire(
new VelocityFastLoginPremiumToggleEvent(playerProfile, reason)); new VelocityFastLoginPremiumToggleEvent(playerProfile, reason));
sendMessage("add-premium"); sendMessage("add-premium");
} }
@ -105,7 +108,8 @@ public class AsyncToggleMessage implements Runnable {
if (isPlayerSender) { if (isPlayerSender) {
sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message));
} else { } else {
core.getPlugin().getProxy().getConsoleCommandSource().sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); ConsoleCommandSource console = core.getPlugin().getProxy().getConsoleCommandSource();
console.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message));
} }
} }
} }

View File

@ -52,7 +52,8 @@ public class ForceLoginTask
private final boolean forcedOnlineMode; private final boolean forcedOnlineMode;
public ForceLoginTask(FastLoginCore<Player, CommandSource, FastLoginVelocity> core, public ForceLoginTask(FastLoginCore<Player, CommandSource, FastLoginVelocity> core,
Player player, RegisteredServer server, VelocityLoginSession session, boolean forcedOnlineMode) { Player player, RegisteredServer server, VelocityLoginSession session,
boolean forcedOnlineMode) {
super(core, player, session); super(core, player, session);
this.server = server; this.server = server;