|
@@ -31,6 +31,7 @@ import java.net.URISyntaxException;
|
31
|
31
|
* @see IRCParser
|
32
|
32
|
*/
|
33
|
33
|
public class ServerInfo {
|
|
34
|
+
|
34
|
35
|
/**
|
35
|
36
|
* A version number for this class. It should be changed whenever the class
|
36
|
37
|
* structure is changed (or anything else that would prevent serialized
|
|
@@ -38,14 +39,6 @@ public class ServerInfo {
|
38
|
39
|
*/
|
39
|
40
|
private static final long serialVersionUID = 1;
|
40
|
41
|
|
41
|
|
- /** Server to connect to (Default: "irc.quakenet.org"). */
|
42
|
|
- private String host = "irc.quakenet.org";
|
43
|
|
- /** Port server listens on for client connections (Default: 6667). */
|
44
|
|
- private int port = 6667;
|
45
|
|
- /** Optional password needed to connect to server (Default: ""). */
|
46
|
|
- private String password = "";
|
47
|
|
- /** Is this an ssl-enabled server (Default: false). */
|
48
|
|
- private boolean isSSL = false;
|
49
|
42
|
/** Are we using a socks proxy (Default: false). */
|
50
|
43
|
private boolean useSocksProxy = false;
|
51
|
44
|
/** Proxy server to connect to (Default: "127.0.0.1"). */
|
|
@@ -60,23 +53,25 @@ public class ServerInfo {
|
60
|
53
|
private URI uri = null;
|
61
|
54
|
|
62
|
55
|
/**
|
63
|
|
- * Constructor using default values.
|
64
|
|
- */
|
65
|
|
- public ServerInfo() {
|
66
|
|
- //Use default values
|
67
|
|
- }
|
68
|
|
-
|
69
|
|
- /**
|
70
|
|
- * Constructor using specifed host, port and password, SSL/Proxy must be specifed separately.
|
|
56
|
+ * Constructor using specifed host, port and password, SSL/Proxy must be
|
|
57
|
+ * specifed separately.
|
71
|
58
|
*
|
72
|
59
|
* @param serverHost Host to use
|
73
|
60
|
* @param serverPort Port to use
|
74
|
61
|
* @param serverPass Password to use
|
75
|
62
|
*/
|
76
|
|
- public ServerInfo(final String serverHost, final int serverPort, final String serverPass) {
|
77
|
|
- host = serverHost;
|
78
|
|
- port = serverPort;
|
79
|
|
- password = serverPass;
|
|
63
|
+ public ServerInfo(final String serverHost, final int serverPort,
|
|
64
|
+ final String serverPass) {
|
|
65
|
+ try {
|
|
66
|
+ uri = new URI("irc", serverPass, serverHost, serverPort, null,
|
|
67
|
+ null, null);
|
|
68
|
+ } catch (URISyntaxException ex) {
|
|
69
|
+ try {
|
|
70
|
+ uri = new URI("irc", null, "127.0.0.1", -1, null, null, null);
|
|
71
|
+ } catch (URISyntaxException ex1) {
|
|
72
|
+ //Won't happen
|
|
73
|
+ }
|
|
74
|
+ }
|
80
|
75
|
}
|
81
|
76
|
|
82
|
77
|
/**
|
|
@@ -87,7 +82,7 @@ public class ServerInfo {
|
87
|
82
|
* @since 0.6.3
|
88
|
83
|
*/
|
89
|
84
|
public ServerInfo(final URI uri) {
|
90
|
|
- setURI(uri);
|
|
85
|
+ this.uri = uri;
|
91
|
86
|
}
|
92
|
87
|
|
93
|
88
|
/**
|
|
@@ -99,117 +94,44 @@ public class ServerInfo {
|
99
|
94
|
* @return URI for this ServerInfo
|
100
|
95
|
*/
|
101
|
96
|
public URI getURI() {
|
102
|
|
- final StringBuilder uriString = new StringBuilder();
|
103
|
|
-
|
104
|
|
- uriString.append(isSSL ? "ircs://" : "irc://");
|
105
|
|
- if (!password.isEmpty()) {
|
106
|
|
- uriString.append(password);
|
107
|
|
- uriString.append("@");
|
108
|
|
- }
|
109
|
|
- uriString.append(host);
|
110
|
|
- uriString.append(":");
|
111
|
|
- uriString.append(port);
|
112
|
|
- if (uri != null) {
|
113
|
|
- if (!uri.getRawPath().isEmpty()) {
|
114
|
|
- uriString.append(uri.getRawPath());
|
115
|
|
- }
|
116
|
|
- if (uri.getRawQuery() != null) {
|
117
|
|
- uriString.append("?");
|
118
|
|
- uriString.append(uri.getRawQuery());
|
119
|
|
- }
|
120
|
|
- if (uri.getRawFragment() != null) {
|
121
|
|
- uriString.append("#");
|
122
|
|
- uriString.append(uri.getRawFragment());
|
123
|
|
- }
|
124
|
|
- }
|
125
|
|
- try {
|
126
|
|
- return new URI(uriString.toString());
|
127
|
|
- } catch (URISyntaxException ex) {
|
128
|
|
- // Creating the new URI shouldn't fail unless the user passed
|
129
|
|
- // stupid settings to setXXXX()
|
130
|
|
- // In this case, try to return any given URI, else a blank one.
|
131
|
|
- try {
|
132
|
|
- return (uri == null) ? new URI("") : uri;
|
133
|
|
- } catch (URISyntaxException ex2) {
|
134
|
|
- /* This can't ever happen. */
|
135
|
|
- return null;
|
136
|
|
- }
|
137
|
|
- }
|
138
|
|
- }
|
139
|
|
-
|
140
|
|
- /**
|
141
|
|
- * Set the URI for this ServerInfo.
|
142
|
|
- * This will overwrite host/port/password and isSSL.
|
143
|
|
- *
|
144
|
|
- * @param uri URI to use to configure this ServerInfo
|
145
|
|
- */
|
146
|
|
- public void setURI(final URI uri) {
|
147
|
|
- this.uri = uri;
|
148
|
|
- host = uri.getHost();
|
149
|
|
- port = uri.getPort() > 0 ? uri.getPort() : 6667;
|
150
|
|
-
|
151
|
|
- if ("ircs".equals(uri.getScheme())) {
|
152
|
|
- setSSL(true);
|
153
|
|
- }
|
154
|
|
-
|
155
|
|
- password = uri.getUserInfo() == null ? "" : uri.getUserInfo();
|
|
97
|
+ return uri;
|
156
|
98
|
}
|
157
|
99
|
|
158
|
|
- /**
|
159
|
|
- * Set the hostname.
|
160
|
|
- *
|
161
|
|
- * @param newValue Value to set to.
|
162
|
|
- */
|
163
|
|
- public void setHost(final String newValue) { host = newValue; }
|
164
|
|
-
|
165
|
100
|
/**
|
166
|
101
|
* Get the hostname.
|
167
|
102
|
*
|
168
|
103
|
* @return Current hostname
|
169
|
104
|
*/
|
170
|
|
- public String getHost() { return host; }
|
171
|
|
-
|
172
|
|
- /**
|
173
|
|
- * Set the port.
|
174
|
|
- *
|
175
|
|
- * @param newValue Value to set to.
|
176
|
|
- */
|
177
|
|
- public void setPort(final int newValue) { port = newValue; }
|
|
105
|
+ public String getHost() {
|
|
106
|
+ return uri.getHost() == null ? "" : uri.getHost();
|
|
107
|
+ }
|
178
|
108
|
|
179
|
109
|
/**
|
180
|
110
|
* Get the port.
|
181
|
111
|
*
|
182
|
112
|
* @return Current port
|
183
|
113
|
*/
|
184
|
|
- public int getPort() { return port; }
|
185
|
|
-
|
186
|
|
- /**
|
187
|
|
- * Set the password.
|
188
|
|
- *
|
189
|
|
- * @param newValue Value to set to.
|
190
|
|
- */
|
191
|
|
- public void setPassword(final String newValue) { password = newValue; }
|
|
114
|
+ public int getPort() {
|
|
115
|
+ return uri.getPort() == -1 ? 6667 : uri.getPort();
|
|
116
|
+ }
|
192
|
117
|
|
193
|
118
|
/**
|
194
|
119
|
* Get the password.
|
195
|
120
|
*
|
196
|
121
|
* @return Current Password
|
197
|
122
|
*/
|
198
|
|
- public String getPassword() { return password; }
|
199
|
|
-
|
200
|
|
- /**
|
201
|
|
- * Set if the server uses ssl.
|
202
|
|
- *
|
203
|
|
- * @param newValue true if server uses ssl, else false
|
204
|
|
- */
|
205
|
|
- public void setSSL(final boolean newValue) { isSSL = newValue; }
|
|
123
|
+ public String getPassword() {
|
|
124
|
+ return uri.getUserInfo() == null ? "" : uri.getUserInfo();
|
|
125
|
+ }
|
206
|
126
|
|
207
|
127
|
/**
|
208
|
128
|
* Get if the server uses ssl.
|
209
|
129
|
*
|
210
|
130
|
* @return true if server uses ssl, else false
|
211
|
131
|
*/
|
212
|
|
- public boolean getSSL() { return isSSL; }
|
|
132
|
+ public boolean isSSL() {
|
|
133
|
+ return "ircs".equals(uri.getScheme());
|
|
134
|
+ }
|
213
|
135
|
|
214
|
136
|
/**
|
215
|
137
|
* Set if we are connecting via a socks proxy.
|