support auto-login of configured users

- fall back to window/form prompt if user is not configured
This commit is contained in:
Blue Kelp 2019-08-02 13:15:32 -07:00
parent 168778026a
commit f62aa390d2
6 changed files with 72 additions and 4 deletions

View file

@ -116,7 +116,7 @@ public class GeyserConnector implements Connector {
config = FileUtils.loadConfig(configFile, GeyserConfiguration.class);
} catch (IOException ex) {
logger.severe("Failed to create config.yml! Make sure it's up to date and writable!");
logger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!");
shutdown();
}

View file

@ -28,12 +28,16 @@ package org.geysermc.connector.configuration;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import java.util.Map;
@Getter
public class GeyserConfiguration {
private BedrockConfiguration bedrock;
private RemoteConfiguration remote;
private Map<String, UserAuthenticationInfo> userAuths;
@JsonProperty("ping-passthrough")
private boolean pingPassthrough;

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.configuration;
public class UserAuthenticationInfo {
public String email;
public String password;
}

View file

@ -28,6 +28,7 @@ package org.geysermc.connector.network;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import com.nukkitx.protocol.bedrock.packet.*;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.configuration.UserAuthenticationInfo;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.Registry;
import org.geysermc.connector.utils.LoginEncryptionUtils;
@ -91,11 +92,30 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
return LoginEncryptionUtils.authenticateFromForm(session, connector, packet.getFormData());
}
private boolean couldLoginUserByName(String bedrockUsername) {
if (connector.getConfig().getUserAuths() != null) {
UserAuthenticationInfo info = connector.getConfig().getUserAuths().get(bedrockUsername);
if (info != null) {
connector.getLogger().debug("using stored credentials for bedrock user " + session.getAuthenticationData().getName());
session.authenticate(info.email, info.password);
return true;
}
}
return false;
}
@Override
public boolean handle(MovePlayerPacket packet) {
connector.getLogger().debug("Handled packet: " + packet.getClass().getSimpleName());
if (!session.isLoggedIn()) {
LoginEncryptionUtils.showLoginWindow(session);
// TODO it is safer to key authentication on something that won't change (UUID, not username)
if (!couldLoginUserByName(session.getAuthenticationData().getName())) {
LoginEncryptionUtils.showLoginWindow(session);
}
// else we were able to log the user in
return true;
}
return false;

View file

@ -150,10 +150,10 @@ public class LoginEncryptionUtils {
return false;
CustomFormResponse response = (CustomFormResponse) customFormWindow.getResponse();
String username = response.getInputResponses().get(2);
String email = response.getInputResponses().get(2);
String password = response.getInputResponses().get(3);
session.authenticate(username, password);
session.authenticate(email, password);
// TODO should we clear the window cache in all cases or just if not already logged in?
// Clear windows so authentication data isn't accidentally cached

View file

@ -21,6 +21,19 @@ remote:
port: 25565
online-mode: false
## the Xbox/MCPE username is the key for the Java server auth-info
## this allows automatic configuration/login to the remote Java server
## if you are brave/stupid enough to put your Mojang account info into
## a config file
#userAuths:
# bluekelp2: # MCPE/Xbox username
# email: not_really_my_email_address_mr_minecrafter53267@gmail.com # Mojang account email address
# password: "this isn't really my password"
#
# herpderp40300499303040503030300500293858393589:
# email: herpderp@derpherp.com
# password: dooooo
# Relay the MOTD, player count and max players from the remote server
ping-passthrough: false