mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[REFACTOR] Moving to log4j2 logger
This commit is contained in:
parent
7277aba7ee
commit
a4596b8c2f
32 changed files with 255 additions and 145 deletions
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.auth;
|
package pro.gravit.launchserver.command.auth;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||||
|
@ -11,6 +13,8 @@
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class AuthCommand extends Command {
|
public final class AuthCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public AuthCommand(LaunchServer server) {
|
public AuthCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
@ -42,6 +46,6 @@ public void invoke(String... args) throws Exception {
|
||||||
UUID uuid = pair.handler.auth(result);
|
UUID uuid = pair.handler.auth(result);
|
||||||
|
|
||||||
// Print auth successful message
|
// Print auth successful message
|
||||||
LogHelper.subInfo("UUID: %s, Username: '%s', Access Token: '%s'", uuid, result.username, result.accessToken);
|
logger.info("UUID: {}, Username: '{}', Access Token: '{}'", uuid, result.username, result.accessToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.auth;
|
package pro.gravit.launchserver.command.auth;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
|
@ -10,6 +12,8 @@
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class UUIDToUsernameCommand extends Command {
|
public final class UUIDToUsernameCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public UUIDToUsernameCommand(LaunchServer server) {
|
public UUIDToUsernameCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
@ -40,6 +44,6 @@ public void invoke(String... args) throws CommandException, IOException {
|
||||||
throw new CommandException("Unknown UUID: " + uuid);
|
throw new CommandException("Unknown UUID: " + uuid);
|
||||||
|
|
||||||
// Print username
|
// Print username
|
||||||
LogHelper.subInfo("Username of player %s: '%s'", uuid, username);
|
logger.info("Username of player {}: '{}'", uuid, username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.auth;
|
package pro.gravit.launchserver.command.auth;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
|
@ -10,6 +12,8 @@
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class UsernameToUUIDCommand extends Command {
|
public final class UsernameToUUIDCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public UsernameToUUIDCommand(LaunchServer server) {
|
public UsernameToUUIDCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
@ -39,6 +43,6 @@ public void invoke(String... args) throws CommandException, IOException {
|
||||||
throw new CommandException(String.format("Unknown username: '%s'", username));
|
throw new CommandException(String.format("Unknown username: '%s'", username));
|
||||||
|
|
||||||
// Print UUID
|
// Print UUID
|
||||||
LogHelper.subInfo("UUID of player '%s': %s", username, uuid);
|
logger.info("UUID of player '{}': {}", username, uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.basic;
|
package pro.gravit.launchserver.command.basic;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bouncycastle.cert.X509CertificateHolder;
|
import org.bouncycastle.cert.X509CertificateHolder;
|
||||||
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
@ -15,6 +17,7 @@
|
||||||
|
|
||||||
public class TestCommand extends Command {
|
public class TestCommand extends Command {
|
||||||
private NettyServerSocketHandler handler = null;
|
private NettyServerSocketHandler handler = null;
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public TestCommand(LaunchServer server) {
|
public TestCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
@ -72,10 +75,10 @@ public void invoke(String... args) throws Exception {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
if ((i % 10000) == 0) {
|
if ((i % 10000) == 0) {
|
||||||
LogHelper.info("Completed %d requests", i);
|
logger.info("Completed {} requests", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LogHelper.info("Completed all requests. Time %d ms", System.currentTimeMillis() - startTime);
|
logger.info("Completed all requests. Time {} ms", System.currentTimeMillis() - startTime);
|
||||||
};
|
};
|
||||||
for (int i = 0; i < 7; ++i) {
|
for (int i = 0; i < 7; ++i) {
|
||||||
CommonHelper.newThread(String.format("Stresser #%d", i), true, runnable).start();
|
CommonHelper.newThread(String.format("Stresser #%d", i), true, runnable).start();
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.hash;
|
package pro.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
@ -10,6 +12,7 @@
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
public final class DownloadAssetCommand extends Command {
|
public final class DownloadAssetCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public DownloadAssetCommand(LaunchServer server) {
|
public DownloadAssetCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
@ -34,16 +37,16 @@ public void invoke(String... args) throws Exception {
|
||||||
Path assetDir = server.updatesDir.resolve(dirName);
|
Path assetDir = server.updatesDir.resolve(dirName);
|
||||||
|
|
||||||
// Create asset dir
|
// Create asset dir
|
||||||
LogHelper.subInfo("Creating asset dir: '%s'", dirName);
|
logger.info("Creating asset dir: '{}'", dirName);
|
||||||
Files.createDirectory(assetDir);
|
Files.createDirectory(assetDir);
|
||||||
|
|
||||||
// Download required asset
|
// Download required asset
|
||||||
LogHelper.subInfo("Downloading asset, it may take some time");
|
logger.info("Downloading asset, it may take some time");
|
||||||
//HttpDownloader.downloadZip(server.mirrorManager.getDefaultMirror().getAssetsURL(version.name), assetDir);
|
//HttpDownloader.downloadZip(server.mirrorManager.getDefaultMirror().getAssetsURL(version.name), assetDir);
|
||||||
server.mirrorManager.downloadZip(assetDir, "assets/%s.zip", versionName);
|
server.mirrorManager.downloadZip(assetDir, "assets/%s.zip", versionName);
|
||||||
|
|
||||||
// Finished
|
// Finished
|
||||||
server.syncUpdatesDir(Collections.singleton(dirName));
|
server.syncUpdatesDir(Collections.singleton(dirName));
|
||||||
LogHelper.subInfo("Asset successfully downloaded: '%s'", dirName);
|
logger.info("Asset successfully downloaded: '{}'", dirName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,6 @@ public void invoke(String... args) throws IOException, CommandException {
|
||||||
// Finished
|
// Finished
|
||||||
server.syncProfilesDir();
|
server.syncProfilesDir();
|
||||||
server.syncUpdatesDir(Collections.singleton(dirName));
|
server.syncUpdatesDir(Collections.singleton(dirName));
|
||||||
LogHelper.subInfo("Client successfully downloaded: '%s'", dirName);
|
logger.info("Client successfully downloaded: '{}'", dirName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import pro.gravit.launcher.Launcher;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.utils.command.CommandException;
|
import pro.gravit.utils.command.CommandException;
|
||||||
|
@ -22,8 +25,8 @@
|
||||||
public final class IndexAssetCommand extends Command {
|
public final class IndexAssetCommand extends Command {
|
||||||
public static final String INDEXES_DIR = "indexes";
|
public static final String INDEXES_DIR = "indexes";
|
||||||
public static final String OBJECTS_DIR = "objects";
|
public static final String OBJECTS_DIR = "objects";
|
||||||
private static final Gson gson = new Gson();
|
|
||||||
private static final String JSON_EXTENSION = ".json";
|
private static final String JSON_EXTENSION = ".json";
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public IndexAssetCommand(LaunchServer server) {
|
public IndexAssetCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
@ -59,26 +62,26 @@ public void invoke(String... args) throws Exception {
|
||||||
throw new CommandException("Unindexed and indexed asset dirs can't be same");
|
throw new CommandException("Unindexed and indexed asset dirs can't be same");
|
||||||
|
|
||||||
// Create new asset dir
|
// Create new asset dir
|
||||||
LogHelper.subInfo("Creating indexed asset dir: '%s'", outputAssetDirName);
|
logger.info("Creating indexed asset dir: '{}'", outputAssetDirName);
|
||||||
Files.createDirectory(outputAssetDir);
|
Files.createDirectory(outputAssetDir);
|
||||||
|
|
||||||
// Index objects
|
// Index objects
|
||||||
JsonObject objects = new JsonObject();
|
JsonObject objects = new JsonObject();
|
||||||
LogHelper.subInfo("Indexing objects");
|
logger.info("Indexing objects");
|
||||||
IOHelper.walk(inputAssetDir, new IndexAssetVisitor(objects, inputAssetDir, outputAssetDir), false);
|
IOHelper.walk(inputAssetDir, new IndexAssetVisitor(objects, inputAssetDir, outputAssetDir), false);
|
||||||
|
|
||||||
// Write index file
|
// Write index file
|
||||||
LogHelper.subInfo("Writing asset index file: '%s'", indexFileName);
|
logger.info("Writing asset index file: '{}'", indexFileName);
|
||||||
|
|
||||||
try (BufferedWriter writer = IOHelper.newWriter(resolveIndexFile(outputAssetDir, indexFileName))) {
|
try (BufferedWriter writer = IOHelper.newWriter(resolveIndexFile(outputAssetDir, indexFileName))) {
|
||||||
JsonObject result = new JsonObject();
|
JsonObject result = new JsonObject();
|
||||||
result.add("objects", objects);
|
result.add("objects", objects);
|
||||||
writer.write(gson.toJson(result));
|
writer.write(Launcher.gsonManager.gson.toJson(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finished
|
// Finished
|
||||||
server.syncUpdatesDir(Collections.singleton(outputAssetDirName));
|
server.syncUpdatesDir(Collections.singleton(outputAssetDirName));
|
||||||
LogHelper.subInfo("Asset successfully indexed: '%s'", inputAssetDirName);
|
logger.info("Asset successfully indexed: '{}'", inputAssetDirName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class IndexObject {
|
public static class IndexObject {
|
||||||
|
@ -91,7 +94,7 @@ public IndexObject(long size, String hash) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class IndexAssetVisitor extends SimpleFileVisitor<Path> {
|
private final class IndexAssetVisitor extends SimpleFileVisitor<Path> {
|
||||||
private final JsonObject objects;
|
private final JsonObject objects;
|
||||||
private final Path inputAssetDir;
|
private final Path inputAssetDir;
|
||||||
private final Path outputAssetDir;
|
private final Path outputAssetDir;
|
||||||
|
@ -105,12 +108,12 @@ private IndexAssetVisitor(JsonObject objects, Path inputAssetDir, Path outputAss
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||||
String name = IOHelper.toString(inputAssetDir.relativize(file));
|
String name = IOHelper.toString(inputAssetDir.relativize(file));
|
||||||
LogHelper.subInfo("Indexing: '%s'", name);
|
logger.info("Indexing: '{}'", name);
|
||||||
|
|
||||||
// Add to index and copy file
|
// Add to index and copy file
|
||||||
String digest = SecurityHelper.toHex(SecurityHelper.digest(DigestAlgorithm.SHA1, file));
|
String digest = SecurityHelper.toHex(SecurityHelper.digest(DigestAlgorithm.SHA1, file));
|
||||||
IndexObject obj = new IndexObject(attrs.size(), digest);
|
IndexObject obj = new IndexObject(attrs.size(), digest);
|
||||||
objects.add(name, gson.toJsonTree(obj));
|
objects.add(name, Launcher.gsonManager.gson.toJsonTree(obj));
|
||||||
IOHelper.copy(file, resolveObjectFile(outputAssetDir, digest));
|
IOHelper.copy(file, resolveObjectFile(outputAssetDir, digest));
|
||||||
|
|
||||||
// Continue visiting
|
// Continue visiting
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.hash;
|
package pro.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launcher.Launcher;
|
import pro.gravit.launcher.Launcher;
|
||||||
import pro.gravit.launcher.hasher.HashedDir;
|
import pro.gravit.launcher.hasher.HashedDir;
|
||||||
import pro.gravit.launcher.profiles.ClientProfile;
|
import pro.gravit.launcher.profiles.ClientProfile;
|
||||||
|
@ -20,6 +22,8 @@
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class SaveProfilesCommand extends Command {
|
public class SaveProfilesCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public SaveProfilesCommand(LaunchServer server) {
|
public SaveProfilesCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
@ -147,7 +151,6 @@ public static void saveProfile(ClientProfile profile, Path path) throws IOExcept
|
||||||
action = new OptionalActionClientArgs(Arrays.asList(list));
|
action = new OptionalActionClientArgs(Arrays.asList(list));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LogHelper.warning("Not converted optional %s with type %s. Type unknown", file.name, file.type.toString());
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
file.actions.add(action);
|
file.actions.add(action);
|
||||||
|
@ -175,7 +178,7 @@ public void invoke(String... args) throws Exception {
|
||||||
for (String profileName : args) {
|
for (String profileName : args) {
|
||||||
Path profilePath = server.profilesDir.resolve(profileName.concat(".json"));
|
Path profilePath = server.profilesDir.resolve(profileName.concat(".json"));
|
||||||
if (!Files.exists(profilePath)) {
|
if (!Files.exists(profilePath)) {
|
||||||
LogHelper.error("Profile %s not found", profilePath.toString());
|
logger.error("Profile {} not found", profilePath.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ClientProfile profile;
|
ClientProfile profile;
|
||||||
|
@ -183,7 +186,7 @@ public void invoke(String... args) throws Exception {
|
||||||
profile = Launcher.gsonManager.configGson.fromJson(reader, ClientProfile.class);
|
profile = Launcher.gsonManager.configGson.fromJson(reader, ClientProfile.class);
|
||||||
}
|
}
|
||||||
saveProfile(profile, profilePath);
|
saveProfile(profile, profilePath);
|
||||||
LogHelper.info("Profile %s save successful", profilePath.toString());
|
logger.info("Profile {} save successful", profilePath.toString());
|
||||||
}
|
}
|
||||||
server.syncProfilesDir();
|
server.syncProfilesDir();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.hash;
|
package pro.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
@ -7,6 +9,7 @@
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class SyncBinariesCommand extends Command {
|
public final class SyncBinariesCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
public SyncBinariesCommand(LaunchServer server) {
|
public SyncBinariesCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
@ -24,6 +27,6 @@ public String getUsageDescription() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws IOException {
|
public void invoke(String... args) throws IOException {
|
||||||
server.syncLauncherBinaries();
|
server.syncLauncherBinaries();
|
||||||
LogHelper.subInfo("Binaries successfully resynced");
|
logger.info("Binaries successfully resynced");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.hash;
|
package pro.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
@ -7,6 +9,7 @@
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class SyncProfilesCommand extends Command {
|
public final class SyncProfilesCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
public SyncProfilesCommand(LaunchServer server) {
|
public SyncProfilesCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
@ -24,6 +27,6 @@ public String getUsageDescription() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws IOException {
|
public void invoke(String... args) throws IOException {
|
||||||
server.syncProfilesDir();
|
server.syncProfilesDir();
|
||||||
LogHelper.subInfo("Profiles successfully resynced");
|
logger.info("Profiles successfully resynced");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.hash;
|
package pro.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
@ -7,6 +9,8 @@
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class SyncUPCommand extends Command {
|
public final class SyncUPCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public SyncUPCommand(LaunchServer server) {
|
public SyncUPCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
@ -24,9 +28,9 @@ public String getUsageDescription() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws IOException {
|
public void invoke(String... args) throws IOException {
|
||||||
server.syncProfilesDir();
|
server.syncProfilesDir();
|
||||||
LogHelper.subInfo("Profiles successfully resynced");
|
logger.info("Profiles successfully resynced");
|
||||||
|
|
||||||
server.syncUpdatesDir(null);
|
server.syncUpdatesDir(null);
|
||||||
LogHelper.subInfo("Updates dir successfully resynced");
|
logger.info("Updates dir successfully resynced");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.hash;
|
package pro.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
@ -10,6 +12,8 @@
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public final class SyncUpdatesCommand extends Command {
|
public final class SyncUpdatesCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public SyncUpdatesCommand(LaunchServer server) {
|
public SyncUpdatesCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
@ -34,6 +38,6 @@ public void invoke(String... args) throws IOException {
|
||||||
|
|
||||||
// Hash updates dir
|
// Hash updates dir
|
||||||
server.syncUpdatesDir(dirs);
|
server.syncUpdatesDir(dirs);
|
||||||
LogHelper.subInfo("Updates dir successfully resynced");
|
logger.info("Updates dir successfully resynced");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.utils.command.CommandException;
|
import pro.gravit.utils.command.CommandException;
|
||||||
|
@ -16,6 +18,8 @@
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public final class UnindexAssetCommand extends Command {
|
public final class UnindexAssetCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public UnindexAssetCommand(LaunchServer server) {
|
public UnindexAssetCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
@ -42,21 +46,21 @@ public void invoke(String... args) throws Exception {
|
||||||
throw new CommandException("Indexed and unindexed asset dirs can't be same");
|
throw new CommandException("Indexed and unindexed asset dirs can't be same");
|
||||||
|
|
||||||
// Create new asset dir
|
// Create new asset dir
|
||||||
LogHelper.subInfo("Creating unindexed asset dir: '%s'", outputAssetDirName);
|
logger.info("Creating unindexed asset dir: '{}'", outputAssetDirName);
|
||||||
Files.createDirectory(outputAssetDir);
|
Files.createDirectory(outputAssetDir);
|
||||||
|
|
||||||
// Read JSON file
|
// Read JSON file
|
||||||
JsonObject objects;
|
JsonObject objects;
|
||||||
LogHelper.subInfo("Reading asset index file: '%s'", indexFileName);
|
logger.info("Reading asset index file: '{}'", indexFileName);
|
||||||
try (BufferedReader reader = IOHelper.newReader(IndexAssetCommand.resolveIndexFile(inputAssetDir, indexFileName))) {
|
try (BufferedReader reader = IOHelper.newReader(IndexAssetCommand.resolveIndexFile(inputAssetDir, indexFileName))) {
|
||||||
objects = JsonParser.parseReader(reader).getAsJsonObject().get("objects").getAsJsonObject();
|
objects = JsonParser.parseReader(reader).getAsJsonObject().get("objects").getAsJsonObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore objects
|
// Restore objects
|
||||||
LogHelper.subInfo("Unindexing %d objects", objects.size());
|
logger.info("Unindexing {} objects", objects.size());
|
||||||
for (Map.Entry<String, JsonElement> member : objects.entrySet()) {
|
for (Map.Entry<String, JsonElement> member : objects.entrySet()) {
|
||||||
String name = member.getKey();
|
String name = member.getKey();
|
||||||
LogHelper.subInfo("Unindexing: '%s'", name);
|
logger.info("Unindexing: '{}'", name);
|
||||||
|
|
||||||
// Copy hashed file to target
|
// Copy hashed file to target
|
||||||
String hash = member.getValue().getAsJsonObject().get("hash").getAsString();
|
String hash = member.getValue().getAsJsonObject().get("hash").getAsString();
|
||||||
|
@ -66,6 +70,6 @@ public void invoke(String... args) throws Exception {
|
||||||
|
|
||||||
// Finished
|
// Finished
|
||||||
server.syncUpdatesDir(Collections.singleton(outputAssetDirName));
|
server.syncUpdatesDir(Collections.singleton(outputAssetDirName));
|
||||||
LogHelper.subInfo("Asset successfully unindexed: '%s'", inputAssetDirName);
|
logger.info("Asset successfully unindexed: '{}'", inputAssetDirName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.service;
|
package pro.gravit.launchserver.command.service;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.launchserver.socket.Client;
|
import pro.gravit.launchserver.socket.Client;
|
||||||
|
@ -11,6 +13,8 @@
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
|
||||||
public class ClientsCommand extends Command {
|
public class ClientsCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public ClientsCommand(LaunchServer server) {
|
public ClientsCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
@ -31,22 +35,22 @@ public void invoke(String... args) {
|
||||||
service.channels.forEach((channel -> {
|
service.channels.forEach((channel -> {
|
||||||
WebSocketFrameHandler frameHandler = channel.pipeline().get(WebSocketFrameHandler.class);
|
WebSocketFrameHandler frameHandler = channel.pipeline().get(WebSocketFrameHandler.class);
|
||||||
if(frameHandler == null) {
|
if(frameHandler == null) {
|
||||||
LogHelper.info("Channel %s", IOHelper.getIP(channel.remoteAddress()));
|
logger.info("Channel {}", IOHelper.getIP(channel.remoteAddress()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Client client = frameHandler.getClient();
|
Client client = frameHandler.getClient();
|
||||||
String ip = frameHandler.context.ip != null ? frameHandler.context.ip : IOHelper.getIP(channel.remoteAddress());
|
String ip = frameHandler.context.ip != null ? frameHandler.context.ip : IOHelper.getIP(channel.remoteAddress());
|
||||||
if (!client.isAuth)
|
if (!client.isAuth)
|
||||||
LogHelper.info("Channel %s | connectUUID %s | checkSign %s", ip, frameHandler.getConnectUUID(), client.checkSign ? "true" : "false");
|
logger.info("Channel {} | connectUUID {} | checkSign {}", ip, frameHandler.getConnectUUID(), client.checkSign ? "true" : "false");
|
||||||
else {
|
else {
|
||||||
LogHelper.info("Client name %s | ip %s | connectUUID %s", client.username == null ? "null" : client.username, ip, frameHandler.getConnectUUID());
|
logger.info("Client name {} | ip {} | connectUUID {}", client.username == null ? "null" : client.username, ip, frameHandler.getConnectUUID());
|
||||||
LogHelper.subInfo("userUUID: %s | session %s", client.uuid == null ? "null" : client.uuid.toString(), client.session == null ? "null" : client.session);
|
logger.info("userUUID: {} | session {}", client.uuid == null ? "null" : client.uuid.toString(), client.session == null ? "null" : client.session);
|
||||||
LogHelper.subInfo("Data: checkSign %s | auth_id %s", client.checkSign ? "true" : "false",
|
logger.info("Data: checkSign {} | auth_id {}", client.checkSign ? "true" : "false",
|
||||||
client.auth_id);
|
client.auth_id);
|
||||||
if (client.trustLevel != null) {
|
if (client.trustLevel != null) {
|
||||||
LogHelper.subInfo("trustLevel | key %s | pubkey %s", client.trustLevel.keyChecked ? "checked" : "unchecked", client.trustLevel.publicKey == null ? "null" : Base64.getEncoder().encode(client.trustLevel.publicKey));
|
logger.info("trustLevel | key {} | pubkey {}", client.trustLevel.keyChecked ? "checked" : "unchecked", client.trustLevel.publicKey == null ? "null" : Base64.getEncoder().encode(client.trustLevel.publicKey));
|
||||||
}
|
}
|
||||||
LogHelper.subInfo("Permissions: %s (permissions %d | flags %d)", client.permissions == null ? "null" : client.permissions.toString(), client.permissions == null ? 0 : client.permissions.permissions, client.permissions == null ? 0 : client.permissions.flags);
|
logger.info("Permissions: {} (permissions {} | flags {})", client.permissions == null ? "null" : client.permissions.toString(), client.permissions == null ? 0 : client.permissions.permissions, client.permissions == null ? 0 : client.permissions.flags);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.service;
|
package pro.gravit.launchserver.command.service;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launcher.Launcher;
|
import pro.gravit.launcher.Launcher;
|
||||||
import pro.gravit.launcher.NeedGarbageCollection;
|
import pro.gravit.launcher.NeedGarbageCollection;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
@ -15,6 +17,8 @@
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
public class ComponentCommand extends Command {
|
public class ComponentCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public ComponentCommand(LaunchServer server) {
|
public ComponentCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
childCommands.put("unload", new UnloadCommand());
|
childCommands.put("unload", new UnloadCommand());
|
||||||
|
@ -33,14 +37,14 @@ public void invoke(String... args) throws Exception {
|
||||||
if (componentName == null) throw new IllegalArgumentException("Must set componentName");
|
if (componentName == null) throw new IllegalArgumentException("Must set componentName");
|
||||||
Component component = server.config.components.get(componentName);
|
Component component = server.config.components.get(componentName);
|
||||||
if (component == null) {
|
if (component == null) {
|
||||||
LogHelper.error("Component %s not found", componentName);
|
logger.error("Component {} not found", componentName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (component instanceof AutoCloseable) {
|
if (component instanceof AutoCloseable) {
|
||||||
((AutoCloseable) component).close();
|
((AutoCloseable) component).close();
|
||||||
}
|
}
|
||||||
server.config.components.remove(componentName);
|
server.config.components.remove(componentName);
|
||||||
LogHelper.info("Component %s unloaded. Use 'config launchserver save' to save changes");
|
logger.info("Component %s unloaded. Use 'config launchserver save' to save changes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private class LoadCommand extends SubCommand {
|
private class LoadCommand extends SubCommand {
|
||||||
|
@ -54,7 +58,7 @@ public void invoke(String... args) throws Exception {
|
||||||
String componentName = args[0];
|
String componentName = args[0];
|
||||||
Class<? extends Component> componentClass = Component.providers.getClass(args[1]);
|
Class<? extends Component> componentClass = Component.providers.getClass(args[1]);
|
||||||
if(componentClass == null) {
|
if(componentClass == null) {
|
||||||
LogHelper.error("Component type %s not registered", componentName);
|
logger.error("Component type {} not registered", componentName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -69,9 +73,9 @@ public void invoke(String... args) throws Exception {
|
||||||
component.setComponentName(componentName);
|
component.setComponentName(componentName);
|
||||||
server.config.components.put(componentName, component);
|
server.config.components.put(componentName, component);
|
||||||
component.init(server);
|
component.init(server);
|
||||||
LogHelper.info("Component %s ready. Use 'config launchserver save' to save changes");
|
logger.info("Component %s ready. Use 'config launchserver save' to save changes");
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
LogHelper.error(throwable);
|
logger.error(throwable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,10 +91,10 @@ public String getUsageDescription() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printHelp() {
|
public void printHelp() {
|
||||||
LogHelper.info("Print help for component:");
|
logger.info("Print help for component:");
|
||||||
LogHelper.subInfo("component unload [componentName]");
|
logger.info("component unload [componentName]");
|
||||||
LogHelper.subInfo("component load [componentName] [filename]");
|
logger.info("component load [componentName] [filename]");
|
||||||
LogHelper.subInfo("component gc [componentName]");
|
logger.info("component gc [componentName]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package pro.gravit.launchserver.command.service;
|
package pro.gravit.launchserver.command.service;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launcher.request.management.PingServerReportRequest;
|
import pro.gravit.launcher.request.management.PingServerReportRequest;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
public class PingServersCommand extends Command {
|
public class PingServersCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public PingServersCommand(LaunchServer server) {
|
public PingServersCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
@ -23,10 +27,10 @@ public String getUsageDescription() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) {
|
public void invoke(String... args) {
|
||||||
server.pingServerManager.map.forEach((name, data) -> {
|
server.pingServerManager.map.forEach((name, data) -> {
|
||||||
LogHelper.info("[%s] online %d / %d", name, data.lastReport == null ? -1 : data.lastReport.playersOnline, data.lastReport == null ? -1 : data.lastReport.maxPlayers);
|
logger.info("[{}] online {} / {}", name, data.lastReport == null ? -1 : data.lastReport.playersOnline, data.lastReport == null ? -1 : data.lastReport.maxPlayers);
|
||||||
if (data.lastReport != null && data.lastReport.users != null) {
|
if (data.lastReport != null && data.lastReport.users != null) {
|
||||||
for (PingServerReportRequest.PingServerReport.UsernameInfo user : data.lastReport.users) {
|
for (PingServerReportRequest.PingServerReport.UsernameInfo user : data.lastReport.users) {
|
||||||
LogHelper.subInfo("User %s", user.username == null ? "null" : user.username);
|
logger.info("User {}", user.username == null ? "null" : user.username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.service;
|
package pro.gravit.launchserver.command.service;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.fusesource.jansi.Ansi;
|
import org.fusesource.jansi.Ansi;
|
||||||
import pro.gravit.launcher.profiles.ClientProfile;
|
import pro.gravit.launcher.profiles.ClientProfile;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
@ -26,13 +28,19 @@
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
public class SecurityCheckCommand extends Command {
|
public class SecurityCheckCommand extends Command {
|
||||||
|
private static transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public SecurityCheckCommand(LaunchServer server) {
|
public SecurityCheckCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printCheckResult(LogHelper.Level level, String module, String comment, Boolean status) {
|
public static void printCheckResult(String module, String comment, Boolean status) {
|
||||||
LogHelper.log(level, String.format("[%s] %s - %s", module, comment, status == null ? "WARN" : (status ? "OK" : "FAIL")), false);
|
logger.info(String.format("[%s] %s - %s", module, comment, status == null ? "WARN" : (status ? "OK" : "FAIL")), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static void printCheckResult(LogHelper.Level level, String module, String comment, Boolean status) {
|
||||||
|
printCheckResult(module, comment, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,66 +58,66 @@ public void invoke(String... args) {
|
||||||
LaunchServerConfig config = server.config;
|
LaunchServerConfig config = server.config;
|
||||||
config.auth.forEach((name, pair) -> {
|
config.auth.forEach((name, pair) -> {
|
||||||
if (pair.provider instanceof AcceptAuthProvider) {
|
if (pair.provider instanceof AcceptAuthProvider) {
|
||||||
printCheckResult(LogHelper.Level.INFO, String.format("auth.%s.provider", name), "Accept auth provider", false);
|
printCheckResult(String.format("auth.%s.provider", name), "Accept auth provider", false);
|
||||||
} else {
|
} else {
|
||||||
printCheckResult(LogHelper.Level.INFO, String.format("auth.%s.provider", name), "", true);
|
printCheckResult(String.format("auth.%s.provider", name), "", true);
|
||||||
}
|
}
|
||||||
if (pair.handler instanceof MemoryAuthHandler) {
|
if (pair.handler instanceof MemoryAuthHandler) {
|
||||||
printCheckResult(LogHelper.Level.INFO, String.format("auth.%s.handler", name), "MemoryAuthHandler test-only", false);
|
printCheckResult(String.format("auth.%s.handler", name), "MemoryAuthHandler test-only", false);
|
||||||
} else {
|
} else {
|
||||||
printCheckResult(LogHelper.Level.INFO, String.format("auth.%s.handler", name), "", true);
|
printCheckResult(String.format("auth.%s.handler", name), "", true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (config.protectHandler instanceof NoProtectHandler) {
|
if (config.protectHandler instanceof NoProtectHandler) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "protectHandler", "protectHandler none", false);
|
printCheckResult("protectHandler", "protectHandler none", false);
|
||||||
} else if (config.protectHandler instanceof AdvancedProtectHandler) {
|
} else if (config.protectHandler instanceof AdvancedProtectHandler) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "protectHandler", "", true);
|
printCheckResult("protectHandler", "", true);
|
||||||
if (!((AdvancedProtectHandler) config.protectHandler).enableHardwareFeature) {
|
if (!((AdvancedProtectHandler) config.protectHandler).enableHardwareFeature) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "protectHandler.hardwareId", "you can improve security by using hwid provider", null);
|
printCheckResult("protectHandler.hardwareId", "you can improve security by using hwid provider", null);
|
||||||
} else {
|
} else {
|
||||||
printCheckResult(LogHelper.Level.INFO, "protectHandler.hardwareId", "", true);
|
printCheckResult("protectHandler.hardwareId", "", true);
|
||||||
}
|
}
|
||||||
} else if (config.protectHandler instanceof StdProtectHandler) {
|
} else if (config.protectHandler instanceof StdProtectHandler) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "protectHandler", "you can improve security by using advanced", null);
|
printCheckResult("protectHandler", "you can improve security by using advanced", null);
|
||||||
} else {
|
} else {
|
||||||
printCheckResult(LogHelper.Level.INFO, "protectHandler", "unknown protectHandler", null);
|
printCheckResult("protectHandler", "unknown protectHandler", null);
|
||||||
}
|
}
|
||||||
if (config.netty.address.startsWith("ws://")) {
|
if (config.netty.address.startsWith("ws://")) {
|
||||||
if (config.netty.ipForwarding)
|
if (config.netty.ipForwarding)
|
||||||
printCheckResult(LogHelper.Level.INFO, "netty.ipForwarding", "ipForwarding may be used to spoofing ip", null);
|
printCheckResult("netty.ipForwarding", "ipForwarding may be used to spoofing ip", null);
|
||||||
printCheckResult(LogHelper.Level.INFO, "netty.address", "websocket connection not secure", false);
|
printCheckResult("netty.address", "websocket connection not secure", false);
|
||||||
} else if (config.netty.address.startsWith("wss://")) {
|
} else if (config.netty.address.startsWith("wss://")) {
|
||||||
if (!config.netty.ipForwarding)
|
if (!config.netty.ipForwarding)
|
||||||
printCheckResult(LogHelper.Level.INFO, "netty.ipForwarding", "ipForwarding not enabled. authLimiter may be get incorrect ip", null);
|
printCheckResult("netty.ipForwarding", "ipForwarding not enabled. authLimiter may be get incorrect ip", null);
|
||||||
printCheckResult(LogHelper.Level.INFO, "netty.address", "", true);
|
printCheckResult("netty.address", "", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.netty.sendExceptionEnabled) {
|
if (config.netty.sendExceptionEnabled) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "netty.sendExceptionEnabled", "recommend \"false\" in production", false);
|
printCheckResult("netty.sendExceptionEnabled", "recommend \"false\" in production", false);
|
||||||
} else {
|
} else {
|
||||||
printCheckResult(LogHelper.Level.INFO, "netty.sendExceptionEnabled", "", true);
|
printCheckResult("netty.sendExceptionEnabled", "", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.netty.launcherURL.startsWith("http://")) {
|
if (config.netty.launcherURL.startsWith("http://")) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "netty.launcherUrl", "launcher jar download connection not secure", false);
|
printCheckResult("netty.launcherUrl", "launcher jar download connection not secure", false);
|
||||||
} else if (config.netty.launcherURL.startsWith("https://")) {
|
} else if (config.netty.launcherURL.startsWith("https://")) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "netty.launcherUrl", "", true);
|
printCheckResult("netty.launcherUrl", "", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.netty.launcherEXEURL.startsWith("http://")) {
|
if (config.netty.launcherEXEURL.startsWith("http://")) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "netty.launcherExeUrl", "launcher exe download connection not secure", false);
|
printCheckResult("netty.launcherExeUrl", "launcher exe download connection not secure", false);
|
||||||
} else if (config.netty.launcherEXEURL.startsWith("https://")) {
|
} else if (config.netty.launcherEXEURL.startsWith("https://")) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "netty.launcherExeUrl", "", true);
|
printCheckResult("netty.launcherExeUrl", "", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.netty.downloadURL.startsWith("http://")) {
|
if (config.netty.downloadURL.startsWith("http://")) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "netty.downloadUrl", "assets/clients download connection not secure", false);
|
printCheckResult("netty.downloadUrl", "assets/clients download connection not secure", false);
|
||||||
} else if (config.netty.downloadURL.startsWith("https://")) {
|
} else if (config.netty.downloadURL.startsWith("https://")) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "netty.downloadUrl", "", true);
|
printCheckResult("netty.downloadUrl", "", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config.sign.enabled) {
|
if (!config.sign.enabled) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "sign", "it is recommended to use a signature", null);
|
printCheckResult("sign", "it is recommended to use a signature", null);
|
||||||
} else {
|
} else {
|
||||||
/*boolean bad = false;
|
/*boolean bad = false;
|
||||||
KeyStore keyStore = SignHelper.getStore(new File(config.sign.keyStore).toPath(), config.sign.keyStorePass, config.sign.keyStoreType);
|
KeyStore keyStore = SignHelper.getStore(new File(config.sign.keyStore).toPath(), config.sign.keyStorePass, config.sign.keyStoreType);
|
||||||
|
@ -117,11 +125,11 @@ public void invoke(String... args) {
|
||||||
X509Certificate cert = (X509Certificate) keyStore.getCertificate(config.sign.keyAlias);
|
X509Certificate cert = (X509Certificate) keyStore.getCertificate(config.sign.keyAlias);
|
||||||
cert.checkValidity();
|
cert.checkValidity();
|
||||||
if(certChain.length <= 1) {
|
if(certChain.length <= 1) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "sign", "certificate chain contains <2 element(recommend 2 and more)", false);
|
printCheckResult("sign", "certificate chain contains <2 element(recommend 2 and more)", false);
|
||||||
bad = true;
|
bad = true;
|
||||||
}
|
}
|
||||||
if((cert.getBasicConstraints() & 1) != 0) {
|
if((cert.getBasicConstraints() & 1) != 0) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "sign", "end certificate - CA", false);
|
printCheckResult("sign", "end certificate - CA", false);
|
||||||
bad = true;
|
bad = true;
|
||||||
}
|
}
|
||||||
for(X509Certificate certificate : certChain)
|
for(X509Certificate certificate : certChain)
|
||||||
|
@ -129,33 +137,33 @@ public void invoke(String... args) {
|
||||||
certificate.checkValidity();
|
certificate.checkValidity();
|
||||||
}
|
}
|
||||||
if(!bad)*/
|
if(!bad)*/
|
||||||
printCheckResult(LogHelper.Level.INFO, "sign", "", true);
|
printCheckResult("sign", "", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.components.values().stream().noneMatch(c -> c instanceof ProGuardComponent)) {
|
if (config.components.values().stream().noneMatch(c -> c instanceof ProGuardComponent)) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "launcher.enabledProGuard", "proguard not enabled", false);
|
printCheckResult("launcher.enabledProGuard", "proguard not enabled", false);
|
||||||
} else {
|
} else {
|
||||||
printCheckResult(LogHelper.Level.INFO, "launcher.enabledProGuard", "", true);
|
printCheckResult("launcher.enabledProGuard", "", true);
|
||||||
}
|
}
|
||||||
if (!config.launcher.stripLineNumbers) {
|
if (!config.launcher.stripLineNumbers) {
|
||||||
printCheckResult(LogHelper.Level.INFO, "launcher.stripLineNumbers", "stripLineNumbers not enabled", false);
|
printCheckResult("launcher.stripLineNumbers", "stripLineNumbers not enabled", false);
|
||||||
} else {
|
} else {
|
||||||
printCheckResult(LogHelper.Level.INFO, "launcher.stripLineNumbers", "", true);
|
printCheckResult("launcher.stripLineNumbers", "", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (config.env) {
|
switch (config.env) {
|
||||||
|
|
||||||
case DEV:
|
case DEV:
|
||||||
printCheckResult(LogHelper.Level.INFO, "env", "found env DEV", false);
|
printCheckResult("env", "found env DEV", false);
|
||||||
break;
|
break;
|
||||||
case DEBUG:
|
case DEBUG:
|
||||||
printCheckResult(LogHelper.Level.INFO, "env", "found env DEBUG", false);
|
printCheckResult("env", "found env DEBUG", false);
|
||||||
break;
|
break;
|
||||||
case STD:
|
case STD:
|
||||||
printCheckResult(LogHelper.Level.INFO, "env", "you can improve security by using env PROD", null);
|
printCheckResult("env", "you can improve security by using env PROD", null);
|
||||||
break;
|
break;
|
||||||
case PROD:
|
case PROD:
|
||||||
printCheckResult(LogHelper.Level.INFO, "env", "", true);
|
printCheckResult("env", "", true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +174,7 @@ public void invoke(String... args) {
|
||||||
for (String exc : profile.getUpdateExclusions()) {
|
for (String exc : profile.getUpdateExclusions()) {
|
||||||
StringTokenizer tokenizer = new StringTokenizer(exc, "/");
|
StringTokenizer tokenizer = new StringTokenizer(exc, "/");
|
||||||
if (exc.endsWith(".jar")) {
|
if (exc.endsWith(".jar")) {
|
||||||
printCheckResult(LogHelper.Level.INFO, profileModuleName, String.format("updateExclusions %s not safe. Cheats may be injected very easy!", exc), false);
|
printCheckResult(profileModuleName, String.format("updateExclusions %s not safe. Cheats may be injected very easy!", exc), false);
|
||||||
bad = true;
|
bad = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -174,19 +182,19 @@ public void invoke(String... args) {
|
||||||
String nextToken = tokenizer.nextToken();
|
String nextToken = tokenizer.nextToken();
|
||||||
if (!tokenizer.hasMoreTokens()) {
|
if (!tokenizer.hasMoreTokens()) {
|
||||||
if (!exc.endsWith("/")) {
|
if (!exc.endsWith("/")) {
|
||||||
printCheckResult(LogHelper.Level.INFO, profileModuleName, String.format("updateExclusions %s not safe. Cheats may be injected very easy!", exc), false);
|
printCheckResult(profileModuleName, String.format("updateExclusions %s not safe. Cheats may be injected very easy!", exc), false);
|
||||||
bad = true;
|
bad = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (nextToken.equals("memory_repo") || nextToken.equals(profile.getVersion().name)) {
|
if (nextToken.equals("memory_repo") || nextToken.equals(profile.getVersion().name)) {
|
||||||
printCheckResult(LogHelper.Level.INFO, profileModuleName, String.format("updateExclusions %s not safe. Cheats may be injected very easy!", exc), false);
|
printCheckResult(profileModuleName, String.format("updateExclusions %s not safe. Cheats may be injected very easy!", exc), false);
|
||||||
bad = true;
|
bad = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!bad)
|
if (!bad)
|
||||||
printCheckResult(LogHelper.Level.INFO, profileModuleName, "", true);
|
printCheckResult(profileModuleName, "", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Linux permissions check
|
//Linux permissions check
|
||||||
|
@ -201,34 +209,34 @@ public void invoke(String... args) {
|
||||||
String[] words = parts[1].trim().split(" ");
|
String[] words = parts[1].trim().split(" ");
|
||||||
uid = Integer.parseInt(words[0]);
|
uid = Integer.parseInt(words[0]);
|
||||||
if(Integer.parseInt(words[0]) == 0 || Integer.parseInt(words[0]) == 0) {
|
if(Integer.parseInt(words[0]) == 0 || Integer.parseInt(words[0]) == 0) {
|
||||||
LogHelper.error("The process is started as root! It is not recommended");
|
logger.error("The process is started as root! It is not recommended");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(parts[0].trim().equalsIgnoreCase("Gid")) {
|
if(parts[0].trim().equalsIgnoreCase("Gid")) {
|
||||||
String[] words = parts[1].trim().split(" ");
|
String[] words = parts[1].trim().split(" ");
|
||||||
gid = Integer.parseInt(words[0]);
|
gid = Integer.parseInt(words[0]);
|
||||||
if(Integer.parseInt(words[0]) == 0 || Integer.parseInt(words[0]) == 0) {
|
if(Integer.parseInt(words[0]) == 0 || Integer.parseInt(words[0]) == 0) {
|
||||||
LogHelper.error("The process is started as root group! It is not recommended");
|
logger.error("The process is started as root group! It is not recommended");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(checkOtherWriteAccess(IOHelper.getCodeSource(LaunchServer.class))) {
|
if(checkOtherWriteAccess(IOHelper.getCodeSource(LaunchServer.class))) {
|
||||||
LogHelper.warning("Write access to LaunchServer.jar. Please use 'chmod 755 LaunchServer.jar'");
|
logger.warn("Write access to LaunchServer.jar. Please use 'chmod 755 LaunchServer.jar'");
|
||||||
}
|
}
|
||||||
if(Files.exists(server.dir.resolve("private.key")) && checkOtherReadOrWriteAccess(server.dir.resolve("private.key"))) {
|
if(Files.exists(server.dir.resolve("private.key")) && checkOtherReadOrWriteAccess(server.dir.resolve("private.key"))) {
|
||||||
LogHelper.warning("Write or read access to private.key. Please use 'chmod 600 private.key'");
|
logger.warn("Write or read access to private.key. Please use 'chmod 600 private.key'");
|
||||||
}
|
}
|
||||||
if(Files.exists(server.dir.resolve("LaunchServerConfig.json")) && checkOtherReadOrWriteAccess(server.dir.resolve("LaunchServerConfig.json"))) {
|
if(Files.exists(server.dir.resolve("LaunchServerConfig.json")) && checkOtherReadOrWriteAccess(server.dir.resolve("LaunchServerConfig.json"))) {
|
||||||
LogHelper.warning("Write or read access to LaunchServerConfig.json. Please use 'chmod 600 LaunchServerConfig.json'");
|
logger.warn("Write or read access to LaunchServerConfig.json. Please use 'chmod 600 LaunchServerConfig.json'");
|
||||||
}
|
}
|
||||||
if(Files.exists(server.dir.resolve("LaunchServerRuntimeConfig.json")) && checkOtherReadOrWriteAccess(server.dir.resolve("LaunchServerRuntimeConfig.json"))) {
|
if(Files.exists(server.dir.resolve("LaunchServerRuntimeConfig.json")) && checkOtherReadOrWriteAccess(server.dir.resolve("LaunchServerRuntimeConfig.json"))) {
|
||||||
LogHelper.warning("Write or read access to LaunchServerRuntimeConfig.json. Please use 'chmod 600 LaunchServerRuntimeConfig.json'");
|
logger.warn("Write or read access to LaunchServerRuntimeConfig.json. Please use 'chmod 600 LaunchServerRuntimeConfig.json'");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogHelper.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LogHelper.info("Check completed");
|
logger.info("Check completed");
|
||||||
}
|
}
|
||||||
public boolean checkOtherWriteAccess(Path file) throws IOException {
|
public boolean checkOtherWriteAccess(Path file) throws IOException {
|
||||||
Set<PosixFilePermission> permissionSet = Files.getPosixFilePermissions(file);
|
Set<PosixFilePermission> permissionSet = Files.getPosixFilePermissions(file);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.service;
|
package pro.gravit.launchserver.command.service;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||||
import pro.gravit.launchserver.auth.handler.CachedAuthHandler;
|
import pro.gravit.launchserver.auth.handler.CachedAuthHandler;
|
||||||
|
@ -9,6 +11,8 @@
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
public class ServerStatusCommand extends Command {
|
public class ServerStatusCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public ServerStatusCommand(LaunchServer server) {
|
public ServerStatusCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
@ -25,23 +29,23 @@ public String getUsageDescription() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) {
|
public void invoke(String... args) {
|
||||||
LogHelper.info("Show server status");
|
logger.info("Show server status");
|
||||||
LogHelper.info("Memory: free %d | total: %d | max: %d", JVMHelper.RUNTIME.freeMemory(), JVMHelper.RUNTIME.totalMemory(), JVMHelper.RUNTIME.maxMemory());
|
logger.info("Memory: free {} | total: {} | max: {}", JVMHelper.RUNTIME.freeMemory(), JVMHelper.RUNTIME.totalMemory(), JVMHelper.RUNTIME.maxMemory());
|
||||||
long uptime = JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000;
|
long uptime = JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000;
|
||||||
long second = uptime % 60;
|
long second = uptime % 60;
|
||||||
long min = (uptime / 60) % 60;
|
long min = (uptime / 60) % 60;
|
||||||
long hour = (uptime / 60 / 60) % 24;
|
long hour = (uptime / 60 / 60) % 24;
|
||||||
long days = (uptime / 60 / 60 / 24);
|
long days = (uptime / 60 / 60 / 24);
|
||||||
LogHelper.info("Uptime: %d days %d hours %d minutes %d seconds", days, hour, min, second);
|
logger.info("Uptime: {} days {} hours {} minutes {} seconds", days, hour, min, second);
|
||||||
LogHelper.info("Uptime (double): %f", (double) JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000);
|
logger.info("Uptime (double): {}", (double) JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000);
|
||||||
int commands = server.commandHandler.getBaseCategory().commandsMap().size();
|
int commands = server.commandHandler.getBaseCategory().commandsMap().size();
|
||||||
for (CommandHandler.Category category : server.commandHandler.getCategories()) {
|
for (CommandHandler.Category category : server.commandHandler.getCategories()) {
|
||||||
commands += category.category.commandsMap().size();
|
commands += category.category.commandsMap().size();
|
||||||
}
|
}
|
||||||
LogHelper.info("Commands: %d(%d categories)", commands, server.commandHandler.getCategories().size() + 1);
|
logger.info("Commands: {}({} categories)", commands, server.commandHandler.getCategories().size() + 1);
|
||||||
for (AuthProviderPair pair : server.config.auth.values()) {
|
for (AuthProviderPair pair : server.config.auth.values()) {
|
||||||
if (pair.handler instanceof CachedAuthHandler) {
|
if (pair.handler instanceof CachedAuthHandler) {
|
||||||
LogHelper.info("AuthHandler %s: EntryCache: %d | usernameCache: %d", pair.name, ((CachedAuthHandler) pair.handler).getEntryCache().size(), ((CachedAuthHandler) pair.handler).getUsernamesCache().size());
|
logger.info("AuthHandler {}: EntryCache: {} | usernameCache: {}", pair.name, ((CachedAuthHandler) pair.handler).getEntryCache().size(), ((CachedAuthHandler) pair.handler).getUsernamesCache().size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.service;
|
package pro.gravit.launchserver.command.service;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.binary.tasks.SignJarTask;
|
import pro.gravit.launchserver.binary.tasks.SignJarTask;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
|
@ -12,6 +14,8 @@
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class SignDirCommand extends Command {
|
public class SignDirCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public SignDirCommand(LaunchServer server) {
|
public SignDirCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +39,7 @@ public void invoke(String... args) throws Exception {
|
||||||
Optional<SignJarTask> task = server.launcherBinary.getTaskByClass(SignJarTask.class);
|
Optional<SignJarTask> task = server.launcherBinary.getTaskByClass(SignJarTask.class);
|
||||||
if (task.isEmpty()) throw new IllegalStateException("SignJarTask not found");
|
if (task.isEmpty()) throw new IllegalStateException("SignJarTask not found");
|
||||||
IOHelper.walk(targetDir, new SignJarVisitor(task.get()), true);
|
IOHelper.walk(targetDir, new SignJarVisitor(task.get()), true);
|
||||||
LogHelper.info("Success signed");
|
logger.info("Success signed");
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SignJarVisitor extends SimpleFileVisitor<Path> {
|
private class SignJarVisitor extends SimpleFileVisitor<Path> {
|
||||||
|
@ -49,7 +53,7 @@ public SignJarVisitor(SignJarTask task) {
|
||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||||
if (file.toFile().getName().endsWith(".jar")) {
|
if (file.toFile().getName().endsWith(".jar")) {
|
||||||
Path tmpSign = server.dir.resolve("build").resolve(file.toFile().getName());
|
Path tmpSign = server.dir.resolve("build").resolve(file.toFile().getName());
|
||||||
LogHelper.info("Signing jar %s", file.toString());
|
logger.info("Signing jar {}", file.toString());
|
||||||
task.sign(server.config.sign, file, tmpSign);
|
task.sign(server.config.sign, file, tmpSign);
|
||||||
Files.deleteIfExists(file);
|
Files.deleteIfExists(file);
|
||||||
Files.move(tmpSign, file);
|
Files.move(tmpSign, file);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.service;
|
package pro.gravit.launchserver.command.service;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.binary.tasks.SignJarTask;
|
import pro.gravit.launchserver.binary.tasks.SignJarTask;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
|
@ -11,6 +13,8 @@
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class SignJarCommand extends Command {
|
public class SignJarCommand extends Command {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public SignJarCommand(LaunchServer server) {
|
public SignJarCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
@ -34,15 +38,15 @@ public void invoke(String... args) throws Exception {
|
||||||
tmpSign = Paths.get(args[1]);
|
tmpSign = Paths.get(args[1]);
|
||||||
else
|
else
|
||||||
tmpSign = server.dir.resolve("build").resolve(target.toFile().getName());
|
tmpSign = server.dir.resolve("build").resolve(target.toFile().getName());
|
||||||
LogHelper.info("Signing jar %s to %s", target.toString(), tmpSign.toString());
|
logger.info("Signing jar {} to {}", target.toString(), tmpSign.toString());
|
||||||
Optional<SignJarTask> task = server.launcherBinary.getTaskByClass(SignJarTask.class);
|
Optional<SignJarTask> task = server.launcherBinary.getTaskByClass(SignJarTask.class);
|
||||||
if (task.isEmpty()) throw new IllegalStateException("SignJarTask not found");
|
if (task.isEmpty()) throw new IllegalStateException("SignJarTask not found");
|
||||||
task.get().sign(server.config.sign, target, tmpSign);
|
task.get().sign(server.config.sign, target, tmpSign);
|
||||||
if (args.length <= 1) {
|
if (args.length <= 1) {
|
||||||
LogHelper.info("Move temp jar %s to %s", tmpSign.toString(), target.toString());
|
logger.info("Move temp jar {} to {}", tmpSign.toString(), target.toString());
|
||||||
Files.deleteIfExists(target);
|
Files.deleteIfExists(target);
|
||||||
Files.move(tmpSign, target);
|
Files.move(tmpSign, target);
|
||||||
}
|
}
|
||||||
LogHelper.info("Success signed");
|
logger.info("Success signed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.components;
|
package pro.gravit.launchserver.components;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launcher.NeedGarbageCollection;
|
import pro.gravit.launcher.NeedGarbageCollection;
|
||||||
import pro.gravit.launchserver.Reconfigurable;
|
import pro.gravit.launchserver.Reconfigurable;
|
||||||
import pro.gravit.utils.command.Command;
|
import pro.gravit.utils.command.Command;
|
||||||
|
@ -12,6 +14,7 @@
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class AbstractLimiter<T> extends Component implements NeedGarbageCollection, Reconfigurable {
|
public abstract class AbstractLimiter<T> extends Component implements NeedGarbageCollection, Reconfigurable {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
public final List<T> exclude = new ArrayList<>();
|
public final List<T> exclude = new ArrayList<>();
|
||||||
protected final transient Map<T, LimitEntry> map = new HashMap<>();
|
protected final transient Map<T, LimitEntry> map = new HashMap<>();
|
||||||
public int rateLimit;
|
public int rateLimit;
|
||||||
|
@ -25,7 +28,7 @@ public Map<String, Command> getCommands() {
|
||||||
public void invoke(String... args) {
|
public void invoke(String... args) {
|
||||||
long size = map.size();
|
long size = map.size();
|
||||||
garbageCollection();
|
garbageCollection();
|
||||||
LogHelper.info("Cleared %d entity", size);
|
logger.info("Cleared {} entity", size);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
commands.put("clear", new SubCommand() {
|
commands.put("clear", new SubCommand() {
|
||||||
|
@ -33,7 +36,7 @@ public void invoke(String... args) {
|
||||||
public void invoke(String... args) {
|
public void invoke(String... args) {
|
||||||
long size = map.size();
|
long size = map.size();
|
||||||
map.clear();
|
map.clear();
|
||||||
LogHelper.info("Cleared %d entity", size);
|
logger.info("Cleared {} entity", size);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
commands.put("addExclude", new SubCommand() {
|
commands.put("addExclude", new SubCommand() {
|
||||||
|
|
|
@ -113,7 +113,7 @@ else if(jfxPath != null && checkFXJMods(jfxPath)) {
|
||||||
ProGuard proGuard = new ProGuard(proguard_cfg);
|
ProGuard proGuard = new ProGuard(proguard_cfg);
|
||||||
proGuard.execute();
|
proGuard.execute();
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
LogHelper.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
IOHelper.copy(inputFile, outputJar);
|
IOHelper.copy(inputFile, outputJar);
|
||||||
|
@ -247,7 +247,7 @@ public void prepare(boolean force) {
|
||||||
genWords(force);
|
genWords(force);
|
||||||
genConfig(force);
|
genConfig(force);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogHelper.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
import io.netty.channel.epoll.Epoll;
|
import io.netty.channel.epoll.Epoll;
|
||||||
import io.netty.handler.logging.LogLevel;
|
import io.netty.handler.logging.LogLevel;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launcher.Launcher;
|
import pro.gravit.launcher.Launcher;
|
||||||
import pro.gravit.launcher.LauncherConfig;
|
import pro.gravit.launcher.LauncherConfig;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
@ -48,6 +50,7 @@ public final class LaunchServerConfig {
|
||||||
public String startScript;
|
public String startScript;
|
||||||
private transient LaunchServer server = null;
|
private transient LaunchServer server = null;
|
||||||
private transient AuthProviderPair authDefault;
|
private transient AuthProviderPair authDefault;
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) {
|
public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) {
|
||||||
LaunchServerConfig newConfig = new LaunchServerConfig();
|
LaunchServerConfig newConfig = new LaunchServerConfig();
|
||||||
|
@ -222,13 +225,13 @@ public void close(LaunchServer.ReloadType type) {
|
||||||
try {
|
try {
|
||||||
((AutoCloseable) component).close();
|
((AutoCloseable) component).close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogHelper.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogHelper.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
if (protectHandler != null) {
|
if (protectHandler != null) {
|
||||||
server.unregisterObject("protectHandler", protectHandler);
|
server.unregisterObject("protectHandler", protectHandler);
|
||||||
|
@ -240,7 +243,7 @@ public void close(LaunchServer.ReloadType type) {
|
||||||
try {
|
try {
|
||||||
((AutoCloseable) sessions).close();
|
((AutoCloseable) sessions).close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogHelper.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -250,7 +253,7 @@ public void close(LaunchServer.ReloadType type) {
|
||||||
try {
|
try {
|
||||||
((AutoCloseable) dao).close();
|
((AutoCloseable) dao).close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogHelper.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.config;
|
package pro.gravit.launchserver.config;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
@ -9,11 +11,12 @@ public class LaunchServerRuntimeConfig {
|
||||||
public String oemUnlockKey;
|
public String oemUnlockKey;
|
||||||
public String registerApiKey;
|
public String registerApiKey;
|
||||||
public String clientCheckSecret;
|
public String clientCheckSecret;
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public void verify() {
|
public void verify() {
|
||||||
if (passwordEncryptKey == null) LogHelper.error("[RuntimeConfig] passwordEncryptKey must not be null");
|
if (passwordEncryptKey == null) logger.error("[RuntimeConfig] passwordEncryptKey must not be null");
|
||||||
if (clientCheckSecret == null) {
|
if (clientCheckSecret == null) {
|
||||||
LogHelper.warning("[RuntimeConfig] clientCheckSecret must not be null");
|
logger.warn("[RuntimeConfig] clientCheckSecret must not be null");
|
||||||
clientCheckSecret = SecurityHelper.randomStringToken();
|
clientCheckSecret = SecurityHelper.randomStringToken();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.launchermodules;
|
package pro.gravit.launchserver.launchermodules;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launcher.Launcher;
|
import pro.gravit.launcher.Launcher;
|
||||||
import pro.gravit.launcher.LauncherTrustManager;
|
import pro.gravit.launcher.LauncherTrustManager;
|
||||||
import pro.gravit.launcher.modules.LauncherModule;
|
import pro.gravit.launcher.modules.LauncherModule;
|
||||||
|
@ -29,6 +31,7 @@ public class LauncherModuleLoader {
|
||||||
public final List<ModuleEntity> launcherModules = new ArrayList<>();
|
public final List<ModuleEntity> launcherModules = new ArrayList<>();
|
||||||
public final Path modulesDir;
|
public final Path modulesDir;
|
||||||
private final LaunchServer server;
|
private final LaunchServer server;
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public LauncherModuleLoader(LaunchServer server) {
|
public LauncherModuleLoader(LaunchServer server) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
|
@ -40,7 +43,7 @@ public void init() {
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(modulesDir);
|
Files.createDirectories(modulesDir);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogHelper.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
server.commandHandler.registerCommand("syncLauncherModules", new SyncLauncherModulesCommand(this));
|
server.commandHandler.registerCommand("syncLauncherModules", new SyncLauncherModulesCommand(this));
|
||||||
|
@ -54,14 +57,14 @@ public void init() {
|
||||||
});
|
});
|
||||||
mainTask.postBuildHook.registerHook((buildContext) -> {
|
mainTask.postBuildHook.registerHook((buildContext) -> {
|
||||||
for (ModuleEntity e : launcherModules) {
|
for (ModuleEntity e : launcherModules) {
|
||||||
LogHelper.debug("Put %s launcher module", e.path.toString());
|
logger.debug("Put {} launcher module", e.path.toString());
|
||||||
buildContext.pushJarFile(e.path, (en) -> false, (en) -> true);
|
buildContext.pushJarFile(e.path, (en) -> false, (en) -> true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
syncModules();
|
syncModules();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogHelper.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +80,7 @@ public void addClassFieldsToProperties(Map<String, Object> propertyMap, String p
|
||||||
Object obj = field.get(object);
|
Object obj = field.get(object);
|
||||||
String propertyName = prefix.concat(".").concat(field.getName().toLowerCase(Locale.US));
|
String propertyName = prefix.concat(".").concat(field.getName().toLowerCase(Locale.US));
|
||||||
if (InjectClassAcceptor.isSerializableValue(obj)) {
|
if (InjectClassAcceptor.isSerializableValue(obj)) {
|
||||||
LogHelper.dev("Property name %s", propertyName);
|
logger.trace("Property name {}", propertyName);
|
||||||
propertyMap.put(propertyName, obj);
|
propertyMap.put(propertyName, obj);
|
||||||
} else {
|
} else {
|
||||||
//Try recursive add fields
|
//Try recursive add fields
|
||||||
|
@ -109,7 +112,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
||||||
Attributes attributes = f.getManifest().getMainAttributes();
|
Attributes attributes = f.getManifest().getMainAttributes();
|
||||||
String mainClass = attributes.getValue("Module-Main-Class");
|
String mainClass = attributes.getValue("Module-Main-Class");
|
||||||
if (mainClass == null) {
|
if (mainClass == null) {
|
||||||
LogHelper.error("In module %s MainClass not found", file.toString());
|
logger.error("In module {} MainClass not found", file.toString());
|
||||||
} else {
|
} else {
|
||||||
if (classLoader == null)
|
if (classLoader == null)
|
||||||
classLoader = new LauncherModuleClassLoader(server.modulesManager.getModuleClassLoader());
|
classLoader = new LauncherModuleClassLoader(server.modulesManager.getModuleClassLoader());
|
||||||
|
@ -122,9 +125,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
||||||
entity.checkResult = server.modulesManager.checkModuleClass(mainClazz);
|
entity.checkResult = server.modulesManager.checkModuleClass(mainClazz);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
if(e instanceof ClassNotFoundException || e instanceof NoClassDefFoundError) {
|
if(e instanceof ClassNotFoundException || e instanceof NoClassDefFoundError) {
|
||||||
LogHelper.error("Module-MainClass in module %s incorrect", file.toString());
|
logger.error("Module-MainClass in module {} incorrect", file.toString());
|
||||||
} else {
|
} else {
|
||||||
LogHelper.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
return super.visitFile(file, attrs);
|
return super.visitFile(file, attrs);
|
||||||
}
|
}
|
||||||
|
@ -132,7 +135,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
||||||
if (entity.moduleConfigClass != null) {
|
if (entity.moduleConfigClass != null) {
|
||||||
entity.moduleConfigName = attributes.getValue("Module-Config-Name");
|
entity.moduleConfigName = attributes.getValue("Module-Config-Name");
|
||||||
if (entity.moduleConfigName == null) {
|
if (entity.moduleConfigName == null) {
|
||||||
LogHelper.warning("Module-Config-Name in module %s null. Module not configured", file.toString());
|
logger.warn("Module-Config-Name in module {} null. Module not configured", file.toString());
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
Class<?> clazz = classLoader.loadClass(entity.moduleConfigClass);
|
Class<?> clazz = classLoader.loadClass(entity.moduleConfigClass);
|
||||||
|
@ -140,7 +143,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
||||||
Object defaultConfig = MethodHandles.publicLookup().findStatic(clazz, "getDefault", MethodType.methodType(Object.class)).invoke();
|
Object defaultConfig = MethodHandles.publicLookup().findStatic(clazz, "getDefault", MethodType.methodType(Object.class)).invoke();
|
||||||
Object targetConfig;
|
Object targetConfig;
|
||||||
if (!Files.exists(configPath)) {
|
if (!Files.exists(configPath)) {
|
||||||
LogHelper.debug("Write default config for module %s to %s", file.toString(), configPath.toString());
|
logger.debug("Write default config for module {} to {}", file.toString(), configPath.toString());
|
||||||
try (Writer writer = IOHelper.newWriter(configPath)) {
|
try (Writer writer = IOHelper.newWriter(configPath)) {
|
||||||
Launcher.gsonManager.configGson.toJson(defaultConfig, writer);
|
Launcher.gsonManager.configGson.toJson(defaultConfig, writer);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +156,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
||||||
if (entity.propertyMap == null) entity.propertyMap = new HashMap<>();
|
if (entity.propertyMap == null) entity.propertyMap = new HashMap<>();
|
||||||
addClassFieldsToProperties(entity.propertyMap, "modules.".concat(entity.moduleConfigName.toLowerCase()), targetConfig, clazz);
|
addClassFieldsToProperties(entity.propertyMap, "modules.".concat(entity.moduleConfigName.toLowerCase()), targetConfig, clazz);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
LogHelper.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package pro.gravit.launchserver.launchermodules;
|
package pro.gravit.launchserver.launchermodules;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.utils.command.Command;
|
import pro.gravit.utils.command.Command;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
public class SyncLauncherModulesCommand extends Command {
|
public class SyncLauncherModulesCommand extends Command {
|
||||||
private final LauncherModuleLoader mod;
|
private final LauncherModuleLoader mod;
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public SyncLauncherModulesCommand(LauncherModuleLoader mod) {
|
public SyncLauncherModulesCommand(LauncherModuleLoader mod) {
|
||||||
this.mod = mod;
|
this.mod = mod;
|
||||||
|
@ -24,6 +27,6 @@ public String getUsageDescription() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
mod.syncModules();
|
mod.syncModules();
|
||||||
LogHelper.info("Launcher Modules synced");
|
logger.info("Launcher Modules synced");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package pro.gravit.launchserver.manangers;
|
package pro.gravit.launchserver.manangers;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
|
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
|
||||||
import org.bouncycastle.asn1.x500.X500Name;
|
import org.bouncycastle.asn1.x500.X500Name;
|
||||||
import org.bouncycastle.asn1.x500.X500NameBuilder;
|
import org.bouncycastle.asn1.x500.X500NameBuilder;
|
||||||
|
@ -54,6 +56,7 @@ public class CertificateManager {
|
||||||
public AsymmetricKeyParameter serverKey;
|
public AsymmetricKeyParameter serverKey;
|
||||||
public LauncherTrustManager trustManager;
|
public LauncherTrustManager trustManager;
|
||||||
public String orgName;
|
public String orgName;
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public X509CertificateHolder generateCertificate(String subjectName, PublicKey subjectPublicKey) throws OperatorCreationException {
|
public X509CertificateHolder generateCertificate(String subjectName, PublicKey subjectPublicKey) throws OperatorCreationException {
|
||||||
SubjectPublicKeyInfo subjectPubKeyInfo = SubjectPublicKeyInfo.getInstance(subjectPublicKey.getEncoded());
|
SubjectPublicKeyInfo subjectPubKeyInfo = SubjectPublicKeyInfo.getInstance(subjectPublicKey.getEncoded());
|
||||||
|
@ -180,7 +183,7 @@ public void readTrustStore(Path dir) throws IOException, CertificateException {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if(IOHelper.exists(dir.resolve("GravitCentralRootCA.crt"))) {
|
if(IOHelper.exists(dir.resolve("GravitCentralRootCA.crt"))) {
|
||||||
LogHelper.warning("Found old default certificate - 'GravitCentralRootCA.crt'. Delete...");
|
logger.warn("Found old default certificate - 'GravitCentralRootCA.crt'. Delete...");
|
||||||
Files.delete(dir.resolve("GravitCentralRootCA.crt"));
|
Files.delete(dir.resolve("GravitCentralRootCA.crt"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,7 +213,7 @@ public void checkClass(Class<?> clazz, LauncherTrustManager.CheckMode mode) thro
|
||||||
if (mode == LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED)
|
if (mode == LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED)
|
||||||
throw new SecurityException(String.format("Class %s not signed", clazz.getName()));
|
throw new SecurityException(String.format("Class %s not signed", clazz.getName()));
|
||||||
else if (mode == LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED)
|
else if (mode == LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED)
|
||||||
LogHelper.warning("Class %s not signed", clazz.getName());
|
logger.warn("Class {} not signed", clazz.getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.manangers;
|
package pro.gravit.launchserver.manangers;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
@ -18,6 +20,7 @@ public class KeyAgreementManager {
|
||||||
public final ECPrivateKey ecdsaPrivateKey;
|
public final ECPrivateKey ecdsaPrivateKey;
|
||||||
public final RSAPublicKey rsaPublicKey;
|
public final RSAPublicKey rsaPublicKey;
|
||||||
public final RSAPrivateKey rsaPrivateKey;
|
public final RSAPrivateKey rsaPrivateKey;
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public KeyAgreementManager(ECPublicKey ecdsaPublicKey, ECPrivateKey ecdsaPrivateKey, RSAPublicKey rsaPublicKey, RSAPrivateKey rsaPrivateKey) {
|
public KeyAgreementManager(ECPublicKey ecdsaPublicKey, ECPrivateKey ecdsaPrivateKey, RSAPublicKey rsaPublicKey, RSAPrivateKey rsaPrivateKey) {
|
||||||
this.ecdsaPublicKey = ecdsaPublicKey;
|
this.ecdsaPublicKey = ecdsaPublicKey;
|
||||||
|
@ -29,33 +32,33 @@ public KeyAgreementManager(ECPublicKey ecdsaPublicKey, ECPrivateKey ecdsaPrivate
|
||||||
public KeyAgreementManager(Path keyDirectory) throws IOException, InvalidKeySpecException {
|
public KeyAgreementManager(Path keyDirectory) throws IOException, InvalidKeySpecException {
|
||||||
Path ecdsaPublicKeyPath = keyDirectory.resolve("ecdsa_id.pub"), ecdsaPrivateKeyPath = keyDirectory.resolve("ecdsa_id");
|
Path ecdsaPublicKeyPath = keyDirectory.resolve("ecdsa_id.pub"), ecdsaPrivateKeyPath = keyDirectory.resolve("ecdsa_id");
|
||||||
if (IOHelper.isFile(ecdsaPublicKeyPath) && IOHelper.isFile(ecdsaPrivateKeyPath)) {
|
if (IOHelper.isFile(ecdsaPublicKeyPath) && IOHelper.isFile(ecdsaPrivateKeyPath)) {
|
||||||
LogHelper.info("Reading ECDSA keypair");
|
logger.info("Reading ECDSA keypair");
|
||||||
ecdsaPublicKey = SecurityHelper.toPublicECDSAKey(IOHelper.read(ecdsaPublicKeyPath));
|
ecdsaPublicKey = SecurityHelper.toPublicECDSAKey(IOHelper.read(ecdsaPublicKeyPath));
|
||||||
ecdsaPrivateKey = SecurityHelper.toPrivateECDSAKey(IOHelper.read(ecdsaPrivateKeyPath));
|
ecdsaPrivateKey = SecurityHelper.toPrivateECDSAKey(IOHelper.read(ecdsaPrivateKeyPath));
|
||||||
} else {
|
} else {
|
||||||
LogHelper.info("Generating ECDSA keypair");
|
logger.info("Generating ECDSA keypair");
|
||||||
KeyPair pair = SecurityHelper.genECDSAKeyPair(new SecureRandom());
|
KeyPair pair = SecurityHelper.genECDSAKeyPair(new SecureRandom());
|
||||||
ecdsaPublicKey = (ECPublicKey) pair.getPublic();
|
ecdsaPublicKey = (ECPublicKey) pair.getPublic();
|
||||||
ecdsaPrivateKey = (ECPrivateKey) pair.getPrivate();
|
ecdsaPrivateKey = (ECPrivateKey) pair.getPrivate();
|
||||||
|
|
||||||
// Write key pair list
|
// Write key pair list
|
||||||
LogHelper.info("Writing ECDSA keypair list");
|
logger.info("Writing ECDSA keypair list");
|
||||||
IOHelper.write(ecdsaPublicKeyPath, ecdsaPublicKey.getEncoded());
|
IOHelper.write(ecdsaPublicKeyPath, ecdsaPublicKey.getEncoded());
|
||||||
IOHelper.write(ecdsaPrivateKeyPath, ecdsaPrivateKey.getEncoded());
|
IOHelper.write(ecdsaPrivateKeyPath, ecdsaPrivateKey.getEncoded());
|
||||||
}
|
}
|
||||||
Path rsaPublicKeyPath = keyDirectory.resolve("rsa_id.pub"), rsaPrivateKeyPath = keyDirectory.resolve("rsa_id");
|
Path rsaPublicKeyPath = keyDirectory.resolve("rsa_id.pub"), rsaPrivateKeyPath = keyDirectory.resolve("rsa_id");
|
||||||
if (IOHelper.isFile(rsaPublicKeyPath) && IOHelper.isFile(rsaPrivateKeyPath)) {
|
if (IOHelper.isFile(rsaPublicKeyPath) && IOHelper.isFile(rsaPrivateKeyPath)) {
|
||||||
LogHelper.info("Reading RSA keypair");
|
logger.info("Reading RSA keypair");
|
||||||
rsaPublicKey = SecurityHelper.toPublicRSAKey(IOHelper.read(rsaPublicKeyPath));
|
rsaPublicKey = SecurityHelper.toPublicRSAKey(IOHelper.read(rsaPublicKeyPath));
|
||||||
rsaPrivateKey = SecurityHelper.toPrivateRSAKey(IOHelper.read(rsaPrivateKeyPath));
|
rsaPrivateKey = SecurityHelper.toPrivateRSAKey(IOHelper.read(rsaPrivateKeyPath));
|
||||||
} else {
|
} else {
|
||||||
LogHelper.info("Generating RSA keypair");
|
logger.info("Generating RSA keypair");
|
||||||
KeyPair pair = SecurityHelper.genRSAKeyPair(new SecureRandom());
|
KeyPair pair = SecurityHelper.genRSAKeyPair(new SecureRandom());
|
||||||
rsaPublicKey = (RSAPublicKey) pair.getPublic();
|
rsaPublicKey = (RSAPublicKey) pair.getPublic();
|
||||||
rsaPrivateKey = (RSAPrivateKey) pair.getPrivate();
|
rsaPrivateKey = (RSAPrivateKey) pair.getPrivate();
|
||||||
|
|
||||||
// Write key pair list
|
// Write key pair list
|
||||||
LogHelper.info("Writing RSA keypair list");
|
logger.info("Writing RSA keypair list");
|
||||||
IOHelper.write(rsaPublicKeyPath, rsaPublicKey.getEncoded());
|
IOHelper.write(rsaPublicKeyPath, rsaPublicKey.getEncoded());
|
||||||
IOHelper.write(rsaPrivateKeyPath, rsaPrivateKey.getEncoded());
|
IOHelper.write(rsaPrivateKeyPath, rsaPrivateKey.getEncoded());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package pro.gravit.launchserver.manangers;
|
package pro.gravit.launchserver.manangers;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launcher.HTTPRequest;
|
import pro.gravit.launcher.HTTPRequest;
|
||||||
import pro.gravit.utils.HttpDownloader;
|
import pro.gravit.utils.HttpDownloader;
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
@ -16,6 +18,7 @@
|
||||||
public class MirrorManager {
|
public class MirrorManager {
|
||||||
protected final ArrayList<Mirror> list = new ArrayList<>();
|
protected final ArrayList<Mirror> list = new ArrayList<>();
|
||||||
private Mirror defaultMirror;
|
private Mirror defaultMirror;
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public void addMirror(String mirror) {
|
public void addMirror(String mirror) {
|
||||||
Mirror m = new Mirror(mirror);
|
Mirror m = new Mirror(mirror);
|
||||||
|
@ -54,11 +57,11 @@ public int size() {
|
||||||
public boolean downloadZip(Mirror mirror, Path path, String mask, Object... args) throws IOException {
|
public boolean downloadZip(Mirror mirror, Path path, String mask, Object... args) throws IOException {
|
||||||
if (!mirror.enabled) return false;
|
if (!mirror.enabled) return false;
|
||||||
URL url = mirror.getURL(mask, args);
|
URL url = mirror.getURL(mask, args);
|
||||||
LogHelper.debug("Try download %s", url.toString());
|
logger.debug("Try download {}", url.toString());
|
||||||
try {
|
try {
|
||||||
HttpDownloader.downloadZip(url, path);
|
HttpDownloader.downloadZip(url, path);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogHelper.error("Download %s failed(%s: %s)", url.toString(), e.getClass().getName(), e.getMessage());
|
logger.error("Download {} failed({}: {})", url.toString(), e.getClass().getName(), e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -82,7 +85,7 @@ public JsonElement jsonRequest(Mirror mirror, JsonElement request, String method
|
||||||
try {
|
try {
|
||||||
return HTTPRequest.jsonRequest(request, method, url);
|
return HTTPRequest.jsonRequest(request, method, url);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogHelper.error("JsonRequest %s failed(%s: %s)", url.toString(), e.getClass().getName(), e.getMessage());
|
logger.error("JsonRequest {} failed({}: {})", url.toString(), e.getClass().getName(), e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler;
|
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler;
|
||||||
import io.netty.handler.logging.LoggingHandler;
|
import io.netty.handler.logging.LoggingHandler;
|
||||||
import io.netty.util.concurrent.GlobalEventExecutor;
|
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.config.LaunchServerConfig;
|
import pro.gravit.launchserver.config.LaunchServerConfig;
|
||||||
import pro.gravit.launchserver.socket.handlers.NettyIpForwardHandler;
|
import pro.gravit.launchserver.socket.handlers.NettyIpForwardHandler;
|
||||||
|
@ -33,15 +35,16 @@ public class LauncherNettyServer implements AutoCloseable {
|
||||||
public final EventLoopGroup workerGroup;
|
public final EventLoopGroup workerGroup;
|
||||||
public final WebSocketService service;
|
public final WebSocketService service;
|
||||||
public final BiHookSet<NettyConnectContext, SocketChannel> pipelineHook = new BiHookSet<>();
|
public final BiHookSet<NettyConnectContext, SocketChannel> pipelineHook = new BiHookSet<>();
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public LauncherNettyServer(LaunchServer server) {
|
public LauncherNettyServer(LaunchServer server) {
|
||||||
LaunchServerConfig.NettyConfig config = server.config.netty;
|
LaunchServerConfig.NettyConfig config = server.config.netty;
|
||||||
NettyObjectFactory.setUsingEpoll(config.performance.usingEpoll);
|
NettyObjectFactory.setUsingEpoll(config.performance.usingEpoll);
|
||||||
if (config.performance.usingEpoll) {
|
if (config.performance.usingEpoll) {
|
||||||
LogHelper.debug("Netty: Epoll enabled");
|
logger.debug("Netty: Epoll enabled");
|
||||||
}
|
}
|
||||||
if (config.performance.usingEpoll && !Epoll.isAvailable()) {
|
if (config.performance.usingEpoll && !Epoll.isAvailable()) {
|
||||||
LogHelper.error("Epoll is not available: (netty,perfomance.usingEpoll configured wrongly)", Epoll.unavailabilityCause());
|
logger.error("Epoll is not available: (netty,perfomance.usingEpoll configured wrongly)", Epoll.unavailabilityCause());
|
||||||
}
|
}
|
||||||
bossGroup = NettyObjectFactory.newEventLoopGroup(config.performance.bossThread, "LauncherNettyServer.bossGroup");
|
bossGroup = NettyObjectFactory.newEventLoopGroup(config.performance.bossThread, "LauncherNettyServer.bossGroup");
|
||||||
workerGroup = NettyObjectFactory.newEventLoopGroup(config.performance.workerThread, "LauncherNettyServer.workerGroup");
|
workerGroup = NettyObjectFactory.newEventLoopGroup(config.performance.workerThread, "LauncherNettyServer.workerGroup");
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package pro.gravit.launchserver.socket;
|
package pro.gravit.launchserver.socket;
|
||||||
|
|
||||||
import io.netty.util.concurrent.DefaultThreadFactory;
|
import io.netty.util.concurrent.DefaultThreadFactory;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
public class NettyThreadFactory extends DefaultThreadFactory {
|
public class NettyThreadFactory extends DefaultThreadFactory {
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public NettyThreadFactory(String poolName) {
|
public NettyThreadFactory(String poolName) {
|
||||||
super(poolName);
|
super(poolName);
|
||||||
}
|
}
|
||||||
|
@ -12,8 +16,10 @@ public NettyThreadFactory(String poolName) {
|
||||||
protected Thread newThread(Runnable r, String name) {
|
protected Thread newThread(Runnable r, String name) {
|
||||||
Thread thread = super.newThread(r, name);
|
Thread thread = super.newThread(r, name);
|
||||||
thread.setUncaughtExceptionHandler((th, e) -> {
|
thread.setUncaughtExceptionHandler((th, e) -> {
|
||||||
if (LogHelper.isDebugEnabled())
|
if(e.getMessage().contains("Connection reset by peer")) {
|
||||||
LogHelper.error(e);
|
return;
|
||||||
|
}
|
||||||
|
logger.error(e);
|
||||||
});
|
});
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
import io.netty.channel.group.ChannelGroup;
|
import io.netty.channel.group.ChannelGroup;
|
||||||
import io.netty.channel.group.ChannelMatchers;
|
import io.netty.channel.group.ChannelMatchers;
|
||||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.launcher.Launcher;
|
import pro.gravit.launcher.Launcher;
|
||||||
import pro.gravit.launcher.events.ExceptionEvent;
|
import pro.gravit.launcher.events.ExceptionEvent;
|
||||||
import pro.gravit.launcher.events.RequestEvent;
|
import pro.gravit.launcher.events.RequestEvent;
|
||||||
|
@ -58,6 +60,7 @@ public class WebSocketService {
|
||||||
public final AtomicLong lastRequestTime = new AtomicLong();
|
public final AtomicLong lastRequestTime = new AtomicLong();
|
||||||
private final LaunchServer server;
|
private final LaunchServer server;
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public WebSocketService(ChannelGroup channels, LaunchServer server) {
|
public WebSocketService(ChannelGroup channels, LaunchServer server) {
|
||||||
this.channels = channels;
|
this.channels = channels;
|
||||||
|
@ -161,7 +164,7 @@ void process(ChannelHandlerContext ctx, WebSocketServerResponse response, Client
|
||||||
try {
|
try {
|
||||||
response.execute(ctx, client);
|
response.execute(ctx, client);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogHelper.error(e);
|
logger.error(e);
|
||||||
RequestEvent event;
|
RequestEvent event;
|
||||||
if (server.config.netty.sendExceptionEnabled) {
|
if (server.config.netty.sendExceptionEnabled) {
|
||||||
event = new ExceptionEvent(e);
|
event = new ExceptionEvent(e);
|
||||||
|
|
Loading…
Reference in a new issue