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

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