Zond: цветной текст
This commit is contained in:
@@ -12,6 +12,7 @@ import org.apache.commons.exec.CommandLine;
|
|||||||
import org.apache.commons.exec.ExecuteException;
|
import org.apache.commons.exec.ExecuteException;
|
||||||
import org.apache.commons.exec.ExecuteWatchdog;
|
import org.apache.commons.exec.ExecuteWatchdog;
|
||||||
import org.apache.commons.exec.Executor;
|
import org.apache.commons.exec.Executor;
|
||||||
|
import org.fusesource.jansi.Ansi;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -30,6 +31,12 @@ public class ZondCommandHandler implements CommandHandler {
|
|||||||
this.proxyStdIn = proxyStdIn;
|
this.proxyStdIn = proxyStdIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String zondColored(String string) {
|
||||||
|
return Ansi.ansi().bg(Ansi.Color.WHITE).fg(Ansi.Color.RED).a("[Zond]")
|
||||||
|
.reset().fg(Ansi.Color.RED).a(' ').a(string)
|
||||||
|
.reset().toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(String commandLine) {
|
public void handle(String commandLine) {
|
||||||
if (commandLine.startsWith(":")) {
|
if (commandLine.startsWith(":")) {
|
||||||
@@ -54,10 +61,10 @@ public class ZondCommandHandler implements CommandHandler {
|
|||||||
} else if (line.equalsIgnoreCase("connect")) {
|
} else if (line.equalsIgnoreCase("connect")) {
|
||||||
Connector.getInstance().startReconnect();
|
Connector.getInstance().startReconnect();
|
||||||
} else if (line.equalsIgnoreCase("disconnect")) {
|
} else if (line.equalsIgnoreCase("disconnect")) {
|
||||||
Shell.getInstance().getOutput().println("Disconnect");
|
Shell.getInstance().getOutput().println(zondColored("Disconnect"));
|
||||||
Connector.getInstance().shutdown();
|
Connector.getInstance().shutdown();
|
||||||
} else if (line.equalsIgnoreCase("reload")) {
|
} else if (line.equalsIgnoreCase("reload")) {
|
||||||
Shell.getInstance().getOutput().println("Reload config");
|
Shell.getInstance().getOutput().println(zondColored("Reload config"));
|
||||||
try {
|
try {
|
||||||
Config.getInstance().load();
|
Config.getInstance().load();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -104,8 +111,8 @@ public class ZondCommandHandler implements CommandHandler {
|
|||||||
|
|
||||||
deadTime = (System.currentTimeMillis()/1000) + (delay*1000);
|
deadTime = (System.currentTimeMillis()/1000) + (delay*1000);
|
||||||
pingMonitor.start(() -> {
|
pingMonitor.start(() -> {
|
||||||
Shell.getInstance().getOutput().println("[!] Process - zobie?");
|
Shell.getInstance().getOutput().println(zondColored("[!] Process - zobie?"));
|
||||||
Shell.getInstance().getOutput().println("[!] Force shutdown process.");
|
Shell.getInstance().getOutput().println(zondColored("[!] Force shutdown process."));
|
||||||
flagForceRestartProcess = true;
|
flagForceRestartProcess = true;
|
||||||
killProcess();
|
killProcess();
|
||||||
});
|
});
|
||||||
@@ -113,7 +120,7 @@ public class ZondCommandHandler implements CommandHandler {
|
|||||||
} catch (ExecuteException e) {
|
} catch (ExecuteException e) {
|
||||||
code = e.getExitValue();
|
code = e.getExitValue();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Shell.getInstance().getOutput().println("[!] Exception message: " + e.getMessage());
|
Shell.getInstance().getOutput().println(zondColored("[!] Exception message: " + e.getMessage()));
|
||||||
code = -99;
|
code = -99;
|
||||||
}
|
}
|
||||||
long currTime = System.currentTimeMillis()/1000;
|
long currTime = System.currentTimeMillis()/1000;
|
||||||
@@ -121,7 +128,7 @@ public class ZondCommandHandler implements CommandHandler {
|
|||||||
server.shutdown();
|
server.shutdown();
|
||||||
pingMonitor.stop();
|
pingMonitor.stop();
|
||||||
server = null;
|
server = null;
|
||||||
Shell.getInstance().getOutput().println("[i] Process finished. Code: " + code);
|
Shell.getInstance().getOutput().println(zondColored("[i] Process finished. Code: " + code));
|
||||||
|
|
||||||
if (pingMonitor.isCorrectShutdown()) {
|
if (pingMonitor.isCorrectShutdown()) {
|
||||||
flagForceRestartProcess = false;
|
flagForceRestartProcess = false;
|
||||||
@@ -129,16 +136,16 @@ public class ZondCommandHandler implements CommandHandler {
|
|||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if (currTime <= deadTime && !flagManualKill) {
|
if (currTime <= deadTime && !flagManualKill) {
|
||||||
Shell.getInstance().getOutput().println("[!] Premature end process.");
|
Shell.getInstance().getOutput().println(zondColored("[!] Premature end process."));
|
||||||
_try++;
|
_try++;
|
||||||
if (_try < 2) {
|
if (_try < 2) {
|
||||||
Shell.getInstance().getOutput().println("[!] Try start process again...");
|
Shell.getInstance().getOutput().println(zondColored("[!] Try start process again..."));
|
||||||
}
|
}
|
||||||
} else if (flagForceRestartProcess) {
|
} else if (flagForceRestartProcess) {
|
||||||
_try = 0;
|
_try = 0;
|
||||||
flagForceRestartProcess = false;
|
flagForceRestartProcess = false;
|
||||||
} else if (code != 0 && code != -99 && !flagManualKill) {
|
} else if (code != 0 && code != -99 && !flagManualKill) {
|
||||||
Shell.getInstance().getOutput().println("[!] Try start process again...");
|
Shell.getInstance().getOutput().println(zondColored("[!] Try start process again..."));
|
||||||
_try = 0;
|
_try = 0;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@@ -147,7 +154,7 @@ public class ZondCommandHandler implements CommandHandler {
|
|||||||
} while (_try < 2);
|
} while (_try < 2);
|
||||||
|
|
||||||
if (_try == 2) {
|
if (_try == 2) {
|
||||||
Shell.getInstance().getOutput().println("[!] Discovered the problem when starting the process");
|
Shell.getInstance().getOutput().println(zondColored("[!] Discovered the problem when starting the process"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
threadExec = new Thread(task, "Zond Exec");
|
threadExec = new Thread(task, "Zond Exec");
|
||||||
|
|||||||
Reference in New Issue
Block a user