Add websocket on client. (#27)

* Add websocket on client.

* Make send methods.
This commit is contained in:
Zaxar163 2018-09-30 14:42:07 +03:00 committed by Gravit
parent 0421ffd65a
commit e4b0c1c646
17 changed files with 75 additions and 27 deletions

View file

@ -53,7 +53,7 @@ compile project(':libLauncher') // pack
bundle 'org.fusesource.jansi:jansi:1.17.1' bundle 'org.fusesource.jansi:jansi:1.17.1'
bundle 'commons-io:commons-io:2.6' bundle 'commons-io:commons-io:2.6'
bundle 'org.javassist:javassist:3.23.1-GA' bundle 'org.javassist:javassist:3.23.1-GA'
bundle 'io.netty:netty-all:4.1.28.Final' bundle 'io.netty:netty-all:4.1.29.Final'
bundle 'org.slf4j:slf4j-simple:1.7.25' bundle 'org.slf4j:slf4j-simple:1.7.25'
bundle 'org.slf4j:slf4j-api:1.7.25' bundle 'org.slf4j:slf4j-api:1.7.25'

View file

@ -31,7 +31,6 @@
import ru.gravit.launcher.Launcher; import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.hasher.FileNameMatcher;
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;

View file

@ -1,6 +1,5 @@
package ru.gravit.launchserver.auth.hwid; package ru.gravit.launchserver.auth.hwid;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;

View file

@ -16,9 +16,6 @@
import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; import ru.gravit.launcher.serialize.config.entry.StringConfigEntry;
public final class JsonAuthProvider extends AuthProvider { public final class JsonAuthProvider extends AuthProvider {
private static final int TIMEOUT = Integer.parseInt(
System.getProperty("launcher.connection.timeout", Integer.toString(1500)));
private final URL url; private final URL url;
private final String userKeyName; private final String userKeyName;
private final String passKeyName; private final String passKeyName;

View file

@ -5,7 +5,6 @@
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import clojure.lang.IFn;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;

View file

@ -21,7 +21,6 @@
import ru.gravit.launcher.Launcher; import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launchserver.manangers.BuildHookManager;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;

View file

@ -1,11 +1,9 @@
package ru.gravit.launchserver.manangers; package ru.gravit.launchserver.manangers;
import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.zip.ZipOutputStream;
import ru.gravit.launcher.AutogenConfig; import ru.gravit.launcher.AutogenConfig;
import ru.gravit.launcher.modules.TestClientModule; import ru.gravit.launcher.modules.TestClientModule;

View file

@ -14,6 +14,7 @@ public ModulesManager(LaunchServer lsrv) {
modules = new ArrayList<>(1); modules = new ArrayList<>(1);
classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader()); classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader());
context = new LaunchServerModuleContext(lsrv, classloader); context = new LaunchServerModuleContext(lsrv, classloader);
registerCoreModule();
} }
private void registerCoreModule() { private void registerCoreModule() {

View file

@ -7,12 +7,10 @@
import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.launchserver.auth.hwid.HWID;
import ru.gravit.launchserver.auth.hwid.HWIDException; import ru.gravit.launchserver.auth.hwid.HWIDException;
import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.AuthProvider;
import ru.gravit.launchserver.auth.provider.AuthProviderResult; import ru.gravit.launchserver.auth.provider.AuthProviderResult;
import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.response.Response;
import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse;
import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.Client;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
@ -23,7 +21,6 @@
import javax.crypto.IllegalBlockSizeException; import javax.crypto.IllegalBlockSizeException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.UUID;
public final class AuthServerResponse extends Response { public final class AuthServerResponse extends Response {
private static String echo(int length) { private static String echo(int length) {

View file

@ -1,13 +1,11 @@
package ru.gravit.launchserver.response.update; package ru.gravit.launchserver.response.update;
import java.util.ArrayList;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.config.entry.ListConfigEntry;
import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.response.Response;

View file

@ -3,6 +3,7 @@
dependencies { dependencies {
compile project(':libLauncher') compile project(':libLauncher')
compile 'javax.websocket:javax.websocket-client-api:1.1'
compileOnly 'com.google.code.gson:gson:2.8.5' compileOnly 'com.google.code.gson:gson:2.8.5'
compileOnly 'com.google.guava:guava:26.0-jre' compileOnly 'com.google.guava:guava:26.0-jre'
compile files('../compat/authlib/authlib-clean.jar') compile files('../compat/authlib/authlib-clean.jar')

View file

@ -1,6 +1,5 @@
package ru.gravit.launcher.request.auth; package ru.gravit.launcher.request.auth;
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.profiles.PlayerProfile;

View file

@ -0,0 +1,67 @@
package ru.gravit.launcher.request.websockets;
import java.io.IOException;
import java.io.Reader;
import javax.websocket.ClientEndpoint;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonValue;
import com.eclipsesource.json.ParseException;
import ru.gravit.utils.helper.LogHelper;
/*
* public class Client {
*
* final static CountDownLatch messageLatch = new CountDownLatch(1);
*
* public static void main(String[] args) {
* try {
* WebSocketContainer container = ContainerProvider.getWebSocketContainer();
* String uri = "ws://echo.websocket.org:80/";
* System.out.println("Connecting to " + uri);
* container.connectToServer(MyClientEndpoint.class, URI.create(uri));
* messageLatch.await(100, TimeUnit.SECONDS);
* } catch (DeploymentException | InterruptedException | IOException ex) {
* Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
* }
* }
* }
*/
@ClientEndpoint
public class ClientJSONPoint {
public Session session = null;
@OnOpen
public void onOpen(final Session session_r) {
session = session_r;
System.out.println("Connected to endpoint: " + session.getBasicRemote());
}
@OnError
public void processError(final Throwable t) {
t.printStackTrace();
}
@OnMessage
public void processMessage(Reader message) {
try {
JsonValue json = Json.parse(message);
} catch (ParseException | IOException ex) {
LogHelper.error(ex);
}
}
public void send(JsonValue js) throws IOException {
session.getBasicRemote().sendText(js.asString());
}
public void sendAsync(JsonValue js) throws IOException {
session.getAsyncRemote().sendText(js.asString());
}
}

View file

@ -45,7 +45,7 @@ public static void main(String[] args) throws Throwable {
} }
LauncherConfig cfg = new LauncherConfig(config.address, config.port, SecurityHelper.toPublicRSAKey(IOHelper.read(Paths.get("public.key"))),new HashMap<>(),config.projectname); LauncherConfig cfg = new LauncherConfig(config.address, config.port, SecurityHelper.toPublicRSAKey(IOHelper.read(Paths.get("public.key"))),new HashMap<>(),config.projectname);
Boolean auth = new AuthServerRequest(cfg,config.login,SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)),0,config.title).request(); Boolean auth = new AuthServerRequest(cfg,config.login,SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)),0,config.title).request();
// TODO check auth...
ProfilesRequest.Result result = new ProfilesRequest(cfg).request(); ProfilesRequest.Result result = new ProfilesRequest(cfg).request();
Launcher.setConfig(cfg); Launcher.setConfig(cfg);
for (SignedObjectHolder<ClientProfile> p : result.profiles) { for (SignedObjectHolder<ClientProfile> p : result.profiles) {
@ -61,6 +61,7 @@ public static void main(String[] args) throws Throwable {
String classname = config.mainclass.isEmpty() ? args[0] : config.mainclass; String classname = config.mainclass.isEmpty() ? args[0] : config.mainclass;
Class<?> mainClass; Class<?> mainClass;
if(config.customClassLoader) { if(config.customClassLoader) {
@SuppressWarnings("unchecked")
Class<ClassLoader> classloader_class = (Class<ClassLoader>) Class.forName(config.classloader); Class<ClassLoader> classloader_class = (Class<ClassLoader>) Class.forName(config.classloader);
ClassLoader loader = classloader_class.getConstructor(ClassLoader.class).newInstance(ClassLoader.getSystemClassLoader()); ClassLoader loader = classloader_class.getConstructor(ClassLoader.class).newInstance(ClassLoader.getSystemClassLoader());
Thread.currentThread().setContextClassLoader(loader); Thread.currentThread().setContextClassLoader(loader);

View file

@ -1,16 +1,12 @@
package ru.gravit.launcher.profiles; package ru.gravit.launcher.profiles;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*; import java.util.*;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.FileNameMatcher;
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.launcher.hasher.HashedFile;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;

View file

@ -1,9 +1,7 @@
package ru.gravit.launcher.ssl; package ru.gravit.launcher.ssl;
import javax.net.ssl.*; import javax.net.ssl.*;
import java.io.IOException;
import java.security.*; import java.security.*;
import java.security.cert.CertificateException;
public class LauncherSSLContext { public class LauncherSSLContext {
public SSLServerSocketFactory ssf; public SSLServerSocketFactory ssf;

View file

@ -2,7 +2,6 @@
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import javassist.ClassPool; import javassist.ClassPool;