Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
import java.util.function.BiConsumer;

public class LoginEncryptionUtils {
private static final ObjectMapper JSON_MAPPER = new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
private static final ObjectMapper JSON_MAPPER = new ObjectMapper()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

private static boolean HAS_SENT_ENCRYPTION_MESSAGE = false;

Expand Down Expand Up @@ -131,7 +132,8 @@ private static void startEncryptionHandshake(GeyserSession session, PublicKey ke
private static void sendEncryptionFailedMessage(GeyserImpl geyser) {
if (!HAS_SENT_ENCRYPTION_MESSAGE) {
geyser.getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.network.encryption.line_1"));
geyser.getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.network.encryption.line_2", "https://geysermc.org/supported_java"));
geyser.getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.network.encryption.line_2",
"https://geysermc.org/supported_java"));
HAS_SENT_ENCRYPTION_MESSAGE = true;
}
}
Expand All @@ -154,11 +156,10 @@ public static void buildAndShowLoginWindow(GeyserSession session) {
.title("geyser.auth.login.form.notice.title")
.content("geyser.auth.login.form.notice.desc")
.optionalButton("geyser.auth.login.form.notice.btn_login.mojang", isPasswordAuthEnabled)
.button("geyser.auth.login.form.notice.btn_login.microsoft")
.button("geyser.auth.login.form.notice.btn_disconnect")
.closedOrInvalidResultHandler(() -> buildAndShowLoginWindow(session))
.validResultHandler((response) -> {
if (response.clickedButtonId() == 0){
if (response.clickedButtonId() == 0) {
buildAndShowLoginDetailsWindow(session);
return;
}
Expand All @@ -168,14 +169,14 @@ public static void buildAndShowLoginWindow(GeyserSession session) {
return;
}



session.disconnect(GeyserLocale.getPlayerLocaleString("geyser.auth.login.form.disconnect", session.locale()));
session.disconnect(GeyserLocale.getPlayerLocaleString("geyser.auth.login.form.disconnect",
session.locale()));
}));
}

/**
* Build a window that explains the user's credentials will be saved to the system.
* Build a window that explains the user's credentials will be saved to the
* system.
*/
public static void buildAndShowConsentWindow(GeyserSession session) {
String locale = session.locale();
Expand All @@ -190,8 +191,7 @@ public static void buildAndShowConsentWindow(GeyserSession session) {
geyser.auth.login.save_token.proceed""")
.button("%gui.ok")
.button("%gui.decline")
.resultHandler(authenticateOrKickHandler(session))
);
.resultHandler(authenticateOrKickHandler(session)));
}

public static void buildAndShowTokenExpiredWindow(GeyserSession session) {
Expand All @@ -206,11 +206,11 @@ public static void buildAndShowTokenExpiredWindow(GeyserSession session) {

geyser.auth.login.save_token.proceed""")
.button("%gui.ok")
.resultHandler(authenticateOrKickHandler(session))
);
.resultHandler(authenticateOrKickHandler(session)));
}

private static BiConsumer<SimpleForm, FormResponseResult<SimpleFormResponse>> authenticateOrKickHandler(GeyserSession session) {
private static BiConsumer<SimpleForm, FormResponseResult<SimpleFormResponse>> authenticateOrKickHandler(
GeyserSession session) {
return (form, genericResult) -> {
if (genericResult instanceof ValidFormResponseResult<SimpleFormResponse> result &&
result.response().clickedButtonId() == 0) {
Expand All @@ -220,14 +220,15 @@ private static BiConsumer<SimpleForm, FormResponseResult<SimpleFormResponse>> au
}
};
}

public static void buildAndShowLoginDetailsWindow(GeyserSession session) {
session.sendForm(
CustomForm.builder()
.translator(GeyserLocale::getPlayerLocaleString, session.locale())
.title("geyser.auth.login.form.details.title")
.label("geyser.auth.login.form.details.desc")
.input("geyser.auth.login.form.details.email", "account@qq.com", "")
.input("geyser.auth.login.form.details.pass", "123456", "")
.input("geyser.auth.login.form.details.email", "abab@warma.fans", "")
.input("geyser.auth.login.form.details.pass", "114514", "")
.invalidResultHandler(() -> buildAndShowLoginDetailsWindow(session))
.closedResultHandler(() -> buildAndShowLoginWindow(session))
.validResultHandler((response) -> session.authenticate(response.next(), response.next())));
Expand All @@ -250,7 +251,8 @@ public static void buildAndShowMicrosoftCodeWindow(GeyserSession session, StepMs
if (timeout != 0) {
message.append("\n\n")
.append(ChatColor.RESET)
.append(GeyserLocale.getPlayerLocaleString("geyser.auth.login.timeout", session.locale(), String.valueOf(timeout)));
.append(GeyserLocale.getPlayerLocaleString("geyser.auth.login.timeout", session.locale(),
String.valueOf(timeout)));
}

session.sendForm(
Expand All @@ -262,14 +264,15 @@ public static void buildAndShowMicrosoftCodeWindow(GeyserSession session, StepMs
.closedOrInvalidResultHandler(() -> buildAndShowLoginWindow(session))
.validResultHandler((response) -> {
if (response.clickedButtonId() == 1) {
session.disconnect(GeyserLocale.getPlayerLocaleString("geyser.auth.login.form.disconnect", locale));
session.disconnect(GeyserLocale
.getPlayerLocaleString("geyser.auth.login.form.disconnect", locale));
}
})
);
}));
}

/*
This checks per line if there is something to be translated, and it skips Bedrock translation keys (%)
* This checks per line if there is something to be translated, and it skips
* Bedrock translation keys (%)
*/
private static String translate(String key, String locale) {
StringBuilder newValue = new StringBuilder();
Expand Down