mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-11 18:57:30 +03:00
Merge branch 'dev' into fix/asm
This commit is contained in:
commit
3a8ac6440b
22 changed files with 446 additions and 53 deletions
|
@ -25,6 +25,7 @@
|
|||
import ru.gravit.launchserver.binary.*;
|
||||
import ru.gravit.launchserver.components.AuthLimiterComponent;
|
||||
import ru.gravit.launchserver.components.Component;
|
||||
import ru.gravit.launchserver.config.LaunchServerRuntimeConfig;
|
||||
import ru.gravit.launchserver.config.adapter.*;
|
||||
import ru.gravit.launchserver.manangers.*;
|
||||
import ru.gravit.launchserver.manangers.hook.AuthHookManager;
|
||||
|
@ -41,10 +42,7 @@
|
|||
import ru.gravit.utils.config.JsonConfigurable;
|
||||
import ru.gravit.utils.helper.*;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.lang.ProcessBuilder.Redirect;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetSocketAddress;
|
||||
|
@ -133,20 +131,16 @@ public AuthProviderPair getAuthProviderPair() {
|
|||
public NettyConfig netty;
|
||||
public GuardLicenseConf guardLicense;
|
||||
|
||||
public boolean compress;
|
||||
|
||||
public String whitelistRejectString;
|
||||
|
||||
public boolean genMappings;
|
||||
public boolean isUsingWrapper;
|
||||
public boolean isDownloadJava;
|
||||
public LauncherConf launcher;
|
||||
|
||||
public boolean isWarningMissArchJava;
|
||||
public boolean enabledProGuard;
|
||||
public boolean enabledRadon;
|
||||
public boolean stripLineNumbers;
|
||||
public boolean deleteTempFiles;
|
||||
public boolean enableRcon;
|
||||
|
||||
public String startScript;
|
||||
|
||||
|
@ -244,6 +238,11 @@ public static class ExeConf {
|
|||
public String txtProductVersion;
|
||||
}
|
||||
|
||||
public class LauncherConf
|
||||
{
|
||||
public String guardType;
|
||||
}
|
||||
|
||||
public class NettyConfig {
|
||||
public boolean clientEnabled;
|
||||
public String launcherURL;
|
||||
|
@ -336,6 +335,7 @@ public static void main(String... args) throws Throwable {
|
|||
public final List<String> args;
|
||||
|
||||
public final Path configFile;
|
||||
public final Path runtimeConfigFile;
|
||||
|
||||
public final Path publicKeyFile;
|
||||
|
||||
|
@ -349,6 +349,7 @@ public static void main(String... args) throws Throwable {
|
|||
// Server config
|
||||
|
||||
public Config config;
|
||||
public LaunchServerRuntimeConfig runtime;
|
||||
|
||||
|
||||
public final RSAPublicKey publicKey;
|
||||
|
@ -413,6 +414,7 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException
|
|||
launcherLibrariesCompile = dir.resolve("launcher-libraries-compile");
|
||||
this.args = Arrays.asList(args);
|
||||
configFile = dir.resolve("LaunchServer.conf");
|
||||
runtimeConfigFile = dir.resolve("RuntimeLaunchServer.conf");
|
||||
publicKeyFile = dir.resolve("public.key");
|
||||
privateKeyFile = dir.resolve("private.key");
|
||||
updatesDir = dir.resolve("updates");
|
||||
|
@ -486,6 +488,20 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException
|
|||
try (BufferedReader reader = IOHelper.newReader(configFile)) {
|
||||
config = Launcher.gson.fromJson(reader, Config.class);
|
||||
}
|
||||
if(!Files.exists(runtimeConfigFile))
|
||||
{
|
||||
LogHelper.info("Reset LaunchServer runtime config file");
|
||||
runtime = new LaunchServerRuntimeConfig();
|
||||
runtime.reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.info("Reading LaunchServer runtime config file");
|
||||
try (BufferedReader reader = IOHelper.newReader(runtimeConfigFile)) {
|
||||
runtime = Launcher.gson.fromJson(reader, LaunchServerRuntimeConfig.class);
|
||||
}
|
||||
}
|
||||
runtime.verify();
|
||||
config.verify();
|
||||
Launcher.applyLauncherEnv(config.env);
|
||||
for (AuthProviderPair provider : config.auth) {
|
||||
|
@ -633,6 +649,18 @@ public void close() {
|
|||
// Close handlers & providers
|
||||
config.close();
|
||||
modulesManager.close();
|
||||
LogHelper.info("Save LaunchServer runtime config");
|
||||
try(Writer writer = IOHelper.newWriter(runtimeConfigFile))
|
||||
{
|
||||
if(LaunchServer.gson != null)
|
||||
{
|
||||
LaunchServer.gson.toJson(runtime, writer);
|
||||
} else {
|
||||
LogHelper.error("Error writing LaunchServer runtime config file. Gson is null");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
// Print last message before death :(
|
||||
LogHelper.info("LaunchServer stopped");
|
||||
}
|
||||
|
|
|
@ -40,8 +40,10 @@ public static String getHandlerName(Class<AuthHandler> clazz) {
|
|||
public static void registerHandlers() {
|
||||
if (!registredHandl) {
|
||||
registerHandler("null", NullAuthHandler.class);
|
||||
registerHandler("json", JsonAuthHandler.class);
|
||||
registerHandler("memory", MemoryAuthHandler.class);
|
||||
registerHandler("mysql", MySQLAuthHandler.class);
|
||||
registerHandler("request", RequestAuthHandler.class);
|
||||
registredHandl = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
package ru.gravit.launchserver.auth.handler;
|
||||
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.utils.HTTPRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.UUID;
|
||||
|
||||
public class JsonAuthHandler extends CachedAuthHandler {
|
||||
public URL getUrl;
|
||||
public URL updateAuthUrl;
|
||||
public URL updateServerIdUrl;
|
||||
public class EntryRequestByUsername
|
||||
{
|
||||
public String username;
|
||||
|
||||
public EntryRequestByUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
}
|
||||
public class EntryRequestByUUID
|
||||
{
|
||||
public UUID uuid;
|
||||
|
||||
public EntryRequestByUUID(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
}
|
||||
public class UpdateAuthRequest
|
||||
{
|
||||
public UUID uuid;
|
||||
public String username;
|
||||
public String accessToken;
|
||||
|
||||
public UpdateAuthRequest(UUID uuid, String username, String accessToken) {
|
||||
this.uuid = uuid;
|
||||
this.username = username;
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
}
|
||||
public class UpdateServerIDRequest
|
||||
{
|
||||
public UUID uuid;
|
||||
public String serverID;
|
||||
|
||||
public UpdateServerIDRequest(UUID uuid, String serverID) {
|
||||
this.uuid = uuid;
|
||||
this.serverID = serverID;
|
||||
}
|
||||
}
|
||||
public class SuccessResponse
|
||||
{
|
||||
public boolean success;
|
||||
}
|
||||
@Override
|
||||
protected Entry fetchEntry(String username) throws IOException {
|
||||
return LaunchServer.gson.fromJson(HTTPRequest.jsonRequest(LaunchServer.gson.toJsonTree(new EntryRequestByUsername(username)), getUrl), Entry.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Entry fetchEntry(UUID uuid) throws IOException {
|
||||
return LaunchServer.gson.fromJson(HTTPRequest.jsonRequest(LaunchServer.gson.toJsonTree(new EntryRequestByUUID(uuid)), getUrl), Entry.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean updateAuth(UUID uuid, String username, String accessToken) throws IOException {
|
||||
return LaunchServer.gson.fromJson(HTTPRequest.jsonRequest(LaunchServer.gson.toJsonTree(new UpdateAuthRequest(uuid, username, accessToken)), updateAuthUrl), SuccessResponse.class).success;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean updateServerID(UUID uuid, String serverID) throws IOException {
|
||||
return LaunchServer.gson.fromJson(HTTPRequest.jsonRequest(LaunchServer.gson.toJsonTree(new UpdateServerIDRequest(uuid, serverID)), updateServerIdUrl), SuccessResponse.class).success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
package ru.gravit.launchserver.auth.handler;
|
||||
|
||||
import ru.gravit.utils.helper.CommonHelper;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class RequestAuthHandler extends CachedAuthHandler {
|
||||
private String usernameFetch;
|
||||
private String uuidFetch;
|
||||
|
||||
private String updateAuth;
|
||||
private String updateServerID;
|
||||
|
||||
private String splitSymbol = ":";
|
||||
private String goodResponse = "OK";
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
if (usernameFetch == null)
|
||||
LogHelper.error("[Verify][AuthHandler] usernameFetch cannot be null");
|
||||
if (uuidFetch == null)
|
||||
LogHelper.error("[Verify][AuthHandler] uuidFetch cannot be null");
|
||||
if (updateAuth == null)
|
||||
LogHelper.error("[Verify][AuthHandler] updateAuth cannot be null");
|
||||
if (updateServerID == null)
|
||||
LogHelper.error("[Verify][AuthHandler] updateServerID cannot be null");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Entry fetchEntry(UUID uuid) throws IOException {
|
||||
String response = IOHelper.request(new URL(CommonHelper.replace(uuidFetch, "uuid", IOHelper.urlEncode(uuid.toString()))));
|
||||
String[] parts = response.split(splitSymbol);
|
||||
String username = parts[0];
|
||||
String accessToken = parts[1];
|
||||
String serverID = parts[2];
|
||||
if (LogHelper.isDebugEnabled()) {
|
||||
LogHelper.debug("[AuthHandler] Getted username: " + username);
|
||||
LogHelper.debug("[AuthHandler] Getted accessToken: " + accessToken);
|
||||
LogHelper.debug("[AuthHandler] Getted serverID: " + serverID);
|
||||
LogHelper.debug("[AuthHandler] Getted UUID: " + uuid);
|
||||
}
|
||||
return new Entry(uuid, username, accessToken, serverID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Entry fetchEntry(String username) throws IOException {
|
||||
String response = IOHelper.request(new URL(CommonHelper.replace(usernameFetch, "user", IOHelper.urlEncode(username))));
|
||||
String[] parts = response.split(splitSymbol);
|
||||
UUID uuid = UUID.fromString(parts[0]);
|
||||
String accessToken = parts[1];
|
||||
String serverID = parts[2];
|
||||
if (LogHelper.isDebugEnabled()) {
|
||||
LogHelper.debug("[AuthHandler] Getted username: " + username);
|
||||
LogHelper.debug("[AuthHandler] Getted accessToken: " + accessToken);
|
||||
LogHelper.debug("[AuthHandler] Getted serverID: " + serverID);
|
||||
LogHelper.debug("[AuthHandler] Getted UUID: " + uuid);
|
||||
}
|
||||
return new Entry(uuid, username, accessToken, serverID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean updateAuth(UUID uuid, String username, String accessToken) throws IOException {
|
||||
String response = IOHelper.request(new URL(CommonHelper.replace(updateAuth, "user", IOHelper.urlEncode(username), "uuid", IOHelper.urlEncode(uuid.toString()), "token", IOHelper.urlEncode(accessToken))));
|
||||
if (LogHelper.isDebugEnabled()) {
|
||||
LogHelper.debug("[AuthHandler] Set accessToken: " + accessToken);
|
||||
LogHelper.debug("[AuthHandler] Set UUID: " + uuid);
|
||||
LogHelper.debug("[AuthHandler] For this username: " + username);
|
||||
}
|
||||
return goodResponse.equals(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean updateServerID(UUID uuid, String serverID) throws IOException {
|
||||
String response = IOHelper.request(new URL(CommonHelper.replace(updateAuth, "serverid", IOHelper.urlEncode(serverID), "uuid", IOHelper.urlEncode(uuid.toString()))));
|
||||
if (LogHelper.isDebugEnabled()) {
|
||||
LogHelper.debug("[AuthHandler] Set serverID: " + serverID);
|
||||
LogHelper.debug("[AuthHandler] For this UUID: " + uuid);
|
||||
}
|
||||
return goodResponse.equals(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
}
|
|
@ -9,6 +9,21 @@ public String generateSecureToken(AuthResponse.AuthContext context) {
|
|||
return SecurityHelper.randomStringToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateClientSecureToken() {
|
||||
return SecurityHelper.randomStringToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verifyClientSecureToken(String token) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowGetAccessToken(AuthResponse.AuthContext context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkLaunchServerLicense() {
|
||||
// None
|
||||
|
|
|
@ -38,6 +38,10 @@ public static void registerHandlers() {
|
|||
|
||||
public abstract String generateSecureToken(AuthResponse.AuthContext context); //Генерация токена для передачи его в LauncherGuardInterface
|
||||
|
||||
public abstract String generateClientSecureToken();
|
||||
public abstract boolean verifyClientSecureToken(String token);
|
||||
public abstract boolean allowGetAccessToken(AuthResponse.AuthContext context);
|
||||
|
||||
public abstract void checkLaunchServerLicense(); //Выдает SecurityException при ошибке проверки лицензии
|
||||
//public abstract
|
||||
}
|
||||
|
|
|
@ -83,6 +83,12 @@ public void setSecretKey(String key) {
|
|||
body.append("\";");
|
||||
}
|
||||
|
||||
public void setGuardType(String key) {
|
||||
body.append("this.guardType = \"");
|
||||
body.append(key);
|
||||
body.append("\";");
|
||||
}
|
||||
|
||||
public void setEnv(LauncherConfig.LauncherEnvironment env) {
|
||||
int i = 2;
|
||||
switch (env) {
|
||||
|
@ -111,18 +117,6 @@ public void setClientPort(int port) {
|
|||
body.append(";");
|
||||
}
|
||||
|
||||
public void setUsingWrapper(boolean b) {
|
||||
body.append("this.isUsingWrapper = ");
|
||||
body.append(b ? "true" : "false");
|
||||
body.append(";");
|
||||
}
|
||||
|
||||
public void setDownloadJava(boolean b) {
|
||||
body.append("this.isDownloadJava = ");
|
||||
body.append(b ? "true" : "false");
|
||||
body.append(";");
|
||||
}
|
||||
|
||||
public void setWarningMissArchJava(boolean b) {
|
||||
body.append("this.isWarningMissArchJava = ");
|
||||
body.append(b ? "true" : "false");
|
||||
|
|
|
@ -134,9 +134,8 @@ public Path process(Path inputJar) throws IOException {
|
|||
jaConfigurator.setProjectName(server.config.projectName);
|
||||
jaConfigurator.setSecretKey(SecurityHelper.randomStringAESKey());
|
||||
jaConfigurator.setClientPort(32148 + SecurityHelper.newRandom().nextInt(512));
|
||||
jaConfigurator.setUsingWrapper(server.config.isUsingWrapper);
|
||||
jaConfigurator.setGuardType(server.config.launcher.guardType);
|
||||
jaConfigurator.setWarningMissArchJava(server.config.isWarningMissArchJava);
|
||||
jaConfigurator.setDownloadJava(server.config.isDownloadJava);
|
||||
jaConfigurator.setEnv(server.config.env);
|
||||
server.buildHookManager.registerAllClientModuleClass(jaConfigurator);
|
||||
reader.getCp().add(new JarFile(inputJar.toFile()));
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package ru.gravit.launchserver.config;
|
||||
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
import ru.gravit.utils.helper.SecurityHelper;
|
||||
|
||||
public class LaunchServerRuntimeConfig {
|
||||
public String clientToken;
|
||||
public void verify()
|
||||
{
|
||||
if(clientToken == null) LogHelper.error("[RuntimeConfig] clientToken must not be null");
|
||||
}
|
||||
public void reset()
|
||||
{
|
||||
clientToken = SecurityHelper.randomStringToken();
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ public class Client {
|
|||
public ClientProfile profile;
|
||||
public boolean isAuth;
|
||||
public boolean checkSign;
|
||||
public boolean isSecure;
|
||||
public ClientPermissions permissions;
|
||||
public String username;
|
||||
public LogHelper.OutputEnity logOutput;
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
import ru.gravit.launchserver.websocket.json.profile.BatchProfileByUsername;
|
||||
import ru.gravit.launchserver.websocket.json.profile.ProfileByUUIDResponse;
|
||||
import ru.gravit.launchserver.websocket.json.profile.ProfileByUsername;
|
||||
import ru.gravit.launchserver.websocket.json.secure.GetSecureTokenResponse;
|
||||
import ru.gravit.launchserver.websocket.json.secure.VerifySecureTokenResponse;
|
||||
import ru.gravit.launchserver.websocket.json.update.LauncherResponse;
|
||||
import ru.gravit.launchserver.websocket.json.update.UpdateListResponse;
|
||||
import ru.gravit.launchserver.websocket.json.update.UpdateResponse;
|
||||
|
@ -88,6 +90,8 @@ public void registerResponses() {
|
|||
registerResponse("batchProfileByUsername", BatchProfileByUsername.class);
|
||||
registerResponse("profileByUsername", ProfileByUsername.class);
|
||||
registerResponse("profileByUUID", ProfileByUUIDResponse.class);
|
||||
registerResponse("getSecureToken", GetSecureTokenResponse.class);
|
||||
registerResponse("verifySecureToken", VerifySecureTokenResponse.class);
|
||||
}
|
||||
|
||||
public void sendObject(ChannelHandlerContext ctx, Object obj) {
|
||||
|
|
|
@ -105,7 +105,6 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
//if (clientData.profile == null) {
|
||||
// throw new AuthException("You profile not found");
|
||||
//}
|
||||
UUID uuid = pair.handler.auth(aresult);
|
||||
if (authType == ConnectTypes.CLIENT)
|
||||
LaunchServer.server.config.hwidHandler.check(hwid, aresult.username);
|
||||
LaunchServer.server.authHookManager.postHook(context, clientData);
|
||||
|
@ -121,8 +120,12 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
LaunchServer.server.sessionManager.addClient(clientData);
|
||||
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());
|
||||
if(LaunchServer.server.config.protectHandler.allowGetAccessToken(context))
|
||||
{
|
||||
UUID uuid = pair.handler.auth(aresult);
|
||||
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()));
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package ru.gravit.launchserver.websocket.json.secure;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import ru.gravit.launcher.events.request.GetSecureTokenRequestEvent;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.launchserver.websocket.WebSocketService;
|
||||
import ru.gravit.launchserver.websocket.json.JsonResponseInterface;
|
||||
|
||||
public class GetSecureTokenResponse implements JsonResponseInterface {
|
||||
@Override
|
||||
public String getType() {
|
||||
return "getSecureToken";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
String secureToken = LaunchServer.server.config.protectHandler.generateClientSecureToken();
|
||||
service.sendObject(ctx, new GetSecureTokenRequestEvent(secureToken));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package ru.gravit.launchserver.websocket.json.secure;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import ru.gravit.launcher.events.request.VerifySecureTokenRequestEvent;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.launchserver.websocket.WebSocketService;
|
||||
import ru.gravit.launchserver.websocket.json.JsonResponseInterface;
|
||||
|
||||
public class VerifySecureTokenResponse implements JsonResponseInterface {
|
||||
public String secureToken;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "verifySecureToken";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
boolean success = LaunchServer.server.config.protectHandler.verifyClientSecureToken(secureToken);
|
||||
if(success) client.isSecure = true;
|
||||
service.sendObject(ctx, new VerifySecureTokenRequestEvent(success));
|
||||
}
|
||||
}
|
|
@ -139,8 +139,6 @@ public void write(HOutput output) throws IOException {
|
|||
private static final String SOCKET_HOST = "127.0.0.1";
|
||||
private static final int SOCKET_PORT = Launcher.getConfig().clientPort;
|
||||
private static final String MAGICAL_INTEL_OPTION = "-XX:HeapDumpPath=ThisTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump";
|
||||
private static final boolean isUsingWrapper = Launcher.getConfig().isUsingWrapper;
|
||||
private static final boolean isDownloadJava = Launcher.getConfig().isDownloadJava;
|
||||
|
||||
private static Path JavaBinPath;
|
||||
@SuppressWarnings("unused")
|
||||
|
@ -165,10 +163,6 @@ public static class ClientUserProperties {
|
|||
String[] cloakDigest;
|
||||
}
|
||||
|
||||
public static boolean isDownloadJava() {
|
||||
return isDownloadJava;
|
||||
}
|
||||
|
||||
public static Path getJavaBinPath() {
|
||||
return JavaBinPath;
|
||||
}
|
||||
|
@ -265,11 +259,6 @@ public static boolean isLaunched() {
|
|||
return Launcher.LAUNCHED.get();
|
||||
}
|
||||
|
||||
|
||||
public static boolean isUsingWrapper() {
|
||||
return JVMHelper.OS_TYPE == OS.MUSTDIE && isUsingWrapper;
|
||||
}
|
||||
|
||||
private static void launch(ClientProfile profile, Params params) throws Throwable {
|
||||
// Add client args
|
||||
Collection<String> args = new LinkedList<>();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package ru.gravit.launcher.guard;
|
||||
|
||||
import ru.gravit.launcher.Launcher;
|
||||
import ru.gravit.launcher.LauncherConfig;
|
||||
import ru.gravit.launcher.client.ClientLauncher;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
@ -8,11 +10,22 @@ public class LauncherGuardManager {
|
|||
public static LauncherGuardInterface guard;
|
||||
|
||||
public static void initGuard(boolean clientInstance) {
|
||||
if (ClientLauncher.isUsingWrapper()) {
|
||||
guard = new LauncherWrapperGuard();
|
||||
} else if (ClientLauncher.isDownloadJava()) {
|
||||
guard = new LauncherJavaGuard();
|
||||
} else guard = new LauncherNoGuard();
|
||||
LauncherConfig config = Launcher.getConfig();
|
||||
switch (config.guardType)
|
||||
{
|
||||
case "wrapper":
|
||||
{
|
||||
guard = new LauncherWrapperGuard();
|
||||
}
|
||||
case "java":
|
||||
{
|
||||
guard = new LauncherJavaGuard();
|
||||
}
|
||||
default:
|
||||
{
|
||||
guard = new LauncherNoGuard();
|
||||
}
|
||||
}
|
||||
guard.init(clientInstance);
|
||||
}
|
||||
|
||||
|
|
|
@ -111,6 +111,8 @@ public void registerResults() {
|
|||
registerResult("error", ErrorRequestEvent.class);
|
||||
registerResult("update", UpdateRequestEvent.class);
|
||||
registerResult("restoreSession", RestoreSessionRequestEvent.class);
|
||||
registerResult("getSecureToken", GetSecureTokenRequestEvent.class);
|
||||
registerResult("verifySecureToken", VerifySecureTokenRequestEvent.class);
|
||||
}
|
||||
|
||||
public void registerHandler(EventHandler eventHandler) {
|
||||
|
|
80
compat/auth/AuthHandler.php
Normal file
80
compat/auth/AuthHandler.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
//Секретный ключ. Внимание! должен совпадать с ключем в лаунчсервере. Пожалуйста, смените его, иначе это ставит под угрозу проект.
|
||||
$secretkey = '12345678';
|
||||
//Настройки связи с базой данных
|
||||
$link = mysqli_connect(
|
||||
'localhost', // Хост
|
||||
'root', // Пользователь
|
||||
'', // Пароль
|
||||
'test' // База данных
|
||||
);
|
||||
|
||||
// Настройка таблицы
|
||||
$settings = [
|
||||
'table' => "dle_users", // Название таблицы
|
||||
'usernameColumn' => "name", // Столбец с именами пользователей
|
||||
'uuidColumn' => "uuid", // Столбец с uuid
|
||||
'accessTokenColumn' => "accessToken", // Столбец с accessToken
|
||||
'ServerIDColumn' => "serverID" // Столбец с serverID
|
||||
];
|
||||
|
||||
// Не трогать
|
||||
// Можно повредить скрипт
|
||||
$AuthHandler = [
|
||||
'type' => filter_input(INPUT_GET, 'type', FILTER_SANITIZE_STRING),
|
||||
'username' => filter_input(INPUT_GET, 'username', FILTER_SANITIZE_STRING),
|
||||
'uuid' => filter_input(INPUT_GET, 'uuid', FILTER_SANITIZE_STRING),
|
||||
'accessToken' => filter_input(INPUT_GET, 'accessToken', FILTER_SANITIZE_STRING),
|
||||
'ServerID' => filter_input(INPUT_GET, 'ServerID', FILTER_SANITIZE_STRING),
|
||||
'secretKey' => filter_input(INPUT_GET, 'secretKey', FILTER_SANITIZE_STRING)
|
||||
];
|
||||
|
||||
if (!isset($AuthHandler['secretKey'])) {
|
||||
die('Не указан ключ!');
|
||||
}
|
||||
|
||||
if ($secretkey != $AuthHandler['secretKey']) {
|
||||
die('Неверный ключ!');
|
||||
}
|
||||
|
||||
if(!$link) {
|
||||
die('Ошибка подключения к базе данных');
|
||||
}
|
||||
|
||||
if(isset($AuthHandler['type'])) {
|
||||
if($AuthHandler['type'] == "FetchByUUID") {
|
||||
if(isset($AuthHandler['uuid'])) {
|
||||
$result = mysqli_query($link, 'SELECT '.$settings['usernameColumn'].','.$settings['accessTokenColumn'].','.$settings['serverID'].' FROM '.$settings['table'].' WHERE '.$settings['uuidColumn'].'="'.$AuthHandler['uuid'].'" LIMIT 1') or die($link->error);
|
||||
$row = $result->fetch_assoc();
|
||||
mysqli_free_result($result);
|
||||
mysqli_close($link);
|
||||
die($row[$settings['usernameColumn']] + ':' + $row[$settings['accessTokenColumn']] + ':' + $row[$settings['serverID']]);
|
||||
}
|
||||
if($AuthHandler['type'] == "FetchByUsername") {
|
||||
if(isset($AuthHandler['uuid'])) {
|
||||
$result = mysqli_query($link, 'SELECT '.$settings['uuidColumn'].','.$settings['accessTokenColumn'].','.$settings['serverID'].' FROM '.$settings['table'].' WHERE '.$settings['usernameColumn'].'="'.$AuthHandler['username'].'" LIMIT 1') or die($link->error);
|
||||
$row = $result->fetch_assoc();
|
||||
mysqli_free_result($result);
|
||||
mysqli_close($link);
|
||||
die($row[$settings['uuidColumn']] + ':' + $row[$settings['accessTokenColumn']] + ':' + $row[$settings['serverID']]);
|
||||
}
|
||||
|
||||
// Обновление строк
|
||||
|
||||
if($AuthHandler['type'] == "SetAccessTokenAndUUID") {
|
||||
$result = mysqli_query($link, 'UPDATE '.$settings['table'].' SET '.$settings['accessTokenColumn'].'="'.$AuthHandler['accessToken'].'" WHERE '.$settings['usernameColumn'].'="'.$AuthHandler['username'].'"') or die($link->error);
|
||||
$result1 = mysqli_query($link, 'UPDATE '.$settings['table'].' SET '.$settings['uuidColumn'].'="'.$AuthHandler['uuid'].'" WHERE '.$settings['usernameColumn'].'="'.$AuthHandler['username'].'"') or die($link->error);
|
||||
mysqli_close($link);
|
||||
die('OK');
|
||||
}
|
||||
if($AuthHandler['type'] == "SetServerID") {
|
||||
$result = mysqli_query($link, 'UPDATE '.$settings['table'].' SET '.$settings['ServerIDColumn'].'="'.$AuthHandler['serverID'].'" WHERE '.$settings['uuidColumn'].'="'.$AuthHandler['uuid'].'"') or die($link->error);
|
||||
mysqli_close($link);
|
||||
die('OK');
|
||||
}
|
||||
die('FAIL!');
|
||||
} else {
|
||||
die('Type not set!');
|
||||
}
|
||||
?>
|
|
@ -6,8 +6,7 @@ public class AutogenConfig {
|
|||
public int clientPort;
|
||||
@SuppressWarnings("unused")
|
||||
private boolean isInitModules;
|
||||
public boolean isUsingWrapper;
|
||||
public boolean isDownloadJava; //Выставление этого флага требует модификации runtime части
|
||||
public String guardType;
|
||||
public String secretKeyClient;
|
||||
public String guardLicenseName;
|
||||
public String guardLicenseKey;
|
||||
|
|
|
@ -30,15 +30,13 @@ public static AutogenConfig getAutogenConfig() {
|
|||
|
||||
@LauncherAPI
|
||||
public final Map<String, byte[]> runtime;
|
||||
|
||||
public final boolean isUsingWrapper;
|
||||
public final boolean isDownloadJava;
|
||||
public final boolean isWarningMissArchJava;
|
||||
public boolean isNettyEnabled;
|
||||
|
||||
public final String guardLicenseName;
|
||||
public final String guardLicenseKey;
|
||||
public final String guardLicenseEncryptKey;
|
||||
public final String guardType;
|
||||
|
||||
@LauncherAPI
|
||||
public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException {
|
||||
|
@ -46,11 +44,11 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException
|
|||
projectname = config.projectname;
|
||||
clientPort = config.clientPort;
|
||||
secretKeyClient = config.secretKeyClient;
|
||||
isDownloadJava = config.isDownloadJava;
|
||||
isUsingWrapper = config.isUsingWrapper;
|
||||
|
||||
isWarningMissArchJava = config.isWarningMissArchJava;
|
||||
guardLicenseEncryptKey = config.guardLicenseEncryptKey;
|
||||
guardLicenseKey = config.guardLicenseKey;
|
||||
guardType = config.guardType;
|
||||
guardLicenseName = config.guardLicenseName;
|
||||
address = config.address;
|
||||
LauncherEnvironment env;
|
||||
|
@ -82,8 +80,7 @@ public LauncherConfig(String address, RSAPublicKey publicKey, Map<String, byte[]
|
|||
this.guardLicenseName = "FREE";
|
||||
this.guardLicenseKey = "AAAA-BBBB-CCCC-DDDD";
|
||||
this.guardLicenseEncryptKey = "12345";
|
||||
isUsingWrapper = true;
|
||||
isDownloadJava = false;
|
||||
guardType = "no";
|
||||
isWarningMissArchJava = true;
|
||||
isNettyEnabled = false;
|
||||
}
|
||||
|
@ -98,8 +95,7 @@ public LauncherConfig(String address, RSAPublicKey publicKey, Map<String, byte[]
|
|||
this.guardLicenseKey = "AAAA-BBBB-CCCC-DDDD";
|
||||
this.guardLicenseEncryptKey = "12345";
|
||||
this.clientPort = 32148;
|
||||
isUsingWrapper = true;
|
||||
isDownloadJava = false;
|
||||
guardType = "no";
|
||||
isWarningMissArchJava = true;
|
||||
isNettyEnabled = false;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package ru.gravit.launcher.events.request;
|
||||
|
||||
import ru.gravit.launcher.LauncherNetworkAPI;
|
||||
import ru.gravit.launcher.request.ResultInterface;
|
||||
|
||||
public class GetSecureTokenRequestEvent implements ResultInterface {
|
||||
@LauncherNetworkAPI
|
||||
public String secureToken;
|
||||
@Override
|
||||
public String getType() {
|
||||
return "GetSecureToken";
|
||||
}
|
||||
|
||||
public GetSecureTokenRequestEvent(String secureToken) {
|
||||
this.secureToken = secureToken;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package ru.gravit.launcher.events.request;
|
||||
|
||||
import ru.gravit.launcher.LauncherAPI;
|
||||
import ru.gravit.launcher.request.ResultInterface;
|
||||
|
||||
public class VerifySecureTokenRequestEvent implements ResultInterface {
|
||||
@LauncherAPI
|
||||
public boolean success;
|
||||
@Override
|
||||
public String getType() {
|
||||
return "verifySecureToken";
|
||||
}
|
||||
|
||||
public VerifySecureTokenRequestEvent(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue