-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add LimboPluginHook * Deprecate LimboServerWrapper * Soft depend on NanoLimboPlugin * Add NanoLimboPluginHook * Add VelocityNanoLimboPluginHook * Add dependencies for NanoLimboPlugin in velocity module pom.xml * Implement PluginHook in LimboPluginHook * Replace NanoLimboPluginHook with NanoLimboProvider * Add BungeeNanoLimboPluginHook * Add NanoLimbo as dependency in bungee pom.xml * Implement LimboPluginHook in LimboAPIHook * Properly implement LimboAPIHook#canHook * Remove redundant LimboHook * Use LimboPluginHook in ServerCore implementations * Create limbo-port in config.yml * Hook into NanoLimboPlugin if possible * Reuse IntStream in NanoLimboPluginHook * Define proper ClassLoader for NanoLimboProvider * Define limbo as initial server in velocity if required * Remove unused import statement * Define initial server on proxy joining * Remove LimboAPI support * Define initial server on proxy joining in velocity
- Loading branch information
Showing
29 changed files
with
551 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
api/src/main/java/com/bivashy/auth/api/hook/LimboPluginHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
.../src/main/java/me/mastercapexd/auth/bungee/hooks/nanolimbo/BungeeNanoLimboPluginHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...ee/src/main/java/me/mastercapexd/auth/bungee/hooks/nanolimbo/BungeeNanoLimboProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
core/src/main/java/me/mastercapexd/auth/hooks/limbo/LimboHook.java
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
core/src/main/java/me/mastercapexd/auth/hooks/nanolimbo/InfoForwardingFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package me.mastercapexd.auth.hooks.nanolimbo; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
|
||
import ua.nanit.limbo.server.data.InfoForwarding; | ||
import ua.nanit.limbo.server.data.InfoForwarding.Type; | ||
|
||
// Class for hiding InfoForwarding dirty way initialization | ||
public class InfoForwardingFactory { | ||
|
||
public InfoForwarding none() { | ||
Map<String, Object> map = Collections.singletonMap("type", Type.NONE); | ||
return createForwarding(map); | ||
} | ||
|
||
public InfoForwarding legacy() { | ||
Map<String, Object> map = Collections.singletonMap("type", Type.LEGACY); | ||
return createForwarding(map); | ||
} | ||
|
||
public InfoForwarding modern(byte[] secretKey) { | ||
Map<String, Object> map = new HashMap<>(); | ||
map.put("type", Type.MODERN); | ||
map.put("secretKey", secretKey); | ||
return createForwarding(map); | ||
} | ||
|
||
public InfoForwarding bungeeGuard(Collection<String> tokens) { | ||
Map<String, Object> map = new HashMap<>(); | ||
map.put("type", Type.BUNGEE_GUARD); | ||
map.put("tokens", new ArrayList<>(tokens)); | ||
return createForwarding(map); | ||
} | ||
|
||
private InfoForwarding createForwarding(Map<String, Object> map) { | ||
InfoForwarding forwarding = new InfoForwarding(); | ||
for (Entry<String, Object> entry : map.entrySet()) { | ||
Class<?> clazz = forwarding.getClass(); | ||
try { | ||
Field field = clazz.getDeclaredField(entry.getKey()); | ||
field.setAccessible(true); | ||
field.set(forwarding, entry.getValue()); | ||
} catch (NoSuchFieldException | IllegalAccessException ignored) { | ||
} | ||
} | ||
return forwarding; | ||
} | ||
|
||
} |
Oops, something went wrong.