Merge branch 'dev' of github.com:GravitLauncher/Launcher into dev

This commit is contained in:
Zaxar163 2020-03-01 10:46:26 +01:00
commit 1131f56e57
No known key found for this signature in database
GPG key ID: 1FE4F2E1F053831B
11 changed files with 193 additions and 13 deletions

View file

@ -63,7 +63,7 @@ public void invoke(String... args) throws Exception {
public abstract void ban(List<HWID> hwid) throws HWIDException;
public void check(HWID hwid, String username) throws HWIDException {
if (hwid.isNull()) return;
if (hwid == null || hwid.isNull()) return;
check0(hwid, username);
}

View file

@ -40,6 +40,11 @@ public Client getOrNewClient(long session) {
return clientSet.computeIfAbsent(session, Client::new);
}
public Client removeClient(long session)
{
return clientSet.remove(session);
}
public void updateClient(long session) {
Client c = clientSet.get(session);

View file

@ -66,6 +66,11 @@ public WebSocketService(ChannelGroup channels, LaunchServer server) {
public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) {
String request = frame.text();
WebSocketServerResponse response = gson.fromJson(request, WebSocketServerResponse.class);
if(response == null)
{
RequestEvent event= new ErrorRequestEvent("This type of request is not supported");
sendObject(ctx, event);
}
process(ctx, response, client, ip);
}
@ -123,6 +128,7 @@ public static void registerResponses() {
providers.register("getAvailabilityAuth", GetAvailabilityAuthResponse.class);
providers.register("register", RegisterResponse.class);
providers.register("setPassword", SetPasswordResponse.class);
providers.register("exit", ExitResponse.class);
}
public void sendObject(ChannelHandlerContext ctx, Object obj) {

View file

@ -0,0 +1,90 @@
package pro.gravit.launchserver.socket.response.auth;
import io.netty.channel.ChannelHandlerContext;
import pro.gravit.launcher.events.RequestEvent;
import pro.gravit.launcher.events.request.ExitRequestEvent;
import pro.gravit.launchserver.socket.Client;
import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler;
import pro.gravit.launchserver.socket.response.SimpleResponse;
public class ExitResponse extends SimpleResponse {
public boolean exitAll;
public String username;
@Override
public String getType() {
return "exit";
}
@Override
public void execute(ChannelHandlerContext ctx, Client client) throws Exception {
if(username != null && ( !client.isAuth || client.permissions == null || !client.permissions.canAdmin ))
{
sendError("Permissions denied");
return;
}
if(username == null)
{
if(client.session == 0 && exitAll)
{
sendError("Session invalid");
return;
}
WebSocketFrameHandler handler = ctx.pipeline().get(WebSocketFrameHandler.class);
if(handler == null)
{
sendError("Exit internal error");
return;
}
Client newClient = new Client(0);
newClient.isSecure = client.isSecure;
newClient.checkSign = client.checkSign;
handler.setClient(newClient);
if(client.session != 0) server.sessionManager.removeClient(client.session);
if(exitAll)
{
service.channels.forEach((channel) -> {
if(channel == null || channel.pipeline() == null) return;
WebSocketFrameHandler wsHandler = channel.pipeline().get(WebSocketFrameHandler.class);
if(wsHandler == null || wsHandler == handler) return;
Client chClient = wsHandler.getClient();
if(client.isAuth && client.username != null)
{
if(!chClient.isAuth || !client.username.equals(chClient.username)) return;
}
else
{
if(chClient.session != client.session) return;
}
Client newCusClient = new Client(0);
newCusClient.isSecure = chClient.isSecure;
newCusClient.checkSign = chClient.checkSign;
wsHandler.setClient(newCusClient);
if(chClient.session != 0) server.sessionManager.removeClient(chClient.session);
ExitRequestEvent event = new ExitRequestEvent(ExitRequestEvent.ExitReason.SERVER);
event.requestUUID = RequestEvent.eventUUID;
wsHandler.service.sendObject(channel, event);
});
}
sendResult(new ExitRequestEvent(ExitRequestEvent.ExitReason.CLIENT));
}
else
{
service.channels.forEach((channel -> {
if(channel == null || channel.pipeline() == null) return;
WebSocketFrameHandler wsHandler = channel.pipeline().get(WebSocketFrameHandler.class);
if(wsHandler == null) return;
Client chClient = wsHandler.getClient();
if(!chClient.isAuth || !username.equals(chClient.username)) return;
Client newCusClient = new Client(0);
newCusClient.isSecure = chClient.isSecure;
newCusClient.checkSign = chClient.checkSign;
wsHandler.setClient(newCusClient);
if(chClient.session != 0) server.sessionManager.removeClient(chClient.session);
ExitRequestEvent event = new ExitRequestEvent(ExitRequestEvent.ExitReason.SERVER);
event.requestUUID = RequestEvent.eventUUID;
wsHandler.service.sendObject(channel, event);
}));
sendResult(new ExitRequestEvent(ExitRequestEvent.ExitReason.NO_EXIT));
}
}
}

View file

@ -1,6 +1,5 @@
package pro.gravit.launcher;
import pro.gravit.launcher.api.SystemService;
import pro.gravit.launcher.client.*;
import pro.gravit.launcher.client.events.ClientEngineInitPhase;
import pro.gravit.launcher.client.events.ClientExitPhase;
@ -59,8 +58,13 @@ public static void checkClass(Class<?> clazz) throws SecurityException {
public static void exitLauncher(int code)
{
modulesManager.invokeEvent(new ClientExitPhase(code));
try {
System.exit(code);
} catch (Throwable e) //Forge Security Manager?
{
NativeJVMHalt.haltA(code);
}
}
public static void main(String... args) throws Throwable {
JVMHelper.checkStackTrace(LauncherEngine.class);
@ -93,7 +97,7 @@ public static void main(String... args) throws Throwable {
LogHelper.debug("Launcher started in %dms", endTime - startTime);
//Request.service.close();
//FunctionalBridge.close();
SystemService.exit(0);
LauncherEngine.exitLauncher(0);
}
public static void initGson(ClientModuleManager modulesManager) {

View file

@ -301,7 +301,7 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl
try {
mainMethod.invokeWithArguments((Object) args.toArray(new String[0]));
} finally {
SystemService.exit(0);
LauncherEngine.exitLauncher(0);
}
}

View file

@ -2,6 +2,7 @@
import pro.gravit.launcher.patches.FMLPatcher;
import pro.gravit.utils.helper.JVMHelper;
import pro.gravit.utils.helper.LogHelper;
import javax.swing.*;
import java.awt.event.WindowEvent;
@ -22,23 +23,30 @@ private boolean aaabBooleanC_D() {
}
public static void haltA(int code) {
Throwable[] th = new Throwable[3];
NativeJVMHalt halt = new NativeJVMHalt(code);
try {
JVMHelper.RUNTIME.exit(code);
} catch (Throwable ignored) {
} catch (Throwable exitExc) {
th[0] = exitExc;
try {
new WindowShutdown();
} catch (Throwable ignored1) {
} catch (Throwable windowExc) {
th[1] = windowExc;
}
}
try {
FMLPatcher.exit(code);
} catch (Throwable ignored) {
} catch (Throwable fmlExc) {
th[2] = fmlExc;
}
for(Throwable t : th)
{
if(t != null) LogHelper.error(t);
}
halt.aaabbb38C_D();
boolean a = halt.aaabBooleanC_D();
System.out.println(a);
halt.aaabbb38C_D();
}

View file

@ -0,0 +1,20 @@
package pro.gravit.launcher.events.request;
import pro.gravit.launcher.events.RequestEvent;
public class ExitRequestEvent extends RequestEvent {
public enum ExitReason
{
SERVER, CLIENT, TIMEOUT, NO_EXIT
}
public final ExitReason reason;
public ExitRequestEvent(ExitReason reason) {
this.reason = reason;
}
@Override
public String getType() {
return "exit";
}
}

View file

@ -0,0 +1,29 @@
package pro.gravit.launcher.request.auth;
import pro.gravit.launcher.events.request.ExitRequestEvent;
import pro.gravit.launcher.request.Request;
public class ExitRequest extends Request<ExitRequestEvent> {
public final boolean exitAll;
public final String username;
public ExitRequest() {
this.exitAll = false;
this.username = null;
}
public ExitRequest(boolean exitAll) {
this.exitAll = exitAll;
this.username = null;
}
public ExitRequest(boolean exitAll, String username) {
this.exitAll = exitAll;
this.username = username;
}
@Override
public String getType() {
return "exit";
}
}

View file

@ -107,6 +107,7 @@ public void registerResults() {
results.register("setpassword", SetPasswordRequestEvent.class);
results.register("notification", NotificationEvent.class);
results.register("signal", SignalEvent.class);
results.register("exit", ExitRequestEvent.class);
}
public void waitIfNotConnected() {

View file

@ -15,24 +15,41 @@ public class UniversalJsonAdapter<R> implements JsonSerializer<R>, JsonDeseriali
public final ProviderMap<R> providerMap;
public final String name;
public final String PROP_NAME;
public final boolean printErrorIfUnknownType;
public UniversalJsonAdapter(ProviderMap<R> providerMap) {
this.providerMap = providerMap;
this.name = providerMap.getName();
this.PROP_NAME = "type";
printErrorIfUnknownType = true;
}
public UniversalJsonAdapter(ProviderMap<R> providerMap, String PROP_NAME) {
this.providerMap = providerMap;
this.name = providerMap.getName();
this.PROP_NAME = PROP_NAME;
printErrorIfUnknownType = true;
}
public UniversalJsonAdapter(ProviderMap<R> providerMap, String name, String PROP_NAME, boolean printErrorIfUnknownType) {
this.providerMap = providerMap;
this.name = name;
this.PROP_NAME = PROP_NAME;
this.printErrorIfUnknownType = printErrorIfUnknownType;
}
public UniversalJsonAdapter(ProviderMap<R> providerMap, String name, boolean printErrorIfUnknownType) {
this.providerMap = providerMap;
this.name = name;
this.PROP_NAME = "type";
this.printErrorIfUnknownType = printErrorIfUnknownType;
}
public R deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
Class<? extends R> cls = providerMap.getClass(typename);
if (cls == null) {
LogHelper.error("%s %s not found", name, typename);
if(printErrorIfUnknownType) LogHelper.error("%s %s not found", name, typename);
return null;
}
return context.deserialize(json, cls);
@ -48,9 +65,9 @@ public JsonElement serialize(R src, Type typeOfSrc, JsonSerializationContext con
}
if(classPath == null)
{
LogHelper.warning("Class %s type null", src.getClass());
if(printErrorIfUnknownType) LogHelper.warning("Class %s type null", src.getClass());
}
jo.add(PROP_NAME, new JsonPrimitive(classPath));
else jo.add(PROP_NAME, new JsonPrimitive(classPath));
return jo;
}