[FEATURE] Доработка LauncherConfig для работы с nettyPort

This commit is contained in:
Gravit 2019-01-29 23:15:17 +07:00
parent 0e215899e4
commit 9ca5158eeb
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 41 additions and 1 deletions

View file

@ -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')
}

View file

@ -5,6 +5,8 @@
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType;
import ru.gravit.launcher.request.auth.AuthRequest.Result;
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
import ru.gravit.launcher.request.websockets.RequestInterface;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits;
@ -67,9 +69,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)

View file

@ -1,8 +1,13 @@
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();
@ -23,4 +28,18 @@ public static ResultInterface sendRequest(RequestInterface request) throws IOExc
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);
}
}

View file

@ -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;