|
@@ -0,0 +1,254 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (c) 2006-2009 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
|
+/**
|
|
26
|
+ * This defines server types.
|
|
27
|
+ * ServerTypes define a regex that will be matched against a lower-cased verison
|
|
28
|
+ * of the input, an array of modes that only ops can request, and what they are
|
|
29
|
+ * matching against.
|
|
30
|
+ * Lowercaseing will be handled using javas built in toLowercase() rather than
|
|
31
|
+ * usig the Server-Specific one.
|
|
32
|
+ *
|
|
33
|
+ * @author shane
|
|
34
|
+ */
|
|
35
|
+public enum ServerType {
|
|
36
|
+ /** Unreal IRCD prior to version 4. */
|
|
37
|
+ UNREAL("unreal", ".*unreal[^4-9].*"),
|
|
38
|
+ /** Unreal IRCD after version 4 (inspircd based). */
|
|
39
|
+ UNREAL4("unreal4", ".*unreal[4-9].*"),
|
|
40
|
+ /** Bahamut. */
|
|
41
|
+ BAHAMUT("bahamut", ".*bahamut.*"),
|
|
42
|
+ /** Some IRCU Fork. */
|
|
43
|
+ NEFARIOUS("nefarious", ".*nefarious.*"),
|
|
44
|
+ /** Quakenets old IRCU Fork. */
|
|
45
|
+ ASUKA("asuka", ".*asuka.*"),
|
|
46
|
+ /** Quakenets current IRCU Fork. */
|
|
47
|
+ SNIRCD("snircd", ".*snircd.*"),
|
|
48
|
+ /** Windows IRCU-Based IRCD. */
|
|
49
|
+ BIRCD("bircd", ".*beware.*"),
|
|
50
|
+ /** Spanish IRCU Fork. */
|
|
51
|
+ IRCHISPANO("irchispano", ".*u2\\.[0-9]+\\.H\\..*"),
|
|
52
|
+ /** IRCU. */
|
|
53
|
+ IRCU2("ircu", ".*u2\\.[0-9]+\\..*"),
|
|
54
|
+ /** Some kind of IRCU Fork. */
|
|
55
|
+ IRCU_GENERIC("ircu", ".*ircu.*"),
|
|
56
|
+ /** Plexus. */
|
|
57
|
+ PLEXUS("plexus", ".*plexus.*"),
|
|
58
|
+ /** OFTCs hybrid fork. */
|
|
59
|
+ OFTC_HYBRID("oftc-hybrid", ".*hybrid.*oftc.*"),
|
|
60
|
+ /** hybrid7. */
|
|
61
|
+ HYBRID7("hybrid7", ".*ircd.hybrid.*", "eI"),
|
|
62
|
+ /** Older versions of Hybrid. */
|
|
63
|
+ HYBRID("hybrid", ".*hybrid.*", "eI"),
|
|
64
|
+ /** Freenodes new IRCD. */
|
|
65
|
+ CHARYBDIS("charybdis", ".*charybdis.*", "eI"),
|
|
66
|
+ /** Freenodes Current IRCD. */
|
|
67
|
+ HYPERION("hyperion", ".*hyperion.*", "eI"),
|
|
68
|
+ /** Freenodes Old IRCD. */
|
|
69
|
+ DANCER("dancer", ".*dancer.*", "eI"),
|
|
70
|
+ /** Inspircd. */
|
|
71
|
+ INSPIRCD("inspircd", ".*inspircd.*"),
|
|
72
|
+ /** Ultimate IRCD. */
|
|
73
|
+ ULTIMATEIRCD("ultimateircd", ".*ultimateircd.*"),
|
|
74
|
+ /** Criten IRCD. */
|
|
75
|
+ CRITENIRCD("critenircd", ".*critenircd.*"),
|
|
76
|
+ /** fqircd. */
|
|
77
|
+ FQIRCD("fqircd", ".*fqircd.*"),
|
|
78
|
+ /** Microsoft's Conference Room "IRCD". */
|
|
79
|
+ CONFERENCEROOM("conferenceroom", ".*conferenceroom.*"),
|
|
80
|
+ /** AustHex custom IRCD. */
|
|
81
|
+ AUSTHEX("austhex", ".*austhex.*"),
|
|
82
|
+ /** AustIRC custom IRCD. */
|
|
83
|
+ AUSTIRC("austirc", ".*austirc.*"),
|
|
84
|
+ /** Ratbox. */
|
|
85
|
+ RATBOX("ratbox", ".*ratbox.*"),
|
|
86
|
+ /** euircd. */
|
|
87
|
+ EUIRCD("euircd", ".*euircd.*"),
|
|
88
|
+ /** weircd. */
|
|
89
|
+ WEIRCD("weircd", ".*weircd.*"),
|
|
90
|
+ /** swiftirc's ircd. */
|
|
91
|
+ SWIFTIRC("swiftirc", ".*swiftirc.*"),
|
|
92
|
+ /** IRCNet. */
|
|
93
|
+ IRCNET("ircnet", "ircnet", null, MatchType.NETWORK),
|
|
94
|
+ /** Star Chat. */
|
|
95
|
+ STARCHAT("starchat", "starchat", null, MatchType.NETWORK),
|
|
96
|
+ /** Newer Bitlbee. */
|
|
97
|
+ BITLBEE("bitlbee", "bitlbee", null, MatchType.NETWORK),
|
|
98
|
+ /** Older Bitlbee. */
|
|
99
|
+ BITLBEE_OLD("bitlbee", "bitlbee", null, MatchType.RAW003),
|
|
100
|
+ /** Pastiche. */
|
|
101
|
+ PASTICHE("bitlbee", "ircd-pastiche", null, MatchType.RAW002),
|
|
102
|
+ /** Generic IRCD. */
|
|
103
|
+ GENERIC("generic", "", null, MatchType.NEVER);
|
|
104
|
+
|
|
105
|
+ /** Define what this ServerType should match on. */
|
|
106
|
+ private enum MatchType {
|
|
107
|
+ /** Match using the ircd version from 004. */
|
|
108
|
+ VERSION,
|
|
109
|
+ /** Match using the network name. */
|
|
110
|
+ NETWORK,
|
|
111
|
+ /** Match using raw 003. */
|
|
112
|
+ RAW003,
|
|
113
|
+ /** Match using raw 002. */
|
|
114
|
+ RAW002,
|
|
115
|
+ /** Never Match (Used by generic). */
|
|
116
|
+ NEVER;
|
|
117
|
+ }
|
|
118
|
+
|
|
119
|
+ /** Type of for this ServerType. */
|
|
120
|
+ private final String type;
|
|
121
|
+
|
|
122
|
+ /** Regex for this ServerType. */
|
|
123
|
+ private final String regex;
|
|
124
|
+
|
|
125
|
+ /** String of chars that only ops can access. */
|
|
126
|
+ private final String opOnly;
|
|
127
|
+
|
|
128
|
+ /** What does this ServerType match? */
|
|
129
|
+ private final MatchType matchType;
|
|
130
|
+
|
|
131
|
+ /**
|
|
132
|
+ * Create a new server type.
|
|
133
|
+ *
|
|
134
|
+ * @param type The name for this type.
|
|
135
|
+ * @param regex The regex for this type.
|
|
136
|
+ */
|
|
137
|
+ ServerType(final String type, final String regex) {
|
|
138
|
+ this(type, regex, null);
|
|
139
|
+ }
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+ /**
|
|
143
|
+ * Create a new server type.
|
|
144
|
+ *
|
|
145
|
+ * @param type The name for this type.
|
|
146
|
+ * @param regex The regex for this type.
|
|
147
|
+ * @param opOnly Any mode chars that are op-only.
|
|
148
|
+ */
|
|
149
|
+ ServerType(final String type, final String regex, final String opOnly) {
|
|
150
|
+ this(type, regex, opOnly, MatchType.VERSION);
|
|
151
|
+ }
|
|
152
|
+
|
|
153
|
+ /**
|
|
154
|
+ * Create a new server type.
|
|
155
|
+ *
|
|
156
|
+ * @param type The name for this type.
|
|
157
|
+ * @param regex The regex for this type.
|
|
158
|
+ * @param opOnly Any mode chars that are op-only.
|
|
159
|
+ * @param matchType What information should we match on?
|
|
160
|
+ */
|
|
161
|
+ ServerType(final String type, final String regex, final String opOnly, final MatchType matchType) {
|
|
162
|
+ this.type = type;
|
|
163
|
+ this.regex = regex;
|
|
164
|
+ this.opOnly = (opOnly == null) ? "" : opOnly;
|
|
165
|
+ this.matchType = matchType;
|
|
166
|
+ }
|
|
167
|
+
|
|
168
|
+ /**
|
|
169
|
+ * Get a string that defines what type this server is.
|
|
170
|
+ *
|
|
171
|
+ * @return String that defines what type this server is.
|
|
172
|
+ */
|
|
173
|
+ public String getType() {
|
|
174
|
+ return type;
|
|
175
|
+ }
|
|
176
|
+
|
|
177
|
+ /**
|
|
178
|
+ * Get the MatchType of this ServerType
|
|
179
|
+ *
|
|
180
|
+ * @return The MatchType of this ServerType
|
|
181
|
+ */
|
|
182
|
+ private MatchType getMatchType() {
|
|
183
|
+ return matchType;
|
|
184
|
+ }
|
|
185
|
+
|
|
186
|
+ /**
|
|
187
|
+ * Get the Regex used by this ServerType.
|
|
188
|
+ *
|
|
189
|
+ * @return The Regex used by this ServerType.
|
|
190
|
+ */
|
|
191
|
+ private String getRegex() {
|
|
192
|
+ return regex;
|
|
193
|
+ }
|
|
194
|
+
|
|
195
|
+ /**
|
|
196
|
+ * Get the modes that are op-only.
|
|
197
|
+ *
|
|
198
|
+ * @return the modes that are op-only.
|
|
199
|
+ */
|
|
200
|
+ public String getOpOnly() {
|
|
201
|
+ return opOnly;
|
|
202
|
+ }
|
|
203
|
+
|
|
204
|
+ /**
|
|
205
|
+ * Check if the given mode is op-only.
|
|
206
|
+ *
|
|
207
|
+ * @param mode
|
|
208
|
+ * @return
|
|
209
|
+ */
|
|
210
|
+ public boolean isOpOnly(final char mode) {
|
|
211
|
+ return (opOnly.indexOf(mode) != -1);
|
|
212
|
+ }
|
|
213
|
+
|
|
214
|
+ /**
|
|
215
|
+ * Find the first ServerType that matches the given details.
|
|
216
|
+ *
|
|
217
|
+ * @param versionInput Version from 004
|
|
218
|
+ * @param networkInput Network Name
|
|
219
|
+ * @param raw003Input 003 line
|
|
220
|
+ * @param raw002Input 002 line
|
|
221
|
+ * @return The Server type that matches the given details.
|
|
222
|
+ */
|
|
223
|
+ public static ServerType findServerType(final String versionInput, final String networkInput, final String raw003Input, final String raw002Input) {
|
|
224
|
+ final String version = (versionInput == null) ? "" : versionInput.toLowerCase();
|
|
225
|
+ final String network = (networkInput == null) ? "" : networkInput.toLowerCase();
|
|
226
|
+ final String raw003 = (raw003Input == null) ? "" : raw003Input.toLowerCase();
|
|
227
|
+ final String raw002 = (raw002Input == null) ? "" : raw002Input.toLowerCase();
|
|
228
|
+
|
|
229
|
+ for (ServerType type : ServerType.values()) {
|
|
230
|
+ switch (type.getMatchType()) {
|
|
231
|
+ case VERSION:
|
|
232
|
+ if (version.matches(type.getRegex())) { return type; }
|
|
233
|
+ break;
|
|
234
|
+ case NETWORK:
|
|
235
|
+ if (network.matches(type.getRegex())) { return type; }
|
|
236
|
+ break;
|
|
237
|
+ case RAW003:
|
|
238
|
+ if (raw003.matches(type.getRegex())) { return type; }
|
|
239
|
+ break;
|
|
240
|
+ case RAW002:
|
|
241
|
+ if (raw002.matches(type.getRegex())) { return type; }
|
|
242
|
+ break;
|
|
243
|
+ case NEVER:
|
|
244
|
+ break;
|
|
245
|
+ default:
|
|
246
|
+ /* Won't happen. */
|
|
247
|
+ break;
|
|
248
|
+ }
|
|
249
|
+ }
|
|
250
|
+
|
|
251
|
+ // Return Generic IRCD.
|
|
252
|
+ return ServerType.GENERIC;
|
|
253
|
+ }
|
|
254
|
+}
|