mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] nettyEnabled/nettyAddress
This commit is contained in:
parent
2fa638d3c6
commit
709efdd04e
4 changed files with 15 additions and 9 deletions
|
@ -58,7 +58,7 @@ public R request() throws Exception {
|
||||||
if (!started.compareAndSet(false, true))
|
if (!started.compareAndSet(false, true))
|
||||||
throw new IllegalStateException("Request already started");
|
throw new IllegalStateException("Request already started");
|
||||||
R wsResult = null;
|
R wsResult = null;
|
||||||
if(config.nettyPort != 0)
|
if(config.isNettyEnabled)
|
||||||
wsResult = requestWebSockets();
|
wsResult = requestWebSockets();
|
||||||
if(wsResult != null) return wsResult;
|
if(wsResult != null) return wsResult;
|
||||||
// Make request to LaunchServer
|
// Make request to LaunchServer
|
||||||
|
|
|
@ -22,8 +22,8 @@ public class ClientWebSocketService extends ClientJSONPoint {
|
||||||
private HashMap<String, Class<? extends ResultInterface>> results;
|
private HashMap<String, Class<? extends ResultInterface>> results;
|
||||||
private HashSet<EventHandler> handlers;
|
private HashSet<EventHandler> handlers;
|
||||||
|
|
||||||
public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int port, int i) {
|
public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int i) {
|
||||||
super(createURL(address, port), Collections.emptyMap(), i);
|
super(createURL(address), Collections.emptyMap(), i);
|
||||||
requests = new HashMap<>();
|
requests = new HashMap<>();
|
||||||
results = new HashMap<>();
|
results = new HashMap<>();
|
||||||
handlers = new HashSet<>();
|
handlers = new HashSet<>();
|
||||||
|
@ -33,9 +33,9 @@ public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int port,
|
||||||
this.gsonBuilder.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter());
|
this.gsonBuilder.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter());
|
||||||
this.gson = gsonBuilder.create();
|
this.gson = gsonBuilder.create();
|
||||||
}
|
}
|
||||||
private static URI createURL(String address, int port) {
|
private static URI createURL(String address) {
|
||||||
try {
|
try {
|
||||||
URI u = new URI("ws://".concat(address).concat(":").concat(String.valueOf(port)).concat("/api"));
|
URI u = new URI(address);
|
||||||
return u;
|
return u;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
|
|
|
@ -33,21 +33,21 @@ public static ResultInterface sendRequest(RequestInterface request) throws IOExc
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public static void initWebSockets(String address, int port)
|
public static void initWebSockets(String address)
|
||||||
{
|
{
|
||||||
service = new ClientWebSocketService(new GsonBuilder(), address, port, 5000);
|
service = new ClientWebSocketService(new GsonBuilder(), address, 5000);
|
||||||
service.registerResults();
|
service.registerResults();
|
||||||
service.registerRequests();
|
service.registerRequests();
|
||||||
service.registerHandler(waitEventHandler);
|
service.registerHandler(waitEventHandler);
|
||||||
try {
|
try {
|
||||||
if(!service.connectBlocking()) LogHelper.error("Error connecting");
|
if(!service.connectBlocking()) LogHelper.error("Error connecting");
|
||||||
LogHelper.debug("Connect to %s:%d",address,port);
|
LogHelper.debug("Connect to %s",address);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static {
|
static {
|
||||||
if(Launcher.getConfig().nettyPort != 0)
|
if(Launcher.getConfig().nettyPort != 0)
|
||||||
initWebSockets(Launcher.getConfig().address.getHostName(),Launcher.getConfig().nettyPort);
|
initWebSockets(Launcher.getConfig().nettyAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ public static AutogenConfig getAutogenConfig() {
|
||||||
// Instance
|
// Instance
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public InetSocketAddress address;
|
public InetSocketAddress address;
|
||||||
|
public String nettyAddress;
|
||||||
public int nettyPort;
|
public int nettyPort;
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public final String projectname;
|
public final String projectname;
|
||||||
|
@ -42,6 +43,7 @@ public static AutogenConfig getAutogenConfig() {
|
||||||
public final boolean isUsingWrapper;
|
public final boolean isUsingWrapper;
|
||||||
public final boolean isDownloadJava;
|
public final boolean isDownloadJava;
|
||||||
public final boolean isWarningMissArchJava;
|
public final boolean isWarningMissArchJava;
|
||||||
|
public final boolean isNettyEnabled;
|
||||||
|
|
||||||
public final String guardLicenseName;
|
public final String guardLicenseName;
|
||||||
public final String guardLicenseKey;
|
public final String guardLicenseKey;
|
||||||
|
@ -63,6 +65,8 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException
|
||||||
guardLicenseKey = config.guardLicenseKey;
|
guardLicenseKey = config.guardLicenseKey;
|
||||||
guardLicenseName = config.guardLicenseName;
|
guardLicenseName = config.guardLicenseName;
|
||||||
nettyPort = config.nettyPort;
|
nettyPort = config.nettyPort;
|
||||||
|
nettyAddress = config.nettyAddress;
|
||||||
|
isNettyEnabled = config.isNettyEnabled;
|
||||||
LauncherEnvironment env;
|
LauncherEnvironment env;
|
||||||
if (config.env == 0) env = LauncherEnvironment.DEV;
|
if (config.env == 0) env = LauncherEnvironment.DEV;
|
||||||
else if (config.env == 1) env = LauncherEnvironment.DEBUG;
|
else if (config.env == 1) env = LauncherEnvironment.DEBUG;
|
||||||
|
@ -99,6 +103,7 @@ public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map<Stri
|
||||||
isUsingWrapper = true;
|
isUsingWrapper = true;
|
||||||
isDownloadJava = false;
|
isDownloadJava = false;
|
||||||
isWarningMissArchJava = true;
|
isWarningMissArchJava = true;
|
||||||
|
isNettyEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -114,6 +119,7 @@ public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map<Stri
|
||||||
isUsingWrapper = true;
|
isUsingWrapper = true;
|
||||||
isDownloadJava = false;
|
isDownloadJava = false;
|
||||||
isWarningMissArchJava = true;
|
isWarningMissArchJava = true;
|
||||||
|
isNettyEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue