Skip to content

Commit

Permalink
Merge branch '1.21.0' into 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Nov 11, 2024
2 parents a9c0f2e + 3a4e2ea commit 2abb4c9
Show file tree
Hide file tree
Showing 19 changed files with 188 additions and 65 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ dependencies {
implementation("org.jline:jline:3.27.1")
implementation("org.jline:jline-terminal-jni:3.27.1")
implementation("ar.com.hjg:pngj:2.1.0")
implementation("com.zaxxer:HikariCP:6.0.0")
implementation("com.zaxxer:HikariCP:6.1.0")
implementation("org.postgresql:postgresql:42.7.4")
// todo: 3.46.0 introduces JFR support
// but it causes a runtime exception in graalvm native image if we do not build with JFR support
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/zenith/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.zenith.network.server.ServerSession;
import com.zenith.network.server.handler.ProxyServerLoginHandler;
import com.zenith.util.ComponentSerializer;
import com.zenith.util.Config;
import com.zenith.util.FastArrayList;
import com.zenith.util.Wait;
import com.zenith.via.ZenithClientChannelInitializer;
Expand Down Expand Up @@ -73,6 +72,9 @@

import static com.github.rfresh2.EventConsumer.of;
import static com.zenith.Shared.*;
import static com.zenith.util.Config.Authentication.AccountType.MSA;
import static com.zenith.util.Config.Authentication.AccountType.OFFLINE;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;


Expand Down Expand Up @@ -484,7 +486,7 @@ public synchronized void stopServer() {
var uuid = minecraftProtocol.getProfile().getId();
CACHE.getChatCache().setPlayerCertificates(minecraftProtocol.getProfile().getPlayerCertificates());
AUTH_LOG.info("Logged in as {} [{}].", username, uuid);
if (CONFIG.server.extra.whitelist.autoAddClient)
if (CONFIG.server.extra.whitelist.autoAddClient && CONFIG.authentication.accountType != OFFLINE)
if (PLAYER_LISTS.getWhitelist().add(username, uuid))
SERVER_LOG.info("Auto added {} [{}] to whitelist", username, uuid);
EXECUTOR.execute(this::updateFavicon);
Expand Down Expand Up @@ -512,7 +514,7 @@ public Future<MinecraftProtocol> loginTask() {

public MinecraftProtocol retrieveLoginTaskResult(Future<MinecraftProtocol> loginTask) {
try {
var maxWait = CONFIG.authentication.accountType == Config.Authentication.AccountType.MSA ? 10 : 300;
var maxWait = CONFIG.authentication.accountType == MSA ? 10 : 300;
for (int currentWait = 0; currentWait < maxWait; currentWait++) {
if (loginTask.isDone()) break;
if (!loggingIn.get()) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/zenith/Shared.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class Shared {
public static final String MANUAL_DISCONNECT = "Manual Disconnect";
public static final String AUTO_DISCONNECT = "AutoDisconnect";
public static final String LOGIN_FAILED = "Login Failed";
public static final String AUTH_REQUIRED = "Cannot join online mode server with offline auth";
public static Config CONFIG;
public static LaunchConfig LAUNCH_CONFIG;
public static final DataCache CACHE;
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/com/zenith/cache/data/chat/ChatCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ public void reset(CacheResetType type) {
if (type == CacheResetType.PROTOCOL_SWITCH || type == CacheResetType.FULL) {
this.commandNodes = new CommandNode[0];
this.firstCommandNodeIndex = 0;
if (type == CacheResetType.FULL) {
this.lastChatTimestamp = System.currentTimeMillis();
}
this.enforcesSecureChat = false;
}
if (type == CacheResetType.FULL) {
chatTypeRegistry.reset();
this.enforcesSecureChat = false;
this.chatTypeRegistry.reset();
this.lastChatTimestamp = System.currentTimeMillis();
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/zenith/cache/data/chunk/ChunkCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public static void sync() {
chunk.lightUpdateData)
)
.forEach(currentPlayer::sendAsync);
CACHE_LOG.info("Syncing {} chunks to current player", chunks.size());
currentPlayer.sendAsync(new ClientboundChunkBatchFinishedPacket(chunks.size()));
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/zenith/command/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public class CommandManager {
new ThemeCommand(),
new TransferCommand(),
new UpdateCommand(),
new UnsupportedCommand(),
new ViaVersionCommand(),
new VisualRangeCommand(),
new WhitelistCommand()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zenith/command/CommandUsage.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public String serialize(CommandSource commandSource) {
+ usageLines.stream()
.map(line -> "\n" + COMMAND.getCommandPrefix(commandSource) + name + " " + line)
.collect(Collectors.joining());
result += "\n\n[Commands Help Wiki](https://t.ly/ue-sg)";
result += "\n\n[Commands Help Wiki](https://link.2b2t.vc/0)";
if (result.length() > 1024) {
DEFAULT_LOG.error("Command usage too long", new RuntimeException());
return this.shortSerialize(commandSource);
Expand Down
38 changes: 24 additions & 14 deletions src/main/java/com/zenith/command/impl/AuthCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public CommandUsage commandUsage() {
"mention on/off",
"openBrowser on/off",
"maxRefreshIntervalMins <minutes>",
"useClientConnectionProxy on/off"
"useClientConnectionProxy on/off",
"chatSigning on/off"
)
);
}
Expand Down Expand Up @@ -81,7 +82,7 @@ public LiteralArgumentBuilder<CommandContext> register() {
c.getSource().getEmbed()
.title("Always Refresh On Login " + toggleStrCaps(CONFIG.authentication.alwaysRefreshOnLogin))
.primaryColor();
return 1;
return OK;
})))
.then(literal("type").requires(this::validateDiscordOrTerminalSource)
.then(literal("deviceCode").executes(c -> {
Expand All @@ -91,7 +92,7 @@ public LiteralArgumentBuilder<CommandContext> register() {
.primaryColor();
Proxy.getInstance().cancelLogin();
Proxy.getInstance().getAuthenticator().clearAuthCache();
return 1;
return OK;
}))
.then(literal("emailAndPassword").executes(c -> {
CONFIG.authentication.accountType = Config.Authentication.AccountType.MSA;
Expand All @@ -100,7 +101,7 @@ public LiteralArgumentBuilder<CommandContext> register() {
.primaryColor();
Proxy.getInstance().cancelLogin();
Proxy.getInstance().getAuthenticator().clearAuthCache();
return 1;
return OK;
}))
.then(literal("deviceCode2").executes(c -> {
CONFIG.authentication.accountType = Config.Authentication.AccountType.DEVICE_CODE_WITHOUT_DEVICE_TOKEN;
Expand All @@ -109,7 +110,7 @@ public LiteralArgumentBuilder<CommandContext> register() {
.primaryColor();
Proxy.getInstance().cancelLogin();
Proxy.getInstance().getAuthenticator().clearAuthCache();
return 1;
return OK;
}))
.then(literal("prism").executes(c -> {
CONFIG.authentication.accountType = Config.Authentication.AccountType.PRISM;
Expand All @@ -118,7 +119,7 @@ public LiteralArgumentBuilder<CommandContext> register() {
.primaryColor();
Proxy.getInstance().cancelLogin();
Proxy.getInstance().getAuthenticator().clearAuthCache();
return 1;
return OK;
})))
.then(literal("email").requires(this::validateTerminalSource)
.then(argument("email", wordWithChars()).executes(c -> {
Expand All @@ -129,13 +130,13 @@ public LiteralArgumentBuilder<CommandContext> register() {
c.getSource().getEmbed()
.title("Invalid Email")
.errorColor();
return 1;
return OK;
}
CONFIG.authentication.email = emailStr;
c.getSource().getEmbed()
.title("Authentication Email Set")
.primaryColor();
return 1;
return OK;
})))
.then(literal("password").requires(this::validateTerminalSource)
.then(argument("password", wordWithChars()).executes(c -> {
Expand All @@ -146,28 +147,28 @@ public LiteralArgumentBuilder<CommandContext> register() {
c.getSource().getEmbed()
.title("Invalid Password")
.errorColor();
return 1;
return OK;
}
CONFIG.authentication.password = passwordStr;
c.getSource().getEmbed()
.title("Authentication Password Set")
.primaryColor();
return 1;
return OK;
})))
.then(literal("mention")
.then(argument("toggle", toggle()).executes(c -> {
CONFIG.discord.mentionRoleOnDeviceCodeAuth = getToggle(c, "toggle");
c.getSource().getEmbed()
.title("Mention Role " + toggleStrCaps(CONFIG.discord.mentionRoleOnDeviceCodeAuth))
.primaryColor();
return 1;
return OK;
})))
.then(literal("openBrowser").then(argument("toggle", toggle()).executes(c -> {
CONFIG.authentication.openBrowserOnLogin = getToggle(c, "toggle");
c.getSource().getEmbed()
.title("Open Browser On Login " + toggleStrCaps(CONFIG.authentication.openBrowserOnLogin))
.primaryColor();
return 1;
return OK;
})))
.then(literal("maxRefreshInterval").then(argument("minutes", integer(5, 500)).executes(c -> {
CONFIG.authentication.maxRefreshIntervalMins = c.getArgument("minutes", Integer.class);
Expand All @@ -181,7 +182,14 @@ public LiteralArgumentBuilder<CommandContext> register() {
c.getSource().getEmbed()
.title("Use Client Connection Proxy " + toggleStrCaps(CONFIG.authentication.useClientConnectionProxy))
.primaryColor();
return 1;
return OK;
})))
.then(literal("chatSigning").then(argument("toggle", toggle()).executes(c -> {
CONFIG.client.chatSigning.enabled = getToggle(c, "toggle");
c.getSource().getEmbed()
.title("Chat Signing " + toggleStrCaps(CONFIG.client.chatSigning.enabled))
.primaryColor();
return OK;
})));
}

Expand All @@ -202,7 +210,8 @@ public void postPopulate(final Embed builder) {
.addField("Mention", toggleStr(CONFIG.discord.mentionRoleOnDeviceCodeAuth), false)
.addField("Open Browser", toggleStr(CONFIG.authentication.openBrowserOnLogin), false)
.addField("Max Refresh Interval", CONFIG.authentication.maxRefreshIntervalMins + " minutes", false)
.addField("Use Client Connection Proxy", toggleStr(CONFIG.authentication.useClientConnectionProxy), false);
.addField("Use Client Connection Proxy", toggleStr(CONFIG.authentication.useClientConnectionProxy), false)
.addField("Chat Signing", toggleStr(CONFIG.client.chatSigning.enabled), false);
}

private String authTypeToString(Config.Authentication.AccountType type) {
Expand All @@ -211,6 +220,7 @@ private String authTypeToString(Config.Authentication.AccountType type) {
case MSA -> "emailAndPassword";
case DEVICE_CODE_WITHOUT_DEVICE_TOKEN -> "deviceCode2";
case PRISM -> "prism";
case OFFLINE -> "offline";
};
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/zenith/command/impl/KillAuraCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CommandUsage commandUsage() {
"""
Attacks entities near the player.
Custom targets list: https://t.ly/RLreZ
Custom targets list: https://link.2b2t.vc/1
""",
asList("on/off",
"attackDelay <ticks>",
Expand Down
88 changes: 88 additions & 0 deletions src/main/java/com/zenith/command/impl/UnsupportedCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.zenith.command.impl;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.zenith.Proxy;
import com.zenith.command.Command;
import com.zenith.command.CommandUsage;
import com.zenith.command.brigadier.CommandCategory;
import com.zenith.command.brigadier.CommandContext;
import com.zenith.command.brigadier.CommandSource;
import com.zenith.discord.Embed;

import static com.zenith.Shared.CONFIG;
import static com.zenith.command.brigadier.CustomStringArgumentType.getString;
import static com.zenith.command.brigadier.CustomStringArgumentType.wordWithChars;
import static com.zenith.command.brigadier.ToggleArgumentType.getToggle;
import static com.zenith.command.brigadier.ToggleArgumentType.toggle;
import static com.zenith.discord.DiscordBot.escape;
import static com.zenith.util.Config.Authentication.AccountType.OFFLINE;
import static java.util.Arrays.asList;

public class UnsupportedCommand extends Command {
@Override
public CommandUsage commandUsage() {
return CommandUsage.args(
"unsupported",
CommandCategory.MANAGE,
"""
Unsupported settings that cause critical security issues.
Do not use edit these unless you absolutely understand what you are doing.
No user support will be provided if you modify any of these settings.
All subcommands are only usable from the terminal.
""",
asList(
"whitelist on/off",
"verifyUsers on/off",
"auth type offline",
"auth offlineUsername <username>"
)
);
}

@Override
public LiteralArgumentBuilder<CommandContext> register() {
return command("unsupported")
.requires(c -> Command.validateCommandSource(c, CommandSource.TERMINAL))
.then(literal("whitelist").then(argument("toggle", toggle()).executes(c -> {
CONFIG.server.extra.whitelist.enable = getToggle(c, "toggle");
c.getSource().getEmbed()
.title("Whitelist " + toggleStrCaps(CONFIG.server.extra.whitelist.enable));
return OK;
})))
.then(literal("verifyUsers").then(argument("toggle", toggle()).executes(c -> {
CONFIG.server.verifyUsers = getToggle(c, "toggle");
c.getSource().getEmbed()
.title("Verify Users " + toggleStrCaps(CONFIG.server.verifyUsers));
return OK;
})))
.then(literal("auth")
.then(literal("type").then(literal("offline").executes(c -> {
CONFIG.authentication.accountType = OFFLINE;
c.getSource().getEmbed()
.title("Authentication Type Set");
Proxy.getInstance().cancelLogin();
Proxy.getInstance().getAuthenticator().clearAuthCache();
})))
.then(literal("offlineUsername").then(argument("username", wordWithChars()).executes(c -> {
CONFIG.authentication.username = getString(c, "username");
c.getSource().getEmbed()
.title("Offline Username Set");
Proxy.getInstance().cancelLogin();
Proxy.getInstance().getAuthenticator().clearAuthCache();
return OK;
}))));
}

@Override
public void postPopulate(Embed builder) {
builder
.addField("Whitelist", toggleStr(CONFIG.server.extra.whitelist.enable), false)
.addField("Verify Users", toggleStr(CONFIG.server.verifyUsers), false)
.addField("Offline Authentication", toggleStr(CONFIG.authentication.accountType == OFFLINE), false)
.addField("Offline Username", escape(CONFIG.authentication.username), false)
.primaryColor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Optional<DeathMessageParseResult> parse(final Component component, final
final Optional<DeathMessageParseResult> parse = instance.parse(inputSplit, playerNames);
if (parse.isPresent()) return parse;
}
if (CONFIG.database.deathsEnabled && CONFIG.database.unknownDeathDiscordMsg && DISCORD.isRunning()) {
if (CONFIG.database.enabled && CONFIG.database.deathsEnabled && CONFIG.database.unknownDeathDiscordMsg && DISCORD.isRunning()) {
DISCORD.sendEmbedMessage(Embed.builder()
.title("Unknown death message")
.description(ComponentSerializer.serializeJson(component))
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/zenith/module/impl/AutoReconnect.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ private boolean isReconnectableDisconnect(final String reason) {
|| reason.equals(MANUAL_DISCONNECT)
|| reason.equals(MinecraftConstants.SERVER_CLOSING_MESSAGE)
|| reason.equals(LOGIN_FAILED)
|| reason.equals(AUTH_REQUIRED)
) {
return false;
} else if (reason.equals(AUTO_DISCONNECT)) {
Expand Down
Loading

0 comments on commit 2abb4c9

Please sign in to comment.