mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +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;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||
|
@ -11,6 +13,8 @@
|
|||
import java.util.UUID;
|
||||
|
||||
public final class AuthCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public AuthCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
@ -42,6 +46,6 @@ public void invoke(String... args) throws Exception {
|
|||
UUID uuid = pair.handler.auth(result);
|
||||
|
||||
// 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;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
|
@ -10,6 +12,8 @@
|
|||
import java.util.UUID;
|
||||
|
||||
public final class UUIDToUsernameCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public UUIDToUsernameCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
@ -40,6 +44,6 @@ public void invoke(String... args) throws CommandException, IOException {
|
|||
throw new CommandException("Unknown UUID: " + uuid);
|
||||
|
||||
// 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;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
|
@ -10,6 +12,8 @@
|
|||
import java.util.UUID;
|
||||
|
||||
public final class UsernameToUUIDCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public UsernameToUUIDCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
@ -39,6 +43,6 @@ public void invoke(String... args) throws CommandException, IOException {
|
|||
throw new CommandException(String.format("Unknown username: '%s'", username));
|
||||
|
||||
// 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;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bouncycastle.cert.X509CertificateHolder;
|
||||
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
|
@ -15,6 +17,7 @@
|
|||
|
||||
public class TestCommand extends Command {
|
||||
private NettyServerSocketHandler handler = null;
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public TestCommand(LaunchServer server) {
|
||||
super(server);
|
||||
|
@ -72,10 +75,10 @@ public void invoke(String... args) throws Exception {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
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) {
|
||||
CommonHelper.newThread(String.format("Stresser #%d", i), true, runnable).start();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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.command.Command;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
|
@ -10,6 +12,7 @@
|
|||
import java.util.Collections;
|
||||
|
||||
public final class DownloadAssetCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public DownloadAssetCommand(LaunchServer server) {
|
||||
super(server);
|
||||
|
@ -34,16 +37,16 @@ public void invoke(String... args) throws Exception {
|
|||
Path assetDir = server.updatesDir.resolve(dirName);
|
||||
|
||||
// Create asset dir
|
||||
LogHelper.subInfo("Creating asset dir: '%s'", dirName);
|
||||
logger.info("Creating asset dir: '{}'", dirName);
|
||||
Files.createDirectory(assetDir);
|
||||
|
||||
// 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);
|
||||
server.mirrorManager.downloadZip(assetDir, "assets/%s.zip", versionName);
|
||||
|
||||
// Finished
|
||||
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
|
||||
server.syncProfilesDir();
|
||||
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.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.command.Command;
|
||||
import pro.gravit.utils.command.CommandException;
|
||||
|
@ -22,8 +25,8 @@
|
|||
public final class IndexAssetCommand extends Command {
|
||||
public static final String INDEXES_DIR = "indexes";
|
||||
public static final String OBJECTS_DIR = "objects";
|
||||
private static final Gson gson = new Gson();
|
||||
private static final String JSON_EXTENSION = ".json";
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public IndexAssetCommand(LaunchServer 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");
|
||||
|
||||
// Create new asset dir
|
||||
LogHelper.subInfo("Creating indexed asset dir: '%s'", outputAssetDirName);
|
||||
logger.info("Creating indexed asset dir: '{}'", outputAssetDirName);
|
||||
Files.createDirectory(outputAssetDir);
|
||||
|
||||
// Index objects
|
||||
JsonObject objects = new JsonObject();
|
||||
LogHelper.subInfo("Indexing objects");
|
||||
logger.info("Indexing objects");
|
||||
IOHelper.walk(inputAssetDir, new IndexAssetVisitor(objects, inputAssetDir, outputAssetDir), false);
|
||||
|
||||
// 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))) {
|
||||
JsonObject result = new JsonObject();
|
||||
result.add("objects", objects);
|
||||
writer.write(gson.toJson(result));
|
||||
writer.write(Launcher.gsonManager.gson.toJson(result));
|
||||
}
|
||||
|
||||
// Finished
|
||||
server.syncUpdatesDir(Collections.singleton(outputAssetDirName));
|
||||
LogHelper.subInfo("Asset successfully indexed: '%s'", inputAssetDirName);
|
||||
logger.info("Asset successfully indexed: '{}'", inputAssetDirName);
|
||||
}
|
||||
|
||||
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 Path inputAssetDir;
|
||||
private final Path outputAssetDir;
|
||||
|
@ -105,12 +108,12 @@ private IndexAssetVisitor(JsonObject objects, Path inputAssetDir, Path outputAss
|
|||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
String name = IOHelper.toString(inputAssetDir.relativize(file));
|
||||
LogHelper.subInfo("Indexing: '%s'", name);
|
||||
logger.info("Indexing: '{}'", name);
|
||||
|
||||
// Add to index and copy file
|
||||
String digest = SecurityHelper.toHex(SecurityHelper.digest(DigestAlgorithm.SHA1, file));
|
||||
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));
|
||||
|
||||
// Continue visiting
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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.hasher.HashedDir;
|
||||
import pro.gravit.launcher.profiles.ClientProfile;
|
||||
|
@ -20,6 +22,8 @@
|
|||
import java.util.*;
|
||||
|
||||
public class SaveProfilesCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public SaveProfilesCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
@ -147,7 +151,6 @@ public static void saveProfile(ClientProfile profile, Path path) throws IOExcept
|
|||
action = new OptionalActionClientArgs(Arrays.asList(list));
|
||||
break;
|
||||
default:
|
||||
LogHelper.warning("Not converted optional %s with type %s. Type unknown", file.name, file.type.toString());
|
||||
continue;
|
||||
}
|
||||
file.actions.add(action);
|
||||
|
@ -175,7 +178,7 @@ public void invoke(String... args) throws Exception {
|
|||
for (String profileName : args) {
|
||||
Path profilePath = server.profilesDir.resolve(profileName.concat(".json"));
|
||||
if (!Files.exists(profilePath)) {
|
||||
LogHelper.error("Profile %s not found", profilePath.toString());
|
||||
logger.error("Profile {} not found", profilePath.toString());
|
||||
return;
|
||||
}
|
||||
ClientProfile profile;
|
||||
|
@ -183,7 +186,7 @@ public void invoke(String... args) throws Exception {
|
|||
profile = Launcher.gsonManager.configGson.fromJson(reader, ClientProfile.class);
|
||||
}
|
||||
saveProfile(profile, profilePath);
|
||||
LogHelper.info("Profile %s save successful", profilePath.toString());
|
||||
logger.info("Profile {} save successful", profilePath.toString());
|
||||
}
|
||||
server.syncProfilesDir();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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.command.Command;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
@ -7,6 +9,7 @@
|
|||
import java.io.IOException;
|
||||
|
||||
public final class SyncBinariesCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
public SyncBinariesCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
@ -24,6 +27,6 @@ public String getUsageDescription() {
|
|||
@Override
|
||||
public void invoke(String... args) throws IOException {
|
||||
server.syncLauncherBinaries();
|
||||
LogHelper.subInfo("Binaries successfully resynced");
|
||||
logger.info("Binaries successfully resynced");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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.command.Command;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
@ -7,6 +9,7 @@
|
|||
import java.io.IOException;
|
||||
|
||||
public final class SyncProfilesCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
public SyncProfilesCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
@ -24,6 +27,6 @@ public String getUsageDescription() {
|
|||
@Override
|
||||
public void invoke(String... args) throws IOException {
|
||||
server.syncProfilesDir();
|
||||
LogHelper.subInfo("Profiles successfully resynced");
|
||||
logger.info("Profiles successfully resynced");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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.command.Command;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
@ -7,6 +9,8 @@
|
|||
import java.io.IOException;
|
||||
|
||||
public final class SyncUPCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public SyncUPCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
@ -24,9 +28,9 @@ public String getUsageDescription() {
|
|||
@Override
|
||||
public void invoke(String... args) throws IOException {
|
||||
server.syncProfilesDir();
|
||||
LogHelper.subInfo("Profiles successfully resynced");
|
||||
logger.info("Profiles successfully resynced");
|
||||
|
||||
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;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
@ -10,6 +12,8 @@
|
|||
import java.util.Set;
|
||||
|
||||
public final class SyncUpdatesCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public SyncUpdatesCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
@ -34,6 +38,6 @@ public void invoke(String... args) throws IOException {
|
|||
|
||||
// Hash updates dir
|
||||
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.JsonObject;
|
||||
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.command.Command;
|
||||
import pro.gravit.utils.command.CommandException;
|
||||
|
@ -16,6 +18,8 @@
|
|||
import java.util.Map;
|
||||
|
||||
public final class UnindexAssetCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public UnindexAssetCommand(LaunchServer 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");
|
||||
|
||||
// Create new asset dir
|
||||
LogHelper.subInfo("Creating unindexed asset dir: '%s'", outputAssetDirName);
|
||||
logger.info("Creating unindexed asset dir: '{}'", outputAssetDirName);
|
||||
Files.createDirectory(outputAssetDir);
|
||||
|
||||
// Read JSON file
|
||||
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))) {
|
||||
objects = JsonParser.parseReader(reader).getAsJsonObject().get("objects").getAsJsonObject();
|
||||
}
|
||||
|
||||
// Restore objects
|
||||
LogHelper.subInfo("Unindexing %d objects", objects.size());
|
||||
logger.info("Unindexing {} objects", objects.size());
|
||||
for (Map.Entry<String, JsonElement> member : objects.entrySet()) {
|
||||
String name = member.getKey();
|
||||
LogHelper.subInfo("Unindexing: '%s'", name);
|
||||
logger.info("Unindexing: '{}'", name);
|
||||
|
||||
// Copy hashed file to target
|
||||
String hash = member.getValue().getAsJsonObject().get("hash").getAsString();
|
||||
|
@ -66,6 +70,6 @@ public void invoke(String... args) throws Exception {
|
|||
|
||||
// Finished
|
||||
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;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
|
@ -11,6 +13,8 @@
|
|||
import java.util.Base64;
|
||||
|
||||
public class ClientsCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public ClientsCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
@ -31,22 +35,22 @@ public void invoke(String... args) {
|
|||
service.channels.forEach((channel -> {
|
||||
WebSocketFrameHandler frameHandler = channel.pipeline().get(WebSocketFrameHandler.class);
|
||||
if(frameHandler == null) {
|
||||
LogHelper.info("Channel %s", IOHelper.getIP(channel.remoteAddress()));
|
||||
logger.info("Channel {}", IOHelper.getIP(channel.remoteAddress()));
|
||||
return;
|
||||
}
|
||||
Client client = frameHandler.getClient();
|
||||
String ip = frameHandler.context.ip != null ? frameHandler.context.ip : IOHelper.getIP(channel.remoteAddress());
|
||||
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 {
|
||||
LogHelper.info("Client name %s | ip %s | connectUUID %s", 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);
|
||||
LogHelper.subInfo("Data: checkSign %s | auth_id %s", client.checkSign ? "true" : "false",
|
||||
logger.info("Client name {} | ip {} | connectUUID {}", client.username == null ? "null" : client.username, ip, frameHandler.getConnectUUID());
|
||||
logger.info("userUUID: {} | session {}", client.uuid == null ? "null" : client.uuid.toString(), client.session == null ? "null" : client.session);
|
||||
logger.info("Data: checkSign {} | auth_id {}", client.checkSign ? "true" : "false",
|
||||
client.auth_id);
|
||||
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;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.launcher.NeedGarbageCollection;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
|
@ -15,6 +17,8 @@
|
|||
import java.nio.file.Paths;
|
||||
|
||||
public class ComponentCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public ComponentCommand(LaunchServer server) {
|
||||
super(server);
|
||||
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");
|
||||
Component component = server.config.components.get(componentName);
|
||||
if (component == null) {
|
||||
LogHelper.error("Component %s not found", componentName);
|
||||
logger.error("Component {} not found", componentName);
|
||||
return;
|
||||
}
|
||||
if (component instanceof AutoCloseable) {
|
||||
((AutoCloseable) component).close();
|
||||
}
|
||||
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 {
|
||||
|
@ -54,7 +58,7 @@ public void invoke(String... args) throws Exception {
|
|||
String componentName = args[0];
|
||||
Class<? extends Component> componentClass = Component.providers.getClass(args[1]);
|
||||
if(componentClass == null) {
|
||||
LogHelper.error("Component type %s not registered", componentName);
|
||||
logger.error("Component type {} not registered", componentName);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
@ -69,9 +73,9 @@ public void invoke(String... args) throws Exception {
|
|||
component.setComponentName(componentName);
|
||||
server.config.components.put(componentName, component);
|
||||
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) {
|
||||
LogHelper.error(throwable);
|
||||
logger.error(throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,10 +91,10 @@ public String getUsageDescription() {
|
|||
}
|
||||
|
||||
public void printHelp() {
|
||||
LogHelper.info("Print help for component:");
|
||||
LogHelper.subInfo("component unload [componentName]");
|
||||
LogHelper.subInfo("component load [componentName] [filename]");
|
||||
LogHelper.subInfo("component gc [componentName]");
|
||||
logger.info("Print help for component:");
|
||||
logger.info("component unload [componentName]");
|
||||
logger.info("component load [componentName] [filename]");
|
||||
logger.info("component gc [componentName]");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
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.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class PingServersCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public PingServersCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
@ -23,10 +27,10 @@ public String getUsageDescription() {
|
|||
@Override
|
||||
public void invoke(String... args) {
|
||||
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) {
|
||||
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;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import pro.gravit.launcher.profiles.ClientProfile;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
|
@ -26,13 +28,19 @@
|
|||
import java.util.StringTokenizer;
|
||||
|
||||
public class SecurityCheckCommand extends Command {
|
||||
private static transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public SecurityCheckCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
||||
public static void printCheckResult(LogHelper.Level level, String module, String comment, Boolean status) {
|
||||
LogHelper.log(level, String.format("[%s] %s - %s", module, comment, status == null ? "WARN" : (status ? "OK" : "FAIL")), false);
|
||||
public static void printCheckResult(String module, String comment, Boolean status) {
|
||||
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
|
||||
|
@ -50,66 +58,66 @@ public void invoke(String... args) {
|
|||
LaunchServerConfig config = server.config;
|
||||
config.auth.forEach((name, pair) -> {
|
||||
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 {
|
||||
printCheckResult(LogHelper.Level.INFO, String.format("auth.%s.provider", name), "", true);
|
||||
printCheckResult(String.format("auth.%s.provider", name), "", true);
|
||||
}
|
||||
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 {
|
||||
printCheckResult(LogHelper.Level.INFO, String.format("auth.%s.handler", name), "", true);
|
||||
printCheckResult(String.format("auth.%s.handler", name), "", true);
|
||||
}
|
||||
});
|
||||
if (config.protectHandler instanceof NoProtectHandler) {
|
||||
printCheckResult(LogHelper.Level.INFO, "protectHandler", "protectHandler none", false);
|
||||
printCheckResult("protectHandler", "protectHandler none", false);
|
||||
} else if (config.protectHandler instanceof AdvancedProtectHandler) {
|
||||
printCheckResult(LogHelper.Level.INFO, "protectHandler", "", true);
|
||||
printCheckResult("protectHandler", "", true);
|
||||
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 {
|
||||
printCheckResult(LogHelper.Level.INFO, "protectHandler.hardwareId", "", true);
|
||||
printCheckResult("protectHandler.hardwareId", "", true);
|
||||
}
|
||||
} 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 {
|
||||
printCheckResult(LogHelper.Level.INFO, "protectHandler", "unknown protectHandler", null);
|
||||
printCheckResult("protectHandler", "unknown protectHandler", null);
|
||||
}
|
||||
if (config.netty.address.startsWith("ws://")) {
|
||||
if (config.netty.ipForwarding)
|
||||
printCheckResult(LogHelper.Level.INFO, "netty.ipForwarding", "ipForwarding may be used to spoofing ip", null);
|
||||
printCheckResult(LogHelper.Level.INFO, "netty.address", "websocket connection not secure", false);
|
||||
printCheckResult("netty.ipForwarding", "ipForwarding may be used to spoofing ip", null);
|
||||
printCheckResult("netty.address", "websocket connection not secure", false);
|
||||
} else if (config.netty.address.startsWith("wss://")) {
|
||||
if (!config.netty.ipForwarding)
|
||||
printCheckResult(LogHelper.Level.INFO, "netty.ipForwarding", "ipForwarding not enabled. authLimiter may be get incorrect ip", null);
|
||||
printCheckResult(LogHelper.Level.INFO, "netty.address", "", true);
|
||||
printCheckResult("netty.ipForwarding", "ipForwarding not enabled. authLimiter may be get incorrect ip", null);
|
||||
printCheckResult("netty.address", "", true);
|
||||
}
|
||||
|
||||
if (config.netty.sendExceptionEnabled) {
|
||||
printCheckResult(LogHelper.Level.INFO, "netty.sendExceptionEnabled", "recommend \"false\" in production", false);
|
||||
printCheckResult("netty.sendExceptionEnabled", "recommend \"false\" in production", false);
|
||||
} else {
|
||||
printCheckResult(LogHelper.Level.INFO, "netty.sendExceptionEnabled", "", true);
|
||||
printCheckResult("netty.sendExceptionEnabled", "", true);
|
||||
}
|
||||
|
||||
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://")) {
|
||||
printCheckResult(LogHelper.Level.INFO, "netty.launcherUrl", "", true);
|
||||
printCheckResult("netty.launcherUrl", "", true);
|
||||
}
|
||||
|
||||
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://")) {
|
||||
printCheckResult(LogHelper.Level.INFO, "netty.launcherExeUrl", "", true);
|
||||
printCheckResult("netty.launcherExeUrl", "", true);
|
||||
}
|
||||
|
||||
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://")) {
|
||||
printCheckResult(LogHelper.Level.INFO, "netty.downloadUrl", "", true);
|
||||
printCheckResult("netty.downloadUrl", "", true);
|
||||
}
|
||||
|
||||
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 {
|
||||
/*boolean bad = false;
|
||||
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);
|
||||
cert.checkValidity();
|
||||
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;
|
||||
}
|
||||
if((cert.getBasicConstraints() & 1) != 0) {
|
||||
printCheckResult(LogHelper.Level.INFO, "sign", "end certificate - CA", false);
|
||||
printCheckResult("sign", "end certificate - CA", false);
|
||||
bad = true;
|
||||
}
|
||||
for(X509Certificate certificate : certChain)
|
||||
|
@ -129,33 +137,33 @@ public void invoke(String... args) {
|
|||
certificate.checkValidity();
|
||||
}
|
||||
if(!bad)*/
|
||||
printCheckResult(LogHelper.Level.INFO, "sign", "", true);
|
||||
printCheckResult("sign", "", true);
|
||||
}
|
||||
|
||||
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 {
|
||||
printCheckResult(LogHelper.Level.INFO, "launcher.enabledProGuard", "", true);
|
||||
printCheckResult("launcher.enabledProGuard", "", true);
|
||||
}
|
||||
if (!config.launcher.stripLineNumbers) {
|
||||
printCheckResult(LogHelper.Level.INFO, "launcher.stripLineNumbers", "stripLineNumbers not enabled", false);
|
||||
printCheckResult("launcher.stripLineNumbers", "stripLineNumbers not enabled", false);
|
||||
} else {
|
||||
printCheckResult(LogHelper.Level.INFO, "launcher.stripLineNumbers", "", true);
|
||||
printCheckResult("launcher.stripLineNumbers", "", true);
|
||||
}
|
||||
|
||||
switch (config.env) {
|
||||
|
||||
case DEV:
|
||||
printCheckResult(LogHelper.Level.INFO, "env", "found env DEV", false);
|
||||
printCheckResult("env", "found env DEV", false);
|
||||
break;
|
||||
case DEBUG:
|
||||
printCheckResult(LogHelper.Level.INFO, "env", "found env DEBUG", false);
|
||||
printCheckResult("env", "found env DEBUG", false);
|
||||
break;
|
||||
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;
|
||||
case PROD:
|
||||
printCheckResult(LogHelper.Level.INFO, "env", "", true);
|
||||
printCheckResult("env", "", true);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -166,7 +174,7 @@ public void invoke(String... args) {
|
|||
for (String exc : profile.getUpdateExclusions()) {
|
||||
StringTokenizer tokenizer = new StringTokenizer(exc, "/");
|
||||
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;
|
||||
continue;
|
||||
}
|
||||
|
@ -174,19 +182,19 @@ public void invoke(String... args) {
|
|||
String nextToken = tokenizer.nextToken();
|
||||
if (!tokenizer.hasMoreTokens()) {
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!bad)
|
||||
printCheckResult(LogHelper.Level.INFO, profileModuleName, "", true);
|
||||
printCheckResult(profileModuleName, "", true);
|
||||
}
|
||||
|
||||
//Linux permissions check
|
||||
|
@ -201,34 +209,34 @@ public void invoke(String... args) {
|
|||
String[] words = parts[1].trim().split(" ");
|
||||
uid = Integer.parseInt(words[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")) {
|
||||
String[] words = parts[1].trim().split(" ");
|
||||
gid = Integer.parseInt(words[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))) {
|
||||
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"))) {
|
||||
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"))) {
|
||||
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"))) {
|
||||
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) {
|
||||
LogHelper.error(e);
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
LogHelper.info("Check completed");
|
||||
logger.info("Check completed");
|
||||
}
|
||||
public boolean checkOtherWriteAccess(Path file) throws IOException {
|
||||
Set<PosixFilePermission> permissionSet = Files.getPosixFilePermissions(file);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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.auth.AuthProviderPair;
|
||||
import pro.gravit.launchserver.auth.handler.CachedAuthHandler;
|
||||
|
@ -9,6 +11,8 @@
|
|||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class ServerStatusCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public ServerStatusCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
@ -25,23 +29,23 @@ public String getUsageDescription() {
|
|||
|
||||
@Override
|
||||
public void invoke(String... args) {
|
||||
LogHelper.info("Show server status");
|
||||
LogHelper.info("Memory: free %d | total: %d | max: %d", JVMHelper.RUNTIME.freeMemory(), JVMHelper.RUNTIME.totalMemory(), JVMHelper.RUNTIME.maxMemory());
|
||||
logger.info("Show server status");
|
||||
logger.info("Memory: free {} | total: {} | max: {}", JVMHelper.RUNTIME.freeMemory(), JVMHelper.RUNTIME.totalMemory(), JVMHelper.RUNTIME.maxMemory());
|
||||
long uptime = JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000;
|
||||
long second = uptime % 60;
|
||||
long min = (uptime / 60) % 60;
|
||||
long hour = (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);
|
||||
LogHelper.info("Uptime (double): %f", (double) JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000);
|
||||
logger.info("Uptime: {} days {} hours {} minutes {} seconds", days, hour, min, second);
|
||||
logger.info("Uptime (double): {}", (double) JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000);
|
||||
int commands = server.commandHandler.getBaseCategory().commandsMap().size();
|
||||
for (CommandHandler.Category category : server.commandHandler.getCategories()) {
|
||||
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()) {
|
||||
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;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.binary.tasks.SignJarTask;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
|
@ -12,6 +14,8 @@
|
|||
import java.util.Optional;
|
||||
|
||||
public class SignDirCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public SignDirCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
@ -35,7 +39,7 @@ public void invoke(String... args) throws Exception {
|
|||
Optional<SignJarTask> task = server.launcherBinary.getTaskByClass(SignJarTask.class);
|
||||
if (task.isEmpty()) throw new IllegalStateException("SignJarTask not found");
|
||||
IOHelper.walk(targetDir, new SignJarVisitor(task.get()), true);
|
||||
LogHelper.info("Success signed");
|
||||
logger.info("Success signed");
|
||||
}
|
||||
|
||||
private class SignJarVisitor extends SimpleFileVisitor<Path> {
|
||||
|
@ -49,7 +53,7 @@ public SignJarVisitor(SignJarTask task) {
|
|||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
if (file.toFile().getName().endsWith(".jar")) {
|
||||
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);
|
||||
Files.deleteIfExists(file);
|
||||
Files.move(tmpSign, file);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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.binary.tasks.SignJarTask;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
|
@ -11,6 +13,8 @@
|
|||
import java.util.Optional;
|
||||
|
||||
public class SignJarCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public SignJarCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
@ -34,15 +38,15 @@ public void invoke(String... args) throws Exception {
|
|||
tmpSign = Paths.get(args[1]);
|
||||
else
|
||||
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);
|
||||
if (task.isEmpty()) throw new IllegalStateException("SignJarTask not found");
|
||||
task.get().sign(server.config.sign, target, tmpSign);
|
||||
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.move(tmpSign, target);
|
||||
}
|
||||
LogHelper.info("Success signed");
|
||||
logger.info("Success signed");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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.launchserver.Reconfigurable;
|
||||
import pro.gravit.utils.command.Command;
|
||||
|
@ -12,6 +14,7 @@
|
|||
import java.util.Map;
|
||||
|
||||
public abstract class AbstractLimiter<T> extends Component implements NeedGarbageCollection, Reconfigurable {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
public final List<T> exclude = new ArrayList<>();
|
||||
protected final transient Map<T, LimitEntry> map = new HashMap<>();
|
||||
public int rateLimit;
|
||||
|
@ -25,7 +28,7 @@ public Map<String, Command> getCommands() {
|
|||
public void invoke(String... args) {
|
||||
long size = map.size();
|
||||
garbageCollection();
|
||||
LogHelper.info("Cleared %d entity", size);
|
||||
logger.info("Cleared {} entity", size);
|
||||
}
|
||||
});
|
||||
commands.put("clear", new SubCommand() {
|
||||
|
@ -33,7 +36,7 @@ public void invoke(String... args) {
|
|||
public void invoke(String... args) {
|
||||
long size = map.size();
|
||||
map.clear();
|
||||
LogHelper.info("Cleared %d entity", size);
|
||||
logger.info("Cleared {} entity", size);
|
||||
}
|
||||
});
|
||||
commands.put("addExclude", new SubCommand() {
|
||||
|
|
|
@ -113,7 +113,7 @@ else if(jfxPath != null && checkFXJMods(jfxPath)) {
|
|||
ProGuard proGuard = new ProGuard(proguard_cfg);
|
||||
proGuard.execute();
|
||||
} catch (ParseException e) {
|
||||
LogHelper.error(e);
|
||||
logger.error(e);
|
||||
}
|
||||
} else
|
||||
IOHelper.copy(inputFile, outputJar);
|
||||
|
@ -247,7 +247,7 @@ public void prepare(boolean force) {
|
|||
genWords(force);
|
||||
genConfig(force);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(e);
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
import io.netty.channel.epoll.Epoll;
|
||||
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.LauncherConfig;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
|
@ -48,6 +50,7 @@ public final class LaunchServerConfig {
|
|||
public String startScript;
|
||||
private transient LaunchServer server = null;
|
||||
private transient AuthProviderPair authDefault;
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) {
|
||||
LaunchServerConfig newConfig = new LaunchServerConfig();
|
||||
|
@ -222,13 +225,13 @@ public void close(LaunchServer.ReloadType type) {
|
|||
try {
|
||||
((AutoCloseable) component).close();
|
||||
} catch (Exception e) {
|
||||
LogHelper.error(e);
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogHelper.error(e);
|
||||
logger.error(e);
|
||||
}
|
||||
if (protectHandler != null) {
|
||||
server.unregisterObject("protectHandler", protectHandler);
|
||||
|
@ -240,7 +243,7 @@ public void close(LaunchServer.ReloadType type) {
|
|||
try {
|
||||
((AutoCloseable) sessions).close();
|
||||
} catch (Exception e) {
|
||||
LogHelper.error(e);
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -250,7 +253,7 @@ public void close(LaunchServer.ReloadType type) {
|
|||
try {
|
||||
((AutoCloseable) dao).close();
|
||||
} catch (Exception e) {
|
||||
LogHelper.error(e);
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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.SecurityHelper;
|
||||
|
||||
|
@ -9,11 +11,12 @@ public class LaunchServerRuntimeConfig {
|
|||
public String oemUnlockKey;
|
||||
public String registerApiKey;
|
||||
public String clientCheckSecret;
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
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) {
|
||||
LogHelper.warning("[RuntimeConfig] clientCheckSecret must not be null");
|
||||
logger.warn("[RuntimeConfig] clientCheckSecret must not be null");
|
||||
clientCheckSecret = SecurityHelper.randomStringToken();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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.LauncherTrustManager;
|
||||
import pro.gravit.launcher.modules.LauncherModule;
|
||||
|
@ -29,6 +31,7 @@ public class LauncherModuleLoader {
|
|||
public final List<ModuleEntity> launcherModules = new ArrayList<>();
|
||||
public final Path modulesDir;
|
||||
private final LaunchServer server;
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public LauncherModuleLoader(LaunchServer server) {
|
||||
this.server = server;
|
||||
|
@ -40,7 +43,7 @@ public void init() {
|
|||
try {
|
||||
Files.createDirectories(modulesDir);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(e);
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
server.commandHandler.registerCommand("syncLauncherModules", new SyncLauncherModulesCommand(this));
|
||||
|
@ -54,14 +57,14 @@ public void init() {
|
|||
});
|
||||
mainTask.postBuildHook.registerHook((buildContext) -> {
|
||||
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);
|
||||
}
|
||||
});
|
||||
try {
|
||||
syncModules();
|
||||
} 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);
|
||||
String propertyName = prefix.concat(".").concat(field.getName().toLowerCase(Locale.US));
|
||||
if (InjectClassAcceptor.isSerializableValue(obj)) {
|
||||
LogHelper.dev("Property name %s", propertyName);
|
||||
logger.trace("Property name {}", propertyName);
|
||||
propertyMap.put(propertyName, obj);
|
||||
} else {
|
||||
//Try recursive add fields
|
||||
|
@ -109,7 +112,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
Attributes attributes = f.getManifest().getMainAttributes();
|
||||
String mainClass = attributes.getValue("Module-Main-Class");
|
||||
if (mainClass == null) {
|
||||
LogHelper.error("In module %s MainClass not found", file.toString());
|
||||
logger.error("In module {} MainClass not found", file.toString());
|
||||
} else {
|
||||
if (classLoader == null)
|
||||
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);
|
||||
} catch (Throwable e) {
|
||||
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 {
|
||||
LogHelper.error(e);
|
||||
logger.error(e);
|
||||
}
|
||||
return super.visitFile(file, attrs);
|
||||
}
|
||||
|
@ -132,7 +135,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
if (entity.moduleConfigClass != null) {
|
||||
entity.moduleConfigName = attributes.getValue("Module-Config-Name");
|
||||
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 {
|
||||
try {
|
||||
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 targetConfig;
|
||||
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)) {
|
||||
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<>();
|
||||
addClassFieldsToProperties(entity.propertyMap, "modules.".concat(entity.moduleConfigName.toLowerCase()), targetConfig, clazz);
|
||||
} catch (Throwable e) {
|
||||
LogHelper.error(e);
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
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.helper.LogHelper;
|
||||
|
||||
public class SyncLauncherModulesCommand extends Command {
|
||||
private final LauncherModuleLoader mod;
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public SyncLauncherModulesCommand(LauncherModuleLoader mod) {
|
||||
this.mod = mod;
|
||||
|
@ -24,6 +27,6 @@ public String getUsageDescription() {
|
|||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
mod.syncModules();
|
||||
LogHelper.info("Launcher Modules synced");
|
||||
logger.info("Launcher Modules synced");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
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.x500.X500Name;
|
||||
import org.bouncycastle.asn1.x500.X500NameBuilder;
|
||||
|
@ -54,6 +56,7 @@ public class CertificateManager {
|
|||
public AsymmetricKeyParameter serverKey;
|
||||
public LauncherTrustManager trustManager;
|
||||
public String orgName;
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public X509CertificateHolder generateCertificate(String subjectName, PublicKey subjectPublicKey) throws OperatorCreationException {
|
||||
SubjectPublicKeyInfo subjectPubKeyInfo = SubjectPublicKeyInfo.getInstance(subjectPublicKey.getEncoded());
|
||||
|
@ -180,7 +183,7 @@ public void readTrustStore(Path dir) throws IOException, CertificateException {
|
|||
|
||||
} else {
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
@ -210,7 +213,7 @@ public void checkClass(Class<?> clazz, LauncherTrustManager.CheckMode mode) thro
|
|||
if (mode == LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED)
|
||||
throw new SecurityException(String.format("Class %s not signed", clazz.getName()));
|
||||
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;
|
||||
}
|
||||
try {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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.LogHelper;
|
||||
import pro.gravit.utils.helper.SecurityHelper;
|
||||
|
@ -18,6 +20,7 @@ public class KeyAgreementManager {
|
|||
public final ECPrivateKey ecdsaPrivateKey;
|
||||
public final RSAPublicKey rsaPublicKey;
|
||||
public final RSAPrivateKey rsaPrivateKey;
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public KeyAgreementManager(ECPublicKey ecdsaPublicKey, ECPrivateKey ecdsaPrivateKey, RSAPublicKey rsaPublicKey, RSAPrivateKey rsaPrivateKey) {
|
||||
this.ecdsaPublicKey = ecdsaPublicKey;
|
||||
|
@ -29,33 +32,33 @@ public KeyAgreementManager(ECPublicKey ecdsaPublicKey, ECPrivateKey ecdsaPrivate
|
|||
public KeyAgreementManager(Path keyDirectory) throws IOException, InvalidKeySpecException {
|
||||
Path ecdsaPublicKeyPath = keyDirectory.resolve("ecdsa_id.pub"), ecdsaPrivateKeyPath = keyDirectory.resolve("ecdsa_id");
|
||||
if (IOHelper.isFile(ecdsaPublicKeyPath) && IOHelper.isFile(ecdsaPrivateKeyPath)) {
|
||||
LogHelper.info("Reading ECDSA keypair");
|
||||
logger.info("Reading ECDSA keypair");
|
||||
ecdsaPublicKey = SecurityHelper.toPublicECDSAKey(IOHelper.read(ecdsaPublicKeyPath));
|
||||
ecdsaPrivateKey = SecurityHelper.toPrivateECDSAKey(IOHelper.read(ecdsaPrivateKeyPath));
|
||||
} else {
|
||||
LogHelper.info("Generating ECDSA keypair");
|
||||
logger.info("Generating ECDSA keypair");
|
||||
KeyPair pair = SecurityHelper.genECDSAKeyPair(new SecureRandom());
|
||||
ecdsaPublicKey = (ECPublicKey) pair.getPublic();
|
||||
ecdsaPrivateKey = (ECPrivateKey) pair.getPrivate();
|
||||
|
||||
// Write key pair list
|
||||
LogHelper.info("Writing ECDSA keypair list");
|
||||
logger.info("Writing ECDSA keypair list");
|
||||
IOHelper.write(ecdsaPublicKeyPath, ecdsaPublicKey.getEncoded());
|
||||
IOHelper.write(ecdsaPrivateKeyPath, ecdsaPrivateKey.getEncoded());
|
||||
}
|
||||
Path rsaPublicKeyPath = keyDirectory.resolve("rsa_id.pub"), rsaPrivateKeyPath = keyDirectory.resolve("rsa_id");
|
||||
if (IOHelper.isFile(rsaPublicKeyPath) && IOHelper.isFile(rsaPrivateKeyPath)) {
|
||||
LogHelper.info("Reading RSA keypair");
|
||||
logger.info("Reading RSA keypair");
|
||||
rsaPublicKey = SecurityHelper.toPublicRSAKey(IOHelper.read(rsaPublicKeyPath));
|
||||
rsaPrivateKey = SecurityHelper.toPrivateRSAKey(IOHelper.read(rsaPrivateKeyPath));
|
||||
} else {
|
||||
LogHelper.info("Generating RSA keypair");
|
||||
logger.info("Generating RSA keypair");
|
||||
KeyPair pair = SecurityHelper.genRSAKeyPair(new SecureRandom());
|
||||
rsaPublicKey = (RSAPublicKey) pair.getPublic();
|
||||
rsaPrivateKey = (RSAPrivateKey) pair.getPrivate();
|
||||
|
||||
// Write key pair list
|
||||
LogHelper.info("Writing RSA keypair list");
|
||||
logger.info("Writing RSA keypair list");
|
||||
IOHelper.write(rsaPublicKeyPath, rsaPublicKey.getEncoded());
|
||||
IOHelper.write(rsaPrivateKeyPath, rsaPrivateKey.getEncoded());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package pro.gravit.launchserver.manangers;
|
||||
|
||||
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.utils.HttpDownloader;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
|
@ -16,6 +18,7 @@
|
|||
public class MirrorManager {
|
||||
protected final ArrayList<Mirror> list = new ArrayList<>();
|
||||
private Mirror defaultMirror;
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public void addMirror(String 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 {
|
||||
if (!mirror.enabled) return false;
|
||||
URL url = mirror.getURL(mask, args);
|
||||
LogHelper.debug("Try download %s", url.toString());
|
||||
logger.debug("Try download {}", url.toString());
|
||||
try {
|
||||
HttpDownloader.downloadZip(url, path);
|
||||
} 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 true;
|
||||
|
@ -82,7 +85,7 @@ public JsonElement jsonRequest(Mirror mirror, JsonElement request, String method
|
|||
try {
|
||||
return HTTPRequest.jsonRequest(request, method, url);
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler;
|
||||
import io.netty.handler.logging.LoggingHandler;
|
||||
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.config.LaunchServerConfig;
|
||||
import pro.gravit.launchserver.socket.handlers.NettyIpForwardHandler;
|
||||
|
@ -33,15 +35,16 @@ public class LauncherNettyServer implements AutoCloseable {
|
|||
public final EventLoopGroup workerGroup;
|
||||
public final WebSocketService service;
|
||||
public final BiHookSet<NettyConnectContext, SocketChannel> pipelineHook = new BiHookSet<>();
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public LauncherNettyServer(LaunchServer server) {
|
||||
LaunchServerConfig.NettyConfig config = server.config.netty;
|
||||
NettyObjectFactory.setUsingEpoll(config.performance.usingEpoll);
|
||||
if (config.performance.usingEpoll) {
|
||||
LogHelper.debug("Netty: Epoll enabled");
|
||||
logger.debug("Netty: Epoll enabled");
|
||||
}
|
||||
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");
|
||||
workerGroup = NettyObjectFactory.newEventLoopGroup(config.performance.workerThread, "LauncherNettyServer.workerGroup");
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package pro.gravit.launchserver.socket;
|
||||
|
||||
import io.netty.util.concurrent.DefaultThreadFactory;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class NettyThreadFactory extends DefaultThreadFactory {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public NettyThreadFactory(String poolName) {
|
||||
super(poolName);
|
||||
}
|
||||
|
@ -12,8 +16,10 @@ public NettyThreadFactory(String poolName) {
|
|||
protected Thread newThread(Runnable r, String name) {
|
||||
Thread thread = super.newThread(r, name);
|
||||
thread.setUncaughtExceptionHandler((th, e) -> {
|
||||
if (LogHelper.isDebugEnabled())
|
||||
LogHelper.error(e);
|
||||
if(e.getMessage().contains("Connection reset by peer")) {
|
||||
return;
|
||||
}
|
||||
logger.error(e);
|
||||
});
|
||||
return thread;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
import io.netty.channel.group.ChannelGroup;
|
||||
import io.netty.channel.group.ChannelMatchers;
|
||||
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.events.ExceptionEvent;
|
||||
import pro.gravit.launcher.events.RequestEvent;
|
||||
|
@ -58,6 +60,7 @@ public class WebSocketService {
|
|||
public final AtomicLong lastRequestTime = new AtomicLong();
|
||||
private final LaunchServer server;
|
||||
private final Gson gson;
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public WebSocketService(ChannelGroup channels, LaunchServer server) {
|
||||
this.channels = channels;
|
||||
|
@ -161,7 +164,7 @@ void process(ChannelHandlerContext ctx, WebSocketServerResponse response, Client
|
|||
try {
|
||||
response.execute(ctx, client);
|
||||
} catch (Exception e) {
|
||||
LogHelper.error(e);
|
||||
logger.error(e);
|
||||
RequestEvent event;
|
||||
if (server.config.netty.sendExceptionEnabled) {
|
||||
event = new ExceptionEvent(e);
|
||||
|
|
Loading…
Reference in a new issue