Pārlūkot izejas kodu

Server.connect() now uses IrcAddress. Issue 2736.

tags/0.6.3m2a1
Chris Smith 15 gadus atpakaļ
vecāks
revīzija
4f7bdf0544

+ 9
- 3
src/com/dmdirc/ParserFactory.java Parādīt failu

@@ -26,6 +26,7 @@ import com.dmdirc.parser.interfaces.Parser;
26 26
 import com.dmdirc.parser.irc.IRCParser;
27 27
 import com.dmdirc.parser.irc.MyInfo;
28 28
 import com.dmdirc.parser.irc.ServerInfo;
29
+import com.dmdirc.util.IrcAddress;
29 30
 
30 31
 /**
31 32
  * Provides a method to retrieve a parser.
@@ -39,11 +40,16 @@ public class ParserFactory {
39 40
      * Retrieves a parser instance.
40 41
      * 
41 42
      * @param myInfo The client information to use
42
-     * @param serverInfo The server details to use
43
+     * @param address The address of the server to connect to
43 44
      * @return An appropriately configured parser
45
+     * @since 0.6.3m2
44 46
      */
45
-    public Parser getParser(final MyInfo myInfo, final ServerInfo serverInfo) {
46
-        return new IRCParser(myInfo, serverInfo);
47
+    public Parser getParser(final MyInfo myInfo, final IrcAddress address) {
48
+        final ServerInfo info = new ServerInfo(address.getServer(), address.getPort(),
49
+                address.getPassword());
50
+        info.setSSL(address.isSSL());
51
+        
52
+        return new IRCParser(myInfo, info);
47 53
     }
48 54
 
49 55
 }

+ 25
- 35
src/com/dmdirc/Server.java Parādīt failu

@@ -51,9 +51,9 @@ import com.dmdirc.ui.input.TabCompletionType;
51 51
 import com.dmdirc.ui.interfaces.InputWindow;
52 52
 import com.dmdirc.ui.interfaces.ServerWindow;
53 53
 import com.dmdirc.ui.interfaces.Window;
54
-
55 54
 import com.dmdirc.util.InvalidAddressException;
56 55
 import com.dmdirc.util.IrcAddress;
56
+
57 57
 import java.io.Serializable;
58 58
 import java.util.ArrayList;
59 59
 import java.util.Hashtable;
@@ -97,20 +97,24 @@ public class Server extends WritableFrameContainer implements Serializable {
97 97
 
98 98
     /** Open channels that currently exist on the server. */
99 99
     private final Map<String, Channel> channels  = new Hashtable<String, Channel>();
100
+
100 101
     /** Open query windows on the server. */
101 102
     private final List<Query> queries = new ArrayList<Query>();
102 103
 
103 104
     /** The Parser instance handling this server. */
104 105
     private transient Parser parser;
106
+
105 107
     /** The IRC Parser Thread. */
106 108
     private transient Thread parserThread;
109
+
107 110
     /** The raw frame used for this server instance. */
108 111
     private Raw raw;
112
+
109 113
     /** The ServerWindow corresponding to this server. */
110 114
     private ServerWindow window;
111 115
 
112
-    /** The details of the server we're connecting to. */
113
-    private ServerInfo serverInfo;
116
+    /** The address of the server we're connecting to. */
117
+    private IrcAddress address;
114 118
 
115 119
     /** The profile we're using. */
116 120
     private transient Identity profile;
@@ -121,9 +125,6 @@ public class Server extends WritableFrameContainer implements Serializable {
121 125
     /** The timer we're using to delay reconnects. */
122 126
     private Timer reconnectTimer;
123 127
 
124
-    /** Channels we're meant to auto-join. */
125
-    private final List<String> autochannels;
126
-
127 128
     /** The tabcompleter used for this server. */
128 129
     private final TabCompleter tabCompleter = new TabCompleter();
129 130
     /** The last activated internal frame for this server. */
@@ -144,9 +145,6 @@ public class Server extends WritableFrameContainer implements Serializable {
144 145
     /** Our string convertor. */
145 146
     private StringConverter converter = new IRCStringConverter();
146 147
 
147
-    /** The parser factory to use. */
148
-    private final ParserFactory parserFactory;
149
-
150 148
     // </editor-fold>
151 149
     
152 150
     // </editor-fold>
@@ -177,11 +175,7 @@ public class Server extends WritableFrameContainer implements Serializable {
177 175
         super("server-disconnected", url.getServer(),
178 176
                 new ConfigManager("", "", url.getServer()));
179 177
 
180
-        serverInfo = new ServerInfo(url.getServer(), url.getPort(), url.getPassword());
181
-        serverInfo.setSSL(url.isSSL());
182
-
183
-        this.autochannels = url.getChannels();
184
-        this.parserFactory = new ParserFactory();
178
+        this.address = url;
185 179
 
186 180
         window = Main.getUI().getServer(this);
187 181
 
@@ -216,7 +210,7 @@ public class Server extends WritableFrameContainer implements Serializable {
216 210
             addRaw();
217 211
         }
218 212
 
219
-        connect(url.getServer(), url.getPort(), url.getPassword(), url.isSSL(), profile);
213
+        connect(url, profile);
220 214
     }
221 215
 
222 216
     // </editor-fold>
@@ -226,19 +220,16 @@ public class Server extends WritableFrameContainer implements Serializable {
226 220
     /**
227 221
      * Connects to a new server with the specified details.
228 222
      *
229
-     * @param server The hostname/ip of the server to connect to
230
-     * @param port The port to connect to
231
-     * @param password The server password
232
-     * @param ssl Whether to use SSL or not
223
+     * @param address The address of the server to connect to
233 224
      * @param profile The profile to use
225
+     * @since 0.6.3m2
234 226
      */
235 227
     @Precondition({
236
-        "The IRC Parser is null or not connected",
228
+        "The current parser is null or not connected",
237 229
         "The specified profile is not null"
238 230
     })
239 231
     @SuppressWarnings("fallthrough")
240
-    public void connect(final String server, final int port, final String password,
241
-            final boolean ssl, final Identity profile) {
232
+    public void connect(final IrcAddress address, final Identity profile) {
242 233
         assert profile != null;
243 234
 
244 235
         synchronized (myState) {
@@ -271,19 +262,19 @@ public class Server extends WritableFrameContainer implements Serializable {
271 262
                         + "is still connected.\n\nMy state:" + getState());
272 263
             }
273 264
 
274
-            if (!server.equals(getName())) {
275
-                setName(server);
265
+            // Update the name of this container (shown in treeview, etc)
266
+            if (!address.getServer().equals(getName())) {
267
+                setName(address.getServer());
276 268
             }
277 269
 
278
-            getConfigManager().migrate("", "", server);
279
-
280
-            serverInfo = buildServerInfo(server, port, password, ssl);
270
+            getConfigManager().migrate("", "", address.getServer());
281 271
 
272
+            this.address = address;
282 273
             this.profile = profile;
283 274
 
284 275
             updateIcon();
285 276
 
286
-            addLine("serverConnecting", server, port);
277
+            addLine("serverConnecting", address.getServer(), address.getPort());
287 278
 
288 279
             parser = buildParser();
289 280
 
@@ -319,8 +310,7 @@ public class Server extends WritableFrameContainer implements Serializable {
319 310
 
320 311
             disconnect(reason);
321 312
             
322
-            connect(serverInfo.getHost(), serverInfo.getPort(),
323
-                    serverInfo.getPassword(), serverInfo.getSSL(), profile);
313
+            connect(address, profile);
324 314
         }
325 315
     }
326 316
 
@@ -712,11 +702,11 @@ public class Server extends WritableFrameContainer implements Serializable {
712 702
      * @return A configured IRC parser.
713 703
      */
714 704
     private Parser buildParser() {
715
-        final CertificateManager certManager = new CertificateManager(serverInfo.getHost(),
705
+        final CertificateManager certManager = new CertificateManager(address.getServer(),
716 706
                 getConfigManager());
717 707
 
718 708
         final MyInfo myInfo = buildMyInfo();
719
-        final Parser myParser = parserFactory.getParser(myInfo, serverInfo);
709
+        final Parser myParser = new ParserFactory().getParser(myInfo, address);
720 710
 
721 711
         if (myParser instanceof SecureParser) {
722 712
             final SecureParser secureParser = (SecureParser) myParser;
@@ -766,7 +756,7 @@ public class Server extends WritableFrameContainer implements Serializable {
766 756
      */
767 757
     private void updateIcon() {
768 758
         final String icon = myState.getState() == ServerState.CONNECTED
769
-                    ? serverInfo.getSSL() ? "secure-server" : "server"
759
+                    ? address.isSSL() ? "secure-server" : "server"
770 760
                     : "server-disconnected";
771 761
         setIcon(icon);
772 762
     }
@@ -804,7 +794,7 @@ public class Server extends WritableFrameContainer implements Serializable {
804 794
                     parser.joinChannel(channel);
805 795
                 }
806 796
             } else {
807
-                autochannels.add(channel);
797
+                address.getChannels().add(channel);
808 798
             }
809 799
         }
810 800
     }
@@ -1354,7 +1344,7 @@ public class Server extends WritableFrameContainer implements Serializable {
1354 1344
                 }
1355 1345
             }
1356 1346
 
1357
-            for (String channel : autochannels) {
1347
+            for (String channel : address.getChannels()) {
1358 1348
                 parser.joinChannel(channel);
1359 1349
             }
1360 1350
 

+ 10
- 12
src/com/dmdirc/addons/ui_swing/dialogs/NewServerDialog.java Parādīt failu

@@ -273,33 +273,31 @@ public final class NewServerDialog extends StandardDialog implements ActionListe
273 273
 
274 274
         final Identity profile =
275 275
                 (Identity) identityField.getSelectedItem();
276
+        final IrcAddress address = new IrcAddress(host, port, pass, sslCheck.isSelected());
276 277
 
277 278
         // Open in a new window?
278
-        if (newServerWindowCheck.isSelected() || ServerManager.getServerManager().
279
-                numServers() == 0 || mainFrame.getActiveFrame() == null) {
280
-            new LoggingSwingWorker() {
279
+        if (newServerWindowCheck.isSelected() || ServerManager.getServerManager()
280
+                .numServers() == 0 || mainFrame.getActiveFrame() == null) {
281 281
 
282
+            new LoggingSwingWorker() {
282 283
                 @Override
283 284
                 protected Object doInBackground() throws Exception {
284
-                    new Server(new IrcAddress(host, port, pass, sslCheck.isSelected()), profile);
285
+                    new Server(address, profile);
285 286
                     return null;
286 287
                 }
287 288
             }.execute();
288 289
         } else {
289
-            final com.dmdirc.ui.interfaces.Window active =
290
-                    mainFrame.getActiveFrame();
291
-            final Server server = ServerManager.getServerManager().
292
-                    getServerFromFrame(active);
290
+            final com.dmdirc.ui.interfaces.Window active = mainFrame.getActiveFrame();
291
+            final Server server = ServerManager.getServerManager().getServerFromFrame(active);
292
+
293 293
             new LoggingSwingWorker() {
294 294
 
295 295
                 @Override
296 296
                 protected Object doInBackground() throws Exception {
297 297
                     if (server == null) {
298
-                        new Server(new IrcAddress(host, port, pass, sslCheck.isSelected()),
299
-                            profile);
298
+                        new Server(address, profile);
300 299
                     } else {
301
-                        server.connect(host, port, pass, sslCheck.isSelected(),
302
-                            profile);
300
+                        server.connect(address, profile);
303 301
                     }
304 302
                     return null;
305 303
                 }

+ 2
- 1
src/com/dmdirc/commandparser/commands/server/ChangeServer.java Parādīt failu

@@ -29,6 +29,7 @@ import com.dmdirc.commandparser.commands.ServerCommand;
29 29
 import com.dmdirc.logger.ErrorLevel;
30 30
 import com.dmdirc.logger.Logger;
31 31
 import com.dmdirc.ui.interfaces.InputWindow;
32
+import com.dmdirc.util.IrcAddress;
32 33
 
33 34
 /**
34 35
  * The /server command allows the user to connect to a new server.
@@ -101,7 +102,7 @@ public final class ChangeServer extends ServerCommand {
101 102
             pass = args.getArgumentsAsString(offset);
102 103
         }
103 104
 
104
-        server.connect(host, port, pass, ssl, server.getProfile());
105
+        server.connect(new IrcAddress(host, port, pass, ssl), server.getProfile());
105 106
     }
106 107
     
107 108
     /** {@inheritDoc} */

Notiek ielāde…
Atcelt
Saglabāt