mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
IDEA Code Reformat
This commit is contained in:
parent
f9b8bd2947
commit
874a30eb6b
81 changed files with 740 additions and 697 deletions
|
@ -9,12 +9,13 @@ public ClientPermissions() {
|
|||
canAdmin = false;
|
||||
canServer = false;
|
||||
}
|
||||
|
||||
public ClientPermissions(long data) {
|
||||
canAdmin = (data & (1)) != 0;
|
||||
canServer = (data & (1 << 1)) != 0;
|
||||
}
|
||||
public static ClientPermissions getSuperuserAccount()
|
||||
{
|
||||
|
||||
public static ClientPermissions getSuperuserAccount() {
|
||||
ClientPermissions perm = new ClientPermissions();
|
||||
perm.canServer = true;
|
||||
perm.canAdmin = true;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
public final class AcceptAuthProvider extends AuthProvider {
|
||||
private final boolean isAdminAccess;
|
||||
|
||||
public AcceptAuthProvider(BlockConfigEntry block, LaunchServer server) {
|
||||
super(block, server);
|
||||
isAdminAccess = block.hasEntry("admin") ? block.getEntryValue("admin", BooleanConfigEntry.class) : false;
|
||||
|
|
|
@ -51,8 +51,8 @@ public static void registerProviders() {
|
|||
registredProv = true;
|
||||
}
|
||||
}
|
||||
public AuthHandler getAccociateHandler(int this_position)
|
||||
{
|
||||
|
||||
public AuthHandler getAccociateHandler(int this_position) {
|
||||
return server.config.authHandler[this_position];
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,7 @@ protected AuthProvider(BlockConfigEntry block, LaunchServer launchServer) {
|
|||
|
||||
@Override
|
||||
public abstract void close() throws IOException;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ServerAdapter<O extends ConfigObject> {
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ public AuthProviderResult(String username, String accessToken) {
|
|||
this.accessToken = accessToken;
|
||||
permissions = ClientPermissions.DEFAULT;
|
||||
}
|
||||
|
||||
public AuthProviderResult(String username, String accessToken, ClientPermissions permissions) {
|
||||
this.username = username;
|
||||
this.accessToken = accessToken;
|
||||
|
|
|
@ -48,6 +48,7 @@ public CtClass getCtClass() {
|
|||
public byte[] getBytecode() throws IOException, CannotCompileException {
|
||||
return ctClass.toBytecode();
|
||||
}
|
||||
|
||||
public void compile() throws CannotCompileException {
|
||||
body.append("}");
|
||||
moduleBody.append("}");
|
||||
|
@ -83,16 +84,19 @@ public void setPort(int port) {
|
|||
body.append(port);
|
||||
body.append(";");
|
||||
}
|
||||
|
||||
public void setClientPort(int port) {
|
||||
body.append("this.clientPort = ");
|
||||
body.append(port);
|
||||
body.append(";");
|
||||
}
|
||||
|
||||
public void setUsingWrapper(boolean b) {
|
||||
body.append("this.isUsingWrapper = ");
|
||||
body.append(b ? "true" : "false");
|
||||
body.append(";");
|
||||
}
|
||||
|
||||
public void setDownloadJava(boolean b) {
|
||||
body.append("this.isDownloadJava = ");
|
||||
body.append(b ? "true" : "false");
|
||||
|
|
|
@ -98,6 +98,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
private static ZipEntry newEntry(String fileName) {
|
||||
return newZipEntry(Launcher.RUNTIME_DIR + IOHelper.CROSS_SEPARATOR + fileName);
|
||||
}
|
||||
|
||||
private static ZipEntry newGuardEntry(String fileName) {
|
||||
return newZipEntry(Launcher.GUARD_DIR + IOHelper.CROSS_SEPARATOR + fileName);
|
||||
}
|
||||
|
@ -145,13 +146,11 @@ public void build() throws IOException {
|
|||
} catch (ParseException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
if(server.buildHookManager.isNeedPostProguardHook())
|
||||
{
|
||||
if (server.buildHookManager.isNeedPostProguardHook()) {
|
||||
Path obfPath = Paths.get(server.config.binaryName + "-obf.jar");
|
||||
Path tmpPath = Paths.get(server.config.binaryName + "-tmp.jar");
|
||||
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(
|
||||
IOHelper.newInput(tmpPath))) {
|
||||
ZipEntry e = input.getNextEntry();
|
||||
|
|
|
@ -43,6 +43,7 @@ public final boolean exists() {
|
|||
public final DigestBytesHolder getBytes() {
|
||||
return binary;
|
||||
}
|
||||
|
||||
public final byte[] getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
*
|
||||
* @param ctx
|
||||
* Context
|
||||
* @param ctx Context
|
||||
*/
|
||||
private static void sendNotModified(ChannelHandlerContext ctx) {
|
||||
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
|
||||
*
|
||||
* @param response
|
||||
* HTTP response
|
||||
* @param response HTTP response
|
||||
*/
|
||||
private static void setDateHeader(FullHttpResponse response) {
|
||||
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
|
||||
*
|
||||
* @param response
|
||||
* HTTP response
|
||||
* @param fileToCache
|
||||
* file to extract content type
|
||||
* @param response HTTP response
|
||||
* @param fileToCache file to extract content type
|
||||
*/
|
||||
private static void setDateAndCacheHeaders(HttpResponse response, File fileToCache) {
|
||||
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
|
||||
*
|
||||
* @param response
|
||||
* HTTP response
|
||||
* @param file
|
||||
* file to extract content type
|
||||
* @param response HTTP response
|
||||
* @param file file to extract content type
|
||||
*/
|
||||
private static void setContentTypeHeader(HttpResponse response, File file) {
|
||||
MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
|
||||
|
|
|
@ -64,6 +64,7 @@ public byte[] classTransform(byte[] clazz, CharSequence classname) {
|
|||
for (Transformer transformer : CLASS_TRANSFORMER) result = transformer.transform(result, classname);
|
||||
return result;
|
||||
}
|
||||
|
||||
public byte[] proGuardClassTransform(byte[] clazz, CharSequence classname) {
|
||||
byte[] result = clazz;
|
||||
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) {
|
||||
POST_HOOKS.add(hook);
|
||||
}
|
||||
|
||||
public void registerProGuardHook(Transformer hook) {
|
||||
POST_PROGUARD_HOOKS.add(hook);
|
||||
}
|
||||
public boolean isNeedPostProguardHook()
|
||||
{
|
||||
|
||||
public boolean isNeedPostProguardHook() {
|
||||
return !POST_PROGUARD_HOOKS.isEmpty();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,58 +7,63 @@
|
|||
import java.util.ArrayList;
|
||||
|
||||
public class MirrorManager {
|
||||
public class Mirror
|
||||
{
|
||||
public class Mirror {
|
||||
URL url;
|
||||
String assetsURLMask;
|
||||
String clientsURLMask;
|
||||
boolean enabled;
|
||||
Mirror(String url)
|
||||
{
|
||||
|
||||
Mirror(String url) {
|
||||
assetsURLMask = url.concat("assets/%s.zip");
|
||||
clientsURLMask = url.concat("clients/%s.zip");
|
||||
}
|
||||
|
||||
private URL formatArg(String mask, String arg) throws MalformedURLException {
|
||||
return new URL(String.format(mask, IOHelper.urlEncode(arg)));
|
||||
}
|
||||
|
||||
public URL getAssetsURL(String assets) throws MalformedURLException {
|
||||
return formatArg(assetsURLMask, assets);
|
||||
}
|
||||
|
||||
public URL getClientsURL(String client) throws MalformedURLException {
|
||||
return formatArg(clientsURLMask, client);
|
||||
}
|
||||
}
|
||||
|
||||
protected ArrayList<Mirror> list = new ArrayList<>();
|
||||
private Mirror defaultMirror;
|
||||
|
||||
public void addMirror(String mirror) throws MalformedURLException {
|
||||
Mirror m = new Mirror(mirror);
|
||||
m.enabled = true;
|
||||
if (defaultMirror == null) defaultMirror = m;
|
||||
}
|
||||
|
||||
public void addMirror(String mirror, boolean enabled) throws MalformedURLException {
|
||||
Mirror m = new Mirror(mirror);
|
||||
m.url = new URL(mirror);
|
||||
m.enabled = enabled;
|
||||
if (defaultMirror == null && enabled) defaultMirror = m;
|
||||
}
|
||||
public Mirror getDefaultMirror()
|
||||
{
|
||||
|
||||
public Mirror getDefaultMirror() {
|
||||
return defaultMirror;
|
||||
}
|
||||
public void setDefaultMirror(Mirror m)
|
||||
{
|
||||
|
||||
public void setDefaultMirror(Mirror m) {
|
||||
defaultMirror = m;
|
||||
}
|
||||
public void disableMirror(int index)
|
||||
{
|
||||
|
||||
public void disableMirror(int index) {
|
||||
list.get(index).enabled = false;
|
||||
}
|
||||
public void enableMirror(int index)
|
||||
{
|
||||
|
||||
public void enableMirror(int index) {
|
||||
list.get(index).enabled = true;
|
||||
}
|
||||
public int size()
|
||||
{
|
||||
|
||||
public int size() {
|
||||
return list.size();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,8 +71,7 @@ public void reply() throws Exception {
|
|||
AuthProvider.authError(server.config.authRejectString);
|
||||
return;
|
||||
}
|
||||
if(!clientData.checkSign)
|
||||
{
|
||||
if (!clientData.checkSign) {
|
||||
throw new AuthException("You must using checkLauncher");
|
||||
}
|
||||
result = provider.auth(login, password, ip);
|
||||
|
|
|
@ -19,8 +19,7 @@ public void reply() throws Exception {
|
|||
writeNoError(output);
|
||||
output.writeBoolean(needChange);
|
||||
//if true
|
||||
if(needChange)
|
||||
{
|
||||
if (needChange) {
|
||||
output.writeString(address, 255);
|
||||
output.writeInt(port);
|
||||
}
|
||||
|
|
|
@ -26,8 +26,7 @@ public void reply() throws IOException {
|
|||
}
|
||||
Client client = server.sessionManager.getOrNewClient(session);
|
||||
byte[] digest = input.readByteArray(0);
|
||||
if(!Arrays.equals(bytes.getDigest(), digest))
|
||||
{
|
||||
if (!Arrays.equals(bytes.getDigest(), digest)) {
|
||||
writeNoError(output);
|
||||
output.writeBoolean(true);
|
||||
output.writeByteArray(bytes.getBytes(), 0);
|
||||
|
|
|
@ -38,9 +38,11 @@ public void reply() throws IOException {
|
|||
return;
|
||||
}
|
||||
Client clientData = server.sessionManager.getClient(session);
|
||||
if(!clientData.isAuth || clientData.type != Client.Type.USER || clientData.profile == null) { requestError("Assess denied"); return;}
|
||||
for(SignedObjectHolder<ClientProfile> p : server.getProfiles())
|
||||
{
|
||||
if (!clientData.isAuth || clientData.type != Client.Type.USER || clientData.profile == null) {
|
||||
requestError("Assess denied");
|
||||
return;
|
||||
}
|
||||
for (SignedObjectHolder<ClientProfile> p : server.getProfiles()) {
|
||||
ClientProfile profile = p.object;
|
||||
if (!clientData.profile.getTitle().equals(profile.getTitle())) continue;
|
||||
if (!profile.isWhitelistContains(clientData.username)) {
|
||||
|
|
|
@ -23,12 +23,13 @@ public Client(long session) {
|
|||
username = "";
|
||||
checkSign = false;
|
||||
}
|
||||
|
||||
//Данные ваторизации
|
||||
public void up() {
|
||||
timestamp = System.currentTimeMillis();
|
||||
}
|
||||
public enum Type
|
||||
{
|
||||
|
||||
public enum Type {
|
||||
SERVER,
|
||||
USER
|
||||
}
|
||||
|
|
|
@ -11,14 +11,17 @@
|
|||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class WebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
|
||||
public static LaunchServer server;
|
||||
public static GsonBuilder builder = new GsonBuilder();
|
||||
public static WebSocketService service = new WebSocketService(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE), LaunchServer.server, builder);
|
||||
private Client client;
|
||||
|
||||
static {
|
||||
service.registerResponses();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) {
|
||||
LogHelper.debug("New client %s", IOHelper.getIP(ctx.channel().remoteAddress()));
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
public class WebSocketService {
|
||||
public final ChannelGroup channels;
|
||||
|
||||
public WebSocketService(ChannelGroup channels, LaunchServer server, GsonBuilder gson) {
|
||||
this.channels = channels;
|
||||
this.server = server;
|
||||
|
@ -40,32 +41,30 @@ public WebSocketService(ChannelGroup channels, LaunchServer server, GsonBuilder
|
|||
private final Gson gson;
|
||||
private final GsonBuilder gsonBuiler;
|
||||
|
||||
void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client)
|
||||
{
|
||||
void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client) {
|
||||
String request = frame.text();
|
||||
JsonResponseInterface response = gson.fromJson(request, JsonResponseInterface.class);
|
||||
try {
|
||||
response.execute(this, ctx, client);
|
||||
} catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
LogHelper.error(e);
|
||||
sendObject(ctx, new ExceptionResult(e));
|
||||
}
|
||||
}
|
||||
public Class getResponseClass(String type)
|
||||
{
|
||||
|
||||
public Class getResponseClass(String type) {
|
||||
return responses.get(type);
|
||||
}
|
||||
public void registerResponse(String key,Class responseInterfaceClass)
|
||||
{
|
||||
|
||||
public void registerResponse(String key, Class responseInterfaceClass) {
|
||||
responses.put(key, responseInterfaceClass);
|
||||
}
|
||||
public void registerClient(Channel channel)
|
||||
{
|
||||
|
||||
public void registerClient(Channel channel) {
|
||||
channels.add(channel);
|
||||
}
|
||||
public void registerResponses()
|
||||
{
|
||||
|
||||
public void registerResponses() {
|
||||
registerResponse("echo", EchoResponse.class);
|
||||
registerResponse("auth", AuthResponse.class);
|
||||
registerResponse("checkServer", CheckServerResponse.class);
|
||||
|
@ -74,20 +73,20 @@ public void registerResponses()
|
|||
registerResponse("updateList", 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)));
|
||||
}
|
||||
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);
|
||||
}
|
||||
public void sendEvent(EventResult obj)
|
||||
{
|
||||
|
||||
public void sendEvent(EventResult obj) {
|
||||
channels.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj)));
|
||||
}
|
||||
public static class ErrorResult
|
||||
{
|
||||
|
||||
public static class ErrorResult {
|
||||
public ErrorResult(String error) {
|
||||
this.error = error;
|
||||
this.type = "requestError";
|
||||
|
@ -96,8 +95,8 @@ public ErrorResult(String error) {
|
|||
public final String error;
|
||||
public final String type;
|
||||
}
|
||||
public static class SuccessResult
|
||||
{
|
||||
|
||||
public static class SuccessResult {
|
||||
public SuccessResult(String requesttype) {
|
||||
this.requesttype = requesttype;
|
||||
this.type = "success";
|
||||
|
@ -106,15 +105,16 @@ public SuccessResult(String requesttype) {
|
|||
public final String requesttype;
|
||||
public final String type;
|
||||
}
|
||||
public static class EventResult
|
||||
{
|
||||
|
||||
public static class EventResult {
|
||||
public EventResult() {
|
||||
this.type = "event";
|
||||
}
|
||||
|
||||
public final String type;
|
||||
}
|
||||
public static class ExceptionResult
|
||||
{
|
||||
|
||||
public static class ExceptionResult {
|
||||
public ExceptionResult(Exception e) {
|
||||
this.message = e.getMessage();
|
||||
this.clazz = e.getClass().getName();
|
||||
|
|
|
@ -22,8 +22,8 @@ public void execute(WebSocketService service,ChannelHandlerContext ctx, Client c
|
|||
LogHelper.info("Echo: %s, isAuth %s", echo, client.isAuth ? "true" : "false");
|
||||
service.sendObject(ctx, new Result(echo));
|
||||
}
|
||||
public class Result
|
||||
{
|
||||
|
||||
public class Result {
|
||||
String echo;
|
||||
|
||||
public Result(String echo) {
|
||||
|
|
|
@ -6,5 +6,6 @@
|
|||
|
||||
public interface JsonResponseInterface {
|
||||
String getType();
|
||||
|
||||
void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
public class ExecCommandResponse implements JsonResponseInterface {
|
||||
public String cmd;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "cmdExec";
|
||||
|
@ -15,8 +16,14 @@ public String getType() {
|
|||
|
||||
@Override
|
||||
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.permissions.canAdmin) {service.sendObject(ctx,new WebSocketService.ErrorResult("Access denied")); return; }
|
||||
if (!client.isAuth) {
|
||||
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);
|
||||
service.sendObject(ctx, new WebSocketService.SuccessResult("cmdExec"));
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public AuthResponse(String login, String password, int authid, HWID hwid) {
|
|||
|
||||
public int authid;
|
||||
public HWID hwid;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "auth";
|
||||
|
@ -45,8 +46,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
AuthProvider.authError(LaunchServer.server.config.authRejectString);
|
||||
return;
|
||||
}
|
||||
if(!clientData.checkSign)
|
||||
{
|
||||
if (!clientData.checkSign) {
|
||||
AuthProvider.authError("Don't skip Launcher Update");
|
||||
return;
|
||||
}
|
||||
|
@ -72,13 +72,12 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
clientData.isAuth = true;
|
||||
clientData.permissions = result.permissions;
|
||||
service.sendObject(ctx, new WebSocketService.SuccessResult("auth"));
|
||||
} catch (AuthException | HWIDException e)
|
||||
{
|
||||
} catch (AuthException | HWIDException e) {
|
||||
service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage()));
|
||||
}
|
||||
}
|
||||
public class Result
|
||||
{
|
||||
|
||||
public class Result {
|
||||
public Result() {
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
public class CheckServerResponse implements JsonResponseInterface {
|
||||
public String serverID;
|
||||
public String username;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "checkServer";
|
||||
|
@ -33,8 +34,8 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
}
|
||||
service.sendObject(ctx, new Result());
|
||||
}
|
||||
public class Result
|
||||
{
|
||||
|
||||
public class Result {
|
||||
public String type = "success";
|
||||
public String requesttype = "checkServer";
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ public class JoinServerResponse implements JsonResponseInterface {
|
|||
public String serverID;
|
||||
public String accessToken;
|
||||
public String username;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "joinServer";
|
||||
|
@ -32,8 +33,8 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
}
|
||||
service.sendObject(ctx, new Result(success));
|
||||
}
|
||||
public class Result
|
||||
{
|
||||
|
||||
public class Result {
|
||||
public String type = "success";
|
||||
public String requesttype = "checkServer";
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ public class LauncherResponse implements JsonResponseInterface {
|
|||
//REPLACED TO REAL URL
|
||||
public static final String JAR_URL = "http://localhost:9752/Launcher.jar";
|
||||
public static final String EXE_URL = "http://localhost:9752/Launcher.exe";
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "launcherUpdate";
|
||||
|
@ -29,29 +30,25 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
{
|
||||
byte[] hash = LaunchServer.server.launcherBinary.getBytes().getDigest();
|
||||
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));
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
service.sendObjectAndClose(ctx, new Result(true, JAR_URL));
|
||||
}
|
||||
} else if (launcher_type == 2) //EXE
|
||||
{
|
||||
byte[] hash = LaunchServer.server.launcherEXEBinary.getBytes().getDigest();
|
||||
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));
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
service.sendObjectAndClose(ctx, new Result(true, EXE_URL));
|
||||
}
|
||||
} else service.sendObject(ctx, new WebSocketService.ErrorResult("Request launcher type error"));
|
||||
|
||||
}
|
||||
public class Result
|
||||
{
|
||||
|
||||
public class Result {
|
||||
public String type = "success";
|
||||
public String requesttype = "launcherUpdate";
|
||||
public String url;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
public class UpdateListResponse implements JsonResponseInterface {
|
||||
public String dir;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "updateList";
|
||||
|
@ -23,8 +24,8 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
HashedDir hdir = LaunchServer.server.updatesDirMap.get(dir).object;
|
||||
service.sendObject(ctx, new Result(hdir));
|
||||
}
|
||||
class Result
|
||||
{
|
||||
|
||||
class Result {
|
||||
public final String type;
|
||||
public final String requesttype;
|
||||
public final HashedDir dir;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
public class AvanguardStarter {
|
||||
static class SecurityThread implements Runnable {
|
||||
static long macID = GuardBind.avnGetMacId();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (!Thread.interrupted()) {
|
||||
|
@ -43,18 +44,16 @@ public void run() {
|
|||
}
|
||||
}
|
||||
}
|
||||
static void safeHalt(int exitcode)
|
||||
{
|
||||
|
||||
static void safeHalt(int exitcode) {
|
||||
try {
|
||||
SafeExitJVMLegacy.exit(exitcode);
|
||||
} catch (Throwable ignored)
|
||||
{
|
||||
} catch (Throwable ignored) {
|
||||
|
||||
}
|
||||
try {
|
||||
SafeExitJVM.exit(exitcode);
|
||||
} catch (Throwable ignored)
|
||||
{
|
||||
} catch (Throwable ignored) {
|
||||
|
||||
}
|
||||
NativeJVMHalt halt = new NativeJVMHalt(exitcode);
|
||||
|
@ -72,8 +71,7 @@ public static void main(boolean init) {
|
|||
LogHelper.error("Cheating == crash!");
|
||||
try {
|
||||
SafeExitJVM.exit(threatType + 7000);
|
||||
} catch (Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
SafeExitJVMLegacy.exit(threatType + 7000);
|
||||
}
|
||||
return false;
|
||||
|
@ -82,8 +80,8 @@ public static void main(boolean init) {
|
|||
GuardBind.avnStartDefence();
|
||||
CommonHelper.newThread("Security Thread", true, new SecurityThread()).start();
|
||||
}
|
||||
public static void load()
|
||||
{
|
||||
|
||||
public static void load() {
|
||||
GuardBind.startAbs(avanguard.toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -43,9 +43,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep
|
|||
} else {
|
||||
LogHelper.debug("Process started success");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
process.waitFor();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -217,8 +217,8 @@ public void start(String... args) throws Throwable {
|
|||
Launcher.modulesManager.postInitModules();
|
||||
invoker.invokeFunction("start", (Object) args);
|
||||
}
|
||||
public static LauncherEngine clientInstance()
|
||||
{
|
||||
|
||||
public static LauncherEngine clientInstance() {
|
||||
return new LauncherEngine();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,8 +88,7 @@ public Params(byte[] launcherDigest, Path assetDir, Path clientDir, PlayerProfil
|
|||
boolean autoEnter, boolean fullScreen, int ram, int width, int height) {
|
||||
this.launcherDigest = launcherDigest.clone();
|
||||
this.updateOptional = new HashSet<>();
|
||||
for(ClientProfile.MarkedString s : Launcher.profile.getOptional())
|
||||
{
|
||||
for (ClientProfile.MarkedString s : Launcher.profile.getOptional()) {
|
||||
if (s.mark) updateOptional.add(s);
|
||||
}
|
||||
// Client paths
|
||||
|
@ -113,8 +112,7 @@ public Params(HInput input) throws Exception {
|
|||
clientDir = IOHelper.toPath(input.readString(0));
|
||||
updateOptional = new HashSet<>();
|
||||
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));
|
||||
}
|
||||
// Client params
|
||||
|
@ -136,8 +134,7 @@ public void write(HOutput output) throws IOException {
|
|||
output.writeString(assetDir.toString(), 0);
|
||||
output.writeString(clientDir.toString(), 0);
|
||||
output.writeLength(updateOptional.size(), 128);
|
||||
for(ClientProfile.MarkedString s : updateOptional)
|
||||
{
|
||||
for (ClientProfile.MarkedString s : updateOptional) {
|
||||
output.writeString(s.string, 512);
|
||||
}
|
||||
// Client params
|
||||
|
@ -227,6 +224,7 @@ private static void addClientArgs(Collection<String> args, ClientProfile profile
|
|||
Collections.addAll(args, "--height", Integer.toString(params.height));
|
||||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static void setJavaBinPath(Path 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
|
||||
mainMethod.invoke((Object) args.toArray(EMPTY_ARRAY));
|
||||
}
|
||||
|
||||
private static Process process = null;
|
||||
|
||||
@LauncherAPI
|
||||
public static Process launch(
|
||||
SignedObjectHolder<HashedDir> assetHDir, SignedObjectHolder<HashedDir> clientHDir,
|
||||
|
@ -304,13 +304,11 @@ public static Process launch(
|
|||
socket.setReuseAddress(true);
|
||||
socket.bind(new InetSocketAddress(SOCKET_HOST, SOCKET_PORT));
|
||||
Socket client = socket.accept();
|
||||
if(process == null)
|
||||
{
|
||||
if (process == null) {
|
||||
LogHelper.error("Process is null");
|
||||
return;
|
||||
}
|
||||
if(!process.isAlive())
|
||||
{
|
||||
if (!process.isAlive()) {
|
||||
LogHelper.error("Process is not alive");
|
||||
JOptionPane.showMessageDialog(null, "Client Process crashed", "Launcher", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
|
@ -337,15 +335,13 @@ public static Process launch(
|
|||
boolean wrapper = isUsingWrapper();
|
||||
Path javaBin;
|
||||
if (wrapper) javaBin = AvanguardStarter.wrapper;
|
||||
else if(isDownloadJava)
|
||||
{
|
||||
else if (isDownloadJava) {
|
||||
//Linux и Mac не должны скачивать свою JVM
|
||||
if (JVMHelper.OS_TYPE == OS.MUSTDIE)
|
||||
javaBin = IOHelper.resolveJavaBin(JavaBinPath);
|
||||
else
|
||||
javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home")));
|
||||
}
|
||||
else
|
||||
} else
|
||||
javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home")));
|
||||
args.add(javaBin.toString());
|
||||
args.add(MAGICAL_INTEL_OPTION);
|
||||
|
@ -463,8 +459,7 @@ public static void main(String... args) throws Throwable {
|
|||
// Verify current state of all dirs
|
||||
//verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest);
|
||||
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;
|
||||
else hdir.removeR(s.string);
|
||||
}
|
||||
|
@ -477,6 +472,7 @@ public static void main(String... args) throws Throwable {
|
|||
launch(profile.object, params);
|
||||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public void launchLocal(SignedObjectHolder<HashedDir> assetHDir, SignedObjectHolder<HashedDir> clientHDir,
|
||||
SignedObjectHolder<ClientProfile> profile, Params params) throws Throwable {
|
||||
|
@ -502,8 +498,7 @@ public void launchLocal(SignedObjectHolder<HashedDir> assetHDir, SignedObjectHol
|
|||
// Verify current state of all dirs
|
||||
//verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest);
|
||||
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;
|
||||
else hdir.removeR(s.string);
|
||||
}
|
||||
|
|
|
@ -14,18 +14,18 @@
|
|||
public class FunctionalBridge {
|
||||
@LauncherAPI
|
||||
public static LauncherSettings settings;
|
||||
|
||||
@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 () -> {
|
||||
if(hdir == null)
|
||||
{
|
||||
if (hdir == null) {
|
||||
Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName));
|
||||
}
|
||||
ClientLauncher.verifyHDir(dir, hdir.object, matcher, digest);
|
||||
return hdir;
|
||||
};
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public LegacyLauncherRequest.Result offlineLauncherRequest() throws IOException, SignatureException {
|
||||
if (settings.lastDigest == null || settings.lastProfiles.isEmpty()) {
|
||||
|
@ -40,6 +40,7 @@ public LegacyLauncherRequest.Result offlineLauncherRequest() throws IOException,
|
|||
// Return last sign and profiles
|
||||
return new LegacyLauncherRequest.Result(null, settings.lastDigest, settings.lastProfiles);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface HashedDirRunnable {
|
||||
SignedObjectHolder<HashedDir> run() throws Exception;
|
||||
|
|
|
@ -47,12 +47,12 @@ public class LauncherSettings {
|
|||
public List<SignedObjectHolder<ClientProfile>> lastProfiles = new LinkedList<>();
|
||||
@LauncherAPI
|
||||
public Map<String, SignedObjectHolder<HashedDir>> lastHDirs = new HashMap<>(16);
|
||||
|
||||
@LauncherAPI
|
||||
public void load() throws SignatureException {
|
||||
LogHelper.debug("Loading settings file");
|
||||
try {
|
||||
try(HInput input = new HInput(IOHelper.newInput(file)))
|
||||
{
|
||||
try (HInput input = new HInput(IOHelper.newInput(file))) {
|
||||
read(input);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -60,12 +60,12 @@ public void load() throws SignatureException {
|
|||
setDefault();
|
||||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public void save() throws SignatureException {
|
||||
LogHelper.debug("Save settings file");
|
||||
try {
|
||||
try(HOutput output = new HOutput(IOHelper.newOutput(file)))
|
||||
{
|
||||
try (HOutput output = new HOutput(IOHelper.newOutput(file))) {
|
||||
write(output);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -73,9 +73,9 @@ public void save() throws SignatureException {
|
|||
setDefault();
|
||||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public void read(HInput input) throws IOException, SignatureException
|
||||
{
|
||||
public void read(HInput input) throws IOException, SignatureException {
|
||||
int magic = input.readInt();
|
||||
if (magic != settingsMagic) {
|
||||
setDefault();
|
||||
|
@ -117,6 +117,7 @@ public void read(HInput input) throws IOException, SignatureException
|
|||
java.lang.String.format("Duplicate offline hashed dir: '%s'", name));
|
||||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public void write(HOutput output) throws IOException {
|
||||
output.writeInt(settingsMagic);
|
||||
|
@ -156,14 +157,14 @@ public void write(HOutput output) throws IOException {
|
|||
entry.getValue().write(output);
|
||||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public void setRAM(int ram)
|
||||
{
|
||||
public void setRAM(int ram) {
|
||||
this.ram = java.lang.Math.min(((ram / 256)) * 256, JVMHelper.RAM);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public void setDefault()
|
||||
{
|
||||
public void setDefault() {
|
||||
// Auth settings
|
||||
login = null;
|
||||
rsaPassword = null;
|
||||
|
@ -182,6 +183,7 @@ public void setDefault()
|
|||
lastProfiles.clear();
|
||||
lastHDirs.clear();
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public byte[] setPassword(String password) throws BadPaddingException, IllegalBlockSizeException {
|
||||
byte[] encrypted = SecurityHelper.newRSAEncryptCipher(Launcher.getConfig().publicKey).doFinal(IOHelper.encode(password));
|
||||
|
|
|
@ -41,6 +41,7 @@ public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword
|
|||
this.encryptedPassword = encryptedPassword.clone();
|
||||
auth_id = 0;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, int auth_id) {
|
||||
super(config);
|
||||
|
@ -53,6 +54,7 @@ public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword
|
|||
public AuthRequest(String login, byte[] encryptedPassword) {
|
||||
this(null, login, encryptedPassword);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public AuthRequest(String login, byte[] encryptedPassword, int auth_id) {
|
||||
this(null, login, encryptedPassword, auth_id);
|
||||
|
|
|
@ -40,6 +40,7 @@ public AuthServerRequest(LauncherConfig config, String login, byte[] encryptedPa
|
|||
auth_id = 0;
|
||||
title = "";
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public AuthServerRequest(LauncherConfig config, String login, byte[] encryptedPassword, int auth_id) {
|
||||
super(config);
|
||||
|
@ -48,6 +49,7 @@ public AuthServerRequest(LauncherConfig config, String login, byte[] encryptedPa
|
|||
this.auth_id = auth_id;
|
||||
title = "";
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public AuthServerRequest(LauncherConfig config, String login, byte[] encryptedPassword, int auth_id, String title) {
|
||||
super(config);
|
||||
|
@ -61,6 +63,7 @@ public AuthServerRequest(LauncherConfig config, String login, byte[] encryptedPa
|
|||
public AuthServerRequest(String login, byte[] encryptedPassword) {
|
||||
this(null, login, encryptedPassword);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public AuthServerRequest(String login, byte[] encryptedPassword, int auth_id) {
|
||||
this(null, login, encryptedPassword, auth_id);
|
||||
|
|
|
@ -13,19 +13,19 @@ public class ChangeServerRequest extends Request<ChangeServerRequest.Result> {
|
|||
public Integer getType() {
|
||||
return RequestType.CHANGESERVER.getNumber();
|
||||
}
|
||||
public boolean change(Result result)
|
||||
{
|
||||
|
||||
public boolean change(Result result) {
|
||||
if (!result.needChange) return false;
|
||||
Launcher.getConfig().address = InetSocketAddress.createUnresolved(result.address, result.port);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Result requestDo(HInput input, HOutput output) throws Exception {
|
||||
readError(input);
|
||||
Result result = new Result();
|
||||
result.needChange = input.readBoolean();
|
||||
if(result.needChange)
|
||||
{
|
||||
if (result.needChange) {
|
||||
result.address = input.readString(255);
|
||||
result.port = input.readInt();
|
||||
}
|
||||
|
@ -33,8 +33,7 @@ protected Result requestDo(HInput input, HOutput output) throws Exception {
|
|||
return result;
|
||||
}
|
||||
|
||||
public class Result
|
||||
{
|
||||
public class Result {
|
||||
public boolean needChange;
|
||||
public String address;
|
||||
public int port;
|
||||
|
|
|
@ -42,8 +42,7 @@ protected PlayerProfile requestDo(HInput input, HOutput output) throws IOExcepti
|
|||
if (Launcher.profile == null) {
|
||||
LogHelper.error("Profile is null. Title is not net.");
|
||||
output.writeString("", SerializeLimits.MAX_CLIENT);
|
||||
}
|
||||
else
|
||||
} else
|
||||
output.writeString(Launcher.profile.getTitle(), SerializeLimits.MAX_CLIENT);
|
||||
output.flush();
|
||||
|
||||
|
|
|
@ -26,34 +26,36 @@ public ClientWebSocketService(GsonBuilder gsonBuilder,ClientJSONPoint point) {
|
|||
this.point = point;
|
||||
point.setService(this);
|
||||
}
|
||||
public void processMessage(Reader reader)
|
||||
{
|
||||
|
||||
public void processMessage(Reader reader) {
|
||||
ResultInterface result = gson.fromJson(reader, ResultInterface.class);
|
||||
result.process();
|
||||
}
|
||||
public Class getRequestClass(String key)
|
||||
{
|
||||
|
||||
public Class getRequestClass(String key) {
|
||||
return requests.get(key);
|
||||
}
|
||||
public void registerRequest(String key, Class clazz)
|
||||
{
|
||||
|
||||
public void registerRequest(String key, Class 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);
|
||||
}
|
||||
public void registerResults()
|
||||
{
|
||||
|
||||
public void registerResults() {
|
||||
|
||||
}
|
||||
|
||||
public void sendObjectAsync(Object obj) throws IOException {
|
||||
point.sendAsync(gson.toJson(obj));
|
||||
}
|
||||
|
||||
public void sendObject(Object obj) throws IOException {
|
||||
point.send(gson.toJson(obj));
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
public class ServerAgent {
|
||||
private static boolean isAgentStarted = false;
|
||||
public static Instrumentation inst;
|
||||
|
||||
public static final class StarterVisitor extends SimpleFileVisitor<Path> {
|
||||
private Instrumentation inst;
|
||||
|
||||
|
@ -25,18 +26,21 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
return super.visitFile(file, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addJVMClassPath(String path) throws IOException {
|
||||
LogHelper.debug("Load %s", path);
|
||||
inst.appendToSystemClassLoaderSearch(new JarFile(path));
|
||||
}
|
||||
|
||||
public static void addJVMClassPath(JarFile file) throws IOException {
|
||||
LogHelper.debug("Load %s", file.getName());
|
||||
inst.appendToSystemClassLoaderSearch(file);
|
||||
}
|
||||
public boolean isAgentStarted()
|
||||
{
|
||||
|
||||
public boolean isAgentStarted() {
|
||||
return isAgentStarted;
|
||||
}
|
||||
|
||||
public static long getObjSize(Object obj) {
|
||||
return inst.getObjectSize(obj);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ public class ServerWrapper {
|
|||
public static ModulesManager modulesManager;
|
||||
public static Path configFile;
|
||||
public static Config config;
|
||||
|
||||
public static boolean auth(ServerWrapper wrapper) {
|
||||
try {
|
||||
LauncherConfig cfg = Launcher.getConfig();
|
||||
|
@ -48,13 +49,13 @@ public static boolean auth(ServerWrapper wrapper) {
|
|||
}
|
||||
}
|
||||
return true;
|
||||
} catch (Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
LogHelper.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean loopAuth(ServerWrapper wrapper, int count, int sleeptime) {
|
||||
if (count == 0) {
|
||||
while (true) {
|
||||
|
@ -71,6 +72,7 @@ public static boolean loopAuth(ServerWrapper wrapper,int count,int sleeptime) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
ServerWrapper wrapper = new ServerWrapper();
|
||||
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);
|
||||
Launcher.setConfig(cfg);
|
||||
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();
|
||||
String classname = config.mainclass.isEmpty() ? args[0] : config.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());
|
||||
Thread.currentThread().setContextClassLoader(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));
|
||||
String[] real_args = new String[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");
|
||||
mainMethod.invoke(real_args);
|
||||
}
|
||||
|
||||
private static void generateConfigIfNotExists() throws IOException {
|
||||
if (IOHelper.isFile(configFile))
|
||||
return;
|
||||
|
@ -123,6 +126,7 @@ private static void generateConfigIfNotExists() throws IOException {
|
|||
TextConfigWriter.write(newConfig.block, writer, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Config extends ConfigObject {
|
||||
public String title;
|
||||
public String projectname;
|
||||
|
@ -136,6 +140,7 @@ public static final class Config extends ConfigObject {
|
|||
public String mainclass;
|
||||
public String login;
|
||||
public String password;
|
||||
|
||||
protected Config(BlockConfigEntry block) {
|
||||
super(block);
|
||||
title = block.getEntryValue("title", StringConfigEntry.class);
|
||||
|
@ -153,5 +158,6 @@ protected Config(BlockConfigEntry block) {
|
|||
syncAuth = block.hasEntry("syncAuth") ? block.getEntryValue("syncAuth", BooleanConfigEntry.class) : true;
|
||||
}
|
||||
}
|
||||
|
||||
public ClientProfile profile;
|
||||
}
|
||||
|
|
|
@ -5,12 +5,10 @@
|
|||
// FMLSecurityManager запрещает делать System.exit из классов
|
||||
// Не входящих в пакеты самого Forge
|
||||
public class SafeExitJVMLegacy {
|
||||
public static void exit(int code)
|
||||
{
|
||||
public static void exit(int code) {
|
||||
try {
|
||||
JVMHelper.RUNTIME.halt(code);
|
||||
} catch (Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
System.exit(code);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,10 @@
|
|||
// FMLSecurityManager запрещает делать System.exit из классов
|
||||
// Не входящих в пакеты самого Forge
|
||||
public class SafeExitJVM {
|
||||
public static void exit(int code)
|
||||
{
|
||||
public static void exit(int code) {
|
||||
try {
|
||||
JVMHelper.RUNTIME.halt(code);
|
||||
} catch (Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
System.exit(code);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,9 +83,9 @@ public static LauncherConfig getConfig() {
|
|||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static void setConfig(LauncherConfig cfg)
|
||||
{
|
||||
public static void setConfig(LauncherConfig cfg) {
|
||||
CONFIG.set(cfg);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,8 +50,8 @@ public static void premain(String agentArgument, Instrumentation instrumentation
|
|||
}
|
||||
}
|
||||
}
|
||||
public static boolean isStarted()
|
||||
{
|
||||
|
||||
public static boolean isStarted() {
|
||||
return isAgentStarted;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
//Набор стандартных событий
|
||||
public class ControlEvent implements EventInterface {
|
||||
private static final UUID uuid = UUID.fromString("f1051a64-0cd0-4ed8-8430-d856a196e91f");
|
||||
|
||||
public enum ControlCommand {
|
||||
STOP, START, PAUSE, CONTINUE, CRASH
|
||||
}
|
||||
|
@ -16,6 +17,7 @@ public ControlEvent(ControlCommand signal) {
|
|||
}
|
||||
|
||||
public ControlCommand signal;
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
//Все обработчики обязаны его игнорировать
|
||||
public final class PingEvent implements EventInterface {
|
||||
private static final UUID uuid = UUID.fromString("7c8be7e7-82ce-4c99-84cd-ee8fcce1b509");
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
|
||||
|
|
|
@ -3,13 +3,16 @@
|
|||
import ru.gravit.utils.event.EventInterface;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
//Используется, что бы послать короткое сообщение, которое вмещается в int
|
||||
public class SignalEvent implements EventInterface {
|
||||
private static final UUID uuid = UUID.fromString("edc3afa1-2726-4da3-95c6-7e6994b981e1");
|
||||
public int signal;
|
||||
|
||||
public SignalEvent(int signal) {
|
||||
this.signal = signal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
|
|
|
@ -71,14 +71,12 @@ private static void handleError(Throwable e) {
|
|||
LogHelper.error(e);
|
||||
try {
|
||||
SafeExitJVMLegacy.exit(-123);
|
||||
} catch (Throwable ignored)
|
||||
{
|
||||
} catch (Throwable ignored) {
|
||||
|
||||
}
|
||||
try {
|
||||
SafeExitJVM.exit(-123);
|
||||
} catch (Throwable ignored)
|
||||
{
|
||||
} catch (Throwable ignored) {
|
||||
|
||||
}
|
||||
NativeJVMHalt halt = new NativeJVMHalt(-123);
|
||||
|
|
|
@ -143,36 +143,33 @@ public Diff diff(HashedDir other, FileNameMatcher matcher) {
|
|||
HashedDir extra = other.sideDiff(this, matcher, new LinkedList<>(), false);
|
||||
return new Diff(mismatch, extra);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public Diff compare(HashedDir other, FileNameMatcher matcher) {
|
||||
HashedDir mismatch = sideDiff(other, matcher, new LinkedList<>(), true);
|
||||
HashedDir extra = other.sideDiff(this, matcher, new LinkedList<>(), false);
|
||||
return new Diff(mismatch, extra);
|
||||
}
|
||||
public void remove(String name)
|
||||
{
|
||||
|
||||
public void remove(String name) {
|
||||
map.remove(name);
|
||||
}
|
||||
public void removeR(String name)
|
||||
{
|
||||
|
||||
public void removeR(String name) {
|
||||
LinkedList<String> dirs = new LinkedList<>();
|
||||
StringTokenizer t = new StringTokenizer(name, "/");
|
||||
while(t.hasMoreTokens())
|
||||
{
|
||||
while (t.hasMoreTokens()) {
|
||||
dirs.add(t.nextToken());
|
||||
}
|
||||
Map<String, HashedEntry> current = map;
|
||||
for(String s : dirs)
|
||||
{
|
||||
for (String s : dirs) {
|
||||
HashedEntry e = current.get(s);
|
||||
if(e == null)
|
||||
{
|
||||
if (e == null) {
|
||||
LogHelper.debug("Null %s", s);
|
||||
for (String x : current.keySet()) LogHelper.debug("Contains %s", x);
|
||||
break;
|
||||
}
|
||||
if(e.getType() == Type.DIR)
|
||||
{
|
||||
if (e.getType() == Type.DIR) {
|
||||
current = ((HashedDir) e).map;
|
||||
LogHelper.debug("Found dir %s", s);
|
||||
} else {
|
||||
|
@ -182,6 +179,7 @@ public void removeR(String name)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public HashedEntry getEntry(String name) {
|
||||
return map.get(name);
|
||||
|
|
|
@ -75,6 +75,7 @@ public String toString() {
|
|||
private final StringConfigEntry serverAddress;
|
||||
|
||||
private final IntegerConfigEntry serverPort;
|
||||
|
||||
public static class MarkedString {
|
||||
@LauncherAPI
|
||||
public String string;
|
||||
|
@ -85,6 +86,7 @@ public MarkedString(String string, boolean mark) {
|
|||
this.string = string;
|
||||
this.mark = mark;
|
||||
}
|
||||
|
||||
public MarkedString(String string) {
|
||||
this.string = string;
|
||||
this.mark = false;
|
||||
|
@ -103,6 +105,7 @@ public int hashCode() {
|
|||
return Objects.hash(string);
|
||||
}
|
||||
}
|
||||
|
||||
// Updater and client watch service
|
||||
private final List<String> update = new ArrayList<>();
|
||||
private final List<String> updateExclusions = new ArrayList<>();
|
||||
|
@ -213,28 +216,34 @@ public String getServerAddress() {
|
|||
}
|
||||
|
||||
@LauncherAPI
|
||||
public Set<MarkedString> getOptional()
|
||||
{
|
||||
public Set<MarkedString> getOptional() {
|
||||
return updateOptional;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public void markOptional(String opt)
|
||||
{
|
||||
if(!updateOptional.contains(new MarkedString(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;});
|
||||
public void markOptional(String opt) {
|
||||
if (!updateOptional.contains(new MarkedString(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;
|
||||
});
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public void unmarkOptional(String opt)
|
||||
{
|
||||
if(!updateOptional.contains(new MarkedString(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;});
|
||||
public void unmarkOptional(String opt) {
|
||||
if (!updateOptional.contains(new MarkedString(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;
|
||||
});
|
||||
}
|
||||
|
||||
public void pushOptional(HashedDir dir, boolean digest) throws IOException {
|
||||
for(MarkedString opt : updateOptional)
|
||||
{
|
||||
for (MarkedString opt : updateOptional) {
|
||||
if (!opt.mark) dir.removeR(opt.string);
|
||||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public int getServerPort() {
|
||||
return serverPort.getValue();
|
||||
|
|
|
@ -16,7 +16,8 @@ public class DigestBytesHolder extends StreamObject {
|
|||
|
||||
@LauncherAPI
|
||||
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.digest = digest.clone();
|
||||
}
|
||||
|
|
|
@ -10,5 +10,6 @@ public NativeJVMHalt(int haltCode) {
|
|||
}
|
||||
|
||||
public int haltCode;
|
||||
|
||||
public native void halt();
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ public class PublicURLClassLoader extends URLClassLoader {
|
|||
@LauncherAPI
|
||||
public static ClassLoader systemclassloader = ClassLoader.getSystemClassLoader();
|
||||
public String nativePath;
|
||||
|
||||
@LauncherAPI
|
||||
public static ClassLoader getSystemClassLoader() {
|
||||
return systemclassloader;
|
||||
|
@ -62,9 +63,9 @@ public PublicURLClassLoader(URL[] urls) {
|
|||
public PublicURLClassLoader(URL[] urls, ClassLoader parent) {
|
||||
super(urls, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String findLibrary(String name)
|
||||
{
|
||||
public String findLibrary(String name) {
|
||||
return nativePath.concat(name);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
public class EventManager {
|
||||
public static final int QUEUE_MAX_SIZE = 2048;
|
||||
public static final int INITIAL_HANDLERS_SIZE = 16;
|
||||
public class Entry
|
||||
{
|
||||
|
||||
public class Entry {
|
||||
public Entry(EventHandler<EventInterface> func, UUID[] events) {
|
||||
this.func = func;
|
||||
this.events = events;
|
||||
|
@ -23,8 +23,8 @@ public Entry(EventHandler<EventInterface> func, UUID[] events) {
|
|||
EventHandler<EventInterface> func;
|
||||
UUID[] events;
|
||||
}
|
||||
public class QueueEntry
|
||||
{
|
||||
|
||||
public class QueueEntry {
|
||||
public QueueEntry(EventInterface event, UUID key) {
|
||||
this.event = event;
|
||||
this.key = key;
|
||||
|
@ -33,19 +33,20 @@ public QueueEntry(EventInterface event, UUID key) {
|
|||
EventInterface event;
|
||||
UUID key;
|
||||
}
|
||||
|
||||
private EventExecutor executor;
|
||||
private Thread executorThread;
|
||||
private AtomicBoolean isStarted = new AtomicBoolean(false);
|
||||
public synchronized void start()
|
||||
{
|
||||
|
||||
public synchronized void start() {
|
||||
if (isStarted.get()) return;
|
||||
executor = new EventExecutor();
|
||||
isStarted.set(true);
|
||||
executorThread = CommonHelper.newThread("EventExecutor", true, executor);
|
||||
executorThread.start();
|
||||
}
|
||||
public synchronized void stop()
|
||||
{
|
||||
|
||||
public synchronized void stop() {
|
||||
if (!isStarted.get()) return;
|
||||
executorThread.interrupt();
|
||||
try {
|
||||
|
@ -53,38 +54,41 @@ public synchronized void stop()
|
|||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<Entry> handlers = new ArrayList<>(INITIAL_HANDLERS_SIZE);
|
||||
public BlockingQueue<QueueEntry> queue = new LinkedBlockingQueue<>(QUEUE_MAX_SIZE); //Максимальный размер очереди
|
||||
public int registerHandler(EventHandler<EventInterface> func, UUID[] events)
|
||||
{
|
||||
if(isStarted.get()) throw new IllegalThreadStateException("It is forbidden to add a handler during thread operation.");
|
||||
|
||||
public int registerHandler(EventHandler<EventInterface> func, UUID[] events) {
|
||||
if (isStarted.get())
|
||||
throw new IllegalThreadStateException("It is forbidden to add a handler during thread operation.");
|
||||
Arrays.sort(events);
|
||||
handlers.add(new Entry(func, events));
|
||||
return handlers.size();
|
||||
}
|
||||
public void unregisterHandler(EventHandler<EventInterface> func)
|
||||
{
|
||||
if(isStarted.get()) throw new IllegalThreadStateException("It is forbidden to remove a handler during thread operation.");
|
||||
|
||||
public void unregisterHandler(EventHandler<EventInterface> func) {
|
||||
if (isStarted.get())
|
||||
throw new IllegalThreadStateException("It is forbidden to remove a handler during thread operation.");
|
||||
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);
|
||||
else queue.add(new QueueEntry(event, key));
|
||||
}
|
||||
public void process(UUID key, EventInterface event)
|
||||
{
|
||||
for(Entry e : handlers)
|
||||
{
|
||||
|
||||
public void process(UUID key, EventInterface event) {
|
||||
for (Entry e : handlers) {
|
||||
if (Arrays.binarySearch(e.events, key) >= 0) e.func.run(key, event);
|
||||
}
|
||||
}
|
||||
|
||||
public class EventExecutor implements Runnable {
|
||||
public boolean enable = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(enable && !Thread.interrupted())
|
||||
{
|
||||
while (enable && !Thread.interrupted()) {
|
||||
try {
|
||||
QueueEntry e = queue.take();
|
||||
process(e.key, e.event);
|
||||
|
|
|
@ -114,13 +114,12 @@ public static URL[] getClassPathURL() {
|
|||
}
|
||||
return list;
|
||||
}
|
||||
public static void checkStackTrace(Class mainClass)
|
||||
{
|
||||
|
||||
public static void checkStackTrace(Class mainClass) {
|
||||
LogHelper.debug("Testing stacktrace");
|
||||
Exception e = new Exception("Testing stacktrace");
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -486,6 +486,7 @@ public static String verifyToken(String token) {
|
|||
|
||||
private SecurityHelper() {
|
||||
}
|
||||
|
||||
//AES
|
||||
public static byte[] encrypt(String seed, byte[] cleartext) throws Exception {
|
||||
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);
|
||||
return cipher.doFinal(encrypted);
|
||||
}
|
||||
|
||||
public static byte[] HexToByte(String hexString) {
|
||||
int len = hexString.length() / 2;
|
||||
byte[] result = new byte[len];
|
||||
|
|
|
@ -9,8 +9,7 @@ public class UnpackHelper {
|
|||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public static boolean unpack(URL resource, Path target) throws IOException {
|
||||
byte[] orig = IOHelper.read(resource);
|
||||
if(IOHelper.exists(target))
|
||||
{
|
||||
if (IOHelper.exists(target)) {
|
||||
if (matches(target, orig)) return false;
|
||||
}
|
||||
if (!IOHelper.exists(target))
|
||||
|
@ -18,6 +17,7 @@ public static boolean unpack(URL resource, Path target) throws IOException {
|
|||
IOHelper.transfer(orig, target, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean matches(Path target, byte[] in) {
|
||||
try {
|
||||
return Arrays.equals(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, in),
|
||||
|
|
Loading…
Reference in a new issue