mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[ANY] IDEA Code Reformat
This commit is contained in:
parent
a2b3ac523b
commit
9884730b1b
141 changed files with 1277 additions and 1529 deletions
|
@ -1,42 +1,7 @@
|
||||||
package ru.gravit.launchserver;
|
package ru.gravit.launchserver;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.ProcessBuilder.Redirect;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.SocketAddress;
|
|
||||||
import java.nio.file.DirectoryStream;
|
|
||||||
import java.nio.file.FileVisitResult;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.SimpleFileVisitor;
|
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
|
||||||
import java.security.KeyPair;
|
|
||||||
import java.security.interfaces.RSAPrivateKey;
|
|
||||||
import java.security.interfaces.RSAPublicKey;
|
|
||||||
import java.security.spec.InvalidKeySpecException;
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.zip.CRC32;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
import ru.gravit.launcher.Launcher;
|
import ru.gravit.launcher.Launcher;
|
||||||
import ru.gravit.launcher.LauncherConfig;
|
import ru.gravit.launcher.LauncherConfig;
|
||||||
import ru.gravit.launcher.hasher.HashedDir;
|
import ru.gravit.launcher.hasher.HashedDir;
|
||||||
|
@ -52,24 +17,12 @@
|
||||||
import ru.gravit.launchserver.auth.permissions.PermissionsHandler;
|
import ru.gravit.launchserver.auth.permissions.PermissionsHandler;
|
||||||
import ru.gravit.launchserver.auth.provider.AuthProvider;
|
import ru.gravit.launchserver.auth.provider.AuthProvider;
|
||||||
import ru.gravit.launchserver.auth.provider.RejectAuthProvider;
|
import ru.gravit.launchserver.auth.provider.RejectAuthProvider;
|
||||||
import ru.gravit.launchserver.binary.EXEL4JLauncherBinary;
|
import ru.gravit.launchserver.binary.*;
|
||||||
import ru.gravit.launchserver.binary.EXELauncherBinary;
|
|
||||||
import ru.gravit.launchserver.binary.JARLauncherBinary;
|
|
||||||
import ru.gravit.launchserver.binary.LauncherBinary;
|
|
||||||
import ru.gravit.launchserver.binary.ProguardConf;
|
|
||||||
import ru.gravit.launchserver.command.handler.CommandHandler;
|
import ru.gravit.launchserver.command.handler.CommandHandler;
|
||||||
import ru.gravit.launchserver.command.handler.JLineCommandHandler;
|
import ru.gravit.launchserver.command.handler.JLineCommandHandler;
|
||||||
import ru.gravit.launchserver.command.handler.StdCommandHandler;
|
import ru.gravit.launchserver.command.handler.StdCommandHandler;
|
||||||
import ru.gravit.launchserver.config.AuthHandlerAdapter;
|
import ru.gravit.launchserver.config.*;
|
||||||
import ru.gravit.launchserver.config.AuthProviderAdapter;
|
import ru.gravit.launchserver.manangers.*;
|
||||||
import ru.gravit.launchserver.config.HWIDHandlerAdapter;
|
|
||||||
import ru.gravit.launchserver.config.PermissionsHandlerAdapter;
|
|
||||||
import ru.gravit.launchserver.config.TextureProviderAdapter;
|
|
||||||
import ru.gravit.launchserver.manangers.MirrorManager;
|
|
||||||
import ru.gravit.launchserver.manangers.ModulesManager;
|
|
||||||
import ru.gravit.launchserver.manangers.ReconfigurableManager;
|
|
||||||
import ru.gravit.launchserver.manangers.ReloadManager;
|
|
||||||
import ru.gravit.launchserver.manangers.SessionManager;
|
|
||||||
import ru.gravit.launchserver.manangers.hook.AuthHookManager;
|
import ru.gravit.launchserver.manangers.hook.AuthHookManager;
|
||||||
import ru.gravit.launchserver.manangers.hook.BuildHookManager;
|
import ru.gravit.launchserver.manangers.hook.BuildHookManager;
|
||||||
import ru.gravit.launchserver.manangers.hook.SocketHookManager;
|
import ru.gravit.launchserver.manangers.hook.SocketHookManager;
|
||||||
|
@ -77,16 +30,32 @@
|
||||||
import ru.gravit.launchserver.socket.ServerSocketHandler;
|
import ru.gravit.launchserver.socket.ServerSocketHandler;
|
||||||
import ru.gravit.launchserver.texture.RequestTextureProvider;
|
import ru.gravit.launchserver.texture.RequestTextureProvider;
|
||||||
import ru.gravit.launchserver.texture.TextureProvider;
|
import ru.gravit.launchserver.texture.TextureProvider;
|
||||||
import ru.gravit.utils.helper.CommonHelper;
|
import ru.gravit.utils.helper.*;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
|
||||||
import ru.gravit.utils.helper.JVMHelper;
|
import java.io.BufferedReader;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import java.io.BufferedWriter;
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import java.io.File;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import java.io.IOException;
|
||||||
|
import java.lang.ProcessBuilder.Redirect;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.nio.file.*;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.security.KeyPair;
|
||||||
|
import java.security.interfaces.RSAPrivateKey;
|
||||||
|
import java.security.interfaces.RSAPublicKey;
|
||||||
|
import java.security.spec.InvalidKeySpecException;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.zip.CRC32;
|
||||||
|
|
||||||
public final class LaunchServer implements Runnable {
|
public final class LaunchServer implements Runnable {
|
||||||
public static final class Config {
|
public static final class Config {
|
||||||
public int port;
|
public int port;
|
||||||
|
|
||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
|
@ -95,7 +64,7 @@ public static final class Config {
|
||||||
public String projectName;
|
public String projectName;
|
||||||
|
|
||||||
public String[] mirrors;
|
public String[] mirrors;
|
||||||
|
|
||||||
public String binaryName;
|
public String binaryName;
|
||||||
|
|
||||||
public LauncherConfig.LauncherEnvironment env;
|
public LauncherConfig.LauncherEnvironment env;
|
||||||
|
@ -104,7 +73,7 @@ public static final class Config {
|
||||||
|
|
||||||
public AuthProvider[] authProvider;
|
public AuthProvider[] authProvider;
|
||||||
|
|
||||||
public AuthHandler authHandler;
|
public AuthHandler authHandler;
|
||||||
|
|
||||||
public PermissionsHandler permissionsHandler;
|
public PermissionsHandler permissionsHandler;
|
||||||
|
|
||||||
|
@ -138,10 +107,10 @@ public static final class Config {
|
||||||
public boolean isWarningMissArchJava;
|
public boolean isWarningMissArchJava;
|
||||||
public boolean enabledProGuard;
|
public boolean enabledProGuard;
|
||||||
public boolean stripLineNumbers;
|
public boolean stripLineNumbers;
|
||||||
public boolean deleteTempFiles;
|
public boolean deleteTempFiles;
|
||||||
public boolean enableRcon;
|
public boolean enableRcon;
|
||||||
|
|
||||||
public String startScript;
|
public String startScript;
|
||||||
|
|
||||||
|
|
||||||
public String getAddress() {
|
public String getAddress() {
|
||||||
|
@ -178,24 +147,19 @@ public void setAddress(String address) {
|
||||||
|
|
||||||
public void verify() {
|
public void verify() {
|
||||||
VerifyHelper.verify(getAddress(), VerifyHelper.NOT_EMPTY, "LaunchServer address can't be empty");
|
VerifyHelper.verify(getAddress(), VerifyHelper.NOT_EMPTY, "LaunchServer address can't be empty");
|
||||||
if(authHandler == null)
|
if (authHandler == null) {
|
||||||
{
|
|
||||||
throw new NullPointerException("AuthHandler must not be null");
|
throw new NullPointerException("AuthHandler must not be null");
|
||||||
}
|
}
|
||||||
if(authProvider == null || authProvider[0] == null)
|
if (authProvider == null || authProvider[0] == null) {
|
||||||
{
|
|
||||||
throw new NullPointerException("AuthProvider must not be null");
|
throw new NullPointerException("AuthProvider must not be null");
|
||||||
}
|
}
|
||||||
if(textureProvider == null)
|
if (textureProvider == null) {
|
||||||
{
|
|
||||||
throw new NullPointerException("TextureProvider must not be null");
|
throw new NullPointerException("TextureProvider must not be null");
|
||||||
}
|
}
|
||||||
if(permissionsHandler == null)
|
if (permissionsHandler == null) {
|
||||||
{
|
|
||||||
throw new NullPointerException("PermissionsHandler must not be null");
|
throw new NullPointerException("PermissionsHandler must not be null");
|
||||||
}
|
}
|
||||||
if(env == null)
|
if (env == null) {
|
||||||
{
|
|
||||||
throw new NullPointerException("Env must not be null");
|
throw new NullPointerException("Env must not be null");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,7 +193,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
||||||
// Read profile
|
// Read profile
|
||||||
ClientProfile profile;
|
ClientProfile profile;
|
||||||
try (BufferedReader reader = IOHelper.newReader(file)) {
|
try (BufferedReader reader = IOHelper.newReader(file)) {
|
||||||
profile = Launcher.gson.fromJson(reader,ClientProfile.class);
|
profile = Launcher.gson.fromJson(reader, ClientProfile.class);
|
||||||
}
|
}
|
||||||
profile.verify();
|
profile.verify();
|
||||||
|
|
||||||
|
@ -262,10 +226,10 @@ public static void main(String... args) throws Throwable {
|
||||||
|
|
||||||
public final Path dir;
|
public final Path dir;
|
||||||
|
|
||||||
public final Path launcherLibraries;
|
public final Path launcherLibraries;
|
||||||
|
|
||||||
|
public final List<String> args;
|
||||||
|
|
||||||
public final List<String> args;
|
|
||||||
|
|
||||||
public final Path configFile;
|
public final Path configFile;
|
||||||
|
|
||||||
public final Path publicKeyFile;
|
public final Path publicKeyFile;
|
||||||
|
@ -273,7 +237,7 @@ public static void main(String... args) throws Throwable {
|
||||||
public final Path privateKeyFile;
|
public final Path privateKeyFile;
|
||||||
|
|
||||||
public final Path updatesDir;
|
public final Path updatesDir;
|
||||||
|
|
||||||
public static LaunchServer server = null;
|
public static LaunchServer server = null;
|
||||||
|
|
||||||
public final Path profilesDir;
|
public final Path profilesDir;
|
||||||
|
@ -333,8 +297,8 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
||||||
this.dir = dir;
|
this.dir = dir;
|
||||||
launcherLibraries = dir.resolve("launcher-libraries");
|
launcherLibraries = dir.resolve("launcher-libraries");
|
||||||
if (!Files.isDirectory(launcherLibraries)) {
|
if (!Files.isDirectory(launcherLibraries)) {
|
||||||
Files.deleteIfExists(launcherLibraries);
|
Files.deleteIfExists(launcherLibraries);
|
||||||
Files.createDirectory(launcherLibraries);
|
Files.createDirectory(launcherLibraries);
|
||||||
}
|
}
|
||||||
this.args = Arrays.asList(args);
|
this.args = Arrays.asList(args);
|
||||||
configFile = dir.resolve("LaunchServer.conf");
|
configFile = dir.resolve("LaunchServer.conf");
|
||||||
|
@ -400,11 +364,10 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
||||||
generateConfigIfNotExists();
|
generateConfigIfNotExists();
|
||||||
LogHelper.info("Reading LaunchServer config file");
|
LogHelper.info("Reading LaunchServer config file");
|
||||||
try (BufferedReader reader = IOHelper.newReader(configFile)) {
|
try (BufferedReader reader = IOHelper.newReader(configFile)) {
|
||||||
config = Launcher.gson.fromJson(reader,Config.class);
|
config = Launcher.gson.fromJson(reader, Config.class);
|
||||||
}
|
}
|
||||||
config.verify();
|
config.verify();
|
||||||
for(AuthProvider provider : config.authProvider)
|
for (AuthProvider provider : config.authProvider) {
|
||||||
{
|
|
||||||
provider.init();
|
provider.init();
|
||||||
}
|
}
|
||||||
config.authHandler.init();
|
config.authHandler.init();
|
||||||
|
@ -421,18 +384,17 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
||||||
authHookManager = new AuthHookManager();
|
authHookManager = new AuthHookManager();
|
||||||
GarbageManager.registerNeedGC(sessionManager);
|
GarbageManager.registerNeedGC(sessionManager);
|
||||||
GarbageManager.registerNeedGC(limiter);
|
GarbageManager.registerNeedGC(limiter);
|
||||||
if(config.permissionsHandler instanceof Reloadable)
|
if (config.permissionsHandler instanceof Reloadable)
|
||||||
reloadManager.registerReloadable("permissionsHandler",(Reloadable) config.permissionsHandler);
|
reloadManager.registerReloadable("permissionsHandler", (Reloadable) config.permissionsHandler);
|
||||||
if(config.authHandler instanceof Reloadable)
|
if (config.authHandler instanceof Reloadable)
|
||||||
reloadManager.registerReloadable("authHandler",(Reloadable) config.authHandler);
|
reloadManager.registerReloadable("authHandler", (Reloadable) config.authHandler);
|
||||||
for(int i=0;i<config.authProvider.length;++i)
|
for (int i = 0; i < config.authProvider.length; ++i) {
|
||||||
{
|
|
||||||
AuthProvider provider = config.authProvider[i];
|
AuthProvider provider = config.authProvider[i];
|
||||||
if(provider instanceof Reloadable)
|
if (provider instanceof Reloadable)
|
||||||
reloadManager.registerReloadable("authHandler".concat(String.valueOf(i)),(Reloadable) provider);
|
reloadManager.registerReloadable("authHandler".concat(String.valueOf(i)), (Reloadable) provider);
|
||||||
}
|
}
|
||||||
if(config.textureProvider instanceof Reloadable)
|
if (config.textureProvider instanceof Reloadable)
|
||||||
reloadManager.registerReloadable("textureProvider",(Reloadable) config.textureProvider);
|
reloadManager.registerReloadable("textureProvider", (Reloadable) config.textureProvider);
|
||||||
|
|
||||||
Arrays.stream(config.mirrors).forEach(s -> {
|
Arrays.stream(config.mirrors).forEach(s -> {
|
||||||
try {
|
try {
|
||||||
|
@ -442,18 +404,17 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(config.permissionsHandler instanceof Reconfigurable)
|
if (config.permissionsHandler instanceof Reconfigurable)
|
||||||
reconfigurableManager.registerReconfigurable("permissionsHandler",(Reconfigurable) config.permissionsHandler);
|
reconfigurableManager.registerReconfigurable("permissionsHandler", (Reconfigurable) config.permissionsHandler);
|
||||||
if(config.authHandler instanceof Reconfigurable)
|
if (config.authHandler instanceof Reconfigurable)
|
||||||
reconfigurableManager.registerReconfigurable("authHandler",(Reconfigurable) config.authHandler);
|
reconfigurableManager.registerReconfigurable("authHandler", (Reconfigurable) config.authHandler);
|
||||||
for(int i=0;i<config.authProvider.length;++i)
|
for (int i = 0; i < config.authProvider.length; ++i) {
|
||||||
{
|
|
||||||
AuthProvider provider = config.authProvider[i];
|
AuthProvider provider = config.authProvider[i];
|
||||||
if(provider instanceof Reconfigurable)
|
if (provider instanceof Reconfigurable)
|
||||||
reconfigurableManager.registerReconfigurable("authHandler".concat(String.valueOf(i)),(Reconfigurable) provider);
|
reconfigurableManager.registerReconfigurable("authHandler".concat(String.valueOf(i)), (Reconfigurable) provider);
|
||||||
}
|
}
|
||||||
if(config.textureProvider instanceof Reconfigurable)
|
if (config.textureProvider instanceof Reconfigurable)
|
||||||
reconfigurableManager.registerReconfigurable("textureProvider",(Reconfigurable) config.textureProvider);
|
reconfigurableManager.registerReconfigurable("textureProvider", (Reconfigurable) config.textureProvider);
|
||||||
|
|
||||||
Arrays.stream(config.mirrors).forEach(s -> {
|
Arrays.stream(config.mirrors).forEach(s -> {
|
||||||
try {
|
try {
|
||||||
|
@ -469,7 +430,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
||||||
// Set launcher EXE binary
|
// Set launcher EXE binary
|
||||||
launcherBinary = new JARLauncherBinary(this);
|
launcherBinary = new JARLauncherBinary(this);
|
||||||
launcherEXEBinary = binary();
|
launcherEXEBinary = binary();
|
||||||
|
|
||||||
launcherBinary.init();
|
launcherBinary.init();
|
||||||
launcherEXEBinary.init();
|
launcherEXEBinary.init();
|
||||||
syncLauncherBinaries();
|
syncLauncherBinaries();
|
||||||
|
@ -492,9 +453,8 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
||||||
modulesManager.postInitModules();
|
modulesManager.postInitModules();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initGson()
|
public static void initGson() {
|
||||||
{
|
if (Launcher.gson != null) return;
|
||||||
if(Launcher.gson != null) return;
|
|
||||||
Launcher.gsonBuilder = new GsonBuilder();
|
Launcher.gsonBuilder = new GsonBuilder();
|
||||||
Launcher.gsonBuilder.registerTypeAdapter(AuthProvider.class, new AuthProviderAdapter());
|
Launcher.gsonBuilder.registerTypeAdapter(AuthProvider.class, new AuthProviderAdapter());
|
||||||
Launcher.gsonBuilder.registerTypeAdapter(TextureProvider.class, new TextureProviderAdapter());
|
Launcher.gsonBuilder.registerTypeAdapter(TextureProvider.class, new TextureProviderAdapter());
|
||||||
|
@ -515,12 +475,12 @@ public static void initGson()
|
||||||
}
|
}
|
||||||
|
|
||||||
private LauncherBinary binary() {
|
private LauncherBinary binary() {
|
||||||
try {
|
try {
|
||||||
Class.forName("net.sf.launch4j.Builder");
|
Class.forName("net.sf.launch4j.Builder");
|
||||||
if (config.launch4j.enabled) return new EXEL4JLauncherBinary(this);
|
if (config.launch4j.enabled) return new EXEL4JLauncherBinary(this);
|
||||||
} catch (ClassNotFoundException ignored) {
|
} catch (ClassNotFoundException ignored) {
|
||||||
LogHelper.warning("Launch4J isn't in classpath.");
|
LogHelper.warning("Launch4J isn't in classpath.");
|
||||||
}
|
}
|
||||||
return new EXELauncherBinary(this);
|
return new EXELauncherBinary(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,17 +539,17 @@ private void generateConfigIfNotExists() throws IOException {
|
||||||
newConfig.hwidHandler = new AcceptHWIDHandler();
|
newConfig.hwidHandler = new AcceptHWIDHandler();
|
||||||
|
|
||||||
newConfig.authProvider = new AuthProvider[]{new RejectAuthProvider("Настройте authProvider")};
|
newConfig.authProvider = new AuthProvider[]{new RejectAuthProvider("Настройте authProvider")};
|
||||||
newConfig.textureProvider = new RequestTextureProvider("http://example.com/skins/%username%.png","http://example.com/cloaks/%username%.png");
|
newConfig.textureProvider = new RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png");
|
||||||
newConfig.permissionsHandler = new JsonFilePermissionsHandler();
|
newConfig.permissionsHandler = new JsonFilePermissionsHandler();
|
||||||
newConfig.port = 7240;
|
newConfig.port = 7240;
|
||||||
newConfig.bindAddress = "0.0.0.0";
|
newConfig.bindAddress = "0.0.0.0";
|
||||||
newConfig.authRejectString = "Превышен лимит авторизаций";
|
newConfig.authRejectString = "Превышен лимит авторизаций";
|
||||||
newConfig.binaryName = "Launcher";
|
newConfig.binaryName = "Launcher";
|
||||||
newConfig.whitelistRejectString = "Вас нет в белом списке";
|
newConfig.whitelistRejectString = "Вас нет в белом списке";
|
||||||
|
|
||||||
newConfig.threadCoreCount = 0; // on your own
|
newConfig.threadCoreCount = 0; // on your own
|
||||||
newConfig.threadCount = JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() >= 4 ? JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() / 2 : JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors();
|
newConfig.threadCount = JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() >= 4 ? JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() / 2 : JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors();
|
||||||
|
|
||||||
newConfig.enabledProGuard = true;
|
newConfig.enabledProGuard = true;
|
||||||
newConfig.stripLineNumbers = true;
|
newConfig.stripLineNumbers = true;
|
||||||
newConfig.deleteTempFiles = true;
|
newConfig.deleteTempFiles = true;
|
||||||
|
@ -604,7 +564,7 @@ private void generateConfigIfNotExists() throws IOException {
|
||||||
// Write LaunchServer config
|
// Write LaunchServer config
|
||||||
LogHelper.info("Writing LaunchServer config file");
|
LogHelper.info("Writing LaunchServer config file");
|
||||||
try (BufferedWriter writer = IOHelper.newWriter(configFile)) {
|
try (BufferedWriter writer = IOHelper.newWriter(configFile)) {
|
||||||
LaunchServer.gson.toJson(newConfig,writer);
|
LaunchServer.gson.toJson(newConfig, writer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,25 +658,25 @@ public void syncUpdatesDir(Collection<String> dirs) throws IOException {
|
||||||
}
|
}
|
||||||
updatesDirMap = Collections.unmodifiableMap(newUpdatesDirMap);
|
updatesDirMap = Collections.unmodifiableMap(newUpdatesDirMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void restart() {
|
public void restart() {
|
||||||
ProcessBuilder builder = new ProcessBuilder();
|
ProcessBuilder builder = new ProcessBuilder();
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
if (config.startScript != null) args.add(config.startScript);
|
if (config.startScript != null) args.add(config.startScript);
|
||||||
else throw new IllegalArgumentException ("Please create start script and link it as startScript in config.");
|
else throw new IllegalArgumentException("Please create start script and link it as startScript in config.");
|
||||||
builder.directory(this.dir.toFile());
|
builder.directory(this.dir.toFile());
|
||||||
builder.inheritIO();
|
builder.inheritIO();
|
||||||
builder.redirectErrorStream(true);
|
builder.redirectErrorStream(true);
|
||||||
builder.redirectOutput(Redirect.PIPE);
|
builder.redirectOutput(Redirect.PIPE);
|
||||||
try {
|
try {
|
||||||
builder.start();
|
builder.start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fullyRestart() {
|
public void fullyRestart() {
|
||||||
restart();
|
restart();
|
||||||
JVMHelper.RUNTIME.exit(0);
|
JVMHelper.RUNTIME.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ru.gravit.launchserver;
|
package ru.gravit.launchserver;
|
||||||
|
|
||||||
public interface Reconfigurable {
|
public interface Reconfigurable {
|
||||||
void reconfig(String action,String[] args);
|
void reconfig(String action, String[] args);
|
||||||
|
|
||||||
void printConfigHelp();
|
void printConfigHelp();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
package ru.gravit.launchserver;
|
package ru.gravit.launchserver;
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface Reloadable {
|
public interface Reloadable {
|
||||||
void reload() throws Exception;
|
void reload() throws Exception;
|
||||||
|
|
|
@ -2,12 +2,7 @@
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.instrument.Instrumentation;
|
import java.lang.instrument.Instrumentation;
|
||||||
import java.nio.file.FileVisitOption;
|
import java.nio.file.*;
|
||||||
import java.nio.file.FileVisitResult;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.nio.file.SimpleFileVisitor;
|
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package ru.gravit.launchserver.asm;
|
package ru.gravit.launchserver.asm;
|
||||||
|
|
||||||
|
import org.objectweb.asm.ClassReader;
|
||||||
|
import org.objectweb.asm.ClassVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -8,12 +13,6 @@
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
import org.objectweb.asm.ClassReader;
|
|
||||||
import org.objectweb.asm.ClassVisitor;
|
|
||||||
import org.objectweb.asm.Opcodes;
|
|
||||||
|
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Позволяет искать методы внутри незагруженных классов и общие суперклассы для
|
* Позволяет искать методы внутри незагруженных классов и общие суперклассы для
|
||||||
* чего угодно. Работает через поиск class-файлов в classpath.
|
* чего угодно. Работает через поиск class-файлов в classpath.
|
||||||
|
@ -97,10 +96,10 @@ public ArrayList<String> getSuperClasses(String type) {
|
||||||
return superclasses;
|
return superclasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
cp.stream().forEach(IOHelper::close);
|
cp.stream().forEach(IOHelper::close);
|
||||||
cp.clear();
|
cp.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package ru.gravit.launchserver.asm;
|
package ru.gravit.launchserver.asm;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClassWriter с другой реализацией метода getCommonSuperClass: при его
|
* ClassWriter с другой реализацией метода getCommonSuperClass: при его
|
||||||
* использовании не происходит загрузки классов.
|
* использовании не происходит загрузки классов.
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package ru.gravit.launchserver.auth;
|
package ru.gravit.launchserver.auth;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.NeedGarbageCollection;
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import ru.gravit.launcher.NeedGarbageCollection;
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
|
||||||
|
|
||||||
public class AuthLimiter implements NeedGarbageCollection {
|
public class AuthLimiter implements NeedGarbageCollection {
|
||||||
static class AuthEntry {
|
static class AuthEntry {
|
||||||
public int value;
|
public int value;
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
package ru.gravit.launchserver.auth;
|
package ru.gravit.launchserver.auth;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||||
import com.zaxxer.hikari.HikariConfig;
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public final class MySQLSourceConfig implements AutoCloseable {
|
public final class MySQLSourceConfig implements AutoCloseable {
|
||||||
|
|
||||||
public static final int TIMEOUT = VerifyHelper.verifyInt(
|
public static final int TIMEOUT = VerifyHelper.verifyInt(
|
||||||
|
@ -22,7 +20,7 @@ public final class MySQLSourceConfig implements AutoCloseable {
|
||||||
VerifyHelper.POSITIVE, "launcher.mysql.maxPoolSize can't be <= 0");
|
VerifyHelper.POSITIVE, "launcher.mysql.maxPoolSize can't be <= 0");
|
||||||
|
|
||||||
// Instance
|
// Instance
|
||||||
private transient final String poolName;
|
private transient final String poolName;
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
private String address;
|
private String address;
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package ru.gravit.launchserver.auth.handler;
|
package ru.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
|
import ru.gravit.launchserver.auth.AuthException;
|
||||||
|
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||||
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import ru.gravit.launchserver.auth.AuthException;
|
|
||||||
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
|
||||||
|
|
||||||
public abstract class AuthHandler implements AutoCloseable {
|
public abstract class AuthHandler implements AutoCloseable {
|
||||||
private static final Map<String, Class<? extends AuthHandler>> AUTH_HANDLERS = new ConcurrentHashMap<>(4);
|
private static final Map<String, Class<? extends AuthHandler>> AUTH_HANDLERS = new ConcurrentHashMap<>(4);
|
||||||
private static boolean registredHandl = false;
|
private static boolean registredHandl = false;
|
||||||
|
@ -25,15 +25,14 @@ public static void registerHandler(String name, Class<? extends AuthHandler> ada
|
||||||
VerifyHelper.putIfAbsent(AUTH_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"),
|
VerifyHelper.putIfAbsent(AUTH_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"),
|
||||||
String.format("Auth handler has been already registered: '%s'", name));
|
String.format("Auth handler has been already registered: '%s'", name));
|
||||||
}
|
}
|
||||||
public static Class<? extends AuthHandler> getHandlerClass(String name)
|
|
||||||
{
|
public static Class<? extends AuthHandler> getHandlerClass(String name) {
|
||||||
return AUTH_HANDLERS.get(name);
|
return AUTH_HANDLERS.get(name);
|
||||||
}
|
}
|
||||||
public static String getHandlerName(Class<AuthHandler> clazz)
|
|
||||||
{
|
public static String getHandlerName(Class<AuthHandler> clazz) {
|
||||||
for(Map.Entry<String,Class<? extends AuthHandler>> e: AUTH_HANDLERS.entrySet())
|
for (Map.Entry<String, Class<? extends AuthHandler>> e : AUTH_HANDLERS.entrySet()) {
|
||||||
{
|
if (e.getValue().equals(clazz)) return e.getKey();
|
||||||
if(e.getValue().equals(clazz)) return e.getKey();
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -66,8 +65,7 @@ public static void registerHandlers() {
|
||||||
|
|
||||||
public abstract String uuidToUsername(UUID uuid) throws IOException;
|
public abstract String uuidToUsername(UUID uuid) throws IOException;
|
||||||
|
|
||||||
public void init()
|
public void init() {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package ru.gravit.launchserver.auth.handler;
|
package ru.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.serialize.HInput;
|
||||||
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import ru.gravit.launcher.serialize.HInput;
|
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
|
||||||
|
|
||||||
public final class BinaryFileAuthHandler extends FileAuthHandler {
|
public final class BinaryFileAuthHandler extends FileAuthHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package ru.gravit.launchserver.auth.handler;
|
package ru.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.NeedGarbageCollection;
|
import ru.gravit.launcher.NeedGarbageCollection;
|
||||||
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||||
import ru.gravit.utils.helper.CommonHelper;
|
import ru.gravit.utils.helper.CommonHelper;
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class CachedAuthHandler extends AuthHandler implements NeedGarbageCollection {
|
public abstract class CachedAuthHandler extends AuthHandler implements NeedGarbageCollection {
|
||||||
public static final class Entry {
|
public static final class Entry {
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ public Entry(UUID uuid, String username, String accessToken, String serverID) {
|
||||||
this.serverID = serverID == null ? null : VerifyHelper.verifyServerID(serverID);
|
this.serverID = serverID == null ? null : VerifyHelper.verifyServerID(serverID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private transient final Map<UUID, Entry> entryCache = new HashMap<>(1024);
|
private transient final Map<UUID, Entry> entryCache = new HashMap<>(1024);
|
||||||
private transient final Map<String, UUID> usernamesCache = new HashMap<>(1024);
|
private transient final Map<String, UUID> usernamesCache = new HashMap<>(1024);
|
||||||
|
|
||||||
|
@ -114,12 +115,11 @@ public Map<String, UUID> getUsernamesCache() {
|
||||||
return usernamesCache;
|
return usernamesCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadEntryCache(Map<UUID, Entry> map)
|
public void loadEntryCache(Map<UUID, Entry> map) {
|
||||||
{
|
|
||||||
entryCache.putAll(map);
|
entryCache.putAll(map);
|
||||||
}
|
}
|
||||||
public void loadUsernameCache(Map<String, UUID> map)
|
|
||||||
{
|
public void loadUsernameCache(Map<String, UUID> map) {
|
||||||
usernamesCache.putAll(map);
|
usernamesCache.putAll(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,17 @@
|
||||||
package ru.gravit.launchserver.auth.handler;
|
package ru.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||||
import ru.gravit.launcher.serialize.HInput;
|
import ru.gravit.launcher.serialize.HInput;
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
import ru.gravit.launcher.serialize.stream.StreamObject;
|
import ru.gravit.launcher.serialize.stream.StreamObject;
|
||||||
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||||
import ru.gravit.utils.helper.CommonHelper;
|
import ru.gravit.utils.helper.*;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import java.io.IOException;
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import java.nio.file.Path;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import java.security.SecureRandom;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
|
|
||||||
public abstract class FileAuthHandler extends AuthHandler {
|
public abstract class FileAuthHandler extends AuthHandler {
|
||||||
public static final class Entry extends StreamObject {
|
public static final class Entry extends StreamObject {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package ru.gravit.launchserver.auth.handler;
|
package ru.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
|
||||||
|
|
||||||
public final class MemoryAuthHandler extends CachedAuthHandler {
|
public final class MemoryAuthHandler extends CachedAuthHandler {
|
||||||
private static String toUsername(UUID uuid) {
|
private static String toUsername(UUID uuid) {
|
||||||
byte[] bytes = ByteBuffer.allocate(16).
|
byte[] bytes = ByteBuffer.allocate(16).
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package ru.gravit.launchserver.auth.handler;
|
package ru.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
|
import ru.gravit.launchserver.auth.MySQLSourceConfig;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
@ -7,9 +10,6 @@
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import ru.gravit.launchserver.auth.MySQLSourceConfig;
|
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public final class MySQLAuthHandler extends CachedAuthHandler {
|
public final class MySQLAuthHandler extends CachedAuthHandler {
|
||||||
private MySQLSourceConfig mySQLHolder;
|
private MySQLSourceConfig mySQLHolder;
|
||||||
private String uuidColumn;
|
private String uuidColumn;
|
||||||
|
@ -23,16 +23,16 @@ public final class MySQLAuthHandler extends CachedAuthHandler {
|
||||||
private transient String queryByUsernameSQL;
|
private transient String queryByUsernameSQL;
|
||||||
private transient String updateAuthSQL;
|
private transient String updateAuthSQL;
|
||||||
private transient String updateServerIDSQL;
|
private transient String updateServerIDSQL;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init()
|
public void init() {
|
||||||
{
|
|
||||||
//Verify
|
//Verify
|
||||||
if(mySQLHolder == null) LogHelper.error("[Verify][AuthHandler] mySQLHolder cannot be null");
|
if (mySQLHolder == null) LogHelper.error("[Verify][AuthHandler] mySQLHolder cannot be null");
|
||||||
if(uuidColumn == null) LogHelper.error("[Verify][AuthHandler] uuidColumn cannot be null");
|
if (uuidColumn == null) LogHelper.error("[Verify][AuthHandler] uuidColumn cannot be null");
|
||||||
if(usernameColumn == null) LogHelper.error("[Verify][AuthHandler] usernameColumn cannot be null");
|
if (usernameColumn == null) LogHelper.error("[Verify][AuthHandler] usernameColumn cannot be null");
|
||||||
if(accessTokenColumn == null) LogHelper.error("[Verify][AuthHandler] accessTokenColumn cannot be null");
|
if (accessTokenColumn == null) LogHelper.error("[Verify][AuthHandler] accessTokenColumn cannot be null");
|
||||||
if(serverIDColumn == null) LogHelper.error("[Verify][AuthHandler] serverIDColumn cannot be null");
|
if (serverIDColumn == null) LogHelper.error("[Verify][AuthHandler] serverIDColumn cannot be null");
|
||||||
if(table == null) LogHelper.error("[Verify][AuthHandler] table cannot be null");
|
if (table == null) LogHelper.error("[Verify][AuthHandler] table cannot be null");
|
||||||
// Prepare SQL queries
|
// Prepare SQL queries
|
||||||
queryByUUIDSQL = String.format("SELECT %s, %s, %s, %s FROM %s WHERE %s=? LIMIT 1",
|
queryByUUIDSQL = String.format("SELECT %s, %s, %s, %s FROM %s WHERE %s=? LIMIT 1",
|
||||||
uuidColumn, usernameColumn, accessTokenColumn, serverIDColumn, table, uuidColumn);
|
uuidColumn, usernameColumn, accessTokenColumn, serverIDColumn, table, uuidColumn);
|
||||||
|
@ -43,6 +43,7 @@ public void init()
|
||||||
updateServerIDSQL = String.format("UPDATE %s SET %s=? WHERE %s=? LIMIT 1",
|
updateServerIDSQL = String.format("UPDATE %s SET %s=? WHERE %s=? LIMIT 1",
|
||||||
table, serverIDColumn, uuidColumn);
|
table, serverIDColumn, uuidColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
mySQLHolder.close();
|
mySQLHolder.close();
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package ru.gravit.launchserver.auth.handler;
|
package ru.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
|
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||||
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
|
||||||
|
|
||||||
public final class NullAuthHandler extends AuthHandler {
|
public final class NullAuthHandler extends AuthHandler {
|
||||||
private volatile AuthHandler handler;
|
private volatile AuthHandler handler;
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package ru.gravit.launchserver.auth.hwid;
|
package ru.gravit.launchserver.auth.hwid;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.HWID;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import ru.gravit.launcher.HWID;
|
|
||||||
|
|
||||||
public class AcceptHWIDHandler extends HWIDHandler {
|
public class AcceptHWIDHandler extends HWIDHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package ru.gravit.launchserver.auth.hwid;
|
package ru.gravit.launchserver.auth.hwid;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.HWID;
|
||||||
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import ru.gravit.launcher.HWID;
|
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
|
||||||
|
|
||||||
public abstract class HWIDHandler implements AutoCloseable {
|
public abstract class HWIDHandler implements AutoCloseable {
|
||||||
private static final Map<String, Class<? extends HWIDHandler>> HW_HANDLERS = new ConcurrentHashMap<>(4);
|
private static final Map<String, Class<? extends HWIDHandler>> HW_HANDLERS = new ConcurrentHashMap<>(4);
|
||||||
private static boolean registredHandl = false;
|
private static boolean registredHandl = false;
|
||||||
|
@ -44,15 +44,13 @@ public void check(HWID hwid, String username) throws HWIDException {
|
||||||
|
|
||||||
public abstract void unban(List<HWID> hwid) throws HWIDException;
|
public abstract void unban(List<HWID> hwid) throws HWIDException;
|
||||||
|
|
||||||
public static Class<? extends HWIDHandler> getHandlerClass(String name)
|
public static Class<? extends HWIDHandler> getHandlerClass(String name) {
|
||||||
{
|
|
||||||
return HW_HANDLERS.get(name);
|
return HW_HANDLERS.get(name);
|
||||||
}
|
}
|
||||||
public static String getHandlerName(Class<? extends HWIDHandler> clazz)
|
|
||||||
{
|
public static String getHandlerName(Class<? extends HWIDHandler> clazz) {
|
||||||
for(Map.Entry<String,Class<? extends HWIDHandler>> e: HW_HANDLERS.entrySet())
|
for (Map.Entry<String, Class<? extends HWIDHandler>> e : HW_HANDLERS.entrySet()) {
|
||||||
{
|
if (e.getValue().equals(clazz)) return e.getKey();
|
||||||
if(e.getValue().equals(clazz)) return e.getKey();
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
package ru.gravit.launchserver.auth.hwid;
|
package ru.gravit.launchserver.auth.hwid;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import ru.gravit.launcher.HWID;
|
||||||
|
import ru.gravit.launcher.OshiHWID;
|
||||||
|
import ru.gravit.utils.HTTPRequest;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.HWID;
|
|
||||||
import ru.gravit.launcher.OshiHWID;
|
|
||||||
import ru.gravit.utils.HTTPRequest;
|
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public final class JsonHWIDHandler extends HWIDHandler {
|
public final class JsonHWIDHandler extends HWIDHandler {
|
||||||
private static final Gson gson = new Gson();
|
private static final Gson gson = new Gson();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package ru.gravit.launchserver.auth.hwid;
|
package ru.gravit.launchserver.auth.hwid;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.HWID;
|
||||||
|
import ru.gravit.launcher.OshiHWID;
|
||||||
|
import ru.gravit.launchserver.auth.MySQLSourceConfig;
|
||||||
|
import ru.gravit.utils.helper.CommonHelper;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
@ -7,12 +13,6 @@
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import ru.gravit.launcher.HWID;
|
|
||||||
import ru.gravit.launcher.OshiHWID;
|
|
||||||
import ru.gravit.launchserver.auth.MySQLSourceConfig;
|
|
||||||
import ru.gravit.utils.helper.CommonHelper;
|
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public class MysqlHWIDHandler extends HWIDHandler {
|
public class MysqlHWIDHandler extends HWIDHandler {
|
||||||
private MySQLSourceConfig mySQLHolder;
|
private MySQLSourceConfig mySQLHolder;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public class MysqlHWIDHandler extends HWIDHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void check0(HWID hwid, String username) throws HWIDException {
|
public void check0(HWID hwid, String username) throws HWIDException {
|
||||||
if(hwid instanceof OshiHWID) {
|
if (hwid instanceof OshiHWID) {
|
||||||
OshiHWID oshiHWID = (OshiHWID) hwid;
|
OshiHWID oshiHWID = (OshiHWID) hwid;
|
||||||
try {
|
try {
|
||||||
Connection c = mySQLHolder.getConnection();
|
Connection c = mySQLHolder.getConnection();
|
||||||
|
@ -68,9 +68,9 @@ public void check0(HWID hwid, String username) throws HWIDException {
|
||||||
// Execute SQL query
|
// Execute SQL query
|
||||||
s.setQueryTimeout(MySQLSourceConfig.TIMEOUT);
|
s.setQueryTimeout(MySQLSourceConfig.TIMEOUT);
|
||||||
try (ResultSet set = s.executeQuery()) {
|
try (ResultSet set = s.executeQuery()) {
|
||||||
if(set.next()) {
|
if (set.next()) {
|
||||||
int hwid_id = set.getInt(userFieldHwid);
|
int hwid_id = set.getInt(userFieldHwid);
|
||||||
if(hwid_id == 0) {
|
if (hwid_id == 0) {
|
||||||
onUpdateInfo(oshiHWID, username, c);
|
onUpdateInfo(oshiHWID, username, c);
|
||||||
} else {
|
} else {
|
||||||
onCheckInfo(oshiHWID, username, c);
|
onCheckInfo(oshiHWID, username, c);
|
||||||
|
@ -93,7 +93,7 @@ public void onUpdateInfo(OshiHWID hwid, String username, Connection c) throws HW
|
||||||
|
|
||||||
ResultSet set = a.executeQuery();
|
ResultSet set = a.executeQuery();
|
||||||
PreparedStatement ps;
|
PreparedStatement ps;
|
||||||
if(set.next()) {
|
if (set.next()) {
|
||||||
int id = set.getInt("id");
|
int id = set.getInt("id");
|
||||||
boolean isBanned = set.getBoolean(hwidFieldBanned);
|
boolean isBanned = set.getBoolean(hwidFieldBanned);
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ public void onUpdateInfo(OshiHWID hwid, String username, Connection c) throws HW
|
||||||
ps.setQueryTimeout(MySQLSourceConfig.TIMEOUT);
|
ps.setQueryTimeout(MySQLSourceConfig.TIMEOUT);
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
|
|
||||||
if(isBanned) {
|
if (isBanned) {
|
||||||
throw new HWIDException(banMessage);
|
throw new HWIDException(banMessage);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -136,9 +136,9 @@ public void onCheckInfo(OshiHWID hwid, String username, Connection c) throws HWI
|
||||||
a.setString(i + 1, CommonHelper.replace(paramsHwids[i], replaceParams));
|
a.setString(i + 1, CommonHelper.replace(paramsHwids[i], replaceParams));
|
||||||
}
|
}
|
||||||
ResultSet set = a.executeQuery();
|
ResultSet set = a.executeQuery();
|
||||||
if(set.next()) {
|
if (set.next()) {
|
||||||
boolean isBanned = set.getBoolean(hwidFieldBanned);
|
boolean isBanned = set.getBoolean(hwidFieldBanned);
|
||||||
if(isBanned) {
|
if (isBanned) {
|
||||||
throw new HWIDException(banMessage);
|
throw new HWIDException(banMessage);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -151,7 +151,7 @@ public void onCheckInfo(OshiHWID hwid, String username, Connection c) throws HWI
|
||||||
|
|
||||||
public void setIsBanned(HWID hwid, boolean isBanned) {
|
public void setIsBanned(HWID hwid, boolean isBanned) {
|
||||||
LogHelper.debug("%s Request HWID: %s", isBanned ? "Ban" : "UnBan", hwid.toString());
|
LogHelper.debug("%s Request HWID: %s", isBanned ? "Ban" : "UnBan", hwid.toString());
|
||||||
if(hwid instanceof OshiHWID) {
|
if (hwid instanceof OshiHWID) {
|
||||||
OshiHWID oshiHWID = (OshiHWID) hwid;
|
OshiHWID oshiHWID = (OshiHWID) hwid;
|
||||||
Connection c = null;
|
Connection c = null;
|
||||||
try {
|
try {
|
||||||
|
@ -199,9 +199,9 @@ public List<HWID> getHwid(String username) {
|
||||||
s.setQueryTimeout(MySQLSourceConfig.TIMEOUT);
|
s.setQueryTimeout(MySQLSourceConfig.TIMEOUT);
|
||||||
|
|
||||||
try (ResultSet set = s.executeQuery()) {
|
try (ResultSet set = s.executeQuery()) {
|
||||||
if(set.next()) {
|
if (set.next()) {
|
||||||
int hwid_id = set.getInt(userFieldHwid);
|
int hwid_id = set.getInt(userFieldHwid);
|
||||||
if(hwid_id != 0) {
|
if (hwid_id != 0) {
|
||||||
s = c.prepareStatement(String.format("SELECT * FROM `%s` WHERE `id` = ? LIMIT 1", tableHwids));
|
s = c.prepareStatement(String.format("SELECT * FROM `%s` WHERE `id` = ? LIMIT 1", tableHwids));
|
||||||
s.setInt(1, hwid_id);
|
s.setInt(1, hwid_id);
|
||||||
ResultSet rs = s.executeQuery();
|
ResultSet rs = s.executeQuery();
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
public class ConfigPermissionsHandler extends PermissionsHandler {
|
public class ConfigPermissionsHandler extends PermissionsHandler {
|
||||||
public boolean isAdmin = false;
|
public boolean isAdmin = false;
|
||||||
public boolean isServer = false;
|
public boolean isServer = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientPermissions getPermissions(String username) {
|
public ClientPermissions getPermissions(String username) {
|
||||||
ClientPermissions permissions = new ClientPermissions();
|
ClientPermissions permissions = new ClientPermissions();
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
package ru.gravit.launchserver.auth.permissions;
|
package ru.gravit.launchserver.auth.permissions;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import ru.gravit.launcher.ClientPermissions;
|
||||||
|
import ru.gravit.launcher.Launcher;
|
||||||
|
import ru.gravit.launchserver.Reloadable;
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
@ -9,57 +16,47 @@
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.ClientPermissions;
|
|
||||||
import ru.gravit.launcher.Launcher;
|
|
||||||
import ru.gravit.launchserver.Reloadable;
|
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public class JsonFilePermissionsHandler extends PermissionsHandler implements Reloadable {
|
public class JsonFilePermissionsHandler extends PermissionsHandler implements Reloadable {
|
||||||
public String filename = "permissions.json";
|
public String filename = "permissions.json";
|
||||||
public static Map<String,ClientPermissions> map;
|
public static Map<String, ClientPermissions> map;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void reload() {
|
||||||
map.clear();
|
map.clear();
|
||||||
Path path = Paths.get(filename);
|
Path path = Paths.get(filename);
|
||||||
Type type = new TypeToken<Map<String,ClientPermissions>>(){}.getType();
|
Type type = new TypeToken<Map<String, ClientPermissions>>() {
|
||||||
try(Reader reader = IOHelper.newReader(path))
|
}.getType();
|
||||||
{
|
try (Reader reader = IOHelper.newReader(path)) {
|
||||||
map = Launcher.gson.fromJson(reader,type);
|
map = Launcher.gson.fromJson(reader, type);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Enity
|
public static class Enity {
|
||||||
{
|
|
||||||
public String username;
|
public String username;
|
||||||
public ClientPermissions permissions;
|
public ClientPermissions permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientPermissions getPermissions(String username)
|
public ClientPermissions getPermissions(String username) {
|
||||||
{
|
return map.getOrDefault(username, ClientPermissions.DEFAULT);
|
||||||
return map.getOrDefault(username,ClientPermissions.DEFAULT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonFilePermissionsHandler() {
|
public JsonFilePermissionsHandler() {
|
||||||
Type type = new TypeToken<Map<String,ClientPermissions>>(){}.getType();
|
Type type = new TypeToken<Map<String, ClientPermissions>>() {
|
||||||
|
}.getType();
|
||||||
Path path = Paths.get(filename);
|
Path path = Paths.get(filename);
|
||||||
if(!IOHelper.exists(path))
|
if (!IOHelper.exists(path)) {
|
||||||
{
|
|
||||||
map = new HashMap<>();
|
map = new HashMap<>();
|
||||||
try(Writer writer = IOHelper.newWriter(path))
|
try (Writer writer = IOHelper.newWriter(path)) {
|
||||||
{
|
Launcher.gson.toJson(map, writer);
|
||||||
Launcher.gson.toJson(map,writer);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try(Reader reader = IOHelper.newReader(path))
|
try (Reader reader = IOHelper.newReader(path)) {
|
||||||
{
|
map = Launcher.gson.fromJson(reader, type);
|
||||||
map = Launcher.gson.fromJson(reader,type);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,33 @@
|
||||||
package ru.gravit.launchserver.auth.permissions;
|
package ru.gravit.launchserver.auth.permissions;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.ClientPermissions;
|
||||||
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import ru.gravit.launcher.ClientPermissions;
|
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
|
||||||
|
|
||||||
public abstract class PermissionsHandler {
|
public abstract class PermissionsHandler {
|
||||||
private static final Map<String, Class<? extends PermissionsHandler>> PERMISSIONS_HANDLERS = new ConcurrentHashMap<>(4);
|
private static final Map<String, Class<? extends PermissionsHandler>> PERMISSIONS_HANDLERS = new ConcurrentHashMap<>(4);
|
||||||
private static boolean registredHandl = false;
|
private static boolean registredHandl = false;
|
||||||
|
|
||||||
public static void registerHandler(String name, Class<? extends PermissionsHandler> adapter) {
|
public static void registerHandler(String name, Class<? extends PermissionsHandler> adapter) {
|
||||||
VerifyHelper.verifyIDName(name);
|
VerifyHelper.verifyIDName(name);
|
||||||
VerifyHelper.putIfAbsent(PERMISSIONS_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"),
|
VerifyHelper.putIfAbsent(PERMISSIONS_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"),
|
||||||
String.format("Auth handler has been already registered: '%s'", name));
|
String.format("Auth handler has been already registered: '%s'", name));
|
||||||
}
|
}
|
||||||
public static Class<? extends PermissionsHandler> getHandlerClass(String name)
|
|
||||||
{
|
public static Class<? extends PermissionsHandler> getHandlerClass(String name) {
|
||||||
return PERMISSIONS_HANDLERS.get(name);
|
return PERMISSIONS_HANDLERS.get(name);
|
||||||
}
|
}
|
||||||
public static String getHandlerName(Class<? extends PermissionsHandler> clazz)
|
|
||||||
{
|
public static String getHandlerName(Class<? extends PermissionsHandler> clazz) {
|
||||||
for(Map.Entry<String,Class<? extends PermissionsHandler>> e: PERMISSIONS_HANDLERS.entrySet())
|
for (Map.Entry<String, Class<? extends PermissionsHandler>> e : PERMISSIONS_HANDLERS.entrySet()) {
|
||||||
{
|
if (e.getValue().equals(clazz)) return e.getKey();
|
||||||
if(e.getValue().equals(clazz)) return e.getKey();
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerHandlers() {
|
public static void registerHandlers() {
|
||||||
if (!registredHandl) {
|
if (!registredHandl) {
|
||||||
registerHandler("json", JsonFilePermissionsHandler.class);
|
registerHandler("json", JsonFilePermissionsHandler.class);
|
||||||
|
@ -35,5 +36,6 @@ public static void registerHandlers() {
|
||||||
registredHandl = true;
|
registredHandl = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract ClientPermissions getPermissions(String username);
|
public abstract ClientPermissions getPermissions(String username);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package ru.gravit.launchserver.auth.provider;
|
package ru.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.auth.AuthException;
|
import ru.gravit.launchserver.auth.AuthException;
|
||||||
import ru.gravit.launchserver.auth.handler.AuthHandler;
|
import ru.gravit.launchserver.auth.handler.AuthHandler;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public abstract class AuthProvider implements AutoCloseable {
|
public abstract class AuthProvider implements AutoCloseable {
|
||||||
private static final Map<String, Class<? extends AuthProvider>> AUTH_PROVIDERS = new ConcurrentHashMap<>(8);
|
private static final Map<String, Class<? extends AuthProvider>> AUTH_PROVIDERS = new ConcurrentHashMap<>(8);
|
||||||
private static boolean registredProv = false;
|
private static boolean registredProv = false;
|
||||||
|
@ -49,20 +49,18 @@ public AuthHandler getAccociateHandler(int this_position) {
|
||||||
@Override
|
@Override
|
||||||
public abstract void close() throws IOException;
|
public abstract void close() throws IOException;
|
||||||
|
|
||||||
public static Class<? extends AuthProvider> getProviderClass(String name)
|
public static Class<? extends AuthProvider> getProviderClass(String name) {
|
||||||
{
|
|
||||||
return AUTH_PROVIDERS.get(name);
|
return AUTH_PROVIDERS.get(name);
|
||||||
}
|
}
|
||||||
public static String getProviderName(Class<? extends AuthProvider> clazz)
|
|
||||||
{
|
public static String getProviderName(Class<? extends AuthProvider> clazz) {
|
||||||
for(Map.Entry<String,Class<? extends AuthProvider>> e: AUTH_PROVIDERS.entrySet())
|
for (Map.Entry<String, Class<? extends AuthProvider>> e : AUTH_PROVIDERS.entrySet()) {
|
||||||
{
|
if (e.getValue().equals(clazz)) return e.getKey();
|
||||||
if(e.getValue().equals(clazz)) return e.getKey();
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public void init()
|
|
||||||
{
|
public void init() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
package ru.gravit.launchserver.auth.provider;
|
package ru.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
|
||||||
import ru.gravit.launcher.ClientPermissions;
|
import ru.gravit.launcher.ClientPermissions;
|
||||||
import ru.gravit.utils.HTTPRequest;
|
import ru.gravit.utils.HTTPRequest;
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
public final class JsonAuthProvider extends AuthProvider {
|
public final class JsonAuthProvider extends AuthProvider {
|
||||||
private static Gson gson = new Gson();
|
private static Gson gson = new Gson();
|
||||||
private URL url;
|
private URL url;
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
package ru.gravit.launchserver.auth.provider;
|
package ru.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import ru.gravit.utils.HTTPRequest;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import ru.gravit.utils.HTTPRequest;
|
|
||||||
|
|
||||||
public final class MojangAuthProvider extends AuthProvider {
|
public final class MojangAuthProvider extends AuthProvider {
|
||||||
private static final Pattern UUID_REGEX = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})");
|
private static final Pattern UUID_REGEX = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})");
|
||||||
private static final URL URL;
|
private static final URL URL;
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
package ru.gravit.launchserver.auth.provider;
|
package ru.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.ClientPermissions;
|
import ru.gravit.launcher.ClientPermissions;
|
||||||
import ru.gravit.launchserver.auth.AuthException;
|
import ru.gravit.launchserver.auth.AuthException;
|
||||||
import ru.gravit.launchserver.auth.MySQLSourceConfig;
|
import ru.gravit.launchserver.auth.MySQLSourceConfig;
|
||||||
|
@ -12,6 +7,11 @@
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public final class MySQLAuthProvider extends AuthProvider {
|
public final class MySQLAuthProvider extends AuthProvider {
|
||||||
private MySQLSourceConfig mySQLHolder;
|
private MySQLSourceConfig mySQLHolder;
|
||||||
private String query;
|
private String query;
|
||||||
|
@ -21,9 +21,9 @@ public final class MySQLAuthProvider extends AuthProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
if(query == null) LogHelper.error("[Verify][AuthProvider] query cannot be null");
|
if (query == null) LogHelper.error("[Verify][AuthProvider] query cannot be null");
|
||||||
if(message == null) LogHelper.error("[Verify][AuthProvider] message cannot be null");
|
if (message == null) LogHelper.error("[Verify][AuthProvider] message cannot be null");
|
||||||
if(mySQLHolder == null) LogHelper.error("[Verify][AuthProvider] mySQLHolder cannot be null");
|
if (mySQLHolder == null) LogHelper.error("[Verify][AuthProvider] mySQLHolder cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package ru.gravit.launchserver.auth.provider;
|
package ru.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
|
||||||
|
|
||||||
public final class NullAuthProvider extends AuthProvider {
|
public final class NullAuthProvider extends AuthProvider {
|
||||||
private volatile AuthProvider provider;
|
private volatile AuthProvider provider;
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package ru.gravit.launchserver.auth.provider;
|
package ru.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.Reconfigurable;
|
import ru.gravit.launchserver.Reconfigurable;
|
||||||
import ru.gravit.launchserver.auth.AuthException;
|
import ru.gravit.launchserver.auth.AuthException;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public final class RejectAuthProvider extends AuthProvider implements Reconfigurable {
|
public final class RejectAuthProvider extends AuthProvider implements Reconfigurable {
|
||||||
public RejectAuthProvider() {
|
public RejectAuthProvider() {
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,9 @@ public RejectAuthProvider(String message) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthProviderResult auth(String login, String password, String ip) throws AuthException {
|
public AuthProviderResult auth(String login, String password, String ip) throws AuthException {
|
||||||
if(whitelist != null)
|
if (whitelist != null) {
|
||||||
{
|
for (String username : whitelist) {
|
||||||
for(String username : whitelist)
|
if (login.equals(username)) {
|
||||||
{
|
|
||||||
if(login.equals(username))
|
|
||||||
{
|
|
||||||
return new AuthProviderResult(login, SecurityHelper.randomStringToken());
|
return new AuthProviderResult(login, SecurityHelper.randomStringToken());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
package ru.gravit.launchserver.auth.provider;
|
package ru.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.ClientPermissions;
|
import ru.gravit.launcher.ClientPermissions;
|
||||||
import ru.gravit.utils.helper.CommonHelper;
|
import ru.gravit.utils.helper.CommonHelper;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class RequestAuthProvider extends AuthProvider {
|
public final class RequestAuthProvider extends AuthProvider {
|
||||||
private String url;
|
private String url;
|
||||||
private transient Pattern pattern;
|
private transient Pattern pattern;
|
||||||
|
@ -18,10 +18,9 @@ public final class RequestAuthProvider extends AuthProvider {
|
||||||
private boolean usePermission;
|
private boolean usePermission;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init()
|
public void init() {
|
||||||
{
|
if (url == null) LogHelper.error("[Verify][AuthProvider] url cannot be null");
|
||||||
if(url == null) LogHelper.error("[Verify][AuthProvider] url cannot be null");
|
if (response == null) LogHelper.error("[Verify][AuthProvider] response cannot be null");
|
||||||
if(response == null) LogHelper.error("[Verify][AuthProvider] response cannot be null");
|
|
||||||
pattern = Pattern.compile(response);
|
pattern = Pattern.compile(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package ru.gravit.launchserver.binary;
|
package ru.gravit.launchserver.binary;
|
||||||
|
|
||||||
|
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -8,9 +11,6 @@
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
|
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
|
||||||
|
|
||||||
public class BuildContext {
|
public class BuildContext {
|
||||||
public final ZipOutputStream output;
|
public final ZipOutputStream output;
|
||||||
public final JAConfigurator config;
|
public final JAConfigurator config;
|
||||||
|
|
|
@ -1,20 +1,16 @@
|
||||||
package ru.gravit.launchserver.binary;
|
package ru.gravit.launchserver.binary;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
import net.sf.launch4j.Builder;
|
import net.sf.launch4j.Builder;
|
||||||
import net.sf.launch4j.Log;
|
import net.sf.launch4j.Log;
|
||||||
import net.sf.launch4j.config.Config;
|
import net.sf.launch4j.config.*;
|
||||||
import net.sf.launch4j.config.ConfigPersister;
|
|
||||||
import net.sf.launch4j.config.Jre;
|
|
||||||
import net.sf.launch4j.config.LanguageID;
|
|
||||||
import net.sf.launch4j.config.VersionInfo;
|
|
||||||
import ru.gravit.launcher.Launcher;
|
import ru.gravit.launcher.Launcher;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public final class EXEL4JLauncherBinary extends LauncherBinary {
|
public final class EXEL4JLauncherBinary extends LauncherBinary {
|
||||||
private final static class Launch4JLog extends Log {
|
private final static class Launch4JLog extends Log {
|
||||||
private static final Launch4JLog INSTANCE = new Launch4JLog();
|
private static final Launch4JLog INSTANCE = new Launch4JLog();
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package ru.gravit.launchserver.binary;
|
package ru.gravit.launchserver.binary;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
public class EXELauncherBinary extends LauncherBinary {
|
public class EXELauncherBinary extends LauncherBinary {
|
||||||
|
|
||||||
public EXELauncherBinary(LaunchServer server) {
|
public EXELauncherBinary(LaunchServer server) {
|
||||||
|
|
|
@ -1,16 +1,11 @@
|
||||||
package ru.gravit.launchserver.binary;
|
package ru.gravit.launchserver.binary;
|
||||||
|
|
||||||
import java.io.IOException;
|
import javassist.*;
|
||||||
|
|
||||||
import javassist.CannotCompileException;
|
|
||||||
import javassist.ClassPool;
|
|
||||||
import javassist.CtClass;
|
|
||||||
import javassist.CtConstructor;
|
|
||||||
import javassist.CtMethod;
|
|
||||||
import javassist.NotFoundException;
|
|
||||||
import ru.gravit.launcher.LauncherConfig;
|
import ru.gravit.launcher.LauncherConfig;
|
||||||
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
|
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class JAConfigurator implements AutoCloseable {
|
public class JAConfigurator implements AutoCloseable {
|
||||||
public ClassPool pool;
|
public ClassPool pool;
|
||||||
public CtClass ctClass;
|
public CtClass ctClass;
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
package ru.gravit.launchserver.binary;
|
package ru.gravit.launchserver.binary;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.Launcher;
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.binary.tasks.*;
|
||||||
|
import ru.gravit.utils.helper.CommonHelper;
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -7,26 +14,14 @@
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import ru.gravit.launcher.Launcher;
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
|
||||||
import ru.gravit.launchserver.binary.tasks.AttachJarsTask;
|
|
||||||
import ru.gravit.launchserver.binary.tasks.LauncherBuildTask;
|
|
||||||
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
|
|
||||||
import ru.gravit.launchserver.binary.tasks.ProGuardBuildTask;
|
|
||||||
import ru.gravit.launchserver.binary.tasks.AdditionalFixesApplyTask;
|
|
||||||
import ru.gravit.launchserver.binary.tasks.PrepareBuildTask;
|
|
||||||
import ru.gravit.utils.helper.CommonHelper;
|
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public final class JARLauncherBinary extends LauncherBinary {
|
public final class JARLauncherBinary extends LauncherBinary {
|
||||||
public final AtomicLong count;
|
public final AtomicLong count;
|
||||||
public final Path runtimeDir;
|
public final Path runtimeDir;
|
||||||
public final Path guardDir;
|
public final Path guardDir;
|
||||||
public final Path buildDir;
|
public final Path buildDir;
|
||||||
public List<LauncherBuildTask> tasks;
|
public List<LauncherBuildTask> tasks;
|
||||||
public List<Path> coreLibs;
|
public List<Path> coreLibs;
|
||||||
|
|
||||||
public JARLauncherBinary(LaunchServer server) throws IOException {
|
public JARLauncherBinary(LaunchServer server) throws IOException {
|
||||||
super(server);
|
super(server);
|
||||||
count = new AtomicLong(0);
|
count = new AtomicLong(0);
|
||||||
|
@ -37,8 +32,8 @@ public JARLauncherBinary(LaunchServer server) throws IOException {
|
||||||
tasks = new ArrayList<>();
|
tasks = new ArrayList<>();
|
||||||
coreLibs = new ArrayList<>();
|
coreLibs = new ArrayList<>();
|
||||||
if (!Files.isDirectory(buildDir)) {
|
if (!Files.isDirectory(buildDir)) {
|
||||||
Files.deleteIfExists(buildDir);
|
Files.deleteIfExists(buildDir);
|
||||||
Files.createDirectory(buildDir);
|
Files.createDirectory(buildDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +45,7 @@ public void init() {
|
||||||
tasks.add(new AttachJarsTask(server));
|
tasks.add(new AttachJarsTask(server));
|
||||||
tasks.add(new AdditionalFixesApplyTask(server));
|
tasks.add(new AdditionalFixesApplyTask(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build() throws IOException {
|
public void build() throws IOException {
|
||||||
LogHelper.info("Building launcher binary file");
|
LogHelper.info("Building launcher binary file");
|
||||||
|
@ -59,9 +54,8 @@ public void build() throws IOException {
|
||||||
boolean isNeedDelete = false;
|
boolean isNeedDelete = false;
|
||||||
long time_start = System.currentTimeMillis();
|
long time_start = System.currentTimeMillis();
|
||||||
long time_this = time_start;
|
long time_this = time_start;
|
||||||
for(LauncherBuildTask task : tasks)
|
for (LauncherBuildTask task : tasks) {
|
||||||
{
|
LogHelper.subInfo("Task %s", task.getName());
|
||||||
LogHelper.subInfo("Task %s",task.getName());
|
|
||||||
Path oldPath = thisPath;
|
Path oldPath = thisPath;
|
||||||
thisPath = task.process(oldPath);
|
thisPath = task.process(oldPath);
|
||||||
long time_task_end = System.currentTimeMillis();
|
long time_task_end = System.currentTimeMillis();
|
||||||
|
@ -69,27 +63,27 @@ public void build() throws IOException {
|
||||||
time_this = time_task_end;
|
time_this = time_task_end;
|
||||||
if (isNeedDelete && server.config.deleteTempFiles) Files.deleteIfExists(oldPath);
|
if (isNeedDelete && server.config.deleteTempFiles) Files.deleteIfExists(oldPath);
|
||||||
isNeedDelete = task.allowDelete();
|
isNeedDelete = task.allowDelete();
|
||||||
LogHelper.subInfo("Task %s processed from %d millis",task.getName(), time_task);
|
LogHelper.subInfo("Task %s processed from %d millis", task.getName(), time_task);
|
||||||
}
|
}
|
||||||
long time_end = System.currentTimeMillis();
|
long time_end = System.currentTimeMillis();
|
||||||
if (isNeedDelete && server.config.deleteTempFiles) IOHelper.move(thisPath, syncBinaryFile);
|
if (isNeedDelete && server.config.deleteTempFiles) IOHelper.move(thisPath, syncBinaryFile);
|
||||||
else IOHelper.copy(thisPath, syncBinaryFile);
|
else IOHelper.copy(thisPath, syncBinaryFile);
|
||||||
LogHelper.info("Build successful from %d millis",time_end - time_start);
|
LogHelper.info("Build successful from %d millis", time_end - time_start);
|
||||||
}
|
|
||||||
|
|
||||||
public String nextName(String taskName) {
|
|
||||||
return String.format("Launcher-%s-%d.jar", taskName, count.getAndIncrement());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Path nextPath(String taskName) {
|
|
||||||
return buildDir.resolve(nextName(taskName));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Path nextPath(LauncherBuildTask task) {
|
|
||||||
return nextPath(task.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Path nextLowerPath(LauncherBuildTask task) {
|
public String nextName(String taskName) {
|
||||||
return nextPath(CommonHelper.low(task.getName()));
|
return String.format("Launcher-%s-%d.jar", taskName, count.getAndIncrement());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Path nextPath(String taskName) {
|
||||||
|
return buildDir.resolve(nextName(taskName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Path nextPath(LauncherBuildTask task) {
|
||||||
|
return nextPath(task.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Path nextLowerPath(LauncherBuildTask task) {
|
||||||
|
return nextPath(CommonHelper.low(task.getName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package ru.gravit.launchserver.binary;
|
package ru.gravit.launchserver.binary;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.serialize.signed.DigestBytesHolder;
|
import ru.gravit.launcher.serialize.signed.DigestBytesHolder;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public abstract class LauncherBinary {
|
public abstract class LauncherBinary {
|
||||||
public final LaunchServer server;
|
public final LaunchServer server;
|
||||||
public Path syncBinaryFile;
|
public Path syncBinaryFile;
|
||||||
|
|
|
@ -1,21 +1,17 @@
|
||||||
package ru.gravit.launchserver.binary;
|
package ru.gravit.launchserver.binary;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ProguardConf {
|
public class ProguardConf {
|
||||||
private static final String charsFirst = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ";
|
private static final String charsFirst = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ";
|
||||||
private static final String chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ";
|
private static final String chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ";
|
||||||
|
@ -40,17 +36,17 @@ public ProguardConf(LaunchServer srv) {
|
||||||
words = proguard.resolve("random.pro");
|
words = proguard.resolve("random.pro");
|
||||||
this.srv = srv;
|
this.srv = srv;
|
||||||
}
|
}
|
||||||
public String[] buildConfig(Path inputJar, Path outputJar)
|
|
||||||
{
|
public String[] buildConfig(Path inputJar, Path outputJar) {
|
||||||
List<String> confStrs = new ArrayList<>();
|
List<String> confStrs = new ArrayList<>();
|
||||||
prepare(false);
|
prepare(false);
|
||||||
if (srv.config.genMappings) confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'");
|
if (srv.config.genMappings) confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'");
|
||||||
confStrs.add("-obfuscationdictionary \'" + words.toFile().getName() + "\'");
|
confStrs.add("-obfuscationdictionary \'" + words.toFile().getName() + "\'");
|
||||||
confStrs.add("-injar \'" + inputJar.toAbsolutePath() + "\'");
|
confStrs.add("-injar \'" + inputJar.toAbsolutePath() + "\'");
|
||||||
confStrs.add("-outjar \'" + outputJar.toAbsolutePath() + "\'");
|
confStrs.add("-outjar \'" + outputJar.toAbsolutePath() + "\'");
|
||||||
srv.launcherBinary.coreLibs.stream()
|
srv.launcherBinary.coreLibs.stream()
|
||||||
.map(e -> "-libraryjars \'" + e.toAbsolutePath().toString() + "\'")
|
.map(e -> "-libraryjars \'" + e.toAbsolutePath().toString() + "\'")
|
||||||
.forEach(confStrs::add);
|
.forEach(confStrs::add);
|
||||||
confStrs.add("-classobfuscationdictionary \'" + words.toFile().getName() + "\'");
|
confStrs.add("-classobfuscationdictionary \'" + words.toFile().getName() + "\'");
|
||||||
confStrs.add(readConf());
|
confStrs.add(readConf());
|
||||||
return confStrs.toArray(new String[0]);
|
return confStrs.toArray(new String[0]);
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
package ru.gravit.launchserver.binary.tasks;
|
package ru.gravit.launchserver.binary.tasks;
|
||||||
|
|
||||||
|
import org.objectweb.asm.ClassReader;
|
||||||
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.asm.ClassMetadataReader;
|
||||||
|
import ru.gravit.launchserver.asm.SafeClassWriter;
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -8,71 +16,62 @@
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import org.objectweb.asm.ClassReader;
|
|
||||||
import org.objectweb.asm.ClassWriter;
|
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
|
||||||
import ru.gravit.launchserver.asm.ClassMetadataReader;
|
|
||||||
import ru.gravit.launchserver.asm.SafeClassWriter;
|
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
|
||||||
|
|
||||||
public class AdditionalFixesApplyTask implements LauncherBuildTask {
|
public class AdditionalFixesApplyTask implements LauncherBuildTask {
|
||||||
private final LaunchServer server;
|
private final LaunchServer server;
|
||||||
|
|
||||||
public AdditionalFixesApplyTask(LaunchServer server) {
|
|
||||||
this.server = server;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public AdditionalFixesApplyTask(LaunchServer server) {
|
||||||
public String getName() {
|
this.server = server;
|
||||||
return "AdditionalFixesApply";
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path process(Path inputFile) throws IOException {
|
public String getName() {
|
||||||
Path out = server.launcherBinary.nextPath("post-fixed");
|
return "AdditionalFixesApply";
|
||||||
try (ClassMetadataReader reader = new ClassMetadataReader()) {
|
}
|
||||||
reader.getCp().add(new JarFile(inputFile.toFile()));
|
|
||||||
try (ZipInputStream input = IOHelper.newZipInput(inputFile);
|
|
||||||
ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(out))) {
|
|
||||||
ZipEntry e = input.getNextEntry();
|
|
||||||
while (e != null) {
|
|
||||||
if (e.isDirectory()) {
|
|
||||||
e = input.getNextEntry();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String filename = e.getName();
|
|
||||||
output.putNextEntry(IOHelper.newZipEntry(e));
|
|
||||||
if (filename.endsWith(".class")) {
|
|
||||||
byte[] bytes = null;
|
|
||||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) {
|
|
||||||
IOHelper.transfer(input, outputStream);
|
|
||||||
bytes = outputStream.toByteArray();
|
|
||||||
}
|
|
||||||
output.write(classFix(bytes, reader, server.config.stripLineNumbers));
|
|
||||||
} else
|
|
||||||
IOHelper.transfer(input, output);
|
|
||||||
e = input.getNextEntry();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static byte[] classFix(byte[] bytes, ClassMetadataReader reader, boolean stripNumbers) {
|
@Override
|
||||||
ClassReader cr = new ClassReader(bytes);
|
public Path process(Path inputFile) throws IOException {
|
||||||
ClassNode cn = new ClassNode();
|
Path out = server.launcherBinary.nextPath("post-fixed");
|
||||||
cr.accept(cn, stripNumbers ? (ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES) : ClassReader.SKIP_FRAMES);
|
try (ClassMetadataReader reader = new ClassMetadataReader()) {
|
||||||
|
reader.getCp().add(new JarFile(inputFile.toFile()));
|
||||||
ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
try (ZipInputStream input = IOHelper.newZipInput(inputFile);
|
||||||
cn.accept(cw);
|
ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(out))) {
|
||||||
return cw.toByteArray();
|
ZipEntry e = input.getNextEntry();
|
||||||
}
|
while (e != null) {
|
||||||
|
if (e.isDirectory()) {
|
||||||
|
e = input.getNextEntry();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String filename = e.getName();
|
||||||
|
output.putNextEntry(IOHelper.newZipEntry(e));
|
||||||
|
if (filename.endsWith(".class")) {
|
||||||
|
byte[] bytes = null;
|
||||||
|
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) {
|
||||||
|
IOHelper.transfer(input, outputStream);
|
||||||
|
bytes = outputStream.toByteArray();
|
||||||
|
}
|
||||||
|
output.write(classFix(bytes, reader, server.config.stripLineNumbers));
|
||||||
|
} else
|
||||||
|
IOHelper.transfer(input, output);
|
||||||
|
e = input.getNextEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
private static byte[] classFix(byte[] bytes, ClassMetadataReader reader, boolean stripNumbers) {
|
||||||
public boolean allowDelete() {
|
ClassReader cr = new ClassReader(bytes);
|
||||||
return true;
|
ClassNode cn = new ClassNode();
|
||||||
}
|
cr.accept(cn, stripNumbers ? (ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES) : ClassReader.SKIP_FRAMES);
|
||||||
|
|
||||||
|
ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
|
cn.accept(cw);
|
||||||
|
return cw.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean allowDelete() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package ru.gravit.launchserver.binary.tasks;
|
package ru.gravit.launchserver.binary.tasks;
|
||||||
|
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -8,75 +12,71 @@
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public class AttachJarsTask implements LauncherBuildTask {
|
public class AttachJarsTask implements LauncherBuildTask {
|
||||||
private final LaunchServer srv;
|
private final LaunchServer srv;
|
||||||
private final List<Path> jars;
|
private final List<Path> jars;
|
||||||
private final List<String> exclusions;
|
private final List<String> exclusions;
|
||||||
|
|
||||||
public AttachJarsTask(LaunchServer srv) {
|
public AttachJarsTask(LaunchServer srv) {
|
||||||
this.srv = srv;
|
this.srv = srv;
|
||||||
jars = new ArrayList<>();
|
jars = new ArrayList<>();
|
||||||
exclusions = new ArrayList<>();
|
exclusions = new ArrayList<>();
|
||||||
exclusions.add("META-INF");
|
exclusions.add("META-INF");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "AttachJars";
|
return "AttachJars";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path process(Path inputFile) throws IOException {
|
public Path process(Path inputFile) throws IOException {
|
||||||
Path outputFile = srv.launcherBinary.nextPath("attached");
|
Path outputFile = srv.launcherBinary.nextPath("attached");
|
||||||
try (ZipInputStream input = IOHelper.newZipInput(inputFile);
|
try (ZipInputStream input = IOHelper.newZipInput(inputFile);
|
||||||
ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(outputFile))) {
|
ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(outputFile))) {
|
||||||
ZipEntry e = input.getNextEntry();
|
ZipEntry e = input.getNextEntry();
|
||||||
while (e != null) {
|
while (e != null) {
|
||||||
if (e.isDirectory()) {
|
if (e.isDirectory()) {
|
||||||
e = input.getNextEntry();
|
e = input.getNextEntry();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
output.putNextEntry(IOHelper.newZipEntry(e));
|
output.putNextEntry(IOHelper.newZipEntry(e));
|
||||||
IOHelper.transfer(input, output);
|
IOHelper.transfer(input, output);
|
||||||
e = input.getNextEntry();
|
e = input.getNextEntry();
|
||||||
}
|
}
|
||||||
attach(output, srv.launcherBinary.coreLibs);
|
attach(output, srv.launcherBinary.coreLibs);
|
||||||
attach(output, jars);
|
attach(output, jars);
|
||||||
}
|
}
|
||||||
return outputFile;
|
return outputFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attach(ZipOutputStream output, List<Path> lst) throws IOException {
|
private void attach(ZipOutputStream output, List<Path> lst) throws IOException {
|
||||||
for (Path p : lst) {
|
for (Path p : lst) {
|
||||||
LogHelper.debug("Attaching: " + p);
|
LogHelper.debug("Attaching: " + p);
|
||||||
try (ZipInputStream input = IOHelper.newZipInput(p)) {
|
try (ZipInputStream input = IOHelper.newZipInput(p)) {
|
||||||
ZipEntry e = input.getNextEntry();
|
ZipEntry e = input.getNextEntry();
|
||||||
while (e != null) {
|
while (e != null) {
|
||||||
String filename = e.getName();
|
String filename = e.getName();
|
||||||
if (exclusions.stream().noneMatch(filename::startsWith) && !e.isDirectory()) {
|
if (exclusions.stream().noneMatch(filename::startsWith) && !e.isDirectory()) {
|
||||||
output.putNextEntry(IOHelper.newZipEntry(e));
|
output.putNextEntry(IOHelper.newZipEntry(e));
|
||||||
IOHelper.transfer(input, output);
|
IOHelper.transfer(input, output);
|
||||||
}
|
}
|
||||||
e = input.getNextEntry();
|
e = input.getNextEntry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean allowDelete() {
|
public boolean allowDelete() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Path> getJars() {
|
public List<Path> getJars() {
|
||||||
return jars;
|
return jars;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getExclusions() {
|
public List<String> getExclusions() {
|
||||||
return exclusions;
|
return exclusions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
public interface LauncherBuildTask {
|
public interface LauncherBuildTask {
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
Path process(Path inputFile) throws IOException;
|
Path process(Path inputFile) throws IOException;
|
||||||
|
|
||||||
boolean allowDelete();
|
boolean allowDelete();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,5 @@
|
||||||
package ru.gravit.launchserver.binary.tasks;
|
package ru.gravit.launchserver.binary.tasks;
|
||||||
|
|
||||||
import static ru.gravit.utils.helper.IOHelper.newZipEntry;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.FileVisitResult;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.SimpleFileVisitor;
|
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.jar.JarFile;
|
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipException;
|
|
||||||
import java.util.zip.ZipInputStream;
|
|
||||||
import java.util.zip.ZipOutputStream;
|
|
||||||
|
|
||||||
import javassist.CannotCompileException;
|
import javassist.CannotCompileException;
|
||||||
import javassist.NotFoundException;
|
import javassist.NotFoundException;
|
||||||
import ru.gravit.launcher.AutogenConfig;
|
import ru.gravit.launcher.AutogenConfig;
|
||||||
|
@ -30,9 +14,26 @@
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileVisitResult;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.SimpleFileVisitor;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipException;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
import static ru.gravit.utils.helper.IOHelper.newZipEntry;
|
||||||
|
|
||||||
public class MainBuildTask implements LauncherBuildTask {
|
public class MainBuildTask implements LauncherBuildTask {
|
||||||
private final LaunchServer server;
|
private final LaunchServer server;
|
||||||
public final ClassMetadataReader reader;
|
public final ClassMetadataReader reader;
|
||||||
|
|
||||||
private final class RuntimeDirVisitor extends SimpleFileVisitor<Path> {
|
private final class RuntimeDirVisitor extends SimpleFileVisitor<Path> {
|
||||||
private final ZipOutputStream output;
|
private final ZipOutputStream output;
|
||||||
private final Map<String, byte[]> runtime;
|
private final Map<String, byte[]> runtime;
|
||||||
|
@ -102,7 +103,7 @@ private static ZipEntry newGuardEntry(String fileName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MainBuildTask(LaunchServer srv) {
|
public MainBuildTask(LaunchServer srv) {
|
||||||
server = srv;
|
server = srv;
|
||||||
reader = new ClassMetadataReader();
|
reader = new ClassMetadataReader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,13 +119,13 @@ public Path process(Path inputJar) throws IOException {
|
||||||
JAConfigurator jaConfigurator = new JAConfigurator(AutogenConfig.class.getName(), this)) {
|
JAConfigurator jaConfigurator = new JAConfigurator(AutogenConfig.class.getName(), this)) {
|
||||||
jaConfigurator.pool.insertClassPath(inputJar.toFile().getAbsolutePath());
|
jaConfigurator.pool.insertClassPath(inputJar.toFile().getAbsolutePath());
|
||||||
server.launcherBinary.coreLibs.stream().map(e -> e.toFile().getAbsolutePath())
|
server.launcherBinary.coreLibs.stream().map(e -> e.toFile().getAbsolutePath())
|
||||||
.forEach(t -> {
|
.forEach(t -> {
|
||||||
try {
|
try {
|
||||||
jaConfigurator.pool.appendClassPath(t);
|
jaConfigurator.pool.appendClassPath(t);
|
||||||
} catch (NotFoundException e2) {
|
} catch (NotFoundException e2) {
|
||||||
LogHelper.error(e2);
|
LogHelper.error(e2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
BuildContext context = new BuildContext(output, jaConfigurator, this);
|
BuildContext context = new BuildContext(output, jaConfigurator, this);
|
||||||
server.buildHookManager.hook(context);
|
server.buildHookManager.hook(context);
|
||||||
jaConfigurator.setAddress(server.config.getAddress());
|
jaConfigurator.setAddress(server.config.getAddress());
|
||||||
|
@ -138,12 +139,12 @@ public Path process(Path inputJar) throws IOException {
|
||||||
server.buildHookManager.registerAllClientModuleClass(jaConfigurator);
|
server.buildHookManager.registerAllClientModuleClass(jaConfigurator);
|
||||||
reader.getCp().add(new JarFile(inputJar.toFile()));
|
reader.getCp().add(new JarFile(inputJar.toFile()));
|
||||||
server.launcherBinary.coreLibs.forEach(e -> {
|
server.launcherBinary.coreLibs.forEach(e -> {
|
||||||
try {
|
try {
|
||||||
reader.getCp().add(new JarFile(e.toFile()));
|
reader.getCp().add(new JarFile(e.toFile()));
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
LogHelper.error(e1);
|
LogHelper.error(e1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(inputJar))) {
|
try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(inputJar))) {
|
||||||
ZipEntry e = input.getNextEntry();
|
ZipEntry e = input.getNextEntry();
|
||||||
while (e != null) {
|
while (e != null) {
|
||||||
|
@ -169,7 +170,7 @@ public Path process(Path inputJar) throws IOException {
|
||||||
}
|
}
|
||||||
bytes = server.buildHookManager.classTransform(bytes, classname, this);
|
bytes = server.buildHookManager.classTransform(bytes, classname, this);
|
||||||
output.write(bytes);
|
output.write(bytes);
|
||||||
} else
|
} else
|
||||||
IOHelper.transfer(input, output);
|
IOHelper.transfer(input, output);
|
||||||
context.fileList.add(filename);
|
context.fileList.add(filename);
|
||||||
e = input.getNextEntry();
|
e = input.getNextEntry();
|
||||||
|
|
|
@ -15,12 +15,12 @@
|
||||||
|
|
||||||
public class PrepareBuildTask implements LauncherBuildTask {
|
public class PrepareBuildTask implements LauncherBuildTask {
|
||||||
private final LaunchServer server;
|
private final LaunchServer server;
|
||||||
private final Path result;
|
private final Path result;
|
||||||
|
|
||||||
public PrepareBuildTask(LaunchServer server) {
|
public PrepareBuildTask(LaunchServer server) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
result = server.launcherBinary.buildDir.resolve(server.config.binaryName + "-clean.jar");
|
result = server.launcherBinary.buildDir.resolve(server.config.binaryName + "-clean.jar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -29,8 +29,8 @@ public String getName() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path process(Path inputFile) throws IOException {
|
public Path process(Path inputFile) throws IOException {
|
||||||
server.launcherBinary.coreLibs.clear();
|
server.launcherBinary.coreLibs.clear();
|
||||||
IOHelper.walk(server.launcherLibraries, new ListFileVisitor(server.launcherBinary.coreLibs), true);
|
IOHelper.walk(server.launcherLibraries, new ListFileVisitor(server.launcherBinary.coreLibs), true);
|
||||||
UnpackHelper.unpack(IOHelper.getResourceURL("Launcher.jar"), result);
|
UnpackHelper.unpack(IOHelper.getResourceURL("Launcher.jar"), result);
|
||||||
tryUnpack();
|
tryUnpack();
|
||||||
return result;
|
return result;
|
||||||
|
@ -46,7 +46,7 @@ public void tryUnpack() throws IOException {
|
||||||
UnpackHelper.unpackZipNoCheck("guard.zip", server.launcherBinary.guardDir);
|
UnpackHelper.unpackZipNoCheck("guard.zip", server.launcherBinary.guardDir);
|
||||||
UnpackHelper.unpackZipNoCheck("runtime.zip", server.launcherBinary.runtimeDir);
|
UnpackHelper.unpackZipNoCheck("runtime.zip", server.launcherBinary.runtimeDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class ListFileVisitor extends SimpleFileVisitor<Path> {
|
private static final class ListFileVisitor extends SimpleFileVisitor<Path> {
|
||||||
private final List<Path> lst;
|
private final List<Path> lst;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package ru.gravit.launchserver.binary.tasks;
|
package ru.gravit.launchserver.binary.tasks;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
import proguard.Configuration;
|
import proguard.Configuration;
|
||||||
import proguard.ConfigurationParser;
|
import proguard.ConfigurationParser;
|
||||||
import proguard.ParseException;
|
import proguard.ParseException;
|
||||||
|
@ -11,38 +8,41 @@
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class ProGuardBuildTask implements LauncherBuildTask {
|
public class ProGuardBuildTask implements LauncherBuildTask {
|
||||||
private final LaunchServer server;
|
private final LaunchServer server;
|
||||||
|
|
||||||
public ProGuardBuildTask(LaunchServer server) {
|
public ProGuardBuildTask(LaunchServer server) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "ProGuard";
|
return "ProGuard";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path process(Path inputFile) throws IOException {
|
public Path process(Path inputFile) throws IOException {
|
||||||
if (server.config.enabledProGuard) {
|
if (server.config.enabledProGuard) {
|
||||||
Path outputJar = server.launcherBinary.nextLowerPath(this);
|
Path outputJar = server.launcherBinary.nextLowerPath(this);
|
||||||
Configuration proguard_cfg = new Configuration();
|
Configuration proguard_cfg = new Configuration();
|
||||||
ConfigurationParser parser = new ConfigurationParser(server.proguardConf.buildConfig(inputFile, outputJar),
|
ConfigurationParser parser = new ConfigurationParser(server.proguardConf.buildConfig(inputFile, outputJar),
|
||||||
server.proguardConf.proguard.toFile(), System.getProperties());
|
server.proguardConf.proguard.toFile(), System.getProperties());
|
||||||
try {
|
try {
|
||||||
parser.parse(proguard_cfg);
|
parser.parse(proguard_cfg);
|
||||||
ProGuard proGuard = new ProGuard(proguard_cfg);
|
ProGuard proGuard = new ProGuard(proguard_cfg);
|
||||||
proGuard.execute();
|
proGuard.execute();
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
}
|
}
|
||||||
return outputJar;
|
return outputJar;
|
||||||
} else {
|
} else {
|
||||||
Path outputJar = server.launcherBinary.nextPath("non-obf");
|
Path outputJar = server.launcherBinary.nextPath("non-obf");
|
||||||
IOHelper.copy(inputFile, outputJar);
|
IOHelper.copy(inputFile, outputJar);
|
||||||
return outputJar;
|
return outputJar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,46 +6,46 @@
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public final class TaskUtil {
|
public final class TaskUtil {
|
||||||
public static void addCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
|
public static void addCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
|
||||||
List<LauncherBuildTask> indexes = new ArrayList<>();
|
List<LauncherBuildTask> indexes = new ArrayList<>();
|
||||||
tasks.stream().filter(pred).forEach(e -> indexes.add(e));
|
tasks.stream().filter(pred).forEach(e -> indexes.add(e));
|
||||||
indexes.forEach(e -> tasks.add(tasks.indexOf(e)+count, taskAdd));
|
indexes.forEach(e -> tasks.add(tasks.indexOf(e) + count, taskAdd));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void replaceCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
|
public static void replaceCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
|
||||||
List<LauncherBuildTask> indexes = new ArrayList<>();
|
List<LauncherBuildTask> indexes = new ArrayList<>();
|
||||||
tasks.stream().filter(pred).forEach(e -> indexes.add(e));
|
tasks.stream().filter(pred).forEach(e -> indexes.add(e));
|
||||||
indexes.forEach(e -> tasks.set(tasks.indexOf(e)+count, taskRep));
|
indexes.forEach(e -> tasks.set(tasks.indexOf(e) + count, taskRep));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addPre(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
|
public static void addPre(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
|
||||||
addCounted(tasks, -1, pred, taskAdd);
|
addCounted(tasks, -1, pred, taskAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void add(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
|
public static void add(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
|
||||||
addCounted(tasks, 0, pred, taskAdd);
|
addCounted(tasks, 0, pred, taskAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addAfter(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
|
public static void addAfter(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
|
||||||
addCounted(tasks, 1, pred, taskAdd);
|
addCounted(tasks, 1, pred, taskAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void replacePre(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
|
public static void replacePre(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
|
||||||
replaceCounted(tasks, -1, pred, taskRep);
|
replaceCounted(tasks, -1, pred, taskRep);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void replace(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
|
public static void replace(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
|
||||||
replaceCounted(tasks, 0, pred, taskRep);
|
replaceCounted(tasks, 0, pred, taskRep);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void replaceAfter(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
|
public static void replaceAfter(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
|
||||||
replaceCounted(tasks, 1, pred, taskRep);
|
replaceCounted(tasks, 1, pred, taskRep);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends LauncherBuildTask> List<T> getTaskByClass(List<LauncherBuildTask> tasks, Class<T> taskClass) {
|
public static <T extends LauncherBuildTask> List<T> getTaskByClass(List<LauncherBuildTask> tasks, Class<T> taskClass) {
|
||||||
return tasks.stream().filter(taskClass::isInstance).map(taskClass::cast).collect(Collectors.toList());
|
return tasks.stream().filter(taskClass::isInstance).map(taskClass::cast).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private TaskUtil() {
|
private TaskUtil() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package ru.gravit.launchserver.command;
|
package ru.gravit.launchserver.command;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class Command {
|
public abstract class Command {
|
||||||
|
|
||||||
protected static String parseUsername(String username) throws CommandException {
|
protected static String parseUsername(String username) throws CommandException {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package ru.gravit.launchserver.command.auth;
|
package ru.gravit.launchserver.command.auth;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.auth.provider.AuthProvider;
|
import ru.gravit.launchserver.auth.provider.AuthProvider;
|
||||||
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class AuthCommand extends Command {
|
public final class AuthCommand extends Command {
|
||||||
public AuthCommand(LaunchServer server) {
|
public AuthCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package ru.gravit.launchserver.command.auth;
|
package ru.gravit.launchserver.command.auth;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.HWID;
|
import ru.gravit.launcher.HWID;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class BanCommand extends Command {
|
public class BanCommand extends Command {
|
||||||
public BanCommand(LaunchServer server) {
|
public BanCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package ru.gravit.launchserver.command.auth;
|
package ru.gravit.launchserver.command.auth;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
import ru.gravit.launchserver.command.CommandException;
|
import ru.gravit.launchserver.command.CommandException;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class UUIDToUsernameCommand extends Command {
|
public final class UUIDToUsernameCommand extends Command {
|
||||||
public UUIDToUsernameCommand(LaunchServer server) {
|
public UUIDToUsernameCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package ru.gravit.launchserver.command.auth;
|
package ru.gravit.launchserver.command.auth;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.HWID;
|
import ru.gravit.launcher.HWID;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class UnbanCommand extends Command {
|
public class UnbanCommand extends Command {
|
||||||
public UnbanCommand(LaunchServer server) {
|
public UnbanCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package ru.gravit.launchserver.command.auth;
|
package ru.gravit.launchserver.command.auth;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
import ru.gravit.launchserver.command.CommandException;
|
import ru.gravit.launchserver.command.CommandException;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class UsernameToUUIDCommand extends Command {
|
public final class UsernameToUUIDCommand extends Command {
|
||||||
public UsernameToUUIDCommand(LaunchServer server) {
|
public UsernameToUUIDCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -24,12 +24,11 @@ public void invoke(String... args) {
|
||||||
boolean newValue, newTraceValue;
|
boolean newValue, newTraceValue;
|
||||||
if (args.length >= 1) {
|
if (args.length >= 1) {
|
||||||
newValue = Boolean.parseBoolean(args[0]);
|
newValue = Boolean.parseBoolean(args[0]);
|
||||||
if(args.length >= 2) newTraceValue = Boolean.parseBoolean(args[1]);
|
if (args.length >= 2) newTraceValue = Boolean.parseBoolean(args[1]);
|
||||||
else newTraceValue = newValue;
|
else newTraceValue = newValue;
|
||||||
LogHelper.setDebugEnabled(newValue);
|
LogHelper.setDebugEnabled(newValue);
|
||||||
LogHelper.setStacktraceEnabled(newTraceValue);
|
LogHelper.setStacktraceEnabled(newTraceValue);
|
||||||
} else
|
} else {
|
||||||
{
|
|
||||||
newValue = LogHelper.isDebugEnabled();
|
newValue = LogHelper.isDebugEnabled();
|
||||||
newTraceValue = LogHelper.isStacktraceEnabled();
|
newTraceValue = LogHelper.isStacktraceEnabled();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package ru.gravit.launchserver.command.basic;
|
package ru.gravit.launchserver.command.basic;
|
||||||
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
import ru.gravit.launchserver.command.CommandException;
|
import ru.gravit.launchserver.command.CommandException;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
public final class HelpCommand extends Command {
|
public final class HelpCommand extends Command {
|
||||||
private static void printCommand(String name, Command command) {
|
private static void printCommand(String name, Command command) {
|
||||||
String args = command.getArgsDescription();
|
String args = command.getArgsDescription();
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package ru.gravit.launchserver.command.basic;
|
package ru.gravit.launchserver.command.basic;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
public class ProguardCleanCommand extends Command {
|
public class ProguardCleanCommand extends Command {
|
||||||
public ProguardCleanCommand(LaunchServer server) {
|
public ProguardCleanCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package ru.gravit.launchserver.command.basic;
|
package ru.gravit.launchserver.command.basic;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class RegenProguardDictCommand extends Command {
|
public class RegenProguardDictCommand extends Command {
|
||||||
|
|
||||||
public RegenProguardDictCommand(LaunchServer server) {
|
public RegenProguardDictCommand(LaunchServer server) {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package ru.gravit.launchserver.command.basic;
|
package ru.gravit.launchserver.command.basic;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
public class RemoveMappingsProguardCommand extends Command {
|
public class RemoveMappingsProguardCommand extends Command {
|
||||||
|
|
||||||
public RemoveMappingsProguardCommand(LaunchServer server) {
|
public RemoveMappingsProguardCommand(LaunchServer server) {
|
||||||
|
|
|
@ -20,6 +20,6 @@ public String getUsageDescription() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) {
|
public void invoke(String... args) {
|
||||||
server.fullyRestart();
|
server.fullyRestart();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,5 @@
|
||||||
package ru.gravit.launchserver.command.basic;
|
package ru.gravit.launchserver.command.basic;
|
||||||
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.profiles.ClientProfile;
|
import ru.gravit.launcher.profiles.ClientProfile;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
@ -9,6 +7,8 @@
|
||||||
import ru.gravit.utils.helper.CommonHelper;
|
import ru.gravit.utils.helper.CommonHelper;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
|
import java.io.Writer;
|
||||||
|
|
||||||
public class TestCommand extends Command {
|
public class TestCommand extends Command {
|
||||||
public TestCommand(LaunchServer server) {
|
public TestCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
@ -35,10 +35,9 @@ public void invoke(String... args) throws Exception {
|
||||||
CommonHelper.newThread("Netty Server", true, handler).start();
|
CommonHelper.newThread("Netty Server", true, handler).start();
|
||||||
}
|
}
|
||||||
if (args[0].equals("profile")) {
|
if (args[0].equals("profile")) {
|
||||||
ClientProfile profile = new ClientProfile("1.7.10","asset1.7.10",0,"Test1.7.10","localhost",25565,true,false,"net.minecraft.launchwrapper.Launch");
|
ClientProfile profile = new ClientProfile("1.7.10", "asset1.7.10", 0, "Test1.7.10", "localhost", 25565, true, false, "net.minecraft.launchwrapper.Launch");
|
||||||
try(Writer writer = IOHelper.newWriter(server.dir.resolve("profiles").resolve("Test.cfg")))
|
try (Writer writer = IOHelper.newWriter(server.dir.resolve("profiles").resolve("Test.cfg"))) {
|
||||||
{
|
LaunchServer.gson.toJson(profile, writer);
|
||||||
LaunchServer.gson.toJson(profile,writer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package ru.gravit.launchserver.command.dump;
|
package ru.gravit.launchserver.command.dump;
|
||||||
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.auth.handler.CachedAuthHandler;
|
import ru.gravit.launchserver.auth.handler.CachedAuthHandler;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class DumpEntryCacheCommand extends Command {
|
public class DumpEntryCacheCommand extends Command {
|
||||||
public DumpEntryCacheCommand(LaunchServer server) {
|
public DumpEntryCacheCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
@ -29,43 +29,39 @@ public String getUsageDescription() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
verifyArgs(args,2);
|
verifyArgs(args, 2);
|
||||||
if(!(server.config.authHandler instanceof CachedAuthHandler)) throw new UnsupportedOperationException("This command used only CachedAuthHandler");
|
if (!(server.config.authHandler instanceof CachedAuthHandler))
|
||||||
|
throw new UnsupportedOperationException("This command used only CachedAuthHandler");
|
||||||
CachedAuthHandler authHandler = (CachedAuthHandler) server.config.authHandler;
|
CachedAuthHandler authHandler = (CachedAuthHandler) server.config.authHandler;
|
||||||
if(args[0].equals("unload"))
|
if (args[0].equals("unload")) {
|
||||||
{
|
LogHelper.info("CachedAuthHandler write to %s", args[1]);
|
||||||
LogHelper.info("CachedAuthHandler write to %s",args[1]);
|
Map<UUID, CachedAuthHandler.Entry> entryCache = authHandler.getEntryCache();
|
||||||
Map<UUID,CachedAuthHandler.Entry> entryCache = authHandler.getEntryCache();
|
|
||||||
Map<String, UUID> usernamesCache = authHandler.getUsernamesCache();
|
Map<String, UUID> usernamesCache = authHandler.getUsernamesCache();
|
||||||
EntryAndUsername serializable = new EntryAndUsername();
|
EntryAndUsername serializable = new EntryAndUsername();
|
||||||
serializable.entryCache = entryCache;
|
serializable.entryCache = entryCache;
|
||||||
serializable.usernameCache = usernamesCache;
|
serializable.usernameCache = usernamesCache;
|
||||||
try(Writer writer = IOHelper.newWriter(Paths.get(args[1])))
|
try (Writer writer = IOHelper.newWriter(Paths.get(args[1]))) {
|
||||||
{
|
LaunchServer.gson.toJson(serializable, writer);
|
||||||
LaunchServer.gson.toJson(serializable,writer);
|
|
||||||
}
|
}
|
||||||
LogHelper.subInfo("Write %d entryCache, %d usernameCache",entryCache.size(),usernamesCache.size());
|
LogHelper.subInfo("Write %d entryCache, %d usernameCache", entryCache.size(), usernamesCache.size());
|
||||||
} else if(args[0].equals("load"))
|
} else if (args[0].equals("load")) {
|
||||||
{
|
LogHelper.info("CachedAuthHandler read from %s", args[1]);
|
||||||
LogHelper.info("CachedAuthHandler read from %s",args[1]);
|
|
||||||
int size_entry = 0;
|
int size_entry = 0;
|
||||||
int size_username = 0;
|
int size_username = 0;
|
||||||
try(Reader reader = IOHelper.newReader(Paths.get(args[1])))
|
try (Reader reader = IOHelper.newReader(Paths.get(args[1]))) {
|
||||||
{
|
EntryAndUsername entryAndUsername = LaunchServer.gson.fromJson(reader, EntryAndUsername.class);
|
||||||
EntryAndUsername entryAndUsername = LaunchServer.gson.fromJson(reader,EntryAndUsername.class);
|
|
||||||
size_entry = entryAndUsername.entryCache.size();
|
size_entry = entryAndUsername.entryCache.size();
|
||||||
size_username = entryAndUsername.usernameCache.size();
|
size_username = entryAndUsername.usernameCache.size();
|
||||||
authHandler.loadEntryCache(entryAndUsername.entryCache);
|
authHandler.loadEntryCache(entryAndUsername.entryCache);
|
||||||
authHandler.loadUsernameCache(entryAndUsername.usernameCache);
|
authHandler.loadUsernameCache(entryAndUsername.usernameCache);
|
||||||
|
|
||||||
}
|
}
|
||||||
LogHelper.subInfo("Readed %d entryCache %d usernameCache",size_entry,size_username);
|
LogHelper.subInfo("Readed %d entryCache %d usernameCache", size_entry, size_username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EntryAndUsername
|
public class EntryAndUsername {
|
||||||
{
|
public Map<UUID, CachedAuthHandler.Entry> entryCache;
|
||||||
public Map<UUID,CachedAuthHandler.Entry> entryCache;
|
|
||||||
public Map<String, UUID> usernameCache;
|
public Map<String, UUID> usernameCache;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
package ru.gravit.launchserver.command.dump;
|
package ru.gravit.launchserver.command.dump;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
import ru.gravit.launchserver.socket.Client;
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
@ -7,14 +14,6 @@
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
|
||||||
import ru.gravit.launchserver.command.Command;
|
|
||||||
import ru.gravit.launchserver.socket.Client;
|
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public class DumpSessionsCommand extends Command {
|
public class DumpSessionsCommand extends Command {
|
||||||
public DumpSessionsCommand(LaunchServer server) {
|
public DumpSessionsCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
@ -32,28 +31,25 @@ public String getUsageDescription() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
verifyArgs(args,2);
|
verifyArgs(args, 2);
|
||||||
if(args[0].equals("unload"))
|
if (args[0].equals("unload")) {
|
||||||
{
|
LogHelper.info("Sessions write to %s", args[1]);
|
||||||
LogHelper.info("Sessions write to %s",args[1]);
|
|
||||||
Set<Client> clientSet = server.sessionManager.getSessions();
|
Set<Client> clientSet = server.sessionManager.getSessions();
|
||||||
try(Writer writer = IOHelper.newWriter(Paths.get(args[1])))
|
try (Writer writer = IOHelper.newWriter(Paths.get(args[1]))) {
|
||||||
{
|
LaunchServer.gson.toJson(clientSet, writer);
|
||||||
LaunchServer.gson.toJson(clientSet,writer);
|
|
||||||
}
|
}
|
||||||
LogHelper.subInfo("Write %d sessions",clientSet.size());
|
LogHelper.subInfo("Write %d sessions", clientSet.size());
|
||||||
} else if(args[0].equals("load"))
|
} else if (args[0].equals("load")) {
|
||||||
{
|
LogHelper.info("Sessions read from %s", args[1]);
|
||||||
LogHelper.info("Sessions read from %s",args[1]);
|
|
||||||
int size = 0;
|
int size = 0;
|
||||||
try(Reader reader = IOHelper.newReader(Paths.get(args[1])))
|
try (Reader reader = IOHelper.newReader(Paths.get(args[1]))) {
|
||||||
{
|
Type setType = new TypeToken<HashSet<Client>>() {
|
||||||
Type setType = new TypeToken<HashSet<Client>>(){}.getType();
|
}.getType();
|
||||||
Set<Client> clientSet = LaunchServer.gson.fromJson(reader,setType);
|
Set<Client> clientSet = LaunchServer.gson.fromJson(reader, setType);
|
||||||
size = clientSet.size();
|
size = clientSet.size();
|
||||||
server.sessionManager.loadSessions(clientSet);
|
server.sessionManager.loadSessions(clientSet);
|
||||||
}
|
}
|
||||||
LogHelper.subInfo("Readed %d sessions",size);
|
LogHelper.subInfo("Readed %d sessions", size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,53 +1,25 @@
|
||||||
package ru.gravit.launchserver.command.handler;
|
package ru.gravit.launchserver.command.handler;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
import ru.gravit.launchserver.command.CommandException;
|
import ru.gravit.launchserver.command.CommandException;
|
||||||
import ru.gravit.launchserver.command.auth.AuthCommand;
|
import ru.gravit.launchserver.command.auth.*;
|
||||||
import ru.gravit.launchserver.command.auth.BanCommand;
|
import ru.gravit.launchserver.command.basic.*;
|
||||||
import ru.gravit.launchserver.command.auth.UUIDToUsernameCommand;
|
|
||||||
import ru.gravit.launchserver.command.auth.UnbanCommand;
|
|
||||||
import ru.gravit.launchserver.command.auth.UsernameToUUIDCommand;
|
|
||||||
import ru.gravit.launchserver.command.basic.BuildCommand;
|
|
||||||
import ru.gravit.launchserver.command.basic.ClearCommand;
|
|
||||||
import ru.gravit.launchserver.command.basic.DebugCommand;
|
|
||||||
import ru.gravit.launchserver.command.basic.GCCommand;
|
|
||||||
import ru.gravit.launchserver.command.basic.HelpCommand;
|
|
||||||
import ru.gravit.launchserver.command.basic.LogConnectionsCommand;
|
|
||||||
import ru.gravit.launchserver.command.basic.ProguardCleanCommand;
|
|
||||||
import ru.gravit.launchserver.command.basic.RebindCommand;
|
|
||||||
import ru.gravit.launchserver.command.basic.RegenProguardDictCommand;
|
|
||||||
import ru.gravit.launchserver.command.basic.RemoveMappingsProguardCommand;
|
|
||||||
import ru.gravit.launchserver.command.basic.RestartCommand;
|
|
||||||
import ru.gravit.launchserver.command.basic.StopCommand;
|
|
||||||
import ru.gravit.launchserver.command.basic.TestCommand;
|
|
||||||
import ru.gravit.launchserver.command.basic.VersionCommand;
|
|
||||||
import ru.gravit.launchserver.command.dump.DumpEntryCacheCommand;
|
import ru.gravit.launchserver.command.dump.DumpEntryCacheCommand;
|
||||||
import ru.gravit.launchserver.command.dump.DumpSessionsCommand;
|
import ru.gravit.launchserver.command.dump.DumpSessionsCommand;
|
||||||
import ru.gravit.launchserver.command.hash.DownloadAssetCommand;
|
import ru.gravit.launchserver.command.hash.*;
|
||||||
import ru.gravit.launchserver.command.hash.DownloadClientCommand;
|
|
||||||
import ru.gravit.launchserver.command.hash.IndexAssetCommand;
|
|
||||||
import ru.gravit.launchserver.command.hash.SyncBinariesCommand;
|
|
||||||
import ru.gravit.launchserver.command.hash.SyncProfilesCommand;
|
|
||||||
import ru.gravit.launchserver.command.hash.SyncUpdatesCommand;
|
|
||||||
import ru.gravit.launchserver.command.hash.UnindexAssetCommand;
|
|
||||||
import ru.gravit.launchserver.command.modules.LoadModuleCommand;
|
import ru.gravit.launchserver.command.modules.LoadModuleCommand;
|
||||||
import ru.gravit.launchserver.command.modules.ModulesCommand;
|
import ru.gravit.launchserver.command.modules.ModulesCommand;
|
||||||
import ru.gravit.launchserver.command.service.*;
|
import ru.gravit.launchserver.command.service.*;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public abstract class CommandHandler implements Runnable {
|
public abstract class CommandHandler implements Runnable {
|
||||||
private static String[] parse(CharSequence line) throws CommandException {
|
private static String[] parse(CharSequence line) throws CommandException {
|
||||||
boolean quoted = false;
|
boolean quoted = false;
|
||||||
|
@ -140,9 +112,9 @@ protected CommandHandler(LaunchServer server) {
|
||||||
registerCommand("dumpEntryCache", new DumpEntryCacheCommand(server));
|
registerCommand("dumpEntryCache", new DumpEntryCacheCommand(server));
|
||||||
|
|
||||||
//Register service commands
|
//Register service commands
|
||||||
registerCommand("reload",new ReloadCommand(server));
|
registerCommand("reload", new ReloadCommand(server));
|
||||||
registerCommand("reloadAll",new ReloadAllCommand(server));
|
registerCommand("reloadAll", new ReloadAllCommand(server));
|
||||||
registerCommand("reloadList",new ReloadListCommand(server));
|
registerCommand("reloadList", new ReloadListCommand(server));
|
||||||
registerCommand("config", new ConfigCommand(server));
|
registerCommand("config", new ConfigCommand(server));
|
||||||
registerCommand("configHelp", new ConfigHelpCommand(server));
|
registerCommand("configHelp", new ConfigHelpCommand(server));
|
||||||
registerCommand("configList", new ConfigListCommand(server));
|
registerCommand("configList", new ConfigListCommand(server));
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package ru.gravit.launchserver.command.handler;
|
package ru.gravit.launchserver.command.handler;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import jline.console.ConsoleReader;
|
import jline.console.ConsoleReader;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper.Output;
|
import ru.gravit.utils.helper.LogHelper.Output;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class JLineCommandHandler extends CommandHandler {
|
public final class JLineCommandHandler extends CommandHandler {
|
||||||
private final class JLineOutput implements Output {
|
private final class JLineOutput implements Output {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package ru.gravit.launchserver.command.handler;
|
package ru.gravit.launchserver.command.handler;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class StdCommandHandler extends CommandHandler {
|
public final class StdCommandHandler extends CommandHandler {
|
||||||
private final BufferedReader reader;
|
private final BufferedReader reader;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package ru.gravit.launchserver.command.hash;
|
package ru.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.profiles.ClientProfile.Version;
|
import ru.gravit.launcher.profiles.ClientProfile.Version;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
@ -11,6 +7,10 @@
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public final class DownloadAssetCommand extends Command {
|
public final class DownloadAssetCommand extends Command {
|
||||||
|
|
||||||
public DownloadAssetCommand(LaunchServer server) {
|
public DownloadAssetCommand(LaunchServer server) {
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
package ru.gravit.launchserver.command.hash;
|
package ru.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.profiles.ClientProfile;
|
import ru.gravit.launcher.profiles.ClientProfile;
|
||||||
import ru.gravit.launcher.profiles.ClientProfile.Version;
|
import ru.gravit.launcher.profiles.ClientProfile.Version;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
@ -16,6 +9,13 @@
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public final class DownloadClientCommand extends Command {
|
public final class DownloadClientCommand extends Command {
|
||||||
|
|
||||||
public DownloadClientCommand(LaunchServer server) {
|
public DownloadClientCommand(LaunchServer server) {
|
||||||
|
@ -52,13 +52,13 @@ public void invoke(String... args) throws IOException, CommandException {
|
||||||
ClientProfile client;
|
ClientProfile client;
|
||||||
String profilePath = String.format("ru/gravit/launchserver/defaults/profile%s.cfg", version.name);
|
String profilePath = String.format("ru/gravit/launchserver/defaults/profile%s.cfg", version.name);
|
||||||
try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL(profilePath))) {
|
try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL(profilePath))) {
|
||||||
client = LaunchServer.gson.fromJson(reader,ClientProfile.class);
|
client = LaunchServer.gson.fromJson(reader, ClientProfile.class);
|
||||||
}
|
}
|
||||||
client.setTitle(dirName);
|
client.setTitle(dirName);
|
||||||
client.setDir(dirName);
|
client.setDir(dirName);
|
||||||
try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir,
|
try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir,
|
||||||
dirName, "cfg"))) {
|
dirName, "cfg"))) {
|
||||||
LaunchServer.gson.toJson(client,writer);
|
LaunchServer.gson.toJson(client, writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finished
|
// Finished
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
package ru.gravit.launchserver.command.hash;
|
package ru.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
import ru.gravit.launchserver.command.CommandException;
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
|
import ru.gravit.utils.helper.SecurityHelper.DigestAlgorithm;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.FileVisitResult;
|
import java.nio.file.FileVisitResult;
|
||||||
|
@ -9,17 +19,6 @@
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
|
||||||
import ru.gravit.launchserver.command.Command;
|
|
||||||
import ru.gravit.launchserver.command.CommandException;
|
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
|
||||||
import ru.gravit.utils.helper.SecurityHelper.DigestAlgorithm;
|
|
||||||
|
|
||||||
public final class IndexAssetCommand extends Command {
|
public final class IndexAssetCommand extends Command {
|
||||||
private static Gson gson = new Gson();
|
private static Gson gson = new Gson();
|
||||||
|
|
||||||
|
@ -115,7 +114,7 @@ public void invoke(String... args) throws Exception {
|
||||||
|
|
||||||
try (BufferedWriter writer = IOHelper.newWriter(resolveIndexFile(outputAssetDir, indexFileName))) {
|
try (BufferedWriter writer = IOHelper.newWriter(resolveIndexFile(outputAssetDir, indexFileName))) {
|
||||||
JsonObject result = new JsonObject();
|
JsonObject result = new JsonObject();
|
||||||
result.add("objects",objects);
|
result.add("objects", objects);
|
||||||
writer.write(gson.toJson(result));
|
writer.write(gson.toJson(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package ru.gravit.launchserver.command.hash;
|
package ru.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class SyncBinariesCommand extends Command {
|
public final class SyncBinariesCommand extends Command {
|
||||||
public SyncBinariesCommand(LaunchServer server) {
|
public SyncBinariesCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package ru.gravit.launchserver.command.hash;
|
package ru.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class SyncProfilesCommand extends Command {
|
public final class SyncProfilesCommand extends Command {
|
||||||
public SyncProfilesCommand(LaunchServer server) {
|
public SyncProfilesCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package ru.gravit.launchserver.command.hash;
|
package ru.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
|
||||||
import ru.gravit.launchserver.command.Command;
|
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public final class SyncUpdatesCommand extends Command {
|
public final class SyncUpdatesCommand extends Command {
|
||||||
public SyncUpdatesCommand(LaunchServer server) {
|
public SyncUpdatesCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
package ru.gravit.launchserver.command.hash;
|
package ru.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
import ru.gravit.launchserver.command.CommandException;
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
|
||||||
import ru.gravit.launchserver.command.Command;
|
|
||||||
import ru.gravit.launchserver.command.CommandException;
|
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public final class UnindexAssetCommand extends Command {
|
public final class UnindexAssetCommand extends Command {
|
||||||
private static JsonParser parser = new JsonParser();
|
private static JsonParser parser = new JsonParser();
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package ru.gravit.launchserver.command.modules;
|
package ru.gravit.launchserver.command.modules;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
public class LoadModuleCommand extends Command {
|
public class LoadModuleCommand extends Command {
|
||||||
public LoadModuleCommand(LaunchServer server) {
|
public LoadModuleCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -21,10 +21,10 @@ public String getUsageDescription() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
verifyArgs(args,2);
|
verifyArgs(args, 2);
|
||||||
LogHelper.info("Call %s module %s action",args[0],args[1]);
|
LogHelper.info("Call %s module %s action", args[0], args[1]);
|
||||||
String[] new_args = new String[args.length - 2];
|
String[] new_args = new String[args.length - 2];
|
||||||
System.arraycopy(args, 2, new_args, 0, args.length - 2);
|
System.arraycopy(args, 2, new_args, 0, args.length - 2);
|
||||||
server.reconfigurableManager.call(args[0],args[1],new_args);
|
server.reconfigurableManager.call(args[0], args[1], new_args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,8 @@ public String getUsageDescription() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
verifyArgs(args,1);
|
verifyArgs(args, 1);
|
||||||
LogHelper.info("Help %s module",args[0]);
|
LogHelper.info("Help %s module", args[0]);
|
||||||
server.reconfigurableManager.printHelp(args[0]);
|
server.reconfigurableManager.printHelp(args[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public String getUsageDescription() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
verifyArgs(args,1);
|
verifyArgs(args, 1);
|
||||||
LogHelper.info("Reload all config");
|
LogHelper.info("Reload all config");
|
||||||
server.reloadManager.reloadAll();
|
server.reloadManager.reloadAll();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,8 @@ public String getUsageDescription() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
verifyArgs(args,1);
|
verifyArgs(args, 1);
|
||||||
LogHelper.info("Reload %s config",args[0]);
|
LogHelper.info("Reload %s config", args[0]);
|
||||||
server.reloadManager.reload(args[0]);
|
server.reloadManager.reload(args[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,18 +24,17 @@ public String getUsageDescription() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) {
|
public void invoke(String... args) {
|
||||||
LogHelper.info("Show server status");
|
LogHelper.info("Show server status");
|
||||||
LogHelper.info("Memory: free %d | total: %d | max: %d", JVMHelper.RUNTIME.freeMemory(), JVMHelper.RUNTIME.totalMemory(),JVMHelper.RUNTIME.maxMemory());
|
LogHelper.info("Memory: free %d | total: %d | max: %d", JVMHelper.RUNTIME.freeMemory(), JVMHelper.RUNTIME.totalMemory(), JVMHelper.RUNTIME.maxMemory());
|
||||||
long uptime = JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000;
|
long uptime = JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000;
|
||||||
long second = uptime % 60;
|
long second = uptime % 60;
|
||||||
long min = (uptime / 60) % 60;
|
long min = (uptime / 60) % 60;
|
||||||
long hour = (uptime / 60 / 60) % 24;
|
long hour = (uptime / 60 / 60) % 24;
|
||||||
long days = (uptime / 60 / 60 / 24);
|
long days = (uptime / 60 / 60 / 24);
|
||||||
LogHelper.info("Uptime: %d days %d hours %d minutes %d seconds",days,hour,min,second);
|
LogHelper.info("Uptime: %d days %d hours %d minutes %d seconds", days, hour, min, second);
|
||||||
LogHelper.info("Uptime (double): %f", (double)JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000);
|
LogHelper.info("Uptime (double): %f", (double) JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000);
|
||||||
LogHelper.info("Sessions: %d | Modules: %d | Commands: %d",server.sessionManager.getSessions().size(), server.modulesManager.modules.size(), server.commandHandler.commandsMap().size());
|
LogHelper.info("Sessions: %d | Modules: %d | Commands: %d", server.sessionManager.getSessions().size(), server.modulesManager.modules.size(), server.commandHandler.commandsMap().size());
|
||||||
if(server.config.authHandler instanceof CachedAuthHandler)
|
if (server.config.authHandler instanceof CachedAuthHandler) {
|
||||||
{
|
LogHelper.info("AuthHandler: EntryCache: %d | usernameCache: %d", ((CachedAuthHandler) server.config.authHandler).getEntryCache().size(), ((CachedAuthHandler) server.config.authHandler).getUsernamesCache().size());
|
||||||
LogHelper.info("AuthHandler: EntryCache: %d | usernameCache: %d",((CachedAuthHandler) server.config.authHandler).getEntryCache().size(),((CachedAuthHandler) server.config.authHandler).getUsernamesCache().size());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
public class SwapAuthProviderCommand extends Command {
|
public class SwapAuthProviderCommand extends Command {
|
||||||
public AuthProvider[] providersCache;
|
public AuthProvider[] providersCache;
|
||||||
|
|
||||||
public SwapAuthProviderCommand(LaunchServer server) {
|
public SwapAuthProviderCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
@ -24,10 +25,10 @@ public String getUsageDescription() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
verifyArgs(args,2);
|
verifyArgs(args, 2);
|
||||||
if(providersCache == null) providersCache = new AuthProvider[server.config.authProvider.length];
|
if (providersCache == null) providersCache = new AuthProvider[server.config.authProvider.length];
|
||||||
int index = Integer.valueOf(args[0]);
|
int index = Integer.valueOf(args[0]);
|
||||||
switch (args[1]) {
|
switch (args[1]) {
|
||||||
case "accept":
|
case "accept":
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
package ru.gravit.launchserver.config;
|
package ru.gravit.launchserver.config;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
import ru.gravit.launchserver.auth.handler.AuthHandler;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
import com.google.gson.JsonDeserializationContext;
|
|
||||||
import com.google.gson.JsonDeserializer;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParseException;
|
|
||||||
import com.google.gson.JsonPrimitive;
|
|
||||||
import com.google.gson.JsonSerializationContext;
|
|
||||||
import com.google.gson.JsonSerializer;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.auth.handler.AuthHandler;
|
|
||||||
|
|
||||||
public class AuthHandlerAdapter implements JsonSerializer<AuthHandler>, JsonDeserializer<AuthHandler> {
|
public class AuthHandlerAdapter implements JsonSerializer<AuthHandler>, JsonDeserializer<AuthHandler> {
|
||||||
private static final String PROP_NAME = "type";
|
private static final String PROP_NAME = "type";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public AuthHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
||||||
|
@ -29,7 +22,7 @@ public JsonElement serialize(AuthHandler src, Type typeOfSrc, JsonSerializationC
|
||||||
JsonObject jo = context.serialize(src).getAsJsonObject();
|
JsonObject jo = context.serialize(src).getAsJsonObject();
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
String classPath = AuthHandler.getHandlerName((Class<AuthHandler>) src.getClass());
|
String classPath = AuthHandler.getHandlerName((Class<AuthHandler>) src.getClass());
|
||||||
jo.add(PROP_NAME, new JsonPrimitive(classPath));
|
jo.add(PROP_NAME, new JsonPrimitive(classPath));
|
||||||
|
|
||||||
return jo;
|
return jo;
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
package ru.gravit.launchserver.config;
|
package ru.gravit.launchserver.config;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
import ru.gravit.launchserver.auth.provider.AuthProvider;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
import com.google.gson.JsonDeserializationContext;
|
|
||||||
import com.google.gson.JsonDeserializer;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParseException;
|
|
||||||
import com.google.gson.JsonPrimitive;
|
|
||||||
import com.google.gson.JsonSerializationContext;
|
|
||||||
import com.google.gson.JsonSerializer;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.auth.provider.AuthProvider;
|
|
||||||
|
|
||||||
public class AuthProviderAdapter implements JsonSerializer<AuthProvider>, JsonDeserializer<AuthProvider> {
|
public class AuthProviderAdapter implements JsonSerializer<AuthProvider>, JsonDeserializer<AuthProvider> {
|
||||||
private static final String PROP_NAME = "type";
|
private static final String PROP_NAME = "type";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public AuthProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
package ru.gravit.launchserver.config;
|
package ru.gravit.launchserver.config;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
import ru.gravit.launchserver.auth.hwid.HWIDHandler;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
import com.google.gson.JsonDeserializationContext;
|
|
||||||
import com.google.gson.JsonDeserializer;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParseException;
|
|
||||||
import com.google.gson.JsonPrimitive;
|
|
||||||
import com.google.gson.JsonSerializationContext;
|
|
||||||
import com.google.gson.JsonSerializer;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.auth.hwid.HWIDHandler;
|
|
||||||
|
|
||||||
public class HWIDHandlerAdapter implements JsonSerializer<HWIDHandler>, JsonDeserializer<HWIDHandler> {
|
public class HWIDHandlerAdapter implements JsonSerializer<HWIDHandler>, JsonDeserializer<HWIDHandler> {
|
||||||
private static final String PROP_NAME = "type";
|
private static final String PROP_NAME = "type";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HWIDHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public HWIDHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
package ru.gravit.launchserver.config;
|
package ru.gravit.launchserver.config;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
import ru.gravit.launchserver.auth.permissions.PermissionsHandler;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
import com.google.gson.JsonDeserializationContext;
|
|
||||||
import com.google.gson.JsonDeserializer;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParseException;
|
|
||||||
import com.google.gson.JsonPrimitive;
|
|
||||||
import com.google.gson.JsonSerializationContext;
|
|
||||||
import com.google.gson.JsonSerializer;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.auth.permissions.PermissionsHandler;
|
|
||||||
|
|
||||||
public class PermissionsHandlerAdapter implements JsonSerializer<PermissionsHandler>, JsonDeserializer<PermissionsHandler> {
|
public class PermissionsHandlerAdapter implements JsonSerializer<PermissionsHandler>, JsonDeserializer<PermissionsHandler> {
|
||||||
private static final String PROP_NAME = "type";
|
private static final String PROP_NAME = "type";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PermissionsHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public PermissionsHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
package ru.gravit.launchserver.config;
|
package ru.gravit.launchserver.config;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
import ru.gravit.launchserver.texture.TextureProvider;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
import com.google.gson.JsonDeserializationContext;
|
|
||||||
import com.google.gson.JsonDeserializer;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParseException;
|
|
||||||
import com.google.gson.JsonPrimitive;
|
|
||||||
import com.google.gson.JsonSerializationContext;
|
|
||||||
import com.google.gson.JsonSerializer;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.texture.TextureProvider;
|
|
||||||
|
|
||||||
public class TextureProviderAdapter implements JsonSerializer<TextureProvider>, JsonDeserializer<TextureProvider> {
|
public class TextureProviderAdapter implements JsonSerializer<TextureProvider>, JsonDeserializer<TextureProvider> {
|
||||||
private static final String PROP_NAME = "type";
|
private static final String PROP_NAME = "type";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TextureProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public TextureProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package ru.gravit.launchserver.fileserver;
|
package ru.gravit.launchserver.fileserver;
|
||||||
|
|
||||||
import java.io.Closeable;
|
|
||||||
|
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
|
||||||
public class ClosingChannelFutureListener implements ChannelFutureListener {
|
public class ClosingChannelFutureListener implements ChannelFutureListener {
|
||||||
public final Closeable[] close;
|
public final Closeable[] close;
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
package ru.gravit.launchserver.fileserver;
|
package ru.gravit.launchserver.fileserver;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpMethod.GET;
|
import io.netty.buffer.ByteBuf;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
|
import io.netty.buffer.Unpooled;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN;
|
import io.netty.channel.*;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.FOUND;
|
import io.netty.handler.codec.http.*;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR;
|
import io.netty.handler.ssl.SslHandler;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.METHOD_NOT_ALLOWED;
|
import io.netty.handler.stream.ChunkedFile;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.NOT_FOUND;
|
import io.netty.util.CharsetUtil;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.NOT_MODIFIED;
|
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
|
|
||||||
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
|
||||||
|
|
||||||
|
import javax.activation.MimetypesFileTypeMap;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
|
@ -18,38 +16,12 @@
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.GregorianCalendar;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.activation.MimetypesFileTypeMap;
|
import static io.netty.handler.codec.http.HttpMethod.GET;
|
||||||
|
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import io.netty.channel.ChannelFuture;
|
|
||||||
import io.netty.channel.ChannelFutureListener;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
|
||||||
import io.netty.channel.ChannelProgressiveFuture;
|
|
||||||
import io.netty.channel.ChannelProgressiveFutureListener;
|
|
||||||
import io.netty.channel.DefaultFileRegion;
|
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
|
||||||
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
|
||||||
import io.netty.handler.codec.http.DefaultHttpResponse;
|
|
||||||
import io.netty.handler.codec.http.FullHttpRequest;
|
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
|
||||||
import io.netty.handler.codec.http.HttpChunkedInput;
|
|
||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
|
||||||
import io.netty.handler.codec.http.HttpHeaderValues;
|
|
||||||
import io.netty.handler.codec.http.HttpResponse;
|
|
||||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
|
||||||
import io.netty.handler.codec.http.HttpUtil;
|
|
||||||
import io.netty.handler.codec.http.LastHttpContent;
|
|
||||||
import io.netty.handler.ssl.SslHandler;
|
|
||||||
import io.netty.handler.stream.ChunkedFile;
|
|
||||||
import io.netty.util.CharsetUtil;
|
|
||||||
|
|
||||||
public class FileServerHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
|
public class FileServerHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package ru.gravit.launchserver.manangers;
|
package ru.gravit.launchserver.manangers;
|
||||||
|
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
|
||||||
|
|
||||||
public class MirrorManager {
|
public class MirrorManager {
|
||||||
public class Mirror {
|
public class Mirror {
|
||||||
URL url;
|
URL url;
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package ru.gravit.launchserver.manangers;
|
package ru.gravit.launchserver.manangers;
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.managers.ModulesConfigManager;
|
import ru.gravit.launcher.managers.ModulesConfigManager;
|
||||||
import ru.gravit.launcher.managers.SimpleModuleManager;
|
import ru.gravit.launcher.managers.SimpleModuleManager;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
@ -10,8 +7,12 @@
|
||||||
import ru.gravit.launchserver.modules.LaunchServerModuleContext;
|
import ru.gravit.launchserver.modules.LaunchServerModuleContext;
|
||||||
import ru.gravit.utils.PublicURLClassLoader;
|
import ru.gravit.utils.PublicURLClassLoader;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ModulesManager extends SimpleModuleManager {
|
public class ModulesManager extends SimpleModuleManager {
|
||||||
public ModulesConfigManager configManager;
|
public ModulesConfigManager configManager;
|
||||||
|
|
||||||
public ModulesManager(LaunchServer lsrv) {
|
public ModulesManager(LaunchServer lsrv) {
|
||||||
modules = new ArrayList<>(1);
|
modules = new ArrayList<>(1);
|
||||||
configManager = new ModulesConfigManager(lsrv.dir.resolve("config"));
|
configManager = new ModulesConfigManager(lsrv.dir.resolve("config"));
|
||||||
|
|
|
@ -1,29 +1,30 @@
|
||||||
package ru.gravit.launchserver.manangers;
|
package ru.gravit.launchserver.manangers;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.Reconfigurable;
|
import ru.gravit.launchserver.Reconfigurable;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ReconfigurableManager {
|
public class ReconfigurableManager {
|
||||||
private final HashMap<String, Reconfigurable> RECONFIGURABLE = new HashMap<>();
|
private final HashMap<String, Reconfigurable> RECONFIGURABLE = new HashMap<>();
|
||||||
public void registerReconfigurable(String name, Reconfigurable reconfigurable)
|
|
||||||
{
|
public void registerReconfigurable(String name, Reconfigurable reconfigurable) {
|
||||||
VerifyHelper.verifyIDName(name);
|
VerifyHelper.verifyIDName(name);
|
||||||
VerifyHelper.putIfAbsent(RECONFIGURABLE, name, Objects.requireNonNull(reconfigurable, "adapter"),
|
VerifyHelper.putIfAbsent(RECONFIGURABLE, name, Objects.requireNonNull(reconfigurable, "adapter"),
|
||||||
String.format("Reloadable has been already registered: '%s'", name));
|
String.format("Reloadable has been already registered: '%s'", name));
|
||||||
}
|
}
|
||||||
public void printHelp(String name)
|
|
||||||
{
|
public void printHelp(String name) {
|
||||||
RECONFIGURABLE.get(name).printConfigHelp();
|
RECONFIGURABLE.get(name).printConfigHelp();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void call(String name, String action, String[] args) {
|
public void call(String name, String action, String[] args) {
|
||||||
RECONFIGURABLE.get(name).reconfig(action,args);
|
RECONFIGURABLE.get(name).reconfig(action, args);
|
||||||
}
|
}
|
||||||
public void printReconfigurables()
|
|
||||||
{
|
public void printReconfigurables() {
|
||||||
LogHelper.info("Print reconfigurables");
|
LogHelper.info("Print reconfigurables");
|
||||||
RECONFIGURABLE.forEach((k, v) -> LogHelper.subInfo(k));
|
RECONFIGURABLE.forEach((k, v) -> LogHelper.subInfo(k));
|
||||||
LogHelper.info("Found %d reconfigurables", RECONFIGURABLE.size());
|
LogHelper.info("Found %d reconfigurables", RECONFIGURABLE.size());
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
package ru.gravit.launchserver.manangers;
|
package ru.gravit.launchserver.manangers;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.Reloadable;
|
import ru.gravit.launchserver.Reloadable;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ReloadManager {
|
public class ReloadManager {
|
||||||
private final HashMap<String,Reloadable> RELOADABLES = new HashMap<>();
|
private final HashMap<String, Reloadable> RELOADABLES = new HashMap<>();
|
||||||
public void registerReloadable(String name,Reloadable reloadable)
|
|
||||||
{
|
public void registerReloadable(String name, Reloadable reloadable) {
|
||||||
VerifyHelper.verifyIDName(name);
|
VerifyHelper.verifyIDName(name);
|
||||||
VerifyHelper.putIfAbsent(RELOADABLES, name, Objects.requireNonNull(reloadable, "adapter"),
|
VerifyHelper.putIfAbsent(RELOADABLES, name, Objects.requireNonNull(reloadable, "adapter"),
|
||||||
String.format("Reloadable has been already registered: '%s'", name));
|
String.format("Reloadable has been already registered: '%s'", name));
|
||||||
}
|
}
|
||||||
public void reloadAll()
|
|
||||||
{
|
public void reloadAll() {
|
||||||
RELOADABLES.forEach((k,v) -> {
|
RELOADABLES.forEach((k, v) -> {
|
||||||
try {
|
try {
|
||||||
v.reload();
|
v.reload();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -25,13 +25,14 @@ public void reloadAll()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reload(String name) throws Exception {
|
public void reload(String name) throws Exception {
|
||||||
RELOADABLES.get(name).reload();
|
RELOADABLES.get(name).reload();
|
||||||
}
|
}
|
||||||
public void printReloadables()
|
|
||||||
{
|
public void printReloadables() {
|
||||||
LogHelper.info("Print reloadables");
|
LogHelper.info("Print reloadables");
|
||||||
RELOADABLES.forEach((k,v) -> LogHelper.subInfo(k));
|
RELOADABLES.forEach((k, v) -> LogHelper.subInfo(k));
|
||||||
LogHelper.info("Found %d reloadables", RELOADABLES.size());
|
LogHelper.info("Found %d reloadables", RELOADABLES.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package ru.gravit.launchserver.manangers;
|
package ru.gravit.launchserver.manangers;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.NeedGarbageCollection;
|
import ru.gravit.launcher.NeedGarbageCollection;
|
||||||
import ru.gravit.launchserver.socket.Client;
|
import ru.gravit.launchserver.socket.Client;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class SessionManager implements NeedGarbageCollection {
|
public class SessionManager implements NeedGarbageCollection {
|
||||||
|
|
||||||
public static final long SESSION_TIMEOUT = 10 * 60 * 1000; // 10 минут
|
public static final long SESSION_TIMEOUT = 10 * 60 * 1000; // 10 минут
|
||||||
|
@ -51,12 +51,12 @@ public void updateClient(long session) {
|
||||||
Client newClient = new Client(session);
|
Client newClient = new Client(session);
|
||||||
clientSet.add(newClient);
|
clientSet.add(newClient);
|
||||||
}
|
}
|
||||||
public Set<Client> getSessions()
|
|
||||||
{
|
public Set<Client> getSessions() {
|
||||||
return clientSet;
|
return clientSet;
|
||||||
}
|
}
|
||||||
public void loadSessions(Set<Client> set)
|
|
||||||
{
|
public void loadSessions(Set<Client> set) {
|
||||||
clientSet.addAll(set);
|
clientSet.addAll(set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,77 +1,73 @@
|
||||||
package ru.gravit.launchserver.manangers.hook;
|
package ru.gravit.launchserver.manangers.hook;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.response.auth.AuthResponse;
|
import ru.gravit.launchserver.response.auth.AuthResponse;
|
||||||
import ru.gravit.launchserver.socket.Client;
|
import ru.gravit.launchserver.socket.Client;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class AuthHookManager {
|
public class AuthHookManager {
|
||||||
private Set<AuthPreHook> PRE_HOOKS = new HashSet<>();
|
private Set<AuthPreHook> PRE_HOOKS = new HashSet<>();
|
||||||
private Set<AuthPostHook> POST_HOOKS = new HashSet<>();
|
private Set<AuthPostHook> POST_HOOKS = new HashSet<>();
|
||||||
private Set<CheckServerHook> CHECKSERVER_HOOKS = new HashSet<>();
|
private Set<CheckServerHook> CHECKSERVER_HOOKS = new HashSet<>();
|
||||||
private Set<JoinServerHook> JOINSERVER_HOOKS = new HashSet<>();
|
private Set<JoinServerHook> JOINSERVER_HOOKS = new HashSet<>();
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface AuthPreHook
|
public interface AuthPreHook {
|
||||||
{
|
|
||||||
void preAuthHook(AuthResponse.AuthContext context, Client client);
|
void preAuthHook(AuthResponse.AuthContext context, Client client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface AuthPostHook
|
public interface AuthPostHook {
|
||||||
{
|
|
||||||
void postAuthHook(AuthResponse.AuthContext context, Client client);
|
void postAuthHook(AuthResponse.AuthContext context, Client client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface CheckServerHook
|
public interface CheckServerHook {
|
||||||
{
|
|
||||||
void checkServerHook(String username, String serverID);
|
void checkServerHook(String username, String serverID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface JoinServerHook
|
public interface JoinServerHook {
|
||||||
{
|
|
||||||
void joinServerHook(String username, String accessToken, String serverID);
|
void joinServerHook(String username, String accessToken, String serverID);
|
||||||
}
|
}
|
||||||
public void registerPostHook(AuthPostHook hook)
|
|
||||||
{
|
public void registerPostHook(AuthPostHook hook) {
|
||||||
POST_HOOKS.add(hook);
|
POST_HOOKS.add(hook);
|
||||||
}
|
}
|
||||||
public void registerJoinServerHook(JoinServerHook hook)
|
|
||||||
{
|
public void registerJoinServerHook(JoinServerHook hook) {
|
||||||
JOINSERVER_HOOKS.add(hook);
|
JOINSERVER_HOOKS.add(hook);
|
||||||
}
|
}
|
||||||
public void registerCheckServerHook(CheckServerHook hook)
|
|
||||||
{
|
public void registerCheckServerHook(CheckServerHook hook) {
|
||||||
CHECKSERVER_HOOKS.add(hook);
|
CHECKSERVER_HOOKS.add(hook);
|
||||||
}
|
}
|
||||||
public void registerPreHook(AuthPreHook hook)
|
|
||||||
{
|
public void registerPreHook(AuthPreHook hook) {
|
||||||
PRE_HOOKS.add(hook);
|
PRE_HOOKS.add(hook);
|
||||||
}
|
}
|
||||||
public void preHook(AuthResponse.AuthContext context, Client client)
|
|
||||||
{
|
public void preHook(AuthResponse.AuthContext context, Client client) {
|
||||||
for(AuthPreHook preHook : PRE_HOOKS)
|
for (AuthPreHook preHook : PRE_HOOKS) {
|
||||||
{
|
preHook.preAuthHook(context, client);
|
||||||
preHook.preAuthHook(context,client);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void checkServerHook(String username, String serverID)
|
|
||||||
{
|
public void checkServerHook(String username, String serverID) {
|
||||||
for(CheckServerHook hook : CHECKSERVER_HOOKS)
|
for (CheckServerHook hook : CHECKSERVER_HOOKS) {
|
||||||
{
|
|
||||||
hook.checkServerHook(username, serverID);
|
hook.checkServerHook(username, serverID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void joinServerHook(String username, String accessToken, String serverID)
|
|
||||||
{
|
public void joinServerHook(String username, String accessToken, String serverID) {
|
||||||
for(JoinServerHook hook : JOINSERVER_HOOKS)
|
for (JoinServerHook hook : JOINSERVER_HOOKS) {
|
||||||
{
|
|
||||||
hook.joinServerHook(username, accessToken, serverID);
|
hook.joinServerHook(username, accessToken, serverID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void postHook(AuthResponse.AuthContext context, Client client)
|
|
||||||
{
|
public void postHook(AuthResponse.AuthContext context, Client client) {
|
||||||
for(AuthPostHook postHook : POST_HOOKS)
|
for (AuthPostHook postHook : POST_HOOKS) {
|
||||||
{
|
|
||||||
postHook.postAuthHook(context, client);
|
postHook.postAuthHook(context, client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
package ru.gravit.launchserver.manangers.hook;
|
package ru.gravit.launchserver.manangers.hook;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.AutogenConfig;
|
import ru.gravit.launcher.AutogenConfig;
|
||||||
import ru.gravit.launcher.modules.TestClientModule;
|
import ru.gravit.launcher.modules.TestClientModule;
|
||||||
import ru.gravit.launchserver.binary.BuildContext;
|
import ru.gravit.launchserver.binary.BuildContext;
|
||||||
import ru.gravit.launchserver.binary.JAConfigurator;
|
import ru.gravit.launchserver.binary.JAConfigurator;
|
||||||
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
|
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class BuildHookManager {
|
public class BuildHookManager {
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
|
|
|
@ -1,89 +1,85 @@
|
||||||
package ru.gravit.launchserver.manangers.hook;
|
package ru.gravit.launchserver.manangers.hook;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.request.RequestException;
|
||||||
|
import ru.gravit.launchserver.socket.SocketContext;
|
||||||
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import ru.gravit.launcher.request.RequestException;
|
|
||||||
import ru.gravit.launchserver.socket.SocketContext;
|
|
||||||
|
|
||||||
public class SocketHookManager {
|
public class SocketHookManager {
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface SocketPreHook
|
public interface SocketPreHook {
|
||||||
{
|
|
||||||
boolean preHook(SocketContext context); //Вернуть true если необходимо продолжть обработку, false если остановить обработку
|
boolean preHook(SocketContext context); //Вернуть true если необходимо продолжть обработку, false если остановить обработку
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface SocketPostHook
|
public interface SocketPostHook {
|
||||||
{
|
|
||||||
void postHook(SocketContext context);
|
void postHook(SocketContext context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface SocketErrorHook
|
public interface SocketErrorHook {
|
||||||
{
|
|
||||||
boolean errorHook(SocketContext context, RequestException e); //Вернуть true если необходимо продолжть обработку, false если остановить обработку
|
boolean errorHook(SocketContext context, RequestException e); //Вернуть true если необходимо продолжть обработку, false если остановить обработку
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface SocketFatalErrorHook
|
public interface SocketFatalErrorHook {
|
||||||
{
|
|
||||||
boolean fatalErrorHook(Socket socket, Exception e); //Вернуть true если необходимо продолжть обработку, false если остановить обработку
|
boolean fatalErrorHook(Socket socket, Exception e); //Вернуть true если необходимо продолжть обработку, false если остановить обработку
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<SocketPostHook> POST_HOOKS;
|
private Set<SocketPostHook> POST_HOOKS;
|
||||||
private Set<SocketPreHook> PRE_HOOKS;
|
private Set<SocketPreHook> PRE_HOOKS;
|
||||||
private Set<SocketErrorHook> ERROR_HOOKS;
|
private Set<SocketErrorHook> ERROR_HOOKS;
|
||||||
private Set<SocketFatalErrorHook> FATALERROR_HOOKS;
|
private Set<SocketFatalErrorHook> FATALERROR_HOOKS;
|
||||||
public void registerPostHook(SocketPostHook hook)
|
|
||||||
{
|
public void registerPostHook(SocketPostHook hook) {
|
||||||
if(POST_HOOKS == null) POST_HOOKS = new HashSet<>();
|
if (POST_HOOKS == null) POST_HOOKS = new HashSet<>();
|
||||||
POST_HOOKS.add(hook);
|
POST_HOOKS.add(hook);
|
||||||
}
|
}
|
||||||
public void registerPreHook(SocketPreHook hook)
|
|
||||||
{
|
public void registerPreHook(SocketPreHook hook) {
|
||||||
if(PRE_HOOKS == null) PRE_HOOKS = new HashSet<>();
|
if (PRE_HOOKS == null) PRE_HOOKS = new HashSet<>();
|
||||||
PRE_HOOKS.add(hook);
|
PRE_HOOKS.add(hook);
|
||||||
}
|
}
|
||||||
public void registerErrorHook(SocketErrorHook hook)
|
|
||||||
{
|
public void registerErrorHook(SocketErrorHook hook) {
|
||||||
if(ERROR_HOOKS == null) ERROR_HOOKS = new HashSet<>();
|
if (ERROR_HOOKS == null) ERROR_HOOKS = new HashSet<>();
|
||||||
ERROR_HOOKS.add(hook);
|
ERROR_HOOKS.add(hook);
|
||||||
}
|
}
|
||||||
public void registerFatalErrorHook(SocketFatalErrorHook hook)
|
|
||||||
{
|
public void registerFatalErrorHook(SocketFatalErrorHook hook) {
|
||||||
if(FATALERROR_HOOKS == null) FATALERROR_HOOKS = new HashSet<>();
|
if (FATALERROR_HOOKS == null) FATALERROR_HOOKS = new HashSet<>();
|
||||||
FATALERROR_HOOKS.add(hook);
|
FATALERROR_HOOKS.add(hook);
|
||||||
}
|
}
|
||||||
public boolean preHook(SocketContext context)
|
|
||||||
{
|
public boolean preHook(SocketContext context) {
|
||||||
if(PRE_HOOKS == null) return true;
|
if (PRE_HOOKS == null) return true;
|
||||||
for(SocketPreHook preHook : PRE_HOOKS)
|
for (SocketPreHook preHook : PRE_HOOKS) {
|
||||||
{
|
if (!preHook.preHook(context)) return false;
|
||||||
if(!preHook.preHook(context)) return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public void postHook(SocketContext context)
|
|
||||||
{
|
public void postHook(SocketContext context) {
|
||||||
if(POST_HOOKS == null) return;
|
if (POST_HOOKS == null) return;
|
||||||
for(SocketPostHook postHook : POST_HOOKS)
|
for (SocketPostHook postHook : POST_HOOKS) {
|
||||||
{
|
|
||||||
postHook.postHook(context);
|
postHook.postHook(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public boolean errorHook(SocketContext context, RequestException e)
|
|
||||||
{
|
public boolean errorHook(SocketContext context, RequestException e) {
|
||||||
if(ERROR_HOOKS == null) return true;
|
if (ERROR_HOOKS == null) return true;
|
||||||
for(SocketErrorHook errorHook : ERROR_HOOKS)
|
for (SocketErrorHook errorHook : ERROR_HOOKS) {
|
||||||
{
|
if (!errorHook.errorHook(context, e)) return false;
|
||||||
if(!errorHook.errorHook(context,e)) return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public boolean fatalErrorHook(Socket socket, Exception e)
|
|
||||||
{
|
public boolean fatalErrorHook(Socket socket, Exception e) {
|
||||||
if(FATALERROR_HOOKS == null) return true;
|
if (FATALERROR_HOOKS == null) return true;
|
||||||
for(SocketFatalErrorHook errorHook : FATALERROR_HOOKS)
|
for (SocketFatalErrorHook errorHook : FATALERROR_HOOKS) {
|
||||||
{
|
if (!errorHook.fatalErrorHook(socket, e)) return false;
|
||||||
if(!errorHook.fatalErrorHook(socket,e)) return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package ru.gravit.launchserver.response;
|
package ru.gravit.launchserver.response;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.serialize.HInput;
|
import ru.gravit.launcher.serialize.HInput;
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
import ru.gravit.launcher.serialize.SerializeLimits;
|
import ru.gravit.launcher.serialize.SerializeLimits;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class PingResponse extends Response {
|
public final class PingResponse extends Response {
|
||||||
public PingResponse(LaunchServer server, long id, HInput input, HOutput output, String ip) {
|
public PingResponse(LaunchServer server, long id, HInput input, HOutput output, String ip) {
|
||||||
super(server, id, input, output, ip);
|
super(server, id, input, output, ip);
|
||||||
|
|
|
@ -1,31 +1,22 @@
|
||||||
package ru.gravit.launchserver.response;
|
package ru.gravit.launchserver.response;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.request.RequestException;
|
import ru.gravit.launcher.request.RequestException;
|
||||||
import ru.gravit.launcher.request.RequestType;
|
import ru.gravit.launcher.request.RequestType;
|
||||||
import ru.gravit.launcher.serialize.HInput;
|
import ru.gravit.launcher.serialize.HInput;
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.response.admin.ExecCommandResponse;
|
import ru.gravit.launchserver.response.admin.ExecCommandResponse;
|
||||||
import ru.gravit.launchserver.response.auth.AuthResponse;
|
import ru.gravit.launchserver.response.auth.*;
|
||||||
import ru.gravit.launchserver.response.auth.AuthServerResponse;
|
|
||||||
import ru.gravit.launchserver.response.auth.ChangeServerResponse;
|
|
||||||
import ru.gravit.launchserver.response.auth.CheckServerResponse;
|
|
||||||
import ru.gravit.launchserver.response.auth.JoinServerResponse;
|
|
||||||
import ru.gravit.launchserver.response.auth.SetProfileResponse;
|
|
||||||
import ru.gravit.launchserver.response.profile.BatchProfileByUsernameResponse;
|
import ru.gravit.launchserver.response.profile.BatchProfileByUsernameResponse;
|
||||||
import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse;
|
import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse;
|
||||||
import ru.gravit.launchserver.response.profile.ProfileByUsernameResponse;
|
import ru.gravit.launchserver.response.profile.ProfileByUsernameResponse;
|
||||||
import ru.gravit.launchserver.response.update.LauncherResponse;
|
import ru.gravit.launchserver.response.update.*;
|
||||||
import ru.gravit.launchserver.response.update.LegacyLauncherResponse;
|
|
||||||
import ru.gravit.launchserver.response.update.ProfilesResponse;
|
|
||||||
import ru.gravit.launchserver.response.update.UpdateListResponse;
|
|
||||||
import ru.gravit.launchserver.response.update.UpdateResponse;
|
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public abstract class Response {
|
public abstract class Response {
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface Factory<R> {
|
public interface Factory<R> {
|
||||||
|
|
|
@ -18,7 +18,8 @@ public ExecCommandResponse(LaunchServer server, long session, HInput input, HOut
|
||||||
@Override
|
@Override
|
||||||
public void reply() throws Exception {
|
public void reply() throws Exception {
|
||||||
Client clientData = server.sessionManager.getClient(session);
|
Client clientData = server.sessionManager.getClient(session);
|
||||||
if(!clientData.isAuth || !clientData.permissions.canAdmin || !server.config.enableRcon) requestError("Access denied");
|
if (!clientData.isAuth || !clientData.permissions.canAdmin || !server.config.enableRcon)
|
||||||
|
requestError("Access denied");
|
||||||
writeNoError(output);
|
writeNoError(output);
|
||||||
String cmd = input.readString(SerializeLimits.MAX_COMMAND);
|
String cmd = input.readString(SerializeLimits.MAX_COMMAND);
|
||||||
LogHelper.Output loutput = message -> {
|
LogHelper.Output loutput = message -> {
|
||||||
|
@ -30,9 +31,8 @@ public void reply() throws Exception {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
LogHelper.addOutput(loutput);
|
LogHelper.addOutput(loutput);
|
||||||
try
|
try {
|
||||||
{
|
server.commandHandler.eval(cmd, false);
|
||||||
server.commandHandler.eval(cmd,false);
|
|
||||||
output.writeBoolean(false);
|
output.writeBoolean(false);
|
||||||
} finally {
|
} finally {
|
||||||
LogHelper.removeOutput(loutput);
|
LogHelper.removeOutput(loutput);
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
package ru.gravit.launchserver.response.auth;
|
package ru.gravit.launchserver.response.auth;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import javax.crypto.BadPaddingException;
|
|
||||||
import javax.crypto.IllegalBlockSizeException;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.OshiHWID;
|
import ru.gravit.launcher.OshiHWID;
|
||||||
import ru.gravit.launcher.profiles.ClientProfile;
|
import ru.gravit.launcher.profiles.ClientProfile;
|
||||||
import ru.gravit.launcher.serialize.HInput;
|
import ru.gravit.launcher.serialize.HInput;
|
||||||
|
@ -25,6 +18,12 @@
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import javax.crypto.BadPaddingException;
|
||||||
|
import javax.crypto.IllegalBlockSizeException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class AuthResponse extends Response {
|
public final class AuthResponse extends Response {
|
||||||
private static String echo(int length) {
|
private static String echo(int length) {
|
||||||
char[] chars = new char[length];
|
char[] chars = new char[length];
|
||||||
|
@ -35,8 +34,8 @@ private static String echo(int length) {
|
||||||
public AuthResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public AuthResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip);
|
||||||
}
|
}
|
||||||
public static class AuthContext
|
|
||||||
{
|
public static class AuthContext {
|
||||||
public AuthContext(long session, String login, int password_lenght, String client, String hwid, boolean isServerAuth) {
|
public AuthContext(long session, String login, int password_lenght, String client, String hwid, boolean isServerAuth) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
this.login = login;
|
this.login = login;
|
||||||
|
@ -53,6 +52,7 @@ public AuthContext(long session, String login, int password_lenght, String clien
|
||||||
public String hwid;
|
public String hwid;
|
||||||
public boolean isServerAuth;
|
public boolean isServerAuth;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reply() throws Exception {
|
public void reply() throws Exception {
|
||||||
String login = input.readString(SerializeLimits.MAX_LOGIN);
|
String login = input.readString(SerializeLimits.MAX_LOGIN);
|
||||||
|
@ -80,9 +80,9 @@ public void reply() throws Exception {
|
||||||
AuthProvider provider = server.config.authProvider[auth_id];
|
AuthProvider provider = server.config.authProvider[auth_id];
|
||||||
Client clientData = server.sessionManager.getClient(session);
|
Client clientData = server.sessionManager.getClient(session);
|
||||||
clientData.type = Client.Type.USER;
|
clientData.type = Client.Type.USER;
|
||||||
AuthContext context = new AuthContext(session,login,password.length(),client,hwid_str,false);
|
AuthContext context = new AuthContext(session, login, password.length(), client, hwid_str, false);
|
||||||
try {
|
try {
|
||||||
server.authHookManager.preHook(context,clientData);
|
server.authHookManager.preHook(context, clientData);
|
||||||
if (server.limiter.isLimit(ip)) {
|
if (server.limiter.isLimit(ip)) {
|
||||||
AuthProvider.authError(server.config.authRejectString);
|
AuthProvider.authError(server.config.authRejectString);
|
||||||
return;
|
return;
|
||||||
|
@ -110,9 +110,9 @@ public void reply() throws Exception {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
server.config.hwidHandler.check(OshiHWID.gson.fromJson(hwid_str, OshiHWID.class), result.username);
|
server.config.hwidHandler.check(OshiHWID.gson.fromJson(hwid_str, OshiHWID.class), result.username);
|
||||||
server.authHookManager.postHook(context,clientData);
|
server.authHookManager.postHook(context, clientData);
|
||||||
} catch (AuthException | HWIDException e) {
|
} catch (AuthException | HWIDException e) {
|
||||||
if(e.getMessage() == null) LogHelper.error(e);
|
if (e.getMessage() == null) LogHelper.error(e);
|
||||||
requestError(e.getMessage());
|
requestError(e.getMessage());
|
||||||
return;
|
return;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
package ru.gravit.launchserver.response.auth;
|
package ru.gravit.launchserver.response.auth;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import javax.crypto.BadPaddingException;
|
|
||||||
import javax.crypto.IllegalBlockSizeException;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.profiles.ClientProfile;
|
import ru.gravit.launcher.profiles.ClientProfile;
|
||||||
import ru.gravit.launcher.serialize.HInput;
|
import ru.gravit.launcher.serialize.HInput;
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
|
@ -22,6 +16,11 @@
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import javax.crypto.BadPaddingException;
|
||||||
|
import javax.crypto.IllegalBlockSizeException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public final class AuthServerResponse extends Response {
|
public final class AuthServerResponse extends Response {
|
||||||
private static String echo(int length) {
|
private static String echo(int length) {
|
||||||
char[] chars = new char[length];
|
char[] chars = new char[length];
|
||||||
|
@ -74,8 +73,7 @@ public void reply() throws Exception {
|
||||||
throw new AuthException("Your profile is not found");
|
throw new AuthException("Your profile is not found");
|
||||||
}
|
}
|
||||||
clientData.permissions = server.config.permissionsHandler.getPermissions(login);
|
clientData.permissions = server.config.permissionsHandler.getPermissions(login);
|
||||||
if(!clientData.permissions.canServer)
|
if (!clientData.permissions.canServer) {
|
||||||
{
|
|
||||||
throw new AuthException("Your account cannot be a server");
|
throw new AuthException("Your account cannot be a server");
|
||||||
}
|
}
|
||||||
clientData.type = Client.Type.SERVER;
|
clientData.type = Client.Type.SERVER;
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package ru.gravit.launchserver.response.auth;
|
package ru.gravit.launchserver.response.auth;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.serialize.HInput;
|
import ru.gravit.launcher.serialize.HInput;
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
import ru.gravit.launcher.serialize.SerializeLimits;
|
import ru.gravit.launcher.serialize.SerializeLimits;
|
||||||
|
@ -14,6 +11,9 @@
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class CheckServerResponse extends Response {
|
public final class CheckServerResponse extends Response {
|
||||||
|
|
||||||
public CheckServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public CheckServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
||||||
|
@ -27,15 +27,14 @@ public void reply() throws IOException {
|
||||||
String client = input.readString(SerializeLimits.MAX_CLIENT);
|
String client = input.readString(SerializeLimits.MAX_CLIENT);
|
||||||
debug("Username: %s, Server ID: %s", username, serverID);
|
debug("Username: %s, Server ID: %s", username, serverID);
|
||||||
Client clientData = server.sessionManager.getClient(session);
|
Client clientData = server.sessionManager.getClient(session);
|
||||||
if(!clientData.isAuth || clientData.type != Client.Type.SERVER)
|
if (!clientData.isAuth || clientData.type != Client.Type.SERVER) {
|
||||||
{
|
|
||||||
requestError("Assess denied");
|
requestError("Assess denied");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Try check server with auth handler
|
// Try check server with auth handler
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
try {
|
try {
|
||||||
server.authHookManager.checkServerHook(username,serverID);
|
server.authHookManager.checkServerHook(username, serverID);
|
||||||
uuid = server.config.authHandler.checkServer(username, serverID);
|
uuid = server.config.authHandler.checkServer(username, serverID);
|
||||||
} catch (AuthException e) {
|
} catch (AuthException e) {
|
||||||
requestError(e.getMessage());
|
requestError(e.getMessage());
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package ru.gravit.launchserver.response.auth;
|
package ru.gravit.launchserver.response.auth;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.serialize.HInput;
|
import ru.gravit.launcher.serialize.HInput;
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
import ru.gravit.launcher.serialize.SerializeLimits;
|
import ru.gravit.launcher.serialize.SerializeLimits;
|
||||||
|
@ -13,6 +11,8 @@
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class JoinServerResponse extends Response {
|
public final class JoinServerResponse extends Response {
|
||||||
|
|
||||||
public JoinServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public JoinServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
||||||
|
@ -25,8 +25,7 @@ public void reply() throws IOException {
|
||||||
String accessToken = SecurityHelper.verifyToken(input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH));
|
String accessToken = SecurityHelper.verifyToken(input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH));
|
||||||
String serverID = VerifyHelper.verifyServerID(input.readASCII(SerializeLimits.MAX_SERVERID)); // With minus sign
|
String serverID = VerifyHelper.verifyServerID(input.readASCII(SerializeLimits.MAX_SERVERID)); // With minus sign
|
||||||
Client clientData = server.sessionManager.getClient(session);
|
Client clientData = server.sessionManager.getClient(session);
|
||||||
if(!clientData.isAuth || clientData.type != Client.Type.USER)
|
if (!clientData.isAuth || clientData.type != Client.Type.USER) {
|
||||||
{
|
|
||||||
requestError("Assess denied");
|
requestError("Assess denied");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +33,7 @@ public void reply() throws IOException {
|
||||||
debug("Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID);
|
debug("Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID);
|
||||||
boolean success;
|
boolean success;
|
||||||
try {
|
try {
|
||||||
server.authHookManager.joinServerHook(username,accessToken,serverID);
|
server.authHookManager.joinServerHook(username, accessToken, serverID);
|
||||||
success = server.config.authHandler.joinServer(username, accessToken, serverID);
|
success = server.config.authHandler.joinServer(username, accessToken, serverID);
|
||||||
} catch (AuthException e) {
|
} catch (AuthException e) {
|
||||||
requestError(e.getMessage());
|
requestError(e.getMessage());
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package ru.gravit.launchserver.response.auth;
|
package ru.gravit.launchserver.response.auth;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.profiles.ClientProfile;
|
import ru.gravit.launcher.profiles.ClientProfile;
|
||||||
import ru.gravit.launcher.serialize.HInput;
|
import ru.gravit.launcher.serialize.HInput;
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
|
@ -10,6 +8,8 @@
|
||||||
import ru.gravit.launchserver.response.Response;
|
import ru.gravit.launchserver.response.Response;
|
||||||
import ru.gravit.launchserver.socket.Client;
|
import ru.gravit.launchserver.socket.Client;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class SetProfileResponse extends Response {
|
public class SetProfileResponse extends Response {
|
||||||
public SetProfileResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public SetProfileResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip);
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package ru.gravit.launchserver.response.profile;
|
package ru.gravit.launchserver.response.profile;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.serialize.HInput;
|
import ru.gravit.launcher.serialize.HInput;
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
import ru.gravit.launcher.serialize.SerializeLimits;
|
import ru.gravit.launcher.serialize.SerializeLimits;
|
||||||
|
@ -10,6 +7,9 @@
|
||||||
import ru.gravit.launchserver.response.Response;
|
import ru.gravit.launchserver.response.Response;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public final class BatchProfileByUsernameResponse extends Response {
|
public final class BatchProfileByUsernameResponse extends Response {
|
||||||
|
|
||||||
public BatchProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public BatchProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package ru.gravit.launchserver.response.profile;
|
package ru.gravit.launchserver.response.profile;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||||
import ru.gravit.launcher.profiles.Texture;
|
import ru.gravit.launcher.profiles.Texture;
|
||||||
import ru.gravit.launcher.serialize.HInput;
|
import ru.gravit.launcher.serialize.HInput;
|
||||||
|
@ -12,6 +9,9 @@
|
||||||
import ru.gravit.launchserver.response.Response;
|
import ru.gravit.launchserver.response.Response;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class ProfileByUUIDResponse extends Response {
|
public final class ProfileByUUIDResponse extends Response {
|
||||||
|
|
||||||
public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String username, String client) {
|
public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String username, String client) {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue