Kaynağa Gözat

Make CHANTYPES handling somewhat sane.

Get rid of weird round-the-houses method of processing, and avoid
duplicating the value in a map and a field.

This fixes our handling of servers doing really stupid, theoretical
things like resetting the CHANTYPES they support. (And by "fixes"
I mean the parser will keep state, while everything else burns
around it.)

Change-Id: Ie4936f21e68e4bb1134e9be3f16932eef4ab086f
Reviewed-on: http://gerrit.dmdirc.com/2831
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
tags/0.8
Chris Smith 10 yıl önce
ebeveyn
işleme
c15082c7b5

+ 17
- 18
src/com/dmdirc/parser/irc/IRCParser.java Dosyayı Görüntüle

@@ -679,9 +679,6 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
679 679
 
680 680
         post005 = true;
681 681
 
682
-        if (!h005Info.containsKey("CHANTYPES")) {
683
-            parseChanPrefix();
684
-        }
685 682
         if (!h005Info.containsKey("PREFIX")) {
686 683
             parsePrefixModes();
687 684
         }
@@ -1665,14 +1662,19 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
1665 1662
     }
1666 1663
 
1667 1664
     /**
1668
-     * Process CHANTYPES from 005.
1665
+     * Resets the channel prefix property to the default, RFC specified value.
1669 1666
      */
1670
-    protected void parseChanPrefix() {
1671
-        if (h005Info.containsKey("CHANTYPES") && !h005Info.get("CHANTYPES").isEmpty()) {
1672
-            chanPrefix = h005Info.get("CHANTYPES");
1673
-        } else {
1674
-            h005Info.put("CHANTYPES", DEFAULT_CHAN_PREFIX);
1675
-        }
1667
+    protected void resetChanPrefix() {
1668
+        chanPrefix = DEFAULT_CHAN_PREFIX;
1669
+    }
1670
+
1671
+    /**
1672
+     * Sets the set of possible channel prefixes to those in the given value.
1673
+     *
1674
+     * @param value The new set of channel prefixes.
1675
+     */
1676
+    protected void setChanPrefix(final String value) {
1677
+        chanPrefix = value;
1676 1678
     }
1677 1679
 
1678 1680
     /**
@@ -1745,15 +1747,12 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
1745 1747
                     list.append(',');
1746 1748
                 }
1747 1749
                 if (!isValidChannelName(channel.getName())) {
1748
-                    if (h005Info.containsKey("CHANTYPES")) {
1749
-                        final String chantypes = h005Info.get("CHANTYPES");
1750
-                        if (chantypes.isEmpty()) {
1751
-                            list.append('#');
1752
-                        } else {
1753
-                            list.append(chantypes.charAt(0));
1754
-                        }
1755
-                    } else {
1750
+                    if (chanPrefix.isEmpty()) {
1751
+                        // TODO: This is wrong - empty chan prefix means the
1752
+                        // IRCd supports no channels.
1756 1753
                         list.append('#');
1754
+                    } else {
1755
+                        list.append(chanPrefix.charAt(0));
1757 1756
                     }
1758 1757
                 }
1759 1758
                 list.append(channel.getName());

+ 10
- 3
src/com/dmdirc/parser/irc/Process004005.java Dosyayı Görüntüle

@@ -182,7 +182,7 @@ public class Process004005 extends IRCProcessor {
182 182
                     processCaseMappingToken(isNegation, value);
183 183
                     break;
184 184
                 case "CHANTYPES":
185
-                    processChanTypesToken();
185
+                    processChanTypesToken(isNegation, value);
186 186
                     break;
187 187
                 case "PREFIX":
188 188
                     processPrefixToken();
@@ -252,9 +252,16 @@ public class Process004005 extends IRCProcessor {
252 252
 
253 253
     /**
254 254
      * Processes a 'CHANTYPES' token received in a 005.
255
+     *
256
+     * @param isNegation Whether the token was negated or not.
257
+     * @param value The value of the token.
255 258
      */
256
-    private void processChanTypesToken() {
257
-        parser.parseChanPrefix();
259
+    private void processChanTypesToken(final boolean isNegation, final String value) {
260
+        if (isNegation) {
261
+            parser.resetChanPrefix();
262
+        } else {
263
+            parser.setChanPrefix(value);
264
+        }
258 265
     }
259 266
 
260 267
     /**

Loading…
İptal
Kaydet