mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +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;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import ru.gravit.launcher.ClientPermissions;
|
||||
import ru.gravit.launcher.HWID;
|
||||
import ru.gravit.launcher.OshiHWID;
|
||||
import ru.gravit.launcher.profiles.ClientProfile;
|
||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.auth.AuthException;
|
||||
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.response.profile.ProfileByUUIDResponse;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||
|
@ -15,6 +19,7 @@
|
|||
import ru.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AuthResponse implements JsonResponseInterface {
|
||||
public String login;
|
||||
|
@ -22,7 +27,7 @@ public class AuthResponse implements JsonResponseInterface {
|
|||
|
||||
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.password = password;
|
||||
this.authid = authid;
|
||||
|
@ -30,7 +35,7 @@ public AuthResponse(String login, String password, int authid, HWID hwid) {
|
|||
}
|
||||
|
||||
public int authid;
|
||||
public HWID hwid;
|
||||
public OshiHWID hwid;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
|
@ -40,6 +45,7 @@ public String getType() {
|
|||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client clientData) throws Exception {
|
||||
try {
|
||||
Result result = new Result();
|
||||
String ip = IOHelper.getIP(ctx.channel().remoteAddress());
|
||||
if (LaunchServer.server.limiter.isLimit(ip)) {
|
||||
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");
|
||||
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];
|
||||
AuthProviderResult result = provider.auth(login, password, ip);
|
||||
if (!VerifyHelper.isValidUsername(result.username)) {
|
||||
AuthProvider.authError(String.format("Illegal result: '%s'", result.username));
|
||||
LaunchServer.server.authHookManager.preHook(context, clientData);
|
||||
AuthProviderResult aresult = provider.auth(login, password, ip);
|
||||
if (!VerifyHelper.isValidUsername(aresult.username)) {
|
||||
AuthProvider.authError(String.format("Illegal result: '%s'", aresult.username));
|
||||
return;
|
||||
}
|
||||
Collection<ClientProfile> profiles = LaunchServer.server.getProfiles();
|
||||
|
@ -67,10 +75,15 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
if (clientData.profile == null) {
|
||||
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.permissions = result.permissions;
|
||||
service.sendObject(ctx, new WebSocketService.SuccessResult("auth"));
|
||||
clientData.permissions = aresult.permissions;
|
||||
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) {
|
||||
service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage()));
|
||||
}
|
||||
|
@ -81,5 +94,8 @@ public Result() {
|
|||
}
|
||||
|
||||
public String error;
|
||||
public ClientPermissions permissions;
|
||||
public PlayerProfile playerProfile;
|
||||
public String accessToken;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
package ru.gravit.launchserver.socket.websocket.json.auth;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.auth.AuthException;
|
||||
import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse;
|
||||
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;
|
||||
public String client;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
|
@ -18,9 +23,12 @@ public String getType() {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) {
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client pClient) {
|
||||
Result result = new Result();
|
||||
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) {
|
||||
service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage()));
|
||||
return;
|
||||
|
@ -35,5 +43,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
public class Result {
|
||||
public String type = "success";
|
||||
public String requesttype = "checkServer";
|
||||
public UUID uuid;
|
||||
public PlayerProfile playerProfile;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue