]> jfr.im git - irc/rizon/acid.git/commitdiff
fix my earlier stupidity, add implementation of ::on that allows doing what it's...
authorchristinaa <redacted>
Tue, 29 Aug 2017 19:01:00 +0000 (13:01 -0600)
committerchristinaa <redacted>
Tue, 29 Aug 2017 19:01:00 +0000 (13:01 -0600)
acid/src/main/java/net/rizon/acid/core/AcidCore.java
acid/src/main/java/net/rizon/acid/core/Message.java
acid/src/main/java/net/rizon/acid/messages/TMode.java

index 9cba6176d24080dff7bcfc3b9ecd36d1f27bb82c..cd2a12bfc700e35c8d213e7c859d13616427d499 100644 (file)
@@ -128,7 +128,18 @@ public abstract class AcidCore
                        m.onServer(server, params);
                }
 
-               m.on(source, params);
+               if (server != null || user != null)
+               {
+                       /*
+                        * Message class will take care of backwards compatibility
+                        * for stuff still using redundant checks.
+                        */
+                       m.on(server, user, params);
+               }
+               else
+               {
+                       m.on(source, params);
+               }
        }
 
        public static void run() throws InterruptedException
index 8e66aed29efe06d229f1e650a2fc1da73b8ea6a9..ad5460655d365c0be735b7be4e6b0c65a1520de5 100644 (file)
@@ -51,6 +51,32 @@ public abstract class Message
        public void onServer(Server source, String[] params) { }
        public void on(String source, String[] params) { }
 
+       /*
+        * handle a message that could come from either UID or SID and matched
+        * either one of them. 
+        */
+       public void on(Server server, User user, String[] params) {
+               /* default implementation for backwards compat */
+               if (user != null && server == null)
+               {
+                       on(user.getNick(), params);
+               }
+               else if (server != null && user == null)
+               {
+                       on(server.getName(), params);
+               }
+               else
+               {
+                       /*
+                        * both server and user are set, this shouldn't be possible
+                        * unless something got changed in AcidCore. or both are null
+                        * which shouldn't be possible either.
+                        */
+                       throw new RuntimeException("both server and user are not null or both are null");
+               }
+
+       }
+
        private static HashMap<String, Message> messages;
 
        public static Message findMessage(String name)
index 5694efae798577fdc32960a660fbaeb5fcc884f7..83c4212addaff9f9a7b8b27c47c17f64ac5d5958 100644 (file)
@@ -24,8 +24,9 @@ public class TMode extends Message
                super("TMODE");
        }
 
-       /* common handler */
-       private void handleTsModeChange(String setBy, String[] params) {
+       @Override
+       public void on(Server server, User user, String[] params)
+       {
                Channel chan = Channel.findChannel(params[1]);
                if (chan == null || shouldDropTsMessage(chan.getTS(), params[0]))
                        return;
@@ -34,27 +35,12 @@ public class TMode extends Message
                for (int i = 3; i < params.length; i++)
                        modes += " " + params[i];
 
-               Acidictive.onChanMode(setBy, chan, modes);
+               Acidictive.onChanMode(
+                       user != null ? user.getNick() : server.getName(),
+                       chan,
+                       modes);
 
                if (chan.size() == 0 && !chan.hasMode('z'))
                        chan.destroy();
        }
-
-       /*
-        * old implementation handled these in ::on which is redundant since
-        * AcidCore::processMessage already does these lookups, no need to
-        * do them again.
-        */
-
-       @Override
-       public void onUser(User user, String[] params)
-       {
-               handleTsModeChange(user.getNick(), params);
-       }
-
-       @Override
-       public void onServer(Server server, String[] params)
-       {
-               handleTsModeChange(server.getName(), params);
-       }
 }
\ No newline at end of file