mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
checkServer and joinServer
This commit is contained in:
parent
79acc5b503
commit
3fe1cdde60
3 changed files with 93 additions and 0 deletions
|
@ -12,6 +12,8 @@
|
||||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseAdapter;
|
import ru.gravit.launchserver.socket.websocket.json.JsonResponseAdapter;
|
||||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||||
import ru.gravit.launchserver.socket.websocket.json.auth.AuthResponse;
|
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.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -60,6 +62,8 @@ public void registerResponses()
|
||||||
{
|
{
|
||||||
registerResponse("echo", EchoResponse.class);
|
registerResponse("echo", EchoResponse.class);
|
||||||
registerResponse("auth", AuthResponse.class);
|
registerResponse("auth", AuthResponse.class);
|
||||||
|
registerResponse("checkServer", CheckServerResponse.class);
|
||||||
|
registerResponse("joinServer", JoinServerResponse.class);
|
||||||
}
|
}
|
||||||
public void sendObject(ChannelHandlerContext ctx, Object obj)
|
public void sendObject(ChannelHandlerContext ctx, Object obj)
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package ru.gravit.launchserver.socket.websocket.json.auth;
|
||||||
|
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.auth.AuthException;
|
||||||
|
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.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class CheckServerResponse implements JsonResponseInterface {
|
||||||
|
public String serverID;
|
||||||
|
public String username;
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "checkServer";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||||
|
UUID uuid;
|
||||||
|
try {
|
||||||
|
uuid = LaunchServer.server.config.authHandler[0].checkServer(username, serverID);
|
||||||
|
} catch (AuthException e) {
|
||||||
|
service.sendObject(ctx,new WebSocketService.ErrorResult(e.getMessage()));
|
||||||
|
return;
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogHelper.error(e);
|
||||||
|
service.sendObject(ctx,new WebSocketService.ErrorResult("Internal authHandler error"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
service.sendObject(ctx,new Result());
|
||||||
|
}
|
||||||
|
public class Result
|
||||||
|
{
|
||||||
|
public String type = "success";
|
||||||
|
public String requesttype = "checkServer";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package ru.gravit.launchserver.socket.websocket.json.auth;
|
||||||
|
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.auth.AuthException;
|
||||||
|
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.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class JoinServerResponse implements JsonResponseInterface {
|
||||||
|
public String serverID;
|
||||||
|
public String accessToken;
|
||||||
|
public String username;
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "joinServer";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||||
|
boolean success;
|
||||||
|
try {
|
||||||
|
success = LaunchServer.server.config.authHandler[0].joinServer(username,accessToken,serverID);
|
||||||
|
} catch (AuthException e) {
|
||||||
|
service.sendObject(ctx,new WebSocketService.ErrorResult(e.getMessage()));
|
||||||
|
return;
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogHelper.error(e);
|
||||||
|
service.sendObject(ctx,new WebSocketService.ErrorResult("Internal authHandler error"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
service.sendObject(ctx,new Result(success));
|
||||||
|
}
|
||||||
|
public class Result
|
||||||
|
{
|
||||||
|
public String type = "success";
|
||||||
|
public String requesttype = "checkServer";
|
||||||
|
|
||||||
|
public Result(boolean allow) {
|
||||||
|
this.allow = allow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean allow;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue