3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

Re-introduce asterisk behavior in configs

Dieser Commit ist enthalten in:
Camotoy 2024-09-12 21:00:30 -04:00
Ursprung e99759d701
Commit 5551169c4c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
5 geänderte Dateien mit 72 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -31,6 +31,7 @@ import org.geysermc.geyser.api.network.AuthType;
import org.geysermc.geyser.api.network.BedrockListener; import org.geysermc.geyser.api.network.BedrockListener;
import org.geysermc.geyser.api.network.RemoteServer; import org.geysermc.geyser.api.network.RemoteServer;
import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.network.GameProtocol;
import org.geysermc.geyser.text.AsteriskSerializer;
import org.geysermc.geyser.util.CooldownUtils; import org.geysermc.geyser.util.CooldownUtils;
import org.spongepowered.configurate.interfaces.meta.Exclude; import org.spongepowered.configurate.interfaces.meta.Exclude;
import org.spongepowered.configurate.interfaces.meta.Field; import org.spongepowered.configurate.interfaces.meta.Field;
@ -200,6 +201,7 @@ public interface GeyserConfig {
Generally, you should only uncomment and change this if you want to limit what IPs can connect to your server.""") Generally, you should only uncomment and change this if you want to limit what IPs can connect to your server.""")
@NonNull @NonNull
@DefaultString("0.0.0.0") @DefaultString("0.0.0.0")
@AsteriskSerializer.Asterisk
String address(); String address();
@Override @Override

Datei anzeigen

@ -25,6 +25,7 @@
package org.geysermc.geyser.configuration; package org.geysermc.geyser.configuration;
import org.geysermc.geyser.text.AsteriskSerializer;
import org.spongepowered.configurate.interfaces.meta.defaults.DefaultNumeric; import org.spongepowered.configurate.interfaces.meta.defaults.DefaultNumeric;
import org.spongepowered.configurate.interfaces.meta.defaults.DefaultString; import org.spongepowered.configurate.interfaces.meta.defaults.DefaultString;
import org.spongepowered.configurate.interfaces.meta.range.NumericRange; import org.spongepowered.configurate.interfaces.meta.range.NumericRange;
@ -44,6 +45,7 @@ public interface GeyserRemoteConfig extends GeyserConfig {
@Override @Override
@Comment("The IP address of the Java Edition server.") @Comment("The IP address of the Java Edition server.")
@DefaultString("127.0.0.1") @DefaultString("127.0.0.1")
@AsteriskSerializer.Asterisk
String address(); String address();
@Override @Override

Datei anzeigen

@ -40,13 +40,17 @@ import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.extension.Extension; import org.geysermc.geyser.api.extension.Extension;
import org.geysermc.geyser.configuration.AdvancedConfig; import org.geysermc.geyser.configuration.AdvancedConfig;
import org.geysermc.geyser.configuration.GeyserConfig;
import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.network.GameProtocol;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.AsteriskSerializer; import org.geysermc.geyser.text.AsteriskSerializer;
import org.geysermc.geyser.util.CpuUtils; import org.geysermc.geyser.util.CpuUtils;
import org.geysermc.geyser.util.FileUtils; import org.geysermc.geyser.util.FileUtils;
import org.geysermc.geyser.util.WebUtils; import org.geysermc.geyser.util.WebUtils;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.ConfigurationOptions;
import org.spongepowered.configurate.interfaces.InterfaceDefaultOptions;
import org.spongepowered.configurate.serialize.SerializationException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -73,8 +77,8 @@ public class DumpInfo {
private final Locale systemLocale; private final Locale systemLocale;
private final String systemEncoding; private final String systemEncoding;
private final GitInfo gitInfo; private final GitInfo gitInfo;
private final GeyserConfig config; private Object config;
private final AdvancedConfig advancedConfig; private Object advancedConfig;
private final Object2IntMap<DeviceOs> userPlatforms; private final Object2IntMap<DeviceOs> userPlatforms;
private final int connectionAttempts; private final int connectionAttempts;
private final HashInfo hashInfo; private final HashInfo hashInfo;
@ -94,8 +98,24 @@ public class DumpInfo {
this.gitInfo = new GitInfo(GeyserImpl.BUILD_NUMBER, GeyserImpl.COMMIT.substring(0, 7), GeyserImpl.COMMIT, GeyserImpl.BRANCH, GeyserImpl.REPOSITORY); this.gitInfo = new GitInfo(GeyserImpl.BUILD_NUMBER, GeyserImpl.COMMIT.substring(0, 7), GeyserImpl.COMMIT, GeyserImpl.BRANCH, GeyserImpl.REPOSITORY);
this.config = geyser.config(); try {
this.advancedConfig = geyser.config().advanced(); // Workaround for JsonAdapter not being allowed on methods
ConfigurationOptions options = InterfaceDefaultOptions.addTo(ConfigurationOptions.defaults(), builder ->
builder.addProcessor(AsteriskSerializer.Asterisk.class, String.class, AsteriskSerializer.CONFIGURATE_SERIALIZER))
.shouldCopyDefaults(false);
ConfigurationNode configNode = CommentedConfigurationNode.root(options);
configNode.set(geyser.config());
this.config = configNode.get(geyser.config().getClass());
ConfigurationNode advancedConfigNode = CommentedConfigurationNode.root(options);
advancedConfigNode.set(geyser.config().advanced());
this.advancedConfig = advancedConfigNode.get(AdvancedConfig.class);
} catch (SerializationException e) {
if (geyser.config().debugMode()) {
e.printStackTrace();
}
}
String md5Hash = "unknown"; String md5Hash = "unknown";
String sha256Hash = "unknown"; String sha256Hash = "unknown";
@ -110,7 +130,7 @@ public class DumpInfo {
//noinspection UnstableApiUsage //noinspection UnstableApiUsage
sha256Hash = byteSource.hash(Hashing.sha256()).toString(); sha256Hash = byteSource.hash(Hashing.sha256()).toString();
} catch (Exception e) { } catch (Exception e) {
if (this.config.debugMode()) { if (geyser.config().debugMode()) {
e.printStackTrace(); e.printStackTrace();
} }
} }

Datei anzeigen

@ -25,9 +25,16 @@
package org.geysermc.geyser.ping; package org.geysermc.geyser.ping;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.annotations.JsonAdapter;
import lombok.Data; import lombok.Data;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import java.lang.reflect.Type;
/** /**
* The structure of this class and its nested classes are specifically * The structure of this class and its nested classes are specifically
* designed for the format received by {@link GeyserLegacyPingPassthrough}. * designed for the format received by {@link GeyserLegacyPingPassthrough}.
@ -36,6 +43,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class GeyserPingInfo { public class GeyserPingInfo {
@Nullable @Nullable
@JsonAdapter(DescriptionDeserializer.class)
private String description; private String description;
private Players players; private Players players;
@ -69,4 +77,14 @@ public class GeyserPingInfo {
this.online = online; this.online = online;
} }
} }
/**
* So GSON does not complain how we are treating Description - it will be converted to a proper Component later.
*/
private static final class DescriptionDeserializer implements JsonDeserializer<String> {
@Override
public String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return json.toString();
}
}
} }

Datei anzeigen

@ -29,7 +29,13 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer; import com.google.gson.JsonSerializer;
import org.spongepowered.configurate.objectmapping.meta.Processor;
import org.spongepowered.configurate.serialize.SerializationException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.net.InetAddress; import java.net.InetAddress;
@ -47,7 +53,7 @@ public class AsteriskSerializer implements JsonSerializer<String> {
return new JsonPrimitive("***"); return new JsonPrimitive("***");
} }
private boolean isSensitiveIp(String ip) { private static boolean isSensitiveIp(String ip) {
for (String address : NON_SENSITIVE_ADDRESSES) { for (String address : NON_SENSITIVE_ADDRESSES) {
if (address.equalsIgnoreCase(ip)) { if (address.equalsIgnoreCase(ip)) {
return false; return false;
@ -65,4 +71,21 @@ public class AsteriskSerializer implements JsonSerializer<String> {
return true; return true;
} }
public static Processor.Factory<Asterisk, String> CONFIGURATE_SERIALIZER = (data, fieldType) -> (value, destination) -> {
if (showSensitive || !isSensitiveIp(value)) {
return;
}
try {
destination.set("***");
} catch (SerializationException e) {
throw new RuntimeException(e); // Error over silently printing an IP address.
}
};
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Asterisk {
}
} }