From: christinaa Date: Tue, 29 Aug 2017 19:01:00 +0000 (-0600) Subject: fix my earlier stupidity, add implementation of ::on that allows doing what it's... X-Git-Url: https://jfr.im/git/irc/rizon/acid.git/commitdiff_plain/bfe4d8202e6486f04550936a9b04fcd10379ad5b fix my earlier stupidity, add implementation of ::on that allows doing what it's supposed to without doing a second set of lookups, otherwise fallback to string ::on (in AcidCore in case of a non TS message) or in Message in case of a TS message for the sake of backwards compatibility with everything else that does a second set of lookups --- diff --git a/acid/src/main/java/net/rizon/acid/core/AcidCore.java b/acid/src/main/java/net/rizon/acid/core/AcidCore.java index 9cba617..cd2a12b 100644 --- a/acid/src/main/java/net/rizon/acid/core/AcidCore.java +++ b/acid/src/main/java/net/rizon/acid/core/AcidCore.java @@ -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 diff --git a/acid/src/main/java/net/rizon/acid/core/Message.java b/acid/src/main/java/net/rizon/acid/core/Message.java index 8e66aed..ad54606 100644 --- a/acid/src/main/java/net/rizon/acid/core/Message.java +++ b/acid/src/main/java/net/rizon/acid/core/Message.java @@ -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 messages; public static Message findMessage(String name) diff --git a/acid/src/main/java/net/rizon/acid/messages/TMode.java b/acid/src/main/java/net/rizon/acid/messages/TMode.java index 5694efa..83c4212 100644 --- a/acid/src/main/java/net/rizon/acid/messages/TMode.java +++ b/acid/src/main/java/net/rizon/acid/messages/TMode.java @@ -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