mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
LauncherUpdateResponse
This commit is contained in:
parent
3fe1cdde60
commit
e133fc06cb
2 changed files with 59 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
|||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.group.ChannelGroup;
|
||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||
|
@ -14,6 +15,7 @@
|
|||
import ru.gravit.launchserver.socket.websocket.json.auth.AuthResponse;
|
||||
import ru.gravit.launchserver.socket.websocket.json.auth.CheckServerResponse;
|
||||
import ru.gravit.launchserver.socket.websocket.json.auth.JoinServerResponse;
|
||||
import ru.gravit.launchserver.socket.websocket.json.update.LauncherResponse;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -64,11 +66,16 @@ public void registerResponses()
|
|||
registerResponse("auth", AuthResponse.class);
|
||||
registerResponse("checkServer", CheckServerResponse.class);
|
||||
registerResponse("joinServer", JoinServerResponse.class);
|
||||
registerResponse("launcherUpdate", LauncherResponse.class);
|
||||
}
|
||||
public void sendObject(ChannelHandlerContext ctx, Object obj)
|
||||
{
|
||||
ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj)));
|
||||
}
|
||||
public void sendObjectAndClose(ChannelHandlerContext ctx, Object obj)
|
||||
{
|
||||
ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj))).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
public void sendEvent(EventResult obj)
|
||||
{
|
||||
channels.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj)));
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package ru.gravit.launchserver.socket.websocket.json.update;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
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;
|
||||
|
||||
public class LauncherResponse implements JsonResponseInterface {
|
||||
public Version version;
|
||||
public String hash;
|
||||
public int launcher_type;
|
||||
@Override
|
||||
public String getType() {
|
||||
return "launcherUpdate";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
if(launcher_type == 1) // JAR
|
||||
{
|
||||
if(hash.equals("1")) //REPLACE REAL HASH
|
||||
{
|
||||
service.sendObject(ctx, new Result(false));
|
||||
} else
|
||||
{
|
||||
service.sendObjectAndClose(ctx, new Result(true));
|
||||
}
|
||||
} else if(launcher_type == 2)
|
||||
{
|
||||
if(hash.equals("2")) //REPLACE REAL HASH
|
||||
{
|
||||
service.sendObject(ctx, new Result(false));
|
||||
} else
|
||||
{
|
||||
service.sendObjectAndClose(ctx, new Result(true));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public class Result
|
||||
{
|
||||
public String type = "success";
|
||||
public String requesttype = "launcherUpdate";
|
||||
|
||||
public Result(boolean needUpdate) {
|
||||
this.needUpdate = needUpdate;
|
||||
}
|
||||
|
||||
public boolean needUpdate;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue