]> jfr.im git - irc/rizon/acid.git/commitdiff
Allow multiple commands with the same name if on different channels
authorAdam <redacted>
Thu, 4 Dec 2014 06:13:50 +0000 (01:13 -0500)
committerAdam <redacted>
Thu, 4 Dec 2014 06:13:50 +0000 (01:13 -0500)
Add authflags protocol function
Add priv for nonoper commands in channels

acid/src/main/java/net/rizon/acid/conf/Command.java
acid/src/main/java/net/rizon/acid/core/AcidUser.java
acid/src/main/java/net/rizon/acid/core/Acidictive.java
acid/src/main/java/net/rizon/acid/core/Protocol.java

index 5ca7aff77c9c58eedd08fbbc57405aad28947a4c..143625394dc163c70b49454adf672b5f36466f3e 100644 (file)
@@ -12,7 +12,7 @@ public class Command implements Validatable
 
        public boolean allowsChannel(String channel)
        {
-               if (channels != null)
+               if (channels != null && channel != null)
                        for (String s : channels)
                                if (Acidictive.conf.getChannelNamed(s).equalsIgnoreCase(channel))
                                        return true;
index fea1fb0025c908e759e08a838feafd730659782a..1ff2e3082c350643eaa2ec02f38088f8a3542d32 100644 (file)
@@ -77,11 +77,11 @@ public class AcidUser extends User
                        return null;
        }
 
-       public net.rizon.acid.conf.Command findConfCommand(final String name)
+       public net.rizon.acid.conf.Command findConfCommand(String name, String channel)
        {
                if (client != null && this.client.commands != null)
                        for (net.rizon.acid.conf.Command c : this.client.commands)
-                               if (c.name.equalsIgnoreCase(name))
+                               if (c.name.equalsIgnoreCase(name) && c.allowsChannel(channel))
                                        return c;
                return null;
        }
index 004f055bb47335ec2e88bdc240a05de906976689..431d138d8bb236e01326d68de7da618a0365dc0e 100644 (file)
@@ -220,8 +220,6 @@ public class Acidictive extends AcidCore
                                                }
                                        }
                                }
-                               else
-                                       return;
                        }
 
                        // Not destined for anything else, must be a command.
@@ -246,7 +244,7 @@ public class Acidictive extends AcidCore
                                        if (u instanceof AcidUser)
                                        {
                                                AcidUser t = (AcidUser) u;
-                                               net.rizon.acid.conf.Command cmd = t.findConfCommand(command);
+                                               net.rizon.acid.conf.Command cmd = t.findConfCommand(command, c.getName());
 
                                                if (cmd != null)
                                                {
@@ -270,7 +268,7 @@ public class Acidictive extends AcidCore
                                        return;
 
                                to = (AcidUser) targ;
-                               confCommand = to.findConfCommand(command);
+                               confCommand = to.findConfCommand(command, null);
                        }
 
                        if (confCommand == null)
@@ -285,8 +283,6 @@ public class Acidictive extends AcidCore
                        if (commandClass == null)
                                return;
 
-                       Command cmd = (Command) commandClass.newInstance();
-
                        if (recipient.startsWith("#"))
                        {
                                // In the proper channels commands can go without access checks. (ish)
@@ -294,16 +290,25 @@ public class Acidictive extends AcidCore
                                {
                                        return; // Access
                                }
-
+                               
                                // Now that we're in the right channel check for just being logged in OR +o OR spoof
-                               if (x.getIdentNick().isEmpty() && !x.hasMode("o") && !x.getIP().equals("0"))
+                               if (!x.getIdentNick().isEmpty() || x.hasFlags("o") || x.getIP().equals("0"))
                                {
-                                       return; // Access
+                                       // ok
+                               }
+                               else
+                               {
+                                       // Only allow explicit "anyone" commands
+                                       if (confCommand.privilege == null || !confCommand.privilege.equals("anyone"))
+                                               return;
                                }
                        }
                        // Message to me, check priv
                        else
                        {
+                               if (!x.hasMode("o"))
+                                       return;
+                               
                                // Non priv commands can be used by any oper
                                if (confCommand.privilege == null)
                                {
@@ -321,6 +326,8 @@ public class Acidictive extends AcidCore
                                        return;
                                }
                        }
+                       
+                       Command cmd = (Command) commandClass.newInstance();
 
                        if (args.length < cmd.GetMinArgs())
                        {
index fb9b2179df4735695cc79a30d382cd42d2f436d2..d386b1b030b01cbd939d82de4213ee3bfabbb05e 100644 (file)
@@ -225,4 +225,9 @@ public class Protocol
        {
                AcidCore.sendln(":" + AcidCore.me.getSID() + " " + num + " " + what);
        }
+
+       public static void authflags(User target, String flags)
+       {
+               encap(target.getServer().getName(), "AUTHFLAGS", target.getUID() + " " + flags);
+       }
 }