IDEA Code Reformat

This commit is contained in:
Gravit 2018-11-08 19:30:16 +07:00
parent f9b8bd2947
commit 874a30eb6b
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
81 changed files with 740 additions and 697 deletions

View file

@ -9,12 +9,13 @@ public ClientPermissions() {
canAdmin = false; canAdmin = false;
canServer = false; canServer = false;
} }
public ClientPermissions(long data) { public ClientPermissions(long data) {
canAdmin = (data & (1)) != 0; canAdmin = (data & (1)) != 0;
canServer = (data & (1 << 1)) != 0; canServer = (data & (1 << 1)) != 0;
} }
public static ClientPermissions getSuperuserAccount()
{ public static ClientPermissions getSuperuserAccount() {
ClientPermissions perm = new ClientPermissions(); ClientPermissions perm = new ClientPermissions();
perm.canServer = true; perm.canServer = true;
perm.canAdmin = true; perm.canAdmin = true;

View file

@ -7,6 +7,7 @@
public final class AcceptAuthProvider extends AuthProvider { public final class AcceptAuthProvider extends AuthProvider {
private final boolean isAdminAccess; private final boolean isAdminAccess;
public AcceptAuthProvider(BlockConfigEntry block, LaunchServer server) { public AcceptAuthProvider(BlockConfigEntry block, LaunchServer server) {
super(block, server); super(block, server);
isAdminAccess = block.hasEntry("admin") ? block.getEntryValue("admin", BooleanConfigEntry.class) : false; isAdminAccess = block.hasEntry("admin") ? block.getEntryValue("admin", BooleanConfigEntry.class) : false;

View file

@ -51,8 +51,8 @@ public static void registerProviders() {
registredProv = true; registredProv = true;
} }
} }
public AuthHandler getAccociateHandler(int this_position)
{ public AuthHandler getAccociateHandler(int this_position) {
return server.config.authHandler[this_position]; return server.config.authHandler[this_position];
} }
@ -67,6 +67,7 @@ protected AuthProvider(BlockConfigEntry block, LaunchServer launchServer) {
@Override @Override
public abstract void close() throws IOException; public abstract void close() throws IOException;
@FunctionalInterface @FunctionalInterface
public interface ServerAdapter<O extends ConfigObject> { public interface ServerAdapter<O extends ConfigObject> {

View file

@ -13,6 +13,7 @@ public AuthProviderResult(String username, String accessToken) {
this.accessToken = accessToken; this.accessToken = accessToken;
permissions = ClientPermissions.DEFAULT; permissions = ClientPermissions.DEFAULT;
} }
public AuthProviderResult(String username, String accessToken, ClientPermissions permissions) { public AuthProviderResult(String username, String accessToken, ClientPermissions permissions) {
this.username = username; this.username = username;
this.accessToken = accessToken; this.accessToken = accessToken;

View file

@ -48,6 +48,7 @@ public CtClass getCtClass() {
public byte[] getBytecode() throws IOException, CannotCompileException { public byte[] getBytecode() throws IOException, CannotCompileException {
return ctClass.toBytecode(); return ctClass.toBytecode();
} }
public void compile() throws CannotCompileException { public void compile() throws CannotCompileException {
body.append("}"); body.append("}");
moduleBody.append("}"); moduleBody.append("}");
@ -83,16 +84,19 @@ public void setPort(int port) {
body.append(port); body.append(port);
body.append(";"); body.append(";");
} }
public void setClientPort(int port) { public void setClientPort(int port) {
body.append("this.clientPort = "); body.append("this.clientPort = ");
body.append(port); body.append(port);
body.append(";"); body.append(";");
} }
public void setUsingWrapper(boolean b) { public void setUsingWrapper(boolean b) {
body.append("this.isUsingWrapper = "); body.append("this.isUsingWrapper = ");
body.append(b ? "true" : "false"); body.append(b ? "true" : "false");
body.append(";"); body.append(";");
} }
public void setDownloadJava(boolean b) { public void setDownloadJava(boolean b) {
body.append("this.isDownloadJava = "); body.append("this.isDownloadJava = ");
body.append(b ? "true" : "false"); body.append(b ? "true" : "false");

View file

@ -98,6 +98,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
private static ZipEntry newEntry(String fileName) { private static ZipEntry newEntry(String fileName) {
return newZipEntry(Launcher.RUNTIME_DIR + IOHelper.CROSS_SEPARATOR + fileName); return newZipEntry(Launcher.RUNTIME_DIR + IOHelper.CROSS_SEPARATOR + 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);
} }
@ -145,13 +146,11 @@ public void build() throws IOException {
} catch (ParseException e1) { } catch (ParseException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
if(server.buildHookManager.isNeedPostProguardHook()) if (server.buildHookManager.isNeedPostProguardHook()) {
{
Path obfPath = Paths.get(server.config.binaryName + "-obf.jar"); Path obfPath = Paths.get(server.config.binaryName + "-obf.jar");
Path tmpPath = Paths.get(server.config.binaryName + "-tmp.jar"); Path tmpPath = Paths.get(server.config.binaryName + "-tmp.jar");
IOHelper.move(obfPath, tmpPath); IOHelper.move(obfPath, tmpPath);
try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(obfPath))) try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(obfPath))) {
{
try (ZipInputStream input = new ZipInputStream( try (ZipInputStream input = new ZipInputStream(
IOHelper.newInput(tmpPath))) { IOHelper.newInput(tmpPath))) {
ZipEntry e = input.getNextEntry(); ZipEntry e = input.getNextEntry();

View file

@ -43,6 +43,7 @@ public final boolean exists() {
public final DigestBytesHolder getBytes() { public final DigestBytesHolder getBytes() {
return binary; return binary;
} }
public final byte[] getSign() { public final byte[] getSign() {
return sign; return sign;
} }

View file

@ -275,8 +275,7 @@ private static void sendError(ChannelHandlerContext ctx, HttpResponseStatus stat
/** /**
* When file timestamp is the same as what the browser is sending up, send a "304 Not Modified" * When file timestamp is the same as what the browser is sending up, send a "304 Not Modified"
* *
* @param ctx * @param ctx Context
* Context
*/ */
private static void sendNotModified(ChannelHandlerContext ctx) { private static void sendNotModified(ChannelHandlerContext ctx) {
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, NOT_MODIFIED); FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, NOT_MODIFIED);
@ -289,8 +288,7 @@ private static void sendNotModified(ChannelHandlerContext ctx) {
/** /**
* Sets the Date header for the HTTP response * Sets the Date header for the HTTP response
* *
* @param response * @param response HTTP response
* HTTP response
*/ */
private static void setDateHeader(FullHttpResponse response) { private static void setDateHeader(FullHttpResponse response) {
SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
@ -303,10 +301,8 @@ private static void setDateHeader(FullHttpResponse response) {
/** /**
* Sets the Date and Cache headers for the HTTP Response * Sets the Date and Cache headers for the HTTP Response
* *
* @param response * @param response HTTP response
* HTTP response * @param fileToCache file to extract content type
* @param fileToCache
* file to extract content type
*/ */
private static void setDateAndCacheHeaders(HttpResponse response, File fileToCache) { private static void setDateAndCacheHeaders(HttpResponse response, File fileToCache) {
SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
@ -327,10 +323,8 @@ private static void setDateAndCacheHeaders(HttpResponse response, File fileToCac
/** /**
* Sets the content type header for the HTTP Response * Sets the content type header for the HTTP Response
* *
* @param response * @param response HTTP response
* HTTP response * @param file file to extract content type
* @param file
* file to extract content type
*/ */
private static void setContentTypeHeader(HttpResponse response, File file) { private static void setContentTypeHeader(HttpResponse response, File file) {
MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap(); MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();

View file

@ -64,6 +64,7 @@ public byte[] classTransform(byte[] clazz, CharSequence classname) {
for (Transformer transformer : CLASS_TRANSFORMER) result = transformer.transform(result, classname); for (Transformer transformer : CLASS_TRANSFORMER) result = transformer.transform(result, classname);
return result; return result;
} }
public byte[] proGuardClassTransform(byte[] clazz, CharSequence classname) { public byte[] proGuardClassTransform(byte[] clazz, CharSequence classname) {
byte[] result = clazz; byte[] result = clazz;
for (Transformer transformer : POST_PROGUARD_HOOKS) result = transformer.transform(result, classname); for (Transformer transformer : POST_PROGUARD_HOOKS) result = transformer.transform(result, classname);
@ -109,11 +110,12 @@ public void registerIgnoredClass(String clazz) {
public void registerPostHook(PostBuildHook hook) { public void registerPostHook(PostBuildHook hook) {
POST_HOOKS.add(hook); POST_HOOKS.add(hook);
} }
public void registerProGuardHook(Transformer hook) { public void registerProGuardHook(Transformer hook) {
POST_PROGUARD_HOOKS.add(hook); POST_PROGUARD_HOOKS.add(hook);
} }
public boolean isNeedPostProguardHook()
{ public boolean isNeedPostProguardHook() {
return !POST_PROGUARD_HOOKS.isEmpty(); return !POST_PROGUARD_HOOKS.isEmpty();
} }

View file

@ -7,58 +7,63 @@
import java.util.ArrayList; import java.util.ArrayList;
public class MirrorManager { public class MirrorManager {
public class Mirror public class Mirror {
{
URL url; URL url;
String assetsURLMask; String assetsURLMask;
String clientsURLMask; String clientsURLMask;
boolean enabled; boolean enabled;
Mirror(String url)
{ Mirror(String url) {
assetsURLMask = url.concat("assets/%s.zip"); assetsURLMask = url.concat("assets/%s.zip");
clientsURLMask = url.concat("clients/%s.zip"); clientsURLMask = url.concat("clients/%s.zip");
} }
private URL formatArg(String mask, String arg) throws MalformedURLException { private URL formatArg(String mask, String arg) throws MalformedURLException {
return new URL(String.format(mask, IOHelper.urlEncode(arg))); return new URL(String.format(mask, IOHelper.urlEncode(arg)));
} }
public URL getAssetsURL(String assets) throws MalformedURLException { public URL getAssetsURL(String assets) throws MalformedURLException {
return formatArg(assetsURLMask, assets); return formatArg(assetsURLMask, assets);
} }
public URL getClientsURL(String client) throws MalformedURLException { public URL getClientsURL(String client) throws MalformedURLException {
return formatArg(clientsURLMask, client); return formatArg(clientsURLMask, client);
} }
} }
protected ArrayList<Mirror> list = new ArrayList<>(); protected ArrayList<Mirror> list = new ArrayList<>();
private Mirror defaultMirror; private Mirror defaultMirror;
public void addMirror(String mirror) throws MalformedURLException { public void addMirror(String mirror) throws MalformedURLException {
Mirror m = new Mirror(mirror); Mirror m = new Mirror(mirror);
m.enabled = true; m.enabled = true;
if (defaultMirror == null) defaultMirror = m; if (defaultMirror == null) defaultMirror = m;
} }
public void addMirror(String mirror, boolean enabled) throws MalformedURLException { public void addMirror(String mirror, boolean enabled) throws MalformedURLException {
Mirror m = new Mirror(mirror); Mirror m = new Mirror(mirror);
m.url = new URL(mirror); m.url = new URL(mirror);
m.enabled = enabled; m.enabled = enabled;
if (defaultMirror == null && enabled) defaultMirror = m; if (defaultMirror == null && enabled) defaultMirror = m;
} }
public Mirror getDefaultMirror()
{ public Mirror getDefaultMirror() {
return defaultMirror; return defaultMirror;
} }
public void setDefaultMirror(Mirror m)
{ public void setDefaultMirror(Mirror m) {
defaultMirror = m; defaultMirror = m;
} }
public void disableMirror(int index)
{ public void disableMirror(int index) {
list.get(index).enabled = false; list.get(index).enabled = false;
} }
public void enableMirror(int index)
{ public void enableMirror(int index) {
list.get(index).enabled = true; list.get(index).enabled = true;
} }
public int size()
{ public int size() {
return list.size(); return list.size();
} }
} }

View file

@ -71,8 +71,7 @@ public void reply() throws Exception {
AuthProvider.authError(server.config.authRejectString); AuthProvider.authError(server.config.authRejectString);
return; return;
} }
if(!clientData.checkSign) if (!clientData.checkSign) {
{
throw new AuthException("You must using checkLauncher"); throw new AuthException("You must using checkLauncher");
} }
result = provider.auth(login, password, ip); result = provider.auth(login, password, ip);

View file

@ -19,8 +19,7 @@ public void reply() throws Exception {
writeNoError(output); writeNoError(output);
output.writeBoolean(needChange); output.writeBoolean(needChange);
//if true //if true
if(needChange) if (needChange) {
{
output.writeString(address, 255); output.writeString(address, 255);
output.writeInt(port); output.writeInt(port);
} }

View file

@ -26,8 +26,7 @@ public void reply() throws IOException {
} }
Client client = server.sessionManager.getOrNewClient(session); Client client = server.sessionManager.getOrNewClient(session);
byte[] digest = input.readByteArray(0); byte[] digest = input.readByteArray(0);
if(!Arrays.equals(bytes.getDigest(), digest)) if (!Arrays.equals(bytes.getDigest(), digest)) {
{
writeNoError(output); writeNoError(output);
output.writeBoolean(true); output.writeBoolean(true);
output.writeByteArray(bytes.getBytes(), 0); output.writeByteArray(bytes.getBytes(), 0);

View file

@ -38,9 +38,11 @@ public void reply() throws IOException {
return; return;
} }
Client clientData = server.sessionManager.getClient(session); Client clientData = server.sessionManager.getClient(session);
if(!clientData.isAuth || clientData.type != Client.Type.USER || clientData.profile == null) { requestError("Assess denied"); return;} if (!clientData.isAuth || clientData.type != Client.Type.USER || clientData.profile == null) {
for(SignedObjectHolder<ClientProfile> p : server.getProfiles()) requestError("Assess denied");
{ return;
}
for (SignedObjectHolder<ClientProfile> p : server.getProfiles()) {
ClientProfile profile = p.object; ClientProfile profile = p.object;
if (!clientData.profile.getTitle().equals(profile.getTitle())) continue; if (!clientData.profile.getTitle().equals(profile.getTitle())) continue;
if (!profile.isWhitelistContains(clientData.username)) { if (!profile.isWhitelistContains(clientData.username)) {

View file

@ -23,12 +23,13 @@ public Client(long session) {
username = ""; username = "";
checkSign = false; checkSign = false;
} }
//Данные ваторизации //Данные ваторизации
public void up() { public void up() {
timestamp = System.currentTimeMillis(); timestamp = System.currentTimeMillis();
} }
public enum Type
{ public enum Type {
SERVER, SERVER,
USER USER
} }

View file

@ -11,14 +11,17 @@
import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.Client;
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 class WebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> { public class WebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
public static LaunchServer server; public static LaunchServer server;
public static GsonBuilder builder = new GsonBuilder(); public static GsonBuilder builder = new GsonBuilder();
public static WebSocketService service = new WebSocketService(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE), LaunchServer.server, builder); public static WebSocketService service = new WebSocketService(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE), LaunchServer.server, builder);
private Client client; private Client client;
static { static {
service.registerResponses(); service.registerResponses();
} }
@Override @Override
public void channelActive(ChannelHandlerContext ctx) { public void channelActive(ChannelHandlerContext ctx) {
LogHelper.debug("New client %s", IOHelper.getIP(ctx.channel().remoteAddress())); LogHelper.debug("New client %s", IOHelper.getIP(ctx.channel().remoteAddress()));

View file

@ -25,6 +25,7 @@
public class WebSocketService { public class WebSocketService {
public final ChannelGroup channels; public final ChannelGroup channels;
public WebSocketService(ChannelGroup channels, LaunchServer server, GsonBuilder gson) { public WebSocketService(ChannelGroup channels, LaunchServer server, GsonBuilder gson) {
this.channels = channels; this.channels = channels;
this.server = server; this.server = server;
@ -40,32 +41,30 @@ public WebSocketService(ChannelGroup channels, LaunchServer server, GsonBuilder
private final Gson gson; private final Gson gson;
private final GsonBuilder gsonBuiler; private final GsonBuilder gsonBuiler;
void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client) void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client) {
{
String request = frame.text(); String request = frame.text();
JsonResponseInterface response = gson.fromJson(request, JsonResponseInterface.class); JsonResponseInterface response = gson.fromJson(request, JsonResponseInterface.class);
try { try {
response.execute(this, ctx, client); response.execute(this, ctx, client);
} catch (Exception e) } catch (Exception e) {
{
LogHelper.error(e); LogHelper.error(e);
sendObject(ctx, new ExceptionResult(e)); sendObject(ctx, new ExceptionResult(e));
} }
} }
public Class getResponseClass(String type)
{ public Class getResponseClass(String type) {
return responses.get(type); return responses.get(type);
} }
public void registerResponse(String key,Class responseInterfaceClass)
{ public void registerResponse(String key, Class responseInterfaceClass) {
responses.put(key, responseInterfaceClass); responses.put(key, responseInterfaceClass);
} }
public void registerClient(Channel channel)
{ public void registerClient(Channel channel) {
channels.add(channel); channels.add(channel);
} }
public void registerResponses()
{ public void registerResponses() {
registerResponse("echo", EchoResponse.class); registerResponse("echo", EchoResponse.class);
registerResponse("auth", AuthResponse.class); registerResponse("auth", AuthResponse.class);
registerResponse("checkServer", CheckServerResponse.class); registerResponse("checkServer", CheckServerResponse.class);
@ -74,20 +73,20 @@ public void registerResponses()
registerResponse("updateList", UpdateListResponse.class); registerResponse("updateList", UpdateListResponse.class);
registerResponse("cmdExec", UpdateListResponse.class); registerResponse("cmdExec", UpdateListResponse.class);
} }
public void sendObject(ChannelHandlerContext ctx, Object obj)
{ public void sendObject(ChannelHandlerContext ctx, Object obj) {
ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj))); ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj)));
} }
public void sendObjectAndClose(ChannelHandlerContext ctx, Object obj)
{ public void sendObjectAndClose(ChannelHandlerContext ctx, Object obj) {
ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj))).addListener(ChannelFutureListener.CLOSE); ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj))).addListener(ChannelFutureListener.CLOSE);
} }
public void sendEvent(EventResult obj)
{ public void sendEvent(EventResult obj) {
channels.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj))); channels.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj)));
} }
public static class ErrorResult
{ public static class ErrorResult {
public ErrorResult(String error) { public ErrorResult(String error) {
this.error = error; this.error = error;
this.type = "requestError"; this.type = "requestError";
@ -96,8 +95,8 @@ public ErrorResult(String error) {
public final String error; public final String error;
public final String type; public final String type;
} }
public static class SuccessResult
{ public static class SuccessResult {
public SuccessResult(String requesttype) { public SuccessResult(String requesttype) {
this.requesttype = requesttype; this.requesttype = requesttype;
this.type = "success"; this.type = "success";
@ -106,15 +105,16 @@ public SuccessResult(String requesttype) {
public final String requesttype; public final String requesttype;
public final String type; public final String type;
} }
public static class EventResult
{ public static class EventResult {
public EventResult() { public EventResult() {
this.type = "event"; this.type = "event";
} }
public final String type; public final String type;
} }
public static class ExceptionResult
{ public static class ExceptionResult {
public ExceptionResult(Exception e) { public ExceptionResult(Exception e) {
this.message = e.getMessage(); this.message = e.getMessage();
this.clazz = e.getClass().getName(); this.clazz = e.getClass().getName();

View file

@ -22,8 +22,8 @@ public void execute(WebSocketService service,ChannelHandlerContext ctx, Client c
LogHelper.info("Echo: %s, isAuth %s", echo, client.isAuth ? "true" : "false"); LogHelper.info("Echo: %s, isAuth %s", echo, client.isAuth ? "true" : "false");
service.sendObject(ctx, new Result(echo)); service.sendObject(ctx, new Result(echo));
} }
public class Result
{ public class Result {
String echo; String echo;
public Result(String echo) { public Result(String echo) {

View file

@ -6,5 +6,6 @@
public interface JsonResponseInterface { public interface JsonResponseInterface {
String getType(); String getType();
void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception; void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception;
} }

View file

@ -8,6 +8,7 @@
public class ExecCommandResponse implements JsonResponseInterface { public class ExecCommandResponse implements JsonResponseInterface {
public String cmd; public String cmd;
@Override @Override
public String getType() { public String getType() {
return "cmdExec"; return "cmdExec";
@ -15,8 +16,14 @@ public String getType() {
@Override @Override
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
if(!client.isAuth) {service.sendObject(ctx,new WebSocketService.ErrorResult("Access denied")); return; } if (!client.isAuth) {
if(!client.permissions.canAdmin) {service.sendObject(ctx,new WebSocketService.ErrorResult("Access denied")); return; } service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied"));
return;
}
if (!client.permissions.canAdmin) {
service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied"));
return;
}
LaunchServer.server.commandHandler.eval(cmd, false); LaunchServer.server.commandHandler.eval(cmd, false);
service.sendObject(ctx, new WebSocketService.SuccessResult("cmdExec")); service.sendObject(ctx, new WebSocketService.SuccessResult("cmdExec"));
} }

View file

@ -32,6 +32,7 @@ public AuthResponse(String login, String password, int authid, HWID hwid) {
public int authid; public int authid;
public HWID hwid; public HWID hwid;
@Override @Override
public String getType() { public String getType() {
return "auth"; return "auth";
@ -45,8 +46,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
AuthProvider.authError(LaunchServer.server.config.authRejectString); AuthProvider.authError(LaunchServer.server.config.authRejectString);
return; return;
} }
if(!clientData.checkSign) if (!clientData.checkSign) {
{
AuthProvider.authError("Don't skip Launcher Update"); AuthProvider.authError("Don't skip Launcher Update");
return; return;
} }
@ -72,13 +72,12 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
clientData.isAuth = true; clientData.isAuth = true;
clientData.permissions = result.permissions; clientData.permissions = result.permissions;
service.sendObject(ctx, new WebSocketService.SuccessResult("auth")); service.sendObject(ctx, new WebSocketService.SuccessResult("auth"));
} catch (AuthException | HWIDException e) } catch (AuthException | HWIDException e) {
{
service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage())); service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage()));
} }
} }
public class Result
{ public class Result {
public Result() { public Result() {
} }

View file

@ -13,6 +13,7 @@
public class CheckServerResponse implements JsonResponseInterface { public class CheckServerResponse implements JsonResponseInterface {
public String serverID; public String serverID;
public String username; public String username;
@Override @Override
public String getType() { public String getType() {
return "checkServer"; return "checkServer";
@ -33,8 +34,8 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
} }
service.sendObject(ctx, new Result()); service.sendObject(ctx, new Result());
} }
public class Result
{ public class Result {
public String type = "success"; public String type = "success";
public String requesttype = "checkServer"; public String requesttype = "checkServer";
} }

View file

@ -12,6 +12,7 @@ public class JoinServerResponse implements JsonResponseInterface {
public String serverID; public String serverID;
public String accessToken; public String accessToken;
public String username; public String username;
@Override @Override
public String getType() { public String getType() {
return "joinServer"; return "joinServer";
@ -32,8 +33,8 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
} }
service.sendObject(ctx, new Result(success)); service.sendObject(ctx, new Result(success));
} }
public class Result
{ public class Result {
public String type = "success"; public String type = "success";
public String requesttype = "checkServer"; public String requesttype = "checkServer";

View file

@ -17,6 +17,7 @@ public class LauncherResponse implements JsonResponseInterface {
//REPLACED TO REAL URL //REPLACED TO REAL URL
public static final String JAR_URL = "http://localhost:9752/Launcher.jar"; public static final String JAR_URL = "http://localhost:9752/Launcher.jar";
public static final String EXE_URL = "http://localhost:9752/Launcher.exe"; public static final String EXE_URL = "http://localhost:9752/Launcher.exe";
@Override @Override
public String getType() { public String getType() {
return "launcherUpdate"; return "launcherUpdate";
@ -29,29 +30,25 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
{ {
byte[] hash = LaunchServer.server.launcherBinary.getBytes().getDigest(); byte[] hash = LaunchServer.server.launcherBinary.getBytes().getDigest();
if (hash == null) service.sendObjectAndClose(ctx, new Result(true, JAR_URL)); if (hash == null) service.sendObjectAndClose(ctx, new Result(true, JAR_URL));
if(Arrays.equals(bytes, hash)) if (Arrays.equals(bytes, hash)) {
{
service.sendObject(ctx, new Result(false, JAR_URL)); service.sendObject(ctx, new Result(false, JAR_URL));
} else } else {
{
service.sendObjectAndClose(ctx, new Result(true, JAR_URL)); service.sendObjectAndClose(ctx, new Result(true, JAR_URL));
} }
} else if (launcher_type == 2) //EXE } else if (launcher_type == 2) //EXE
{ {
byte[] hash = LaunchServer.server.launcherEXEBinary.getBytes().getDigest(); byte[] hash = LaunchServer.server.launcherEXEBinary.getBytes().getDigest();
if (hash == null) service.sendObjectAndClose(ctx, new Result(true, EXE_URL)); if (hash == null) service.sendObjectAndClose(ctx, new Result(true, EXE_URL));
if(Arrays.equals(bytes, hash)) if (Arrays.equals(bytes, hash)) {
{
service.sendObject(ctx, new Result(false, EXE_URL)); service.sendObject(ctx, new Result(false, EXE_URL));
} else } else {
{
service.sendObjectAndClose(ctx, new Result(true, EXE_URL)); service.sendObjectAndClose(ctx, new Result(true, EXE_URL));
} }
} else service.sendObject(ctx, new WebSocketService.ErrorResult("Request launcher type error")); } else service.sendObject(ctx, new WebSocketService.ErrorResult("Request launcher type error"));
} }
public class Result
{ public class Result {
public String type = "success"; public String type = "success";
public String requesttype = "launcherUpdate"; public String requesttype = "launcherUpdate";
public String url; public String url;

View file

@ -9,6 +9,7 @@
public class UpdateListResponse implements JsonResponseInterface { public class UpdateListResponse implements JsonResponseInterface {
public String dir; public String dir;
@Override @Override
public String getType() { public String getType() {
return "updateList"; return "updateList";
@ -23,8 +24,8 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
HashedDir hdir = LaunchServer.server.updatesDirMap.get(dir).object; HashedDir hdir = LaunchServer.server.updatesDirMap.get(dir).object;
service.sendObject(ctx, new Result(hdir)); service.sendObject(ctx, new Result(hdir));
} }
class Result
{ class Result {
public final String type; public final String type;
public final String requesttype; public final String requesttype;
public final HashedDir dir; public final HashedDir dir;

View file

@ -15,6 +15,7 @@
public class AvanguardStarter { public class AvanguardStarter {
static class SecurityThread implements Runnable { static class SecurityThread implements Runnable {
static long macID = GuardBind.avnGetMacId(); static long macID = GuardBind.avnGetMacId();
@Override @Override
public void run() { public void run() {
while (!Thread.interrupted()) { while (!Thread.interrupted()) {
@ -43,18 +44,16 @@ public void run() {
} }
} }
} }
static void safeHalt(int exitcode)
{ static void safeHalt(int exitcode) {
try { try {
SafeExitJVMLegacy.exit(exitcode); SafeExitJVMLegacy.exit(exitcode);
} catch (Throwable ignored) } catch (Throwable ignored) {
{
} }
try { try {
SafeExitJVM.exit(exitcode); SafeExitJVM.exit(exitcode);
} catch (Throwable ignored) } catch (Throwable ignored) {
{
} }
NativeJVMHalt halt = new NativeJVMHalt(exitcode); NativeJVMHalt halt = new NativeJVMHalt(exitcode);
@ -72,8 +71,7 @@ public static void main(boolean init) {
LogHelper.error("Cheating == crash!"); LogHelper.error("Cheating == crash!");
try { try {
SafeExitJVM.exit(threatType + 7000); SafeExitJVM.exit(threatType + 7000);
} catch (Throwable e) } catch (Throwable e) {
{
SafeExitJVMLegacy.exit(threatType + 7000); SafeExitJVMLegacy.exit(threatType + 7000);
} }
return false; return false;
@ -82,8 +80,8 @@ public static void main(boolean init) {
GuardBind.avnStartDefence(); GuardBind.avnStartDefence();
CommonHelper.newThread("Security Thread", true, new SecurityThread()).start(); CommonHelper.newThread("Security Thread", true, new SecurityThread()).start();
} }
public static void load()
{ public static void load() {
GuardBind.startAbs(avanguard.toString()); GuardBind.startAbs(avanguard.toString());
} }

View file

@ -43,9 +43,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep
} else { } else {
LogHelper.debug("Process started success"); LogHelper.debug("Process started success");
} }
} } else {
else
{
process.waitFor(); process.waitFor();
} }
} }

View file

@ -217,8 +217,8 @@ public void start(String... args) throws Throwable {
Launcher.modulesManager.postInitModules(); Launcher.modulesManager.postInitModules();
invoker.invokeFunction("start", (Object) args); invoker.invokeFunction("start", (Object) args);
} }
public static LauncherEngine clientInstance()
{ public static LauncherEngine clientInstance() {
return new LauncherEngine(); return new LauncherEngine();
} }
} }

View file

@ -88,8 +88,7 @@ public Params(byte[] launcherDigest, Path assetDir, Path clientDir, PlayerProfil
boolean autoEnter, boolean fullScreen, int ram, int width, int height) { boolean autoEnter, boolean fullScreen, int ram, int width, int height) {
this.launcherDigest = launcherDigest.clone(); this.launcherDigest = launcherDigest.clone();
this.updateOptional = new HashSet<>(); this.updateOptional = new HashSet<>();
for(ClientProfile.MarkedString s : Launcher.profile.getOptional()) for (ClientProfile.MarkedString s : Launcher.profile.getOptional()) {
{
if (s.mark) updateOptional.add(s); if (s.mark) updateOptional.add(s);
} }
// Client paths // Client paths
@ -113,8 +112,7 @@ public Params(HInput input) throws Exception {
clientDir = IOHelper.toPath(input.readString(0)); clientDir = IOHelper.toPath(input.readString(0));
updateOptional = new HashSet<>(); updateOptional = new HashSet<>();
int len = input.readLength(128); int len = input.readLength(128);
for(int i=0;i<len;++i) for (int i = 0; i < len; ++i) {
{
updateOptional.add(new ClientProfile.MarkedString(input.readString(512), true)); updateOptional.add(new ClientProfile.MarkedString(input.readString(512), true));
} }
// Client params // Client params
@ -136,8 +134,7 @@ public void write(HOutput output) throws IOException {
output.writeString(assetDir.toString(), 0); output.writeString(assetDir.toString(), 0);
output.writeString(clientDir.toString(), 0); output.writeString(clientDir.toString(), 0);
output.writeLength(updateOptional.size(), 128); output.writeLength(updateOptional.size(), 128);
for(ClientProfile.MarkedString s : updateOptional) for (ClientProfile.MarkedString s : updateOptional) {
{
output.writeString(s.string, 512); output.writeString(s.string, 512);
} }
// Client params // Client params
@ -227,6 +224,7 @@ private static void addClientArgs(Collection<String> args, ClientProfile profile
Collections.addAll(args, "--height", Integer.toString(params.height)); Collections.addAll(args, "--height", Integer.toString(params.height));
} }
} }
@LauncherAPI @LauncherAPI
public static void setJavaBinPath(Path javaBinPath) { public static void setJavaBinPath(Path javaBinPath) {
JavaBinPath = javaBinPath; JavaBinPath = javaBinPath;
@ -289,7 +287,9 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl
System.setProperty("minecraft.applet.TargetDirectory", params.clientDir.toString()); // For 1.5.2 System.setProperty("minecraft.applet.TargetDirectory", params.clientDir.toString()); // For 1.5.2
mainMethod.invoke((Object) args.toArray(EMPTY_ARRAY)); mainMethod.invoke((Object) args.toArray(EMPTY_ARRAY));
} }
private static Process process = null; private static Process process = null;
@LauncherAPI @LauncherAPI
public static Process launch( public static Process launch(
SignedObjectHolder<HashedDir> assetHDir, SignedObjectHolder<HashedDir> clientHDir, SignedObjectHolder<HashedDir> assetHDir, SignedObjectHolder<HashedDir> clientHDir,
@ -304,13 +304,11 @@ public static Process launch(
socket.setReuseAddress(true); socket.setReuseAddress(true);
socket.bind(new InetSocketAddress(SOCKET_HOST, SOCKET_PORT)); socket.bind(new InetSocketAddress(SOCKET_HOST, SOCKET_PORT));
Socket client = socket.accept(); Socket client = socket.accept();
if(process == null) if (process == null) {
{
LogHelper.error("Process is null"); LogHelper.error("Process is null");
return; return;
} }
if(!process.isAlive()) if (!process.isAlive()) {
{
LogHelper.error("Process is not alive"); LogHelper.error("Process is not alive");
JOptionPane.showMessageDialog(null, "Client Process crashed", "Launcher", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, "Client Process crashed", "Launcher", JOptionPane.ERROR_MESSAGE);
return; return;
@ -337,15 +335,13 @@ public static Process launch(
boolean wrapper = isUsingWrapper(); boolean wrapper = isUsingWrapper();
Path javaBin; Path javaBin;
if (wrapper) javaBin = AvanguardStarter.wrapper; if (wrapper) javaBin = AvanguardStarter.wrapper;
else if(isDownloadJava) else if (isDownloadJava) {
{
//Linux и Mac не должны скачивать свою JVM //Linux и Mac не должны скачивать свою JVM
if (JVMHelper.OS_TYPE == OS.MUSTDIE) if (JVMHelper.OS_TYPE == OS.MUSTDIE)
javaBin = IOHelper.resolveJavaBin(JavaBinPath); javaBin = IOHelper.resolveJavaBin(JavaBinPath);
else else
javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home")));
} } else
else
javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home")));
args.add(javaBin.toString()); args.add(javaBin.toString());
args.add(MAGICAL_INTEL_OPTION); args.add(MAGICAL_INTEL_OPTION);
@ -463,8 +459,7 @@ public static void main(String... args) throws Throwable {
// Verify current state of all dirs // Verify current state of all dirs
//verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest);
HashedDir hdir = clientHDir.object; HashedDir hdir = clientHDir.object;
for(ClientProfile.MarkedString s : Launcher.profile.getOptional()) for (ClientProfile.MarkedString s : Launcher.profile.getOptional()) {
{
if (params.updateOptional.contains(s)) s.mark = true; if (params.updateOptional.contains(s)) s.mark = true;
else hdir.removeR(s.string); else hdir.removeR(s.string);
} }
@ -477,6 +472,7 @@ public static void main(String... args) throws Throwable {
launch(profile.object, params); launch(profile.object, params);
} }
} }
@LauncherAPI @LauncherAPI
public void launchLocal(SignedObjectHolder<HashedDir> assetHDir, SignedObjectHolder<HashedDir> clientHDir, public void launchLocal(SignedObjectHolder<HashedDir> assetHDir, SignedObjectHolder<HashedDir> clientHDir,
SignedObjectHolder<ClientProfile> profile, Params params) throws Throwable { SignedObjectHolder<ClientProfile> profile, Params params) throws Throwable {
@ -502,8 +498,7 @@ public void launchLocal(SignedObjectHolder<HashedDir> assetHDir, SignedObjectHol
// Verify current state of all dirs // Verify current state of all dirs
//verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest);
HashedDir hdir = clientHDir.object; HashedDir hdir = clientHDir.object;
for(ClientProfile.MarkedString s : Launcher.profile.getOptional()) for (ClientProfile.MarkedString s : Launcher.profile.getOptional()) {
{
if (params.updateOptional.contains(s)) s.mark = true; if (params.updateOptional.contains(s)) s.mark = true;
else hdir.removeR(s.string); else hdir.removeR(s.string);
} }

View file

@ -14,18 +14,18 @@
public class FunctionalBridge { public class FunctionalBridge {
@LauncherAPI @LauncherAPI
public static LauncherSettings settings; public static LauncherSettings settings;
@LauncherAPI @LauncherAPI
public HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder<HashedDir> hdir, FileNameMatcher matcher, boolean digest) throws Exception public HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder<HashedDir> hdir, FileNameMatcher matcher, boolean digest) throws Exception {
{
return () -> { return () -> {
if(hdir == null) if (hdir == null) {
{
Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName)); Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName));
} }
ClientLauncher.verifyHDir(dir, hdir.object, matcher, digest); ClientLauncher.verifyHDir(dir, hdir.object, matcher, digest);
return hdir; return hdir;
}; };
} }
@LauncherAPI @LauncherAPI
public LegacyLauncherRequest.Result offlineLauncherRequest() throws IOException, SignatureException { public LegacyLauncherRequest.Result offlineLauncherRequest() throws IOException, SignatureException {
if (settings.lastDigest == null || settings.lastProfiles.isEmpty()) { if (settings.lastDigest == null || settings.lastProfiles.isEmpty()) {
@ -40,6 +40,7 @@ public LegacyLauncherRequest.Result offlineLauncherRequest() throws IOException,
// Return last sign and profiles // Return last sign and profiles
return new LegacyLauncherRequest.Result(null, settings.lastDigest, settings.lastProfiles); return new LegacyLauncherRequest.Result(null, settings.lastDigest, settings.lastProfiles);
} }
@FunctionalInterface @FunctionalInterface
public interface HashedDirRunnable { public interface HashedDirRunnable {
SignedObjectHolder<HashedDir> run() throws Exception; SignedObjectHolder<HashedDir> run() throws Exception;

View file

@ -47,12 +47,12 @@ public class LauncherSettings {
public List<SignedObjectHolder<ClientProfile>> lastProfiles = new LinkedList<>(); public List<SignedObjectHolder<ClientProfile>> lastProfiles = new LinkedList<>();
@LauncherAPI @LauncherAPI
public Map<String, SignedObjectHolder<HashedDir>> lastHDirs = new HashMap<>(16); public Map<String, SignedObjectHolder<HashedDir>> lastHDirs = new HashMap<>(16);
@LauncherAPI @LauncherAPI
public void load() throws SignatureException { public void load() throws SignatureException {
LogHelper.debug("Loading settings file"); LogHelper.debug("Loading settings file");
try { try {
try(HInput input = new HInput(IOHelper.newInput(file))) try (HInput input = new HInput(IOHelper.newInput(file))) {
{
read(input); read(input);
} }
} catch (IOException e) { } catch (IOException e) {
@ -60,12 +60,12 @@ public void load() throws SignatureException {
setDefault(); setDefault();
} }
} }
@LauncherAPI @LauncherAPI
public void save() throws SignatureException { public void save() throws SignatureException {
LogHelper.debug("Save settings file"); LogHelper.debug("Save settings file");
try { try {
try(HOutput output = new HOutput(IOHelper.newOutput(file))) try (HOutput output = new HOutput(IOHelper.newOutput(file))) {
{
write(output); write(output);
} }
} catch (IOException e) { } catch (IOException e) {
@ -73,9 +73,9 @@ public void save() throws SignatureException {
setDefault(); setDefault();
} }
} }
@LauncherAPI @LauncherAPI
public void read(HInput input) throws IOException, SignatureException public void read(HInput input) throws IOException, SignatureException {
{
int magic = input.readInt(); int magic = input.readInt();
if (magic != settingsMagic) { if (magic != settingsMagic) {
setDefault(); setDefault();
@ -117,6 +117,7 @@ public void read(HInput input) throws IOException, SignatureException
java.lang.String.format("Duplicate offline hashed dir: '%s'", name)); java.lang.String.format("Duplicate offline hashed dir: '%s'", name));
} }
} }
@LauncherAPI @LauncherAPI
public void write(HOutput output) throws IOException { public void write(HOutput output) throws IOException {
output.writeInt(settingsMagic); output.writeInt(settingsMagic);
@ -156,14 +157,14 @@ public void write(HOutput output) throws IOException {
entry.getValue().write(output); entry.getValue().write(output);
} }
} }
@LauncherAPI @LauncherAPI
public void setRAM(int ram) public void setRAM(int ram) {
{
this.ram = java.lang.Math.min(((ram / 256)) * 256, JVMHelper.RAM); this.ram = java.lang.Math.min(((ram / 256)) * 256, JVMHelper.RAM);
} }
@LauncherAPI @LauncherAPI
public void setDefault() public void setDefault() {
{
// Auth settings // Auth settings
login = null; login = null;
rsaPassword = null; rsaPassword = null;
@ -182,6 +183,7 @@ public void setDefault()
lastProfiles.clear(); lastProfiles.clear();
lastHDirs.clear(); lastHDirs.clear();
} }
@LauncherAPI @LauncherAPI
public byte[] setPassword(String password) throws BadPaddingException, IllegalBlockSizeException { public byte[] setPassword(String password) throws BadPaddingException, IllegalBlockSizeException {
byte[] encrypted = SecurityHelper.newRSAEncryptCipher(Launcher.getConfig().publicKey).doFinal(IOHelper.encode(password)); byte[] encrypted = SecurityHelper.newRSAEncryptCipher(Launcher.getConfig().publicKey).doFinal(IOHelper.encode(password));

View file

@ -41,6 +41,7 @@ public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword
this.encryptedPassword = encryptedPassword.clone(); this.encryptedPassword = encryptedPassword.clone();
auth_id = 0; auth_id = 0;
} }
@LauncherAPI @LauncherAPI
public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, int auth_id) { public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, int auth_id) {
super(config); super(config);
@ -53,6 +54,7 @@ public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword
public AuthRequest(String login, byte[] encryptedPassword) { public AuthRequest(String login, byte[] encryptedPassword) {
this(null, login, encryptedPassword); this(null, login, encryptedPassword);
} }
@LauncherAPI @LauncherAPI
public AuthRequest(String login, byte[] encryptedPassword, int auth_id) { public AuthRequest(String login, byte[] encryptedPassword, int auth_id) {
this(null, login, encryptedPassword, auth_id); this(null, login, encryptedPassword, auth_id);

View file

@ -40,6 +40,7 @@ public AuthServerRequest(LauncherConfig config, String login, byte[] encryptedPa
auth_id = 0; auth_id = 0;
title = ""; title = "";
} }
@LauncherAPI @LauncherAPI
public AuthServerRequest(LauncherConfig config, String login, byte[] encryptedPassword, int auth_id) { public AuthServerRequest(LauncherConfig config, String login, byte[] encryptedPassword, int auth_id) {
super(config); super(config);
@ -48,6 +49,7 @@ public AuthServerRequest(LauncherConfig config, String login, byte[] encryptedPa
this.auth_id = auth_id; this.auth_id = auth_id;
title = ""; title = "";
} }
@LauncherAPI @LauncherAPI
public AuthServerRequest(LauncherConfig config, String login, byte[] encryptedPassword, int auth_id, String title) { public AuthServerRequest(LauncherConfig config, String login, byte[] encryptedPassword, int auth_id, String title) {
super(config); super(config);
@ -61,6 +63,7 @@ public AuthServerRequest(LauncherConfig config, String login, byte[] encryptedPa
public AuthServerRequest(String login, byte[] encryptedPassword) { public AuthServerRequest(String login, byte[] encryptedPassword) {
this(null, login, encryptedPassword); this(null, login, encryptedPassword);
} }
@LauncherAPI @LauncherAPI
public AuthServerRequest(String login, byte[] encryptedPassword, int auth_id) { public AuthServerRequest(String login, byte[] encryptedPassword, int auth_id) {
this(null, login, encryptedPassword, auth_id); this(null, login, encryptedPassword, auth_id);

View file

@ -13,19 +13,19 @@ public class ChangeServerRequest extends Request<ChangeServerRequest.Result> {
public Integer getType() { public Integer getType() {
return RequestType.CHANGESERVER.getNumber(); return RequestType.CHANGESERVER.getNumber();
} }
public boolean change(Result result)
{ public boolean change(Result result) {
if (!result.needChange) return false; if (!result.needChange) return false;
Launcher.getConfig().address = InetSocketAddress.createUnresolved(result.address, result.port); Launcher.getConfig().address = InetSocketAddress.createUnresolved(result.address, result.port);
return true; return true;
} }
@Override @Override
protected Result requestDo(HInput input, HOutput output) throws Exception { protected Result requestDo(HInput input, HOutput output) throws Exception {
readError(input); readError(input);
Result result = new Result(); Result result = new Result();
result.needChange = input.readBoolean(); result.needChange = input.readBoolean();
if(result.needChange) if (result.needChange) {
{
result.address = input.readString(255); result.address = input.readString(255);
result.port = input.readInt(); result.port = input.readInt();
} }
@ -33,8 +33,7 @@ protected Result requestDo(HInput input, HOutput output) throws Exception {
return result; return result;
} }
public class Result public class Result {
{
public boolean needChange; public boolean needChange;
public String address; public String address;
public int port; public int port;

View file

@ -42,8 +42,7 @@ protected PlayerProfile requestDo(HInput input, HOutput output) throws IOExcepti
if (Launcher.profile == null) { if (Launcher.profile == null) {
LogHelper.error("Profile is null. Title is not net."); LogHelper.error("Profile is null. Title is not net.");
output.writeString("", SerializeLimits.MAX_CLIENT); output.writeString("", SerializeLimits.MAX_CLIENT);
} } else
else
output.writeString(Launcher.profile.getTitle(), SerializeLimits.MAX_CLIENT); output.writeString(Launcher.profile.getTitle(), SerializeLimits.MAX_CLIENT);
output.flush(); output.flush();

View file

@ -26,34 +26,36 @@ public ClientWebSocketService(GsonBuilder gsonBuilder,ClientJSONPoint point) {
this.point = point; this.point = point;
point.setService(this); point.setService(this);
} }
public void processMessage(Reader reader)
{ public void processMessage(Reader reader) {
ResultInterface result = gson.fromJson(reader, ResultInterface.class); ResultInterface result = gson.fromJson(reader, ResultInterface.class);
result.process(); result.process();
} }
public Class getRequestClass(String key)
{ public Class getRequestClass(String key) {
return requests.get(key); return requests.get(key);
} }
public void registerRequest(String key, Class clazz)
{ public void registerRequest(String key, Class clazz) {
requests.put(key, clazz); requests.put(key, clazz);
} }
public void registerRequests()
{ public void registerRequests() {
} }
public void registerResult(String key, Class clazz)
{ public void registerResult(String key, Class clazz) {
results.put(key, clazz); results.put(key, clazz);
} }
public void registerResults()
{ public void registerResults() {
} }
public void sendObjectAsync(Object obj) throws IOException { public void sendObjectAsync(Object obj) throws IOException {
point.sendAsync(gson.toJson(obj)); point.sendAsync(gson.toJson(obj));
} }
public void sendObject(Object obj) throws IOException { public void sendObject(Object obj) throws IOException {
point.send(gson.toJson(obj)); point.send(gson.toJson(obj));
} }

View file

@ -12,6 +12,7 @@
public class ServerAgent { public class ServerAgent {
private static boolean isAgentStarted = false; private static boolean isAgentStarted = false;
public static Instrumentation inst; public static Instrumentation inst;
public static final class StarterVisitor extends SimpleFileVisitor<Path> { public static final class StarterVisitor extends SimpleFileVisitor<Path> {
private Instrumentation inst; private Instrumentation inst;
@ -25,18 +26,21 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
return super.visitFile(file, attrs); return super.visitFile(file, attrs);
} }
} }
public static void addJVMClassPath(String path) throws IOException { public static void addJVMClassPath(String path) throws IOException {
LogHelper.debug("Load %s", path); LogHelper.debug("Load %s", path);
inst.appendToSystemClassLoaderSearch(new JarFile(path)); inst.appendToSystemClassLoaderSearch(new JarFile(path));
} }
public static void addJVMClassPath(JarFile file) throws IOException { public static void addJVMClassPath(JarFile file) throws IOException {
LogHelper.debug("Load %s", file.getName()); LogHelper.debug("Load %s", file.getName());
inst.appendToSystemClassLoaderSearch(file); inst.appendToSystemClassLoaderSearch(file);
} }
public boolean isAgentStarted()
{ public boolean isAgentStarted() {
return isAgentStarted; return isAgentStarted;
} }
public static long getObjSize(Object obj) { public static long getObjSize(Object obj) {
return inst.getObjectSize(obj); return inst.getObjectSize(obj);
} }

View file

@ -33,6 +33,7 @@ public class ServerWrapper {
public static ModulesManager modulesManager; public static ModulesManager modulesManager;
public static Path configFile; public static Path configFile;
public static Config config; public static Config config;
public static boolean auth(ServerWrapper wrapper) { public static boolean auth(ServerWrapper wrapper) {
try { try {
LauncherConfig cfg = Launcher.getConfig(); LauncherConfig cfg = Launcher.getConfig();
@ -48,13 +49,13 @@ public static boolean auth(ServerWrapper wrapper) {
} }
} }
return true; return true;
} catch (Throwable e) } catch (Throwable e) {
{
LogHelper.error(e); LogHelper.error(e);
return false; return false;
} }
} }
public static boolean loopAuth(ServerWrapper wrapper, int count, int sleeptime) { public static boolean loopAuth(ServerWrapper wrapper, int count, int sleeptime) {
if (count == 0) { if (count == 0) {
while (true) { while (true) {
@ -71,6 +72,7 @@ public static boolean loopAuth(ServerWrapper wrapper,int count,int sleeptime) {
} }
return false; return false;
} }
public static void main(String[] args) throws Throwable { public static void main(String[] args) throws Throwable {
ServerWrapper wrapper = new ServerWrapper(); ServerWrapper wrapper = new ServerWrapper();
modulesManager = new ModulesManager(wrapper); modulesManager = new ModulesManager(wrapper);
@ -85,7 +87,8 @@ public static void main(String[] args) throws Throwable {
LauncherConfig cfg = new LauncherConfig(config.address, config.port, SecurityHelper.toPublicRSAKey(IOHelper.read(Paths.get("public.key"))), new HashMap<>(), config.projectname); LauncherConfig cfg = new LauncherConfig(config.address, config.port, SecurityHelper.toPublicRSAKey(IOHelper.read(Paths.get("public.key"))), new HashMap<>(), config.projectname);
Launcher.setConfig(cfg); Launcher.setConfig(cfg);
if (config.syncAuth) auth(wrapper); if (config.syncAuth) auth(wrapper);
else CommonHelper.newThread("Server Auth Thread",true,() -> ServerWrapper.loopAuth(wrapper,config.reconnectCount,config.reconnectSleep)); else
CommonHelper.newThread("Server Auth Thread", true, () -> ServerWrapper.loopAuth(wrapper, config.reconnectCount, config.reconnectSleep));
modulesManager.initModules(); modulesManager.initModules();
String classname = config.mainclass.isEmpty() ? args[0] : config.mainclass; String classname = config.mainclass.isEmpty() ? args[0] : config.mainclass;
Class<?> mainClass; Class<?> mainClass;
@ -95,8 +98,7 @@ public static void main(String[] args) throws Throwable {
ClassLoader loader = classloader_class.getConstructor(ClassLoader.class).newInstance(ClassLoader.getSystemClassLoader()); ClassLoader loader = classloader_class.getConstructor(ClassLoader.class).newInstance(ClassLoader.getSystemClassLoader());
Thread.currentThread().setContextClassLoader(loader); Thread.currentThread().setContextClassLoader(loader);
mainClass = Class.forName(classname, false, loader); mainClass = Class.forName(classname, false, loader);
} } else mainClass = Class.forName(classname);
else mainClass = Class.forName(classname);
MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)); MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class));
String[] real_args = new String[args.length - 1]; String[] real_args = new String[args.length - 1];
System.arraycopy(args, 1, real_args, 0, args.length - 1); System.arraycopy(args, 1, real_args, 0, args.length - 1);
@ -104,6 +106,7 @@ public static void main(String[] args) throws Throwable {
LogHelper.debug("Invoke main method"); LogHelper.debug("Invoke main method");
mainMethod.invoke(real_args); mainMethod.invoke(real_args);
} }
private static void generateConfigIfNotExists() throws IOException { private static void generateConfigIfNotExists() throws IOException {
if (IOHelper.isFile(configFile)) if (IOHelper.isFile(configFile))
return; return;
@ -123,6 +126,7 @@ private static void generateConfigIfNotExists() throws IOException {
TextConfigWriter.write(newConfig.block, writer, true); TextConfigWriter.write(newConfig.block, writer, true);
} }
} }
public static final class Config extends ConfigObject { public static final class Config extends ConfigObject {
public String title; public String title;
public String projectname; public String projectname;
@ -136,6 +140,7 @@ public static final class Config extends ConfigObject {
public String mainclass; public String mainclass;
public String login; public String login;
public String password; public String password;
protected Config(BlockConfigEntry block) { protected Config(BlockConfigEntry block) {
super(block); super(block);
title = block.getEntryValue("title", StringConfigEntry.class); title = block.getEntryValue("title", StringConfigEntry.class);
@ -153,5 +158,6 @@ protected Config(BlockConfigEntry block) {
syncAuth = block.hasEntry("syncAuth") ? block.getEntryValue("syncAuth", BooleanConfigEntry.class) : true; syncAuth = block.hasEntry("syncAuth") ? block.getEntryValue("syncAuth", BooleanConfigEntry.class) : true;
} }
} }
public ClientProfile profile; public ClientProfile profile;
} }

View file

@ -5,12 +5,10 @@
// FMLSecurityManager запрещает делать System.exit из классов // FMLSecurityManager запрещает делать System.exit из классов
// Не входящих в пакеты самого Forge // Не входящих в пакеты самого Forge
public class SafeExitJVMLegacy { public class SafeExitJVMLegacy {
public static void exit(int code) public static void exit(int code) {
{
try { try {
JVMHelper.RUNTIME.halt(code); JVMHelper.RUNTIME.halt(code);
} catch (Throwable e) } catch (Throwable e) {
{
System.exit(code); System.exit(code);
} }
} }

View file

@ -5,12 +5,10 @@
// FMLSecurityManager запрещает делать System.exit из классов // FMLSecurityManager запрещает делать System.exit из классов
// Не входящих в пакеты самого Forge // Не входящих в пакеты самого Forge
public class SafeExitJVM { public class SafeExitJVM {
public static void exit(int code) public static void exit(int code) {
{
try { try {
JVMHelper.RUNTIME.halt(code); JVMHelper.RUNTIME.halt(code);
} catch (Throwable e) } catch (Throwable e) {
{
System.exit(code); System.exit(code);
} }
} }

View file

@ -83,9 +83,9 @@ public static LauncherConfig getConfig() {
} }
return config; return config;
} }
@LauncherAPI @LauncherAPI
public static void setConfig(LauncherConfig cfg) public static void setConfig(LauncherConfig cfg) {
{
CONFIG.set(cfg); CONFIG.set(cfg);
} }

View file

@ -50,8 +50,8 @@ public static void premain(String agentArgument, Instrumentation instrumentation
} }
} }
} }
public static boolean isStarted()
{ public static boolean isStarted() {
return isAgentStarted; return isAgentStarted;
} }
} }

View file

@ -7,6 +7,7 @@
//Набор стандартных событий //Набор стандартных событий
public class ControlEvent implements EventInterface { public class ControlEvent implements EventInterface {
private static final UUID uuid = UUID.fromString("f1051a64-0cd0-4ed8-8430-d856a196e91f"); private static final UUID uuid = UUID.fromString("f1051a64-0cd0-4ed8-8430-d856a196e91f");
public enum ControlCommand { public enum ControlCommand {
STOP, START, PAUSE, CONTINUE, CRASH STOP, START, PAUSE, CONTINUE, CRASH
} }
@ -16,6 +17,7 @@ public ControlEvent(ControlCommand signal) {
} }
public ControlCommand signal; public ControlCommand signal;
@Override @Override
public UUID getUUID() { public UUID getUUID() {
return uuid; return uuid;

View file

@ -8,6 +8,7 @@
//Все обработчики обязаны его игнорировать //Все обработчики обязаны его игнорировать
public final class PingEvent implements EventInterface { public final class PingEvent implements EventInterface {
private static final UUID uuid = UUID.fromString("7c8be7e7-82ce-4c99-84cd-ee8fcce1b509"); private static final UUID uuid = UUID.fromString("7c8be7e7-82ce-4c99-84cd-ee8fcce1b509");
@Override @Override
public UUID getUUID() { public UUID getUUID() {

View file

@ -3,13 +3,16 @@
import ru.gravit.utils.event.EventInterface; import ru.gravit.utils.event.EventInterface;
import java.util.UUID; import java.util.UUID;
//Используется, что бы послать короткое сообщение, которое вмещается в int //Используется, что бы послать короткое сообщение, которое вмещается в int
public class SignalEvent implements EventInterface { public class SignalEvent implements EventInterface {
private static final UUID uuid = UUID.fromString("edc3afa1-2726-4da3-95c6-7e6994b981e1"); private static final UUID uuid = UUID.fromString("edc3afa1-2726-4da3-95c6-7e6994b981e1");
public int signal; public int signal;
public SignalEvent(int signal) { public SignalEvent(int signal) {
this.signal = signal; this.signal = signal;
} }
@Override @Override
public UUID getUUID() { public UUID getUUID() {
return uuid; return uuid;

View file

@ -71,14 +71,12 @@ private static void handleError(Throwable e) {
LogHelper.error(e); LogHelper.error(e);
try { try {
SafeExitJVMLegacy.exit(-123); SafeExitJVMLegacy.exit(-123);
} catch (Throwable ignored) } catch (Throwable ignored) {
{
} }
try { try {
SafeExitJVM.exit(-123); SafeExitJVM.exit(-123);
} catch (Throwable ignored) } catch (Throwable ignored) {
{
} }
NativeJVMHalt halt = new NativeJVMHalt(-123); NativeJVMHalt halt = new NativeJVMHalt(-123);

View file

@ -143,36 +143,33 @@ public Diff diff(HashedDir other, FileNameMatcher matcher) {
HashedDir extra = other.sideDiff(this, matcher, new LinkedList<>(), false); HashedDir extra = other.sideDiff(this, matcher, new LinkedList<>(), false);
return new Diff(mismatch, extra); return new Diff(mismatch, extra);
} }
@LauncherAPI @LauncherAPI
public Diff compare(HashedDir other, FileNameMatcher matcher) { public Diff compare(HashedDir other, FileNameMatcher matcher) {
HashedDir mismatch = sideDiff(other, matcher, new LinkedList<>(), true); HashedDir mismatch = sideDiff(other, matcher, new LinkedList<>(), true);
HashedDir extra = other.sideDiff(this, matcher, new LinkedList<>(), false); HashedDir extra = other.sideDiff(this, matcher, new LinkedList<>(), false);
return new Diff(mismatch, extra); return new Diff(mismatch, extra);
} }
public void remove(String name)
{ public void remove(String name) {
map.remove(name); map.remove(name);
} }
public void removeR(String name)
{ public void removeR(String name) {
LinkedList<String> dirs = new LinkedList<>(); LinkedList<String> dirs = new LinkedList<>();
StringTokenizer t = new StringTokenizer(name, "/"); StringTokenizer t = new StringTokenizer(name, "/");
while(t.hasMoreTokens()) while (t.hasMoreTokens()) {
{
dirs.add(t.nextToken()); dirs.add(t.nextToken());
} }
Map<String, HashedEntry> current = map; Map<String, HashedEntry> current = map;
for(String s : dirs) for (String s : dirs) {
{
HashedEntry e = current.get(s); HashedEntry e = current.get(s);
if(e == null) if (e == null) {
{
LogHelper.debug("Null %s", s); LogHelper.debug("Null %s", s);
for (String x : current.keySet()) LogHelper.debug("Contains %s", x); for (String x : current.keySet()) LogHelper.debug("Contains %s", x);
break; break;
} }
if(e.getType() == Type.DIR) if (e.getType() == Type.DIR) {
{
current = ((HashedDir) e).map; current = ((HashedDir) e).map;
LogHelper.debug("Found dir %s", s); LogHelper.debug("Found dir %s", s);
} else { } else {
@ -182,6 +179,7 @@ public void removeR(String name)
} }
} }
} }
@LauncherAPI @LauncherAPI
public HashedEntry getEntry(String name) { public HashedEntry getEntry(String name) {
return map.get(name); return map.get(name);

View file

@ -75,6 +75,7 @@ public String toString() {
private final StringConfigEntry serverAddress; private final StringConfigEntry serverAddress;
private final IntegerConfigEntry serverPort; private final IntegerConfigEntry serverPort;
public static class MarkedString { public static class MarkedString {
@LauncherAPI @LauncherAPI
public String string; public String string;
@ -85,6 +86,7 @@ public MarkedString(String string, boolean mark) {
this.string = string; this.string = string;
this.mark = mark; this.mark = mark;
} }
public MarkedString(String string) { public MarkedString(String string) {
this.string = string; this.string = string;
this.mark = false; this.mark = false;
@ -103,6 +105,7 @@ public int hashCode() {
return Objects.hash(string); return Objects.hash(string);
} }
} }
// Updater and client watch service // Updater and client watch service
private final List<String> update = new ArrayList<>(); private final List<String> update = new ArrayList<>();
private final List<String> updateExclusions = new ArrayList<>(); private final List<String> updateExclusions = new ArrayList<>();
@ -213,28 +216,34 @@ public String getServerAddress() {
} }
@LauncherAPI @LauncherAPI
public Set<MarkedString> getOptional() public Set<MarkedString> getOptional() {
{
return updateOptional; return updateOptional;
} }
@LauncherAPI @LauncherAPI
public void markOptional(String opt) public void markOptional(String opt) {
{ if (!updateOptional.contains(new MarkedString(opt)))
if(!updateOptional.contains(new MarkedString(opt))) throw new SecurityException(String.format("Optional mod %s not found in optionalList",opt)); throw new SecurityException(String.format("Optional mod %s not found in optionalList", opt));
updateOptional.forEach(e -> {if(e.string.equals(opt)) e.mark = true;}); updateOptional.forEach(e -> {
if (e.string.equals(opt)) e.mark = true;
});
} }
@LauncherAPI @LauncherAPI
public void unmarkOptional(String opt) public void unmarkOptional(String opt) {
{ if (!updateOptional.contains(new MarkedString(opt)))
if(!updateOptional.contains(new MarkedString(opt))) throw new SecurityException(String.format("Optional mod %s not found in optionalList",opt)); throw new SecurityException(String.format("Optional mod %s not found in optionalList", opt));
updateOptional.forEach(e -> {if(e.string.equals(opt)) e.mark = false;}); updateOptional.forEach(e -> {
if (e.string.equals(opt)) e.mark = false;
});
} }
public void pushOptional(HashedDir dir, boolean digest) throws IOException { public void pushOptional(HashedDir dir, boolean digest) throws IOException {
for(MarkedString opt : updateOptional) for (MarkedString opt : updateOptional) {
{
if (!opt.mark) dir.removeR(opt.string); if (!opt.mark) dir.removeR(opt.string);
} }
} }
@LauncherAPI @LauncherAPI
public int getServerPort() { public int getServerPort() {
return serverPort.getValue(); return serverPort.getValue();

View file

@ -16,7 +16,8 @@ public class DigestBytesHolder extends StreamObject {
@LauncherAPI @LauncherAPI
public DigestBytesHolder(byte[] bytes, byte[] digest, SecurityHelper.DigestAlgorithm algorithm) throws SignatureException { public DigestBytesHolder(byte[] bytes, byte[] digest, SecurityHelper.DigestAlgorithm algorithm) throws SignatureException {
if(Arrays.equals(SecurityHelper.digest(algorithm,bytes),digest)) throw new SignatureException("Invalid digest"); if (Arrays.equals(SecurityHelper.digest(algorithm, bytes), digest))
throw new SignatureException("Invalid digest");
this.bytes = bytes.clone(); this.bytes = bytes.clone();
this.digest = digest.clone(); this.digest = digest.clone();
} }

View file

@ -10,5 +10,6 @@ public NativeJVMHalt(int haltCode) {
} }
public int haltCode; public int haltCode;
public native void halt(); public native void halt();
} }

View file

@ -9,6 +9,7 @@ public class PublicURLClassLoader extends URLClassLoader {
@LauncherAPI @LauncherAPI
public static ClassLoader systemclassloader = ClassLoader.getSystemClassLoader(); public static ClassLoader systemclassloader = ClassLoader.getSystemClassLoader();
public String nativePath; public String nativePath;
@LauncherAPI @LauncherAPI
public static ClassLoader getSystemClassLoader() { public static ClassLoader getSystemClassLoader() {
return systemclassloader; return systemclassloader;
@ -62,9 +63,9 @@ public PublicURLClassLoader(URL[] urls) {
public PublicURLClassLoader(URL[] urls, ClassLoader parent) { public PublicURLClassLoader(URL[] urls, ClassLoader parent) {
super(urls, parent); super(urls, parent);
} }
@Override @Override
public String findLibrary(String name) public String findLibrary(String name) {
{
return nativePath.concat(name); return nativePath.concat(name);
} }

View file

@ -13,8 +13,8 @@
public class EventManager { public class EventManager {
public static final int QUEUE_MAX_SIZE = 2048; public static final int QUEUE_MAX_SIZE = 2048;
public static final int INITIAL_HANDLERS_SIZE = 16; public static final int INITIAL_HANDLERS_SIZE = 16;
public class Entry
{ public class Entry {
public Entry(EventHandler<EventInterface> func, UUID[] events) { public Entry(EventHandler<EventInterface> func, UUID[] events) {
this.func = func; this.func = func;
this.events = events; this.events = events;
@ -23,8 +23,8 @@ public Entry(EventHandler<EventInterface> func, UUID[] events) {
EventHandler<EventInterface> func; EventHandler<EventInterface> func;
UUID[] events; UUID[] events;
} }
public class QueueEntry
{ public class QueueEntry {
public QueueEntry(EventInterface event, UUID key) { public QueueEntry(EventInterface event, UUID key) {
this.event = event; this.event = event;
this.key = key; this.key = key;
@ -33,19 +33,20 @@ public QueueEntry(EventInterface event, UUID key) {
EventInterface event; EventInterface event;
UUID key; UUID key;
} }
private EventExecutor executor; private EventExecutor executor;
private Thread executorThread; private Thread executorThread;
private AtomicBoolean isStarted = new AtomicBoolean(false); private AtomicBoolean isStarted = new AtomicBoolean(false);
public synchronized void start()
{ public synchronized void start() {
if (isStarted.get()) return; if (isStarted.get()) return;
executor = new EventExecutor(); executor = new EventExecutor();
isStarted.set(true); isStarted.set(true);
executorThread = CommonHelper.newThread("EventExecutor", true, executor); executorThread = CommonHelper.newThread("EventExecutor", true, executor);
executorThread.start(); executorThread.start();
} }
public synchronized void stop()
{ public synchronized void stop() {
if (!isStarted.get()) return; if (!isStarted.get()) return;
executorThread.interrupt(); executorThread.interrupt();
try { try {
@ -53,38 +54,41 @@ public synchronized void stop()
} catch (InterruptedException ignored) { } catch (InterruptedException ignored) {
} }
} }
public ArrayList<Entry> handlers = new ArrayList<>(INITIAL_HANDLERS_SIZE); public ArrayList<Entry> handlers = new ArrayList<>(INITIAL_HANDLERS_SIZE);
public BlockingQueue<QueueEntry> queue = new LinkedBlockingQueue<>(QUEUE_MAX_SIZE); //Максимальный размер очереди public BlockingQueue<QueueEntry> queue = new LinkedBlockingQueue<>(QUEUE_MAX_SIZE); //Максимальный размер очереди
public int registerHandler(EventHandler<EventInterface> func, UUID[] events)
{ public int registerHandler(EventHandler<EventInterface> func, UUID[] events) {
if(isStarted.get()) throw new IllegalThreadStateException("It is forbidden to add a handler during thread operation."); if (isStarted.get())
throw new IllegalThreadStateException("It is forbidden to add a handler during thread operation.");
Arrays.sort(events); Arrays.sort(events);
handlers.add(new Entry(func, events)); handlers.add(new Entry(func, events));
return handlers.size(); return handlers.size();
} }
public void unregisterHandler(EventHandler<EventInterface> func)
{ public void unregisterHandler(EventHandler<EventInterface> func) {
if(isStarted.get()) throw new IllegalThreadStateException("It is forbidden to remove a handler during thread operation."); if (isStarted.get())
throw new IllegalThreadStateException("It is forbidden to remove a handler during thread operation.");
handlers.removeIf(e -> e.func.equals(func)); handlers.removeIf(e -> e.func.equals(func));
} }
public void sendEvent(UUID key, EventInterface event, boolean blocking)
{ public void sendEvent(UUID key, EventInterface event, boolean blocking) {
if (blocking) process(key, event); if (blocking) process(key, event);
else queue.add(new QueueEntry(event, key)); else queue.add(new QueueEntry(event, key));
} }
public void process(UUID key, EventInterface event)
{ public void process(UUID key, EventInterface event) {
for(Entry e : handlers) for (Entry e : handlers) {
{
if (Arrays.binarySearch(e.events, key) >= 0) e.func.run(key, event); if (Arrays.binarySearch(e.events, key) >= 0) e.func.run(key, event);
} }
} }
public class EventExecutor implements Runnable { public class EventExecutor implements Runnable {
public boolean enable = true; public boolean enable = true;
@Override @Override
public void run() { public void run() {
while(enable && !Thread.interrupted()) while (enable && !Thread.interrupted()) {
{
try { try {
QueueEntry e = queue.take(); QueueEntry e = queue.take();
process(e.key, e.event); process(e.key, e.event);

View file

@ -114,13 +114,12 @@ public static URL[] getClassPathURL() {
} }
return list; return list;
} }
public static void checkStackTrace(Class mainClass)
{ public static void checkStackTrace(Class mainClass) {
LogHelper.debug("Testing stacktrace"); LogHelper.debug("Testing stacktrace");
Exception e = new Exception("Testing stacktrace"); Exception e = new Exception("Testing stacktrace");
StackTraceElement[] list = e.getStackTrace(); StackTraceElement[] list = e.getStackTrace();
if(!list[list.length - 1].getClassName().equals(mainClass.getName())) if (!list[list.length - 1].getClassName().equals(mainClass.getName())) {
{
throw new SecurityException(String.format("Invalid StackTraceElement: %s", list[list.length - 1].getClassName())); throw new SecurityException(String.format("Invalid StackTraceElement: %s", list[list.length - 1].getClassName()));
} }
} }

View file

@ -486,6 +486,7 @@ public static String verifyToken(String token) {
private SecurityHelper() { private SecurityHelper() {
} }
//AES //AES
public static byte[] encrypt(String seed, byte[] cleartext) throws Exception { public static byte[] encrypt(String seed, byte[] cleartext) throws Exception {
byte[] rawKey = getRawKey(seed.getBytes()); byte[] rawKey = getRawKey(seed.getBytes());
@ -520,6 +521,7 @@ public static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
cipher.init(Cipher.DECRYPT_MODE, sKeySpec); cipher.init(Cipher.DECRYPT_MODE, sKeySpec);
return cipher.doFinal(encrypted); return cipher.doFinal(encrypted);
} }
public static byte[] HexToByte(String hexString) { public static byte[] HexToByte(String hexString) {
int len = hexString.length() / 2; int len = hexString.length() / 2;
byte[] result = new byte[len]; byte[] result = new byte[len];

View file

@ -9,8 +9,7 @@ public class UnpackHelper {
@SuppressWarnings("ResultOfMethodCallIgnored") @SuppressWarnings("ResultOfMethodCallIgnored")
public static boolean unpack(URL resource, Path target) throws IOException { public static boolean unpack(URL resource, Path target) throws IOException {
byte[] orig = IOHelper.read(resource); byte[] orig = IOHelper.read(resource);
if(IOHelper.exists(target)) if (IOHelper.exists(target)) {
{
if (matches(target, orig)) return false; if (matches(target, orig)) return false;
} }
if (!IOHelper.exists(target)) if (!IOHelper.exists(target))
@ -18,6 +17,7 @@ public static boolean unpack(URL resource, Path target) throws IOException {
IOHelper.transfer(orig, target, false); IOHelper.transfer(orig, target, false);
return true; return true;
} }
private static boolean matches(Path target, byte[] in) { private static boolean matches(Path target, byte[] in) {
try { try {
return Arrays.equals(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, in), return Arrays.equals(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, in),