mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] LaunchServerConsole
This commit is contained in:
parent
ec5ef7af4f
commit
57231d948d
8 changed files with 113 additions and 9 deletions
20
LaunchServerConsole/build.gradle
Normal file
20
LaunchServerConsole/build.gradle
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
String mainClassName = "ru.gravit.launchserver.console.ConsoleMain"
|
||||||
|
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url "http://repo.spring.io/plugins-release/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceCompatibility = '1.8'
|
||||||
|
targetCompatibility = '1.8'
|
||||||
|
|
||||||
|
jar {
|
||||||
|
from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
|
||||||
|
manifest.attributes("Main-Class": mainClassName)
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly project(':ServerWrapper')
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package ru.gravit.launchserver.console;
|
||||||
|
|
||||||
|
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.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ConsoleMain {
|
||||||
|
public static CommandHandler commandHandler;
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
if(ServerWrapper.config == null)
|
||||||
|
{
|
||||||
|
LogHelper.warning("ServerWrapper not found");
|
||||||
|
}
|
||||||
|
if(!ServerWrapper.permissions.canAdmin)
|
||||||
|
{
|
||||||
|
LogHelper.warning("Permission canAdmin not found");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Class.forName("jline.Terminal");
|
||||||
|
|
||||||
|
// JLine2 available
|
||||||
|
commandHandler = new RemoteJLineCommandHandler();
|
||||||
|
LogHelper.info("JLine2 terminal enabled");
|
||||||
|
} catch (ClassNotFoundException ignored) {
|
||||||
|
commandHandler = new RemoteStdCommandHandler(true);
|
||||||
|
LogHelper.warning("JLine2 isn't in classpath, using std");
|
||||||
|
}
|
||||||
|
LogHelper.info("CommandHandler started. Use 'exit' to exit this console");
|
||||||
|
commandHandler.run();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package ru.gravit.launchserver.console;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.request.admin.ExecCommandRequest;
|
||||||
|
import ru.gravit.utils.command.Command;
|
||||||
|
import ru.gravit.utils.command.JLineCommandHandler;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
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);
|
||||||
|
ExecCommandRequest request = new ExecCommandRequest(System.out::println, line);
|
||||||
|
try {
|
||||||
|
request.request();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogHelper.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package ru.gravit.launchserver.console;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.request.admin.ExecCommandRequest;
|
||||||
|
import ru.gravit.utils.command.Command;
|
||||||
|
import ru.gravit.utils.command.CommandHandler;
|
||||||
|
import ru.gravit.utils.command.StdCommandHandler;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
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);
|
||||||
|
ExecCommandRequest request = new ExecCommandRequest(System.out::println, line);
|
||||||
|
try {
|
||||||
|
request.request();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogHelper.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,7 +16,7 @@
|
||||||
public abstract class CommandHandler implements Runnable {
|
public abstract class CommandHandler implements Runnable {
|
||||||
private final Map<String, Command> commands = new ConcurrentHashMap<>(32);
|
private final Map<String, Command> commands = new ConcurrentHashMap<>(32);
|
||||||
|
|
||||||
public final void eval(String line, boolean bell) {
|
public void eval(String line, boolean bell) {
|
||||||
LogHelper.info("Command '%s'", line);
|
LogHelper.info("Command '%s'", line);
|
||||||
|
|
||||||
// Parse line to tokens
|
// Parse line to tokens
|
||||||
|
@ -33,7 +33,7 @@ public final void eval(String line, boolean bell) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public final void eval(String[] args, boolean bell) {
|
public void eval(String[] args, boolean bell) {
|
||||||
if (args.length == 0)
|
if (args.length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public final void eval(String[] args, boolean bell) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public final Command lookup(String name) throws CommandException {
|
public Command lookup(String name) throws CommandException {
|
||||||
Command command = commands.get(name);
|
Command command = commands.get(name);
|
||||||
if (command == null)
|
if (command == null)
|
||||||
throw new CommandException(String.format("Unknown command: '%s'", name));
|
throw new CommandException(String.format("Unknown command: '%s'", name));
|
||||||
|
@ -72,14 +72,14 @@ private void readLoop() throws IOException {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public final void registerCommand(String name, Command command) {
|
public void registerCommand(String name, Command command) {
|
||||||
VerifyHelper.verifyIDName(name);
|
VerifyHelper.verifyIDName(name);
|
||||||
VerifyHelper.putIfAbsent(commands, name, Objects.requireNonNull(command, "command"),
|
VerifyHelper.putIfAbsent(commands, name, Objects.requireNonNull(command, "command"),
|
||||||
String.format("Command has been already registered: '%s'", name));
|
String.format("Command has been already registered: '%s'", name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
readLoop();
|
readLoop();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -95,7 +95,7 @@ public final void run() {
|
||||||
public abstract void clear() throws IOException;
|
public abstract void clear() throws IOException;
|
||||||
|
|
||||||
|
|
||||||
public final Map<String, Command> commandsMap() {
|
public Map<String, Command> commandsMap() {
|
||||||
return Collections.unmodifiableMap(commands);
|
return Collections.unmodifiableMap(commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class JLineCommandHandler extends CommandHandler {
|
public class JLineCommandHandler extends CommandHandler {
|
||||||
private final class JLineOutput implements Output {
|
private final class JLineOutput implements Output {
|
||||||
@Override
|
@Override
|
||||||
public void println(String message) {
|
public void println(String message) {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class StdCommandHandler extends CommandHandler {
|
public class StdCommandHandler extends CommandHandler {
|
||||||
private final BufferedReader reader;
|
private final BufferedReader reader;
|
||||||
|
|
||||||
public StdCommandHandler(boolean readCommands) {
|
public StdCommandHandler(boolean readCommands) {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
include 'LauncherAPI'
|
include 'LauncherAPI'
|
||||||
include 'ServerWrapper'
|
include 'ServerWrapper'
|
||||||
include 'LaunchServer'
|
include 'LaunchServer'
|
||||||
|
include 'LaunchServerConsole'
|
||||||
include 'modules'
|
include 'modules'
|
||||||
file('modules').eachDir { sub ->
|
file('modules').eachDir { sub ->
|
||||||
if (sub.name.endsWith('_module')) include 'modules:' + sub.name
|
if (sub.name.endsWith('_module')) include 'modules:' + sub.name
|
||||||
|
|
Loading…
Reference in a new issue