|
@@ -22,14 +22,17 @@
|
22
|
22
|
|
23
|
23
|
package com.md87.charliebravo;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.parser.irc.ChannelClientInfo;
|
26
|
|
-import com.dmdirc.parser.irc.ChannelInfo;
|
27
|
|
-import com.dmdirc.parser.irc.ClientInfo;
|
|
25
|
+
|
|
26
|
+import com.dmdirc.parser.interfaces.ChannelClientInfo;
|
|
27
|
+import com.dmdirc.parser.interfaces.ChannelInfo;
|
|
28
|
+import com.dmdirc.parser.interfaces.ClientInfo;
|
|
29
|
+import com.dmdirc.parser.interfaces.Parser;
|
|
30
|
+import com.dmdirc.parser.interfaces.callbacks.ChannelKickListener;
|
|
31
|
+import com.dmdirc.parser.interfaces.callbacks.ChannelMessageListener;
|
|
32
|
+import com.dmdirc.parser.interfaces.callbacks.PrivateCtcpListener;
|
|
33
|
+import com.dmdirc.parser.interfaces.callbacks.PrivateMessageListener;
|
28
|
34
|
import com.dmdirc.parser.irc.IRCParser;
|
29
|
|
-import com.dmdirc.parser.irc.callbacks.interfaces.IChannelKick;
|
30
|
|
-import com.dmdirc.parser.irc.callbacks.interfaces.IChannelMessage;
|
31
|
|
-import com.dmdirc.parser.irc.callbacks.interfaces.IPrivateCTCP;
|
32
|
|
-import com.dmdirc.parser.irc.callbacks.interfaces.IPrivateMessage;
|
|
35
|
+
|
33
|
36
|
import com.dmdirc.util.RollingList;
|
34
|
37
|
import com.md87.charliebravo.commands.AuthenticateCommand;
|
35
|
38
|
import com.md87.charliebravo.commands.CalcCommand;
|
|
@@ -51,6 +54,7 @@ import com.md87.charliebravo.commands.TranslateCommand;
|
51
|
54
|
import com.md87.charliebravo.commands.WhoisCommand;
|
52
|
55
|
import com.md87.util.crypto.ArcFourEncrypter;
|
53
|
56
|
import java.util.ArrayList;
|
|
57
|
+import java.util.Date;
|
54
|
58
|
import java.util.HashMap;
|
55
|
59
|
import java.util.List;
|
56
|
60
|
import java.util.Map;
|
|
@@ -62,7 +66,7 @@ import net.miginfocom.Base64;
|
62
|
66
|
*
|
63
|
67
|
* @author chris
|
64
|
68
|
*/
|
65
|
|
-public class InputHandler implements IChannelMessage, IPrivateMessage, IPrivateCTCP, IChannelKick {
|
|
69
|
+public class InputHandler implements ChannelMessageListener, PrivateMessageListener, PrivateCtcpListener, ChannelKickListener {
|
66
|
70
|
|
67
|
71
|
protected IRCParser parser;
|
68
|
72
|
|
|
@@ -118,24 +122,25 @@ public class InputHandler implements IChannelMessage, IPrivateMessage, IPrivateC
|
118
|
122
|
public void setParser(final IRCParser parser) {
|
119
|
123
|
this.parser = parser;
|
120
|
124
|
|
121
|
|
- parser.getCallbackManager().addCallback("OnChannelMessage", this);
|
122
|
|
- parser.getCallbackManager().addCallback("OnPrivateMessage", this);
|
123
|
|
- parser.getCallbackManager().addCallback("OnPrivateCTCP", this);
|
124
|
|
- parser.getCallbackManager().addCallback("OnChannelKick", this);
|
|
125
|
+ parser.getCallbackManager().addCallback(ChannelMessageListener.class, this);
|
|
126
|
+ parser.getCallbackManager().addCallback(PrivateMessageListener.class, this);
|
|
127
|
+ parser.getCallbackManager().addCallback(PrivateCtcpListener.class, this);
|
|
128
|
+ parser.getCallbackManager().addCallback(ChannelKickListener.class, this);
|
125
|
129
|
}
|
126
|
130
|
|
127
|
|
- public void onChannelMessage(final IRCParser tParser, final ChannelInfo cChannel,
|
|
131
|
+ @Override
|
|
132
|
+ public void onChannelMessage(final Parser tParser, final Date date, final ChannelInfo cChannel,
|
128
|
133
|
final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
|
129
|
134
|
for (String nick : getNicknames()) {
|
130
|
135
|
if (sMessage.matches("^(?i)" + Matcher.quoteReplacement(nick) + "[,:!] .*")) {
|
131
|
|
- handleInput(ClientInfo.parseHost(sHost), cChannel.getName(),
|
|
136
|
+ handleInput(tParser.parseHostmask(sHost)[0], cChannel.getName(),
|
132
|
137
|
sMessage.substring(nick.length() + 2));
|
133
|
138
|
break;
|
134
|
139
|
} else if (sMessage.matches("^(?i)" + Matcher.quoteReplacement(nick) + "\\?")
|
135
|
140
|
&& snippets.containsKey(cChannel.getName())) {
|
136
|
141
|
final RollingList<String> snips = snippets.get(cChannel.getName());
|
137
|
142
|
final String snippet = snips.get(snips.getList().size() - 1);
|
138
|
|
- handleInput(ClientInfo.parseHost(sHost), cChannel.getName(), snippet);
|
|
143
|
+ handleInput(tParser.parseHostmask(sHost)[0], cChannel.getName(), snippet);
|
139
|
144
|
snips.remove(snippet);
|
140
|
145
|
break;
|
141
|
146
|
}
|
|
@@ -165,13 +170,15 @@ public class InputHandler implements IChannelMessage, IPrivateMessage, IPrivateC
|
165
|
170
|
};
|
166
|
171
|
}
|
167
|
172
|
|
168
|
|
- public void onPrivateMessage(final IRCParser tParser, final String sMessage, final String sHost) {
|
169
|
|
- handleInput(ClientInfo.parseHost(sHost), ClientInfo.parseHost(sHost), sMessage);
|
|
173
|
+ @Override
|
|
174
|
+ public void onPrivateMessage(final Parser tParser, final Date date, final String sMessage, final String sHost) {
|
|
175
|
+ handleInput(tParser.parseHostmask(sHost)[0], tParser.parseHostmask(sHost)[0], sMessage);
|
170
|
176
|
}
|
171
|
177
|
|
|
178
|
+ @Override
|
172
|
179
|
@SuppressWarnings("unchecked")
|
173
|
|
- public void onPrivateCTCP(IRCParser tParser, String sType, String sMessage, String sHost) {
|
174
|
|
- final ClientInfo client = tParser.getClientInfoOrFake(sHost);
|
|
180
|
+ public void onPrivateCTCP(Parser tParser, Date date, String sType, String sMessage, String sHost) {
|
|
181
|
+ final ClientInfo client = tParser.getClient(sHost);
|
175
|
182
|
if ("COOKIE".equals(sType)) {
|
176
|
183
|
final String status = (String) client.getMap().get("Cookie");
|
177
|
184
|
final String key1 = (String) client.getMap().get("Key1");
|
|
@@ -179,7 +186,7 @@ public class InputHandler implements IChannelMessage, IPrivateMessage, IPrivateC
|
179
|
186
|
final String idp = (String) client.getMap().get("OpenID-p");
|
180
|
187
|
|
181
|
188
|
if ("GETKEY".equals(sMessage) && "SET".equals(status)) {
|
182
|
|
- parser.sendCTCP(ClientInfo.parseHost(sHost), "COOKIE", "SETKEY " + key1);
|
|
189
|
+ parser.sendCTCP(tParser.parseHostmask(sHost)[0], "COOKIE", "SETKEY " + key1);
|
183
|
190
|
client.getMap().put("Cookie", "GETKEY");
|
184
|
191
|
} else if (sMessage.startsWith("OFFER")) {
|
185
|
192
|
final String what = sMessage.substring(6);
|
|
@@ -197,7 +204,7 @@ public class InputHandler implements IChannelMessage, IPrivateMessage, IPrivateC
|
197
|
204
|
|
198
|
205
|
client.getMap().put("Cookie", "OFFER");
|
199
|
206
|
client.getMap().put("Key2", newkey2);
|
200
|
|
- parser.sendCTCP(ClientInfo.parseHost(sHost), "COOKIE", "GET " + newkey2);
|
|
207
|
+ parser.sendCTCP(tParser.parseHostmask(sHost)[0], "COOKIE", "GET " + newkey2);
|
201
|
208
|
} else if (sMessage.startsWith("SHOW") && "OFFER".equals(status)) {
|
202
|
209
|
final String payload = sMessage.substring(5);
|
203
|
210
|
final String info = new String(new ArcFourEncrypter(key1 + key2)
|
|
@@ -253,7 +260,7 @@ public class InputHandler implements IChannelMessage, IPrivateMessage, IPrivateC
|
253
|
260
|
final CommandOptions opts = command.getClass()
|
254
|
261
|
.getAnnotation(CommandOptions.class);
|
255
|
262
|
|
256
|
|
- final String id = (String) parser.getClientInfoOrFake(source)
|
|
263
|
+ final String id = (String) parser.getClient(source)
|
257
|
264
|
.getMap().get("OpenID");
|
258
|
265
|
|
259
|
266
|
if (opts.requireAuthorisation() && id == null) {
|
|
@@ -315,10 +322,11 @@ public class InputHandler implements IChannelMessage, IPrivateMessage, IPrivateC
|
315
|
322
|
}
|
316
|
323
|
}
|
317
|
324
|
|
318
|
|
- public void onChannelKick(IRCParser tParser, ChannelInfo cChannel,
|
|
325
|
+ @Override
|
|
326
|
+ public void onChannelKick(Parser tParser, Date date, ChannelInfo cChannel,
|
319
|
327
|
ChannelClientInfo cKickedClient, ChannelClientInfo cKickedByClient,
|
320
|
328
|
String sReason, String sKickedByHost) {
|
321
|
|
- if (cKickedClient.getClient().equals(parser.getMyself())) {
|
|
329
|
+ if (cKickedClient.getClient().equals(parser.getLocalClient())) {
|
322
|
330
|
tParser.joinChannel(cChannel.getName());
|
323
|
331
|
}
|
324
|
332
|
}
|