Переглянути джерело

No point using 2 separate queue's...

pull/115/head
Shane Mc Cormack 8 роки тому
джерело
коміт
6e105baeb0

+ 45
- 17
irc/src/com/dmdirc/parser/irc/processors/ProcessJoin.java Переглянути файл

@@ -61,9 +61,7 @@ public class ProcessJoin extends IRCProcessor {
61 61
     /** Mode manager to use for channel modes. */
62 62
     private final ModeManager chanModeManager;
63 63
     /** Pending Joins. */
64
-    private final Queue<String> pendingJoins = new LinkedList<>();
65
-    /** Pending Join Keys. */
66
-    private final Queue<String> pendingJoinKeys = new LinkedList<>();
64
+    private final Queue<PendingJoin> pendingJoins = new LinkedList<>();
67 65
 
68 66
     /**
69 67
      * Create a new instance of the IRCProcessor Object.
@@ -183,24 +181,21 @@ public class ProcessJoin extends IRCProcessor {
183 181
             parser.addChannel(iChannel);
184 182
             sendString("MODE " + iChannel.getName(), QueuePriority.LOW);
185 183
 
186
-            final String pendingJoin = pendingJoins.poll();
187
-            final String pendingJoinKey = pendingJoinKeys.poll();
188
-            if (pendingJoin != null && pendingJoin.equalsIgnoreCase(channelName)) {
189
-                callDebugInfo(IRCParser.DEBUG_INFO, "processJoin: Guessing channel Key: " + pendingJoin + " -> " + pendingJoinKey);
190
-                iChannel.setInternalPassword(pendingJoinKey == null ? "" : pendingJoinKey);
184
+            final PendingJoin pendingJoin = pendingJoins.poll();
185
+            if (pendingJoin != null && parser.getStringConverter().equalsIgnoreCase(pendingJoin.getChannel(), channelName)) {
186
+                callDebugInfo(IRCParser.DEBUG_INFO, "processJoin: Guessing channel Key: " + pendingJoin.getChannel() + " -> " + pendingJoin.getKey());
187
+                iChannel.setInternalPassword(pendingJoin.getKey());
191 188
             } else {
192 189
                 // Out of sync, clear
193
-                callDebugInfo(IRCParser.DEBUG_INFO, "processJoin: pending join keys out of sync (Got: " + pendingJoin + ", Wanted: " + channelName + ") - Clearing.");
190
+                callDebugInfo(IRCParser.DEBUG_INFO, "processJoin: pending join keys out of sync (Got: " + pendingJoin.getChannel() + ", Wanted: " + channelName + ") - Clearing.");
194 191
                 pendingJoins.clear();
195
-                pendingJoinKeys.clear();
196 192
             }
197 193
 
198 194
             callChannelSelfJoin(iChannel);
199 195
         } else {
200 196
             // Some kind of failed to join, pop the pending join queues.
201
-            final String pendingJoin = pendingJoins.poll();
202
-            final String pendingJoinKey = pendingJoinKeys.poll();
203
-            callDebugInfo(IRCParser.DEBUG_INFO, "processJoin: Failed to join channel (" + sParam + ") - Skipping " + pendingJoin + " (" + pendingJoinKey + ")");
197
+            final PendingJoin pendingJoin = pendingJoins.poll();
198
+            callDebugInfo(IRCParser.DEBUG_INFO, "processJoin: Failed to join channel (" + sParam + ") - Skipping " + pendingJoin.getChannel() + " (" + pendingJoin.getKey() + ")");
204 199
         }
205 200
     }
206 201
 
@@ -218,8 +213,6 @@ public class ProcessJoin extends IRCProcessor {
218 213
                 keys.addAll(Arrays.asList(newLine[2].split(",")));
219 214
             }
220 215
 
221
-            // PendingJoins and PendingJoinKeys should always be the same length (even if no key was given).
222
-            //
223 216
             // We don't get any errors for channels we try to join that we are already in
224 217
             // But the IRCD will still swallow the key attempt.
225 218
             //
@@ -229,8 +222,7 @@ public class ProcessJoin extends IRCProcessor {
229 222
                 final String key = keys.poll();
230 223
                 if (getChannel(chan) == null) {
231 224
                     callDebugInfo(IRCParser.DEBUG_INFO, "processJoin: Intercepted possible channel Key: " + chan + " -> " + key);
232
-                    pendingJoins.add(chan);
233
-                    pendingJoinKeys.add(key);
225
+                    pendingJoins.add(new PendingJoin(chan, key));
234 226
                 } else {
235 227
                     callDebugInfo(IRCParser.DEBUG_INFO, "processJoin: Ignoring possible channel Key for existing channel: " + chan + " -> " + key);
236 228
                 }
@@ -260,4 +252,40 @@ public class ProcessJoin extends IRCProcessor {
260 252
                 parser, LocalDateTime.now(), cChannel));
261 253
     }
262 254
 
255
+
256
+    private class PendingJoin {
257
+        /** Channel name. */
258
+        private final String channel;
259
+        /** Guessed Key. */
260
+        private final String key;
261
+
262
+        /**
263
+         * Create a new PendingJoin
264
+         *
265
+         * @param channel Channel
266
+         * @param key Guessed Key (if there is one)
267
+         */
268
+        public PendingJoin(final String channel, final String key) {
269
+            this.channel = channel;
270
+            this.key = (key == null ? "" : key);
271
+        }
272
+
273
+        /**
274
+         * Get the channel name.
275
+         *
276
+         * @return Channel name,
277
+         */
278
+        public String getChannel() {
279
+            return channel;
280
+        }
281
+
282
+        /**
283
+         * Get the key
284
+         *
285
+         * @return Key
286
+         */
287
+        public String getKey() {
288
+            return key;
289
+        }
290
+    }
263 291
 }

Завантаження…
Відмінити
Зберегти