]> jfr.im git - irc/rizon/acid.git/commitdiff
add support for storing ban-like modes (only +e/+b for now) for channels
authorchristinaa <redacted>
Tue, 29 Aug 2017 08:30:54 +0000 (01:30 -0700)
committerchristinaa <redacted>
Tue, 29 Aug 2017 08:30:54 +0000 (01:30 -0700)
acid/src/main/java/net/rizon/acid/core/Channel.java

index 265960383365a4726cc1a1bd3fd75e0425829062..3e0c6b1d2ceed81a9328fd49bcda2646a54f4b5b 100644 (file)
@@ -1,8 +1,9 @@
 package net.rizon.acid.core;
 
 import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Set;
+import java.util.HashSet;
 import java.util.Collection;
 import java.util.TreeMap;
 import org.slf4j.Logger;
@@ -20,6 +21,14 @@ public class Channel
        private String key;
        private int limit;
 
+       /*
+        * support for ban-like modes (as the TS6 spec calls them) that include
+        * a mask with them. only handle those for now, stuff like +I can be added
+        * easily if it's needed.
+        */
+       private HashSet<String> modesBans = new HashSet<String>();
+       private HashSet<String> modesExempt = new HashSet<String>();
+
        public Channel(String channel, int ts)
        {
                this.ts = ts;
@@ -107,6 +116,34 @@ public class Channel
                return modes.indexOf(mode) != -1;
        }
 
+       /* interface for message handlers to change ban-like modes */
+       public void changeMaskMode(char mode, boolean adding, String mask)
+       {
+               Set<String> set;
+
+               if (mode == 'b')
+                       set = modesBans;
+               else if (mode == 'e')
+                       set = modesExempt;
+               else
+                       return;
+
+               if (adding)
+                       set.add(mask);
+               else
+                       set.remove(mask);
+       }
+
+       public Set<String> getBans()
+       {
+               return modesBans;
+       }
+
+       public Set<String> getExempts()
+       {
+               return modesExempt;
+       }
+
        public String getKey()
        {
                return key;
@@ -212,8 +249,6 @@ public class Channel
                Acidictive.reply(target, to, c, "Listed " + (owners.size() + admins.size() + ops.size() + hops.size() + voices.size() + regs.size()) + " users that are currently in " + channel);
        }
 
-       private static HashMap<String, Channel> channelMap = new HashMap<String, Channel>();
-
        public static Set<String> getChannels()
        {
                return channelMap.keySet();