[REFACTOR] Idea Reformat Code

This commit is contained in:
Gravita 2021-05-25 16:17:29 +07:00
parent 2c41b510ad
commit cd99641327
123 changed files with 846 additions and 903 deletions

View file

@ -11,7 +11,10 @@
import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.AuthProviderPair;
import pro.gravit.launchserver.auth.session.MemorySessionStorage; import pro.gravit.launchserver.auth.session.MemorySessionStorage;
import pro.gravit.launchserver.binary.*; import pro.gravit.launchserver.binary.EXEL4JLauncherBinary;
import pro.gravit.launchserver.binary.EXELauncherBinary;
import pro.gravit.launchserver.binary.JARLauncherBinary;
import pro.gravit.launchserver.binary.LauncherBinary;
import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.config.LaunchServerConfig;
import pro.gravit.launchserver.config.LaunchServerRuntimeConfig; import pro.gravit.launchserver.config.LaunchServerRuntimeConfig;
import pro.gravit.launchserver.launchermodules.LauncherModuleLoader; import pro.gravit.launchserver.launchermodules.LauncherModuleLoader;
@ -50,8 +53,6 @@
* Not a singletron * Not a singletron
*/ */
public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurable { public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurable {
private final Logger logger = LogManager.getLogger();
public static final Class<? extends LauncherBinary> defaultLauncherEXEBinaryClass = null; public static final Class<? extends LauncherBinary> defaultLauncherEXEBinaryClass = null;
/** /**
* Working folder path * Working folder path
@ -69,12 +70,12 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab
* The path to the folder with compile-only libraries for the launcher * The path to the folder with compile-only libraries for the launcher
*/ */
public final Path launcherLibrariesCompile; public final Path launcherLibrariesCompile;
// Constant paths
/** /**
* The path to the folder with updates/webroot * The path to the folder with updates/webroot
*/ */
public final Path updatesDir; public final Path updatesDir;
// Constant paths
/** /**
* Save/Reload LaunchServer config * Save/Reload LaunchServer config
*/ */
@ -100,7 +101,6 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab
* Pipeline for building EXE * Pipeline for building EXE
*/ */
public final LauncherBinary launcherEXEBinary; public final LauncherBinary launcherEXEBinary;
//public static LaunchServer server = null; //public static LaunchServer server = null;
public final Class<? extends LauncherBinary> launcherEXEBinaryClass; public final Class<? extends LauncherBinary> launcherEXEBinaryClass;
// Server config // Server config
@ -125,6 +125,7 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab
public final ScheduledExecutorService service; public final ScheduledExecutorService service;
public final AtomicBoolean started = new AtomicBoolean(false); public final AtomicBoolean started = new AtomicBoolean(false);
public final LauncherModuleLoader launcherModuleLoader; public final LauncherModuleLoader launcherModuleLoader;
private final Logger logger = LogManager.getLogger();
public LaunchServerConfig config; public LaunchServerConfig config;
public volatile Map<String, HashedDir> updatesDirMap; public volatile Map<String, HashedDir> updatesDirMap;
// Updates and profiles // Updates and profiles
@ -542,7 +543,8 @@ public void collect() {
if (launcherLibrariesCompileDir == null) if (launcherLibrariesCompileDir == null)
launcherLibrariesCompileDir = getPath(LAUNCHERLIBRARIESCOMPILE_NAME); launcherLibrariesCompileDir = getPath(LAUNCHERLIBRARIESCOMPILE_NAME);
if (keyDirectory == null) keyDirectory = getPath(KEY_NAME); if (keyDirectory == null) keyDirectory = getPath(KEY_NAME);
if(tmpDir ==null) tmpDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve(String.format("launchserver-%s", SecurityHelper.randomStringToken())); if (tmpDir == null)
tmpDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve(String.format("launchserver-%s", SecurityHelper.randomStringToken()));
} }
private Path getPath(String dirName) { private Path getPath(String dirName) {

View file

@ -8,8 +8,6 @@
import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.command.CommandHandler;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey;
public class LaunchServerBuilder { public class LaunchServerBuilder {
private LaunchServerConfig config; private LaunchServerConfig config;

View file

@ -31,7 +31,6 @@
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.JVMHelper;
import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.SecurityHelper;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
@ -39,12 +38,8 @@
import java.io.Writer; import java.io.Writer;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.KeyPair;
import java.security.SecureRandom;
import java.security.Security; import java.security.Security;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey;
public class LaunchServerStarter { public class LaunchServerStarter {
public static final boolean allowUnsigned = Boolean.getBoolean("launchserver.allowUnsigned"); public static final boolean allowUnsigned = Boolean.getBoolean("launchserver.allowUnsigned");

View file

@ -5,7 +5,6 @@
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.VerifyHelper; import pro.gravit.utils.helper.VerifyHelper;
import javax.sql.DataSource; import javax.sql.DataSource;

View file

@ -4,7 +4,6 @@
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.postgresql.ds.PGSimpleDataSource; import org.postgresql.ds.PGSimpleDataSource;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.VerifyHelper; import pro.gravit.utils.helper.VerifyHelper;
import javax.sql.DataSource; import javax.sql.DataSource;
@ -18,11 +17,9 @@ public final class PostgreSQLSourceConfig implements AutoCloseable {
private static final int MAX_POOL_SIZE = VerifyHelper.verifyInt( private static final int MAX_POOL_SIZE = VerifyHelper.verifyInt(
Integer.parseUnsignedInt(System.getProperty("launcher.postgresql.maxPoolSize", Integer.toString(3))), Integer.parseUnsignedInt(System.getProperty("launcher.postgresql.maxPoolSize", Integer.toString(3))),
VerifyHelper.POSITIVE, "launcher.postgresql.maxPoolSize can't be <= 0"); VerifyHelper.POSITIVE, "launcher.postgresql.maxPoolSize can't be <= 0");
private transient final Logger logger = LogManager.getLogger();
// Instance // Instance
private String poolName; private String poolName;
private transient final Logger logger = LogManager.getLogger();
// Config // Config
private String[] addresses; private String[] addresses;
private int[] ports; private int[] ports;

View file

@ -18,7 +18,6 @@
import pro.gravit.utils.command.Command; import pro.gravit.utils.command.Command;
import pro.gravit.utils.command.CommandException; import pro.gravit.utils.command.CommandException;
import pro.gravit.utils.command.SubCommand; import pro.gravit.utils.command.SubCommand;
import pro.gravit.utils.helper.SecurityHelper;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
@ -31,8 +30,9 @@
*/ */
public abstract class AuthCoreProvider implements AutoCloseable, Reconfigurable { public abstract class AuthCoreProvider implements AutoCloseable, Reconfigurable {
public static final ProviderMap<AuthCoreProvider> providers = new ProviderMap<>("AuthCoreProvider"); public static final ProviderMap<AuthCoreProvider> providers = new ProviderMap<>("AuthCoreProvider");
private static boolean registredProviders = false;
private static final Logger logger = LogManager.getLogger(); private static final Logger logger = LogManager.getLogger();
private static boolean registredProviders = false;
public static void registerProviders() { public static void registerProviders() {
if (!registredProviders) { if (!registredProviders) {
providers.register("reject", RejectAuthCoreProvider.class); providers.register("reject", RejectAuthCoreProvider.class);
@ -40,14 +40,23 @@ public static void registerProviders() {
registredProviders = true; registredProviders = true;
} }
} }
public abstract User getUserByUsername(String username); public abstract User getUserByUsername(String username);
public abstract User getUserByUUID(UUID uuid); public abstract User getUserByUUID(UUID uuid);
public abstract UserSession getUserSessionByOAuthAccessToken(String accessToken) throws OAuthAccessTokenExpired; public abstract UserSession getUserSessionByOAuthAccessToken(String accessToken) throws OAuthAccessTokenExpired;
public abstract AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthResponse.AuthContext context /* may be null */); public abstract AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthResponse.AuthContext context /* may be null */);
public abstract void verifyAuth(AuthResponse.AuthContext context) throws AuthException; public abstract void verifyAuth(AuthResponse.AuthContext context) throws AuthException;
public abstract PasswordVerifyReport verifyPassword(User user, AuthRequest.AuthPasswordInterface password); public abstract PasswordVerifyReport verifyPassword(User user, AuthRequest.AuthPasswordInterface password);
public abstract AuthManager.AuthReport createOAuthSession(User user, AuthResponse.AuthContext context /* may be null */, PasswordVerifyReport report /* may be null */, boolean minecraftAccess) throws IOException; public abstract AuthManager.AuthReport createOAuthSession(User user, AuthResponse.AuthContext context /* may be null */, PasswordVerifyReport report /* may be null */, boolean minecraftAccess) throws IOException;
public abstract void init(LaunchServer server); public abstract void init(LaunchServer server);
// Auth Handler methods // Auth Handler methods
protected abstract boolean updateServerID(User user, String serverID) throws IOException; protected abstract boolean updateServerID(User user, String serverID) throws IOException;
@ -125,11 +134,11 @@ public boolean joinServer(Client client, String username, String accessToken, St
public abstract void close() throws IOException; public abstract void close() throws IOException;
public static class PasswordVerifyReport { public static class PasswordVerifyReport {
public static final PasswordVerifyReport REQUIRED_2FA = new PasswordVerifyReport(-1);
public static final PasswordVerifyReport FAILED = new PasswordVerifyReport(false);
public final boolean success; public final boolean success;
public final boolean needMoreFactor; public final boolean needMoreFactor;
public final List<Integer> factors; public final List<Integer> factors;
public static final PasswordVerifyReport REQUIRED_2FA = new PasswordVerifyReport(-1);
public static final PasswordVerifyReport FAILED = new PasswordVerifyReport(false);
public PasswordVerifyReport(boolean success) { public PasswordVerifyReport(boolean success) {
this.success = success; this.success = success;

View file

@ -6,8 +6,12 @@
public interface User { public interface User {
String getUsername(); String getUsername();
UUID getUUID(); UUID getUUID();
String getServerId(); String getServerId();
String getAccessToken(); String getAccessToken();
ClientPermissions getPermissions(); ClientPermissions getPermissions();
} }

View file

@ -2,6 +2,8 @@
public interface UserSession { public interface UserSession {
String getID(); String getID();
User getUser(); User getUser();
long getExpireIn(); long getExpireIn();
} }

View file

@ -5,5 +5,6 @@
public interface AuthSupportExit { public interface AuthSupportExit {
boolean deleteSession(UserSession session); boolean deleteSession(UserSession session);
boolean exitUser(User user); boolean exitUser(User user);
} }

View file

@ -7,5 +7,6 @@
public interface AuthSupportGetSessionsFromUser { public interface AuthSupportGetSessionsFromUser {
List<UserSession> getSessionsByUser(User user); List<UserSession> getSessionsByUser(User user);
void clearSessionsByUser(User user); void clearSessionsByUser(User user);
} }

View file

@ -2,5 +2,6 @@
public interface UserSupportMoney { public interface UserSupportMoney {
long getMoney(); long getMoney();
long getDonateMoney(); long getDonateMoney();
} }

View file

@ -8,7 +8,10 @@
import pro.gravit.launchserver.auth.provider.AuthProviderResult; import pro.gravit.launchserver.auth.provider.AuthProviderResult;
import pro.gravit.utils.command.Command; import pro.gravit.utils.command.Command;
import pro.gravit.utils.command.SubCommand; import pro.gravit.utils.command.SubCommand;
import pro.gravit.utils.helper.*; import pro.gravit.utils.helper.CommonHelper;
import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.SecurityHelper;
import pro.gravit.utils.helper.VerifyHelper;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;

View file

@ -12,6 +12,7 @@
public class DigestPasswordVerifier extends PasswordVerifier { public class DigestPasswordVerifier extends PasswordVerifier {
private transient final Logger logger = LogManager.getLogger(); private transient final Logger logger = LogManager.getLogger();
public String algo; public String algo;
@Override @Override
public boolean check(String encryptedPassword, String password) { public boolean check(String encryptedPassword, String password) {
try { try {

View file

@ -13,6 +13,7 @@ public class DoubleDigestPasswordVerifier extends PasswordVerifier {
private transient final Logger logger = LogManager.getLogger(); private transient final Logger logger = LogManager.getLogger();
public String algo; public String algo;
public boolean toHexMode; public boolean toHexMode;
@Override @Override
public boolean check(String encryptedPassword, String password) { public boolean check(String encryptedPassword, String password) {
try { try {

View file

@ -5,6 +5,7 @@
public abstract class PasswordVerifier { public abstract class PasswordVerifier {
public static final ProviderMap<PasswordVerifier> providers = new ProviderMap<>("PasswordVerifier"); public static final ProviderMap<PasswordVerifier> providers = new ProviderMap<>("PasswordVerifier");
private static boolean registeredProviders = false; private static boolean registeredProviders = false;
public static void registerProviders() { public static void registerProviders() {
if (!registeredProviders) { if (!registeredProviders) {
providers.register("plain", PlainPasswordVerifier.class); providers.register("plain", PlainPasswordVerifier.class);
@ -13,5 +14,6 @@ public static void registerProviders() {
registeredProviders = true; registeredProviders = true;
} }
} }
public abstract boolean check(String encryptedPassword, String password); public abstract boolean check(String encryptedPassword, String password);
} }

View file

@ -16,7 +16,6 @@
import pro.gravit.launchserver.socket.response.auth.AuthResponse; import pro.gravit.launchserver.socket.response.auth.AuthResponse;
import pro.gravit.launchserver.socket.response.secure.HardwareReportResponse; import pro.gravit.launchserver.socket.response.secure.HardwareReportResponse;
import pro.gravit.utils.command.Command; import pro.gravit.utils.command.Command;
import pro.gravit.utils.helper.LogHelper;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View file

@ -16,10 +16,10 @@
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class MemoryHWIDProvider extends HWIDProvider implements Reconfigurable { public class MemoryHWIDProvider extends HWIDProvider implements Reconfigurable {
private transient final Logger logger = LogManager.getLogger();
public double warningSpoofingLevel = -1.0; public double warningSpoofingLevel = -1.0;
public double criticalCompareLevel = 1.0; public double criticalCompareLevel = 1.0;
public transient Set<MemoryHWIDEntity> db = ConcurrentHashMap.newKeySet(); public transient Set<MemoryHWIDEntity> db = ConcurrentHashMap.newKeySet();
private transient final Logger logger = LogManager.getLogger();
@Override @Override
public Map<String, Command> getCommands() { public Map<String, Command> getCommands() {

View file

@ -13,16 +13,15 @@
import java.sql.*; import java.sql.*;
public class MysqlHWIDProvider extends HWIDProvider { public class MysqlHWIDProvider extends HWIDProvider {
private transient final Logger logger = LogManager.getLogger();
public MySQLSourceConfig mySQLHolder; public MySQLSourceConfig mySQLHolder;
public double warningSpoofingLevel = -1.0; public double warningSpoofingLevel = -1.0;
public double criticalCompareLevel = 1.0; public double criticalCompareLevel = 1.0;
public String tableHWID = "hwids"; public String tableHWID = "hwids";
public String tableHWIDLog = "hwidLog"; public String tableHWIDLog = "hwidLog";
public String tableUsers; public String tableUsers;
public String usersNameColumn; public String usersNameColumn;
public String usersHWIDColumn; public String usersHWIDColumn;
private String sqlFindByPublicKey; private String sqlFindByPublicKey;
private String sqlFindByHardware; private String sqlFindByHardware;
private String sqlCreateHardware; private String sqlCreateHardware;
@ -30,8 +29,6 @@ public class MysqlHWIDProvider extends HWIDProvider {
private String sqlUpdateHardware; private String sqlUpdateHardware;
private String sqlUpdateUsers; private String sqlUpdateUsers;
private transient final Logger logger = LogManager.getLogger();
@Override @Override
public void init(LaunchServer server) { public void init(LaunchServer server) {
sqlFindByPublicKey = String.format("SELECT hwDiskId, baseboardSerialNumber, displayId, bitness, totalMemory, logicalProcessors, physicalProcessors, processorMaxFreq, battery, id, banned FROM %s WHERE `publicKey` = ?", tableHWID); sqlFindByPublicKey = String.format("SELECT hwDiskId, baseboardSerialNumber, displayId, bitness, totalMemory, logicalProcessors, physicalProcessors, processorMaxFreq, battery, id, banned FROM %s WHERE `publicKey` = ?", tableHWID);

View file

@ -33,9 +33,11 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p
firstPassword = ((AuthPlainPassword) password).password; firstPassword = ((AuthPlainPassword) password).password;
secondPassword = null; secondPassword = null;
} else if (password instanceof Auth2FAPassword) { } else if (password instanceof Auth2FAPassword) {
if (!(((Auth2FAPassword) password).firstPassword instanceof AuthPlainPassword)) throw new AuthException("This password type not supported"); if (!(((Auth2FAPassword) password).firstPassword instanceof AuthPlainPassword))
throw new AuthException("This password type not supported");
firstPassword = ((AuthPlainPassword) ((Auth2FAPassword) password).firstPassword).password; firstPassword = ((AuthPlainPassword) ((Auth2FAPassword) password).firstPassword).password;
if (!(((Auth2FAPassword) password).secondPassword instanceof AuthTOTPPassword)) throw new AuthException("This password type not supported"); if (!(((Auth2FAPassword) password).secondPassword instanceof AuthTOTPPassword))
throw new AuthException("This password type not supported");
secondPassword = ((AuthTOTPPassword) ((Auth2FAPassword) password).secondPassword).totp; secondPassword = ((AuthTOTPPassword) ((Auth2FAPassword) password).secondPassword).totp;
} else { } else {
throw new AuthException("This password type not supported"); throw new AuthException("This password type not supported");

View file

@ -8,7 +8,6 @@
import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.auth.AuthException;
import pro.gravit.utils.command.Command; import pro.gravit.utils.command.Command;
import pro.gravit.utils.command.SubCommand; import pro.gravit.utils.command.SubCommand;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.SecurityHelper;
import java.util.ArrayList; import java.util.ArrayList;
@ -16,11 +15,10 @@
import java.util.Map; import java.util.Map;
public final class RejectAuthProvider extends AuthProvider implements Reconfigurable { public final class RejectAuthProvider extends AuthProvider implements Reconfigurable {
private transient final Logger logger = LogManager.getLogger();
public String message; public String message;
public ArrayList<String> whitelist = new ArrayList<>(); public ArrayList<String> whitelist = new ArrayList<>();
private transient final Logger logger = LogManager.getLogger();
public RejectAuthProvider() { public RejectAuthProvider() {
} }

View file

@ -7,7 +7,6 @@
import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.auth.AuthException;
import pro.gravit.utils.helper.CommonHelper; import pro.gravit.utils.helper.CommonHelper;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.SecurityHelper;
import java.io.IOException; import java.io.IOException;

View file

@ -6,9 +6,7 @@
import pro.gravit.launcher.NeedGarbageCollection; import pro.gravit.launcher.NeedGarbageCollection;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
import java.nio.file.Files; import java.nio.file.Files;

View file

@ -17,11 +17,11 @@
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class BinaryPipeline { public class BinaryPipeline {
private transient final Logger logger = LogManager.getLogger();
public final List<LauncherBuildTask> tasks = new ArrayList<>(); public final List<LauncherBuildTask> tasks = new ArrayList<>();
public final AtomicLong count = new AtomicLong(0); public final AtomicLong count = new AtomicLong(0);
public final Path buildDir; public final Path buildDir;
public final String nameFormat; public final String nameFormat;
private transient final Logger logger = LogManager.getLogger();
public BinaryPipeline(Path buildDir, String nameFormat) { public BinaryPipeline(Path buildDir, String nameFormat) {
this.buildDir = buildDir; this.buildDir = buildDir;

View file

@ -1,12 +1,10 @@
package pro.gravit.launchserver.binary; package pro.gravit.launchserver.binary;
import org.jetbrains.annotations.NotNull;
import pro.gravit.launcher.Launcher; import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launcher.serialize.HOutput;
import pro.gravit.launcher.serialize.stream.StreamObject; import pro.gravit.launcher.serialize.stream.StreamObject;
import pro.gravit.launchserver.binary.tasks.MainBuildTask; import pro.gravit.launchserver.binary.tasks.MainBuildTask;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.SecurityHelper;
import javax.crypto.Cipher; import javax.crypto.Cipher;
@ -33,7 +31,6 @@
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;

View file

@ -2,7 +2,6 @@
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;

View file

@ -3,7 +3,6 @@
import pro.gravit.launcher.Launcher; import pro.gravit.launcher.Launcher;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.binary.tasks.*; import pro.gravit.launchserver.binary.tasks.*;
import pro.gravit.launchserver.components.ProGuardComponent;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;

View file

@ -2,7 +2,6 @@
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;

View file

@ -34,12 +34,11 @@
public class CertificateAutogenTask implements LauncherBuildTask { public class CertificateAutogenTask implements LauncherBuildTask {
private final LaunchServer server; private final LaunchServer server;
private transient final Logger logger = LogManager.getLogger();
public X509Certificate certificate; public X509Certificate certificate;
public X509CertificateHolder bcCertificate; public X509CertificateHolder bcCertificate;
public CMSSignedDataGenerator signedDataGenerator; public CMSSignedDataGenerator signedDataGenerator;
private transient final Logger logger = LogManager.getLogger();
public CertificateAutogenTask(LaunchServer server) { public CertificateAutogenTask(LaunchServer server) {
this.server = server; this.server = server;
} }

View file

@ -17,7 +17,6 @@
import pro.gravit.launchserver.binary.BuildContext; import pro.gravit.launchserver.binary.BuildContext;
import pro.gravit.utils.HookException; import pro.gravit.utils.HookException;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.SecurityHelper;
import java.io.IOException; import java.io.IOException;
@ -63,7 +62,8 @@ public Path process(Path inputJar) throws IOException {
reader.getCp().add(new JarFile(inputJar.toFile())); reader.getCp().add(new JarFile(inputJar.toFile()));
for (Path e : server.launcherBinary.coreLibs) { for (Path e : server.launcherBinary.coreLibs) {
reader.getCp().add(new JarFile(e.toFile())); reader.getCp().add(new JarFile(e.toFile()));
}; }
;
context.pushJarFile(inputJar, (e) -> blacklist.contains(e.getName()), (e) -> true); context.pushJarFile(inputJar, (e) -> blacklist.contains(e.getName()), (e) -> true);
// map for guard // map for guard
@ -114,7 +114,8 @@ protected void initProps() {
properties.put("launchercore.env", server.config.env); properties.put("launchercore.env", server.config.env);
properties.put("launcher.memory", server.config.launcher.memoryLimit); properties.put("launcher.memory", server.config.launcher.memoryLimit);
if (server.config.launcher.encryptRuntime) { if (server.config.launcher.encryptRuntime) {
if (server.runtime.runtimeEncryptKey == null) server.runtime.runtimeEncryptKey = SecurityHelper.randomStringToken(); if (server.runtime.runtimeEncryptKey == null)
server.runtime.runtimeEncryptKey = SecurityHelper.randomStringToken();
properties.put("runtimeconfig.runtimeEncryptKey", server.runtime.runtimeEncryptKey); properties.put("runtimeconfig.runtimeEncryptKey", server.runtime.runtimeEncryptKey);
} }
properties.put("launcher.certificatePinning", server.config.launcher.certificatePinning); properties.put("launcher.certificatePinning", server.config.launcher.certificatePinning);

View file

@ -26,9 +26,9 @@
public class SignJarTask implements LauncherBuildTask { public class SignJarTask implements LauncherBuildTask {
private transient static final Logger logger = LogManager.getLogger();
private final LaunchServerConfig.JarSignerConf config; private final LaunchServerConfig.JarSignerConf config;
private final LaunchServer srv; private final LaunchServer srv;
private transient static final Logger logger = LogManager.getLogger();
public SignJarTask(LaunchServerConfig.JarSignerConf config, LaunchServer srv) { public SignJarTask(LaunchServerConfig.JarSignerConf config, LaunchServer srv) {
this.config = config; this.config = config;

View file

@ -8,7 +8,6 @@
import pro.gravit.launchserver.auth.provider.AuthProvider; import pro.gravit.launchserver.auth.provider.AuthProvider;
import pro.gravit.launchserver.auth.provider.AuthProviderResult; import pro.gravit.launchserver.auth.provider.AuthProviderResult;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.helper.LogHelper;
import java.util.UUID; import java.util.UUID;

View file

@ -6,7 +6,6 @@
import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.AuthProviderPair;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.command.CommandException; import pro.gravit.utils.command.CommandException;
import pro.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
import java.util.UUID; import java.util.UUID;

View file

@ -6,7 +6,6 @@
import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.AuthProviderPair;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.command.CommandException; import pro.gravit.utils.command.CommandException;
import pro.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
import java.util.UUID; import java.util.UUID;

View file

@ -10,14 +10,13 @@
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.launchserver.socket.handlers.NettyServerSocketHandler; import pro.gravit.launchserver.socket.handlers.NettyServerSocketHandler;
import pro.gravit.utils.helper.CommonHelper; import pro.gravit.utils.helper.CommonHelper;
import pro.gravit.utils.helper.LogHelper;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.security.KeyPair; import java.security.KeyPair;
public class TestCommand extends Command { public class TestCommand extends Command {
private NettyServerSocketHandler handler = null;
private transient final Logger logger = LogManager.getLogger(); private transient final Logger logger = LogManager.getLogger();
private NettyServerSocketHandler handler = null;
public TestCommand(LaunchServer server) { public TestCommand(LaunchServer server) {
super(server); super(server);

View file

@ -6,12 +6,12 @@
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.Version; import pro.gravit.utils.Version;
import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.JVMHelper;
import pro.gravit.utils.helper.LogHelper;
import java.lang.management.RuntimeMXBean; import java.lang.management.RuntimeMXBean;
public final class VersionCommand extends Command { public final class VersionCommand extends Command {
private transient final Logger logger = LogManager.getLogger(); private transient final Logger logger = LogManager.getLogger();
public VersionCommand(LaunchServer server) { public VersionCommand(LaunchServer server) {
super(server); super(server);
} }

View file

@ -5,7 +5,6 @@
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;

View file

@ -9,9 +9,7 @@
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.command.CommandException; import pro.gravit.utils.command.CommandException;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;

View file

@ -1,6 +1,5 @@
package pro.gravit.launchserver.command.hash; package pro.gravit.launchserver.command.hash;
import com.google.gson.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -9,7 +8,6 @@
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.command.CommandException; import pro.gravit.utils.command.CommandException;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.SecurityHelper;
import pro.gravit.utils.helper.SecurityHelper.DigestAlgorithm; import pro.gravit.utils.helper.SecurityHelper.DigestAlgorithm;

View file

@ -3,7 +3,6 @@
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import pro.gravit.launcher.Launcher; import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.hasher.HashedDir;
import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.ClientProfileBuilder; import pro.gravit.launcher.profiles.ClientProfileBuilder;
import pro.gravit.launcher.profiles.optional.OptionalFile; import pro.gravit.launcher.profiles.optional.OptionalFile;
@ -12,7 +11,6 @@
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
@ -28,10 +26,6 @@ public SaveProfilesCommand(LaunchServer server) {
super(server); super(server);
} }
public enum MakeProfileOption {
LAUNCHWRAPPER, VANILLA, FORGE, FABRIC, LITELOADER
}
public static ClientProfile makeProfile(ClientProfile.Version version, String title, MakeProfileOption... options) { public static ClientProfile makeProfile(ClientProfile.Version version, String title, MakeProfileOption... options) {
ClientProfileBuilder builder = new ClientProfileBuilder(); ClientProfileBuilder builder = new ClientProfileBuilder();
builder.setVersion(version.name); builder.setVersion(version.name);
@ -191,4 +185,8 @@ public void invoke(String... args) throws Exception {
server.syncProfilesDir(); server.syncProfilesDir();
} }
} }
public enum MakeProfileOption {
LAUNCHWRAPPER, VANILLA, FORGE, FABRIC, LITELOADER
}
} }

View file

@ -4,12 +4,12 @@
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
public final class SyncBinariesCommand extends Command { public final class SyncBinariesCommand extends Command {
private transient final Logger logger = LogManager.getLogger(); private transient final Logger logger = LogManager.getLogger();
public SyncBinariesCommand(LaunchServer server) { public SyncBinariesCommand(LaunchServer server) {
super(server); super(server);
} }

View file

@ -4,12 +4,12 @@
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
public final class SyncProfilesCommand extends Command { public final class SyncProfilesCommand extends Command {
private transient final Logger logger = LogManager.getLogger(); private transient final Logger logger = LogManager.getLogger();
public SyncProfilesCommand(LaunchServer server) { public SyncProfilesCommand(LaunchServer server) {
super(server); super(server);
} }

View file

@ -4,7 +4,6 @@
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;

View file

@ -4,7 +4,6 @@
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;

View file

@ -9,7 +9,6 @@
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.command.CommandException; import pro.gravit.utils.command.CommandException;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.nio.file.Files; import java.nio.file.Files;

View file

@ -8,13 +8,13 @@
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.launchserver.launchermodules.LauncherModuleLoader; import pro.gravit.launchserver.launchermodules.LauncherModuleLoader;
import pro.gravit.utils.helper.LogHelper;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.Arrays; import java.util.Arrays;
public class ModulesCommand extends Command { public class ModulesCommand extends Command {
private transient final Logger logger = LogManager.getLogger(); private transient final Logger logger = LogManager.getLogger();
public ModulesCommand(LaunchServer server) { public ModulesCommand(LaunchServer server) {
super(server); super(server);
} }

View file

@ -8,7 +8,6 @@
import pro.gravit.launchserver.socket.WebSocketService; import pro.gravit.launchserver.socket.WebSocketService;
import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler; import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import java.util.Base64; import java.util.Base64;

View file

@ -3,13 +3,11 @@
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import pro.gravit.launcher.Launcher; import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.NeedGarbageCollection;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.launchserver.components.Component; import pro.gravit.launchserver.components.Component;
import pro.gravit.utils.command.SubCommand; import pro.gravit.utils.command.SubCommand;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import java.io.Reader; import java.io.Reader;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
@ -25,6 +23,28 @@ public ComponentCommand(LaunchServer server) {
childCommands.put("load", new LoadCommand()); childCommands.put("load", new LoadCommand());
} }
@Override
public String getArgsDescription() {
return "[action] [component name] [more args]";
}
@Override
public String getUsageDescription() {
return "component manager";
}
public void printHelp() {
logger.info("Print help for component:");
logger.info("component unload [componentName]");
logger.info("component load [componentName] [filename]");
logger.info("component gc [componentName]");
}
@Override
public void invoke(String... args) throws Exception {
invokeSubcommands(args);
}
private class UnloadCommand extends SubCommand { private class UnloadCommand extends SubCommand {
public UnloadCommand() { public UnloadCommand() {
super("[componentName]", "Unload component"); super("[componentName]", "Unload component");
@ -47,6 +67,7 @@ public void invoke(String... args) throws Exception {
logger.info("Component %s unloaded. Use 'config launchserver save' to save changes"); logger.info("Component %s unloaded. Use 'config launchserver save' to save changes");
} }
} }
private class LoadCommand extends SubCommand { private class LoadCommand extends SubCommand {
public LoadCommand() { public LoadCommand() {
super("[componentName] [componentType] (json file)", "Load component"); super("[componentName] [componentType] (json file)", "Load component");
@ -79,26 +100,4 @@ public void invoke(String... args) throws Exception {
} }
} }
} }
@Override
public String getArgsDescription() {
return "[action] [component name] [more args]";
}
@Override
public String getUsageDescription() {
return "component manager";
}
public void printHelp() {
logger.info("Print help for component:");
logger.info("component unload [componentName]");
logger.info("component load [componentName] [filename]");
logger.info("component gc [componentName]");
}
@Override
public void invoke(String... args) throws Exception {
invokeSubcommands(args);
}
} }

View file

@ -5,7 +5,6 @@
import pro.gravit.launcher.request.management.PingServerReportRequest; import pro.gravit.launcher.request.management.PingServerReportRequest;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.helper.LogHelper;
public class PingServersCommand extends Command { public class PingServersCommand extends Command {
private transient final Logger logger = LogManager.getLogger(); private transient final Logger logger = LogManager.getLogger();

View file

@ -2,7 +2,6 @@
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.fusesource.jansi.Ansi;
import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.auth.handler.MemoryAuthHandler; import pro.gravit.launchserver.auth.handler.MemoryAuthHandler;
@ -13,14 +12,12 @@
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.launchserver.components.ProGuardComponent; import pro.gravit.launchserver.components.ProGuardComponent;
import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.config.LaunchServerConfig;
import pro.gravit.utils.helper.FormatHelper;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.JVMHelper;
import pro.gravit.utils.helper.LogHelper; import pro.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.LinkOption;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermission;
@ -238,10 +235,12 @@ public void invoke(String... args) {
} }
logger.info("Check completed"); logger.info("Check completed");
} }
public boolean checkOtherWriteAccess(Path file) throws IOException { public boolean checkOtherWriteAccess(Path file) throws IOException {
Set<PosixFilePermission> permissionSet = Files.getPosixFilePermissions(file); Set<PosixFilePermission> permissionSet = Files.getPosixFilePermissions(file);
return permissionSet.contains(PosixFilePermission.OTHERS_WRITE); return permissionSet.contains(PosixFilePermission.OTHERS_WRITE);
} }
public boolean checkOtherReadOrWriteAccess(Path file) throws IOException { public boolean checkOtherReadOrWriteAccess(Path file) throws IOException {
Set<PosixFilePermission> permissionSet = Files.getPosixFilePermissions(file); Set<PosixFilePermission> permissionSet = Files.getPosixFilePermissions(file);
return permissionSet.contains(PosixFilePermission.OTHERS_WRITE) || permissionSet.contains(PosixFilePermission.OTHERS_READ); return permissionSet.contains(PosixFilePermission.OTHERS_WRITE) || permissionSet.contains(PosixFilePermission.OTHERS_READ);

View file

@ -8,7 +8,6 @@
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.command.CommandHandler;
import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.JVMHelper;
import pro.gravit.utils.helper.LogHelper;
public class ServerStatusCommand extends Command { public class ServerStatusCommand extends Command {
private transient final Logger logger = LogManager.getLogger(); private transient final Logger logger = LogManager.getLogger();

View file

@ -6,7 +6,6 @@
import pro.gravit.launchserver.binary.tasks.SignJarTask; import pro.gravit.launchserver.binary.tasks.SignJarTask;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
import java.nio.file.*; import java.nio.file.*;

View file

@ -5,7 +5,6 @@
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.binary.tasks.SignJarTask; import pro.gravit.launchserver.binary.tasks.SignJarTask;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.helper.LogHelper;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;

View file

@ -6,7 +6,6 @@
import pro.gravit.launchserver.Reconfigurable; import pro.gravit.launchserver.Reconfigurable;
import pro.gravit.utils.command.Command; import pro.gravit.utils.command.Command;
import pro.gravit.utils.command.SubCommand; import pro.gravit.utils.command.SubCommand;
import pro.gravit.utils.helper.LogHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -14,9 +13,9 @@
import java.util.Map; import java.util.Map;
public abstract class AbstractLimiter<T> extends Component implements NeedGarbageCollection, Reconfigurable { public abstract class AbstractLimiter<T> extends Component implements NeedGarbageCollection, Reconfigurable {
private transient final Logger logger = LogManager.getLogger();
public final List<T> exclude = new ArrayList<>(); public final List<T> exclude = new ArrayList<>();
protected final transient Map<T, LimitEntry> map = new HashMap<>(); protected final transient Map<T, LimitEntry> map = new HashMap<>();
private transient final Logger logger = LogManager.getLogger();
public int rateLimit; public int rateLimit;
public int rateLimitMillis; public int rateLimitMillis;

View file

@ -7,7 +7,10 @@
import pro.gravit.launchserver.binary.tasks.LauncherBuildTask; import pro.gravit.launchserver.binary.tasks.LauncherBuildTask;
import pro.gravit.utils.command.Command; import pro.gravit.utils.command.Command;
import pro.gravit.utils.command.SubCommand; import pro.gravit.utils.command.SubCommand;
import pro.gravit.utils.helper.*; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.JVMHelper;
import pro.gravit.utils.helper.SecurityHelper;
import pro.gravit.utils.helper.UnpackHelper;
import proguard.Configuration; import proguard.Configuration;
import proguard.ConfigurationParser; import proguard.ConfigurationParser;
import proguard.ParseException; import proguard.ParseException;
@ -20,9 +23,13 @@
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class ProGuardComponent extends Component implements AutoCloseable, Reconfigurable { public class ProGuardComponent extends Component implements AutoCloseable, Reconfigurable {
private transient static final Logger logger = LogManager.getLogger();
public String modeAfter = "MainBuild"; public String modeAfter = "MainBuild";
public String dir = "proguard"; public String dir = "proguard";
public boolean enabled = true; public boolean enabled = true;
@ -30,7 +37,40 @@ public class ProGuardComponent extends Component implements AutoCloseable, Recon
public transient ProguardConf proguardConf; public transient ProguardConf proguardConf;
private transient LaunchServer launchServer; private transient LaunchServer launchServer;
private transient ProGuardBuildTask buildTask; private transient ProGuardBuildTask buildTask;
private transient static final Logger logger = LogManager.getLogger();
public static boolean checkFXJMods(Path path) {
if (!IOHelper.exists(path.resolve("javafx.base.jmod")))
return false;
if (!IOHelper.exists(path.resolve("javafx.graphics.jmod")))
return false;
return IOHelper.exists(path.resolve("javafx.controls.jmod"));
}
public static boolean checkJMods(Path path) {
return IOHelper.exists(path.resolve("java.base.jmod"));
}
public static Path tryFindOpenJFXPath(Path jvmDir) {
String dirName = jvmDir.getFileName().toString();
Path parent = jvmDir.getParent();
if (parent == null) return null;
Path archJFXPath = parent.resolve(dirName.replace("openjdk", "openjfx")).resolve("jmods");
if (Files.isDirectory(archJFXPath)) {
return archJFXPath;
}
Path arch2JFXPath = parent.resolve(dirName.replace("jdk", "openjfx")).resolve("jmods");
if (Files.isDirectory(arch2JFXPath)) {
return arch2JFXPath;
}
if (JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) {
Path debianJfxPath = Paths.get("/usr/share/openjfx/jmods");
if (Files.isDirectory(debianJfxPath)) {
return debianJfxPath;
}
}
return null;
}
@Override @Override
public void init(LaunchServer launchServer) { public void init(LaunchServer launchServer) {
this.launchServer = launchServer; this.launchServer = launchServer;
@ -100,8 +140,7 @@ public Path process(Path inputFile) throws IOException {
if (checkFXJMods(IOHelper.JVM_DIR.resolve("jmods"))) { if (checkFXJMods(IOHelper.JVM_DIR.resolve("jmods"))) {
logger.debug("JavaFX jmods resolved in JDK path"); logger.debug("JavaFX jmods resolved in JDK path");
jfxPath = null; jfxPath = null;
} } else if (jfxPath != null && checkFXJMods(jfxPath)) {
else if(jfxPath != null && checkFXJMods(jfxPath)) {
logger.debug("JMods resolved in {}", jfxPath.toString()); logger.debug("JMods resolved in {}", jfxPath.toString());
} else { } else {
logger.error("JavaFX jmods not found. May be install OpenJFX?"); logger.error("JavaFX jmods not found. May be install OpenJFX?");
@ -126,39 +165,6 @@ public boolean allowDelete() {
} }
} }
public static boolean checkFXJMods(Path path) {
if (!IOHelper.exists(path.resolve("javafx.base.jmod")))
return false;
if (!IOHelper.exists(path.resolve("javafx.graphics.jmod")))
return false;
return IOHelper.exists(path.resolve("javafx.controls.jmod"));
}
public static boolean checkJMods(Path path) {
return IOHelper.exists(path.resolve("java.base.jmod"));
}
public static Path tryFindOpenJFXPath(Path jvmDir) {
String dirName = jvmDir.getFileName().toString();
Path parent = jvmDir.getParent();
if(parent == null) return null;
Path archJFXPath = parent.resolve(dirName.replace("openjdk", "openjfx")).resolve("jmods");
if(Files.isDirectory(archJFXPath)) {
return archJFXPath;
}
Path arch2JFXPath = parent.resolve(dirName.replace("jdk", "openjfx")).resolve("jmods");
if(Files.isDirectory(arch2JFXPath)) {
return arch2JFXPath;
}
if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) {
Path debianJfxPath = Paths.get("/usr/share/openjfx/jmods");
if(Files.isDirectory(debianJfxPath)) {
return debianJfxPath;
}
}
return null;
}
public static class ProguardConf { public static class ProguardConf {
public static final String[] JAVA9_OPTS = new String[]{ public static final String[] JAVA9_OPTS = new String[]{
"-libraryjars '<java.home>/jmods/'" "-libraryjars '<java.home>/jmods/'"

View file

@ -23,7 +23,6 @@
import pro.gravit.launchserver.dao.provider.DaoProvider; import pro.gravit.launchserver.dao.provider.DaoProvider;
import pro.gravit.utils.Version; import pro.gravit.utils.Version;
import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.JVMHelper;
import pro.gravit.utils.helper.LogHelper;
import java.io.File; import java.io.File;
import java.util.Arrays; import java.util.Arrays;
@ -31,6 +30,7 @@
import java.util.Map; import java.util.Map;
public final class LaunchServerConfig { public final class LaunchServerConfig {
private transient final Logger logger = LogManager.getLogger();
public String projectName; public String projectName;
public String[] mirrors; public String[] mirrors;
public String binaryName; public String binaryName;
@ -40,7 +40,6 @@ public final class LaunchServerConfig {
@Deprecated @Deprecated
public DaoProvider dao; public DaoProvider dao;
public SessionStorage sessions; public SessionStorage sessions;
// Handlers & Providers // Handlers & Providers
public ProtectHandler protectHandler; public ProtectHandler protectHandler;
public Map<String, Component> components; public Map<String, Component> components;
@ -51,7 +50,6 @@ public final class LaunchServerConfig {
public String startScript; public String startScript;
private transient LaunchServer server = null; private transient LaunchServer server = null;
private transient AuthProviderPair authDefault; private transient AuthProviderPair authDefault;
private transient final Logger logger = LogManager.getLogger();
public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) {
LaunchServerConfig newConfig = new LaunchServerConfig(); LaunchServerConfig newConfig = new LaunchServerConfig();

View file

@ -2,16 +2,15 @@
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.SecurityHelper;
public class LaunchServerRuntimeConfig { public class LaunchServerRuntimeConfig {
private transient final Logger logger = LogManager.getLogger();
public String passwordEncryptKey; public String passwordEncryptKey;
public String runtimeEncryptKey; public String runtimeEncryptKey;
public String oemUnlockKey; public String oemUnlockKey;
public String registerApiKey; public String registerApiKey;
public String clientCheckSecret; public String clientCheckSecret;
private transient final Logger logger = LogManager.getLogger();
public void verify() { public void verify() {
if (passwordEncryptKey == null) logger.error("[RuntimeConfig] passwordEncryptKey must not be null"); if (passwordEncryptKey == null) logger.error("[RuntimeConfig] passwordEncryptKey must not be null");

View file

@ -21,11 +21,32 @@
public class LogAppender extends AbstractAppender { public class LogAppender extends AbstractAppender {
private static volatile LogAppender INSTANCE; private static volatile LogAppender INSTANCE;
private final Set<Consumer<LogEvent>> set = new HashSet<>(); private final Set<Consumer<LogEvent>> set = new HashSet<>();
public LogAppender(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions, Property[] properties) { public LogAppender(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions, Property[] properties) {
super(name, filter, layout, ignoreExceptions, properties); super(name, filter, layout, ignoreExceptions, properties);
INSTANCE = this; INSTANCE = this;
} }
public static LogAppender getInstance() {
return INSTANCE;
}
@PluginFactory
public static LogAppender createAppender(
@PluginAttribute("name") String name,
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filter") final Filter filter,
@PluginAttribute("otherAttribute") String otherAttribute) {
if (name == null) {
LOGGER.error("No name provided for MyCustomAppenderImpl");
return null;
}
if (layout == null) {
layout = PatternLayout.createDefaultLayout();
}
return new LogAppender(name, filter, layout, true, Property.EMPTY_ARRAY);
}
@Override @Override
public void append(LogEvent event) { public void append(LogEvent event) {
try { try {
@ -47,24 +68,4 @@ public void addListener(Consumer<LogEvent> consumer) {
public void removeListener(Consumer<LogEvent> consumer) { public void removeListener(Consumer<LogEvent> consumer) {
set.remove(consumer); set.remove(consumer);
} }
public static LogAppender getInstance() {
return INSTANCE;
}
@PluginFactory
public static LogAppender createAppender(
@PluginAttribute("name") String name,
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filter") final Filter filter,
@PluginAttribute("otherAttribute") String otherAttribute) {
if (name == null) {
LOGGER.error("No name provided for MyCustomAppenderImpl");
return null;
}
if (layout == null) {
layout = PatternLayout.createDefaultLayout();
}
return new LogAppender(name, filter, layout, true, Property.EMPTY_ARRAY);
}
} }

View file

@ -9,7 +9,6 @@
import pro.gravit.launchserver.asm.InjectClassAcceptor; import pro.gravit.launchserver.asm.InjectClassAcceptor;
import pro.gravit.launchserver.binary.tasks.MainBuildTask; import pro.gravit.launchserver.binary.tasks.MainBuildTask;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;

View file

@ -3,7 +3,6 @@
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import pro.gravit.utils.command.Command; import pro.gravit.utils.command.Command;
import pro.gravit.utils.helper.LogHelper;
public class SyncLauncherModulesCommand extends Command { public class SyncLauncherModulesCommand extends Command {
private final LauncherModuleLoader mod; private final LauncherModuleLoader mod;

View file

@ -38,6 +38,7 @@ public AuthManager(LaunchServer server) {
/** /**
* Create AuthContext * Create AuthContext
*
* @return AuthContext instance * @return AuthContext instance
*/ */
public AuthResponse.AuthContext makeAuthContext(Client client, AuthResponse.ConnectTypes authType, AuthProviderPair pair, String login, String profileName, String ip) { public AuthResponse.AuthContext makeAuthContext(Client client, AuthResponse.ConnectTypes authType, AuthProviderPair pair, String login, String profileName, String ip) {
@ -49,6 +50,7 @@ public AuthResponse.AuthContext makeAuthContext(Client client, AuthResponse.Conn
/** /**
* Validate auth params ans state * Validate auth params ans state
*
* @param context Auth context * @param context Auth context
* @throws AuthException auth not possible * @throws AuthException auth not possible
*/ */
@ -63,38 +65,9 @@ public void check(AuthResponse.AuthContext context) throws AuthException {
} }
} }
public static class AuthReport {
public final String minecraftAccessToken;
public final String oauthAccessToken;
public final String oauthRefreshToken;
public final long oauthExpire;
private AuthReport(String minecraftAccessToken, String oauthAccessToken, String oauthRefreshToken, long oauthExpire) {
this.minecraftAccessToken = minecraftAccessToken;
this.oauthAccessToken = oauthAccessToken;
this.oauthRefreshToken = oauthRefreshToken;
this.oauthExpire = oauthExpire;
}
public static AuthReport ofOAuth(String oauthAccessToken, String oauthRefreshToken, long oauthExpire) {
return new AuthReport(null, oauthAccessToken, oauthRefreshToken, oauthExpire);
}
public static AuthReport ofOAuthWithMinecraft(String minecraftAccessToken, String oauthAccessToken, String oauthRefreshToken, long oauthExpire) {
return new AuthReport(minecraftAccessToken, oauthAccessToken, oauthRefreshToken, oauthExpire);
}
public static AuthReport ofMinecraftAccessToken(String minecraftAccessToken) {
return new AuthReport(minecraftAccessToken, null, null, 0);
}
public boolean isUsingOAuth() {
return oauthAccessToken != null || oauthRefreshToken != null;
}
}
/** /**
* Full client authorization with password verification * Full client authorization with password verification
*
* @param context AuthContext * @param context AuthContext
* @param password User password * @param password User password
* @return Access token * @return Access token
@ -176,8 +149,7 @@ private AuthReport authWithCore(AuthResponse.AuthContext context, AuthRequest.Au
context.client.coreObject = user; context.client.coreObject = user;
internalAuth(context.client, context.authType, context.pair, user.getUsername(), uuid, user.getPermissions(), result.isUsingOAuth()); internalAuth(context.client, context.authType, context.pair, user.getUsername(), uuid, user.getPermissions(), result.isUsingOAuth());
return result; return result;
} } else {
else {
if (report.needMoreFactor) { if (report.needMoreFactor) {
if (report.factors.size() == 1 && report.factors.get(0) == -1) { if (report.factors.size() == 1 && report.factors.get(0) == -1) {
throw new AuthException(AuthRequestEvent.TWO_FACTOR_NEED_ERROR_MESSAGE); throw new AuthException(AuthRequestEvent.TWO_FACTOR_NEED_ERROR_MESSAGE);
@ -211,8 +183,7 @@ public UUID checkServer(Client client, String username, String serverID) throws
if (client.auth == null) return null; if (client.auth == null) return null;
if (client.auth.isUseCore()) { if (client.auth.isUseCore()) {
return client.auth.core.checkServer(client, username, serverID); return client.auth.core.checkServer(client, username, serverID);
} } else {
else {
return client.auth.handler.checkServer(username, serverID); return client.auth.handler.checkServer(username, serverID);
} }
} }
@ -231,16 +202,14 @@ public AuthRequest.AuthPasswordInterface decryptPassword(AuthRequest.AuthPasswor
Auth2FAPassword auth2FAPassword = (Auth2FAPassword) password; Auth2FAPassword auth2FAPassword = (Auth2FAPassword) password;
auth2FAPassword.firstPassword = tryDecryptPasswordPlain(auth2FAPassword.firstPassword); auth2FAPassword.firstPassword = tryDecryptPasswordPlain(auth2FAPassword.firstPassword);
auth2FAPassword.secondPassword = tryDecryptPasswordPlain(auth2FAPassword.secondPassword); auth2FAPassword.secondPassword = tryDecryptPasswordPlain(auth2FAPassword.secondPassword);
} } else if (password instanceof AuthMultiPassword) {
else if(password instanceof AuthMultiPassword) {
AuthMultiPassword multiPassword = (AuthMultiPassword) password; AuthMultiPassword multiPassword = (AuthMultiPassword) password;
List<AuthRequest.AuthPasswordInterface> list = new ArrayList<>(multiPassword.list.size()); List<AuthRequest.AuthPasswordInterface> list = new ArrayList<>(multiPassword.list.size());
for (AuthRequest.AuthPasswordInterface p : multiPassword.list) { for (AuthRequest.AuthPasswordInterface p : multiPassword.list) {
list.add(tryDecryptPasswordPlain(p)); list.add(tryDecryptPasswordPlain(p));
} }
multiPassword.list = list; multiPassword.list = list;
} } else {
else {
password = tryDecryptPasswordPlain(password); password = tryDecryptPasswordPlain(password);
} }
return password; return password;
@ -276,4 +245,34 @@ private AuthRequest.AuthPasswordInterface tryDecryptPasswordPlain(AuthRequest.Au
} }
return password; return password;
} }
public static class AuthReport {
public final String minecraftAccessToken;
public final String oauthAccessToken;
public final String oauthRefreshToken;
public final long oauthExpire;
private AuthReport(String minecraftAccessToken, String oauthAccessToken, String oauthRefreshToken, long oauthExpire) {
this.minecraftAccessToken = minecraftAccessToken;
this.oauthAccessToken = oauthAccessToken;
this.oauthRefreshToken = oauthRefreshToken;
this.oauthExpire = oauthExpire;
}
public static AuthReport ofOAuth(String oauthAccessToken, String oauthRefreshToken, long oauthExpire) {
return new AuthReport(null, oauthAccessToken, oauthRefreshToken, oauthExpire);
}
public static AuthReport ofOAuthWithMinecraft(String minecraftAccessToken, String oauthAccessToken, String oauthRefreshToken, long oauthExpire) {
return new AuthReport(minecraftAccessToken, oauthAccessToken, oauthRefreshToken, oauthExpire);
}
public static AuthReport ofMinecraftAccessToken(String minecraftAccessToken) {
return new AuthReport(minecraftAccessToken, null, null, 0);
}
public boolean isUsingOAuth() {
return oauthAccessToken != null || oauthRefreshToken != null;
}
}
} }

View file

@ -25,7 +25,6 @@
import pro.gravit.launcher.LauncherTrustManager; import pro.gravit.launcher.LauncherTrustManager;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.JVMHelper;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.SecurityHelper;
import java.io.*; import java.io.*;
@ -50,13 +49,13 @@
public class CertificateManager { public class CertificateManager {
public final int validDays = 60; public final int validDays = 60;
public final int minusHours = 6; public final int minusHours = 6;
private transient final Logger logger = LogManager.getLogger();
public X509CertificateHolder ca; public X509CertificateHolder ca;
public AsymmetricKeyParameter caKey; public AsymmetricKeyParameter caKey;
public X509CertificateHolder server; public X509CertificateHolder server;
public AsymmetricKeyParameter serverKey; public AsymmetricKeyParameter serverKey;
public LauncherTrustManager trustManager; public LauncherTrustManager trustManager;
public String orgName; public String orgName;
private transient final Logger logger = LogManager.getLogger();
public X509CertificateHolder generateCertificate(String subjectName, PublicKey subjectPublicKey) throws OperatorCreationException { public X509CertificateHolder generateCertificate(String subjectName, PublicKey subjectPublicKey) throws OperatorCreationException {
SubjectPublicKeyInfo subjectPubKeyInfo = SubjectPublicKeyInfo.getInstance(subjectPublicKey.getEncoded()); SubjectPublicKeyInfo subjectPubKeyInfo = SubjectPublicKeyInfo.getInstance(subjectPublicKey.getEncoded());

View file

@ -3,12 +3,12 @@
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.SecurityHelper;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.*; import java.security.KeyPair;
import java.security.SecureRandom;
import java.security.interfaces.ECPrivateKey; import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey; import java.security.interfaces.ECPublicKey;
import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPrivateKey;

View file

@ -6,7 +6,6 @@
import pro.gravit.launcher.HTTPRequest; import pro.gravit.launcher.HTTPRequest;
import pro.gravit.utils.HttpDownloader; import pro.gravit.utils.HttpDownloader;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@ -17,8 +16,8 @@
public class MirrorManager { public class MirrorManager {
protected final ArrayList<Mirror> list = new ArrayList<>(); protected final ArrayList<Mirror> list = new ArrayList<>();
private Mirror defaultMirror;
private transient final Logger logger = LogManager.getLogger(); private transient final Logger logger = LogManager.getLogger();
private Mirror defaultMirror;
public void addMirror(String mirror) { public void addMirror(String mirror) {
Mirror m = new Mirror(mirror); Mirror m = new Mirror(mirror);

View file

@ -23,7 +23,6 @@
import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler; import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler;
import pro.gravit.launchserver.socket.handlers.fileserver.FileServerHandler; import pro.gravit.launchserver.socket.handlers.fileserver.FileServerHandler;
import pro.gravit.utils.BiHookSet; import pro.gravit.utils.BiHookSet;
import pro.gravit.utils.helper.LogHelper;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;

View file

@ -3,7 +3,6 @@
import io.netty.util.concurrent.DefaultThreadFactory; import io.netty.util.concurrent.DefaultThreadFactory;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import pro.gravit.utils.helper.LogHelper;
public class NettyThreadFactory extends DefaultThreadFactory { public class NettyThreadFactory extends DefaultThreadFactory {
private transient final Logger logger = LogManager.getLogger(); private transient final Logger logger = LogManager.getLogger();

View file

@ -38,7 +38,6 @@
import pro.gravit.utils.BiHookSet; import pro.gravit.utils.BiHookSet;
import pro.gravit.utils.ProviderMap; import pro.gravit.utils.ProviderMap;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.UUID; import java.util.UUID;

View file

@ -5,7 +5,6 @@
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.config.LaunchServerConfig;
import pro.gravit.launchserver.socket.LauncherNettyServer; import pro.gravit.launchserver.socket.LauncherNettyServer;
import pro.gravit.utils.helper.LogHelper;
import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.SSLServerSocketFactory;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -13,10 +12,9 @@
@SuppressWarnings("unused") @SuppressWarnings("unused")
public final class NettyServerSocketHandler implements Runnable, AutoCloseable { public final class NettyServerSocketHandler implements Runnable, AutoCloseable {
private transient final LaunchServer server; private transient final LaunchServer server;
private transient final Logger logger = LogManager.getLogger();
@Deprecated @Deprecated
public volatile boolean logConnections = Boolean.getBoolean("launcher.logConnections"); public volatile boolean logConnections = Boolean.getBoolean("launcher.logConnections");
private transient final Logger logger = LogManager.getLogger();
public LauncherNettyServer nettyServer; public LauncherNettyServer nettyServer;
private SSLServerSocketFactory ssf; private SSLServerSocketFactory ssf;

View file

@ -9,7 +9,6 @@
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import pro.gravit.launcher.Launcher; import pro.gravit.launcher.Launcher;
import pro.gravit.launchserver.socket.NettyConnectContext; import pro.gravit.launchserver.socket.NettyConnectContext;
import pro.gravit.utils.helper.LogHelper;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -18,7 +17,6 @@
import java.util.Map; import java.util.Map;
import java.util.TreeSet; import java.util.TreeSet;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
public class NettyWebAPIHandler extends SimpleChannelInboundHandler<FullHttpRequest> { public class NettyWebAPIHandler extends SimpleChannelInboundHandler<FullHttpRequest> {

View file

@ -13,7 +13,6 @@
import pro.gravit.launchserver.socket.WebSocketService; import pro.gravit.launchserver.socket.WebSocketService;
import pro.gravit.utils.BiHookSet; import pro.gravit.utils.BiHookSet;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;

View file

@ -7,7 +7,6 @@
import io.netty.handler.stream.ChunkedFile; import io.netty.handler.stream.ChunkedFile;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
import pro.gravit.launchserver.socket.handlers.ContentType; import pro.gravit.launchserver.socket.handlers.ContentType;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.VerifyHelper; import pro.gravit.utils.helper.VerifyHelper;
import java.io.File; import java.io.File;

View file

@ -5,28 +5,14 @@
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import pro.gravit.launcher.events.request.AuthRequestEvent; import pro.gravit.launcher.events.request.AuthRequestEvent;
import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.AuthRequest;
import pro.gravit.launcher.request.auth.password.*;
import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.auth.AuthException;
import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.AuthProviderPair;
import pro.gravit.launchserver.auth.provider.AuthProvider;
import pro.gravit.launchserver.auth.provider.AuthProviderDAOResult;
import pro.gravit.launchserver.auth.provider.AuthProviderResult;
import pro.gravit.launchserver.manangers.AuthManager; import pro.gravit.launchserver.manangers.AuthManager;
import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.Client;
import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.launchserver.socket.response.SimpleResponse;
import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse; import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse;
import pro.gravit.utils.HookException; import pro.gravit.utils.HookException;
import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.SecurityHelper;
import pro.gravit.utils.helper.VerifyHelper;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import java.security.SecureRandom;
import java.util.Random;
import java.util.UUID; import java.util.UUID;
public class AuthResponse extends SimpleResponse { public class AuthResponse extends SimpleResponse {

View file

@ -9,13 +9,12 @@
import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.launchserver.socket.response.SimpleResponse;
import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse; import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse;
import pro.gravit.utils.HookException; import pro.gravit.utils.HookException;
import pro.gravit.utils.helper.LogHelper;
public class CheckServerResponse extends SimpleResponse { public class CheckServerResponse extends SimpleResponse {
private transient final Logger logger = LogManager.getLogger();
public String serverID; public String serverID;
public String username; public String username;
public String client; public String client;
private transient final Logger logger = LogManager.getLogger();
@Override @Override
public String getType() { public String getType() {

View file

@ -9,13 +9,12 @@
import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.Client;
import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.launchserver.socket.response.SimpleResponse;
import pro.gravit.utils.HookException; import pro.gravit.utils.HookException;
import pro.gravit.utils.helper.LogHelper;
public class JoinServerResponse extends SimpleResponse { public class JoinServerResponse extends SimpleResponse {
private transient final Logger logger = LogManager.getLogger();
public String serverID; public String serverID;
public String accessToken; public String accessToken;
public String username; public String username;
private transient final Logger logger = LogManager.getLogger();
@Override @Override
public String getType() { public String getType() {

View file

@ -19,22 +19,19 @@
import java.util.Map; import java.util.Map;
public class RestoreResponse extends SimpleResponse { public class RestoreResponse extends SimpleResponse {
@FunctionalInterface
public interface ExtendedTokenProvider {
boolean accept(Client client, AuthProviderPair pair, String extendedToken);
}
public static Map<String, ExtendedTokenProvider> providers = new HashMap<>(); public static Map<String, ExtendedTokenProvider> providers = new HashMap<>();
private static boolean registeredProviders = false; private static boolean registeredProviders = false;
public String authId;
public String accessToken;
public Map<String, String> extended;
public boolean needUserInfo;
public static void registerProviders(LaunchServer server) { public static void registerProviders(LaunchServer server) {
if (!registeredProviders) { if (!registeredProviders) {
providers.put(LauncherRequestEvent.LAUNCHER_EXTENDED_TOKEN_NAME, new LauncherResponse.LauncherTokenVerifier(server)); providers.put(LauncherRequestEvent.LAUNCHER_EXTENDED_TOKEN_NAME, new LauncherResponse.LauncherTokenVerifier(server));
registeredProviders = true; registeredProviders = true;
} }
} }
public String authId;
public String accessToken;
public Map<String, String> extended;
public boolean needUserInfo;
@Override @Override
public String getType() { public String getType() {
@ -94,4 +91,9 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception {
sendResult(new RestoreRequestEvent(invalidTokens)); sendResult(new RestoreRequestEvent(invalidTokens));
} }
} }
@FunctionalInterface
public interface ExtendedTokenProvider {
boolean accept(Client client, AuthProviderPair pair, String extendedToken);
}
} }

View file

@ -61,8 +61,7 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception {
if (user == null) { if (user == null) {
sendError("User not found"); sendError("User not found");
return; return;
} } else username = user.getUsername();
else username = user.getUsername();
} else { } else {
username = pair.handler.uuidToUsername(uuid); username = pair.handler.uuidToUsername(uuid);
if (username == null) { if (username == null) {

View file

@ -1,6 +1,8 @@
package pro.gravit.launchserver.socket.response.update; package pro.gravit.launchserver.socket.response.update;
import io.jsonwebtoken.*; import io.jsonwebtoken.JwtParser;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -74,6 +76,14 @@ public String createLauncherExtendedToken() {
.compact(); .compact();
} }
private boolean checkSecure(String hash, String salt) {
if (hash == null || salt == null) return false;
byte[] normal_hash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256,
server.runtime.clientCheckSecret.concat(".").concat(salt));
byte[] launcher_hash = Base64.getDecoder().decode(hash);
return Arrays.equals(normal_hash, launcher_hash);
}
public static class LauncherTokenVerifier implements RestoreResponse.ExtendedTokenProvider { public static class LauncherTokenVerifier implements RestoreResponse.ExtendedTokenProvider {
private final LaunchServer server; private final LaunchServer server;
private final JwtParser parser; private final JwtParser parser;
@ -102,12 +112,4 @@ public boolean accept(Client client, AuthProviderPair pair, String extendedToken
} }
} }
private boolean checkSecure(String hash, String salt) {
if (hash == null || salt == null) return false;
byte[] normal_hash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256,
server.runtime.clientCheckSecret.concat(".").concat(salt));
byte[] launcher_hash = Base64.getDecoder().decode(hash);
return Arrays.equals(normal_hash, launcher_hash);
}
} }

View file

@ -2,7 +2,8 @@
<Configuration status="INFO" packages="pro.gravit.launchserver.config.log4j"> <Configuration status="INFO" packages="pro.gravit.launchserver.config.log4j">
<Appenders> <Appenders>
<Console name="Console" target="SYSTEM_OUT"> <Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} %highlight{[%-5level]}{FATAL=red, ERROR=red, WARN=yellow, INFO=default, DEBUG=green, TRACE=blue} %highlight{%msg}{FATAL=red, ERROR=red, WARN=yellow, INFO=default, DEBUG=green, TRACE=blue}%n" /> <PatternLayout
pattern="%d{HH:mm:ss.SSS} %highlight{[%-5level]}{FATAL=red, ERROR=red, WARN=yellow, INFO=default, DEBUG=green, TRACE=blue} %highlight{%msg}{FATAL=red, ERROR=red, WARN=yellow, INFO=default, DEBUG=green, TRACE=blue}%n"/>
<Filters> <Filters>
<MarkerFilter marker="JANSI" onMatch="ACCEPT" onMismatch="NEUTRAL"/> <MarkerFilter marker="JANSI" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
<MarkerFilter marker="NOJANSI" onMatch="DENY" onMismatch="NEUTRAL"/> <MarkerFilter marker="NOJANSI" onMatch="DENY" onMismatch="NEUTRAL"/>

View file

@ -25,11 +25,7 @@
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.KeyPair;
import java.security.SecureRandom;
import java.security.Security; import java.security.Security;
import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey;
public class ConfigurationTest { public class ConfigurationTest {
@TempDir @TempDir
@ -61,6 +57,7 @@ public static void prepare() throws Throwable {
.setCommandHandler(new StdCommandHandler(false)); .setCommandHandler(new StdCommandHandler(false));
launchServer = builder.build(); launchServer = builder.build();
} }
@Test @Test
public void reloadTest() throws Exception { public void reloadTest() throws Exception {
AuthProvider provider = new AuthProvider() { AuthProvider provider = new AuthProvider() {

View file

@ -13,14 +13,9 @@
import pro.gravit.launchserver.manangers.LaunchServerGsonManager; import pro.gravit.launchserver.manangers.LaunchServerGsonManager;
import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager; import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager;
import pro.gravit.utils.command.StdCommandHandler; import pro.gravit.utils.command.StdCommandHandler;
import pro.gravit.utils.helper.SecurityHelper;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.KeyPair;
import java.security.SecureRandom;
import java.security.Security; import java.security.Security;
import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey;
public class StartLaunchServerTest { public class StartLaunchServerTest {
@TempDir @TempDir

View file

@ -9,6 +9,13 @@
public class TestLaunchServerConfigManager implements LaunchServer.LaunchServerConfigManager { public class TestLaunchServerConfigManager implements LaunchServer.LaunchServerConfigManager {
public LaunchServerConfig config; public LaunchServerConfig config;
public LaunchServerRuntimeConfig runtimeConfig; public LaunchServerRuntimeConfig runtimeConfig;
public TestLaunchServerConfigManager() {
config = LaunchServerConfig.getDefault(LaunchServer.LaunchServerEnv.TEST);
runtimeConfig = new LaunchServerRuntimeConfig();
runtimeConfig.reset();
}
@Override @Override
public LaunchServerConfig readConfig() throws IOException { public LaunchServerConfig readConfig() throws IOException {
return config; return config;
@ -28,10 +35,4 @@ public void writeConfig(LaunchServerConfig config) throws IOException {
public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOException { public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOException {
} }
public TestLaunchServerConfigManager() {
config = LaunchServerConfig.getDefault(LaunchServer.LaunchServerEnv.TEST);
runtimeConfig = new LaunchServerRuntimeConfig();
runtimeConfig.reset();
}
} }

View file

@ -2,7 +2,8 @@
<Configuration status="INFO"> <Configuration status="INFO">
<Appenders> <Appenders>
<Console name="Console" target="SYSTEM_OUT"> <Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} %highlight{[%-5level]}{FATAL=red, ERROR=red, WARN=yellow, INFO=default, DEBUG=green, TRACE=blue} %highlight{%msg}{FATAL=red, ERROR=red, WARN=yellow, INFO=default, DEBUG=green, TRACE=blue}%n" /> <PatternLayout
pattern="%d{HH:mm:ss.SSS} %highlight{[%-5level]}{FATAL=red, ERROR=red, WARN=yellow, INFO=default, DEBUG=green, TRACE=blue} %highlight{%msg}{FATAL=red, ERROR=red, WARN=yellow, INFO=default, DEBUG=green, TRACE=blue}%n"/>
</Console> </Console>
</Appenders> </Appenders>
<Loggers> <Loggers>

View file

@ -293,6 +293,7 @@ public static boolean isExistExtJavaLibrary(Path jvmDir, String name) {
return IOHelper.isFile(jrePath) || IOHelper.isFile(jdkPath); return IOHelper.isFile(jrePath) || IOHelper.isFile(jdkPath);
} }
} }
public static class ClientLauncherWrapperContext { public static class ClientLauncherWrapperContext {
public JavaVersion javaVersion; public JavaVersion javaVersion;
public Path executePath; public Path executePath;
@ -305,6 +306,7 @@ public static class ClientLauncherWrapperContext {
public List<String> jvmModules = new ArrayList<>(); public List<String> jvmModules = new ArrayList<>();
public List<String> clientArgs = new ArrayList<>(); public List<String> clientArgs = new ArrayList<>();
public List<Path> javaFXPaths = new ArrayList<>(); public List<Path> javaFXPaths = new ArrayList<>();
public void addSystemProperty(String name) { public void addSystemProperty(String name) {
String property = System.getProperty(name); String property = System.getProperty(name);
if (property != null) if (property != null)

View file

@ -18,7 +18,6 @@
import pro.gravit.launcher.request.RequestException; import pro.gravit.launcher.request.RequestException;
import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.AuthRequest;
import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest; import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest;
import pro.gravit.launcher.request.auth.RestoreSessionRequest;
import pro.gravit.launcher.request.websockets.StdWebSocketService; import pro.gravit.launcher.request.websockets.StdWebSocketService;
import pro.gravit.launcher.utils.NativeJVMHalt; import pro.gravit.launcher.utils.NativeJVMHalt;
import pro.gravit.utils.helper.*; import pro.gravit.utils.helper.*;
@ -40,12 +39,12 @@ public class LauncherEngine {
public static ClientLauncherProcess.ClientParams clientParams; public static ClientLauncherProcess.ClientParams clientParams;
public static LauncherGuardInterface guard; public static LauncherGuardInterface guard;
public static ClientModuleManager modulesManager; public static ClientModuleManager modulesManager;
public final boolean clientInstance;
// Instance // Instance
private final AtomicBoolean started = new AtomicBoolean(false); private final AtomicBoolean started = new AtomicBoolean(false);
public RuntimeProvider runtimeProvider; public RuntimeProvider runtimeProvider;
public ECPublicKey publicKey; public ECPublicKey publicKey;
public ECPrivateKey privateKey; public ECPrivateKey privateKey;
public final boolean clientInstance;
private LauncherEngine(boolean clientInstance) { private LauncherEngine(boolean clientInstance) {

View file

@ -23,7 +23,6 @@
import pro.gravit.launcher.request.RequestException; import pro.gravit.launcher.request.RequestException;
import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.AuthRequest;
import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest; import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest;
import pro.gravit.launcher.request.auth.RestoreSessionRequest;
import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HInput;
import pro.gravit.launcher.utils.DirWatcher; import pro.gravit.launcher.utils.DirWatcher;
import pro.gravit.utils.helper.*; import pro.gravit.utils.helper.*;

View file

@ -7,7 +7,6 @@
import pro.gravit.launcher.modules.impl.SimpleModuleManager; import pro.gravit.launcher.modules.impl.SimpleModuleManager;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collection;
public final class ClientModuleManager extends SimpleModuleManager { public final class ClientModuleManager extends SimpleModuleManager {
public ClientModuleManager() { public ClientModuleManager() {

View file

@ -2,8 +2,6 @@
import pro.gravit.launcher.ClientLauncherWrapper; import pro.gravit.launcher.ClientLauncherWrapper;
import java.util.Collection;
public interface ClientWrapperModule { public interface ClientWrapperModule {
void wrapperPhase(ClientLauncherWrapper.ClientLauncherWrapperContext context); void wrapperPhase(ClientLauncherWrapper.ClientLauncherWrapperContext context);
} }

View file

@ -29,8 +29,6 @@ public final class LauncherConfig extends StreamObject {
@LauncherInject("launcher.port") @LauncherInject("launcher.port")
public final int clientPort; public final int clientPort;
public final LauncherTrustManager trustManager; public final LauncherTrustManager trustManager;
@Deprecated
public ECPublicKey publicKey = null;
public final ECPublicKey ecdsaPublicKey; public final ECPublicKey ecdsaPublicKey;
public final RSAPublicKey rsaPublicKey; public final RSAPublicKey rsaPublicKey;
public final Map<String, byte[]> runtime; public final Map<String, byte[]> runtime;
@ -48,6 +46,8 @@ public final class LauncherConfig extends StreamObject {
public final String runtimeEncryptKey; public final String runtimeEncryptKey;
@LauncherInject("launcher.address") @LauncherInject("launcher.address")
public final String address; public final String address;
@Deprecated
public ECPublicKey publicKey = null;
@LauncherInject("runtimeconfig.secretKeyClient") @LauncherInject("runtimeconfig.secretKeyClient")
public String secretKeyClient; public String secretKeyClient;
@LauncherInject("runtimeconfig.oemUnlockKey") @LauncherInject("runtimeconfig.oemUnlockKey")

View file

@ -61,6 +61,11 @@ public AuthRequestEvent(ClientPermissions permissions, PlayerProfile playerProfi
this.oauth = oauth; this.oauth = oauth;
} }
@Override
public String getType() {
return "auth";
}
public static class OAuthRequestEvent { public static class OAuthRequestEvent {
public final String accessToken; public final String accessToken;
public final String refreshToken; public final String refreshToken;
@ -72,9 +77,4 @@ public OAuthRequestEvent(String accessToken, String refreshToken, long expire) {
this.expire = expire; this.expire = expire;
} }
} }
@Override
public String getType() {
return "auth";
}
} }

View file

@ -36,7 +36,11 @@ public enum ServerFeature {
} }
} }
public interface AuthAvailabilityDetails extends TypeSerializeInterface {
}
public static class AuthAvailability { public static class AuthAvailability {
public final List<AuthAvailabilityDetails> details;
@LauncherNetworkAPI @LauncherNetworkAPI
public String name; public String name;
@LauncherNetworkAPI @LauncherNetworkAPI
@ -48,8 +52,6 @@ public static class AuthAvailability {
@LauncherNetworkAPI @LauncherNetworkAPI
public AuthType secondType; public AuthType secondType;
public final List<AuthAvailabilityDetails> details;
@Deprecated @Deprecated
public AuthAvailability(String name, String displayName, AuthType firstType, AuthType secondType) { public AuthAvailability(String name, String displayName, AuthType firstType, AuthType secondType) {
this.name = name; this.name = name;
@ -81,6 +83,4 @@ public enum AuthType {
OTHER OTHER
} }
} }
public interface AuthAvailabilityDetails extends TypeSerializeInterface {
}
} }

View file

@ -7,9 +7,9 @@
public class LauncherRequestEvent extends RequestEvent { public class LauncherRequestEvent extends RequestEvent {
public static final String LAUNCHER_EXTENDED_TOKEN_NAME = "launcher";
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static final UUID uuid = UUID.fromString("d54cc12a-4f59-4f23-9b10-f527fdd2e38f"); private static final UUID uuid = UUID.fromString("d54cc12a-4f59-4f23-9b10-f527fdd2e38f");
public static final String LAUNCHER_EXTENDED_TOKEN_NAME = "launcher";
@LauncherNetworkAPI @LauncherNetworkAPI
public String url; public String url;
@LauncherNetworkAPI @LauncherNetworkAPI

View file

@ -5,26 +5,15 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
public abstract class LauncherModule { public abstract class LauncherModule {
protected final LauncherModuleInfo moduleInfo; protected final LauncherModuleInfo moduleInfo;
private final static class EventEntity<T extends Event> {
final Class<T> clazz;
final EventHandler<T> handler;
private EventEntity(EventHandler<T> handler, Class<T> clazz) {
this.clazz = clazz;
this.handler = handler;
}
}
private final List<EventEntity<? extends Event>> eventList = new ArrayList<>(4); private final List<EventEntity<? extends Event>> eventList = new ArrayList<>(4);
protected LauncherModulesManager modulesManager; protected LauncherModulesManager modulesManager;
protected ModulesConfigManager modulesConfigManager; protected ModulesConfigManager modulesConfigManager;
protected InitStatus initStatus = InitStatus.CREATED; protected InitStatus initStatus = InitStatus.CREATED;
private LauncherModulesContext context; private LauncherModulesContext context;
private LauncherTrustManager.CheckClassResult checkResult; private LauncherTrustManager.CheckClassResult checkResult;
protected LauncherModule() { protected LauncherModule() {
moduleInfo = new LauncherModuleInfo("UnknownModule"); moduleInfo = new LauncherModuleInfo("UnknownModule");
} }
@ -70,6 +59,17 @@ public final LauncherTrustManager.CheckClassResult getCheckResult() {
return new LauncherTrustManager.CheckClassResult(this.checkResult); return new LauncherTrustManager.CheckClassResult(this.checkResult);
} }
/**
* The internal method used by the ModuleManager
* DO NOT TOUCH
*
* @param result Check result
*/
public final void setCheckResult(LauncherTrustManager.CheckClassResult result) {
if (this.checkResult != null) throw new IllegalStateException("Module already set check result");
this.checkResult = result;
}
protected final LauncherModule requireModule(String name, Version minVersion) { protected final LauncherModule requireModule(String name, Version minVersion) {
if (context == null) throw new IllegalStateException("requireModule must be used in init() phase"); if (context == null) throw new IllegalStateException("requireModule must be used in init() phase");
LauncherModule module = context.getModulesManager().getModule(name); LauncherModule module = context.getModulesManager().getModule(name);
@ -91,17 +91,6 @@ else if(module.moduleInfo.version.isLowerThan(minVersion))
throw new RuntimeException(String.format("Module %s required %s v%s or higher (current version %s)", moduleInfo.name, requiredModuleName, minVersion.getVersionString(), module.moduleInfo.version.getVersionString())); throw new RuntimeException(String.format("Module %s required %s v%s or higher (current version %s)", moduleInfo.name, requiredModuleName, minVersion.getVersionString(), module.moduleInfo.version.getVersionString()));
} }
/**
* The internal method used by the ModuleManager
* DO NOT TOUCH
*
* @param result Check result
*/
public final void setCheckResult(LauncherTrustManager.CheckClassResult result) {
if (this.checkResult != null) throw new IllegalStateException("Module already set check result");
this.checkResult = result;
}
/** /**
* This method is called before initializing all modules and resolving dependencies. * This method is called before initializing all modules and resolving dependencies.
* <b>You can</b>: * <b>You can</b>:
@ -213,12 +202,21 @@ public boolean isAvailable() {
} }
} }
@FunctionalInterface @FunctionalInterface
public interface EventHandler<T extends Event> { public interface EventHandler<T extends Event> {
void event(T e); void event(T e);
} }
private final static class EventEntity<T extends Event> {
final Class<T> clazz;
final EventHandler<T> handler;
private EventEntity(EventHandler<T> handler, Class<T> clazz) {
this.clazz = clazz;
this.handler = handler;
}
}
public static class Event { public static class Event {
protected boolean cancel = false; protected boolean cancel = false;

View file

@ -2,7 +2,6 @@
import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.FileNameMatcher;
import pro.gravit.launcher.hasher.HashedDir;
import pro.gravit.launcher.profiles.optional.OptionalDepend; import pro.gravit.launcher.profiles.optional.OptionalDepend;
import pro.gravit.launcher.profiles.optional.OptionalFile; import pro.gravit.launcher.profiles.optional.OptionalFile;
import pro.gravit.launcher.profiles.optional.OptionalTrigger; import pro.gravit.launcher.profiles.optional.OptionalTrigger;
@ -83,6 +82,59 @@ public final class ClientProfile implements Comparable<ClientProfile> {
@LauncherNetworkAPI @LauncherNetworkAPI
private String mainClass; private String mainClass;
public ClientProfile() {
update = new ArrayList<>();
updateExclusions = new ArrayList<>();
updateShared = new ArrayList<>();
updateVerify = new ArrayList<>();
updateOptional = new HashSet<>();
jvmArgs = new ArrayList<>();
classPath = new ArrayList<>();
altClassPath = new ArrayList<>();
clientArgs = new ArrayList<>();
compatClasses = new ArrayList<>();
properties = new HashMap<>();
servers = new ArrayList<>(1);
securityManagerConfig = SecurityManagerConfig.CLIENT;
classLoaderConfig = ClassLoaderConfig.LAUNCHER;
signedClientConfig = SignedClientConfig.NONE;
runtimeInClientConfig = RuntimeInClientConfig.NONE;
}
public ClientProfile(List<String> update, List<String> updateExclusions, List<String> updateShared, List<String> updateVerify, Set<OptionalFile> updateOptional, List<String> jvmArgs, List<String> classPath, List<String> altClassPath, List<String> clientArgs, List<String> compatClasses, Map<String, String> properties, List<ServerProfile> servers, SecurityManagerConfig securityManagerConfig, ClassLoaderConfig classLoaderConfig, SignedClientConfig signedClientConfig, RuntimeInClientConfig runtimeInClientConfig, String version, String assetIndex, String dir, String assetDir, int recommendJavaVersion, int minJavaVersion, int maxJavaVersion, boolean warnMissJavaVersion, ProfileDefaultSettings settings, int sortIndex, UUID uuid, String title, String info, boolean updateFastCheck, String mainClass) {
this.update = update;
this.updateExclusions = updateExclusions;
this.updateShared = updateShared;
this.updateVerify = updateVerify;
this.updateOptional = updateOptional;
this.jvmArgs = jvmArgs;
this.classPath = classPath;
this.altClassPath = altClassPath;
this.clientArgs = clientArgs;
this.compatClasses = compatClasses;
this.properties = properties;
this.servers = servers;
this.securityManagerConfig = securityManagerConfig;
this.classLoaderConfig = classLoaderConfig;
this.signedClientConfig = signedClientConfig;
this.runtimeInClientConfig = runtimeInClientConfig;
this.version = version;
this.assetIndex = assetIndex;
this.dir = dir;
this.assetDir = assetDir;
this.recommendJavaVersion = recommendJavaVersion;
this.minJavaVersion = minJavaVersion;
this.maxJavaVersion = maxJavaVersion;
this.warnMissJavaVersion = warnMissJavaVersion;
this.settings = settings;
this.sortIndex = sortIndex;
this.uuid = uuid;
this.title = title;
this.info = info;
this.updateFastCheck = updateFastCheck;
this.mainClass = mainClass;
}
public ServerProfile getDefaultServerProfile() { public ServerProfile getDefaultServerProfile() {
for (ServerProfile profile : servers) { for (ServerProfile profile : servers) {
if (profile.isDefault) return profile; if (profile.isDefault) return profile;
@ -205,8 +257,6 @@ public void updateOptionalGraph() {
} }
} }
@Deprecated @Deprecated
public OptionalFile getOptionalFile(String file, OptionalType type) { public OptionalFile getOptionalFile(String file, OptionalType type) {
for (OptionalFile f : updateOptional) for (OptionalFile f : updateOptional)
@ -406,8 +456,6 @@ public void setRuntimeInClientConfig(RuntimeInClientConfig runtimeInClientConfig
this.runtimeInClientConfig = runtimeInClientConfig; this.runtimeInClientConfig = runtimeInClientConfig;
} }
public enum Version { public enum Version {
MC125("1.2.5", 29), MC125("1.2.5", 29),
MC147("1.4.7", 51), MC147("1.4.7", 51),
@ -495,10 +543,6 @@ public static class ServerProfile {
public int serverPort; public int serverPort;
public boolean isDefault = true; public boolean isDefault = true;
public InetSocketAddress toSocketAddress() {
return InetSocketAddress.createUnresolved(serverAddress, serverPort);
}
public ServerProfile() { public ServerProfile() {
} }
@ -514,6 +558,10 @@ public ServerProfile(String name, String serverAddress, int serverPort, boolean
this.serverPort = serverPort; this.serverPort = serverPort;
this.isDefault = isDefault; this.isDefault = isDefault;
} }
public InetSocketAddress toSocketAddress() {
return InetSocketAddress.createUnresolved(serverAddress, serverPort);
}
} }
public static class ProfileDefaultSettings { public static class ProfileDefaultSettings {
@ -521,57 +569,4 @@ public static class ProfileDefaultSettings {
public boolean autoEnter; public boolean autoEnter;
public boolean fullScreen; public boolean fullScreen;
} }
public ClientProfile() {
update = new ArrayList<>();
updateExclusions = new ArrayList<>();
updateShared = new ArrayList<>();
updateVerify = new ArrayList<>();
updateOptional = new HashSet<>();
jvmArgs = new ArrayList<>();
classPath = new ArrayList<>();
altClassPath = new ArrayList<>();
clientArgs = new ArrayList<>();
compatClasses = new ArrayList<>();
properties = new HashMap<>();
servers = new ArrayList<>(1);
securityManagerConfig = SecurityManagerConfig.CLIENT;
classLoaderConfig = ClassLoaderConfig.LAUNCHER;
signedClientConfig = SignedClientConfig.NONE;
runtimeInClientConfig = RuntimeInClientConfig.NONE;
}
public ClientProfile(List<String> update, List<String> updateExclusions, List<String> updateShared, List<String> updateVerify, Set<OptionalFile> updateOptional, List<String> jvmArgs, List<String> classPath, List<String> altClassPath, List<String> clientArgs, List<String> compatClasses, Map<String, String> properties, List<ServerProfile> servers, SecurityManagerConfig securityManagerConfig, ClassLoaderConfig classLoaderConfig, SignedClientConfig signedClientConfig, RuntimeInClientConfig runtimeInClientConfig, String version, String assetIndex, String dir, String assetDir, int recommendJavaVersion, int minJavaVersion, int maxJavaVersion, boolean warnMissJavaVersion, ProfileDefaultSettings settings, int sortIndex, UUID uuid, String title, String info, boolean updateFastCheck, String mainClass) {
this.update = update;
this.updateExclusions = updateExclusions;
this.updateShared = updateShared;
this.updateVerify = updateVerify;
this.updateOptional = updateOptional;
this.jvmArgs = jvmArgs;
this.classPath = classPath;
this.altClassPath = altClassPath;
this.clientArgs = clientArgs;
this.compatClasses = compatClasses;
this.properties = properties;
this.servers = servers;
this.securityManagerConfig = securityManagerConfig;
this.classLoaderConfig = classLoaderConfig;
this.signedClientConfig = signedClientConfig;
this.runtimeInClientConfig = runtimeInClientConfig;
this.version = version;
this.assetIndex = assetIndex;
this.dir = dir;
this.assetDir = assetDir;
this.recommendJavaVersion = recommendJavaVersion;
this.minJavaVersion = minJavaVersion;
this.maxJavaVersion = maxJavaVersion;
this.warnMissJavaVersion = warnMissJavaVersion;
this.settings = settings;
this.sortIndex = sortIndex;
this.uuid = uuid;
this.title = title;
this.info = info;
this.updateFastCheck = updateFastCheck;
this.mainClass = mainClass;
}
} }

View file

@ -15,9 +15,6 @@ public class OptionalView {
public Map<OptionalFile, Set<OptionalFile>> dependenciesCountMap = new HashMap<>(); public Map<OptionalFile, Set<OptionalFile>> dependenciesCountMap = new HashMap<>();
public Map<OptionalFile, OptionalFileInstallInfo> installInfo = new HashMap<>(); public Map<OptionalFile, OptionalFileInstallInfo> installInfo = new HashMap<>();
public Set<OptionalFile> all; public Set<OptionalFile> all;
public static class OptionalFileInstallInfo {
public boolean isManual;
}
public OptionalView(ClientProfile profile) { public OptionalView(ClientProfile profile) {
this.all = profile.getOptional(); this.all = profile.getOptional();
@ -162,4 +159,8 @@ private boolean contains(OptionalFile file, OptionalFile[] array) {
} }
return false; return false;
} }
public static class OptionalFileInstallInfo {
public boolean isManual;
}
} }

View file

@ -14,8 +14,6 @@
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.stream.Collectors;
public abstract class Request<R extends WebSocketEvent> implements WebSocketRequest { public abstract class Request<R extends WebSocketEvent> implements WebSocketRequest {
public static StdWebSocketService service; public static StdWebSocketService service;
@ -25,9 +23,6 @@ public abstract class Request<R extends WebSocketEvent> implements WebSocketRequ
private static String authId; private static String authId;
private static long tokenExpiredTime; private static long tokenExpiredTime;
private static List<ExtendedTokenCallback> extendedTokenCallbacks = new ArrayList<>(4); private static List<ExtendedTokenCallback> extendedTokenCallbacks = new ArrayList<>(4);
public interface ExtendedTokenCallback {
String tryGetNewToken(String name);
}
@LauncherNetworkAPI @LauncherNetworkAPI
public final UUID requestUUID = UUID.randomUUID(); public final UUID requestUUID = UUID.randomUUID();
private transient final AtomicBoolean started = new AtomicBoolean(false); private transient final AtomicBoolean started = new AtomicBoolean(false);
@ -50,10 +45,6 @@ public static void setOAuth(String authId, AuthRequestEvent.OAuthRequestEvent ev
} }
} }
public void addExtendedTokenCallback(ExtendedTokenCallback cb) {
extendedTokenCallbacks.add(cb);
}
public static AuthRequestEvent.OAuthRequestEvent getOAuth() { public static AuthRequestEvent.OAuthRequestEvent getOAuth() {
return oauth; return oauth;
} }
@ -159,6 +150,10 @@ public static void requestError(String message) throws RequestException {
throw new RequestException(message); throw new RequestException(message);
} }
public void addExtendedTokenCallback(ExtendedTokenCallback cb) {
extendedTokenCallbacks.add(cb);
}
public R request() throws Exception { public R request() throws Exception {
if (!started.compareAndSet(false, true)) if (!started.compareAndSet(false, true))
throw new IllegalStateException("Request already started"); throw new IllegalStateException("Request already started");
@ -167,7 +162,6 @@ public R request() throws Exception {
return requestDo(service); return requestDo(service);
} }
public R request(StdWebSocketService service) throws Exception { public R request(StdWebSocketService service) throws Exception {
if (!started.compareAndSet(false, true)) if (!started.compareAndSet(false, true))
throw new IllegalStateException("Request already started"); throw new IllegalStateException("Request already started");
@ -178,4 +172,8 @@ protected R requestDo(StdWebSocketService service) throws Exception {
return service.requestSync(this); return service.requestSync(this);
} }
public interface ExtendedTokenCallback {
String tryGetNewToken(String name);
}
} }

View file

@ -2,10 +2,7 @@
import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.events.request.AuthRequestEvent; import pro.gravit.launcher.events.request.AuthRequestEvent;
import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent;
import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.Request;
import pro.gravit.launcher.request.auth.details.AuthPasswordDetails;
import pro.gravit.launcher.request.auth.details.AuthWebViewDetails;
import pro.gravit.launcher.request.auth.password.*; import pro.gravit.launcher.request.auth.password.*;
import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.launcher.request.websockets.WebSocketRequest;
import pro.gravit.utils.ProviderMap; import pro.gravit.utils.ProviderMap;

View file

@ -2,6 +2,7 @@
import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.AuthRequest;
@Deprecated @Deprecated
public class AuthECPassword implements AuthRequest.AuthPasswordInterface { public class AuthECPassword implements AuthRequest.AuthPasswordInterface {
@LauncherNetworkAPI @LauncherNetworkAPI

View file

@ -6,6 +6,7 @@
public class AuthMultiPassword implements AuthRequest.AuthPasswordInterface { public class AuthMultiPassword implements AuthRequest.AuthPasswordInterface {
public List<AuthRequest.AuthPasswordInterface> list; public List<AuthRequest.AuthPasswordInterface> list;
@Override @Override
public boolean check() { public boolean check() {
return list != null && list.stream().allMatch(l -> l != null && l.check()); return list != null && list.stream().allMatch(l -> l != null && l.check());

View file

@ -24,6 +24,22 @@ public Version(int major, int minor, int patch) {
release = Type.UNKNOWN; release = Type.UNKNOWN;
} }
public Version(int major, int minor, int patch, int build) {
this.major = major;
this.minor = minor;
this.patch = patch;
this.build = build;
release = Type.UNKNOWN;
}
public Version(int major, int minor, int patch, int build, Type release) {
this.major = major;
this.minor = minor;
this.patch = patch;
this.build = build;
this.release = release;
}
public static Version of(int major, int minor, int patch) { public static Version of(int major, int minor, int patch) {
return new Version(major, minor, patch); return new Version(major, minor, patch);
} }
@ -36,24 +52,6 @@ public static Version of(int major, int minor, int patch, int build, Type releas
return new Version(major, minor, patch, build, release); return new Version(major, minor, patch, build, release);
} }
public Version(int major, int minor, int patch, int build) {
this.major = major;
this.minor = minor;
this.patch = patch;
this.build = build;
release = Type.UNKNOWN;
}
public Version(int major, int minor, int patch, int build, Type release) {
this.major = major;
this.minor = minor;
this.patch = patch;
this.build = build;
this.release = release;
}
public static Version getVersion() { public static Version getVersion() {
return new Version(MAJOR, MINOR, PATCH, BUILD, RELEASE); return new Version(MAJOR, MINOR, PATCH, BUILD, RELEASE);
} }

View file

@ -4,7 +4,6 @@
import pro.gravit.utils.command.Command; import pro.gravit.utils.command.Command;
import pro.gravit.utils.command.CommandException; import pro.gravit.utils.command.CommandException;
import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.command.CommandHandler;
import pro.gravit.utils.helper.FormatHelper;
import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.LogHelper;
import java.util.Arrays; import java.util.Arrays;

View file

@ -7,7 +7,10 @@
import javax.script.ScriptEngineFactory; import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.*; import java.util.Base64;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Locale;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;

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