Merge pull request #504 from InkerBot/main

Add SodionAuthBungee support
This commit is contained in:
games647
2021-04-07 10:48:56 +02:00
committed by GitHub
11 changed files with 145 additions and 24 deletions

View File

@@ -90,6 +90,7 @@ Possible values: `Premium`, `Cracked`, `Unknown`
* [BungeeAuth](https://www.spigotmc.org/resources/bungeeauth.493/) * [BungeeAuth](https://www.spigotmc.org/resources/bungeeauth.493/)
* [BungeeAuthenticator](https://www.spigotmc.org/resources/bungeecordauthenticator.87669/) * [BungeeAuthenticator](https://www.spigotmc.org/resources/bungeecordauthenticator.87669/)
* [SodionAuth (2.0+)](https://github.com/Mohist-Community/SodionAuth)
## Network requests ## Network requests

View File

@@ -272,7 +272,7 @@
<dependency> <dependency>
<groupId>com.github.Mohist-Community.SodionAuth</groupId> <groupId>com.github.Mohist-Community.SodionAuth</groupId>
<artifactId>SodionAuth-Bukkit</artifactId> <artifactId>SodionAuth-Bukkit</artifactId>
<version>b74392aa34</version> <version>2bdfdc854b</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>com.github.Mohist-Community.SodionAuth</groupId> <groupId>com.github.Mohist-Community.SodionAuth</groupId>

View File

@@ -35,11 +35,11 @@ import red.mohist.sodionauth.core.exception.AuthenticatedException;
/** /**
* GitHub: https://github.com/Mohist-Community/SodionAuth * GitHub: https://github.com/Mohist-Community/SodionAuth
* <p> * <p>
* Project page: * Project page: https://gitea.e-loli.com/SodionAuth/SodionAuth
* <p> * <p>
* Bukkit: Unknown * Bukkit: Unknown
* <p> * <p>
* Spigot: Unknown * Spigot: https://www.spigotmc.org/resources/sodionauth.76944/
*/ */
public class SodionAuthHook implements AuthPlugin<Player> { public class SodionAuthHook implements AuthPlugin<Player> {

View File

@@ -94,13 +94,13 @@ public class DelayedAuthHook implements Runnable {
private AuthPlugin<Player> getAuthHook() { private AuthPlugin<Player> getAuthHook() {
try { try {
@SuppressWarnings("unchecked")
List<Class<? extends AuthPlugin<Player>>> hooks = Arrays.asList(AuthMeHook.class, List<Class<? extends AuthPlugin<Player>>> hooks = Arrays.asList(AuthMeHook.class,
CrazyLoginHook.class, LogItHook.class, LoginSecurityHook.class, CrazyLoginHook.class, LogItHook.class, LoginSecurityHook.class,
SodionAuthHook.class, UltraAuthHook.class, xAuthHook.class); SodionAuthHook.class, UltraAuthHook.class, xAuthHook.class);
for (Class<? extends AuthPlugin<Player>> clazz : hooks) { for (Class<? extends AuthPlugin<Player>> clazz : hooks) {
String pluginName = clazz.getSimpleName().replace("Hook", ""); String pluginName = clazz.getSimpleName();
pluginName = pluginName.substring(0, pluginName.length() - "Hook".length());
//uses only member classes which uses AuthPlugin interface (skip interfaces) //uses only member classes which uses AuthPlugin interface (skip interfaces)
if (Bukkit.getPluginManager().isPluginEnabled(pluginName)) { if (Bukkit.getPluginManager().isPluginEnabled(pluginName)) {
//check only for enabled plugins. A single plugin could be disabled by plugin managers //check only for enabled plugins. A single plugin could be disabled by plugin managers

View File

@@ -23,6 +23,7 @@ softdepend:
# Auth plugins # Auth plugins
- AuthMe - AuthMe
- LoginSecurity - LoginSecurity
- SodionAuth
- xAuth - xAuth
- LogIt - LogIt
- UltraAuth - UltraAuth

View File

@@ -97,6 +97,14 @@
<id>spigotplugins-repo</id> <id>spigotplugins-repo</id>
<url>https://maven.gamestrike.de/mvn/</url> <url>https://maven.gamestrike.de/mvn/</url>
</repository> </repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@@ -138,5 +146,19 @@
<version>0.0.2</version> <version>0.0.2</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.github.Mohist-Community.SodionAuth</groupId>
<artifactId>SodionAuth-Bungee</artifactId>
<version>2bdfdc854b</version>
<exclusions>
<exclusion>
<groupId>com.github.Mohist-Community.SodionAuth</groupId>
<artifactId>SodionAuth-Libs</artifactId>
</exclusion>
</exclusions>
<optional>true</optional>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -26,11 +26,13 @@
package com.github.games647.fastlogin.bungee; package com.github.games647.fastlogin.bungee;
import com.github.games647.fastlogin.bungee.hook.BungeeAuthHook; import com.github.games647.fastlogin.bungee.hook.BungeeAuthHook;
import com.github.games647.fastlogin.bungee.hook.BungeeCordAuthenticatorHook; import com.github.games647.fastlogin.bungee.hook.BungeeCordAuthenticatorBungeeHook;
import com.github.games647.fastlogin.bungee.hook.SodionAuthHook;
import com.github.games647.fastlogin.bungee.listener.ConnectListener; import com.github.games647.fastlogin.bungee.listener.ConnectListener;
import com.github.games647.fastlogin.bungee.listener.PluginMessageListener; import com.github.games647.fastlogin.bungee.listener.PluginMessageListener;
import com.github.games647.fastlogin.core.AsyncScheduler; import com.github.games647.fastlogin.core.AsyncScheduler;
import com.github.games647.fastlogin.core.CommonUtil; import com.github.games647.fastlogin.core.CommonUtil;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import com.github.games647.fastlogin.core.message.ChangePremiumMessage; import com.github.games647.fastlogin.core.message.ChangePremiumMessage;
import com.github.games647.fastlogin.core.message.ChannelMessage; import com.github.games647.fastlogin.core.message.ChannelMessage;
import com.github.games647.fastlogin.core.message.NamespaceKey; import com.github.games647.fastlogin.core.message.NamespaceKey;
@@ -43,6 +45,8 @@ import com.google.common.io.ByteStreams;
import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
@@ -55,6 +59,8 @@ import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.PluginManager; import net.md_5.bungee.api.plugin.PluginManager;
import net.md_5.bungee.api.scheduler.GroupedThreadFactory; import net.md_5.bungee.api.scheduler.GroupedThreadFactory;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.slf4j.Logger; import org.slf4j.Logger;
/** /**
@@ -110,16 +116,24 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin<CommandSen
} }
private void registerHook() { private void registerHook() {
Plugin BungeeAuth = getProxy().getPluginManager().getPlugin("BungeeAuth"); try {
if (BungeeAuth != null) { List<Class<? extends AuthPlugin<ProxiedPlayer>>> hooks = Arrays.asList(
core.setAuthPluginHook(new BungeeAuthHook()); BungeeAuthHook.class, BungeeCordAuthenticatorBungeeHook.class, SodionAuthHook.class);
logger.info("Hooked into BungeeAuth");
for (Class<? extends AuthPlugin<ProxiedPlayer>> clazz : hooks) {
String pluginName = clazz.getSimpleName();
pluginName = pluginName.substring(0, pluginName.length() - "Hook".length());
//uses only member classes which uses AuthPlugin interface (skip interfaces)
Plugin plugin = getProxy().getPluginManager().getPlugin(pluginName);
if (plugin != null) {
logger.info("Hooking into auth plugin: {}", pluginName);
core.setAuthPluginHook(
clazz.getDeclaredConstructor(FastLoginBungee.class).newInstance(this));
break;
} }
Plugin BungeeCordAuthenticatorBungee = getProxy().getPluginManager().getPlugin("BungeeCordAuthenticatorBungee"); }
if (BungeeCordAuthenticatorBungee != null) { } catch (ReflectiveOperationException ex) {
logger.info("Try to hook into BungeeCordAuthenticatorBungee..."); logger.error("Couldn't load the auth hook class", ex);
BungeeCordAuthenticatorHook hook = new BungeeCordAuthenticatorHook(BungeeCordAuthenticatorBungee, logger);
core.setAuthPluginHook(hook);
} }
} }

View File

@@ -25,6 +25,7 @@
*/ */
package com.github.games647.fastlogin.bungee.hook; package com.github.games647.fastlogin.bungee.hook;
import com.github.games647.fastlogin.bungee.FastLoginBungee;
import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import me.vik1395.BungeeAuth.Main; import me.vik1395.BungeeAuth.Main;
@@ -43,6 +44,9 @@ public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
private final RequestHandler requestHandler = new RequestHandler(); private final RequestHandler requestHandler = new RequestHandler();
public BungeeAuthHook(FastLoginBungee plugin) {
}
@Override @Override
public boolean forceLogin(ProxiedPlayer player) { public boolean forceLogin(ProxiedPlayer player) {
String playerName = player.getName(); String playerName = player.getName();

View File

@@ -27,15 +27,13 @@ package com.github.games647.fastlogin.bungee.hook;
import java.sql.SQLException; import java.sql.SQLException;
import com.github.games647.fastlogin.bungee.FastLoginBungee;
import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import org.slf4j.Logger;
import de.xxschrandxx.bca.bungee.BungeeCordAuthenticatorBungee; import de.xxschrandxx.bca.bungee.BungeeCordAuthenticatorBungee;
import de.xxschrandxx.bca.bungee.api.BungeeCordAuthenticatorBungeeAPI; import de.xxschrandxx.bca.bungee.api.BungeeCordAuthenticatorBungeeAPI;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Plugin;
/** /**
* GitHub: * GitHub:
@@ -45,14 +43,14 @@ import net.md_5.bungee.api.plugin.Plugin;
* *
* Spigot: https://www.spigotmc.org/resources/bungeecordauthenticator.87669/ * Spigot: https://www.spigotmc.org/resources/bungeecordauthenticator.87669/
*/ */
public class BungeeCordAuthenticatorHook implements AuthPlugin<ProxiedPlayer> { public class BungeeCordAuthenticatorBungeeHook implements AuthPlugin<ProxiedPlayer> {
public final BungeeCordAuthenticatorBungeeAPI api; public final BungeeCordAuthenticatorBungeeAPI api;
public BungeeCordAuthenticatorHook(Plugin plugin, Logger logger) { public BungeeCordAuthenticatorBungeeHook(FastLoginBungee plugin) {
BungeeCordAuthenticatorBungee bcab = (BungeeCordAuthenticatorBungee) plugin; api = ((BungeeCordAuthenticatorBungee) plugin.getProxy().getPluginManager()
api = bcab.getAPI(); .getPlugin("BungeeCordAuthenticatorBungee")).getAPI();
logger.info("BungeeCordAuthenticatorHook | Hooked successful!"); plugin.getLog().info("BungeeCordAuthenticatorHook | Hooked successful!");
} }
@Override @Override

View File

@@ -0,0 +1,80 @@
/*
* SPDX-License-Identifier: MIT
*
* The MIT License (MIT)
*
* Copyright (c) 2015-2021 <Your name and contributors>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.games647.fastlogin.bungee.hook;
import com.github.games647.fastlogin.bungee.FastLoginBungee;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import red.mohist.sodionauth.bungee.implementation.BungeePlayer;
import red.mohist.sodionauth.core.SodionAuthApi;
import red.mohist.sodionauth.core.exception.AuthenticatedException;
import java.util.concurrent.ExecutionException;
/**
* GitHub: https://github.com/Mohist-Community/SodionAuth
* <p>
* Project page: https://gitea.e-loli.com/SodionAuth/SodionAuth
* <p>
* Bukkit: Unknown
* <p>
* Spigot: https://www.spigotmc.org/resources/sodionauth.76944/
*/
public class SodionAuthHook implements AuthPlugin<ProxiedPlayer> {
private final FastLoginBungee plugin;
public SodionAuthHook(FastLoginBungee plugin) {
this.plugin = plugin;
}
@Override
public boolean forceLogin(ProxiedPlayer player) {
try {
SodionAuthApi.login(new BungeePlayer(player));
} catch (AuthenticatedException e) {
plugin.getLog().warn(ALREADY_AUTHENTICATED, player);
return false;
}
return true;
}
@Override
public boolean forceRegister(ProxiedPlayer player, String password) {
try{
return SodionAuthApi.register(new BungeePlayer(player), password);
} catch (UnsupportedOperationException e){
plugin.getLog().warn("Currently SodionAuth is not accepting forceRegister, " +
"It may be caused by unsupported AuthBackend");
return false;
}
}
@Override
public boolean isRegistered(String playerName) {
return SodionAuthApi.isRegistered(playerName);
}
}

View File

@@ -12,6 +12,7 @@ softDepends:
# BungeeCord auth plugins # BungeeCord auth plugins
- BungeeAuth - BungeeAuth
- BungeeCordAuthenticatorBungee - BungeeCordAuthenticatorBungee
- SodionAuth
description: | description: |
${project.description} ${project.description}