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 11KB

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