|
@@ -39,6 +39,7 @@ import com.dmdirc.parser.interfaces.callbacks.Post005Listener;
|
39
|
39
|
import com.dmdirc.parser.interfaces.callbacks.ServerErrorListener;
|
40
|
40
|
import com.dmdirc.parser.interfaces.callbacks.SocketCloseListener;
|
41
|
41
|
import com.dmdirc.parser.common.CallbackManager;
|
|
42
|
+import com.dmdirc.parser.common.ChannelJoinRequest;
|
42
|
43
|
import com.dmdirc.parser.common.QueuePriority;
|
43
|
44
|
|
44
|
45
|
import java.io.BufferedReader;
|
|
@@ -53,6 +54,7 @@ import java.net.UnknownHostException;
|
53
|
54
|
import java.security.KeyManagementException;
|
54
|
55
|
import java.security.NoSuchAlgorithmException;
|
55
|
56
|
import java.security.cert.X509Certificate;
|
|
57
|
+import java.util.ArrayList;
|
56
|
58
|
import java.util.Arrays;
|
57
|
59
|
import java.util.Collection;
|
58
|
60
|
import java.util.HashMap;
|
|
@@ -357,11 +359,33 @@ public class IRCParser implements SecureParser, Runnable {
|
357
|
359
|
|
358
|
360
|
/** {@inheritDoc} */
|
359
|
361
|
@Override
|
360
|
|
- public void updateURI(final URI uri) {
|
361
|
|
- final String channels = new ServerInfo(uri).getChannels();
|
362
|
|
- if (channels != null) {
|
363
|
|
- joinChannel(channels, true);
|
|
362
|
+ public Collection<? extends ChannelJoinRequest> extractChannels(final URI uri) {
|
|
363
|
+ return extractChannels(new ServerInfo(uri).getChannels());
|
|
364
|
+ }
|
|
365
|
+
|
|
366
|
+ /**
|
|
367
|
+ * Extracts a set of channels and optional keys from the specified String.
|
|
368
|
+ * Channels are separated by commas, and keys are separated from their
|
|
369
|
+ * channels by a space.
|
|
370
|
+ *
|
|
371
|
+ * @since 0.6.4
|
|
372
|
+ * @param channels The string of channels to parse
|
|
373
|
+ * @return A corresponding collection of join request objects
|
|
374
|
+ */
|
|
375
|
+ protected Collection<? extends ChannelJoinRequest> extractChannels(final String channels) {
|
|
376
|
+ final List<ChannelJoinRequest> res = new ArrayList<ChannelJoinRequest>();
|
|
377
|
+
|
|
378
|
+ for (String channel : channels.split(",")) {
|
|
379
|
+ final String[] parts = channel.split(" ", 2);
|
|
380
|
+
|
|
381
|
+ if (parts.length == 2) {
|
|
382
|
+ res.add(new ChannelJoinRequest(parts[0], parts[1]));
|
|
383
|
+ } else {
|
|
384
|
+ res.add(new ChannelJoinRequest(parts[0]));
|
|
385
|
+ }
|
364
|
386
|
}
|
|
387
|
+
|
|
388
|
+ return res;
|
365
|
389
|
}
|
366
|
390
|
|
367
|
391
|
/** {@inheritDoc} */
|
|
@@ -1468,24 +1492,13 @@ public class IRCParser implements SecureParser, Runnable {
|
1468
|
1492
|
/** {@inheritDoc} */
|
1469
|
1493
|
@Override
|
1470
|
1494
|
public void joinChannel(final String channel) {
|
1471
|
|
- joinChannel(channel, "", true);
|
1472
|
|
- }
|
1473
|
|
-
|
1474
|
|
- /**
|
1475
|
|
- * Join a Channel.
|
1476
|
|
- *
|
1477
|
|
- * @param sChannelName Name of channel to join
|
1478
|
|
- * @param autoPrefix Automatically prepend the first channel prefix defined
|
1479
|
|
- * in 005 if sChannelName is an invalid channel.
|
1480
|
|
- */
|
1481
|
|
- public void joinChannel(final String sChannelName, final boolean autoPrefix) {
|
1482
|
|
- joinChannel(sChannelName, "", autoPrefix);
|
|
1495
|
+ joinChannels(extractChannels(channel).toArray(new ChannelJoinRequest[0]));
|
1483
|
1496
|
}
|
1484
|
1497
|
|
1485
|
1498
|
/** {@inheritDoc} */
|
1486
|
1499
|
@Override
|
1487
|
1500
|
public void joinChannel(final String channel, final String key) {
|
1488
|
|
- joinChannel(channel, key, true);
|
|
1501
|
+ joinChannels(new ChannelJoinRequest(channel, key));
|
1489
|
1502
|
}
|
1490
|
1503
|
|
1491
|
1504
|
/**
|
|
@@ -1497,35 +1510,26 @@ public class IRCParser implements SecureParser, Runnable {
|
1497
|
1510
|
* @param key Key to use to try and join the channel (If a list is given
|
1498
|
1511
|
* then this key will be used for any channels that do not
|
1499
|
1512
|
* specify one themselves.
|
1500
|
|
- * @param autoPrefix Automatically prepend the first channel prefix defined
|
1501
|
|
- * in 005 to any of the channels passsed if they are
|
1502
|
|
- * otherwise invalid channels.
|
1503
|
1513
|
*/
|
1504
|
|
- public void joinChannel(final String channel, final String key, final boolean autoPrefix) {
|
1505
|
|
- final String[] bits = channel.split(",");
|
1506
|
|
-
|
|
1514
|
+ @Override
|
|
1515
|
+ public void joinChannels(final ChannelJoinRequest ... channels) {
|
1507
|
1516
|
// We store a map from key->channels to allow intelligent joining of
|
1508
|
1517
|
// channels using as few JOIN commands as needed.
|
1509
|
1518
|
final Map<String, StringBuffer> joinMap = new HashMap<String, StringBuffer>();
|
1510
|
1519
|
|
1511
|
|
- for (String bit : bits) {
|
1512
|
|
- // Find any key for this channel
|
1513
|
|
- final String[] keybits = bit.split(" ", 2);
|
1514
|
|
- final String channelName = keybits[0];
|
1515
|
|
- final String thisKey = (keybits.length > 1) ? keybits[1] : key;
|
1516
|
|
-
|
|
1520
|
+ for (ChannelJoinRequest channel : channels) {
|
1517
|
1521
|
// Make sure we have a list to put stuff in.
|
1518
|
|
- StringBuffer list = joinMap.get(thisKey);
|
|
1522
|
+ StringBuffer list = joinMap.get(channel.getPassword());
|
1519
|
1523
|
if (list == null) {
|
1520
|
1524
|
list = new StringBuffer();
|
1521
|
|
- joinMap.put(thisKey, list);
|
|
1525
|
+ joinMap.put(channel.getPassword(), list);
|
1522
|
1526
|
}
|
1523
|
1527
|
|
1524
|
1528
|
// Add the channel to the list. If the name is invalid and
|
1525
|
1529
|
// autoprefix is off we will just skip this channel.
|
1526
|
|
- if (channelName.length() > 0 && (isValidChannelName(channelName) || autoPrefix)) {
|
|
1530
|
+ if (!channel.getName().isEmpty()) {
|
1527
|
1531
|
if (list.length() > 0) { list.append(","); }
|
1528
|
|
- if (!isValidChannelName(channelName) && autoPrefix) {
|
|
1532
|
+ if (!isValidChannelName(channel.getName())) {
|
1529
|
1533
|
if (h005Info.containsKey("CHANTYPES")) {
|
1530
|
1534
|
final String chantypes = h005Info.get("CHANTYPES");
|
1531
|
1535
|
if (chantypes.isEmpty()) {
|
|
@@ -1537,7 +1541,7 @@ public class IRCParser implements SecureParser, Runnable {
|
1537
|
1541
|
list.append('#');
|
1538
|
1542
|
}
|
1539
|
1543
|
}
|
1540
|
|
- list.append(channelName);
|
|
1544
|
+ list.append(channel.getName());
|
1541
|
1545
|
}
|
1542
|
1546
|
}
|
1543
|
1547
|
|
|
@@ -1545,7 +1549,7 @@ public class IRCParser implements SecureParser, Runnable {
|
1545
|
1549
|
final String thisKey = entrySet.getKey();
|
1546
|
1550
|
final String channelString = entrySet.getValue().toString();
|
1547
|
1551
|
if (!channelString.isEmpty()) {
|
1548
|
|
- if (thisKey.isEmpty()) {
|
|
1552
|
+ if (thisKey == null || thisKey.isEmpty()) {
|
1549
|
1553
|
sendString("JOIN " + channelString);
|
1550
|
1554
|
} else {
|
1551
|
1555
|
sendString("JOIN " + channelString + " " + thisKey);
|