]> jfr.im git - irc/rizon/acid.git/commitdiff
Use Channels to refer to Channels many places instead of String
authorAdam <redacted>
Wed, 22 Oct 2014 23:28:17 +0000 (19:28 -0400)
committerAdam <redacted>
Wed, 22 Oct 2014 23:28:17 +0000 (19:28 -0400)
acid/src/main/java/net/rizon/acid/core/AcidUser.java
acid/src/main/java/net/rizon/acid/core/User.java
acid/src/main/java/net/rizon/acid/messages/Join.java
acid/src/main/java/net/rizon/acid/messages/Kick.java
acid/src/main/java/net/rizon/acid/messages/Part.java
acid/src/main/java/net/rizon/acid/messages/SJoin.java
trapbot/src/main/java/net/rizon/acid/plugins/trapbot/commands/Untrap.java

index ab7c6adf315ae528d4eb9ae93a2774c95cc5568f..6279caa851e0fe4011e12f1aacc107d5803a6a3c 100644 (file)
@@ -32,24 +32,16 @@ public class AcidUser extends User
                if (this.getNSPass() != null && !this.getNSPass().isEmpty())
                        Protocol.privmsg(this.getUID(), "NickServ@services.rizon.net", "IDENTIFY " + this.getNSPass()); // XXX
 
-               for (String channel : this.getChannels())
-               {
-                       Channel chan = Channel.findChannel(channel);
-                       if (chan == null)
-                       {
-                               chan = new Channel(channel, AcidCore.getTS());
-                               chan.setMode('n'); chan.setMode('t');
-                       }
+               for (Channel chan : this.getChannels())
                        Protocol.join(this, chan);
-               }
        }
        
        public void joinChan(final String channel)
        {
-               if (this.isOnChan(channel))
-                       return;
-               
                Channel chan = Channel.findChannel(channel);
+               if (chan != null && this.isOnChan(chan))
+                       return;
+
                if (chan == null)
                {
                        chan = new Channel(channel, AcidCore.getTS());
@@ -58,19 +50,17 @@ public class AcidUser extends User
                if (!Acidictive.me.isBursting())
                        Protocol.join(this, chan);
                chan.addUser(this.getNick(), "");
-               this.addChan(chan.getName(), "" + AcidCore.getTS());
+               this.addChan(chan);
        }
        
-       public void partChan(final String channel)
+       public void partChan(Channel chan)
        {
-               if (!this.isOnChan(channel))
+               if (!this.isOnChan(chan))
                        return;
                
-               Protocol.part(this, channel);
-               Channel chan = Channel.findChannel(channel);
-               if (chan != null)
-                       chan.removeUser(this.getNick());
-               this.remChan(channel);
+               Protocol.part(this, chan.getName());
+               chan.removeUser(this.getNick());
+               this.remChan(chan);
        }
        
        public void quit(final String reason)
index 5807b90981691fa9a1df549f8f081896fb8218f4..e4933888d9d812cfd4ccf466dbc47fe6a2bca761 100644 (file)
@@ -1,18 +1,19 @@
 package net.rizon.acid.core;
 
+import net.rizon.acid.conf.AccessPreset;
+
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Set;
 import java.util.logging.Level;
 
-import net.rizon.acid.conf.AccessPreset;
-
 public class User implements Comparable<User>
 {
        private static final Logger log = Logger.getLogger(User.class.getName());
@@ -23,7 +24,7 @@ public class User implements Comparable<User>
        private String flags; // Access flags
        private ArrayList<String> oldNicks;
        private Hashtable<String, ArrayList<Integer>> chans;
-       private Hashtable<String, String> chanList;
+       private HashSet<Channel> chanList;
 
        public User(String nick, String user, String host, String vhost, String name,
                        Server server, int nickTS, int conTS, String modes, String UID, String ip)
@@ -47,7 +48,7 @@ public class User implements Comparable<User>
                this.su = "";
                oldNicks = new ArrayList<String>();
                chans = new Hashtable<String, ArrayList<Integer>>();
-               chanList = new Hashtable<String, String>();
+               chanList = new HashSet<Channel>();
 
                uidMap.put(UID, this);
                nickMap.put(nick.toLowerCase(), this);
@@ -57,12 +58,9 @@ public class User implements Comparable<User>
 
        public void onQuit()
        {
-               for (Iterator<String> it = this.getChannels().iterator(); it.hasNext();)
+               for (Iterator<Channel> it = chanList.iterator(); it.hasNext();)
                {
-                       Channel chan = Channel.findChannel(it.next());
-                       if (chan == null)
-                               continue;
-
+                       Channel chan = it.next();
                        chan.removeUser(this.getNick());
                        it.remove();
                }
@@ -107,48 +105,41 @@ public class User implements Comparable<User>
 
        }
 
-       public boolean isOnChan(String chan)
+       public boolean isOnChan(Channel chan)
        {
-               return chanList.get(chan.toLowerCase()) != null;
+               return chanList.contains(chan);
        }
 
-       public void addChan(String chan, String TS)
+       public void addChan(Channel chan)
        {
-               if (chan != null && !chan.equals(""))
-               {
-                       if (chanList.get(chan.toLowerCase()) == null)
-                               chanList.put(chan.toLowerCase(), TS);
-               }
+               chanList.add(chan);
        }
 
-       public void remChan(String chan)
+       public void remChan(Channel chan)
        {
-               if (chan != null && !chan.equals(""))
-               {
-                       chanList.remove(chan.toLowerCase());
-               }
+               chanList.remove(chan);
        }
 
-       public Set<String> getChannels()
+       public Set<Channel> getChannels()
        {
-               return this.chanList.keySet();
+               return this.chanList;
        }
 
        public String getChanStr()
        {
-               String s = "none";
+               String s = "";
 
-               for (Iterator<String> it = chanList.keySet().iterator(); it.hasNext();)
+               for (Channel c : chanList)
                {
-                       Channel chan = Channel.findChannel(it.next());
-
-                       String temp = chan.getModes(this.getNick()) + chan.getName();
-                       if (s.equals("none"))
-                               s = temp;
+                       if (s.isEmpty())
+                               s = c.getName();
                        else
-                               s += " " + temp;
+                               s += " " + c.getName();
                }
 
+               if (s.isEmpty())
+                       s = "none";
+
                return s;
        }
 
@@ -175,12 +166,8 @@ public class User implements Comparable<User>
 
                this.setMode("-r");
 
-               for (Iterator<String> it = this.getChannels().iterator(); it.hasNext();)
+               for (Channel chan : chanList)
                {
-                       Channel chan = Channel.findChannel(it.next());
-                       if (chan == null)
-                               continue;
-
                        chan.onNick(oldnick, this.getNick());
                }
        }
@@ -203,9 +190,7 @@ public class User implements Comparable<User>
 
        public boolean hasMode(String mode)
        {
-               if (modes.indexOf(mode) != -1)
-                       return true;
-               return false;
+               return modes.contains(mode);
        }
 
        public void setMode(String mode)
index 56119575dba03bb0ed6137eb66fb3bfc27fe99c1..2d52f7ca678eba13f6d6a5074f1e73ab823cf8e9 100644 (file)
@@ -24,7 +24,7 @@ public class Join extends Message
                        chan = new Channel(channel, Integer.parseInt(ts));
 
                chan.addUser(u.getNick(), "");
-               u.addChan(chan.getName(), ts);
+               u.addChan(chan);
 
                User[] user = new User[1];
                user[0] = u;
index 85a244f27bb9c75be26fa929be4977023c21cb6d..87d0798f3d935eef6f6aff34cdf4064b8eaff463 100644 (file)
@@ -1,7 +1,5 @@
 package net.rizon.acid.messages;
 
-import java.util.logging.Level;
-
 import net.rizon.acid.core.AcidCore;
 import net.rizon.acid.core.Acidictive;
 import net.rizon.acid.core.Channel;
@@ -9,6 +7,8 @@ import net.rizon.acid.core.Message;
 import net.rizon.acid.core.Server;
 import net.rizon.acid.core.User;
 
+import java.util.logging.Level;
+
 public class Kick extends Message
 {
        public Kick()
@@ -43,7 +43,7 @@ public class Kick extends Message
                }
 
                chan.removeUser(kickee.getNick());
-               kickee.remChan(chan.getName());
+               kickee.remChan(chan);
 
                Acidictive.onKick(kicker, kickee, channel, params[2]);
        }
index 8bb0aac0eb29bbf5d534cb3113ba2b325d1804c1..004b6183a2cf27d9d136a5f4a5703774d21199dc 100644 (file)
@@ -1,13 +1,13 @@
 package net.rizon.acid.messages;
 
-import java.util.logging.Level;
-
 import net.rizon.acid.core.AcidCore;
 import net.rizon.acid.core.Acidictive;
 import net.rizon.acid.core.Channel;
 import net.rizon.acid.core.Message;
 import net.rizon.acid.core.User;
 
+import java.util.logging.Level;
+
 public class Part extends Message
 {
        public Part()
@@ -28,7 +28,7 @@ public class Part extends Message
                }
 
                chan.removeUser(u.getNick());
-               u.remChan(chan.getName());
+               u.remChan(chan);
 
                Acidictive.onPart(u.getNick(), chan.getName());
        }
index 9996c8890a624ffab61a62a212f992c3defdd181..021a649ca50776882f89073f2576e1392c81c0b6 100644 (file)
@@ -1,7 +1,5 @@
 package net.rizon.acid.messages;
 
-import java.util.logging.Level;
-
 import net.rizon.acid.core.AcidCore;
 import net.rizon.acid.core.Acidictive;
 import net.rizon.acid.core.Channel;
@@ -9,6 +7,8 @@ import net.rizon.acid.core.Message;
 import net.rizon.acid.core.Server;
 import net.rizon.acid.core.User;
 
+import java.util.logging.Level;
+
 public class SJoin extends Message
 {
        public SJoin()
@@ -87,7 +87,7 @@ public class SJoin extends Message
                        if (users[i] != null)
                        {
                                chan.addUser(users[i].getNick(), keep_their_modes ? getModes(u[i]) : "");
-                               users[i].addChan(chan.getName(), "" + ts); // wtf?
+                               users[i].addChan(chan);
                        }
                        else
                                AcidCore.log.log(Level.WARNING, "SJOIN for nonexistant user " + stripped_user + " from " + source.getName());
index 979de412219493db5278a6b96d6b840653e022ff..2434e64f040f810e7ad4657bd85d5050db3be995 100644 (file)
@@ -33,7 +33,7 @@ public class Untrap extends Command
                        return;
                }
 
-               if (!u.isOnChan(trapchan.getName()))
+               if (!u.isOnChan(trapchan))
                {
                        Acidictive.reply(x, to, c, "User " + u.getNick() + " is on on " + trapbot.getTrapChanName());
                        return;