mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Восстановлена работа LaunchServerConsole
This commit is contained in:
parent
7869618d51
commit
31b9d43a7f
10 changed files with 130 additions and 38 deletions
|
@ -18,11 +18,7 @@ public String getType() {
|
|||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) {
|
||||
if (!client.isAuth) {
|
||||
service.sendObject(ctx, new ErrorRequestEvent("Access denied"));
|
||||
return;
|
||||
}
|
||||
if (!client.permissions.canAdmin) {
|
||||
if (!client.isAuth || !client.permissions.canAdmin) {
|
||||
service.sendObject(ctx, new ErrorRequestEvent("Access denied"));
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
import ru.gravit.launcher.server.ServerWrapper;
|
||||
import ru.gravit.utils.command.CommandHandler;
|
||||
import ru.gravit.utils.command.JLineCommandHandler;
|
||||
import ru.gravit.utils.command.StdCommandHandler;
|
||||
import ru.gravit.utils.command.basic.HelpCommand;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -20,13 +23,21 @@ public static void main(String[] args) throws IOException {
|
|||
Class.forName("jline.Terminal");
|
||||
|
||||
// JLine2 available
|
||||
commandHandler = new RemoteJLineCommandHandler();
|
||||
commandHandler = new JLineCommandHandler();
|
||||
LogHelper.info("JLine2 terminal enabled");
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
commandHandler = new RemoteStdCommandHandler(true);
|
||||
commandHandler = new StdCommandHandler(true);
|
||||
LogHelper.warning("JLine2 isn't in classpath, using std");
|
||||
}
|
||||
registerCommands();
|
||||
LogHelper.info("CommandHandler started. Use 'exit' to exit this console");
|
||||
commandHandler.run();
|
||||
}
|
||||
public static void registerCommands()
|
||||
{
|
||||
commandHandler.registerCommand("help", new HelpCommand(commandHandler));
|
||||
commandHandler.registerCommand("exit", new ExitCommand());
|
||||
commandHandler.registerCommand("logListener", new LogListenerCommand());
|
||||
commandHandler.registerCommand("exec", new ExecCommand());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package ru.gravit.launchserver.console;
|
||||
|
||||
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(" ")).request();
|
||||
if(!request.success) LogHelper.error("Error executing command");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package ru.gravit.launchserver.console;
|
||||
|
||||
import ru.gravit.utils.command.Command;
|
||||
|
||||
public class ExitCommand extends Command {
|
||||
public ExitCommand() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgsDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsageDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package ru.gravit.launchserver.console;
|
||||
|
||||
import ru.gravit.launcher.events.request.LogEvent;
|
||||
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
|
||||
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
|
||||
{
|
||||
@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");
|
||||
LegacyRequestBridge.service.sendObject(new LogListenerRequest());
|
||||
LogHelper.info("Add log handler");
|
||||
LegacyRequestBridge.service.registerHandler((result) -> {
|
||||
if(result instanceof LogEvent)
|
||||
{
|
||||
System.out.println(((LogEvent) result).string);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package ru.gravit.launchserver.console;
|
||||
|
||||
import ru.gravit.utils.command.JLineCommandHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class RemoteJLineCommandHandler extends JLineCommandHandler {
|
||||
public RemoteJLineCommandHandler() throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eval(String line, boolean bell) {
|
||||
if (line.equals("exit")) System.exit(0);
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package ru.gravit.launchserver.console;
|
||||
|
||||
import ru.gravit.utils.command.StdCommandHandler;
|
||||
|
||||
public class RemoteStdCommandHandler extends StdCommandHandler {
|
||||
public RemoteStdCommandHandler(boolean readCommands) {
|
||||
super(readCommands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eval(String line, boolean bell) {
|
||||
if (line.equals("exit")) System.exit(0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package ru.gravit.launcher.request.admin;
|
||||
|
||||
import ru.gravit.launcher.LauncherAPI;
|
||||
import ru.gravit.launcher.events.request.ExecCommandRequestEvent;
|
||||
import ru.gravit.launcher.request.Request;
|
||||
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
|
||||
import ru.gravit.launcher.request.websockets.RequestInterface;
|
||||
|
||||
public class ExecCommandRequest extends Request<ExecCommandRequestEvent> implements RequestInterface {
|
||||
@LauncherAPI
|
||||
public String cmd;
|
||||
|
||||
public ExecCommandRequest(String cmd) {
|
||||
this.cmd = cmd;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExecCommandRequestEvent requestDo() throws Exception {
|
||||
return (ExecCommandRequestEvent) LegacyRequestBridge.sendRequest(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "execCmd";
|
||||
}
|
||||
}
|
|
@ -113,6 +113,8 @@ public void registerResults() {
|
|||
registerResult("restoreSession", RestoreSessionRequestEvent.class);
|
||||
registerResult("getSecureToken", GetSecureTokenRequestEvent.class);
|
||||
registerResult("verifySecureToken", VerifySecureTokenRequestEvent.class);
|
||||
registerResult("log", LogEvent.class);
|
||||
registerResult("execCmd", ExecCommandRequestEvent.class);
|
||||
}
|
||||
|
||||
public void registerHandler(EventHandler eventHandler) {
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
public class ExecCommandRequestEvent implements ResultInterface {
|
||||
@Override
|
||||
public String getType() {
|
||||
return "execCmd";
|
||||
return "cmdExec";
|
||||
}
|
||||
@LauncherNetworkAPI
|
||||
boolean success;
|
||||
public boolean success;
|
||||
|
||||
public ExecCommandRequestEvent(boolean success) {
|
||||
this.success = success;
|
||||
|
|
Loading…
Reference in a new issue