]> jfr.im git - irc/rizon/moo.git/commitdiff
Work on some of commands
authorAdam <redacted>
Sun, 21 Feb 2016 03:03:47 +0000 (22:03 -0500)
committerAdam <redacted>
Sun, 21 Feb 2016 03:03:47 +0000 (22:03 -0500)
26 files changed:
commands/src/main/java/net/rizon/moo/plugin/commands/CommandMap.java [deleted file]
commands/src/main/java/net/rizon/moo/plugin/commands/CommandSid.java [deleted file]
commands/src/main/java/net/rizon/moo/plugin/commands/CommandWhy.java [deleted file]
commands/src/main/java/net/rizon/moo/plugin/commands/commands.java
commands/src/main/java/net/rizon/moo/plugin/commands/map/CommandMap.java [new file with mode: 0755]
commands/src/main/java/net/rizon/moo/plugin/commands/map/CommandMapAll.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/map/CommandMapRegular.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/map/Message211.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/map/Message219.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/map/Message265.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/sid/CommandSidBase.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/sid/CommandSidClient.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/sid/CommandSidHub.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/uptime/CommandUptime.java [moved from commands/src/main/java/net/rizon/moo/plugin/commands/CommandUptime.java with 62% similarity]
commands/src/main/java/net/rizon/moo/plugin/commands/uptime/Message242.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/version/CommandVersion.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/version/CommandVersionBase.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/version/CommandVersions.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/version/Message351.java [moved from commands/src/main/java/net/rizon/moo/plugin/commands/CommandVersions.java with 53% similarity]
commands/src/main/java/net/rizon/moo/plugin/commands/why/CommandWhy.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/why/Message216.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/why/Message219Why.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/why/Message225.java [new file with mode: 0644]
fun/src/main/java/net/rizon/moo/plugin/fun/fun.java
moo/src/main/java/net/rizon/moo/Command.java
pom.xml

diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/CommandMap.java b/commands/src/main/java/net/rizon/moo/plugin/commands/CommandMap.java
deleted file mode 100755 (executable)
index 048d388..0000000
+++ /dev/null
@@ -1,257 +0,0 @@
-package net.rizon.moo.plugin.commands;
-
-import java.util.Iterator;
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-
-import net.rizon.moo.Command;
-import net.rizon.moo.CommandSource;
-import net.rizon.moo.Message;
-import net.rizon.moo.Moo;
-import net.rizon.moo.Plugin;
-import net.rizon.moo.Server;
-
-class message211 extends Message
-{
-       public message211()
-       {
-               super("211");
-       }
-
-       /*
-        * 0: moo
-        * 1: services.rizon.net[unknown@255.255.255.255]
-        * 2: 0  // Buf length
-        * 3: 24 // send.messages
-        * 4: 1  // send.bytes
-        * 5: 40 // recv.messages
-        * 6: 2  // recv.bytes
-        * 7: 48 0 TS GLN TBURST SVS UNKLN KLN KNOCK ENCAP CHW IE EX TS6 EOB QS
-        */
-       @Override
-       public void run(String source, String[] message)
-       {
-               long bytes = Long.parseLong(message[2]);
-               Server serv = Server.findServerAbsolute(source);
-               if (serv == null)
-                       serv = new Server(source);
-               serv.bytes += bytes;
-       }
-}
-
-class message219 extends Message
-{
-       public message219()
-       {
-               super("219");
-       }
-
-       private String convertBytes(long b)
-       {
-               String what = "bytes";
-
-               if (b > 1024L)
-               {
-                       b /= 1024L;
-                       what = "KB";
-               }
-               if (b > 1024L)
-               {
-                       b /= 1024L;
-                       what = "MB";
-               }
-               if (b > 1024L)
-               {
-                       b /= 1024L;
-                       what = "GB";
-               }
-               if (b > 1024L)
-               {
-                       b /= 1024L;
-                       what = "TB";
-               }
-
-               String tmp = Long.toString(b);
-               int dp = tmp.indexOf('.');
-               if (tmp.length() > dp + 2)
-                       return tmp.substring(0, dp + 3) + " " + what;
-               else
-                       return b + " " + what;
-       }
-
-       protected static CommandSource source;
-       public static boolean request_all = false;
-
-       @Override
-       public void run(String source, String[] message)
-       {
-               Server serv = Server.findServerAbsolute(source);
-               if (serv == null || message219.source == null || message[1].equals("?") == false)
-                       return;
-               else if (request_all || serv.bytes >= 1024)
-                       message219.source.reply("[MAP] " + source + " " + this.convertBytes(serv.bytes));
-       }
-}
-
-class message265 extends Message
-{
-       public message265()
-       {
-               super("265");
-       }
-
-       protected static CommandSource source;
-       public static int request_users = 0;
-       private static Pattern p = Pattern.compile("Current local users:? (\\d+)[ ,]*[Mm]ax:? (\\d+)");
-
-       @Override
-       public void run(String source, String[] message)
-       {
-               if (message265.source == null || message.length < 2)
-                       return;
-               
-               Matcher m = p.matcher(message[message.length - 1]);
-               m.matches();            
-               int users = Integer.parseInt(m.group(1));               
-
-               if (users >= request_users)
-                       message265.source.reply("[MAP] " + source + " " + users);
-       }
-}
-
-class commandMapBase extends Command
-{
-       private boolean full;
-
-       public commandMapBase(Plugin pkg, final String cmd, boolean full)
-       {
-               super(pkg, cmd, "View hub lag and routing information");
-               this.full = full;
-
-               this.requiresChannel(Moo.conf.staff_channels);
-               this.requiresChannel(Moo.conf.oper_channels);
-               this.requiresChannel(Moo.conf.admin_channels);
-       }
-
-       @Override
-       public void onHelp(CommandSource source)
-       {
-               source.notice("Syntax: " + this.getCommandName() + " [{ usercount | HUB server.name | FIND mask}]");
-               source.notice("Searches for information about servers.");
-               source.notice("Without any further arguments, the sendq (in bytes) of hubs is shown.");
-               if(!this.getCommandName().equalsIgnoreCase("!MAP-"))
-                       source.notice("The sendq output will be hidden unless it exceeds 1023 bytes, use !MAP- to see them.");
-               source.notice("If a user count is given, only servers and their user count with that amount of");
-               source.notice("(or more) users will be shown.");
-               source.notice("HUB server.name shows what other servers server.name is connected to.");
-               source.notice("FIND mask tries to find all servers matching the given mask.");
-       }
-
-       @Override
-       public void execute(CommandSource source, String[] params)
-       {
-               if (params.length == 1)
-               {
-                       for (Server s : Server.getServers())
-                               if (s.isHub())
-                               {
-                                       s.bytes = 0;
-                                       Moo.write("STATS", "?", s.getName());
-                               }
-                       message219.request_all = this.full;
-                       message219.source = source;
-               }
-               else if (params.length > 1)
-               {
-                       if (params[1].equalsIgnoreCase("HUB") && params.length > 2)
-                       {
-                               Server s = Server.findServer(params[2]);
-                               if (s == null)
-                                       source.reply("[MAP] Server " + params[2] + " not found");
-                               else
-                                       for (Iterator<Server> it = s.links.iterator(); it.hasNext();)
-                                               source.reply("[MAP] " + s.getName() + " is linked to " + it.next().getName());
-                       }
-                       else if (params[1].equalsIgnoreCase("FIND") && params.length > 2)
-                       {
-                               int count = 0;
-                               for (Server s : Server.getServers())
-                               {
-                                       if (Moo.matches(s.getName(), "*" + params[2] + "*"))
-                                       {
-                                               source.reply("[MAP] Server " + s.getName() + " matches " + params[2]);
-                                               ++count;
-                                       }
-                               }
-                               source.reply("[MAP] End of match, " + count + " servers found");
-                       }
-                       else
-                       {
-                               try
-                               {
-                                       int users = Integer.parseInt(params[1]);
-
-                                       for (Server s : Server.getServers())
-                                               Moo.write("USERS", s.getName());
-
-                                       message265.source = source;
-                                       message265.request_users = users;
-                               }
-                               catch (NumberFormatException ex)
-                               {
-                                       Server s = Server.findServer(params[1]);
-                                       if (s == null)
-                                               source.reply("[MAP] Server " + params[1] + " not found");
-                                       else
-                                       {
-                                               s.bytes = 0;
-                                               Moo.write("STATS", "?", s.getName());;
-                                               message219.request_all = this.full;
-                                               message219.source = source;
-                                       }
-                               }
-                       }
-               }
-       }
-}
-
-class commandMapRegular extends commandMapBase
-{
-       public commandMapRegular(Plugin pkg)
-       {
-               super(pkg, "!MAP", false);
-       }
-}
-
-class commandMapAll extends commandMapBase
-{
-       public commandMapAll(Plugin pkg)
-       {
-               super(pkg, "!MAP-" , true);
-       }
-}
-
-class CommandMap
-{
-       private message211 msg_211 = new message211();
-       private message219 msg_219 = new message219();
-       private message265 msg_265 = new message265();
-       private commandMapRegular map_reg;
-       private commandMapAll map_all;
-
-       public CommandMap(Plugin pkg)
-       {
-               this.map_reg = new commandMapRegular(pkg);
-               this.map_all = new commandMapAll(pkg);
-       }
-
-       public void remove()
-       {
-               this.msg_211.remove();
-               this.msg_219.remove();
-               this.msg_265.remove();
-
-               this.map_reg.remove();
-               this.map_all.remove();
-       }
-}
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/CommandSid.java b/commands/src/main/java/net/rizon/moo/plugin/commands/CommandSid.java
deleted file mode 100644 (file)
index ce42049..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-package net.rizon.moo.plugin.commands;
-
-import java.util.Random;
-
-import net.rizon.moo.Command;
-import net.rizon.moo.CommandSource;
-import net.rizon.moo.Moo;
-import net.rizon.moo.Plugin;
-import net.rizon.moo.Server;
-
-abstract class commandSidBase extends Command
-{
-       protected commandSidBase(Plugin pkg, final String name, final String desc)
-       {
-               super(pkg, name, desc);
-               this.requiresChannel(Moo.conf.admin_channels);
-       }
-
-       private static boolean inUse(final String sid)
-       {
-               for (Server s : Server.getServers())
-                       if (s.getSID() != null && s.getSID().equalsIgnoreCase(sid))
-                               return true;
-
-               return false;
-       }
-
-       protected static final Random rand  = new Random();
-
-       protected abstract String getSID();
-
-       @Override
-       public void execute(CommandSource source, String[] params)
-       {
-               String sid;
-
-               do
-                       sid = getSID();
-               while (inUse(sid));
-
-               source.reply("[SID] " + sid);
-       }
-}
-
-final class commandSidClient extends commandSidBase
-{
-       public commandSidClient(Plugin pkg)
-       {
-               super(pkg, "!SID", "Generates a new server ID");
-       }
-
-       @Override
-       public void onHelp(CommandSource source)
-       {
-               source.notice("Syntax: !SID");
-               source.notice("Generates a new SID for a client server. It will be checked not to be already in use.");
-       }
-
-       @Override
-       protected String getSID()
-       {
-               int i = rand.nextInt(100);
-               String s = Integer.toString(i);
-               if (s.length() == 1)
-                       s = "0" + s;
-               s += "C";
-               return s;
-       }
-}
-
-final class commandSidHub extends commandSidBase
-{
-       public commandSidHub(Plugin pkg)
-       {
-               super(pkg, "!HUBSID", "Generates a new hub server ID");
-       }
-
-       @Override
-       public void onHelp(CommandSource source)
-       {
-               source.notice("Syntax: !HUBSID");
-               source.notice("Generates a new SID for a hub. It will be checked not to be already in use.");
-       }
-
-       @Override
-       protected String getSID()
-       {
-               int i = rand.nextInt(100);
-               String s = Integer.toString(i);
-               if (s.length() == 1)
-                       s = "0" + s;
-               s += "H";
-               return s;
-       }
-}
-
-class CommandSid
-{
-       private commandSidClient sid_client;
-       private commandSidHub sid_hub;
-
-       public CommandSid(Plugin pkg)
-       {
-               this.sid_client = new commandSidClient(pkg);
-               this.sid_hub = new commandSidHub(pkg);
-       }
-
-       public void remove()
-       {
-               this.sid_client.remove();
-               this.sid_hub.remove();
-       }
-}
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/CommandWhy.java b/commands/src/main/java/net/rizon/moo/plugin/commands/CommandWhy.java
deleted file mode 100644 (file)
index 499439a..0000000
+++ /dev/null
@@ -1,191 +0,0 @@
-package net.rizon.moo.plugin.commands;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-import net.rizon.moo.Command;
-import net.rizon.moo.CommandSource;
-import net.rizon.moo.Message;
-import net.rizon.moo.Moo;
-import net.rizon.moo.Plugin;
-import net.rizon.moo.Server;
-
-class DNSBLChecker extends Thread
-{
-       private static final String DNSBLs[] = { "rbl.efnetrbl.org", "dnsbl.dronebl.org" };
-
-       private CommandSource source;
-
-       private String ip;
-
-       public DNSBLChecker(CommandSource source, final String ip)
-       {
-               this.source = source;
-               this.ip = ip;
-       }
-
-       @Override
-       public void run()
-       {
-               String octets[] = ip.split("\\.");
-               if (octets.length != 4)
-                       return;
-
-               String reverse_ip = octets[3] + "." + octets[2] + "." + octets[1] + "." + octets[0];
-
-               for (final String dnsbl : DNSBLs)
-               {
-                       String lookup_addr = reverse_ip + "." + dnsbl;
-
-                       try
-                       {
-                               InetAddress.getAllByName(lookup_addr);
-                               source.reply(this.ip + " is listed in " + dnsbl);
-                       }
-                       catch (UnknownHostException ex)
-                       {
-                       }
-               }
-       }
-}
-
-class message_216 extends Message
-{
-       public message_216()
-       {
-               super("216");
-       }
-
-       @Override
-       public void run(String source, String[] message)
-       {
-               if (message[1].equals("k") == false && message[1].equals("K") == false)
-                       return;
-               else if (CommandWhy.host_ip.isEmpty())
-                       return;
-               else if (message[2].equalsIgnoreCase(CommandWhy.host_ip) == false && message[2].equalsIgnoreCase(CommandWhy.host_host) == false)
-                       return;
-
-               CommandWhy.command_source.reply("[" + source + "] " + message[2] + " is " + message[1] + "-lined for: " + message[5]);
-
-               CommandWhy.host_ip = "";
-               CommandWhy.host_host = "";
-       }
-}
-
-class message_225 extends Message
-{
-       public message_225()
-       {
-               super("225");
-       }
-
-       @Override
-       public void run(String source, String[] message)
-       {
-               if (message[1].equals("d") == false)
-                       return;
-               else if (CommandWhy.host_ip.isEmpty())
-                       return;
-               else if (message[2].equalsIgnoreCase(CommandWhy.host_ip) == false && message[2].equalsIgnoreCase(CommandWhy.host_host) == false)
-                       return;
-
-               CommandWhy.command_source.reply("[" + source + "] " + message[2] + " is " + message[1] + "-lined for: " + message[3]);
-
-               CommandWhy.host_ip = "";
-               CommandWhy.host_host = "";
-       }
-}
-
-class message219_why extends Message
-{
-       public message219_why()
-       {
-               super("219");
-       }
-
-       @Override
-       public void run(String source, String[] message)
-       {
-               if (CommandWhy.host_ip.isEmpty())
-                       return;
-
-               CommandWhy.requested--;
-
-               if (CommandWhy.requested == 0)
-               {
-                       CommandWhy.command_source.reply(CommandWhy.host_ip + " (" + CommandWhy.host_host + ") is not banned");
-
-                       CommandWhy.host_ip = "";
-                       CommandWhy.host_host = "";
-               }
-       }
-}
-
-class CommandWhy extends Command
-{
-       @SuppressWarnings("unused")
-       private static final message_216 message216 = new message_216();
-       @SuppressWarnings("unused")
-       private static final message_225 message225 = new message_225();
-       @SuppressWarnings("unused")
-       private static final message219_why message219 = new message219_why();
-
-       protected static CommandSource command_source;
-       public static String host_ip = "", host_host = "";
-       public static int requested = 0;
-
-       public CommandWhy(Plugin pkg)
-       {
-               super(pkg, "!WHY", "Find why an IP is banned");
-
-               this.requiresChannel(Moo.conf.staff_channels);
-               this.requiresChannel(Moo.conf.oper_channels);
-               this.requiresChannel(Moo.conf.admin_channels);
-       }
-
-       @Override
-       public void onHelp(CommandSource source)
-       {
-               source.notice("Syntax: !WHY <ip/host>");
-               source.notice("Finds out why a certain IP is banned. It is looked for in DNSBLs and k/K/d:lines");
-       }
-
-       @Override
-       public void execute(CommandSource source, String[] params)
-       {
-               if (params.length <= 1)
-               {
-                       source.reply("Syntax: !WHY <ip/host>");
-                       return;
-               }
-
-               try
-               {
-                       InetAddress addr = InetAddress.getByName(params[1]);
-                       host_ip = addr.getHostAddress();
-                       host_host = addr.getHostName();
-               }
-               catch (UnknownHostException ex)
-               {
-                       source.reply("Invalid IP or host");
-                       return;
-               }
-
-
-               Thread t = new DNSBLChecker(source, host_ip);
-               t.start();
-
-               requested = 0;
-               for (Server s : Server.getServers())
-                       if (s.getSplit() == null && !s.isServices() && !s.isHub())
-                       {
-                               Moo.write("STATS", "k", s.getName());
-                               Moo.write("STATS", "K", s.getName());
-                               Moo.write("STATS", "d", s.getName());
-                               requested += 3;
-                       }
-
-               command_source = source;
-       }
-}
index fb24cee0157ab53bbb17878eb2e680dfe9c70fef..602e1937c820773b40900ed348a74ee59058bd7a 100644 (file)
@@ -1,17 +1,34 @@
 package net.rizon.moo.plugin.commands;
 
+import net.rizon.moo.plugin.commands.uptime.CommandUptime;
+import net.rizon.moo.plugin.commands.why.CommandWhy;
+import net.rizon.moo.plugin.commands.version.CommandVersions;
+import com.google.inject.multibindings.Multibinder;
+import java.util.List;
 import net.rizon.moo.Command;
-import net.rizon.moo.Moo;
+import net.rizon.moo.Message;
 import net.rizon.moo.Plugin;
-import net.rizon.moo.conf.Protocol;
+import net.rizon.moo.plugin.commands.map.CommandMapAll;
+import net.rizon.moo.plugin.commands.map.CommandMapRegular;
+import net.rizon.moo.plugin.commands.map.Message211;
+import net.rizon.moo.plugin.commands.map.Message219;
+import net.rizon.moo.plugin.commands.map.Message265;
+import net.rizon.moo.plugin.commands.sid.CommandSidClient;
+import net.rizon.moo.plugin.commands.sid.CommandSidHub;
+import net.rizon.moo.plugin.commands.uptime.Message242;
+import net.rizon.moo.plugin.commands.version.CommandVersion;
+import net.rizon.moo.plugin.commands.version.Message351;
+import net.rizon.moo.plugin.commands.why.Message216;
+import net.rizon.moo.plugin.commands.why.Message219Why;
+import net.rizon.moo.plugin.commands.why.Message225;
 
 public class commands extends Plugin
 {
-       private Command climit, oline, slackers, soa, uptime, why;
-       private CommandTime time;
-       private CommandMap map;
-       private CommandSid sid;
-       private CommandVersions version;
+//     private Command climit, oline, slackers, soa, uptime, why;
+//     private CommandTime time;
+//     private CommandMap map;
+//     private CommandSid sid;
+//     private CommandVersions version;
 
        public commands()
        {
@@ -21,45 +38,68 @@ public class commands extends Plugin
        @Override
        public void start() throws Exception
        {
-               if (Moo.conf.general.protocol == Protocol.PLEXUS)
-               {
-                       climit = new CommandClimit(this);
-                       map = new CommandMap(this);
-                       oline = new CommandOline(this);
-                       sid = new CommandSid(this);
-                       slackers = new CommandSlackers(this);
-               }
-               soa = new CommandSoa(this);
-               time = new CommandTime(this);
-               uptime = new CommandUptime(this);
-               if (Moo.conf.general.protocol == Protocol.PLEXUS)
-               {
-                       version = new CommandVersions(this);
-                       why = new CommandWhy(this);
-               }
+//             if (Moo.conf.general.protocol == Protocol.PLEXUS)
+//             {
+//                     climit = new CommandClimit(this);
+//                     map = new CommandMap(this);
+//                     oline = new CommandOline(this);
+//                     sid = new CommandSid(this);
+//                     slackers = new CommandSlackers(this);
+//             }
+//             soa = new CommandSoa(this);
+//             time = new CommandTime(this);
+//             uptime = new CommandUptime(this);
+//             if (Moo.conf.general.protocol == Protocol.PLEXUS)
+//             {
+//                     version = new CommandVersions(this);
+//                     why = new CommandWhy(this);
+//             }
        }
 
        @Override
        public void stop()
        {
-               if (climit != null)
-                       climit.remove();
-               if (map != null)
-                       map.remove();
-               if (oline != null)
-                       oline.remove();
-               if (sid != null)
-                       sid.remove();
-               if (slackers != null)
-                       slackers.remove();
-               this.soa.remove();
-               this.time.remove();
-               this.uptime.remove();
-               if (version != null)
-                       this.version.remove();
-               if (why != null)
-                       this.why.remove();
-               if (time != null)
-                       time.remove();
+       }
+
+       @Override
+       public List<Command> getCommands()
+       {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       @Override
+       protected void configure()
+       {
+               bind(commands.class).toInstance(this);
+
+               Multibinder<Command> commandBinder = Multibinder.newSetBinder(binder(), Command.class);
+               Multibinder<Message> messageBinder = Multibinder.newSetBinder(binder(), Message.class);
+
+               commandBinder.addBinding().to(CommandClimit.class);
+               commandBinder.addBinding().to(CommandOline.class);
+               commandBinder.addBinding().to(CommandSlackers.class);
+               commandBinder.addBinding().to(CommandSoa.class);
+               commandBinder.addBinding().to(CommandTime.class);
+
+               commandBinder.addBinding().to(CommandMapAll.class);
+               commandBinder.addBinding().to(CommandMapRegular.class);
+               messageBinder.addBinding().to(Message211.class);
+               messageBinder.addBinding().to(Message219.class);
+               messageBinder.addBinding().to(Message265.class);
+
+               commandBinder.addBinding().to(CommandVersion.class);
+               commandBinder.addBinding().to(CommandVersions.class);
+               messageBinder.addBinding().to(Message351.class);
+
+               commandBinder.addBinding().to(CommandSidClient.class);
+               commandBinder.addBinding().to(CommandSidHub.class);
+
+               commandBinder.addBinding().to(CommandWhy.class);
+               messageBinder.addBinding().to(Message216.class);
+               messageBinder.addBinding().to(Message219Why.class);
+               messageBinder.addBinding().to(Message225.class);
+
+               commandBinder.addBinding().to(CommandUptime.class);
+               messageBinder.addBinding().to(Message242.class);
        }
 }
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/map/CommandMap.java b/commands/src/main/java/net/rizon/moo/plugin/commands/map/CommandMap.java
new file mode 100755 (executable)
index 0000000..9e69774
--- /dev/null
@@ -0,0 +1,114 @@
+package net.rizon.moo.plugin.commands.map;
+
+import com.google.inject.Inject;
+import java.util.Iterator;
+
+import net.rizon.moo.Command;
+import net.rizon.moo.CommandSource;
+import net.rizon.moo.conf.Config;
+import net.rizon.moo.irc.Protocol;
+import net.rizon.moo.irc.Server;
+import net.rizon.moo.irc.ServerManager;
+import net.rizon.moo.util.Match;
+
+abstract class CommandMap extends Command
+{
+       @Inject
+       private ServerManager serverManager;
+
+       @Inject
+       private Protocol protocol;
+
+       private boolean full;
+
+       public CommandMap(Config conf, String cmd, boolean full)
+       {
+               super(cmd, "View hub lag and routing information");
+               this.full = full;
+
+               this.requiresChannel(conf.staff_channels);
+               this.requiresChannel(conf.oper_channels);
+               this.requiresChannel(conf.admin_channels);
+       }
+
+       @Override
+       public void onHelp(CommandSource source)
+       {
+               source.notice("Syntax: " + this.getCommandName() + " [{ usercount | HUB server.name | FIND mask}]");
+               source.notice("Searches for information about servers.");
+               source.notice("Without any further arguments, the sendq (in bytes) of hubs is shown.");
+               if(!this.getCommandName().equalsIgnoreCase("!MAP-"))
+                       source.notice("The sendq output will be hidden unless it exceeds 1023 bytes, use !MAP- to see them.");
+               source.notice("If a user count is given, only servers and their user count with that amount of");
+               source.notice("(or more) users will be shown.");
+               source.notice("HUB server.name shows what other servers server.name is connected to.");
+               source.notice("FIND mask tries to find all servers matching the given mask.");
+       }
+
+       @Override
+       public void execute(CommandSource source, String[] params)
+       {
+               if (params.length == 1)
+               {
+                       for (Server s : serverManager.getServers())
+                               if (s.isHub())
+                               {
+                                       s.bytes = 0;
+                                       protocol.write("STATS", "?", s.getName());
+                               }
+                       Message219.request_all = this.full;
+                       Message219.source = source;
+               }
+               else if (params.length > 1)
+               {
+                       if (params[1].equalsIgnoreCase("HUB") && params.length > 2)
+                       {
+                               Server s = serverManager.findServer(params[2]);
+                               if (s == null)
+                                       source.reply("[MAP] Server " + params[2] + " not found");
+                               else
+                                       for (Iterator<Server> it = s.links.iterator(); it.hasNext();)
+                                               source.reply("[MAP] " + s.getName() + " is linked to " + it.next().getName());
+                       }
+                       else if (params[1].equalsIgnoreCase("FIND") && params.length > 2)
+                       {
+                               int count = 0;
+                               for (Server s : serverManager.getServers())
+                               {
+                                       if (Match.matches(s.getName(), "*" + params[2] + "*"))
+                                       {
+                                               source.reply("[MAP] Server " + s.getName() + " matches " + params[2]);
+                                               ++count;
+                                       }
+                               }
+                               source.reply("[MAP] End of match, " + count + " servers found");
+                       }
+                       else
+                       {
+                               try
+                               {
+                                       int users = Integer.parseInt(params[1]);
+
+                                       for (Server s : serverManager.getServers())
+                                               protocol.write("USERS", s.getName());
+
+                                       Message265.source = source;
+                                       Message265.request_users = users;
+                               }
+                               catch (NumberFormatException ex)
+                               {
+                                       Server s = serverManager.findServer(params[1]);
+                                       if (s == null)
+                                               source.reply("[MAP] Server " + params[1] + " not found");
+                                       else
+                                       {
+                                               s.bytes = 0;
+                                               protocol.write("STATS", "?", s.getName());;
+                                               Message219.request_all = this.full;
+                                               Message219.source = source;
+                                       }
+                               }
+                       }
+               }
+       }
+}
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/map/CommandMapAll.java b/commands/src/main/java/net/rizon/moo/plugin/commands/map/CommandMapAll.java
new file mode 100644 (file)
index 0000000..d7a4665
--- /dev/null
@@ -0,0 +1,13 @@
+package net.rizon.moo.plugin.commands.map;
+
+import com.google.inject.Inject;
+import net.rizon.moo.conf.Config;
+
+public class CommandMapAll extends CommandMap
+{
+       @Inject
+       public CommandMapAll(Config conf)
+       {
+               super(conf, "!MAP-" , true);
+       }
+}
\ No newline at end of file
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/map/CommandMapRegular.java b/commands/src/main/java/net/rizon/moo/plugin/commands/map/CommandMapRegular.java
new file mode 100644 (file)
index 0000000..25db446
--- /dev/null
@@ -0,0 +1,13 @@
+package net.rizon.moo.plugin.commands.map;
+
+import com.google.inject.Inject;
+import net.rizon.moo.conf.Config;
+
+public class CommandMapRegular extends CommandMap
+{
+       @Inject
+       public CommandMapRegular(Config conf)
+       {
+               super(conf, "!MAP", false);
+       }
+}
\ No newline at end of file
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/map/Message211.java b/commands/src/main/java/net/rizon/moo/plugin/commands/map/Message211.java
new file mode 100644 (file)
index 0000000..3c65b6d
--- /dev/null
@@ -0,0 +1,41 @@
+package net.rizon.moo.plugin.commands.map;
+
+import com.google.inject.Inject;
+import net.rizon.moo.Message;
+import net.rizon.moo.io.IRCMessage;
+import net.rizon.moo.irc.Server;
+import net.rizon.moo.irc.ServerManager;
+
+public class Message211 extends Message
+{
+       @Inject
+       private ServerManager serverManager;
+
+       public Message211()
+       {
+               super("211");
+       }
+
+       /*
+        * 0: moo
+        * 1: services.rizon.net[unknown@255.255.255.255]
+        * 2: 0  // Buf length
+        * 3: 24 // send.messages
+        * 4: 1  // send.bytes
+        * 5: 40 // recv.messages
+        * 6: 2  // recv.bytes
+        * 7: 48 0 TS GLN TBURST SVS UNKLN KLN KNOCK ENCAP CHW IE EX TS6 EOB QS
+        */
+       @Override
+       public void run(IRCMessage message)
+       {
+               long bytes = Long.parseLong(message.getParams()[2]);
+               Server serv = serverManager.findServerAbsolute(message.getSource());
+               if (serv == null)
+               {
+                       serv = new Server(message.getSource());
+                       serverManager.insertServer(serv);
+               }
+               serv.bytes += bytes;
+       }
+}
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/map/Message219.java b/commands/src/main/java/net/rizon/moo/plugin/commands/map/Message219.java
new file mode 100644 (file)
index 0000000..b5ef604
--- /dev/null
@@ -0,0 +1,67 @@
+package net.rizon.moo.plugin.commands.map;
+
+import com.google.inject.Inject;
+import net.rizon.moo.CommandSource;
+import net.rizon.moo.Message;
+import net.rizon.moo.io.IRCMessage;
+import net.rizon.moo.irc.Server;
+import net.rizon.moo.irc.ServerManager;
+
+public class Message219 extends Message
+{
+       @Inject
+       private ServerManager serverManager;
+
+       public Message219()
+       {
+               super("219");
+       }
+
+       private String convertBytes(long b)
+       {
+               String what = "bytes";
+
+               if (b > 1024L)
+               {
+                       b /= 1024L;
+                       what = "KB";
+               }
+               if (b > 1024L)
+               {
+                       b /= 1024L;
+                       what = "MB";
+               }
+               if (b > 1024L)
+               {
+                       b /= 1024L;
+                       what = "GB";
+               }
+               if (b > 1024L)
+               {
+                       b /= 1024L;
+                       what = "TB";
+               }
+
+               String tmp = Long.toString(b);
+               int dp = tmp.indexOf('.');
+               if (tmp.length() > dp + 2)
+                       return tmp.substring(0, dp + 3) + " " + what;
+               else
+                       return b + " " + what;
+       }
+
+       protected static CommandSource source;
+       public static boolean request_all = false;
+
+       @Override
+       public void run(IRCMessage message)
+       {
+               Server serv = serverManager.findServerAbsolute(message.getSource());
+
+               if (serv == null || source == null || message.getParams()[1].equals("?") == false)
+                       return;
+
+               if (request_all || serv.bytes >= 1024)
+                       source.reply("[MAP] " + message.getSource() + " " + this.convertBytes(serv.bytes));
+       }
+}
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/map/Message265.java b/commands/src/main/java/net/rizon/moo/plugin/commands/map/Message265.java
new file mode 100644 (file)
index 0000000..dcc985b
--- /dev/null
@@ -0,0 +1,33 @@
+package net.rizon.moo.plugin.commands.map;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import net.rizon.moo.CommandSource;
+import net.rizon.moo.Message;
+import net.rizon.moo.io.IRCMessage;
+
+public class Message265 extends Message
+{
+       public Message265()
+       {
+               super("265");
+       }
+
+       protected static CommandSource source;
+       public static int request_users = 0;
+       private static Pattern p = Pattern.compile("Current local users:? (\\d+)[ ,]*[Mm]ax:? (\\d+)");
+
+       @Override
+       public void run(IRCMessage message)
+       {
+               if (source == null || message.getParams().length < 2)
+                       return;
+
+               Matcher m = p.matcher(message.getParams()[message.getParams().length - 1]);
+               m.matches();
+               int users = Integer.parseInt(m.group(1));
+
+               if (users >= request_users)
+                       source.reply("[MAP] " + message.getSource() + " " + users);
+       }
+}
\ No newline at end of file
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/sid/CommandSidBase.java b/commands/src/main/java/net/rizon/moo/plugin/commands/sid/CommandSidBase.java
new file mode 100644 (file)
index 0000000..e34d9ba
--- /dev/null
@@ -0,0 +1,46 @@
+package net.rizon.moo.plugin.commands.sid;
+
+import com.google.inject.Inject;
+import java.util.Random;
+import net.rizon.moo.Command;
+import net.rizon.moo.CommandSource;
+import net.rizon.moo.conf.Config;
+import net.rizon.moo.irc.Server;
+import net.rizon.moo.irc.ServerManager;
+
+abstract class CommandSidBase extends Command
+{
+       @Inject
+       private ServerManager serverManager;
+
+       protected CommandSidBase(Config conf, String name, String desc)
+       {
+               super(name, desc);
+               this.requiresChannel(conf.admin_channels);
+       }
+
+       private boolean inUse(final String sid)
+       {
+               for (Server s : serverManager.getServers())
+                       if (s.getSID() != null && s.getSID().equalsIgnoreCase(sid))
+                               return true;
+
+               return false;
+       }
+
+       protected static final Random rand  = new Random();
+
+       protected abstract String getSID();
+
+       @Override
+       public void execute(CommandSource source, String[] params)
+       {
+               String sid;
+
+               do
+                       sid = getSID();
+               while (inUse(sid));
+
+               source.reply("[SID] " + sid);
+       }
+}
\ No newline at end of file
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/sid/CommandSidClient.java b/commands/src/main/java/net/rizon/moo/plugin/commands/sid/CommandSidClient.java
new file mode 100644 (file)
index 0000000..1d4c3f4
--- /dev/null
@@ -0,0 +1,32 @@
+package net.rizon.moo.plugin.commands.sid;
+
+import com.google.inject.Inject;
+import net.rizon.moo.CommandSource;
+import net.rizon.moo.conf.Config;
+
+public class CommandSidClient extends CommandSidBase
+{
+       @Inject
+       public CommandSidClient(Config conf)
+       {
+               super(conf, "!SID", "Generates a new server ID");
+       }
+
+       @Override
+       public void onHelp(CommandSource source)
+       {
+               source.notice("Syntax: !SID");
+               source.notice("Generates a new SID for a client server. It will be checked not to be already in use.");
+       }
+
+       @Override
+       protected String getSID()
+       {
+               int i = rand.nextInt(100);
+               String s = Integer.toString(i);
+               if (s.length() == 1)
+                       s = "0" + s;
+               s += "C";
+               return s;
+       }
+}
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/sid/CommandSidHub.java b/commands/src/main/java/net/rizon/moo/plugin/commands/sid/CommandSidHub.java
new file mode 100644 (file)
index 0000000..8bd4bb2
--- /dev/null
@@ -0,0 +1,32 @@
+package net.rizon.moo.plugin.commands.sid;
+
+import com.google.inject.Inject;
+import net.rizon.moo.CommandSource;
+import net.rizon.moo.conf.Config;
+
+public class CommandSidHub extends CommandSidBase
+{
+       @Inject
+       public CommandSidHub(Config conf)
+       {
+               super(conf, "!HUBSID", "Generates a new hub server ID");
+       }
+
+       @Override
+       public void onHelp(CommandSource source)
+       {
+               source.notice("Syntax: !HUBSID");
+               source.notice("Generates a new SID for a hub. It will be checked not to be already in use.");
+       }
+
+       @Override
+       protected String getSID()
+       {
+               int i = rand.nextInt(100);
+               String s = Integer.toString(i);
+               if (s.length() == 1)
+                       s = "0" + s;
+               s += "H";
+               return s;
+       }
+}
\ No newline at end of file
similarity index 62%
rename from commands/src/main/java/net/rizon/moo/plugin/commands/CommandUptime.java
rename to commands/src/main/java/net/rizon/moo/plugin/commands/uptime/CommandUptime.java
index 03a67db6c921f4d95eac497a219255a49092e2b4..a770bf1744f4be34879cefcd2cca724fbc7c0e7f 100644 (file)
@@ -1,79 +1,37 @@
-package net.rizon.moo.plugin.commands;
+package net.rizon.moo.plugin.commands.uptime;
 
+import com.google.inject.Inject;
 import java.util.Date;
-import java.util.HashSet;
 
 import net.rizon.moo.Command;
 import net.rizon.moo.CommandSource;
 import net.rizon.moo.Message;
 import net.rizon.moo.Moo;
-import net.rizon.moo.Plugin;
-import net.rizon.moo.Server;
 import net.rizon.moo.Split;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import net.rizon.moo.conf.Config;
+import net.rizon.moo.irc.Protocol;
+import net.rizon.moo.irc.Server;
+import net.rizon.moo.irc.ServerManager;
+import net.rizon.moo.util.Match;
+import net.rizon.moo.util.TimeDifference;
 
-class message242 extends Message
-{
-       protected static CommandSource source;
-       public static HashSet<String> waiting_for = new HashSet<String>();
-
-       public message242()
-       {
-               super("242");
-       }
-
-       @Override
-       public void run(String source, String[] message)
-       {
-               Server s = Server.findServerAbsolute(source);
-               if (s == null)
-                       s = new Server(source);
-
-               String upstr = message[1];
-               String[] tokens = upstr.split(" ");
-               String[] times = tokens[4].split(":");
-
-               int days, hours, mins, secs;
-               try
-               {
-                       days = Integer.parseInt(tokens[2]);
-                       hours = Integer.parseInt(times[0]);
-                       mins = Integer.parseInt(times[1]);
-                       secs = Integer.parseInt(times[2]);
-               }
-               catch (NumberFormatException ex)
-               {
-                       CommandUptime.logger.warn("Unable to parse 242", ex);
-                       return;
-               }
-
-               long total_ago = secs + (mins * 60) + (hours * 60 * 60) + (days * 60 * 60 * 24 );
-               s.uptime = new Date(System.currentTimeMillis() - (total_ago * 1000L));
-
-               waiting_for.remove(s.getName());
-
-               if (waiting_for.isEmpty())
-               {
-                       CommandUptime.post_update(message242.source);
-               }
-       }
-}
 
 class CommandUptime extends Command
 {
-       static final Logger logger = LoggerFactory.getLogger(CommandUptime.class);
-       
-       @SuppressWarnings("unused")
-       private static message242 message_242 = new message242();
+       @Inject
+       private ServerManager serverManager;
+
+       @Inject
+       private Protocol protocol;
 
-       public CommandUptime(Plugin pkg)
+       @Inject
+       public CommandUptime(Config conf)
        {
-               super(pkg, "!UPTIME", "View server uptimes");
+               super("!UPTIME", "View server uptimes");
 
-               this.requiresChannel(Moo.conf.staff_channels);
-               this.requiresChannel(Moo.conf.oper_channels);
-               this.requiresChannel(Moo.conf.admin_channels);
+               this.requiresChannel(conf.staff_channels);
+               this.requiresChannel(conf.oper_channels);
+               this.requiresChannel(conf.admin_channels);
        }
 
        private static boolean only_extremes;
@@ -112,26 +70,26 @@ class CommandUptime extends Command
                else
                        only_extremes = true;
 
-               message242.waiting_for.clear();
-               for (Server s : Server.getServers())
+               Message242.waiting_for.clear();
+               for (Server s : serverManager.getServers())
                {
                        if (s.isServices() == false && s.getSplit() == null)
                        {
-                               Moo.write("STATS", "u", s.getName());
-                               message242.waiting_for.add(s.getName());
+                               protocol.write("STATS", "u", s.getName());
+                               Message242.waiting_for.add(s.getName());
                        }
                }
 
-               message242.source = source;
+               Message242.source = source;
        }
 
-       private static Split findLastSplit(Server s)
+       private Split findLastSplit(Server s)
        {
                for (int i = s.getSplits().length; i > 0; --i)
                {
                        Split sp = s.getSplits()[i - 1];
 
-                       Server serv = Server.findServerAbsolute(sp.from);
+                       Server serv = serverManager.findServerAbsolute(sp.from);
                        if (serv == null)
                                continue;
 
@@ -152,10 +110,10 @@ class CommandUptime extends Command
                return null;
        }
 
-       private static int dashesFor(Server s)
+       private int dashesFor(Server s)
        {
                int longest = 0;
-               for (Server s2 : Server.getServers())
+               for (Server s2 : serverManager.getServers())
                {
                        int l = s2.getName().length();
                        if (l > longest)
@@ -165,13 +123,13 @@ class CommandUptime extends Command
                return longest - s.getName().length() + 2;
        }
 
-       public static void post_update(CommandSource source)
+       public void post_update(CommandSource source)
        {
                Date highest = null, lowest = null;
                Split highest_sp = null, lowest_sp = null;
                Date now = new Date();
 
-               for (Server s : Server.getServers())
+               for (Server s : serverManager.getServers())
                {
                        if (s.isServices() || s.uptime == null)
                                continue;
@@ -189,11 +147,11 @@ class CommandUptime extends Command
                }
 
                boolean shown = false;
-               for (Server s : Server.getServers())
+               for (Server s : serverManager.getServers())
                {
                        if (s.isServices() || s.uptime == null)
                                continue;
-                       else if (want_server != null && Moo.matches(s.getName(), "*" + want_server + "*") == false)
+                       else if (want_server != null && Match.matches(s.getName(), "*" + want_server + "*") == false)
                                continue;
 
                        boolean is_extreme = false;
@@ -232,7 +190,7 @@ class CommandUptime extends Command
                                        buffer += Message.COLOR_RED;
                                        is_extreme = true;
                                }
-                               buffer += Moo.difference(now, sp.when);
+                               buffer += TimeDifference.difference(now, sp.when);
                                buffer += Message.COLOR_END;
                        }
 
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/uptime/Message242.java b/commands/src/main/java/net/rizon/moo/plugin/commands/uptime/Message242.java
new file mode 100644 (file)
index 0000000..856202a
--- /dev/null
@@ -0,0 +1,71 @@
+package net.rizon.moo.plugin.commands.uptime;
+
+import com.google.inject.Inject;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+import net.rizon.moo.CommandSource;
+import net.rizon.moo.Message;
+import net.rizon.moo.io.IRCMessage;
+import net.rizon.moo.irc.Server;
+import net.rizon.moo.irc.ServerManager;
+import org.slf4j.Logger;
+
+public class Message242 extends Message
+{
+       @Inject
+       private static Logger logger;
+       
+       @Inject
+       private ServerManager serverManager;
+
+       @Inject
+       private CommandUptime commandUptime;
+       
+       protected static CommandSource source;
+       public static Set<String> waiting_for = new HashSet<>();
+
+       public Message242()
+       {
+               super("242");
+       }
+
+       @Override
+       public void run(IRCMessage message)
+       {
+               Server s = serverManager.findServerAbsolute(message.getSource());
+               if (s == null)
+               {
+                       s = new Server(message.getSource());
+                       serverManager.insertServer(s);
+               }
+
+               String upstr = message.getParams()[1];
+               String[] tokens = upstr.split(" ");
+               String[] times = tokens[4].split(":");
+
+               int days, hours, mins, secs;
+               try
+               {
+                       days = Integer.parseInt(tokens[2]);
+                       hours = Integer.parseInt(times[0]);
+                       mins = Integer.parseInt(times[1]);
+                       secs = Integer.parseInt(times[2]);
+               }
+               catch (NumberFormatException ex)
+               {
+                       logger.warn("Unable to parse 242", ex);
+                       return;
+               }
+
+               long total_ago = secs + (mins * 60) + (hours * 60 * 60) + (days * 60 * 60 * 24 );
+               s.uptime = new Date(System.currentTimeMillis() - (total_ago * 1000L));
+
+               waiting_for.remove(s.getName());
+
+               if (waiting_for.isEmpty())
+               {
+                       commandUptime.post_update(Message242.source);
+               }
+       }
+}
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/version/CommandVersion.java b/commands/src/main/java/net/rizon/moo/plugin/commands/version/CommandVersion.java
new file mode 100644 (file)
index 0000000..c1b973c
--- /dev/null
@@ -0,0 +1,14 @@
+package net.rizon.moo.plugin.commands.version;
+
+import com.google.inject.Inject;
+import net.rizon.moo.conf.Config;
+
+
+public class CommandVersion extends CommandVersionBase
+{
+       @Inject
+       public CommandVersion(Config conf, String command)
+       {
+               super(conf, "!VERSION");
+       }
+}
\ No newline at end of file
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/version/CommandVersionBase.java b/commands/src/main/java/net/rizon/moo/plugin/commands/version/CommandVersionBase.java
new file mode 100644 (file)
index 0000000..b1e8dda
--- /dev/null
@@ -0,0 +1,74 @@
+package net.rizon.moo.plugin.commands.version;
+
+import com.google.inject.Inject;
+import net.rizon.moo.Command;
+import net.rizon.moo.CommandSource;
+import net.rizon.moo.conf.Config;
+import net.rizon.moo.irc.Protocol;
+import net.rizon.moo.irc.Server;
+import net.rizon.moo.irc.ServerManager;
+import org.slf4j.Logger;
+
+abstract class CommandVersionBase extends Command
+{
+       @Inject
+       protected static Logger logger;
+
+       @Inject
+       private ServerManager serverManager;
+
+       @Inject
+       private Protocol protocol;
+
+       static Server want_server = null;
+
+       public static boolean onlyOld;
+
+       public CommandVersionBase(Config conf, String command)
+       {
+               super(command, "View the IRCd versions");
+
+               this.requiresChannel(conf.oper_channels);
+               this.requiresChannel(conf.admin_channels);
+       }
+
+       @Override
+       public void onHelp(CommandSource source)
+       {
+               source.notice("Syntax: !VERSIONS [OLD|server]");
+               source.notice("This command gets the version and serno of all currently linked IRCds and lists them.");
+               source.notice("If OLD is given as a parameter, only versions that aren't the latest will be shown.");
+               source.notice("If a server name is given, the version for that server will be shown.");
+       }
+
+       @Override
+       public void execute(CommandSource source, String[] params)
+       {
+               if (params.length > 1)
+               {
+                       if (params[1].equalsIgnoreCase("OLD"))
+                       {
+                               onlyOld = true;
+                               want_server = null;
+                       }
+                       else
+                       {
+                               onlyOld = false;
+                               want_server = serverManager.findServer(params[1]);
+                       }
+               }
+               else
+                       want_server = null;
+
+               for (Server s : serverManager.getServers())
+               {
+                       if (s.isServices() == false)
+                       {
+                               protocol.write("VERSION", s.getName());
+                               Message351.waiting_for.add(s.getName());
+                       }
+               }
+
+               Message351.command_source = source;
+       }
+}
\ No newline at end of file
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/version/CommandVersions.java b/commands/src/main/java/net/rizon/moo/plugin/commands/version/CommandVersions.java
new file mode 100644 (file)
index 0000000..24bbacb
--- /dev/null
@@ -0,0 +1,14 @@
+package net.rizon.moo.plugin.commands.version;
+
+import com.google.inject.Inject;
+import net.rizon.moo.conf.Config;
+
+
+public class CommandVersions extends CommandVersionBase
+{
+       @Inject
+       public CommandVersions(Config conf, String command)
+       {
+               super(conf, "!VERSIONS");
+       }
+}
\ No newline at end of file
similarity index 53%
rename from commands/src/main/java/net/rizon/moo/plugin/commands/CommandVersions.java
rename to commands/src/main/java/net/rizon/moo/plugin/commands/version/Message351.java
index 763cbcac02d9d299a0510a590671f914f9d78ff9..27bcfa3e9f033e5bd5885b9ae585851d8f88f3a9 100644 (file)
@@ -1,27 +1,32 @@
-package net.rizon.moo.plugin.commands;
+package net.rizon.moo.plugin.commands.version;
 
-import java.util.Map;
-import java.util.HashSet;
+import com.google.inject.Inject;
 import java.util.HashMap;
-
-import net.rizon.moo.Command;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 import net.rizon.moo.CommandSource;
 import net.rizon.moo.Message;
-import net.rizon.moo.Moo;
-import net.rizon.moo.Plugin;
-import net.rizon.moo.Server;
+import net.rizon.moo.io.IRCMessage;
+import net.rizon.moo.irc.Server;
+import net.rizon.moo.irc.ServerManager;
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-class message351 extends Message
+public class Message351 extends Message
 {
-       public message351()
+       @Inject
+       private static Logger logger;
+       
+       @Inject
+       private ServerManager serverManager;
+       
+       public Message351()
        {
                super("351");
        }
 
        protected static CommandSource command_source;
-       public static HashSet<String> waiting_for = new HashSet<String>();
+       public static Set<String> waiting_for = new HashSet<>();
        private static Map<Integer, Integer> max_vers = new HashMap<>();
 
        final class ServerVersion
@@ -85,10 +90,10 @@ class message351 extends Message
                return color;
        }
 
-       private static int dashesFor(Server s)
+       private int dashesFor(Server s)
        {
                int longest = 0;
-               for (Server s2 : Server.getServers())
+               for (Server s2 : serverManager.getServers())
                {
                        int l = s2.getName().length();
                        if (l > longest)
@@ -99,16 +104,19 @@ class message351 extends Message
        }
 
        @Override
-       public void run(String source, String[] msg)
+       public void run(IRCMessage message)
        {
-               Server s = Server.findServerAbsolute(source);
+               Server s = serverManager.findServerAbsolute(message.getSource());
                if (s == null)
-                       s = new Server(source);
+               {
+                       s = new Server(message.getSource());
+                       serverManager.insertServer(s);
+               }
 
-               if (commandVersionsBase.want_server != null && commandVersionsBase.want_server != s)
+               if (CommandVersionBase.want_server != null && CommandVersionBase.want_server != s)
                        return;
 
-               String tok = msg[1];
+               String tok = message.getParams()[1];
 
                int pos = tok.length() - 1;
                for (; pos > 0 && tok.charAt(pos) != '('; --pos);
@@ -136,10 +144,10 @@ class message351 extends Message
                        if (command_source == null)
                                return;
 
-                       if (commandVersionsBase.onlyOld && isMaxVersion(ver_num))
+                       if (CommandVersionBase.onlyOld && isMaxVersion(ver_num))
                                return;
 
-                       String buf = "[VERSION] " + source + " ";
+                       String buf = "[VERSION] " + message.getSource() + " ";
                        for (int i = 0, dashes = dashesFor(s); i < dashes; ++i)
                                buf += "-";
                        buf += " ";
@@ -156,84 +164,7 @@ class message351 extends Message
                }
                catch (Exception ex)
                {
-                       commandVersionsBase.logger.warn("Unable to parse 351", ex);
+                       logger.warn("Unable to parse 351", ex);
                }
        }
 }
-
-class commandVersionsBase extends Command
-{
-       static final Logger logger = LoggerFactory.getLogger(commandVersionsBase.class);
-       
-       @SuppressWarnings("unused")
-       private static message351 msg_351 = new message351();
-       static Server want_server = null;
-
-       public static boolean onlyOld;
-
-       public commandVersionsBase(Plugin pkg, final String command)
-       {
-               super(pkg, command, "View the IRCd versions");
-
-               this.requiresChannel(Moo.conf.oper_channels);
-               this.requiresChannel(Moo.conf.admin_channels);
-       }
-
-       @Override
-       public void onHelp(CommandSource source)
-       {
-               source.notice("Syntax: !VERSIONS [OLD|server]");
-               source.notice("This command gets the version and serno of all currently linked IRCds and lists them.");
-               source.notice("If OLD is given as a parameter, only versions that aren't the latest will be shown.");
-               source.notice("If a server name is given, the version for that server will be shown.");
-       }
-
-       @Override
-       public void execute(CommandSource source, String[] params)
-       {
-               if (params.length > 1)
-               {
-                       if (params[1].equalsIgnoreCase("OLD"))
-                       {
-                               onlyOld = true;
-                               want_server = null;
-                       }
-                       else
-                       {
-                               onlyOld = false;
-                               want_server = Server.findServer(params[1]);
-                       }
-               }
-               else
-                       want_server = null;
-
-               for (Server s : Server.getServers())
-               {
-                       if (s.isServices() == false)
-                       {
-                               Moo.write("VERSION", s.getName());
-                               message351.waiting_for.add(s.getName());
-                       }
-               }
-
-               message351.command_source = source;
-       }
-}
-
-class CommandVersions
-{
-       private Command vs, v;
-
-       public CommandVersions(Plugin pkg)
-       {
-               vs = new commandVersionsBase(pkg, "!VERSIONS");
-               // Some people can't type for their life...
-               v = new commandVersionsBase(pkg, "!VERSION");
-       }
-
-       public void remove()
-       {
-               vs.remove();
-               v.remove();
-       }
-}
\ No newline at end of file
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/why/CommandWhy.java b/commands/src/main/java/net/rizon/moo/plugin/commands/why/CommandWhy.java
new file mode 100644 (file)
index 0000000..1d9ff54
--- /dev/null
@@ -0,0 +1,120 @@
+package net.rizon.moo.plugin.commands.why;
+
+import com.google.inject.Inject;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import net.rizon.moo.Command;
+import net.rizon.moo.CommandSource;
+import net.rizon.moo.Moo;
+import net.rizon.moo.conf.Config;
+import net.rizon.moo.irc.Protocol;
+import net.rizon.moo.irc.Server;
+import net.rizon.moo.irc.ServerManager;
+
+class DNSBLChecker extends Thread
+{
+       private static final String DNSBLs[] = { "rbl.efnetrbl.org", "dnsbl.dronebl.org" };
+
+       private CommandSource source;
+
+       private String ip;
+
+       public DNSBLChecker(CommandSource source, final String ip)
+       {
+               this.source = source;
+               this.ip = ip;
+       }
+
+       @Override
+       public void run()
+       {
+               String octets[] = ip.split("\\.");
+               if (octets.length != 4)
+                       return;
+
+               String reverse_ip = octets[3] + "." + octets[2] + "." + octets[1] + "." + octets[0];
+
+               for (final String dnsbl : DNSBLs)
+               {
+                       String lookup_addr = reverse_ip + "." + dnsbl;
+
+                       try
+                       {
+                               InetAddress.getAllByName(lookup_addr);
+                               source.reply(this.ip + " is listed in " + dnsbl);
+                       }
+                       catch (UnknownHostException ex)
+                       {
+                       }
+               }
+       }
+}
+
+public class CommandWhy extends Command
+{
+       @Inject
+       private ServerManager serverManager;
+
+       @Inject
+       private Protocol protocol;
+       
+       protected static CommandSource command_source;
+       public static String host_ip = "", host_host = "";
+       public static int requested = 0;
+
+       @Inject
+       public CommandWhy(Config conf)
+       {
+               super("!WHY", "Find why an IP is banned");
+
+               this.requiresChannel(conf.staff_channels);
+               this.requiresChannel(conf.oper_channels);
+               this.requiresChannel(conf.admin_channels);
+       }
+
+       @Override
+       public void onHelp(CommandSource source)
+       {
+               source.notice("Syntax: !WHY <ip/host>");
+               source.notice("Finds out why a certain IP is banned. It is looked for in DNSBLs and k/K/d:lines");
+       }
+
+       @Override
+       public void execute(CommandSource source, String[] params)
+       {
+               if (params.length <= 1)
+               {
+                       source.reply("Syntax: !WHY <ip/host>");
+                       return;
+               }
+
+               try
+               {
+                       InetAddress addr = InetAddress.getByName(params[1]);
+                       host_ip = addr.getHostAddress();
+                       host_host = addr.getHostName();
+               }
+               catch (UnknownHostException ex)
+               {
+                       source.reply("Invalid IP or host");
+                       return;
+               }
+
+
+               Thread t = new DNSBLChecker(source, host_ip);
+               t.start();
+
+               requested = 0;
+               for (Server s : serverManager.getServers())
+                       if (s.getSplit() == null && !s.isServices() && !s.isHub())
+                       {
+                               protocol.write("STATS", "k", s.getName());
+                               protocol.write("STATS", "K", s.getName());
+                               protocol.write("STATS", "d", s.getName());
+                               requested += 3;
+                       }
+
+               command_source = source;
+       }
+}
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/why/Message216.java b/commands/src/main/java/net/rizon/moo/plugin/commands/why/Message216.java
new file mode 100644 (file)
index 0000000..1c66cc0
--- /dev/null
@@ -0,0 +1,30 @@
+package net.rizon.moo.plugin.commands.why;
+
+import net.rizon.moo.Message;
+import net.rizon.moo.io.IRCMessage;
+
+public class Message216 extends Message
+{
+       public Message216()
+       {
+               super("216");
+       }
+
+       @Override
+       public void run(IRCMessage message)
+       {
+               if (message.getParams()[1].equals("k") == false && message.getParams()[1].equals("K") == false)
+                       return;
+
+               if (CommandWhy.host_ip.isEmpty())
+                       return;
+
+               if (message.getParams()[2].equalsIgnoreCase(CommandWhy.host_ip) == false && message.getParams()[2].equalsIgnoreCase(CommandWhy.host_host) == false)
+                       return;
+
+               CommandWhy.command_source.reply("[" + message.getSource() + "] " + message.getParams()[2] + " is " + message.getParams()[1] + "-lined for: " + message.getParams()[5]);
+
+               CommandWhy.host_ip = "";
+               CommandWhy.host_host = "";
+       }
+}
\ No newline at end of file
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/why/Message219Why.java b/commands/src/main/java/net/rizon/moo/plugin/commands/why/Message219Why.java
new file mode 100644 (file)
index 0000000..c255b99
--- /dev/null
@@ -0,0 +1,29 @@
+package net.rizon.moo.plugin.commands.why;
+
+import net.rizon.moo.Message;
+import net.rizon.moo.io.IRCMessage;
+
+public class Message219Why extends Message
+{
+       public Message219Why()
+       {
+               super("219");
+       }
+
+       @Override
+       public void run(IRCMessage message)
+       {
+               if (CommandWhy.host_ip.isEmpty())
+                       return;
+
+               CommandWhy.requested--;
+
+               if (CommandWhy.requested == 0)
+               {
+                       CommandWhy.command_source.reply(CommandWhy.host_ip + " (" + CommandWhy.host_host + ") is not banned");
+
+                       CommandWhy.host_ip = "";
+                       CommandWhy.host_host = "";
+               }
+       }
+}
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/why/Message225.java b/commands/src/main/java/net/rizon/moo/plugin/commands/why/Message225.java
new file mode 100644 (file)
index 0000000..ddc9b32
--- /dev/null
@@ -0,0 +1,30 @@
+package net.rizon.moo.plugin.commands.why;
+
+import net.rizon.moo.Message;
+import net.rizon.moo.io.IRCMessage;
+
+public class Message225 extends Message
+{
+       public Message225()
+       {
+               super("225");
+       }
+
+       @Override
+       public void run(IRCMessage message)
+       {
+               if (message.getParams()[1].equals("d") == false)
+                       return;
+
+               if (CommandWhy.host_ip.isEmpty())
+                       return;
+
+               if (message.getParams()[2].equalsIgnoreCase(CommandWhy.host_ip) == false && message.getParams()[2].equalsIgnoreCase(CommandWhy.host_host) == false)
+                       return;
+
+               CommandWhy.command_source.reply("[" + message.getSource() + "] " + message.getParams()[2] + " is " + message.getParams()[1] + "-lined for: " + message.getParams()[3]);
+
+               CommandWhy.host_ip = "";
+               CommandWhy.host_host = "";
+       }
+}
\ No newline at end of file
index 4de89c96030688c66e9de70f0433bf46cb4490d5..4cf4c74f9a8c41a74da0401e9adb5deabc1d89e6 100644 (file)
@@ -26,7 +26,6 @@ public class fun extends Plugin implements EventListener
        @Override
        public void stop()
        {
-       //      rt.remove();
        }
 
        @Override
index f4feff6fb8398fa411d39f3d42c94097ea69574f..4ac5789f0476bcc1d714e2bfbb73059b583199ad 100644 (file)
@@ -10,37 +10,23 @@ public abstract class Command
        private String description;
        private List<String> channels = new ArrayList<>();
 
-       public Command(Plugin pkg, final String cmdname, final String desc)
-       {
-               this.pkg = pkg;
-               this.cmdname = cmdname;
-               this.description = desc;
-
-               //pkg.commands.add(this);
-       }
-
        public Command(String cmdname, String description)
        {
                this.cmdname = cmdname;
                this.description = description;
        }
 
-       public void remove()
-       {
-               //pkg.commands.remove(this);
-       }
-
        public Plugin getPackage()
        {
                return this.pkg;
        }
 
-       public final String getCommandName()
+       public String getCommandName()
        {
                return this.cmdname;
        }
 
-       public final String getDescription()
+       public String getDescription()
        {
                return this.description;
        }
diff --git a/pom.xml b/pom.xml
index e994ae46cf9d338bb181d72371ad8abbbad07589..07dd55dec38b6b06ecba5fc136043717d7937303 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -24,9 +24,9 @@
        <modules>
                <module>moo</module>
 
-               <module>antiidle</module><!--
-               <module>commands</module>
-               <module>commits</module>-->
+               <module>antiidle</module>
+<!--           <module>commands</module>-->
+               <!--<module>commits</module>-->
                <module>core</module>
                <module>dnsbl</module>
 <!--           <module>dnsblstats</module>-->