You can now configure the MOTD, also fixed an old bug.

You can customize the MOTD you see when you login (with the exception
of what server you're logged into and some other info) and this
includes colorization support via minecraft color codes (you need the
special color code character that minecraft uses though, the example
motd.txt has an included rainbow you can work from.)

Hopefully fixed an old bug with the logger writting to the disconnected
client session which causes a ton of exceptions because the session is gone.
This commit is contained in:
Justin Crawford 2019-10-04 23:18:59 -07:00
parent 3e45f7ebf4
commit 73c30f5214
No known key found for this signature in database
GPG Key ID: 0D84DEDBB8EF259C
4 changed files with 50 additions and 11 deletions

View File

@ -130,6 +130,7 @@
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
<include>motd.txt</include>
</includes>
</resource>
</resources>

View File

@ -20,6 +20,10 @@ import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ExitCallback;
import org.bukkit.Bukkit;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -89,9 +93,9 @@ public class ConsoleShellFactory implements ShellFactory {
this.ConsoleReader.addCompleter(new ConsoleCommandCompleter());
StreamHandler streamHandler = new FlushyStreamHandler(out, new ConsoleLogFormatter(), this.ConsoleReader);
streamHandlerAppender = new StreamHandlerAppender(streamHandler);
this.streamHandlerAppender = new StreamHandlerAppender(streamHandler);
((Logger)LogManager.getRootLogger()).addAppender(streamHandlerAppender);
((Logger)LogManager.getRootLogger()).addAppender(this.streamHandlerAppender);
this.environment = env;
this.Username = env.getEnv().get(Environment.ENV_USER);
@ -107,7 +111,7 @@ public class ConsoleShellFactory implements ShellFactory {
}
@Override
public void destroy(ChannelSession cs) { ((Logger)LogManager.getRootLogger()).removeAppender(streamHandlerAppender); }
public void destroy(ChannelSession cs) { ((Logger)LogManager.getRootLogger()).removeAppender(this.streamHandlerAppender); }
public void run()
{
@ -150,6 +154,9 @@ public class ConsoleShellFactory implements ShellFactory {
}
});
}
// This should help stop one of the bugs where bytes are waiting to be written
// but the client fucked off already so the plugin throws an exception.
((Logger)LogManager.getRootLogger()).removeAppender(this.streamHandlerAppender);
}
catch (IOException e)
{
@ -164,16 +171,25 @@ public class ConsoleShellFactory implements ShellFactory {
private void printPreamble(ConsoleReader cr) throws IOException
{
cr.println(" _____ _____ _ _ _____" + "\r");
cr.println(" / ____/ ____| | | | __ \\" + "\r");
cr.println("| (___| (___ | |__| | | | |" + "\r");
cr.println(" \\___ \\\\___ \\| __ | | | |" + "\r");
cr.println(" ____) |___) | | | | |__| |" + "\r");
cr.println("|_____/_____/|_| |_|_____/" + "\r");
File f = new File(SshdPlugin.instance.getDataFolder(), "motd.txt");
try
{
BufferedReader br = new BufferedReader(new FileReader(f));
String st;
while ((st = br.readLine()) != null)
cr.println(ConsoleLogFormatter.ColorizeString(st) + "\r");
}
catch (FileNotFoundException e)
{
SshdPlugin.instance.getLogger().log(Level.WARNING, "Could not open " + f + ": File does not exist.");
// Not showing the SSH motd is not a fatal failure, let the session continue.
}
// Doesn't really guarantee our actual system hostname but
// it's better than not having one at all.
cr.println("Connected to: " + InetAddress.getLocalHost().getHostName() + " (" + Bukkit.getServer().getName() + ")\r");
cr.println(ConsoleLogFormatter.ColorizeString(Bukkit.getServer().getMotd()) + "\r");
cr.println(ConsoleLogFormatter.ColorizeString(Bukkit.getServer().getMotd()).replaceAll("\n", "\r\n"));
cr.println("\r");
cr.println("Type 'exit' to exit the shell." + "\r");
cr.println("===============================================" + "\r");

View File

@ -10,7 +10,9 @@ import com.ryanmichela.sshd.ConsoleShellFactory;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.util.Collections;
import java.util.logging.Level;
@ -29,8 +31,20 @@ class SshdPlugin extends JavaPlugin
saveDefaultConfig();
File authorizedKeys = new File(getDataFolder(), "authorized_keys");
if (!authorizedKeys.exists())
{
authorizedKeys.mkdirs();
try
{
File motd = new File(getDataFolder(), "motd.txt");
if (!motd.exists())
{
InputStream link = (getClass().getResourceAsStream("/motd.txt"));
Files.copy(link, motd.getAbsoluteFile().toPath());
}
}
catch (IOException e)
{
e.printStackTrace();
}
// Don't go any lower than INFO or SSHD will cause a stack overflow exception.

View File

@ -0,0 +1,8 @@
§l§4 _____ _____ _ _ _____§r
§l§6 / ____/ ____| | | | __ \§r
§l§2| (___| (___ | |__| | | | |§r
§l§3 \___ \\___ \| __ | | | |§r
§l§9 ____) |___) | | | | |__| |§r
§l§5|_____/_____/|_| |_|_____/§r
===============================================