JavaScript updates

This commit is contained in:
Gravit 2018-09-19 19:03:52 +07:00
parent 416289f7a7
commit be91c9dc5b
15 changed files with 36 additions and 96 deletions

View file

@ -1,5 +1,5 @@
def mainClassName = "LaunchServer" def mainClassName = "ru.gravit.launchserver.LaunchServer"
def mainAgentName = "StarterAgent" def mainAgentName = "ru.gravit.launchserver.StarterAgent"
repositories { repositories {
maven { maven {

View file

@ -382,7 +382,7 @@ public LaunchServer(Path dir, boolean portable) throws IOException, InvalidKeySp
// pre init modules // pre init modules
modulesManager = new ModulesManager(this); modulesManager = new ModulesManager(this);
modulesManager.autoload(); modulesManager.autoload(dir.resolve("modules"));
modulesManager.preInitModules(); modulesManager.preInitModules();
// Read LaunchServer config // Read LaunchServer config

View file

@ -39,7 +39,7 @@ public ProguardConf(LaunchServer srv) {
words = proguard.resolve("random.pro"); words = proguard.resolve("random.pro");
confStrs = new HashSet<>(); confStrs = new HashSet<>();
prepare(false); prepare(false);
confStrs.add(readConf()); confStrs.add("@".concat(config.toString()));
if (this.srv.config.genMappings) confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'"); if (this.srv.config.genMappings) confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'");
confStrs.add("-obfuscationdictionary \'" + words.toFile().getName() + "\'"); confStrs.add("-obfuscationdictionary \'" + words.toFile().getName() + "\'");
confStrs.add("-classobfuscationdictionary \'" + words.toFile().getName() + "\'"); confStrs.add("-classobfuscationdictionary \'" + words.toFile().getName() + "\'");

View file

@ -24,12 +24,12 @@ public JAConfigurator(Class<?> configclass) throws NotFoundException {
} }
public void addModuleClass(String fullName) public void addModuleClass(String fullName)
{ {
body.append("Module mod"); body.append("ru.gravit.launcher.modules.Module mod");
body.append(autoincrement); body.append(autoincrement);
body.append(" = new "); body.append(" = new ");
body.append(fullName); body.append(fullName);
body.append("();"); body.append("();");
body.append("Launcher.modulesManager.registerModule( mod"); body.append("ru.gravit.launcher.Launcher.modulesManager.registerModule( mod");
body.append(autoincrement); body.append(autoincrement);
body.append(" , true );"); body.append(" , true );");
autoincrement++; autoincrement++;

View file

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

View file

@ -1,7 +1,7 @@
-libraryjars '<java.home>/lib/rt.jar' -libraryjars '<java.home>/lib/rt.jar'
-libraryjars '<java.home>/lib/jce.jar' -libraryjars '<java.home>/lib/jce.jar'
-libraryjars '<java.home>/lib/ext/nashorn.jar' -libraryjars '<java.home>/lib/ext/nashorn.jar'
-injars ../Launcher.jar(!META-INF/versions/**) -injars ../Launcher.jar
-outjars ../Launcher-obf.jar -outjars ../Launcher-obf.jar
-keepattributes SourceFile,LineNumberTable -keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute Source -renamesourcefileattribute Source
@ -15,7 +15,7 @@
-forceprocessing -forceprocessing
-overloadaggressively -overloadaggressively
-repackageclasses 'launcher' -repackageclasses 'ru.gravit.launcher'
-keep class ru.zaxar163.* -keep class ru.zaxar163.*
-keepattributes SourceFile,LineNumberTable,*Annotation* -keepattributes SourceFile,LineNumberTable,*Annotation*
-renamesourcefileattribute SourceFile -renamesourcefileattribute SourceFile
@ -32,15 +32,15 @@
*; *;
} }
-keepclassmembers @LauncherAPI class ** { -keepclassmembers @ru.gravit.launcher.LauncherAPI class ** {
<fields>; <fields>;
<methods>; <methods>;
} }
-keepclassmembers class ** { -keepclassmembers class ** {
@LauncherAPI @ru.gravit.launcher.LauncherAPI
<fields>; <fields>;
@LauncherAPI @ru.gravit.launcher.LauncherAPI
<methods>; <methods>;
} }

View file

@ -1,5 +1,5 @@
String mainClassName = "LauncherEngine" String mainClassName = "ru.gravit.launcher.LauncherEngine"
String mainAgentName = "LauncherAgent" String mainAgentName = "ru.gravit.launcher.LauncherAgent"
repositories { repositories {

View file

@ -171,7 +171,9 @@ public GameProfile hasJoinedServer(GameProfile profile, String serverID) throws
public GameProfile hasJoinedServer(GameProfile profile, String serverID, InetAddress address) throws AuthenticationUnavailableException { public GameProfile hasJoinedServer(GameProfile profile, String serverID, InetAddress address) throws AuthenticationUnavailableException {
return hasJoinedServer(profile, serverID); return hasJoinedServer(profile, serverID);
} }
public YggdrasilAuthenticationService getAuthenticationService() {
return (YggdrasilAuthenticationService)super.getAuthenticationService();
}
@Override @Override
public void joinServer(GameProfile profile, String accessToken, String serverID) throws AuthenticationException { public void joinServer(GameProfile profile, String accessToken, String serverID) throws AuthenticationException {
if (!ClientLauncher.isLaunched()) if (!ClientLauncher.isLaunched())

View file

@ -147,8 +147,6 @@ public static void addLauncherClassBindings(Map<String, Object> bindings) {
} }
public static void main(String... args) throws Throwable { public static void main(String... args) throws Throwable {
if(System.getProperty("log4j.configurationFile") == null)
System.setProperty("log4j.configurationFile", "ru/gravit/launcher/log4j2.xml");
JVMHelper.verifySystemProperties(Launcher.class, true); JVMHelper.verifySystemProperties(Launcher.class, true);
LogHelper.printVersion("Launcher"); LogHelper.printVersion("Launcher");
// Start Launcher // Start Launcher
@ -172,10 +170,11 @@ private LauncherEngine() {
} }
@LauncherAPI @LauncherAPI
public Object loadScript(URL url) throws IOException, ScriptException { public Object loadScript(String path) throws IOException, ScriptException {
URL url = Launcher.getResourceURL(path);
LogHelper.debug("Loading script: '%s'", url); LogHelper.debug("Loading script: '%s'", url);
try (BufferedReader reader = IOHelper.newReader(url)) { try (BufferedReader reader = IOHelper.newReader(url)) {
return engine.eval(reader); return engine.eval(reader,engine.getBindings(ScriptContext.ENGINE_SCOPE));
} }
} }
@ -198,7 +197,10 @@ public void start(String... args) throws Throwable {
throw new IllegalStateException("Launcher has been already started"); throw new IllegalStateException("Launcher has been already started");
Launcher.modulesManager.initModules(); Launcher.modulesManager.initModules();
// Load init.js script // Load init.js script
loadScript(Launcher.getResourceURL(Launcher.INIT_SCRIPT_FILE)); loadScript(Launcher.API_SCRIPT_FILE);
loadScript(Launcher.INIT_SCRIPT_FILE);
loadScript("config.js");
loadScript("dialog/dialog.js");
LogHelper.info("Invoking start() function"); LogHelper.info("Invoking start() function");
Invocable invoker = (Invocable) engine; Invocable invoker = (Invocable) engine;
if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) {

View file

@ -9,11 +9,12 @@
@SuppressWarnings("AbstractClassNeverImplemented") @SuppressWarnings("AbstractClassNeverImplemented")
public abstract class JSApplication extends Application { public abstract class JSApplication extends Application {
private static final AtomicReference<JSApplication> INSTANCE = new AtomicReference<>(); private static final AtomicReference<JSApplication> INSTANCE = new AtomicReference<>();
@LauncherAPI
public static JSApplication getInstance() { public static JSApplication getInstance() {
return INSTANCE.get(); return INSTANCE.get();
} }
@SuppressWarnings("ConstructorNotProtectedInAbstractClass") @SuppressWarnings("ConstructorNotProtectedInAbstractClass")
public JSApplication() { public JSApplication() {
INSTANCE.set(this); INSTANCE.set(this);

View file

@ -6,5 +6,4 @@
compileOnly 'org.javassist:javassist:3.23.1-GA' compileOnly 'org.javassist:javassist:3.23.1-GA'
compile files('../compat/authlib/authlib-clean.jar') compile files('../compat/authlib/authlib-clean.jar')
compile 'com.eclipsesource.minimal-json:minimal-json:0.9.4' compile 'com.eclipsesource.minimal-json:minimal-json:0.9.4'
compile group: 'org.eclipse.jetty.websocket', name: 'websocket-client', version: '9.4.12.v20180830'
} }

View file

@ -40,6 +40,8 @@ public final class Launcher {
public static final String CONFIG_FILE = "config.bin"; public static final String CONFIG_FILE = "config.bin";
@LauncherAPI @LauncherAPI
public static final String INIT_SCRIPT_FILE = "init.js"; public static final String INIT_SCRIPT_FILE = "init.js";
@LauncherAPI
public static final String API_SCRIPT_FILE = "engine/api.js";
private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL); private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL);

View file

@ -1,8 +0,0 @@
package ru.gravit.utils.websocket;
import ru.gravit.launcher.serialize.HInput;
@FunctionalInterface
public interface MessageInterface {
void request(HInput input);
}

View file

@ -1,67 +0,0 @@
package ru.gravit.utils.websocket;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.concurrent.*;
import jdk.nashorn.internal.ir.RuntimeNode;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.utils.helper.IOHelper;
/**
* Basic Echo Client Socket
*/
@WebSocket(maxTextMessageSize = 64 * 1024)
public class WebSocketClient
{
private final CountDownLatch closeLatch;
@SuppressWarnings("unused")
private Session session;
private final MessageInterface adapter;
public WebSocketClient(MessageInterface adapter)
{
this.closeLatch = new CountDownLatch(1);
this.adapter = adapter;
}
public boolean awaitClose(int duration, TimeUnit unit) throws InterruptedException
{
return this.closeLatch.await(duration,unit);
}
@OnWebSocketClose
public void onClose(int statusCode, String reason)
{
System.out.printf("Connection closed: %d - %s%n",statusCode,reason);
this.session = null;
this.closeLatch.countDown(); // trigger latch
}
@OnWebSocketConnect
public void onConnect(Session session)
{
System.out.printf("Got connect: %s%n",session);
this.session = session;
}
public void request(ByteBuffer buffer) throws IOException {
session.getRemote().sendBytes(buffer);
}
@OnWebSocketMessage
public void onMessage(String msg) throws IOException {
byte[] bytes = msg.getBytes();
InputStream stream = new ByteArrayInputStream(bytes);
HInput input = new HInput(stream);
adapter.request(input);
}
}

View file

@ -23,6 +23,11 @@ public LauncherVersion getVersion() {
return new LauncherVersion(1, 0, 1, 2); return new LauncherVersion(1, 0, 1, 2);
} }
@Override
public int getPriority() {
return 1;
}
@Override @Override
public void init(ModuleContext context1) { public void init(ModuleContext context1) {
if (context1.getType().equals(ModuleContext.Type.LAUNCHSERVER)) { if (context1.getType().equals(ModuleContext.Type.LAUNCHSERVER)) {