mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-03 22:30:31 +03:00
parent
ef57f8b02f
commit
b2b810ddea
12 changed files with 37 additions and 31 deletions
|
@ -66,7 +66,6 @@
|
|||
|
||||
public final class LaunchServer implements Runnable, AutoCloseable {
|
||||
public static final class Config extends ConfigObject {
|
||||
|
||||
public final int port;
|
||||
|
||||
// Handlers & Providers
|
||||
|
@ -80,6 +79,9 @@ public static final class Config extends ConfigObject {
|
|||
public final HWIDHandler hwidHandler;
|
||||
|
||||
// Misc options
|
||||
public final int threadCount;
|
||||
|
||||
public final int threadCoreCount;
|
||||
|
||||
public final ExeConf launch4j;
|
||||
|
||||
|
@ -111,6 +113,11 @@ private Config(BlockConfigEntry block, Path coredir, LaunchServer server) {
|
|||
address = block.getEntry("address", StringConfigEntry.class);
|
||||
port = VerifyHelper.verifyInt(block.getEntryValue("port", IntegerConfigEntry.class),
|
||||
VerifyHelper.range(0, 65535), "Illegal LaunchServer port");
|
||||
threadCoreCount = block.hasEntry("threadCoreCacheSize") ? VerifyHelper.verifyInt(block.getEntryValue("threadCoreCacheSize", IntegerConfigEntry.class),
|
||||
VerifyHelper.range(0, 100), "Illegal LaunchServer inital thread pool cache size") : 0;
|
||||
int internalThreadCount = block.hasEntry("threadCacheSize") ? VerifyHelper.verifyInt(block.getEntryValue("threadCacheSize", IntegerConfigEntry.class),
|
||||
VerifyHelper.range(2, 100), "Illegal LaunchServer thread pool cache size") : (JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() >= 4 ? JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() / 2 : JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors());
|
||||
threadCount = threadCoreCount > internalThreadCount ? threadCoreCount : internalThreadCount;
|
||||
authRateLimit = VerifyHelper.verifyInt(block.getEntryValue("authRateLimit", IntegerConfigEntry.class),
|
||||
VerifyHelper.range(0, 1000000), "Illegal authRateLimit");
|
||||
authRateLimitMilis = VerifyHelper.verifyInt(block.getEntryValue("authRateLimitMilis", IntegerConfigEntry.class),
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@SuppressWarnings({"unused", "rawtypes"})
|
||||
public final class NettyServerSocketHandler implements Runnable, AutoCloseable {
|
||||
private static final String WEBSOCKET_PATH = "/api";
|
||||
private static SSLServerSocketFactory ssf;
|
||||
|
|
|
@ -5,8 +5,10 @@
|
|||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
|
@ -35,7 +37,7 @@ public interface Listener {
|
|||
// Instance
|
||||
private final LaunchServer server;
|
||||
private final AtomicReference<ServerSocket> serverSocket = new AtomicReference<>();
|
||||
private final ExecutorService threadPool = Executors.newCachedThreadPool(THREAD_FACTORY);
|
||||
private final ExecutorService threadPool;
|
||||
|
||||
public final SessionManager sessionManager;
|
||||
private final AtomicLong idCounter = new AtomicLong(0L);
|
||||
|
@ -43,13 +45,16 @@ public interface Listener {
|
|||
private volatile Listener listener;
|
||||
|
||||
public ServerSocketHandler(LaunchServer server) {
|
||||
this.server = server;
|
||||
sessionManager = new SessionManager();
|
||||
this(server, new SessionManager());
|
||||
GarbageManager.registerNeedGC(sessionManager);
|
||||
}
|
||||
|
||||
public ServerSocketHandler(LaunchServer server, SessionManager sessionManager) {
|
||||
this.server = server;
|
||||
threadPool = new ThreadPoolExecutor(server.config.threadCoreCount, Integer.MAX_VALUE,
|
||||
server.config.threadCount, TimeUnit.SECONDS,
|
||||
new SynchronousQueue<Runnable>(),
|
||||
THREAD_FACTORY);
|
||||
this.sessionManager = sessionManager;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
@SuppressWarnings({"unused", "rawtypes"})
|
||||
public class WebSocketService {
|
||||
public final ChannelGroup channels;
|
||||
|
||||
|
@ -30,9 +31,8 @@ public WebSocketService(ChannelGroup channels, LaunchServer server, GsonBuilder
|
|||
this.channels = channels;
|
||||
this.server = server;
|
||||
this.gsonBuiler = gson;
|
||||
this.
|
||||
gsonBuiler.registerTypeAdapter(JsonResponseInterface.class, new JsonResponseAdapter(this));
|
||||
gsonBuiler.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter());
|
||||
this.gsonBuiler.registerTypeAdapter(JsonResponseInterface.class, new JsonResponseAdapter(this));
|
||||
this.gsonBuiler.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter());
|
||||
this.gson = gsonBuiler.create();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class CheckServerResponse implements JsonResponseInterface {
|
||||
public String serverID;
|
||||
public String username;
|
||||
|
@ -21,9 +19,8 @@ public String getType() {
|
|||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = LaunchServer.server.config.authHandler[0].checkServer(username, serverID);
|
||||
LaunchServer.server.config.authHandler[0].checkServer(username, serverID);
|
||||
} catch (AuthException e) {
|
||||
service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage()));
|
||||
return;
|
||||
|
|
|
@ -13,8 +13,8 @@ public class ClientWebSocketService {
|
|||
public final GsonBuilder gsonBuilder;
|
||||
public final Gson gson;
|
||||
public final ClientJSONPoint point;
|
||||
private HashMap<String, Class> requests;
|
||||
private HashMap<String, Class> results;
|
||||
private HashMap<String, Class<RequestInterface>> requests;
|
||||
private HashMap<String, Class<ResultInterface>> results;
|
||||
|
||||
public ClientWebSocketService(GsonBuilder gsonBuilder, ClientJSONPoint point) {
|
||||
requests = new HashMap<>();
|
||||
|
@ -32,11 +32,11 @@ public void processMessage(Reader reader) {
|
|||
result.process();
|
||||
}
|
||||
|
||||
public Class getRequestClass(String key) {
|
||||
public Class<RequestInterface> getRequestClass(String key) {
|
||||
return requests.get(key);
|
||||
}
|
||||
|
||||
public void registerRequest(String key, Class clazz) {
|
||||
public void registerRequest(String key, Class<RequestInterface> clazz) {
|
||||
requests.put(key, clazz);
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ public void registerRequests() {
|
|||
|
||||
}
|
||||
|
||||
public void registerResult(String key, Class clazz) {
|
||||
public void registerResult(String key, Class<ResultInterface> clazz) {
|
||||
results.put(key, clazz);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,12 +14,6 @@ public class ServerAgent {
|
|||
public static Instrumentation inst;
|
||||
|
||||
public static final class StarterVisitor extends SimpleFileVisitor<Path> {
|
||||
private Instrumentation inst;
|
||||
|
||||
public StarterVisitor(Instrumentation inst) {
|
||||
this.inst = inst;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
if (file.toFile().getName().endsWith(".jar")) addJVMClassPath(new JarFile(file.toFile()));
|
||||
|
@ -51,7 +45,7 @@ public static void premain(String agentArgument, Instrumentation instrumentation
|
|||
isAgentStarted = true;
|
||||
|
||||
try {
|
||||
Files.walkFileTree(Paths.get("libraries"), Collections.singleton(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new StarterVisitor(inst));
|
||||
Files.walkFileTree(Paths.get("libraries"), Collections.singleton(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new StarterVisitor());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ public static boolean auth(ServerWrapper wrapper) {
|
|||
try {
|
||||
LauncherConfig cfg = Launcher.getConfig();
|
||||
Boolean auth = new AuthServerRequest(cfg, config.login, SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), 0, config.title).request();
|
||||
if (auth == null) throw new Exception("Non auth!"); // security check
|
||||
ProfilesRequest.Result result = new ProfilesRequest(cfg).request();
|
||||
for (SignedObjectHolder<ClientProfile> p : result.profiles) {
|
||||
LogHelper.debug("Get profile: %s", p.object.getTitle());
|
||||
|
|
|
@ -265,7 +265,7 @@ private HashedDir sideDiff(HashedDir other, FileNameMatcher matcher, Deque<Strin
|
|||
return diff;
|
||||
}
|
||||
|
||||
private HashedDir sideCompare(HashedDir other, FileNameMatcher matcher, Deque<String> path, boolean mismatchList) {
|
||||
public HashedDir sideCompare(HashedDir other, FileNameMatcher matcher, Deque<String> path, boolean mismatchList) {
|
||||
HashedDir diff = new HashedDir();
|
||||
for (Entry<String, HashedEntry> mapEntry : map.entrySet()) {
|
||||
String name = mapEntry.getKey();
|
||||
|
|
|
@ -15,7 +15,7 @@ public HashedEntryAdapter() {
|
|||
@Override
|
||||
public HashedEntry deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
||||
Class cls = null;
|
||||
Class<?> cls = null;
|
||||
if (typename.equals("dir")) cls = HashedDir.class;
|
||||
if (typename.equals("file")) cls = HashedFile.class;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
public class LauncherSSLContext {
|
||||
public SSLServerSocketFactory ssf;
|
||||
public SSLSocketFactory sf;
|
||||
@SuppressWarnings("unused")
|
||||
private SSLContext sc;
|
||||
|
||||
public LauncherSSLContext(KeyStore ks, String keypassword) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException {
|
||||
|
|
|
@ -115,7 +115,7 @@ public static URL[] getClassPathURL() {
|
|||
return list;
|
||||
}
|
||||
|
||||
public static void checkStackTrace(Class mainClass) {
|
||||
public static void checkStackTrace(Class<?> mainClass) {
|
||||
LogHelper.debug("Testing stacktrace");
|
||||
Exception e = new Exception("Testing stacktrace");
|
||||
StackTraceElement[] list = e.getStackTrace();
|
||||
|
|
Loading…
Reference in a new issue