fix: Possible fix for #44

This commit is contained in:
4drian3d 2022-07-28 15:01:06 +00:00
parent 30023ece19
commit 9c65541b8e
6 changed files with 13 additions and 26 deletions

View File

@ -7,7 +7,7 @@
<groupId>com.glyart.authmevelocity</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>2.2.0</version>
<version>2.2.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>com.glyart.authmevelocity</groupId>
<version>2.2.0</version>
<version>2.2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -21,7 +21,7 @@ public final class AuthMeConfig {
this.commands = ConfigUtils.getObjectOrElse(toml, "Commands", Commands.class,
() -> new Commands(Set.of("login", "register", "l", "reg", "email", "captcha"), "<red>You cannot execute commands if you are not logged in yet"));
this.ensure = ConfigUtils.getObjectOrElse(toml, "EnsureAuthServer", EnsureAuthServer.class,
() -> new EnsureAuthServer(false, "<red>You could not connect to a login server, please try again later"));
() -> new EnsureAuthServer(false));
}
public static class ServerOnLogin {
@ -62,21 +62,15 @@ public final class AuthMeConfig {
public static class EnsureAuthServer {
private final boolean ensureFirstServerIsAuthServer;
private final String disconnectMessage;
public EnsureAuthServer(boolean ensureFirstServerIsAuthServer, String disconnectMessage){
public EnsureAuthServer(boolean ensureFirstServerIsAuthServer){
this.ensureFirstServerIsAuthServer = ensureFirstServerIsAuthServer;
this.disconnectMessage = disconnectMessage;
}
public boolean ensureAuthServer(){
return this.ensureFirstServerIsAuthServer;
}
public @NotNull String getDisconnectMessage(){
return this.disconnectMessage;
}
}
public @NotNull Commands getCommandsConfig(){

View File

@ -96,7 +96,7 @@ public final class ProxyListener {
@Subscribe
public void onServerPostConnect(ServerPostConnectEvent event) {
final Player player = event.getPlayer();
if(api.isInAuthServer(player)){
if (api.isLogged(player) && api.isInAuthServer(player)){
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
buf.writeUTF("LOGIN");
player.getCurrentServer().ifPresent(sv ->
@ -122,26 +122,22 @@ public final class ProxyListener {
@Subscribe(order = PostOrder.LATE)
public void onInitialServer(PlayerChooseInitialServerEvent event, Continuation continuation){
if(
!config.getEnsureOptions().ensureAuthServer()
if(!config.getEnsureOptions().ensureAuthServer()
|| event.getInitialServer().map(api::isAuthServer).orElse(false)
) {
continuation.resume();
return;
}
@Nullable RegisteredServer server = getAvailableServer();
if (server == null) {
continuation.resume();
logger.error("Cannot send the player {} to an auth server", event.getPlayer().getUsername());
String disconnectMessage = config.getEnsureOptions().getDisconnectMessage();
event.getPlayer().disconnect(ConfigUtils.MINIMESSAGE.deserialize(disconnectMessage));
return;
}
// Velocity takes over in case the initial server is not present
event.setInitialServer(server);
continuation.resume();
if (server == null) {
logger.error("Cannot send the player {} to an auth server", event.getPlayer().getUsername());
}
}
// TODO: Implement #40
private @Nullable RegisteredServer getAvailableServer() {
for(String sv : config.getAuthServers()){
Optional<RegisteredServer> opt = proxy.getServer(sv);

View File

@ -24,6 +24,3 @@ authServers = ["auth1", "auth2"]
[EnsureAuthServer]
# Ensure that the first server to which players connect is an auth server
ensureFirstServerIsAuthServer = false
# Message to be sent to the player in case no auth server is available
disconnectMessage = "<red>You could not connect to a login server, please try again later"

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>com.glyart.authmevelocity</groupId>
<version>2.2.0</version>
<version>2.2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>