diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 7d300b5a..c12dbc13 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -53,7 +53,22 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.zip.CRC32; -public final class LaunchServer implements Runnable { +public final class LaunchServer implements Runnable, AutoCloseable, Reloadable { + @Override + public void reload() throws Exception { + config.close(); + LogHelper.info("Reading LaunchServer config file"); + try (BufferedReader reader = IOHelper.newReader(configFile)) { + config = Launcher.gson.fromJson(reader, Config.class); + } + config.verify(); + Launcher.applyLauncherEnv(config.env); + for (AuthProvider provider : config.authProvider) { + provider.init(); + } + config.authHandler.init(); + } + public static final class Config { public int port; @@ -170,6 +185,34 @@ public void verify() { throw new NullPointerException("Netty must not be null"); } } + public void close() + { + try { + authHandler.close(); + } catch (IOException e) { + LogHelper.error(e); + } + try { + for (AuthProvider p : authProvider) p.close(); + } catch (IOException e) { + LogHelper.error(e); + } + try { + textureProvider.close(); + } catch (IOException e) { + LogHelper.error(e); + } + try { + hwidHandler.close(); + } catch (Exception e) { + LogHelper.error(e); + } + try { + permissionsHandler.close(); + } catch (Exception e) { + LogHelper.error(e); + } + } } public static class ExeConf { @@ -233,7 +276,7 @@ public static void main(String... args) throws Throwable { LogHelper.printLicense("LaunchServer"); // Start LaunchServer - Instant start = Instant.now(); + long startTime = System.currentTimeMillis(); try { LaunchServer launchserver = new LaunchServer(IOHelper.WORKING_DIR, args); if(args.length == 0) launchserver.run(); @@ -244,8 +287,8 @@ public static void main(String... args) throws Throwable { LogHelper.error(exc); return; } - Instant end = Instant.now(); - LogHelper.debug("LaunchServer started in %dms", Duration.between(start, end).toMillis()); + long endTime = System.currentTimeMillis(); + LogHelper.debug("LaunchServer started in %dms", endTime - startTime); } // Constant paths @@ -269,7 +312,7 @@ public static void main(String... args) throws Throwable { public final Path profilesDir; // Server config - public final Config config; + public Config config; public final RSAPublicKey publicKey; @@ -417,6 +460,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE authHookManager = new AuthHookManager(); GarbageManager.registerNeedGC(sessionManager); GarbageManager.registerNeedGC(limiter); + reloadManager.registerReloadable("launchServer", this); if (config.permissionsHandler instanceof Reloadable) reloadManager.registerReloadable("permissionsHandler", (Reloadable) config.permissionsHandler); if (config.authHandler instanceof Reloadable) @@ -521,22 +565,7 @@ public void close() { serverSocketHandler.close(); // Close handlers & providers - try { - config.authHandler.close(); - } catch (IOException e) { - LogHelper.error(e); - } - try { - for (AuthProvider p : config.authProvider) p.close(); - } catch (IOException e) { - LogHelper.error(e); - } - try { - config.textureProvider.close(); - } catch (IOException e) { - LogHelper.error(e); - } - config.hwidHandler.close(); + config.close(); modulesManager.close(); // Print last message before death :( LogHelper.info("LaunchServer stopped"); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java index fccb3b40..19c348c1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java @@ -31,6 +31,7 @@ public final class MySQLSourceConfig implements AutoCloseable { private String password; private String database; private String timeZone; + private boolean enableHikari; // Cache private transient DataSource source; @@ -79,20 +80,24 @@ public synchronized Connection getConnection() throws SQLException { hikari = false; // Try using HikariCP source = mysqlSource; - try { - Class.forName("com.zaxxer.hikari.HikariDataSource"); - hikari = true; // Used for shutdown. Not instanceof because of possible classpath error - HikariConfig cfg = new HikariConfig(); - cfg.setDataSource(mysqlSource); - cfg.setPoolName(poolName); - cfg.setMaximumPoolSize(MAX_POOL_SIZE); - // Set HikariCP pool - // Replace source with hds - source = new HikariDataSource(cfg); - LogHelper.warning("HikariCP pooling enabled for '%s'", poolName); - } catch (ClassNotFoundException ignored) { - LogHelper.debug("HikariCP isn't in classpath for '%s'", poolName); + if(enableHikari) + { + try { + Class.forName("com.zaxxer.hikari.HikariDataSource"); + hikari = true; // Used for shutdown. Not instanceof because of possible classpath error + HikariConfig cfg = new HikariConfig(); + cfg.setDataSource(mysqlSource); + cfg.setPoolName(poolName); + cfg.setMaximumPoolSize(MAX_POOL_SIZE); + // Set HikariCP pool + // Replace source with hds + source = new HikariDataSource(cfg); + LogHelper.warning("HikariCP pooling enabled for '%s'", poolName); + } catch (ClassNotFoundException ignored) { + LogHelper.debug("HikariCP isn't in classpath for '%s'", poolName); + } } + } return source.getConnection(); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java index 5438e20b..2e816879 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java @@ -38,7 +38,7 @@ public void check(HWID hwid, String username) throws HWIDException { public abstract void check0(HWID hwid, String username) throws HWIDException; @Override - public abstract void close(); + public abstract void close() throws Exception; public abstract List getHwid(String username) throws HWIDException; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java index 11ae3d6f..8eb46a41 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java @@ -151,6 +151,7 @@ public void onCheckInfo(OshiHWID hwid, String username, Connection c) throws HWI db_hwid.processorID = set.getString(hwidFieldProcessorID); db_hwid.HWDiskSerial = set.getString(hwidFieldHWDiskSerial); db_hwid.totalMemory = Long.valueOf(set.getString(hwidFieldTotalMemory)); + db_hwid.macAddr = ""; LogHelper.dev("Compare HWID: %s vs %s", hwid.getSerializeString(), db_hwid.getSerializeString()); int compare_point = hwid.compare(db_hwid); if(compare_point < compare) continue; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java index a128e759..4ffe4a74 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java @@ -13,4 +13,9 @@ public ClientPermissions getPermissions(String username) { permissions.canAdmin = isAdmin; return permissions; } + + @Override + public void close() { + + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java index 7b81d70d..b434bb5e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java @@ -7,4 +7,9 @@ public class DefaultPermissionsHandler extends PermissionsHandler { public ClientPermissions getPermissions(String username) { return ClientPermissions.DEFAULT; } + + @Override + public void close() throws Exception { + + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java index dce8df30..c46c1857 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java @@ -33,6 +33,11 @@ public void reload() { } } + @Override + public void close() throws Exception { + + } + public static class Enity { public String username; public ClientPermissions permissions; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java index cb6aa234..d7d98402 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java @@ -34,6 +34,11 @@ public void reload() { } } + @Override + public void close() throws Exception { + + } + public static class Enity { public String username; public ClientPermissions permissions; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java index d3d379e9..d7058b71 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java @@ -7,7 +7,7 @@ import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; -public abstract class PermissionsHandler { +public abstract class PermissionsHandler implements AutoCloseable { private static final Map> PERMISSIONS_HANDLERS = new ConcurrentHashMap<>(4); private static boolean registredHandl = false; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/ProguardConf.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/ProguardConf.java index add2373b..6853ee48 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/ProguardConf.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/ProguardConf.java @@ -16,9 +16,12 @@ public class ProguardConf { private static final String charsFirst = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"; private static final String chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ"; - private static String generateString(SecureRandom rand, int il) { - StringBuilder sb = new StringBuilder(il); - sb.append(charsFirst.charAt(rand.nextInt(charsFirst.length()))); + private static String generateString(SecureRandom rand, String lowString, String upString, int il) { + StringBuilder sb = new StringBuilder(il + lowString.length()); + for(int i = 0;i { - Response newResponse(LaunchServer server, long id, HInput input, HOutput output, String ip); + Response newResponse(LaunchServer server, long id, HInput input, HOutput output, String ip, Client clientData); } private static final Map> RESPONSES = new ConcurrentHashMap<>(8); - public static Response getResponse(int type, LaunchServer server, long session, HInput input, HOutput output, String ip) { - return RESPONSES.get(type).newResponse(server, session, input, output, ip); + public static Response getResponse(int type, LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + return RESPONSES.get(type).newResponse(server, session, input, output, ip, clientData); } public static void registerResponse(int type, Factory factory) { @@ -72,15 +73,18 @@ public static void requestError(String message) throws RequestException { protected final String ip; + protected final Client clientData; + protected final long session; - protected Response(LaunchServer server, long session, HInput input, HOutput output, String ip) { + protected Response(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { this.server = server; this.input = input; this.output = output; this.ip = ip; this.session = session; + this.clientData = clientData; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/admin/ExecCommandResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/admin/ExecCommandResponse.java index be4114e5..968696db 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/admin/ExecCommandResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/admin/ExecCommandResponse.java @@ -11,8 +11,8 @@ import java.io.IOException; public class ExecCommandResponse extends Response { - public ExecCommandResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { - super(server, session, input, output, ip); + public ExecCommandResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + super(server, session, input, output, ip, clientData); } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java index 6b56666f..20a6ff60 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java @@ -31,8 +31,8 @@ private static String echo(int length) { return new String(chars); } - public AuthResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { - super(server, session, input, output, ip); + public AuthResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + super(server, session, input, output, ip, clientData); } public static class AuthContext { @@ -81,7 +81,6 @@ public void reply() throws Exception { debug("Login: '%s', Password: '%s'", login, echo(password.length())); AuthProviderResult result; AuthProvider provider = server.config.authProvider[auth_id]; - Client clientData = server.sessionManager.getClient(session); clientData.type = Client.Type.USER; AuthContext context = new AuthContext(session, login, password.length(), customText, client, hwid_str, false); try { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java index 08370200..66ce8cce 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java @@ -28,8 +28,8 @@ private static String echo(int length) { return new String(chars); } - public AuthServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { - super(server, session, input, output, ip); + public AuthServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + super(server, session, input, output, ip, clientData); } @Override @@ -52,7 +52,6 @@ public void reply() throws Exception { debug("ServerLogin: '%s', Password: '%s'", login, echo(password.length())); AuthProviderResult result; AuthProvider provider = server.config.authProvider[auth_id]; - Client clientData = server.sessionManager.getClient(session); try { if (server.limiter.isLimit(ip)) { AuthProvider.authError(server.config.authRejectString); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/ChangeServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/ChangeServerResponse.java index 6994a7ed..6dd2f01e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/ChangeServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/ChangeServerResponse.java @@ -4,14 +4,15 @@ import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.response.Response; +import ru.gravit.launchserver.socket.Client; public class ChangeServerResponse extends Response { public static boolean needChange = false; public static String address; public static int port; - public ChangeServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { - super(server, session, input, output, ip); + public ChangeServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + super(server, session, input, output, ip, clientData); } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java index b2974674..002e381d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java @@ -16,8 +16,8 @@ public final class CheckServerResponse extends Response { - public CheckServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { - super(server, session, input, output, ip); + public CheckServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + super(server, session, input, output, ip, clientData); } @Override @@ -26,7 +26,6 @@ public void reply() throws IOException { String serverID = VerifyHelper.verifyServerID(input.readASCII(41)); // With minus sign String client = input.readString(SerializeLimits.MAX_CLIENT); debug("Username: %s, Server ID: %s", username, serverID); - Client clientData = server.sessionManager.getClient(session); if (!clientData.isAuth || clientData.type != Client.Type.SERVER) { requestError("Access denied"); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java index 821848a6..27e16ebf 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java @@ -15,8 +15,8 @@ public final class JoinServerResponse extends Response { - public JoinServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { - super(server, session, input, output, ip); + public JoinServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + super(server, session, input, output, ip, clientData); } @Override @@ -24,7 +24,6 @@ public void reply() throws IOException { String username = VerifyHelper.verifyUsername(input.readString(SerializeLimits.MAX_LOGIN)); String accessToken = SecurityHelper.verifyToken(input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH)); String serverID = VerifyHelper.verifyServerID(input.readASCII(SerializeLimits.MAX_SERVERID)); // With minus sign - Client clientData = server.sessionManager.getClient(session); if (!clientData.isAuth || clientData.type != Client.Type.USER) { requestError("Access denied"); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java index 33b30d83..271aa816 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java @@ -11,14 +11,13 @@ import java.util.Collection; public class SetProfileResponse extends Response { - public SetProfileResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { - super(server, session, input, output, ip); + public SetProfileResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + super(server, session, input, output, ip, clientData); } @Override public void reply() throws Exception { String client = input.readString(SerializeLimits.MAX_CLIENT); - Client clientData = server.sessionManager.getClient(session); if (!clientData.isAuth) requestError("You not auth"); Collection profiles = server.getProfiles(); for (ClientProfile p : profiles) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java index 8d9f5181..ca444257 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java @@ -5,6 +5,7 @@ import ru.gravit.launcher.serialize.SerializeLimits; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.response.Response; +import ru.gravit.launchserver.socket.Client; import ru.gravit.utils.helper.VerifyHelper; import java.io.IOException; @@ -12,8 +13,8 @@ public final class BatchProfileByUsernameResponse extends Response { - public BatchProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { - super(server, session, input, output, ip); + public BatchProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + super(server, session, input, output, ip, clientData); } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java index 0aeeca44..2d636be5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java @@ -7,6 +7,7 @@ import ru.gravit.launcher.serialize.SerializeLimits; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.response.Response; +import ru.gravit.launchserver.socket.Client; import ru.gravit.utils.helper.LogHelper; import java.io.IOException; @@ -37,8 +38,8 @@ public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String us return new PlayerProfile(uuid, username, skin, cloak); } - public ProfileByUUIDResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { - super(server, session, input, output, ip); + public ProfileByUUIDResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + super(server, session, input, output, ip, clientData); } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java index 859ada26..043418b5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java @@ -5,6 +5,7 @@ import ru.gravit.launcher.serialize.SerializeLimits; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.response.Response; +import ru.gravit.launchserver.socket.Client; import ru.gravit.utils.helper.VerifyHelper; import java.io.IOException; @@ -24,8 +25,8 @@ public static void writeProfile(LaunchServer server, HOutput output, String user ProfileByUUIDResponse.getProfile(server, uuid, username, client).write(output); } - public ProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { - super(server, session, input, output, ip); + public ProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + super(server, session, input, output, ip, clientData); } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LauncherResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LauncherResponse.java index 411be0d3..242e657b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LauncherResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LauncherResponse.java @@ -13,8 +13,8 @@ public final class LauncherResponse extends Response { - public LauncherResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { - super(server, session, input, output, ip); + public LauncherResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + super(server, session, input, output, ip, clientData); } @Override @@ -25,17 +25,16 @@ public void reply() throws IOException { requestError("Missing launcher binary"); return; } - Client client = server.sessionManager.getOrNewClient(session); byte[] digest = input.readByteArray(SerializeLimits.MAX_DIGEST); if (!Arrays.equals(bytes.getDigest(), digest)) { writeNoError(output); output.writeBoolean(true); output.writeByteArray(bytes.getBytes(), 0); - client.checkSign = false; + clientData.checkSign = false; return; } writeNoError(output); output.writeBoolean(false); - client.checkSign = true; + clientData.checkSign = true; } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LegacyLauncherResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LegacyLauncherResponse.java index 92aba4d6..2994bdd7 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LegacyLauncherResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LegacyLauncherResponse.java @@ -5,14 +5,15 @@ import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.binary.LauncherBinary; import ru.gravit.launchserver.response.Response; +import ru.gravit.launchserver.socket.Client; import ru.gravit.utils.helper.SecurityHelper; import java.io.IOException; public final class LegacyLauncherResponse extends Response { - public LegacyLauncherResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { - super(server, session, input, output, ip); + public LegacyLauncherResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + super(server, session, input, output, ip, clientData); } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/ProfilesResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/ProfilesResponse.java index 47dd872e..26c66668 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/ProfilesResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/ProfilesResponse.java @@ -14,16 +14,15 @@ public final class ProfilesResponse extends Response { - public ProfilesResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { - super(server, session, input, output, ip); + public ProfilesResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + super(server, session, input, output, ip, clientData); } @Override public void reply() throws IOException { // Resolve launcher binary - Client client = server.sessionManager.getClient(session); input.readBoolean(); - if (client.type == Client.Type.USER && !client.checkSign) { + if (clientData.type == Client.Type.USER && !clientData.checkSign) { LogHelper.warning("User session: %d ip %s try get profiles", session, ip); requestError("Access denied"); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateListResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateListResponse.java index ffb1dddf..ec8c4d1c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateListResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateListResponse.java @@ -6,14 +6,15 @@ import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.response.Response; +import ru.gravit.launchserver.socket.Client; import java.util.Map.Entry; import java.util.Set; public final class UpdateListResponse extends Response { - public UpdateListResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { - super(server, session, input, output, ip); + public UpdateListResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + super(server, session, input, output, ip, clientData); } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateResponse.java index 8e4c547b..c5234956 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateResponse.java @@ -24,8 +24,8 @@ public final class UpdateResponse extends Response { - public UpdateResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { - super(server, session, input, output, ip); + public UpdateResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { + super(server, session, input, output, ip, clientData); } @Override @@ -37,7 +37,6 @@ public void reply() throws IOException { requestError(String.format("Unknown update dir: %s", updateDirName)); return; } - Client clientData = server.sessionManager.getClient(session); if (!clientData.isAuth || clientData.type != Client.Type.USER || clientData.profile == null) { requestError("Access denied"); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java index 6d6922a3..7cb10056 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java @@ -82,12 +82,12 @@ private Handshake readHandshake(HInput input, HOutput output) throws IOException return new Handshake(type, session); } - private void respond(Integer type, HInput input, HOutput output, long session, String ip) throws Exception { + private void respond(Integer type, HInput input, HOutput output, long session, String ip, Client clientData) throws Exception { if (server.serverSocketHandler.logConnections) LogHelper.info("Connection #%d from %s", session, ip); // Choose response based on type - Response response = Response.getResponse(type, server, session, input, output, ip); + Response response = Response.getResponse(type, server, session, input, output, ip, clientData); // Reply response.reply(); @@ -115,11 +115,13 @@ public void run() { context.ip = IOHelper.getIP(socket.getRemoteSocketAddress()); context.session = handshake.session; context.type = handshake.type; + Client clientData = server.sessionManager.getOrNewClient(context.session); + context.client = clientData; // Start response if (socketHookManager.preHook(context)) { try { - respond(handshake.type, input, output, handshake.session, context.ip); + respond(handshake.type, input, output, handshake.session, context.ip, clientData); socketHookManager.postHook(context); } catch (RequestException e) { if (server.socketHookManager.errorHook(context, e)) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/SocketContext.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/SocketContext.java index f4012818..a3b142fa 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/SocketContext.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/SocketContext.java @@ -4,9 +4,10 @@ import ru.gravit.launcher.serialize.HOutput; public class SocketContext { - HInput input; - HOutput output; - long session; - String ip; - Integer type; + public HInput input; + public HOutput output; + public long session; + public String ip; + public Integer type; + public Client client; } diff --git a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java index 3c2d9df1..eb0f6aa9 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java @@ -1,6 +1,7 @@ package ru.gravit.launcher; import ru.gravit.launcher.client.ClientLauncher; +import ru.gravit.launcher.client.DirBridge; import ru.gravit.utils.helper.EnvHelper; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.JVMHelper; @@ -19,18 +20,22 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep LogHelper.printLicense("Launcher"); LogHelper.info("Restart Launcher with JavaAgent..."); LogHelper.info("If need debug output use -Dlauncher.debug=true"); + LogHelper.info("If need stacktrace output use -Dlauncher.stacktrace=true"); JVMHelper.checkStackTrace(ClientLauncherWrapper.class); JVMHelper.verifySystemProperties(Launcher.class, true); EnvHelper.checkDangerousParams(); LogHelper.debug("Restart Launcher"); ProcessBuilder processBuilder = new ProcessBuilder(); - processBuilder.inheritIO(); + if (LogHelper.isDebugEnabled()) processBuilder.inheritIO(); Path javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); List args = new LinkedList<>(); args.add(javaBin.toString()); String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled()))); + JVMHelper.addSystemPropertyToArgs(args, DirBridge.CUSTOMDIR_PROPERTY); + JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_CUSTOMDIR_PROPERTY); + JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_OPTDIR_PROPERTY); Collections.addAll(args, "-javaagent:".concat(pathLauncher)); Collections.addAll(args, "-cp"); Collections.addAll(args, pathLauncher); diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 37a794fa..acb552ce 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -30,15 +30,15 @@ public static void main(String... args) throws Throwable { // Start Launcher initGson(); LogHelper.setStacktraceEnabled(true); - Instant start = Instant.now(); + long startTime = System.currentTimeMillis(); try { new LauncherEngine().start(args); } catch (Exception e) { LogHelper.error(e); return; } - Instant end = Instant.now(); - LogHelper.debug("Launcher started in %dms", Duration.between(start, end).toMillis()); + long endTime = System.currentTimeMillis(); + LogHelper.debug("Launcher started in %dms", endTime - startTime); } public static void initGson() { @@ -58,7 +58,6 @@ private LauncherEngine() { @LauncherAPI public void start(String... args) throws Throwable { - LogHelper.debug("%d", LauncherSettings.settingsMagic); Launcher.modulesManager = new ClientModuleManager(this); LauncherConfig.getAutogenConfig().initModules(); Launcher.modulesManager.preInitModules(); diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index 840f51ff..7c1dfcbe 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -347,8 +347,9 @@ public static Process launch( context.args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); context.args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled()))); context.args.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, Boolean.toString(LogHelper.isDevEnabled()))); - if (LauncherConfig.ADDRESS_OVERRIDE != null) - context.args.add(JVMHelper.jvmProperty(LauncherConfig.ADDRESS_OVERRIDE_PROPERTY, LauncherConfig.ADDRESS_OVERRIDE)); + JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.CUSTOMDIR_PROPERTY); + JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_CUSTOMDIR_PROPERTY); + JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_OPTDIR_PROPERTY); if (JVMHelper.OS_TYPE == OS.MUSTDIE) { if (JVMHelper.OS_VERSION.startsWith("10.")) { LogHelper.debug("MustDie 10 fix is applied"); @@ -474,46 +475,6 @@ public static void main(String... args) throws Throwable { } } - @LauncherAPI - public void launchLocal(HashedDir assetHDir, HashedDir clientHDir, - ClientProfile profile, Params params) throws Throwable { - RSAPublicKey publicKey = Launcher.getConfig().publicKey; - LogHelper.debug("Verifying ClientLauncher sign and classpath"); - SecurityHelper.verifySign(LegacyLauncherRequest.BINARY_PATH, params.launcherDigest, publicKey); - LinkedList classPath = resolveClassPathList(params.clientDir, profile.getClassPath()); - for (Path classpathURL : classPath) { - LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); - } - URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath()); - classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); - Thread.currentThread().setContextClassLoader(classLoader); - classLoader.nativePath = params.clientDir.resolve(NATIVES_DIR).toString(); - PublicURLClassLoader.systemclassloader = classLoader; - // Start client with WatchService monitoring - boolean digest = !profile.isUpdateFastCheck(); - LogHelper.debug("Starting JVM and client WatchService"); - FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher(); - FileNameMatcher clientMatcher = profile.getClientUpdateMatcher(); - try (DirWatcher assetWatcher = new DirWatcher(params.assetDir, assetHDir, assetMatcher, digest); - DirWatcher clientWatcher = new DirWatcher(params.clientDir, clientHDir, clientMatcher, digest)) { - // Verify current state of all dirs - //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); - HashedDir hdir = clientHDir; - //for (OptionalFile s : Launcher.profile.getOptional()) { - // if (params.updateOptional.contains(s)) s.mark = true; - // else hdir.removeR(s.file); - //} - Launcher.profile.pushOptionalFile(hdir,false); - verifyHDir(params.assetDir, assetHDir, assetMatcher, digest); - verifyHDir(params.clientDir, hdir, clientMatcher, digest); - Launcher.modulesManager.postInitModules(); - // Start WatchService, and only then client - CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start(); - CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start(); - launch(profile, params); - } - } - private static URL[] resolveClassPath(Path clientDir, String... classPath) throws IOException { Collection result = new LinkedList<>(); for (String classPathEntry : classPath) { diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java index c24b966a..830249a0 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java @@ -10,6 +10,11 @@ import java.nio.file.Paths; public class DirBridge { + + public static final String USE_CUSTOMDIR_PROPERTY = "launcher.usecustomdir"; + public static final String CUSTOMDIR_PROPERTY = "launcher.customdir"; + public static final String USE_OPTDIR_PROPERTY = "launcher.useoptdir"; + @LauncherAPI public static Path dir; @LauncherAPI @@ -27,12 +32,12 @@ public static void move(Path newDir) throws IOException { @LauncherAPI public static Path getAppDataDir() throws IOException { - Boolean isCustomDir = Boolean.getBoolean(System.getProperty("launcher.usecustomdir", "false")); + boolean isCustomDir = Boolean.getBoolean(System.getProperty(USE_CUSTOMDIR_PROPERTY, "false")); if (isCustomDir) { - return Paths.get(System.getProperty("launcher.customdir")); + return Paths.get(System.getProperty(CUSTOMDIR_PROPERTY)); } if (JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) { - Boolean isOpt = Boolean.getBoolean(System.getProperty("launcher.useoptdir", "false")); + boolean isOpt = Boolean.getBoolean(System.getProperty(USE_OPTDIR_PROPERTY, "false")); if (isOpt) { Path opt = Paths.get("/").resolve("opt"); if (!IOHelper.isDir(opt)) Files.createDirectories(opt); diff --git a/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java b/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java index 4c2ea950..59449386 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java +++ b/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java @@ -7,6 +7,8 @@ import ru.gravit.launcher.OshiHWID; import ru.gravit.utils.helper.LogHelper; +import java.net.NetworkInterface; + public class OshiHWIDProvider implements LauncherHWIDInterface { public SystemInfo systemInfo; public HardwareAbstractionLayer hardware; @@ -111,6 +113,9 @@ public void printHardwareInformation() { for(NetworkIF networkIF : hardware.getNetworkIFs()) { LogHelper.debug("Network Interface: %s mac: %s", networkIF.getName(), networkIF.getMacaddr()); + NetworkInterface network = networkIF.getNetworkInterface(); + if(network.isLoopback() || network.isVirtual()) continue; + LogHelper.debug("Network Interface display: %s name: %s", network.getDisplayName(), network.getName()); for(String ipv4 : networkIF.getIPv4addr()) { if(ipv4.startsWith("127.")) continue; diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java index 11777930..222a6c3c 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java @@ -41,8 +41,6 @@ public static void update(LauncherConfig config, LauncherRequestEvent result) th args.add(IOHelper.resolveJavaBin(null).toString()); if (LogHelper.isDebugEnabled()) args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); - if (LauncherConfig.ADDRESS_OVERRIDE != null) - args.add(JVMHelper.jvmProperty(LauncherConfig.ADDRESS_OVERRIDE_PROPERTY, LauncherConfig.ADDRESS_OVERRIDE)); args.add("-jar"); args.add(BINARY_PATH.toString()); ProcessBuilder builder = new ProcessBuilder(args.toArray(new String[0])); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LegacyLauncherRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LegacyLauncherRequest.java index 30d643b1..c2a089ef 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LegacyLauncherRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LegacyLauncherRequest.java @@ -61,8 +61,6 @@ public static void update(LauncherConfig config, Result result) throws Signature args.add(IOHelper.resolveJavaBin(null).toString()); if (LogHelper.isDebugEnabled()) args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); - if (LauncherConfig.ADDRESS_OVERRIDE != null) - args.add(JVMHelper.jvmProperty(LauncherConfig.ADDRESS_OVERRIDE_PROPERTY, LauncherConfig.ADDRESS_OVERRIDE)); args.add("-jar"); args.add(BINARY_PATH.toString()); ProcessBuilder builder = new ProcessBuilder(args.toArray(new String[0])); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index 6bfbdec0..18c3c6f2 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -60,7 +60,7 @@ public final class Launcher { private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL); public static final int MAJOR = 4; public static final int MINOR = 4; - public static final int PATCH = 1; + public static final int PATCH = 2; public static final int BUILD = 1; public static final Version.Type RELEASE = Version.Type.STABLE; public static GsonBuilder gsonBuilder; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java index 77dfebdc..82adbf6a 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java @@ -14,10 +14,6 @@ import java.util.*; public final class LauncherConfig extends StreamObject { - @LauncherAPI - public static final String ADDRESS_OVERRIDE_PROPERTY = "launcher.addressOverride"; - @LauncherAPI - public static final String ADDRESS_OVERRIDE = System.getProperty(ADDRESS_OVERRIDE_PROPERTY, null); private static final AutogenConfig config = new AutogenConfig(); @@ -51,9 +47,7 @@ public static AutogenConfig getAutogenConfig() { @LauncherAPI public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException { - String localAddress = config.address; - address = InetSocketAddress.createUnresolved( - ADDRESS_OVERRIDE == null ? localAddress : ADDRESS_OVERRIDE, config.port); + address = InetSocketAddress.createUnresolved( config.address, config.port); publicKey = SecurityHelper.toPublicRSAKey(input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH)); projectname = config.projectname; clientPort = config.clientPort; @@ -84,10 +78,6 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException String.format("Duplicate runtime resource: '%s'", name)); } runtime = Collections.unmodifiableMap(localResources); - - // Print warning if address override is enabled - if (ADDRESS_OVERRIDE != null) - LogHelper.warning("Address override is enabled: '%s'", ADDRESS_OVERRIDE); } @LauncherAPI diff --git a/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java b/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java index 4911d294..5d52e491 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java @@ -43,7 +43,7 @@ public int compare(HWID hwid) { if(oshi.HWDiskSerial.equals(HWDiskSerial)) rate+=45; if(oshi.processorID.equals(processorID)) rate+=18; if(oshi.serialNumber.equals(serialNumber)) rate+=15; - if(oshi.macAddr.equals(macAddr)) rate+=19; + if(!oshi.macAddr.isEmpty() && oshi.macAddr.equals(macAddr)) rate+=19; return rate; } return 0; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java b/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java index 6969a37f..381b023a 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java @@ -122,7 +122,6 @@ private void processKey(WatchKey key) throws IOException { // Resolve paths and verify is not exclusion Path path = watchDir.resolve((Path) event.context()); Deque stringPath = toPath(dir.relativize(path)); - LogHelper.debug("DirWatcher event %s", String.join("/", stringPath)); if (matcher != null && !matcher.shouldVerify(stringPath)) continue; // Exclusion; should not be verified // Verify is REALLY modified (not just attributes) diff --git a/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java b/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java index b66f2913..18e31149 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java +++ b/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java @@ -38,7 +38,7 @@ public void eval(String[] args, boolean bell) { return; // Measure start time and invoke command - Instant startTime = Instant.now(); + long startTime = System.currentTimeMillis(); try { lookup(args[0]).invoke(Arrays.copyOfRange(args, 1, args.length)); } catch (Exception e) { @@ -46,8 +46,8 @@ public void eval(String[] args, boolean bell) { } // Bell if invocation took > 1s - Instant endTime = Instant.now(); - if (bell && Duration.between(startTime, endTime).getSeconds() >= 5) + long endTime = System.currentTimeMillis(); + if (bell && endTime - startTime >= 5000) try { bell(); } catch (IOException e) { diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java index 32b66599..a4e3710c 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java @@ -10,6 +10,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; +import java.util.Collection; import java.util.Locale; import java.util.Map; @@ -155,6 +156,14 @@ public static String systemToJvmProperty(String name) { return String.format("-D%s=%s", name, System.getProperties().getProperty(name)); } + @LauncherAPI + public static void addSystemPropertyToArgs(Collection args, String name) + { + String property = System.getProperty(name); + if(property != null) + args.add(String.format("-D%s=%s", name, property)); + } + public static void verifySystemProperties(Class mainClass, boolean requireSystem) { Locale.setDefault(Locale.US);