From b2cfb10f849267c6f5d9f49dd9f2322d44770ac4 Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Mon, 24 Oct 2011 20:04:27 -0400 Subject: [PATCH] Updated to new config system. Major rewrite, removed password auth (single password)... very --- nbproject/project.properties | 3 +- src/com/bekvon/bukkit/mctelnet/MCTelnet.java | 409 +++++----- .../bukkit/mctelnet/TelnetListener.java | 705 +++++++++--------- .../bekvon/bukkit/mctelnet/TelnetUtil.java | 93 +++ src/config.yml | 8 + src/plugin.yml | 7 +- 6 files changed, 627 insertions(+), 598 deletions(-) create mode 100644 src/com/bekvon/bukkit/mctelnet/TelnetUtil.java create mode 100644 src/config.yml diff --git a/nbproject/project.properties b/nbproject/project.properties index c23dd27..45a8cb1 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -26,11 +26,10 @@ dist.jar=${dist.dir}/MCTelnet.jar dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= -file.reference.craftbukkit-0.0.1-SNAPSHOT.jar=C:\\github\\craftbukkit-0.0.1-SNAPSHOT.jar includes=** jar.compress=false javac.classpath=\ - ${file.reference.craftbukkit-0.0.1-SNAPSHOT.jar} + ${libs.Bukkit.classpath} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false diff --git a/src/com/bekvon/bukkit/mctelnet/MCTelnet.java b/src/com/bekvon/bukkit/mctelnet/MCTelnet.java index 684737a..b6512d3 100644 --- a/src/com/bekvon/bukkit/mctelnet/MCTelnet.java +++ b/src/com/bekvon/bukkit/mctelnet/MCTelnet.java @@ -1,251 +1,206 @@ package com.bekvon.bukkit.mctelnet; +import java.io.File; import java.io.IOException; -import java.lang.reflect.Field; import java.net.ServerSocket; import java.net.Socket; +import java.net.UnknownHostException; import java.util.ArrayList; -import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.craftbukkit.CraftServer; import org.bukkit.plugin.java.JavaPlugin; -import java.math.BigInteger; import java.net.InetAddress; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; import java.util.Iterator; -import java.util.Map.Entry; -import org.bukkit.util.config.ConfigurationNode; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; public class MCTelnet extends JavaPlugin { - private ServerSocket listenerSocket; - private ArrayList clientHolder; - private Thread listenerThread; - private boolean run = false; - int port = 8765; - InetAddress listenAddress; + private static final String CONFIG_FILE = "config.yml"; + + private static final Logger log = Logger.getLogger("Minecraft"); + + private ServerSocket listenerSocket = null; + private ArrayList clientHolder; + private Thread listenerThread = null; + private boolean is_running = false; + private int port = 8765; + private InetAddress listenAddress = null; + + protected String password = null; + + @Override + public void onEnable() + { + try + { + log.log(Level.INFO, "[" + getDescription().getName() + "]: Enabled - Version " + this.getDescription().getVersion() + " by bekvon, revamped by Madgeek1450."); + log.log(Level.INFO, "[" + getDescription().getName() + "]: Starting server."); + + TelnetUtil.createDefaultConfiguration(CONFIG_FILE, this, getFile()); + FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), CONFIG_FILE)); + + password = config.getString("password", null); + if (password == null) + { + log.log(Level.SEVERE, "[" + getDescription().getName() + "]: Password is not defined in config file! Can't start server!"); + return; + } - public MCTelnet() - { - } + port = config.getInt("port", port); - public void onDisable() - { - run = false; - if (listenerSocket != null) - { - try - { - synchronized (listenerSocket) - { - if (listenerSocket != null) - { - listenerSocket.close(); - } - } - } - catch (IOException ex) - { - Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); - } - } - try - { - Thread.sleep(1000); - } - catch (InterruptedException ex) - { - Logger.getLogger(MCTelnet.class.getName()).log(Level.SEVERE, null, ex); - } - } + String address = config.getString("address", null); + if (address != null) + { + try + { + listenAddress = null; + listenAddress = InetAddress.getByName(address); + } + catch (UnknownHostException ex) + { + log.log(Level.SEVERE, "[" + getDescription().getName() + "]: Unknown host: " + address); + return; + } + } + else + { + address = "*"; + } - public void onEnable() - { - try - { - Logger.getLogger("Minecraft").log(Level.INFO, "[MCTelnet] - Starting Up! Version: " + this.getDescription().getVersion() + " by bekvon"); - run = true; - this.getConfiguration().load(); - testConfig(); - if (this.getConfiguration().getBoolean("encryptPasswords", false)) - { - encryptPasswords(); - } - port = this.getConfiguration().getInt("telnetPort", port); - try - { - String address = this.getConfiguration().getString("listenAddress", null); - if (address != null) - { - listenAddress = InetAddress.getByName(address); - } - } - catch (Exception ex) - { - System.out.println("[MCTelnet] Exception when trying to binding to custom address:" + ex.getMessage()); - } - if (listenAddress != null) - { - listenerSocket = new java.net.ServerSocket(port, 10, listenAddress); - } - else - { - listenerSocket = new java.net.ServerSocket(port, 10); - } - clientHolder = new ArrayList(); - listenerThread = new Thread(new Runnable() - { - public void run() - { - acceptConnections(); - } - }); - listenerThread.start(); - Field cfield = CraftServer.class.getDeclaredField("console"); - cfield.setAccessible(true); - Logger.getLogger("Minecraft").log(Level.INFO, "[MCTelnet] - Listening on: " + listenerSocket.getInetAddress().getHostAddress() + ":" + port); - } - catch (Exception ex) - { - Logger.getLogger("Minecraft").log(Level.SEVERE, "[MCTelnet] - Unable to Enable! Error: " + ex.getMessage()); - this.setEnabled(false); - } - } + try + { + if (listenAddress != null) + { + listenerSocket = new java.net.ServerSocket(port, 10, listenAddress); + } + else + { + listenerSocket = new java.net.ServerSocket(port); + } + + String host_ip = listenerSocket.getInetAddress().getHostAddress(); + if (host_ip.equals("0.0.0.0")) + { + host_ip = "*"; + } - private void encryptPasswords() - { - Map users = this.getConfiguration().getNodes("users"); - if (users != null) - { - Iterator> thisIt = users.entrySet().iterator(); - if (thisIt != null) - { - while (thisIt.hasNext()) - { - Entry thisEntry = thisIt.next(); - if (thisEntry != null) - { - ConfigurationNode thisNode = thisEntry.getValue(); - if (thisNode != null && !thisNode.getBoolean("passEncrypted", false)) - { - this.getConfiguration().setProperty("users." + thisEntry.getKey() + ".password", hashPassword(thisNode.getString("password"))); - this.getConfiguration().setProperty("users." + thisEntry.getKey() + ".passEncrypted", true); - this.getConfiguration().save(); - } - } - } - } - } - } + log.log(Level.INFO, "[" + getDescription().getName() + "]: Server started on " + host_ip + ":" + port); + } + catch (IOException ex) + { + log.log(Level.SEVERE, "[" + getDescription().getName() + "]: Cant bind to " + address + ":" + port); + } - public static String hashPassword(String password) - { - String hashword = null; - try - { - MessageDigest md5 = MessageDigest.getInstance("MD5"); - md5.update(password.getBytes()); - BigInteger hash = new BigInteger(1, md5.digest()); - hashword = hash.toString(16); - } - catch (NoSuchAlgorithmException nsae) - { - } - return hashword; - } + clientHolder = new ArrayList(); + + is_running = true; - private void acceptConnections() - { - while (run) - { - try - { - Socket client = listenerSocket.accept(); - if (client != null) - { - clientHolder.add(new TelnetListener(client, this)); - System.out.print("[MCTelnet] - Client connected: " + client.getInetAddress().toString()); - } - for (int i = 0; i < clientHolder.size(); i++) - { - TelnetListener thisListener = clientHolder.get(i); - if (thisListener.isAlive() == false) - { - clientHolder.remove(i); - } - } - } - catch (IOException ex) - { - run = false; - } - } - Logger.getLogger("Minecraft").log(Level.INFO, "[MCTelnet] - Shutting Down!"); - for (int i = 0; i < clientHolder.size(); i++) - { - TelnetListener temp = clientHolder.get(i); - temp.killClient(); - } - listenerSocket = null; - clientHolder.clear(); - clientHolder = null; - this.setEnabled(false); - } + listenerThread = new Thread(new Runnable() + { + public void run() + { + acceptConnections(); + } + }); + listenerThread.start(); + } + catch (Throwable ex) + { + log.log(Level.SEVERE, "[" + getDescription().getName() + "]: Error starting plugin!", ex); + } + } + + @Override + public void onDisable() + { + is_running = false; + + log.log(Level.INFO, "[" + getDescription().getName() + "]: Stopping server."); + + try + { + Thread.sleep(250); + } + catch (Throwable ex) + { + } + + if (clientHolder != null) + { + try + { + for (TelnetListener listener : clientHolder) + { + listener.killClient(); + } + clientHolder.clear(); + clientHolder = null; + } + catch (Throwable ex) + { + } + } - private void testConfig() - { - String testConfig = this.getConfiguration().getString("telnetPort", null); - if (testConfig == null || testConfig.equals("")) - { - this.getConfiguration().setProperty("telnetPort", 8765); - this.getConfiguration().save(); - } - testConfig = this.getConfiguration().getString("listenAddress", null); - if (testConfig == null || testConfig.equals("")) - { - this.getConfiguration().setProperty("listenAddress", "0.0.0.0"); - this.getConfiguration().save(); - } - testConfig = this.getConfiguration().getString("encryptPasswords", null); - if (testConfig == null || testConfig.equals("")) - { - this.getConfiguration().setProperty("encryptPasswords", true); - this.getConfiguration().save(); - } + if (listenerSocket != null) + { + try + { + synchronized (listenerSocket) + { + if (listenerSocket != null) + { + listenerSocket.close(); + } + } + listenerSocket = null; + } + catch (Throwable ex) + { + } + } + + try + { + Thread.sleep(250); + } + catch (Throwable ex) + { + log.log(Level.SEVERE, null, ex); + } + } + + private void acceptConnections() + { + while (is_running) + { + Socket client = null; + try + { + client = listenerSocket.accept(); + if (client != null) + { + clientHolder.add(new TelnetListener(client, this)); - } + log.info("[" + getDescription().getName() + "]: Client connected: " + client.getInetAddress().getHostAddress()); - @Override - public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) - { - if (this.isEnabled()) - { - if (cmd.getName().equals("telnetreload")) - { - if (sender instanceof ConsoleCommandSender) - { - this.getConfiguration().load(); - testConfig(); - if (this.getConfiguration().getBoolean("encryptPasswords", false)) - { - encryptPasswords(); - } - sender.sendMessage("[MCTelnet] - Reloaded Config..."); - for (int i = 0; i < clientHolder.size(); i++) - { - TelnetListener thisListener = clientHolder.get(i); - thisListener.sendMessage("[MCTelnet] - Telnet Restarting..."); - thisListener.killClient(); - } - } - return true; - } - } - return super.onCommand(sender, cmd, commandLabel, args); - } + Iterator listeners = clientHolder.iterator(); + while (listeners.hasNext()) + { + TelnetListener listener = listeners.next(); + if (!listener.isAlive()) + { + listeners.remove(); + } + } + } + } + catch (IOException ex) + { + is_running = false; + } + } + + this.setEnabled(false); + } } diff --git a/src/com/bekvon/bukkit/mctelnet/TelnetListener.java b/src/com/bekvon/bukkit/mctelnet/TelnetListener.java index 4e56f04..e8477a7 100644 --- a/src/com/bekvon/bukkit/mctelnet/TelnetListener.java +++ b/src/com/bekvon/bukkit/mctelnet/TelnetListener.java @@ -11,7 +11,6 @@ import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; -import net.minecraft.server.MinecraftServer; import org.bukkit.ChatColor; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -19,371 +18,349 @@ import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionAttachment; import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.Plugin; -import org.bukkit.util.config.ConfigurationNode; public class TelnetListener extends Handler implements CommandSender { - private boolean run; - private boolean isAuth; - private String authUser; - private Thread listenThread; - Socket clientSocket; - MinecraftServer mcserv; - BufferedReader instream; - BufferedWriter outstream; - MCTelnet parent; - String ip; - String passRegex = "[^a-zA-Z0-9\\-\\.\\_]"; - String commandRegex = "[^\\x20-\\x7E§]"; + private static final Logger log = Logger.getLogger("Minecraft"); + private boolean is_running = false; + private boolean is_authenticated = false; + private boolean already_stopped = false; + private String telnet_username = null; + private Thread listenThread; + private Socket clientSocket; + private BufferedReader instream; + private BufferedWriter outstream; + private MCTelnet plugin; + private String client_ip; + private static final String COMMAND_REGEX = "[^\\x20-\\x7E]"; + private static final String LOGIN_REGEX = "[^a-zA-Z0-9\\-\\.\\_]"; + + public TelnetListener(Socket socket, MCTelnet plugin) + { + this.is_running = true; + this.clientSocket = socket; + this.plugin = plugin; + if (clientSocket.getInetAddress() != null) + { + this.client_ip = clientSocket.getInetAddress().getHostAddress(); + } + + startListener(); + } + + private void startListener() + { + listenThread = new Thread(new Runnable() + { + public void run() + { + init(); + } + }); + listenThread.start(); + } + + private void init() + { + try + { + instream = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); + outstream = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream())); + } + catch (Throwable ex) + { + is_running = false; + return; + } + + //sendTelnetCommand(WILL, LINEMODE); + //sendTelnetCommand(DO, LINEMODE); + //sendTelnetCommand(WONT, ECHO); + //sendTelnetCommand(DO, ECHO); + + writeOut("[MCTelnet] - Session Started!\r\n"); + + authenticateLoop(); + commandLoop(); + shutdown(); + } + + private void authenticateLoop() + { + int tries = 0; + + while (is_running && clientSocket.isConnected() && !is_authenticated) + { + try + { + //Get Username: + writeOut("Username: "); + String username = instream.readLine().replaceAll(LOGIN_REGEX, "").trim(); + + //sendTelnetCommand(WILL, ECHO); + //sendTelnetCommand(DONT, ECHO); - public TelnetListener(Socket inSock, MCTelnet iparent) - { - run = true; - clientSocket = inSock; - parent = iparent; - passRegex = parent.getConfiguration().getString("passwordRegex", passRegex); - //commandRegex = parent.getConfiguration().getString("commandRegex", commandRegex); - ip = clientSocket.getInetAddress().toString(); - listenThread = new Thread(new Runnable() - { - public void run() - { - mainLoop(); - } - }); - listenThread.start(); - } - - private void mainLoop() - { - try - { - instream = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); - outstream = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream())); - //sendTelnetCommand(251,3); - //sendTelnetCommand(253,3); - sendTelnetCommand(251, 34); - sendTelnetCommand(253, 34); - sendTelnetCommand(252, 1); - sendTelnetCommand(253, 1); - outstream.write("[MCTelnet] - Session Started!\r\n"); - outstream.flush(); - } - catch (IOException ex) - { - Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); - run = false; - } - if (!clientSocket.getInetAddress().isLoopbackAddress() || !parent.getConfiguration().getBoolean("allowAuthlessLocalhost", false)) - { - authenticateLoop(); - } - else - { - isAuth = true; - authUser = parent.getConfiguration().getString("rootUser"); - } - commandLoop(); - shutdown(); - } - - private void authenticateLoop() - { - int retrys = 0; - while (run && clientSocket.isConnected() && isAuth == false) - { - try - { - outstream.write("Username:"); - outstream.flush(); - String username = instream.readLine().replaceAll(passRegex, ""); - sendTelnetCommand(251, 1); - sendTelnetCommand(254, 1); - outstream.write("Password:"); - outstream.flush(); - String pw = instream.readLine().replaceAll(passRegex, ""); - outstream.write("\r\n"); - sendTelnetCommand(252, 1); - sendTelnetCommand(253, 1); - ConfigurationNode parentnode = parent.getConfiguration().getNode("users"); - if (parentnode != null) - { - ConfigurationNode usernode = parentnode.getNode(username); - if (usernode != null) - { - String userpw = usernode.getString("password"); - if (usernode.getBoolean("passEncrypted", false)) - { - pw = MCTelnet.hashPassword(pw); - } - if (pw.equals(userpw)) - { - authUser = username; - isAuth = true; - } - } - } - if (isAuth) - { - outstream.write("Logged In as " + authUser + "!\r\n:"); - outstream.flush(); - } - else - { - Thread.sleep(2000); - outstream.write("Invalid Username or Password!\r\n\r\n"); - outstream.flush(); - } - retrys++; - if (retrys == 3 && isAuth == false) - { - try - { - outstream.write("Too many failed login attempts!"); - outstream.flush(); - } - catch (Exception ex) - { - } - return; - } - } - catch (Exception ex) - { - run = false; - authUser = null; - isAuth = false; - } - } - } - - private void commandLoop() - { - try - { - if (isAuth) - { - String[] validCommands = new String[0]; - - Logger.getLogger("Minecraft").addHandler(this); - - while (run && clientSocket.isConnected() && isAuth) - { - String command = ""; - command = instream.readLine().replaceAll(commandRegex, "").trim(); - if (command.equals("exit")) - { - run = false; - clientSocket.close(); - return; - } - if (!clientSocket.isClosed()) - { - parent.getServer().dispatchCommand(this, command); - System.out.println("[MCTelnet] " + authUser + " issued command: " + command); - } - } - } - } - catch (Exception ex) - { - } - } - - public boolean isAlive() - { - return run; - } - - public void killClient() - { - try - { - run = false; - outstream.write("[MCTelnet] - Closing Connection!"); - clientSocket.close(); - } - catch (IOException ex) - { - } - } - - private void shutdown() - { - try - { - run = false; - Logger.getLogger("Minecraft").removeHandler(this); - Logger.getLogger("Minecraft").log(Level.INFO, "[MCTelnet] Closing connection: " + ip); - if (!clientSocket.isClosed()) - { - outstream.write("[MCTelnet] - Closing Connection!"); - clientSocket.close(); - } - mcserv = null; - parent = null; - } - catch (Exception ex) - { - Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); - run = false; - } - } - - @Override - public void publish(LogRecord record) - { - try - { - if (!clientSocket.isClosed()) - { - outstream.write(ChatColor.stripColor(record.getMessage()) + "\r\n:"); - outstream.flush(); - } - } - catch (IOException ex) - { - } - } - - @Override - public void flush() - { - if (clientSocket.isConnected()) - { - try - { - outstream.flush(); - } - catch (IOException ex) - { - } - } - } - - public void sendMessage(String string) - { - if (clientSocket.isConnected()) - { - try - { - string = ChatColor.stripColor(string); - outstream.write(string + "\r\n:"); - outstream.flush(); - } - catch (IOException ex) - { - } - } - } - - public boolean isOp() - { - if (authUser.equalsIgnoreCase("console")) - { - return true; - } - if (parent.getConfiguration().getBoolean("allowOPsAll", false)) - { - return parent.getServer().getPlayer(authUser).isOp(); - } - return false; - } - - public boolean isPlayer() - { - return false; - } - - public Server getServer() - { - return parent.getServer(); - } - - @Override - public void close() throws SecurityException - { - shutdown(); - } - - private void sendTelnetCommand(int command, int option) - { - if (clientSocket.isConnected()) - { - try - { - String tcmd = ("" + ((char) 255) + ((char) command) + ((char) option)); - outstream.write(tcmd); - outstream.flush(); - } - catch (IOException ex) - { - } - } - } - - public String getName() - { - return authUser; - } - - public boolean isPermissionSet(String string) - { - return true; - } - - public boolean isPermissionSet(Permission prmsn) - { - return true; - } - - public boolean hasPermission(String string) - { - return true; - } - - public boolean hasPermission(Permission prmsn) - { - return true; - } - - public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln) - { - return null; - } - - public PermissionAttachment addAttachment(Plugin plugin) - { - return null; - } - - public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln, int i) - { - return null; - } - - public PermissionAttachment addAttachment(Plugin plugin, int i) - { - return null; - } - - public void removeAttachment(PermissionAttachment pa) - { - return; - } - - public void recalculatePermissions() - { - return; - } - - public Set getEffectivePermissions() - { - return null; - } - - public void setOp(boolean bln) - { - return; - } + //Get Password: + writeOut("Password: "); + String password = instream.readLine().replaceAll(LOGIN_REGEX, "").trim(); + writeOut("\r\n"); + + //sendTelnetCommand(WONT, ECHO); + //sendTelnetCommand(DO, ECHO); + + if (password.equals(plugin.password)) + { + telnet_username = username; + is_authenticated = true; + } + + if (is_authenticated) + { + writeOut("Logged In as " + getName() + ".\r\n:"); + return; + } + else + { + try + { + Thread.sleep(2000); + } + catch (InterruptedException ex) + { + } + writeOut("Invalid Username or Password.\r\n\r\n"); + } + + if (++tries >= 3) + { + writeOut("Too many failed login attempts.\r\n"); + return; + } + } + catch (Throwable ex) + { + is_running = false; + telnet_username = null; + is_authenticated = false; + } + } + } + + private void commandLoop() + { + if (!is_running || !is_authenticated) + { + return; + } + + Logger.getLogger("Minecraft").addHandler(this); + + while (is_running && clientSocket.isConnected() && is_authenticated) + { + String command = null; + try + { + command = instream.readLine(); + } + catch (IOException ex) + { + } + + if (command != null) + { + if (!command.isEmpty()) + { + command = command.replaceAll(COMMAND_REGEX, "").trim(); + plugin.getServer().dispatchCommand(this, command); + log.log(Level.INFO, "[" + plugin.getDescription().getName() + "]: " + getName() + " issued command: " + command); + } + else + { + writeOut(":"); + } + } + } + } + + private void shutdown() + { + if (already_stopped) + { + return; + } + already_stopped = true; + + is_running = false; + + log.log(Level.INFO, "[" + plugin.getDescription().getName() + "]: Closing connection: " + client_ip); + Logger.getLogger("Minecraft").removeHandler(this); + + if (!clientSocket.isClosed()) + { + writeOut("[" + plugin.getDescription().getName() + "]: Closing connection."); + try + { + clientSocket.close(); + } + catch (IOException ex) + { + } + } + } + +// public static final int WILL = 251; //Sender wants to do something. +// public static final int WONT = 252; //Sender doesn't want to do something. +// public static final int DO = 253; //Sender wants the other end to do something. +// public static final int DONT = 254; //Sender wants the other not to do something. +// +// public static final int ECHO = 1; +// public static final int LINEMODE = 34; +// +// private void sendTelnetCommand(int command, int option) +// { +// writeOut(("" + ((char) 255) + ((char) command) + ((char) option))); +// } + + private void writeOut(String message) + { + if (outstream != null) + { + if (clientSocket.isConnected()) + { + try + { + outstream.write(message); + outstream.flush(); + } + catch (IOException ex) + { + is_running = false; + } + } + } + } + + public boolean isAlive() + { + return is_running; + } + + public void killClient() + { + shutdown(); + } + + @Override + public void publish(LogRecord record) + { + writeOut(ChatColor.stripColor(record.getMessage()) + "\r\n:"); + } + + @Override + public void flush() + { + if (clientSocket.isConnected()) + { + try + { + outstream.flush(); + } + catch (IOException ex) + { + } + } + } + + @Override + public void close() throws SecurityException + { + shutdown(); + } + + public void sendMessage(String string) + { + writeOut(ChatColor.stripColor(string) + "\r\n:"); + } + + public Server getServer() + { + return plugin.getServer(); + } + + public String getName() + { + if (telnet_username != null) + { + return telnet_username; + } + else + { + return plugin.getDescription().getName(); + } + } + + public boolean isPermissionSet(String string) + { + return true; + } + + public boolean isPermissionSet(Permission prmsn) + { + return true; + } + + public boolean hasPermission(String string) + { + return true; + } + + public boolean hasPermission(Permission prmsn) + { + return true; + } + + public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln) + { + return null; + } + + public PermissionAttachment addAttachment(Plugin plugin) + { + return null; + } + + public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln, int i) + { + return null; + } + + public PermissionAttachment addAttachment(Plugin plugin, int i) + { + return null; + } + + public void removeAttachment(PermissionAttachment pa) + { + return; + } + + public void recalculatePermissions() + { + return; + } + + public Set getEffectivePermissions() + { + return null; + } + + public boolean isOp() + { + return true; + } + + public void setOp(boolean bln) + { + return; + } } diff --git a/src/com/bekvon/bukkit/mctelnet/TelnetUtil.java b/src/com/bekvon/bukkit/mctelnet/TelnetUtil.java new file mode 100644 index 0000000..73bfe5b --- /dev/null +++ b/src/com/bekvon/bukkit/mctelnet/TelnetUtil.java @@ -0,0 +1,93 @@ +package com.bekvon.bukkit.mctelnet; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.jar.JarFile; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.zip.ZipEntry; + +public class TelnetUtil +{ + private static final Logger log = Logger.getLogger("Minecraft"); + + private TelnetUtil() + { + } + + public static void createDefaultConfiguration(String name, MCTelnet tfm, File plugin_file) + { + File actual = new File(tfm.getDataFolder(), name); + if (!actual.exists()) + { + log.info("[" + tfm.getDescription().getName() + "]: Installing default configuration file template: " + actual.getPath()); + InputStream input = null; + try + { + JarFile file = new JarFile(plugin_file); + ZipEntry copy = file.getEntry(name); + if (copy == null) + { + log.severe("[" + tfm.getDescription().getName() + "]: Unable to read default configuration: " + actual.getPath()); + return; + } + input = file.getInputStream(copy); + } + catch (IOException ioex) + { + log.severe("[" + tfm.getDescription().getName() + "]: Unable to read default configuration: " + actual.getPath()); + } + if (input != null) + { + FileOutputStream output = null; + + try + { + tfm.getDataFolder().mkdirs(); + output = new FileOutputStream(actual); + byte[] buf = new byte[8192]; + int length = 0; + while ((length = input.read(buf)) > 0) + { + output.write(buf, 0, length); + } + + log.info("[" + tfm.getDescription().getName() + "]: Default configuration file written: " + actual.getPath()); + } + catch (IOException ioex) + { + log.log(Level.SEVERE, "[" + tfm.getDescription().getName() + "]: Unable to write default configuration: " + actual.getPath(), ioex); + } + finally + { + try + { + if (input != null) + { + input.close(); + } + } + catch (IOException ioex) + { + } + + try + { + if (output != null) + { + output.close(); + } + } + catch (IOException ioex) + { + } + } + } + } + } +} diff --git a/src/config.yml b/src/config.yml new file mode 100644 index 0000000..3a6675b --- /dev/null +++ b/src/config.yml @@ -0,0 +1,8 @@ +# Port to bind to: +port: 8765 + +# Address to listen on, leave blank for all: +address: + +# Main connection password, must be defined: +password: diff --git a/src/plugin.yml b/src/plugin.yml index 5853455..f206790 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,8 +1,5 @@ name: MCTelnet main: com.bekvon.bukkit.mctelnet.MCTelnet -version: 1.2.7 +version: 1.3 description: Telnet console access plugin. -author: bekvon -commands: - telnetreload: - description: Reloads MCTelnets config file... \ No newline at end of file +author: bekvon \ No newline at end of file