|
@@ -0,0 +1,97 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (c) 2006-2012 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
|
+ * Process CAP extension.
|
|
29
|
+ * There are currently no callbacks related to this, as it is just to tell
|
|
30
|
+ * the server what we support.
|
|
31
|
+ *
|
|
32
|
+ * For all the capabilities we support, we are always able to handle lines#
|
|
33
|
+ * either with or without the capability enabled, so we don't actually need to
|
|
34
|
+ * keep much/any state here, which makes this easy.
|
|
35
|
+ *
|
|
36
|
+ * See: http://www.leeh.co.uk/draft-mitchell-irc-capabilities-02.html
|
|
37
|
+ */
|
|
38
|
+public class ProcessCap extends TimestampedIRCProcessor {
|
|
39
|
+ /** Have we handled the pre-connect cap request? */
|
|
40
|
+ private boolean hasCapped = false;
|
|
41
|
+
|
|
42
|
+ /**
|
|
43
|
+ * Create a new instance of the IRCProcessor Object.
|
|
44
|
+ *
|
|
45
|
+ * @param parser IRCParser That owns this IRCProcessor
|
|
46
|
+ * @param manager ProcessingManager that is in charge of this IRCProcessor
|
|
47
|
+ */
|
|
48
|
+ protected ProcessCap(final IRCParser parser, final ProcessingManager manager) {
|
|
49
|
+ super(parser, manager);
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ /**
|
|
53
|
+ * Process CAP responses.
|
|
54
|
+ *
|
|
55
|
+ * @param sParam Type of line to process ("CAP")
|
|
56
|
+ * @param token IRCTokenised line to process
|
|
57
|
+ */
|
|
58
|
+ @Override
|
|
59
|
+ public void process(final Date date, final String sParam, final String[] token) {
|
|
60
|
+ // We will only automatically handle the first ever pre-001 CAP LS
|
|
61
|
+ // response.
|
|
62
|
+ // After that, the user may be sending stuff themselves so we do
|
|
63
|
+ // nothing.
|
|
64
|
+ if (!hasCapped && !parser.got001 && token.length > 4 && token[3].equalsIgnoreCase("LS")) {
|
|
65
|
+ final String[] caps = token[token.length - 1].split(" ");
|
|
66
|
+ for (final String cap : caps) {
|
|
67
|
+ if (cap.equalsIgnoreCase("multi-prefix") || cap.equalsIgnoreCase("tsirc") || cap.equalsIgnoreCase("userhost-in-names")) {
|
|
68
|
+ // Send cap requests as individual lines, as some servers
|
|
69
|
+ // only appear to accept them one at a time.
|
|
70
|
+ parser.sendRawMessage("CAP REQ :" + cap);
|
|
71
|
+ }
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ // If this is the last of the LS responses, set hasCapped to true
|
|
75
|
+ // so that we don't try this again, and send "CAP END"
|
|
76
|
+ // We will accept any of the following to be the end of the list:
|
|
77
|
+ // :DFBnc.Server CAP Dataforce LS :some caps
|
|
78
|
+ // :DFBnc.Server CAP Dataforce LS
|
|
79
|
+ // but not:
|
|
80
|
+ // :DFBnc.Server CAP Dataforce LS *
|
|
81
|
+ if (token.length == 4 || (token.length == 5 && !token[4].equals("*"))) {
|
|
82
|
+ hasCapped = true;
|
|
83
|
+ parser.sendRawMessage("CAP END");
|
|
84
|
+ }
|
|
85
|
+ }
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ /**
|
|
89
|
+ * What does this IRCProcessor handle.
|
|
90
|
+ *
|
|
91
|
+ * @return String[] with the names of the tokens we handle.
|
|
92
|
+ */
|
|
93
|
+ @Override
|
|
94
|
+ public String[] handles() {
|
|
95
|
+ return new String[]{"CAP"};
|
|
96
|
+ }
|
|
97
|
+}
|