Auth type refactor in internal config (#2410)

This commit is contained in:
Konicai 2021-07-28 19:44:09 -04:00 committed by GitHub
parent 5529a1cc1c
commit b86648332a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 46 additions and 24 deletions

View File

@ -31,6 +31,7 @@ import org.geysermc.common.PlatformType;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.bootstrap.GeyserBootstrap;
import org.geysermc.connector.command.CommandManager;
import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.dump.BootstrapDumpInfo;
import org.geysermc.connector.ping.GeyserLegacyPingPassthrough;
@ -100,13 +101,13 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
return;
}
if (geyserConfig.getRemote().getAuthType().equals("floodgate") && getProxy().getPluginManager().getPlugin("floodgate") == null) {
if (geyserConfig.getRemote().getAuthType() == AuthType.FLOODGATE && getProxy().getPluginManager().getPlugin("floodgate") == null) {
geyserLogger.severe(LanguageUtils.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " " + LanguageUtils.getLocaleStringLog("geyser.bootstrap.floodgate.disabling"));
return;
} else if (geyserConfig.isAutoconfiguredRemote() && getProxy().getPluginManager().getPlugin("floodgate") != null) {
// Floodgate installed means that the user wants Floodgate authentication
geyserLogger.debug("Auto-setting to Floodgate authentication.");
geyserConfig.getRemote().setAuthType("floodgate");
geyserConfig.getRemote().setAuthType(AuthType.FLOODGATE);
}
geyserConfig.loadFloodgate(this);

View File

@ -36,6 +36,7 @@ import org.geysermc.common.PlatformType;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.bootstrap.GeyserBootstrap;
import org.geysermc.connector.command.CommandManager;
import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.dump.BootstrapDumpInfo;
import org.geysermc.connector.network.translators.world.WorldManager;
@ -127,14 +128,14 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
return;
}
if (geyserConfig.getRemote().getAuthType().equals("floodgate") && Bukkit.getPluginManager().getPlugin("floodgate") == null) {
if (geyserConfig.getRemote().getAuthType() == AuthType.FLOODGATE && Bukkit.getPluginManager().getPlugin("floodgate") == null) {
geyserLogger.severe(LanguageUtils.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " " + LanguageUtils.getLocaleStringLog("geyser.bootstrap.floodgate.disabling"));
this.getPluginLoader().disablePlugin(this);
return;
} else if (geyserConfig.isAutoconfiguredRemote() && Bukkit.getPluginManager().getPlugin("floodgate") != null) {
// Floodgate installed means that the user wants Floodgate authentication
geyserLogger.debug("Auto-setting to Floodgate authentication.");
geyserConfig.getRemote().setAuthType("floodgate");
geyserConfig.getRemote().setAuthType(AuthType.FLOODGATE);
}
geyserConfig.loadFloodgate(this);

View File

@ -36,6 +36,7 @@ import lombok.Getter;
import org.geysermc.common.PlatformType;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.bootstrap.GeyserBootstrap;
import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.dump.BootstrapDumpInfo;
import org.geysermc.connector.ping.GeyserLegacyPingPassthrough;
@ -116,13 +117,13 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
} catch (ClassNotFoundException ignored) {
}
if (geyserConfig.getRemote().getAuthType().equals("floodgate") && !proxyServer.getPluginManager().getPlugin("floodgate").isPresent()) {
if (geyserConfig.getRemote().getAuthType() == AuthType.FLOODGATE && !proxyServer.getPluginManager().getPlugin("floodgate").isPresent()) {
geyserLogger.severe(LanguageUtils.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " " + LanguageUtils.getLocaleStringLog("geyser.bootstrap.floodgate.disabling"));
return;
} else if (geyserConfig.isAutoconfiguredRemote() && proxyServer.getPluginManager().getPlugin("floodgate").isPresent()) {
// Floodgate installed means that the user wants Floodgate authentication
geyserLogger.debug("Auto-setting to Floodgate authentication.");
geyserConfig.getRemote().setAuthType("floodgate");
geyserConfig.getRemote().setAuthType(AuthType.FLOODGATE);
}
geyserConfig.loadFloodgate(this, proxyServer, configFolder.toFile());

View File

@ -25,6 +25,7 @@
package org.geysermc.connector;
import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.configuration.GeyserJacksonConfiguration;
import org.geysermc.connector.utils.LanguageUtils;
@ -33,7 +34,7 @@ import java.nio.file.Path;
public class FloodgateKeyLoader {
public static Path getKeyPath(GeyserJacksonConfiguration config, Object floodgate, Path floodgateDataFolder, Path geyserDataFolder, GeyserLogger logger) {
if (!config.getRemote().getAuthType().equals("floodgate")) {
if (config.getRemote().getAuthType() != AuthType.FLOODGATE) {
return geyserDataFolder.resolve(config.getFloodgateKeyFile());
}

View File

@ -106,9 +106,6 @@ public class GeyserConnector {
@Setter
private static boolean shouldStartListener = true;
@Setter
private AuthType defaultAuthType;
private final TimeSyncer timeSyncer;
private FloodgateCipher cipher;
private FloodgateSkinUploader skinUploader;
@ -192,10 +189,8 @@ public class GeyserConnector {
}
}
defaultAuthType = AuthType.getByName(config.getRemote().getAuthType());
TimeSyncer timeSyncer = null;
if (defaultAuthType == AuthType.FLOODGATE) {
if (config.getRemote().getAuthType() == AuthType.FLOODGATE) {
timeSyncer = new TimeSyncer(Constants.NTP_SERVER);
try {
Key key = new AesKeyProducer().produceFrom(config.getFloodgateKeyPath());
@ -273,7 +268,7 @@ public class GeyserConnector {
metrics = new Metrics(this, "GeyserMC", config.getMetrics().getUniqueId(), false, java.util.logging.Logger.getLogger(""));
metrics.addCustomChart(new Metrics.SingleLineChart("players", players::size));
// Prevent unwanted words best we can
metrics.addCustomChart(new Metrics.SimplePie("authMode", () -> AuthType.getByName(config.getRemote().getAuthType()).toString().toLowerCase()));
metrics.addCustomChart(new Metrics.SimplePie("authMode", () -> config.getRemote().getAuthType().toString().toLowerCase()));
metrics.addCustomChart(new Metrics.SimplePie("platform", platformType::getPlatformName));
metrics.addCustomChart(new Metrics.SimplePie("defaultLocale", LanguageUtils::getDefaultLocale));
metrics.addCustomChart(new Metrics.SimplePie("version", () -> GeyserConnector.VERSION));
@ -463,7 +458,6 @@ public class GeyserConnector {
}
newsHandler.shutdown();
players.clear();
defaultAuthType = null;
this.getCommandManager().getCommands().clear();
bootstrap.getGeyserLogger().info(LanguageUtils.getLocaleStringLog("geyser.core.shutdown.done"));
@ -555,6 +549,15 @@ public class GeyserConnector {
return !"DEV".equals(GeyserConnector.VERSION);
}
/**
* Deprecated. Get the AuthType from the GeyserConfiguration through {@link GeyserConnector#getConfig()}
* @return The
*/
@Deprecated
public AuthType getDefaultAuthType() {
return getConfig().getRemote().getAuthType();
}
public static GeyserConnector getInstance() {
return instance;
}

View File

@ -25,8 +25,13 @@
package org.geysermc.connector.common;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import lombok.Getter;
import java.io.IOException;
@Getter
public enum AuthType {
OFFLINE,
@ -40,7 +45,7 @@ public enum AuthType {
}
/**
* Convert the AuthType string (from config) to the enum, OFFLINE on fail
* Convert the AuthType string (from config) to the enum, ONLINE on fail
*
* @param name AuthType string
*
@ -53,6 +58,13 @@ public enum AuthType {
return type;
}
}
return OFFLINE;
return ONLINE;
}
public static class Deserializer extends JsonDeserializer<AuthType> {
@Override
public AuthType deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return getByName(p.getValueAsString());
}
}
}

View File

@ -27,6 +27,7 @@ package org.geysermc.connector.configuration;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.geysermc.connector.GeyserLogger;
import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.network.CIDRMatcher;
import org.geysermc.connector.utils.LanguageUtils;
@ -135,7 +136,7 @@ public interface GeyserConfiguration {
void setPort(int port);
String getAuthType();
AuthType getAuthType();
boolean isPasswordAuthentication();

View File

@ -32,6 +32,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.Getter;
import lombok.Setter;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.common.serializer.AsteriskSerializer;
import org.geysermc.connector.network.CIDRMatcher;
@ -59,7 +60,7 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration
private boolean extendedWorldHeight = false;
@JsonProperty("floodgate-key-file")
private String floodgateKeyFile = "public-key.pem";
private String floodgateKeyFile = "key.pem";
public abstract Path getFloodgateKeyPath();
@ -194,8 +195,9 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration
private int port = 25565;
@Setter
@JsonDeserialize(using = AuthType.Deserializer.class)
@JsonProperty("auth-type")
private String authType = "online";
private AuthType authType = AuthType.ONLINE;
@JsonProperty("allow-password-authentication")
private boolean passwordAuthentication = true;

View File

@ -478,7 +478,7 @@ public class GeyserSession implements CommandSender {
startGame();
this.remoteAddress = connector.getConfig().getRemote().getAddress();
this.remotePort = connector.getConfig().getRemote().getPort();
this.remoteAuthType = connector.getDefaultAuthType();
this.remoteAuthType = connector.getConfig().getRemote().getAuthType();
// Set the hardcoded shield ID to the ID we just defined in StartGamePacket
upstream.getSession().getHardcodedBlockingId().set(this.itemMappings.getStoredItems().shield().getBedrockId());

View File

@ -104,7 +104,7 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
session.sendDownstreamPacket(new ClientPluginMessagePacket("minecraft:brand", PluginMessageUtils.getGeyserBrandData()));
// register the plugin messaging channels used in Floodgate
if (session.getConnector().getDefaultAuthType() == AuthType.FLOODGATE) {
if (session.getRemoteAuthType() == AuthType.FLOODGATE) {
session.sendDownstreamPacket(new ClientPluginMessagePacket("minecraft:register", PluginMessageUtils.getFloodgateRegisterData()));
}

View File

@ -43,7 +43,7 @@ public class JavaPluginMessageTranslator extends PacketTranslator<ServerPluginMe
@Override
public void translate(ServerPluginMessagePacket packet, GeyserSession session) {
// The only plugin messages it has to listen for are Floodgate plugin messages
if (session.getConnector().getDefaultAuthType() != AuthType.FLOODGATE) {
if (session.getRemoteAuthType() != AuthType.FLOODGATE) {
return;
}

View File

@ -286,7 +286,7 @@ public class SkinManager {
String skinUrl = isAlex ? SkinProvider.EMPTY_SKIN_ALEX.getTextureUrl() : SkinProvider.EMPTY_SKIN.getTextureUrl();
String capeUrl = SkinProvider.EMPTY_CAPE.getTextureUrl();
if (("steve".equals(skinUrl) || "alex".equals(skinUrl)) && GeyserConnector.getInstance().getDefaultAuthType() != AuthType.ONLINE) {
if (("steve".equals(skinUrl) || "alex".equals(skinUrl)) && GeyserConnector.getInstance().getConfig().getRemote().getAuthType() != AuthType.ONLINE) {
GeyserSession session = GeyserConnector.getInstance().getPlayerByUuid(profile.getId());
if (session != null) {