您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Connection.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. * Retrieves the status object for this server. Effecting state transitions on the object
  182. * returned by this method will almost certainly cause problems.
  183. *
  184. * @since 0.6.3m1
  185. * @return This server's status object.
  186. */
  187. ServerStatus getStatus();
  188. /**
  189. * Determines whether the server knows of the specified query.
  190. *
  191. * @param host The host of the query to look for
  192. *
  193. * @return True iff the query is known, false otherwise
  194. */
  195. boolean hasQuery(final String host);
  196. /**
  197. * Returns a {@link User} object representing the local client.
  198. *
  199. * @return Local user, or empty if there is no local client
  200. */
  201. Optional<User> getLocalUser();
  202. /**
  203. * Returns a {@link User} object representing the specified details.
  204. *
  205. * @return Retrieved user, or empty if there was no match
  206. */
  207. User getUser(final String details);
  208. /**
  209. * Returns the current away status.
  210. *
  211. * @return True if the client is marked as away, false otherwise
  212. */
  213. boolean isAway();
  214. /**
  215. * Determines whether this server is currently connected to the specified network.
  216. *
  217. * @param target The network to check for
  218. *
  219. * @return True if this server is connected to the network, false otherwise
  220. *
  221. * @since 0.6.3m1rc3
  222. */
  223. boolean isNetwork(final String target);
  224. /**
  225. * Reconnects to the server with a specified reason.
  226. *
  227. * @param reason The quit reason to send
  228. */
  229. void reconnect(final String reason);
  230. /**
  231. * Reconnects to the server.
  232. */
  233. void reconnect();
  234. /**
  235. * Saves the contents of our ignore list to the network identity.
  236. */
  237. void saveIgnoreList();
  238. /**
  239. * Replies to an incoming CTCP message.
  240. *
  241. * @param source The source of the message
  242. * @param type The CTCP type
  243. * @param args The CTCP arguments
  244. */
  245. void sendCTCPReply(final String source, final String type, final String args);
  246. /**
  247. * Updates our away state and fires the relevant listeners.
  248. *
  249. * @param message The away message to use, empty is not away.
  250. */
  251. void updateAwayState(final Optional<String> message);
  252. /**
  253. * Updates this server's ignore list to use the entries stored in the config manager.
  254. */
  255. void updateIgnoreList();
  256. /**
  257. * Updates the name and title of this window.
  258. */
  259. void updateTitle();
  260. /**
  261. * Sends a raw line to the underlying connection.
  262. *
  263. * @param line The line to be sent
  264. */
  265. void sendLine(String line);
  266. /**
  267. * Sends a message to the specified target.
  268. *
  269. * @param target target to send message to
  270. * @param message Message to send
  271. */
  272. void sendMessage(String target, String message);
  273. /**
  274. * Gets the core model for the input/output window for this connection.
  275. *
  276. * @return A model for windows based on this connection.
  277. */
  278. WindowModel getWindowModel();
  279. /**
  280. * Returns the available channel modes applicable to users.
  281. *
  282. * @return User modes in ascending order, or an empty string if they're not known
  283. */
  284. String getUserModes();
  285. /**
  286. * Returns the available boolean modes.
  287. *
  288. * @return Boolean modes or an empty string if they're not known
  289. */
  290. String getBooleanModes();
  291. /**
  292. * Returns the available list modes.
  293. *
  294. * @return List modes or an empty string if they're not known
  295. */
  296. String getListModes();
  297. /**
  298. * Returns the available parameter modes. Parameter modes need a parameter to set, but not to
  299. * unset.
  300. *
  301. * @return Parameter modes or an empty string if they're not known
  302. */
  303. String getParameterModes();
  304. /**
  305. * Returns the available double parameter modes. Double parameter modes need a parameter to
  306. * both set and unset.
  307. *
  308. * @return Double parameter modes or an empty string if they're not known
  309. */
  310. String getDoubleParameterModes();
  311. /**
  312. * Returns the maximum number list modes of a certain type that can be set.
  313. *
  314. * @param mode Mode to query
  315. *
  316. * @return Maximum modes that can be set, or -1 if they're not known
  317. */
  318. int getMaxListModes(final char mode);
  319. /**
  320. * Gets the manager that handles this connection's group chats.
  321. *
  322. * @return The group chat manager for this connection.
  323. */
  324. GroupChatManager getGroupChatManager();
  325. /**
  326. * Gets the manager that handles this connection's invites.
  327. *
  328. * @return The invite manager for this connection.
  329. */
  330. InviteManager getInviteManager();
  331. /**
  332. * Sets the local user's current nickname on this connection.
  333. *
  334. * @param nickname New nickname
  335. */
  336. void setNickname(final String nickname);
  337. /**
  338. * Returns the current nickname for this connection.
  339. *
  340. * @return Current nickname, or an empty if not present
  341. */
  342. Optional<String> getNickname();
  343. /**
  344. * Requests information about another user on the server.
  345. *
  346. * @param user User to request information about
  347. */
  348. void requestUserInfo(User user);
  349. }