diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index de70b34b..8c9398ed 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -184,18 +184,6 @@ task dumpClientLibs(type: Copy) { url = 'https://www.gnu.org/licenses/gpl-3.0.html' } } - developers { - developer { - id = 'gravit' - name = 'Gravit' - email = 'gravit.min@ya.ru' - } - developer { - id = 'zaxar163' - name = 'Zaxar163' - email = 'zahar.vcherachny@yandex.ru' - } - } scm { connection = 'scm:git:https://github.com/GravitLauncher/Launcher.git' diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 553c1674..8ad75c78 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -14,10 +14,7 @@ import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.config.LaunchServerRuntimeConfig; import pro.gravit.launchserver.launchermodules.LauncherModuleLoader; -import pro.gravit.launchserver.manangers.CertificateManager; -import pro.gravit.launchserver.manangers.MirrorManager; -import pro.gravit.launchserver.manangers.ReconfigurableManager; -import pro.gravit.launchserver.manangers.SessionManager; +import pro.gravit.launchserver.manangers.*; import pro.gravit.launchserver.manangers.hook.AuthHookManager; import pro.gravit.launchserver.modules.events.LaunchServerFullInitEvent; import pro.gravit.launchserver.modules.events.LaunchServerInitPhase; @@ -82,6 +79,7 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab public final MirrorManager mirrorManager; public final ReconfigurableManager reconfigurableManager; public final ConfigManager configManager; + public final PingServerManager pingServerManager; // HWID ban + anti-brutforce public final CertificateManager certificateManager; public final ProguardConf proguardConf; @@ -146,6 +144,7 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La reconfigurableManager = new ReconfigurableManager(); authHookManager = new AuthHookManager(); configManager = new ConfigManager(); + pingServerManager = new PingServerManager(this); //Generate or set new Certificate API certificateManager.orgName = config.projectName; if (config.certificate != null && config.certificate.enabled) { @@ -389,6 +388,8 @@ public void syncProfilesDir() throws IOException { // Sort and set new profiles newProfies.sort(Comparator.comparing(a -> a)); profilesList = Collections.unmodifiableList(newProfies); + if(pingServerManager != null) + pingServerManager.syncServers(); } public void syncUpdatesDir(Collection dirs) throws IOException { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/hwid/MysqlHWIDProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/hwid/MysqlHWIDProvider.java index 623593b0..426707bf 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/hwid/MysqlHWIDProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/hwid/MysqlHWIDProvider.java @@ -72,7 +72,8 @@ private HardwareReportRequest.HardwareInfo fetchHardwareInfo(ResultSet set) thro HardwareReportRequest.HardwareInfo hardwareInfo = new HardwareReportRequest.HardwareInfo(); hardwareInfo.hwDiskId = set.getString(1); hardwareInfo.baseboardSerialNumber = set.getString(2); - hardwareInfo.displayId = IOHelper.read(set.getBlob(3).getBinaryStream()); + Blob displayId = set.getBlob(3); + hardwareInfo.displayId = displayId == null ? null : IOHelper.read(displayId.getBinaryStream()); hardwareInfo.bitness = set.getInt(4); hardwareInfo.totalMemory = set.getLong(5); hardwareInfo.logicalProcessors = set.getInt(6); @@ -90,7 +91,7 @@ public void createHardwareInfo(HardwareReportRequest.HardwareInfo hardwareInfo, s.setBlob(1, new ByteArrayInputStream(publicKey)); s.setString(2, hardwareInfo.hwDiskId); s.setString(3, hardwareInfo.baseboardSerialNumber); - s.setBlob(4, new ByteArrayInputStream(hardwareInfo.displayId)); + s.setBlob(4, hardwareInfo.displayId == null ? null : new ByteArrayInputStream(hardwareInfo.displayId)); s.setInt(5, hardwareInfo.bitness); s.setLong(6, hardwareInfo.totalMemory); s.setInt(7, hardwareInfo.logicalProcessors); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java index 45f01c24..77e74150 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java @@ -48,6 +48,7 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand updates.registerCommand("syncBinaries", new SyncBinariesCommand(server)); updates.registerCommand("syncUpdates", new SyncUpdatesCommand(server)); updates.registerCommand("syncProfiles", new SyncProfilesCommand(server)); + updates.registerCommand("syncUP", new SyncUPCommand(server)); updates.registerCommand("saveProfiles", new SaveProfilesCommand(server)); Category updatesCategory = new Category(updates, "updates", "Update and Sync Management"); handler.registerCategory(updatesCategory); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java index ef403ecc..211d32af 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java @@ -63,6 +63,14 @@ public void invoke(String... args) throws IOException, CommandException { client.setTitle(dirName); client.setDir(dirName); client.setUUID(UUID.randomUUID()); + if(client.getServers() != null) + { + ClientProfile.ServerProfile serverProfile = client.getDefaultServerProfile(); + if(serverProfile != null) + { + serverProfile.name = dirName; + } + } try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir, dirName, "json"))) { Launcher.gsonManager.configGson.toJson(client, writer); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java index c628a4be..adc9bcf5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java @@ -19,8 +19,18 @@ public SaveProfilesCommand(LaunchServer server) { super(server); } + @SuppressWarnings("deprecated") public static void saveProfile(ClientProfile profile, Path path) throws IOException { if (profile.getUUID() == null) profile.setUUID(UUID.randomUUID()); + if(profile.getServers().size() == 0) + { + ClientProfile.ServerProfile serverProfile = new ClientProfile.ServerProfile(); + serverProfile.isDefault = true; + serverProfile.name = profile.getTitle(); + serverProfile.serverAddress = profile.getServerAddress(); + serverProfile.serverPort = profile.getServerPort(); + profile.getServers().add(serverProfile); + } try (Writer w = IOHelper.newWriter(path)) { Launcher.gsonManager.configGson.toJson(profile, w); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncUPCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncUPCommand.java new file mode 100644 index 00000000..83bb9c61 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncUPCommand.java @@ -0,0 +1,32 @@ +package pro.gravit.launchserver.command.hash; + +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; +import pro.gravit.utils.helper.LogHelper; + +import java.io.IOException; + +public final class SyncUPCommand extends Command { + public SyncUPCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return null; + } + + @Override + public String getUsageDescription() { + return "Resync profiles & updates dirs"; + } + + @Override + public void invoke(String... args) throws IOException { + server.syncProfilesDir(); + LogHelper.subInfo("Profiles successfully resynced"); + + server.syncUpdatesDir(null); + LogHelper.subInfo("Updates dir successfully resynced"); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index 08ca4407..c3d29578 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -48,7 +48,7 @@ public final class LaunchServerConfig { public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { LaunchServerConfig newConfig = new LaunchServerConfig(); - newConfig.mirrors = new String[]{"https://mirror.gravit.pro/"}; + newConfig.mirrors = new String[]{"https://mirror.gravit.pro/", "https://gravit-launcher-mirror.storage.googleapis.com/"}; newConfig.launch4j = new LaunchServerConfig.ExeConf(); newConfig.launch4j.enabled = true; newConfig.launch4j.copyright = "© GravitLauncher Team"; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java b/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java index 5c9c38a2..6575c9ca 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java @@ -19,10 +19,7 @@ import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.jar.Attributes; import java.util.jar.JarFile; @@ -148,9 +145,10 @@ public void addClassFieldsToProperties(Map propertyMap, String p for (Field field : fields) { if ((field.getModifiers() & Modifier.STATIC) != 0) continue; Object obj = field.get(object); - String propertyName = prefix.concat(".").concat(field.getName()); + String propertyName = prefix.concat(".").concat(field.getName().toLowerCase(Locale.US)); if(InjectClassAcceptor.isSerializableValue(obj)) { + LogHelper.dev("Property name %s", propertyName); propertyMap.put(propertyName, obj); } else diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java index 4b735948..f19ca95f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java @@ -15,6 +15,7 @@ import pro.gravit.launchserver.dao.provider.DaoProvider; import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager; import pro.gravit.launchserver.socket.WebSocketService; +import pro.gravit.launchserver.socket.response.UnknownResponse; import pro.gravit.launchserver.socket.response.WebSocketServerResponse; import pro.gravit.utils.UniversalJsonAdapter; @@ -34,7 +35,7 @@ public void registerAdapters(GsonBuilder builder) { builder.registerTypeAdapter(Component.class, new UniversalJsonAdapter<>(Component.providers)); builder.registerTypeAdapter(ProtectHandler.class, new UniversalJsonAdapter<>(ProtectHandler.providers)); builder.registerTypeAdapter(DaoProvider.class, new UniversalJsonAdapter<>(DaoProvider.providers)); - builder.registerTypeAdapter(WebSocketServerResponse.class, new UniversalJsonAdapter<>(WebSocketService.providers)); + builder.registerTypeAdapter(WebSocketServerResponse.class, new UniversalJsonAdapter<>(WebSocketService.providers, UnknownResponse.class)); builder.registerTypeAdapter(WebSocketEvent.class, new JsonResultSerializeAdapter()); builder.registerTypeAdapter(AuthRequest.AuthPasswordInterface.class, new UniversalJsonAdapter<>(AuthRequest.providers)); builder.registerTypeAdapter(HWIDProvider.class, new UniversalJsonAdapter<>(HWIDProvider.providers)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/PingServerManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/PingServerManager.java new file mode 100644 index 00000000..04937680 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/PingServerManager.java @@ -0,0 +1,65 @@ +package pro.gravit.launchserver.manangers; + +import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.request.management.PingServerReportRequest; +import pro.gravit.launchserver.LaunchServer; + +import java.util.HashMap; +import java.util.Map; + +public class PingServerManager { + public static long REPORT_EXPIRED_TIME = 20*1000; + + public static class ServerInfoEntry + { + public PingServerReportRequest.PingServerReport lastReport; + public long lastReportTime; + public final ClientProfile profile; + + public ServerInfoEntry(ClientProfile profile, PingServerReportRequest.PingServerReport lastReport) { + this.lastReport = lastReport; + this.profile = profile; + this.lastReportTime = System.currentTimeMillis(); + } + + public ServerInfoEntry(ClientProfile profile) { + this.profile = profile; + } + + public boolean isExpired() + { + return System.currentTimeMillis() - lastReportTime > REPORT_EXPIRED_TIME; + } + } + public final Map map = new HashMap<>(); + private final LaunchServer server; + + public PingServerManager(LaunchServer server) { + this.server = server; + } + public void syncServers() + { + server.getProfiles().forEach((p) -> { + for(ClientProfile.ServerProfile sp : p.getServers()) + { + ServerInfoEntry entry = map.get(sp.name); + if(entry == null) + { + map.put(sp.name, new ServerInfoEntry(p)); + } + } + }); + } + public boolean updateServer(String name, PingServerReportRequest.PingServerReport report) + { + ServerInfoEntry entry = map.get(name); + if(entry == null) + return false; + else + { + entry.lastReportTime = System.currentTimeMillis(); + entry.lastReport = report; + return true; + } + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java index 6e6b2681..fe2a8775 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -15,9 +15,10 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.launchserver.socket.response.WebSocketServerResponse; -import pro.gravit.launchserver.socket.response.admin.AddLogListenerResponse; -import pro.gravit.launchserver.socket.response.admin.ExecCommandResponse; import pro.gravit.launchserver.socket.response.auth.*; +import pro.gravit.launchserver.socket.response.management.PingServerReportResponse; +import pro.gravit.launchserver.socket.response.management.PingServerResponse; +import pro.gravit.launchserver.socket.response.management.ServerStatusResponse; import pro.gravit.launchserver.socket.response.profile.BatchProfileByUsername; import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse; import pro.gravit.launchserver.socket.response.profile.ProfileByUsername; @@ -34,6 +35,7 @@ import pro.gravit.utils.helper.LogHelper; import java.lang.reflect.Type; +import java.util.concurrent.atomic.AtomicLong; public class WebSocketService { public static final ProviderMap providers = new ProviderMap<>(); @@ -42,6 +44,18 @@ public class WebSocketService { private final LaunchServer server; private final Gson gson; + //Statistic data + public AtomicLong shortRequestLatency = new AtomicLong(); + public AtomicLong shortRequestCounter = new AtomicLong(); + + public AtomicLong middleRequestLatency = new AtomicLong(); + public AtomicLong middleRequestCounter = new AtomicLong(); + + public AtomicLong longRequestLatency = new AtomicLong(); + public AtomicLong longRequestCounter = new AtomicLong(); + + public AtomicLong lastRequestTime = new AtomicLong(); + public WebSocketService(ChannelGroup channels, LaunchServer server) { this.channels = channels; this.server = server; @@ -58,9 +72,7 @@ public static void registerResponses() { providers.register("profiles", ProfilesResponse.class); providers.register("launcher", LauncherResponse.class); providers.register("updateList", UpdateListResponse.class); - providers.register("cmdExec", ExecCommandResponse.class); providers.register("setProfile", SetProfileResponse.class); - providers.register("addLogListener", AddLogListenerResponse.class); providers.register("update", UpdateResponse.class); providers.register("restoreSession", RestoreSessionResponse.class); providers.register("batchProfileByUsername", BatchProfileByUsername.class); @@ -74,16 +86,58 @@ public static void registerResponses() { providers.register("verifySecureLevelKey", VerifySecureLevelKeyResponse.class); providers.register("securityReport", SecurityReportResponse.class); providers.register("hardwareReport", HardwareReportResponse.class); + providers.register("serverStatus", ServerStatusResponse.class); + providers.register("pingServerReport", PingServerReportResponse.class); + providers.register("pingServer", PingServerResponse.class); } public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) { + long startTimeNanos = System.nanoTime(); String request = frame.text(); WebSocketServerResponse response = gson.fromJson(request, WebSocketServerResponse.class); if (response == null) { RequestEvent event = new ErrorRequestEvent("This type of request is not supported"); sendObject(ctx, event); + return; } process(ctx, response, client, ip); + long executeTime = System.nanoTime() - startTimeNanos; + if(executeTime > 0) + { + addRequestTimeToStats(executeTime); + } + } + + public void addRequestTimeToStats(long nanos) + { + if(nanos < 100_000_000L) // < 100 millis + { + shortRequestCounter.getAndIncrement(); + shortRequestLatency.getAndAdd(nanos); + } + else if(nanos < 1_000_000_000L) // > 100 millis and < 1 second + { + middleRequestCounter.getAndIncrement(); + middleRequestLatency.getAndAdd(nanos); + } + else // > 1 second + { + longRequestCounter.getAndIncrement(); + longRequestLatency.getAndAdd(nanos); + } + long lastTime = lastRequestTime.get(); + long currentTime = System.currentTimeMillis(); + if(currentTime - lastTime > 60*1000) //1 minute + { + lastRequestTime.set(currentTime); + shortRequestLatency.set(0); + shortRequestCounter.set(0); + middleRequestCounter.set(0); + middleRequestLatency.set(0); + longRequestCounter.set(0); + longRequestLatency.set(0); + } + } void process(ChannelHandlerContext ctx, WebSocketServerResponse response, Client client, String ip) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/UnknownResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/UnknownResponse.java new file mode 100644 index 00000000..af41a0dc --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/UnknownResponse.java @@ -0,0 +1,16 @@ +package pro.gravit.launchserver.socket.response; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launchserver.socket.Client; + +public class UnknownResponse extends SimpleResponse { + @Override + public String getType() { + return "unknown"; + } + + @Override + public void execute(ChannelHandlerContext ctx, Client client) { + sendError("This type of request is not supported"); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/AddLogListenerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/AddLogListenerResponse.java deleted file mode 100644 index 00e8482f..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/AddLogListenerResponse.java +++ /dev/null @@ -1,45 +0,0 @@ -package pro.gravit.launchserver.socket.response.admin; - -import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.events.request.LogEvent; -import pro.gravit.launchserver.socket.Client; -import pro.gravit.launchserver.socket.response.SimpleResponse; -import pro.gravit.utils.helper.LogHelper; - -public class AddLogListenerResponse extends SimpleResponse { - public final LogHelper.OutputTypes outputType = LogHelper.OutputTypes.PLAIN; - - @Override - public String getType() { - return "addLogListener"; - } - - @Override - public void execute(ChannelHandlerContext ctx, Client client) { - if (!client.isAuth) { - sendError("Access denied"); - return; - } - if (!client.permissions.isPermission(ClientPermissions.PermissionConsts.ADMIN)) { - sendError("Access denied"); - return; - } - if (client.logOutput != null) { - LogHelper.info("Client %s remove log listener", client.username); - LogHelper.removeOutput(client.logOutput); - } else { - LogHelper.info("Client %s add log listener", client.username); - LogHelper.Output output = (str) -> { - if (!ctx.isRemoved()) { - service.sendObject(ctx, new LogEvent(str)); - } else { - LogHelper.removeOutput(client.logOutput); - LogHelper.info("Client %s remove log listener", client.username); - } - }; - client.logOutput = new LogHelper.OutputEnity(output, outputType); - LogHelper.addOutput(client.logOutput); - } - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/ExecCommandResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/ExecCommandResponse.java deleted file mode 100644 index b8d34d38..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/ExecCommandResponse.java +++ /dev/null @@ -1,26 +0,0 @@ -package pro.gravit.launchserver.socket.response.admin; - -import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.events.request.ExecCommandRequestEvent; -import pro.gravit.launchserver.socket.Client; -import pro.gravit.launchserver.socket.response.SimpleResponse; - -public class ExecCommandResponse extends SimpleResponse { - public String cmd; - - @Override - public String getType() { - return "cmdExec"; - } - - @Override - public void execute(ChannelHandlerContext ctx, Client client) { - if (!client.isAuth || !client.permissions.isPermission(ClientPermissions.PermissionConsts.ADMIN)) { - sendError("Access denied"); - return; - } - server.commandHandler.eval(cmd, false); - sendResult(new ExecCommandRequestEvent(true)); - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java index 15667812..ae85d459 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java @@ -98,13 +98,20 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti } result.session = clientData.session; } - if (authType != ConnectTypes.API && server.config.protectHandler.allowGetAccessToken(context)) { - UUID uuid = pair.handler.auth(aresult); - result.playerProfile = ProfileByUUIDResponse.getProfile(uuid, aresult.username, client, clientData.auth.textureProvider); + UUID uuid; + if (authType == ConnectTypes.CLIENT && server.config.protectHandler.allowGetAccessToken(context)) { + uuid = pair.handler.auth(aresult); if (LogHelper.isDebugEnabled()) { LogHelper.debug("Auth: %s accessToken %s uuid: %s", login, result.accessToken, uuid.toString()); } } + else + { + uuid = pair.handler.usernameToUUID(aresult.username); + result.accessToken = null; + } + result.playerProfile = ProfileByUUIDResponse.getProfile(uuid, aresult.username, client, clientData.auth.textureProvider); + clientData.type = authType; sendResult(result); } catch (AuthException | HookException e) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/PingServerReportResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/PingServerReportResponse.java new file mode 100644 index 00000000..5474e83f --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/PingServerReportResponse.java @@ -0,0 +1,27 @@ +package pro.gravit.launchserver.socket.response.management; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launcher.ClientPermissions; +import pro.gravit.launcher.events.request.PingServerReportRequestEvent; +import pro.gravit.launcher.request.management.PingServerReportRequest; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.SimpleResponse; + +public class PingServerReportResponse extends SimpleResponse { + public PingServerReportRequest.PingServerReport data; + public String name; + @Override + public String getType() { + return "pingServerReport"; + } + + @Override + public void execute(ChannelHandlerContext ctx, Client client) throws Exception { + if(!client.isAuth || client.permissions == null || !client.permissions.isPermission(ClientPermissions.PermissionConsts.MANAGEMENT)) + { + sendError("Access denied"); + } + server.pingServerManager.updateServer(name, data); + sendResult(new PingServerReportRequestEvent()); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/PingServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/PingServerResponse.java new file mode 100644 index 00000000..8fc83c28 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/PingServerResponse.java @@ -0,0 +1,47 @@ +package pro.gravit.launchserver.socket.response.management; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launcher.events.request.PingServerRequestEvent; +import pro.gravit.launcher.request.management.PingServerReportRequest; +import pro.gravit.launchserver.auth.protect.interfaces.ProfilesProtectHandler; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.SimpleResponse; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class PingServerResponse extends SimpleResponse { + public List serverNames; //May be null + @Override + public String getType() { + return "pingServer"; + } + + @Override + public void execute(ChannelHandlerContext ctx, Client client) throws Exception { + Map map = new HashMap<>(); + if(serverNames == null) + { + server.pingServerManager.map.forEach((name, entity) -> { + if(server.config.protectHandler instanceof ProfilesProtectHandler) + { + if(!((ProfilesProtectHandler) server.config.protectHandler).canGetProfile(entity.profile, client)) + { + return; + } + } + if(!entity.isExpired()) + { + map.put(name, entity.lastReport); + } + }); + } + else + { + sendError("Not implemented"); + return; + } + sendResult(new PingServerRequestEvent(map)); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/ServerStatusResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/ServerStatusResponse.java new file mode 100644 index 00000000..d8631c80 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/ServerStatusResponse.java @@ -0,0 +1,28 @@ +package pro.gravit.launchserver.socket.response.management; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launcher.events.request.ServerStatusRequestEvent; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.WebSocketService; +import pro.gravit.launchserver.socket.response.SimpleResponse; +import pro.gravit.utils.helper.JVMHelper; + +public class ServerStatusResponse extends SimpleResponse { + @Override + public String getType() { + return "serverStatus"; + } + + @Override + public void execute(ChannelHandlerContext ctx, Client client) throws Exception { + ServerStatusRequestEvent event = new ServerStatusRequestEvent(server.config.projectName); + event.totalJavaMemory = JVMHelper.RUNTIME.totalMemory(); + event.freeJavaMemory = JVMHelper.RUNTIME.freeMemory(); + event.shortLatency = ( service.shortRequestLatency.get() / service.shortRequestCounter.get() ) / 1_000_000; + event.middleLatency = ( service.middleRequestLatency.get() / service.middleRequestCounter.get() ) / 1_000_000; + event.longLatency = ( service.longRequestLatency.get() / service.longRequestCounter.get() ) / 1_000_000; + event.latency = ( ( service.shortRequestLatency.get() + service.middleRequestLatency.get() + service.longRequestLatency.get() ) / + ( service.shortRequestCounter.get() + service.middleRequestCounter.get() + service.longRequestCounter.get() ) ) / 1_000_000; + sendResult(event); + } +} diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.10.2.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.10.2.cfg index 423bfe49..45e13630 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.10.2.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.10.2.cfg @@ -6,14 +6,16 @@ "info": "Информация о сервере", "sortIndex": 0, "title": "xxxxxxxx", - "serverAddress": "localhost", - "serverPort": 25565, - "update": ["servers.dat"], - "updateExclusions": [ - "mods/OpenSecurity", - "mods/VoxelMods", - "mods/railcraft" + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } ], + "update": ["servers.dat"], + "updateExclusions": [], "updateShared": [], "updateVerify": [ "libraries", "natives", "mods", diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.11.2.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.11.2.cfg index 77a61146..81b5a96c 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.11.2.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.11.2.cfg @@ -6,14 +6,16 @@ "info": "Информация о сервере", "sortIndex": 0, "title": "xxxxxxxx", - "serverAddress": "localhost", - "serverPort": 25565, - "update": ["servers.dat"], - "updateExclusions": [ - "mods/OpenSecurity", - "mods/VoxelMods", - "mods/railcraft" + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } ], + "update": ["servers.dat"], + "updateExclusions": [], "updateShared": [], "updateVerify": [ "libraries", "natives", "mods", diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.12.2.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.12.2.cfg index b4b2a11f..a6896906 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.12.2.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.12.2.cfg @@ -6,14 +6,16 @@ "info": "Информация о сервере", "sortIndex": 0, "title": "xxxxxxxx", - "serverAddress": "localhost", - "serverPort": 25565, - "update": ["servers.dat"], - "updateExclusions": [ - "mods/OpenSecurity", - "mods/VoxelMods", - "mods/railcraft" + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } ], + "update": ["servers.dat"], + "updateExclusions": [], "updateShared": [], "updateVerify": [ "libraries", "natives", "mods", @@ -35,8 +37,8 @@ ], "classPath": ["forge.jar", "liteloader.jar", "minecraft.jar", "libraries"], "clientArgs": [ - "--tweakClass", "net.minecraftforge.fml.common.launcher.FMLTweaker", - "--tweakClass", "com.mumfrey.liteloader.launch.LiteLoaderTweaker" + "--tweakClass", "com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "--tweakClass", "net.minecraftforge.fml.common.launcher.FMLTweaker" ], "optionalJVMArgs": [], "optionalClientArgs": [], diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.13.1.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.13.1.cfg index 12f2ccae..9fbd07dc 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.13.1.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.13.1.cfg @@ -6,14 +6,16 @@ "info": "Информация о сервере", "sortIndex": 0, "title": "xxxxxxxx", - "serverAddress": "localhost", - "serverPort": 25565, - "update": ["servers.dat"], - "updateExclusions": [ - "mods/OpenSecurity", - "mods/VoxelMods", - "mods/railcraft" + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } ], + "update": ["servers.dat"], + "updateExclusions": [], "updateShared": [], "updateVerify": [ "libraries", "natives", "mods", diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.13.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.13.cfg index 19afb377..110c6c74 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.13.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.13.cfg @@ -6,14 +6,16 @@ "info": "Информация о сервере", "sortIndex": 0, "title": "xxxxxxxx", - "serverAddress": "localhost", - "serverPort": 25565, - "update": ["servers.dat"], - "updateExclusions": [ - "mods/OpenSecurity", - "mods/VoxelMods", - "mods/railcraft" + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } ], + "update": ["servers.dat"], + "updateExclusions": [], "updateShared": [], "updateVerify": [ "libraries", "natives", "mods", diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.14.4.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.14.4.cfg index 0fac6e8b..a6cfc177 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.14.4.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.14.4.cfg @@ -6,8 +6,14 @@ "info": "Информация о сервере", "sortIndex": 0, "title": "xxxxxxxx", - "serverAddress": "localhost", - "serverPort": 25565, + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } + ], "update": [ "servers.dat" ], diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.1.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.1.cfg index f265344f..55c0fbe1 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.1.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.1.cfg @@ -6,8 +6,14 @@ "info": "Информация о сервере", "sortIndex": 0, "title": "xxxxxxxx", - "serverAddress": "localhost", - "serverPort": 25565, + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } + ], "update": [ "servers.dat" ], diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.2.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.2.cfg index d59a68be..b4889638 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.2.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.2.cfg @@ -6,8 +6,14 @@ "info": "Информация о сервере", "sortIndex": 0, "title": "xxxxxxxx", - "serverAddress": "localhost", - "serverPort": 25565, + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } + ], "update": [ "servers.dat" ], diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.16.1.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.16.1.cfg new file mode 100644 index 00000000..db57fe05 --- /dev/null +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.16.1.cfg @@ -0,0 +1,44 @@ +{ + "version": "1.16.1", + "assetIndex": "1.16.1", + "assetDir": "asset1.16.1", + "dir": "HiTech", + "info": "Информация о сервере", + "sortIndex": 0, + "title": "xxxxxxxx", + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } + ], + "update": [ + "servers.dat" + ], + "updateExclusions": [], + "updateShared": [], + "updateVerify": [ + "libraries", + "natives", + "minecraft.jar" + ], + "updateOptional": [], + "updateFastCheck": true, + "useWhitelist": false, + "mainClass": "net.minecraft.client.main.Main", + "jvmArgs": [ + "-XX:+UseConcMarkSweepGC", + "-XX:+CMSIncrementalMode", + "-XX:-UseAdaptiveSizePolicy", + "-Xmn128M", + "-XX:+DisableAttachMechanism" + ], + "classPath": [ + "minecraft.jar", + "libraries" + ], + "clientArgs": [], + "whitelist": [] +} diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.4.7.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.4.7.cfg index 81857091..058bec47 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.4.7.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.4.7.cfg @@ -6,8 +6,14 @@ "info": "Информация о сервере", "sortIndex": 0, "title": "Test1.4.7", - "serverAddress": "localhost", - "serverPort": 25565, + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } + ], "update": ["servers.dat"], "updateExclusions": [], "updateShared": [], diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.5.2.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.5.2.cfg index cbc38a43..bb7542f8 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.5.2.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.5.2.cfg @@ -6,8 +6,14 @@ "info": "Информация о сервере", "sortIndex": 0, "title": "Test1.5.2", - "serverAddress": "localhost", - "serverPort": 25565, + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } + ], "update": ["servers.dat"], "updateExclusions": [], "updateShared": [], diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.6.4.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.6.4.cfg index 9e2af4dc..e5585821 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.6.4.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.6.4.cfg @@ -6,8 +6,14 @@ "info": "Информация о сервере", "sortIndex": 0, "title": "Test1.6.4", - "serverAddress": "localhost", - "serverPort": 25565, + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } + ], "update": ["servers.dat"], "updateExclusions": [], "updateShared": [], diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.7.10.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.7.10.cfg index fa35d761..2e20b6a0 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.7.10.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.7.10.cfg @@ -6,8 +6,14 @@ "info": "Информация о сервере", "sortIndex": 0, "title": "Test1.7.10", - "serverAddress": "localhost", - "serverPort": 25565, + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } + ], "update": ["servers.dat"], "updateExclusions": [], "updateShared": [], diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.7.2.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.7.2.cfg index 089b7a85..890f7b82 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.7.2.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.7.2.cfg @@ -6,8 +6,14 @@ "info": "Информация о сервере", "sortIndex": 0, "title": "Test1.7.2", - "serverAddress": "localhost", - "serverPort": 25565, + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } + ], "update": ["servers.dat"], "updateExclusions": [], "updateShared": [], diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.8.9.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.8.9.cfg index 0550c3de..68c1d1ce 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.8.9.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.8.9.cfg @@ -6,8 +6,14 @@ "info": "Информация о сервере", "sortIndex": 0, "title": "Test1.8.9", - "serverAddress": "localhost", - "serverPort": 25565, + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } + ], "update": ["servers.dat"], "updateExclusions": [], "updateShared": [], diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.9.4.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.9.4.cfg index 3dff6561..329b20c0 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.9.4.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.9.4.cfg @@ -6,8 +6,14 @@ "info": "Информация о сервере", "sortIndex": 0, "title": "Test1.9.4", - "serverAddress": "localhost", - "serverPort": 25565, + "servers": [ + { + "name": "----", + "serverAddress": "localhost", + "serverPort": 25565, + "isDefault": true + } + ], "update": ["servers.dat"], "updateExclusions": [], "updateShared": [], diff --git a/Launcher/build.gradle b/Launcher/build.gradle index bb7ac52a..10dbc4b7 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -93,18 +93,6 @@ task dumpLibs(type: Copy) { url = 'https://www.gnu.org/licenses/gpl-3.0.html' } } - developers { - developer { - id = 'gravit' - name = 'Gravit' - email = 'gravit.min@ya.ru' - } - developer { - id = 'zaxar163' - name = 'Zaxar163' - email = 'zahar.vcherachny@yandex.ru' - } - } scm { connection = 'scm:git:https://github.com/GravitLauncher/Launcher.git' developerConnection = 'scm:git:ssh://git@github.com:GravitLauncher/Launcher.git' diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index 258b3490..90e52953 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -14,13 +14,55 @@ import java.nio.file.Paths; import java.util.LinkedList; import java.util.List; +import java.util.Properties; public class ClientLauncherWrapper { public static final String MAGIC_ARG = "-Djdk.attach.allowAttachSelf"; public static final String WAIT_PROCESS_PROPERTY = "launcher.waitProcess"; - public static final String NO_JAVA9_CHECK_PROPERTY = "launcher.noJava9Check"; - public static final boolean noJava9check = Boolean.getBoolean(NO_JAVA9_CHECK_PROPERTY); + public static final String NO_JAVA_CHECK_PROPERTY = "launcher.noJavaCheck"; + public static boolean noJavaCheck = Boolean.getBoolean(NO_JAVA_CHECK_PROPERTY); public static boolean waitProcess = Boolean.getBoolean(WAIT_PROCESS_PROPERTY); + public static class JavaVersion + { + public final Path jvmDir; + public final int version; + public boolean enabledJavaFX; + + public JavaVersion(Path jvmDir, int version) { + this.jvmDir = jvmDir; + this.version = version; + this.enabledJavaFX = true; + } + public static JavaVersion getCurrentJavaVersion() + { + return new JavaVersion(Paths.get(System.getProperty("java.home")), JVMHelper.getVersion()); + } + public static JavaVersion getByPath(Path jvmDir) throws IOException { + Path releaseFile = jvmDir.resolve("release"); + if(!IOHelper.isFile(releaseFile)) return null; + Properties properties = new Properties(); + properties.load(IOHelper.newReader(releaseFile)); + int javaVersion = getJavaVersion(properties.getProperty("JAVA_VERSION").replaceAll("\"", "")); + JavaVersion resultJavaVersion = new JavaVersion(jvmDir, javaVersion); + if(javaVersion <= 8) + { + resultJavaVersion.enabledJavaFX = isExistExtJavaLibrary(jvmDir, "jfxrt"); + } + else + { + resultJavaVersion.enabledJavaFX = tryFindModule(jvmDir, "javafx.base") != null; + if(!resultJavaVersion.enabledJavaFX) + resultJavaVersion.enabledJavaFX = tryFindModule(jvmDir.resolve("jre"), "javafx.base") != null; + } + return resultJavaVersion; + } + public static boolean isExistExtJavaLibrary(Path jvmDir, String name) + { + Path jrePath = jvmDir.resolve("lib").resolve("ext").resolve(name.concat(".jar")); + Path jdkPath = jvmDir.resolve("jre").resolve("lib").resolve("ext").resolve(name.concat(".jar")); + return IOHelper.isFile(jrePath) || IOHelper.isFile(jdkPath); + } + } public static void main(String[] arguments) throws IOException, InterruptedException { LogHelper.printVersion("Launcher"); @@ -49,7 +91,19 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep LogHelper.info("Restart Launcher with JavaAgent..."); ProcessBuilder processBuilder = new ProcessBuilder(); if (waitProcess) processBuilder.inheritIO(); - Path javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); + + JavaVersion javaVersion = null; + try { + if(!noJavaCheck) javaVersion = findJava(); + } catch (Throwable e) { + LogHelper.error(e); + } + if (javaVersion == null) + { + javaVersion = JavaVersion.getCurrentJavaVersion(); + } + + Path javaBin = IOHelper.resolveJavaBin(javaVersion.jvmDir); List args = new LinkedList<>(); args.add(javaBin.toString()); String pathLauncher = IOHelper.getCodeSource(LauncherEngine.class).toString(); @@ -60,13 +114,12 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_CUSTOMDIR_PROPERTY); JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_OPTDIR_PROPERTY); JVMHelper.addSystemPropertyToArgs(args, DirWatcher.IGN_OVERFLOW); - if (!noJava9check && !System.getProperty("java.version").startsWith("1.8")) { + if (javaVersion.version >= 9) { LogHelper.debug("Found Java 9+ ( %s )", System.getProperty("java.version")); - Path jvmDir = Paths.get(System.getProperty("java.home")); String pathToFx = System.getenv("PATH_TO_FX"); Path fxPath = pathToFx == null ? null : Paths.get(pathToFx); StringBuilder builder = new StringBuilder(); - Path[] findPath = new Path[]{jvmDir, fxPath}; + Path[] findPath = new Path[]{javaVersion.jvmDir, javaVersion.jvmDir.resolve("jre"), fxPath}; tryAddModule(findPath, "javafx.base", builder); tryAddModule(findPath, "javafx.graphics", builder); tryAddModule(findPath, "javafx.fxml", builder); @@ -133,4 +186,73 @@ public static boolean tryAddModule(Path[] paths, String moduleName, StringBuilde } return false; } + + public static JavaVersion findJavaByProgramFiles(Path path) + { + LogHelper.debug("Check Java in %s", path.toString()); + JavaVersion selectedJava = null; + File[] candidates = path.toFile().listFiles(File::isDirectory); + if(candidates == null) return null; + for(File candidate : candidates) + { + Path javaPath = candidate.toPath(); + try { + JavaVersion javaVersion = JavaVersion.getByPath(javaPath); + if(javaVersion == null || javaVersion.version < 8) continue; + LogHelper.debug("Found Java %d in %s (javafx %s)", javaVersion.version, javaVersion.jvmDir.toString(), javaVersion.enabledJavaFX ? "true" : "false"); + if(javaVersion.enabledJavaFX && (selectedJava == null || !selectedJava.enabledJavaFX)) + { + selectedJava = javaVersion; + continue; + } + if(selectedJava != null && javaVersion.enabledJavaFX && javaVersion.version < selectedJava.version) + { + selectedJava = javaVersion; + } + } catch (IOException e) { + LogHelper.error(e); + } + } + if(selectedJava != null) + { + LogHelper.debug("Selected Java %d in %s (javafx %s)", selectedJava.version, selectedJava.jvmDir.toString(), selectedJava.enabledJavaFX ? "true" : "false"); + } + return selectedJava; + } + + public static JavaVersion findJava() + { + if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) + { + JavaVersion result = null; + Path defaultJvmContainerDir = Paths.get(System.getProperty("java.home")).getParent(); + if(defaultJvmContainerDir.getParent().getFileName().toString().contains("x86")) //Program Files (x86) ? + { + Path programFiles64 = defaultJvmContainerDir.getParent().getParent().resolve("Program Files").resolve("Java"); + if(IOHelper.isDir(programFiles64)) + { + result = findJavaByProgramFiles(programFiles64); + } + } + if(result == null) + { + result = findJavaByProgramFiles(defaultJvmContainerDir); + } + return result; + } + return null; + } + + public static int getJavaVersion(String version) + { + if (version.startsWith("1.")) { + version = version.substring(2, 3); + } else { + int dot = version.indexOf("."); + if (dot != -1) { + version = version.substring(0, dot); + } + } + return Integer.parseInt(version); + } } diff --git a/LauncherAPI/build.gradle b/LauncherAPI/build.gradle index 0b33f0bd..724e14f4 100644 --- a/LauncherAPI/build.gradle +++ b/LauncherAPI/build.gradle @@ -47,18 +47,6 @@ task javadocJar(type: Jar) { url = 'https://www.gnu.org/licenses/gpl-3.0.html' } } - developers { - developer { - id = 'gravit' - name = 'Gravit' - email = 'gravit.min@ya.ru' - } - developer { - id = 'zaxar163' - name = 'Zaxar163' - email = 'zahar.vcherachny@yandex.ru' - } - } scm { connection = 'scm:git:https://github.com/GravitLauncher/Launcher.git' developerConnection = 'scm:git:ssh://git@github.com:GravitLauncher/Launcher.git' diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ExecCommandRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ExecCommandRequestEvent.java deleted file mode 100644 index c20104d7..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ExecCommandRequestEvent.java +++ /dev/null @@ -1,18 +0,0 @@ -package pro.gravit.launcher.events.request; - -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.RequestEvent; - -public class ExecCommandRequestEvent extends RequestEvent { - @LauncherNetworkAPI - public final boolean success; - - public ExecCommandRequestEvent(boolean success) { - this.success = success; - } - - @Override - public String getType() { - return "cmdExec"; - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/PingServerReportRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/PingServerReportRequestEvent.java new file mode 100644 index 00000000..ed45ae0f --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/PingServerReportRequestEvent.java @@ -0,0 +1,10 @@ +package pro.gravit.launcher.events.request; + +import pro.gravit.launcher.events.RequestEvent; + +public class PingServerReportRequestEvent extends RequestEvent { + @Override + public String getType() { + return "pingServerReport"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/PingServerRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/PingServerRequestEvent.java new file mode 100644 index 00000000..c4bf8558 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/PingServerRequestEvent.java @@ -0,0 +1,22 @@ +package pro.gravit.launcher.events.request; + +import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.request.management.PingServerReportRequest; + +import java.util.Map; + +public class PingServerRequestEvent extends RequestEvent { + public Map serverMap; + + public PingServerRequestEvent() { + } + + public PingServerRequestEvent(Map serverMap) { + this.serverMap = serverMap; + } + + @Override + public String getType() { + return "pingServer"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ServerStatusRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ServerStatusRequestEvent.java new file mode 100644 index 00000000..ddf97ba8 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ServerStatusRequestEvent.java @@ -0,0 +1,25 @@ +package pro.gravit.launcher.events.request; + +import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.utils.helper.JVMHelper; + +public class ServerStatusRequestEvent extends RequestEvent { + public final String projectName; + public long totalJavaMemory; + public long freeJavaMemory; + + //Latency + public long shortLatency; //Millis + public long middleLatency; //Millis + public long longLatency; //Millis + public long latency; + + public ServerStatusRequestEvent(String projectName) { + this.projectName = projectName; + } + + @Override + public String getType() { + return "serverStatus"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index df6c97ad..3117e929 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -60,8 +60,10 @@ public final class ClientProfile implements Comparable { private String title; @LauncherNetworkAPI private String info; + @Deprecated @LauncherNetworkAPI private String serverAddress; + @Deprecated @LauncherNetworkAPI private int serverPort; @LauncherNetworkAPI @@ -70,6 +72,24 @@ public final class ClientProfile implements Comparable { @LauncherNetworkAPI private String mainClass; + public static class ServerProfile + { + public String name; + public String serverAddress; + public int serverPort; + public boolean isDefault = true; + } + @LauncherNetworkAPI + private List servers = new ArrayList<>(1); + public ServerProfile getDefaultServerProfile() + { + for(ServerProfile profile : servers) + { + if(profile.isDefault) return profile; + } + return null; + } + @Override public int compareTo(ClientProfile o) { return Integer.compare(getSortIndex(), o.getSortIndex()); @@ -131,8 +151,13 @@ public String getMainClass() { return mainClass; } + public List getServers() { + return servers; + } + public String getServerAddress() { - return serverAddress; + ServerProfile profile = getDefaultServerProfile(); + return profile == null ? "localhost" : profile.serverAddress; } public Set getOptional() { @@ -245,9 +270,10 @@ public void pushOptionalClassPath(pushOptionalClassPathCallback callback) throws } public int getServerPort() { - return serverPort; + ServerProfile profile = getDefaultServerProfile(); + return profile == null ? 25565 : profile.serverPort; } - + @Deprecated public InetSocketAddress getServerSocketAddress() { return InetSocketAddress.createUnresolved(getServerAddress(), getServerPort()); } @@ -383,7 +409,8 @@ public enum Version { MC1144("1.14.4", 498), MC115("1.15", 573), MC1151("1.15.1", 575), - MC1152("1.15.2", 578); + MC1152("1.15.2", 578), + MC1161("1.16.1", 736); private static final Map VERSIONS; static { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ExecCommandRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ExecCommandRequest.java deleted file mode 100644 index 69cf6f79..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ExecCommandRequest.java +++ /dev/null @@ -1,19 +0,0 @@ -package pro.gravit.launcher.request.admin; - -import pro.gravit.launcher.events.request.ExecCommandRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.WebSocketRequest; - -public class ExecCommandRequest extends Request implements WebSocketRequest { - - public final String cmd; - - public ExecCommandRequest(String cmd) { - this.cmd = cmd; - } - - @Override - public String getType() { - return "cmdExec"; - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/PingServerReportRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/PingServerReportRequest.java new file mode 100644 index 00000000..1b783bc2 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/PingServerReportRequest.java @@ -0,0 +1,44 @@ +package pro.gravit.launcher.request.management; + +import pro.gravit.launcher.events.request.PingServerReportRequestEvent; +import pro.gravit.launcher.request.Request; + +import java.util.List; + +public class PingServerReportRequest extends Request { + @Override + public String getType() { + return "pingServerReport"; + } + + public static class PingServerReport + { + public final String name; + public final int maxPlayers; // player slots + public final int playersOnline; + public static class UsernameInfo + { + public final String username; + + public UsernameInfo(String username) { + this.username = username; + } + } + //Server addional info + public double tps; //Server tps + public List users; + + public PingServerReport(String name, int maxPlayers, int playersOnline) { + this.name = name; + this.maxPlayers = maxPlayers; + this.playersOnline = playersOnline; + } + } + public final String name; + public final PingServerReport data; + + public PingServerReportRequest(String name, PingServerReport data) { + this.name = name; + this.data = data; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/PingServerRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/PingServerRequest.java new file mode 100644 index 00000000..635caf41 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/PingServerRequest.java @@ -0,0 +1,28 @@ +package pro.gravit.launcher.request.management; + +import pro.gravit.launcher.events.request.PingServerRequestEvent; +import pro.gravit.launcher.request.Request; + +import java.util.ArrayList; +import java.util.List; + +public class PingServerRequest extends Request { + public List serverNames; //May be null + + public PingServerRequest() { + } + + public PingServerRequest(List serverNames) { + this.serverNames = serverNames; + } + + public PingServerRequest(String serverName) { + this.serverNames = new ArrayList<>(); + serverNames.add(serverName); + } + + @Override + public String getType() { + return "pingServer"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/ServerStatusRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/ServerStatusRequest.java new file mode 100644 index 00000000..e40199ca --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/ServerStatusRequest.java @@ -0,0 +1,11 @@ +package pro.gravit.launcher.request.management; + +import pro.gravit.launcher.events.request.ServerStatusRequestEvent; +import pro.gravit.launcher.request.Request; + +public class ServerStatusRequest extends Request { + @Override + public String getType() { + return "serverStatus"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java index d1d5948a..fb4bd479 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -90,7 +90,6 @@ public void registerResults() { results.register("update", UpdateRequestEvent.class); results.register("restoreSession", RestoreSessionRequestEvent.class); results.register("log", LogEvent.class); - results.register("cmdExec", ExecCommandRequestEvent.class); results.register("getAvailabilityAuth", GetAvailabilityAuthRequestEvent.class); results.register("exception", ExceptionEvent.class); results.register("register", RegisterRequestEvent.class); @@ -102,6 +101,9 @@ public void registerResults() { results.register("verifySecureLevelKey", VerifySecureLevelKeyRequestEvent.class); results.register("securityReport", SecurityReportRequestEvent.class); results.register("hardwareReport", HardwareReportRequestEvent.class); + results.register("serverStatus", ServerStatusRequestEvent.class); + results.register("pingServerReport", PingServerReportRequestEvent.class); + results.register("pingServer", PingServerRequestEvent.class); } public void waitIfNotConnected() { diff --git a/LauncherCore/build.gradle b/LauncherCore/build.gradle index cea9711f..893510f4 100644 --- a/LauncherCore/build.gradle +++ b/LauncherCore/build.gradle @@ -67,18 +67,6 @@ task javadocJar(type: Jar) { url = 'https://www.gnu.org/licenses/gpl-3.0.html' } } - developers { - developer { - id = 'gravit' - name = 'Gravit' - email = 'gravit.min@ya.ru' - } - developer { - id = 'zaxar163' - name = 'Zaxar163' - email = 'zahar.vcherachny@yandex.ru' - } - } scm { connection = 'scm:git:https://github.com/GravitLauncher/Launcher.git' developerConnection = 'scm:git:ssh://git@github.com:GravitLauncher/Launcher.git' diff --git a/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java b/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java index c7681e2d..1b289ce8 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java @@ -15,41 +15,50 @@ public class UniversalJsonAdapter implements JsonSerializer, JsonDeseriali public final ProviderMap providerMap; public final String name; public final String PROP_NAME; - public final boolean printErrorIfUnknownType; + public Class defaultClass; public UniversalJsonAdapter(ProviderMap providerMap) { this.providerMap = providerMap; this.name = providerMap.getName(); this.PROP_NAME = "type"; - printErrorIfUnknownType = true; } public UniversalJsonAdapter(ProviderMap providerMap, String PROP_NAME) { this.providerMap = providerMap; this.name = providerMap.getName(); this.PROP_NAME = PROP_NAME; - printErrorIfUnknownType = true; } - public UniversalJsonAdapter(ProviderMap providerMap, String name, String PROP_NAME, boolean printErrorIfUnknownType) { + public UniversalJsonAdapter(ProviderMap providerMap, String name, Class defaultClass) { + this.providerMap = providerMap; + this.name = name; + this.defaultClass = defaultClass; + this.PROP_NAME = "type"; + } + + public UniversalJsonAdapter(ProviderMap providerMap, Class defaultClass) { + this.providerMap = providerMap; + this.defaultClass = defaultClass; + this.name = providerMap.getName(); + this.PROP_NAME = "type"; + } + + public UniversalJsonAdapter(ProviderMap providerMap, String name, String PROP_NAME, Class defaultClass) { this.providerMap = providerMap; this.name = name; this.PROP_NAME = PROP_NAME; - this.printErrorIfUnknownType = printErrorIfUnknownType; - } - - public UniversalJsonAdapter(ProviderMap providerMap, String name, boolean printErrorIfUnknownType) { - this.providerMap = providerMap; - this.name = name; - this.PROP_NAME = "type"; - this.printErrorIfUnknownType = printErrorIfUnknownType; + this.defaultClass = defaultClass; } public R deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); Class cls = providerMap.getClass(typename); if (cls == null) { - if (printErrorIfUnknownType) LogHelper.error("%s %s not found", name, typename); + //if (printErrorIfUnknownType) LogHelper.error("%s %s not found", name, typename); + if(defaultClass != null) + { + return context.deserialize(json, defaultClass); + } return null; } return context.deserialize(json, cls); @@ -63,10 +72,9 @@ public JsonElement serialize(R src, Type typeOfSrc, JsonSerializationContext con if (classPath == null && src instanceof TypeSerializeInterface) { classPath = ((TypeSerializeInterface) src).getType(); } - if (classPath == null) { - if (printErrorIfUnknownType) LogHelper.warning("Class %s type null", src.getClass()); - } else jo.add(PROP_NAME, new JsonPrimitive(classPath)); - + if (classPath != null) { + jo.add(PROP_NAME, new JsonPrimitive(classPath)); + } return jo; } } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index bc7eac8d..eacd42c1 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -6,7 +6,7 @@ public final class Version { public static final int MAJOR = 5; public static final int MINOR = 1; - public static final int PATCH = 6; + public static final int PATCH = 7; public static final int BUILD = 1; public static final Version.Type RELEASE = Type.STABLE; public final int major; diff --git a/ServerWrapper/build.gradle b/ServerWrapper/build.gradle index 9934b0e9..b99abe6b 100644 --- a/ServerWrapper/build.gradle +++ b/ServerWrapper/build.gradle @@ -68,18 +68,6 @@ pack project(':LauncherAuthlib') url = 'https://www.gnu.org/licenses/gpl-3.0.html' } } - developers { - developer { - id = 'gravit' - name = 'Gravit' - email = 'gravit.min@ya.ru' - } - developer { - id = 'zaxar163' - name = 'Zaxar163' - email = 'zahar.vcherachny@yandex.ru' - } - } scm { connection = 'scm:git:https://github.com/GravitLauncher/Launcher.git' diff --git a/build.gradle b/build.gradle index 61f01261..d04df198 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ id 'org.openjfx.javafxplugin' version '0.0.8' apply false } group = 'pro.gravit.launcher' -version = '5.1.6' +version = '5.1.7' apply from: 'props.gradle' diff --git a/modules b/modules index 5a9d5d27..c3e4635e 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 5a9d5d27ea3113bd6f2b899b331dddc61b3b1588 +Subproject commit c3e4635e96c1d7d98f84217eedb732157967b0b5