mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Реализована ServerWrapper часть вебсокетов
This commit is contained in:
parent
27ab69cd78
commit
30645741f4
10 changed files with 65 additions and 6 deletions
|
@ -16,6 +16,7 @@
|
|||
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
import ru.gravit.utils.helper.SecurityHelper;
|
||||
import ru.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
|
@ -121,6 +122,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
result.session = clientData.session;
|
||||
}
|
||||
result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server, uuid, aresult.username, client, clientData.auth.textureProvider);
|
||||
LogHelper.debug("Auth: %s accessToken %s uuid: %s", login, result.accessToken, uuid.toString());
|
||||
service.sendObject(ctx, result);
|
||||
} catch (AuthException | HWIDException e) {
|
||||
service.sendObject(ctx, new ErrorRequestEvent(e.getMessage()));
|
||||
|
|
|
@ -28,6 +28,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
result.uuid = pClient.auth.handler.checkServer(username, serverID);
|
||||
if (result.uuid != null)
|
||||
result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server, result.uuid, username, client, pClient.auth.textureProvider);
|
||||
LogHelper.debug("checkServer: %s uuid: %s serverID: %s", result.playerProfile.username, result.uuid.toString(), serverID);
|
||||
} catch (AuthException e) {
|
||||
service.sendObject(ctx, new ErrorRequestEvent(e.getMessage()));
|
||||
return;
|
||||
|
@ -36,7 +37,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
service.sendObject(ctx, new ErrorRequestEvent("Internal authHandler error"));
|
||||
return;
|
||||
}
|
||||
service.sendObject(ctx, new CheckServerRequestEvent());
|
||||
service.sendObject(ctx, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
success = LaunchServer.server.config.getAuthProviderPair().handler.joinServer(username, accessToken, serverID);
|
||||
}
|
||||
else success = client.auth.handler.joinServer(username, accessToken, serverID);
|
||||
LogHelper.debug("joinServer: %s accessToken: %s serverID: %s", username, accessToken, serverID);
|
||||
} catch (AuthException e) {
|
||||
service.sendObject(ctx, new ErrorRequestEvent(e.getMessage()));
|
||||
return;
|
||||
|
|
|
@ -19,7 +19,7 @@ public String getType() {
|
|||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
if (!client.checkSign) {
|
||||
if (!client.checkSign && !client.isAuth) {
|
||||
service.sendObject(ctx, new ErrorRequestEvent("Access denied"));
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -16,14 +16,24 @@
|
|||
import java.io.IOException;
|
||||
|
||||
public final class AuthRequest extends Request<AuthRequestEvent> implements RequestInterface {
|
||||
|
||||
@LauncherNetworkAPI
|
||||
private final String login;
|
||||
|
||||
@LauncherNetworkAPI
|
||||
private final byte[] encryptedPassword;
|
||||
@LauncherNetworkAPI
|
||||
private final String auth_id;
|
||||
@LauncherNetworkAPI
|
||||
private final HWID hwid;
|
||||
@LauncherNetworkAPI
|
||||
private final String customText;
|
||||
@LauncherNetworkAPI
|
||||
private final boolean getSession;
|
||||
@LauncherNetworkAPI
|
||||
private final ConnectTypes authType;
|
||||
|
||||
public enum ConnectTypes {
|
||||
SERVER, CLIENT, BOT
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hwid) {
|
||||
|
@ -34,6 +44,7 @@ public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hw
|
|||
customText = "";
|
||||
auth_id = "";
|
||||
getSession = true;
|
||||
authType = ConnectTypes.CLIENT;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
@ -45,6 +56,7 @@ public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hw
|
|||
this.auth_id = auth_id;
|
||||
customText = "";
|
||||
getSession = true;
|
||||
authType = ConnectTypes.CLIENT;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
@ -56,6 +68,7 @@ public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hw
|
|||
this.auth_id = auth_id;
|
||||
this.customText = customText;
|
||||
getSession = true;
|
||||
authType = ConnectTypes.CLIENT;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
@ -63,6 +76,16 @@ public AuthRequest(String login, byte[] password, HWID hwid) {
|
|||
this(null, login, password, hwid);
|
||||
}
|
||||
|
||||
public AuthRequest(String login, byte[] encryptedPassword, String auth_id, ConnectTypes authType) {
|
||||
this.login = login;
|
||||
this.encryptedPassword = encryptedPassword;
|
||||
this.auth_id = auth_id;
|
||||
this.authType = authType;
|
||||
this.hwid = null;
|
||||
this.customText = "";
|
||||
this.getSession = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthRequestEvent requestWebSockets() throws Exception {
|
||||
return (AuthRequestEvent) LegacyRequestBridge.sendRequest(this);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ru.gravit.launcher.request.websockets;
|
||||
|
||||
import com.google.gson.*;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
|
@ -16,6 +17,10 @@ public JsonRequestAdapter(ClientWebSocketService service) {
|
|||
public RequestInterface deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
||||
Class<? extends RequestInterface> cls = service.getRequestClass(typename);
|
||||
if(cls == null)
|
||||
{
|
||||
LogHelper.error("Request type %s not found", typename);
|
||||
}
|
||||
|
||||
|
||||
return (RequestInterface) context.deserialize(json, cls);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import com.google.gson.*;
|
||||
import ru.gravit.launcher.request.ResultInterface;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
|
@ -17,6 +18,10 @@ public JsonResultAdapter(ClientWebSocketService service) {
|
|||
public ResultInterface deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
||||
Class<? extends ResultInterface> cls = service.getResultClass(typename);
|
||||
if(cls == null)
|
||||
{
|
||||
LogHelper.error("Result type %s not found", typename);
|
||||
}
|
||||
|
||||
|
||||
return (ResultInterface) context.deserialize(json, cls);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import ru.gravit.launcher.LauncherConfig;
|
||||
import ru.gravit.launcher.events.request.ProfilesRequestEvent;
|
||||
import ru.gravit.launcher.profiles.ClientProfile;
|
||||
import ru.gravit.launcher.request.auth.AuthRequest;
|
||||
import ru.gravit.launcher.request.auth.AuthServerRequest;
|
||||
import ru.gravit.launcher.request.update.ProfilesRequest;
|
||||
import ru.gravit.launcher.server.setup.ServerWrapperSetup;
|
||||
|
@ -51,7 +52,13 @@ public ServerWrapper(Type type, Path configPath) {
|
|||
public boolean auth() {
|
||||
try {
|
||||
LauncherConfig cfg = Launcher.getConfig();
|
||||
if(!config.websocket.enabled)
|
||||
permissions = new AuthServerRequest(cfg, config.login, SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), config.auth_id, config.title).request();
|
||||
else
|
||||
{
|
||||
AuthRequest request = new AuthRequest(config.login, SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), config.auth_id, AuthRequest.ConnectTypes.SERVER);
|
||||
permissions = request.request().permissions;
|
||||
}
|
||||
ProfilesRequestEvent result = new ProfilesRequest(cfg).request();
|
||||
for (ClientProfile p : result.profiles) {
|
||||
LogHelper.debug("Get profile: %s", p.getTitle());
|
||||
|
@ -184,6 +191,12 @@ public void updateLauncherConfig() {
|
|||
LauncherConfig cfg = null;
|
||||
try {
|
||||
cfg = new LauncherConfig(config.address, config.port, SecurityHelper.toPublicRSAKey(IOHelper.read(publicKeyFile)), new HashMap<>(), config.projectname);
|
||||
if(config.websocket != null && config.websocket.enabled)
|
||||
{
|
||||
cfg.isNettyEnabled = true;
|
||||
cfg.nettyAddress = config.websocket.address;
|
||||
cfg.nettyPort = 1111;
|
||||
}
|
||||
} catch (InvalidKeySpecException | IOException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
|
@ -216,6 +229,9 @@ public Config getDefaultConfig() {
|
|||
newConfig.stopOnError = true;
|
||||
newConfig.reconnectCount = 10;
|
||||
newConfig.reconnectSleep = 1000;
|
||||
newConfig.websocket = new WebSocketConf();
|
||||
newConfig.websocket.address = "ws://localhost:9274/api";
|
||||
newConfig.websocket.enabled = false;
|
||||
newConfig.env = LauncherConfig.LauncherEnvironment.STD;
|
||||
return newConfig;
|
||||
}
|
||||
|
@ -229,6 +245,7 @@ public static final class Config {
|
|||
public String title;
|
||||
public String projectname;
|
||||
public String address;
|
||||
public WebSocketConf websocket;
|
||||
public int port;
|
||||
public int reconnectCount;
|
||||
public int reconnectSleep;
|
||||
|
@ -246,6 +263,11 @@ public static final class Config {
|
|||
public String auth_id = "";
|
||||
public LauncherConfig.LauncherEnvironment env;
|
||||
}
|
||||
public static final class WebSocketConf
|
||||
{
|
||||
public boolean enabled;
|
||||
public String address;
|
||||
}
|
||||
|
||||
public ClientProfile profile;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public static AutogenConfig getAutogenConfig() {
|
|||
public final boolean isUsingWrapper;
|
||||
public final boolean isDownloadJava;
|
||||
public final boolean isWarningMissArchJava;
|
||||
public final boolean isNettyEnabled;
|
||||
public boolean isNettyEnabled;
|
||||
|
||||
public final String guardLicenseName;
|
||||
public final String guardLicenseKey;
|
||||
|
|
|
@ -28,6 +28,6 @@ public UUID getUUID() {
|
|||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "checkServe";
|
||||
return "checkServer";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue