mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-10 17:49:40 +03:00
Merge branch 'release/4.3.1'
This commit is contained in:
commit
aac9856e53
51 changed files with 795 additions and 113 deletions
|
@ -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<Path> {
|
||||
private final Collection<ClientProfile> 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<ClientProfile> profilesList;
|
||||
|
||||
public volatile Map<String, SignedObjectHolder<HashedDir>> 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<ClientProfile> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ClientProfile>) LaunchServer.server.getProfiles()));
|
||||
}
|
||||
}
|
|
@ -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<ClientProfile> 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"));
|
||||
}
|
||||
}
|
|
@ -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<list.length;++i)
|
||||
{
|
||||
UUID uuid = LaunchServer.server.config.authHandler.usernameToUUID(list[i].username);
|
||||
result.playerProfiles[i] = ProfileByUUIDResponse.getProfile(LaunchServer.server,uuid,list[i].username,list[i].client);
|
||||
}
|
||||
service.sendObject(ctx, result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package ru.gravit.launchserver.socket.websocket.json.profile;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import ru.gravit.launcher.events.request.ProfileByUUIDRequestEvent;
|
||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||
import ru.gravit.launcher.profiles.Texture;
|
||||
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 ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ProfileByUUIDResponse implements JsonResponseInterface {
|
||||
public UUID uuid;
|
||||
public String client;
|
||||
public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String username, String client) {
|
||||
// Get skin texture
|
||||
Texture skin;
|
||||
try {
|
||||
skin = server.config.textureProvider.getSkinTexture(uuid, username, client);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(new IOException(String.format("Can't get skin texture: '%s'", username), e));
|
||||
skin = null;
|
||||
}
|
||||
|
||||
// Get cloak texture
|
||||
Texture cloak;
|
||||
try {
|
||||
cloak = server.config.textureProvider.getCloakTexture(uuid, username, client);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(new IOException(String.format("Can't get cloak texture: '%s'", username), e));
|
||||
cloak = null;
|
||||
}
|
||||
|
||||
// Return combined profile
|
||||
return new PlayerProfile(uuid, username, skin, cloak);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "profileByUUID";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
String username = LaunchServer.server.config.authHandler.uuidToUsername(uuid);
|
||||
service.sendObject(ctx, new ProfileByUUIDRequestEvent(getProfile(LaunchServer.server,uuid,username,this.client)));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package ru.gravit.launchserver.socket.websocket.json.profile;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import ru.gravit.launcher.events.request.ProfileByUsernameRequestEvent;
|
||||
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;
|
||||
|
||||
import static ru.gravit.launchserver.socket.websocket.json.profile.ProfileByUUIDResponse.getProfile;
|
||||
|
||||
public class ProfileByUsername implements JsonResponseInterface {
|
||||
String username;
|
||||
String client;
|
||||
@Override
|
||||
public String getType() {
|
||||
return "profileByUsername";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
UUID uuid = LaunchServer.server.config.authHandler.usernameToUUID(username);
|
||||
service.sendObject(ctx, new ProfileByUsernameRequestEvent(getProfile(LaunchServer.server,uuid,username,this.client)));
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package ru.gravit.launchserver.socket.websocket.json.update;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import ru.gravit.launcher.events.request.LauncherRequestEvent;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
||||
|
@ -29,35 +30,25 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
if (launcher_type == 1) // JAR
|
||||
{
|
||||
byte[] hash = LaunchServer.server.launcherBinary.getBytes().getDigest();
|
||||
if (hash == null) service.sendObjectAndClose(ctx, new Result(true, JAR_URL));
|
||||
if (hash == null) service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, JAR_URL));
|
||||
if (Arrays.equals(bytes, hash)) {
|
||||
service.sendObject(ctx, new Result(false, JAR_URL));
|
||||
client.checkSign = true;
|
||||
service.sendObject(ctx, new LauncherRequestEvent(false, JAR_URL));
|
||||
} else {
|
||||
service.sendObjectAndClose(ctx, new Result(true, JAR_URL));
|
||||
service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, JAR_URL));
|
||||
}
|
||||
} else if (launcher_type == 2) //EXE
|
||||
{
|
||||
byte[] hash = LaunchServer.server.launcherEXEBinary.getBytes().getDigest();
|
||||
if (hash == null) service.sendObjectAndClose(ctx, new Result(true, EXE_URL));
|
||||
if (hash == null) service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, EXE_URL));
|
||||
if (Arrays.equals(bytes, hash)) {
|
||||
service.sendObject(ctx, new Result(false, EXE_URL));
|
||||
client.checkSign = true;
|
||||
service.sendObject(ctx, new LauncherRequestEvent(false, EXE_URL));
|
||||
} else {
|
||||
service.sendObjectAndClose(ctx, new Result(true, EXE_URL));
|
||||
service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, EXE_URL));
|
||||
}
|
||||
} else service.sendObject(ctx, new WebSocketService.ErrorResult("Request launcher type error"));
|
||||
|
||||
}
|
||||
|
||||
public class Result {
|
||||
public String type = "success";
|
||||
public String requesttype = "launcherUpdate";
|
||||
public String url;
|
||||
|
||||
public Result(boolean needUpdate, String url) {
|
||||
this.needUpdate = needUpdate;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public boolean needUpdate;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ru.gravit.launchserver.socket.websocket.json.update;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import ru.gravit.launcher.events.request.UpdateListRequestEvent;
|
||||
import ru.gravit.launcher.hasher.HashedDir;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
|
@ -22,18 +23,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
return;
|
||||
}
|
||||
HashedDir hdir = LaunchServer.server.updatesDirMap.get(dir).object;
|
||||
service.sendObject(ctx, new Result(hdir));
|
||||
service.sendObject(ctx, new UpdateListRequestEvent(hdir));
|
||||
}
|
||||
|
||||
class Result {
|
||||
public final String type;
|
||||
public final String requesttype;
|
||||
public final HashedDir dir;
|
||||
|
||||
Result(HashedDir dir) {
|
||||
this.dir = dir;
|
||||
type = "success";
|
||||
requesttype = "updateList";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package ru.gravit.launcher.guard;
|
||||
|
||||
import ru.gravit.launcher.client.ClientLauncher;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package ru.gravit.launcher.guard;
|
||||
|
||||
import ru.gravit.launcher.client.DirBridge;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
import ru.gravit.launcher.client.DirBridge;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.JVMHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
import ru.gravit.utils.helper.UnpackHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
dependencies {
|
||||
compile project(':libLauncher')
|
||||
compile 'javax.websocket:javax.websocket-client-api:1.1'
|
||||
compileOnly 'javax.websocket:javax.websocket-client-api:1.1'
|
||||
compileOnly 'com.google.guava:guava:26.0-jre'
|
||||
compile files('../compat/authlib/authlib-clean.jar')
|
||||
}
|
||||
|
|
|
@ -67,9 +67,26 @@ public AuthRequest(String login, byte[] encryptedPassword, HWID hwid, int auth_i
|
|||
public Integer getType() {
|
||||
return RequestType.AUTH.getNumber();
|
||||
}
|
||||
/*public class EchoRequest implements RequestInterface
|
||||
{
|
||||
String echo;
|
||||
|
||||
public EchoRequest(String echo) {
|
||||
this.echo = echo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "echo";
|
||||
}
|
||||
}*/
|
||||
@Override
|
||||
protected Result requestDo(HInput input, HOutput output) throws IOException {
|
||||
/*try {
|
||||
LegacyRequestBridge.sendRequest(new EchoRequest("Hello World!"));
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
output.writeString(login, SerializeLimits.MAX_LOGIN);
|
||||
output.writeBoolean(Launcher.profile != null);
|
||||
if (Launcher.profile != null)
|
||||
|
|
|
@ -25,11 +25,6 @@
|
|||
@ClientEndpoint
|
||||
public class ClientJSONPoint {
|
||||
public Session session = null;
|
||||
private ClientWebSocketService service;
|
||||
|
||||
public void setService(ClientWebSocketService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(final Session session_r) {
|
||||
|
@ -44,7 +39,7 @@ public void processError(final Throwable t) {
|
|||
|
||||
@OnMessage
|
||||
public void processMessage(Reader message) {
|
||||
service.processMessage(message);
|
||||
|
||||
}
|
||||
|
||||
public void send(String js) throws IOException {
|
||||
|
|
|
@ -4,39 +4,46 @@
|
|||
import com.google.gson.GsonBuilder;
|
||||
import ru.gravit.launcher.hasher.HashedEntry;
|
||||
import ru.gravit.launcher.hasher.HashedEntryAdapter;
|
||||
import ru.gravit.launcher.request.ResultInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class ClientWebSocketService {
|
||||
public class ClientWebSocketService extends ClientJSONPoint {
|
||||
public final GsonBuilder gsonBuilder;
|
||||
public final Gson gson;
|
||||
public final ClientJSONPoint point;
|
||||
private HashMap<String, Class<RequestInterface>> requests;
|
||||
private HashMap<String, Class<ResultInterface>> results;
|
||||
private HashMap<String, Class<? extends RequestInterface>> requests;
|
||||
private HashMap<String, Class<? extends ResultInterface>> results;
|
||||
private HashSet<EventHandler> 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<RequestInterface> getRequestClass(String key) {
|
||||
public Class<? extends RequestInterface> getRequestClass(String key) {
|
||||
return requests.get(key);
|
||||
}
|
||||
public Class<? extends ResultInterface> getResultClass(String key) {
|
||||
return results.get(key);
|
||||
}
|
||||
|
||||
public void registerRequest(String key, Class<RequestInterface> clazz) {
|
||||
public void registerRequest(String key, Class<? extends RequestInterface> clazz) {
|
||||
requests.put(key, clazz);
|
||||
}
|
||||
|
||||
|
@ -44,7 +51,7 @@ public void registerRequests() {
|
|||
|
||||
}
|
||||
|
||||
public void registerResult(String key, Class<ResultInterface> clazz) {
|
||||
public void registerResult(String key, Class<? extends ResultInterface> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<RequestInterface> cls = service.getRequestClass(typename);
|
||||
Class<? extends RequestInterface> cls = service.getRequestClass(typename);
|
||||
|
||||
|
||||
return (RequestInterface) context.deserialize(json, cls);
|
||||
|
|
|
@ -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<ResultInterface>, JsonDeserializer<ResultInterface> {
|
||||
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<? extends ResultInterface> 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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package ru.gravit.launcher.request.websockets;
|
||||
|
||||
public interface ResultInterface {
|
||||
void process();
|
||||
}
|
|
@ -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<ResultEvent> 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -28,4 +28,8 @@
|
|||
}
|
||||
}
|
||||
|
||||
wrapper {
|
||||
distributionType = Wrapper.DistributionType.ALL
|
||||
}
|
||||
|
||||
defaultTasks 'build'
|
||||
|
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -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<ClientProfile> profiles;
|
||||
|
||||
public ProfilesRequestEvent(List<ClientProfile> profiles) {
|
||||
this.profiles = profiles;
|
||||
}
|
||||
|
||||
String error;
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "profiles";
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -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<ResultInterface> {
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package ru.gravit.launcher.request;
|
||||
|
||||
public interface ResultInterface {
|
||||
String getType();
|
||||
}
|
|
@ -97,7 +97,7 @@ public enum Type {
|
|||
public static final Map<String, Type> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
2
modules
2
modules
|
@ -1 +1 @@
|
|||
Subproject commit 53106ee20700cb73ad65fd7dddf69b0d0b766f4c
|
||||
Subproject commit 9a7e59fb8df543305a2b708822a398dcabcac4b9
|
Loading…
Reference in a new issue