Bungeecord support added
This commit is contained in:
parent
681de108a1
commit
f5569b2346
73
bungee/pom.xml
Normal file
73
bungee/pom.xml
Normal file
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.alterdekim.xcraft.auth</groupId>
|
||||
<artifactId>xcraft-auth</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bungeecord-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<artifactId>bungee</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>${bungee.api.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alterdekim.xcraft.auth</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.36</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,84 @@
|
||||
package com.alterdekim.xcraft.auth.bungee;
|
||||
|
||||
import com.alterdekim.xcraft.auth.SaltNic;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import static com.alterdekim.xcraft.auth.lib.Patcher.patchAuthLib;
|
||||
|
||||
public class XCraft extends Plugin {
|
||||
|
||||
private static SaltNic server = null;
|
||||
|
||||
public static int SERVER_PORT = 8999;
|
||||
public static int INTERNAL_PORT = 8999;
|
||||
public static String PUBLIC_DOMAIN = "localhost";
|
||||
public static Boolean USE_HTTPS = false;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
try {
|
||||
Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
|
||||
SERVER_PORT = config.getInt("public_port");
|
||||
INTERNAL_PORT = config.getInt("internal_port");
|
||||
PUBLIC_DOMAIN = config.getString("public_domain");
|
||||
USE_HTTPS = config.getBoolean("use_https");
|
||||
} catch (IOException e) {
|
||||
getLogger().info("No config file present");
|
||||
makeConfig();
|
||||
}
|
||||
if( server == null ) {
|
||||
try {
|
||||
getLogger().info("Starting SaltNic server...");
|
||||
server = new SaltNic(getLogger(), INTERNAL_PORT, USE_HTTPS, PUBLIC_DOMAIN, SERVER_PORT);
|
||||
} catch (IOException e) {
|
||||
getLogger().severe("Failed to start SaltNic server: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
getLogger().info("Patching AuthLib URLs...");
|
||||
while(true) {
|
||||
try {
|
||||
patchAuthLib(getLogger(), INTERNAL_PORT);
|
||||
getLogger().info("AuthLib URLs patched successfully!");
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
getLogger().severe("Failed to patch AuthLib: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (server != null) {
|
||||
server.stop();
|
||||
getLogger().info("SaltNic session server stopped.");
|
||||
server = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void makeConfig() {
|
||||
if (!getDataFolder().exists()) {
|
||||
getDataFolder().mkdir();
|
||||
}
|
||||
|
||||
File file = new File(getDataFolder(), "config.yml");
|
||||
|
||||
|
||||
if (!file.exists()) {
|
||||
try (InputStream in = getResourceAsStream("config.yml")) {
|
||||
Files.copy(in, file.toPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
5
bungee/src/main/resources/bungee.yml
Normal file
5
bungee/src/main/resources/bungee.yml
Normal file
@ -0,0 +1,5 @@
|
||||
name: XCraftAuth
|
||||
main: com.alterdekim.xcraft.auth.bungee.XCraft
|
||||
version: 1.0
|
||||
author: Michael Wain
|
||||
description: XCraft authentication system for Spigot
|
43
common/pom.xml
Normal file
43
common/pom.xml
Normal file
@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.alterdekim.xcraft.auth</groupId>
|
||||
<artifactId>xcraft-auth</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>common</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.nanohttpd</groupId>
|
||||
<artifactId>nanohttpd</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mindrot</groupId>
|
||||
<artifactId>jbcrypt</artifactId>
|
||||
<version>0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jsoniter</groupId>
|
||||
<artifactId>jsoniter</artifactId>
|
||||
<version>0.9.23</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapdb</groupId>
|
||||
<artifactId>mapdb</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.36</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -22,8 +22,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static com.alterdekim.xcraft.auth.XCraft.*;
|
||||
|
||||
public class SaltNic extends NanoHTTPD {
|
||||
|
||||
private final Logger logger;
|
||||
@ -36,13 +34,20 @@ public class SaltNic extends NanoHTTPD {
|
||||
private static final String CAPE_DIRECTORY = "plugins/XCraftAuth/capes";
|
||||
private static final int MAX_FILE_SIZE = 1024 * 1024;
|
||||
|
||||
public SaltNic(Logger logger) throws IOException {
|
||||
super(INTERNAL_PORT);
|
||||
private final boolean USE_HTTPS;
|
||||
private final String PUBLIC_DOMAIN;
|
||||
private final int SERVER_PORT;
|
||||
|
||||
public SaltNic(Logger logger, int internal_port, boolean use_https, String public_domain, int server_port) throws IOException {
|
||||
super(internal_port);
|
||||
this.logger = logger;
|
||||
this.USE_HTTPS = use_https;
|
||||
this.PUBLIC_DOMAIN = public_domain;
|
||||
this.SERVER_PORT = server_port;
|
||||
this.storage = new UserStorage();
|
||||
this.sessions = new ConcurrentHashMap<>();
|
||||
start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
|
||||
logger.info("SaltNic session server started on http://localhost:"+INTERNAL_PORT);
|
||||
logger.info("SaltNic session server started on http://localhost:"+ internal_port);
|
||||
}
|
||||
|
||||
@Override
|
@ -0,0 +1,28 @@
|
||||
package com.alterdekim.xcraft.auth.lib;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.URL;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Patcher {
|
||||
|
||||
public static void patchAuthLib(Logger logger, int internal_port) throws Exception {
|
||||
Class<?> clazz = Class.forName("com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService");
|
||||
modifyFinalField(clazz, "BASE_URL", "http://localhost:"+internal_port+"/api/", logger);
|
||||
modifyFinalField(clazz, "JOIN_URL", new URL("http://localhost:"+internal_port+"/api/join"), logger);
|
||||
modifyFinalField(clazz, "CHECK_URL", new URL("http://localhost:"+internal_port+"/api/hasJoined"), logger);
|
||||
}
|
||||
|
||||
private static void modifyFinalField(Class<?> clazz, String fieldName, Object newValue, Logger logger) throws Exception {
|
||||
Field field = clazz.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
field.set(null, newValue);
|
||||
logger.info(fieldName + " patched to: " + newValue);
|
||||
}
|
||||
}
|
88
pom.xml
88
pom.xml
@ -7,89 +7,19 @@
|
||||
<groupId>com.alterdekim.xcraft.auth</groupId>
|
||||
<artifactId>xcraft-auth</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>common</module>
|
||||
<module>spigot</module>
|
||||
<module>bungee</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spigot.api.version>1.12.2-R0.1-SNAPSHOT</spigot.api.version>
|
||||
<bungee.api.version>1.12-SNAPSHOT</bungee.api.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.nanohttpd</groupId>
|
||||
<artifactId>nanohttpd</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mindrot</groupId>
|
||||
<artifactId>jbcrypt</artifactId>
|
||||
<version>0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jsoniter</groupId>
|
||||
<artifactId>jsoniter</artifactId>
|
||||
<version>0.9.23</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.36</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapdb</groupId>
|
||||
<artifactId>mapdb</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.36</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
73
spigot/pom.xml
Normal file
73
spigot/pom.xml
Normal file
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.alterdekim.xcraft.auth</groupId>
|
||||
<artifactId>xcraft-auth</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<artifactId>spigot</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>${spigot.api.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alterdekim.xcraft.auth</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.36</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -1,6 +1,7 @@
|
||||
package com.alterdekim.xcraft.auth;
|
||||
package com.alterdekim.xcraft.auth.spigot;
|
||||
|
||||
|
||||
import com.alterdekim.xcraft.auth.SaltNic;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -8,6 +9,8 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.URL;
|
||||
|
||||
import static com.alterdekim.xcraft.auth.lib.Patcher.patchAuthLib;
|
||||
|
||||
public class XCraft extends JavaPlugin {
|
||||
|
||||
private static SaltNic server = null;
|
||||
@ -27,7 +30,7 @@ public class XCraft extends JavaPlugin {
|
||||
INTERNAL_PORT = getConfig().getInt("internal_port");
|
||||
PUBLIC_DOMAIN = getConfig().getString("public_domain");
|
||||
USE_HTTPS = getConfig().getBoolean("use_https");
|
||||
server = new SaltNic(getLogger());
|
||||
server = new SaltNic(getLogger(), INTERNAL_PORT, USE_HTTPS, PUBLIC_DOMAIN, SERVER_PORT);
|
||||
} catch (IOException e) {
|
||||
getLogger().severe("Failed to start SaltNic server: " + e.getMessage());
|
||||
}
|
||||
@ -35,7 +38,7 @@ public class XCraft extends JavaPlugin {
|
||||
getLogger().info("Patching AuthLib URLs...");
|
||||
while(true) {
|
||||
try {
|
||||
patchAuthLib();
|
||||
patchAuthLib(getLogger(), INTERNAL_PORT);
|
||||
getLogger().info("AuthLib URLs patched successfully!");
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
@ -45,25 +48,6 @@ public class XCraft extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private void patchAuthLib() throws Exception {
|
||||
Class<?> clazz = Class.forName("com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService");
|
||||
modifyFinalField(clazz, "BASE_URL", "http://localhost:"+INTERNAL_PORT+"/api/");
|
||||
modifyFinalField(clazz, "JOIN_URL", new URL("http://localhost:"+INTERNAL_PORT+"/api/join"));
|
||||
modifyFinalField(clazz, "CHECK_URL", new URL("http://localhost:"+INTERNAL_PORT+"/api/hasJoined"));
|
||||
}
|
||||
|
||||
private void modifyFinalField(Class<?> clazz, String fieldName, Object newValue) throws Exception {
|
||||
Field field = clazz.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
field.set(null, newValue);
|
||||
getLogger().info(fieldName + " patched to: " + newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (server != null) {
|
4
spigot/src/main/resources/config.yml
Normal file
4
spigot/src/main/resources/config.yml
Normal file
@ -0,0 +1,4 @@
|
||||
public_domain: "localhost"
|
||||
public_port: 8999
|
||||
internal_port: 8999
|
||||
use_https: false
|
6
spigot/src/main/resources/plugin.yml
Normal file
6
spigot/src/main/resources/plugin.yml
Normal file
@ -0,0 +1,6 @@
|
||||
name: XCraftAuth
|
||||
main: com.alterdekim.xcraft.auth.spigot.XCraft
|
||||
version: 1.0
|
||||
author: Michael Wain
|
||||
api-version: 1.12.2
|
||||
description: XCraft authentication system for Spigot
|
@ -1,6 +0,0 @@
|
||||
name: XCraftAuth
|
||||
main: com.alterdekim.xcraft.auth.XCraft
|
||||
version: 1.0
|
||||
author: Michael Wain
|
||||
api-version: 1.12.2
|
||||
description: XCraft authentication system for Spigot
|
Loading…
x
Reference in New Issue
Block a user