smartirc.php
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· PHP 代码 · 共 1,982 行 · 第 1/5 页
PHP
1,982 行
$this->_usesockets = false;
}
}
} else {
$this->_usesockets = false;
}
}
/**
* Sets the level of debug messages.
*
* Sets the debug level (bitwise), useful for testing/developing your code.
* Here the list of all possible debug levels:
* SMARTIRC_DEBUG_NONE
* SMARTIRC_DEBUG_NOTICE
* SMARTIRC_DEBUG_CONNECTION
* SMARTIRC_DEBUG_SOCKET
* SMARTIRC_DEBUG_IRCMESSAGES
* SMARTIRC_DEBUG_MESSAGETYPES
* SMARTIRC_DEBUG_ACTIONHANDLER
* SMARTIRC_DEBUG_TIMEHANDLER
* SMARTIRC_DEBUG_MESSAGEHANDLER
* SMARTIRC_DEBUG_CHANNELSYNCING
* SMARTIRC_DEBUG_MODULES
* SMARTIRC_DEBUG_USERSYNCING
* SMARTIRC_DEBUG_ALL
*
* Default: SMARTIRC_DEBUG_NOTICE
*
* @see DOCUMENTATION
* @see SMARTIRC_DEBUG_NOTICE
* @param integer $level
* @return void
* @access public
*/
function setDebug($level)
{
$this->_debug = $level;
}
/**
* Enables/disables the benchmark engine.
*
* @param boolean $boolean
* @return void
* @access public
*/
function setBenchmark($boolean)
{
if (is_bool($boolean)) {
$this->_benchmark = $boolean;
} else {
$this->_benchmark = false;
}
}
/**
* Deprecated, use setChannelSyncing() instead!
*
* @deprecated
* @param boolean $boolean
* @return void
* @access public
*/
function setChannelSynching($boolean)
{
$this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: you are using setChannelSynching() which is a deprecated method, use setChannelSyncing() instead!', __FILE__, __LINE__);
$this->setChannelSyncing($boolean);
}
/**
* Enables/disables channel syncing.
*
* Channel syncing means, all users on all channel we are joined are tracked in the
* channel array. This makes it very handy for botcoding.
*
* @param boolean $boolean
* @return void
* @access public
*/
function setChannelSyncing($boolean)
{
if (is_bool($boolean)) {
$this->_channelsyncing = $boolean;
} else {
$this->_channelsyncing = false;
}
if ($this->_channelsyncing == true) {
$this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: Channel syncing enabled', __FILE__, __LINE__);
} else {
$this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: Channel syncing disabled', __FILE__, __LINE__);
}
}
/**
* Sets the CTCP version reply string.
*
* @param string $versionstring
* @return void
* @access public
*/
function setCtcpVersion($versionstring)
{
$this->_ctcpversion = $versionstring;
}
/**
* Sets the destination of all log messages.
*
* Sets the destination of log messages.
* $type can be:
* SMARTIRC_FILE for saving the log into a file
* SMARTIRC_STDOUT for echoing the log to stdout
* SMARTIRC_SYSLOG for sending the log to the syslog
* Default: SMARTIRC_STDOUT
*
* @see SMARTIRC_STDOUT
* @param integer $type must be on of the constants
* @return void
* @access public
*/
function setLogdestination($type)
{
switch ($type) {
case (SMARTIRC_FILE ||
SMARTIRC_STDOUT ||
SMARTIRC_SYSLOG ||
SMARTIRC_BROWSEROUT ||
SMARTIRC_NONE):
$this->_logdestination = $type;
break;
default:
$this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: unknown logdestination type ('.$type.'), will use STDOUT instead', __FILE__, __LINE__);
$this->_logdestination = SMARTIRC_STDOUT;
}
}
/**
* Sets the file for the log if the destination is set to file.
*
* Sets the logfile, if {@link setLogdestination logdestination} is set to SMARTIRC_FILE.
* This should be only used with full path!
*
* @param string $file
* @return void
* @access public
*/
function setLogfile($file)
{
$this->_logfile = $file;
}
/**
* Sets the delaytime before closing the socket when disconnect.
*
* @param integer $milliseconds
* @return void
* @access public
*/
function setDisconnecttime($milliseconds)
{
if (is_integer($milliseconds) && $milliseconds >= 100) {
$this->_disconnecttime = $milliseconds;
} else {
$this->_disconnecttime = 100;
}
}
/**
* Sets the delay for receiving data from the IRC server.
*
* Sets the delaytime between messages that are received, this reduces your CPU load.
* Don't set this too low (min 100ms).
* Default: 100
*
* @param integer $milliseconds
* @return void
* @access public
*/
function setReceivedelay($milliseconds)
{
if (is_integer($milliseconds) && $milliseconds >= 100) {
$this->_receivedelay = $milliseconds;
} else {
$this->_receivedelay = 100;
}
}
/**
* Sets the delay for sending data to the IRC server.
*
* Sets the delaytime between messages that are sent, because IRC servers doesn't like floods.
* This will avoid sending your messages too fast to the IRC server.
* Default: 250
*
* @param integer $milliseconds
* @return void
* @access public
*/
function setSenddelay($milliseconds)
{
if (is_integer($milliseconds)) {
$this->_senddelay = $milliseconds;
} else {
$this->_senddelay = 250;
}
}
/**
* Enables/disables autoreconnecting.
*
* @param boolean $boolean
* @return void
* @access public
*/
function setAutoReconnect($boolean)
{
if (is_bool($boolean)) {
$this->_autoreconnect = $boolean;
} else {
$this->_autoreconnect = false;
}
}
/**
* Enables/disables autoretry for connecting to a server.
*
* @param boolean $boolean
* @return void
* @access public
*/
function setAutoRetry($boolean)
{
if (is_bool($boolean)) {
$this->_autoretry = $boolean;
} else {
$this->_autoretry = false;
}
}
/**
* Sets the receive timeout.
*
* If the timeout occurs, the connection will be reinitialized
* Default: 300 seconds
*
* @param integer $seconds
* @return void
* @access public
*/
function setReceiveTimeout($seconds)
{
if (is_integer($seconds)) {
$this->_rxtimeout = $seconds;
} else {
$this->_rxtimeout = 300;
}
}
/**
* Sets the transmit timeout.
*
* If the timeout occurs, the connection will be reinitialized
* Default: 300 seconds
*
* @param integer $seconds
* @return void
* @access public
*/
function setTransmitTimeout($seconds)
{
if (is_integer($seconds)) {
$this->_txtimeout = $seconds;
} else {
$this->_txtimeout = 300;
}
}
/**
* Starts the benchmark (sets the counters).
*
* @return void
* @access public
*/
function startBenchmark()
{
$this->_benchmark_starttime = $this->_microint();
$this->log(SMARTIRC_DEBUG_NOTICE, 'benchmark started', __FILE__, __LINE__);
}
/**
* Stops the benchmark and displays the result.
*
* @return void
* @access public
*/
function stopBenchmark()
{
$this->_benchmark_stoptime = $this->_microint();
$this->log(SMARTIRC_DEBUG_NOTICE, 'benchmark stopped', __FILE__, __LINE__);
if ($this->_benchmark) {
$this->showBenchmark();
}
}
/**
* Shows the benchmark result.
*
* @return void
* @access public
*/
function showBenchmark()
{
$this->log(SMARTIRC_DEBUG_NOTICE, 'benchmark time: '.((float)$this->_benchmark_stoptime-(float)$this->_benchmark_starttime), __FILE__, __LINE__);
}
/**
* Adds an entry to the log.
*
* Adds an entry to the log with Linux style log format.
* Possible $level constants (can also be combined with "|"s)
* SMARTIRC_DEBUG_NONE
* SMARTIRC_DEBUG_NOTICE
* SMARTIRC_DEBUG_CONNECTION
* SMARTIRC_DEBUG_SOCKET
* SMARTIRC_DEBUG_IRCMESSAGES
* SMARTIRC_DEBUG_MESSAGETYPES
* SMARTIRC_DEBUG_ACTIONHANDLER
* SMARTIRC_DEBUG_TIMEHANDLER
* SMARTIRC_DEBUG_MESSAGEHANDLER
* SMARTIRC_DEBUG_CHANNELSYNCING
* SMARTIRC_DEBUG_MODULES
* SMARTIRC_DEBUG_USERSYNCING
* SMARTIRC_DEBUG_ALL
*
* @see SMARTIRC_DEBUG_NOTICE
* @param integer $level bit constants (SMARTIRC_DEBUG_*)
* @param string $entry the new log entry
* @return void
* @access public
*/
function log($level, $entry, $file = null, $line = null)
{
// prechecks
if (!(is_integer($level)) ||
!($level & SMARTIRC_DEBUG_ALL)) {
$this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: invalid log level passed to log() ('.$level.')', __FILE__, __LINE__);
return;
}
if (!($level & $this->_debug) ||
($this->_logdestination == SMARTIRC_NONE)) {
return;
}
if (substr($entry, -1) != "\n") {
$entry .= "\n";
}
if ($file !== null &&
$line !== null) {
$file = basename($file);
$entry = $file.'('.$line.') '.$entry;
} else {
$entry = 'unknown(0) '.$entry;
}
$formatedentry = date('M d H:i:s ').$entry;
switch ($this->_logdestination) {
case SMARTIRC_STDOUT:
echo $formatedentry;
flush();
break;
case SMARTIRC_BROWSEROUT:
echo '<pre>'.htmlentities($formatedentry).'</pre>';
break;
case SMARTIRC_FILE:
if (!is_resource($this->_logfilefp)) {
if ($this->_logfilefp === null) {
// we reconncted and don't want to destroy the old log entries
$this->_logfilefp = @fopen($this->_logfile,'a');
} else {
$this->_logfilefp = @fopen($this->_logfile,'w');
}
}
@fwrite($this->_logfilefp, $formatedentry);
fflush($this->_logfilefp);
break;
case SMARTIRC_SYSLOG:
define_syslog_variables();
if (!is_int($this->_logfilefp)) {
$this->_logfilefp = openlog('Net_SmartIRC', LOG_NDELAY, LOG_DAEMON);
}
syslog(LOG_INFO, $entry);
break;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?