/
Connection.java
416 lines (362 loc) · 11.4 KB
/
Connection.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/*
* Copyright (c) 2006-2015 DMDirc Developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.dmdirc.interfaces;
import com.dmdirc.Query;
import com.dmdirc.ServerState;
import com.dmdirc.ServerStatus;
import com.dmdirc.config.profiles.Profile;
import com.dmdirc.interfaces.config.ConfigProvider;
import com.dmdirc.parser.common.IgnoreList;
import com.dmdirc.parser.interfaces.Parser;
import java.net.URI;
import java.util.Collection;
import java.util.Optional;
import javax.annotation.Nonnull;
/**
* Represents an abstract connection to a remote chat system.
*/
public interface Connection {
/**
* Compare the given URI to the URI we are currently using to see if they would both result in
* the server connecting to the same place, even if the URIs do not match exactly.
*
* @param uri URI to compare with the Servers own URI.
*
* @return True if the Given URI is the "same" as the one we are using.
*
* @since 0.6.3
*/
boolean compareURI(final URI uri);
/**
* Connects to a new server with the previously supplied address and profile.
*
* @since 0.6.3m2
*/
void connect();
/**
* Connects to a new server with the specified details.
*
* @param address The address of the server to connect to
* @param profile The profile to use
*
* @since 0.6.3
*/
void connect(final URI address, final Profile profile);
/**
* Deletes a query from this server.
*
* @param query The query that should be removed.
*/
void delQuery(final Query query);
/**
* Disconnects from the server with the default quit message.
*/
void disconnect();
/**
* Disconnects from the server.
*
* @param reason disconnect reason
*/
void disconnect(final String reason);
/**
* Retrieves the address of this server.
*
* @return This sever's address
*/
String getAddress();
/**
* Gets the current away message.
*
* @return Null if the client isn't away, or a textual away message if it is
*/
String getAwayMessage();
/**
* Retrieves this server's ignore list.
*
* @return This server's ignore list
*/
IgnoreList getIgnoreList();
/**
* Retrieves the name of this server's IRCd.
*
* @return The name of this server's IRCd
*/
String getIrcd();
/**
* Retrieves the name of this server's network. The network name is determined using the
* following rules:
*
* 1. If the server includes its network name in the 005 information, we use that 2. If the
* server's name ends in biz, com, info, net or org, we use the second level domain (e.g.,
* foo.com) 3. If the server's name contains more than two dots, we drop everything up to and
* including the first part, and use the remainder 4. In all other cases, we use the full server
* name
*
* @return The name of this server's network
*/
String getNetwork();
/**
* Retrieves the identity for this server's network.
*
* @return This server's network identity
*/
ConfigProvider getNetworkIdentity();
/**
* Retrieves the parser used for this connection.
*
* @return this connection's parser
*/
@Nonnull
Optional<Parser> getParser();
/**
* Retrieves the profile that's in use for this server.
*
* @return The profile in use by this server
*/
Profile getProfile();
/**
* Retrieves the protocol used by this server.
*
* @return This server's protocol
*
* @since 0.6.3
*/
String getProtocol();
/**
* Retrieves a list of queries belonging to this server.
*
* @return list of queries belonging to this server
*/
Collection<Query> getQueries();
/**
* Retrieves the specified query belonging to this server. If the query does not yet exist, it
* is created automatically.
*
* @param host The host of the query to look for
*
* @return The appropriate query object
*/
Query getQuery(final String host);
/**
* Retrieves the specified query belonging to this server. If the query does not yet exist, it
* is created automatically.
*
* @param host The host of the query to look for
* @param focus Should we focus the window on open?
*
* @return The appropriate query object
*/
Query getQuery(final String host, final boolean focus);
/**
* Retrieves the identity for this server.
*
* @return This server's identity
*/
ConfigProvider getServerIdentity();
/**
* Retrieves the current state for this server.
*
* @return This server's state
*/
ServerState getState();
/**
* Retrieves the status object for this server. Effecting state transitions on the object
* returned by this method will almost certainly cause problems.
*
* @since 0.6.3m1
* @return This server's status object.
*/
ServerStatus getStatus();
/**
* Determines whether the server knows of the specified query.
*
* @param host The host of the query to look for
*
* @return True iff the query is known, false otherwise
*/
boolean hasQuery(final String host);
/**
* Returns a {@link User} object representing the local client.
*
* @return Local user, or empty if there is no local client
*/
Optional<User> getLocalUser();
/**
* Returns a {@link User} object representing the specified details.
*
* @return Retrieved user, or empty if there was no match
*/
User getUser(final String details);
/**
* Returns the current away status.
*
* @return True if the client is marked as away, false otherwise
*/
boolean isAway();
/**
* Determines whether this server is currently connected to the specified network.
*
* @param target The network to check for
*
* @return True if this server is connected to the network, false otherwise
*
* @since 0.6.3m1rc3
*/
boolean isNetwork(final String target);
/**
* Reconnects to the server with a specified reason.
*
* @param reason The quit reason to send
*/
void reconnect(final String reason);
/**
* Reconnects to the server.
*/
void reconnect();
/**
* Saves the contents of our ignore list to the network identity.
*/
void saveIgnoreList();
/**
* Replies to an incoming CTCP message.
*
* @param source The source of the message
* @param type The CTCP type
* @param args The CTCP arguments
*/
void sendCTCPReply(final String source, final String type, final String args);
/**
* Updates our away state and fires the relevant listeners.
*
* @param message The away message to use, empty is not away.
*/
void updateAwayState(final Optional<String> message);
/**
* Updates this server's ignore list to use the entries stored in the config manager.
*/
void updateIgnoreList();
/**
* Updates the state of this server following a nick change of someone that the user has a query
* open with. Namely, this updates the tabcompleter with the new name, and ensures that the
* <code>queries</code> map uses the correct nickname.
*
* @param query The query object being updated
* @param oldNick The old nickname of the user
* @param newNick The new nickname of the user
*
* @since 0.6.4
*/
void updateQuery(final Query query, final String oldNick, final String newNick);
/**
* Updates the name and title of this window.
*/
void updateTitle();
/**
* Sends a raw line to the underlying connection.
*
* @param line The line to be sent
*/
void sendLine(String line);
/**
* Sends a message to the specified target.
*
* @param target target to send message to
* @param message Message to send
*/
void sendMessage(String target, String message);
/**
* Gets the core model for the input/output window for this connection.
*
* @return A model for windows based on this connection.
*/
WindowModel getWindowModel();
/**
* Returns the available channel modes applicable to users.
*
* @return User modes in ascending order, or an empty string if they're not known
*/
String getUserModes();
/**
* Returns the available boolean modes.
*
* @return Boolean modes or an empty string if they're not known
*/
String getBooleanModes();
/**
* Returns the available list modes.
*
* @return List modes or an empty string if they're not known
*/
String getListModes();
/**
* Returns the available parameter modes. Parameter modes need a parameter to set, but not to
* unset.
*
* @return Parameter modes or an empty string if they're not known
*/
String getParameterModes();
/**
* Returns the available double parameter modes. Double parameter modes need a parameter to
* both set and unset.
*
* @return Double parameter modes or an empty string if they're not known
*/
String getDoubleParameterModes();
/**
* Returns the maximum number list modes of a certain type that can be set.
*
* @param mode Mode to query
*
* @return Maximum modes that can be set, or -1 if they're not known
*/
int getMaxListModes(final char mode);
/**
* Gets the manager that handles this connection's group chats.
*
* @return The group chat manager for this connection.
*/
GroupChatManager getGroupChatManager();
/**
* Gets the manager that handles this connection's invites.
*
* @return The invite manager for this connection.
*/
InviteManager getInviteManager();
/**
* Sets the local user's current nickname on this connection.
*
* @param nickname New nickname
*/
void setNickname(final String nickname);
/**
* Returns the current nickname for this connection.
*
* @return Current nickname, or an empty if not present
*/
Optional<String> getNickname();
/**
* Requests information about another user on the server.
*
* @param user User to request information about
*/
void requestUserInfo(User user);
}