fix: Possible fix for #44
This commit is contained in:
parent
30023ece19
commit
9c65541b8e
2
pom.xml
2
pom.xml
@ -7,7 +7,7 @@
|
|||||||
<groupId>com.glyart.authmevelocity</groupId>
|
<groupId>com.glyart.authmevelocity</groupId>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>2.2.0</version>
|
<version>2.2.1-SNAPSHOT</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<groupId>com.glyart.authmevelocity</groupId>
|
<groupId>com.glyart.authmevelocity</groupId>
|
||||||
<version>2.2.0</version>
|
<version>2.2.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ public final class AuthMeConfig {
|
|||||||
this.commands = ConfigUtils.getObjectOrElse(toml, "Commands", Commands.class,
|
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"));
|
() -> 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,
|
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 {
|
public static class ServerOnLogin {
|
||||||
@ -62,21 +62,15 @@ public final class AuthMeConfig {
|
|||||||
|
|
||||||
public static class EnsureAuthServer {
|
public static class EnsureAuthServer {
|
||||||
private final boolean ensureFirstServerIsAuthServer;
|
private final boolean ensureFirstServerIsAuthServer;
|
||||||
private final String disconnectMessage;
|
|
||||||
|
|
||||||
public EnsureAuthServer(boolean ensureFirstServerIsAuthServer, String disconnectMessage){
|
public EnsureAuthServer(boolean ensureFirstServerIsAuthServer){
|
||||||
this.ensureFirstServerIsAuthServer = ensureFirstServerIsAuthServer;
|
this.ensureFirstServerIsAuthServer = ensureFirstServerIsAuthServer;
|
||||||
this.disconnectMessage = disconnectMessage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean ensureAuthServer(){
|
public boolean ensureAuthServer(){
|
||||||
return this.ensureFirstServerIsAuthServer;
|
return this.ensureFirstServerIsAuthServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull String getDisconnectMessage(){
|
|
||||||
return this.disconnectMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Commands getCommandsConfig(){
|
public @NotNull Commands getCommandsConfig(){
|
||||||
|
@ -96,7 +96,7 @@ public final class ProxyListener {
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onServerPostConnect(ServerPostConnectEvent event) {
|
public void onServerPostConnect(ServerPostConnectEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
if(api.isInAuthServer(player)){
|
if (api.isLogged(player) && api.isInAuthServer(player)){
|
||||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||||
buf.writeUTF("LOGIN");
|
buf.writeUTF("LOGIN");
|
||||||
player.getCurrentServer().ifPresent(sv ->
|
player.getCurrentServer().ifPresent(sv ->
|
||||||
@ -122,26 +122,22 @@ public final class ProxyListener {
|
|||||||
|
|
||||||
@Subscribe(order = PostOrder.LATE)
|
@Subscribe(order = PostOrder.LATE)
|
||||||
public void onInitialServer(PlayerChooseInitialServerEvent event, Continuation continuation){
|
public void onInitialServer(PlayerChooseInitialServerEvent event, Continuation continuation){
|
||||||
if(
|
if(!config.getEnsureOptions().ensureAuthServer()
|
||||||
!config.getEnsureOptions().ensureAuthServer()
|
|
||||||
|| event.getInitialServer().map(api::isAuthServer).orElse(false)
|
|| event.getInitialServer().map(api::isAuthServer).orElse(false)
|
||||||
) {
|
) {
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@Nullable RegisteredServer server = getAvailableServer();
|
@Nullable RegisteredServer server = getAvailableServer();
|
||||||
if (server == null) {
|
// Velocity takes over in case the initial server is not present
|
||||||
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;
|
|
||||||
}
|
|
||||||
event.setInitialServer(server);
|
event.setInitialServer(server);
|
||||||
continuation.resume();
|
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() {
|
private @Nullable RegisteredServer getAvailableServer() {
|
||||||
for(String sv : config.getAuthServers()){
|
for(String sv : config.getAuthServers()){
|
||||||
Optional<RegisteredServer> opt = proxy.getServer(sv);
|
Optional<RegisteredServer> opt = proxy.getServer(sv);
|
||||||
|
@ -24,6 +24,3 @@ authServers = ["auth1", "auth2"]
|
|||||||
[EnsureAuthServer]
|
[EnsureAuthServer]
|
||||||
# Ensure that the first server to which players connect is an auth server
|
# Ensure that the first server to which players connect is an auth server
|
||||||
ensureFirstServerIsAuthServer = false
|
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"
|
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<groupId>com.glyart.authmevelocity</groupId>
|
<groupId>com.glyart.authmevelocity</groupId>
|
||||||
<version>2.2.0</version>
|
<version>2.2.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user