Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Connection.java 12KB

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