feat(velocity): Implement Velocity debug mode
This commit is contained in:
parent
315f6b043b
commit
1c7c50675a
@ -7,8 +7,6 @@ import org.slf4j.Logger;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
|
||||
|
||||
public final class Loader {
|
||||
|
@ -69,7 +69,7 @@ public final class AuthMeVelocityPlugin extends JavaPlugin {
|
||||
|
||||
public void logDebug(String debug) {
|
||||
if (config.get().debug()) {
|
||||
getSLF4JLogger().info("[DEBUG] "+debug);
|
||||
getSLF4JLogger().info("[DEBUG] {}", debug);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
|
||||
new VelocityLibraryManager<>(
|
||||
logger, pluginDirectory, proxy.getPluginManager(), this));
|
||||
libraries.loadLibraries();
|
||||
logDebug("Loaded plugin libraries");
|
||||
|
||||
this.config = Loader.loadMainConfig(pluginDirectory, ProxyConfiguration.class, logger);
|
||||
|
||||
@ -90,10 +91,12 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
|
||||
proxy.getEventManager().register(this, listener));
|
||||
|
||||
if (proxy.getPluginManager().isLoaded("fastlogin")) {
|
||||
logDebug("Register FastLogin compatibility");
|
||||
proxy.getEventManager().register(this, new FastLoginListener(proxy, this));
|
||||
}
|
||||
|
||||
if (proxy.getPluginManager().isLoaded("miniplaceholders")) {
|
||||
logDebug("Register MiniPlaceholders compatibility");
|
||||
AuthMePlaceholders.getExpansion(this).register();
|
||||
}
|
||||
|
||||
@ -166,4 +169,10 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
|
||||
public boolean isAuthServer(String server){
|
||||
return config.get().authServers().contains(server);
|
||||
}
|
||||
|
||||
public void logDebug(String msg) {
|
||||
if (config.get().debug()) {
|
||||
logger.info("[DEBUG] {}", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,12 +34,14 @@ public class ConnectListener {
|
||||
public void onInitialServer(PlayerChooseInitialServerEvent event, Continuation continuation){
|
||||
if(!plugin.config().get().ensureAuthServer().ensureFirstServerIsAuthServer()) {
|
||||
continuation.resume();
|
||||
plugin.logDebug("PlayerChooseInitialServerEvent | Not enabled");
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<RegisteredServer> optionalSV = event.getInitialServer();
|
||||
if(optionalSV.isPresent() && plugin.isAuthServer(optionalSV.get())){
|
||||
continuation.resume();
|
||||
plugin.logDebug("PlayerChooseInitialServerEvent | Player is in auth server");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -48,19 +50,22 @@ public class ConnectListener {
|
||||
event.setInitialServer(server);
|
||||
continuation.resume();
|
||||
if (server == null) {
|
||||
plugin.logDebug("PlayerChooseInitialServerEvent | Null server");
|
||||
logger.error("Cannot send the player {} to an auth server", event.getPlayer().getUsername());
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onServerPreConnect(ServerPreConnectEvent event, Continuation continuation) {
|
||||
if (!event.getResult().isAllowed() && plugin.isLogged(event.getPlayer())) {
|
||||
if (!event.getResult().isAllowed() || plugin.isLogged(event.getPlayer())) {
|
||||
plugin.logDebug("ServerPreConnectEvent | Not allowed or player not logged");
|
||||
continuation.resume();
|
||||
return;
|
||||
}
|
||||
|
||||
// this should be present, "event.getResult().isAllowed()" is the "isPresent" check
|
||||
if(!plugin.isAuthServer(event.getResult().getServer().get())) {
|
||||
if(!plugin.isAuthServer(event.getResult().getServer().orElse(null))) {
|
||||
plugin.logDebug("ServerPreConnectEvent | Server is not an auth server");
|
||||
event.setResult(ServerPreConnectEvent.ServerResult.denied());
|
||||
}
|
||||
continuation.resume();
|
||||
@ -70,7 +75,8 @@ public class ConnectListener {
|
||||
public void onServerPostConnect(ServerPostConnectEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (plugin.isLogged(player) && plugin.isInAuthServer(player)) {
|
||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||
plugin.logDebug("ServerPostConnectEvent | Already logged player and connected to an Auth server");
|
||||
final ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||
buf.writeUTF("LOGIN");
|
||||
player.getCurrentServer().ifPresent(sv ->
|
||||
sv.sendPluginMessage(AuthMeVelocityPlugin.AUTHMEVELOCITY_CHANNEL, buf.toByteArray()));
|
||||
|
@ -4,18 +4,18 @@ import com.github.games647.fastlogin.velocity.event.VelocityFastLoginAutoLoginEv
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
|
||||
import me.adrianed.authmevelocity.api.velocity.AuthMeVelocityAPI;
|
||||
import me.adrianed.authmevelocity.velocity.AuthMeVelocityPlugin;
|
||||
|
||||
public class FastLoginListener {
|
||||
private final ProxyServer proxy;
|
||||
private final AuthMeVelocityAPI api;
|
||||
public FastLoginListener(ProxyServer proxy, AuthMeVelocityAPI api){
|
||||
private final AuthMeVelocityPlugin plugin;
|
||||
public FastLoginListener(ProxyServer proxy, AuthMeVelocityPlugin plugin){
|
||||
this.proxy = proxy;
|
||||
this.api = api;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@Subscribe
|
||||
public void onAutoLogin(VelocityFastLoginAutoLoginEvent event){
|
||||
proxy.getPlayer(event.getProfile().getName())
|
||||
.ifPresent(api::addPlayer);
|
||||
plugin.logDebug("VelocityFastLoginAutoLoginEvent | Attempt to auto register player");
|
||||
proxy.getPlayer(event.getProfile().getName()).ifPresent(plugin::addPlayer);
|
||||
}
|
||||
}
|
||||
|
@ -43,14 +43,16 @@ public class PluginMessageListener {
|
||||
|
||||
@Subscribe
|
||||
public void onPluginMessage(final PluginMessageEvent event, Continuation continuation) {
|
||||
final boolean cancelled = !(event.getSource() instanceof ServerConnection)
|
||||
final boolean cancelled = !event.getResult().isAllowed()
|
||||
||!(event.getSource() instanceof ServerConnection)
|
||||
|| !event.getIdentifier().equals(AuthMeVelocityPlugin.AUTHMEVELOCITY_CHANNEL);
|
||||
if (cancelled) {
|
||||
continuation.resume();
|
||||
plugin.logDebug("PluginMessageEvent | Not allowed");
|
||||
return;
|
||||
}
|
||||
|
||||
ServerConnection connection = ((ServerConnection)event.getSource());
|
||||
final ServerConnection connection = ((ServerConnection)event.getSource());
|
||||
|
||||
event.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||
|
||||
@ -63,26 +65,39 @@ public class PluginMessageListener {
|
||||
|
||||
switch (type) {
|
||||
case LOGIN -> {
|
||||
plugin.logDebug("PluginMessageEvent | Login type");
|
||||
if (player != null && plugin.addPlayer(player)){
|
||||
proxy.getEventManager().fireAndForget(new ProxyLoginEvent(player));
|
||||
this.createServerConnectionRequest(player, connection);
|
||||
plugin.logDebug("PluginMessageEvent | Player not null");
|
||||
}
|
||||
}
|
||||
case LOGOUT -> {
|
||||
plugin.logDebug("PluginMessageEvent | Logout type");
|
||||
if (player != null && plugin.removePlayer(player)){
|
||||
proxy.getEventManager().fireAndForget(new ProxyLogoutEvent(player));
|
||||
plugin.logDebug("PluginMessageEvent | Player not null");
|
||||
}
|
||||
}
|
||||
case REGISTER -> {
|
||||
if (player != null)
|
||||
plugin.logDebug("PluginMessageEvent | Register");
|
||||
if (player != null) {
|
||||
proxy.getEventManager().fireAndForget(new ProxyRegisterEvent(player));
|
||||
plugin.logDebug("PluginMessageEvent | Player not null");
|
||||
}
|
||||
}
|
||||
case UNREGISTER -> {
|
||||
if(player != null)
|
||||
plugin.logDebug("PluginMessageEvent | Unregister type");
|
||||
if(player != null) {
|
||||
plugin.logDebug("PluginMessageEvent | Player not null");
|
||||
proxy.getEventManager().fireAndForget(new ProxyUnregisterEvent(player));
|
||||
}
|
||||
case FORCE_UNREGISTER ->
|
||||
}
|
||||
case FORCE_UNREGISTER -> {
|
||||
proxy.getEventManager().fireAndForget(new ProxyForcedUnregisterEvent(player));
|
||||
plugin.logDebug("PluginMessageEvent | Forced Unregister type");
|
||||
}
|
||||
|
||||
}
|
||||
continuation.resume();
|
||||
}
|
||||
@ -100,14 +115,14 @@ public class PluginMessageListener {
|
||||
.thenApply(PreSendOnLoginEvent::getResult)
|
||||
.thenApply(GenericResult::isAllowed)
|
||||
.thenAcceptAsync(allowed -> {
|
||||
if (!allowed) {
|
||||
if (!allowed.booleanValue()) {
|
||||
return;
|
||||
}
|
||||
player.createConnectionRequest(server)
|
||||
.connect()
|
||||
.thenApply(Result::isSuccessful)
|
||||
.thenAcceptAsync(result -> {
|
||||
if(!result) {
|
||||
if(!result.booleanValue()) {
|
||||
logger.info("Unable to connect the player {} to the server {}",
|
||||
player.getUsername(),
|
||||
server.getServerInfo().getName());
|
||||
|
@ -28,25 +28,28 @@ public final class ProxyListener {
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void onCommandExecute(final CommandExecuteEvent event, Continuation continuation) {
|
||||
if (!(event.getCommandSource() instanceof Player)){
|
||||
if (!(event.getCommandSource() instanceof final Player player)){
|
||||
plugin.logDebug("CommandExecuteEvent | CommandSource is not a player");
|
||||
continuation.resume();
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player)event.getCommandSource();
|
||||
|
||||
if (plugin.isLogged(player)) {
|
||||
plugin.logDebug("CommandExecuteEvent | Player is not logged");
|
||||
continuation.resume();
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.isInAuthServer(player)) {
|
||||
plugin.logDebug("CommandExecuteEvent | Player is in Auth Server");
|
||||
String command = AuthmeUtils.getFirstArgument(event.getCommand());
|
||||
if (!plugin.config().get().commands().allowedCommands().contains(command)) {
|
||||
plugin.logDebug("CommandExecuteEvent | Player executed an blocked command");
|
||||
sendBlockedMessage(player);
|
||||
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
}
|
||||
} else {
|
||||
plugin.logDebug("CommandExecuteEven | Player is not in auth server");
|
||||
sendBlockedMessage(player);
|
||||
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
}
|
||||
@ -56,6 +59,7 @@ public final class ProxyListener {
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void onPlayerChat(final PlayerChatEvent event) {
|
||||
if (plugin.isNotLogged(event.getPlayer())) {
|
||||
plugin.logDebug("PlayerChatEvent | Player is not logged");
|
||||
event.setResult(PlayerChatEvent.ChatResult.denied());
|
||||
}
|
||||
}
|
||||
@ -63,6 +67,7 @@ public final class ProxyListener {
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void onTabComplete(TabCompleteEvent event){
|
||||
if (plugin.isLogged(event.getPlayer())) {
|
||||
plugin.logDebug("TabCompleteEvent | Player is already logged");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -73,6 +78,7 @@ public final class ProxyListener {
|
||||
}
|
||||
}
|
||||
|
||||
plugin.logDebug("TabCompleteEvent | Not allowed tabcompletion");
|
||||
event.getSuggestions().clear();
|
||||
}
|
||||
|
||||
|
@ -11,12 +11,12 @@ public class AuthmeUtils {
|
||||
* @param string the string
|
||||
* @return the first argument
|
||||
*/
|
||||
public static @NotNull String getFirstArgument(@NotNull String string){
|
||||
int index = Objects.requireNonNull(string).indexOf(" ");
|
||||
public static @NotNull String getFirstArgument(final @NotNull String string){
|
||||
final int index = Objects.requireNonNull(string).indexOf(' ');
|
||||
if (index == -1) {
|
||||
return string;
|
||||
}
|
||||
return string.substring(0, index);
|
||||
}
|
||||
private AuthmeUtils(){}
|
||||
private AuthmeUtils() {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user