소스 검색

Adds callbacks for server notices issue 2993

Change-Id: Ic28eb35b5b606584ce76e08034b643c1e9f31d7c
Reviewed-on: http://gerrit.dmdirc.com/491
Tested-by: Gregory Holmes <greboid@dmdirc.com>
Automatic-Compile: DMDirc Local Commits <devs-public@dmdirc.com>
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
tags/0.6.3
Gregory Holmes 14 년 전
부모
커밋
9c2c63dc87

+ 1
- 0
src/com/dmdirc/parser/common/CallbackManager.java 파일 보기

@@ -67,6 +67,7 @@ public abstract class CallbackManager<T extends Parser> {
67 67
         UnknownMessageListener.class, UnknownNoticeListener.class,
68 68
         UserModeChangeListener.class, UserModeDiscoveryListener.class,
69 69
         WallDesyncListener.class, WallopListener.class, WalluserListener.class,
70
+        ServerNoticeListener.class, UnknownServerNoticeListener.class,
70 71
     };
71 72
     
72 73
     /** Hashtable used to store the different types of callback known. */

+ 44
- 0
src/com/dmdirc/parser/interfaces/callbacks/ServerNoticeListener.java 파일 보기

@@ -0,0 +1,44 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.parser.interfaces.callbacks;
24
+
25
+import com.dmdirc.parser.interfaces.Parser;
26
+import com.dmdirc.parser.interfaces.SpecificCallback;
27
+
28
+/**
29
+ * Called when a server sends a notice to you.
30
+ * sHost is the hostname of the server sending the notice.<br>
31
+ */
32
+@SpecificCallback
33
+public interface ServerNoticeListener extends CallbackInterface {
34
+	/**
35
+	 * Called when a server sends a notice to you.
36
+	 * sHost is the hostname of the server sending the notice.<br>
37
+	 * 
38
+	 * @param tParser Reference to the parser object that made the callback.
39
+	 * @param sMessage Notice contents
40
+	 * @param sHost Hostname of sender
41
+	 * @see com.dmdirc.parser.irc.ProcessMessage#callPrivateNotice
42
+	 */
43
+	void onServerNotice(Parser tParser, String sMessage, String sHost);
44
+}

+ 44
- 0
src/com/dmdirc/parser/interfaces/callbacks/UnknownServerNoticeListener.java 파일 보기

@@ -0,0 +1,44 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.parser.interfaces.callbacks;
24
+
25
+import com.dmdirc.parser.interfaces.Parser;
26
+
27
+/**
28
+ * Called when a server sends a notice not aimed specifically at you or a channel (ie $*).
29
+ * sHost is the hostname of the server sending the message.<br>
30
+ */
31
+public interface UnknownServerNoticeListener extends CallbackInterface {
32
+	/**
33
+	 * Called when a server sends a notice not aimed specifically at you or a channel (ie $*).
34
+	 * sHost is the hostname of the server sending the message.<br>
35
+	 * cClient is null if user is a server, or not on any common channel.
36
+	 * 
37
+	 * @param tParser Reference to the parser object that made the callback.
38
+	 * @param sMessage Notice contents
39
+	 * @param sTarget Actual target of notice
40
+	 * @param sHost Hostname of sender
41
+	 * @see com.dmdirc.parser.irc.ProcessMessage#callUnknownServerNotice
42
+	 */
43
+	void onUnknownServerNotice(Parser tParser, String sMessage, String sTarget, String sHost);
44
+}

+ 37
- 2
src/com/dmdirc/parser/irc/ProcessMessage.java 파일 보기

@@ -37,11 +37,13 @@ import com.dmdirc.parser.interfaces.callbacks.PrivateCtcpListener;
37 37
 import com.dmdirc.parser.interfaces.callbacks.PrivateCtcpReplyListener;
38 38
 import com.dmdirc.parser.interfaces.callbacks.PrivateMessageListener;
39 39
 import com.dmdirc.parser.interfaces.callbacks.PrivateNoticeListener;
40
+import com.dmdirc.parser.interfaces.callbacks.ServerNoticeListener;
40 41
 import com.dmdirc.parser.interfaces.callbacks.UnknownActionListener;
41 42
 import com.dmdirc.parser.interfaces.callbacks.UnknownCtcpListener;
42 43
 import com.dmdirc.parser.interfaces.callbacks.UnknownCtcpReplyListener;
43 44
 import com.dmdirc.parser.interfaces.callbacks.UnknownMessageListener;
44 45
 import com.dmdirc.parser.interfaces.callbacks.UnknownNoticeListener;
46
+import com.dmdirc.parser.interfaces.callbacks.UnknownServerNoticeListener;
45 47
 
46 48
 import java.util.regex.PatternSyntaxException;
47 49
 
@@ -207,7 +209,11 @@ public class ProcessMessage extends IRCProcessor {
207 209
                 if (isCTCP) {
208 210
                     callPrivateCTCPReply(sCTCP, sMessage, token[0]);
209 211
                 } else {
210
-                    callPrivateNotice(sMessage, token[0]);
212
+                    if (token[0].indexOf("@") == -1) {
213
+                        callServerNotice(sMessage, token[0]);
214
+                    } else {
215
+                        callPrivateNotice(sMessage, token[0]);
216
+                    }
211 217
                 }
212 218
             }
213 219
         } else {
@@ -226,7 +232,11 @@ public class ProcessMessage extends IRCProcessor {
226 232
                 if (isCTCP) {
227 233
                     callUnknownCTCPReply(sCTCP, sMessage, token[2], token[0]);
228 234
                 } else {
229
-                    callUnknownNotice(sMessage, token[2], token[0]);
235
+                    if (token[0].indexOf("@") == -1) {
236
+                        callUnknownServerNotice(sMessage, token[2], token[0]);
237
+                    } else {
238
+                        callUnknownNotice(sMessage, token[2], token[0]);
239
+                    }
230 240
                 }
231 241
             }
232 242
         }
@@ -395,6 +405,18 @@ public class ProcessMessage extends IRCProcessor {
395 405
     protected boolean callPrivateNotice(final String sMessage, final String sHost) {
396 406
         return getCallbackManager().getCallbackType(PrivateNoticeListener.class).call(sMessage, sHost);
397 407
     }
408
+
409
+    /**
410
+     * Callback to all objects implementing the ServerNotice Callback.
411
+     *
412
+     * @see com.dmdirc.parser.irc.callbacks.interfaces.ServerNotice
413
+     * @param sMessage Notice contents
414
+     * @param sHost Hostname of sender (or servername)
415
+     * @return true if a method was called, false otherwise
416
+     */
417
+    protected boolean callServerNotice(final String sMessage, final String sHost) {
418
+        return getCallbackManager().getCallbackType(ServerNoticeListener.class).call(sMessage, sHost);
419
+    }
398 420
     
399 421
     /**
400 422
      * Callback to all objects implementing the UnknownAction Callback.
@@ -463,6 +485,19 @@ public class ProcessMessage extends IRCProcessor {
463 485
         return getCallbackManager().getCallbackType(UnknownNoticeListener.class).call(sMessage, sTarget, sHost);
464 486
     }
465 487
 
488
+    /**
489
+     * Callback to all objects implementing the UnknownNotice Callback.
490
+     *
491
+     * @see com.dmdirc.parser.irc.callbacks.interfaces.IUnknownNotice
492
+     * @param sMessage Notice contents
493
+     * @param sTarget Actual target of notice
494
+     * @param sHost Hostname of sender (or servername)
495
+     * @return true if a method was called, false otherwise
496
+     */
497
+    protected boolean callUnknownServerNotice(final String sMessage, final String sTarget, final String sHost) {
498
+        return getCallbackManager().getCallbackType(UnknownServerNoticeListener.class).call(sMessage, sTarget, sHost);
499
+    }
500
+
466 501
     
467 502
     /**
468 503
      * What does this IRCProcessor handle.

Loading…
취소
저장