IRC client framework (wrapper around libircclient library).
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

IRCClientSession.h 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. //
  2. // IRCClientSession.h
  3. // IRCClient
  4. /*! \mainpage IRCClient - a Cocoa IRC Framework to create IRC clients
  5. *
  6. * \section intro_sec Introduction
  7. *
  8. * IRCClient is a Cocoa Framework that uses the excellent libircclient library
  9. * written by Georgy Yunaev.
  10. *
  11. * \section usage Basic Usage
  12. *
  13. * To use this framework, you will need to write an IRCClientSessionDelegate to
  14. * handle all of the events generated by the server, and an IRCClientChannelDelegate
  15. * to handle all of the events generated by channels on that server.
  16. *
  17. * You then create an IRCClientSession object in your code, assign the required
  18. * properties, and call connect: to connect to the server and run: to create
  19. * the new thread and start receiving events. For example:
  20. *
  21. * \code
  22. * IRCClientSession *session = [[IRCClientSession alloc] init];
  23. * MyIRCClientSessionDelegate *controller = [[MyIRCClientSessionDelegate alloc] init];
  24. *
  25. * [session setDelegate:controller];
  26. * [controller setSession:session];
  27. *
  28. * [session setServer:@"irc.dal.net"];
  29. * [session setPort:@"6667"];
  30. * [session setNickname:@"test"];
  31. * [session setUsername:@"test"];
  32. * [session setRealname:@"test"];
  33. * [session connect];
  34. *
  35. * [session run]; //starts the thread
  36. * \endcode
  37. *
  38. * \section author Author, copyright, support.
  39. *
  40. * If you have any questions, bug reports, suggestions regarding libircclient
  41. * or the IRCClient framework, please visit http://libircclient.sourceforge.net
  42. *
  43. * <PRE>
  44. * libircclient Copyright (C) 2004-2009 Georgy Yunaev gyunaev@ulduzsoft.com
  45. * Original IRCClient Copyright (C) 2009 Nathan Ollerenshaw chrome@stupendous.net
  46. * Modified IRCClient Copyright 2015 Said Achmiz (www.saidachmiz.net)
  47. *
  48. * This library is free software; you can redistribute it and/or modify it
  49. * under the terms of the GNU Lesser General Public License as published by
  50. * the Free Software Foundation; either version 2 of the License, or (at your
  51. * option) any later version.
  52. *
  53. * This library is distributed in the hope that it will be useful, but WITHOUT
  54. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  55. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  56. * License for more details.
  57. * </PRE>
  58. */
  59. #import <Cocoa/Cocoa.h>
  60. #import "IRCClientSessionDelegate.h"
  61. /** @class IRCClientSession
  62. * @brief Represents a connected IRC Session.
  63. *
  64. * IRCClientSession represents a single connection to an IRC server. On initialising
  65. * the object, and setting the delegate, server, port, password, nickname, username and realname
  66. * properties, you call the connect: and run: methods to connect to the IRC server
  67. * and start a new thread.
  68. *
  69. * This thread then sends messages back to the main runloop to the IRC server delegate,
  70. * or to the IRCClientChannel delegate as required.
  71. */
  72. @class IRCClientChannel;
  73. /**********************************************/
  74. #pragma mark IRCClientSession class declaration
  75. /**********************************************/
  76. @interface IRCClientSession : NSObject
  77. /************************/
  78. #pragma mark - Properties
  79. /************************/
  80. /** delegate to send events to. */
  81. @property (assign) id <IRCClientSessionDelegate> delegate;
  82. /** User-defined session ID (for one delegate to keep track of multiple sessions,
  83. if desired).
  84. */
  85. @property (assign) NSUInteger sessionID;
  86. /** The version string for the client to send back on CTCP VERSION requests */
  87. @property (copy) NSString *version;
  88. /** IRC server to connect to */
  89. @property (copy) NSString *server;
  90. /** IRC port to connect to */
  91. @property (assign) NSUInteger port;
  92. /** Server password to provide on connect (may be left empty or nil) */
  93. @property (copy) NSData *password;
  94. /** Nickname of the connected client. Note that setting this after connection will
  95. not result in the client renaming on IRC. You need to send a nick: message instead.
  96. */
  97. @property (copy) NSString *nickname;
  98. /** Username of the connected client. Also known as the ident.
  99. Setting this after connection does nothing.
  100. */
  101. @property (copy) NSString *username;
  102. /** Realname of the connected client.
  103. Setting this after connection does nothing.
  104. */
  105. @property (copy) NSString *realname;
  106. /** The default text encoding for messages on this server.
  107. This concerns messages received via PRIVMSG and NOTICE, and TOPIC in a channel.
  108. It also affects what encoding reasons given for QUIT messages are assumed to be in.
  109. You may change this at any time.
  110. */
  111. @property (assign) NSStringEncoding encoding;
  112. /** An NSDictionary of channels that the client is currently connected to. */
  113. @property (readonly) NSDictionary *channels;
  114. /** returns YES if the server is currently connected successfully, and NO if
  115. it is not. */
  116. @property (readonly, getter=isConnected) bool connected;
  117. /***************************/
  118. #pragma mark - Class methods
  119. /***************************/
  120. /** Connect to the IRC server.
  121. Note that this performs the initial DNS lookup and the TCP connection, so if
  122. there are any problems you will be notified via the return code of the message.
  123. Look at the libircclient documentation for the different return codes.
  124. */
  125. - (int)connect;
  126. /** Disconnect from the IRC server.
  127. This always works, as it simply shuts down the socket. If you want to disconnect
  128. in a friendly way, you should use the quit: message.
  129. */
  130. - (void)disconnect;
  131. /** Starts a new thread and starts the libircclient runloop, processing events and
  132. firing messages back to the main runloop as required. Calling this again will
  133. do nothing other than raise a warning in your logs.
  134. */
  135. - (void)run;
  136. /**************************/
  137. #pragma mark - IRC commands
  138. /**************************/
  139. /** Sends a raw message to the IRC server. Please consult rfc1459 for the format
  140. of IRC commands. */
  141. - (int)sendRaw:(NSData *)message;
  142. /** quits the IRC server with the given reason.
  143. On success, a userQuit:withReason: event will be sent to the
  144. IRCClientSessionDelegate with the nickname of the IRC client and the reason
  145. provided by the user (or nil if no reason was provided).
  146. */
  147. - (int)quit:(NSData *)reason;
  148. /** Joins a channel with a given name and key
  149. On success, a userJoined:channel: event will be sent to the
  150. IRCClientSessionDelegate with the nickname of the IRC client and the name of
  151. the channel that was joined.
  152. @param channel the channel to join
  153. @param key they key for the channel (may be nil)
  154. */
  155. - (int)join:(NSData *)channel key:(NSData *)key;
  156. /** lists channels on the IRC server.
  157. @param channel a channel name or string to pass to the LIST command. Implementation specific.
  158. */
  159. - (int)list:(NSData *)channel;
  160. /** sets the user mode for the IRC client
  161. @param mode string to set
  162. */
  163. - (int)userMode:(NSString *)mode;
  164. /** sets the IRC client nickname.
  165. On success, a nickChangedFrom:to: event will be sent to the
  166. IRCClientSessionDelegate with our old nick and the new nick that we now
  167. have.
  168. @param newnick new nickname to set.
  169. */
  170. - (int)nick:(NSString *)newnick;
  171. /** sends a WHOIS request to the IRC server
  172. @param nick nickname of the irc client to whois.
  173. */
  174. - (int)whois:(NSString *)nick;
  175. /** send a PRIVMSG to another IRC client
  176. @param message message to send
  177. @param target the other IRC client to send the message to.
  178. */
  179. - (int)message:(NSData *)message to:(NSString *)target;
  180. /** send a CTCP ACTION to another IRC client
  181. @param action the action message to send
  182. @param target the nickname of the irc client to send the message to.
  183. */
  184. - (int)action:(NSData *)action to:(NSString *)target;
  185. /** send a NOTICE to another IRC client
  186. @param notice the message text to send
  187. @param target the nickname of the irc client to send the notice to.
  188. */
  189. - (int)notice:(NSData *)notice to:(NSString *)target;
  190. /** send a CTCP request to another IRC client
  191. @param request the CTCP request string to send
  192. @param target the nickname of the IRC client to send the request to.
  193. */
  194. - (int)ctcpRequest:(NSData *)request target:(NSString *)target;
  195. /** send a CTCP reply to another IRC client
  196. @param reply the CTCP reply string to send
  197. @param target the nickname of the IRC client to send the reply to.
  198. */
  199. - (int)ctcpReply:(NSData *)reply target:(NSString *)target;
  200. @end
  201. NSString* getNickFromNickUserHost(NSString *nuh);
  202. NSString* getUserFromNickUserHost(NSString *nuh);
  203. NSString* getHostFromNickUserHost(NSString *nuh);