Merge branch 'release/4.5.0'

This commit is contained in:
Gravit 2019-03-28 11:20:07 +07:00
commit c69460d802
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
28 changed files with 167 additions and 72 deletions

View file

@ -60,7 +60,10 @@ bundle project(':Radon')
}
launch4j('net.sf.launch4j:launch4j:3.12') {
exclude group: '*'
exclude group: 'org.apache.ant'
exclude group: 'net.java.abeille'
exclude group: 'foxtrot'
exclude group: 'com.jgoodies'
}
launch4jCJ('net.sf.launch4j:launch4j:3.12:workdir-win32') {
@ -103,10 +106,8 @@ task launch4jA(type: Copy) {
eachFile { FileCopyDetails fcp ->
if (fcp.name.startsWith("launch4j")) {
fcp.name = "launch4j.jar"
fcp.mode = 0755
} else {
fcp.exclude()
}
fcp.mode = 0755
}
}

View file

@ -8,7 +8,6 @@
import ru.gravit.launcher.managers.GarbageManager;
import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
import ru.gravit.launchserver.auth.AuthLimiter;
import ru.gravit.launchserver.auth.AuthProviderPair;
import ru.gravit.launchserver.auth.protect.NoProtectHandler;
import ru.gravit.launchserver.auth.protect.ProtectHandler;
@ -118,11 +117,9 @@ public AuthProviderPair getAuthProviderPair()
return null;
}
public PermissionsHandler permissionsHandler;
public HWIDHandler hwidHandler;
public HashMap<String, Component> components;
public Map<String, Component> components;
// Misc options
public int threadCount;
@ -188,13 +185,12 @@ public void verify() {
throw new NullPointerException("AuthHandler must not be null");
}
boolean isOneDefault = false;
for(AuthProviderPair pair : auth)
{
if(pair.isDefault)
{
for(AuthProviderPair pair : auth) {
if (pair.isDefault) {
isOneDefault = true;
break;
}
}
if(protectHandler == null)
{
throw new NullPointerException("ProtectHandler must not be null");
@ -468,7 +464,6 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
{
config.protectHandler.checkLaunchServerLicense();
}
config.authHandler.init();
if(config.components != null)
{
LogHelper.debug("PreInit components");

View file

@ -1,13 +1,10 @@
package ru.gravit.launchserver.auth.protect;
import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.launchserver.auth.handler.AuthHandler;
import ru.gravit.launchserver.response.auth.AuthResponse;
import ru.gravit.utils.helper.VerifyHelper;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public abstract class ProtectHandler {

View file

@ -1,8 +1,6 @@
package ru.gravit.launchserver.auth.provider;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.launchserver.auth.handler.AuthHandler;
import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException;

View file

@ -1,10 +1,6 @@
package ru.gravit.launchserver.command;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.command.CommandException;
import ru.gravit.utils.helper.VerifyHelper;
import java.util.UUID;
public abstract class Command extends ru.gravit.utils.command.Command {

View file

@ -34,8 +34,6 @@ public void invoke(String... args) throws Exception {
String login = args[0];
String password = args[1];
int auth_id = 0;
if (args.length >= 3) auth_id = Integer.valueOf(args[3]);
// Authenticate
AuthProvider provider = pair.provider;

View file

@ -1,8 +1,6 @@
package ru.gravit.launchserver.command.handler;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command;
import ru.gravit.utils.command.CommandException;
import ru.gravit.launchserver.command.auth.*;
import ru.gravit.launchserver.command.basic.*;
import ru.gravit.launchserver.command.dump.DumpEntryCacheCommand;
@ -13,15 +11,6 @@
import ru.gravit.launchserver.command.modules.LoadModuleCommand;
import ru.gravit.launchserver.command.modules.ModulesCommand;
import ru.gravit.launchserver.command.service.*;
import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public abstract class CommandHandler extends ru.gravit.utils.command.CommandHandler {
public static void registerCommands(ru.gravit.utils.command.CommandHandler handler)
@ -76,5 +65,6 @@ public static void registerCommands(ru.gravit.utils.command.CommandHandler handl
handler.registerCommand("checkInstall", new CheckInstallCommand(server));
handler.registerCommand("multi", new MultiCommand(server));
handler.registerCommand("getModulus", new GetModulusCommand(server));
handler.registerCommand("component", new ComponentCommand(server));
}
}

View file

@ -0,0 +1,105 @@
package ru.gravit.launchserver.command.service;
import ru.gravit.launcher.NeedGarbageCollection;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.components.Component;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
import java.io.Reader;
import java.nio.file.Paths;
public class ComponentCommand extends Command {
public ComponentCommand(LaunchServer server) {
super(server);
}
@Override
public String getArgsDescription() {
return "[action] [component name] [more args]";
}
@Override
public String getUsageDescription() {
return "component manager";
}
public void printHelp()
{
LogHelper.info("Print help for component:");
LogHelper.subInfo("component unload [componentName]");
LogHelper.subInfo("component load [componentName] [filename]");
LogHelper.subInfo("component gc [componentName]");
}
@Override
public void invoke(String... args) throws Exception {
verifyArgs(args, 1);
String componentName = null;
if(args.length > 1) componentName = args[1];
switch(args[0])
{
case "unload":
{
if(componentName == null) throw new IllegalArgumentException("Must set componentName");
Component component = server.config.components.get(componentName);
if(component == null) {
LogHelper.error("Component %s not found", componentName);
return;
}
if(component instanceof AutoCloseable)
{
((AutoCloseable) component).close();
}
else
{
LogHelper.error("Component %s unload not supported", componentName);
return;
}
break;
}
case "gc":
{
if(componentName == null) throw new IllegalArgumentException("Must set componentName");
Component component = server.config.components.get(componentName);
if(component == null) {
LogHelper.error("Component %s not found", componentName);
return;
}
if(component instanceof NeedGarbageCollection)
{
((NeedGarbageCollection) component).garbageCollection();
}
else
{
LogHelper.error("Component %s gc not supported", componentName);
return;
}
break;
}
case "load":
{
if(componentName == null) throw new IllegalArgumentException("Must set componentName");
if(args.length <= 2) throw new IllegalArgumentException("Must set file");
String fileName = args[2];
try(Reader reader = IOHelper.newReader(Paths.get(fileName)))
{
Component component = LaunchServer.gson.fromJson(reader, Component.class);
component.preInit(server);
component.init(server);
component.postInit(server);
LogHelper.info("Component %s(%s) loaded", componentName, component.getClass().getName());
}
}
case "help":
{
printHelp();
}
default:
{
printHelp();
}
}
}
}

View file

@ -1,6 +1,5 @@
package ru.gravit.launchserver.command.service;
import io.netty.handler.codec.base64.Base64;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command;
import ru.gravit.utils.helper.LogHelper;
@ -22,6 +21,6 @@ public String getUsageDescription() {
@Override
public void invoke(String... args) throws Exception {
LogHelper.info("You publickey modulus: ", LaunchServer.server.publicKey.getModulus().toString(16));
LogHelper.info("You publickey modulus: %s", LaunchServer.server.publicKey.getModulus().toString(16));
}
}

View file

@ -9,20 +9,16 @@
import ru.gravit.launchserver.socket.Client;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
public class AuthLimiterComponent extends Component implements NeedGarbageCollection {
private LaunchServer server;
@Override
public void preInit(LaunchServer launchServer) {
}
@Override
public void init(LaunchServer launchServer) {
server = launchServer;
launchServer.authHookManager.registerPreHook(this::preAuthHook);
}

View file

@ -1,7 +1,6 @@
package ru.gravit.launchserver.config;
import com.google.gson.*;
import ru.gravit.launchserver.auth.handler.AuthHandler;
import ru.gravit.launchserver.auth.protect.ProtectHandler;
import ru.gravit.utils.helper.LogHelper;

View file

@ -8,7 +8,7 @@
public class SessionManager implements NeedGarbageCollection {
public static final long SESSION_TIMEOUT = 10 * 60 * 1000; // 10 минут
public static final long SESSION_TIMEOUT = 3 * 60 * 60 * 1000; // 3 часа
public static final boolean GARBAGE_SERVER = Boolean.parseBoolean(System.getProperty("launcher.garbageSessionsServer", "false"));
private HashSet<Client> clientSet = new HashSet<>(128);

View file

@ -1,6 +1,5 @@
package ru.gravit.launchserver.manangers.hook;
import ru.gravit.launcher.request.RequestException;
import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.launchserver.response.auth.AuthResponse;
import ru.gravit.launchserver.socket.Client;

View file

@ -56,7 +56,9 @@ public void reply() throws Exception {
else pair = server.config.getAuthProviderPair(auth_id);
if(pair == null) requestError("Auth type not found");
AuthProvider provider = pair.provider;
AuthResponse.AuthContext context = new AuthResponse.AuthContext(session, login, password.length(), null, client, null, ip, true);
try {
server.authHookManager.preHook(context, clientData);
result = provider.auth(login, password, ip);
if (!VerifyHelper.isValidUsername(result.username)) {
AuthProvider.authError(String.format("Illegal result: '%s'", result.username));
@ -77,6 +79,7 @@ public void reply() throws Exception {
}
clientData.type = Client.Type.SERVER;
clientData.username = result.username;
server.authHookManager.postHook(context, clientData);
} catch (AuthException | HWIDException e) {
requestError(e.getMessage());
return;

View file

@ -5,7 +5,6 @@
import ru.gravit.launcher.serialize.SerializeLimits;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.auth.AuthProviderPair;
import ru.gravit.launchserver.auth.handler.AuthHandler;
import ru.gravit.launchserver.response.Response;
import ru.gravit.launchserver.socket.Client;
import ru.gravit.utils.helper.VerifyHelper;

View file

@ -52,7 +52,7 @@ private Handshake readHandshake(HInput input, HOutput output) throws IOException
if (magicNumber == Launcher.PROTOCOL_MAGIC_LEGACY - 1) { // Previous launcher protocol
session = 0;
legacy = true;
} else if (magicNumber == Launcher.PROTOCOL_MAGIC_LEGACY - 2) { // Previous launcher protocol
} else if (magicNumber == ServerSocketHandler.LEGACY_LAUNCHER_MAGIC) { // Previous launcher protocol
session = 0;
legacy = true;
} else if (magicNumber == Launcher.PROTOCOL_MAGIC_LEGACY) {

View file

@ -1,5 +1,6 @@
package ru.gravit.launchserver.socket;
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.managers.GarbageManager;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.manangers.SessionManager;
@ -37,6 +38,7 @@ public interface Listener {
public final SessionManager sessionManager;
private final AtomicLong idCounter = new AtomicLong(0L);
public static int LEGACY_LAUNCHER_MAGIC = Launcher.PROTOCOL_MAGIC_LEGACY - 2;
private volatile Listener listener;

View file

@ -3,7 +3,6 @@
import io.netty.channel.ChannelHandlerContext;
import ru.gravit.launcher.events.request.ErrorRequestEvent;
import ru.gravit.launcher.events.request.JoinServerRequestEvent;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.launchserver.socket.Client;
import ru.gravit.launchserver.socket.websocket.WebSocketService;

View file

@ -2,8 +2,6 @@
import ru.gravit.launcher.server.ServerWrapper;
import ru.gravit.utils.command.CommandHandler;
import ru.gravit.utils.command.JLineCommandHandler;
import ru.gravit.utils.command.StdCommandHandler;
import ru.gravit.utils.helper.LogHelper;
import java.io.IOException;

View file

@ -1,7 +1,6 @@
package ru.gravit.launchserver.console;
import ru.gravit.launcher.request.admin.ExecCommandRequest;
import ru.gravit.utils.command.Command;
import ru.gravit.utils.command.JLineCommandHandler;
import ru.gravit.utils.helper.LogHelper;

View file

@ -1,8 +1,6 @@
package ru.gravit.launchserver.console;
import ru.gravit.launcher.request.admin.ExecCommandRequest;
import ru.gravit.utils.command.Command;
import ru.gravit.utils.command.CommandHandler;
import ru.gravit.utils.command.StdCommandHandler;
import ru.gravit.utils.helper.LogHelper;

View file

@ -4,7 +4,6 @@
import ru.gravit.launcher.client.ClientModuleManager;
import ru.gravit.launcher.client.DirBridge;
import ru.gravit.launcher.client.FunctionalBridge;
import ru.gravit.launcher.client.LauncherSettings;
import ru.gravit.launcher.guard.LauncherGuardManager;
import ru.gravit.launcher.gui.JSRuntimeProvider;
import ru.gravit.launcher.gui.RuntimeProvider;
@ -13,8 +12,6 @@
import ru.gravit.utils.helper.JVMHelper;
import ru.gravit.utils.helper.LogHelper;
import java.time.Duration;
import java.time.Instant;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;

View file

@ -11,7 +11,6 @@
import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.profiles.PlayerProfile;
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.update.LegacyLauncherRequest;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.stream.StreamObject;
@ -34,8 +33,9 @@
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.security.interfaces.RSAPublicKey;
import java.util.*;
import java.util.Timer;
import java.util.concurrent.TimeUnit;
public final class ClientLauncher {
private static Gson gson = new Gson();
@ -294,6 +294,8 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl
}
private static Process process = null;
private static boolean clientStarted = false;
private static Thread writeParamsThread;
@LauncherAPI
public static Process launch(
@ -302,12 +304,18 @@ public static Process launch(
// Write params file (instead of CLI; Mustdie32 API can't handle command line > 32767 chars)
LogHelper.debug("Writing ClientLauncher params");
ClientLauncherContext context = new ClientLauncherContext();
CommonHelper.newThread("Client params writter", true, () ->
clientStarted = false;
if(writeParamsThread != null && writeParamsThread.isAlive())
{
writeParamsThread.interrupt();
}
writeParamsThread = CommonHelper.newThread("Client params writter", true, () ->
{
try {
try (ServerSocket socket = new ServerSocket()) {
socket.setReuseAddress(true);
socket.setSoTimeout(30000);
socket.bind(new InetSocketAddress(SOCKET_HOST, SOCKET_PORT));
Socket client = socket.accept();
if (process == null) {
@ -325,13 +333,13 @@ public static Process launch(
assetHDir.write(output);
clientHDir.write(output);
}
clientStarted = true;
}
} catch (IOException e) {
LogHelper.error(e);
}
}).start();
});
writeParamsThread.start();
checkJVMBitsAndVersion();
LogHelper.debug("Resolving JVM binary");
Path javaBin = LauncherGuardManager.getGuardJavaBinPath();
@ -386,7 +394,28 @@ public static Process launch(
}
// Let's rock!
process = builder.start();
if(!LogHelper.isDebugEnabled()) Thread.sleep(1000); //даем время потоку записи
if(!LogHelper.isDebugEnabled()) {
for(int i=0;i<50;++i)
{
if(!process.isAlive())
{
int exitCode = process.exitValue();
LogHelper.error("Process exit code %d", exitCode);
if(writeParamsThread != null && writeParamsThread.isAlive()) writeParamsThread.interrupt();
break;
}
if(clientStarted)
{
break;
}
Thread.sleep(200);
}
if(!clientStarted)
{
LogHelper.error("Write Client Params not successful. Using debug mode for more information");
}
}
clientStarted = false;
return process;
}
@ -397,7 +426,6 @@ public static void main(String... args) throws Throwable {
LauncherConfig.getAutogenConfig().initModules(); //INIT
initGson();
Launcher.modulesManager.preInitModules();
checkJVMBitsAndVersion();
JVMHelper.verifySystemProperties(ClientLauncher.class, true);
EnvHelper.checkDangerousParams();
JVMHelper.checkStackTrace(ClientLauncher.class);
@ -430,6 +458,7 @@ public static void main(String... args) throws Throwable {
}
Launcher.profile = profile;
Request.setSession(params.session);
checkJVMBitsAndVersion();
Launcher.modulesManager.initModules();
// Verify ClientLauncher sign and classpath
LogHelper.debug("Verifying ClientLauncher sign and classpath");

View file

@ -65,6 +65,7 @@ public void addCustomEnv(ClientLauncherContext context) {
env.put("GUARD_USERNAME", context.playerProfile.username);
env.put("GUARD_PUBLICKEY", config.publicKey.getModulus().toString(16));
env.put("GUARD_PROJECTNAME", config.projectname);
if(protectToken != null)
env.put("GUARD_TOKEN", protectToken);
if(config.guardLicenseName != null)
env.put("GUARD_LICENSE_NAME", config.guardLicenseName);

View file

@ -59,8 +59,8 @@ 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 = 4;
public static final int PATCH = 2;
public static final int MINOR = 5;
public static final int PATCH = 0;
public static final int BUILD = 1;
public static final Version.Type RELEASE = Version.Type.STABLE;
public static GsonBuilder gsonBuilder;

View file

@ -3,7 +3,6 @@
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.stream.StreamObject;
import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.SecurityHelper;
import ru.gravit.utils.helper.VerifyHelper;

View file

@ -5,8 +5,6 @@
import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;

@ -1 +1 @@
Subproject commit 073b52f785527e01ca548fc56b71130b41ce648e
Subproject commit 043b9ac4ffbca9a7378f22d7feeb4829e630a6c3