Skip to content

Commit 7192dcd

Browse files
author
games647
authored
Merge pull request #504 from InkerBot/main
Add SodionAuthBungee support
2 parents 9568556 + 2c3fd4a commit 7192dcd

File tree

11 files changed

+145
-24
lines changed

11 files changed

+145
-24
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Possible values: `Premium`, `Cracked`, `Unknown`
9090

9191
* [BungeeAuth](https://www.spigotmc.org/resources/bungeeauth.493/)
9292
* [BungeeAuthenticator](https://www.spigotmc.org/resources/bungeecordauthenticator.87669/)
93+
* [SodionAuth (2.0+)](https://github.com/Mohist-Community/SodionAuth)
9394

9495
## Network requests
9596

bukkit/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@
272272
<dependency>
273273
<groupId>com.github.Mohist-Community.SodionAuth</groupId>
274274
<artifactId>SodionAuth-Bukkit</artifactId>
275-
<version>b74392aa34</version>
275+
<version>2bdfdc854b</version>
276276
<exclusions>
277277
<exclusion>
278278
<groupId>com.github.Mohist-Community.SodionAuth</groupId>

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/SodionAuthHook.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
/**
3636
* GitHub: https://github.com/Mohist-Community/SodionAuth
3737
* <p>
38-
* Project page:
38+
* Project page: https://gitea.e-loli.com/SodionAuth/SodionAuth
3939
* <p>
4040
* Bukkit: Unknown
4141
* <p>
42-
* Spigot: Unknown
42+
* Spigot: https://www.spigotmc.org/resources/sodionauth.76944/
4343
*/
4444
public class SodionAuthHook implements AuthPlugin<Player> {
4545

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/DelayedAuthHook.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ private boolean registerHooks() {
9494

9595
private AuthPlugin<Player> getAuthHook() {
9696
try {
97-
@SuppressWarnings("unchecked")
9897
List<Class<? extends AuthPlugin<Player>>> hooks = Arrays.asList(AuthMeHook.class,
9998
CrazyLoginHook.class, LogItHook.class, LoginSecurityHook.class,
10099
SodionAuthHook.class, UltraAuthHook.class, xAuthHook.class);
101100

102101
for (Class<? extends AuthPlugin<Player>> clazz : hooks) {
103-
String pluginName = clazz.getSimpleName().replace("Hook", "");
102+
String pluginName = clazz.getSimpleName();
103+
pluginName = pluginName.substring(0, pluginName.length() - "Hook".length());
104104
//uses only member classes which uses AuthPlugin interface (skip interfaces)
105105
if (Bukkit.getPluginManager().isPluginEnabled(pluginName)) {
106106
//check only for enabled plugins. A single plugin could be disabled by plugin managers

bukkit/src/main/resources/plugin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ softdepend:
2323
# Auth plugins
2424
- AuthMe
2525
- LoginSecurity
26+
- SodionAuth
2627
- xAuth
2728
- LogIt
2829
- UltraAuth

bungee/pom.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@
9797
<id>spigotplugins-repo</id>
9898
<url>https://maven.gamestrike.de/mvn/</url>
9999
</repository>
100+
101+
<repository>
102+
<id>jitpack.io</id>
103+
<url>https://jitpack.io</url>
104+
<snapshots>
105+
<enabled>false</enabled>
106+
</snapshots>
107+
</repository>
100108
</repositories>
101109

102110
<dependencies>
@@ -138,5 +146,19 @@
138146
<version>0.0.2</version>
139147
<scope>provided</scope>
140148
</dependency>
149+
150+
<dependency>
151+
<groupId>com.github.Mohist-Community.SodionAuth</groupId>
152+
<artifactId>SodionAuth-Bungee</artifactId>
153+
<version>2bdfdc854b</version>
154+
<exclusions>
155+
<exclusion>
156+
<groupId>com.github.Mohist-Community.SodionAuth</groupId>
157+
<artifactId>SodionAuth-Libs</artifactId>
158+
</exclusion>
159+
</exclusions>
160+
<optional>true</optional>
161+
<scope>provided</scope>
162+
</dependency>
141163
</dependencies>
142164
</project>

bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
package com.github.games647.fastlogin.bungee;
2727

2828
import com.github.games647.fastlogin.bungee.hook.BungeeAuthHook;
29-
import com.github.games647.fastlogin.bungee.hook.BungeeCordAuthenticatorHook;
29+
import com.github.games647.fastlogin.bungee.hook.BungeeCordAuthenticatorBungeeHook;
30+
import com.github.games647.fastlogin.bungee.hook.SodionAuthHook;
3031
import com.github.games647.fastlogin.bungee.listener.ConnectListener;
3132
import com.github.games647.fastlogin.bungee.listener.PluginMessageListener;
3233
import com.github.games647.fastlogin.core.AsyncScheduler;
3334
import com.github.games647.fastlogin.core.CommonUtil;
35+
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
3436
import com.github.games647.fastlogin.core.message.ChangePremiumMessage;
3537
import com.github.games647.fastlogin.core.message.ChannelMessage;
3638
import com.github.games647.fastlogin.core.message.NamespaceKey;
@@ -43,6 +45,8 @@
4345
import com.google.common.util.concurrent.ThreadFactoryBuilder;
4446

4547
import java.nio.file.Path;
48+
import java.util.Arrays;
49+
import java.util.List;
4650
import java.util.concurrent.ConcurrentMap;
4751
import java.util.concurrent.ThreadFactory;
4852

@@ -55,6 +59,8 @@
5559
import net.md_5.bungee.api.plugin.PluginManager;
5660
import net.md_5.bungee.api.scheduler.GroupedThreadFactory;
5761

62+
import org.bukkit.Bukkit;
63+
import org.bukkit.entity.Player;
5864
import org.slf4j.Logger;
5965

6066
/**
@@ -110,16 +116,24 @@ public ConcurrentMap<PendingConnection, BungeeLoginSession> getSession() {
110116
}
111117

112118
private void registerHook() {
113-
Plugin BungeeAuth = getProxy().getPluginManager().getPlugin("BungeeAuth");
114-
if (BungeeAuth != null) {
115-
core.setAuthPluginHook(new BungeeAuthHook());
116-
logger.info("Hooked into BungeeAuth");
117-
}
118-
Plugin BungeeCordAuthenticatorBungee = getProxy().getPluginManager().getPlugin("BungeeCordAuthenticatorBungee");
119-
if (BungeeCordAuthenticatorBungee != null) {
120-
logger.info("Try to hook into BungeeCordAuthenticatorBungee...");
121-
BungeeCordAuthenticatorHook hook = new BungeeCordAuthenticatorHook(BungeeCordAuthenticatorBungee, logger);
122-
core.setAuthPluginHook(hook);
119+
try {
120+
List<Class<? extends AuthPlugin<ProxiedPlayer>>> hooks = Arrays.asList(
121+
BungeeAuthHook.class, BungeeCordAuthenticatorBungeeHook.class, SodionAuthHook.class);
122+
123+
for (Class<? extends AuthPlugin<ProxiedPlayer>> clazz : hooks) {
124+
String pluginName = clazz.getSimpleName();
125+
pluginName = pluginName.substring(0, pluginName.length() - "Hook".length());
126+
//uses only member classes which uses AuthPlugin interface (skip interfaces)
127+
Plugin plugin = getProxy().getPluginManager().getPlugin(pluginName);
128+
if (plugin != null) {
129+
logger.info("Hooking into auth plugin: {}", pluginName);
130+
core.setAuthPluginHook(
131+
clazz.getDeclaredConstructor(FastLoginBungee.class).newInstance(this));
132+
break;
133+
}
134+
}
135+
} catch (ReflectiveOperationException ex) {
136+
logger.error("Couldn't load the auth hook class", ex);
123137
}
124138
}
125139

bungee/src/main/java/com/github/games647/fastlogin/bungee/hook/BungeeAuthHook.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626
package com.github.games647.fastlogin.bungee.hook;
2727

28+
import com.github.games647.fastlogin.bungee.FastLoginBungee;
2829
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
2930

3031
import me.vik1395.BungeeAuth.Main;
@@ -43,6 +44,9 @@ public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
4344

4445
private final RequestHandler requestHandler = new RequestHandler();
4546

47+
public BungeeAuthHook(FastLoginBungee plugin) {
48+
}
49+
4650
@Override
4751
public boolean forceLogin(ProxiedPlayer player) {
4852
String playerName = player.getName();

bungee/src/main/java/com/github/games647/fastlogin/bungee/hook/BungeeCordAuthenticatorHook.java renamed to bungee/src/main/java/com/github/games647/fastlogin/bungee/hook/BungeeCordAuthenticatorBungeeHook.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@
2727

2828
import java.sql.SQLException;
2929

30+
import com.github.games647.fastlogin.bungee.FastLoginBungee;
3031
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
3132

32-
import org.slf4j.Logger;
33-
3433
import de.xxschrandxx.bca.bungee.BungeeCordAuthenticatorBungee;
3534
import de.xxschrandxx.bca.bungee.api.BungeeCordAuthenticatorBungeeAPI;
3635

3736
import net.md_5.bungee.api.connection.ProxiedPlayer;
38-
import net.md_5.bungee.api.plugin.Plugin;
3937

4038
/**
4139
* GitHub:
@@ -45,14 +43,14 @@
4543
*
4644
* Spigot: https://www.spigotmc.org/resources/bungeecordauthenticator.87669/
4745
*/
48-
public class BungeeCordAuthenticatorHook implements AuthPlugin<ProxiedPlayer> {
46+
public class BungeeCordAuthenticatorBungeeHook implements AuthPlugin<ProxiedPlayer> {
4947

5048
public final BungeeCordAuthenticatorBungeeAPI api;
5149

52-
public BungeeCordAuthenticatorHook(Plugin plugin, Logger logger) {
53-
BungeeCordAuthenticatorBungee bcab = (BungeeCordAuthenticatorBungee) plugin;
54-
api = bcab.getAPI();
55-
logger.info("BungeeCordAuthenticatorHook | Hooked successful!");
50+
public BungeeCordAuthenticatorBungeeHook(FastLoginBungee plugin) {
51+
api = ((BungeeCordAuthenticatorBungee) plugin.getProxy().getPluginManager()
52+
.getPlugin("BungeeCordAuthenticatorBungee")).getAPI();
53+
plugin.getLog().info("BungeeCordAuthenticatorHook | Hooked successful!");
5654
}
5755

5856
@Override
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2015-2021 <Your name and contributors>
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
* SOFTWARE.
25+
*/
26+
package com.github.games647.fastlogin.bungee.hook;
27+
28+
import com.github.games647.fastlogin.bungee.FastLoginBungee;
29+
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
30+
import net.md_5.bungee.api.connection.ProxiedPlayer;
31+
import red.mohist.sodionauth.bungee.implementation.BungeePlayer;
32+
import red.mohist.sodionauth.core.SodionAuthApi;
33+
import red.mohist.sodionauth.core.exception.AuthenticatedException;
34+
35+
import java.util.concurrent.ExecutionException;
36+
37+
/**
38+
* GitHub: https://github.com/Mohist-Community/SodionAuth
39+
* <p>
40+
* Project page: https://gitea.e-loli.com/SodionAuth/SodionAuth
41+
* <p>
42+
* Bukkit: Unknown
43+
* <p>
44+
* Spigot: https://www.spigotmc.org/resources/sodionauth.76944/
45+
*/
46+
public class SodionAuthHook implements AuthPlugin<ProxiedPlayer> {
47+
48+
private final FastLoginBungee plugin;
49+
50+
public SodionAuthHook(FastLoginBungee plugin) {
51+
this.plugin = plugin;
52+
}
53+
54+
@Override
55+
public boolean forceLogin(ProxiedPlayer player) {
56+
try {
57+
SodionAuthApi.login(new BungeePlayer(player));
58+
} catch (AuthenticatedException e) {
59+
plugin.getLog().warn(ALREADY_AUTHENTICATED, player);
60+
return false;
61+
}
62+
return true;
63+
}
64+
65+
@Override
66+
public boolean forceRegister(ProxiedPlayer player, String password) {
67+
try{
68+
return SodionAuthApi.register(new BungeePlayer(player), password);
69+
} catch (UnsupportedOperationException e){
70+
plugin.getLog().warn("Currently SodionAuth is not accepting forceRegister, " +
71+
"It may be caused by unsupported AuthBackend");
72+
return false;
73+
}
74+
}
75+
76+
@Override
77+
public boolean isRegistered(String playerName) {
78+
return SodionAuthApi.isRegistered(playerName);
79+
}
80+
}

0 commit comments

Comments
 (0)