From ea894b3a7b64236c52f405b3c5f7204704ed8b49 Mon Sep 17 00:00:00 2001 From: InkerBot <2924657226@qq.com> Date: Tue, 6 Apr 2021 00:31:17 +0800 Subject: [PATCH] Add SodionAuthBungee hook --- README.md | 1 + bungee/pom.xml | 22 +++++ .../fastlogin/bungee/FastLoginBungee.java | 8 ++ .../fastlogin/bungee/hook/SodionAuthHook.java | 81 +++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 bungee/src/main/java/com/github/games647/fastlogin/bungee/hook/SodionAuthHook.java diff --git a/README.md b/README.md index f9a4dee5..683822d2 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ Possible values: `Premium`, `Cracked`, `Unknown` * [BungeeAuth](https://www.spigotmc.org/resources/bungeeauth.493/) * [BungeeAuthenticator](https://www.spigotmc.org/resources/bungeecordauthenticator.87669/) +* [SodionAuth (2.0+)](https://github.com/Mohist-Community/SodionAuth) ## Network requests diff --git a/bungee/pom.xml b/bungee/pom.xml index 74a68857..410da12e 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -97,6 +97,14 @@ spigotplugins-repo https://maven.gamestrike.de/mvn/ + + + jitpack.io + https://jitpack.io + + false + + @@ -138,5 +146,19 @@ 0.0.2 provided + + + com.github.Mohist-Community.SodionAuth + SodionAuth-Bungee + 3a71c7f936 + + + com.github.Mohist-Community.SodionAuth + SodionAuth-Libs + + + true + provided + diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java index bfb60eba..3c1410da 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java @@ -27,6 +27,7 @@ package com.github.games647.fastlogin.bungee; import com.github.games647.fastlogin.bungee.hook.BungeeAuthHook; import com.github.games647.fastlogin.bungee.hook.BungeeCordAuthenticatorHook; +import com.github.games647.fastlogin.bungee.hook.SodionAuthHook; import com.github.games647.fastlogin.bungee.listener.ConnectListener; import com.github.games647.fastlogin.bungee.listener.PluginMessageListener; import com.github.games647.fastlogin.core.AsyncScheduler; @@ -121,6 +122,13 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin + * + * 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 + *

+ * Project page: https://gitea.e-loli.com/SodionAuth/SodionAuth + *

+ * Bukkit: Unknown + *

+ * Spigot: https://www.spigotmc.org/resources/sodionauth.76944/ + */ +public class SodionAuthHook implements AuthPlugin { + + 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; + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + return false; + } + } + public boolean isRegistered(String playerName) { + return SodionAuthApi.isRegistered(playerName); + } +}