mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-09 00:59:44 +03:00
Тестовый AuthResponse
This commit is contained in:
parent
5fa271314c
commit
fdb7da1460
6 changed files with 101 additions and 5 deletions
|
@ -287,7 +287,7 @@ public static void main(String... args) throws Throwable {
|
||||||
public final Path privateKeyFile;
|
public final Path privateKeyFile;
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public final Path updatesDir;
|
public final Path updatesDir;
|
||||||
|
public static LaunchServer server;
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public final Path profilesDir;
|
public final Path profilesDir;
|
||||||
// Server config
|
// Server config
|
||||||
|
@ -350,6 +350,7 @@ public LaunchServer(Path dir, boolean portable) throws IOException, InvalidKeySp
|
||||||
TextureProvider.registerProviders();
|
TextureProvider.registerProviders();
|
||||||
HWIDHandler.registerHandlers();
|
HWIDHandler.registerHandlers();
|
||||||
Response.registerResponses();
|
Response.registerResponses();
|
||||||
|
LaunchServer.server = this;
|
||||||
|
|
||||||
// Set command handler
|
// Set command handler
|
||||||
CommandHandler localCommandHandler;
|
CommandHandler localCommandHandler;
|
||||||
|
|
|
@ -126,6 +126,7 @@ public void run() {
|
||||||
//engine.setUseClientMode(false);
|
//engine.setUseClientMode(false);
|
||||||
EventLoopGroup bossGroup = new NioEventLoopGroup();
|
EventLoopGroup bossGroup = new NioEventLoopGroup();
|
||||||
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||||
|
WebSocketFrameHandler.server = LaunchServer.server;
|
||||||
try {
|
try {
|
||||||
ServerBootstrap b = new ServerBootstrap();
|
ServerBootstrap b = new ServerBootstrap();
|
||||||
b.group(bossGroup, workerGroup)
|
b.group(bossGroup, workerGroup)
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
import io.netty.channel.group.DefaultChannelGroup;
|
import io.netty.channel.group.DefaultChannelGroup;
|
||||||
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
||||||
import io.netty.util.concurrent.GlobalEventExecutor;
|
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponse;
|
import ru.gravit.launchserver.socket.websocket.json.JsonResponse;
|
||||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseAdapter;
|
import ru.gravit.launchserver.socket.websocket.json.JsonResponseAdapter;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
@ -19,9 +20,11 @@
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
|
||||||
public class WebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
|
public class WebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
|
||||||
static final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
|
public static final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
|
||||||
static Gson gson;
|
public static Gson gson;
|
||||||
static GsonBuilder builder = new GsonBuilder();
|
|
||||||
|
public static LaunchServer server;
|
||||||
|
public static GsonBuilder builder = new GsonBuilder();
|
||||||
static {
|
static {
|
||||||
builder.registerTypeAdapter(JsonResponse.class,new JsonResponseAdapter());
|
builder.registerTypeAdapter(JsonResponse.class,new JsonResponseAdapter());
|
||||||
gson = builder.create();
|
gson = builder.create();
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
||||||
|
import ru.gravit.launchserver.socket.websocket.WebSocketFrameHandler;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
public class EchoResponse implements JsonResponse {
|
public class EchoResponse implements JsonResponse {
|
||||||
|
@ -19,5 +20,14 @@ public String getType() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(ChannelHandlerContext ctx, WebSocketFrame frame) {
|
public void execute(ChannelHandlerContext ctx, WebSocketFrame frame) {
|
||||||
LogHelper.info("Echo: %s",echo);
|
LogHelper.info("Echo: %s",echo);
|
||||||
|
ctx.channel().write(WebSocketFrameHandler.gson.toJson(new Result(echo)));
|
||||||
|
}
|
||||||
|
public class Result
|
||||||
|
{
|
||||||
|
String echo;
|
||||||
|
|
||||||
|
public Result(String echo) {
|
||||||
|
this.echo = echo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,5 +5,5 @@
|
||||||
|
|
||||||
public interface JsonResponse {
|
public interface JsonResponse {
|
||||||
String getType();
|
String getType();
|
||||||
void execute(ChannelHandlerContext ctx, WebSocketFrame frame);
|
void execute(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
package ru.gravit.launchserver.socket.websocket.json.auth;
|
||||||
|
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
||||||
|
import ru.gravit.launcher.profiles.ClientProfile;
|
||||||
|
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.auth.AuthException;
|
||||||
|
import ru.gravit.launchserver.auth.hwid.HWID;
|
||||||
|
import ru.gravit.launchserver.auth.hwid.HWIDException;
|
||||||
|
import ru.gravit.launchserver.auth.provider.AuthProvider;
|
||||||
|
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||||
|
import ru.gravit.launchserver.socket.websocket.WebSocketFrameHandler;
|
||||||
|
import ru.gravit.launchserver.socket.websocket.json.JsonResponse;
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public class AuthResponse implements JsonResponse {
|
||||||
|
public String login;
|
||||||
|
public String client;
|
||||||
|
private LaunchServer server = LaunchServer.server;
|
||||||
|
|
||||||
|
public String password;
|
||||||
|
|
||||||
|
public AuthResponse(String login, String password, int authid, HWID hwid) {
|
||||||
|
this.login = login;
|
||||||
|
this.password = password;
|
||||||
|
this.authid = authid;
|
||||||
|
this.hwid = hwid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int authid;
|
||||||
|
public HWID hwid;
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "auth";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception {
|
||||||
|
try {
|
||||||
|
String ip = IOHelper.getIP(ctx.channel().remoteAddress());
|
||||||
|
if (server.limiter.isLimit(ip)) {
|
||||||
|
AuthProvider.authError(server.config.authRejectString);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AuthProvider provider = server.config.authProvider[authid];
|
||||||
|
AuthProviderResult result = provider.auth(login, password, ip);
|
||||||
|
if (!VerifyHelper.isValidUsername(result.username)) {
|
||||||
|
AuthProvider.authError(String.format("Illegal result: '%s'", result.username));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Collection<SignedObjectHolder<ClientProfile>> profiles = server.getProfiles();
|
||||||
|
for (SignedObjectHolder<ClientProfile> p : profiles) {
|
||||||
|
if (p.object.getTitle().equals(client)) {
|
||||||
|
if (!p.object.isWhitelistContains(login)) {
|
||||||
|
throw new AuthException(server.config.whitelistRejectString);
|
||||||
|
}
|
||||||
|
//clientData.profile = p.object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//if(clientData.profile == null) {
|
||||||
|
// throw new AuthException("You profile not found");
|
||||||
|
//}
|
||||||
|
server.config.hwidHandler.check(hwid, result.username);
|
||||||
|
} catch (AuthException | HWIDException e)
|
||||||
|
{
|
||||||
|
ctx.channel().write(WebSocketFrameHandler.gson.toJson(new ErrorResult(e.getMessage())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class ErrorResult
|
||||||
|
{
|
||||||
|
public ErrorResult(String error) {
|
||||||
|
this.error = error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String error;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue