You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Connection.java 10KB

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