Перевод конфигов на Json часть 3

Комплируется, пока не работает
This commit is contained in:
Gravit 2018-12-23 23:22:19 +07:00
parent 7c35cb0a34
commit 79891d711e
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
19 changed files with 85 additions and 156 deletions

View file

@ -1,10 +1,10 @@
package ru.gravit.launchserver.auth; package ru.gravit.launchserver.auth;
import ru.gravit.launcher.NeedGarbageCollection; import ru.gravit.launcher.NeedGarbageCollection;
import ru.gravit.launcher.serialize.config.entry.StringConfigEntry;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -60,7 +60,7 @@ public AuthLimiter(LaunchServer srv) {
map = new HashMap<>(); map = new HashMap<>();
excludeIps = new ArrayList<>(); excludeIps = new ArrayList<>();
if (srv.config.authLimitExclusions != null) if (srv.config.authLimitExclusions != null)
srv.config.authLimitExclusions.stream(StringConfigEntry.class).forEach(excludeIps::add); excludeIps.addAll(Arrays.asList(srv.config.authLimitExclusions));
rateLimit = srv.config.authRateLimit; rateLimit = srv.config.authRateLimit;
rateLimitMilis = srv.config.authRateLimitMilis; rateLimitMilis = srv.config.authRateLimitMilis;
} }

View file

@ -3,11 +3,6 @@
import com.mysql.cj.jdbc.MysqlDataSource; import com.mysql.cj.jdbc.MysqlDataSource;
import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import ru.gravit.launcher.serialize.config.ConfigObject;
import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry;
import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry;
import ru.gravit.launcher.serialize.config.entry.IntegerConfigEntry;
import ru.gravit.launcher.serialize.config.entry.StringConfigEntry;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
@ -15,7 +10,7 @@
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
public final class MySQLSourceConfig extends ConfigObject implements AutoCloseable { public final class MySQLSourceConfig implements AutoCloseable {
public static final int TIMEOUT = VerifyHelper.verifyInt( public static final int TIMEOUT = VerifyHelper.verifyInt(
Integer.parseUnsignedInt(System.getProperty("launcher.mysql.idleTimeout", Integer.toString(5000))), Integer.parseUnsignedInt(System.getProperty("launcher.mysql.idleTimeout", Integer.toString(5000))),
@ -28,13 +23,13 @@ public final class MySQLSourceConfig extends ConfigObject implements AutoCloseab
private final String poolName; private final String poolName;
// Config // Config
private final String address; private String address;
private final int port; private int port;
private final boolean useSSL; private boolean useSSL;
private final boolean verifyCertificates; private boolean verifyCertificates;
private final String username; private String username;
private final String password; private String password;
private final String database; private String database;
private String timeZone; private String timeZone;
// Cache // Cache
@ -42,23 +37,8 @@ public final class MySQLSourceConfig extends ConfigObject implements AutoCloseab
private boolean hikari; private boolean hikari;
public MySQLSourceConfig(String poolName, BlockConfigEntry block) { public MySQLSourceConfig(String poolName) {
super(block);
this.poolName = poolName; this.poolName = poolName;
address = VerifyHelper.verify(block.getEntryValue("address", StringConfigEntry.class),
VerifyHelper.NOT_EMPTY, "MySQL address can't be empty");
port = VerifyHelper.verifyInt(block.getEntryValue("port", IntegerConfigEntry.class),
VerifyHelper.range(0, 65535), "Illegal MySQL port");
username = VerifyHelper.verify(block.getEntryValue("username", StringConfigEntry.class),
VerifyHelper.NOT_EMPTY, "MySQL username can't be empty");
password = block.getEntryValue("password", StringConfigEntry.class);
database = VerifyHelper.verify(block.getEntryValue("database", StringConfigEntry.class),
VerifyHelper.NOT_EMPTY, "MySQL database can't be empty");
timeZone = block.hasEntry("timezone") ? VerifyHelper.verify(block.getEntryValue("timezone", StringConfigEntry.class),
VerifyHelper.NOT_EMPTY, "MySQL time zone can't be empty") : null;
// Password shouldn't be verified
useSSL = block.hasEntry("useSSL") ? block.getEntryValue("useSSL", BooleanConfigEntry.class) : true;
verifyCertificates = block.hasEntry("verifyCertificates") ? block.getEntryValue("verifyCertificates", BooleanConfigEntry.class) : false;
} }
@Override @Override

View file

@ -35,7 +35,6 @@ public static void registerProviders() {
// Auth providers that doesn't do nothing :D // Auth providers that doesn't do nothing :D
registerProvider("com.mojang", MojangAuthProvider.class); registerProvider("com.mojang", MojangAuthProvider.class);
registerProvider("mysql", MySQLAuthProvider.class); registerProvider("mysql", MySQLAuthProvider.class);
registerProvider("file", FileAuthProvider.class);
registerProvider("request", RequestAuthProvider.class); registerProvider("request", RequestAuthProvider.class);
registerProvider("json", JsonAuthProvider.class); registerProvider("json", JsonAuthProvider.class);
registredProv = true; registredProv = true;

View file

@ -1,10 +1,8 @@
package ru.gravit.launchserver.command.hash; package ru.gravit.launchserver.command.hash;
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.profiles.ClientProfile.Version; import ru.gravit.launcher.profiles.ClientProfile.Version;
import ru.gravit.launcher.serialize.config.TextConfigReader;
import ru.gravit.launcher.serialize.config.TextConfigWriter;
import ru.gravit.launcher.serialize.config.entry.StringConfigEntry;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.command.CommandException; import ru.gravit.launchserver.command.CommandException;
@ -55,14 +53,12 @@ public void invoke(String... args) throws IOException, CommandException {
ClientProfile client; ClientProfile client;
String profilePath = String.format("ru/gravit/launchserver/defaults/profile%s.cfg", version.name); String profilePath = String.format("ru/gravit/launchserver/defaults/profile%s.cfg", version.name);
try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL(profilePath))) { try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL(profilePath))) {
client = new ClientProfile(TextConfigReader.read(reader, false)); client = Launcher.gson.fromJson(reader,ClientProfile.class);
} }
client.setTitle(dirName); client.setTitle(dirName);
client.block.getEntry("dir", StringConfigEntry.class).setValue(dirName);
client.block.getEntry("title", StringConfigEntry.class).setValue(dirName);
try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir, try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir,
dirName, "cfg"))) { dirName, "cfg"))) {
TextConfigWriter.write(client.block, writer, true); Launcher.gson.toJson(client,writer);
} }
// Finished // Finished

View file

@ -77,13 +77,13 @@ public void reply() throws Exception {
return; return;
} }
if (isClient) { if (isClient) {
Collection<SignedObjectHolder<ClientProfile>> profiles = server.getProfiles(); Collection<ClientProfile> profiles = server.getProfiles();
for (SignedObjectHolder<ClientProfile> p : profiles) { for (ClientProfile p : profiles) {
if (p.object.getTitle().equals(client)) { if (p.getTitle().equals(client)) {
if (!p.object.isWhitelistContains(login)) { if (!p.isWhitelistContains(login)) {
throw new AuthException(server.config.whitelistRejectString); throw new AuthException(server.config.whitelistRejectString);
} }
clientData.profile = p.object; clientData.profile = p;
} }
} }
if (clientData.profile == null) { if (clientData.profile == null) {

View file

@ -64,13 +64,13 @@ public void reply() throws Exception {
AuthProvider.authError(String.format("Illegal result: '%s'", result.username)); AuthProvider.authError(String.format("Illegal result: '%s'", result.username));
return; return;
} }
Collection<SignedObjectHolder<ClientProfile>> profiles = server.getProfiles(); Collection<ClientProfile> profiles = server.getProfiles();
for (SignedObjectHolder<ClientProfile> p : profiles) { for (ClientProfile p : profiles) {
if (p.object.getTitle().equals(client)) { if (p.getTitle().equals(client)) {
if (!p.object.isWhitelistContains(login)) { if (!p.isWhitelistContains(login)) {
throw new AuthException(server.config.whitelistRejectString); throw new AuthException(server.config.whitelistRejectString);
} }
clientData.profile = p.object; clientData.profile = p;
} }
} }
if (clientData.profile == null) { if (clientData.profile == null) {

View file

@ -21,14 +21,14 @@ public void reply() throws Exception {
String client = input.readString(SerializeLimits.MAX_CLIENT); String client = input.readString(SerializeLimits.MAX_CLIENT);
Client clientData = server.sessionManager.getClient(session); Client clientData = server.sessionManager.getClient(session);
if (!clientData.isAuth) requestError("You not auth"); if (!clientData.isAuth) requestError("You not auth");
Collection<SignedObjectHolder<ClientProfile>> profiles = server.getProfiles(); Collection<ClientProfile> profiles = server.getProfiles();
for (SignedObjectHolder<ClientProfile> p : profiles) { for (ClientProfile p : profiles) {
if (p.object.getTitle().equals(client)) { if (p.getTitle().equals(client)) {
if (!p.object.isWhitelistContains(clientData.username)) { if (!p.isWhitelistContains(clientData.username)) {
requestError(server.config.whitelistRejectString); requestError(server.config.whitelistRejectString);
return; return;
} }
clientData.profile = p.object; clientData.profile = p;
writeNoError(output); writeNoError(output);
output.writeBoolean(true); output.writeBoolean(true);
break; break;

View file

@ -1,5 +1,6 @@
package ru.gravit.launchserver.response.update; package ru.gravit.launchserver.response.update;
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.HOutput;
@ -29,11 +30,11 @@ public void reply() throws IOException {
return; return;
} }
writeNoError(output); writeNoError(output);
Collection<SignedObjectHolder<ClientProfile>> profiles = server.getProfiles(); Collection<ClientProfile> profiles = server.getProfiles();
output.writeLength(profiles.size(), 0); output.writeLength(profiles.size(), 0);
for (SignedObjectHolder<ClientProfile> profile : profiles) { for (ClientProfile profile : profiles) {
LogHelper.debug("Writted profile: %s", profile.object.getTitle()); LogHelper.debug("Writted profile: %s", profile.getTitle());
profile.write(output); output.writeString(Launcher.gson.toJson(profile),0);
} }
} }
} }

View file

@ -42,10 +42,9 @@ public void reply() throws IOException {
requestError("Assess denied"); requestError("Assess denied");
return; return;
} }
for (SignedObjectHolder<ClientProfile> p : server.getProfiles()) { for (ClientProfile p : server.getProfiles()) {
ClientProfile profile = p.object; if (!clientData.profile.getTitle().equals(p.getTitle())) continue;
if (!clientData.profile.getTitle().equals(profile.getTitle())) continue; if (!p.isWhitelistContains(clientData.username)) {
if (!profile.isWhitelistContains(clientData.username)) {
requestError("You don't download this folder"); requestError("You don't download this folder");
return; return;
} }

View file

@ -56,13 +56,13 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
AuthProvider.authError(String.format("Illegal result: '%s'", result.username)); AuthProvider.authError(String.format("Illegal result: '%s'", result.username));
return; return;
} }
Collection<SignedObjectHolder<ClientProfile>> profiles = LaunchServer.server.getProfiles(); Collection<ClientProfile> profiles = LaunchServer.server.getProfiles();
for (SignedObjectHolder<ClientProfile> p : profiles) { for (ClientProfile p : profiles) {
if (p.object.getTitle().equals(client)) { if (p.getTitle().equals(client)) {
if (!p.object.isWhitelistContains(login)) { if (!p.isWhitelistContains(login)) {
throw new AuthException(LaunchServer.server.config.whitelistRejectString); throw new AuthException(LaunchServer.server.config.whitelistRejectString);
} }
clientData.profile = p.object; clientData.profile = p;
} }
} }
if (clientData.profile == null) { if (clientData.profile == null) {

View file

@ -1,7 +1,6 @@
package ru.gravit.launchserver.texture; package ru.gravit.launchserver.texture;
import ru.gravit.launcher.profiles.Texture; import ru.gravit.launcher.profiles.Texture;
import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException; import java.io.IOException;
@ -11,10 +10,6 @@
public final class NullTextureProvider extends TextureProvider { public final class NullTextureProvider extends TextureProvider {
private volatile TextureProvider provider; private volatile TextureProvider provider;
public NullTextureProvider(BlockConfigEntry block) {
super(block);
}
@Override @Override
public void close() throws IOException { public void close() throws IOException {
TextureProvider provider = this.provider; TextureProvider provider = this.provider;

View file

@ -2,8 +2,6 @@
import ru.gravit.launcher.Launcher; import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.profiles.Texture; import ru.gravit.launcher.profiles.Texture;
import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry;
import ru.gravit.launcher.serialize.config.entry.StringConfigEntry;
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
@ -32,19 +30,9 @@ private static String getTextureURL(String url, UUID uuid, String username, Stri
} }
// Instance // Instance
private final String skinURL; private String skinURL;
private final String cloakURL; private String cloakURL;
public RequestTextureProvider(BlockConfigEntry block) {
super(block);
skinURL = block.getEntryValue("skinsURL", StringConfigEntry.class);
cloakURL = block.getEntryValue("cloaksURL", StringConfigEntry.class);
// Verify
IOHelper.verifyURL(getTextureURL(skinURL, ZERO_UUID, "skinUsername", ""));
IOHelper.verifyURL(getTextureURL(cloakURL, ZERO_UUID, "cloakUsername", ""));
}
@Override @Override
public void close() { public void close() {

View file

@ -1,8 +1,6 @@
package ru.gravit.launchserver.texture; package ru.gravit.launchserver.texture;
import ru.gravit.launcher.profiles.Texture; import ru.gravit.launcher.profiles.Texture;
import ru.gravit.launcher.serialize.config.ConfigObject;
import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException; import java.io.IOException;
@ -11,40 +9,27 @@
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public abstract class TextureProvider extends ConfigObject implements AutoCloseable { public abstract class TextureProvider implements AutoCloseable {
private static final Map<String, Adapter<TextureProvider>> TEXTURE_PROVIDERS = new ConcurrentHashMap<>(2); private static final Map<String, Class> TEXTURE_PROVIDERS = new ConcurrentHashMap<>(2);
private static boolean registredProv = false; private static boolean registredProv = false;
public static TextureProvider newProvider(String name, BlockConfigEntry block) { public static void registerProvider(String name, Class adapter) {
VerifyHelper.verifyIDName(name);
Adapter<TextureProvider> authHandlerAdapter = VerifyHelper.getMapValue(TEXTURE_PROVIDERS, name,
String.format("Unknown texture provider: '%s'", name));
return authHandlerAdapter.convert(block);
}
public static void registerProvider(String name, Adapter<TextureProvider> adapter) {
VerifyHelper.putIfAbsent(TEXTURE_PROVIDERS, name, Objects.requireNonNull(adapter, "adapter"), VerifyHelper.putIfAbsent(TEXTURE_PROVIDERS, name, Objects.requireNonNull(adapter, "adapter"),
String.format("Texture provider has been already registered: '%s'", name)); String.format("Texture provider has been already registered: '%s'", name));
} }
public static void registerProviders() { public static void registerProviders() {
if (!registredProv) { if (!registredProv) {
registerProvider("null", NullTextureProvider::new); registerProvider("null", NullTextureProvider.class);
registerProvider("void", VoidTextureProvider::new); registerProvider("void", VoidTextureProvider.class);
// Auth providers that doesn't do nothing :D // Auth providers that doesn't do nothing :D
registerProvider("request", RequestTextureProvider::new); registerProvider("request", RequestTextureProvider.class);
registredProv = true; registredProv = true;
} }
} }
protected TextureProvider(BlockConfigEntry block) {
super(block);
}
@Override @Override
public abstract void close() throws IOException; public abstract void close() throws IOException;

View file

@ -1,14 +1,10 @@
package ru.gravit.launchserver.texture; package ru.gravit.launchserver.texture;
import ru.gravit.launcher.profiles.Texture; import ru.gravit.launcher.profiles.Texture;
import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry;
import java.util.UUID; import java.util.UUID;
public final class VoidTextureProvider extends TextureProvider { public final class VoidTextureProvider extends TextureProvider {
public VoidTextureProvider(BlockConfigEntry block) {
super(block);
}
@Override @Override
public void close() { public void close() {

View file

@ -27,10 +27,6 @@
import ru.gravit.launcher.request.uuid.ProfileByUsernameRequest; import ru.gravit.launcher.request.uuid.ProfileByUsernameRequest;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.config.ConfigObject;
import ru.gravit.launcher.serialize.config.TextConfigReader;
import ru.gravit.launcher.serialize.config.TextConfigWriter;
import ru.gravit.launcher.serialize.config.entry.*;
import ru.gravit.launcher.serialize.signed.SignedBytesHolder; import ru.gravit.launcher.serialize.signed.SignedBytesHolder;
import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
import ru.gravit.launcher.serialize.stream.EnumSerializer; import ru.gravit.launcher.serialize.stream.EnumSerializer;
@ -96,18 +92,6 @@ public static void addLauncherClassBindings(Map<String, Object> bindings) {
bindings.put("SignedObjectHolderClass", SignedObjectHolder.class); bindings.put("SignedObjectHolderClass", SignedObjectHolder.class);
bindings.put("EnumSerializerClass", EnumSerializer.class); bindings.put("EnumSerializerClass", EnumSerializer.class);
// Set config serialization class bindings
bindings.put("ConfigObjectClass", ConfigObject.class);
bindings.put("ConfigObjectAdapterClass", ConfigObject.Adapter.class);
bindings.put("BlockConfigEntryClass", BlockConfigEntry.class);
bindings.put("BooleanConfigEntryClass", BooleanConfigEntry.class);
bindings.put("IntegerConfigEntryClass", IntegerConfigEntry.class);
bindings.put("ListConfigEntryClass", ListConfigEntry.class);
bindings.put("StringConfigEntryClass", StringConfigEntry.class);
bindings.put("ConfigEntryTypeClass", ConfigEntry.Type.class);
bindings.put("TextConfigReaderClass", TextConfigReader.class);
bindings.put("TextConfigWriterClass", TextConfigWriter.class);
// Set helper class bindings // Set helper class bindings
bindings.put("CommonHelperClass", CommonHelper.class); bindings.put("CommonHelperClass", CommonHelper.class);
bindings.put("IOHelperClass", IOHelper.class); bindings.put("IOHelperClass", IOHelper.class);

View file

@ -292,7 +292,7 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl
@LauncherAPI @LauncherAPI
public static Process launch( public static Process launch(
SignedObjectHolder<HashedDir> assetHDir, SignedObjectHolder<HashedDir> clientHDir, SignedObjectHolder<HashedDir> assetHDir, SignedObjectHolder<HashedDir> clientHDir,
SignedObjectHolder<ClientProfile> profile, Params params, boolean pipeOutput) throws Throwable { ClientProfile profile, Params params, boolean pipeOutput) throws Throwable {
// Write params file (instead of CLI; Mustdie32 API can't handle command line > 32767 chars) // Write params file (instead of CLI; Mustdie32 API can't handle command line > 32767 chars)
LogHelper.debug("Writing ClientLauncher params"); LogHelper.debug("Writing ClientLauncher params");
CommonHelper.newThread("Client params writter", false, () -> CommonHelper.newThread("Client params writter", false, () ->
@ -314,7 +314,7 @@ public static Process launch(
} }
try (HOutput output = new HOutput(client.getOutputStream())) { try (HOutput output = new HOutput(client.getOutputStream())) {
params.write(output); params.write(output);
profile.write(output); output.writeString(Launcher.gson.toJson(profile),0);
assetHDir.write(output); assetHDir.write(output);
clientHDir.write(output); clientHDir.write(output);
} }
@ -363,7 +363,7 @@ public static Process launch(
} }
// Add classpath and main class // Add classpath and main class
String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString();
Collections.addAll(args, profile.object.getJvmArgs()); Collections.addAll(args, profile.getJvmArgs());
Collections.addAll(args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path Collections.addAll(args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path
Collections.addAll(args, "-javaagent:".concat(pathLauncher)); Collections.addAll(args, "-javaagent:".concat(pathLauncher));
if (wrapper) if (wrapper)
@ -412,7 +412,7 @@ public static void main(String... args) throws Throwable {
// Read and delete params file // Read and delete params file
LogHelper.debug("Reading ClientLauncher params"); LogHelper.debug("Reading ClientLauncher params");
Params params; Params params;
SignedObjectHolder<ClientProfile> profile; ClientProfile profile;
SignedObjectHolder<HashedDir> assetHDir, clientHDir; SignedObjectHolder<HashedDir> assetHDir, clientHDir;
RSAPublicKey publicKey = Launcher.getConfig().publicKey; RSAPublicKey publicKey = Launcher.getConfig().publicKey;
try { try {
@ -420,7 +420,7 @@ public static void main(String... args) throws Throwable {
socket.connect(new InetSocketAddress(SOCKET_HOST, SOCKET_PORT)); socket.connect(new InetSocketAddress(SOCKET_HOST, SOCKET_PORT));
try (HInput input = new HInput(socket.getInputStream())) { try (HInput input = new HInput(socket.getInputStream())) {
params = new Params(input); params = new Params(input);
profile = new SignedObjectHolder<>(input, publicKey, ClientProfile.RO_ADAPTER); profile = gson.fromJson(input.readString(0),ClientProfile.class);
// Read hdirs // Read hdirs
assetHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new); assetHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new);
@ -432,26 +432,26 @@ public static void main(String... args) throws Throwable {
System.exit(-98); System.exit(-98);
return; return;
} }
Launcher.profile = profile.object; Launcher.profile = profile;
Launcher.modulesManager.initModules(); Launcher.modulesManager.initModules();
// Verify ClientLauncher sign and classpath // Verify ClientLauncher sign and classpath
LogHelper.debug("Verifying ClientLauncher sign and classpath"); LogHelper.debug("Verifying ClientLauncher sign and classpath");
//TODO: GO TO DIGEST //TODO: GO TO DIGEST
//SecurityHelper.verifySign(LegacyLauncherRequest.BINARY_PATH, params.launcherDigest, publicKey); //SecurityHelper.verifySign(LegacyLauncherRequest.BINARY_PATH, params.launcherDigest, publicKey);
LinkedList<Path> classPath = resolveClassPathList(params.clientDir, profile.object.getClassPath()); LinkedList<Path> classPath = resolveClassPathList(params.clientDir, profile.getClassPath());
for (Path classpathURL : classPath) { for (Path classpathURL : classPath) {
LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString());
} }
URL[] classpathurls = resolveClassPath(params.clientDir, profile.object.getClassPath()); URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath());
classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader());
Thread.currentThread().setContextClassLoader(classLoader); Thread.currentThread().setContextClassLoader(classLoader);
classLoader.nativePath = params.clientDir.resolve(NATIVES_DIR).toString(); classLoader.nativePath = params.clientDir.resolve(NATIVES_DIR).toString();
PublicURLClassLoader.systemclassloader = classLoader; PublicURLClassLoader.systemclassloader = classLoader;
// Start client with WatchService monitoring // Start client with WatchService monitoring
boolean digest = !profile.object.isUpdateFastCheck(); boolean digest = !profile.isUpdateFastCheck();
LogHelper.debug("Starting JVM and client WatchService"); LogHelper.debug("Starting JVM and client WatchService");
FileNameMatcher assetMatcher = profile.object.getAssetUpdateMatcher(); FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher();
FileNameMatcher clientMatcher = profile.object.getClientUpdateMatcher(); FileNameMatcher clientMatcher = profile.getClientUpdateMatcher();
try (DirWatcher assetWatcher = new DirWatcher(params.assetDir, assetHDir.object, assetMatcher, digest); try (DirWatcher assetWatcher = new DirWatcher(params.assetDir, assetHDir.object, assetMatcher, digest);
DirWatcher clientWatcher = new DirWatcher(params.clientDir, clientHDir.object, clientMatcher, digest)) { DirWatcher clientWatcher = new DirWatcher(params.clientDir, clientHDir.object, clientMatcher, digest)) {
// Verify current state of all dirs // Verify current state of all dirs
@ -467,30 +467,30 @@ public static void main(String... args) throws Throwable {
// Start WatchService, and only then client // Start WatchService, and only then client
CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start(); CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start();
CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start(); CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start();
launch(profile.object, params); launch(profile, params);
} }
} }
@LauncherAPI @LauncherAPI
public void launchLocal(SignedObjectHolder<HashedDir> assetHDir, SignedObjectHolder<HashedDir> clientHDir, public void launchLocal(SignedObjectHolder<HashedDir> assetHDir, SignedObjectHolder<HashedDir> clientHDir,
SignedObjectHolder<ClientProfile> profile, Params params) throws Throwable { ClientProfile profile, Params params) throws Throwable {
RSAPublicKey publicKey = Launcher.getConfig().publicKey; RSAPublicKey publicKey = Launcher.getConfig().publicKey;
LogHelper.debug("Verifying ClientLauncher sign and classpath"); LogHelper.debug("Verifying ClientLauncher sign and classpath");
SecurityHelper.verifySign(LegacyLauncherRequest.BINARY_PATH, params.launcherDigest, publicKey); SecurityHelper.verifySign(LegacyLauncherRequest.BINARY_PATH, params.launcherDigest, publicKey);
LinkedList<Path> classPath = resolveClassPathList(params.clientDir, profile.object.getClassPath()); LinkedList<Path> classPath = resolveClassPathList(params.clientDir, profile.getClassPath());
for (Path classpathURL : classPath) { for (Path classpathURL : classPath) {
LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString());
} }
URL[] classpathurls = resolveClassPath(params.clientDir, profile.object.getClassPath()); URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath());
classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader());
Thread.currentThread().setContextClassLoader(classLoader); Thread.currentThread().setContextClassLoader(classLoader);
classLoader.nativePath = params.clientDir.resolve(NATIVES_DIR).toString(); classLoader.nativePath = params.clientDir.resolve(NATIVES_DIR).toString();
PublicURLClassLoader.systemclassloader = classLoader; PublicURLClassLoader.systemclassloader = classLoader;
// Start client with WatchService monitoring // Start client with WatchService monitoring
boolean digest = !profile.object.isUpdateFastCheck(); boolean digest = !profile.isUpdateFastCheck();
LogHelper.debug("Starting JVM and client WatchService"); LogHelper.debug("Starting JVM and client WatchService");
FileNameMatcher assetMatcher = profile.object.getAssetUpdateMatcher(); FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher();
FileNameMatcher clientMatcher = profile.object.getClientUpdateMatcher(); FileNameMatcher clientMatcher = profile.getClientUpdateMatcher();
try (DirWatcher assetWatcher = new DirWatcher(params.assetDir, assetHDir.object, assetMatcher, digest); try (DirWatcher assetWatcher = new DirWatcher(params.assetDir, assetHDir.object, assetMatcher, digest);
DirWatcher clientWatcher = new DirWatcher(params.clientDir, clientHDir.object, clientMatcher, digest)) { DirWatcher clientWatcher = new DirWatcher(params.clientDir, clientHDir.object, clientMatcher, digest)) {
// Verify current state of all dirs // Verify current state of all dirs
@ -506,7 +506,7 @@ public void launchLocal(SignedObjectHolder<HashedDir> assetHDir, SignedObjectHol
// Start WatchService, and only then client // Start WatchService, and only then client
CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start(); CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start();
CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start(); CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start();
launch(profile.object, params); launch(profile, params);
} }
} }

View file

@ -44,7 +44,7 @@ public class LauncherSettings {
@LauncherAPI @LauncherAPI
public byte[] lastDigest; public byte[] lastDigest;
@LauncherAPI @LauncherAPI
public List<SignedObjectHolder<ClientProfile>> lastProfiles = new LinkedList<>(); public List<ClientProfile> lastProfiles = new LinkedList<>();
@LauncherAPI @LauncherAPI
public Map<String, SignedObjectHolder<HashedDir>> lastHDirs = new HashMap<>(16); public Map<String, SignedObjectHolder<HashedDir>> lastHDirs = new HashMap<>(16);
@ -108,7 +108,7 @@ public void read(HInput input) throws IOException, SignatureException {
lastProfiles.clear(); lastProfiles.clear();
int lastProfilesCount = input.readLength(0); int lastProfilesCount = input.readLength(0);
for (int i = 0; i < lastProfilesCount; i++) { for (int i = 0; i < lastProfilesCount; i++) {
lastProfiles.add(new SignedObjectHolder<>(input, publicKey, ClientProfile.RO_ADAPTER)); lastProfiles.add(Launcher.gson.fromJson(input.readString(0),ClientProfile.class));
} }
lastHDirs.clear(); lastHDirs.clear();
int lastHDirsCount = input.readLength(0); int lastHDirsCount = input.readLength(0);
@ -149,8 +149,8 @@ public void write(HOutput output) throws IOException {
output.writeByteArray(lastDigest, 0); output.writeByteArray(lastDigest, 0);
} }
output.writeLength(lastProfiles.size(), 0); output.writeLength(lastProfiles.size(), 0);
for (SignedObjectHolder<ClientProfile> profile : lastProfiles) { for (ClientProfile profile : lastProfiles) {
profile.write(output); output.writeString(Launcher.gson.toJson(profile),0);
} }
output.writeLength(lastHDirs.size(), 0); output.writeLength(lastHDirs.size(), 0);
for (Map.Entry<String, SignedObjectHolder<HashedDir>> entry : lastHDirs.entrySet()) { for (Map.Entry<String, SignedObjectHolder<HashedDir>> entry : lastHDirs.entrySet()) {

View file

@ -26,11 +26,11 @@
public final class LegacyLauncherRequest extends Request<Result> { public final class LegacyLauncherRequest extends Request<Result> {
public static final class Result { public static final class Result {
@LauncherAPI @LauncherAPI
public final List<SignedObjectHolder<ClientProfile>> profiles; public final List<ClientProfile> profiles;
private final byte[] binary; private final byte[] binary;
private final byte[] sign; private final byte[] sign;
public Result(byte[] binary, byte[] sign, List<SignedObjectHolder<ClientProfile>> profiles) { public Result(byte[] binary, byte[] sign, List<ClientProfile> profiles) {
this.binary = binary == null ? null : binary.clone(); this.binary = binary == null ? null : binary.clone();
this.sign = sign.clone(); this.sign = sign.clone();
this.profiles = Collections.unmodifiableList(profiles); this.profiles = Collections.unmodifiableList(profiles);
@ -116,9 +116,12 @@ protected Result requestDo(HInput input, HOutput output) throws Exception {
// Read clients profiles list // Read clients profiles list
int count = input.readLength(0); int count = input.readLength(0);
List<SignedObjectHolder<ClientProfile>> profiles = new ArrayList<>(count); List<ClientProfile> profiles = new ArrayList<>(count);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
profiles.add(new SignedObjectHolder<>(input, publicKey, ClientProfile.RO_ADAPTER)); {
String prof = input.readString(0);
profiles.add(Launcher.gson.fromJson(prof,ClientProfile.class));
}
// Return request result // Return request result
return new Result(null, sign, profiles); return new Result(null, sign, profiles);

View file

@ -1,5 +1,6 @@
package ru.gravit.launcher.request.update; package ru.gravit.launcher.request.update;
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile;
@ -48,8 +49,10 @@ protected Result requestDo(HInput input, HOutput output) throws Exception {
int count = input.readLength(0); int count = input.readLength(0);
List<ClientProfile> profiles = new ArrayList<>(count); List<ClientProfile> profiles = new ArrayList<>(count);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
profiles.add(new SignedObjectHolder<>(input, config.publicKey, ClientProfile.RO_ADAPTER)); {
String prof = input.readString(0);
profiles.add(Launcher.gson.fromJson(prof,ClientProfile.class));
}
// Return request result // Return request result
return new Result(profiles); return new Result(profiles);
} }