Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. /*
  2. * Copyright (c) 2006-2014 DMDirc Developers
  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. package com.dmdirc.interfaces;
  23. import com.dmdirc.Channel;
  24. import com.dmdirc.FrameContainer;
  25. import com.dmdirc.Invite;
  26. import com.dmdirc.Query;
  27. import com.dmdirc.ServerState;
  28. import com.dmdirc.ServerStatus;
  29. import com.dmdirc.config.profiles.Profile;
  30. import com.dmdirc.interfaces.config.ConfigProvider;
  31. import com.dmdirc.parser.common.ChannelJoinRequest;
  32. import com.dmdirc.parser.common.IgnoreList;
  33. import com.dmdirc.parser.interfaces.Parser;
  34. import java.net.URI;
  35. import java.util.Collection;
  36. import java.util.Date;
  37. import java.util.List;
  38. import java.util.Optional;
  39. import javax.annotation.Nonnull;
  40. /**
  41. * Represents an abstract connection to a remote chat system.
  42. */
  43. public interface Connection {
  44. /**
  45. * Attempts to accept the specified invites, and join the corresponding channels.
  46. *
  47. * @param invites The invites to process
  48. *
  49. * @since 0.6.4
  50. */
  51. void acceptInvites(final Invite... invites);
  52. /**
  53. * Attempts to accept all active invites for this server, and join the corresponding channels.
  54. *
  55. * @since 0.6.4
  56. */
  57. void acceptInvites();
  58. /**
  59. * Adds an invite to this server, and fires the appropriate listeners.
  60. *
  61. * @param invite The invite to be added
  62. */
  63. void addInvite(final Invite invite);
  64. /**
  65. * Passes the arguments to all frames for this server.
  66. *
  67. * @param messageType The type of message to send
  68. * @param date The date at which the event occurred
  69. * @param args The arguments of the message
  70. */
  71. void addLineToAll(final String messageType, final Date date, final Object... args);
  72. /**
  73. * Compare the given URI to the URI we are currently using to see if they would both result in
  74. * the server connecting to the same place, even if the URIs do not match exactly.
  75. *
  76. * @param uri URI to compare with the Servers own URI.
  77. *
  78. * @return True if the Given URI is the "same" as the one we are using.
  79. *
  80. * @since 0.6.3
  81. */
  82. boolean compareURI(final URI uri);
  83. /**
  84. * Connects to a new server with the previously supplied address and profile.
  85. *
  86. * @since 0.6.3m2
  87. */
  88. void connect();
  89. /**
  90. * Connects to a new server with the specified details.
  91. *
  92. * @param address The address of the server to connect to
  93. * @param profile The profile to use
  94. *
  95. * @since 0.6.3
  96. */
  97. void connect(final URI address, final Profile profile);
  98. /**
  99. * Removes a specific channel and window from this server.
  100. *
  101. * @param chan channel to remove
  102. */
  103. void delChannel(final String chan);
  104. /**
  105. * Deletes a query from this server.
  106. *
  107. * @param query The query that should be removed.
  108. */
  109. void delQuery(final Query query);
  110. /**
  111. * Disconnects from the server with the default quit message.
  112. */
  113. void disconnect();
  114. /**
  115. * Disconnects from the server.
  116. *
  117. * @param reason disconnect reason
  118. */
  119. void disconnect(final String reason);
  120. /**
  121. * Retrieves the address of this server.
  122. *
  123. * @return This sever's address
  124. */
  125. String getAddress();
  126. /**
  127. * Gets the current away message.
  128. *
  129. * @return Null if the client isn't away, or a textual away message if it is
  130. */
  131. String getAwayMessage();
  132. /**
  133. * Retrieves the specified channel belonging to this server.
  134. *
  135. * @param channel The channel to be retrieved
  136. *
  137. * @return The appropriate channel object
  138. */
  139. Optional<GroupChat> getChannel(final String channel);
  140. /**
  141. * Retrieves the possible channel prefixes in use on this server.
  142. *
  143. * @return This server's possible channel prefixes
  144. */
  145. String getChannelPrefixes();
  146. /**
  147. * Gets a collection of all channels on this connection.
  148. *
  149. * @return collection of channels belonging to this connection
  150. */
  151. Collection<Channel> getChannels();
  152. /**
  153. * Retrieves this server's ignore list.
  154. *
  155. * @return This server's ignore list
  156. */
  157. IgnoreList getIgnoreList();
  158. /**
  159. * Returns the list of invites for this server.
  160. *
  161. * @return Invite list
  162. */
  163. List<Invite> getInvites();
  164. /**
  165. * Retrieves the name of this server's IRCd.
  166. *
  167. * @return The name of this server's IRCd
  168. */
  169. String getIrcd();
  170. /**
  171. * Retrieves the name of this server's network. The network name is determined using the
  172. * following rules:
  173. *
  174. * 1. If the server includes its network name in the 005 information, we use that 2. If the
  175. * server's name ends in biz, com, info, net or org, we use the second level domain (e.g.,
  176. * foo.com) 3. If the server's name contains more than two dots, we drop everything up to and
  177. * including the first part, and use the remainder 4. In all other cases, we use the full server
  178. * name
  179. *
  180. * @return The name of this server's network
  181. */
  182. String getNetwork();
  183. /**
  184. * Retrieves the identity for this server's network.
  185. *
  186. * @return This server's network identity
  187. */
  188. ConfigProvider getNetworkIdentity();
  189. /**
  190. * Retrieves the parser used for this connection.
  191. *
  192. * @return this connection's parser
  193. */
  194. @Nonnull
  195. Optional<Parser> getParser();
  196. /**
  197. * Retrieves the profile that's in use for this server.
  198. *
  199. * @return The profile in use by this server
  200. */
  201. Profile getProfile();
  202. /**
  203. * Retrieves the protocol used by this server.
  204. *
  205. * @return This server's protocol
  206. *
  207. * @since 0.6.3
  208. */
  209. String getProtocol();
  210. /**
  211. * Retrieves a list of queries belonging to this server.
  212. *
  213. * @return list of queries belonging to this server
  214. */
  215. Collection<Query> getQueries();
  216. /**
  217. * Retrieves the specified query belonging to this server. If the query does not yet exist, it
  218. * is created automatically.
  219. *
  220. * @param host The host of the query to look for
  221. *
  222. * @return The appropriate query object
  223. */
  224. Query getQuery(final String host);
  225. /**
  226. * Retrieves the specified query belonging to this server. If the query does not yet exist, it
  227. * is created automatically.
  228. *
  229. * @param host The host of the query to look for
  230. * @param focus Should we focus the window on open?
  231. *
  232. * @return The appropriate query object
  233. */
  234. Query getQuery(final String host, final boolean focus);
  235. /**
  236. * Retrieves the identity for this server.
  237. *
  238. * @return This server's identity
  239. */
  240. ConfigProvider getServerIdentity();
  241. /**
  242. * Retrieves the current state for this server.
  243. *
  244. * @return This server's state
  245. */
  246. ServerState getState();
  247. /**
  248. * Retrieves the status object for this server. Effecting state transitions on the object
  249. * returned by this method will almost certainly cause problems.
  250. *
  251. * @since 0.6.3m1
  252. * @return This server's status object.
  253. */
  254. ServerStatus getStatus();
  255. /**
  256. * Determines whether the server knows of the specified query.
  257. *
  258. * @param host The host of the query to look for
  259. *
  260. * @return True iff the query is known, false otherwise
  261. */
  262. boolean hasQuery(final String host);
  263. /**
  264. * Returns a {@link User} object representing the local client.
  265. *
  266. * @return Local user, or empty if there is no local client
  267. */
  268. User getLocalUser();
  269. /**
  270. * Returns a {@link User} object representing the specified details.
  271. *
  272. * @return Retrieved user, or empty if there was no match
  273. */
  274. User getUser(final String details);
  275. /**
  276. * Returns the current away status.
  277. *
  278. * @return True if the client is marked as away, false otherwise
  279. */
  280. boolean isAway();
  281. /**
  282. * Determines whether this server is currently connected to the specified network.
  283. *
  284. * @param target The network to check for
  285. *
  286. * @return True if this server is connected to the network, false otherwise
  287. *
  288. * @since 0.6.3m1rc3
  289. */
  290. boolean isNetwork(final String target);
  291. /**
  292. * Determines if the specified channel name is valid. A channel name is valid if we already have
  293. * an existing Channel with the same name, or we have a valid parser instance and the parser
  294. * says it's valid.
  295. *
  296. * @param channelName The name of the channel to test
  297. *
  298. * @return True if the channel name is valid, false otherwise
  299. */
  300. boolean isValidChannelName(final String channelName);
  301. /**
  302. * Attempts to join the specified channels. If channels with the same name already exist, they
  303. * are (re)joined and their windows activated.
  304. *
  305. * @param requests The channel join requests to process
  306. *
  307. * @since 0.6.4
  308. */
  309. void join(final ChannelJoinRequest... requests);
  310. /**
  311. * Attempts to join the specified channels. If channels with the same name already exist, they
  312. * are (re)joined.
  313. *
  314. * @param focus Whether or not to focus any new channels
  315. * @param requests The channel join requests to process
  316. *
  317. * @since 0.6.4
  318. */
  319. void join(final boolean focus, final ChannelJoinRequest... requests);
  320. /**
  321. * Reconnects to the server with a specified reason.
  322. *
  323. * @param reason The quit reason to send
  324. */
  325. void reconnect(final String reason);
  326. /**
  327. * Reconnects to the server.
  328. */
  329. void reconnect();
  330. /**
  331. * Removes an invite from this server, and fires the appropriate listeners.
  332. *
  333. * @param invite The invite to be removed
  334. */
  335. void removeInvite(final Invite invite);
  336. /**
  337. * Removes all invites for the specified channel.
  338. *
  339. * @param channel The channel to remove invites for
  340. */
  341. void removeInvites(final String channel);
  342. /**
  343. * Removes all invites for all channels.
  344. */
  345. void removeInvites();
  346. /**
  347. * Saves the contents of our ignore list to the network identity.
  348. */
  349. void saveIgnoreList();
  350. /**
  351. * Replies to an incoming CTCP message.
  352. *
  353. * @param source The source of the message
  354. * @param type The CTCP type
  355. * @param args The CTCP arguments
  356. */
  357. void sendCTCPReply(final String source, final String type, final String args);
  358. /**
  359. * Updates our away state and fires the relevant listeners.
  360. *
  361. * @param message The away message to use, empty is not away.
  362. */
  363. void updateAwayState(final Optional<String> message);
  364. /**
  365. * Updates this server's ignore list to use the entries stored in the config manager.
  366. */
  367. void updateIgnoreList();
  368. /**
  369. * Updates the state of this server following a nick change of someone that the user has a query
  370. * open with. Namely, this updates the tabcompleter with the new name, and ensures that the
  371. * <code>queries</code> map uses the correct nickname.
  372. *
  373. * @param query The query object being updated
  374. * @param oldNick The old nickname of the user
  375. * @param newNick The new nickname of the user
  376. *
  377. * @since 0.6.4
  378. */
  379. void updateQuery(final Query query, final String oldNick, final String newNick);
  380. /**
  381. * Updates the name and title of this window.
  382. */
  383. void updateTitle();
  384. /**
  385. * Sends a raw line to the underlying connection.
  386. *
  387. * @param line The line to be sent
  388. */
  389. void sendLine(String line);
  390. /**
  391. * Gets the core model for the input/output window for this connection.
  392. *
  393. * @return A model for windows based on this connection.
  394. */
  395. FrameContainer getWindowModel();
  396. }