diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index f1552b8d..b16afa2b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -27,6 +27,7 @@ import ru.gravit.launchserver.manangers.hook.BuildHookManager; import ru.gravit.launchserver.manangers.hook.SocketHookManager; import ru.gravit.launchserver.response.Response; +import ru.gravit.launchserver.socket.NettyServerSocketHandler; import ru.gravit.launchserver.socket.ServerSocketHandler; import ru.gravit.launchserver.texture.RequestTextureProvider; import ru.gravit.launchserver.texture.TextureProvider; @@ -86,6 +87,7 @@ public static final class Config { public int threadCoreCount; public ExeConf launch4j; + public NettyConfig netty; public boolean compress; @@ -178,6 +180,11 @@ public static class ExeConf { public String txtFileVersion; public String txtProductVersion; } + public class NettyConfig + { + public String bindAddress; + public int port; + } private final class ProfilesFileVisitor extends SimpleFileVisitor { private final Collection result; @@ -213,7 +220,11 @@ public static void main(String... args) throws Throwable { // Start LaunchServer Instant start = Instant.now(); try { - new LaunchServer(IOHelper.WORKING_DIR, args).run(); + LaunchServer launchserver = new LaunchServer(IOHelper.WORKING_DIR, args); + if(args.length == 0) launchserver.run(); + else { //Обработка команды + launchserver.commandHandler.eval(args,false); + } } catch (Throwable exc) { LogHelper.error(exc); return; @@ -283,13 +294,15 @@ public static void main(String... args) throws Throwable { public final ServerSocketHandler serverSocketHandler; + public final NettyServerSocketHandler nettyServerSocketHandler; + private final AtomicBoolean started = new AtomicBoolean(false); // Updates and profiles private volatile List profilesList; - public volatile Map> updatesDirMap; + public final Timer taskPool; public final Updater updater; public static Gson gson; @@ -297,6 +310,7 @@ public static void main(String... args) throws Throwable { public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecException { this.dir = dir; + taskPool = new Timer("Timered task worker thread", true); launcherLibraries = dir.resolve("launcher-libraries"); if (!Files.isDirectory(launcherLibraries)) { Files.deleteIfExists(launcherLibraries); @@ -444,6 +458,10 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE modulesManager.postInitModules(); // start updater this.updater = new Updater(this); + if(config.netty != null) + nettyServerSocketHandler = new NettyServerSocketHandler(this); + else + nettyServerSocketHandler = null; } public static void initGson() { @@ -581,6 +599,11 @@ public void rebindServerSocket() { CommonHelper.newThread("Server Socket Thread", false, serverSocketHandler).start(); } + public void rebindNettyServerSocket() { + nettyServerSocketHandler.close(); + CommonHelper.newThread("Netty Server Socket Thread", false, nettyServerSocketHandler).start(); + } + @Override public void run() { if (started.getAndSet(true)) @@ -590,6 +613,8 @@ public void run() { JVMHelper.RUNTIME.addShutdownHook(CommonHelper.newThread(null, false, this::close)); CommonHelper.newThread("Command Thread", true, commandHandler).start(); rebindServerSocket(); + if(config.netty != null) + rebindNettyServerSocket(); modulesManager.finishModules(); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/Updater.java b/LaunchServer/src/main/java/ru/gravit/launchserver/Updater.java index 7136de39..a6d57254 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/Updater.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/Updater.java @@ -6,7 +6,6 @@ import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; -import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.atomic.AtomicReference; import java.util.regex.Matcher; @@ -25,12 +24,10 @@ public class Updater extends TimerTask { private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss", Locale.US); private static final long period = 1000*3600; private static final Version VERSION = Launcher.getVersion(); - private final Timer taskPool; private final GHRepository gravitLauncher; private Version parent = VERSION; public Updater(LaunchServer srv) { - this.taskPool = new Timer("Updater thread", true); GHRepository gravitLauncherTmp = null; try { @@ -40,7 +37,7 @@ public Updater(LaunchServer srv) { } this.gravitLauncher = gravitLauncherTmp; run(); - if (srv.config.updatesNotify) taskPool.schedule(this, new Date(System.currentTimeMillis()+period), period); + if (srv.config.updatesNotify) srv.taskPool.schedule(this, new Date(System.currentTimeMillis()+period), period); } @Override @@ -68,8 +65,8 @@ public void run() { LogHelper.error(e); } } - - private static final Pattern startingVerPattern = Pattern.compile("\\d+\\.\\d+\\.\\d+"); + + private static final Pattern startingVerPattern = Pattern.compile("\\d+\\.\\d+\\.\\d+\\.?\\d*"); private static final Pattern pointPatternSpltitter = Pattern.compile("\\."); private static Version parseVer(String relS) { @@ -78,11 +75,11 @@ private static Version parseVer(String relS) { String[] ver = pointPatternSpltitter.split(relS.substring(verMatcher.start(), verMatcher.end())); if (ver.length < 3) return VERSION; return new Version(Integer.parseInt(ver[0]), Integer.parseInt(ver[1]), - Integer.parseInt(ver[2]), ver.length > 3 ? Integer.parseInt(ver[3]) : 0, findRelType(relS.substring(verMatcher.end()+1))); + Integer.parseInt(ver[2]), ver.length > 3 ? Integer.parseInt(ver[3]) : 0, findRelType(relS.substring(verMatcher.end()))); } private static Type findRelType(String substring) { - if (substring.length() < 3 || substring.isEmpty()) return Type.UNKNOWN; + if (substring.isEmpty()) return Type.UNKNOWN; String tS = substring; if (tS.startsWith("-")) tS = tS.substring(1); final String wrk = tS.toLowerCase(Locale.ENGLISH); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java index cf300df7..71673a44 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java @@ -89,6 +89,12 @@ public void setPort(int port) { body.append(";"); } + public void setNettyPort(int port) { + body.append("this.nettyPort = "); + body.append(port); + body.append(";"); + } + public void setEnv(LauncherConfig.LauncherEnvironment env) { int i = 2; switch (env) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AttachJarsTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AttachJarsTask.java index e337495e..1c10ee28 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AttachJarsTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AttachJarsTask.java @@ -21,7 +21,7 @@ public AttachJarsTask(LaunchServer srv) { this.srv = srv; jars = new ArrayList<>(); exclusions = new ArrayList<>(); - exclusions.add("META-INF"); + exclusions.add("META-INF/MANIFEST.MF"); } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java index 5acbad06..aefe45f6 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -130,6 +130,8 @@ public Path process(Path inputJar) throws IOException { server.buildHookManager.hook(context); jaConfigurator.setAddress(server.config.getAddress()); jaConfigurator.setPort(server.config.port); + if(server.config.netty != null) + jaConfigurator.setNettyPort(server.config.netty.port); jaConfigurator.setProjectName(server.config.projectName); jaConfigurator.setSecretKey(SecurityHelper.randomStringAESKey()); jaConfigurator.setClientPort(32148 + SecurityHelper.newRandom().nextInt(512)); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java index 1e610f6a..c3d18b6c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java @@ -8,6 +8,8 @@ import ru.gravit.launchserver.command.dump.DumpEntryCacheCommand; import ru.gravit.launchserver.command.dump.DumpSessionsCommand; import ru.gravit.launchserver.command.hash.*; +import ru.gravit.launchserver.command.install.CheckInstallCommand; +import ru.gravit.launchserver.command.install.MultiCommand; import ru.gravit.launchserver.command.modules.LoadModuleCommand; import ru.gravit.launchserver.command.modules.ModulesCommand; import ru.gravit.launchserver.command.service.*; @@ -120,6 +122,8 @@ protected CommandHandler(LaunchServer server) { registerCommand("configList", new ConfigListCommand(server)); registerCommand("swapAuthProvider", new SwapAuthProviderCommand(server)); registerCommand("serverStatus", new ServerStatusCommand(server)); + registerCommand("checkInstall", new CheckInstallCommand(server)); + registerCommand("multi", new MultiCommand(server)); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/install/CheckInstallCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/install/CheckInstallCommand.java new file mode 100644 index 00000000..0c9c2ae2 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/install/CheckInstallCommand.java @@ -0,0 +1,26 @@ +package ru.gravit.launchserver.command.install; + +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; +import ru.gravit.utils.helper.LogHelper; + +public class CheckInstallCommand extends Command { + public CheckInstallCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return null; + } + + @Override + public String getUsageDescription() { + return null; + } + + @Override + public void invoke(String... args) throws Exception { + LogHelper.info("Check install success"); + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/install/MultiCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/install/MultiCommand.java new file mode 100644 index 00000000..6033e9ae --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/install/MultiCommand.java @@ -0,0 +1,28 @@ +package ru.gravit.launchserver.command.install; + +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; + +public class MultiCommand extends Command { + public MultiCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return null; + } + + @Override + public String getUsageDescription() { + return null; + } + + @Override + public void invoke(String... args) throws Exception { + for(String arg : args) + { + server.commandHandler.eval(arg, false); + } + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java index 9e4542c8..3b243156 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java @@ -148,7 +148,7 @@ public void initChannel(NioSocketChannel ch) { pipeline.addLast(new WebSocketFrameHandler()); } }); - ChannelFuture f = b.bind(new InetSocketAddress(9876)).sync(); //TEST ONLY! + ChannelFuture f = b.bind(new InetSocketAddress(LaunchServer.server.config.netty.port)).sync(); //TEST ONLY! f.channel().closeFuture().sync(); } catch (InterruptedException e) { e.printStackTrace(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java index 31d5a726..42fae12e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java @@ -9,6 +9,8 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import ru.gravit.launcher.hasher.HashedEntry; import ru.gravit.launcher.hasher.HashedEntryAdapter; +import ru.gravit.launcher.request.JsonResultSerializeAdapter; +import ru.gravit.launcher.request.ResultInterface; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.websocket.json.EchoResponse; @@ -17,6 +19,7 @@ import ru.gravit.launchserver.socket.websocket.json.auth.AuthResponse; import ru.gravit.launchserver.socket.websocket.json.auth.CheckServerResponse; import ru.gravit.launchserver.socket.websocket.json.auth.JoinServerResponse; +import ru.gravit.launchserver.socket.websocket.json.auth.ProfilesResponse; import ru.gravit.launchserver.socket.websocket.json.update.LauncherResponse; import ru.gravit.launchserver.socket.websocket.json.update.UpdateListResponse; import ru.gravit.utils.helper.LogHelper; @@ -32,6 +35,7 @@ public WebSocketService(ChannelGroup channels, LaunchServer server, GsonBuilder this.server = server; this.gsonBuiler = gson; this.gsonBuiler.registerTypeAdapter(JsonResponseInterface.class, new JsonResponseAdapter(this)); + this.gsonBuiler.registerTypeAdapter(ResultInterface.class,new JsonResultSerializeAdapter()); this.gsonBuiler.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter()); this.gson = gsonBuiler.create(); } @@ -69,6 +73,7 @@ public void registerResponses() { registerResponse("auth", AuthResponse.class); registerResponse("checkServer", CheckServerResponse.class); registerResponse("joinServer", JoinServerResponse.class); + registerResponse("profiles", ProfilesResponse.class); registerResponse("launcherUpdate", LauncherResponse.class); registerResponse("updateList", UpdateListResponse.class); registerResponse("cmdExec", UpdateListResponse.class); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java index bb6fc899..74368989 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java @@ -1,13 +1,15 @@ package ru.gravit.launchserver.socket.websocket.json.auth; import io.netty.channel.ChannelHandlerContext; -import ru.gravit.launcher.HWID; +import ru.gravit.launcher.OshiHWID; +import ru.gravit.launcher.events.request.AuthRequestEvent; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.hwid.HWIDException; import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.AuthProviderResult; +import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse; import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.websocket.WebSocketService; import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; @@ -15,6 +17,7 @@ import ru.gravit.utils.helper.VerifyHelper; import java.util.Collection; +import java.util.UUID; public class AuthResponse implements JsonResponseInterface { public String login; @@ -22,7 +25,7 @@ public class AuthResponse implements JsonResponseInterface { public String password; - public AuthResponse(String login, String password, int authid, HWID hwid) { + public AuthResponse(String login, String password, int authid, OshiHWID hwid) { this.login = login; this.password = password; this.authid = authid; @@ -30,7 +33,12 @@ public AuthResponse(String login, String password, int authid, HWID hwid) { } public int authid; - public HWID hwid; + public ConnectTypes authType; + public OshiHWID hwid; + public enum ConnectTypes + { + SERVER,CLIENT,BOT + } @Override public String getType() { @@ -40,19 +48,31 @@ public String getType() { @Override public void execute(WebSocketService service, ChannelHandlerContext ctx, Client clientData) throws Exception { try { + AuthRequestEvent result = new AuthRequestEvent(); String ip = IOHelper.getIP(ctx.channel().remoteAddress()); if (LaunchServer.server.limiter.isLimit(ip)) { AuthProvider.authError(LaunchServer.server.config.authRejectString); return; } - if (!clientData.checkSign) { + if (authType != ConnectTypes.CLIENT &&!clientData.checkSign) { AuthProvider.authError("Don't skip Launcher Update"); return; } + clientData.permissions = LaunchServer.server.config.permissionsHandler.getPermissions(login); + if(authType == ConnectTypes.BOT && !clientData.permissions.canBot) + { + AuthProvider.authError("authType: BOT not allowed for this account"); + } + if(authType == ConnectTypes.SERVER && !clientData.permissions.canServer) + { + AuthProvider.authError("authType: SERVER not allowed for this account"); + } + ru.gravit.launchserver.response.auth.AuthResponse.AuthContext context = new ru.gravit.launchserver.response.auth.AuthResponse.AuthContext(0, login, password.length(), client, null, false); AuthProvider provider = LaunchServer.server.config.authProvider[authid]; - AuthProviderResult result = provider.auth(login, password, ip); - if (!VerifyHelper.isValidUsername(result.username)) { - AuthProvider.authError(String.format("Illegal result: '%s'", result.username)); + LaunchServer.server.authHookManager.preHook(context, clientData); + AuthProviderResult aresult = provider.auth(login, password, ip); + if (!VerifyHelper.isValidUsername(aresult.username)) { + AuthProvider.authError(String.format("Illegal result: '%s'", aresult.username)); return; } Collection profiles = LaunchServer.server.getProfiles(); @@ -67,19 +87,19 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client if (clientData.profile == null) { throw new AuthException("You profile not found"); } - LaunchServer.server.config.hwidHandler.check(hwid, result.username); + UUID uuid = LaunchServer.server.config.authHandler.auth(aresult); + if(authType == ConnectTypes.CLIENT) + LaunchServer.server.config.hwidHandler.check(hwid, aresult.username); + LaunchServer.server.authHookManager.postHook(context, clientData); clientData.isAuth = true; - clientData.permissions = result.permissions; - service.sendObject(ctx, new WebSocketService.SuccessResult("auth")); + clientData.permissions = aresult.permissions; + result.accessToken = aresult.accessToken; + result.permissions = clientData.permissions; + result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,uuid,aresult.username,client); + service.sendObject(ctx, result); } catch (AuthException | HWIDException e) { service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage())); } } - public class Result { - public Result() { - } - - public String error; - } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java index db7940ce..c615542d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java @@ -1,8 +1,10 @@ package ru.gravit.launchserver.socket.websocket.json.auth; import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.events.request.CheckServerEvent; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; +import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse; import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.websocket.WebSocketService; import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; @@ -11,6 +13,7 @@ public class CheckServerResponse implements JsonResponseInterface { public String serverID; public String username; + public String client; @Override public String getType() { @@ -18,9 +21,12 @@ public String getType() { } @Override - public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) { + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client pClient) { + CheckServerEvent result = new CheckServerEvent(); try { - LaunchServer.server.config.authHandler.checkServer(username, serverID); + result.uuid = LaunchServer.server.config.authHandler.checkServer(username, serverID); + if(result.uuid != null) + result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,result.uuid,username,client); } catch (AuthException e) { service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage())); return; @@ -29,11 +35,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client service.sendObject(ctx, new WebSocketService.ErrorResult("Internal authHandler error")); return; } - service.sendObject(ctx, new Result()); + service.sendObject(ctx, new CheckServerEvent()); } - public class Result { - public String type = "success"; - public String requesttype = "checkServer"; - } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java index 612c9e4a..56eeb0d2 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver.socket.websocket.json.auth; import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.events.request.JoinServerRequestEvent; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.socket.Client; @@ -31,17 +32,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client service.sendObject(ctx, new WebSocketService.ErrorResult("Internal authHandler error")); return; } - service.sendObject(ctx, new Result(success)); + service.sendObject(ctx, new JoinServerRequestEvent(success)); } - public class Result { - public String type = "success"; - public String requesttype = "checkServer"; - - public Result(boolean allow) { - this.allow = allow; - } - - public boolean allow; - } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java new file mode 100644 index 00000000..778b1caa --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java @@ -0,0 +1,28 @@ +package ru.gravit.launchserver.socket.websocket.json.auth; + +import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.events.request.ProfilesRequestEvent; +import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.socket.Client; +import ru.gravit.launchserver.socket.websocket.WebSocketService; +import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; + +import java.util.List; + +public class ProfilesResponse implements JsonResponseInterface { + @Override + public String getType() { + return "profiles"; + } + + @Override + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + if(!client.isAuth) + { + service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied")); + return; + } + service.sendObject(ctx, new ProfilesRequestEvent((List) LaunchServer.server.getProfiles())); + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java new file mode 100644 index 00000000..a4490683 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java @@ -0,0 +1,40 @@ +package ru.gravit.launchserver.socket.websocket.json.auth; + +import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.socket.Client; +import ru.gravit.launchserver.socket.websocket.WebSocketService; +import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; + +import java.util.Collection; + +public class SetProfileResponse implements JsonResponseInterface { + public String client; + @Override + public String getType() { + return "setProfile"; + } + + @Override + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + if(!client.isAuth) + { + service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied")); + return; + } + Collection profiles = LaunchServer.server.getProfiles(); + for (ClientProfile p : profiles) { + if (p.getTitle().equals(this.client)) { + if (!p.isWhitelistContains(client.username)) { + service.sendObject(ctx, new WebSocketService.ErrorResult(LaunchServer.server.config.whitelistRejectString)); + return; + } + client.profile = p; + service.sendObject(ctx, new WebSocketService.SuccessResult(getType())); + break; + } + } + service.sendObject(ctx, new WebSocketService.ErrorResult("Profile not found")); + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java new file mode 100644 index 00000000..22fade29 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java @@ -0,0 +1,36 @@ +package ru.gravit.launchserver.socket.websocket.json.profile; + +import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent; +import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.socket.Client; +import ru.gravit.launchserver.socket.websocket.WebSocketService; +import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; + +import java.util.UUID; + +public class BatchProfileByUsername implements JsonResponseInterface { + class Entry + { + String username; + String client; + } + Entry[] list; + @Override + public String getType() { + return "batchProfileByUsername"; + } + + @Override + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + BatchProfileByUsernameRequestEvent result = new BatchProfileByUsernameRequestEvent(); + result.playerProfiles = new PlayerProfile[list.length]; + for(int i=0;i> requests; - private HashMap> results; + private HashMap> requests; + private HashMap> results; + private HashSet handlers; - public ClientWebSocketService(GsonBuilder gsonBuilder, ClientJSONPoint point) { + public ClientWebSocketService(GsonBuilder gsonBuilder) { requests = new HashMap<>(); results = new HashMap<>(); + handlers = new HashSet<>(); this.gsonBuilder = gsonBuilder; gsonBuilder.registerTypeAdapter(RequestInterface.class, new JsonRequestAdapter(this)); gsonBuilder.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter()); this.gson = gsonBuilder.create(); - this.point = point; - point.setService(this); } - + @Override public void processMessage(Reader reader) { ResultInterface result = gson.fromJson(reader, ResultInterface.class); - result.process(); + for(EventHandler handler : handlers) + { + handler.process(result); + } } - public Class getRequestClass(String key) { + public Class getRequestClass(String key) { return requests.get(key); } + public Class getResultClass(String key) { + return results.get(key); + } - public void registerRequest(String key, Class clazz) { + public void registerRequest(String key, Class clazz) { requests.put(key, clazz); } @@ -44,7 +51,7 @@ public void registerRequests() { } - public void registerResult(String key, Class clazz) { + public void registerResult(String key, Class clazz) { results.put(key, clazz); } @@ -52,11 +59,21 @@ public void registerResults() { } + public void registerHandler(EventHandler eventHandler) + { + handlers.add(eventHandler); + } + public void sendObjectAsync(Object obj) throws IOException { - point.sendAsync(gson.toJson(obj)); + sendAsync(gson.toJson(obj)); } public void sendObject(Object obj) throws IOException { - point.send(gson.toJson(obj)); + send(gson.toJson(obj)); + } + @FunctionalInterface + public interface EventHandler + { + void process(ResultInterface resultInterface); } } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java index da6d860d..be546079 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java @@ -15,7 +15,7 @@ public JsonRequestAdapter(ClientWebSocketService service) { @Override public RequestInterface deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); - Class cls = service.getRequestClass(typename); + Class cls = service.getRequestClass(typename); return (RequestInterface) context.deserialize(json, cls); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonResultAdapter.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonResultAdapter.java new file mode 100644 index 00000000..1ddd605d --- /dev/null +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonResultAdapter.java @@ -0,0 +1,35 @@ +package ru.gravit.launcher.request.websockets; + +import com.google.gson.*; +import ru.gravit.launcher.request.ResultInterface; + +import java.lang.reflect.Type; + +public class JsonResultAdapter implements JsonSerializer, JsonDeserializer { + private final ClientWebSocketService service; + private static final String PROP_NAME = "type"; + + public JsonResultAdapter(ClientWebSocketService service) { + this.service = service; + } + + @Override + public ResultInterface deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); + Class cls = service.getResultClass(typename); + + + return (ResultInterface) context.deserialize(json, cls); + } + + @Override + public JsonElement serialize(ResultInterface src, Type typeOfSrc, JsonSerializationContext context) { + // note : won't work, you must delegate this + JsonObject jo = context.serialize(src).getAsJsonObject(); + + String classPath = src.getType(); + jo.add(PROP_NAME, new JsonPrimitive(classPath)); + + return jo; + } +} diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java new file mode 100644 index 00000000..760fe522 --- /dev/null +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java @@ -0,0 +1,45 @@ +package ru.gravit.launcher.request.websockets; + +import com.google.gson.GsonBuilder; +import ru.gravit.launcher.Launcher; +import ru.gravit.launcher.request.ResultInterface; + +import javax.websocket.ContainerProvider; +import javax.websocket.WebSocketContainer; +import java.io.IOException; +import java.net.URI; + +public class LegacyRequestBridge { + public static WaitEventHandler waitEventHandler = new WaitEventHandler(); + public static ClientWebSocketService service; + public static ResultInterface sendRequest(RequestInterface request) throws IOException, InterruptedException { + WaitEventHandler.ResultEvent e = new WaitEventHandler.ResultEvent(); + e.type = request.getType(); + waitEventHandler.requests.add(e); + service.sendObject(request); + while(!e.ready) + { + synchronized(e) + { + e.wait(); + } + } + ResultInterface result = e.result; + waitEventHandler.requests.remove(e); + return result; + } + public static void initWebSockets(String address, int port) + { + service = new ClientWebSocketService(new GsonBuilder()); + try { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + container.connectToServer(service, new URI("ws://".concat(address).concat(":".concat(String.valueOf(port)).concat("/api")))); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + static { + if(Launcher.getConfig().nettyPort != 0) + initWebSockets(Launcher.getConfig().address.getHostName(),Launcher.getConfig().nettyPort); + } +} diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ResultInterface.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ResultInterface.java deleted file mode 100644 index bc30c1f0..00000000 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ResultInterface.java +++ /dev/null @@ -1,5 +0,0 @@ -package ru.gravit.launcher.request.websockets; - -public interface ResultInterface { - void process(); -} diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java new file mode 100644 index 00000000..45aa9f78 --- /dev/null +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java @@ -0,0 +1,30 @@ +package ru.gravit.launcher.request.websockets; + +import ru.gravit.launcher.request.ResultInterface; + +import java.util.HashSet; + +public class WaitEventHandler implements ClientWebSocketService.EventHandler { + public HashSet requests; + @Override + public void process(ResultInterface result) { + for(ResultEvent r : requests) + { + if(r.type.equals(result.getType())) + { + synchronized (r) + { + r.result = result; + r.ready = true; + r.notifyAll(); + } + } + } + } + public static class ResultEvent + { + public ResultInterface result; + public String type; + public boolean ready; + } +} diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java index 8ee17b3d..8d8f25e4 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -152,14 +152,22 @@ public static void main(String... args) throws Throwable { if (loader != null) mainClass = Class.forName(classname, true, loader); else mainClass = Class.forName(classname); MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)); - String[] real_args = new String[args.length - 1]; - System.arraycopy(args, 1, real_args, 0, args.length - 1); modulesManager.postInitModules(); LogHelper.info("ServerWrapper: Project %s, LaunchServer address: %s port %d. Title: %s", config.projectname, config.address, config.port, config.title); LogHelper.info("Minecraft Version (for profile): %s", wrapper.profile == null ? "unknown" : wrapper.profile.getVersion().name); LogHelper.info("Start Minecraft Server"); LogHelper.debug("Invoke main method %s", mainClass.getName()); - mainMethod.invoke(real_args); + if(config.args == null) + { + String[] real_args = new String[args.length - 1]; + System.arraycopy(args, 1, real_args, 0, args.length - 1); + mainMethod.invoke(real_args); + } + + else + { + mainMethod.invoke(config.args); + } } private static void generateConfigIfNotExists() throws IOException { @@ -207,6 +215,7 @@ public static final class Config { public String librariesDir; public String mainclass; public String login; + public String[] args; public String password; public LauncherConfig.LauncherEnvironment env; } diff --git a/build.gradle b/build.gradle index d359fea1..feb4e53f 100644 --- a/build.gradle +++ b/build.gradle @@ -28,4 +28,8 @@ } } +wrapper { + distributionType = Wrapper.DistributionType.ALL +} + defaultTasks 'build' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 75b8c7c8..ee671127 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java index aa64bb0b..b1c131fa 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java @@ -4,6 +4,7 @@ public class AutogenConfig { public String projectname; public String address; public int port; + public int nettyPort; public int clientPort; @SuppressWarnings("unused") private boolean isInitModules; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index a01a817c..64ef8488 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -60,7 +60,7 @@ public final class Launcher { private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL); public static final int MAJOR = 4; public static final int MINOR = 3; - public static final int PATCH = 0; + public static final int PATCH = 1; public static final int BUILD = 1; public static final Version.Type RELEASE = Version.Type.STABLE; public static GsonBuilder gsonBuilder; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java index ea50ef9d..15595196 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java @@ -28,6 +28,7 @@ public static AutogenConfig getAutogenConfig() { // Instance @LauncherAPI public InetSocketAddress address; + public int nettyPort; @LauncherAPI public final String projectname; public final int clientPort; @@ -54,6 +55,7 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException isDownloadJava = config.isDownloadJava; isUsingWrapper = config.isUsingWrapper; isWarningMissArchJava = config.isWarningMissArchJava; + nettyPort = config.nettyPort; LauncherEnvironment env; if (config.env == 0) env = LauncherEnvironment.DEV; else if (config.env == 1) env = LauncherEnvironment.DEBUG; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/AuthRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/AuthRequestEvent.java new file mode 100644 index 00000000..c378c916 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/AuthRequestEvent.java @@ -0,0 +1,29 @@ +package ru.gravit.launcher.events.request; + +import ru.gravit.launcher.ClientPermissions; +import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.launcher.request.ResultInterface; +import ru.gravit.utils.event.EventInterface; + +import java.util.UUID; + +public class AuthRequestEvent implements EventInterface, ResultInterface { + private static final UUID uuid = UUID.fromString("77e1bfd7-adf9-4f5d-87d6-a7dd068deb74"); + public AuthRequestEvent() { + } + + public String error; + public ClientPermissions permissions; + public PlayerProfile playerProfile; + public String accessToken; + + @Override + public UUID getUUID() { + return uuid; + } + + @Override + public String getType() { + return "auth"; + } +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/BatchProfileByUsernameRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/BatchProfileByUsernameRequestEvent.java new file mode 100644 index 00000000..18806ac1 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/BatchProfileByUsernameRequestEvent.java @@ -0,0 +1,23 @@ +package ru.gravit.launcher.events.request; + +import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.launcher.request.ResultInterface; +import ru.gravit.utils.event.EventInterface; + +import java.util.UUID; + +public class BatchProfileByUsernameRequestEvent implements EventInterface, ResultInterface +{ + private static final UUID uuid = UUID.fromString("c1d6729e-be2c-48cc-b5ae-af8c012232c3"); + public String error; + public PlayerProfile[] playerProfiles; + @Override + public UUID getUUID() { + return uuid; + } + + @Override + public String getType() { + return "batchProfileByUsername"; + } +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/CheckServerEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/CheckServerEvent.java new file mode 100644 index 00000000..497a9893 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/CheckServerEvent.java @@ -0,0 +1,23 @@ +package ru.gravit.launcher.events.request; + +import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.launcher.request.ResultInterface; +import ru.gravit.utils.event.EventInterface; + +import java.util.UUID; + +public class CheckServerEvent implements EventInterface, ResultInterface { + private static final UUID _uuid = UUID.fromString("8801d07c-51ba-4059-b61d-fe1f1510b28a"); + public String type = "success"; + public UUID uuid; + public PlayerProfile playerProfile; + @Override + public UUID getUUID() { + return _uuid; + } + + @Override + public String getType() { + return "checkServe"; + } +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/JoinServerRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/JoinServerRequestEvent.java new file mode 100644 index 00000000..3a76863c --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/JoinServerRequestEvent.java @@ -0,0 +1,26 @@ +package ru.gravit.launcher.events.request; + +import ru.gravit.launcher.request.ResultInterface; +import ru.gravit.utils.event.EventInterface; + +import java.util.UUID; + +public class JoinServerRequestEvent implements EventInterface, ResultInterface { + private static final UUID uuid = UUID.fromString("2a12e7b5-3f4a-4891-a2f9-ea141c8e1995"); + public String type = "success"; + + public JoinServerRequestEvent(boolean allow) { + this.allow = allow; + } + + public boolean allow; + @Override + public UUID getUUID() { + return uuid; + } + + @Override + public String getType() { + return "joinServer"; + } +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/LauncherRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/LauncherRequestEvent.java new file mode 100644 index 00000000..55f37ed2 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/LauncherRequestEvent.java @@ -0,0 +1,28 @@ +package ru.gravit.launcher.events.request; + +import ru.gravit.launcher.request.ResultInterface; +import ru.gravit.utils.event.EventInterface; + +import java.util.UUID; + +public class LauncherRequestEvent implements EventInterface, ResultInterface { + private static final UUID uuid = UUID.fromString("d54cc12a-4f59-4f23-9b10-f527fdd2e38f"); + public String type = "success"; + public String url; + + public LauncherRequestEvent(boolean needUpdate, String url) { + this.needUpdate = needUpdate; + this.url = url; + } + + public boolean needUpdate; + @Override + public UUID getUUID() { + return uuid; + } + + @Override + public String getType() { + return "launcher"; + } +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java new file mode 100644 index 00000000..27c73810 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java @@ -0,0 +1,27 @@ +package ru.gravit.launcher.events.request; + +import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.launcher.request.ResultInterface; +import ru.gravit.utils.event.EventInterface; + +import java.util.UUID; + +public class ProfileByUUIDRequestEvent implements EventInterface, ResultInterface +{ + private static final UUID uuid = UUID.fromString("b9014cf3-4b95-4d38-8c5f-867f190a18a0"); + String error; + PlayerProfile playerProfile; + + public ProfileByUUIDRequestEvent(PlayerProfile playerProfile) { + this.playerProfile = playerProfile; + } + @Override + public UUID getUUID() { + return uuid; + } + + @Override + public String getType() { + return "profileByUUID"; + } +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java new file mode 100644 index 00000000..b85829f1 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java @@ -0,0 +1,27 @@ +package ru.gravit.launcher.events.request; + +import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.launcher.request.ResultInterface; +import ru.gravit.utils.event.EventInterface; + +import java.util.UUID; + +public class ProfileByUsernameRequestEvent implements EventInterface, ResultInterface +{ + private static final UUID uuid = UUID.fromString("06204302-ff6b-4779-b97d-541e3bc39aa1"); + String error; + PlayerProfile playerProfile; + + public ProfileByUsernameRequestEvent(PlayerProfile playerProfile) { + this.playerProfile = playerProfile; + } + @Override + public UUID getUUID() { + return uuid; + } + + @Override + public String getType() { + return "profileByUsername"; + } +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfilesRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfilesRequestEvent.java new file mode 100644 index 00000000..3b788f17 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfilesRequestEvent.java @@ -0,0 +1,29 @@ +package ru.gravit.launcher.events.request; + +import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launcher.request.ResultInterface; +import ru.gravit.utils.event.EventInterface; + +import java.util.List; +import java.util.UUID; + +public class ProfilesRequestEvent implements EventInterface, ResultInterface +{ + private static final UUID uuid = UUID.fromString("2f26fbdf-598a-46dd-92fc-1699c0e173b1"); + List profiles; + + public ProfilesRequestEvent(List profiles) { + this.profiles = profiles; + } + + String error; + @Override + public UUID getUUID() { + return uuid; + } + + @Override + public String getType() { + return "profiles"; + } +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateListRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateListRequestEvent.java new file mode 100644 index 00000000..73136430 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateListRequestEvent.java @@ -0,0 +1,27 @@ +package ru.gravit.launcher.events.request; + +import ru.gravit.launcher.hasher.HashedDir; +import ru.gravit.launcher.request.ResultInterface; +import ru.gravit.utils.event.EventInterface; + +import java.util.UUID; + +public class UpdateListRequestEvent implements EventInterface, ResultInterface { + private static final UUID uuid = UUID.fromString("5fa836ae-6b61-401c-96ac-d8396f07ec6b"); + public final String type; + public final HashedDir dir; + + public UpdateListRequestEvent(HashedDir dir) { + this.dir = dir; + type = "success"; + } + @Override + public UUID getUUID() { + return uuid; + } + + @Override + public String getType() { + return "updateList"; + } +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/request/JsonResultSerializeAdapter.java b/libLauncher/src/main/java/ru/gravit/launcher/request/JsonResultSerializeAdapter.java new file mode 100644 index 00000000..7e73ba70 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/request/JsonResultSerializeAdapter.java @@ -0,0 +1,21 @@ +package ru.gravit.launcher.request; + +import com.google.gson.*; +import ru.gravit.launcher.request.ResultInterface; + +import java.lang.reflect.Type; + +public class JsonResultSerializeAdapter implements JsonSerializer { + private static final String PROP_NAME = "type"; + + @Override + public JsonElement serialize(ResultInterface src, Type typeOfSrc, JsonSerializationContext context) { + // note : won't work, you must delegate this + JsonObject jo = context.serialize(src).getAsJsonObject(); + + String classPath = src.getType(); + jo.add(PROP_NAME, new JsonPrimitive(classPath)); + + return jo; + } +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/request/ResultInterface.java b/libLauncher/src/main/java/ru/gravit/launcher/request/ResultInterface.java new file mode 100644 index 00000000..814c26a6 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/request/ResultInterface.java @@ -0,0 +1,5 @@ +package ru.gravit.launcher.request; + +public interface ResultInterface { + String getType(); +} diff --git a/libLauncher/src/main/java/ru/gravit/utils/Version.java b/libLauncher/src/main/java/ru/gravit/utils/Version.java index 1f0a0577..87d90be8 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/Version.java +++ b/libLauncher/src/main/java/ru/gravit/utils/Version.java @@ -97,7 +97,7 @@ public enum Type { public static final Map unModTypes = Collections.unmodifiableMap(types); static { - Arrays.asList(values()).stream().forEach(type -> types.put(type.name().substring(0, type.name().length() < 3 ? type.name().length() : 3), type)); + Arrays.asList(values()).stream().forEach(type -> types.put(type.name().substring(0, type.name().length() < 3 ? type.name().length() : 3).toLowerCase(Locale.ENGLISH), type)); } } } diff --git a/modules b/modules index 53106ee2..9a7e59fb 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 53106ee20700cb73ad65fd7dddf69b0d0b766f4c +Subproject commit 9a7e59fb8df543305a2b708822a398dcabcac4b9