[Velocity] Fix plugin resuming event processing if login is not handled

This causes login timeouts if this plugin doesn't handle the login for
cases like:

* Anti-Bot is triggered
* Another plugin already denied the login

Fixes #1146
This commit is contained in:
games647
2024-01-23 13:59:49 +01:00
parent 707572a007
commit dbf5ae2fae
2 changed files with 12 additions and 21 deletions

View File

@ -28,15 +28,15 @@ package com.github.games647.fastlogin.velocity.listener;
import com.github.games647.craftapi.UUIDAdapter; import com.github.games647.craftapi.UUIDAdapter;
import com.github.games647.fastlogin.core.antibot.AntiBotService; import com.github.games647.fastlogin.core.antibot.AntiBotService;
import com.github.games647.fastlogin.core.antibot.AntiBotService.Action; import com.github.games647.fastlogin.core.antibot.AntiBotService.Action;
import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService;
import com.github.games647.fastlogin.core.shared.LoginSession; import com.github.games647.fastlogin.core.shared.LoginSession;
import com.github.games647.fastlogin.core.storage.StoredProfile; import com.github.games647.fastlogin.core.storage.StoredProfile;
import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService;
import com.github.games647.fastlogin.velocity.FastLoginVelocity; import com.github.games647.fastlogin.velocity.FastLoginVelocity;
import com.github.games647.fastlogin.velocity.VelocityLoginSession; import com.github.games647.fastlogin.velocity.VelocityLoginSession;
import com.github.games647.fastlogin.velocity.task.AsyncPremiumCheck; import com.github.games647.fastlogin.velocity.task.AsyncPremiumCheck;
import com.github.games647.fastlogin.velocity.task.ForceLoginTask;
import com.github.games647.fastlogin.velocity.task.FloodgateAuthTask; import com.github.games647.fastlogin.velocity.task.FloodgateAuthTask;
import com.velocitypowered.api.event.Continuation; import com.github.games647.fastlogin.velocity.task.ForceLoginTask;
import com.velocitypowered.api.event.EventTask;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.DisconnectEvent;
import com.velocitypowered.api.event.connection.PreLoginEvent; import com.velocitypowered.api.event.connection.PreLoginEvent;
@ -70,9 +70,9 @@ public class ConnectListener {
} }
@Subscribe @Subscribe
public void onPreLogin(PreLoginEvent preLoginEvent, Continuation continuation) { public EventTask onPreLogin(PreLoginEvent preLoginEvent) {
if (!preLoginEvent.getResult().isAllowed()) { if (!preLoginEvent.getResult().isAllowed()) {
return; return null;
} }
InboundConnection connection = preLoginEvent.getConnection(); InboundConnection connection = preLoginEvent.getConnection();
@ -84,26 +84,24 @@ public class ConnectListener {
switch (action) { switch (action) {
case Ignore: case Ignore:
// just ignore // just ignore
return; return null;
case Block: case Block:
String message = plugin.getCore().getMessage("kick-antibot"); String message = plugin.getCore().getMessage("kick-antibot");
TextComponent messageParsed = LegacyComponentSerializer.legacyAmpersand().deserialize(message); TextComponent messageParsed = LegacyComponentSerializer.legacyAmpersand().deserialize(message);
PreLoginComponentResult reason = PreLoginComponentResult.denied(messageParsed); PreLoginComponentResult reason = PreLoginComponentResult.denied(messageParsed);
preLoginEvent.setResult(reason); preLoginEvent.setResult(reason);
break; return null;
case Continue: case Continue:
default: default:
Runnable asyncPremiumCheck = new AsyncPremiumCheck( return EventTask.async(
plugin, connection, username, continuation, preLoginEvent new AsyncPremiumCheck(plugin, connection, username, preLoginEvent)
); );
plugin.getScheduler().runAsync(asyncPremiumCheck);
break;
} }
} }
@Subscribe @Subscribe
public void onGameprofileRequest(GameProfileRequestEvent event) { public void onGameProfileRequest(GameProfileRequestEvent event) {
if (event.isOnlineMode()) { if (event.isOnlineMode()) {
LoginSession session = plugin.getSession().get(event.getConnection().getRemoteAddress()); LoginSession session = plugin.getSession().get(event.getConnection().getRemoteAddress());
if (session == null) { if (session == null) {

View File

@ -33,7 +33,6 @@ import com.github.games647.fastlogin.velocity.VelocityLoginSession;
import com.github.games647.fastlogin.velocity.VelocityLoginSource; import com.github.games647.fastlogin.velocity.VelocityLoginSource;
import com.github.games647.fastlogin.velocity.event.VelocityFastLoginPreLoginEvent; import com.github.games647.fastlogin.velocity.event.VelocityFastLoginPreLoginEvent;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.Continuation;
import com.velocitypowered.api.event.connection.PreLoginEvent; import com.velocitypowered.api.event.connection.PreLoginEvent;
import com.velocitypowered.api.proxy.InboundConnection; import com.velocitypowered.api.proxy.InboundConnection;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
@ -45,28 +44,22 @@ public class AsyncPremiumCheck extends JoinManagement<Player, CommandSource, Vel
private final FastLoginVelocity plugin; private final FastLoginVelocity plugin;
private final String username; private final String username;
private final Continuation continuation;
private final PreLoginEvent preLoginEvent; private final PreLoginEvent preLoginEvent;
private final InboundConnection connection; private final InboundConnection connection;
public AsyncPremiumCheck(FastLoginVelocity plugin, InboundConnection connection, String username, public AsyncPremiumCheck(FastLoginVelocity plugin, InboundConnection connection, String username,
Continuation continuation, PreLoginEvent preLoginEvent) { PreLoginEvent preLoginEvent) {
super(plugin.getCore(), plugin.getCore().getAuthPluginHook(), plugin.getBedrockService()); super(plugin.getCore(), plugin.getCore().getAuthPluginHook(), plugin.getBedrockService());
this.plugin = plugin; this.plugin = plugin;
this.connection = connection; this.connection = connection;
this.username = username; this.username = username;
this.continuation = continuation;
this.preLoginEvent = preLoginEvent; this.preLoginEvent = preLoginEvent;
} }
@Override @Override
public void run() { public void run() {
plugin.getSession().remove(connection.getRemoteAddress()); plugin.getSession().remove(connection.getRemoteAddress());
try { super.onLogin(username, new VelocityLoginSource(connection, preLoginEvent));
super.onLogin(username, new VelocityLoginSource(connection, preLoginEvent));
} finally {
continuation.resume();
}
} }
@Override @Override