mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
LauncherUpdateResponse реализация
This commit is contained in:
parent
2024018eb2
commit
275305b16c
5 changed files with 21 additions and 5 deletions
|
@ -7,6 +7,7 @@
|
|||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.launcher.serialize.signed.SignedBytesHolder;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.utils.helper.SecurityHelper;
|
||||
|
||||
public abstract class LauncherBinary {
|
||||
@LauncherAPI
|
||||
|
@ -15,6 +16,7 @@ public abstract class LauncherBinary {
|
|||
protected final Path binaryFile;
|
||||
protected final Path syncBinaryFile;
|
||||
private volatile SignedBytesHolder binary;
|
||||
private volatile byte[] hash;
|
||||
|
||||
@LauncherAPI
|
||||
protected LauncherBinary(LaunchServer server, Path binaryFile) {
|
||||
|
@ -42,11 +44,16 @@ public final boolean exists() {
|
|||
public final SignedBytesHolder getBytes() {
|
||||
return binary;
|
||||
}
|
||||
@LauncherAPI
|
||||
public final byte[] getHash() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public final boolean sync() throws IOException {
|
||||
boolean exists = exists();
|
||||
binary = exists ? new SignedBytesHolder(IOHelper.read(syncBinaryFile), server.privateKey) : null;
|
||||
hash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA512,IOHelper.newInput(syncBinaryFile));
|
||||
return exists;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.command.Command;
|
||||
import ru.gravit.launchserver.socket.NettyServerSocketHandler;
|
||||
import ru.gravit.utils.helper.CommonHelper;
|
||||
|
||||
public class TestCommand extends Command {
|
||||
public TestCommand(LaunchServer server) {
|
||||
|
@ -27,7 +28,10 @@ public void invoke(String... args) throws Exception {
|
|||
if (handler == null)
|
||||
handler = new NettyServerSocketHandler(server);
|
||||
if (args[0].equals("start")) {
|
||||
handler.run();
|
||||
CommonHelper.newThread("Netty Server",true,handler);
|
||||
}
|
||||
if (args[0].equals("stop")) {
|
||||
handler.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package ru.gravit.launchserver.socket.websocket.json.update;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||
import ru.gravit.utils.Version;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
|
||||
public class LauncherResponse implements JsonResponseInterface {
|
||||
public Version version;
|
||||
public String hash;
|
||||
|
@ -17,9 +21,10 @@ public String getType() {
|
|||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
byte[] bytes = Base64.getDecoder().decode(hash);
|
||||
if(launcher_type == 1) // JAR
|
||||
{
|
||||
if(hash.equals("1")) //REPLACE REAL HASH
|
||||
if(Arrays.equals(bytes, LaunchServer.server.launcherBinary.getHash())) //REPLACE REAL HASH
|
||||
{
|
||||
service.sendObject(ctx, new Result(false));
|
||||
} else
|
||||
|
@ -28,14 +33,14 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
}
|
||||
} else if(launcher_type == 2)
|
||||
{
|
||||
if(hash.equals("2")) //REPLACE REAL HASH
|
||||
if(Arrays.equals(bytes, LaunchServer.server.launcherEXEBinary.getHash())) //REPLACE REAL HASH
|
||||
{
|
||||
service.sendObject(ctx, new Result(false));
|
||||
} else
|
||||
{
|
||||
service.sendObjectAndClose(ctx, new Result(true));
|
||||
}
|
||||
}
|
||||
} else service.sendObject(ctx, new WebSocketService.ErrorResult("Request launcher type error"));
|
||||
|
||||
}
|
||||
public class Result
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
dependencies {
|
||||
compile project(':libLauncher')
|
||||
compile 'javax.websocket:javax.websocket-client-api:1.1'
|
||||
compileOnly 'com.google.code.gson:gson:2.8.5'
|
||||
compileOnly 'com.google.guava:guava:26.0-jre'
|
||||
compile files('../compat/authlib/authlib-clean.jar')
|
||||
}
|
||||
|
|
|
@ -5,4 +5,5 @@
|
|||
compileOnly 'org.fusesource.jansi:jansi:1.17.1'
|
||||
compileOnly 'org.javassist:javassist:3.23.1-GA'
|
||||
compile 'com.eclipsesource.minimal-json:minimal-json:0.9.4'
|
||||
compile 'com.google.code.gson:gson:2.8.5'
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue