Viewing Issue Advanced Details

ID 0001816 Category [DMDirc] IRC Parser Severity minor
Reproducibility always Date Submitted 2008-09-17 21:41 Last Update 2009-11-21 22:56
Reporter MD87 Assigned To Dataforce View Status public
Priority high Status closed Resolution fixed
Platform Fixed in Version Target Version 0.6.3m2
Product Version Product Build
Summary 0001816: Parser support for opnotices
Description
Parser support for opnotices
Needs unit test yes
Upstream Bug URL

Relationships

blocks 0001917closedMD87 Channel onotices should appear in the channel window 

Notes

authorShane Mc Cormack <shane@dmdirc.com>2009-07-03 19:55:21 (GMT)
commit809132dacab790d94c485e24664babe324b298c0 (patch) (side-by-side diff)
Add support to the parser for OP NOTICES.
Also supports ANY <prefix>#channel <NOTICE|PRIVMSG> as allowed by some IRCDs. Fixes issue 1816.
-rw-r--r--src/com/dmdirc/parser/irc/ProcessMessage.java51
-rw-r--r--src/com/dmdirc/parser/irc/callbacks/CallbackManager.java1
-rw-r--r--src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelModeMessage.java58
-rw-r--r--src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelModeNotice.java58
4 files changed, 165 insertions, 3 deletions
Click to Expand/Collapse
diff src/com/dmdirc/parser/irc/ProcessMessage.java
@@ -132,10 +132,21 @@ public class ProcessMessage extends IRCProcessor {
// OnUnknown* Callbacks are fired if the target was neither of the above
// Actions and CTCPs are send as PRIVMSGS
// CTCPReplies are sent as Notices
- if (isValidChannelName(token[2])) {
- iChannel = getChannelInfo(token[2]);
+
+ // Check if we have a Mode Prefix for channel targets.
+ // Non-Channel messages still use the whole token, even if the first char
+ // is a prefix.
+ // CTCP and CTCPReplies that are aimed at a channel with a prefix are
+ // handled as if the prefix wasn't used. This can be changed in the future
+ // if desired.
+ final char modePrefix = token[2].charAt(1);
+ final boolean hasModePrefix = (myParser.hPrefixMap.containsKey(modePrefix) && !myParser.hPrefixModes.containsKey(modePrefix));
+ final String targetName = (hasModePrefix) ? token[2].substring(1) : token[2];
+
+ if (isValidChannelName(targetName)) {
+ iChannel = getChannelInfo(targetName);
if (iChannel == null) {
- // callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got message for channel ("+token[2]+") that I am not on.", myParser.getLastLine()));
+ // callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got message for channel ("+targetName+") that I am not on.", myParser.getLastLine()));
return;
}
if (iClient != null) { iChannelClient = iChannel.getUser(iClient); }
@@ -143,6 +154,8 @@ public class ProcessMessage extends IRCProcessor {
if (!isAction) {
if (isCTCP) {
callChannelCTCP(iChannel, iChannelClient, sCTCP, sMessage, token[0]);
+ } else if (hasModePrefix) {
+ callChannelModeMessage(modePrefix, iChannel, iChannelClient, sMessage, token[0]);
} else {
callChannelMessage(iChannel, iChannelClient, sMessage, token[0]);
}
@@ -152,6 +165,8 @@ public class ProcessMessage extends IRCProcessor {
} else if (sParam.equalsIgnoreCase("NOTICE")) {
if (isCTCP) {
callChannelCTCPReply(iChannel, iChannelClient, sCTCP, sMessage, token[0]);
+ } else if (hasModePrefix) {
+ callChannelModeNotice(modePrefix, iChannel, iChannelClient, sMessage, token[0]);
} else {
callChannelNotice(iChannel, iChannelClient, sMessage, token[0]);
}
@@ -269,6 +284,36 @@ public class ProcessMessage extends IRCProcessor {
}
/**
+ * Callback to all objects implementing the ChannelModeNotice Callback.
+ *
+ * @see com.dmdirc.parser.irc.callbacks.interfaces.IChannelModeNotice
+ * @param prefix Prefix that was used to send this notice.
+ * @param cChannel Channel where the notice was sent to
+ * @param cChannelClient ChannelClient who sent the notice (may be null if server)
+ * @param sMessage notice contents
+ * @param sHost Hostname of sender (or servername)
+ * @return true if a method was called, false otherwise
+ */
+ protected boolean callChannelModeNotice(final char prefix, final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
+ return getCallbackManager().getCallbackType("OnChannelModeNotice").call(prefix, cChannel, cChannelClient, sMessage, sHost);
+ }
+
+ /**
+ * Callback to all objects implementing the ChannelModeMessage Callback.
+ *
+ * @see com.dmdirc.parser.irc.callbacks.interfaces.IChannelModeMessage
+ * @param prefix Prefix that was used to send this notice.
+ * @param cChannel Channel where the notice was sent to
+ * @param cChannelClient ChannelClient who sent the notice (may be null if server)
+ * @param sMessage message contents
+ * @param sHost Hostname of sender (or servername)
+ * @return true if a method was called, false otherwise
+ */
+ protected boolean callChannelModeMessage(final char prefix, final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
+ return getCallbackManager().getCallbackType("OnChannelModeMessage").call(prefix, cChannel, cChannelClient, sMessage, sHost);
+ }
+
+ /**
* Callback to all objects implementing the PrivateAction Callback.
*
* @see com.dmdirc.parser.irc.callbacks.interfaces.IPrivateAction
Click to Expand/Collapse
diff src/com/dmdirc/parser/irc/callbacks/CallbackManager.java
@@ -42,6 +42,7 @@ public final class CallbackManager {
IChannelGotListModes.class, IChannelGotNames.class, IChannelJoin.class,
IChannelKick.class, IChannelMessage.class, IChannelModeChanged.class,
IChannelNickChanged.class, IChannelNonUserModeChanged.class,
+ IChannelModeMessage.class, IChannelModeNotice.class,
IChannelNotice.class, IChannelPart.class, IChannelQuit.class,
IChannelSelfJoin.class, IChannelSingleModeChanged.class,
IChannelTopic.class, IChannelUserModeChanged.class, IConnectError.class,
Click to Expand/Collapse
diff src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelModeMessage.java
new file mode 100644
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.dmdirc.parser.irc.callbacks.interfaces;
+
+import com.dmdirc.parser.irc.ChannelClientInfo;
+import com.dmdirc.parser.irc.ChannelInfo;
+import com.dmdirc.parser.irc.IRCParser;
+import com.dmdirc.parser.irc.callbacks.FakableArgument;
+import com.dmdirc.parser.irc.callbacks.FakableSource;
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
+
+/**
+ * Called when a person sends a Message to a channel with a mode prefix.
+ * (Examples @#Channel +#Channel)
+ * sHost is the hostname of the person sending the Message. (Can be a server or a person)<br>
+ * cChannelClient is null if user is a server, or not on the channel.
+ */
+@SpecificCallback
+public interface IChannelModeMessage extends ICallbackInterface {
+ /**
+ * Called when a person sends a Message to a channel.
+ * sHost is the hostname of the person sending the Message. (Can be a server or a person)<br>
+ * cChannelClient is null if user is a server, or not on the channel.
+ *
+ * @param tParser Reference to the parser object that made the callback.
+ * @param cChannel Channel where the Message was sent to
+ * @param cChannelClient ChannelClient who sent the Message (may be null if server)
+ * @param sMessage Message contents
+ * @param sHost Hostname of sender (or servername)
+ * @see com.dmdirc.parser.irc.ProcessMessage#callChannelModeMessage
+ */
+ void onChannelModeMessage(@FakableSource IRCParser tParser,
+ char prefix,
+ @FakableSource ChannelInfo cChannel,
+ @FakableArgument ChannelClientInfo cChannelClient,
+ String sMessage,
+ @FakableSource String sHost);
+}
Click to Expand/Collapse
diff src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelModeNotice.java
new file mode 100644
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.dmdirc.parser.irc.callbacks.interfaces;
+
+import com.dmdirc.parser.irc.ChannelClientInfo;
+import com.dmdirc.parser.irc.ChannelInfo;
+import com.dmdirc.parser.irc.IRCParser;
+import com.dmdirc.parser.irc.callbacks.FakableArgument;
+import com.dmdirc.parser.irc.callbacks.FakableSource;
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
+
+/**
+ * Called when a person sends a notice to a channel with a mode prefix.
+ * (Examples @#Channel +#Channel)
+ * sHost is the hostname of the person sending the notice. (Can be a server or a person)<br>
+ * cChannelClient is null if user is a server, or not on the channel.
+ */
+@SpecificCallback
+public interface IChannelModeNotice extends ICallbackInterface {
+ /**
+ * Called when a person sends a notice to a channel.
+ * sHost is the hostname of the person sending the notice. (Can be a server or a person)<br>
+ * cChannelClient is null if user is a server, or not on the channel.
+ *
+ * @param tParser Reference to the parser object that made the callback.
+ * @param cChannel Channel where the notice was sent to
+ * @param cChannelClient ChannelClient who sent the notice (may be null if server)
+ * @param sMessage notice contents
+ * @param sHost Hostname of sender (or servername)
+ * @see com.dmdirc.parser.irc.ProcessMessage#callChannelModeNotice
+ */
+ void onChannelModeNotice(@FakableSource IRCParser tParser,
+ char prefix,
+ @FakableSource ChannelInfo cChannel,
+ @FakableArgument ChannelClientInfo cChannelClient,
+ String sMessage,
+ @FakableSource String sHost);
+}
(0007297)
MD87 (administrator)
2009-07-21 19:21

This doesn't seem to be working.
(0007497)
Dataforce (administrator)
2009-08-09 01:51

I've tested and this works and correctly fires the ChannelModeNoticeListener
(0007502)
Dataforce (administrator)
2009-08-10 11:22

Reflection hacks by Chris assumed that the ChannelInfo would be the first parameter, so wasn't matching correctly against the specific. Reordering channel and prefix fixed it.
(0007512)
MD87 (administrator)
2009-08-10 14:24

This is fixed then?

Issue History

Date Modified Username Field Change
2008-09-17 21:41 MD87 New Issue
2008-09-17 21:41 MD87 Status new => assigned
2008-09-17 21:41 MD87 Assigned To => Dataforce
2008-10-02 00:08 MD87 Relationship added has duplicate 0001917
2009-05-06 22:05 MD87 Needs unit test => no
2009-05-06 22:05 MD87 Target Version 0.6.3 => 0.6.3m2
2009-06-02 00:33 MD87 Needs unit test no => yes
2009-07-03 20:56 Dataforce Relationship replaced blocks 0001917
2009-07-03 20:58 Dataforce Checkin
2009-07-03 20:58 Dataforce Note Added: 0007088
2009-07-03 20:58 Dataforce Status assigned => resolved
2009-07-03 20:58 Dataforce Resolution open => fixed
2009-07-21 19:21 MD87 Note Added: 0007297
2009-07-21 19:21 MD87 Status resolved => assigned
2009-07-21 19:21 MD87 Resolution fixed => reopened
2009-07-21 20:22 MD87 Priority normal => high
2009-08-09 01:51 Dataforce Note Added: 0007497
2009-08-10 11:22 Dataforce Note Added: 0007502
2009-08-10 14:24 MD87 Note Added: 0007512
2009-08-10 14:24 MD87 Status assigned => resolved
2009-08-10 14:24 MD87 Resolution reopened => fixed
2009-11-08 12:51 Greboid Status resolved => closed
2009-11-21 22:56 MD87 Category *Unsorted => IRC Parser