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:
parent
3e45f7ebf4
commit
73c30f5214
1
pom.xml
1
pom.xml
@ -130,6 +130,7 @@
|
|||||||
<includes>
|
<includes>
|
||||||
<include>plugin.yml</include>
|
<include>plugin.yml</include>
|
||||||
<include>config.yml</include>
|
<include>config.yml</include>
|
||||||
|
<include>motd.txt</include>
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -20,6 +20,10 @@ import org.apache.sshd.server.Environment;
|
|||||||
import org.apache.sshd.server.ExitCallback;
|
import org.apache.sshd.server.ExitCallback;
|
||||||
import org.bukkit.Bukkit;
|
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.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@ -89,9 +93,9 @@ public class ConsoleShellFactory implements ShellFactory {
|
|||||||
this.ConsoleReader.addCompleter(new ConsoleCommandCompleter());
|
this.ConsoleReader.addCompleter(new ConsoleCommandCompleter());
|
||||||
|
|
||||||
StreamHandler streamHandler = new FlushyStreamHandler(out, new ConsoleLogFormatter(), this.ConsoleReader);
|
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.environment = env;
|
||||||
this.Username = env.getEnv().get(Environment.ENV_USER);
|
this.Username = env.getEnv().get(Environment.ENV_USER);
|
||||||
@ -107,7 +111,7 @@ public class ConsoleShellFactory implements ShellFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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()
|
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)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
@ -164,16 +171,25 @@ public class ConsoleShellFactory implements ShellFactory {
|
|||||||
|
|
||||||
private void printPreamble(ConsoleReader cr) throws IOException
|
private void printPreamble(ConsoleReader cr) throws IOException
|
||||||
{
|
{
|
||||||
cr.println(" _____ _____ _ _ _____" + "\r");
|
File f = new File(SshdPlugin.instance.getDataFolder(), "motd.txt");
|
||||||
cr.println(" / ____/ ____| | | | __ \\" + "\r");
|
try
|
||||||
cr.println("| (___| (___ | |__| | | | |" + "\r");
|
{
|
||||||
cr.println(" \\___ \\\\___ \\| __ | | | |" + "\r");
|
BufferedReader br = new BufferedReader(new FileReader(f));
|
||||||
cr.println(" ____) |___) | | | | |__| |" + "\r");
|
|
||||||
cr.println("|_____/_____/|_| |_|_____/" + "\r");
|
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
|
// Doesn't really guarantee our actual system hostname but
|
||||||
// it's better than not having one at all.
|
// it's better than not having one at all.
|
||||||
cr.println("Connected to: " + InetAddress.getLocalHost().getHostName() + " (" + Bukkit.getServer().getName() + ")\r");
|
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("\r");
|
||||||
cr.println("Type 'exit' to exit the shell." + "\r");
|
cr.println("Type 'exit' to exit the shell." + "\r");
|
||||||
cr.println("===============================================" + "\r");
|
cr.println("===============================================" + "\r");
|
||||||
|
@ -10,7 +10,9 @@ import com.ryanmichela.sshd.ConsoleShellFactory;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.nio.file.FileSystems;
|
import java.nio.file.FileSystems;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@ -29,8 +31,20 @@ class SshdPlugin extends JavaPlugin
|
|||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
File authorizedKeys = new File(getDataFolder(), "authorized_keys");
|
File authorizedKeys = new File(getDataFolder(), "authorized_keys");
|
||||||
if (!authorizedKeys.exists())
|
if (!authorizedKeys.exists())
|
||||||
{
|
|
||||||
authorizedKeys.mkdirs();
|
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.
|
// Don't go any lower than INFO or SSHD will cause a stack overflow exception.
|
||||||
|
8
src/main/resources/motd.txt
Normal file
8
src/main/resources/motd.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
§l§4 _____ _____ _ _ _____§r
|
||||||
|
§l§6 / ____/ ____| | | | __ \§r
|
||||||
|
§l§2| (___| (___ | |__| | | | |§r
|
||||||
|
§l§3 \___ \\___ \| __ | | | |§r
|
||||||
|
§l§9 ____) |___) | | | | |__| |§r
|
||||||
|
§l§5|_____/_____/|_| |_|_____/§r
|
||||||
|
|
||||||
|
===============================================
|
Loading…
Reference in New Issue
Block a user