Merge branch 'release/5.1.7'

This commit is contained in:
Gravit 2020-07-15 10:58:38 +07:00
commit 4b894c3ae1
No known key found for this signature in database
GPG key ID: 98A079490768CCE5
54 changed files with 817 additions and 276 deletions

View file

@ -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'

View file

@ -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<String> dirs) throws IOException {

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);
}

View file

@ -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");
}
}

View file

@ -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";

View file

@ -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<String, Object> 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

View file

@ -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));

View file

@ -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<String, ServerInfoEntry> 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;
}
}
}

View file

@ -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<WebSocketServerResponse> 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) {

View file

@ -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");
}
}

View file

@ -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);
}
}
}

View file

@ -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));
}
}

View file

@ -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) {

View file

@ -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());
}
}

View file

@ -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<String> serverNames; //May be null
@Override
public String getType() {
return "pingServer";
}
@Override
public void execute(ChannelHandlerContext ctx, Client client) throws Exception {
Map<String, PingServerReportRequest.PingServerReport> 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));
}
}

View file

@ -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);
}
}

View file

@ -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",

View file

@ -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",

View file

@ -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": [],

View file

@ -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",

View file

@ -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",

View file

@ -6,8 +6,14 @@
"info": "Информация о сервере",
"sortIndex": 0,
"title": "xxxxxxxx",
"serverAddress": "localhost",
"serverPort": 25565,
"servers": [
{
"name": "----",
"serverAddress": "localhost",
"serverPort": 25565,
"isDefault": true
}
],
"update": [
"servers.dat"
],

View file

@ -6,8 +6,14 @@
"info": "Информация о сервере",
"sortIndex": 0,
"title": "xxxxxxxx",
"serverAddress": "localhost",
"serverPort": 25565,
"servers": [
{
"name": "----",
"serverAddress": "localhost",
"serverPort": 25565,
"isDefault": true
}
],
"update": [
"servers.dat"
],

View file

@ -6,8 +6,14 @@
"info": "Информация о сервере",
"sortIndex": 0,
"title": "xxxxxxxx",
"serverAddress": "localhost",
"serverPort": 25565,
"servers": [
{
"name": "----",
"serverAddress": "localhost",
"serverPort": 25565,
"isDefault": true
}
],
"update": [
"servers.dat"
],

View file

@ -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": []
}

View file

@ -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": [],

View file

@ -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": [],

View file

@ -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": [],

View file

@ -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": [],

View file

@ -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": [],

View file

@ -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": [],

View file

@ -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": [],

View file

@ -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'

View file

@ -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<String> 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);
}
}

View file

@ -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'

View file

@ -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";
}
}

View file

@ -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";
}
}

View file

@ -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<String, PingServerReportRequest.PingServerReport> serverMap;
public PingServerRequestEvent() {
}
public PingServerRequestEvent(Map<String, PingServerReportRequest.PingServerReport> serverMap) {
this.serverMap = serverMap;
}
@Override
public String getType() {
return "pingServer";
}
}

View file

@ -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";
}
}

View file

@ -60,8 +60,10 @@ public final class ClientProfile implements Comparable<ClientProfile> {
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<ClientProfile> {
@LauncherNetworkAPI
private String mainClass;
public static class ServerProfile
{
public String name;
public String serverAddress;
public int serverPort;
public boolean isDefault = true;
}
@LauncherNetworkAPI
private List<ServerProfile> 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<ServerProfile> getServers() {
return servers;
}
public String getServerAddress() {
return serverAddress;
ServerProfile profile = getDefaultServerProfile();
return profile == null ? "localhost" : profile.serverAddress;
}
public Set<OptionalFile> 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<String, Version> VERSIONS;
static {

View file

@ -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<ExecCommandRequestEvent> implements WebSocketRequest {
public final String cmd;
public ExecCommandRequest(String cmd) {
this.cmd = cmd;
}
@Override
public String getType() {
return "cmdExec";
}
}

View file

@ -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<PingServerReportRequestEvent> {
@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<UsernameInfo> 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;
}
}

View file

@ -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<PingServerRequestEvent> {
public List<String> serverNames; //May be null
public PingServerRequest() {
}
public PingServerRequest(List<String> serverNames) {
this.serverNames = serverNames;
}
public PingServerRequest(String serverName) {
this.serverNames = new ArrayList<>();
serverNames.add(serverName);
}
@Override
public String getType() {
return "pingServer";
}
}

View file

@ -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<ServerStatusRequestEvent> {
@Override
public String getType() {
return "serverStatus";
}
}

View file

@ -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() {

View file

@ -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'

View file

@ -15,41 +15,50 @@ public class UniversalJsonAdapter<R> implements JsonSerializer<R>, JsonDeseriali
public final ProviderMap<R> providerMap;
public final String name;
public final String PROP_NAME;
public final boolean printErrorIfUnknownType;
public Class<? extends R> defaultClass;
public UniversalJsonAdapter(ProviderMap<R> providerMap) {
this.providerMap = providerMap;
this.name = providerMap.getName();
this.PROP_NAME = "type";
printErrorIfUnknownType = true;
}
public UniversalJsonAdapter(ProviderMap<R> providerMap, String PROP_NAME) {
this.providerMap = providerMap;
this.name = providerMap.getName();
this.PROP_NAME = PROP_NAME;
printErrorIfUnknownType = true;
}
public UniversalJsonAdapter(ProviderMap<R> providerMap, String name, String PROP_NAME, boolean printErrorIfUnknownType) {
public UniversalJsonAdapter(ProviderMap<R> providerMap, String name, Class<? extends R> defaultClass) {
this.providerMap = providerMap;
this.name = name;
this.defaultClass = defaultClass;
this.PROP_NAME = "type";
}
public UniversalJsonAdapter(ProviderMap<R> providerMap, Class<? extends R> defaultClass) {
this.providerMap = providerMap;
this.defaultClass = defaultClass;
this.name = providerMap.getName();
this.PROP_NAME = "type";
}
public UniversalJsonAdapter(ProviderMap<R> providerMap, String name, String PROP_NAME, Class<? extends R> defaultClass) {
this.providerMap = providerMap;
this.name = name;
this.PROP_NAME = PROP_NAME;
this.printErrorIfUnknownType = printErrorIfUnknownType;
}
public UniversalJsonAdapter(ProviderMap<R> 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<? extends R> 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;
}
}

View file

@ -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;

View file

@ -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'

View file

@ -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'

@ -1 +1 @@
Subproject commit 5a9d5d27ea3113bd6f2b899b331dddc61b3b1588
Subproject commit c3e4635e96c1d7d98f84217eedb732157967b0b5