* Formatting fixes. (TODO: reformat by IDEA)

* Working transformers.

* Remove line numbers option.

* Remove some comments.

* Closing fix.

* ClientLauncher fixes.

* Final fixes.

* Last fix.

* Small fix.
This commit is contained in:
Zaxar163 2019-01-07 08:01:15 +03:00 committed by Gravit
parent dece60b8f8
commit 5ee0ed089e
42 changed files with 341 additions and 205 deletions

View file

@ -65,7 +65,11 @@
import ru.gravit.launchserver.config.HWIDHandlerAdapter; import ru.gravit.launchserver.config.HWIDHandlerAdapter;
import ru.gravit.launchserver.config.PermissionsHandlerAdapter; import ru.gravit.launchserver.config.PermissionsHandlerAdapter;
import ru.gravit.launchserver.config.TextureProviderAdapter; import ru.gravit.launchserver.config.TextureProviderAdapter;
import ru.gravit.launchserver.manangers.*; import ru.gravit.launchserver.manangers.MirrorManager;
import ru.gravit.launchserver.manangers.ModulesManager;
import ru.gravit.launchserver.manangers.ReconfigurableManager;
import ru.gravit.launchserver.manangers.ReloadManager;
import ru.gravit.launchserver.manangers.SessionManager;
import ru.gravit.launchserver.manangers.hook.AuthHookManager; import ru.gravit.launchserver.manangers.hook.AuthHookManager;
import ru.gravit.launchserver.manangers.hook.BuildHookManager; import ru.gravit.launchserver.manangers.hook.BuildHookManager;
import ru.gravit.launchserver.manangers.hook.SocketHookManager; import ru.gravit.launchserver.manangers.hook.SocketHookManager;
@ -82,7 +86,7 @@
public final class LaunchServer implements Runnable { public final class LaunchServer implements Runnable {
public static final class Config { public static final class Config {
public int port; public int port;
private String address; private String address;
@ -127,7 +131,6 @@ public static final class Config {
public String authRejectString; public String authRejectString;
public String whitelistRejectString; public String whitelistRejectString;
public boolean genMappings; public boolean genMappings;
@ -136,6 +139,7 @@ public static final class Config {
public boolean isWarningMissArchJava; public boolean isWarningMissArchJava;
public boolean enabledProGuard; public boolean enabledProGuard;
public boolean stripLineNumbers;
public String startScript; public String startScript;
@ -264,7 +268,8 @@ public static void main(String... args) throws Throwable {
public final Path privateKeyFile; public final Path privateKeyFile;
public final Path updatesDir; public final Path updatesDir;
public static LaunchServer server;
public static LaunchServer server = null;
public final Path profilesDir; public final Path profilesDir;
// Server config // Server config
@ -277,7 +282,7 @@ public static void main(String... args) throws Throwable {
public final RSAPrivateKey privateKey; public final RSAPrivateKey privateKey;
// Launcher binary // Launcher binary
public final LauncherBinary launcherBinary; public final JARLauncherBinary launcherBinary;
public final LauncherBinary launcherEXEBinary; public final LauncherBinary launcherEXEBinary;
// HWID ban + anti-brutforce // HWID ban + anti-brutforce
@ -572,8 +577,8 @@ private void generateConfigIfNotExists() throws IOException {
newConfig.threadCoreCount = 0; // on your own newConfig.threadCoreCount = 0; // on your own
newConfig.enabledProGuard = true; newConfig.enabledProGuard = true;
newConfig.stripLineNumbers = false;
newConfig.threadCount = JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() >= 4 ? JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() / 2 : JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors(); newConfig.threadCount = JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() >= 4 ? JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() / 2 : JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors();
// Set server address // Set server address
LogHelper.println("LaunchServer address: "); LogHelper.println("LaunchServer address: ");
newConfig.setAddress(commandHandler.readLine()); newConfig.setAddress(commandHandler.readLine());
@ -587,8 +592,6 @@ private void generateConfigIfNotExists() throws IOException {
} }
} }
@SuppressWarnings("ReturnOfCollectionOrArrayField")
public Collection<ClientProfile> getProfiles() { public Collection<ClientProfile> getProfiles() {
return profilesList; return profilesList;
} }

View file

@ -1,5 +1,6 @@
package ru.gravit.launchserver.asm; package ru.gravit.launchserver.asm;
import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -17,7 +18,7 @@
* Позволяет искать методы внутри незагруженных классов и общие суперклассы для * Позволяет искать методы внутри незагруженных классов и общие суперклассы для
* чего угодно. Работает через поиск class-файлов в classpath. * чего угодно. Работает через поиск class-файлов в classpath.
*/ */
public class ClassMetadataReader { public class ClassMetadataReader implements Closeable {
private class CheckSuperClassVisitor extends ClassVisitor { private class CheckSuperClassVisitor extends ClassVisitor {
String superClassName; String superClassName;
@ -96,4 +97,10 @@ public ArrayList<String> getSuperClasses(String type) {
return superclasses; return superclasses;
} }
@Override
public void close() throws IOException {
cp.stream().forEach(IOHelper::close);
cp.clear();
}
} }

View file

@ -17,11 +17,9 @@
public final class JsonHWIDHandler extends HWIDHandler { public final class JsonHWIDHandler extends HWIDHandler {
private static final Gson gson = new Gson(); private static final Gson gson = new Gson();
@SuppressWarnings("unused")
private URL url; private URL url;
private URL urlBan; private URL urlBan;
private URL urlUnBan; private URL urlUnBan;
@SuppressWarnings("unused")
private URL urlGet; private URL urlGet;
public class banRequest { public class banRequest {

View file

@ -11,9 +11,9 @@
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import ru.gravit.launcher.ClientPermissions;
import ru.gravit.launcher.Launcher; import ru.gravit.launcher.Launcher;
import ru.gravit.launchserver.Reloadable; import ru.gravit.launchserver.Reloadable;
import ru.gravit.launcher.ClientPermissions;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;

View file

@ -13,8 +13,6 @@
public abstract class AuthProvider implements AutoCloseable { public abstract class AuthProvider implements AutoCloseable {
private static final Map<String, Class<? extends AuthProvider>> AUTH_PROVIDERS = new ConcurrentHashMap<>(8); private static final Map<String, Class<? extends AuthProvider>> AUTH_PROVIDERS = new ConcurrentHashMap<>(8);
private static boolean registredProv = false; private static boolean registredProv = false;
protected transient LaunchServer server = LaunchServer.server;
public static AuthProviderResult authError(String message) throws AuthException { public static AuthProviderResult authError(String message) throws AuthException {
throw new AuthException(message); throw new AuthException(message);
@ -42,7 +40,7 @@ public static void registerProviders() {
} }
public AuthHandler getAccociateHandler(int this_position) { public AuthHandler getAccociateHandler(int this_position) {
return server.config.authHandler; return LaunchServer.server.config.authHandler;
} }

View file

@ -1,7 +1,7 @@
package ru.gravit.launchserver.auth.provider; package ru.gravit.launchserver.auth.provider;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launcher.ClientPermissions; import ru.gravit.launcher.ClientPermissions;
import ru.gravit.launchserver.LaunchServer;
public class AuthProviderResult { public class AuthProviderResult {

View file

@ -5,8 +5,8 @@
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.launcher.ClientPermissions; import ru.gravit.launcher.ClientPermissions;
import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.launchserver.auth.MySQLSourceConfig; import ru.gravit.launchserver.auth.MySQLSourceConfig;
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;

View file

@ -1,12 +1,12 @@
package ru.gravit.launchserver.auth.provider; package ru.gravit.launchserver.auth.provider;
import java.util.ArrayList;
import ru.gravit.launchserver.Reconfigurable; import ru.gravit.launchserver.Reconfigurable;
import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import java.util.ArrayList;
public final class RejectAuthProvider extends AuthProvider implements Reconfigurable { public final class RejectAuthProvider extends AuthProvider implements Reconfigurable {
public RejectAuthProvider() { public RejectAuthProvider() {
} }

View file

@ -4,28 +4,36 @@
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import ru.gravit.launcher.Launcher;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.binary.tasks.LauncherBuildTask; import ru.gravit.launchserver.binary.tasks.LauncherBuildTask;
import ru.gravit.launchserver.binary.tasks.MainBuildTask; import ru.gravit.launchserver.binary.tasks.MainBuildTask;
import ru.gravit.launchserver.binary.tasks.ProGuardBuildTask; import ru.gravit.launchserver.binary.tasks.ProGuardBuildTask;
import ru.gravit.launchserver.binary.tasks.StripLineNumbersTask;
import ru.gravit.launchserver.binary.tasks.UnpackBuildTask; import ru.gravit.launchserver.binary.tasks.UnpackBuildTask;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
public final class JARLauncherBinary extends LauncherBinary { public final class JARLauncherBinary extends LauncherBinary {
public ArrayList<LauncherBuildTask> tasks; public ArrayList<LauncherBuildTask> tasks;
public final Path runtimeDir;
public final Path guardDir;
public JARLauncherBinary(LaunchServer server) throws IOException { public JARLauncherBinary(LaunchServer server) throws IOException {
super(server); super(server);
tasks = new ArrayList<>(); tasks = new ArrayList<>();
tasks.add(new UnpackBuildTask()); tasks.add(new UnpackBuildTask(server));
tasks.add(new MainBuildTask()); tasks.add(new MainBuildTask(server));
if(server.config.enabledProGuard) tasks.add(new ProGuardBuildTask()); if(server.config.enabledProGuard) tasks.add(new ProGuardBuildTask(server));
if(server.config.stripLineNumbers) tasks.add(new StripLineNumbersTask(server));
syncBinaryFile = server.dir.resolve(server.config.binaryName + ".jar"); syncBinaryFile = server.dir.resolve(server.config.binaryName + ".jar");
runtimeDir = server.dir.resolve(Launcher.RUNTIME_DIR);
guardDir = server.dir.resolve(Launcher.GUARD_DIR);
} }
@Override @Override
public void build() throws IOException { public void build() throws IOException {
// Build launcher binary
LogHelper.info("Building launcher binary file"); LogHelper.info("Building launcher binary file");
Path thisPath = null; Path thisPath = null;
boolean isNeedDelete = false; boolean isNeedDelete = false;
@ -39,7 +47,7 @@ public void build() throws IOException {
long time_task_end = System.currentTimeMillis(); long time_task_end = System.currentTimeMillis();
long time_task = time_task_end - time_this; long time_task = time_task_end - time_this;
time_this = time_task_end; time_this = time_task_end;
if(isNeedDelete) Files.delete(oldPath); if (isNeedDelete) Files.delete(oldPath);
isNeedDelete = task.allowDelete(); isNeedDelete = task.allowDelete();
LogHelper.subInfo("Task %s processed from %d millis",task.getName(), time_task); LogHelper.subInfo("Task %s processed from %d millis",task.getName(), time_task);
} }

View file

@ -1,21 +1,7 @@
package ru.gravit.launchserver.binary.tasks; package ru.gravit.launchserver.binary.tasks;
import javassist.CannotCompileException; import static ru.gravit.utils.helper.IOHelper.newZipEntry;
import javassist.NotFoundException;
import ru.gravit.launcher.AutogenConfig;
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.binary.BuildContext;
import ru.gravit.launchserver.binary.JAConfigurator;
import ru.gravit.launchserver.binary.JARLauncherBinary;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.SecurityHelper;
import ru.gravit.utils.helper.UnpackHelper;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.file.FileVisitResult; import java.nio.file.FileVisitResult;
@ -24,17 +10,31 @@
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipException; 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;
import static ru.gravit.utils.helper.IOHelper.newZipEntry; import javassist.CannotCompileException;
import javassist.NotFoundException;
import ru.gravit.launcher.AutogenConfig;
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.asm.ClassMetadataReader;
import ru.gravit.launchserver.binary.BuildContext;
import ru.gravit.launchserver.binary.JAConfigurator;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.SecurityHelper;
public class MainBuildTask implements LauncherBuildTask { public class MainBuildTask implements LauncherBuildTask {
public static LaunchServer server = LaunchServer.server;
public final Path binaryFile; public final Path binaryFile;
public Path cleanJar; public Path cleanJar;
private final LaunchServer server;
public final ClassMetadataReader reader;
private final class RuntimeDirVisitor extends SimpleFileVisitor<Path> { private final class RuntimeDirVisitor extends SimpleFileVisitor<Path> {
private final ZipOutputStream output; private final ZipOutputStream output;
private final Map<String, byte[]> runtime; private final Map<String, byte[]> runtime;
@ -46,14 +46,14 @@ private RuntimeDirVisitor(ZipOutputStream output, Map<String, byte[]> runtime) {
@Override @Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
String dirName = IOHelper.toString(UnpackBuildTask.runtimeDir.relativize(dir)); String dirName = IOHelper.toString(server.launcherBinary.runtimeDir.relativize(dir));
output.putNextEntry(newEntry(dirName + '/')); output.putNextEntry(newEntry(dirName + '/'));
return super.preVisitDirectory(dir, attrs); return super.preVisitDirectory(dir, attrs);
} }
@Override @Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
String fileName = IOHelper.toString(UnpackBuildTask.runtimeDir.relativize(file)); String fileName = IOHelper.toString(server.launcherBinary.runtimeDir.relativize(file));
runtime.put(fileName, SecurityHelper.digest(SecurityHelper.DigestAlgorithm.MD5, file)); runtime.put(fileName, SecurityHelper.digest(SecurityHelper.DigestAlgorithm.MD5, file));
// Create zip entry and transfer contents // Create zip entry and transfer contents
@ -65,8 +65,6 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
} }
} }
// TODO: new native security wrapper and library...
@SuppressWarnings("unused")
private final class GuardDirVisitor extends SimpleFileVisitor<Path> { private final class GuardDirVisitor extends SimpleFileVisitor<Path> {
private final ZipOutputStream output; private final ZipOutputStream output;
private final Map<String, byte[]> guard; private final Map<String, byte[]> guard;
@ -78,14 +76,14 @@ private GuardDirVisitor(ZipOutputStream output, Map<String, byte[]> guard) {
@Override @Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
String dirName = IOHelper.toString(UnpackBuildTask.guardDir.relativize(dir)); String dirName = IOHelper.toString(server.launcherBinary.guardDir.relativize(dir));
output.putNextEntry(newGuardEntry(dirName + '/')); output.putNextEntry(newGuardEntry(dirName + '/'));
return super.preVisitDirectory(dir, attrs); return super.preVisitDirectory(dir, attrs);
} }
@Override @Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
String fileName = IOHelper.toString(UnpackBuildTask.guardDir.relativize(file)); String fileName = IOHelper.toString(server.launcherBinary.guardDir.relativize(file));
guard.put(fileName, SecurityHelper.digest(SecurityHelper.DigestAlgorithm.MD5, file)); guard.put(fileName, SecurityHelper.digest(SecurityHelper.DigestAlgorithm.MD5, file));
// Create zip entry and transfer contents // Create zip entry and transfer contents
@ -104,8 +102,11 @@ private static ZipEntry newEntry(String fileName) {
private static ZipEntry newGuardEntry(String fileName) { private static ZipEntry newGuardEntry(String fileName) {
return newZipEntry(Launcher.GUARD_DIR + IOHelper.CROSS_SEPARATOR + fileName); return newZipEntry(Launcher.GUARD_DIR + IOHelper.CROSS_SEPARATOR + fileName);
} }
public MainBuildTask() {
public MainBuildTask(LaunchServer srv) {
server = srv;
binaryFile = server.dir.resolve(server.config.binaryName + "-main.jar"); binaryFile = server.dir.resolve(server.config.binaryName + "-main.jar");
reader = new ClassMetadataReader();
} }
@Override @Override
@ -120,7 +121,7 @@ public Path process(Path cleanJar) throws IOException {
JAConfigurator jaConfigurator = new JAConfigurator(AutogenConfig.class.getName(), this)) { JAConfigurator jaConfigurator = new JAConfigurator(AutogenConfig.class.getName(), this)) {
jaConfigurator.pool.insertClassPath(cleanJar.toFile().getAbsolutePath()); jaConfigurator.pool.insertClassPath(cleanJar.toFile().getAbsolutePath());
BuildContext context = new BuildContext(output, jaConfigurator, this); BuildContext context = new BuildContext(output, jaConfigurator, this);
server.buildHookManager.preHook(context); server.buildHookManager.hook(context);
jaConfigurator.setAddress(server.config.getAddress()); jaConfigurator.setAddress(server.config.getAddress());
jaConfigurator.setPort(server.config.port); jaConfigurator.setPort(server.config.port);
jaConfigurator.setProjectName(server.config.projectName); jaConfigurator.setProjectName(server.config.projectName);
@ -130,6 +131,7 @@ public Path process(Path cleanJar) throws IOException {
jaConfigurator.setDownloadJava(server.config.isDownloadJava); jaConfigurator.setDownloadJava(server.config.isDownloadJava);
jaConfigurator.setEnv(server.config.env); jaConfigurator.setEnv(server.config.env);
server.buildHookManager.registerAllClientModuleClass(jaConfigurator); server.buildHookManager.registerAllClientModuleClass(jaConfigurator);
reader.getCp().add(new JarFile(cleanJar.toFile()));
try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(cleanJar))) { try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(cleanJar))) {
ZipEntry e = input.getNextEntry(); ZipEntry e = input.getNextEntry();
while (e != null) { while (e != null) {
@ -145,7 +147,7 @@ public Path process(Path cleanJar) throws IOException {
e = input.getNextEntry(); e = input.getNextEntry();
continue; continue;
} }
/*if (filename.endsWith(".class")) { if (filename.endsWith(".class")) {
String classname = filename.replace('/', '.').substring(0, String classname = filename.replace('/', '.').substring(0,
filename.length() - ".class".length()); filename.length() - ".class".length());
byte[] bytes; byte[] bytes;
@ -154,10 +156,8 @@ public Path process(Path cleanJar) throws IOException {
bytes = outputStream.toByteArray(); bytes = outputStream.toByteArray();
} }
bytes = server.buildHookManager.classTransform(bytes, classname, this); bytes = server.buildHookManager.classTransform(bytes, classname, this);
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) { output.write(bytes);
IOHelper.transfer(inputStream, output); } else
}
} else */
IOHelper.transfer(input, output); IOHelper.transfer(input, output);
context.fileList.add(filename); context.fileList.add(filename);
e = input.getNextEntry(); e = input.getNextEntry();
@ -172,8 +172,8 @@ public Path process(Path cleanJar) throws IOException {
Map<String, byte[]> runtime = new HashMap<>(256); Map<String, byte[]> runtime = new HashMap<>(256);
if (server.buildHookManager.buildRuntime()) { if (server.buildHookManager.buildRuntime()) {
// Write launcher guard dir // Write launcher guard dir
IOHelper.walk(UnpackBuildTask.runtimeDir, new RuntimeDirVisitor(output, runtime), false); IOHelper.walk(server.launcherBinary.runtimeDir, new RuntimeDirVisitor(output, runtime), false);
// IOHelper.walk(guardDir, new GuardDirVisitor(output, runtime), false); IOHelper.walk(server.launcherBinary.guardDir, new GuardDirVisitor(output, runtime), false);
} }
// Create launcher config file // Create launcher config file
byte[] launcherConfigBytes; byte[] launcherConfigBytes;
@ -192,10 +192,10 @@ public Path process(Path cleanJar) throws IOException {
output.putNextEntry(e); output.putNextEntry(e);
jaConfigurator.compile(); jaConfigurator.compile();
output.write(jaConfigurator.getBytecode()); output.write(jaConfigurator.getBytecode());
server.buildHookManager.postHook(context);
} catch (CannotCompileException | NotFoundException e) { } catch (CannotCompileException | NotFoundException e) {
LogHelper.error(e); LogHelper.error(e);
} }
reader.close();
return binaryFile; return binaryFile;
} }

View file

@ -1,17 +1,22 @@
package ru.gravit.launchserver.binary.tasks; package ru.gravit.launchserver.binary.tasks;
import java.io.IOException;
import java.nio.file.Path;
import proguard.Configuration; import proguard.Configuration;
import proguard.ConfigurationParser; import proguard.ConfigurationParser;
import proguard.ParseException; import proguard.ParseException;
import proguard.ProGuard; import proguard.ProGuard;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import java.io.IOException;
import java.nio.file.Path;
public class ProGuardBuildTask implements LauncherBuildTask { public class ProGuardBuildTask implements LauncherBuildTask {
public static LaunchServer server = LaunchServer.server; private final LaunchServer server;
@Override
public ProGuardBuildTask(LaunchServer server) {
this.server = server;
}
@Override
public String getName() { public String getName() {
return "ProGuard"; return "ProGuard";
} }

View file

@ -0,0 +1,70 @@
package ru.gravit.launchserver.binary.tasks;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.asm.ClassMetadataReader;
import ru.gravit.launchserver.asm.SafeClassWriter;
import ru.gravit.utils.helper.IOHelper;
public class StripLineNumbersTask implements LauncherBuildTask {
private final LaunchServer server;
public StripLineNumbersTask(LaunchServer server) {
this.server = server;
}
@Override
public String getName() {
return "Strip debug task";
}
@Override
public Path process(Path inputFile) throws IOException {
Path out = server.dir.resolve(server.config.projectName + "-stripped.jar");
try (ClassMetadataReader reader = new ClassMetadataReader()) {
reader.getCp().add(new JarFile(inputFile.toFile()));
try (ZipInputStream input = IOHelper.newZipInput(inputFile);
ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(out))) {
ZipEntry e = input.getNextEntry();
while (e != null) {
String filename = e.getName();
output.putNextEntry(IOHelper.newZipEntry(e));
if (filename.endsWith(".class")) {
byte[] bytes = null;
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) {
IOHelper.transfer(input, outputStream);
bytes = outputStream.toByteArray();
}
output.write(classFix(bytes, reader));
} else
IOHelper.transfer(input, output);
e = input.getNextEntry();
}
}
}
return out;
}
private static byte[] classFix(byte[] bytes, ClassMetadataReader reader) {
ClassReader cr = new ClassReader(bytes);
ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
cr.accept(cw, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
return cw.toByteArray();
}
@Override
public boolean allowDelete() {
return true;
}
}

View file

@ -1,19 +1,21 @@
package ru.gravit.launchserver.binary.tasks; package ru.gravit.launchserver.binary.tasks;
import ru.gravit.launcher.Launcher;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.UnpackHelper; import ru.gravit.utils.helper.UnpackHelper;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.nio.file.Path; import java.nio.file.Path;
public class UnpackBuildTask implements LauncherBuildTask { public class UnpackBuildTask implements LauncherBuildTask {
public static final Path runtimeDir = LaunchServer.server.dir.resolve(Launcher.RUNTIME_DIR); private final LaunchServer server;
public static final Path guardDir = LaunchServer.server.dir.resolve(Launcher.GUARD_DIR); private final Path result;
public static LaunchServer server = LaunchServer.server;
public UnpackBuildTask(LaunchServer server) {
this.server = server;
result = server.dir.resolve(server.config.binaryName + "-clean.jar");
}
@Override @Override
public String getName() { public String getName() {
@ -22,9 +24,8 @@ public String getName() {
@Override @Override
public Path process(Path inputFile) throws IOException { public Path process(Path inputFile) throws IOException {
Path result = server.dir.resolve(server.config.binaryName + "-clean.jar"); UnpackHelper.unpack(IOHelper.getResourceURL("Launcher.jar"), result);
URL url = IOHelper.getResourceURL("Launcher.jar"); tryUnpack();
UnpackHelper.unpack(url, result);
return result; return result;
} }
@ -35,7 +36,7 @@ public boolean allowDelete() {
public void tryUnpack() throws IOException { public void tryUnpack() throws IOException {
LogHelper.info("Unpacking launcher native guard files and runtime"); LogHelper.info("Unpacking launcher native guard files and runtime");
UnpackHelper.unpackZipNoCheck("guard.zip", guardDir); UnpackHelper.unpackZipNoCheck("guard.zip", server.launcherBinary.guardDir);
UnpackHelper.unpackZipNoCheck("runtime.zip", runtimeDir); UnpackHelper.unpackZipNoCheck("runtime.zip", server.launcherBinary.runtimeDir);
} }
} }

View file

@ -19,7 +19,6 @@ public String getUsageDescription() {
} }
@Override @Override
@SuppressWarnings("CallToSystemExit")
public void invoke(String... args) { public void invoke(String... args) {
server.fullyRestart(); server.fullyRestart();
} }

View file

@ -20,7 +20,6 @@ public String getUsageDescription() {
} }
@Override @Override
@SuppressWarnings("CallToSystemExit")
public void invoke(String... args) { public void invoke(String... args) {
JVMHelper.RUNTIME.exit(0); JVMHelper.RUNTIME.exit(0);
} }

View file

@ -36,7 +36,7 @@ public void invoke(String... args) throws Exception {
} }
if (args[0].equals("profile")) { if (args[0].equals("profile")) {
ClientProfile profile = new ClientProfile("1.7.10","asset1.7.10",0,"Test1.7.10","localhost",25565,true,false,"net.minecraft.launchwrapper.Launch"); ClientProfile profile = new ClientProfile("1.7.10","asset1.7.10",0,"Test1.7.10","localhost",25565,true,false,"net.minecraft.launchwrapper.Launch");
try(Writer writer = IOHelper.newWriter(LaunchServer.server.dir.resolve("profiles").resolve("Test.cfg"))) try(Writer writer = IOHelper.newWriter(server.dir.resolve("profiles").resolve("Test.cfg")))
{ {
LaunchServer.gson.toJson(profile,writer); LaunchServer.gson.toJson(profile,writer);
} }

View file

@ -44,7 +44,13 @@
import ru.gravit.launchserver.command.hash.UnindexAssetCommand; import ru.gravit.launchserver.command.hash.UnindexAssetCommand;
import ru.gravit.launchserver.command.modules.LoadModuleCommand; import ru.gravit.launchserver.command.modules.LoadModuleCommand;
import ru.gravit.launchserver.command.modules.ModulesCommand; import ru.gravit.launchserver.command.modules.ModulesCommand;
import ru.gravit.launchserver.command.service.*; import ru.gravit.launchserver.command.service.ConfigCommand;
import ru.gravit.launchserver.command.service.ConfigHelpCommand;
import ru.gravit.launchserver.command.service.ConfigListCommand;
import ru.gravit.launchserver.command.service.ReloadAllCommand;
import ru.gravit.launchserver.command.service.ReloadCommand;
import ru.gravit.launchserver.command.service.ReloadListCommand;
import ru.gravit.launchserver.command.service.SwapAuthProviderCommand;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;

View file

@ -1,12 +1,12 @@
package ru.gravit.launchserver.manangers; package ru.gravit.launchserver.manangers;
import java.util.HashMap;
import java.util.Objects;
import ru.gravit.launchserver.Reconfigurable; import ru.gravit.launchserver.Reconfigurable;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import java.util.HashMap;
import java.util.Objects;
public class ReconfigurableManager { public class ReconfigurableManager {
private final HashMap<String, Reconfigurable> RECONFIGURABLE = new HashMap<>(); private final HashMap<String, Reconfigurable> RECONFIGURABLE = new HashMap<>();
public void registerReconfigurable(String name, Reconfigurable reconfigurable) public void registerReconfigurable(String name, Reconfigurable reconfigurable)

View file

@ -1,11 +1,11 @@
package ru.gravit.launchserver.manangers.hook; package ru.gravit.launchserver.manangers.hook;
import ru.gravit.launchserver.response.auth.AuthResponse;
import ru.gravit.launchserver.socket.Client;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import ru.gravit.launchserver.response.auth.AuthResponse;
import ru.gravit.launchserver.socket.Client;
public class AuthHookManager { public class AuthHookManager {
private Set<AuthPreHook> PRE_HOOKS = new HashSet<>(); private Set<AuthPreHook> PRE_HOOKS = new HashSet<>();
private Set<AuthPostHook> POST_HOOKS = new HashSet<>(); private Set<AuthPostHook> POST_HOOKS = new HashSet<>();

View file

@ -4,7 +4,6 @@
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.zip.ZipOutputStream;
import ru.gravit.launcher.AutogenConfig; import ru.gravit.launcher.AutogenConfig;
import ru.gravit.launcher.modules.TestClientModule; import ru.gravit.launcher.modules.TestClientModule;
@ -13,10 +12,6 @@
import ru.gravit.launchserver.binary.tasks.MainBuildTask; import ru.gravit.launchserver.binary.tasks.MainBuildTask;
public class BuildHookManager { public class BuildHookManager {
@FunctionalInterface
public interface ZipBuildHook {
void build(ZipOutputStream context);
}
@FunctionalInterface @FunctionalInterface
public interface BuildHook { public interface BuildHook {
@ -29,22 +24,14 @@ public interface Transformer {
} }
private boolean BUILDRUNTIME; private boolean BUILDRUNTIME;
private final Set<BuildHook> POST_HOOKS; private final Set<BuildHook> HOOKS;
private final Set<Runnable> POST_PROGUARDRUN_HOOKS;
private final Set<Transformer> POST_PROGUARD_HOOKS;
private final Set<BuildHook> PRE_HOOKS;
private final Set<ZipBuildHook> POST_PROGUARD_BUILDHOOKS;
private final Set<Transformer> CLASS_TRANSFORMER; private final Set<Transformer> CLASS_TRANSFORMER;
private final Set<String> CLASS_BLACKLIST; private final Set<String> CLASS_BLACKLIST;
private final Set<String> MODULE_CLASS; private final Set<String> MODULE_CLASS;
private final Map<String, byte[]> INCLUDE_CLASS; private final Map<String, byte[]> INCLUDE_CLASS;
public BuildHookManager() { public BuildHookManager() {
POST_HOOKS = new HashSet<>(4); HOOKS = new HashSet<>(4);
POST_PROGUARDRUN_HOOKS = new HashSet<>(4);
POST_PROGUARD_HOOKS = new HashSet<>(4);
PRE_HOOKS = new HashSet<>(4);
POST_PROGUARD_BUILDHOOKS = new HashSet<>(4);
CLASS_BLACKLIST = new HashSet<>(4); CLASS_BLACKLIST = new HashSet<>(4);
MODULE_CLASS = new HashSet<>(4); MODULE_CLASS = new HashSet<>(4);
INCLUDE_CLASS = new HashMap<>(4); INCLUDE_CLASS = new HashMap<>(4);
@ -57,22 +44,6 @@ public BuildHookManager() {
registerClientModuleClass(TestClientModule.class.getName()); registerClientModuleClass(TestClientModule.class.getName());
} }
public Set<ZipBuildHook> getProguardBuildHooks() {
return POST_PROGUARD_BUILDHOOKS;
}
public Set<Runnable> getPostProguardRunHooks() {
return POST_PROGUARDRUN_HOOKS;
}
public void addPostProguardRunHook(Runnable hook) {
POST_PROGUARDRUN_HOOKS.add(hook);
}
public void addPostProguardRunHook(ZipBuildHook hook) {
POST_PROGUARD_BUILDHOOKS.add(hook);
}
public void autoRegisterIgnoredClass(String clazz) { public void autoRegisterIgnoredClass(String clazz) {
CLASS_BLACKLIST.add(clazz.replace('.', '/').concat(".class")); CLASS_BLACKLIST.add(clazz.replace('.', '/').concat(".class"));
} }
@ -87,12 +58,6 @@ public byte[] classTransform(byte[] clazz, String classname, MainBuildTask reade
return result; return result;
} }
public byte[] proGuardClassTransform(byte[] clazz, String classname, MainBuildTask reader) {
byte[] result = clazz;
for (Transformer transformer : POST_PROGUARD_HOOKS) result = transformer.transform(result, classname, reader);
return result;
}
public void registerIncludeClass(String classname, byte[] classdata) { public void registerIncludeClass(String classname, byte[] classdata) {
INCLUDE_CLASS.put(classname, classdata); INCLUDE_CLASS.put(classname, classdata);
} }
@ -108,12 +73,8 @@ public boolean isContainsBlacklist(String clazz) {
return false; return false;
} }
public void postHook(BuildContext context) { public void hook(BuildContext context) {
for (BuildHook hook : POST_HOOKS) hook.build(context); for (BuildHook hook : HOOKS) hook.build(context);
}
public void preHook(BuildContext context) {
for (BuildHook hook : PRE_HOOKS) hook.build(context);
} }
public void registerAllClientModuleClass(JAConfigurator cfg) { public void registerAllClientModuleClass(JAConfigurator cfg) {
@ -132,20 +93,8 @@ public void registerIgnoredClass(String clazz) {
CLASS_BLACKLIST.add(clazz); CLASS_BLACKLIST.add(clazz);
} }
public void registerPostHook(BuildHook hook) { public void registerHook(BuildHook hook) {
POST_HOOKS.add(hook); HOOKS.add(hook);
}
public void registerProGuardHook(Transformer hook) {
POST_PROGUARD_HOOKS.add(hook);
}
public boolean isNeedPostProguardHook() {
return POST_PROGUARD_HOOKS.size() > 1 || !POST_PROGUARDRUN_HOOKS.isEmpty() || !POST_PROGUARD_BUILDHOOKS.isEmpty();
}
public void registerPreHook(BuildHook hook) {
PRE_HOOKS.add(hook);
} }
public void setBuildRuntime(boolean runtime) { public void setBuildRuntime(boolean runtime) {

View file

@ -1,12 +1,12 @@
package ru.gravit.launchserver.manangers.hook; package ru.gravit.launchserver.manangers.hook;
import ru.gravit.launcher.request.RequestException;
import ru.gravit.launchserver.socket.SocketContext;
import java.net.Socket; import java.net.Socket;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import ru.gravit.launcher.request.RequestException;
import ru.gravit.launchserver.socket.SocketContext;
public class SocketHookManager { public class SocketHookManager {
@FunctionalInterface @FunctionalInterface
public interface SocketPreHook public interface SocketPreHook

View file

@ -104,8 +104,7 @@ protected final void debug(String message, Object... args) {
public abstract void reply() throws Exception; public abstract void reply() throws Exception;
@SuppressWarnings("MethodMayBeStatic") // Intentionally not static protected static final void writeNoError(HOutput output) throws IOException {
protected final void writeNoError(HOutput output) throws IOException {
output.writeString("", 0); output.writeString("", 0);
} }
} }

View file

@ -1,7 +1,7 @@
package ru.gravit.launchserver.socket; package ru.gravit.launchserver.socket;
import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.ClientPermissions; import ru.gravit.launcher.ClientPermissions;
import ru.gravit.launcher.profiles.ClientProfile;
public class Client { public class Client {
public long session; public long session;

View file

@ -1,14 +1,22 @@
{ {
"port": 7240, "port": 7240,
"authHandler": { "address": "xx.xx",
"type": "memory" "bindAddress": "0.0.0.0",
}, "projectName": "XXX",
"mirrors": [
"http://mirror.gravitlauncher.ml/"
],
"binaryName": "Launcher",
"env": "STD",
"authProvider": [ "authProvider": [
{ {
"message": "Настройте authProvider", "message": "Настройте authProvider",
"type": "reject" "type": "reject"
} }
], ],
"authHandler": {
"type": "memory"
},
"permissionsHandler": { "permissionsHandler": {
"filename": "permissions.json", "filename": "permissions.json",
"type": "json" "type": "json"
@ -21,12 +29,14 @@
"hwidHandler": { "hwidHandler": {
"type": "accept" "type": "accept"
}, },
"threadCount": 0, "threadCount": 2,
"threadCoreCount": 0, "threadCoreCount": 0,
"launch4j": { "launch4j": {
"enabled": false, "enabled": false,
"fileDesc": "GravitLauncher 4.1.0", "productName": "GravitLauncher",
"fileVer": "4.1.0", "productVer": "4.2.0.0",
"fileDesc": "GravitLauncher 4.2.0",
"fileVer": "4.2.0.0",
"internalName": "Launcher", "internalName": "Launcher",
"copyright": "© GravitLauncher Team", "copyright": "© GravitLauncher Team",
"trademarks": "This product is licensed under GPLv3", "trademarks": "This product is licensed under GPLv3",
@ -44,12 +54,8 @@
"genMappings": false, "genMappings": false,
"isUsingWrapper": false, "isUsingWrapper": false,
"isDownloadJava": false, "isDownloadJava": false,
"mirrors": [ "isWarningMissArchJava": false,
"http://mirror.gravitlauncher.ml/" "enabledProGuard": true,
], "stripLineNumbers": true,
"binaryName": "Launcher", "startScript": ".\\start.sh"
"address": "localhost",
"bindAddress": "0.0.0.0",
"env": "STD",
"isWarningMissArchJava": false
} }

View file

@ -4,7 +4,6 @@
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@SuppressWarnings("AbstractClassNeverImplemented")
public abstract class JSApplication extends Application { public abstract class JSApplication extends Application {
private static final AtomicReference<JSApplication> INSTANCE = new AtomicReference<>(); private static final AtomicReference<JSApplication> INSTANCE = new AtomicReference<>();
@ -13,8 +12,6 @@ public static JSApplication getInstance() {
return INSTANCE.get(); return INSTANCE.get();
} }
@SuppressWarnings("ConstructorNotProtectedInAbstractClass")
public JSApplication() { public JSApplication() {
INSTANCE.set(this); INSTANCE.set(this);
} }

View file

@ -279,9 +279,6 @@ public static boolean isUsingWrapper() {
} }
private static void launch(ClientProfile profile, Params params) throws Throwable { private static void launch(ClientProfile profile, Params params) throws Throwable {
// Add natives path
//JVMHelper.addNativePath(params.clientDir.resolve(NATIVES_DIR));
// Add client args // Add client args
Collection<String> args = new LinkedList<>(); Collection<String> args = new LinkedList<>();
if (profile.getVersion().compareTo(ClientProfile.Version.MC164) >= 0) if (profile.getVersion().compareTo(ClientProfile.Version.MC164) >= 0)
@ -338,16 +335,12 @@ public static Process launch(
LogHelper.error(e); LogHelper.error(e);
} }
}).start(); }).start();
// Resolve java bin and set permissions
LogHelper.debug("Resolving JVM binary");
//Path javaBin = IOHelper.resolveJavaBin(jvmDir);
checkJVMBitsAndVersion(); checkJVMBitsAndVersion();
// Fill CLI arguments // Fill CLI arguments
List<String> args = new LinkedList<>(); List<String> args = new LinkedList<>();
boolean wrapper = isUsingWrapper(); boolean wrapper = isUsingWrapper();
Path javaBin; LogHelper.debug("Resolving JVM binary");
/*if (wrapper) javaBin = AvanguardStarter.wrapper; Path javaBin = null;
else*/
if (isDownloadJava) { if (isDownloadJava) {
//Linux и Mac не должны скачивать свою JVM //Linux и Mac не должны скачивать свою JVM
if (JVMHelper.OS_TYPE == OS.MUSTDIE) if (JVMHelper.OS_TYPE == OS.MUSTDIE)

View file

@ -41,17 +41,14 @@ public MinecraftProfileTexture(String url, String hash) {
this.hash = hash; this.hash = hash;
} }
@SuppressWarnings("unused")
public String getHash() { public String getHash() {
return hash; return hash;
} }
@SuppressWarnings({"unused", "SameReturnValue"})
public String getMetadata(String key) { public String getMetadata(String key) {
return null; return null;
} }
@SuppressWarnings("unused")
public String getUrl() { public String getUrl() {
return url; return url;
} }

View file

@ -13,18 +13,15 @@
import java.util.UUID; import java.util.UUID;
// Used to bypass Launcher's class name obfuscation and access API // Used to bypass Launcher's class name obfuscation and access API
@SuppressWarnings("unused")
@LauncherAPI @LauncherAPI
public final class CompatBridge { public final class CompatBridge {
public static final int PROFILES_MAX_BATCH_SIZE = SerializeLimits.MAX_BATCH_SIZE; public static final int PROFILES_MAX_BATCH_SIZE = SerializeLimits.MAX_BATCH_SIZE;
@SuppressWarnings("unused")
public static CompatProfile checkServer(String username, String serverID) throws Exception { public static CompatProfile checkServer(String username, String serverID) throws Exception {
LogHelper.debug("CompatBridge.checkServer, Username: '%s', Server ID: %s", username, serverID); LogHelper.debug("CompatBridge.checkServer, Username: '%s', Server ID: %s", username, serverID);
return CompatProfile.fromPlayerProfile(new CheckServerRequest(username, serverID).request()); return CompatProfile.fromPlayerProfile(new CheckServerRequest(username, serverID).request());
} }
@SuppressWarnings("unused")
public static boolean joinServer(String username, String accessToken, String serverID) throws Exception { public static boolean joinServer(String username, String accessToken, String serverID) throws Exception {
// Join server // Join server
@ -32,17 +29,14 @@ public static boolean joinServer(String username, String accessToken, String ser
return new JoinServerRequest(username, accessToken, serverID).request(); return new JoinServerRequest(username, accessToken, serverID).request();
} }
@SuppressWarnings("unused")
public static CompatProfile profileByUsername(String username) throws Exception { public static CompatProfile profileByUsername(String username) throws Exception {
return CompatProfile.fromPlayerProfile(new ProfileByUsernameRequest(username).request()); return CompatProfile.fromPlayerProfile(new ProfileByUsernameRequest(username).request());
} }
@SuppressWarnings("unused")
public static CompatProfile profileByUUID(UUID uuid) throws Exception { public static CompatProfile profileByUUID(UUID uuid) throws Exception {
return CompatProfile.fromPlayerProfile(new ProfileByUUIDRequest(uuid).request()); return CompatProfile.fromPlayerProfile(new ProfileByUUIDRequest(uuid).request());
} }
@SuppressWarnings("unused")
public static CompatProfile[] profilesByUsername(String... usernames) throws Exception { public static CompatProfile[] profilesByUsername(String... usernames) throws Exception {
PlayerProfile[] profiles = new BatchProfileByUsernameRequest(usernames).request(); PlayerProfile[] profiles = new BatchProfileByUsernameRequest(usernames).request();

View file

@ -7,7 +7,6 @@
import java.util.UUID; import java.util.UUID;
@SuppressWarnings("unused")
@LauncherAPI @LauncherAPI
public final class CompatProfile { public final class CompatProfile {
public static final String SKIN_URL_PROPERTY = Launcher.SKIN_URL_PROPERTY; public static final String SKIN_URL_PROPERTY = Launcher.SKIN_URL_PROPERTY;

View file

@ -10,27 +10,23 @@
// Used by 1.6.4 and below versions // Used by 1.6.4 and below versions
@LauncherAPI @LauncherAPI
public final class LegacyBridge { public final class LegacyBridge {
@SuppressWarnings("unused")
public static boolean checkServer(String username, String serverID) throws Exception { public static boolean checkServer(String username, String serverID) throws Exception {
LogHelper.debug("LegacyBridge.checkServer, Username: '%s', Server ID: %s", username, serverID); LogHelper.debug("LegacyBridge.checkServer, Username: '%s', Server ID: %s", username, serverID);
return new CheckServerRequest(username, serverID).request() != null; return new CheckServerRequest(username, serverID).request() != null;
} }
@SuppressWarnings("unused")
public static String getCloakURL(String username) { public static String getCloakURL(String username) {
LogHelper.debug("LegacyBridge.getCloakURL: '%s'", username); LogHelper.debug("LegacyBridge.getCloakURL: '%s'", username);
return CommonHelper.replace(System.getProperty("launcher.legacy.cloaksURL", return CommonHelper.replace(System.getProperty("launcher.legacy.cloaksURL",
"http://skins.minecraft.net/MinecraftCloaks/%username%.png"), "username", IOHelper.urlEncode(username)); "http://skins.minecraft.net/MinecraftCloaks/%username%.png"), "username", IOHelper.urlEncode(username));
} }
@SuppressWarnings("unused")
public static String getSkinURL(String username) { public static String getSkinURL(String username) {
LogHelper.debug("LegacyBridge.getSkinURL: '%s'", username); LogHelper.debug("LegacyBridge.getSkinURL: '%s'", username);
return CommonHelper.replace(System.getProperty("launcher.legacy.skinsURL", return CommonHelper.replace(System.getProperty("launcher.legacy.skinsURL",
"http://skins.minecraft.net/MinecraftSkins/%username%.png"), "username", IOHelper.urlEncode(username)); "http://skins.minecraft.net/MinecraftSkins/%username%.png"), "username", IOHelper.urlEncode(username));
} }
@SuppressWarnings("unused")
public static String joinServer(String username, String accessToken, String serverID) { public static String joinServer(String username, String accessToken, String serverID) {
// Join server // Join server

View file

@ -10,7 +10,6 @@
import java.net.Proxy; import java.net.Proxy;
public final class YggdrasilAuthenticationService implements AuthenticationService { public final class YggdrasilAuthenticationService implements AuthenticationService {
@SuppressWarnings("UnusedParameters")
public YggdrasilAuthenticationService(Proxy proxy, String clientToken) { public YggdrasilAuthenticationService(Proxy proxy, String clientToken) {
LogHelper.debug("Patched AuthenticationService created: '%s'", clientToken); LogHelper.debug("Patched AuthenticationService created: '%s'", clientToken);
} }

View file

@ -54,7 +54,6 @@ protected final void readError(HInput input) throws IOException {
} }
@LauncherAPI @LauncherAPI
@SuppressWarnings("DesignForExtension")
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");

View file

@ -83,7 +83,6 @@ public Integer getType() {
} }
@Override @Override
@SuppressWarnings("CallToSystemExit")
protected Result requestDo(HInput input, HOutput output) throws Exception { protected Result requestDo(HInput input, HOutput output) throws Exception {
Path launcherPath = IOHelper.getCodeSource(LauncherRequest.class); Path launcherPath = IOHelper.getCodeSource(LauncherRequest.class);
byte[] digest = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA512, launcherPath); byte[] digest = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA512, launcherPath);

View file

@ -93,7 +93,6 @@ public Integer getType() {
} }
@Override @Override
@SuppressWarnings("CallToSystemExit")
protected Result requestDo(HInput input, HOutput output) throws Exception { protected Result requestDo(HInput input, HOutput output) throws Exception {
output.writeBoolean(EXE_BINARY); output.writeBoolean(EXE_BINARY);
output.flush(); output.flush();

View file

@ -12,7 +12,6 @@ public JsonRequestAdapter(ClientWebSocketService service) {
this.service = service; this.service = service;
} }
@SuppressWarnings("unchecked")
@Override @Override
public RequestInterface deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { public RequestInterface deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();

View file

@ -46,7 +46,6 @@ public static long getObjSize(Object obj) {
public static Boolean isAutoloadLibraries = Boolean.getBoolean(System.getProperty("serverwrapper,agentlibrariesload", "false")); public static Boolean isAutoloadLibraries = Boolean.getBoolean(System.getProperty("serverwrapper,agentlibrariesload", "false"));
public static Boolean isAgentProxy = Boolean.getBoolean(System.getProperty("serverwrapper,agentproxy", "false")); public static Boolean isAgentProxy = Boolean.getBoolean(System.getProperty("serverwrapper,agentproxy", "false"));
@SuppressWarnings("JavaLangInvokeHandleSignature")
public static void premain(String agentArgument, Instrumentation instrumentation) { public static void premain(String agentArgument, Instrumentation instrumentation) {
LogHelper.debug("Server Agent"); LogHelper.debug("Server Agent");
inst = instrumentation; inst = instrumentation;

View file

@ -85,8 +85,7 @@ public static void initGson()
Launcher.gson = Launcher.gsonBuilder.create(); Launcher.gson = Launcher.gsonBuilder.create();
} }
@SuppressWarnings("ConfusingArgumentToVarargsMethod") public static void main(String... args) throws Throwable {
public static void main(String[] args) throws Throwable {
ServerWrapper wrapper = new ServerWrapper(); ServerWrapper wrapper = new ServerWrapper();
LogHelper.printVersion("ServerWrapper"); LogHelper.printVersion("ServerWrapper");
LogHelper.printLicense("ServerWrapper"); LogHelper.printLicense("ServerWrapper");

View file

@ -5,7 +5,8 @@ public class AutogenConfig {
public String address; public String address;
public int port; public int port;
public int clientPort; public int clientPort;
private boolean isInitModules; @SuppressWarnings("unused")
private boolean isInitModules;
public boolean isUsingWrapper; public boolean isUsingWrapper;
public boolean isDownloadJava; //Выставление этого флага требует модификации runtime части public boolean isDownloadJava; //Выставление этого флага требует модификации runtime части
public String secretKeyClient; public String secretKeyClient;
@ -17,11 +18,8 @@ public class AutogenConfig {
// 3 - Production (дебаг выключен, минимальный объем сообщений, stacktrace не выводится) // 3 - Production (дебаг выключен, минимальный объем сообщений, stacktrace не выводится)
AutogenConfig() { AutogenConfig() {
} }
@SuppressWarnings("UnnecessaryReturnStatement")
public void initModules() { public void initModules() {
if (isInitModules) return;
} }
} }

View file

@ -7,7 +7,7 @@
import java.util.jar.JarFile; import java.util.jar.JarFile;
@LauncherAPI @LauncherAPI
public class LauncherAgent { public final class LauncherAgent {
private static boolean isAgentStarted = false; private static boolean isAgentStarted = false;
public static Instrumentation inst; public static Instrumentation inst;

View file

@ -84,7 +84,6 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException
} }
@LauncherAPI @LauncherAPI
@SuppressWarnings("AssignmentToCollectionOrArrayFieldFromParameter")
public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map<String, byte[]> runtime, String projectname) { public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map<String, byte[]> runtime, String projectname) {
this.address = InetSocketAddress.createUnresolved(address, port); this.address = InetSocketAddress.createUnresolved(address, port);
this.publicKey = Objects.requireNonNull(publicKey, "publicKey"); this.publicKey = Objects.requireNonNull(publicKey, "publicKey");
@ -97,7 +96,6 @@ public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map<Stri
} }
@LauncherAPI @LauncherAPI
@SuppressWarnings("AssignmentToCollectionOrArrayFieldFromParameter")
public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map<String, byte[]> runtime) { public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map<String, byte[]> runtime) {
this.address = InetSocketAddress.createUnresolved(address, port); this.address = InetSocketAddress.createUnresolved(address, port);
this.publicKey = Objects.requireNonNull(publicKey, "publicKey"); this.publicKey = Objects.requireNonNull(publicKey, "publicKey");

View file

@ -10,9 +10,8 @@
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.*; import java.util.*;
@SuppressWarnings("ComparableImplementedButEqualsNotOverridden")
public final class ClientProfile implements Comparable<ClientProfile> { public final class ClientProfile implements Comparable<ClientProfile> {
public ClientProfile(String version, String assetIndex, int sortIndex, String title, String serverAddress, int serverPort, boolean updateFastCheck, boolean useWhitelist, String mainClass) { public ClientProfile(String version, String assetIndex, int sortIndex, String title, String serverAddress, int serverPort, boolean updateFastCheck, boolean useWhitelist, String mainClass) {
this.version = version; this.version = version;
this.assetIndex = assetIndex; this.assetIndex = assetIndex;
this.sortIndex = sortIndex; this.sortIndex = sortIndex;
@ -421,4 +420,131 @@ public void verify() {
// Client launcher // Client launcher
VerifyHelper.verify(getTitle(), VerifyHelper.NOT_EMPTY, "Main class can't be empty"); VerifyHelper.verify(getTitle(), VerifyHelper.NOT_EMPTY, "Main class can't be empty");
} }
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((assetDir == null) ? 0 : assetDir.hashCode());
result = prime * result + ((assetIndex == null) ? 0 : assetIndex.hashCode());
result = prime * result + ((classPath == null) ? 0 : classPath.hashCode());
result = prime * result + ((clientArgs == null) ? 0 : clientArgs.hashCode());
result = prime * result + ((dir == null) ? 0 : dir.hashCode());
result = prime * result + ((jvmArgs == null) ? 0 : jvmArgs.hashCode());
result = prime * result + ((mainClass == null) ? 0 : mainClass.hashCode());
result = prime * result + ((serverAddress == null) ? 0 : serverAddress.hashCode());
result = prime * result + serverPort;
result = prime * result + sortIndex;
result = prime * result + ((title == null) ? 0 : title.hashCode());
result = prime * result + ((update == null) ? 0 : update.hashCode());
result = prime * result + ((updateExclusions == null) ? 0 : updateExclusions.hashCode());
result = prime * result + (updateFastCheck ? 1231 : 1237);
result = prime * result + ((updateOptional == null) ? 0 : updateOptional.hashCode());
result = prime * result + ((updateShared == null) ? 0 : updateShared.hashCode());
result = prime * result + ((updateVerify == null) ? 0 : updateVerify.hashCode());
result = prime * result + (useWhitelist ? 1231 : 1237);
result = prime * result + ((version == null) ? 0 : version.hashCode());
result = prime * result + ((whitelist == null) ? 0 : whitelist.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ClientProfile other = (ClientProfile) obj;
if (assetDir == null) {
if (other.assetDir != null)
return false;
} else if (!assetDir.equals(other.assetDir))
return false;
if (assetIndex == null) {
if (other.assetIndex != null)
return false;
} else if (!assetIndex.equals(other.assetIndex))
return false;
if (classPath == null) {
if (other.classPath != null)
return false;
} else if (!classPath.equals(other.classPath))
return false;
if (clientArgs == null) {
if (other.clientArgs != null)
return false;
} else if (!clientArgs.equals(other.clientArgs))
return false;
if (dir == null) {
if (other.dir != null)
return false;
} else if (!dir.equals(other.dir))
return false;
if (jvmArgs == null) {
if (other.jvmArgs != null)
return false;
} else if (!jvmArgs.equals(other.jvmArgs))
return false;
if (mainClass == null) {
if (other.mainClass != null)
return false;
} else if (!mainClass.equals(other.mainClass))
return false;
if (serverAddress == null) {
if (other.serverAddress != null)
return false;
} else if (!serverAddress.equals(other.serverAddress))
return false;
if (serverPort != other.serverPort)
return false;
if (sortIndex != other.sortIndex)
return false;
if (title == null) {
if (other.title != null)
return false;
} else if (!title.equals(other.title))
return false;
if (update == null) {
if (other.update != null)
return false;
} else if (!update.equals(other.update))
return false;
if (updateExclusions == null) {
if (other.updateExclusions != null)
return false;
} else if (!updateExclusions.equals(other.updateExclusions))
return false;
if (updateFastCheck != other.updateFastCheck)
return false;
if (updateOptional == null) {
if (other.updateOptional != null)
return false;
} else if (!updateOptional.equals(other.updateOptional))
return false;
if (updateShared == null) {
if (other.updateShared != null)
return false;
} else if (!updateShared.equals(other.updateShared))
return false;
if (updateVerify == null) {
if (other.updateVerify != null)
return false;
} else if (!updateVerify.equals(other.updateVerify))
return false;
if (useWhitelist != other.useWhitelist)
return false;
if (version == null) {
if (other.version != null)
return false;
} else if (!version.equals(other.version))
return false;
if (whitelist == null) {
if (other.whitelist != null)
return false;
} else if (!whitelist.equals(other.whitelist))
return false;
return true;
}
} }

View file

@ -14,7 +14,6 @@
import java.util.Map; import java.util.Map;
public final class JVMHelper { public final class JVMHelper {
@SuppressWarnings("unused")
@LauncherAPI @LauncherAPI
public enum OS { public enum OS {
MUSTDIE("mustdie"), LINUX("linux"), MACOSX("macosx"); MUSTDIE("mustdie"), LINUX("linux"), MACOSX("macosx");
@ -84,7 +83,6 @@ public static Class<?> firstClass(String... names) throws ClassNotFoundException
} }
@LauncherAPI @LauncherAPI
@SuppressWarnings("CallToSystemGC")
public static void fullGC() { public static void fullGC() {
RUNTIME.gc(); RUNTIME.gc();
RUNTIME.runFinalization(); RUNTIME.runFinalization();
@ -122,7 +120,6 @@ public static void checkStackTrace(Class<?> mainClass) {
} }
} }
@SuppressWarnings("CallToSystemGetenv")
private static int getCorrectOSArch() { private static int getCorrectOSArch() {
// As always, mustdie must die // As always, mustdie must die
if (OS_TYPE == OS.MUSTDIE) if (OS_TYPE == OS.MUSTDIE)