Skip to content

Commit

Permalink
Merge branch 'main' into 45-suggestion-add-tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	core/pom.xml
  • Loading branch information
bivashy committed Oct 14, 2023
2 parents c41c4db + 31debf5 commit 835285d
Show file tree
Hide file tree
Showing 60 changed files with 733 additions and 369 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "maven" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
6 changes: 3 additions & 3 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
<properties>
<jbcrypt.version>0.4</jbcrypt.version>
<multimessenger.version>1.0.5</multimessenger.version>
<adventure.serializer.version>4.13.0</adventure.serializer.version>
<adventure.serializer.version>4.14.0</adventure.serializer.version>
<adventure.platform.version>4.3.0</adventure.platform.version>
<ormlite.version>6.1</ormlite.version>
<google.authenticator.version>1.5.0</google.authenticator.version>
<event-bus.version>1.2</event-bus.version>
<event-bus.version>1.3</event-bus.version>
<configuration-library.version>4.0.2</configuration-library.version>
<libby.version>1.3.4</libby.version>
<libby.version>2.0.0</libby.version>
</properties>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.IntStream;

import com.bivashy.auth.api.config.bossbar.BossBarSettings;
import com.bivashy.auth.api.config.database.DatabaseSettings;
Expand Down Expand Up @@ -42,6 +43,8 @@ public interface PluginConfig {

List<Pattern> getAllowedCommands();

IntStream getLimboPortRange();

List<String> getAuthenticationSteps();

String getAuthenticationStepName(int index);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.bivashy.auth.api.hook;

import com.bivashy.auth.api.server.proxy.ProxyServer;

public interface LimboPluginHook extends PluginHook {

ProxyServer createServer(String serverName);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import java.util.Collection;

import net.byteflux.libby.Library;
import net.byteflux.libby.LibraryManager;
import net.byteflux.libby.transitive.ExcludedDependency;
import com.alessiodp.libby.Library;
import com.alessiodp.libby.LibraryManager;
import com.alessiodp.libby.transitive.ExcludedDependency;

public interface LibraryManagement {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

import com.bivashy.auth.api.server.proxy.ProxyServer;

@Deprecated
public interface LimboServerWrapper extends ProxyServer {
}
15 changes: 12 additions & 3 deletions bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

<properties>
<bungeecord.version>1.19-R0.1-SNAPSHOT</bungeecord.version>
<lamp.command-library.version>3.1.6</lamp.command-library.version>
<lamp.command-library.version>3.1.7</lamp.command-library.version>
<adventure.bungee.version>4.3.0</adventure.bungee.version>
<telegram.api.version>6.5.0</telegram.api.version>
<vk.api.version>0.4.2</vk.api.version>
<libby.version>1.3.4</libby.version>
<libby.version>2.0.0</libby.version>
<nanolimbo.version>1.0.6</nanolimbo.version>
</properties>

<repositories>
Expand Down Expand Up @@ -59,7 +60,7 @@

<!-- Lamp Bungee Module -->
<dependency>
<groupId>com.github.bivashy.Lamp</groupId>
<groupId>com.github.Revxrsal.Lamp</groupId>
<artifactId>bungee</artifactId>
<version>${lamp.command-library.version}</version>
</dependency>
Expand Down Expand Up @@ -87,6 +88,14 @@
<scope>provided</scope>
</dependency>

<!-- NanoLimboPlugin API -->
<dependency>
<groupId>com.github.bivashy.NanoLimboPlugin</groupId>
<artifactId>api</artifactId>
<version>${nanolimbo.version}</version>
<scope>provided</scope>
</dependency>

<!-- Libby -->
<dependency>
<groupId>com.github.bivashy.libby</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
package me.mastercapexd.auth.bungee;

import com.bivashy.auth.api.AuthPlugin;
import com.bivashy.auth.api.management.LoginManagement;
import java.util.Collection;
import java.util.Collections;

import com.alessiodp.libby.BungeeLibraryManager;
import com.bivashy.auth.api.hook.LimboPluginHook;
import com.bivashy.messenger.vk.message.VkMessage;
import com.bivashy.messenger.vk.provider.VkApiProvider;
import com.ubivashka.vk.bungee.BungeeVkApiPlugin;

import me.mastercapexd.auth.BaseAuthPlugin;
import me.mastercapexd.auth.bungee.commands.BungeeCommandsRegistry;
import me.mastercapexd.auth.bungee.hooks.BungeeVkPluginHook;
import me.mastercapexd.auth.bungee.hooks.nanolimbo.BungeeNanoLimboPluginHook;
import me.mastercapexd.auth.bungee.listener.AuthenticationListener;
import me.mastercapexd.auth.bungee.listener.VkDispatchListener;
import me.mastercapexd.auth.hooks.VkPluginHook;
import me.mastercapexd.auth.management.BaseLibraryManagement;
import me.mastercapexd.auth.vk.command.VKCommandRegistry;
import net.byteflux.libby.BungeeLibraryManager;
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.md_5.bungee.api.plugin.Plugin;

public class BungeeAuthPluginBootstrap extends Plugin {

private static BungeeAuthPluginBootstrap instance;
private BungeeAudiences bungeeAudiences;
private LoginManagement loginManagement;
private BaseAuthPlugin authPlugin;

public static BungeeAuthPluginBootstrap getInstance() {
Expand All @@ -38,6 +41,7 @@ public void onEnable() {
new BaseLibraryManagement(new BungeeLibraryManager(this)));
initializeListener();
initializeCommand();
initializeLimbo();
if (authPlugin.getConfig().getVKSettings().isEnabled())
initializeVk();
}
Expand All @@ -56,6 +60,13 @@ private void initializeCommand() {
new BungeeCommandsRegistry(this, authPlugin);
}

private void initializeLimbo() {
Collection<LimboPluginHook> limboPluginHooks = Collections.singleton(new BungeeNanoLimboPluginHook(authPlugin.getConfig().getLimboPortRange()));
limboPluginHooks.stream()
.filter(LimboPluginHook::canHook)
.forEach(limboPluginHook -> authPlugin.putHook(LimboPluginHook.class, limboPluginHook));
}

private void initializeVk() {
authPlugin.putHook(VkPluginHook.class, new BungeeVkPluginHook());

Expand All @@ -70,7 +81,4 @@ public BungeeAudiences getBungeeAudiences() {
return bungeeAudiences;
}

public AuthPlugin getAuthPlugin() {
return authPlugin;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import java.util.stream.Collectors;

import com.bivashy.auth.api.AuthPlugin;
import com.bivashy.auth.api.hook.LimboPluginHook;
import com.bivashy.auth.api.server.ServerCore;
import com.bivashy.auth.api.server.bossbar.ServerBossbar;
import com.bivashy.auth.api.server.message.ServerComponent;
import com.bivashy.auth.api.server.player.ServerPlayer;
import com.bivashy.auth.api.server.proxy.limbo.LimboServerWrapper;
import com.bivashy.auth.api.server.scheduler.ServerScheduler;
import com.bivashy.auth.api.server.title.ServerTitle;

Expand All @@ -25,7 +25,6 @@
import me.mastercapexd.auth.bungee.player.BungeeServerPlayer;
import me.mastercapexd.auth.bungee.scheduler.BungeeSchedulerWrapper;
import me.mastercapexd.auth.bungee.server.BungeeServer;
import me.mastercapexd.auth.hooks.limbo.LimboHook;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
Expand Down Expand Up @@ -109,15 +108,9 @@ public ServerComponent componentLegacy(String legacy) {
@Override
public Optional<com.bivashy.auth.api.server.proxy.ProxyServer> serverFromName(String serverName) {
ServerInfo serverInfo = PROXY_SERVER.getServerInfo(serverName);
LimboHook limboHook = AuthPlugin.instance().getHook(LimboHook.class);
if (serverInfo == null && limboHook != null) {
if (!limboHook.isLimbo(serverName))
return Optional.empty();
LimboServerWrapper server = limboHook.createLimboWrapper(serverName);
if (!server.isExists())
return Optional.empty();
return Optional.of(server);
}
LimboPluginHook limboHook = AuthPlugin.instance().getHook(LimboPluginHook.class);
if (serverInfo == null && limboHook != null)
return Optional.of(limboHook.createServer(serverName));
return Optional.of(new BungeeServer(serverInfo));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

import com.bivashy.auth.api.server.bossbar.ServerBossbar;
import com.bivashy.auth.api.server.message.ServerComponent;
import com.bivashy.auth.api.server.player.ServerPlayer;
import com.google.common.collect.Sets;

import me.mastercapexd.auth.bungee.player.BungeeServerPlayer;
import net.md_5.bungee.protocol.packet.BossBar;

public class BungeeServerBossbar extends ServerBossbar {
private final Set<ServerPlayer> players = Sets.newHashSet();
private final Set<ServerPlayer> players = new HashSet<>();
private final UUID uuid = UUID.randomUUID();

public BungeeServerBossbar(ServerComponent component) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.bivashy.auth.api.AuthPlugin;
import com.bivashy.auth.api.account.Account;
import com.bivashy.auth.api.config.PluginConfig;
import com.bivashy.auth.api.config.message.MessageContext;
import com.bivashy.auth.api.model.PlayerIdSupplier;
import com.bivashy.auth.api.server.command.ServerCommandActor;
import com.bivashy.auth.api.server.player.ServerPlayer;
Expand Down Expand Up @@ -42,7 +43,7 @@ public BungeeCommandsRegistry(BungeeAuthPluginBootstrap pluginBootstrap, AuthPlu
String value = context.pop();
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(value);
if (player == null) {
throw new SendComponentException(config.getServerMessages().getMessage("player-offline"));
throw new SendComponentException(config.getServerMessages().getMessage("player-offline", MessageContext.of("%player_name%", value)));
}
return new ArgumentServerPlayer(new BungeeServerPlayer(player));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void senderNotConsole(CommandActor actor, SenderNotConsoleException excep

@Override
public void invalidPlayer(CommandActor actor, InvalidPlayerException exception) {
sendComponent(actor, messages.getMessage("player-offline", MessageContext.of("%player%", exception.getInput())));
sendComponent(actor, messages.getMessage("player-offline", MessageContext.of("%player_name%", exception.getInput())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package me.mastercapexd.auth.bungee.hooks.nanolimbo;

import java.net.SocketAddress;
import java.util.stream.IntStream;

import com.bivashy.auth.api.AuthPlugin;
import com.bivashy.auth.api.config.PluginConfig;
import com.bivashy.auth.api.hook.LimboPluginHook;

import me.mastercapexd.auth.bungee.BungeeAuthPluginBootstrap;
import me.mastercapexd.auth.bungee.server.BungeeServer;
import me.mastercapexd.auth.hooks.nanolimbo.NanoLimboProvider;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.event.ServerConnectEvent.Reason;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;

public class BungeeNanoLimboPluginHook implements LimboPluginHook, Listener {

private final int[] limboPorts;
private NanoLimboProvider provider;

public BungeeNanoLimboPluginHook(IntStream limboPortRange) {
this.limboPorts = limboPortRange.toArray();
if (!canHook())
return;
this.provider = new BungeeNanoLimboProvider(ProxyServer.getInstance().getPluginManager().getPlugin("NanoLimboBungee").getClass().getClassLoader());
ProxyServer.getInstance().getPluginManager().registerListener(BungeeAuthPluginBootstrap.getInstance(), this);
}

@Override
public com.bivashy.auth.api.server.proxy.ProxyServer createServer(String serverName) {
SocketAddress address = provider.findAvailableAddress(limboPorts).orElseThrow(
() -> new IllegalStateException("Cannot find available port for limbo server!"));
provider.createAndStartLimbo(address);
ServerInfo serverInfo = ProxyServer.getInstance().constructServerInfo(serverName, address, "", false);
ProxyServer.getInstance().getConfig().getServers().put(serverInfo.getName(), serverInfo);
return new BungeeServer(serverInfo);
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onServerChoose(ServerConnectEvent event) {
// TODO: Implement ServerConnectEvent in the InitialServerManagement
if (event.getReason() != Reason.JOIN_PROXY)
return;
PluginConfig config = AuthPlugin.instance().getConfig();
event.setTarget(config.findServerInfo(config.getAuthServers()).asProxyServer().as(BungeeServer.class).getServerInfo());
}

@Override
public boolean canHook() {
return ProxyServer.getInstance().getPluginManager().getPlugin("NanoLimboBungee") != null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.mastercapexd.auth.bungee.hooks.nanolimbo;

import me.mastercapexd.auth.hooks.nanolimbo.NanoLimboProvider;
import ua.nanit.limbo.server.data.InfoForwarding;

public class BungeeNanoLimboProvider implements NanoLimboProvider {

private final ClassLoader classLoader;

public BungeeNanoLimboProvider(ClassLoader classLoader) {
this.classLoader = classLoader;
}

@Override
public InfoForwarding createForwarding() {
return FORWARDING_FACTORY.legacy();
}

@Override
public ClassLoader classLoader() {
return classLoader;
}

}
5 changes: 4 additions & 1 deletion bungee/src/main/resources/bungee.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: mcAuth
main: me.mastercapexd.auth.bungee.BungeeAuthPluginBootstrap
version: ${project.version}
softDepends: [VK-API,JavaTelegramBotApi]
softDepends:
- VK-API
- JavaTelegramBotApi
- NanoLimboBungee
author: bivashy, MasterCapeXD
Loading

0 comments on commit 835285d

Please sign in to comment.