注册 登录
  • 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

Mark’s IRC API Library 一个php编写的IRC API库

PHP 水墨上仙 2924次浏览 已收录 0个评论 手机上查看

Mark’s IRC API Library 一个php编写的IRC API库
Formats data for sending to an IRC network. This library does not handle * actual connecting to the IRC server or parsing the IRC servers output. * * The raw_send method can be used to send data to the IRC in formats that are * either not standard, or not yet implemented here. I know there is a lot more * to implement, and I plan to do so as time goes on.

<?php
/**
 * Mark's IRC API Library
 * 
 * Formats data for sending to an IRC network. This library does not handle
 * actual connecting to the IRC server or parsing the IRC servers output.
 * 
 * The raw_send method can be used to send data to the IRC in formats that are
 * either not standard, or not yet implemented here. I know there is a lot more
 * to implement, and I plan to do so as time goes on.
 * 
 * @author    Mark LaDoux
 * @copyright Copyright © 2012, Mark LaDoux
 * @version   1.0.0
 * @link      http://markladoux.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");
    }
 
}


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明Mark’s IRC API Library 一个php编写的IRC API库
喜欢 (0)
[开心洋葱]
分享 (0)
关于作者:
水墨上仙

您必须 登录 才能发表评论!

……
加载中……