Re-implement telnet commands.

This commit is contained in:
Wilee999 2014-01-19 12:40:00 -08:00
parent 8dac5b018e
commit 1a5ff8a258
2 changed files with 58 additions and 2 deletions

View file

@ -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);
}
}
}
}

View file

@ -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