misc: Improved AutoLogin debug messages

This commit is contained in:
Adrian 2023-04-21 23:08:48 -05:00
parent 7c5c75d4b9
commit d617995bbe
No known key found for this signature in database
GPG Key ID: FB8EF84DCE1BE452
3 changed files with 29 additions and 17 deletions

View File

@ -1,5 +1,5 @@
group = io.github.4drian3d
version = 4.0.1
version = 4.0.2-SNAPSHOT
description = AuthMeReloaded Support for Velocity
url = https://modrinth.com/plugin/authmevelocity
id = authmevelocity

View File

@ -29,8 +29,10 @@ import com.velocitypowered.api.event.player.ServerPreConnectEvent;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import io.github._4drian3d.authmevelocity.common.configuration.ProxyConfiguration;
import io.github._4drian3d.authmevelocity.velocity.AuthMeVelocityPlugin;
import io.github._4drian3d.authmevelocity.velocity.utils.AuthMeUtils;
import io.github._4drian3d.authmevelocity.velocity.utils.Pair;
import org.slf4j.Logger;
import java.util.Optional;
@ -60,8 +62,8 @@ public final class ConnectListener {
plugin.logDebug("PlayerChooseInitialServerEvent | Player is in auth server");
return;
}
final var config = plugin.config().get();
final var server = AuthMeUtils.serverToSend(
final ProxyConfiguration config = plugin.config().get();
final Pair<RegisteredServer> server = AuthMeUtils.serverToSend(
config.ensureAuthServer().sendMode(), proxy, config.authServers(), config.advanced().randomAttempts());
// Velocity takes over in case the initial server is not present
@ -96,18 +98,26 @@ public final class ConnectListener {
@Subscribe
public void onServerPostConnect(final ServerPostConnectEvent event) {
final Player player = event.getPlayer();
if (plugin.isLogged(player) && plugin.isInAuthServer(player)) {
plugin.logDebug("ServerPostConnectEvent | Already logged player and connected to an Auth server");
final ByteArrayDataOutput buf = ByteStreams.newDataOutput();
buf.writeUTF("LOGIN");
player.getCurrentServer().ifPresent(sv -> {
var byteArray = buf.toByteArray();
if (!sv.sendPluginMessage(AuthMeVelocityPlugin.MODERN_CHANNEL, byteArray)) {
plugin.logDebug("ServerPostConnectEvent | Failed to send on Modern Channel");
var legacyResult = sv.sendPluginMessage(AuthMeVelocityPlugin.LEGACY_CHANNEL, byteArray);
if(!legacyResult) plugin.logDebug("ServerPostConnectEvent | Failed to send on Legacy Channel");
}
});
final boolean isLogged = plugin.isLogged(player);
plugin.logDebug("ServerPostConnectEvent | Player "+player.getUsername()+" is logged: " + isLogged);
final boolean isInAuthServer = plugin.isInAuthServer(player);
plugin.logDebug("ServerPostConnectEvent | Player "+player.getUsername()+" is in AuthServer: " + isInAuthServer);
if (!(isLogged && isInAuthServer)) {
return;
}
plugin.logDebug("ServerPostConnectEvent | Already logged player and connected to an Auth server");
final ByteArrayDataOutput buf = ByteStreams.newDataOutput();
buf.writeUTF("LOGIN");
player.getCurrentServer().ifPresent(server -> {
final byte[] byteArray = buf.toByteArray();
if (!server.sendPluginMessage(AuthMeVelocityPlugin.MODERN_CHANNEL, byteArray)) {
plugin.logDebug("ServerPostConnectEvent | Failed to send on Modern Channel");
final boolean legacyResult = server.sendPluginMessage(AuthMeVelocityPlugin.LEGACY_CHANNEL, byteArray);
if (!legacyResult) plugin.logDebug("ServerPostConnectEvent | Failed to send on Legacy Channel");
}
});
}
}

View File

@ -29,8 +29,10 @@ import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import io.github._4drian3d.authmevelocity.api.velocity.event.*;
import io.github._4drian3d.authmevelocity.common.MessageType;
import io.github._4drian3d.authmevelocity.common.configuration.ProxyConfiguration;
import io.github._4drian3d.authmevelocity.velocity.AuthMeVelocityPlugin;
import io.github._4drian3d.authmevelocity.velocity.utils.AuthMeUtils;
import io.github._4drian3d.authmevelocity.velocity.utils.Pair;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
@ -113,9 +115,9 @@ public class PluginMessageListener {
private void createServerConnectionRequest(Player player, ServerConnection connection){
final RegisteredServer loginServer = player.getCurrentServer().orElse(connection).getServer();
final var config = plugin.config().get();
final ProxyConfiguration config = plugin.config().get();
final var toSend = AuthMeUtils.serverToSend(
final Pair<RegisteredServer> toSend = AuthMeUtils.serverToSend(
config.sendOnLogin().sendMode(), proxy, config.sendOnLogin().teleportServers(), config.advanced().randomAttempts());
if (toSend.isEmpty()) {