]> jfr.im git - irc/rizon/moo.git/commitdiff
dnsbl
authorAdam <redacted>
Sun, 21 Feb 2016 01:33:53 +0000 (20:33 -0500)
committerAdam <redacted>
Sun, 21 Feb 2016 01:33:53 +0000 (20:33 -0500)
36 files changed:
core/src/main/java/net/rizon/moo/plugin/core/CommandHelp.java
core/src/main/java/net/rizon/moo/plugin/core/CommandHost.java
core/src/main/java/net/rizon/moo/plugin/core/CommandPlugins.java
core/src/main/java/net/rizon/moo/plugin/core/CommandRand.java
core/src/main/java/net/rizon/moo/plugin/core/CommandReload.java
core/src/main/java/net/rizon/moo/plugin/core/CommandShell.java
core/src/main/java/net/rizon/moo/plugin/core/CommandShutdown.java
core/src/main/java/net/rizon/moo/plugin/core/CommandStatus.java
core/src/main/java/net/rizon/moo/plugin/core/core.java
dnsbl/src/main/java/net/rizon/moo/plugin/dnsbl/BlacklistManager.java
dnsbl/src/main/java/net/rizon/moo/plugin/dnsbl/CommandDnsbl.java
dnsbl/src/main/java/net/rizon/moo/plugin/dnsbl/EventDnsblCheck.java
dnsbl/src/main/java/net/rizon/moo/plugin/dnsbl/ResultCache.java
dnsbl/src/main/java/net/rizon/moo/plugin/dnsbl/actions/Action.java
dnsbl/src/main/java/net/rizon/moo/plugin/dnsbl/actions/ActionAkill.java
dnsbl/src/main/java/net/rizon/moo/plugin/dnsbl/actions/ActionLog.java
dnsbl/src/main/java/net/rizon/moo/plugin/dnsbl/dnsbl.java
fun/src/main/java/net/rizon/moo/plugin/fun/CommandRizonTime.java
fun/src/main/java/net/rizon/moo/plugin/fun/EventFun.java
fun/src/main/java/net/rizon/moo/plugin/fun/fun.java
moo/src/main/java/net/rizon/moo/Command.java
moo/src/main/java/net/rizon/moo/Mail.java
moo/src/main/java/net/rizon/moo/MessageManager.java
moo/src/main/java/net/rizon/moo/Moo.java
moo/src/main/java/net/rizon/moo/MooModule.java
moo/src/main/java/net/rizon/moo/Plugin.java
moo/src/main/java/net/rizon/moo/io/ClientInitializer.java
moo/src/main/java/net/rizon/moo/io/NettyModule.java
moo/src/main/java/net/rizon/moo/irc/Protocol.java
moo/src/main/java/net/rizon/moo/logging/ConsoleFilter.java
moo/src/main/java/net/rizon/moo/logging/Logger.java
moo/src/main/java/net/rizon/moo/protocol/Message001.java
moo/src/main/java/net/rizon/moo/protocol/MessageInvite.java
moo/src/main/java/net/rizon/moo/protocol/MessageNotice.java
moo/src/main/java/net/rizon/moo/protocol/MessagePrivmsg.java
pom.xml

index 5d063c0163db0be1b97f2fe9742e59f611b38403..f02611feaca4a72359bffd1c04e29bd5856ad707 100644 (file)
@@ -1,14 +1,16 @@
 package net.rizon.moo.plugin.core;
 
+import com.google.inject.Inject;
 import net.rizon.moo.Command;
 import net.rizon.moo.CommandSource;
 import net.rizon.moo.Plugin;
+import net.rizon.moo.conf.Config;
 
-public class CommandHelp extends Command
+class CommandHelp extends Command
 {
-       public CommandHelp(Plugin pkg)
+       CommandHelp()
        {
-               super(pkg, "!HELP", "Shows this list");
+               super("!HELP", "Shows this list");
        }
 
        @Override
@@ -25,7 +27,7 @@ public class CommandHelp extends Command
                {
                        boolean show_header = false;
 
-                       for (Command c : pkg.commands)
+                       for (Command c : pkg.getCommands())
                        {
                                if (!c.isRequiredChannel(source.getTargetName()))
                                        continue;
index 836171b20576b1fc235ef7663858e1e99e700dfc..104c5c6794a61a196ea4d87e32fb19749311c781 100644 (file)
@@ -1,22 +1,23 @@
 package net.rizon.moo.plugin.core;
 
+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.Plugin;
+import net.rizon.moo.conf.Config;
 
 class CommandHost extends Command
 {
-       public CommandHost(Plugin pkg)
+       @Inject
+       CommandHost(Config conf)
        {
-               super(pkg, "!HOST", "Resolve a hostname");
+               super("!HOST", "Resolve a hostname");
 
-               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);
        }
 
        @Override
index 0d228a977e99865fd95a3678df2c688f8384394b..b32def7cff2b1fb571b2db4144b3cd6298e37e0c 100644 (file)
@@ -6,17 +6,22 @@ import net.rizon.moo.Command;
 import net.rizon.moo.CommandSource;
 import net.rizon.moo.Moo;
 import net.rizon.moo.Plugin;
+import net.rizon.moo.conf.Config;
 import org.slf4j.Logger;
 
 class CommandPlugins extends Command
 {
        @Inject
        private static Logger logger;
+
+       @Inject
+       private Moo moo;
        
-       public CommandPlugins(Plugin pkg)
+       @Inject
+       CommandPlugins(Config conf)
        {
-               super(pkg, "!PLUGINS", "Manage plugins");
-               this.requiresChannel(Moo.conf.admin_channels);
+               super("!PLUGINS", "Manage plugins");
+               this.requiresChannel(conf.admin_channels);
        }
 
        @Override
@@ -34,6 +39,7 @@ class CommandPlugins extends Command
                        try
                        {
                                Plugin p = Plugin.loadPlugin(params[2]);
+                               moo.rebuildInjector();
                                source.reply("Plugin " + p.getName() + " loaded");
                        }
                        catch (Throwable ex)
@@ -53,6 +59,7 @@ class CommandPlugins extends Command
                        else
                        {
                                p.remove();
+                               moo.rebuildInjector();
                                source.reply("Plugin " + p.getName() + " removed");
                        }
                }
@@ -66,10 +73,12 @@ class CommandPlugins extends Command
                        else
                        {
                                p.remove();
+                               moo.rebuildInjector();
 
                                try
                                {
                                        p = Plugin.loadPlugin(params[2]);
+                                       moo.rebuildInjector();
                                        source.reply("Plugin " + p.getName() + " reloaded");
                                }
                                catch (Throwable ex)
index 02b200c2b44c4bbb8fa5f2f71baa0d19d86712f6..a4f2d1fc169b8aebf5168cbcf0e410dc2b6ef6bf 100644 (file)
@@ -1,5 +1,6 @@
 package net.rizon.moo.plugin.core;
 
+import com.google.inject.Inject;
 import java.util.Random;
 
 import net.rizon.moo.Command;
@@ -8,9 +9,10 @@ import net.rizon.moo.Plugin;
 
 class CommandRand extends Command
 {
-       public CommandRand(Plugin pkg)
+       @Inject
+       CommandRand()
        {
-               super(pkg, ".RAND", "Generate a random string");
+               super(".RAND", "Generate a random string");
        }
 
        private static String randChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@_#^&%$";
index 5374a6d8ddbfc0802df143f9fb3610bf55038c9e..2ac211cd637aed7d3c81d61dc29d4e5b29214cab 100644 (file)
@@ -17,13 +17,17 @@ class CommandReload extends Command
        @Inject
        private static Logger logger;
 
+       @Inject
+       private Moo moo;
+
        @Inject
        private EventBus eventBus;
 
-       public CommandReload(Plugin pkg)
+       @Inject
+       CommandReload(Config conf)
        {
-               super(pkg, "!RELOAD", "Reloads the configuration file");
-               this.requiresChannel(Moo.conf.admin_channels);
+               super("!RELOAD", "Reloads the configuration file");
+               this.requiresChannel(conf.admin_channels);
        }
 
        @Override
@@ -42,7 +46,9 @@ class CommandReload extends Command
                        
                        eventBus.post(new OnReload(source));
 
-                       Moo.conf = c;
+                       moo.setConf(c);
+                       moo.rebuildInjector();
+                       
                        source.reply("Successfully reloaded configuration");
                }
                catch (Exception ex)
index 1a4f1fcd97182290df0a8538fb3f63e50d69e321..33bce9853b206d98575fdd224cbef3cb65500c38 100644 (file)
@@ -10,28 +10,31 @@ import net.rizon.moo.Command;
 import net.rizon.moo.CommandSource;
 import net.rizon.moo.Moo;
 import net.rizon.moo.Plugin;
+import net.rizon.moo.conf.Config;
 import net.rizon.moo.irc.Protocol;
+import net.rizon.moo.plugin.core.conf.CoreConfiguration;
 
 class shellExec extends Thread
 {
+       private CoreConfiguration conf;
        private Protocol protocol;
        private CommandSource source;
        private String command;
 
-       public shellExec(Protocol protocol, CommandSource source, String command)
+       public shellExec(CoreConfiguration conf, Protocol protocol, CommandSource source, String command)
        {
+               this.conf = conf;
                this.protocol = protocol;
                this.source = source;
                this.command = command;
        }
 
-
        @Override
        public void run()
        {
                try
                {
-                       Process proc = Runtime.getRuntime().exec(this.command, null, new File(core.conf.shell.base));
+                       Process proc = Runtime.getRuntime().exec(this.command, null, new File(conf.shell.base));
                        BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
                        for (String line; (line = in.readLine()) != null;)
                        {
@@ -62,10 +65,14 @@ class CommandShell extends Command
        @Inject
        private Protocol protocol;
 
-       public CommandShell(Plugin pkg)
+       @Inject
+       private CoreConfiguration conf;
+
+       @Inject
+       CommandShell(Config conf)
        {
-               super(pkg, "!SHELL", "Execute a shell command");
-               this.requiresChannel(Moo.conf.admin_channels);
+               super("!SHELL", "Execute a shell command");
+               this.requiresChannel(conf.admin_channels);
        }
 
        @Override
@@ -73,16 +80,16 @@ class CommandShell extends Command
        {
                source.notice("!SHELL <command>");
                source.notice("!SHELL executes a single shell command from the configured shell base directory.");
-               source.notice("This command is currently " + (core.conf.shell.enabled ? "enabled" : "disabled") + ".");
+               source.notice("This command is currently " + (conf.shell.enabled ? "enabled" : "disabled") + ".");
        }
 
        @Override
        public void execute(CommandSource source, String[] params)
        {
-               if (!core.conf.shell.enabled || params.length == 1)
+               if (!conf.shell.enabled || params.length == 1)
                        return;
 
-               File base = new File(core.conf.shell.base);
+               File base = new File(conf.shell.base);
                if (base.exists() == false || base.isDirectory() == false)
                {
                        source.reply("Shell base dir is set to an invalid path");
@@ -96,7 +103,7 @@ class CommandShell extends Command
                if (param.indexOf("..") != -1)
                        return;
 
-               shellExec e = new shellExec(protocol, source, param);
+               shellExec e = new shellExec(conf, protocol, source, param);
                e.start();
        }
 }
index 78f7188ea56b042c64109cfdb1ac486c36104add..ba92d458f5c83fe903919891fd82ab218d21bc49 100644 (file)
@@ -5,6 +5,7 @@ import net.rizon.moo.Command;
 import net.rizon.moo.CommandSource;
 import net.rizon.moo.Moo;
 import net.rizon.moo.Plugin;
+import net.rizon.moo.conf.Config;
 import net.rizon.moo.irc.Protocol;
 
 
@@ -13,17 +14,21 @@ class CommandShutdown extends Command
        @Inject
        private Protocol protocol;
 
-       public CommandShutdown(Plugin pkg)
+       @Inject
+       private Config conf;
+
+       @Inject
+       CommandShutdown(Config conf)
        {
-               super(pkg, "!SHUTDOWN", "Shutdown " + Moo.conf.general.nick);
-               this.requiresChannel(Moo.conf.admin_channels);
+               super("!SHUTDOWN", "Shutdown " + conf.general.nick);
+               this.requiresChannel(conf.admin_channels);
        }
 
        @Override
        public void onHelp(CommandSource source)
        {
                source.notice("Syntax: !SHUTDOWN");
-               source.notice("!SHUTDOWN shuts " + Moo.conf.general.nick + " down.");
+               source.notice("!SHUTDOWN shuts " + conf.general.nick + " down.");
                source.notice("Please note that this will show the nick!user@host of the user");
                source.notice("issuing this command in the quit message.");
        }
index 0bba9c91d7b844b2d9eb6e4d5514923f55cef1ab..7b183411323bb194a2a045f1edc105239e1ef6bd 100644 (file)
@@ -1,16 +1,22 @@
 package net.rizon.moo.plugin.core;
 
+import com.google.inject.Inject;
 import net.rizon.moo.Command;
 import net.rizon.moo.CommandSource;
 import net.rizon.moo.Moo;
 import net.rizon.moo.Plugin;
 import net.rizon.moo.Version;
+import net.rizon.moo.conf.Config;
 
 class CommandStatus extends Command
 {
-       public CommandStatus(Plugin pkg)
+       @Inject
+       private Config conf;
+
+       @Inject
+       CommandStatus(Config conf)
        {
-               super(pkg, "!STATUS", "View " + Moo.conf.general.nick + "'s status");
+               super("!STATUS", "View " + conf.general.nick + "'s status");
        }
 
        private String convertBytes(long bb)
@@ -56,14 +62,14 @@ class CommandStatus extends Command
        public void onHelp(CommandSource source)
        {
                source.notice("Syntax: !STATUS");
-               source.notice("!STATUS prints misc info on " + Moo.conf.general.nick + ".");
-               source.notice("This includes the version, the date when " + Moo.conf.general.nick + " was started,");
+               source.notice("!STATUS prints misc info on " + conf.general.nick + ".");
+               source.notice("This includes the version, the date when " + conf.general.nick + " was started,");
                source.notice("the amount of currently running threads and memory usage.");
        }
 
        @Override
        public void execute(CommandSource source, String[] params)
        {
-               source.reply("[STATUS] " + Moo.conf.general.nick + " version " + Moo.conf.version + ", created on " + Moo.getCreated() + ". Revision " + Version.getFullVersion() + ". Using " + Thread.activeCount() + " threads and " + this.getMemory() + " of memory");
+               source.reply("[STATUS] " + conf.general.nick + " version " + conf.version + ", created on " + Moo.getCreated() + ". Revision " + Version.getFullVersion() + ". Using " + Thread.activeCount() + " threads and " + this.getMemory() + " of memory");
        }
 }
\ No newline at end of file
index f7c45af30724f269627bc54982507fbbe6c538bd..8efe18863623ea72c0ce7e591a6494046a2ec801 100644 (file)
@@ -3,24 +3,45 @@ package net.rizon.moo.plugin.core;
 import com.google.common.eventbus.Subscribe;
 import com.google.inject.Inject;
 import com.google.inject.multibindings.Multibinder;
+import java.util.Arrays;
+import java.util.List;
 import net.rizon.moo.Command;
-import net.rizon.moo.Moo;
 import net.rizon.moo.Plugin;
 import net.rizon.moo.events.EventListener;
 import net.rizon.moo.events.OnReload;
 import net.rizon.moo.plugin.core.conf.CoreConfiguration;
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class core extends Plugin implements EventListener
 {
        @Inject
        private static Logger logger;
-       
-       public static CoreConfiguration conf;
 
+       private CoreConfiguration conf;
+
+       @Inject
        private CommandHelp help;
-       private Command host, plugins, rand, reload, shell, shutdown, status;
+
+       @Inject
+       private CommandHost host;
+
+       @Inject
+       private CommandPlugins plugins;
+
+       @Inject
+       private CommandRand rand;
+
+       @Inject
+       private CommandReload reload;
+
+       @Inject
+       private CommandShell shell;
+
+       @Inject
+       private CommandShutdown shutdown;
+
+       @Inject
+       private CommandStatus status;
 
        public core() throws Exception
        {
@@ -28,28 +49,22 @@ public class core extends Plugin implements EventListener
                conf = CoreConfiguration.load();
        }
        
-       
        @Override
        protected void configure()
        {
-               help = new CommandHelp(this);
-               host = new CommandHost(this);
-               plugins = new CommandPlugins(this);
-               rand = new CommandRand(this);
-               reload = new CommandReload(this);
-               shell = new CommandShell(this);
-               shutdown = new CommandShutdown(this);
-               status = new CommandStatus(this);
+               bind(core.class).toInstance(this);
+               
+               bind(CoreConfiguration.class).toInstance(conf);
                
                Multibinder<Command> commandBinder = Multibinder.newSetBinder(binder(), Command.class);
-               commandBinder.addBinding().toInstance(help);
-               commandBinder.addBinding().toInstance(host);
-               commandBinder.addBinding().toInstance(plugins);
-               commandBinder.addBinding().toInstance(rand);
-               commandBinder.addBinding().toInstance(reload);
-               commandBinder.addBinding().toInstance(shell);
-               commandBinder.addBinding().toInstance(shutdown);
-               commandBinder.addBinding().toInstance(status);
+               commandBinder.addBinding().to(CommandHelp.class);
+               commandBinder.addBinding().to(CommandHost.class);
+               commandBinder.addBinding().to(CommandPlugins.class);
+               commandBinder.addBinding().to(CommandRand.class);
+               commandBinder.addBinding().to(CommandReload.class);
+               commandBinder.addBinding().to(CommandShell.class);
+               commandBinder.addBinding().to(CommandShutdown.class);
+               commandBinder.addBinding().to(CommandStatus.class);
 
                Multibinder<EventListener> eventListenerBinder = Multibinder.newSetBinder(binder(), EventListener.class);
                eventListenerBinder.addBinding().toInstance(this);
@@ -63,14 +78,6 @@ public class core extends Plugin implements EventListener
        @Override
        public void stop()
        {
-               help.remove();
-               host.remove();
-               plugins.remove();
-               rand.remove();
-               reload.remove();
-               shell.remove();
-               shutdown.remove();
-               status.remove();
        }
        
        @Subscribe
@@ -78,7 +85,7 @@ public class core extends Plugin implements EventListener
        {
                try
                {
-                       core.conf = CoreConfiguration.load();
+                       conf = CoreConfiguration.load();
                }
                catch (Exception ex)
                {
@@ -87,4 +94,10 @@ public class core extends Plugin implements EventListener
                        logger.warn("Unable to reload core configuration", ex);
                }
        }
+
+       @Override
+       public List<Command> getCommands()
+       {
+               return Arrays.asList(help, host, plugins, rand, reload, shell, shutdown, status);
+       }
 }
index 730bd3d6b93a4454ecca4f96d1441e827e5627ca..1d488fb4b9cb335113e505fb603ee0468159388d 100644 (file)
@@ -1,33 +1,35 @@
 package net.rizon.moo.plugin.dnsbl;
 
+import com.google.inject.Inject;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
-import java.util.logging.Level;
 
 import net.rizon.moo.plugin.dnsbl.actions.Action;
+import net.rizon.moo.plugin.dnsbl.conf.DnsblConfiguration;
 import net.rizon.moo.plugin.dnsbl.conf.DnsblServerConfiguration;
 import net.rizon.moo.plugin.dnsbl.conf.RuleConfiguration;
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 class BlacklistManager
 {
-       private static final Logger logger = LoggerFactory.getLogger(BlacklistManager.class);
+       @Inject
+       private static Logger logger;
+
+       @Inject
+       private dnsbl dnsbl;
+
+       @Inject
+       private DnsblConfiguration conf;
        
-       private Map<String, Blacklist> blacklists = new HashMap<String, Blacklist>();
+       private Map<String, Blacklist> blacklists = new HashMap<>();
 
-       /**
-        * Loads the list of DNSBL server configuration.
-        * @param configuration List of server configurations.
-        */
-       public void load(List<DnsblServerConfiguration> configuration)
+       public void load()
        {
                blacklists.clear();
 
-               for (DnsblServerConfiguration c : configuration)
+               for (DnsblServerConfiguration c : conf.servers)
                {
                        Blacklist b = new Blacklist(c.address);
                        blacklists.put(c.address, b);
@@ -38,7 +40,7 @@ class BlacklistManager
                                if (response.equals(Rule.RESPONSE_ANY))
                                        response = null;
 
-                               Action action = Action.getByName(rule.action);
+                               Action action = dnsbl.getByName(rule.action);
                                if (action == null)
                                {
                                        // Invalid config item, ignore it.
index be69bc58ee7dbf4d723d73f706e490638b8bf215..e35ab4f92da7c5f36de898754236f9417115fa61 100644 (file)
@@ -1,5 +1,6 @@
 package net.rizon.moo.plugin.dnsbl;
 
+import com.google.inject.Inject;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -8,8 +9,7 @@ import java.util.Map;
 
 import net.rizon.moo.Command;
 import net.rizon.moo.CommandSource;
-import net.rizon.moo.Moo;
-import net.rizon.moo.Plugin;
+import net.rizon.moo.conf.Config;
 import net.rizon.moo.plugin.dnsbl.actions.Action;
 
 import org.xbill.DNS.Record;
@@ -17,15 +17,20 @@ import org.xbill.DNS.Record;
 
 class CommandDnsbl extends Command
 {
+       @Inject
        private BlacklistManager blacklists;
+
+       @Inject
        private ResultCache cache;
 
-       public CommandDnsbl(Plugin pkg, BlacklistManager blacklistManager, ResultCache cache)
+       @Inject
+       private dnsbl dnsbl;
+
+       @Inject
+       CommandDnsbl(Config conf)
        {
-               super(pkg, "!DNSBL", "Manage DNSBL servers");
-               this.requiresChannel(Moo.conf.admin_channels);
-               this.blacklists = blacklistManager;
-               this.cache = cache;
+               super("!DNSBL", "Manage DNSBL servers");
+               this.requiresChannel(conf.admin_channels);
        }
 
        @Override
@@ -51,7 +56,7 @@ class CommandDnsbl extends Command
                source.notice("  Check IP against DNSBLs and return what actions would have been taken.");
                source.notice("  If server is given, only check against server. ");
                source.notice("Possible actions:");
-               for (Action a : Action.getAllActions())
+               for (Action a : dnsbl.getAllActions())
                        source.notice("  " + a.getName() + ": " + a.getDescription());
        }
 
@@ -206,7 +211,7 @@ class CommandDnsbl extends Command
 
                String host = params[0];
                String response = params[1], actualResponse;
-               Action action = Action.getByName(params[2].toUpperCase());
+               Action action = dnsbl.getByName(params[2].toUpperCase());
 
                if (response.equals(Rule.RESPONSE_ANY))
                        actualResponse = null;
@@ -254,7 +259,7 @@ class CommandDnsbl extends Command
 
                String host = params[0];
                String response = params[1], actualResponse;
-               Action action = Action.getByName(params[2].toUpperCase());
+               Action action = dnsbl.getByName(params[2].toUpperCase());
 
                if (response.equals(Rule.RESPONSE_ANY))
                        actualResponse = null;
index 37242167dbc90ee5f708df0c5d1c1be6c4018490..a08237f748d4d42397fdfd13656de8f7451df37f 100644 (file)
@@ -1,36 +1,34 @@
 package net.rizon.moo.plugin.dnsbl;
 
+import com.google.common.eventbus.EventBus;
 import com.google.common.eventbus.Subscribe;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.logging.Level;
-
-import net.rizon.moo.CommandSource;
-import net.rizon.moo.Event;
+import javax.inject.Inject;
 import net.rizon.moo.Moo;
 import net.rizon.moo.events.EventClientConnect;
 import net.rizon.moo.events.EventDNSBLHit;
+import net.rizon.moo.events.EventListener;
 import net.rizon.moo.events.OnReload;
 import net.rizon.moo.plugin.dnsbl.actions.Action;
 import net.rizon.moo.plugin.dnsbl.conf.DnsblConfiguration;
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-class EventDnsblCheck
+class EventDnsblCheck implements EventListener
 {
-       private static final Logger logger = LoggerFactory.getLogger(EventDnsblCheck.class);
-       
+       @Inject
+       private static Logger logger;
+
+       @Inject
        private BlacklistManager rules;
+       @Inject
        private ResultCache cache;
 
-       public EventDnsblCheck(BlacklistManager rules, ResultCache cache)
-       {
-               this.rules = rules;
-               this.cache = cache;
-       }
+       @Inject
+       private EventBus eventBus;
 
        private void takeAction(String nick, String ip, List<DnsblCheckResult> results)
        {
@@ -47,7 +45,7 @@ class EventDnsblCheck
                        for (Map.Entry<String, List<Action>> dnsblResult : result.getActions().entrySet())
                        {
                                // XXX this is calling event from a thread
-                               Moo.getEventBus().post(new EventDNSBLHit(nick, ip, result.getBlacklist().getName(), dnsblResult.getKey()));
+                               eventBus.post(new EventDNSBLHit(nick, ip, result.getBlacklist().getName(), dnsblResult.getKey()));
 
                                // And those responses each have a set of actions.
                                for (Action a : dnsblResult.getValue())
@@ -107,11 +105,11 @@ class EventDnsblCheck
                try
                {
                        DnsblConfiguration c = DnsblConfiguration.load();
-                       rules.load(c.servers);
-                       cache.load(c.cache);
-                       cache.clear();
-                       DnsblChecker.load(c);
-                       dnsbl.conf = c;
+//                     rules.load(c.servers);
+//                     cache.load(c.cache);
+//                     cache.clear();
+//                     DnsblChecker.load(c);
+//                     dnsbl.conf = c;
                }
                catch (Exception ex)
                {
index bc4e5b0ee556db53f33660f990d38d05af74f4ca..08b876c48d60b78941f6e99fdf2f0a5c7dd384cf 100644 (file)
@@ -1,5 +1,6 @@
 package net.rizon.moo.plugin.dnsbl;
 
+import com.google.inject.Inject;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.HashMap;
@@ -8,12 +9,15 @@ import java.util.List;
 import java.util.Map;
 
 import net.rizon.moo.plugin.dnsbl.conf.CacheConfiguration;
+import net.rizon.moo.plugin.dnsbl.conf.DnsblConfiguration;
 
 class ResultCache
 {
        private static final long EXPIRE_TICK = 60 * 1000L;
        private long lastExpired;
-       private int entryLifetime = 60;
+
+       @Inject
+       private DnsblConfiguration conf;
 
        protected class Entry
        {
@@ -40,16 +44,6 @@ class ResultCache
 
        private Map<String, Entry> entries = new HashMap<String, Entry>();
 
-       /**
-        * Loads the configuration for the ResultCache.
-        * @param c Configuration settings to load.
-        */
-       public void load(CacheConfiguration c)
-       {
-               if (c.lifetime > 0)
-                       this.entryLifetime = c.lifetime;
-       }
-
        public synchronized void addEntry(String ip, List<DnsblCheckResult> results)
        {
                if (System.currentTimeMillis() > lastExpired + EXPIRE_TICK)
@@ -63,7 +57,7 @@ class ResultCache
                // Calculate expiration date.
                Calendar c = Calendar.getInstance();
                c.setTime(now);
-               c.add(Calendar.SECOND, this.entryLifetime);
+               c.add(Calendar.SECOND, conf.cache.lifetime > 0 ? conf.cache.lifetime : 60);
 
                Date expiration = c.getTime();
                this.entries.put(ip, new Entry(results, expiration));
index f1efdbf45300f77dca69d4f64acdefa5e152e8fe..200275c27e1fc0f7cac5dc78705d7433f4af58de 100644 (file)
@@ -4,8 +4,6 @@ import net.rizon.moo.plugin.dnsbl.Blacklist;
 
 public abstract class Action
 {
-       private static Action[] allActions = { new ActionAkill(), new ActionLog() };
-
        private String name;
        private String description;
 
@@ -31,18 +29,4 @@ public abstract class Action
        {
                return this.description;
        }
-
-       public static Action[] getAllActions()
-       {
-               return allActions;
-       }
-
-       public static Action getByName(String name)
-       {
-               for (Action a : getAllActions())
-                       if (a.name.equals(name))
-                               return a;
-
-               return null;
-       }
 }
index b3590835a4c61cc60d7fb6758d54447f2ff1da8d..35689b62c7dfeff18fc4e7377480e951944c2b39 100644 (file)
@@ -1,11 +1,19 @@
 package net.rizon.moo.plugin.dnsbl.actions;
 
-import net.rizon.moo.Moo;
+import com.google.inject.Inject;
+import static net.rizon.moo.Moo.moo;
+import net.rizon.moo.irc.Protocol;
 import net.rizon.moo.plugin.dnsbl.Blacklist;
-import net.rizon.moo.plugin.dnsbl.dnsbl;
+import net.rizon.moo.plugin.dnsbl.conf.DnsblConfiguration;
 
 public class ActionAkill extends Action
 {
+       @Inject
+       private DnsblConfiguration conf;
+
+       @Inject
+       private Protocol protocol;
+
        public ActionAkill()
        {
                super("AKILL", "Ban IP and terminate connection");
@@ -14,11 +22,11 @@ public class ActionAkill extends Action
        @Override
        public void onHit(Blacklist blacklist, String dnsblResponse, String nick, String ip)
        {
-               String message = dnsbl.conf.akill.message
+               String message = conf.akill.message
                        .replace("%h", ip)
                        .replace("%d", blacklist.getName())
                        .replace("%r", dnsblResponse);
-               Moo.akill(ip, dnsbl.conf.akill.duration, message);
+               protocol.akill(ip, conf.akill.duration, message);
        }
 
        @Override
index 8274a627b451dd8ea7792c7341c3a2e70a096fe6..5f96236bbcde9a07a9260ae19665c3ce362af2af 100644 (file)
@@ -1,10 +1,19 @@
 package net.rizon.moo.plugin.dnsbl.actions;
 
+import com.google.inject.Inject;
 import net.rizon.moo.Moo;
+import net.rizon.moo.conf.Config;
+import net.rizon.moo.irc.Protocol;
 import net.rizon.moo.plugin.dnsbl.Blacklist;
 
 public class ActionLog extends Action
 {
+       @Inject
+       private Config conf;
+
+       @Inject
+       private Protocol protocol;
+
        public ActionLog()
        {
                super("LOG", "Log connection for inspection by ircops");
@@ -13,6 +22,6 @@ public class ActionLog extends Action
        @Override
        public void onHit(Blacklist blacklist, String response, String nick, String ip)
        {
-               Moo.privmsgAll(Moo.conf.spam_channels, "DNSBL " + blacklist.getName() + " gave hit on " + nick + " (" + ip + "): " + response);
+               protocol.privmsgAll(conf.spam_channels, "DNSBL " + blacklist.getName() + " gave hit on " + nick + " (" + ip + "): " + response);
        }
 }
index 1ce5ec115245e1251b1b6c9edcba7b07769b9ae6..483821471e2f09ac7120ae1fa7a22eb24c2e8854 100644 (file)
@@ -1,16 +1,31 @@
 package net.rizon.moo.plugin.dnsbl;
 
-import net.rizon.moo.Moo;
+import com.google.inject.Inject;
+import com.google.inject.multibindings.Multibinder;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import net.rizon.moo.Command;
 import net.rizon.moo.Plugin;
+import net.rizon.moo.events.EventListener;
+import net.rizon.moo.plugin.dnsbl.actions.Action;
+import net.rizon.moo.plugin.dnsbl.actions.ActionAkill;
+import net.rizon.moo.plugin.dnsbl.actions.ActionLog;
 import net.rizon.moo.plugin.dnsbl.conf.DnsblConfiguration;
 
 public class dnsbl extends Plugin
 {
+       @Inject
        private CommandDnsbl command;
+
+       @Inject
        private BlacklistManager blacklistManager;
-       private ResultCache cache;
-       private EventDnsblCheck event;
-       public static DnsblConfiguration conf;
+
+       @Inject
+       private Set<Action> actions;
+
+       private DnsblConfiguration conf;
 
        public dnsbl() throws Exception
        {
@@ -21,22 +36,57 @@ public class dnsbl extends Plugin
        @Override
        public void start()
        {
-               this.blacklistManager = new BlacklistManager();
-               this.cache = new ResultCache();
-               this.command = new CommandDnsbl(this, this.blacklistManager, this.cache);
-               this.event = new EventDnsblCheck(this.blacklistManager, this.cache);
-               
-               Moo.getEventBus().register(event);
-
                DnsblChecker.load(conf);
-               this.cache.load(conf.cache);
-               this.blacklistManager.load(conf.servers);
+               blacklistManager.load();
        }
 
        @Override
        public void stop()
        {
-               this.command.remove();
-               Moo.getEventBus().unregister(event);
+       }
+
+       @Override
+       public List<Command> getCommands()
+       {
+               return Arrays.<Command>asList(command);
+       }
+
+       @Override
+       protected void configure()
+       {
+               bind(dnsbl.class).toInstance(this);
+               
+               bind(DnsblConfiguration.class).toInstance(conf);
+
+               bind(BlacklistManager.class).toInstance(new BlacklistManager());
+               bind(ResultCache.class).toInstance(new ResultCache());
+
+               Multibinder<Command> commandBinder = Multibinder.newSetBinder(binder(), Command.class);
+               commandBinder.addBinding().to(CommandDnsbl.class);
+
+               Multibinder<EventListener> eventListenerBinder = Multibinder.newSetBinder(binder(), EventListener.class);
+               eventListenerBinder.addBinding().to(EventDnsblCheck.class);
+
+               Multibinder<Action> actionBinder = Multibinder.newSetBinder(binder(), Action.class);
+               actionBinder.addBinding().to(ActionAkill.class);
+               actionBinder.addBinding().to(ActionLog.class);
+       }
+
+       public Collection<Action> getAllActions()
+       {
+               return actions;
+       }
+
+       public Action getByName(String name)
+       {
+               for (Action a : getAllActions())
+               {
+                       if (a.getName().equals(name))
+                       {
+                               return a;
+                       }
+               }
+
+               return null;
        }
 }
index 07f16b7dc374f4eb583f8a1114f758195e64dc54..8bc46a0797a15ee69b0af2fc6b741fb4bdbcba35 100644 (file)
@@ -11,9 +11,9 @@ class CommandRizonTime extends Command
 {
        private HashMap<String, String> cache = new HashMap<String, String>();
 
-       public CommandRizonTime(Plugin pkg)
+       CommandRizonTime()
        {
-               super(pkg, "!RIZONTIME", "Calculates out a length of time in Rizon Time(tm)");
+               super("!RIZONTIME", "Calculates out a length of time in Rizon Time(tm)");
        }
 
        @Override
index 1cc9db322a693109586eaaabe6ffe4b1c227cf56..112a4c286e8eab8a3093816de34f5088c6201d85 100644 (file)
@@ -1,6 +1,7 @@
 package net.rizon.moo.plugin.fun;
 
 import com.google.common.eventbus.Subscribe;
+import com.google.inject.Inject;
 import java.util.HashMap;
 import java.util.Random;
 import java.util.concurrent.TimeUnit;
@@ -8,15 +9,19 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import net.rizon.moo.Moo;
+import net.rizon.moo.events.EventListener;
 import net.rizon.moo.events.EventPrivmsg;
 import net.rizon.moo.events.EventQuit;
+import net.rizon.moo.irc.Protocol;
 
 class TimedKill implements Runnable
 {
+       private Protocol protocol;
        private String dest, reason;
 
-       public TimedKill(final String dest, final String reason)
+       public TimedKill(Protocol protocol, String dest, String reason)
        {
+               this.protocol = protocol;
                this.dest = dest;
                this.reason = reason;
        }
@@ -24,11 +29,11 @@ class TimedKill implements Runnable
        @Override
        public void run()
        {
-               Moo.kill(this.dest, this.reason);
+               protocol.kill(this.dest, this.reason);
        }
 }
 
-class EventFun
+class EventFun implements EventListener
 {
        private static final Pattern killPattern = Pattern.compile("Killed \\(([^ ]*) \\(([^)]*)\\)\\)");
 
@@ -36,26 +41,29 @@ class EventFun
                        welcome = new HashMap<String, Integer>(),
                        gratz = new HashMap<String, Integer>();
 
+       @Inject
+       private Protocol protocol;
+
        @Subscribe
        public void onPrivmsg(EventPrivmsg evt)
        {
                String message = evt.getMessage(), source = evt.getSource(), channel = evt.getChannel();
                
                if (message.startsWith("\1ACTION pets " + Moo.me.getNick()))
-                       Moo.privmsg(channel, "\1ACTION moos\1");
+                       protocol.privmsg(channel, "\1ACTION moos\1");
                else if (message.startsWith("\1ACTION milks " + Moo.me.getNick()))
                {
                        int e = source.indexOf('!');
                        String nick = source.substring(0, e != -1 ? e : source.length());
-                       Moo.privmsg(channel, "\1ACTION kicks " + nick + " in the face\1");
+                       protocol.privmsg(channel, "\1ACTION kicks " + nick + " in the face\1");
                }
                else if (message.startsWith("\1ACTION feeds " + Moo.me.getNick()))
-                       Moo.privmsg(channel, "\1ACTION eats happily\1");
+                       protocol.privmsg(channel, "\1ACTION eats happily\1");
                else if (message.startsWith("\1ACTION kicks " + Moo.me.getNick()))
                {
                        int e = source.indexOf('!');
                        String nick = source.substring(0, e != -1 ? e : source.length());
-                       Moo.privmsg(channel, "\1ACTION body slams " + nick + "\1");
+                       protocol.privmsg(channel, "\1ACTION body slams " + nick + "\1");
                }
                else if (message.startsWith("\1ACTION brands " + Moo.me.getNick()))
                {
@@ -64,24 +72,24 @@ class EventFun
                        boolean kill = new Random().nextInt(100) == 0;
 
                        if (kill == false)
-                               Moo.privmsg(channel, "\1ACTION headbutts " + nick + " and proceeds to stomp on their lifeless body\1");
+                               protocol.privmsg(channel, "\1ACTION headbutts " + nick + " and proceeds to stomp on their lifeless body\1");
                        else
                        {
-                               Moo.privmsg(channel, "FEEL THE WRATH OF " + Moo.me.getNick().toUpperCase());
-                               Moo.kill(nick, "HOW DARE YOU ATTEMPT TO BRAND " + Moo.me.getNick().toUpperCase());
+                               protocol.privmsg(channel, "FEEL THE WRATH OF " + Moo.me.getNick().toUpperCase());
+                               protocol.kill(nick, "HOW DARE YOU ATTEMPT TO BRAND " + Moo.me.getNick().toUpperCase());
                        }
                }
                else if (message.startsWith("\1ACTION tips " + Moo.me.getNick()))
                {
                        int e = source.indexOf('!');
                        String nick = source.substring(0, e != -1 ? e : source.length());
-                       Moo.privmsg(channel, "\1ACTION inadvertently falls on " + nick + " and crushes them\1");
+                       protocol.privmsg(channel, "\1ACTION inadvertently falls on " + nick + " and crushes them\1");
                }
                else if (message.startsWith("\1ACTION slaughters " + Moo.me.getNick()))
                {
                        int e = source.indexOf('!');
                        String nick = source.substring(0, e != -1 ? e : source.length());
-                       Moo.privmsg(channel, "\1ACTION runs " + nick + " through a food processor and proceeds to eat them\1");
+                       protocol.privmsg(channel, "\1ACTION runs " + nick + " through a food processor and proceeds to eat them\1");
                }
        }
 
@@ -110,7 +118,7 @@ class EventFun
                                        if (r.nextBoolean())
                                                my_kill_reason = my_kill_reason.toUpperCase();
 
-                                       Moo.schedule(new TimedKill(killee, my_kill_reason), new Random().nextInt(250) + 60, TimeUnit.SECONDS);
+                                       Moo.schedule(new TimedKill(protocol, killee, my_kill_reason), new Random().nextInt(250) + 60, TimeUnit.SECONDS);
                                }
                        }
                        else if (kill_reason.toLowerCase().indexOf("welcome") > -1)
@@ -131,7 +139,7 @@ class EventFun
                                        if (r.nextBoolean())
                                                my_kill_reason = my_kill_reason.toUpperCase();
 
-                                       Moo.schedule(new TimedKill(killee, my_kill_reason), new Random().nextInt(250) + 60, TimeUnit.SECONDS);
+                                       Moo.schedule(new TimedKill(protocol, killee, my_kill_reason), new Random().nextInt(250) + 60, TimeUnit.SECONDS);
                                }
                        }
                        else if (kill_reason.toLowerCase().indexOf("congrat") > -1 || kill_reason.toLowerCase().indexOf("gratz") > -1)
@@ -146,7 +154,7 @@ class EventFun
                                        if (r.nextBoolean())
                                                my_kill_reason = my_kill_reason.toUpperCase();
 
-                                       Moo.schedule(new TimedKill(killee, my_kill_reason), new Random().nextInt(250) + 60, TimeUnit.SECONDS);
+                                       Moo.schedule(new TimedKill(protocol, killee, my_kill_reason), new Random().nextInt(250) + 60, TimeUnit.SECONDS);
                                }
                        }
                }
index a549ec91d218b0411c28a54a111b32a49e787da2..4de89c96030688c66e9de70f0433bf46cb4490d5 100644 (file)
@@ -1,14 +1,17 @@
 package net.rizon.moo.plugin.fun;
 
+import com.google.inject.Inject;
+import com.google.inject.multibindings.Multibinder;
+import java.util.Arrays;
+import java.util.List;
 import net.rizon.moo.Command;
-import net.rizon.moo.Moo;
 import net.rizon.moo.Plugin;
-import net.rizon.moo.conf.Protocol;
+import net.rizon.moo.events.EventListener;
 
-public class fun extends Plugin
+public class fun extends Plugin implements EventListener
 {
-       private Command rt;
-       private EventFun e;
+       @Inject
+       private CommandRizonTime rizonTime;
 
        public fun() throws Exception
        {
@@ -18,20 +21,30 @@ public class fun extends Plugin
        @Override
        public void start() throws Exception
        {
-               if (Moo.conf.general.protocol == Protocol.PLEXUS)
-               {
-                       rt = new CommandRizonTime(this);
-                       e = new EventFun();
-                       Moo.getEventBus().register(e);
-               }
        }
 
        @Override
        public void stop()
        {
-               if (rt != null)
-                       rt.remove();
-               if (e != null)
-                       Moo.getEventBus().unregister(e);
+       //      rt.remove();
+       }
+
+       @Override
+       protected void configure()
+       {
+               bind(fun.class).toInstance(this);
+               
+               Multibinder<Command> commandBinder = Multibinder.newSetBinder(binder(), Command.class);
+               commandBinder.addBinding().to(CommandRizonTime.class);
+
+               Multibinder<EventListener> eventListenerBinder = Multibinder.newSetBinder(binder(), EventListener.class);
+               eventListenerBinder.addBinding().toInstance(this);
+               eventListenerBinder.addBinding().to(EventFun.class);
+       }
+
+       @Override
+       public List<Command> getCommands()
+       {
+               return Arrays.<Command>asList(rizonTime);
        }
 }
\ No newline at end of file
index aeca89285f78ce7f01a6b14330574e11818f3393..f4feff6fb8398fa411d39f3d42c94097ea69574f 100644 (file)
@@ -1,13 +1,14 @@
 package net.rizon.moo;
 
 import java.util.ArrayList;
+import java.util.List;
 
 public abstract class Command
 {
        private Plugin pkg;
        private String cmdname;
        private String description;
-       private ArrayList<String> channels = new ArrayList<String>();
+       private List<String> channels = new ArrayList<>();
 
        public Command(Plugin pkg, final String cmdname, final String desc)
        {
@@ -15,14 +16,18 @@ public abstract class Command
                this.cmdname = cmdname;
                this.description = desc;
 
-               pkg.commands.add(this);
+               //pkg.commands.add(this);
+       }
+
+       public Command(String cmdname, String description)
+       {
+               this.cmdname = cmdname;
+               this.description = description;
        }
 
-       //@Override
        public void remove()
        {
-               pkg.commands.remove(this);
-               //super.remove();
+               //pkg.commands.remove(this);
        }
 
        public Plugin getPackage()
index fb7cd11546f0ff82c867fdd696b61001e1439a98..a5fff35c875b9242c8cd68ae007af575bbe8774b 100644 (file)
@@ -1,9 +1,11 @@
 package net.rizon.moo;
 
+import com.google.inject.Inject;
 import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
+import net.rizon.moo.conf.Config;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -67,9 +69,12 @@ class mailThread extends Thread
 
 public class Mail
 {
-       public static void send(final String to, final String subject, final String message)
+       @Inject
+       private Config conf;
+       
+       public void send(final String to, final String subject, final String message)
        {
-               String smpath = Moo.conf.mail.path;
+               String smpath = conf.mail.path;
 
                File sendmail = new File(smpath);
                if (sendmail.isFile() == false)
index 93492c4acbbdf958ea0de13166aabce28922143a..1d307a03cc18ea8b8fb327e8bdd367e0dc2914d5 100644 (file)
@@ -12,9 +12,7 @@ public class MessageManager
        public void run(IRCMessage message)
        {
                for (Message m : messages)
-               {
                        if (m.getName().equalsIgnoreCase(message.getCommand()))
                                m.run(message);
-               }
        }
 }
index d7945564cf25f2034707f7c9dc9878f370bafb8b..6c6e5c068016417bd0039f67780035afaf06a61b 100644 (file)
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -62,10 +63,10 @@ public class Moo
        private static final Logger logger = LoggerFactory.getLogger(Moo.class);
        private static final Date created = new Date();
        
-       private EventLoopGroup group = new NioEventLoopGroup(1);
+       private final EventLoopGroup group = new NioEventLoopGroup(1);
        public static io.netty.channel.Channel channel;
 
-       public static Config conf = null;
+       private Config conf;
        public static Database db = null;
        public static boolean quitting = false;
 
@@ -94,9 +95,14 @@ public class Moo
                moo.start();
        }
 
-       // Don't allow guice to JIT bind Moo
-       private Moo()
+       public Config getConf()
        {
+               return conf;
+       }
+
+       public void setConf(Config conf)
+       {
+               this.conf = conf;
        }
        
        private void run() throws InterruptedException
@@ -160,24 +166,16 @@ public class Moo
                        }
                }
 
+               logger.info("moo v{} starting up", Version.getFullVersion());
+
                this.rebuildInjector();
-//             List<Module> modules = new ArrayList<>();
-//             for (Plugin p : Plugin.getPlugins())
-//                     modules.add(p);
-//             modules.add(new MooModule());
-//             modules.add(new NettyModule());
-//             modules.add(new Plexus());
-//
-//             injector = Guice.createInjector(modules);
-//
-//             injector.injectMembers(this);
 
-               logger.info("moo v{} starting up", Version.getFullVersion());
+               eventManager.build();
 
                eventBus.post(new InitDatabases());
 
                eventBus.post(new LoadDatabases());
-               
+
                scheduleWithFixedDelay(databaseTimer, 5, TimeUnit.MINUTES);
 
                while (quitting == false)
@@ -240,11 +238,14 @@ public class Moo
                return moo.group.schedule(r, t, unit);
        }
 
-       private void rebuildInjector()
+       public void rebuildInjector()
        {
+               for (Plugin p : Plugin.getPlugins())
+                       p.stop();
+               
                List<Module> modules = new ArrayList<>();
 
-               modules.add(new MooModule());
+               modules.add(new MooModule(this));
                modules.add(new NettyModule());
                modules.add(new Plexus());
 
@@ -257,6 +258,14 @@ public class Moo
 
                eventManager.build();
 
-               // XXX these are scheduler stuff here
+               for (Plugin p : Plugin.getPlugins())
+                       try
+                       {
+                               p.start();
+                       }
+                       catch (Exception ex)
+                       {
+                               logger.warn("unable to start plugin " + p.getName(), ex);
+                       }
        }
 }
index c410564235fa8e6919cf92bc30ee4b9cede38cfd..66494c62a8074bd1ee4eaaf0bd07f9882cd1814e 100644 (file)
@@ -6,6 +6,7 @@ import com.google.inject.AbstractModule;
 import com.google.inject.Provides;
 import com.google.inject.matcher.Matchers;
 import com.google.inject.multibindings.Multibinder;
+import net.rizon.moo.conf.Config;
 import net.rizon.moo.events.EventListener;
 import net.rizon.moo.injectors.logger.LogTypeListener;
 import net.rizon.moo.irc.IRC;
@@ -14,16 +15,27 @@ import net.rizon.moo.irc.ServerManager;
 public class MooModule extends AbstractModule
 {
        private static IRC irc = new IRC();
+       private static ServerManager serverManager = new ServerManager();
+
+       private Moo moo;
+
+       MooModule(Moo moo)
+       {
+               this.moo = moo;
+       }
 
        @Override
        protected void configure()
        {
+               bind(Moo.class).toInstance(moo);
+               bind(Mail.class);
+               
                bind(EventBus.class).toInstance(new EventBus());
                
                bind(CommandManager.class).toInstance(new CommandManager());
                bind(MessageManager.class).toInstance(new MessageManager());
                bind(EventManager.class).toInstance(new EventManager());
-               bind(ServerManager.class).toInstance(new ServerManager());
+               bind(ServerManager.class).toInstance(serverManager);
                bind(DatabaseTimer.class).toInstance(new DatabaseTimer());
                
                bindListener(Matchers.any(), new LogTypeListener());
@@ -31,6 +43,12 @@ public class MooModule extends AbstractModule
                Multibinder<EventListener> eventListenerBinder = Multibinder.newSetBinder(binder(), EventListener.class);
                eventListenerBinder.addBinding().to(ServerManager.class);
        }
+       
+       @Provides
+       Config provideConfig()
+       {
+               return moo.getConf();
+       }
 
        @Provides
        IRC provideIRC()
index 36107318224f1df5159d3a20751613f6d93933dc..16f138f8cd3a99525d1b7380144ab1ec3480d99d 100644 (file)
@@ -4,6 +4,7 @@ import com.google.inject.AbstractModule;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.util.LinkedList;
+import java.util.List;
 
 public abstract class Plugin extends AbstractModule
 {
@@ -13,7 +14,7 @@ public abstract class Plugin extends AbstractModule
        private String name, desc;
        public String pname;
        protected ClassLoader loader; // Loader for this plugin
-       public LinkedList<Command> commands = new LinkedList<Command>();
+       //public List<Command> commands = new LinkedList<>();
 
        protected Plugin(String name, String desc)
        {
@@ -48,6 +49,8 @@ public abstract class Plugin extends AbstractModule
        public abstract void start() throws Exception;
        public abstract void stop();
 
+       public abstract List<Command> getCommands();
+
        //@SuppressWarnings("resource")
        private static Plugin loadPlugin(String base, String name, boolean core) throws Throwable
        {
@@ -72,7 +75,6 @@ public abstract class Plugin extends AbstractModule
                p.pname = name;
                p.loader = cl;
 
-               p.start();
                return p;
        }
 
index 3b3c1d8049329fdbc6971cf63a1919a22c712222..638ec61c2e6593c65e0c292a636b45bc9f287a77 100644 (file)
@@ -26,6 +26,7 @@ import javax.net.ssl.KeyManagerFactory;
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLEngine;
 import net.rizon.moo.Moo;
+import net.rizon.moo.conf.Config;
 
 public class ClientInitializer extends ChannelInitializer<SocketChannel>
 {
@@ -38,23 +39,26 @@ public class ClientInitializer extends ChannelInitializer<SocketChannel>
        private LoggingHandler loggingHandler;
        
        @Inject
-       private ClientHandler clientHandler;    
+       private ClientHandler clientHandler;
+
+       @Inject
+       private Config conf;
        
        @Override
        protected void initChannel(SocketChannel ch) throws Exception
        {
                ChannelPipeline pipeline = ch.pipeline();
                
-               if (Moo.conf.general.ssl)
+               if (conf.general.ssl)
                {
                        SslContext sslCtx;
                        
-                       if (Moo.conf.general.cert != null && Moo.conf.general.key != null)
+                       if (conf.general.cert != null && conf.general.key != null)
                        {
                                CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
                                
-                               byte[] certBytes = Files.readAllBytes(new File(Moo.conf.general.cert).toPath());
-                               byte[] keyBytes = Files.readAllBytes(new File(Moo.conf.general.key).toPath());
+                               byte[] certBytes = Files.readAllBytes(new File(conf.general.cert).toPath());
+                               byte[] keyBytes = Files.readAllBytes(new File(conf.general.key).toPath());
                                
                                X509Certificate cert = (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(certBytes));
                                PrivateKey key = (PrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
index ec6397cfb1e9c0877804bad7eea92c3448ece70b..4ab166136b5ad91dab2d4c31e639564506fd65a2 100644 (file)
@@ -5,13 +5,17 @@ import io.netty.channel.Channel;
 
 public class NettyModule extends AbstractModule
 {
+       // Only allow one client handler, since netty calls back into this. We need to
+       // update the injections into it
+       private static final ClientHandler handler = new ClientHandler();
+
        @Override
        protected void configure()
        {
                bind(ClientInitializer.class);
                bind(Handler.class);
                bind(LoggingHandler.class);
-               bind(ClientHandler.class);
+               bind(ClientHandler.class).toInstance(handler);
                bind(Channel.class).toProvider(ChannelProvider.class);
        }
 }
index e88247e723dff066025f582f80b29dbbb93d354b..6b07859a831d1765aca4f5cbf634bc99243bb5b0 100644 (file)
@@ -5,13 +5,16 @@ import com.google.inject.Provider;
 import java.util.EnumSet;
 import net.rizon.moo.Moo;
 import static net.rizon.moo.Moo.akillServ;
-import static net.rizon.moo.Moo.conf;
+import net.rizon.moo.conf.Config;
 import net.rizon.moo.io.IRCMessage;
 
 public class Protocol
 {
        @Inject
        private Provider<io.netty.channel.Channel> channelProvider;
+
+       @Inject
+       private Config conf;
        
        public void write(String command, Object... args)
        {
@@ -69,7 +72,7 @@ public class Protocol
 
        public void reply(String source, String target, String buffer)
        {
-               if (target.equalsIgnoreCase(Moo.conf.general.nick))
+               if (target.equalsIgnoreCase(conf.general.nick))
                        notice(source, buffer);
                else
                        privmsg(target, buffer);
index 0a3c4c0a7b53fff2f26d59894246ba9e65b65ec7..3b82f1ad14a307c9cfe9ab610ba5e9ffa085b185 100644 (file)
@@ -11,8 +11,9 @@ public class ConsoleFilter extends Filter<ILoggingEvent>
        @Override
        public FilterReply decide(ILoggingEvent event)
        {
-               boolean show = Moo.conf.debug || event.getLevel() != Level.DEBUG;
-               return show ? FilterReply.ACCEPT : FilterReply.DENY;
+               //boolean show = Moo.conf.debug || event.getLevel() != Level.DEBUG;
+               //return show ? FilterReply.ACCEPT : FilterReply.DENY;
+               return FilterReply.ACCEPT;
        }
 
 }
index a98c9684d3a01a30d0e10ce337c7cc9fa8e58b6a..0da4cf45e47b903d793783646343dd3fb85ac3ef 100644 (file)
@@ -29,9 +29,9 @@ public class Logger extends UnsynchronizedAppenderBase<ILoggingEvent>
                Level level = event.getLevel();
                boolean bad = level == Level.ERROR || level == Level.WARN || level == Level.ALL;
 
-               if (Moo.conf != null)
-                       if (level == Level.INFO || bad)
-                               for (final String ch : Moo.conf.moo_log_channels)
+//             if (Moo.conf != null)
+//                     if (level == Level.INFO || bad)
+//                             for (final String ch : Moo.conf.moo_log_channels)
                                {
 //                                     if (message != null)
 //                                             Moo.privmsg(ch, message); // XXX logback makes this so can't really inject? post event? cant get eventbus.
index c9527bb36fa4a1d06cd15b7c9143a92eefe6fcce..32bf567ac17b60744de30b2a782df2242b5f3db2 100644 (file)
@@ -4,6 +4,7 @@ import com.google.common.eventbus.EventBus;
 import com.google.inject.Inject;
 import net.rizon.moo.Message;
 import net.rizon.moo.Moo;
+import net.rizon.moo.conf.Config;
 import net.rizon.moo.irc.Server;
 import net.rizon.moo.irc.User;
 import net.rizon.moo.events.OnConnect;
@@ -25,6 +26,9 @@ public class Message001 extends Message
 
        @Inject
        private ServerManager serverManager;
+
+       @Inject
+       private Config conf;
        
        public Message001()
        {
@@ -34,15 +38,15 @@ public class Message001 extends Message
        @Override
        public void run(IRCMessage message)
        {
-               if (Moo.conf.general.oper != null)
-                       protocol.write("OPER", Moo.conf.general.oper.name, Moo.conf.general.oper.pass);
-               if (Moo.conf.general.nickserv != null)
-                       protocol.privmsg("NickServ", "IDENTIFY " + Moo.conf.general.nickserv.pass);
+               if (conf.general.oper != null)
+                       protocol.write("OPER", conf.general.oper.name, conf.general.oper.pass);
+               if (conf.general.nickserv != null)
+                       protocol.privmsg("NickServ", "IDENTIFY " + conf.general.nickserv.pass);
 
-               Moo.me = new User(Moo.conf.general.nick);
+               Moo.me = new User(conf.general.nick);
                irc.insertUser(Moo.me);
 
-               for (String s : Moo.conf.channels)
+               for (String s : conf.channels)
                        protocol.join(s);
 
                protocol.write("MAP");
index d54d8a997774bf4ad99a0a88e09c026531a25d15..e56bd02cf58b37c19f34cd056ba8f9557440597a 100644 (file)
@@ -3,6 +3,7 @@ package net.rizon.moo.protocol;
 import com.google.inject.Inject;
 import net.rizon.moo.Message;
 import net.rizon.moo.Moo;
+import net.rizon.moo.conf.Config;
 import net.rizon.moo.io.IRCMessage;
 import net.rizon.moo.irc.Protocol;
 
@@ -10,6 +11,9 @@ public class MessageInvite extends Message
 {
        @Inject
        private Protocol protocol;
+
+       @Inject
+       private Config conf;
        
        public MessageInvite()
        {
@@ -20,7 +24,7 @@ public class MessageInvite extends Message
        public void run(IRCMessage message)
        {
                if (message.getParams().length > 1 && message.getParams()[0].equalsIgnoreCase(Moo.me.getNick()))
-                       if (Moo.conf.channelsContains(message.getParams()[1]))
+                       if (conf.channelsContains(message.getParams()[1]))
                                protocol.join(message.getParams()[1]);
        }
 }
\ No newline at end of file
index d437cc5191b52cce9504c05d233e39d035c60b8e..0e7264330604c67d3ad4c5ca99af27cd15676821 100644 (file)
@@ -8,6 +8,7 @@ import java.util.regex.Pattern;
 
 import net.rizon.moo.Message;
 import net.rizon.moo.Moo;
+import net.rizon.moo.conf.Config;
 import net.rizon.moo.events.EventClientConnect;
 import net.rizon.moo.events.EventNotice;
 import net.rizon.moo.events.OnServerLink;
@@ -30,6 +31,9 @@ public class MessageNotice extends Message
        @Inject
        private ServerManager serverManager;
 
+       @Inject
+       private Config conf;
+
        public MessageNotice()
        {
                super("NOTICE");
@@ -61,10 +65,10 @@ public class MessageNotice extends Message
        // XXX this should be in a plugin
        private void process(String source, String message)
        {
-               if (Moo.conf.general.nickserv != null && source.equals(Moo.conf.general.nickserv.mask))
+               if (conf.general.nickserv != null && source.equals(conf.general.nickserv.mask))
                {
                        if (message.contains("This nickname is registered"))
-                               protocol.privmsg(source, "IDENTIFY " + Moo.conf.general.nickserv.pass);
+                               protocol.privmsg(source, "IDENTIFY " + conf.general.nickserv.pass);
                }
                else if (source.indexOf('@') == -1)
                {
index bc6584150efd875aa5b34e4d76e827c1c0d3faa9..a030e46197701bfeac213f521880dbbb65c372fe 100644 (file)
@@ -7,6 +7,7 @@ import net.rizon.moo.CommandManager;
 
 import net.rizon.moo.Message;
 import net.rizon.moo.Moo;
+import net.rizon.moo.conf.Config;
 import net.rizon.moo.events.EventPrivmsg;
 import net.rizon.moo.io.IRCMessage;
 import net.rizon.moo.irc.Protocol;
@@ -21,6 +22,9 @@ public class MessagePrivmsg extends Message
        
        @Inject
        private CommandManager manager;
+
+       @Inject
+       private Config conf;
        
        public MessagePrivmsg()
        {
@@ -38,7 +42,7 @@ public class MessagePrivmsg extends Message
                eventBus.post(new EventPrivmsg(message.getSource(), target, text));
 
                if (text.equals("\1VERSION\1"))
-                       protocol.notice(message.getNick(), "\1VERSION " + Moo.conf.version + "\1");
+                       protocol.notice(message.getNick(), "\1VERSION " + conf.version + "\1");
                else if (text.equals("\1TIME\1"))
                        protocol.notice(message.getNick(), "\1TIME " + (new Date().toString()) + "\1");
                
diff --git a/pom.xml b/pom.xml
index ccc49d3ab32aad7fad573521e5e2768ae80cc437..d07f217ce00ae123804aeda500f57fb59241aea4 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                <module>commands</module>
                <module>commits</module>-->
                <module>core</module>
-<!--           <module>dnsbl</module>
-               <module>dnsblstats</module>
+               <module>dnsbl</module>
+<!--           <module>dnsblstats</module>-->
                <module>fun</module>
-               <module>grapher</module>
+<!--           <module>grapher</module>
                <module>logging</module>
                <module>mxbl</module>
                <module>osflood</module>