Browse Source

Add support for "TimestampedIRC" (See: http://shanemcc.co.uk/irc/#timestamping)

 - This is used for backbuffer support in DFBnc, we currently only care about timestamps in
   ProcessMessage, everything else will just use the current time in their callbacks as before.

Change-Id: I248bfd4d72800465ba4b06331261a8519690c3d5
Reviewed-on: http://gerrit.dmdirc.com/2172
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.7rc1
Shane Mc Cormack 12 years ago
parent
commit
3f23300f78

+ 31
- 5
src/com/dmdirc/parser/irc/IRCParser.java View File

@@ -54,6 +54,7 @@ import java.util.ArrayList;
54 54
 import java.util.Arrays;
55 55
 import java.util.Collection;
56 56
 import java.util.Collections;
57
+import java.util.Date;
57 58
 import java.util.Deque;
58 59
 import java.util.HashMap;
59 60
 import java.util.LinkedList;
@@ -207,6 +208,10 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
207 208
     private IRCClientInfo myself = new IRCClientInfo(this, "myself").setFake(true);
208 209
     /** Hashtable storing all information gathered from 005. */
209 210
     final Map<String, String> h005Info = new HashMap<String, String>();
211
+    /** Does this server support timestamped IRC? */
212
+    boolean timestampedIRC = false;
213
+    /** difference in ms between our time and the servers time. */
214
+    long tsdiff;
210 215
     /** Ignore List. */
211 216
     private IgnoreList myIgnoreList = new IgnoreList();
212 217
     /** Reference to the callback Manager. */
@@ -1043,6 +1048,7 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1043 1048
         if (tokens.length < 1) {
1044 1049
             tokens = new String[]{""};
1045 1050
         }
1051
+
1046 1052
         return tokens;
1047 1053
     }
1048 1054
 
@@ -1187,7 +1193,17 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1187 1193
     protected void processLine(final ReadLine line) {
1188 1194
         callDataIn(line.getLine());
1189 1195
 
1190
-        final String[] token = line.getTokens();
1196
+        String[] token = line.getTokens();
1197
+        Date lineTS = new Date();
1198
+        if (timestampedIRC && token[0].charAt(0) == '@') {
1199
+            try {
1200
+                final int tsEnd = token[0].indexOf('@', 1);
1201
+                final long ts = Long.parseLong(token[0].substring(1, tsEnd));
1202
+                token[0] = token[0].substring(tsEnd + 1);
1203
+                lineTS = new Date(ts - tsdiff);
1204
+            } catch (final NumberFormatException nfe) { /* Do nothing. */ }
1205
+        }
1206
+
1191 1207
         int nParam;
1192 1208
         setPingNeeded(false);
1193 1209
 
@@ -1211,13 +1227,22 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1211 1227
                     errorMessage.append(token[i]);
1212 1228
                 }
1213 1229
                 callServerError(errorMessage.toString());
1230
+            } else if (timestampedIRC && token[1].equalsIgnoreCase("TSIRC") && token.length > 3) {
1231
+                if (token[2].equals("1")) {
1232
+                    try {
1233
+                        final long ts = Long.parseLong(token[3]);
1234
+                        tsdiff = ts - System.currentTimeMillis();
1235
+                    } catch (final NumberFormatException nfe) { /* Do nothing. */ }
1236
+                } else {
1237
+                    timestampedIRC = false;
1238
+                }
1214 1239
             } else {
1215 1240
                 if (got001) {
1216 1241
                     // Freenode sends a random notice in a stupid place, others might do aswell
1217 1242
                     // These shouldn't cause post005 to be fired, so handle them here.
1218 1243
                     if (token[0].equalsIgnoreCase("NOTICE") || (token.length > 2 && token[2].equalsIgnoreCase("NOTICE"))) {
1219 1244
                         try {
1220
-                            myProcessingManager.process("Notice Auth", token);
1245
+                            myProcessingManager.process(lineTS, "Notice Auth", token);
1221 1246
                         } catch (ProcessorNotFoundException e) {
1222 1247
                             // ???
1223 1248
                         }
@@ -1243,7 +1268,7 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1243 1268
                     }
1244 1269
                     // After 001 we potentially care about everything!
1245 1270
                     try {
1246
-                        myProcessingManager.process(sParam, token);
1271
+                        myProcessingManager.process(lineTS, sParam, token);
1247 1272
                     } catch (ProcessorNotFoundException e) {
1248 1273
                         // ???
1249 1274
                     }
@@ -1267,7 +1292,7 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1267 1292
                             // Some networks send a CTCP during the auth process, handle it
1268 1293
                             if (token.length > 3 && !token[3].isEmpty() && token[3].charAt(0) == (char) 1 && token[3].charAt(token[3].length() - 1) == (char) 1) {
1269 1294
                                 try {
1270
-                                    myProcessingManager.process(sParam, token);
1295
+                                    myProcessingManager.process(lineTS, sParam, token);
1271 1296
                                 } catch (ProcessorNotFoundException e) {
1272 1297
                                 }
1273 1298
                                 break;
@@ -1280,7 +1305,7 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1280 1305
 
1281 1306
                             // Otherwise, send to Notice Auth
1282 1307
                             try {
1283
-                                myProcessingManager.process("Notice Auth", token);
1308
+                                myProcessingManager.process(lineTS, "Notice Auth", token);
1284 1309
                             } catch (ProcessorNotFoundException e) {
1285 1310
                             }
1286 1311
                             break;
@@ -1293,6 +1318,7 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1293 1318
             callErrorInfo(ei);
1294 1319
         }
1295 1320
     }
1321
+
1296 1322
     /** The IRCStringConverter for this parser */
1297 1323
     private IRCStringConverter stringConverter = null;
1298 1324
 

+ 7
- 4
src/com/dmdirc/parser/irc/Process004005.java View File

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.parser.irc;
24 24
 
25 25
 import com.dmdirc.parser.common.ParserError;
26
+import com.dmdirc.parser.common.QueuePriority;
26 27
 import com.dmdirc.parser.interfaces.callbacks.NetworkDetectedListener;
27 28
 
28 29
 import java.util.regex.Matcher;
@@ -112,10 +113,7 @@ public class Process004005 extends IRCProcessor {
112 113
                     try {
113 114
                         encoding = IRCEncoding.valueOf(value.toUpperCase().replace('-', '_'));
114 115
                     } catch (IllegalArgumentException ex) {
115
-                        parser.callErrorInfo(new ParserError(
116
-                                ParserError.ERROR_WARNING,
117
-                                "Unknown casemapping: '" + value + "' - assuming rfc1459",
118
-                                parser.getLastLine()));
116
+                        parser.callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Unknown casemapping: '" + value + "' - assuming rfc1459", parser.getLastLine()));
119 117
                     }
120 118
 
121 119
                     final boolean encodingChanged = parser.getStringConverter().getEncoding() != encoding;
@@ -151,6 +149,11 @@ public class Process004005 extends IRCProcessor {
151 149
                         parser.getProcessingManager().addProcessor(handles, parser.getProcessingManager().getProcessor("__LISTMODE__"));
152 150
                     } catch (ProcessorNotFoundException e) {
153 151
                     }
152
+                } else if ("TIMESTAMPEDIRC".equals(key)) {
153
+                    parser.timestampedIRC = true;
154
+                    // Let the server know we also understand timestamped irc.
155
+                    // See my other proposal: http://shanemcc.co.uk/irc/#timestamping
156
+                    parser.sendString("TIMESTAMPEDIRC ON", QueuePriority.HIGH);
154 157
                 }
155 158
             }
156 159
         }

+ 82
- 65
src/com/dmdirc/parser/irc/ProcessMessage.java View File

@@ -45,6 +45,7 @@ import com.dmdirc.parser.interfaces.callbacks.UnknownMessageListener;
45 45
 import com.dmdirc.parser.interfaces.callbacks.UnknownNoticeListener;
46 46
 import com.dmdirc.parser.interfaces.callbacks.UnknownServerNoticeListener;
47 47
 
48
+import java.util.Date;
48 49
 import java.util.regex.PatternSyntaxException;
49 50
 
50 51
 /**
@@ -55,7 +56,7 @@ import java.util.regex.PatternSyntaxException;
55 56
  * Actions are handled here aswell separately from CTCPs.<br>
56 57
  * Each type has 5 Calls, making 15 callbacks handled here.
57 58
  */
58
-public class ProcessMessage extends IRCProcessor {
59
+public class ProcessMessage extends TimestampedIRCProcessor {
59 60
 
60 61
     /**
61 62
      * Create a new instance of the IRCProcessor Object.
@@ -79,7 +80,7 @@ public class ProcessMessage extends IRCProcessor {
79 80
      * @param token IRCTokenised line to process
80 81
      */
81 82
     @Override
82
-    public void process(final String sParam, final String[] token) {
83
+    public void process(final Date date, final String sParam, final String[] token) {
83 84
         // Ignore people!
84 85
         String sMessage = "";
85 86
         if (token[0].charAt(0) == ':') {
@@ -108,7 +109,7 @@ public class ProcessMessage extends IRCProcessor {
108 109
         // Is this actually a notice auth?
109 110
         if (token[0].indexOf('!') == -1 && token[1].equalsIgnoreCase("NOTICE") && token[2].equalsIgnoreCase("AUTH")) {
110 111
             try {
111
-                parser.getProcessingManager().process("Notice Auth", token);
112
+                parser.getProcessingManager().process(date, "Notice Auth", token);
112 113
             } catch (ProcessorNotFoundException e) {
113 114
             }
114 115
             return;
@@ -133,9 +134,7 @@ public class ProcessMessage extends IRCProcessor {
133 134
             // Actions are special CTCPs
134 135
             // Bits is the message been split into 2 parts
135 136
             //         the first word and the rest
136
-            if (sParam.equalsIgnoreCase("PRIVMSG") && bits[0].equalsIgnoreCase(
137
-                    char1 + "ACTION") && Character.valueOf(sMessage.charAt(
138
-                    sMessage.length() - 1)).equals(char1)) {
137
+            if (sParam.equalsIgnoreCase("PRIVMSG") && bits[0].equalsIgnoreCase(char1 + "ACTION") && Character.valueOf(sMessage.charAt(sMessage.length() - 1)).equals(char1)) {
139 138
                 isAction = true;
140 139
                 if (bits.length > 1) {
141 140
                     sMessage = bits[1];
@@ -146,8 +145,7 @@ public class ProcessMessage extends IRCProcessor {
146 145
             }
147 146
             // If the message is not an action, check if it is another type of CTCP
148 147
             // CTCPs have Character(1) at the start/end of the line
149
-            if (!isAction && Character.valueOf(sMessage.charAt(0)).equals(char1)
150
-                    && Character.valueOf(sMessage.charAt(sMessage.length() - 1)).equals(char1)) {
148
+            if (!isAction && Character.valueOf(sMessage.charAt(0)).equals(char1) && Character.valueOf(sMessage.charAt(sMessage.length() - 1)).equals(char1)) {
151 149
                 isCTCP = true;
152 150
                 // Bits is the message been split into 2 parts, the first word and the rest
153 151
                 // Some CTCPs have messages and some do not
@@ -209,44 +207,44 @@ public class ProcessMessage extends IRCProcessor {
209 207
             }
210 208
             if (sParam.equalsIgnoreCase("PRIVMSG")) {
211 209
                 if (isAction) {
212
-                    callChannelAction(iChannel, iChannelClient, sMessage, token[0]);
210
+                    callChannelAction(date, iChannel, iChannelClient, sMessage, token[0]);
213 211
                 } else {
214 212
                     if (isCTCP) {
215
-                        callChannelCTCP(iChannel, iChannelClient, sCTCP, sMessage, token[0]);
213
+                        callChannelCTCP(date, iChannel, iChannelClient, sCTCP, sMessage, token[0]);
216 214
                     } else if (hasModePrefix) {
217
-                        callChannelModeMessage(modePrefix, iChannel, iChannelClient, sMessage, token[0]);
215
+                        callChannelModeMessage(date, modePrefix, iChannel, iChannelClient, sMessage, token[0]);
218 216
                     } else {
219
-                        callChannelMessage(iChannel, iChannelClient, sMessage, token[0]);
217
+                        callChannelMessage(date, iChannel, iChannelClient, sMessage, token[0]);
220 218
                     }
221 219
                 }
222 220
             } else if (sParam.equalsIgnoreCase("NOTICE")) {
223 221
                 if (isCTCP) {
224
-                    callChannelCTCPReply(iChannel, iChannelClient, sCTCP, sMessage, token[0]);
222
+                    callChannelCTCPReply(date, iChannel, iChannelClient, sCTCP, sMessage, token[0]);
225 223
                 } else if (hasModePrefix) {
226
-                    callChannelModeNotice(modePrefix, iChannel, iChannelClient, sMessage, token[0]);
224
+                    callChannelModeNotice(date, modePrefix, iChannel, iChannelClient, sMessage, token[0]);
227 225
                 } else {
228
-                    callChannelNotice(iChannel, iChannelClient, sMessage, token[0]);
226
+                    callChannelNotice(date, iChannel, iChannelClient, sMessage, token[0]);
229 227
                 }
230 228
             }
231 229
         } else if (parser.getStringConverter().equalsIgnoreCase(token[2], parser.getMyNickname())) {
232 230
             if (sParam.equalsIgnoreCase("PRIVMSG")) {
233 231
                 if (isAction) {
234
-                    callPrivateAction(sMessage, token[0]);
232
+                    callPrivateAction(date, sMessage, token[0]);
235 233
                 } else {
236 234
                     if (isCTCP) {
237
-                        callPrivateCTCP(sCTCP, sMessage, token[0]);
235
+                        callPrivateCTCP(date, sCTCP, sMessage, token[0]);
238 236
                     } else {
239
-                        callPrivateMessage(sMessage, token[0]);
237
+                        callPrivateMessage(date, sMessage, token[0]);
240 238
                     }
241 239
                 }
242 240
             } else if (sParam.equalsIgnoreCase("NOTICE")) {
243 241
                 if (isCTCP) {
244
-                    callPrivateCTCPReply(sCTCP, sMessage, token[0]);
242
+                    callPrivateCTCPReply(date, sCTCP, sMessage, token[0]);
245 243
                 } else {
246 244
                     if (token[0].indexOf('@') == -1) {
247
-                        callServerNotice(sMessage, token[0]);
245
+                        callServerNotice(date, sMessage, token[0]);
248 246
                     } else {
249
-                        callPrivateNotice(sMessage, token[0]);
247
+                        callPrivateNotice(date, sMessage, token[0]);
250 248
                     }
251 249
                 }
252 250
             }
@@ -254,22 +252,22 @@ public class ProcessMessage extends IRCProcessor {
254 252
             callDebugInfo(IRCParser.DEBUG_INFO, "Message for Other (" + token[2] + ")");
255 253
             if (sParam.equalsIgnoreCase("PRIVMSG")) {
256 254
                 if (isAction) {
257
-                    callUnknownAction(sMessage, token[2], token[0]);
255
+                    callUnknownAction(date, sMessage, token[2], token[0]);
258 256
                 } else {
259 257
                     if (isCTCP) {
260
-                        callUnknownCTCP(sCTCP, sMessage, token[2], token[0]);
258
+                        callUnknownCTCP(date, sCTCP, sMessage, token[2], token[0]);
261 259
                     } else {
262
-                        callUnknownMessage(sMessage, token[2], token[0]);
260
+                        callUnknownMessage(date, sMessage, token[2], token[0]);
263 261
                     }
264 262
                 }
265 263
             } else if (sParam.equalsIgnoreCase("NOTICE")) {
266 264
                 if (isCTCP) {
267
-                    callUnknownCTCPReply(sCTCP, sMessage, token[2], token[0]);
265
+                    callUnknownCTCPReply(date, sCTCP, sMessage, token[2], token[0]);
268 266
                 } else {
269 267
                     if (token[0].indexOf('@') == -1) {
270
-                        callUnknownServerNotice(sMessage, token[2], token[0]);
268
+                        callUnknownServerNotice(date, sMessage, token[2], token[0]);
271 269
                     } else {
272
-                        callUnknownNotice(sMessage, token[2], token[0]);
270
+                        callUnknownNotice(date, sMessage, token[2], token[0]);
273 271
                     }
274 272
                 }
275 273
             }
@@ -280,20 +278,22 @@ public class ProcessMessage extends IRCProcessor {
280 278
      * Callback to all objects implementing the ChannelAction Callback.
281 279
      *
282 280
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IChannelAction
281
+     * @param date The date of this line
283 282
      * @param cChannel Channel where the action was sent to
284 283
      * @param cChannelClient ChannelClient who sent the action (may be null if server)
285 284
      * @param sMessage action contents
286 285
      * @param sHost Hostname of sender (or servername)
287 286
      * @return true if a method was called, false otherwise
288 287
      */
289
-    protected boolean callChannelAction(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
290
-        return getCallbackManager().getCallbackType(ChannelActionListener.class).call(cChannel, cChannelClient, sMessage, sHost);
288
+    protected boolean callChannelAction(final Date date, final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
289
+        return getCallbackManager().getCallbackType(ChannelActionListener.class).call(date, cChannel, cChannelClient, sMessage, sHost);
291 290
     }
292 291
 
293 292
     /**
294 293
      * Callback to all objects implementing the ChannelCTCP Callback.
295 294
      *
296 295
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IChannelCTCP
296
+     * @param date The date of this line
297 297
      * @param cChannel Channel where CTCP was sent
298 298
      * @param cChannelClient ChannelClient who sent the message (may be null if server)
299 299
      * @param sType Type of CTCP (VERSION, TIME etc)
@@ -301,14 +301,15 @@ public class ProcessMessage extends IRCProcessor {
301 301
      * @param sHost Hostname of sender (or servername)
302 302
      * @return true if a method was called, false otherwise
303 303
      */
304
-    protected boolean callChannelCTCP(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sType, final String sMessage, final String sHost) {
305
-        return getCallbackManager().getCallbackType(ChannelCtcpListener.class).call(cChannel, cChannelClient, sType, sMessage, sHost);
304
+    protected boolean callChannelCTCP(final Date date, final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sType, final String sMessage, final String sHost) {
305
+        return getCallbackManager().getCallbackType(ChannelCtcpListener.class).call(date, cChannel, cChannelClient, sType, sMessage, sHost);
306 306
     }
307 307
 
308 308
     /**
309 309
      * Callback to all objects implementing the ChannelCTCPReply Callback.
310 310
      *
311 311
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IChannelCTCPReply
312
+     * @param date The date of this line
312 313
      * @param cChannel Channel where CTCPReply was sent
313 314
      * @param cChannelClient ChannelClient who sent the message (may be null if server)
314 315
      * @param sType Type of CTCPRReply (VERSION, TIME etc)
@@ -316,42 +317,45 @@ public class ProcessMessage extends IRCProcessor {
316 317
      * @param sHost Hostname of sender (or servername)
317 318
      * @return true if a method was called, false otherwise
318 319
      */
319
-    protected boolean callChannelCTCPReply(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sType, final String sMessage, final String sHost) {
320
-        return getCallbackManager().getCallbackType(ChannelCtcpReplyListener.class).call(cChannel, cChannelClient, sType, sMessage, sHost);
320
+    protected boolean callChannelCTCPReply(final Date date, final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sType, final String sMessage, final String sHost) {
321
+        return getCallbackManager().getCallbackType(ChannelCtcpReplyListener.class).call(date, cChannel, cChannelClient, sType, sMessage, sHost);
321 322
     }
322 323
 
323 324
     /**
324 325
      * Callback to all objects implementing the ChannelMessage Callback.
325 326
      *
326 327
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IChannelMessage
328
+     * @param date The date of this line
327 329
      * @param cChannel Channel where the message was sent to
328 330
      * @param cChannelClient ChannelClient who sent the message (may be null if server)
329 331
      * @param sMessage Message contents
330 332
      * @param sHost Hostname of sender (or servername)
331 333
      * @return true if a method was called, false otherwise
332 334
      */
333
-    protected boolean callChannelMessage(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
334
-        return getCallbackManager().getCallbackType(ChannelMessageListener.class).call(cChannel, cChannelClient, sMessage, sHost);
335
+    protected boolean callChannelMessage(final Date date, final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
336
+        return getCallbackManager().getCallbackType(ChannelMessageListener.class).call(date, cChannel, cChannelClient, sMessage, sHost);
335 337
     }
336 338
 
337 339
     /**
338 340
      * Callback to all objects implementing the ChannelNotice Callback.
339 341
      *
340 342
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IChannelNotice
343
+     * @param date The date of this line
341 344
      * @param cChannel Channel where the notice was sent to
342 345
      * @param cChannelClient ChannelClient who sent the notice (may be null if server)
343 346
      * @param sMessage notice contents
344 347
      * @param sHost Hostname of sender (or servername)
345 348
      * @return true if a method was called, false otherwise
346 349
      */
347
-    protected boolean callChannelNotice(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
348
-        return getCallbackManager().getCallbackType(ChannelNoticeListener.class).call(cChannel, cChannelClient, sMessage, sHost);
350
+    protected boolean callChannelNotice(final Date date, final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
351
+        return getCallbackManager().getCallbackType(ChannelNoticeListener.class).call(date, cChannel, cChannelClient, sMessage, sHost);
349 352
     }
350 353
 
351 354
     /**
352 355
      * Callback to all objects implementing the ChannelModeNotice Callback.
353 356
      *
354 357
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IChannelModeNotice
358
+     * @param date The date of this line
355 359
      * @param prefix Prefix that was used to send this notice.
356 360
      * @param cChannel Channel where the notice was sent to
357 361
      * @param cChannelClient ChannelClient who sent the notice (may be null if server)
@@ -359,14 +363,15 @@ public class ProcessMessage extends IRCProcessor {
359 363
      * @param sHost Hostname of sender (or servername)
360 364
      * @return true if a method was called, false otherwise
361 365
      */
362
-    protected boolean callChannelModeNotice(final char prefix, final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
363
-        return getCallbackManager().getCallbackType(ChannelModeNoticeListener.class).call(cChannel, prefix, cChannelClient, sMessage, sHost);
366
+    protected boolean callChannelModeNotice(final Date date, final char prefix, final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
367
+        return getCallbackManager().getCallbackType(ChannelModeNoticeListener.class).call(date, cChannel, prefix, cChannelClient, sMessage, sHost);
364 368
     }
365 369
 
366 370
     /**
367 371
      * Callback to all objects implementing the ChannelModeMessage Callback.
368 372
      *
369 373
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IChannelModeMessage
374
+     * @param date The date of this line
370 375
      * @param prefix Prefix that was used to send this notice.
371 376
      * @param cChannel Channel where the notice was sent to
372 377
      * @param cChannelClient ChannelClient who sent the notice (may be null if server)
@@ -374,162 +379,174 @@ public class ProcessMessage extends IRCProcessor {
374 379
      * @param sHost Hostname of sender (or servername)
375 380
      * @return true if a method was called, false otherwise
376 381
      */
377
-    protected boolean callChannelModeMessage(final char prefix, final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
378
-        return getCallbackManager().getCallbackType(ChannelModeMessageListener.class).call(cChannel, prefix, cChannelClient, sMessage, sHost);
382
+    protected boolean callChannelModeMessage(final Date date, final char prefix, final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
383
+        return getCallbackManager().getCallbackType(ChannelModeMessageListener.class).call(date, cChannel, prefix, cChannelClient, sMessage, sHost);
379 384
     }
380 385
 
381 386
     /**
382 387
      * Callback to all objects implementing the PrivateAction Callback.
383 388
      *
384 389
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IPrivateAction
390
+     * @param date The date of this line
385 391
      * @param sMessage action contents
386 392
      * @param sHost Hostname of sender (or servername)
387 393
      * @return true if a method was called, false otherwise
388 394
      */
389
-    protected boolean callPrivateAction(final String sMessage, final String sHost) {
390
-        return getCallbackManager().getCallbackType(PrivateActionListener.class).call(sMessage, sHost);
395
+    protected boolean callPrivateAction(final Date date, final String sMessage, final String sHost) {
396
+        return getCallbackManager().getCallbackType(PrivateActionListener.class).call(date, sMessage, sHost);
391 397
     }
392 398
 
393 399
     /**
394 400
      * Callback to all objects implementing the PrivateCTCP Callback.
395 401
      *
396 402
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IPrivateCTCP
403
+     * @param date The date of this line
397 404
      * @param sType Type of CTCP (VERSION, TIME etc)
398 405
      * @param sMessage Additional contents
399 406
      * @param sHost Hostname of sender (or servername)
400 407
      * @return true if a method was called, false otherwise
401 408
      */
402
-    protected boolean callPrivateCTCP(final String sType, final String sMessage, final String sHost) {
403
-        return getCallbackManager().getCallbackType(PrivateCtcpListener.class).call(sType, sMessage, sHost);
409
+    protected boolean callPrivateCTCP(final Date date, final String sType, final String sMessage, final String sHost) {
410
+        return getCallbackManager().getCallbackType(PrivateCtcpListener.class).call(date, sType, sMessage, sHost);
404 411
     }
405 412
 
406 413
     /**
407 414
      * Callback to all objects implementing the PrivateCTCPReply Callback.
408 415
      *
409 416
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IPrivateCTCPReply
417
+     * @param date The date of this line
410 418
      * @param sType Type of CTCPRReply (VERSION, TIME etc)
411 419
      * @param sMessage Reply Contents
412 420
      * @param sHost Hostname of sender (or servername)
413 421
      * @return true if a method was called, false otherwise
414 422
      */
415
-    protected boolean callPrivateCTCPReply(final String sType, final String sMessage, final String sHost) {
416
-        return getCallbackManager().getCallbackType(PrivateCtcpReplyListener.class).call(sType, sMessage, sHost);
423
+    protected boolean callPrivateCTCPReply(final Date date, final String sType, final String sMessage, final String sHost) {
424
+        return getCallbackManager().getCallbackType(PrivateCtcpReplyListener.class).call(date, sType, sMessage, sHost);
417 425
     }
418 426
 
419 427
     /**
420 428
      * Callback to all objects implementing the PrivateMessage Callback.
421 429
      *
422 430
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IPrivateMessage
431
+     * @param date The date of this line
423 432
      * @param sMessage Message contents
424 433
      * @param sHost Hostname of sender (or servername)
425 434
      * @return true if a method was called, false otherwise
426 435
      */
427
-    protected boolean callPrivateMessage(final String sMessage, final String sHost) {
428
-        return getCallbackManager().getCallbackType(PrivateMessageListener.class).call(sMessage, sHost);
436
+    protected boolean callPrivateMessage(final Date date, final String sMessage, final String sHost) {
437
+        return getCallbackManager().getCallbackType(PrivateMessageListener.class).call(date, sMessage, sHost);
429 438
     }
430 439
 
431 440
     /**
432 441
      * Callback to all objects implementing the PrivateNotice Callback.
433 442
      *
434 443
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IPrivateNotice
444
+     * @param date The date of this line
435 445
      * @param sMessage Notice contents
436 446
      * @param sHost Hostname of sender (or servername)
437 447
      * @return true if a method was called, false otherwise
438 448
      */
439
-    protected boolean callPrivateNotice(final String sMessage, final String sHost) {
440
-        return getCallbackManager().getCallbackType(PrivateNoticeListener.class).call(sMessage, sHost);
449
+    protected boolean callPrivateNotice(final Date date, final String sMessage, final String sHost) {
450
+        return getCallbackManager().getCallbackType(PrivateNoticeListener.class).call(date, sMessage, sHost);
441 451
     }
442 452
 
443 453
     /**
444 454
      * Callback to all objects implementing the ServerNotice Callback.
445 455
      *
446 456
      * @see com.dmdirc.parser.irc.callbacks.interfaces.ServerNotice
457
+     * @param date The date of this line
447 458
      * @param sMessage Notice contents
448 459
      * @param sHost Hostname of sender (or servername)
449 460
      * @return true if a method was called, false otherwise
450 461
      */
451
-    protected boolean callServerNotice(final String sMessage, final String sHost) {
452
-        return getCallbackManager().getCallbackType(ServerNoticeListener.class).call(sMessage, sHost);
462
+    protected boolean callServerNotice(final Date date, final String sMessage, final String sHost) {
463
+        return getCallbackManager().getCallbackType(ServerNoticeListener.class).call(date, sMessage, sHost);
453 464
     }
454 465
 
455 466
     /**
456 467
      * Callback to all objects implementing the UnknownAction Callback.
457 468
      *
458 469
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IUnknownAction
470
+     * @param date The date of this line
459 471
      * @param sMessage Action contents
460 472
      * @param sTarget Actual target of action
461 473
      * @param sHost Hostname of sender (or servername)
462 474
      * @return true if a method was called, false otherwise
463 475
      */
464
-    protected boolean callUnknownAction(final String sMessage, final String sTarget, final String sHost) {
465
-        return getCallbackManager().getCallbackType(UnknownActionListener.class).call(sMessage, sTarget, sHost);
476
+    protected boolean callUnknownAction(final Date date, final String sMessage, final String sTarget, final String sHost) {
477
+        return getCallbackManager().getCallbackType(UnknownActionListener.class).call(date, sMessage, sTarget, sHost);
466 478
     }
467 479
 
468 480
     /**
469 481
      * Callback to all objects implementing the UnknownCTCP Callback.
470 482
      *
471 483
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IUnknownCTCP
484
+     * @param date The date of this line
472 485
      * @param sType Type of CTCP (VERSION, TIME etc)
473 486
      * @param sMessage Additional contents
474 487
      * @param sTarget Actual Target of CTCP
475 488
      * @param sHost Hostname of sender (or servername)
476 489
      * @return true if a method was called, false otherwise
477 490
      */
478
-    protected boolean callUnknownCTCP(final String sType, final String sMessage, final String sTarget, final String sHost) {
479
-        return getCallbackManager().getCallbackType(UnknownCtcpListener.class).call(sType, sMessage, sTarget, sHost);
491
+    protected boolean callUnknownCTCP(final Date date, final String sType, final String sMessage, final String sTarget, final String sHost) {
492
+        return getCallbackManager().getCallbackType(UnknownCtcpListener.class).call(date, sType, sMessage, sTarget, sHost);
480 493
     }
481 494
 
482 495
     /**
483 496
      * Callback to all objects implementing the UnknownCTCPReply Callback.
484 497
      *
485 498
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IUnknownCTCPReply
499
+     * @param date The date of this line
486 500
      * @param sType Type of CTCPRReply (VERSION, TIME etc)
487 501
      * @param sMessage Reply Contents
488 502
      * @param sTarget Actual Target of CTCPReply
489 503
      * @param sHost Hostname of sender (or servername)
490 504
      * @return true if a method was called, false otherwise
491 505
      */
492
-    protected boolean callUnknownCTCPReply(final String sType, final String sMessage, final String sTarget, final String sHost) {
493
-        return getCallbackManager().getCallbackType(UnknownCtcpReplyListener.class).call(sType, sMessage, sTarget, sHost);
506
+    protected boolean callUnknownCTCPReply(final Date date, final String sType, final String sMessage, final String sTarget, final String sHost) {
507
+        return getCallbackManager().getCallbackType(UnknownCtcpReplyListener.class).call(date, sType, sMessage, sTarget, sHost);
494 508
     }
495 509
 
496 510
     /**
497 511
      * Callback to all objects implementing the UnknownMessage Callback.
498 512
      *
499 513
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IUnknownMessage
514
+     * @param date The date of this line
500 515
      * @param sMessage Message contents
501 516
      * @param sTarget Actual target of message
502 517
      * @param sHost Hostname of sender (or servername)
503 518
      * @return true if a method was called, false otherwise
504 519
      */
505
-    protected boolean callUnknownMessage(final String sMessage, final String sTarget, final String sHost) {
506
-        return getCallbackManager().getCallbackType(UnknownMessageListener.class).call(sMessage, sTarget, sHost);
520
+    protected boolean callUnknownMessage(final Date date, final String sMessage, final String sTarget, final String sHost) {
521
+        return getCallbackManager().getCallbackType(UnknownMessageListener.class).call(date, sMessage, sTarget, sHost);
507 522
     }
508 523
 
509 524
     /**
510 525
      * Callback to all objects implementing the UnknownNotice Callback.
511 526
      *
512 527
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IUnknownNotice
528
+     * @param date The date of this line
513 529
      * @param sMessage Notice contents
514 530
      * @param sTarget Actual target of notice
515 531
      * @param sHost Hostname of sender (or servername)
516 532
      * @return true if a method was called, false otherwise
517 533
      */
518
-    protected boolean callUnknownNotice(final String sMessage, final String sTarget, final String sHost) {
519
-        return getCallbackManager().getCallbackType(UnknownNoticeListener.class).call(sMessage, sTarget, sHost);
534
+    protected boolean callUnknownNotice(final Date date, final String sMessage, final String sTarget, final String sHost) {
535
+        return getCallbackManager().getCallbackType(UnknownNoticeListener.class).call(date, sMessage, sTarget, sHost);
520 536
     }
521 537
 
522 538
     /**
523 539
      * Callback to all objects implementing the UnknownNotice Callback.
524 540
      *
525 541
      * @see com.dmdirc.parser.irc.callbacks.interfaces.IUnknownNotice
542
+     * @param date The date of this line
526 543
      * @param sMessage Notice contents
527 544
      * @param sTarget Actual target of notice
528 545
      * @param sHost Hostname of sender (or servername)
529 546
      * @return true if a method was called, false otherwise
530 547
      */
531
-    protected boolean callUnknownServerNotice(final String sMessage, final String sTarget, final String sHost) {
532
-        return getCallbackManager().getCallbackType(UnknownServerNoticeListener.class).call(sMessage, sTarget, sHost);
548
+    protected boolean callUnknownServerNotice(final Date date, final String sMessage, final String sTarget, final String sHost) {
549
+        return getCallbackManager().getCallbackType(UnknownServerNoticeListener.class).call(date, sMessage, sTarget, sHost);
533 550
     }
534 551
 
535 552
     /**

+ 18
- 1
src/com/dmdirc/parser/irc/ProcessingManager.java View File

@@ -25,6 +25,7 @@ package com.dmdirc.parser.irc;
25 25
 import com.dmdirc.parser.common.ParserError;
26 26
 import com.dmdirc.parser.interfaces.callbacks.NumericListener;
27 27
 
28
+import java.util.Date;
28 29
 import java.util.HashMap;
29 30
 import java.util.Map;
30 31
 
@@ -187,10 +188,26 @@ public class ProcessingManager {
187 188
      * @throws ProcessorNotFoundException exception if no processors exists to handle the line
188 189
      */
189 190
     public void process(final String sParam, final String[] token) throws ProcessorNotFoundException {
191
+        process(new Date(), sParam, token);
192
+    }
193
+
194
+    /**
195
+     * Process a Line.
196
+     *
197
+     * @param date Date of line.
198
+     * @param sParam Type of line to process ("005", "PRIVMSG" etc)
199
+     * @param token IRCTokenised line to process
200
+     * @throws ProcessorNotFoundException exception if no processors exists to handle the line
201
+     */
202
+    public void process(final Date date, final String sParam, final String[] token) throws ProcessorNotFoundException {
190 203
         IRCProcessor messageProcessor = null;
191 204
         try {
192 205
             messageProcessor = getProcessor(sParam);
193
-            messageProcessor.process(sParam, token);
206
+            if (messageProcessor instanceof TimestampedIRCProcessor) {
207
+                ((TimestampedIRCProcessor)messageProcessor).process(date, sParam, token);
208
+            } else {
209
+                messageProcessor.process(sParam, token);
210
+            }
194 211
         } catch (ProcessorNotFoundException p) {
195 212
             throw p;
196 213
         } catch (Exception e) {

+ 59
- 0
src/com/dmdirc/parser/irc/TimestampedIRCProcessor.java View File

@@ -0,0 +1,59 @@
1
+/*
2
+ * Copyright (c) 2006-2011 DMDirc Developers
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.irc;
24
+
25
+import java.util.Date;
26
+
27
+/**
28
+ * TimestampedIRCProcessor.
29
+ *
30
+ * Superclass for all IRCProcessor types that accept timestamps for process.
31
+ */
32
+public abstract class TimestampedIRCProcessor extends IRCProcessor {
33
+    /**
34
+     * Create a new instance of the IRCTimestampedProcessor Object.
35
+     *
36
+     * @param parser IRCParser That owns this IRCProcessor
37
+     * @param manager ProcessingManager that is in charge of this IRCProcessor
38
+     */
39
+    protected TimestampedIRCProcessor(final IRCParser parser, final ProcessingManager manager) {
40
+        super(parser, manager);
41
+    }
42
+
43
+    /** {@inheritDoc} */
44
+    @Override
45
+    public final void process(final String sParam, final String[] token) {
46
+        process(new Date(), sParam, token);
47
+    }
48
+
49
+    /**
50
+     * Process a Line.
51
+     *
52
+     * @param date Date of this line
53
+     * @param sParam Type of line to process ("005", "PRIVMSG" etc)
54
+     * @param token IRCTokenised line to process
55
+     */
56
+    public abstract void process(final Date date, final String sParam, final String[] token);
57
+
58
+
59
+}

Loading…
Cancel
Save