From 1a5ff8a2588a961ea0027b0b656d63811b8c38aa Mon Sep 17 00:00:00 2001 From: Wilee999 Date: Sun, 19 Jan 2014 12:40:00 -0800 Subject: [PATCH 1/3] Re-implement telnet commands. --- .../BukkitTelnet/BT_ClientSession.java | 38 ++++++++++++++++++- .../StevenLawson/BukkitTelnet/BT_Handler.java | 22 ++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java b/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java index b203f20..3923696 100644 --- a/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java +++ b/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java @@ -19,6 +19,10 @@ import org.bukkit.scheduler.BukkitRunnable; public final class BT_ClientSession extends Thread { + public enum FilterMode + { + FULL, NONCHAT_ONLY, CHAT_ONLY + } private static final Pattern NONASCII_FILTER = Pattern.compile("[^\\x20-\\x7E]"); private static final Pattern AUTH_INPUT_FILTER = Pattern.compile("[^a-zA-Z0-9]"); private static final Pattern COMMAND_INPUT_FILTER = Pattern.compile("^[^a-zA-Z0-9/\\?!\\.]+"); @@ -26,6 +30,7 @@ public final class BT_ClientSession extends Thread private final Socket clientSocket; private final String clientAddress; // + public static FilterMode filter_mode = FilterMode.FULL; private SessionLogHandler sessionLogHandler; private SessionCommandSender sessionCommandSender; private BufferedWriter writer; @@ -365,7 +370,38 @@ public final class BT_ClientSession extends Thread command = COMMAND_INPUT_FILTER.matcher(NONASCII_FILTER.matcher(command).replaceAll("")).replaceFirst("").trim(); if (!command.isEmpty()) { - sendBukkitCommand(command); + if (command.toLowerCase().startsWith("telnet")) + { + if (command.equalsIgnoreCase("telnet.help")) + { + writeOut("Telnet commands:\r\n"); + writeOut("telnet.help - See all of the telnet commands.\r\n"); + writeOut("telnet.stopserver - Shutdown the server.\r\n"); + writeOut("telnet.log - Change your logging settings.\r\n"); + } + else if (command.equalsIgnoreCase("telnet.stopserver")) + { + writeOut("Shutting down the server...\r\n"); + System.exit(0); + } + else if (command.equalsIgnoreCase("telnet.log")) + { + if (filter_mode == FilterMode.CHAT_ONLY) + { + filter_mode = FilterMode.FULL; + writeOut("Showing full console log.\r\n"); + } + else + { + filter_mode = FilterMode.CHAT_ONLY; + writeOut("Showing chat log only.\r\n"); + } + } + } + else + { + sendBukkitCommand(command); + } } } } diff --git a/src/me/StevenLawson/BukkitTelnet/BT_Handler.java b/src/me/StevenLawson/BukkitTelnet/BT_Handler.java index a60189d..99431b5 100644 --- a/src/me/StevenLawson/BukkitTelnet/BT_Handler.java +++ b/src/me/StevenLawson/BukkitTelnet/BT_Handler.java @@ -3,6 +3,9 @@ package me.StevenLawson.BukkitTelnet; import java.util.logging.Formatter; import java.util.logging.Handler; import java.util.logging.LogRecord; + +import me.StevenLawson.BukkitTelnet.BT_ClientSession.FilterMode; + import org.bukkit.ChatColor; public abstract class BT_Handler extends Handler @@ -33,7 +36,24 @@ public abstract class BT_Handler extends Handler message = ChatColor.stripColor(message); - writeOut(message + "\r\n:"); + if (BT_ClientSession.filter_mode == FilterMode.CHAT_ONLY) + { + if (message.startsWith("<") || message.startsWith("[Server:") || message.startsWith("[CONSOLE]<") || message.startsWith("[TotalFreedomMod] [ADMIN]")) + { + writeOut(message + "\r\n:"); + } + } + else if (BT_ClientSession.filter_mode == FilterMode.NONCHAT_ONLY) + { + if (!(message.startsWith("<") || message.startsWith("[Server:") || message.startsWith("[CONSOLE]<") || message.startsWith("[TotalFreedomMod] [ADMIN]"))) + { + writeOut(message + "\r\n:"); + } + } + else + { + writeOut(message + "\r\n:"); + } } @Override From 2ef8f3daf38f5bef93de8ca92d56be3bffb1653b Mon Sep 17 00:00:00 2001 From: Wilee999 Date: Sun, 19 Jan 2014 13:20:44 -0800 Subject: [PATCH 2/3] Log who uses telnet.stopserver. --- src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java b/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java index 3923696..6f1f709 100644 --- a/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java +++ b/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java @@ -382,6 +382,7 @@ public final class BT_ClientSession extends Thread else if (command.equalsIgnoreCase("telnet.stopserver")) { writeOut("Shutting down the server...\r\n"); + BT_Log.warning(this.userName + " has shutdown the server."); System.exit(0); } else if (command.equalsIgnoreCase("telnet.log")) From 75d4c19eb2f454287d981bb1adeba61093b2912b Mon Sep 17 00:00:00 2001 From: Wilee999 Date: Fri, 24 Jan 2014 22:29:11 -0800 Subject: [PATCH 3/3] Implement new telnet.exit command. --- src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java b/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java index 6f1f709..c2fa329 100644 --- a/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java +++ b/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java @@ -378,6 +378,7 @@ public final class BT_ClientSession extends Thread writeOut("telnet.help - See all of the telnet commands.\r\n"); writeOut("telnet.stopserver - Shutdown the server.\r\n"); writeOut("telnet.log - Change your logging settings.\r\n"); + writeOut("telnet.exit - Quit the telnet session."); } else if (command.equalsIgnoreCase("telnet.stopserver")) { @@ -398,6 +399,10 @@ public final class BT_ClientSession extends Thread writeOut("Showing chat log only.\r\n"); } } + else if (command.equalsIgnoreCase("telnet.exit")) + { + terminateSession(); + } } else {