mirror of
https://github.com/GeyserMC/Floodgate.git
synced 2026-01-04 15:31:48 +00:00
Switched to ConfigUtils 2.0
This commit is contained in:
@@ -27,11 +27,11 @@ object Versions {
|
||||
const val geyserVersion = "2.0.7-SNAPSHOT"
|
||||
const val cumulusVersion = "1.1.1"
|
||||
const val eventsVersion = "1.0-SNAPSHOT"
|
||||
const val configUtilsVersion = "1.0-SNAPSHOT"
|
||||
const val configUtilsVersion = "2.0-SNAPSHOT"
|
||||
const val fastutilVersion = "8.5.3"
|
||||
const val guiceVersion = "5.1.0"
|
||||
const val nettyVersion = "4.1.49.Final"
|
||||
const val snakeyamlVersion = "1.28"
|
||||
const val snakeyamlVersion = "2.0"
|
||||
const val cloudVersion = "1.5.0"
|
||||
const val bstatsVersion = "3.0.1"
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public class BungeeDataAddon implements InjectorAddon {
|
||||
@Override
|
||||
public void onInject(Channel channel, boolean toServer) {
|
||||
if (toServer) {
|
||||
if (config.isSendFloodgateData()) {
|
||||
if (config.sendFloodgateData()) {
|
||||
channel.pipeline().addAfter(
|
||||
packetEncoder, "floodgate_data_handler",
|
||||
new BungeeServerDataHandler(api, playerAttribute)
|
||||
|
||||
@@ -131,7 +131,7 @@ public final class BungeeListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPostLogin(PostLoginEvent event) {
|
||||
// To fix the February 2 2022 Mojang authentication changes
|
||||
if (!config.isSendFloodgateData()) {
|
||||
if (!config.sendFloodgateData()) {
|
||||
FloodgatePlayer player = api.getPlayer(event.getPlayer().getUniqueId());
|
||||
if (player != null && !player.isLinked()) {
|
||||
skinApplier.applySkin(player, new SkinDataImpl("", ""));
|
||||
|
||||
@@ -83,6 +83,6 @@ public final class DebugAddon implements InjectorAddon {
|
||||
|
||||
@Override
|
||||
public boolean shouldInject() {
|
||||
return config.isDebug();
|
||||
return config.debug();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,10 +113,10 @@ public abstract class CommonDataHandler extends ChannelInboundHandlerAdapter {
|
||||
setKickMessage(Constants.INTERNAL_ERROR_MESSAGE);
|
||||
break;
|
||||
case DECRYPT_ERROR:
|
||||
setKickMessage(config.getDisconnect().getInvalidKey());
|
||||
setKickMessage(config.disconnect().invalidKey());
|
||||
break;
|
||||
case INVALID_DATA_LENGTH:
|
||||
setKickMessage(config.getDisconnect().getInvalidArgumentsLength());
|
||||
setKickMessage(config.disconnect().invalidArgumentsLength());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -187,7 +187,7 @@ public abstract class CommonDataHandler extends ChannelInboundHandlerAdapter {
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
super.exceptionCaught(ctx, cause);
|
||||
if (config.isDebug()) {
|
||||
if (config.debug()) {
|
||||
cause.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,10 +66,10 @@ public class HandshakeDataImpl implements HandshakeData {
|
||||
UUID javaUniqueId = null;
|
||||
|
||||
if (bedrockData != null) {
|
||||
String prefix = config.getUsernamePrefix();
|
||||
String prefix = config.usernamePrefix();
|
||||
int usernameLength = Math.min(bedrockData.getUsername().length(), 16 - prefix.length());
|
||||
javaUsername = prefix + bedrockData.getUsername().substring(0, usernameLength);
|
||||
if (config.isReplaceSpaces()) {
|
||||
if (config.replaceSpaces()) {
|
||||
javaUsername = javaUsername.replace(" ", "_");
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public class SimpleFloodgateApi implements FloodgateApi {
|
||||
|
||||
@Override
|
||||
public String getPlayerPrefix() {
|
||||
return config.getUsernamePrefix();
|
||||
return config.usernamePrefix();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -159,9 +159,9 @@ public final class LinkAccountCommand implements FloodgateCommand {
|
||||
|
||||
@Override
|
||||
public boolean shouldRegister(FloodgateConfig config) {
|
||||
FloodgateConfig.PlayerLinkConfig linkConfig = config.getPlayerLink();
|
||||
return linkConfig.isEnabled() &&
|
||||
(linkConfig.isEnableOwnLinking() || linkConfig.isEnableGlobalLinking());
|
||||
FloodgateConfig.PlayerLinkConfig linkConfig = config.playerLink();
|
||||
return linkConfig.enabled() &&
|
||||
(linkConfig.enableOwnLinking() || linkConfig.enableGlobalLinking());
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -106,9 +106,9 @@ public final class UnlinkAccountCommand implements FloodgateCommand {
|
||||
|
||||
@Override
|
||||
public boolean shouldRegister(FloodgateConfig config) {
|
||||
FloodgateConfig.PlayerLinkConfig linkConfig = config.getPlayerLink();
|
||||
return linkConfig.isEnabled() &&
|
||||
(linkConfig.isEnableOwnLinking() || linkConfig.isEnableGlobalLinking());
|
||||
FloodgateConfig.PlayerLinkConfig linkConfig = config.playerLink();
|
||||
return linkConfig.enabled() &&
|
||||
(linkConfig.enableOwnLinking() || linkConfig.enableGlobalLinking());
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -110,8 +110,8 @@ public class WhitelistCommand implements FloodgateCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if (name.startsWith(config.getUsernamePrefix())) {
|
||||
name = name.substring(config.getUsernamePrefix().length());
|
||||
if (name.startsWith(config.usernamePrefix())) {
|
||||
name = name.substring(config.usernamePrefix().length());
|
||||
}
|
||||
|
||||
if (name.length() < 1 || name.length() > 16) {
|
||||
@@ -122,10 +122,10 @@ public class WhitelistCommand implements FloodgateCommand {
|
||||
// todo let it use translations
|
||||
|
||||
String tempName = name;
|
||||
if (config.isReplaceSpaces()) {
|
||||
if (config.replaceSpaces()) {
|
||||
tempName = tempName.replace(' ', '_');
|
||||
}
|
||||
final String correctName = config.getUsernamePrefix() + tempName;
|
||||
final String correctName = config.usernamePrefix() + tempName;
|
||||
final String strippedName = name;
|
||||
|
||||
// We need to get the UUID of the player if it's not manually specified
|
||||
|
||||
@@ -25,10 +25,12 @@
|
||||
|
||||
package org.geysermc.floodgate.core.config;
|
||||
|
||||
import io.micronaut.context.ApplicationContext;
|
||||
import io.micronaut.context.annotation.Bean;
|
||||
import io.micronaut.context.annotation.Factory;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.Key;
|
||||
@@ -36,10 +38,11 @@ import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
import org.geysermc.configutils.ConfigUtilities;
|
||||
import org.geysermc.configutils.file.codec.PathFileCodec;
|
||||
import org.geysermc.configutils.file.template.ResourceTemplateReader;
|
||||
import org.geysermc.configutils.updater.change.Changes;
|
||||
import org.geysermc.floodgate.core.event.lifecycle.ConfigLoadedEvent;
|
||||
import org.geysermc.floodgate.core.scope.ProxyOnly;
|
||||
import org.geysermc.floodgate.core.scope.ServerOnly;
|
||||
import org.geysermc.floodgate.core.util.LanguageManager;
|
||||
import org.geysermc.floodgate.crypto.FloodgateCipher;
|
||||
import org.geysermc.floodgate.crypto.KeyProducer;
|
||||
|
||||
@@ -49,40 +52,40 @@ public final class ConfigLoader {
|
||||
private final Path dataDirectory;
|
||||
private final KeyProducer keyProducer;
|
||||
private final FloodgateCipher cipher;
|
||||
private final LanguageManager languageManager;
|
||||
private final ApplicationContext context;
|
||||
|
||||
@Inject
|
||||
ConfigLoader(
|
||||
@Named("dataDirectory") Path dataDirectory,
|
||||
KeyProducer keyProducer,
|
||||
FloodgateCipher cipher
|
||||
FloodgateCipher cipher,
|
||||
LanguageManager languageManager,
|
||||
ApplicationContext context
|
||||
) {
|
||||
this.dataDirectory = dataDirectory;
|
||||
this.keyProducer = keyProducer;
|
||||
this.cipher = cipher;
|
||||
this.languageManager = languageManager;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ServerOnly
|
||||
@Singleton
|
||||
FloodgateConfig config() {
|
||||
return load(FloodgateConfig.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ProxyOnly
|
||||
@Singleton
|
||||
ProxyFloodgateConfig proxyConfig() {
|
||||
return load(ProxyFloodgateConfig.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends FloodgateConfig> T load(Class<? extends FloodgateConfig> configClass) {
|
||||
String templateFile = "config.yml";
|
||||
if (ProxyFloodgateConfig.class.isAssignableFrom(configClass)) {
|
||||
templateFile = "proxy-" + templateFile;
|
||||
}
|
||||
|
||||
//todo old Floodgate logged a message when version = 0 and it generated a new key.
|
||||
// Might be nice to allow you to run a function for a specific version.
|
||||
|
||||
// it would also be nice to have sections in versionBuilder so that you don't have to
|
||||
// provide the path all the time
|
||||
|
||||
@@ -90,27 +93,31 @@ public final class ConfigLoader {
|
||||
ConfigUtilities.builder()
|
||||
.fileCodec(PathFileCodec.of(dataDirectory))
|
||||
.configFile("config.yml")
|
||||
.templateReader(ResourceTemplateReader.of(getClass()))
|
||||
.template(templateFile)
|
||||
.changes(Changes.builder()
|
||||
.version(1, Changes.versionBuilder()
|
||||
.keyRenamed("player-link.enable", "player-link.enabled")
|
||||
.keyRenamed("player-link.allow-linking", "player-link.allowed"))
|
||||
.keyRenamed("playerLink.enable", "playerLink.enabled")
|
||||
.keyRenamed("playerLink.allowLinking", "playerLink.allowed"))
|
||||
.version(2, Changes.versionBuilder()
|
||||
.keyRenamed("player-link.use-global-linking", "player-link.enable-global-linking"))
|
||||
.keyRenamed("playerLink.useGlobalLinking", "playerLink.enableGlobalLinking"))
|
||||
.build())
|
||||
.definePlaceholder("metrics.uuid", UUID::randomUUID)
|
||||
.postInitializeCallbackArgument(this)
|
||||
.commentTranslator((key) -> languageManager.getLogString("floodgate.config." + key))
|
||||
.build();
|
||||
|
||||
T config;
|
||||
try {
|
||||
return (T) utilities.executeOn(configClass);
|
||||
config = (T) utilities.executeOn(configClass);
|
||||
} catch (Throwable throwable) {
|
||||
throw new RuntimeException(
|
||||
"Failed to load the config! Try to delete the config file if this error persists",
|
||||
throwable
|
||||
);
|
||||
}
|
||||
|
||||
context.getEventPublisher(ConfigLoadedEvent.class)
|
||||
.publishEvent(new ConfigLoadedEvent(config));
|
||||
return config;
|
||||
}
|
||||
|
||||
public void generateKey(Path keyPath) {
|
||||
|
||||
@@ -29,40 +29,31 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.Key;
|
||||
import lombok.Getter;
|
||||
import org.geysermc.configutils.loader.callback.CallbackResult;
|
||||
import org.geysermc.configutils.loader.callback.GenericPostInitializeCallback;
|
||||
import org.geysermc.configutils.node.meta.Comment;
|
||||
import org.geysermc.configutils.node.meta.ConfigSection;
|
||||
import org.geysermc.configutils.node.meta.ConfigVersion;
|
||||
import org.geysermc.configutils.node.meta.Defaults.DefaultBoolean;
|
||||
import org.geysermc.configutils.node.meta.Defaults.DefaultNumeric;
|
||||
import org.geysermc.configutils.node.meta.Defaults.DefaultString;
|
||||
import org.geysermc.configutils.node.meta.Exclude;
|
||||
import org.geysermc.configutils.node.meta.Hidden;
|
||||
import org.geysermc.configutils.node.meta.Placeholder;
|
||||
|
||||
/**
|
||||
* The global Floodgate configuration file used in every platform. Some platforms have their own
|
||||
* addition to the global configuration like {@link ProxyFloodgateConfig} for the proxies.
|
||||
*/
|
||||
@Getter
|
||||
public class FloodgateConfig implements GenericPostInitializeCallback<ConfigLoader> {
|
||||
private String keyFileName;
|
||||
private String usernamePrefix = "";
|
||||
private boolean replaceSpaces;
|
||||
|
||||
private String defaultLocale;
|
||||
|
||||
private DisconnectMessages disconnect;
|
||||
private PlayerLinkConfig playerLink;
|
||||
private MetricsConfig metrics;
|
||||
|
||||
private boolean debug;
|
||||
private int configVersion;
|
||||
|
||||
|
||||
private Key key;
|
||||
private String rawUsernamePrefix;
|
||||
|
||||
public boolean isProxy() {
|
||||
@ConfigVersion(3)
|
||||
public interface FloodgateConfig extends GenericPostInitializeCallback<ConfigLoader> {
|
||||
default boolean proxy() {
|
||||
return this instanceof ProxyFloodgateConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallbackResult postInitialize(ConfigLoader loader) {
|
||||
Path keyPath = loader.getDataDirectory().resolve(getKeyFileName());
|
||||
default CallbackResult postInitialize(ConfigLoader loader) {
|
||||
Path keyPath = loader.getDataDirectory().resolve(keyFileName());
|
||||
|
||||
// don't assume that the key always exists with the existence of a config
|
||||
if (!Files.exists(keyPath)) {
|
||||
@@ -72,41 +63,108 @@ public class FloodgateConfig implements GenericPostInitializeCallback<ConfigLoad
|
||||
try {
|
||||
Key floodgateKey = loader.getKeyProducer().produceFrom(keyPath);
|
||||
loader.getCipher().init(floodgateKey);
|
||||
key = floodgateKey;
|
||||
key(floodgateKey);
|
||||
} catch (IOException exception) {
|
||||
return CallbackResult.failed(exception.getMessage());
|
||||
}
|
||||
|
||||
rawUsernamePrefix = usernamePrefix;
|
||||
rawUsernamePrefix(usernamePrefix());
|
||||
|
||||
// Java usernames can't be longer than 16 chars
|
||||
if (usernamePrefix.length() >= 16) {
|
||||
usernamePrefix = ".";
|
||||
if (usernamePrefix().length() >= 16) {
|
||||
usernamePrefix(".");
|
||||
}
|
||||
|
||||
// this happens before the config is serialized,
|
||||
// so the messages in the config will be translated
|
||||
loader.getLanguageManager().loadConfiguredDefaultLocale(this);
|
||||
|
||||
return CallbackResult.ok();
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static class DisconnectMessages {
|
||||
private String invalidKey;
|
||||
private String invalidArgumentsLength;
|
||||
@Comment
|
||||
@DefaultString("key.pem")
|
||||
String keyFileName();
|
||||
|
||||
@Comment
|
||||
@DefaultString(".")
|
||||
String usernamePrefix();
|
||||
|
||||
void usernamePrefix(String usernamePrefix);
|
||||
|
||||
@Comment
|
||||
@DefaultBoolean(true)
|
||||
boolean replaceSpaces();
|
||||
|
||||
@Comment
|
||||
@DefaultString("system")
|
||||
String defaultLocale();
|
||||
|
||||
DisconnectMessages disconnect();
|
||||
|
||||
@Comment
|
||||
PlayerLinkConfig playerLink();
|
||||
|
||||
MetricsConfig metrics();
|
||||
|
||||
@Hidden
|
||||
@DefaultBoolean
|
||||
boolean debug();
|
||||
|
||||
@Exclude Key key();
|
||||
|
||||
void key(Key key);
|
||||
|
||||
@Exclude String rawUsernamePrefix();
|
||||
|
||||
void rawUsernamePrefix(String usernamePrefix);
|
||||
|
||||
@ConfigSection
|
||||
interface DisconnectMessages {
|
||||
@DefaultString("Please connect through the official Geyser")
|
||||
String invalidKey();
|
||||
|
||||
@DefaultString("Expected {} arguments, got {}. Is Geyser up-to-date?")
|
||||
String invalidArgumentsLength();
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static class PlayerLinkConfig {
|
||||
private boolean enabled;
|
||||
private boolean requireLink;
|
||||
private boolean enableOwnLinking;
|
||||
private boolean allowed;
|
||||
private long linkCodeTimeout;
|
||||
private String type;
|
||||
private boolean enableGlobalLinking;
|
||||
@ConfigSection
|
||||
interface PlayerLinkConfig {
|
||||
@Comment
|
||||
@DefaultBoolean(true)
|
||||
boolean enabled();
|
||||
|
||||
@Comment
|
||||
@DefaultBoolean
|
||||
boolean requireLink();
|
||||
|
||||
@Comment
|
||||
@DefaultBoolean
|
||||
boolean enableOwnLinking();
|
||||
|
||||
@Comment
|
||||
@DefaultBoolean(true)
|
||||
boolean allowed();
|
||||
|
||||
@Comment
|
||||
@DefaultNumeric(300)
|
||||
long linkCodeTimeout();
|
||||
|
||||
@Comment
|
||||
@DefaultString("mysql")
|
||||
String type();
|
||||
|
||||
@Comment
|
||||
@DefaultBoolean(true)
|
||||
boolean enableGlobalLinking();
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static class MetricsConfig {
|
||||
private boolean enabled;
|
||||
private String uuid;
|
||||
@ConfigSection
|
||||
interface MetricsConfig {
|
||||
@DefaultBoolean(true)
|
||||
boolean enabled();
|
||||
|
||||
@Placeholder
|
||||
String uuid();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,12 +25,15 @@
|
||||
|
||||
package org.geysermc.floodgate.core.config;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.geysermc.configutils.node.meta.ConfigVersion;
|
||||
import org.geysermc.configutils.node.meta.Defaults.DefaultBoolean;
|
||||
import org.geysermc.configutils.node.meta.Inherit;
|
||||
|
||||
/**
|
||||
* The Floodgate configuration used by proxy platforms, currently Velocity and Bungeecord.
|
||||
*/
|
||||
@Getter
|
||||
public final class ProxyFloodgateConfig extends FloodgateConfig {
|
||||
private boolean sendFloodgateData;
|
||||
@Inherit(ConfigVersion.class)
|
||||
public interface ProxyFloodgateConfig extends FloodgateConfig {
|
||||
@DefaultBoolean
|
||||
boolean sendFloodgateData();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import io.micronaut.context.ApplicationContext;
|
||||
import io.micronaut.core.annotation.AnnotationMetadata;
|
||||
import io.micronaut.inject.qualifiers.Qualifiers;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.inject.Inject;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -45,13 +46,21 @@ import org.geysermc.floodgate.core.util.EagerSingleton;
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class EventBus extends EventBusImpl<Object, FloodgateSubscriber<?>>
|
||||
implements FloodgateEventBus {
|
||||
@Inject ApplicationContext context;
|
||||
|
||||
// @Inject
|
||||
// Set<@Listener Object> detectedListeners;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public boolean fire(@NonNull Object event) {
|
||||
context.getEventPublisher((Class) event.getClass()).publishEvent(event);
|
||||
// todo differentiate internal events from public events
|
||||
return super.fire(event);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
void registerListeners(ApplicationContext context) {
|
||||
// https://github.com/micronaut-projects/micronaut-core/issues/8881
|
||||
// todo this doesn't really seem to work?
|
||||
context.getBeansOfType(
|
||||
Object.class,
|
||||
Qualifiers.byAnnotation(AnnotationMetadata.EMPTY_METADATA, Listener.class)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Floodgate
|
||||
*/
|
||||
|
||||
package org.geysermc.floodgate.core.event.lifecycle;
|
||||
|
||||
import org.geysermc.floodgate.core.config.FloodgateConfig;
|
||||
|
||||
public record ConfigLoadedEvent(FloodgateConfig config) {
|
||||
}
|
||||
@@ -66,10 +66,10 @@ public abstract class CommonPlayerLink implements PlayerLink {
|
||||
|
||||
@Inject
|
||||
void init(FloodgateConfig config) {
|
||||
FloodgateConfig.PlayerLinkConfig linkConfig = config.getPlayerLink();
|
||||
enabled = linkConfig.isEnabled();
|
||||
allowLinking = linkConfig.isAllowed();
|
||||
verifyLinkTimeout = linkConfig.getLinkCodeTimeout();
|
||||
FloodgateConfig.PlayerLinkConfig linkConfig = config.playerLink();
|
||||
enabled = linkConfig.enabled();
|
||||
allowLinking = linkConfig.allowed();
|
||||
verifyLinkTimeout = linkConfig.linkCodeTimeout();
|
||||
}
|
||||
|
||||
public String createCode() {
|
||||
|
||||
@@ -84,8 +84,8 @@ public final class PlayerLinkHolder {
|
||||
throw new IllegalStateException("Config cannot be null!");
|
||||
}
|
||||
|
||||
PlayerLinkConfig linkConfig = config.getPlayerLink();
|
||||
if (!linkConfig.isEnabled()) {
|
||||
PlayerLinkConfig linkConfig = config.playerLink();
|
||||
if (!linkConfig.enabled()) {
|
||||
return new DisabledPlayerLink();
|
||||
}
|
||||
|
||||
@@ -101,8 +101,8 @@ public final class PlayerLinkHolder {
|
||||
|
||||
// we can skip the rest if global linking is enabled and no database implementations has
|
||||
// been found, or when global linking is enabled and own player linking is disabled.
|
||||
if (linkConfig.isEnableGlobalLinking() &&
|
||||
(files.isEmpty() || !linkConfig.isEnableOwnLinking())) {
|
||||
if (linkConfig.enableGlobalLinking() &&
|
||||
(files.isEmpty() || !linkConfig.enableOwnLinking())) {
|
||||
return currentContext.getBean(GlobalPlayerLinking.class);
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ public final class PlayerLinkHolder {
|
||||
// We only want to load one database implementation
|
||||
if (files.size() > 1) {
|
||||
boolean found = false;
|
||||
databaseName = linkConfig.getType();
|
||||
databaseName = linkConfig.type();
|
||||
|
||||
String expectedName = "floodgate-" + databaseName + "-database.jar";
|
||||
for (Path path : files) {
|
||||
@@ -129,7 +129,7 @@ public final class PlayerLinkHolder {
|
||||
|
||||
if (!found) {
|
||||
logger.error(
|
||||
"Failed to find an implementation for type: {}", linkConfig.getType()
|
||||
"Failed to find an implementation for type: {}", linkConfig.type()
|
||||
);
|
||||
return new DisabledPlayerLink();
|
||||
}
|
||||
@@ -195,7 +195,7 @@ public final class PlayerLinkHolder {
|
||||
instance = childContext.getBean(mainClass);
|
||||
|
||||
// we use our own internal PlayerLinking when global linking is enabled
|
||||
if (linkConfig.isEnableGlobalLinking()) {
|
||||
if (linkConfig.enableGlobalLinking()) {
|
||||
GlobalPlayerLinking linking = childContext.getBean(GlobalPlayerLinking.class);
|
||||
linking.setDatabaseImpl(instance);
|
||||
linking.load();
|
||||
|
||||
@@ -48,7 +48,7 @@ public final class JavaUtilFloodgateLogger implements FloodgateLogger {
|
||||
@Inject
|
||||
public void init(LanguageManager languageManager, FloodgateConfig config) {
|
||||
this.languageManager = languageManager;
|
||||
if (config.isDebug()) {
|
||||
if (config.debug()) {
|
||||
logger.setLevel(Level.ALL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public final class FloodgateHandshakeHandler {
|
||||
);
|
||||
} catch (Exception e) {
|
||||
// all the other exceptions are caused by invalid/tempered Floodgate data
|
||||
if (config.isDebug()) {
|
||||
if (config.debug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ public final class FloodgateHandshakeHandler {
|
||||
channel, true, bedrockData.clone(), config,
|
||||
linkedPlayer != null ? linkedPlayer.clone() : null, hostname);
|
||||
|
||||
if (config.getPlayerLink().isRequireLink() && linkedPlayer == null) {
|
||||
if (config.playerLink().requireLink() && linkedPlayer == null) {
|
||||
String reason = languageManager.getString(
|
||||
"floodgate.core.not_linked",
|
||||
bedrockData.getLanguageCode(),
|
||||
|
||||
@@ -98,7 +98,7 @@ public class FormChannel implements PluginMessageChannel {
|
||||
|
||||
public byte[] createFormData(Form form) {
|
||||
short formId = getNextFormId();
|
||||
if (config.isProxy()) {
|
||||
if (config.proxy()) {
|
||||
formId |= 0x8000;
|
||||
}
|
||||
storedForms.put(formId, form);
|
||||
|
||||
@@ -59,7 +59,7 @@ public class SkinChannel implements PluginMessageChannel {
|
||||
Result result = handleServerCall(data, sourceUuid, sourceUsername);
|
||||
// aka translate 'handled' into 'forward' when send-floodgate-data is enabled
|
||||
if (!result.isAllowed() && result.getReason() == null) {
|
||||
if (config.isProxy() && ((ProxyFloodgateConfig) config).isSendFloodgateData()) {
|
||||
if (config.proxy() && ((ProxyFloodgateConfig) config).sendFloodgateData()) {
|
||||
return Result.forward();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,13 +26,15 @@
|
||||
package org.geysermc.floodgate.core.scope;
|
||||
|
||||
import io.micronaut.context.annotation.Requires;
|
||||
import jakarta.inject.Named;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE_USE})
|
||||
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD})
|
||||
@Requires(property = "platform.proxy", value = "true")
|
||||
@Named
|
||||
public @interface ProxyOnly {
|
||||
}
|
||||
|
||||
@@ -26,13 +26,15 @@
|
||||
package org.geysermc.floodgate.core.scope;
|
||||
|
||||
import io.micronaut.context.annotation.Requires;
|
||||
import jakarta.inject.Named;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE_USE})
|
||||
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD})
|
||||
@Requires(property = "platform.proxy", value = "false")
|
||||
@Named
|
||||
public @interface ServerOnly {
|
||||
}
|
||||
|
||||
@@ -47,7 +47,6 @@ import org.geysermc.floodgate.core.config.FloodgateConfig;
|
||||
public final class LanguageManager {
|
||||
private final Map<String, Properties> localeMappings = new HashMap<>();
|
||||
|
||||
@Inject BeanProvider<FloodgateConfig> config;
|
||||
@Inject BeanProvider<FloodgateLogger> logger;
|
||||
|
||||
/**
|
||||
@@ -75,15 +74,17 @@ public final class LanguageManager {
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
FloodgateLogger logger = this.logger.get();
|
||||
|
||||
if (!loadLocale("en_US")) {// Fallback
|
||||
logger.error("Failed to load the fallback language. This will likely cause errors!");
|
||||
if (!loadLocale("en_US")) {
|
||||
logger.get().error("Failed to load the fallback language. This will likely cause errors!");
|
||||
}
|
||||
defaultLocale = "en_US";
|
||||
}
|
||||
|
||||
defaultLocale = formatLocale(config.get().getDefaultLocale());
|
||||
public void loadConfiguredDefaultLocale(FloodgateConfig config) {
|
||||
FloodgateLogger logger = this.logger.get();
|
||||
defaultLocale = formatLocale(config.defaultLocale());
|
||||
|
||||
if (isValidLanguage(defaultLocale)) {
|
||||
if (!"system".equals(defaultLocale) && isValidLanguage(defaultLocale)) {
|
||||
if (loadLocale(defaultLocale)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -57,13 +57,13 @@ public final class Metrics {
|
||||
@Named("implementationName") String implementationName,
|
||||
FloodgateLogger logger
|
||||
) {
|
||||
MetricsConfig metricsConfig = config.getMetrics();
|
||||
MetricsConfig metricsConfig = config.metrics();
|
||||
|
||||
metricsBase = new MetricsBase(
|
||||
"server-implementation",
|
||||
metricsConfig.getUuid(),
|
||||
metricsConfig.uuid(),
|
||||
Constants.METRICS_ID,
|
||||
metricsConfig.isEnabled(),
|
||||
metricsConfig.enabled(),
|
||||
this::appendPlatformData,
|
||||
jsonObjectBuilder -> { /* NOP */ },
|
||||
null,
|
||||
|
||||
@@ -25,22 +25,21 @@
|
||||
|
||||
package org.geysermc.floodgate.core.util;
|
||||
|
||||
import io.micronaut.runtime.event.annotation.EventListener;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.geysermc.event.Listener;
|
||||
import org.geysermc.event.subscribe.Subscribe;
|
||||
import org.geysermc.floodgate.api.logger.FloodgateLogger;
|
||||
import org.geysermc.floodgate.core.config.FloodgateConfig;
|
||||
import org.geysermc.floodgate.core.event.lifecycle.PostEnableEvent;
|
||||
|
||||
@Listener
|
||||
@Singleton
|
||||
@EagerSingleton
|
||||
public final class PostEnableMessages {
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
|
||||
@@ -64,7 +63,7 @@ public final class PostEnableMessages {
|
||||
|
||||
@PostConstruct
|
||||
void registerPrefixMessages() {
|
||||
String prefix = config.getRawUsernamePrefix();
|
||||
String prefix = config.rawUsernamePrefix();
|
||||
|
||||
if (prefix.isEmpty()) {
|
||||
add(new String[]{
|
||||
@@ -95,12 +94,12 @@ public final class PostEnableMessages {
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@EventListener
|
||||
public void onPostEnable(PostEnableEvent ignored) {
|
||||
// normally proxies don't have a lot of plugins, so proxies don't need to sleep as long
|
||||
executorService.schedule(
|
||||
() -> messages.forEach(logger::warn),
|
||||
config.isProxy() ? 2 : 5,
|
||||
config.proxy() ? 2 : 5,
|
||||
TimeUnit.SECONDS
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,11 +13,13 @@ relocate("cloud.commandframework")
|
||||
// used in cloud
|
||||
relocate("io.leangen.geantyref")
|
||||
|
||||
relocate("org.yaml.snakeyaml")
|
||||
|
||||
|
||||
// these dependencies are already present on the platform
|
||||
provided("com.google.code.gson", "gson", gsonVersion)
|
||||
provided("com.google.guava", "guava", guavaVersion)
|
||||
provided("com.google.inject", "guice", Versions.guiceVersion)
|
||||
provided("org.yaml", "snakeyaml", Versions.snakeyamlVersion) // included in Configurate
|
||||
//provided("org.yaml", "snakeyaml", Versions.snakeyamlVersion) // included in Configurate
|
||||
provided("com.velocitypowered", "velocity-api", Versions.velocityVersion)
|
||||
provided("org.apache.logging.log4j", "log4j-core", log4jVersion)
|
||||
|
||||
@@ -70,7 +70,7 @@ public final class VelocityDataAddon implements InjectorAddon {
|
||||
@Override
|
||||
public void onInject(Channel channel, boolean toServer) {
|
||||
if (toServer) {
|
||||
if (config.isSendFloodgateData()) {
|
||||
if (config.sendFloodgateData()) {
|
||||
channel.pipeline().addAfter(
|
||||
packetEncoder, "floodgate_data_handler",
|
||||
new VelocityServerDataHandler(api, proxy)
|
||||
|
||||
@@ -154,7 +154,7 @@ public final class VelocityListener {
|
||||
Collections.emptyList()
|
||||
);
|
||||
// The texture properties addition is to fix the February 2 2022 Mojang authentication changes
|
||||
if (!config.isSendFloodgateData() && !player.isLinked()) {
|
||||
if (!config.sendFloodgateData() && !player.isLinked()) {
|
||||
profile = profile.addProperty(new Property("textures", "", ""));
|
||||
}
|
||||
event.setGameProfile(profile);
|
||||
|
||||
@@ -28,12 +28,13 @@ package org.geysermc.floodgate.velocity.logger;
|
||||
import static org.geysermc.floodgate.core.util.MessageFormatter.format;
|
||||
|
||||
import io.micronaut.context.BeanProvider;
|
||||
import io.micronaut.runtime.event.annotation.EventListener;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import org.geysermc.floodgate.api.logger.FloodgateLogger;
|
||||
import org.geysermc.floodgate.core.config.FloodgateConfig;
|
||||
import org.geysermc.floodgate.core.event.lifecycle.ConfigLoadedEvent;
|
||||
import org.geysermc.floodgate.core.util.LanguageManager;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@@ -42,9 +43,9 @@ public final class Slf4jFloodgateLogger implements FloodgateLogger {
|
||||
@Inject BeanProvider<LanguageManager> languageManager;
|
||||
@Inject Logger logger;
|
||||
|
||||
@Inject
|
||||
void init(FloodgateConfig config) {
|
||||
if (config.isDebug() && !logger.isDebugEnabled()) {
|
||||
@EventListener
|
||||
void onConfigLoaded(ConfigLoadedEvent event) {
|
||||
if (event.config().debug() && !logger.isDebugEnabled()) {
|
||||
Configurator.setLevel(logger.getName(), Level.DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user