From 7d279da5af123b264ed4a4dd6dab6c9e41bcc175 Mon Sep 17 00:00:00 2001 From: xDark Date: Tue, 13 Aug 2019 21:02:33 +0300 Subject: [PATCH 1/3] =?UTF-8?q?[ANY]=20=D0=A7=D0=B8=D1=81=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/LaunchServer.java | 5 ++- .../auth/hwid/MysqlHWIDHandler.java | 16 ++++++-- .../auth/texture/RequestTextureProvider.java | 8 +++- .../command/dump/DumpSessionsCommand.java | 3 +- .../manangers/SessionManager.java | 39 ++++++++++--------- .../socket/LauncherNettyServer.java | 8 ++-- .../socket/NettyObjectFactory.java | 7 ++-- .../launchserver/socket/WebSocketService.java | 11 +++--- .../handlers/NettyIpForwardHandler.java | 4 +- .../handlers/WebSocketFrameHandler.java | 14 +++++-- .../socket/response/auth/AuthResponse.java | 5 ++- .../response/auth/CheckServerResponse.java | 4 +- .../response/auth/JoinServerResponse.java | 4 +- .../launcher/client/ClientLauncher.java | 6 +-- .../client/LauncherUpdateController.java | 12 ++++-- .../launcher/downloader/ListDownloader.java | 4 +- .../managers/SimpleModuleManager.java | 4 +- .../request/websockets/ClientJSONPoint.java | 6 +-- .../StandartClientWebSocketService.java | 8 ++-- .../websockets/WebSocketClientHandler.java | 6 ++- .../YggdrasilGameProfileRepository.java | 12 ++++-- .../YggdrasilMinecraftSessionService.java | 36 ++++++++++++----- .../java/cpw/mods/fml/SafeExitJVMLegacy.java | 6 +-- .../net/minecraftforge/fml/SafeExitJVM.java | 6 +-- .../pro/gravit/launcher/hasher/HashedDir.java | 16 ++++++-- .../launcher/hasher/HashedEntryAdapter.java | 1 - .../launcher/managers/GarbageManager.java | 5 ++- 27 files changed, 162 insertions(+), 94 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index edba1d34..24d8fb7e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -33,6 +33,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.zip.CRC32; +import io.netty.channel.epoll.Epoll; import org.bouncycastle.crypto.util.PrivateKeyFactory; import org.bouncycastle.operator.OperatorCreationException; @@ -359,7 +360,7 @@ public static void main(String... args) throws Throwable { LogHelper.printLicense("LaunchServer"); if (!StarterAgent.isAgentStarted()) { LogHelper.error("StarterAgent is not started!"); - LogHelper.error("Your should add to JVM options this option: `-javaagent:LaunchServer.jar`"); + LogHelper.error("You should add to JVM options this option: `-javaagent:LaunchServer.jar`"); } // Start LaunchServer @@ -810,7 +811,7 @@ private void generateConfigIfNotExists(boolean testEnv) throws IOException { newConfig.netty.fileServerEnabled = true; newConfig.netty.binds = new NettyBindAddress[]{new NettyBindAddress("0.0.0.0", 9274)}; newConfig.netty.performance = new NettyPerformanceConfig(); - newConfig.netty.performance.usingEpoll = JVMHelper.OS_TYPE == JVMHelper.OS.LINUX; //Only linux + newConfig.netty.performance.usingEpoll = Epoll.isAvailable(); newConfig.netty.performance.bossThread = 2; newConfig.netty.performance.workerThread = 8; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java index 2447034e..283af7d5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java @@ -153,11 +153,15 @@ public void onCheckInfo(OshiHWID hwid, String username, Connection c) throws HWI db_hwid.HWDiskSerial = set.getString(hwidFieldHWDiskSerial); db_hwid.totalMemory = Long.valueOf(set.getString(hwidFieldTotalMemory)); db_hwid.macAddr = set.getString(hwidFieldMAC); - LogHelper.dev("Compare HWID: %s vs %s", hwid.getSerializeString(), db_hwid.getSerializeString()); + if (LogHelper.isDevEnabled()) { + LogHelper.dev("Compare HWID: %s vs %s", hwid.getSerializeString(), db_hwid.getSerializeString()); + } int compare_point = hwid.compare(db_hwid); if (compare_point < compare) continue; else { - LogHelper.debug("User %s hwid check: found compare %d in %d", username, compare_point, set.getInt("id")); + if (LogHelper.isDevEnabled()) { + LogHelper.debug("User %s hwid check: found compare %d in %d", username, compare_point, set.getInt("id")); + } } } if (oneCompareMode) isOne = true; @@ -175,7 +179,9 @@ public void onCheckInfo(OshiHWID hwid, String username, Connection c) throws HWI } public void setIsBanned(HWID hwid, boolean isBanned) { - LogHelper.debug("%s Request HWID: %s", isBanned ? "Ban" : "UnBan", hwid.toString()); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("%s Request HWID: %s", isBanned ? "Ban" : "UnBan", hwid.toString()); + } if (hwid instanceof OshiHWID) { OshiHWID oshiHWID = (OshiHWID) hwid; try (Connection c = mySQLHolder.getConnection()) { @@ -214,7 +220,9 @@ public void unban(List list) { public List getHwid(String username) { ArrayList list = new ArrayList<>(); try (Connection c = mySQLHolder.getConnection()) { - LogHelper.debug("Try find HWID from username %s", username); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Try find HWID from username %s", username); + } PreparedStatement s = c.prepareStatement(String.format("SELECT %s, %s FROM `%s` WHERE `%s` = ? LIMIT 1", userFieldHwid, userFieldLogin, tableUsers, userFieldLogin)); s.setString(1, username); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java index f39bdaed..9e963f51 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java @@ -20,11 +20,15 @@ public RequestTextureProvider(String skinURL, String cloakURL) { } private static Texture getTexture(String url, boolean cloak) throws IOException { - LogHelper.debug("Getting texture: '%s'", url); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Getting texture: '%s'", url); + } try { return new Texture(url, cloak); } catch (FileNotFoundException ignored) { - LogHelper.subDebug("Texture not found :("); + if (LogHelper.isDebugEnabled()) { + LogHelper.subDebug("Texture not found :("); + } return null; // Simply not found } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpSessionsCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpSessionsCommand.java index 350e7515..90b790a7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpSessionsCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpSessionsCommand.java @@ -4,6 +4,7 @@ import java.io.Writer; import java.lang.reflect.Type; import java.nio.file.Paths; +import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -41,7 +42,7 @@ public void invoke(String... args) throws Exception { public void invoke(String... args) throws Exception { verifyArgs(args, 1); LogHelper.info("Sessions write to %s", args[0]); - Set clientSet = server.sessionManager.getSessions(); + Collection clientSet = server.sessionManager.getSessions(); try (Writer writer = IOHelper.newWriter(Paths.get(args[0]))) { Launcher.gsonManager.configGson.toJson(clientSet, writer); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java index 66da470c..8e25b32f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java @@ -1,7 +1,11 @@ package pro.gravit.launchserver.manangers; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; import pro.gravit.launcher.NeedGarbageCollection; import pro.gravit.launchserver.socket.Client; @@ -10,53 +14,50 @@ public class SessionManager implements NeedGarbageCollection { public static final long SESSION_TIMEOUT = 3 * 60 * 60 * 1000; // 3 часа public static final boolean GARBAGE_SERVER = Boolean.parseBoolean(System.getProperty("launcher.garbageSessionsServer", "false")); - private HashSet clientSet = new HashSet<>(128); + private Map clientSet = new HashMap<>(128); public boolean addClient(Client client) { - clientSet.add(client); + clientSet.put(client.session, client); return true; } @Override public void garbageCollection() { long time = System.currentTimeMillis(); - clientSet.removeIf(c -> (c.timestamp + SESSION_TIMEOUT < time) && ((c.type == Client.Type.USER) || ((c.type == Client.Type.SERVER) && GARBAGE_SERVER))); + clientSet.entrySet().removeIf(entry -> { + Client c = entry.getValue(); + return (c.timestamp + SESSION_TIMEOUT < time) && ((c.type == Client.Type.USER) || ((c.type == Client.Type.SERVER) && GARBAGE_SERVER)); + }); } public Client getClient(long session) { - for (Client c : clientSet) - if (c.session == session) return c; - return null; + return clientSet.get(session); } public Client getOrNewClient(long session) { - for (Client c : clientSet) - if (c.session == session) return c; - Client newClient = new Client(session); - clientSet.add(newClient); - return newClient; + return clientSet.computeIfAbsent(session, Client::new); } public void updateClient(long session) { - for (Client c : clientSet) { - if (c.session == session) { - c.up(); - return; - } + Client c = clientSet.get(session); + if (c != null) { + c.up(); + return; } Client newClient = new Client(session); - clientSet.add(newClient); + clientSet.put(session, newClient); } public Set getSessions() { - return clientSet; + // TODO: removeme + return new HashSet<>(clientSet.values()); } public void loadSessions(Set set) { - clientSet.addAll(set); + clientSet.putAll(set.stream().collect(Collectors.toMap(c -> c.session, Function.identity()))); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java index b0315870..f46cae9b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java @@ -7,6 +7,7 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; +import io.netty.channel.epoll.Epoll; import io.netty.channel.group.DefaultChannelGroup; import io.netty.channel.socket.SocketChannel; import io.netty.handler.codec.http.HttpObjectAggregator; @@ -20,7 +21,6 @@ import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler; import pro.gravit.launchserver.socket.handlers.fileserver.FileServerHandler; import pro.gravit.utils.BiHookSet; -import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; public class LauncherNettyServer implements AutoCloseable { @@ -38,16 +38,16 @@ public LauncherNettyServer(LaunchServer server) { { LogHelper.debug("Netty: Epoll enabled"); } - if(config.performance.usingEpoll && JVMHelper.OS_TYPE != JVMHelper.OS.LINUX) + if(config.performance.usingEpoll && !Epoll.isAvailable()) { - LogHelper.error("netty,perfomance.usingEpoll work only Linux systems"); + LogHelper.error("netty,perfomance.usingEpoll is not available: ", Epoll.unavailabilityCause()); } bossGroup = NettyObjectFactory.newEventLoopGroup(config.performance.bossThread); workerGroup = NettyObjectFactory.newEventLoopGroup(config.performance.workerThread); serverBootstrap = new ServerBootstrap(); service = new WebSocketService(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE), server); serverBootstrap.group(bossGroup, workerGroup) - .channel(NettyObjectFactory.getServerSocketChannelClass()) + .channelFactory(NettyObjectFactory.getServerSocketChannelFactory()) .handler(new LoggingHandler(config.logLevel)) .childHandler(new ChannelInitializer() { @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/NettyObjectFactory.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/NettyObjectFactory.java index 2157e95c..119b72c5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/NettyObjectFactory.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/NettyObjectFactory.java @@ -1,5 +1,6 @@ package pro.gravit.launchserver.socket; +import io.netty.channel.ChannelFactory; import io.netty.channel.EventLoopGroup; import io.netty.channel.ServerChannel; import io.netty.channel.epoll.EpollEventLoopGroup; @@ -20,12 +21,12 @@ public static EventLoopGroup newEventLoopGroup(int threads) else return new NioEventLoopGroup(threads); } - public static Class getServerSocketChannelClass() + public static ChannelFactory getServerSocketChannelFactory() { if(epoll) - return EpollServerSocketChannel.class; + return EpollServerSocketChannel::new; else - return NioServerSocketChannel.class; + return NioServerSocketChannel::new; } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java index 1f9ec67a..56701166 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -9,6 +9,7 @@ import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.group.ChannelGroup; +import io.netty.channel.group.ChannelMatchers; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.events.ExceptionEvent; @@ -120,22 +121,22 @@ public static void registerResponses() { } public void sendObject(ChannelHandlerContext ctx, Object obj) { - ctx.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, WebSocketEvent.class))); + ctx.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, WebSocketEvent.class)), ctx.voidPromise()); } public void sendObject(ChannelHandlerContext ctx, Object obj, Type type) { - ctx.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, type))); + ctx.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, type)), ctx.voidPromise()); } public void sendObjectAll(Object obj) { for (Channel ch : channels) { - ch.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, WebSocketEvent.class))); + ch.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, WebSocketEvent.class)), ch.voidPromise()); } } public void sendObjectAll(Object obj, Type type) { for (Channel ch : channels) { - ch.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, type))); + ch.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, type)), ch.voidPromise()); } } @@ -148,7 +149,7 @@ public void sendObjectAndClose(ChannelHandlerContext ctx, Object obj, Type type) } public void sendEvent(EventResult obj) { - channels.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj))); + channels.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj)), ChannelMatchers.all(), true); } public static class EventResult implements WebSocketEvent { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyIpForwardHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyIpForwardHandler.java index 4908b4e4..ec74df6b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyIpForwardHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyIpForwardHandler.java @@ -36,7 +36,9 @@ protected void decode(ChannelHandlerContext ctx, HttpRequest msg, List o realIP = headers.get("X-Real-IP"); } if (realIP != null) { - LogHelper.dev("Real IP address %s", realIP); + if (LogHelper.isDevEnabled()) { + LogHelper.dev("Real IP address %s", realIP); + } context.ip = realIP; } else LogHelper.error("IpForwarding error. Headers not found"); out.add(msg); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java index 05f66935..071c0fb8 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java @@ -2,6 +2,7 @@ import java.util.concurrent.TimeUnit; +import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; @@ -40,11 +41,14 @@ public void setClient(Client client) { @Override public void channelActive(ChannelHandlerContext ctx) { - LogHelper.dev("New client %s", IOHelper.getIP(ctx.channel().remoteAddress())); + if (LogHelper.isDevEnabled()) { + LogHelper.dev("New client %s", IOHelper.getIP(ctx.channel().remoteAddress())); + } client = new Client(0); - service.registerClient(ctx.channel()); + Channel ch = ctx.channel(); + service.registerClient(ch); ctx.executor().schedule(() -> { - ctx.channel().writeAndFlush(new PingWebSocketFrame()); + ch.writeAndFlush(new PingWebSocketFrame(), ch.voidPromise()); }, 30L, TimeUnit.SECONDS); } @@ -58,7 +62,9 @@ protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) { ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content())); //return; } else if ((frame instanceof PongWebSocketFrame)) { - LogHelper.dev("WebSocket Client received pong"); + if (LogHelper.isDevEnabled()) { + LogHelper.dev("WebSocket Client received pong"); + } } else if ((frame instanceof CloseWebSocketFrame)) { ctx.channel().close(); } else { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java index 32f07b0b..84cc20be 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java @@ -112,6 +112,7 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti result.permissions = clientData.permissions; if (authType == ConnectTypes.SERVER && !clientData.permissions.canServer) { AuthProvider.authError("authType: SERVER not allowed for this account"); + return; } if (getSession) { if (clientData.session == 0) { @@ -123,7 +124,9 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti if (authType != ConnectTypes.API && server.config.protectHandler.allowGetAccessToken(context)) { UUID uuid = pair.handler.auth(aresult); result.playerProfile = ProfileByUUIDResponse.getProfile(uuid, aresult.username, client, clientData.auth.textureProvider); - LogHelper.debug("Auth: %s accessToken %s uuid: %s", login, result.accessToken, uuid.toString()); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Auth: %s accessToken %s uuid: %s", login, result.accessToken, uuid.toString()); + } } sendResult(result); } catch (AuthException | HWIDException | HookException e) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java index 3068eb08..bd49d359 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java @@ -27,7 +27,9 @@ public void execute(ChannelHandlerContext ctx, Client pClient) { result.uuid = pClient.auth.handler.checkServer(username, serverID); if (result.uuid != null) result.playerProfile = ProfileByUUIDResponse.getProfile(result.uuid, username, client, pClient.auth.textureProvider); - LogHelper.debug("checkServer: %s uuid: %s serverID: %s", result.playerProfile.username, result.uuid.toString(), serverID); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("checkServer: %s uuid: %s serverID: %s", result.playerProfile.username, result.uuid.toString(), serverID); + } } catch (AuthException | HookException e) { sendError(e.getMessage()); return; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java index c1a66a7f..685e3c66 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java @@ -27,7 +27,9 @@ public void execute(ChannelHandlerContext ctx, Client client) { LogHelper.warning("Client auth is null. Using default."); success = server.config.getAuthProviderPair().handler.joinServer(username, accessToken, serverID); } else success = client.auth.handler.joinServer(username, accessToken, serverID); - LogHelper.debug("joinServer: %s accessToken: %s serverID: %s", username, accessToken, serverID); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("joinServer: %s accessToken: %s serverID: %s", username, accessToken, serverID); + } } catch (AuthException | HookException e) { sendError(e.getMessage()); return; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index a4fe3cd0..c22033e7 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -540,7 +540,7 @@ private static LinkedList resolveClassPathList(Path clientDir, String... c return result; } - public static void initGson() { + private static void initGson() { Launcher.gsonManager = new ClientGsonManager(); Launcher.gsonManager.initGson(); } @@ -552,8 +552,8 @@ public static void setProfile(ClientProfile profile) { } public static void verifyHDir(Path dir, HashedDir hdir, FileNameMatcher matcher, boolean digest) throws IOException { - if (matcher != null) - matcher = matcher.verifyOnly(); + //if (matcher != null) + // matcher = matcher.verifyOnly(); // Hash directory and compare (ignore update-only matcher entries, it will break offline-mode) HashedDir currentHDir = new HashedDir(dir, matcher, true, digest); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java index 3e5333a4..7918a20a 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java @@ -72,7 +72,9 @@ public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff //if(file.isSame(ret, true)) { Path source = request.getDir().resolve(path); - LogHelper.debug("Copy file %s to %s", ret.toAbsolutePath().toString(), source.toAbsolutePath().toString()); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Copy file %s to %s", ret.toAbsolutePath().toString(), source.toAbsolutePath().toString()); + } //Let's go! Files.copy(ret, source); try (InputStream input = IOHelper.newInput(ret)) { @@ -93,11 +95,15 @@ public Path tryFind(NewLauncherSettings.HashedStoreEntry en, HashedFile file) th if (entry.getType() == HashedEntry.Type.DIR) return HashedDir.WalkAction.CONTINUE; HashedFile tfile = (HashedFile) entry; if (tfile.isSame(file)) { - LogHelper.dev("[DIR:%s] Found file %s in %s", en.name, name, path); + if (LogHelper.isDevEnabled()) { + LogHelper.dev("[DIR:%s] Found file %s in %s", en.name, name, path); + } Path tdir = Paths.get(en.fullPath).resolve(path); try { if (tfile.isSame(tdir, true)) { - LogHelper.dev("[DIR:%s] Confirmed file %s in %s", en.name, name, path); + if (LogHelper.isDevEnabled()) { + LogHelper.dev("[DIR:%s] Confirmed file %s in %s", en.name, name, path); + } ret.set(tdir); return HashedDir.WalkAction.STOP; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java index 991cf546..4633e6f4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java @@ -168,7 +168,9 @@ public Path handleResponse(HttpResponse response) throws IOException { if (callback != null) { callback.stateChanged(entry.getName(), 0, entry.getSize()); } - LogHelper.dev("Resolved filename %s to %s", filename, target.toAbsolutePath().toString()); + if (LogHelper.isDevEnabled()) { + LogHelper.dev("Resolved filename %s to %s", filename, target.toAbsolutePath().toString()); + } transfer(source, target, filename, size, callback, totalCallback); entry = input.getNextEntry(); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModuleManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModuleManager.java index f6ecda38..70673128 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModuleManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModuleManager.java @@ -50,7 +50,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO public void autoload(Path dir) throws IOException { LogHelper.info("Load modules"); if (Files.notExists(dir)) Files.createDirectory(dir); - IOHelper.walk(dir, new ModulesVisitor(), true); + else { + IOHelper.walk(dir, new ModulesVisitor(), true); + } sort(); LogHelper.info("Loaded %d modules", modules.size()); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java index 7451afa8..f45619d5 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java @@ -85,7 +85,7 @@ public void open() throws Exception { public ChannelFuture send(String text) { LogHelper.dev("Send: %s", text); - return ch.writeAndFlush(new TextWebSocketFrame(text)); + return ch.writeAndFlush(new TextWebSocketFrame(text), ch.voidPromise()); } abstract void onMessage(String message) throws Exception; @@ -98,7 +98,7 @@ public void close() throws InterruptedException { //System.out.println("WebSocket Client sending close"); isClosed = true; if (ch != null && ch.isActive()) { - ch.writeAndFlush(new CloseWebSocketFrame()); + ch.writeAndFlush(new CloseWebSocketFrame(), ch.voidPromise()); ch.closeFuture().sync(); } @@ -106,7 +106,7 @@ public void close() throws InterruptedException { } public void eval(final String text) throws IOException { - ch.writeAndFlush(new TextWebSocketFrame(text)); + ch.writeAndFlush(new TextWebSocketFrame(text), ch.voidPromise()); } } \ No newline at end of file diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java index d7123b27..0b9da5ab 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java @@ -56,8 +56,8 @@ public boolean isDone() { @Override public WebSocketEvent get() throws InterruptedException, ExecutionException { if (isCanceled) return null; - while (!event.ready) { - synchronized (event) { + synchronized (event) { + while (!event.ready) { event.wait(); } } @@ -73,8 +73,8 @@ public WebSocketEvent get() throws InterruptedException, ExecutionException { @Override public WebSocketEvent get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException { if (isCanceled) return null; - while (!event.ready) { - synchronized (event) { + synchronized (event) { + while (!event.ready) { event.wait(timeout); } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java index 6d0c41c3..61a58a3c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java @@ -73,12 +73,14 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except if (frame instanceof TextWebSocketFrame) { final TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; clientJSONPoint.onMessage(textFrame.text()); - LogHelper.dev("Message: %s", textFrame.text()); + if (LogHelper.isDevEnabled()) { + LogHelper.dev("Message: %s", textFrame.text()); + } // uncomment to print request // logger.info(textFrame.text()); } else if ((frame instanceof PingWebSocketFrame)) { frame.content().retain(); - ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content())); + ch.writeAndFlush(new PongWebSocketFrame(frame.content()), ch.voidPromise()); //return; } else if (frame instanceof PongWebSocketFrame) { } else if (frame instanceof CloseWebSocketFrame) diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java index 242717d7..3a73db11 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java @@ -47,7 +47,9 @@ public void findProfilesByNames(String[] usernames, Agent agent, ProfileLookupCa sliceProfiles = new BatchProfileByUsernameRequest(sliceUsernames).request().playerProfiles; } catch (Exception e) { for (String username : sliceUsernames) { - LogHelper.debug("Couldn't find profile '%s': %s", username, e); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Couldn't find profile '%s': %s", username, e); + } callback.onProfileLookupFailed(new GameProfile((UUID) null, username), e); } @@ -61,13 +63,17 @@ public void findProfilesByNames(String[] usernames, Agent agent, ProfileLookupCa PlayerProfile pp = sliceProfiles[i]; if (pp == null) { String username = sliceUsernames[i]; - LogHelper.debug("Couldn't find profile '%s'", username); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Couldn't find profile '%s'", username); + } callback.onProfileLookupFailed(new GameProfile((UUID) null, username), new ProfileNotFoundException("Server did not find the requested profile")); continue; } // Report as looked up - LogHelper.debug("Successfully looked up profile '%s'", pp.username); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Successfully looked up profile '%s'", pp.username); + } callback.onProfileLookupSucceeded(YggdrasilMinecraftSessionService.toGameProfile(pp)); } diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java index 12d46688..783ac600 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java @@ -33,7 +33,9 @@ public final class YggdrasilMinecraftSessionService extends BaseMinecraftSession public static final boolean NO_TEXTURES = Boolean.parseBoolean("launcher.com.mojang.authlib.noTextures"); public static void fillTextureProperties(GameProfile profile, PlayerProfile pp) { - LogHelper.debug("fillTextureProperties, Username: '%s'", profile.getName()); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("fillTextureProperties, Username: '%s'", profile.getName()); + } if (NO_TEXTURES) return; @@ -42,12 +44,16 @@ public static void fillTextureProperties(GameProfile profile, PlayerProfile pp) if (pp.skin != null) { properties.put(Launcher.SKIN_URL_PROPERTY, new Property(Launcher.SKIN_URL_PROPERTY, pp.skin.url, "")); properties.put(Launcher.SKIN_DIGEST_PROPERTY, new Property(Launcher.SKIN_DIGEST_PROPERTY, SecurityHelper.toHex(pp.skin.digest), "")); - LogHelper.debug("fillTextureProperties, Has skin texture for username '%s'", profile.getName()); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("fillTextureProperties, Has skin texture for username '%s'", profile.getName()); + } } if (pp.cloak != null) { properties.put(Launcher.CLOAK_URL_PROPERTY, new Property(Launcher.CLOAK_URL_PROPERTY, pp.cloak.url, "")); properties.put(Launcher.CLOAK_DIGEST_PROPERTY, new Property(Launcher.CLOAK_DIGEST_PROPERTY, SecurityHelper.toHex(pp.cloak.digest), "")); - LogHelper.debug("fillTextureProperties, Has cloak texture for username '%s'", profile.getName()); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("fillTextureProperties, Has cloak texture for username '%s'", profile.getName()); + } } } @@ -92,7 +98,9 @@ public YggdrasilMinecraftSessionService(AuthenticationService service) { public GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) { // Verify has UUID UUID uuid = profile.getUUID(); - LogHelper.debug("fillProfileProperties, UUID: %s", uuid); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("fillProfileProperties, UUID: %s", uuid); + } if (uuid == null) return profile; @@ -101,7 +109,9 @@ public GameProfile fillProfileProperties(GameProfile profile, boolean requireSec try { pp = new ProfileByUUIDRequest(uuid).request().playerProfile; } catch (Exception e) { - LogHelper.debug("Couldn't fetch profile properties for '%s': %s", profile, e); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Couldn't fetch profile properties for '%s': %s", profile, e); + } return profile; } @@ -112,14 +122,18 @@ public GameProfile fillProfileProperties(GameProfile profile, boolean requireSec } // Create new game profile from player profile - LogHelper.debug("Successfully fetched profile properties for '%s'", profile); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Successfully fetched profile properties for '%s'", profile); + } fillTextureProperties(profile, pp); return toGameProfile(pp); } @Override public Map getTextures(GameProfile profile, boolean requireSecure) { - LogHelper.debug("getTextures, Username: '%s', UUID: '%s'", profile.getName(), profile.getUUID()); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("getTextures, Username: '%s', UUID: '%s'", profile.getName(), profile.getUUID()); + } Map textures = new EnumMap<>(MinecraftProfileTexture.Type.class); // Add textures @@ -151,7 +165,9 @@ public Map getTextures(Ga @Override public GameProfile hasJoinedServer(GameProfile profile, String serverID) throws AuthenticationUnavailableException { String username = profile.getName(); - LogHelper.debug("checkServer, Username: '%s', Server ID: %s", username, serverID); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("checkServer, Username: '%s', Server ID: %s", username, serverID); + } // Make checkServer request PlayerProfile pp; @@ -180,7 +196,9 @@ public void joinServer(GameProfile profile, String accessToken, String serverID) // Join server String username = profile.getName(); - LogHelper.debug("joinServer, Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("joinServer, Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID); + } // Make joinServer request boolean success; diff --git a/LauncherAuthlib/src/main/java/cpw/mods/fml/SafeExitJVMLegacy.java b/LauncherAuthlib/src/main/java/cpw/mods/fml/SafeExitJVMLegacy.java index 16372cfc..d80d9c5c 100644 --- a/LauncherAuthlib/src/main/java/cpw/mods/fml/SafeExitJVMLegacy.java +++ b/LauncherAuthlib/src/main/java/cpw/mods/fml/SafeExitJVMLegacy.java @@ -6,10 +6,6 @@ // Не входящих в пакеты самого Forge public class SafeExitJVMLegacy { public static void exit(int code) { - try { - JVMHelper.RUNTIME.halt(code); - } catch (Throwable e) { - System.exit(code); - } + JVMHelper.RUNTIME.halt(code); } } diff --git a/LauncherAuthlib/src/main/java/net/minecraftforge/fml/SafeExitJVM.java b/LauncherAuthlib/src/main/java/net/minecraftforge/fml/SafeExitJVM.java index ba36a8a5..448ff164 100644 --- a/LauncherAuthlib/src/main/java/net/minecraftforge/fml/SafeExitJVM.java +++ b/LauncherAuthlib/src/main/java/net/minecraftforge/fml/SafeExitJVM.java @@ -6,10 +6,6 @@ // Не входящих в пакеты самого Forge public class SafeExitJVM { public static void exit(int code) { - try { - JVMHelper.RUNTIME.halt(code); - } catch (Throwable e) { - System.exit(code); - } + JVMHelper.RUNTIME.halt(code); } } diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java index 3bacee9d..9e6a5309 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java @@ -173,16 +173,24 @@ public void removeR(String name) { for (String s : dirs) { HashedEntry e = current.get(s); if (e == null) { - LogHelper.debug("Null %s", s); - for (String x : current.keySet()) LogHelper.debug("Contains %s", x); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Null %s", s); + } + if (LogHelper.isDebugEnabled()) { + for (String x : current.keySet()) LogHelper.debug("Contains %s", x); + } break; } if (e.getType() == Type.DIR) { current = ((HashedDir) e).map; - LogHelper.debug("Found dir %s", s); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Found dir %s", s); + } } else { current.remove(s); - LogHelper.debug("Found filename %s", s); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Found filename %s", s); + } break; } } diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntryAdapter.java b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntryAdapter.java index d1f0a38a..625d24fe 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntryAdapter.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntryAdapter.java @@ -26,7 +26,6 @@ public HashedEntry deserialize(JsonElement json, Type typeOfT, JsonDeserializati if (typename.equals("dir")) cls = HashedDir.class; if (typename.equals("file")) cls = HashedFile.class; - return (HashedEntry) context.deserialize(json, cls); } diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/managers/GarbageManager.java b/LauncherCore/src/main/java/pro/gravit/launcher/managers/GarbageManager.java index 00f822d7..7810f5e4 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/managers/GarbageManager.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/managers/GarbageManager.java @@ -1,6 +1,7 @@ package pro.gravit.launcher.managers; -import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; import java.util.Timer; import java.util.TimerTask; @@ -19,7 +20,7 @@ public Entry(NeedGarbageCollection invoke, long timer) { private static final Timer timer = new Timer("GarbageTimer"); - private static final ArrayList NEED_GARBARE_COLLECTION = new ArrayList<>(); + private static final Set NEED_GARBARE_COLLECTION = new HashSet<>(); public static void gc() { for (Entry gc : NEED_GARBARE_COLLECTION) From 0524e77e3ebd8c87e2777396e09f6d239f7b4065 Mon Sep 17 00:00:00 2001 From: xDark Date: Tue, 13 Aug 2019 22:11:51 +0300 Subject: [PATCH 2/3] =?UTF-8?q?[ANY]=20=D0=A7=D0=B8=D1=81=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=BE=D0=B4=D0=B0=20x2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/LauncherAgent.java | 24 +++++----- .../launcher/client/ClientLauncher.java | 46 +++++++++++-------- .../launcher/hwid/OshiHWIDProvider.java | 1 + .../pro/gravit/launcher/utils/DirWatcher.java | 10 ---- .../launcher/downloader/ListDownloader.java | 8 +++- .../YggdrasilGameProfileRepository.java | 11 +++-- .../YggdrasilMinecraftSessionService.java | 18 +++++--- .../pro/gravit/utils/helper/IOHelper.java | 6 ++- .../pro/gravit/utils/helper/LogHelper.java | 11 ++--- .../gravit/launcher/server/ServerWrapper.java | 2 +- 10 files changed, 73 insertions(+), 64 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java index 4a4329a1..c0f855bf 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java @@ -22,6 +22,7 @@ import cpw.mods.fml.SafeExitJVMLegacy; import net.minecraftforge.fml.SafeExitJVM; import pro.gravit.launcher.utils.NativeJVMHalt; +import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; @LauncherAPI @@ -46,19 +47,20 @@ public static void premain(String agentArgument, Instrumentation instrumentation NativeJVMHalt.class.getName(); NativeJVMHalt.initFunc(); isAgentStarted = true; - boolean pb = true; - boolean rt = true; - if (agentArgument != null) { - String trimmedArg = agentArgument.trim(); - if (!trimmedArg.isEmpty()) { - if (trimmedArg.contains("p")) pb = false; - if (trimmedArg.contains("r")) rt = false; - } - } if (System.getProperty("java.vm.name").toUpperCase(Locale.US).contains("HOTSPOT")) try { - if (ManagementFactory.getOperatingSystemMXBean().getName().startsWith("Windows")) replaceClasses(pb, rt); - else replaceClasses(false, false); + if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { + boolean pb = true; + boolean rt = true; + if (agentArgument != null) { + String trimmedArg = agentArgument.trim(); + if (!trimmedArg.isEmpty()) { + if (trimmedArg.contains("p")) pb = false; + if (trimmedArg.contains("r")) rt = false; + } + } + replaceClasses(pb, rt); + } else replaceClasses(false, false); } catch (Error e) { NativeJVMHalt.haltA(294); throw e; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index c22033e7..9d066ce3 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -14,11 +14,15 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.PosixFilePermission; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.EnumSet; import java.util.LinkedList; +import java.util.List; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.swing.JOptionPane; @@ -55,16 +59,16 @@ public final class ClientLauncher { private static final class ClassPathFileVisitor extends SimpleFileVisitor { - private final Collection result; + private final Stream.Builder result; - private ClassPathFileVisitor(Collection result) { + private ClassPathFileVisitor(Stream.Builder result) { this.result = result; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (IOHelper.hasExtension(file, "jar") || IOHelper.hasExtension(file, "zip")) - result.add(file); + result.accept(file); return super.visitFile(file, attrs); } } @@ -282,10 +286,17 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl System.setProperty("minecraft.applet.TargetDirectory", params.clientDir.toString()); } Collections.addAll(args, profile.getClientArgs()); - LogHelper.debug("Args: " + args); + List copy = new ArrayList<>(args); + for (int i = 0, l = copy.size(); i < l; i++) { + String s = copy.get(i); + if ( i + 1 < l && ("--accessToken".equals(s) || "--session".equals(s))) { + copy.set(i + 1, "censored"); + } + } + LogHelper.debug("Args: " + copy); // Resolve main class and method Class mainClass = classLoader.loadClass(profile.getMainClass()); - MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)).asFixedArity(); + MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)); Launcher.LAUNCHED.set(true); JVMHelper.fullGC(); // Invoke main method @@ -407,7 +418,7 @@ public static Process launch( Thread.sleep(200); } if (!clientStarted) { - LogHelper.error("Write Client Params not successful. Using debug mode for more information"); + LogHelper.error("Client did not start properly. Enable debug mode for more information"); } } clientStarted = false; @@ -515,29 +526,24 @@ public static void main(String... args) throws Throwable { } private static URL[] resolveClassPath(Path clientDir, String... classPath) throws IOException { - Collection result = new LinkedList<>(); - for (String classPathEntry : classPath) { - Path path = clientDir.resolve(IOHelper.toPath(classPathEntry)); - if (IOHelper.isDir(path)) { // Recursive walking and adding - IOHelper.walk(path, new ClassPathFileVisitor(result), false); - continue; - } - result.add(path); - } - return result.stream().map(IOHelper::toURL).toArray(URL[]::new); + return resolveClassPathStream(clientDir, classPath).map(IOHelper::toURL).toArray(URL[]::new); } private static LinkedList resolveClassPathList(Path clientDir, String... classPath) throws IOException { - LinkedList result = new LinkedList<>(); + return resolveClassPathStream(clientDir, classPath).collect(Collectors.toCollection(LinkedList::new)); + } + + private static Stream resolveClassPathStream(Path clientDir, String... classPath) throws IOException { + Stream.Builder builder = Stream.builder(); for (String classPathEntry : classPath) { Path path = clientDir.resolve(IOHelper.toPath(classPathEntry)); if (IOHelper.isDir(path)) { // Recursive walking and adding - IOHelper.walk(path, new ClassPathFileVisitor(result), false); + IOHelper.walk(path, new ClassPathFileVisitor(builder), false); continue; } - result.add(path); + builder.accept(path); } - return result; + return builder.build(); } private static void initGson() { diff --git a/Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java b/Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java index 2f14a995..e977bf9b 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java +++ b/Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java @@ -68,6 +68,7 @@ public String getHWDisk() { public String getMacAddr() { for (NetworkIF networkIF : hardware.getNetworkIFs()) { + if (networkIF.getNetworkInterface().isVirtual()) continue; for (String ipv4 : networkIF.getIPv4addr()) { if (ipv4.startsWith("127.")) continue; if (ipv4.startsWith("10.")) continue; diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java b/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java index 6c3b5146..213b073f 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java @@ -27,15 +27,6 @@ public final class DirWatcher implements Runnable, AutoCloseable { private final class RegisterFileVisitor extends SimpleFileVisitor { - private final Deque path = new LinkedList<>(); - - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { - FileVisitResult result = super.postVisitDirectory(dir, exc); - if (!DirWatcher.this.dir.equals(dir)) - path.removeLast(); - return result; - } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { @@ -46,7 +37,6 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th } // Maybe it's unnecessary to go deeper - path.add(IOHelper.getFileName(dir)); //if (matcher != null && !matcher.shouldVerify(path)) { // return FileVisitResult.SKIP_SUBTREE; //} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java index 4633e6f4..1145a507 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java @@ -60,7 +60,9 @@ public void download(String base, List applies, Path dstDirFile, D URI u = new URI(scheme, host, path + apply.apply, "", ""); callback.stateChanged(apply.apply, 0L, apply.size); Path targetPath = dstDirFile.resolve(apply.apply); - LogHelper.debug("Download URL: %s to file %s dir: %s", u.toString(), targetPath.toAbsolutePath().toString(), dstDirFile.toAbsolutePath().toString()); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Download URL: %s to file %s dir: %s", u.toString(), targetPath.toAbsolutePath().toString(), dstDirFile.toAbsolutePath().toString()); + } if (get == null) get = new HttpGet(u); else { get.reset(); @@ -104,7 +106,9 @@ public void downloadOne(String url, Path target) throws IOException, URISyntaxEx HttpGet get; URI u = new URL(url).toURI(); - LogHelper.debug("Download URL: %s", u.toString()); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Download URL: %s", u.toString()); + } get = new HttpGet(u); httpclient.execute(get, new FileDownloadResponseHandler(target.toAbsolutePath())); } diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java index 3a73db11..0d54ba97 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java @@ -46,8 +46,9 @@ public void findProfilesByNames(String[] usernames, Agent agent, ProfileLookupCa try { sliceProfiles = new BatchProfileByUsernameRequest(sliceUsernames).request().playerProfiles; } catch (Exception e) { + boolean debug = LogHelper.isDebugEnabled(); for (String username : sliceUsernames) { - if (LogHelper.isDebugEnabled()) { + if (debug) { LogHelper.debug("Couldn't find profile '%s': %s", username, e); } callback.onProfileLookupFailed(new GameProfile((UUID) null, username), e); @@ -59,11 +60,13 @@ public void findProfilesByNames(String[] usernames, Agent agent, ProfileLookupCa } // Request succeeded! - for (int i = 0; i < sliceProfiles.length; i++) { + int len = sliceProfiles.length; + boolean debug = len > 0 && LogHelper.isDebugEnabled(); + for (int i = 0; i < len; i++) { PlayerProfile pp = sliceProfiles[i]; if (pp == null) { String username = sliceUsernames[i]; - if (LogHelper.isDebugEnabled()) { + if (debug) { LogHelper.debug("Couldn't find profile '%s'", username); } callback.onProfileLookupFailed(new GameProfile((UUID) null, username), new ProfileNotFoundException("Server did not find the requested profile")); @@ -71,7 +74,7 @@ public void findProfilesByNames(String[] usernames, Agent agent, ProfileLookupCa } // Report as looked up - if (LogHelper.isDebugEnabled()) { + if (debug) { LogHelper.debug("Successfully looked up profile '%s'", pp.username); } callback.onProfileLookupSucceeded(YggdrasilMinecraftSessionService.toGameProfile(pp)); diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java index 783ac600..d7afaede 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java @@ -33,7 +33,8 @@ public final class YggdrasilMinecraftSessionService extends BaseMinecraftSession public static final boolean NO_TEXTURES = Boolean.parseBoolean("launcher.com.mojang.authlib.noTextures"); public static void fillTextureProperties(GameProfile profile, PlayerProfile pp) { - if (LogHelper.isDebugEnabled()) { + boolean debug = LogHelper.isDebugEnabled(); + if (debug) { LogHelper.debug("fillTextureProperties, Username: '%s'", profile.getName()); } if (NO_TEXTURES) @@ -44,14 +45,14 @@ public static void fillTextureProperties(GameProfile profile, PlayerProfile pp) if (pp.skin != null) { properties.put(Launcher.SKIN_URL_PROPERTY, new Property(Launcher.SKIN_URL_PROPERTY, pp.skin.url, "")); properties.put(Launcher.SKIN_DIGEST_PROPERTY, new Property(Launcher.SKIN_DIGEST_PROPERTY, SecurityHelper.toHex(pp.skin.digest), "")); - if (LogHelper.isDebugEnabled()) { + if (debug) { LogHelper.debug("fillTextureProperties, Has skin texture for username '%s'", profile.getName()); } } if (pp.cloak != null) { properties.put(Launcher.CLOAK_URL_PROPERTY, new Property(Launcher.CLOAK_URL_PROPERTY, pp.cloak.url, "")); properties.put(Launcher.CLOAK_DIGEST_PROPERTY, new Property(Launcher.CLOAK_DIGEST_PROPERTY, SecurityHelper.toHex(pp.cloak.digest), "")); - if (LogHelper.isDebugEnabled()) { + if (debug) { LogHelper.debug("fillTextureProperties, Has cloak texture for username '%s'", profile.getName()); } } @@ -98,7 +99,8 @@ public YggdrasilMinecraftSessionService(AuthenticationService service) { public GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) { // Verify has UUID UUID uuid = profile.getUUID(); - if (LogHelper.isDebugEnabled()) { + boolean debug = LogHelper.isDebugEnabled(); + if (debug) { LogHelper.debug("fillProfileProperties, UUID: %s", uuid); } if (uuid == null) @@ -109,7 +111,7 @@ public GameProfile fillProfileProperties(GameProfile profile, boolean requireSec try { pp = new ProfileByUUIDRequest(uuid).request().playerProfile; } catch (Exception e) { - if (LogHelper.isDebugEnabled()) { + if (debug) { LogHelper.debug("Couldn't fetch profile properties for '%s': %s", profile, e); } return profile; @@ -117,12 +119,14 @@ public GameProfile fillProfileProperties(GameProfile profile, boolean requireSec // Verify is found if (pp == null) { - LogHelper.debug("Couldn't fetch profile properties for '%s' as the profile does not exist", profile); + if (debug) { + LogHelper.debug("Couldn't fetch profile properties for '%s' as the profile does not exist", profile); + } return profile; } // Create new game profile from player profile - if (LogHelper.isDebugEnabled()) { + if (debug) { LogHelper.debug("Successfully fetched profile properties for '%s'", profile); } fillTextureProperties(profile, pp); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java index 77b34f1b..1d602582 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java @@ -624,7 +624,11 @@ public static void setSocketFlags(Socket socket) throws SocketException { // Set socket options socket.setSoTimeout(SOCKET_TIMEOUT); - socket.setTrafficClass(0b11100); + try { + socket.setTrafficClass(0b11100); + } catch (SocketException ignored) { + // Windows XP has no support for that + } socket.setPerformancePreferences(1, 0, 2); } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java index 59ed544e..694c56db 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java @@ -345,14 +345,9 @@ public static void subWarning(String format, Object... args) { @LauncherAPI public static String toString(Throwable exc) { - try (StringWriter sw = new StringWriter()) { - try (PrintWriter pw = new PrintWriter(sw)) { - exc.printStackTrace(pw); - } - return sw.toString(); - } catch (IOException e) { - throw new InternalError(e); - } + StringWriter sw = new StringWriter(); + exc.printStackTrace(new PrintWriter(sw)); + return sw.toString(); } @LauncherAPI diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index 8c7bba1c..a0fd85ea 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -105,7 +105,7 @@ public void run(String... args) throws Throwable { loadConfig(); ServerWrapperSetup setup = new ServerWrapperSetup(); setup.run(); - System.exit(0); + System.exit(1); } modulesManager = new ModulesManager(wrapper); modulesManager.autoload(modulesDir); From 2a975d749c581d02fcdf6ce30d00cdef1469bf97 Mon Sep 17 00:00:00 2001 From: xDark Date: Tue, 13 Aug 2019 22:16:57 +0300 Subject: [PATCH 3/3] =?UTF-8?q?[FIX]=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B3=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=B0=D1=82=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/socket/LauncherNettyServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java index f46cae9b..63a1e79e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java @@ -40,7 +40,7 @@ public LauncherNettyServer(LaunchServer server) { } if(config.performance.usingEpoll && !Epoll.isAvailable()) { - LogHelper.error("netty,perfomance.usingEpoll is not available: ", Epoll.unavailabilityCause()); + LogHelper.error("Epoll is not available: (netty,perfomance.usingEpoll configured wrongly)", Epoll.unavailabilityCause()); } bossGroup = NettyObjectFactory.newEventLoopGroup(config.performance.bossThread); workerGroup = NettyObjectFactory.newEventLoopGroup(config.performance.workerThread);