mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-14 20:21:45 +03:00
[FIX] Фикс авторизации и CheckServer в WebSockets
This commit is contained in:
parent
09802d418e
commit
01d6587c11
2 changed files with 36 additions and 10 deletions
|
@ -1,13 +1,17 @@
|
||||||
package ru.gravit.launchserver.socket.websocket.json.auth;
|
package ru.gravit.launchserver.socket.websocket.json.auth;
|
||||||
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import ru.gravit.launcher.ClientPermissions;
|
||||||
import ru.gravit.launcher.HWID;
|
import ru.gravit.launcher.HWID;
|
||||||
|
import ru.gravit.launcher.OshiHWID;
|
||||||
import ru.gravit.launcher.profiles.ClientProfile;
|
import ru.gravit.launcher.profiles.ClientProfile;
|
||||||
|
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.auth.AuthException;
|
import ru.gravit.launchserver.auth.AuthException;
|
||||||
import ru.gravit.launchserver.auth.hwid.HWIDException;
|
import ru.gravit.launchserver.auth.hwid.HWIDException;
|
||||||
import ru.gravit.launchserver.auth.provider.AuthProvider;
|
import ru.gravit.launchserver.auth.provider.AuthProvider;
|
||||||
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||||
|
import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse;
|
||||||
import ru.gravit.launchserver.socket.Client;
|
import ru.gravit.launchserver.socket.Client;
|
||||||
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
||||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||||
|
@ -15,6 +19,7 @@
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class AuthResponse implements JsonResponseInterface {
|
public class AuthResponse implements JsonResponseInterface {
|
||||||
public String login;
|
public String login;
|
||||||
|
@ -22,7 +27,7 @@ public class AuthResponse implements JsonResponseInterface {
|
||||||
|
|
||||||
public String password;
|
public String password;
|
||||||
|
|
||||||
public AuthResponse(String login, String password, int authid, HWID hwid) {
|
public AuthResponse(String login, String password, int authid, OshiHWID hwid) {
|
||||||
this.login = login;
|
this.login = login;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.authid = authid;
|
this.authid = authid;
|
||||||
|
@ -30,7 +35,7 @@ public AuthResponse(String login, String password, int authid, HWID hwid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int authid;
|
public int authid;
|
||||||
public HWID hwid;
|
public OshiHWID hwid;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
|
@ -40,6 +45,7 @@ public String getType() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client clientData) throws Exception {
|
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client clientData) throws Exception {
|
||||||
try {
|
try {
|
||||||
|
Result result = new Result();
|
||||||
String ip = IOHelper.getIP(ctx.channel().remoteAddress());
|
String ip = IOHelper.getIP(ctx.channel().remoteAddress());
|
||||||
if (LaunchServer.server.limiter.isLimit(ip)) {
|
if (LaunchServer.server.limiter.isLimit(ip)) {
|
||||||
AuthProvider.authError(LaunchServer.server.config.authRejectString);
|
AuthProvider.authError(LaunchServer.server.config.authRejectString);
|
||||||
|
@ -49,10 +55,12 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
||||||
AuthProvider.authError("Don't skip Launcher Update");
|
AuthProvider.authError("Don't skip Launcher Update");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ru.gravit.launchserver.response.auth.AuthResponse.AuthContext context = new ru.gravit.launchserver.response.auth.AuthResponse.AuthContext(0, login, password.length(), client, null, false);
|
||||||
AuthProvider provider = LaunchServer.server.config.authProvider[authid];
|
AuthProvider provider = LaunchServer.server.config.authProvider[authid];
|
||||||
AuthProviderResult result = provider.auth(login, password, ip);
|
LaunchServer.server.authHookManager.preHook(context, clientData);
|
||||||
if (!VerifyHelper.isValidUsername(result.username)) {
|
AuthProviderResult aresult = provider.auth(login, password, ip);
|
||||||
AuthProvider.authError(String.format("Illegal result: '%s'", result.username));
|
if (!VerifyHelper.isValidUsername(aresult.username)) {
|
||||||
|
AuthProvider.authError(String.format("Illegal result: '%s'", aresult.username));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Collection<ClientProfile> profiles = LaunchServer.server.getProfiles();
|
Collection<ClientProfile> profiles = LaunchServer.server.getProfiles();
|
||||||
|
@ -67,10 +75,15 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
||||||
if (clientData.profile == null) {
|
if (clientData.profile == null) {
|
||||||
throw new AuthException("You profile not found");
|
throw new AuthException("You profile not found");
|
||||||
}
|
}
|
||||||
LaunchServer.server.config.hwidHandler.check(hwid, result.username);
|
UUID uuid = LaunchServer.server.config.authHandler.auth(aresult);
|
||||||
|
LaunchServer.server.config.hwidHandler.check(hwid, aresult.username);
|
||||||
|
LaunchServer.server.authHookManager.postHook(context, clientData);
|
||||||
clientData.isAuth = true;
|
clientData.isAuth = true;
|
||||||
clientData.permissions = result.permissions;
|
clientData.permissions = aresult.permissions;
|
||||||
service.sendObject(ctx, new WebSocketService.SuccessResult("auth"));
|
result.accessToken = aresult.accessToken;
|
||||||
|
result.permissions = clientData.permissions;
|
||||||
|
result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,uuid,aresult.username,client);
|
||||||
|
service.sendObject(ctx, result);
|
||||||
} catch (AuthException | HWIDException e) {
|
} catch (AuthException | HWIDException e) {
|
||||||
service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage()));
|
service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage()));
|
||||||
}
|
}
|
||||||
|
@ -81,5 +94,8 @@ public Result() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String error;
|
public String error;
|
||||||
|
public ClientPermissions permissions;
|
||||||
|
public PlayerProfile playerProfile;
|
||||||
|
public String accessToken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,21 @@
|
||||||
package ru.gravit.launchserver.socket.websocket.json.auth;
|
package ru.gravit.launchserver.socket.websocket.json.auth;
|
||||||
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.auth.AuthException;
|
import ru.gravit.launchserver.auth.AuthException;
|
||||||
|
import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse;
|
||||||
import ru.gravit.launchserver.socket.Client;
|
import ru.gravit.launchserver.socket.Client;
|
||||||
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
||||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class CheckServerResponse implements JsonResponseInterface {
|
public class CheckServerResponse implements JsonResponseInterface {
|
||||||
public String serverID;
|
public String serverID;
|
||||||
public String username;
|
public String username;
|
||||||
|
public String client;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
|
@ -18,9 +23,12 @@ public String getType() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) {
|
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client pClient) {
|
||||||
|
Result result = new Result();
|
||||||
try {
|
try {
|
||||||
LaunchServer.server.config.authHandler.checkServer(username, serverID);
|
result.uuid = LaunchServer.server.config.authHandler.checkServer(username, serverID);
|
||||||
|
if(result.uuid != null)
|
||||||
|
result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,result.uuid,username,client);
|
||||||
} catch (AuthException e) {
|
} catch (AuthException e) {
|
||||||
service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage()));
|
service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage()));
|
||||||
return;
|
return;
|
||||||
|
@ -35,5 +43,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
||||||
public class Result {
|
public class Result {
|
||||||
public String type = "success";
|
public String type = "success";
|
||||||
public String requesttype = "checkServer";
|
public String requesttype = "checkServer";
|
||||||
|
public UUID uuid;
|
||||||
|
public PlayerProfile playerProfile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue