mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[REFACTOR] IDEA Code Inspect
This commit is contained in:
parent
f7decac23d
commit
038af764a1
26 changed files with 48 additions and 71 deletions
|
@ -34,7 +34,6 @@
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.ProcessBuilder.Redirect;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.security.KeyStore;
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
import pro.gravit.utils.launch.LaunchOptions;
|
||||
import pro.gravit.utils.launch.ModuleLaunch;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
import pro.gravit.utils.ProviderMap;
|
||||
import pro.gravit.utils.command.Command;
|
||||
import pro.gravit.utils.command.SubCommand;
|
||||
import pro.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
import pro.gravit.launcher.base.events.request.GetAvailabilityAuthRequestEvent;
|
||||
import pro.gravit.launcher.base.request.auth.AuthRequest;
|
||||
import pro.gravit.launcher.base.request.auth.details.AuthLoginOnlyDetails;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthException;
|
||||
import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportSudo;
|
||||
import pro.gravit.launchserver.manangers.AuthManager;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package pro.gravit.launchserver.auth.core;
|
||||
|
||||
import pro.gravit.launcher.base.request.auth.AuthRequest;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthException;
|
||||
import pro.gravit.launchserver.manangers.AuthManager;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
import pro.gravit.launchserver.command.hash.*;
|
||||
import pro.gravit.launchserver.command.modules.LoadModuleCommand;
|
||||
import pro.gravit.launchserver.command.modules.ModulesCommand;
|
||||
import pro.gravit.launchserver.command.profiles.MakeProfileCommand;
|
||||
import pro.gravit.launchserver.command.profiles.ProfilesCommand;
|
||||
import pro.gravit.launchserver.command.profiles.SaveProfilesCommand;
|
||||
import pro.gravit.launchserver.command.service.*;
|
||||
import pro.gravit.launchserver.command.sync.*;
|
||||
import pro.gravit.launchserver.command.tools.SignDirCommand;
|
||||
|
|
|
@ -60,19 +60,19 @@ public void invoke(String... args) {
|
|||
LaunchServerConfig config = server.config;
|
||||
config.auth.forEach((name, pair) -> {
|
||||
});
|
||||
if (config.protectHandler instanceof NoProtectHandler) {
|
||||
printCheckResult("protectHandler", "protectHandler none", false);
|
||||
} else if (config.protectHandler instanceof AdvancedProtectHandler) {
|
||||
switch (config.protectHandler) {
|
||||
case NoProtectHandler noProtectHandler -> printCheckResult("protectHandler", "protectHandler none", false);
|
||||
case AdvancedProtectHandler advancedProtectHandler -> {
|
||||
printCheckResult("protectHandler", "", true);
|
||||
if (!((AdvancedProtectHandler) config.protectHandler).enableHardwareFeature) {
|
||||
if (!advancedProtectHandler.enableHardwareFeature) {
|
||||
printCheckResult("protectHandler.hardwareId", "you can improve security by using hwid provider", null);
|
||||
} else {
|
||||
printCheckResult("protectHandler.hardwareId", "", true);
|
||||
}
|
||||
} else if (config.protectHandler instanceof StdProtectHandler) {
|
||||
}
|
||||
case StdProtectHandler stdProtectHandler ->
|
||||
printCheckResult("protectHandler", "you can improve security by using advanced", null);
|
||||
} else {
|
||||
printCheckResult("protectHandler", "unknown protectHandler", null);
|
||||
case null, default -> printCheckResult("protectHandler", "unknown protectHandler", null);
|
||||
}
|
||||
if (config.netty.address.startsWith("ws://")) {
|
||||
if (config.netty.ipForwarding)
|
||||
|
@ -110,7 +110,7 @@ public void invoke(String... args) {
|
|||
KeyStore keyStore = SignHelper.getStore(new File(config.sign.keyStore).toPath(), config.sign.keyStorePass, config.sign.keyStoreType);
|
||||
Certificate[] certChainPlain = keyStore.getCertificateChain(config.sign.keyAlias);
|
||||
List<X509Certificate> certChain = Arrays.stream(certChainPlain).map(e -> (X509Certificate) e).toList();
|
||||
X509Certificate cert = certChain.get(0);
|
||||
X509Certificate cert = certChain.getFirst();
|
||||
cert.checkValidity();
|
||||
if (certChain.size() == 1) {
|
||||
printCheckResult("sign", "certificate chain contains <2 element(recommend 2 and more)", false);
|
||||
|
|
|
@ -90,7 +90,7 @@ public boolean check(T address) {
|
|||
}
|
||||
}
|
||||
|
||||
static class LimitEntry {
|
||||
protected static class LimitEntry {
|
||||
long time;
|
||||
int trys;
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
import pro.gravit.utils.command.SubCommand;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.JVMHelper;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
import pro.gravit.utils.helper.SecurityHelper;
|
||||
import pro.gravit.utils.helper.UnpackHelper;
|
||||
|
||||
|
@ -20,7 +19,6 @@
|
|||
import java.nio.file.Paths;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
|
@ -15,9 +15,7 @@
|
|||
import pro.gravit.launchserver.components.AuthLimiterComponent;
|
||||
import pro.gravit.launchserver.components.Component;
|
||||
import pro.gravit.launchserver.components.ProGuardComponent;
|
||||
import pro.gravit.utils.helper.JVMHelper;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.HOURS;
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
import pro.gravit.launchserver.socket.response.auth.JoinServerResponse;
|
||||
import pro.gravit.launchserver.socket.response.auth.SetProfileResponse;
|
||||
import pro.gravit.utils.BiHookSet;
|
||||
import pro.gravit.utils.HookSet;
|
||||
|
||||
public class AuthHookManager {
|
||||
public final BiHookSet<AuthResponse.AuthContext, Client> preHook = new BiHookSet<>();
|
||||
|
|
|
@ -142,9 +142,7 @@ public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client
|
|||
if(executors == null) {
|
||||
process(safeStatus, client, ip, context, response);
|
||||
} else {
|
||||
executors.submit(() -> {
|
||||
process(safeStatus, client, ip, context, response);
|
||||
});
|
||||
executors.submit(() -> process(safeStatus, client, ip, context, response));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,8 @@ protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) {
|
|||
} catch (Throwable ex) {
|
||||
logger.error("WebSocket frame handler hook error", ex);
|
||||
}
|
||||
if (frame instanceof TextWebSocketFrame textWebSocketFrame) {
|
||||
switch (frame) {
|
||||
case TextWebSocketFrame textWebSocketFrame -> {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Message from {}: {}", context.ip == null ? IOHelper.getIP(ctx.channel().remoteAddress()) : context.ip, textWebSocketFrame.text());
|
||||
}
|
||||
|
@ -77,20 +78,23 @@ protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) {
|
|||
}
|
||||
ctx.channel().close();
|
||||
}
|
||||
} else if ((frame instanceof PingWebSocketFrame)) {
|
||||
}
|
||||
case PingWebSocketFrame pingWebSocketFrame -> {
|
||||
frame.content().retain();
|
||||
ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content()));
|
||||
//return;
|
||||
} else if (frame instanceof PongWebSocketFrame) {
|
||||
logger.trace("WebSocket Client received pong");
|
||||
} else if (frame instanceof CloseWebSocketFrame closeWebSocketFrame) {
|
||||
}
|
||||
case PongWebSocketFrame pongWebSocketFrame -> logger.trace("WebSocket Client received pong");
|
||||
case CloseWebSocketFrame closeWebSocketFrame -> {
|
||||
int statusCode = closeWebSocketFrame.statusCode();
|
||||
ctx.channel().close();
|
||||
} else {
|
||||
}
|
||||
case null, default -> {
|
||||
String message = "unsupported frame type: " + frame.getClass().getName();
|
||||
logger.error(new UnsupportedOperationException(message)); // prevent strange crash here.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext channelHandlerContext) throws Exception {
|
||||
|
|
|
@ -152,7 +152,7 @@ private static void setDateAndCacheHeaders(HttpResponse response, File fileToCac
|
|||
response.headers().set(HttpHeaderNames.DATE, dateFormatter.format(time));
|
||||
|
||||
// Add cache headers
|
||||
response.headers().set(HttpHeaderNames.EXPIRES, dateFormatter.format(time.plus(HTTP_CACHE_SECONDS, ChronoUnit.SECONDS)));
|
||||
response.headers().set(HttpHeaderNames.EXPIRES, dateFormatter.format(time.plusSeconds(HTTP_CACHE_SECONDS)));
|
||||
response.headers().set(HttpHeaderNames.CACHE_CONTROL, "private, max-age=" + HTTP_CACHE_SECONDS);
|
||||
response.headers().set(
|
||||
HttpHeaderNames.LAST_MODIFIED, dateFormatter.format(Instant.ofEpochMilli(fileToCache.lastModified())));
|
||||
|
|
|
@ -150,7 +150,7 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException {
|
|||
systemClassPath.addAll(ClientLauncherEntryPoint.resolveClassPath(workDir, params.actions, params.profile)
|
||||
.filter(x -> !params.profile.getModulePath().contains(workDir.relativize(x).toString()))
|
||||
.map(Path::toString)
|
||||
.collect(Collectors.toList()));
|
||||
.toList());
|
||||
}
|
||||
if (Launcher.getConfig().environment != LauncherConfig.LauncherEnvironment.PROD) {
|
||||
processArgs.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, String.valueOf(LogHelper.isDevEnabled())));
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
|
|
@ -126,11 +126,7 @@ public void enable(OptionalFile file, boolean manual, BiConsumer<OptionalFile, B
|
|||
if (enabled.contains(file)) return;
|
||||
enabled.add(file);
|
||||
if (callback != null) callback.accept(file, true);
|
||||
OptionalFileInstallInfo installInfo = this.installInfo.get(file);
|
||||
if (installInfo == null) {
|
||||
installInfo = new OptionalFileInstallInfo();
|
||||
this.installInfo.put(file, installInfo);
|
||||
}
|
||||
OptionalFileInstallInfo installInfo = this.installInfo.computeIfAbsent(file, k -> new OptionalFileInstallInfo());
|
||||
installInfo.isManual = manual;
|
||||
if (file.dependencies != null) {
|
||||
for (OptionalFile dep : file.dependencies) {
|
||||
|
|
|
@ -27,7 +27,7 @@ public String getType() {
|
|||
return "batchProfileByUsername";
|
||||
}
|
||||
|
||||
static class Entry {
|
||||
public static class Entry {
|
||||
@LauncherNetworkAPI
|
||||
String username;
|
||||
@LauncherNetworkAPI
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
import java.security.cert.CertificateException;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
|
|
@ -13,8 +13,7 @@ public class BasicLauncherEventHandler implements RequestService.EventHandler {
|
|||
|
||||
@Override
|
||||
public <T extends WebSocketEvent> boolean eventHandle(T event) {
|
||||
if (event instanceof SecurityReportRequestEvent) {
|
||||
SecurityReportRequestEvent event1 = (SecurityReportRequestEvent) event;
|
||||
if (event instanceof SecurityReportRequestEvent event1) {
|
||||
if (event1.action == SecurityReportRequestEvent.ReportAction.TOKEN_EXPIRED) {
|
||||
try {
|
||||
Request.restore();
|
||||
|
@ -22,8 +21,7 @@ public <T extends WebSocketEvent> boolean eventHandle(T event) {
|
|||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
} else if (event instanceof ExtendedTokenRequestEvent) {
|
||||
ExtendedTokenRequestEvent event1 = (ExtendedTokenRequestEvent) event;
|
||||
} else if (event instanceof ExtendedTokenRequestEvent event1) {
|
||||
String token = event1.getExtendedToken();
|
||||
if (token != null) {
|
||||
Request.addExtendedToken(event1.getExtendedTokenName(), new Request.ExtendedToken(event1.getExtendedToken(), event1.getExtendedTokenExpire()));
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
import pro.gravit.launcher.base.modules.LauncherModule;
|
||||
import pro.gravit.launcher.base.modules.impl.SimpleModuleManager;
|
||||
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
|
|
@ -84,7 +84,6 @@ private static CheckClassResultTypeApi fromType(LauncherTrustManager.CheckClassR
|
|||
case UNTRUSTED -> CheckClassResultTypeApi.UNTRUSTED;
|
||||
case UNVERIFED -> CheckClassResultTypeApi.UNVERIFED;
|
||||
case UNCOMPAT -> CheckClassResultTypeApi.UNCOMPAT;
|
||||
default -> CheckClassResultTypeApi.UNKNOWN;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ public HashedDir(HInput input) throws IOException {
|
|||
entry = switch (type) {
|
||||
case FILE -> new HashedFile(input);
|
||||
case DIR -> new HashedDir(input);
|
||||
default -> throw new AssertionError("Unsupported hashed entry type: " + type.name());
|
||||
};
|
||||
|
||||
// Try add entry to map
|
||||
|
|
|
@ -61,7 +61,6 @@ public static String getNativeExtension(JVMHelper.OS OS_TYPE) {
|
|||
case MUSTDIE -> ".dll";
|
||||
case LINUX -> ".so";
|
||||
case MACOSX -> ".dylib";
|
||||
default -> throw new InternalError(String.format("Unsupported OS TYPE '%s'", OS_TYPE));
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ public static void unpackZipNoCheck(String resource, Path target) throws IOExcep
|
|||
IOHelper.transfer(input, target.resolve(IOHelper.toPath(entry.getName())));
|
||||
}
|
||||
}
|
||||
} catch (NoSuchFileException e) {
|
||||
} catch (NoSuchFileException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue