implement username dialog for offline login

This commit is contained in:
Hakan Candar 2024-04-01 21:21:47 +03:00
parent c9ca4c82f7
commit e287539634
3 changed files with 29 additions and 2 deletions

View File

@ -216,9 +216,10 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
public PacketSignal handle(ResourcePackClientResponsePacket packet) {
switch (packet.getStatus()) {
case COMPLETED:
if (geyser.getConfig().getRemote().authType() != AuthType.ONLINE) {
AuthType authType = geyser.getConfig().getRemote().authType();
if (authType == AuthType.FLOODGATE) {
session.authenticate(session.getAuthData().name());
} else if (!couldLoginUserByName(session.getAuthData().name())) {
} else if (!couldLoginUserByName(session.getAuthData().name()) || authType == AuthType.OFFLINE) {
// We must spawn the white world
session.connect();
}

View File

@ -59,6 +59,11 @@ public class BedrockSetLocalPlayerAsInitializedTranslator extends PacketTranslat
}
// else we were able to log the user in
}
if (session.remoteServer().authType() == AuthType.OFFLINE) {
LoginEncryptionUtils.buildAndShowOfflineLoginWindow(session);
}
if (session.isLoggedIn()) {
// Sigh - as of Bedrock 1.18
session.getEntityCache().updateBossBars();

View File

@ -34,6 +34,7 @@ import org.cloudburstmc.protocol.bedrock.packet.ServerToClientHandshakePacket;
import org.cloudburstmc.protocol.bedrock.util.ChainValidationResult;
import org.cloudburstmc.protocol.bedrock.util.ChainValidationResult.IdentityData;
import org.cloudburstmc.protocol.bedrock.util.EncryptionUtils;
import org.geysermc.cumulus.form.CustomForm;
import org.geysermc.cumulus.form.ModalForm;
import org.geysermc.cumulus.form.SimpleForm;
import org.geysermc.cumulus.response.SimpleFormResponse;
@ -153,6 +154,26 @@ public class LoginEncryptionUtils {
}));
}
public static void buildAndShowOfflineLoginWindow(GeyserSession session) {
if (session.isLoggedIn()) {
// Can happen if a window is1 cancelled during dimension switch
return;
}
// Set DoDaylightCycle to false so the time doesn't accelerate while we're here
session.setDaylightCycle(false);
session.sendForm(
CustomForm.builder()
.translator(GeyserLocale::getPlayerLocaleString, session.locale())
.title("geyser.auth.login.form.details.title")
.input("geyser.auth.login.form.details.email", "", session.bedrockUsername())
.closedOrInvalidResultHandler(() -> buildAndShowOfflineLoginWindow(session))
.validResultHandler((response) -> {
session.authenticate(response.asInput(0));
}));
}
/**
* Build a window that explains the user's credentials will be saved to the system.
*/