mirror of https://github.com/Minestom/Minestom.git
Implement config manager
This commit is contained in:
parent
87dda18a24
commit
61cd9d19d2
|
@ -0,0 +1,22 @@
|
|||
package net.minestom.server;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.utils.FinalObject;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Can be used to change Minestom defaults before {@link MinecraftServer#start} is called.
|
||||
*/
|
||||
public final class ConfigurationManager {
|
||||
public final FinalObject<Boolean> REQUIRE_VALID_PLAYER_PUBLIC_KEY = new FinalObject<>();
|
||||
public final FinalObject<Component> MISSING_PLAYER_PUBLIC_KEY = new FinalObject<>();
|
||||
public final FinalObject<Component> INVALID_PLAYER_PUBLIC_KEY = new FinalObject<>();
|
||||
|
||||
@ApiStatus.Internal
|
||||
public void initDefaults() {
|
||||
REQUIRE_VALID_PLAYER_PUBLIC_KEY.optionalSet(false);
|
||||
MISSING_PLAYER_PUBLIC_KEY.optionalSet(Component.text("Missing public key!", NamedTextColor.RED));
|
||||
INVALID_PLAYER_PUBLIC_KEY.optionalSet(Component.text("Invalid public key!", NamedTextColor.RED));
|
||||
}
|
||||
}
|
|
@ -191,6 +191,10 @@ public final class MinecraftServer {
|
|||
return serverProcess.chatRegistry();
|
||||
}
|
||||
|
||||
public static ConfigurationManager getConfigurationManager() {
|
||||
return serverProcess.configuration();
|
||||
}
|
||||
|
||||
public static PacketProcessor getPacketProcessor() {
|
||||
return serverProcess.packetProcessor();
|
||||
}
|
||||
|
|
|
@ -141,6 +141,8 @@ public interface ServerProcess extends Snapshotable {
|
|||
|
||||
@NotNull ChatRegistryManager chatRegistry();
|
||||
|
||||
@NotNull ConfigurationManager configuration();
|
||||
|
||||
void start(@NotNull SocketAddress socketAddress);
|
||||
|
||||
void stop();
|
||||
|
|
|
@ -70,6 +70,7 @@ final class ServerProcessImpl implements ServerProcess {
|
|||
private final ThreadDispatcher<Chunk> dispatcher;
|
||||
private final Ticker ticker;
|
||||
private final ChatRegistryManager chatRegistryManager;
|
||||
private final ConfigurationManager configurationManager;
|
||||
|
||||
private final AtomicBoolean started = new AtomicBoolean();
|
||||
private final AtomicBoolean stopped = new AtomicBoolean();
|
||||
|
@ -98,6 +99,7 @@ final class ServerProcessImpl implements ServerProcess {
|
|||
this.dispatcher = ThreadDispatcher.singleThread();
|
||||
this.ticker = new TickerImpl();
|
||||
this.chatRegistryManager = new ChatRegistryManager();
|
||||
this.configurationManager = new ConfigurationManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -210,12 +212,19 @@ final class ServerProcessImpl implements ServerProcess {
|
|||
return chatRegistryManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfigurationManager configuration() {
|
||||
return configurationManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(@NotNull SocketAddress socketAddress) {
|
||||
if (!started.compareAndSet(false, true)) {
|
||||
throw new IllegalStateException("Server already started");
|
||||
}
|
||||
|
||||
configurationManager.initDefaults();
|
||||
|
||||
extension.start();
|
||||
extension.gotoPreInit();
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ package net.minestom.server.network.packet.client.login;
|
|||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.ConfigurationManager;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.crypto.PlayerPublicKey;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.extras.MojangAuth;
|
||||
|
@ -33,12 +35,16 @@ public record LoginStartPacket(@NotNull String username, @Nullable PlayerPublicK
|
|||
@Override
|
||||
public void process(@NotNull PlayerConnection connection) {
|
||||
connection.setPlayerPublicKey(publicKey);
|
||||
final ConfigurationManager config = MinecraftServer.getConfigurationManager();
|
||||
|
||||
//TODO Verification toggling
|
||||
if (publicKey != null) {
|
||||
if (!publicKey.isValid()) {
|
||||
// TODO Configurable message
|
||||
connection.sendPacket(new LoginDisconnectPacket(Component.text("Invalid signature", NamedTextColor.RED)));
|
||||
if (config.REQUIRE_VALID_PLAYER_PUBLIC_KEY.get()) {
|
||||
if (publicKey != null) {
|
||||
if (!publicKey.isValid()) {
|
||||
connection.sendPacket(new LoginDisconnectPacket(config.INVALID_PLAYER_PUBLIC_KEY.get()));
|
||||
connection.disconnect();
|
||||
}
|
||||
} else {
|
||||
connection.sendPacket(new LoginDisconnectPacket(config.MISSING_PLAYER_PUBLIC_KEY.get()));
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package net.minestom.server.utils;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
|
@ -9,7 +7,6 @@ import java.util.function.Supplier;
|
|||
*
|
||||
* @param <T> type of the object
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public final class FinalObject<T> {
|
||||
private T obj;
|
||||
private boolean finalized;
|
||||
|
|
Loading…
Reference in New Issue