mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] Управление лаунчсервером из лаунчера
This commit is contained in:
parent
0e9d8b4ca7
commit
ea202eee5b
6 changed files with 93 additions and 3 deletions
|
@ -0,0 +1,24 @@
|
||||||
|
package ru.gravit.launcher.console.admin;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.events.request.ExecCommandRequestEvent;
|
||||||
|
import ru.gravit.launcher.request.admin.ExecCommandRequest;
|
||||||
|
import ru.gravit.utils.command.Command;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
public class ExecCommand extends Command {
|
||||||
|
@Override
|
||||||
|
public String getArgsDescription() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsageDescription() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invoke(String... args) throws Exception {
|
||||||
|
ExecCommandRequestEvent request = new ExecCommandRequest(String.join(" ", args)).request();
|
||||||
|
if(!request.success) LogHelper.error("Error executing command");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package ru.gravit.launcher.console.admin;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.LauncherNetworkAPI;
|
||||||
|
import ru.gravit.launcher.events.request.LogEvent;
|
||||||
|
import ru.gravit.launcher.request.Request;
|
||||||
|
import ru.gravit.launcher.request.websockets.RequestInterface;
|
||||||
|
import ru.gravit.utils.command.Command;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
public class LogListenerCommand extends Command {
|
||||||
|
public class LogListenerRequest implements RequestInterface
|
||||||
|
{
|
||||||
|
@LauncherNetworkAPI
|
||||||
|
public LogHelper.OutputTypes outputType;
|
||||||
|
|
||||||
|
public LogListenerRequest(LogHelper.OutputTypes outputType) {
|
||||||
|
this.outputType = outputType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "addLogListener";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String getArgsDescription() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsageDescription() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invoke(String... args) throws Exception {
|
||||||
|
LogHelper.info("Send log listener request");
|
||||||
|
Request.service.sendObject(new LogListenerRequest(LogHelper.JANSI ? LogHelper.OutputTypes.JANSI : LogHelper.OutputTypes.PLAIN));
|
||||||
|
LogHelper.info("Add log handler");
|
||||||
|
Request.service.registerHandler((result) -> {
|
||||||
|
if(result instanceof LogEvent)
|
||||||
|
{
|
||||||
|
LogHelper.rawLog(() -> {
|
||||||
|
return ((LogEvent) result).string;
|
||||||
|
}, () -> {
|
||||||
|
return ((LogEvent) result).string;
|
||||||
|
}, () -> {
|
||||||
|
return ((LogEvent) result).string;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,8 @@
|
||||||
package ru.gravit.launcher.managers;
|
package ru.gravit.launcher.managers;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.console.admin.ExecCommand;
|
||||||
|
import ru.gravit.launcher.console.admin.LogListenerCommand;
|
||||||
|
import ru.gravit.utils.command.BaseCommandCategory;
|
||||||
import ru.gravit.utils.command.basic.ClearCommand;
|
import ru.gravit.utils.command.basic.ClearCommand;
|
||||||
import ru.gravit.utils.command.basic.DebugCommand;
|
import ru.gravit.utils.command.basic.DebugCommand;
|
||||||
import ru.gravit.utils.command.basic.GCCommand;
|
import ru.gravit.utils.command.basic.GCCommand;
|
||||||
|
@ -48,5 +51,9 @@ public static boolean checkUnlockKey(String key)
|
||||||
public static void unlock()
|
public static void unlock()
|
||||||
{
|
{
|
||||||
handler.registerCommand("debug", new DebugCommand());
|
handler.registerCommand("debug", new DebugCommand());
|
||||||
|
BaseCommandCategory admin = new BaseCommandCategory();
|
||||||
|
admin.registerCommand("exec", new ExecCommand());
|
||||||
|
admin.registerCommand("logListen", new LogListenerCommand());
|
||||||
|
handler.registerCategory(new CommandHandler.Category(admin, "admin", "Server admin commands"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,6 @@ public ExecCommandRequest(String cmd) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return "execCmd";
|
return "cmdExec";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ public void registerResults() {
|
||||||
registerResult("getSecureToken", GetSecureTokenRequestEvent.class);
|
registerResult("getSecureToken", GetSecureTokenRequestEvent.class);
|
||||||
registerResult("verifySecureToken", VerifySecureTokenRequestEvent.class);
|
registerResult("verifySecureToken", VerifySecureTokenRequestEvent.class);
|
||||||
registerResult("log", LogEvent.class);
|
registerResult("log", LogEvent.class);
|
||||||
registerResult("execCmd", ExecCommandRequestEvent.class);
|
registerResult("cmdExec", ExecCommandRequestEvent.class);
|
||||||
registerResult("getAvailabilityAuth", GetAvailabilityAuthRequestEvent.class);
|
registerResult("getAvailabilityAuth", GetAvailabilityAuthRequestEvent.class);
|
||||||
registerResult("exception", ExceptionEvent.class);
|
registerResult("exception", ExceptionEvent.class);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import org.fusesource.jansi.AnsiConsole;
|
import org.fusesource.jansi.AnsiConsole;
|
||||||
import org.fusesource.jansi.AnsiOutputStream;
|
import org.fusesource.jansi.AnsiOutputStream;
|
||||||
import ru.gravit.launcher.LauncherAPI;
|
import ru.gravit.launcher.LauncherAPI;
|
||||||
|
import ru.gravit.launcher.LauncherNetworkAPI;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -47,7 +48,12 @@ public OutputEnity(Output output, OutputTypes type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum OutputTypes {
|
public enum OutputTypes {
|
||||||
PLAIN, JANSI, HTML
|
@LauncherNetworkAPI
|
||||||
|
PLAIN,
|
||||||
|
@LauncherNetworkAPI
|
||||||
|
JANSI,
|
||||||
|
@LauncherNetworkAPI
|
||||||
|
HTML
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Set<OutputEnity> OUTPUTS = Collections.newSetFromMap(new ConcurrentHashMap<>(2));
|
private static final Set<OutputEnity> OUTPUTS = Collections.newSetFromMap(new ConcurrentHashMap<>(2));
|
||||||
|
|
Loading…
Reference in a new issue