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 mainAgentName = "StarterAgent"
def mainClassName = "ru.gravit.launchserver.LaunchServer"
def mainAgentName = "ru.gravit.launchserver.StarterAgent"
repositories {
maven {

View file

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

View file

@ -39,7 +39,7 @@ public ProguardConf(LaunchServer srv) {
words = proguard.resolve("random.pro");
confStrs = new HashSet<>();
prepare(false);
confStrs.add(readConf());
confStrs.add("@".concat(config.toString()));
if (this.srv.config.genMappings) confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'");
confStrs.add("-obfuscationdictionary \'" + 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)
{
body.append("Module mod");
body.append("ru.gravit.launcher.modules.Module mod");
body.append(autoincrement);
body.append(" = new ");
body.append(fullName);
body.append("();");
body.append("Launcher.modulesManager.registerModule( mod");
body.append("ru.gravit.launcher.Launcher.modulesManager.registerModule( mod");
body.append(autoincrement);
body.append(" , true );");
autoincrement++;

View file

@ -49,6 +49,10 @@ private Handshake readHandshake(HInput input, HOutput output) throws IOException
session = 0;
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

View file

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

View file

@ -1,5 +1,5 @@
String mainClassName = "LauncherEngine"
String mainAgentName = "LauncherAgent"
String mainClassName = "ru.gravit.launcher.LauncherEngine"
String mainAgentName = "ru.gravit.launcher.LauncherAgent"
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 {
return hasJoinedServer(profile, serverID);
}
public YggdrasilAuthenticationService getAuthenticationService() {
return (YggdrasilAuthenticationService)super.getAuthenticationService();
}
@Override
public void joinServer(GameProfile profile, String accessToken, String serverID) throws AuthenticationException {
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 {
if(System.getProperty("log4j.configurationFile") == null)
System.setProperty("log4j.configurationFile", "ru/gravit/launcher/log4j2.xml");
JVMHelper.verifySystemProperties(Launcher.class, true);
LogHelper.printVersion("Launcher");
// Start Launcher
@ -172,10 +170,11 @@ private LauncherEngine() {
}
@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);
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");
Launcher.modulesManager.initModules();
// 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");
Invocable invoker = (Invocable) engine;
if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) {

View file

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

View file

@ -6,5 +6,4 @@
compileOnly 'org.javassist:javassist:3.23.1-GA'
compile files('../compat/authlib/authlib-clean.jar')
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";
@LauncherAPI
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);

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);
}
@Override
public int getPriority() {
return 1;
}
@Override
public void init(ModuleContext context1) {
if (context1.getType().equals(ModuleContext.Type.LAUNCHSERVER)) {