php 的IRC API库的解决办法
内容摘要
这篇文章主要为大家详细介绍了php 的IRC API库的简单示例,具有一定的参考价值,可以用来参考一下。
对一个php编写的IRC API库对此感兴趣的朋友,看看idc笔记做的技术笔记!
<?ph
对一个php编写的IRC API库对此感兴趣的朋友,看看idc笔记做的技术笔记!
<?ph
文章正文
这篇文章主要为大家详细介绍了php 的IRC API库的简单示例,具有一定的参考价值,可以用来参考一下。
对一个php编写的IRC API库对此感兴趣的朋友,看看idc笔记做的技术笔记!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | <code class = "php" > <?php /** * 一个php编写的IRC API库 * * Mark的IRC API库 * * 格式化发送到IRC网络的数据。 这个库无法处理 * 实际连接到IRC服务器或解析IRC服务器输出。 * * raw_send方法可用于以XML格式将数据发送到IRC * 要么不标准,要么尚未实施。 我知道还有很多 * 实施,我计划随着时间的推移这样做。 * * @param * @author 五一二笔记网: www.idcnote.com * **/ class IRC { /** * Library version * * @access protected * @var string */ protected $_version = '1.0.0' ; /** * Connection socket * * @access protected * @var object */ protected $_socket ; /** * Constructor * * configures the class for use * * @access public * @param object * @return void */ public function __construct( $socket ) { $this ->_socket = $socket ; } /** * version * * Reports the libraries version * * @access public * @return string */ public function version() { return $this ->_version; } /** * say * * send a message to the target * * @access public * @param string $target * @param string $message * @return void */ public function say( $target , $message ) { $data = "PRIVMSG {$target} :{$message}" ; $this ->raw_send( $data ); } /** * emote * * send an emote to the target ( equiv to IRC client /me does something ) * * @access public * @param string $target * @param string $message * @return void */ public function emote( $target , $message ) { $data = chr (1). "ACTION {$message}" . chr (1); $this ->say( $target , $data ); } /** * ctcp * * send a ctcp to the target * * @access public * @param string $target * @param string $message * @return void */ public function ctcp( $target , $message ) { $data = chr (1). $message . chr (1); $this ->say( $target , $data ); } /** * notice * * send a notice to the target * * @access public * @param string $target * @param string $message * @return void */ public function notice( $target , $message ) { $data = "NOTICE {$target} :{$message}" ; $this ->raw_send( $data ); } /** * set_nick * * change user nick name * * @access public * @param string * @return void */ public function set_nick( $nick ) { $data = "NICK {$nick}" ; $this ->raw_send( $data ); } /** * set_user * * prepare user ident string * * @access public * @param string * @return void */ public function set_user( $nick ) { $data = "USER $nick $nick $nick $nick :$nick" ; $this ->raw_send( $data ); } /** * send_pass * * Identify with nickserv * * @access public * @param string * @return void */ public function send_pass( $password ) { $this ->say( 'nickserv' , "IDENTIFY {$password}" ); } /** * disconnect * * Terminates IRC connection. Does not terminate reset process in the case * you have implemented a reconnect function * * @access public * @param string|null * @return void */ public function disconnect( $message = NULL) { $data = ( $message !== NULL) ? "QUIT :{$message}" : "QUIT" ; $this ->raw_send( $data ); } /** * enter_channel * * enter an IRC channel * * @access public * @param string * @return void */ public function enter_channel( $channel ) { $data = ( $channel [0] == '#' ) ? "JOIN {$channel}" : "JOIN #{$channel}" ; $this ->raw_send( $data ); } /** * leave_channel * * leaves an IRC channel * * @access public * @param string * @return void */ public function leave_channel( $channel ) { $data = ( $channel [0] == '#' ) ? "PART {$channel}" : "PART #{$channel}" ; $this ->raw_send( $data ); } /** * raw_send * * Sends raw commands to the IRC server. I left it a public function for * hackability reasons. Makes it easier to add custom commands for * non-standard servers, or to test new features without having to edit * the class directly every time. Of course you could always just extend * the class. * * @access public * @return void */ public function raw_send( $data ) { fwrite( $this ->_socket, $data . "\n" ); } } /*** 来自php教程(www.idcnote.com) ***/ </code> |
注:关于php 的IRC API库的简单示例的内容就先介绍到这里,更多相关文章的可以留意
代码注释