Browse Source

Add ServerTypeGroup to allow grouping of servers with common behaviour. (Fixes issue 3491).

Switch everything that does something on a per-ircd basis to use ServerTypes not Strings.
Deprecate getIRCD() in favour of getServerSoftware() and getServerSoftwareType().

Change-Id: I324eaadeb39a9999f7dd9d7b8e6bd583dce7abca
Reviewed-on: http://gerrit.dmdirc.com/431
Reviewed-by: Chris Smith <chris@dmdirc.com>
Tested-by: Chris Smith <chris@dmdirc.com>
tags/0.6.3
Shane Mc Cormack 14 years ago
parent
commit
ee73a74211

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

@@ -496,7 +496,7 @@ public class IRCChannelInfo implements ChannelInfo {
496 496
         // Hyperion sucks.
497 497
         if (cMode == 'b' || cMode == 'q') {
498 498
             final ServerType serverType = myParser.getServerType();
499
-            if ((serverType == ServerType.DANCER || serverType == ServerType.HYPERION)) {
499
+            if (ServerTypeGroup.FREENODE.isMember(serverType)) {
500 500
                 if (cMode == 'b' && givenItem.getItem().charAt(0) == '%') {
501 501
                     cMode = 'q';
502 502
                 } else if (cMode == 'q' && givenItem.getItem().charAt(0) != '%') {

+ 11
- 8
src/com/dmdirc/parser/irc/IRCParser.java View File

@@ -1198,9 +1198,9 @@ public class IRCParser implements SecureParser, Runnable {
1198 1198
         String[] bits = null;
1199 1199
         String modeStr;
1200 1200
         if (h005Info.containsKey("USERCHANMODES")) {
1201
-            if (getIRCD(true).equalsIgnoreCase("dancer")) {
1201
+            if (getServerType() == ServerType.DANCER) {
1202 1202
                 sDefaultModes.insert(0, "dqeI");
1203
-            } else if (getIRCD(true).equalsIgnoreCase("austirc")) {
1203
+            } else if (getServerType() == ServerType.AUSTIRC) {
1204 1204
                 sDefaultModes.insert(0, "e");
1205 1205
             }
1206 1206
             modeStr = h005Info.get("USERCHANMODES");
@@ -1630,7 +1630,7 @@ public class IRCParser implements SecureParser, Runnable {
1630 1630
             try {
1631 1631
                 result = Integer.parseInt(h005Info.get("MAXBANS"));
1632 1632
             } catch (NumberFormatException nfe) { result = -1; }
1633
-        } else if (result == -2 && getIRCD(true).equalsIgnoreCase("weircd")) {
1633
+        } else if (result == -2 && getServerType() == ServerType.WEIRCD) {
1634 1634
             // -_-
1635 1635
             result = 50;
1636 1636
         } else if (result == -2) {
@@ -1779,26 +1779,29 @@ public class IRCParser implements SecureParser, Runnable {
1779 1779
      *
1780 1780
      * @param getType if this is false the string from 004 is returned. Else a guess of the type (ircu, hybrid, ircnet)
1781 1781
      * @return IRCD Version or Type
1782
+     * @deprecated Use getServerSoftware() or getServerSoftwareType() instead.
1782 1783
      */
1784
+    @Deprecated
1783 1785
     public String getIRCD(final boolean getType) {
1784 1786
         if (getType) {
1785
-            return getServerType().getType();
1787
+            return getServerSoftwareType();
1786 1788
         } else {
1787
-            final String version = h005Info.get("004IRCD");
1788
-            return (version == null) ? "" : version;
1789
+            return getServerSoftware();
1789 1790
         }
1790 1791
     }
1791 1792
 
1793
+
1792 1794
     /** {@inheritDoc} */
1793 1795
     @Override
1794 1796
     public String getServerSoftware() {
1795
-        return getIRCD(false);
1797
+        final String version = h005Info.get("004IRCD");
1798
+        return (version == null) ? "" : version;
1796 1799
     }
1797 1800
 
1798 1801
     /** {@inheritDoc} */
1799 1802
     @Override
1800 1803
     public String getServerSoftwareType() {
1801
-        return getIRCD(true);
1804
+        return getServerType().getType();
1802 1805
     }
1803 1806
 
1804 1807
     /**

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

@@ -143,8 +143,8 @@ public class Process004005 extends IRCProcessor {
143 143
      */
144 144
     protected boolean callGotNetwork() {
145 145
         final String networkName = myParser.networkName;
146
-        final String ircdVersion = myParser.getIRCD(false);
147
-        final String ircdType = myParser.getIRCD(true);
146
+        final String ircdVersion = myParser.getServerSoftware();
147
+        final String ircdType = myParser.getServerSoftwareType();
148 148
         
149 149
         return getCallbackManager().getCallbackType(NetworkDetectedListener.class).call(networkName, ircdVersion, ircdType);
150 150
     }

+ 6
- 6
src/com/dmdirc/parser/irc/ProcessListModes.java View File

@@ -82,11 +82,11 @@ public class ProcessListModes extends IRCProcessor {
82 82
                 mode = 'R';
83 83
             }
84 84
             isItem = sParam.equals("344");
85
-        } else if ((serverType == ServerType.SWIFTIRC || serverType == ServerType.AUSTHEX8) && (sParam.equals("386") || sParam.equals("387"))) {
85
+        } else if (ServerTypeGroup.OWNER_386.isMember(serverType) && (sParam.equals("386") || sParam.equals("387"))) {
86 86
             // Channel Owner list
87 87
             mode = 'q';
88 88
             isItem = sParam.equals("387");
89
-        } else if ((serverType == ServerType.SWIFTIRC || serverType == ServerType.AUSTHEX8) && (sParam.equals("388") || sParam.equals("389"))) {
89
+        } else if (ServerTypeGroup.PROTECTED_388.isMember(serverType) && (sParam.equals("388") || sParam.equals("389"))) {
90 90
             // Protected User list
91 91
             mode = 'a';
92 92
             isItem = sParam.equals("389");
@@ -118,7 +118,7 @@ public class ProcessListModes extends IRCProcessor {
118 118
                     //
119 119
                     // Only raise an LMQ error if the lmqmode isn't one of bdq if the
120 120
                     // guess is one of bdq
121
-                    if ((serverType == ServerType.DANCER || serverType == ServerType.HYPERION) && (mode == 'b' || mode == 'q' || mode == 'd')) {
121
+                    if (ServerTypeGroup.FREENODE.isMember(serverType) && (mode == 'b' || mode == 'q' || mode == 'd')) {
122 122
                         LinkedList<Character> lmq = (LinkedList<Character>)listModeQueue;
123 123
                         if (mode == 'b') {
124 124
                             error = !(oldMode == 'q' || oldMode == 'd');
@@ -131,7 +131,7 @@ public class ProcessListModes extends IRCProcessor {
131 131
                         } else if (mode == 'd') {
132 132
                             error = !(oldMode == 'b' || oldMode == 'q');
133 133
                         }
134
-                    } else if ((serverType == ServerType.IRCD_SEVEN || serverType == ServerType.CHARYBDIS) && (mode == 'b' || mode == 'q')) {
134
+                    } else if (ServerTypeGroup.CHARYBDIS.isMember(serverType) && (mode == 'b' || mode == 'q')) {
135 135
                         // Finally freenode appear to have an ircd which isn't completely annoying.
136 136
                         // Only error if the LMQ thinks the mode should be
137 137
                         // something thats not the other one of these 2 modes.
@@ -154,7 +154,7 @@ public class ProcessListModes extends IRCProcessor {
154 154
         }
155 155
         
156 156
         if (isItem) {
157
-            if ((!isCleverMode) && listModeQueue == null && (serverType == ServerType.DANCER || serverType == ServerType.HYPERION) && token.length > 4 && mode == 'b') {
157
+            if ((!isCleverMode) && listModeQueue == null && ServerTypeGroup.FREENODE.isMember(serverType) && token.length > 4 && mode == 'b') {
158 158
                 // Assume mode is a 'd' mode
159 159
                 mode = 'd';
160 160
                 // Now work out if its not (or attempt to.)
@@ -174,7 +174,7 @@ public class ProcessListModes extends IRCProcessor {
174 174
                     myParser.callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got list mode: '"+mode+"' - but channel object doesn't agree.", myParser.getLastLine()));
175 175
                 } else {
176 176
                     list.clear();
177
-                    if ((serverType == ServerType.DANCER || serverType == ServerType.HYPERION) && (mode == 'b' || mode == 'q')) {
177
+                    if (ServerTypeGroup.FREENODE.isMember(serverType) && (mode == 'b' || mode == 'q')) {
178 178
                         // Also clear the other list if b or q.
179 179
                         final Character otherMode = (mode == 'b') ? 'q' : 'b';
180 180
                         

+ 3
- 3
src/com/dmdirc/parser/irc/ServerType.java View File

@@ -1,16 +1,16 @@
1 1
 /*
2 2
  *  Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
- * 
3
+ *
4 4
  *  Permission is hereby granted, free of charge, to any person obtaining a copy
5 5
  *  of this software and associated documentation files (the "Software"), to deal
6 6
  *  in the Software without restriction, including without limitation the rights
7 7
  *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 8
  *  copies of the Software, and to permit persons to whom the Software is
9 9
  *  furnished to do so, subject to the following conditions:
10
- * 
10
+ *
11 11
  *  The above copyright notice and this permission notice shall be included in
12 12
  *  all copies or substantial portions of the Software.
13
- * 
13
+ *
14 14
  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 15
  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 16
  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

+ 95
- 0
src/com/dmdirc/parser/irc/ServerTypeGroup.java View File

@@ -0,0 +1,95 @@
1
+/*
2
+ *  Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
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.Arrays;
26
+import java.util.List;
27
+
28
+/**
29
+ * Groups of servers do things the same way as each other.
30
+ */
31
+public enum ServerTypeGroup {
32
+    /**
33
+     * Freenode Group.
34
+     */
35
+    FREENODE("Freenode IRCDs", new ServerType[]{ServerType.HYPERION, ServerType.DANCER}),
36
+    /**
37
+     * Charybdis Group.
38
+     */
39
+    CHARYBDIS("Charybdis-esque IRCDs", new ServerType[]{ServerType.IRCD_SEVEN, ServerType.CHARYBDIS}),
40
+    /**
41
+     * Group for ircds that put the channel owners in a list under raw 386
42
+     * rather than as a channel user mode.
43
+     */
44
+    OWNER_386("Owner List", new ServerType[]{ServerType.SWIFTIRC, ServerType.AUSTHEX8}),
45
+    /**
46
+     * Group for ircds that put the protected users in a list under raw 388
47
+     * rather than as a channel user mode.
48
+     */
49
+    PROTECTED_388("Protected List", new ServerType[]{ServerType.SWIFTIRC, ServerType.AUSTHEX8});
50
+
51
+    /** Name of the group. */
52
+    final String name;
53
+
54
+    /** Group Members. */
55
+    final List<ServerType> members;
56
+
57
+    /**
58
+     * Create a new ServerTypeGroup.
59
+     *
60
+     * @param name Name of this group.
61
+     * @param members Members of this group.
62
+     */
63
+    ServerTypeGroup(final String name, final ServerType[] members) {
64
+        this.name = name;
65
+        this.members = Arrays.asList(members);
66
+    }
67
+
68
+    /**
69
+     * Get the members of this group.
70
+     *
71
+     * @return The members of this group.
72
+     */
73
+    public List<ServerType> getMembers() {
74
+        return members;
75
+    }
76
+
77
+    /**
78
+     * Get the name of this group.
79
+     *
80
+     * @return The name of this group.
81
+     */
82
+    public String getName() {
83
+        return name;
84
+    }
85
+
86
+    /**
87
+     * Check if the given ServerType is a member of this group.
88
+     *
89
+     * @param type The type to check.
90
+     * @return True of the given ServerType is a member of this group.
91
+     */
92
+    public boolean isMember(final ServerType type) {
93
+        return members.contains(type);
94
+    }
95
+}

Loading…
Cancel
Save