Merge branch 'release/4.2.2'

This commit is contained in:
Gravit 2019-01-21 19:59:34 +07:00
commit 767feff6b9
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
180 changed files with 1712 additions and 1894 deletions

2
.gitignore vendored
View file

@ -107,3 +107,5 @@ buildnumber
*.directory *.directory
cmd.bat cmd.bat
cmd.sh cmd.sh
## PVS Studio
.PVS-Studio/

View file

@ -1,42 +1,7 @@
package ru.gravit.launchserver; package ru.gravit.launchserver;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.lang.ProcessBuilder.Redirect;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.SocketAddress;
import java.nio.file.DirectoryStream;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.security.KeyPair;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.zip.CRC32;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import ru.gravit.launcher.Launcher; import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
@ -52,24 +17,12 @@
import ru.gravit.launchserver.auth.permissions.PermissionsHandler; import ru.gravit.launchserver.auth.permissions.PermissionsHandler;
import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.AuthProvider;
import ru.gravit.launchserver.auth.provider.RejectAuthProvider; import ru.gravit.launchserver.auth.provider.RejectAuthProvider;
import ru.gravit.launchserver.binary.EXEL4JLauncherBinary; import ru.gravit.launchserver.binary.*;
import ru.gravit.launchserver.binary.EXELauncherBinary;
import ru.gravit.launchserver.binary.JARLauncherBinary;
import ru.gravit.launchserver.binary.LauncherBinary;
import ru.gravit.launchserver.binary.ProguardConf;
import ru.gravit.launchserver.command.handler.CommandHandler; import ru.gravit.launchserver.command.handler.CommandHandler;
import ru.gravit.launchserver.command.handler.JLineCommandHandler; import ru.gravit.launchserver.command.handler.JLineCommandHandler;
import ru.gravit.launchserver.command.handler.StdCommandHandler; import ru.gravit.launchserver.command.handler.StdCommandHandler;
import ru.gravit.launchserver.config.AuthHandlerAdapter; import ru.gravit.launchserver.config.*;
import ru.gravit.launchserver.config.AuthProviderAdapter; import ru.gravit.launchserver.manangers.*;
import ru.gravit.launchserver.config.HWIDHandlerAdapter;
import ru.gravit.launchserver.config.PermissionsHandlerAdapter;
import ru.gravit.launchserver.config.TextureProviderAdapter;
import ru.gravit.launchserver.manangers.MirrorManager;
import ru.gravit.launchserver.manangers.ModulesManager;
import ru.gravit.launchserver.manangers.ReconfigurableManager;
import ru.gravit.launchserver.manangers.ReloadManager;
import ru.gravit.launchserver.manangers.SessionManager;
import ru.gravit.launchserver.manangers.hook.AuthHookManager; import ru.gravit.launchserver.manangers.hook.AuthHookManager;
import ru.gravit.launchserver.manangers.hook.BuildHookManager; import ru.gravit.launchserver.manangers.hook.BuildHookManager;
import ru.gravit.launchserver.manangers.hook.SocketHookManager; import ru.gravit.launchserver.manangers.hook.SocketHookManager;
@ -77,12 +30,27 @@
import ru.gravit.launchserver.socket.ServerSocketHandler; import ru.gravit.launchserver.socket.ServerSocketHandler;
import ru.gravit.launchserver.texture.RequestTextureProvider; import ru.gravit.launchserver.texture.RequestTextureProvider;
import ru.gravit.launchserver.texture.TextureProvider; import ru.gravit.launchserver.texture.TextureProvider;
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.*;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.JVMHelper; import java.io.BufferedReader;
import ru.gravit.utils.helper.LogHelper; import java.io.BufferedWriter;
import ru.gravit.utils.helper.SecurityHelper; import java.io.File;
import ru.gravit.utils.helper.VerifyHelper; import java.io.IOException;
import java.lang.ProcessBuilder.Redirect;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.security.KeyPair;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.zip.CRC32;
public final class LaunchServer implements Runnable { public final class LaunchServer implements Runnable {
public static final class Config { public static final class Config {
@ -178,24 +146,19 @@ public void setAddress(String address) {
public void verify() { public void verify() {
VerifyHelper.verify(getAddress(), VerifyHelper.NOT_EMPTY, "LaunchServer address can't be empty"); VerifyHelper.verify(getAddress(), VerifyHelper.NOT_EMPTY, "LaunchServer address can't be empty");
if(authHandler == null) if (authHandler == null) {
{
throw new NullPointerException("AuthHandler must not be null"); throw new NullPointerException("AuthHandler must not be null");
} }
if(authProvider == null || authProvider[0] == null) if (authProvider == null || authProvider[0] == null) {
{
throw new NullPointerException("AuthProvider must not be null"); throw new NullPointerException("AuthProvider must not be null");
} }
if(textureProvider == null) if (textureProvider == null) {
{
throw new NullPointerException("TextureProvider must not be null"); throw new NullPointerException("TextureProvider must not be null");
} }
if(permissionsHandler == null) if (permissionsHandler == null) {
{
throw new NullPointerException("PermissionsHandler must not be null"); throw new NullPointerException("PermissionsHandler must not be null");
} }
if(env == null) if (env == null) {
{
throw new NullPointerException("Env must not be null"); throw new NullPointerException("Env must not be null");
} }
} }
@ -403,8 +366,8 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
config = Launcher.gson.fromJson(reader, Config.class); config = Launcher.gson.fromJson(reader, Config.class);
} }
config.verify(); config.verify();
for(AuthProvider provider : config.authProvider) Launcher.applyLauncherEnv(config.env);
{ for (AuthProvider provider : config.authProvider) {
provider.init(); provider.init();
} }
config.authHandler.init(); config.authHandler.init();
@ -425,8 +388,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
reloadManager.registerReloadable("permissionsHandler", (Reloadable) config.permissionsHandler); reloadManager.registerReloadable("permissionsHandler", (Reloadable) config.permissionsHandler);
if (config.authHandler instanceof Reloadable) if (config.authHandler instanceof Reloadable)
reloadManager.registerReloadable("authHandler", (Reloadable) config.authHandler); reloadManager.registerReloadable("authHandler", (Reloadable) config.authHandler);
for(int i=0;i<config.authProvider.length;++i) for (int i = 0; i < config.authProvider.length; ++i) {
{
AuthProvider provider = config.authProvider[i]; AuthProvider provider = config.authProvider[i];
if (provider instanceof Reloadable) if (provider instanceof Reloadable)
reloadManager.registerReloadable("authHandler".concat(String.valueOf(i)), (Reloadable) provider); reloadManager.registerReloadable("authHandler".concat(String.valueOf(i)), (Reloadable) provider);
@ -434,20 +396,13 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
if (config.textureProvider instanceof Reloadable) if (config.textureProvider instanceof Reloadable)
reloadManager.registerReloadable("textureProvider", (Reloadable) config.textureProvider); reloadManager.registerReloadable("textureProvider", (Reloadable) config.textureProvider);
Arrays.stream(config.mirrors).forEach(s -> { Arrays.stream(config.mirrors).forEach(mirrorManager::addMirror);
try {
mirrorManager.addMirror(s);
} catch (MalformedURLException e) {
e.printStackTrace();
}
});
if (config.permissionsHandler instanceof Reconfigurable) if (config.permissionsHandler instanceof Reconfigurable)
reconfigurableManager.registerReconfigurable("permissionsHandler", (Reconfigurable) config.permissionsHandler); reconfigurableManager.registerReconfigurable("permissionsHandler", (Reconfigurable) config.permissionsHandler);
if (config.authHandler instanceof Reconfigurable) if (config.authHandler instanceof Reconfigurable)
reconfigurableManager.registerReconfigurable("authHandler", (Reconfigurable) config.authHandler); reconfigurableManager.registerReconfigurable("authHandler", (Reconfigurable) config.authHandler);
for(int i=0;i<config.authProvider.length;++i) for (int i = 0; i < config.authProvider.length; ++i) {
{
AuthProvider provider = config.authProvider[i]; AuthProvider provider = config.authProvider[i];
if (provider instanceof Reconfigurable) if (provider instanceof Reconfigurable)
reconfigurableManager.registerReconfigurable("authHandler".concat(String.valueOf(i)), (Reconfigurable) provider); reconfigurableManager.registerReconfigurable("authHandler".concat(String.valueOf(i)), (Reconfigurable) provider);
@ -455,13 +410,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
if (config.textureProvider instanceof Reconfigurable) if (config.textureProvider instanceof Reconfigurable)
reconfigurableManager.registerReconfigurable("textureProvider", (Reconfigurable) config.textureProvider); reconfigurableManager.registerReconfigurable("textureProvider", (Reconfigurable) config.textureProvider);
Arrays.stream(config.mirrors).forEach(s -> { Arrays.stream(config.mirrors).forEach(mirrorManager::addMirror);
try {
mirrorManager.addMirror(s);
} catch (MalformedURLException e) {
e.printStackTrace();
}
});
// init modules // init modules
modulesManager.initModules(); modulesManager.initModules();
@ -492,8 +441,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
modulesManager.postInitModules(); modulesManager.postInitModules();
} }
public static void initGson() public static void initGson() {
{
if (Launcher.gson != null) return; if (Launcher.gson != null) return;
Launcher.gsonBuilder = new GsonBuilder(); Launcher.gsonBuilder = new GsonBuilder();
Launcher.gsonBuilder.registerTypeAdapter(AuthProvider.class, new AuthProviderAdapter()); Launcher.gsonBuilder.registerTypeAdapter(AuthProvider.class, new AuthProviderAdapter());
@ -593,6 +541,8 @@ private void generateConfigIfNotExists() throws IOException {
newConfig.enabledProGuard = true; newConfig.enabledProGuard = true;
newConfig.stripLineNumbers = true; newConfig.stripLineNumbers = true;
newConfig.deleteTempFiles = true; newConfig.deleteTempFiles = true;
newConfig.isWarningMissArchJava = true;
// Set server address // Set server address
LogHelper.println("LaunchServer address: "); LogHelper.println("LaunchServer address: ");
newConfig.setAddress(commandHandler.readLine()); newConfig.setAddress(commandHandler.readLine());
@ -635,6 +585,7 @@ public void run() {
JVMHelper.RUNTIME.addShutdownHook(CommonHelper.newThread(null, false, this::close)); JVMHelper.RUNTIME.addShutdownHook(CommonHelper.newThread(null, false, this::close));
CommonHelper.newThread("Command Thread", true, commandHandler).start(); CommonHelper.newThread("Command Thread", true, commandHandler).start();
rebindServerSocket(); rebindServerSocket();
modulesManager.finishModules();
} }
@ -699,8 +650,7 @@ public void syncUpdatesDir(Collection<String> dirs) throws IOException {
public void restart() { public void restart() {
ProcessBuilder builder = new ProcessBuilder(); ProcessBuilder builder = new ProcessBuilder();
List<String> args = new ArrayList<>(); if (config.startScript != null) builder.command(Collections.singletonList(config.startScript));
if (config.startScript != null) args.add(config.startScript);
else throw new IllegalArgumentException("Please create start script and link it as startScript in config."); else throw new IllegalArgumentException("Please create start script and link it as startScript in config.");
builder.directory(this.dir.toFile()); builder.directory(this.dir.toFile());
builder.inheritIO(); builder.inheritIO();

View file

@ -2,5 +2,6 @@
public interface Reconfigurable { public interface Reconfigurable {
void reconfig(String action, String[] args); void reconfig(String action, String[] args);
void printConfigHelp(); void printConfigHelp();
} }

View file

@ -1,4 +1,5 @@
package ru.gravit.launchserver; package ru.gravit.launchserver;
@FunctionalInterface @FunctionalInterface
public interface Reloadable { public interface Reloadable {
void reload() throws Exception; void reload() throws Exception;

View file

@ -2,12 +2,7 @@
import java.io.IOException; import java.io.IOException;
import java.lang.instrument.Instrumentation; import java.lang.instrument.Instrumentation;
import java.nio.file.FileVisitOption; import java.nio.file.*;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.Collections; import java.util.Collections;
import java.util.jar.JarFile; import java.util.jar.JarFile;

View file

@ -1,5 +1,10 @@
package ru.gravit.launchserver.asm; package ru.gravit.launchserver.asm;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;
import ru.gravit.utils.helper.IOHelper;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -8,12 +13,6 @@
import java.util.List; import java.util.List;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;
import ru.gravit.utils.helper.IOHelper;
/** /**
* Позволяет искать методы внутри незагруженных классов и общие суперклассы для * Позволяет искать методы внутри незагруженных классов и общие суперклассы для
* чего угодно. Работает через поиск class-файлов в classpath. * чего угодно. Работает через поиск class-файлов в classpath.
@ -98,7 +97,7 @@ public ArrayList<String> getSuperClasses(String type) {
} }
@Override @Override
public void close() throws IOException { public void close() {
cp.stream().forEach(IOHelper::close); cp.stream().forEach(IOHelper::close);
cp.clear(); cp.clear();
} }

View file

@ -1,10 +1,10 @@
package ru.gravit.launchserver.asm; package ru.gravit.launchserver.asm;
import java.util.ArrayList;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
import java.util.ArrayList;
/** /**
* ClassWriter с другой реализацией метода getCommonSuperClass: при его * ClassWriter с другой реализацией метода getCommonSuperClass: при его
* использовании не происходит загрузки классов. * использовании не происходит загрузки классов.

View file

@ -1,13 +1,13 @@
package ru.gravit.launchserver.auth; package ru.gravit.launchserver.auth;
import ru.gravit.launcher.NeedGarbageCollection;
import ru.gravit.launchserver.LaunchServer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import ru.gravit.launcher.NeedGarbageCollection;
import ru.gravit.launchserver.LaunchServer;
public class AuthLimiter implements NeedGarbageCollection { public class AuthLimiter implements NeedGarbageCollection {
static class AuthEntry { static class AuthEntry {
public int value; public int value;

View file

@ -1,17 +1,15 @@
package ru.gravit.launchserver.auth; package ru.gravit.launchserver.auth;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import com.mysql.cj.jdbc.MysqlDataSource; import com.mysql.cj.jdbc.MysqlDataSource;
import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
public final class MySQLSourceConfig implements AutoCloseable { public final class MySQLSourceConfig implements AutoCloseable {
public static final int TIMEOUT = VerifyHelper.verifyInt( public static final int TIMEOUT = VerifyHelper.verifyInt(

View file

@ -1,15 +1,15 @@
package ru.gravit.launchserver.auth.handler; package ru.gravit.launchserver.auth.handler;
import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
import ru.gravit.utils.helper.VerifyHelper;
public abstract class AuthHandler implements AutoCloseable { public abstract class AuthHandler implements AutoCloseable {
private static final Map<String, Class<? extends AuthHandler>> AUTH_HANDLERS = new ConcurrentHashMap<>(4); private static final Map<String, Class<? extends AuthHandler>> AUTH_HANDLERS = new ConcurrentHashMap<>(4);
private static boolean registredHandl = false; private static boolean registredHandl = false;
@ -25,14 +25,13 @@ public static void registerHandler(String name, Class<? extends AuthHandler> ada
VerifyHelper.putIfAbsent(AUTH_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"), VerifyHelper.putIfAbsent(AUTH_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"),
String.format("Auth handler has been already registered: '%s'", name)); String.format("Auth handler has been already registered: '%s'", name));
} }
public static Class<? extends AuthHandler> getHandlerClass(String name)
{ public static Class<? extends AuthHandler> getHandlerClass(String name) {
return AUTH_HANDLERS.get(name); return AUTH_HANDLERS.get(name);
} }
public static String getHandlerName(Class<AuthHandler> clazz)
{ public static String getHandlerName(Class<AuthHandler> clazz) {
for(Map.Entry<String,Class<? extends AuthHandler>> e: AUTH_HANDLERS.entrySet()) for (Map.Entry<String, Class<? extends AuthHandler>> e : AUTH_HANDLERS.entrySet()) {
{
if (e.getValue().equals(clazz)) return e.getKey(); if (e.getValue().equals(clazz)) return e.getKey();
} }
return null; return null;
@ -66,8 +65,7 @@ public static void registerHandlers() {
public abstract String uuidToUsername(UUID uuid) throws IOException; public abstract String uuidToUsername(UUID uuid) throws IOException;
public void init() public void init() {
{
} }
} }

View file

@ -1,14 +1,14 @@
package ru.gravit.launchserver.auth.handler; package ru.gravit.launchserver.auth.handler;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.utils.helper.IOHelper;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.utils.helper.IOHelper;
public final class BinaryFileAuthHandler extends FileAuthHandler { public final class BinaryFileAuthHandler extends FileAuthHandler {
@Override @Override

View file

@ -1,17 +1,17 @@
package ru.gravit.launchserver.auth.handler; package ru.gravit.launchserver.auth.handler;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import ru.gravit.launcher.NeedGarbageCollection; import ru.gravit.launcher.NeedGarbageCollection;
import ru.gravit.launchserver.auth.provider.AuthProviderResult; import ru.gravit.launchserver.auth.provider.AuthProviderResult;
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
public abstract class CachedAuthHandler extends AuthHandler implements NeedGarbageCollection { public abstract class CachedAuthHandler extends AuthHandler implements NeedGarbageCollection {
public static final class Entry { public static final class Entry {
@ -28,6 +28,7 @@ public Entry(UUID uuid, String username, String accessToken, String serverID) {
this.serverID = serverID == null ? null : VerifyHelper.verifyServerID(serverID); this.serverID = serverID == null ? null : VerifyHelper.verifyServerID(serverID);
} }
} }
private transient final Map<UUID, Entry> entryCache = new HashMap<>(1024); private transient final Map<UUID, Entry> entryCache = new HashMap<>(1024);
private transient final Map<String, UUID> usernamesCache = new HashMap<>(1024); private transient final Map<String, UUID> usernamesCache = new HashMap<>(1024);
@ -114,12 +115,11 @@ public Map<String, UUID> getUsernamesCache() {
return usernamesCache; return usernamesCache;
} }
public void loadEntryCache(Map<UUID, Entry> map) public void loadEntryCache(Map<UUID, Entry> map) {
{
entryCache.putAll(map); entryCache.putAll(map);
} }
public void loadUsernameCache(Map<String, UUID> map)
{ public void loadUsernameCache(Map<String, UUID> map) {
usernamesCache.putAll(map); usernamesCache.putAll(map);
} }

View file

@ -1,25 +1,17 @@
package ru.gravit.launchserver.auth.handler; package ru.gravit.launchserver.auth.handler;
import java.io.IOException;
import java.nio.file.Path;
import java.security.SecureRandom;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.profiles.PlayerProfile;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.stream.StreamObject; import ru.gravit.launcher.serialize.stream.StreamObject;
import ru.gravit.launchserver.auth.provider.AuthProviderResult; import ru.gravit.launchserver.auth.provider.AuthProviderResult;
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.*;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import java.io.IOException;
import ru.gravit.utils.helper.SecurityHelper; import java.nio.file.Path;
import ru.gravit.utils.helper.VerifyHelper; import java.security.SecureRandom;
import java.util.*;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public abstract class FileAuthHandler extends AuthHandler { public abstract class FileAuthHandler extends AuthHandler {
public static final class Entry extends StreamObject { public static final class Entry extends StreamObject {

View file

@ -1,12 +1,12 @@
package ru.gravit.launchserver.auth.handler; package ru.gravit.launchserver.auth.handler;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.VerifyHelper;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
import java.util.UUID; import java.util.UUID;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.VerifyHelper;
public final class MemoryAuthHandler extends CachedAuthHandler { public final class MemoryAuthHandler extends CachedAuthHandler {
private static String toUsername(UUID uuid) { private static String toUsername(UUID uuid) {
byte[] bytes = ByteBuffer.allocate(16). byte[] bytes = ByteBuffer.allocate(16).

View file

@ -1,15 +1,14 @@
package ru.gravit.launchserver.auth.handler; package ru.gravit.launchserver.auth.handler;
import ru.gravit.launchserver.auth.MySQLSourceConfig;
import ru.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.UUID; import java.util.UUID;
import ru.gravit.launchserver.auth.MySQLSourceConfig;
import ru.gravit.utils.helper.LogHelper;
public final class MySQLAuthHandler extends CachedAuthHandler { public final class MySQLAuthHandler extends CachedAuthHandler {
private MySQLSourceConfig mySQLHolder; private MySQLSourceConfig mySQLHolder;
private String uuidColumn; private String uuidColumn;
@ -23,9 +22,9 @@ public final class MySQLAuthHandler extends CachedAuthHandler {
private transient String queryByUsernameSQL; private transient String queryByUsernameSQL;
private transient String updateAuthSQL; private transient String updateAuthSQL;
private transient String updateServerIDSQL; private transient String updateServerIDSQL;
@Override @Override
public void init() public void init() {
{
//Verify //Verify
if (mySQLHolder == null) LogHelper.error("[Verify][AuthHandler] mySQLHolder cannot be null"); if (mySQLHolder == null) LogHelper.error("[Verify][AuthHandler] mySQLHolder cannot be null");
if (uuidColumn == null) LogHelper.error("[Verify][AuthHandler] uuidColumn cannot be null"); if (uuidColumn == null) LogHelper.error("[Verify][AuthHandler] uuidColumn cannot be null");
@ -43,6 +42,7 @@ public void init()
updateServerIDSQL = String.format("UPDATE %s SET %s=? WHERE %s=? LIMIT 1", updateServerIDSQL = String.format("UPDATE %s SET %s=? WHERE %s=? LIMIT 1",
table, serverIDColumn, uuidColumn); table, serverIDColumn, uuidColumn);
} }
@Override @Override
public void close() { public void close() {
mySQLHolder.close(); mySQLHolder.close();
@ -65,11 +65,8 @@ protected Entry fetchEntry(UUID uuid) throws IOException {
private Entry query(String sql, String value) throws IOException { private Entry query(String sql, String value) throws IOException {
try { try {
Connection c = mySQLHolder.getConnection(); PreparedStatement s = mySQLHolder.getConnection().prepareStatement(sql);
PreparedStatement s = c.prepareStatement(sql);
s.setString(1, value); s.setString(1, value);
// Execute query
s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); s.setQueryTimeout(MySQLSourceConfig.TIMEOUT);
try (ResultSet set = s.executeQuery()) { try (ResultSet set = s.executeQuery()) {
return constructEntry(set); return constructEntry(set);
@ -82,13 +79,10 @@ private Entry query(String sql, String value) throws IOException {
@Override @Override
protected boolean updateAuth(UUID uuid, String username, String accessToken) throws IOException { protected boolean updateAuth(UUID uuid, String username, String accessToken) throws IOException {
try { try {
Connection c = mySQLHolder.getConnection(); PreparedStatement s = mySQLHolder.getConnection().prepareStatement(updateAuthSQL);
PreparedStatement s = c.prepareStatement(updateAuthSQL);
s.setString(1, username); // Username case s.setString(1, username); // Username case
s.setString(2, accessToken); s.setString(2, accessToken);
s.setString(3, uuid.toString()); s.setString(3, uuid.toString());
// Execute update
s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); s.setQueryTimeout(MySQLSourceConfig.TIMEOUT);
return s.executeUpdate() > 0; return s.executeUpdate() > 0;
} catch (SQLException e) { } catch (SQLException e) {
@ -99,12 +93,9 @@ protected boolean updateAuth(UUID uuid, String username, String accessToken) thr
@Override @Override
protected boolean updateServerID(UUID uuid, String serverID) throws IOException { protected boolean updateServerID(UUID uuid, String serverID) throws IOException {
try { try {
Connection c = mySQLHolder.getConnection(); PreparedStatement s = mySQLHolder.getConnection().prepareStatement(updateServerIDSQL);
PreparedStatement s = c.prepareStatement(updateServerIDSQL);
s.setString(1, serverID); s.setString(1, serverID);
s.setString(2, uuid.toString()); s.setString(2, uuid.toString());
// Execute update
s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); s.setQueryTimeout(MySQLSourceConfig.TIMEOUT);
return s.executeUpdate() > 0; return s.executeUpdate() > 0;
} catch (SQLException e) { } catch (SQLException e) {

View file

@ -1,12 +1,12 @@
package ru.gravit.launchserver.auth.handler; package ru.gravit.launchserver.auth.handler;
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
import ru.gravit.utils.helper.VerifyHelper;
public final class NullAuthHandler extends AuthHandler { public final class NullAuthHandler extends AuthHandler {
private volatile AuthHandler handler; private volatile AuthHandler handler;

View file

@ -1,10 +1,10 @@
package ru.gravit.launchserver.auth.hwid; package ru.gravit.launchserver.auth.hwid;
import ru.gravit.launcher.HWID;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import ru.gravit.launcher.HWID;
public class AcceptHWIDHandler extends HWIDHandler { public class AcceptHWIDHandler extends HWIDHandler {
@Override @Override

View file

@ -1,13 +1,13 @@
package ru.gravit.launchserver.auth.hwid; package ru.gravit.launchserver.auth.hwid;
import ru.gravit.launcher.HWID;
import ru.gravit.utils.helper.VerifyHelper;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import ru.gravit.launcher.HWID;
import ru.gravit.utils.helper.VerifyHelper;
public abstract class HWIDHandler implements AutoCloseable { public abstract class HWIDHandler implements AutoCloseable {
private static final Map<String, Class<? extends HWIDHandler>> HW_HANDLERS = new ConcurrentHashMap<>(4); private static final Map<String, Class<? extends HWIDHandler>> HW_HANDLERS = new ConcurrentHashMap<>(4);
private static boolean registredHandl = false; private static boolean registredHandl = false;
@ -44,14 +44,12 @@ public void check(HWID hwid, String username) throws HWIDException {
public abstract void unban(List<HWID> hwid) throws HWIDException; public abstract void unban(List<HWID> hwid) throws HWIDException;
public static Class<? extends HWIDHandler> getHandlerClass(String name) public static Class<? extends HWIDHandler> getHandlerClass(String name) {
{
return HW_HANDLERS.get(name); return HW_HANDLERS.get(name);
} }
public static String getHandlerName(Class<? extends HWIDHandler> clazz)
{ public static String getHandlerName(Class<? extends HWIDHandler> clazz) {
for(Map.Entry<String,Class<? extends HWIDHandler>> e: HW_HANDLERS.entrySet()) for (Map.Entry<String, Class<? extends HWIDHandler>> e : HW_HANDLERS.entrySet()) {
{
if (e.getValue().equals(clazz)) return e.getKey(); if (e.getValue().equals(clazz)) return e.getKey();
} }
return null; return null;

View file

@ -1,19 +1,18 @@
package ru.gravit.launchserver.auth.hwid; package ru.gravit.launchserver.auth.hwid;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import ru.gravit.launcher.HWID;
import ru.gravit.launcher.OshiHWID;
import ru.gravit.utils.HTTPRequest;
import ru.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import ru.gravit.launcher.HWID;
import ru.gravit.launcher.OshiHWID;
import ru.gravit.utils.HTTPRequest;
import ru.gravit.utils.helper.LogHelper;
public final class JsonHWIDHandler extends HWIDHandler { public final class JsonHWIDHandler extends HWIDHandler {
private static final Gson gson = new Gson(); private static final Gson gson = new Gson();
@ -21,6 +20,7 @@ public final class JsonHWIDHandler extends HWIDHandler {
private URL urlBan; private URL urlBan;
private URL urlUnBan; private URL urlUnBan;
private URL urlGet; private URL urlGet;
private String apiKey;
public class banRequest { public class banRequest {
public banRequest(OshiHWID hwid) { public banRequest(OshiHWID hwid) {
@ -28,6 +28,12 @@ public banRequest(OshiHWID hwid) {
} }
OshiHWID hwid; OshiHWID hwid;
String apiKey;
public banRequest(OshiHWID hwid, String apiKey) {
this.hwid = hwid;
this.apiKey = apiKey;
}
} }
public class checkRequest { public class checkRequest {
@ -38,7 +44,13 @@ public checkRequest(String username, OshiHWID hwid) {
String username; String username;
OshiHWID hwid; OshiHWID hwid;
String apiKey;
public checkRequest(String username, OshiHWID hwid, String apiKey) {
this.username = username;
this.hwid = hwid;
this.apiKey = apiKey;
}
} }
public class Result { public class Result {
@ -56,12 +68,18 @@ public HWIDRequest(String username) {
} }
String username; String username;
String apiKey;
public HWIDRequest(String username, String apiKey) {
this.username = username;
this.apiKey = apiKey;
}
} }
@Override @Override
public void ban(List<HWID> l_hwid) throws HWIDException { public void ban(List<HWID> l_hwid) throws HWIDException {
for (HWID hwid : l_hwid) { for (HWID hwid : l_hwid) {
banRequest request = new banRequest((OshiHWID) hwid); banRequest request = new banRequest((OshiHWID) hwid, apiKey);
try { try {
JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan); JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan);
Result r = gson.fromJson(result, Result.class); Result r = gson.fromJson(result, Result.class);
@ -75,7 +93,7 @@ public void ban(List<HWID> l_hwid) throws HWIDException {
@Override @Override
public void check0(HWID hwid, String username) throws HWIDException { public void check0(HWID hwid, String username) throws HWIDException {
checkRequest request = new checkRequest(username, (OshiHWID) hwid); checkRequest request = new checkRequest(username, (OshiHWID) hwid, apiKey);
try { try {
JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), url); JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), url);
BannedResult r = gson.fromJson(result, BannedResult.class); BannedResult r = gson.fromJson(result, BannedResult.class);
@ -96,7 +114,7 @@ public void close() {
@Override @Override
public List<HWID> getHwid(String username) throws HWIDException { public List<HWID> getHwid(String username) throws HWIDException {
ArrayList<HWID> hwids = new ArrayList<>(); ArrayList<HWID> hwids = new ArrayList<>();
HWIDRequest request = new HWIDRequest(username); HWIDRequest request = new HWIDRequest(username, apiKey);
try { try {
JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlGet); JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlGet);
OshiHWID[] r = gson.fromJson(result, OshiHWID[].class); OshiHWID[] r = gson.fromJson(result, OshiHWID[].class);
@ -111,7 +129,7 @@ public List<HWID> getHwid(String username) throws HWIDException {
@Override @Override
public void unban(List<HWID> l_hwid) throws HWIDException { public void unban(List<HWID> l_hwid) throws HWIDException {
for (HWID hwid : l_hwid) { for (HWID hwid : l_hwid) {
banRequest request = new banRequest((OshiHWID) hwid); banRequest request = new banRequest((OshiHWID) hwid, apiKey);
try { try {
JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlUnBan); JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlUnBan);
Result r = gson.fromJson(result, Result.class); Result r = gson.fromJson(result, Result.class);

View file

@ -1,5 +1,11 @@
package ru.gravit.launchserver.auth.hwid; package ru.gravit.launchserver.auth.hwid;
import ru.gravit.launcher.HWID;
import ru.gravit.launcher.OshiHWID;
import ru.gravit.launchserver.auth.MySQLSourceConfig;
import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.LogHelper;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -7,12 +13,6 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import ru.gravit.launcher.HWID;
import ru.gravit.launcher.OshiHWID;
import ru.gravit.launchserver.auth.MySQLSourceConfig;
import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.LogHelper;
public class MysqlHWIDHandler extends HWIDHandler { public class MysqlHWIDHandler extends HWIDHandler {
private MySQLSourceConfig mySQLHolder; private MySQLSourceConfig mySQLHolder;
@ -226,6 +226,6 @@ public List<HWID> getHwid(String username) {
@Override @Override
public void close() { public void close() {
// Do nothing mySQLHolder.close();
} }
} }

View file

@ -5,6 +5,7 @@
public class ConfigPermissionsHandler extends PermissionsHandler { public class ConfigPermissionsHandler extends PermissionsHandler {
public boolean isAdmin = false; public boolean isAdmin = false;
public boolean isServer = false; public boolean isServer = false;
@Override @Override
public ClientPermissions getPermissions(String username) { public ClientPermissions getPermissions(String username) {
ClientPermissions permissions = new ClientPermissions(); ClientPermissions permissions = new ClientPermissions();

View file

@ -1,5 +1,12 @@
package ru.gravit.launchserver.auth.permissions; package ru.gravit.launchserver.auth.permissions;
import com.google.gson.reflect.TypeToken;
import ru.gravit.launcher.ClientPermissions;
import ru.gravit.launcher.Launcher;
import ru.gravit.launchserver.Reloadable;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
@ -9,56 +16,46 @@
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.google.gson.reflect.TypeToken;
import ru.gravit.launcher.ClientPermissions;
import ru.gravit.launcher.Launcher;
import ru.gravit.launchserver.Reloadable;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
public class JsonFilePermissionsHandler extends PermissionsHandler implements Reloadable { public class JsonFilePermissionsHandler extends PermissionsHandler implements Reloadable {
public String filename = "permissions.json"; public String filename = "permissions.json";
public static Map<String, ClientPermissions> map; public static Map<String, ClientPermissions> map;
@Override @Override
public void reload() throws Exception { public void reload() {
map.clear(); map.clear();
Path path = Paths.get(filename); Path path = Paths.get(filename);
Type type = new TypeToken<Map<String,ClientPermissions>>(){}.getType(); Type type = new TypeToken<Map<String, ClientPermissions>>() {
try(Reader reader = IOHelper.newReader(path)) }.getType();
{ try (Reader reader = IOHelper.newReader(path)) {
map = Launcher.gson.fromJson(reader, type); map = Launcher.gson.fromJson(reader, type);
} catch (IOException e) { } catch (IOException e) {
LogHelper.error(e); LogHelper.error(e);
} }
} }
public static class Enity public static class Enity {
{
public String username; public String username;
public ClientPermissions permissions; public ClientPermissions permissions;
} }
@Override @Override
public ClientPermissions getPermissions(String username) public ClientPermissions getPermissions(String username) {
{
return map.getOrDefault(username, ClientPermissions.DEFAULT); return map.getOrDefault(username, ClientPermissions.DEFAULT);
} }
public JsonFilePermissionsHandler() { public JsonFilePermissionsHandler() {
Type type = new TypeToken<Map<String,ClientPermissions>>(){}.getType(); Type type = new TypeToken<Map<String, ClientPermissions>>() {
}.getType();
Path path = Paths.get(filename); Path path = Paths.get(filename);
if(!IOHelper.exists(path)) if (!IOHelper.exists(path)) {
{
map = new HashMap<>(); map = new HashMap<>();
try(Writer writer = IOHelper.newWriter(path)) try (Writer writer = IOHelper.newWriter(path)) {
{
Launcher.gson.toJson(map, writer); Launcher.gson.toJson(map, writer);
} catch (IOException e) { } catch (IOException e) {
LogHelper.error(e); LogHelper.error(e);
} }
} }
try(Reader reader = IOHelper.newReader(path)) try (Reader reader = IOHelper.newReader(path)) {
{
map = Launcher.gson.fromJson(reader, type); map = Launcher.gson.fromJson(reader, type);
} catch (IOException e) { } catch (IOException e) {
LogHelper.error(e); LogHelper.error(e);

View file

@ -1,32 +1,33 @@
package ru.gravit.launchserver.auth.permissions; package ru.gravit.launchserver.auth.permissions;
import ru.gravit.launcher.ClientPermissions;
import ru.gravit.utils.helper.VerifyHelper;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import ru.gravit.launcher.ClientPermissions;
import ru.gravit.utils.helper.VerifyHelper;
public abstract class PermissionsHandler { public abstract class PermissionsHandler {
private static final Map<String, Class<? extends PermissionsHandler>> PERMISSIONS_HANDLERS = new ConcurrentHashMap<>(4); private static final Map<String, Class<? extends PermissionsHandler>> PERMISSIONS_HANDLERS = new ConcurrentHashMap<>(4);
private static boolean registredHandl = false; private static boolean registredHandl = false;
public static void registerHandler(String name, Class<? extends PermissionsHandler> adapter) { public static void registerHandler(String name, Class<? extends PermissionsHandler> adapter) {
VerifyHelper.verifyIDName(name); VerifyHelper.verifyIDName(name);
VerifyHelper.putIfAbsent(PERMISSIONS_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"), VerifyHelper.putIfAbsent(PERMISSIONS_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"),
String.format("Auth handler has been already registered: '%s'", name)); String.format("Auth handler has been already registered: '%s'", name));
} }
public static Class<? extends PermissionsHandler> getHandlerClass(String name)
{ public static Class<? extends PermissionsHandler> getHandlerClass(String name) {
return PERMISSIONS_HANDLERS.get(name); return PERMISSIONS_HANDLERS.get(name);
} }
public static String getHandlerName(Class<? extends PermissionsHandler> clazz)
{ public static String getHandlerName(Class<? extends PermissionsHandler> clazz) {
for(Map.Entry<String,Class<? extends PermissionsHandler>> e: PERMISSIONS_HANDLERS.entrySet()) for (Map.Entry<String, Class<? extends PermissionsHandler>> e : PERMISSIONS_HANDLERS.entrySet()) {
{
if (e.getValue().equals(clazz)) return e.getKey(); if (e.getValue().equals(clazz)) return e.getKey();
} }
return null; return null;
} }
public static void registerHandlers() { public static void registerHandlers() {
if (!registredHandl) { if (!registredHandl) {
registerHandler("json", JsonFilePermissionsHandler.class); registerHandler("json", JsonFilePermissionsHandler.class);
@ -35,5 +36,6 @@ public static void registerHandlers() {
registredHandl = true; registredHandl = true;
} }
} }
public abstract ClientPermissions getPermissions(String username); public abstract ClientPermissions getPermissions(String username);
} }

View file

@ -1,15 +1,15 @@
package ru.gravit.launchserver.auth.provider; package ru.gravit.launchserver.auth.provider;
import java.io.IOException;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.launchserver.auth.handler.AuthHandler; import ru.gravit.launchserver.auth.handler.AuthHandler;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
public abstract class AuthProvider implements AutoCloseable { public abstract class AuthProvider implements AutoCloseable {
private static final Map<String, Class<? extends AuthProvider>> AUTH_PROVIDERS = new ConcurrentHashMap<>(8); private static final Map<String, Class<? extends AuthProvider>> AUTH_PROVIDERS = new ConcurrentHashMap<>(8);
private static boolean registredProv = false; private static boolean registredProv = false;
@ -49,20 +49,18 @@ public AuthHandler getAccociateHandler(int this_position) {
@Override @Override
public abstract void close() throws IOException; public abstract void close() throws IOException;
public static Class<? extends AuthProvider> getProviderClass(String name) public static Class<? extends AuthProvider> getProviderClass(String name) {
{
return AUTH_PROVIDERS.get(name); return AUTH_PROVIDERS.get(name);
} }
public static String getProviderName(Class<? extends AuthProvider> clazz)
{ public static String getProviderName(Class<? extends AuthProvider> clazz) {
for(Map.Entry<String,Class<? extends AuthProvider>> e: AUTH_PROVIDERS.entrySet()) for (Map.Entry<String, Class<? extends AuthProvider>> e : AUTH_PROVIDERS.entrySet()) {
{
if (e.getValue().equals(clazz)) return e.getKey(); if (e.getValue().equals(clazz)) return e.getKey();
} }
return null; return null;
} }
public void init()
{ public void init() {
} }
} }

View file

@ -1,18 +1,18 @@
package ru.gravit.launchserver.auth.provider; package ru.gravit.launchserver.auth.provider;
import java.io.IOException;
import java.net.URL;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import ru.gravit.launcher.ClientPermissions; import ru.gravit.launcher.ClientPermissions;
import ru.gravit.utils.HTTPRequest; import ru.gravit.utils.HTTPRequest;
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import java.io.IOException;
import java.net.URL;
public final class JsonAuthProvider extends AuthProvider { public final class JsonAuthProvider extends AuthProvider {
private static Gson gson = new Gson(); private static Gson gson = new Gson();
private URL url; private URL url;
private String apiKey;
public class authResult { public class authResult {
String username; String username;
@ -27,14 +27,22 @@ public authRequest(String username, String password, String ip) {
this.ip = ip; this.ip = ip;
} }
public authRequest(String username, String password, String ip, String apiKey) {
this.username = username;
this.password = password;
this.ip = ip;
this.apiKey = apiKey;
}
String username; String username;
String password; String password;
String ip; String ip;
String apiKey;
} }
@Override @Override
public AuthProviderResult auth(String login, String password, String ip) throws IOException { public AuthProviderResult auth(String login, String password, String ip) throws IOException {
authRequest authRequest = new authRequest(login, password, ip); authRequest authRequest = new authRequest(login, password, ip, apiKey);
JsonElement request = gson.toJsonTree(authRequest); JsonElement request = gson.toJsonTree(authRequest);
JsonElement content = HTTPRequest.jsonRequest(request, url); JsonElement content = HTTPRequest.jsonRequest(request, url);
if (!content.isJsonObject()) if (!content.isJsonObject())

View file

@ -1,16 +1,15 @@
package ru.gravit.launchserver.auth.provider; package ru.gravit.launchserver.auth.provider;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import ru.gravit.utils.HTTPRequest;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.UUID; import java.util.UUID;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import ru.gravit.utils.HTTPRequest;
public final class MojangAuthProvider extends AuthProvider { public final class MojangAuthProvider extends AuthProvider {
private static final Pattern UUID_REGEX = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})"); private static final Pattern UUID_REGEX = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})");
private static final URL URL; private static final URL URL;

View file

@ -1,10 +1,5 @@
package ru.gravit.launchserver.auth.provider; package ru.gravit.launchserver.auth.provider;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import ru.gravit.launcher.ClientPermissions; import ru.gravit.launcher.ClientPermissions;
import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.launchserver.auth.MySQLSourceConfig; import ru.gravit.launchserver.auth.MySQLSourceConfig;
@ -12,6 +7,10 @@
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public final class MySQLAuthProvider extends AuthProvider { public final class MySQLAuthProvider extends AuthProvider {
private MySQLSourceConfig mySQLHolder; private MySQLSourceConfig mySQLHolder;
private String query; private String query;
@ -28,8 +27,7 @@ public void init() {
@Override @Override
public AuthProviderResult auth(String login, String password, String ip) throws SQLException, AuthException { public AuthProviderResult auth(String login, String password, String ip) throws SQLException, AuthException {
Connection c = mySQLHolder.getConnection(); PreparedStatement s = mySQLHolder.getConnection().prepareStatement(query);
PreparedStatement s = c.prepareStatement(query);
String[] replaceParams = {"login", login, "password", password, "ip", ip}; String[] replaceParams = {"login", login, "password", password, "ip", ip};
for (int i = 0; i < queryParams.length; i++) for (int i = 0; i < queryParams.length; i++)
s.setString(i + 1, CommonHelper.replace(queryParams[i], replaceParams)); s.setString(i + 1, CommonHelper.replace(queryParams[i], replaceParams));
@ -43,6 +41,6 @@ public AuthProviderResult auth(String login, String password, String ip) throws
@Override @Override
public void close() { public void close() {
// Do nothing mySQLHolder.close();
} }
} }

View file

@ -1,10 +1,10 @@
package ru.gravit.launchserver.auth.provider; package ru.gravit.launchserver.auth.provider;
import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
import ru.gravit.utils.helper.VerifyHelper;
public final class NullAuthProvider extends AuthProvider { public final class NullAuthProvider extends AuthProvider {
private volatile AuthProvider provider; private volatile AuthProvider provider;

View file

@ -1,12 +1,12 @@
package ru.gravit.launchserver.auth.provider; package ru.gravit.launchserver.auth.provider;
import java.util.ArrayList;
import ru.gravit.launchserver.Reconfigurable; import ru.gravit.launchserver.Reconfigurable;
import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import java.util.ArrayList;
public final class RejectAuthProvider extends AuthProvider implements Reconfigurable { public final class RejectAuthProvider extends AuthProvider implements Reconfigurable {
public RejectAuthProvider() { public RejectAuthProvider() {
} }
@ -20,12 +20,9 @@ public RejectAuthProvider(String message) {
@Override @Override
public AuthProviderResult auth(String login, String password, String ip) throws AuthException { public AuthProviderResult auth(String login, String password, String ip) throws AuthException {
if(whitelist != null) if (whitelist != null) {
{ for (String username : whitelist) {
for(String username : whitelist) if (login.equals(username)) {
{
if(login.equals(username))
{
return new AuthProviderResult(login, SecurityHelper.randomStringToken()); return new AuthProviderResult(login, SecurityHelper.randomStringToken());
} }
} }
@ -40,24 +37,22 @@ public void close() {
@Override @Override
public void reconfig(String action, String[] args) { public void reconfig(String action, String[] args) {
if(action.equals("message")) switch (action) {
{ case "message":
message = args[0]; message = args[0];
LogHelper.info("New reject message: %s", message); LogHelper.info("New reject message: %s", message);
} break;
else if(action.equals("whitelist.add")) case "whitelist.add":
{
if (whitelist == null) whitelist = new ArrayList<>(); if (whitelist == null) whitelist = new ArrayList<>();
whitelist.add(args[0]); whitelist.add(args[0]);
} break;
else if(action.equals("whitelist.remove")) case "whitelist.remove":
{
if (whitelist == null) whitelist = new ArrayList<>(); if (whitelist == null) whitelist = new ArrayList<>();
whitelist.remove(args[0]); whitelist.remove(args[0]);
} break;
else if(action.equals("whitelist.clear")) case "whitelist.clear":
{
whitelist.clear(); whitelist.clear();
break;
} }
} }

View file

@ -1,16 +1,16 @@
package ru.gravit.launchserver.auth.provider; package ru.gravit.launchserver.auth.provider;
import java.io.IOException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import ru.gravit.launcher.ClientPermissions; import ru.gravit.launcher.ClientPermissions;
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import java.io.IOException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class RequestAuthProvider extends AuthProvider { public final class RequestAuthProvider extends AuthProvider {
private String url; private String url;
private transient Pattern pattern; private transient Pattern pattern;
@ -18,8 +18,7 @@ public final class RequestAuthProvider extends AuthProvider {
private boolean usePermission; private boolean usePermission;
@Override @Override
public void init() public void init() {
{
if (url == null) LogHelper.error("[Verify][AuthProvider] url cannot be null"); if (url == null) LogHelper.error("[Verify][AuthProvider] url cannot be null");
if (response == null) LogHelper.error("[Verify][AuthProvider] response cannot be null"); if (response == null) LogHelper.error("[Verify][AuthProvider] response cannot be null");
pattern = Pattern.compile(response); pattern = Pattern.compile(response);

View file

@ -1,5 +1,8 @@
package ru.gravit.launchserver.binary; package ru.gravit.launchserver.binary;
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
import ru.gravit.utils.helper.IOHelper;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashSet; import java.util.HashSet;
@ -8,9 +11,6 @@
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
import ru.gravit.utils.helper.IOHelper;
public class BuildContext { public class BuildContext {
public final ZipOutputStream output; public final ZipOutputStream output;
public final JAConfigurator config; public final JAConfigurator config;

View file

@ -1,20 +1,16 @@
package ru.gravit.launchserver.binary; package ru.gravit.launchserver.binary;
import java.io.IOException;
import java.nio.file.Path;
import net.sf.launch4j.Builder; import net.sf.launch4j.Builder;
import net.sf.launch4j.Log; import net.sf.launch4j.Log;
import net.sf.launch4j.config.Config; import net.sf.launch4j.config.*;
import net.sf.launch4j.config.ConfigPersister;
import net.sf.launch4j.config.Jre;
import net.sf.launch4j.config.LanguageID;
import net.sf.launch4j.config.VersionInfo;
import ru.gravit.launcher.Launcher; import ru.gravit.launcher.Launcher;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.io.IOException;
import java.nio.file.Path;
public final class EXEL4JLauncherBinary extends LauncherBinary { public final class EXEL4JLauncherBinary extends LauncherBinary {
private final static class Launch4JLog extends Log { private final static class Launch4JLog extends Log {
private static final Launch4JLog INSTANCE = new Launch4JLog(); private static final Launch4JLog INSTANCE = new Launch4JLog();

View file

@ -1,12 +1,12 @@
package ru.gravit.launchserver.binary; package ru.gravit.launchserver.binary;
import java.io.IOException;
import java.nio.file.Files;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.io.IOException;
import java.nio.file.Files;
public class EXELauncherBinary extends LauncherBinary { public class EXELauncherBinary extends LauncherBinary {
public EXELauncherBinary(LaunchServer server) { public EXELauncherBinary(LaunchServer server) {

View file

@ -1,16 +1,11 @@
package ru.gravit.launchserver.binary; package ru.gravit.launchserver.binary;
import java.io.IOException; import javassist.*;
import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtConstructor;
import javassist.CtMethod;
import javassist.NotFoundException;
import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launchserver.binary.tasks.MainBuildTask; import ru.gravit.launchserver.binary.tasks.MainBuildTask;
import java.io.IOException;
public class JAConfigurator implements AutoCloseable { public class JAConfigurator implements AutoCloseable {
public ClassPool pool; public ClassPool pool;
public CtClass ctClass; public CtClass ctClass;

View file

@ -1,5 +1,12 @@
package ru.gravit.launchserver.binary; package ru.gravit.launchserver.binary;
import ru.gravit.launcher.Launcher;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.binary.tasks.*;
import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -7,18 +14,6 @@
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import ru.gravit.launcher.Launcher;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.binary.tasks.AttachJarsTask;
import ru.gravit.launchserver.binary.tasks.LauncherBuildTask;
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
import ru.gravit.launchserver.binary.tasks.ProGuardBuildTask;
import ru.gravit.launchserver.binary.tasks.AdditionalFixesApplyTask;
import ru.gravit.launchserver.binary.tasks.PrepareBuildTask;
import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
public final class JARLauncherBinary extends LauncherBinary { public final class JARLauncherBinary extends LauncherBinary {
public final AtomicLong count; public final AtomicLong count;
public final Path runtimeDir; public final Path runtimeDir;
@ -59,8 +54,7 @@ public void build() throws IOException {
boolean isNeedDelete = false; boolean isNeedDelete = false;
long time_start = System.currentTimeMillis(); long time_start = System.currentTimeMillis();
long time_this = time_start; long time_this = time_start;
for(LauncherBuildTask task : tasks) for (LauncherBuildTask task : tasks) {
{
LogHelper.subInfo("Task %s", task.getName()); LogHelper.subInfo("Task %s", task.getName());
Path oldPath = thisPath; Path oldPath = thisPath;
thisPath = task.process(oldPath); thisPath = task.process(oldPath);

View file

@ -1,13 +1,13 @@
package ru.gravit.launchserver.binary; package ru.gravit.launchserver.binary;
import java.io.IOException;
import java.nio.file.Path;
import ru.gravit.launcher.serialize.signed.DigestBytesHolder; import ru.gravit.launcher.serialize.signed.DigestBytesHolder;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import java.io.IOException;
import java.nio.file.Path;
public abstract class LauncherBinary { public abstract class LauncherBinary {
public final LaunchServer server; public final LaunchServer server;
public Path syncBinaryFile; public Path syncBinaryFile;

View file

@ -1,21 +1,17 @@
package ru.gravit.launchserver.binary; package ru.gravit.launchserver.binary;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
public class ProguardConf { public class ProguardConf {
private static final String charsFirst = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"; private static final String charsFirst = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ";
private static final String chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ"; private static final String chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ";
@ -40,8 +36,8 @@ public ProguardConf(LaunchServer srv) {
words = proguard.resolve("random.pro"); words = proguard.resolve("random.pro");
this.srv = srv; this.srv = srv;
} }
public String[] buildConfig(Path inputJar, Path outputJar)
{ public String[] buildConfig(Path inputJar, Path outputJar) {
List<String> confStrs = new ArrayList<>(); List<String> confStrs = new ArrayList<>();
prepare(false); prepare(false);
if (srv.config.genMappings) confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'"); if (srv.config.genMappings) confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'");

View file

@ -1,5 +1,13 @@
package ru.gravit.launchserver.binary.tasks; package ru.gravit.launchserver.binary.tasks;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.asm.ClassMetadataReader;
import ru.gravit.launchserver.asm.SafeClassWriter;
import ru.gravit.utils.helper.IOHelper;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
@ -8,15 +16,6 @@
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.asm.ClassMetadataReader;
import ru.gravit.launchserver.asm.SafeClassWriter;
import ru.gravit.utils.helper.IOHelper;
public class AdditionalFixesApplyTask implements LauncherBuildTask { public class AdditionalFixesApplyTask implements LauncherBuildTask {
private final LaunchServer server; private final LaunchServer server;

View file

@ -1,5 +1,9 @@
package ru.gravit.launchserver.binary.tasks; package ru.gravit.launchserver.binary.tasks;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
@ -8,10 +12,6 @@
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
public class AttachJarsTask implements LauncherBuildTask { public class AttachJarsTask implements LauncherBuildTask {
private final LaunchServer srv; private final LaunchServer srv;
private final List<Path> jars; private final List<Path> jars;

View file

@ -5,6 +5,8 @@
public interface LauncherBuildTask { public interface LauncherBuildTask {
String getName(); String getName();
Path process(Path inputFile) throws IOException; Path process(Path inputFile) throws IOException;
boolean allowDelete(); boolean allowDelete();
} }

View file

@ -1,21 +1,5 @@
package ru.gravit.launchserver.binary.tasks; package ru.gravit.launchserver.binary.tasks;
import static ru.gravit.utils.helper.IOHelper.newZipEntry;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import javassist.CannotCompileException; import javassist.CannotCompileException;
import javassist.NotFoundException; import javassist.NotFoundException;
import ru.gravit.launcher.AutogenConfig; import ru.gravit.launcher.AutogenConfig;
@ -30,9 +14,26 @@
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import static ru.gravit.utils.helper.IOHelper.newZipEntry;
public class MainBuildTask implements LauncherBuildTask { public class MainBuildTask implements LauncherBuildTask {
private final LaunchServer server; private final LaunchServer server;
public final ClassMetadataReader reader; public final ClassMetadataReader reader;
private final class RuntimeDirVisitor extends SimpleFileVisitor<Path> { private final class RuntimeDirVisitor extends SimpleFileVisitor<Path> {
private final ZipOutputStream output; private final ZipOutputStream output;
private final Map<String, byte[]> runtime; private final Map<String, byte[]> runtime;

View file

@ -19,7 +19,7 @@ public class PrepareBuildTask implements LauncherBuildTask {
public PrepareBuildTask(LaunchServer server) { public PrepareBuildTask(LaunchServer server) {
this.server = server; this.server = server;
result = server.launcherBinary.buildDir.resolve(server.config.binaryName + "-clean.jar"); result = server.launcherBinary.buildDir.resolve("Launcher-clean.jar");
} }
@Override @Override

View file

@ -1,8 +1,5 @@
package ru.gravit.launchserver.binary.tasks; package ru.gravit.launchserver.binary.tasks;
import java.io.IOException;
import java.nio.file.Path;
import proguard.Configuration; import proguard.Configuration;
import proguard.ConfigurationParser; import proguard.ConfigurationParser;
import proguard.ParseException; import proguard.ParseException;
@ -11,6 +8,9 @@
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.io.IOException;
import java.nio.file.Path;
public class ProGuardBuildTask implements LauncherBuildTask { public class ProGuardBuildTask implements LauncherBuildTask {
private final LaunchServer server; private final LaunchServer server;

View file

@ -8,22 +8,14 @@
public final class TaskUtil { public final class TaskUtil {
public static void addCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) { public static void addCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
List<LauncherBuildTask> indexes = new ArrayList<>(); List<LauncherBuildTask> indexes = new ArrayList<>();
tasks.stream().filter(pred).forEach(e -> { tasks.stream().filter(pred).forEach(e -> indexes.add(e));
indexes.add(e); indexes.forEach(e -> tasks.add(tasks.indexOf(e) + count, taskAdd));
});
indexes.forEach(e -> {
tasks.add(tasks.indexOf(e)+count, taskAdd);
});
} }
public static void replaceCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) { public static void replaceCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
List<LauncherBuildTask> indexes = new ArrayList<>(); List<LauncherBuildTask> indexes = new ArrayList<>();
tasks.stream().filter(pred).forEach(e -> { tasks.stream().filter(pred).forEach(e -> indexes.add(e));
indexes.add(e); indexes.forEach(e -> tasks.set(tasks.indexOf(e) + count, taskRep));
});
indexes.forEach(e -> {
tasks.set(tasks.indexOf(e)+count, taskRep);
});
} }
public static void addPre(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) { public static void addPre(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {

View file

@ -1,10 +1,10 @@
package ru.gravit.launchserver.command; package ru.gravit.launchserver.command;
import java.util.UUID;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import java.util.UUID;
public abstract class Command { public abstract class Command {
protected static String parseUsername(String username) throws CommandException { protected static String parseUsername(String username) throws CommandException {

View file

@ -1,13 +1,13 @@
package ru.gravit.launchserver.command.auth; package ru.gravit.launchserver.command.auth;
import java.util.UUID;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.AuthProvider;
import ru.gravit.launchserver.auth.provider.AuthProviderResult; import ru.gravit.launchserver.auth.provider.AuthProviderResult;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.util.UUID;
public final class AuthCommand extends Command { public final class AuthCommand extends Command {
public AuthCommand(LaunchServer server) { public AuthCommand(LaunchServer server) {
super(server); super(server);

View file

@ -1,11 +1,11 @@
package ru.gravit.launchserver.command.auth; package ru.gravit.launchserver.command.auth;
import java.util.List;
import ru.gravit.launcher.HWID; import ru.gravit.launcher.HWID;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import java.util.List;
public class BanCommand extends Command { public class BanCommand extends Command {
public BanCommand(LaunchServer server) { public BanCommand(LaunchServer server) {
super(server); super(server);

View file

@ -1,13 +1,13 @@
package ru.gravit.launchserver.command.auth; package ru.gravit.launchserver.command.auth;
import java.io.IOException;
import java.util.UUID;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.command.CommandException; import ru.gravit.launchserver.command.CommandException;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.io.IOException;
import java.util.UUID;
public final class UUIDToUsernameCommand extends Command { public final class UUIDToUsernameCommand extends Command {
public UUIDToUsernameCommand(LaunchServer server) { public UUIDToUsernameCommand(LaunchServer server) {
super(server); super(server);

View file

@ -1,11 +1,11 @@
package ru.gravit.launchserver.command.auth; package ru.gravit.launchserver.command.auth;
import java.util.List;
import ru.gravit.launcher.HWID; import ru.gravit.launcher.HWID;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import java.util.List;
public class UnbanCommand extends Command { public class UnbanCommand extends Command {
public UnbanCommand(LaunchServer server) { public UnbanCommand(LaunchServer server) {
super(server); super(server);

View file

@ -1,13 +1,13 @@
package ru.gravit.launchserver.command.auth; package ru.gravit.launchserver.command.auth;
import java.io.IOException;
import java.util.UUID;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.command.CommandException; import ru.gravit.launchserver.command.CommandException;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.io.IOException;
import java.util.UUID;
public final class UsernameToUUIDCommand extends Command { public final class UsernameToUUIDCommand extends Command {
public UsernameToUUIDCommand(LaunchServer server) { public UsernameToUUIDCommand(LaunchServer server) {
super(server); super(server);

View file

@ -28,8 +28,7 @@ public void invoke(String... args) {
else newTraceValue = newValue; else newTraceValue = newValue;
LogHelper.setDebugEnabled(newValue); LogHelper.setDebugEnabled(newValue);
LogHelper.setStacktraceEnabled(newTraceValue); LogHelper.setStacktraceEnabled(newTraceValue);
} else } else {
{
newValue = LogHelper.isDebugEnabled(); newValue = LogHelper.isDebugEnabled();
newTraceValue = LogHelper.isStacktraceEnabled(); newTraceValue = LogHelper.isStacktraceEnabled();
} }

View file

@ -1,12 +1,12 @@
package ru.gravit.launchserver.command.basic; package ru.gravit.launchserver.command.basic;
import java.util.Map.Entry;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.command.CommandException; import ru.gravit.launchserver.command.CommandException;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.util.Map.Entry;
public final class HelpCommand extends Command { public final class HelpCommand extends Command {
private static void printCommand(String name, Command command) { private static void printCommand(String name, Command command) {
String args = command.getArgsDescription(); String args = command.getArgsDescription();

View file

@ -1,11 +1,11 @@
package ru.gravit.launchserver.command.basic; package ru.gravit.launchserver.command.basic;
import java.io.IOException;
import java.nio.file.Files;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import java.io.IOException;
import java.nio.file.Files;
public class ProguardCleanCommand extends Command { public class ProguardCleanCommand extends Command {
public ProguardCleanCommand(LaunchServer server) { public ProguardCleanCommand(LaunchServer server) {
super(server); super(server);

View file

@ -1,10 +1,10 @@
package ru.gravit.launchserver.command.basic; package ru.gravit.launchserver.command.basic;
import java.io.IOException;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import java.io.IOException;
public class RegenProguardDictCommand extends Command { public class RegenProguardDictCommand extends Command {
public RegenProguardDictCommand(LaunchServer server) { public RegenProguardDictCommand(LaunchServer server) {

View file

@ -1,11 +1,11 @@
package ru.gravit.launchserver.command.basic; package ru.gravit.launchserver.command.basic;
import java.io.IOException;
import java.nio.file.Files;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import java.io.IOException;
import java.nio.file.Files;
public class RemoveMappingsProguardCommand extends Command { public class RemoveMappingsProguardCommand extends Command {
public RemoveMappingsProguardCommand(LaunchServer server) { public RemoveMappingsProguardCommand(LaunchServer server) {

View file

@ -1,20 +1,16 @@
package ru.gravit.launchserver.command.basic; package ru.gravit.launchserver.command.basic;
import java.io.Writer;
import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.socket.NettyServerSocketHandler; import ru.gravit.launchserver.socket.NettyServerSocketHandler;
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.IOHelper;
public class TestCommand extends Command { public class TestCommand extends Command {
public TestCommand(LaunchServer server) { public TestCommand(LaunchServer server) {
super(server); super(server);
} }
NettyServerSocketHandler handler; private NettyServerSocketHandler handler = null;
@Override @Override
public String getArgsDescription() { public String getArgsDescription() {
@ -33,15 +29,6 @@ public void invoke(String... args) throws Exception {
handler = new NettyServerSocketHandler(server); handler = new NettyServerSocketHandler(server);
if (args[0].equals("start")) { if (args[0].equals("start")) {
CommonHelper.newThread("Netty Server", true, handler).start(); 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);
}
} }
if (args[0].equals("stop")) { if (args[0].equals("stop")) {
handler.close(); handler.close();

View file

@ -1,17 +1,17 @@
package ru.gravit.launchserver.command.dump; package ru.gravit.launchserver.command.dump;
import java.io.Reader;
import java.io.Writer;
import java.nio.file.Paths;
import java.util.Map;
import java.util.UUID;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.auth.handler.CachedAuthHandler; import ru.gravit.launchserver.auth.handler.CachedAuthHandler;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.io.Reader;
import java.io.Writer;
import java.nio.file.Paths;
import java.util.Map;
import java.util.UUID;
public class DumpEntryCacheCommand extends Command { public class DumpEntryCacheCommand extends Command {
public DumpEntryCacheCommand(LaunchServer server) { public DumpEntryCacheCommand(LaunchServer server) {
super(server); super(server);
@ -30,28 +30,25 @@ public String getUsageDescription() {
@Override @Override
public void invoke(String... args) throws Exception { public void invoke(String... args) throws Exception {
verifyArgs(args, 2); verifyArgs(args, 2);
if(!(server.config.authHandler instanceof CachedAuthHandler)) throw new UnsupportedOperationException("This command used only CachedAuthHandler"); if (!(server.config.authHandler instanceof CachedAuthHandler))
throw new UnsupportedOperationException("This command used only CachedAuthHandler");
CachedAuthHandler authHandler = (CachedAuthHandler) server.config.authHandler; CachedAuthHandler authHandler = (CachedAuthHandler) server.config.authHandler;
if(args[0].equals("unload")) if (args[0].equals("unload")) {
{
LogHelper.info("CachedAuthHandler write to %s", args[1]); LogHelper.info("CachedAuthHandler write to %s", args[1]);
Map<UUID, CachedAuthHandler.Entry> entryCache = authHandler.getEntryCache(); Map<UUID, CachedAuthHandler.Entry> entryCache = authHandler.getEntryCache();
Map<String, UUID> usernamesCache = authHandler.getUsernamesCache(); Map<String, UUID> usernamesCache = authHandler.getUsernamesCache();
EntryAndUsername serializable = new EntryAndUsername(); EntryAndUsername serializable = new EntryAndUsername();
serializable.entryCache = entryCache; serializable.entryCache = entryCache;
serializable.usernameCache = usernamesCache; serializable.usernameCache = usernamesCache;
try(Writer writer = IOHelper.newWriter(Paths.get(args[1]))) try (Writer writer = IOHelper.newWriter(Paths.get(args[1]))) {
{
LaunchServer.gson.toJson(serializable, writer); LaunchServer.gson.toJson(serializable, writer);
} }
LogHelper.subInfo("Write %d entryCache, %d usernameCache", entryCache.size(), usernamesCache.size()); LogHelper.subInfo("Write %d entryCache, %d usernameCache", entryCache.size(), usernamesCache.size());
} else if(args[0].equals("load")) } else if (args[0].equals("load")) {
{
LogHelper.info("CachedAuthHandler read from %s", args[1]); LogHelper.info("CachedAuthHandler read from %s", args[1]);
int size_entry = 0; int size_entry = 0;
int size_username = 0; int size_username = 0;
try(Reader reader = IOHelper.newReader(Paths.get(args[1]))) try (Reader reader = IOHelper.newReader(Paths.get(args[1]))) {
{
EntryAndUsername entryAndUsername = LaunchServer.gson.fromJson(reader, EntryAndUsername.class); EntryAndUsername entryAndUsername = LaunchServer.gson.fromJson(reader, EntryAndUsername.class);
size_entry = entryAndUsername.entryCache.size(); size_entry = entryAndUsername.entryCache.size();
size_username = entryAndUsername.usernameCache.size(); size_username = entryAndUsername.usernameCache.size();
@ -63,8 +60,7 @@ public void invoke(String... args) throws Exception {
} }
} }
public class EntryAndUsername public class EntryAndUsername {
{
public Map<UUID, CachedAuthHandler.Entry> entryCache; public Map<UUID, CachedAuthHandler.Entry> entryCache;
public Map<String, UUID> usernameCache; public Map<String, UUID> usernameCache;
} }

View file

@ -1,5 +1,12 @@
package ru.gravit.launchserver.command.dump; package ru.gravit.launchserver.command.dump;
import com.google.gson.reflect.TypeToken;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.socket.Client;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -7,14 +14,6 @@
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import com.google.gson.reflect.TypeToken;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.socket.Client;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
public class DumpSessionsCommand extends Command { public class DumpSessionsCommand extends Command {
public DumpSessionsCommand(LaunchServer server) { public DumpSessionsCommand(LaunchServer server) {
super(server); super(server);
@ -33,22 +32,19 @@ public String getUsageDescription() {
@Override @Override
public void invoke(String... args) throws Exception { public void invoke(String... args) throws Exception {
verifyArgs(args, 2); verifyArgs(args, 2);
if(args[0].equals("unload")) if (args[0].equals("unload")) {
{
LogHelper.info("Sessions write to %s", args[1]); LogHelper.info("Sessions write to %s", args[1]);
Set<Client> clientSet = server.sessionManager.getSessions(); Set<Client> clientSet = server.sessionManager.getSessions();
try(Writer writer = IOHelper.newWriter(Paths.get(args[1]))) try (Writer writer = IOHelper.newWriter(Paths.get(args[1]))) {
{
LaunchServer.gson.toJson(clientSet, writer); LaunchServer.gson.toJson(clientSet, writer);
} }
LogHelper.subInfo("Write %d sessions", clientSet.size()); LogHelper.subInfo("Write %d sessions", clientSet.size());
} else if(args[0].equals("load")) } else if (args[0].equals("load")) {
{
LogHelper.info("Sessions read from %s", args[1]); LogHelper.info("Sessions read from %s", args[1]);
int size = 0; int size = 0;
try(Reader reader = IOHelper.newReader(Paths.get(args[1]))) try (Reader reader = IOHelper.newReader(Paths.get(args[1]))) {
{ Type setType = new TypeToken<HashSet<Client>>() {
Type setType = new TypeToken<HashSet<Client>>(){}.getType(); }.getType();
Set<Client> clientSet = LaunchServer.gson.fromJson(reader, setType); Set<Client> clientSet = LaunchServer.gson.fromJson(reader, setType);
size = clientSet.size(); size = clientSet.size();
server.sessionManager.loadSessions(clientSet); server.sessionManager.loadSessions(clientSet);

View file

@ -1,53 +1,25 @@
package ru.gravit.launchserver.command.handler; package ru.gravit.launchserver.command.handler;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.command.CommandException; import ru.gravit.launchserver.command.CommandException;
import ru.gravit.launchserver.command.auth.AuthCommand; import ru.gravit.launchserver.command.auth.*;
import ru.gravit.launchserver.command.auth.BanCommand; import ru.gravit.launchserver.command.basic.*;
import ru.gravit.launchserver.command.auth.UUIDToUsernameCommand;
import ru.gravit.launchserver.command.auth.UnbanCommand;
import ru.gravit.launchserver.command.auth.UsernameToUUIDCommand;
import ru.gravit.launchserver.command.basic.BuildCommand;
import ru.gravit.launchserver.command.basic.ClearCommand;
import ru.gravit.launchserver.command.basic.DebugCommand;
import ru.gravit.launchserver.command.basic.GCCommand;
import ru.gravit.launchserver.command.basic.HelpCommand;
import ru.gravit.launchserver.command.basic.LogConnectionsCommand;
import ru.gravit.launchserver.command.basic.ProguardCleanCommand;
import ru.gravit.launchserver.command.basic.RebindCommand;
import ru.gravit.launchserver.command.basic.RegenProguardDictCommand;
import ru.gravit.launchserver.command.basic.RemoveMappingsProguardCommand;
import ru.gravit.launchserver.command.basic.RestartCommand;
import ru.gravit.launchserver.command.basic.StopCommand;
import ru.gravit.launchserver.command.basic.TestCommand;
import ru.gravit.launchserver.command.basic.VersionCommand;
import ru.gravit.launchserver.command.dump.DumpEntryCacheCommand; import ru.gravit.launchserver.command.dump.DumpEntryCacheCommand;
import ru.gravit.launchserver.command.dump.DumpSessionsCommand; import ru.gravit.launchserver.command.dump.DumpSessionsCommand;
import ru.gravit.launchserver.command.hash.DownloadAssetCommand; import ru.gravit.launchserver.command.hash.*;
import ru.gravit.launchserver.command.hash.DownloadClientCommand;
import ru.gravit.launchserver.command.hash.IndexAssetCommand;
import ru.gravit.launchserver.command.hash.SyncBinariesCommand;
import ru.gravit.launchserver.command.hash.SyncProfilesCommand;
import ru.gravit.launchserver.command.hash.SyncUpdatesCommand;
import ru.gravit.launchserver.command.hash.UnindexAssetCommand;
import ru.gravit.launchserver.command.modules.LoadModuleCommand; import ru.gravit.launchserver.command.modules.LoadModuleCommand;
import ru.gravit.launchserver.command.modules.ModulesCommand; import ru.gravit.launchserver.command.modules.ModulesCommand;
import ru.gravit.launchserver.command.service.*; import ru.gravit.launchserver.command.service.*;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public abstract class CommandHandler implements Runnable { public abstract class CommandHandler implements Runnable {
private static String[] parse(CharSequence line) throws CommandException { private static String[] parse(CharSequence line) throws CommandException {
boolean quoted = false; boolean quoted = false;

View file

@ -1,12 +1,12 @@
package ru.gravit.launchserver.command.handler; package ru.gravit.launchserver.command.handler;
import java.io.IOException;
import jline.console.ConsoleReader; import jline.console.ConsoleReader;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.LogHelper.Output; import ru.gravit.utils.helper.LogHelper.Output;
import java.io.IOException;
public final class JLineCommandHandler extends CommandHandler { public final class JLineCommandHandler extends CommandHandler {
private final class JLineOutput implements Output { private final class JLineOutput implements Output {
@Override @Override

View file

@ -1,11 +1,11 @@
package ru.gravit.launchserver.command.handler; package ru.gravit.launchserver.command.handler;
import java.io.BufferedReader;
import java.io.IOException;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import java.io.BufferedReader;
import java.io.IOException;
public final class StdCommandHandler extends CommandHandler { public final class StdCommandHandler extends CommandHandler {
private final BufferedReader reader; private final BufferedReader reader;
@ -16,7 +16,6 @@ public StdCommandHandler(LaunchServer server, boolean readCommands) {
@Override @Override
public void bell() { public void bell() {
// Do nothing, unsupported
} }
@Override @Override

View file

@ -1,9 +1,5 @@
package ru.gravit.launchserver.command.hash; package ru.gravit.launchserver.command.hash;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import ru.gravit.launcher.profiles.ClientProfile.Version; import ru.gravit.launcher.profiles.ClientProfile.Version;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
@ -11,6 +7,10 @@
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
public final class DownloadAssetCommand extends Command { public final class DownloadAssetCommand extends Command {
public DownloadAssetCommand(LaunchServer server) { public DownloadAssetCommand(LaunchServer server) {

View file

@ -1,12 +1,5 @@
package ru.gravit.launchserver.command.hash; package ru.gravit.launchserver.command.hash;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.profiles.ClientProfile.Version; import ru.gravit.launcher.profiles.ClientProfile.Version;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
@ -16,6 +9,13 @@
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
public final class DownloadClientCommand extends Command { public final class DownloadClientCommand extends Command {
public DownloadClientCommand(LaunchServer server) { public DownloadClientCommand(LaunchServer server) {

View file

@ -1,5 +1,15 @@
package ru.gravit.launchserver.command.hash; package ru.gravit.launchserver.command.hash;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.command.CommandException;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.SecurityHelper;
import ru.gravit.utils.helper.SecurityHelper.DigestAlgorithm;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.IOException; import java.io.IOException;
import java.nio.file.FileVisitResult; import java.nio.file.FileVisitResult;
@ -9,17 +19,6 @@
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.Collections; import java.util.Collections;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.command.CommandException;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.SecurityHelper;
import ru.gravit.utils.helper.SecurityHelper.DigestAlgorithm;
public final class IndexAssetCommand extends Command { public final class IndexAssetCommand extends Command {
private static Gson gson = new Gson(); private static Gson gson = new Gson();

View file

@ -1,11 +1,11 @@
package ru.gravit.launchserver.command.hash; package ru.gravit.launchserver.command.hash;
import java.io.IOException;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.io.IOException;
public final class SyncBinariesCommand extends Command { public final class SyncBinariesCommand extends Command {
public SyncBinariesCommand(LaunchServer server) { public SyncBinariesCommand(LaunchServer server) {
super(server); super(server);

View file

@ -1,11 +1,11 @@
package ru.gravit.launchserver.command.hash; package ru.gravit.launchserver.command.hash;
import java.io.IOException;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.io.IOException;
public final class SyncProfilesCommand extends Command { public final class SyncProfilesCommand extends Command {
public SyncProfilesCommand(LaunchServer server) { public SyncProfilesCommand(LaunchServer server) {
super(server); super(server);

View file

@ -1,14 +1,14 @@
package ru.gravit.launchserver.command.hash; package ru.gravit.launchserver.command.hash;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command;
import ru.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command;
import ru.gravit.utils.helper.LogHelper;
public final class SyncUpdatesCommand extends Command { public final class SyncUpdatesCommand extends Command {
public SyncUpdatesCommand(LaunchServer server) { public SyncUpdatesCommand(LaunchServer server) {
super(server); super(server);

View file

@ -1,21 +1,20 @@
package ru.gravit.launchserver.command.hash; package ru.gravit.launchserver.command.hash;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.command.CommandException;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.command.CommandException;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
public final class UnindexAssetCommand extends Command { public final class UnindexAssetCommand extends Command {
private static JsonParser parser = new JsonParser(); private static JsonParser parser = new JsonParser();

View file

@ -1,11 +1,11 @@
package ru.gravit.launchserver.command.modules; package ru.gravit.launchserver.command.modules;
import java.net.URI;
import java.nio.file.Paths;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import java.net.URI;
import java.nio.file.Paths;
public class LoadModuleCommand extends Command { public class LoadModuleCommand extends Command {
public LoadModuleCommand(LaunchServer server) { public LoadModuleCommand(LaunchServer server) {
super(server); super(server);

View file

@ -19,7 +19,7 @@ public String getUsageDescription() {
} }
@Override @Override
public void invoke(String... args) throws Exception { public void invoke(String... args) {
server.reconfigurableManager.printReconfigurables(); server.reconfigurableManager.printReconfigurables();
} }
} }

View file

@ -19,7 +19,7 @@ public String getUsageDescription() {
} }
@Override @Override
public void invoke(String... args) throws Exception { public void invoke(String... args) {
server.reloadManager.printReloadables(); server.reloadManager.printReloadables();
} }
} }

View file

@ -22,7 +22,7 @@ public String getUsageDescription() {
} }
@Override @Override
public void invoke(String... args) throws Exception { public void invoke(String... args) {
LogHelper.info("Show server status"); LogHelper.info("Show server status");
LogHelper.info("Memory: free %d | total: %d | max: %d", JVMHelper.RUNTIME.freeMemory(), JVMHelper.RUNTIME.totalMemory(), JVMHelper.RUNTIME.maxMemory()); LogHelper.info("Memory: free %d | total: %d | max: %d", JVMHelper.RUNTIME.freeMemory(), JVMHelper.RUNTIME.totalMemory(), JVMHelper.RUNTIME.maxMemory());
long uptime = JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000; long uptime = JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000;
@ -33,8 +33,7 @@ public void invoke(String... args) throws Exception {
LogHelper.info("Uptime: %d days %d hours %d minutes %d seconds", days, hour, min, second); LogHelper.info("Uptime: %d days %d hours %d minutes %d seconds", days, hour, min, second);
LogHelper.info("Uptime (double): %f", (double) JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000); LogHelper.info("Uptime (double): %f", (double) JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000);
LogHelper.info("Sessions: %d | Modules: %d | Commands: %d", server.sessionManager.getSessions().size(), server.modulesManager.modules.size(), server.commandHandler.commandsMap().size()); LogHelper.info("Sessions: %d | Modules: %d | Commands: %d", server.sessionManager.getSessions().size(), server.modulesManager.modules.size(), server.commandHandler.commandsMap().size());
if(server.config.authHandler instanceof CachedAuthHandler) if (server.config.authHandler instanceof CachedAuthHandler) {
{
LogHelper.info("AuthHandler: EntryCache: %d | usernameCache: %d", ((CachedAuthHandler) server.config.authHandler).getEntryCache().size(), ((CachedAuthHandler) server.config.authHandler).getUsernamesCache().size()); LogHelper.info("AuthHandler: EntryCache: %d | usernameCache: %d", ((CachedAuthHandler) server.config.authHandler).getEntryCache().size(), ((CachedAuthHandler) server.config.authHandler).getUsernamesCache().size());
} }
} }

View file

@ -9,6 +9,7 @@
public class SwapAuthProviderCommand extends Command { public class SwapAuthProviderCommand extends Command {
public AuthProvider[] providersCache; public AuthProvider[] providersCache;
public SwapAuthProviderCommand(LaunchServer server) { public SwapAuthProviderCommand(LaunchServer server) {
super(server); super(server);
} }
@ -29,38 +30,34 @@ public void invoke(String... args) throws Exception {
verifyArgs(args, 2); verifyArgs(args, 2);
if (providersCache == null) providersCache = new AuthProvider[server.config.authProvider.length]; if (providersCache == null) providersCache = new AuthProvider[server.config.authProvider.length];
int index = Integer.valueOf(args[0]); int index = Integer.valueOf(args[0]);
if(args[1].equals("accept")) switch (args[1]) {
{ case "accept":
if(providersCache[index] == null) if (providersCache[index] == null) {
{
AcceptAuthProvider provider = new AcceptAuthProvider(); AcceptAuthProvider provider = new AcceptAuthProvider();
providersCache[index] = server.config.authProvider[index]; providersCache[index] = server.config.authProvider[index];
server.config.authProvider[index] = provider; server.config.authProvider[index] = provider;
LogHelper.info("AuthProvider[%d] is AcceptAuthProvider", index); LogHelper.info("AuthProvider[%d] is AcceptAuthProvider", index);
} } else LogHelper.error("Changes detected. Use undo");
else LogHelper.error("Changes detected. Use undo"); break;
} else if(args[1].equals("reject")) case "reject":
{ if (providersCache[index] == null) {
if(providersCache[index] == null)
{
RejectAuthProvider rejectAuthProvider; RejectAuthProvider rejectAuthProvider;
if (args.length < 3) rejectAuthProvider = new RejectAuthProvider(); if (args.length < 3) rejectAuthProvider = new RejectAuthProvider();
else rejectAuthProvider = new RejectAuthProvider(args[2]); else rejectAuthProvider = new RejectAuthProvider(args[2]);
providersCache[index] = server.config.authProvider[index]; providersCache[index] = server.config.authProvider[index];
server.config.authProvider[index] = rejectAuthProvider; server.config.authProvider[index] = rejectAuthProvider;
LogHelper.info("AuthProvider[%d] is RejectAuthProvider", index); LogHelper.info("AuthProvider[%d] is RejectAuthProvider", index);
} } else LogHelper.error("Changes detected. Use undo");
else LogHelper.error("Changes detected. Use undo"); break;
} else if(args[1].equals("undo")) case "undo":
{
if (providersCache[index] == null) LogHelper.error("Cache clean. Undo impossible"); if (providersCache[index] == null) LogHelper.error("Cache clean. Undo impossible");
else else {
{
server.config.authProvider[index].close(); server.config.authProvider[index].close();
server.config.authProvider[index] = providersCache[index]; server.config.authProvider[index] = providersCache[index];
providersCache[index] = null; providersCache[index] = null;
} }
break;
} }
} }
} }

View file

@ -1,20 +1,13 @@
package ru.gravit.launchserver.config; package ru.gravit.launchserver.config;
import com.google.gson.*;
import ru.gravit.launchserver.auth.handler.AuthHandler;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import ru.gravit.launchserver.auth.handler.AuthHandler;
public class AuthHandlerAdapter implements JsonSerializer<AuthHandler>, JsonDeserializer<AuthHandler> { public class AuthHandlerAdapter implements JsonSerializer<AuthHandler>, JsonDeserializer<AuthHandler> {
private static final String PROP_NAME = "type"; private static final String PROP_NAME = "type";
@Override @Override
public AuthHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { public AuthHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();

View file

@ -1,20 +1,13 @@
package ru.gravit.launchserver.config; package ru.gravit.launchserver.config;
import com.google.gson.*;
import ru.gravit.launchserver.auth.provider.AuthProvider;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import ru.gravit.launchserver.auth.provider.AuthProvider;
public class AuthProviderAdapter implements JsonSerializer<AuthProvider>, JsonDeserializer<AuthProvider> { public class AuthProviderAdapter implements JsonSerializer<AuthProvider>, JsonDeserializer<AuthProvider> {
private static final String PROP_NAME = "type"; private static final String PROP_NAME = "type";
@Override @Override
public AuthProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { public AuthProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();

View file

@ -1,20 +1,13 @@
package ru.gravit.launchserver.config; package ru.gravit.launchserver.config;
import com.google.gson.*;
import ru.gravit.launchserver.auth.hwid.HWIDHandler;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import ru.gravit.launchserver.auth.hwid.HWIDHandler;
public class HWIDHandlerAdapter implements JsonSerializer<HWIDHandler>, JsonDeserializer<HWIDHandler> { public class HWIDHandlerAdapter implements JsonSerializer<HWIDHandler>, JsonDeserializer<HWIDHandler> {
private static final String PROP_NAME = "type"; private static final String PROP_NAME = "type";
@Override @Override
public HWIDHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { public HWIDHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();

View file

@ -1,20 +1,13 @@
package ru.gravit.launchserver.config; package ru.gravit.launchserver.config;
import com.google.gson.*;
import ru.gravit.launchserver.auth.permissions.PermissionsHandler;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import ru.gravit.launchserver.auth.permissions.PermissionsHandler;
public class PermissionsHandlerAdapter implements JsonSerializer<PermissionsHandler>, JsonDeserializer<PermissionsHandler> { public class PermissionsHandlerAdapter implements JsonSerializer<PermissionsHandler>, JsonDeserializer<PermissionsHandler> {
private static final String PROP_NAME = "type"; private static final String PROP_NAME = "type";
@Override @Override
public PermissionsHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { public PermissionsHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();

View file

@ -1,20 +1,13 @@
package ru.gravit.launchserver.config; package ru.gravit.launchserver.config;
import com.google.gson.*;
import ru.gravit.launchserver.texture.TextureProvider;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import ru.gravit.launchserver.texture.TextureProvider;
public class TextureProviderAdapter implements JsonSerializer<TextureProvider>, JsonDeserializer<TextureProvider> { public class TextureProviderAdapter implements JsonSerializer<TextureProvider>, JsonDeserializer<TextureProvider> {
private static final String PROP_NAME = "type"; private static final String PROP_NAME = "type";
@Override @Override
public TextureProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { public TextureProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();

View file

@ -1,11 +1,11 @@
package ru.gravit.launchserver.fileserver; package ru.gravit.launchserver.fileserver;
import java.io.Closeable;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import java.io.Closeable;
public class ClosingChannelFutureListener implements ChannelFutureListener { public class ClosingChannelFutureListener implements ChannelFutureListener {
public final Closeable[] close; public final Closeable[] close;

View file

@ -1,16 +1,14 @@
package ru.gravit.launchserver.fileserver; package ru.gravit.launchserver.fileserver;
import static io.netty.handler.codec.http.HttpMethod.GET; import io.netty.buffer.ByteBuf;
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST; import io.netty.buffer.Unpooled;
import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN; import io.netty.channel.*;
import static io.netty.handler.codec.http.HttpResponseStatus.FOUND; import io.netty.handler.codec.http.*;
import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR; import io.netty.handler.ssl.SslHandler;
import static io.netty.handler.codec.http.HttpResponseStatus.METHOD_NOT_ALLOWED; import io.netty.handler.stream.ChunkedFile;
import static io.netty.handler.codec.http.HttpResponseStatus.NOT_FOUND; import io.netty.util.CharsetUtil;
import static io.netty.handler.codec.http.HttpResponseStatus.NOT_MODIFIED;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
import javax.activation.MimetypesFileTypeMap;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
@ -18,38 +16,12 @@
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.file.Path; import java.nio.file.Path;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.*;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.activation.MimetypesFileTypeMap; import static io.netty.handler.codec.http.HttpMethod.GET;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import io.netty.buffer.ByteBuf; import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelProgressiveFuture;
import io.netty.channel.ChannelProgressiveFutureListener;
import io.netty.channel.DefaultFileRegion;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.DefaultHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpChunkedInput;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpUtil;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.handler.ssl.SslHandler;
import io.netty.handler.stream.ChunkedFile;
import io.netty.util.CharsetUtil;
public class FileServerHandler extends SimpleChannelInboundHandler<FullHttpRequest> { public class FileServerHandler extends SimpleChannelInboundHandler<FullHttpRequest> {

View file

@ -1,11 +1,11 @@
package ru.gravit.launchserver.manangers; package ru.gravit.launchserver.manangers;
import ru.gravit.utils.helper.IOHelper;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import ru.gravit.utils.helper.IOHelper;
public class MirrorManager { public class MirrorManager {
public class Mirror { public class Mirror {
URL url; URL url;
@ -34,7 +34,7 @@ public URL getClientsURL(String client) throws MalformedURLException {
protected ArrayList<Mirror> list = new ArrayList<>(); protected ArrayList<Mirror> list = new ArrayList<>();
private Mirror defaultMirror; private Mirror defaultMirror;
public void addMirror(String mirror) throws MalformedURLException { public void addMirror(String mirror) {
Mirror m = new Mirror(mirror); Mirror m = new Mirror(mirror);
m.enabled = true; m.enabled = true;
if (defaultMirror == null) defaultMirror = m; if (defaultMirror == null) defaultMirror = m;

View file

@ -1,20 +1,21 @@
package ru.gravit.launchserver.manangers; package ru.gravit.launchserver.manangers;
import java.net.URL; import ru.gravit.launcher.managers.SimpleModulesConfigManager;
import java.util.ArrayList;
import ru.gravit.launcher.managers.ModulesConfigManager;
import ru.gravit.launcher.managers.SimpleModuleManager; import ru.gravit.launcher.managers.SimpleModuleManager;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.modules.CoreModule; import ru.gravit.launchserver.modules.CoreModule;
import ru.gravit.launchserver.modules.LaunchServerModuleContext; import ru.gravit.launchserver.modules.LaunchServerModuleContext;
import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.PublicURLClassLoader;
import java.net.URL;
import java.util.ArrayList;
public class ModulesManager extends SimpleModuleManager { public class ModulesManager extends SimpleModuleManager {
public ModulesConfigManager configManager; public SimpleModulesConfigManager configManager;
public ModulesManager(LaunchServer lsrv) { public ModulesManager(LaunchServer lsrv) {
modules = new ArrayList<>(1); modules = new ArrayList<>(1);
configManager = new ModulesConfigManager(lsrv.dir.resolve("config")); configManager = new SimpleModulesConfigManager(lsrv.dir.resolve("config"));
classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader()); classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader());
context = new LaunchServerModuleContext(lsrv, classloader, configManager); context = new LaunchServerModuleContext(lsrv, classloader, configManager);
registerCoreModule(); registerCoreModule();

View file

@ -1,29 +1,30 @@
package ru.gravit.launchserver.manangers; package ru.gravit.launchserver.manangers;
import java.util.HashMap;
import java.util.Objects;
import ru.gravit.launchserver.Reconfigurable; import ru.gravit.launchserver.Reconfigurable;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import java.util.HashMap;
import java.util.Objects;
public class ReconfigurableManager { public class ReconfigurableManager {
private final HashMap<String, Reconfigurable> RECONFIGURABLE = new HashMap<>(); private final HashMap<String, Reconfigurable> RECONFIGURABLE = new HashMap<>();
public void registerReconfigurable(String name, Reconfigurable reconfigurable)
{ public void registerReconfigurable(String name, Reconfigurable reconfigurable) {
VerifyHelper.verifyIDName(name); VerifyHelper.verifyIDName(name);
VerifyHelper.putIfAbsent(RECONFIGURABLE, name, Objects.requireNonNull(reconfigurable, "adapter"), VerifyHelper.putIfAbsent(RECONFIGURABLE, name, Objects.requireNonNull(reconfigurable, "adapter"),
String.format("Reloadable has been already registered: '%s'", name)); String.format("Reloadable has been already registered: '%s'", name));
} }
public void printHelp(String name)
{ public void printHelp(String name) {
RECONFIGURABLE.get(name).printConfigHelp(); RECONFIGURABLE.get(name).printConfigHelp();
} }
public void call(String name, String action, String[] args) throws Exception {
public void call(String name, String action, String[] args) {
RECONFIGURABLE.get(name).reconfig(action, args); RECONFIGURABLE.get(name).reconfig(action, args);
} }
public void printReconfigurables()
{ public void printReconfigurables() {
LogHelper.info("Print reconfigurables"); LogHelper.info("Print reconfigurables");
RECONFIGURABLE.forEach((k, v) -> LogHelper.subInfo(k)); RECONFIGURABLE.forEach((k, v) -> LogHelper.subInfo(k));
LogHelper.info("Found %d reconfigurables", RECONFIGURABLE.size()); LogHelper.info("Found %d reconfigurables", RECONFIGURABLE.size());

View file

@ -1,22 +1,22 @@
package ru.gravit.launchserver.manangers; package ru.gravit.launchserver.manangers;
import java.util.HashMap;
import java.util.Objects;
import ru.gravit.launchserver.Reloadable; import ru.gravit.launchserver.Reloadable;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import java.util.HashMap;
import java.util.Objects;
public class ReloadManager { public class ReloadManager {
private final HashMap<String, Reloadable> RELOADABLES = new HashMap<>(); private final HashMap<String, Reloadable> RELOADABLES = new HashMap<>();
public void registerReloadable(String name,Reloadable reloadable)
{ public void registerReloadable(String name, Reloadable reloadable) {
VerifyHelper.verifyIDName(name); VerifyHelper.verifyIDName(name);
VerifyHelper.putIfAbsent(RELOADABLES, name, Objects.requireNonNull(reloadable, "adapter"), VerifyHelper.putIfAbsent(RELOADABLES, name, Objects.requireNonNull(reloadable, "adapter"),
String.format("Reloadable has been already registered: '%s'", name)); String.format("Reloadable has been already registered: '%s'", name));
} }
public void reloadAll()
{ public void reloadAll() {
RELOADABLES.forEach((k, v) -> { RELOADABLES.forEach((k, v) -> {
try { try {
v.reload(); v.reload();
@ -25,11 +25,12 @@ public void reloadAll()
} }
}); });
} }
public void reload(String name) throws Exception { public void reload(String name) throws Exception {
RELOADABLES.get(name).reload(); RELOADABLES.get(name).reload();
} }
public void printReloadables()
{ public void printReloadables() {
LogHelper.info("Print reloadables"); LogHelper.info("Print reloadables");
RELOADABLES.forEach((k, v) -> LogHelper.subInfo(k)); RELOADABLES.forEach((k, v) -> LogHelper.subInfo(k));
LogHelper.info("Found %d reloadables", RELOADABLES.size()); LogHelper.info("Found %d reloadables", RELOADABLES.size());

View file

@ -1,11 +1,11 @@
package ru.gravit.launchserver.manangers; package ru.gravit.launchserver.manangers;
import java.util.HashSet;
import java.util.Set;
import ru.gravit.launcher.NeedGarbageCollection; import ru.gravit.launcher.NeedGarbageCollection;
import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.Client;
import java.util.HashSet;
import java.util.Set;
public class SessionManager implements NeedGarbageCollection { public class SessionManager implements NeedGarbageCollection {
public static final long SESSION_TIMEOUT = 10 * 60 * 1000; // 10 минут public static final long SESSION_TIMEOUT = 10 * 60 * 1000; // 10 минут
@ -51,12 +51,12 @@ public void updateClient(long session) {
Client newClient = new Client(session); Client newClient = new Client(session);
clientSet.add(newClient); clientSet.add(newClient);
} }
public Set<Client> getSessions()
{ public Set<Client> getSessions() {
return clientSet; return clientSet;
} }
public void loadSessions(Set<Client> set)
{ public void loadSessions(Set<Client> set) {
clientSet.addAll(set); clientSet.addAll(set);
} }
} }

View file

@ -1,77 +1,73 @@
package ru.gravit.launchserver.manangers.hook; package ru.gravit.launchserver.manangers.hook;
import java.util.HashSet;
import java.util.Set;
import ru.gravit.launchserver.response.auth.AuthResponse; import ru.gravit.launchserver.response.auth.AuthResponse;
import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.Client;
import java.util.HashSet;
import java.util.Set;
public class AuthHookManager { public class AuthHookManager {
private Set<AuthPreHook> PRE_HOOKS = new HashSet<>(); private Set<AuthPreHook> PRE_HOOKS = new HashSet<>();
private Set<AuthPostHook> POST_HOOKS = new HashSet<>(); private Set<AuthPostHook> POST_HOOKS = new HashSet<>();
private Set<CheckServerHook> CHECKSERVER_HOOKS = new HashSet<>(); private Set<CheckServerHook> CHECKSERVER_HOOKS = new HashSet<>();
private Set<JoinServerHook> JOINSERVER_HOOKS = new HashSet<>(); private Set<JoinServerHook> JOINSERVER_HOOKS = new HashSet<>();
@FunctionalInterface @FunctionalInterface
public interface AuthPreHook public interface AuthPreHook {
{
void preAuthHook(AuthResponse.AuthContext context, Client client); void preAuthHook(AuthResponse.AuthContext context, Client client);
} }
@FunctionalInterface @FunctionalInterface
public interface AuthPostHook public interface AuthPostHook {
{
void postAuthHook(AuthResponse.AuthContext context, Client client); void postAuthHook(AuthResponse.AuthContext context, Client client);
} }
@FunctionalInterface @FunctionalInterface
public interface CheckServerHook public interface CheckServerHook {
{
void checkServerHook(String username, String serverID); void checkServerHook(String username, String serverID);
} }
@FunctionalInterface @FunctionalInterface
public interface JoinServerHook public interface JoinServerHook {
{
void joinServerHook(String username, String accessToken, String serverID); void joinServerHook(String username, String accessToken, String serverID);
} }
public void registerPostHook(AuthPostHook hook)
{ public void registerPostHook(AuthPostHook hook) {
POST_HOOKS.add(hook); POST_HOOKS.add(hook);
} }
public void registerJoinServerHook(JoinServerHook hook)
{ public void registerJoinServerHook(JoinServerHook hook) {
JOINSERVER_HOOKS.add(hook); JOINSERVER_HOOKS.add(hook);
} }
public void registerCheckServerHook(CheckServerHook hook)
{ public void registerCheckServerHook(CheckServerHook hook) {
CHECKSERVER_HOOKS.add(hook); CHECKSERVER_HOOKS.add(hook);
} }
public void registerPreHook(AuthPreHook hook)
{ public void registerPreHook(AuthPreHook hook) {
PRE_HOOKS.add(hook); PRE_HOOKS.add(hook);
} }
public void preHook(AuthResponse.AuthContext context, Client client)
{ public void preHook(AuthResponse.AuthContext context, Client client) {
for(AuthPreHook preHook : PRE_HOOKS) for (AuthPreHook preHook : PRE_HOOKS) {
{
preHook.preAuthHook(context, client); preHook.preAuthHook(context, client);
} }
} }
public void checkServerHook(String username, String serverID)
{ public void checkServerHook(String username, String serverID) {
for(CheckServerHook hook : CHECKSERVER_HOOKS) for (CheckServerHook hook : CHECKSERVER_HOOKS) {
{
hook.checkServerHook(username, serverID); hook.checkServerHook(username, serverID);
} }
} }
public void joinServerHook(String username, String accessToken, String serverID)
{ public void joinServerHook(String username, String accessToken, String serverID) {
for(JoinServerHook hook : JOINSERVER_HOOKS) for (JoinServerHook hook : JOINSERVER_HOOKS) {
{
hook.joinServerHook(username, accessToken, serverID); hook.joinServerHook(username, accessToken, serverID);
} }
} }
public void postHook(AuthResponse.AuthContext context, Client client)
{ public void postHook(AuthResponse.AuthContext context, Client client) {
for(AuthPostHook postHook : POST_HOOKS) for (AuthPostHook postHook : POST_HOOKS) {
{
postHook.postAuthHook(context, client); postHook.postAuthHook(context, client);
} }
} }

View file

@ -1,16 +1,15 @@
package ru.gravit.launchserver.manangers.hook; package ru.gravit.launchserver.manangers.hook;
import ru.gravit.launcher.AutogenConfig;
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.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; 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;
public class BuildHookManager { public class BuildHookManager {
@FunctionalInterface @FunctionalInterface
@ -41,7 +40,6 @@ public BuildHookManager() {
registerIgnoredClass("META-INF/DEPENDENCIES"); registerIgnoredClass("META-INF/DEPENDENCIES");
registerIgnoredClass("META-INF/LICENSE"); registerIgnoredClass("META-INF/LICENSE");
registerIgnoredClass("META-INF/NOTICE"); registerIgnoredClass("META-INF/NOTICE");
registerClientModuleClass(TestClientModule.class.getName());
} }
public void autoRegisterIgnoredClass(String clazz) { public void autoRegisterIgnoredClass(String clazz) {

View file

@ -1,88 +1,84 @@
package ru.gravit.launchserver.manangers.hook; package ru.gravit.launchserver.manangers.hook;
import ru.gravit.launcher.request.RequestException;
import ru.gravit.launchserver.socket.SocketContext;
import java.net.Socket; import java.net.Socket;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import ru.gravit.launcher.request.RequestException;
import ru.gravit.launchserver.socket.SocketContext;
public class SocketHookManager { public class SocketHookManager {
@FunctionalInterface @FunctionalInterface
public interface SocketPreHook public interface SocketPreHook {
{
boolean preHook(SocketContext context); //Вернуть true если необходимо продолжть обработку, false если остановить обработку boolean preHook(SocketContext context); //Вернуть true если необходимо продолжть обработку, false если остановить обработку
} }
@FunctionalInterface @FunctionalInterface
public interface SocketPostHook public interface SocketPostHook {
{
void postHook(SocketContext context); void postHook(SocketContext context);
} }
@FunctionalInterface @FunctionalInterface
public interface SocketErrorHook public interface SocketErrorHook {
{
boolean errorHook(SocketContext context, RequestException e); //Вернуть true если необходимо продолжть обработку, false если остановить обработку boolean errorHook(SocketContext context, RequestException e); //Вернуть true если необходимо продолжть обработку, false если остановить обработку
} }
@FunctionalInterface @FunctionalInterface
public interface SocketFatalErrorHook public interface SocketFatalErrorHook {
{
boolean fatalErrorHook(Socket socket, Exception e); //Вернуть true если необходимо продолжть обработку, false если остановить обработку boolean fatalErrorHook(Socket socket, Exception e); //Вернуть true если необходимо продолжть обработку, false если остановить обработку
} }
private Set<SocketPostHook> POST_HOOKS; private Set<SocketPostHook> POST_HOOKS;
private Set<SocketPreHook> PRE_HOOKS; private Set<SocketPreHook> PRE_HOOKS;
private Set<SocketErrorHook> ERROR_HOOKS; private Set<SocketErrorHook> ERROR_HOOKS;
private Set<SocketFatalErrorHook> FATALERROR_HOOKS; private Set<SocketFatalErrorHook> FATALERROR_HOOKS;
public void registerPostHook(SocketPostHook hook)
{ public void registerPostHook(SocketPostHook hook) {
if (POST_HOOKS == null) POST_HOOKS = new HashSet<>(); if (POST_HOOKS == null) POST_HOOKS = new HashSet<>();
POST_HOOKS.add(hook); POST_HOOKS.add(hook);
} }
public void registerPreHook(SocketPreHook hook)
{ public void registerPreHook(SocketPreHook hook) {
if (PRE_HOOKS == null) PRE_HOOKS = new HashSet<>(); if (PRE_HOOKS == null) PRE_HOOKS = new HashSet<>();
PRE_HOOKS.add(hook); PRE_HOOKS.add(hook);
} }
public void registerErrorHook(SocketErrorHook hook)
{ public void registerErrorHook(SocketErrorHook hook) {
if (ERROR_HOOKS == null) ERROR_HOOKS = new HashSet<>(); if (ERROR_HOOKS == null) ERROR_HOOKS = new HashSet<>();
ERROR_HOOKS.add(hook); ERROR_HOOKS.add(hook);
} }
public void registerFatalErrorHook(SocketFatalErrorHook hook)
{ public void registerFatalErrorHook(SocketFatalErrorHook hook) {
if (FATALERROR_HOOKS == null) FATALERROR_HOOKS = new HashSet<>(); if (FATALERROR_HOOKS == null) FATALERROR_HOOKS = new HashSet<>();
FATALERROR_HOOKS.add(hook); FATALERROR_HOOKS.add(hook);
} }
public boolean preHook(SocketContext context)
{ public boolean preHook(SocketContext context) {
if (PRE_HOOKS == null) return true; if (PRE_HOOKS == null) return true;
for(SocketPreHook preHook : PRE_HOOKS) for (SocketPreHook preHook : PRE_HOOKS) {
{
if (!preHook.preHook(context)) return false; if (!preHook.preHook(context)) return false;
} }
return true; return true;
} }
public void postHook(SocketContext context)
{ public void postHook(SocketContext context) {
if (POST_HOOKS == null) return; if (POST_HOOKS == null) return;
for(SocketPostHook postHook : POST_HOOKS) for (SocketPostHook postHook : POST_HOOKS) {
{
postHook.postHook(context); postHook.postHook(context);
} }
} }
public boolean errorHook(SocketContext context, RequestException e)
{ public boolean errorHook(SocketContext context, RequestException e) {
if (ERROR_HOOKS == null) return true; if (ERROR_HOOKS == null) return true;
for(SocketErrorHook errorHook : ERROR_HOOKS) for (SocketErrorHook errorHook : ERROR_HOOKS) {
{
if (!errorHook.errorHook(context, e)) return false; if (!errorHook.errorHook(context, e)) return false;
} }
return true; return true;
} }
public boolean fatalErrorHook(Socket socket, Exception e)
{ public boolean fatalErrorHook(Socket socket, Exception e) {
if (FATALERROR_HOOKS == null) return true; if (FATALERROR_HOOKS == null) return true;
for(SocketFatalErrorHook errorHook : FATALERROR_HOOKS) for (SocketFatalErrorHook errorHook : FATALERROR_HOOKS) {
{
if (!errorHook.fatalErrorHook(socket, e)) return false; if (!errorHook.fatalErrorHook(socket, e)) return false;
} }
return true; return true;

View file

@ -1,18 +1,18 @@
package ru.gravit.launchserver.modules; package ru.gravit.launchserver.modules;
import ru.gravit.launcher.managers.ModulesConfigManager; import ru.gravit.launcher.managers.SimpleModulesConfigManager;
import ru.gravit.launcher.modules.ModuleContext; import ru.gravit.launcher.modules.ModuleContext;
import ru.gravit.launcher.modules.ModulesConfigManagerInterface; import ru.gravit.launcher.modules.ModulesConfigManager;
import ru.gravit.launcher.modules.ModulesManagerInterface; import ru.gravit.launcher.modules.ModulesManager;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.PublicURLClassLoader;
public class LaunchServerModuleContext implements ModuleContext { public class LaunchServerModuleContext implements ModuleContext {
public final LaunchServer launchServer; public final LaunchServer launchServer;
public final PublicURLClassLoader classloader; public final PublicURLClassLoader classloader;
public final ModulesConfigManager modulesConfigManager; public final SimpleModulesConfigManager modulesConfigManager;
public LaunchServerModuleContext(LaunchServer server, PublicURLClassLoader classloader, ModulesConfigManager modulesConfigManager) { public LaunchServerModuleContext(LaunchServer server, PublicURLClassLoader classloader, SimpleModulesConfigManager modulesConfigManager) {
launchServer = server; launchServer = server;
this.classloader = classloader; this.classloader = classloader;
this.modulesConfigManager = modulesConfigManager; this.modulesConfigManager = modulesConfigManager;
@ -24,12 +24,12 @@ public Type getType() {
} }
@Override @Override
public ModulesManagerInterface getModulesManager() { public ModulesManager getModulesManager() {
return launchServer.modulesManager; return launchServer.modulesManager;
} }
@Override @Override
public ModulesConfigManagerInterface getModulesConfigManager() { public ModulesConfigManager getModulesConfigManager() {
return modulesConfigManager; return modulesConfigManager;
} }
} }

View file

@ -1,12 +1,12 @@
package ru.gravit.launchserver.response; package ru.gravit.launchserver.response;
import java.io.IOException;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits; import ru.gravit.launcher.serialize.SerializeLimits;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import java.io.IOException;
public final class PingResponse extends Response { public final class PingResponse extends Response {
public PingResponse(LaunchServer server, long id, HInput input, HOutput output, String ip) { public PingResponse(LaunchServer server, long id, HInput input, HOutput output, String ip) {
super(server, id, input, output, ip); super(server, id, input, output, ip);

View file

@ -1,31 +1,22 @@
package ru.gravit.launchserver.response; package ru.gravit.launchserver.response;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import ru.gravit.launcher.request.RequestException; import ru.gravit.launcher.request.RequestException;
import ru.gravit.launcher.request.RequestType; import ru.gravit.launcher.request.RequestType;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.response.admin.ExecCommandResponse; import ru.gravit.launchserver.response.admin.ExecCommandResponse;
import ru.gravit.launchserver.response.auth.AuthResponse; import ru.gravit.launchserver.response.auth.*;
import ru.gravit.launchserver.response.auth.AuthServerResponse;
import ru.gravit.launchserver.response.auth.ChangeServerResponse;
import ru.gravit.launchserver.response.auth.CheckServerResponse;
import ru.gravit.launchserver.response.auth.JoinServerResponse;
import ru.gravit.launchserver.response.auth.SetProfileResponse;
import ru.gravit.launchserver.response.profile.BatchProfileByUsernameResponse; import ru.gravit.launchserver.response.profile.BatchProfileByUsernameResponse;
import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse; import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse;
import ru.gravit.launchserver.response.profile.ProfileByUsernameResponse; import ru.gravit.launchserver.response.profile.ProfileByUsernameResponse;
import ru.gravit.launchserver.response.update.LauncherResponse; import ru.gravit.launchserver.response.update.*;
import ru.gravit.launchserver.response.update.LegacyLauncherResponse;
import ru.gravit.launchserver.response.update.ProfilesResponse;
import ru.gravit.launchserver.response.update.UpdateListResponse;
import ru.gravit.launchserver.response.update.UpdateResponse;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public abstract class Response { public abstract class Response {
@FunctionalInterface @FunctionalInterface
public interface Factory<R> { public interface Factory<R> {

View file

@ -18,7 +18,8 @@ public ExecCommandResponse(LaunchServer server, long session, HInput input, HOut
@Override @Override
public void reply() throws Exception { public void reply() throws Exception {
Client clientData = server.sessionManager.getClient(session); Client clientData = server.sessionManager.getClient(session);
if(!clientData.isAuth || !clientData.permissions.canAdmin || !server.config.enableRcon) requestError("Access denied"); if (!clientData.isAuth || !clientData.permissions.canAdmin || !server.config.enableRcon)
requestError("Access denied");
writeNoError(output); writeNoError(output);
String cmd = input.readString(SerializeLimits.MAX_COMMAND); String cmd = input.readString(SerializeLimits.MAX_COMMAND);
LogHelper.Output loutput = message -> { LogHelper.Output loutput = message -> {
@ -30,8 +31,7 @@ public void reply() throws Exception {
} }
}; };
LogHelper.addOutput(loutput); LogHelper.addOutput(loutput);
try try {
{
server.commandHandler.eval(cmd, false); server.commandHandler.eval(cmd, false);
output.writeBoolean(false); output.writeBoolean(false);
} finally { } finally {

View file

@ -1,12 +1,5 @@
package ru.gravit.launchserver.response.auth; package ru.gravit.launchserver.response.auth;
import java.util.Arrays;
import java.util.Collection;
import java.util.UUID;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import ru.gravit.launcher.OshiHWID; import ru.gravit.launcher.OshiHWID;
import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
@ -25,6 +18,12 @@
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import java.util.Arrays;
import java.util.Collection;
import java.util.UUID;
public final class AuthResponse extends Response { public final class AuthResponse extends Response {
private static String echo(int length) { private static String echo(int length) {
char[] chars = new char[length]; char[] chars = new char[length];
@ -35,8 +34,8 @@ private static String echo(int length) {
public AuthResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { public AuthResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
super(server, session, input, output, ip); super(server, session, input, output, ip);
} }
public static class AuthContext
{ public static class AuthContext {
public AuthContext(long session, String login, int password_lenght, String client, String hwid, boolean isServerAuth) { public AuthContext(long session, String login, int password_lenght, String client, String hwid, boolean isServerAuth) {
this.session = session; this.session = session;
this.login = login; this.login = login;
@ -53,6 +52,7 @@ public AuthContext(long session, String login, int password_lenght, String clien
public String hwid; public String hwid;
public boolean isServerAuth; public boolean isServerAuth;
} }
@Override @Override
public void reply() throws Exception { public void reply() throws Exception {
String login = input.readString(SerializeLimits.MAX_LOGIN); String login = input.readString(SerializeLimits.MAX_LOGIN);

View file

@ -1,11 +1,5 @@
package ru.gravit.launchserver.response.auth; package ru.gravit.launchserver.response.auth;
import java.util.Arrays;
import java.util.Collection;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.HOutput;
@ -22,6 +16,11 @@
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import java.util.Arrays;
import java.util.Collection;
public final class AuthServerResponse extends Response { public final class AuthServerResponse extends Response {
private static String echo(int length) { private static String echo(int length) {
char[] chars = new char[length]; char[] chars = new char[length];
@ -74,8 +73,7 @@ public void reply() throws Exception {
throw new AuthException("Your profile is not found"); throw new AuthException("Your profile is not found");
} }
clientData.permissions = server.config.permissionsHandler.getPermissions(login); clientData.permissions = server.config.permissionsHandler.getPermissions(login);
if(!clientData.permissions.canServer) if (!clientData.permissions.canServer) {
{
throw new AuthException("Your account cannot be a server"); throw new AuthException("Your account cannot be a server");
} }
clientData.type = Client.Type.SERVER; clientData.type = Client.Type.SERVER;

View file

@ -1,8 +1,5 @@
package ru.gravit.launchserver.response.auth; package ru.gravit.launchserver.response.auth;
import java.io.IOException;
import java.util.UUID;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits; import ru.gravit.launcher.serialize.SerializeLimits;
@ -14,6 +11,9 @@
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException;
import java.util.UUID;
public final class CheckServerResponse extends Response { public final class CheckServerResponse extends Response {
public CheckServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { public CheckServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
@ -27,8 +27,7 @@ public void reply() throws IOException {
String client = input.readString(SerializeLimits.MAX_CLIENT); String client = input.readString(SerializeLimits.MAX_CLIENT);
debug("Username: %s, Server ID: %s", username, serverID); debug("Username: %s, Server ID: %s", username, serverID);
Client clientData = server.sessionManager.getClient(session); Client clientData = server.sessionManager.getClient(session);
if(!clientData.isAuth || clientData.type != Client.Type.SERVER) if (!clientData.isAuth || clientData.type != Client.Type.SERVER) {
{
requestError("Assess denied"); requestError("Assess denied");
return; return;
} }

View file

@ -1,7 +1,5 @@
package ru.gravit.launchserver.response.auth; package ru.gravit.launchserver.response.auth;
import java.io.IOException;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits; import ru.gravit.launcher.serialize.SerializeLimits;
@ -13,6 +11,8 @@
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException;
public final class JoinServerResponse extends Response { public final class JoinServerResponse extends Response {
public JoinServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { public JoinServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
@ -25,8 +25,7 @@ public void reply() throws IOException {
String accessToken = SecurityHelper.verifyToken(input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH)); String accessToken = SecurityHelper.verifyToken(input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH));
String serverID = VerifyHelper.verifyServerID(input.readASCII(SerializeLimits.MAX_SERVERID)); // With minus sign String serverID = VerifyHelper.verifyServerID(input.readASCII(SerializeLimits.MAX_SERVERID)); // With minus sign
Client clientData = server.sessionManager.getClient(session); Client clientData = server.sessionManager.getClient(session);
if(!clientData.isAuth || clientData.type != Client.Type.USER) if (!clientData.isAuth || clientData.type != Client.Type.USER) {
{
requestError("Assess denied"); requestError("Assess denied");
return; return;
} }

View file

@ -1,7 +1,5 @@
package ru.gravit.launchserver.response.auth; package ru.gravit.launchserver.response.auth;
import java.util.Collection;
import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.HOutput;
@ -10,6 +8,8 @@
import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.response.Response;
import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.Client;
import java.util.Collection;
public class SetProfileResponse extends Response { public class SetProfileResponse extends Response {
public SetProfileResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { public SetProfileResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
super(server, session, input, output, ip); super(server, session, input, output, ip);

View file

@ -1,8 +1,5 @@
package ru.gravit.launchserver.response.profile; package ru.gravit.launchserver.response.profile;
import java.io.IOException;
import java.util.Arrays;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits; import ru.gravit.launcher.serialize.SerializeLimits;
@ -10,6 +7,9 @@
import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.response.Response;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException;
import java.util.Arrays;
public final class BatchProfileByUsernameResponse extends Response { public final class BatchProfileByUsernameResponse extends Response {
public BatchProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { public BatchProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {

View file

@ -1,8 +1,5 @@
package ru.gravit.launchserver.response.profile; package ru.gravit.launchserver.response.profile;
import java.io.IOException;
import java.util.UUID;
import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.profiles.PlayerProfile;
import ru.gravit.launcher.profiles.Texture; import ru.gravit.launcher.profiles.Texture;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
@ -12,6 +9,9 @@
import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.response.Response;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.io.IOException;
import java.util.UUID;
public final class ProfileByUUIDResponse extends Response { public final class ProfileByUUIDResponse extends Response {
public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String username, String client) { public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String username, String client) {

Some files were not shown because too many files have changed in this diff Show more