From 8f6319d979ec6b3b17f99202b172dc0208cac6fe Mon Sep 17 00:00:00 2001 From: Haarolean Date: Sun, 6 May 2018 19:42:39 +0300 Subject: [PATCH] Fixed #10 Fixed #6 once more Added exit command alias --- .../ryanmichela/sshd/ConsoleShellFactory.java | 9 ++++++--- .../ryanmichela/sshd/FlushyOutputStream.java | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java b/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java index ef9b3c6..2e9ab32 100644 --- a/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java +++ b/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java @@ -29,6 +29,7 @@ public class ConsoleShellFactory implements Factory { } public static class ConsoleShell implements Command, Runnable { + private InputStream in; private OutputStream out; private OutputStream err; @@ -101,14 +102,16 @@ public class ConsoleShellFactory implements Factory { while (true) { String command = consoleReader.readLine("\r>", null); if (command == null) continue; - if (command.equals("exit")) break; + if (command.equals("exit") || command.equals("quit")) break; Bukkit.getScheduler().runTask(SshdPlugin.instance, () -> { - if (SshdPlugin.instance.getConfig().getString("mode").equals("RPC") && command.startsWith("rpc")) { + if (SshdPlugin.instance.getConfig().getString("mode").equals("RPC") && + command.startsWith("rpc")) { //NO ECHO NO PREAMBLE AND SHIT String cmd = command.substring("rpc".length() + 1, command.length()); Bukkit.dispatchCommand(sshdCommandSender, cmd); } else { - SshdPlugin.instance.getLogger().info("<" + environment.getEnv().get(Environment.ENV_USER) + "> " + command); + SshdPlugin.instance.getLogger() + .info("<" + environment.getEnv().get(Environment.ENV_USER) + "> " + command); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); } }); diff --git a/src/main/java/com/ryanmichela/sshd/FlushyOutputStream.java b/src/main/java/com/ryanmichela/sshd/FlushyOutputStream.java index b79a5f8..be823bf 100644 --- a/src/main/java/com/ryanmichela/sshd/FlushyOutputStream.java +++ b/src/main/java/com/ryanmichela/sshd/FlushyOutputStream.java @@ -1,5 +1,7 @@ package com.ryanmichela.sshd; +import org.apache.sshd.common.SshException; + import java.io.IOException; import java.io.OutputStream; @@ -7,6 +9,7 @@ import java.io.OutputStream; * Copyright 2013 Ryan Michela */ public class FlushyOutputStream extends OutputStream { + private OutputStream base; private boolean isClosed = false; @@ -16,23 +19,27 @@ public class FlushyOutputStream extends OutputStream { @Override public void write(int b) throws IOException { - if(isClosed) return; + if (isClosed) return; base.write(b); base.flush(); } @Override public void write(byte[] b) throws IOException { - if(isClosed) return; + if (isClosed) return; base.write(b); base.flush(); } @Override public void write(byte[] b, int off, int len) throws IOException { - if(isClosed) return; - base.write(b, off, len); - base.flush(); + if (isClosed) return; + try { + base.write(b, off, len); + base.flush(); + } catch (SshException e) { + if (!e.getMessage().contains("channel already closed")) throw e; + } } @Override