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