chore: remove IRC bot
This commit is contained in:
parent
f486fcf8da
commit
559668b6ee
34 changed files with 0 additions and 14242 deletions
147
ircbot/bot.conf
147
ircbot/bot.conf
|
@ -1,147 +0,0 @@
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
;| PHP-IRC v2.2.1 Service Release
|
|
||||||
;| =======================================================
|
|
||||||
;| by Manick
|
|
||||||
;| (c) 2001-2006 by http://www.phpbots.org/
|
|
||||||
;| Contact: manick@manekian.com
|
|
||||||
;| irc: #manekian@irc.rizon.net
|
|
||||||
;| ========================================
|
|
||||||
;| Special Contributions were made by:
|
|
||||||
;| cortex
|
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
;| > Configuration File
|
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
;| > This program is free software; you can redistribute it and/or
|
|
||||||
;| > modify it under the terms of the GNU General Public License
|
|
||||||
;| > as published by the Free Software Foundation; either version 2
|
|
||||||
;| > of the License, or (at your option) any later version.
|
|
||||||
;| >
|
|
||||||
;| > This program is distributed in the hope that it will be useful,
|
|
||||||
;| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;| > GNU General Public License for more details.
|
|
||||||
;| >
|
|
||||||
;| > You should have received a copy of the GNU General Public License
|
|
||||||
;| > along with this program; if not, write to the Free Software
|
|
||||||
;| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
;| Changes
|
|
||||||
;| =======-------
|
|
||||||
;| > If you wish to suggest or submit an update/change to the source
|
|
||||||
;| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
;| > will look to adding it in as soon as I can.
|
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
;====Bot config file
|
|
||||||
|
|
||||||
;====Contains the nickname of the Bot
|
|
||||||
nick LW-Bot
|
|
||||||
|
|
||||||
;====The nickserv password, if any (autoident)..
|
|
||||||
password ...
|
|
||||||
|
|
||||||
;====Real name..
|
|
||||||
realname Legacy Worlds Bot
|
|
||||||
|
|
||||||
;====The server you are going to connect to
|
|
||||||
server localhost
|
|
||||||
|
|
||||||
;====The server port
|
|
||||||
port 6667
|
|
||||||
|
|
||||||
;====The server password you are going to connect to
|
|
||||||
;serverpassword test
|
|
||||||
|
|
||||||
;====NAT IP
|
|
||||||
;natip 192.168.1.101
|
|
||||||
|
|
||||||
;===BIND IP
|
|
||||||
;Specify the IP this bot should bind to when connecting to a server
|
|
||||||
;bind 127.0.0.1
|
|
||||||
|
|
||||||
;====DCC Range start for chats/files
|
|
||||||
;dccrangestart 6081
|
|
||||||
|
|
||||||
;====DCC Reverse Protocl
|
|
||||||
;This follows the mIRC DCC Server Protocol
|
|
||||||
;When this is set, you will connect to this port
|
|
||||||
;on the users machine, and send them the file, similar to
|
|
||||||
;sysreset's firewall workaround.
|
|
||||||
;This function is EXPERIMENTAL
|
|
||||||
;====
|
|
||||||
;mircdccreverse 4000
|
|
||||||
|
|
||||||
;====Who on join?
|
|
||||||
;After joining a channel, populate the host lists
|
|
||||||
;with /WHO information? This probably isn't so good
|
|
||||||
;for larger channels...
|
|
||||||
;This function populates host/ident information for
|
|
||||||
;all users in a channel. Useful for running channel protection
|
|
||||||
;scripts and such. The DCC Reverse setting above using a WHOIS
|
|
||||||
;command to get user hosts, so this doesn't have to be set
|
|
||||||
;to use the above setting.
|
|
||||||
;====
|
|
||||||
;populatewho
|
|
||||||
|
|
||||||
;====Populate ban list?
|
|
||||||
;This will make php-irc run MODE #chan +b upon joining, populating
|
|
||||||
;the ban list. This is useful for running channel protection or ban
|
|
||||||
;rotating scripts.
|
|
||||||
;====
|
|
||||||
;populatebans
|
|
||||||
|
|
||||||
;====Flood lines
|
|
||||||
;when someone types text that is a trigger for the bot, how many times can they type
|
|
||||||
;different triggers (within a 10 second period) before the bot ignores them for spamming the bot
|
|
||||||
floodlines 500
|
|
||||||
|
|
||||||
;====Time to ban user in seconds for abusing the bots triggers
|
|
||||||
floodtime 60
|
|
||||||
|
|
||||||
;====Channels.. unlimited
|
|
||||||
;====i.e., channel #channel key
|
|
||||||
;====but you don't have to specify a key
|
|
||||||
channel #testing meeeh
|
|
||||||
|
|
||||||
;====Your ident
|
|
||||||
ident lwbot
|
|
||||||
|
|
||||||
;====Log file
|
|
||||||
logfile __CFG:cachedir__/ircbot.log
|
|
||||||
|
|
||||||
;====uncomment the following lines to use a database
|
|
||||||
;either 'usedatabase mysql' or 'usedatabase postgre'
|
|
||||||
;usedatabase mysql
|
|
||||||
|
|
||||||
;dbuser root
|
|
||||||
;dbpass none
|
|
||||||
;db question
|
|
||||||
;dbprefix bot_
|
|
||||||
;dbhost localhost
|
|
||||||
;dbport
|
|
||||||
|
|
||||||
;====Send queue timeout
|
|
||||||
;How often to send more text to the irc server. This handles the 'notice'
|
|
||||||
;and 'privMsg' commands sent from modules and such (in seconds)
|
|
||||||
queuetimeout 1
|
|
||||||
|
|
||||||
;====Send queue buffer
|
|
||||||
;How many bytes of text to send to the server every 'queuetimeout' period.
|
|
||||||
queuebuffer 225
|
|
||||||
|
|
||||||
;====Perm. Ignore (These hosts will always be ignored, forever)
|
|
||||||
;example:
|
|
||||||
;ignore *!*@*
|
|
||||||
|
|
||||||
;====DCC Admin password //default is 'mypass'
|
|
||||||
;dccadminpass a029d0df84eb5549c641e04a9ef389e5
|
|
||||||
|
|
||||||
;====set this to your function file
|
|
||||||
functionfile function.conf
|
|
||||||
|
|
||||||
;====whether this bot accepts sends from other people
|
|
||||||
upload no
|
|
||||||
|
|
||||||
;====The place where uploaded files are put.
|
|
||||||
;uploaddir /home/my/dir/
|
|
476
ircbot/bot.php
476
ircbot/bot.php
|
@ -1,476 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2005 by http://www.phpbots.org/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > Main module
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.2.0
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
|
||||||
set_time_limit(0);
|
|
||||||
|
|
||||||
|
|
||||||
$oldDir = getcwd();
|
|
||||||
chdir("../scripts");
|
|
||||||
$__logPrefix = "lwBot";
|
|
||||||
$__loader = array(
|
|
||||||
'log', 'classloader', 'version', 'game', 'tick', 'config',
|
|
||||||
'db_connection', 'db_accessor', 'db', 'library'
|
|
||||||
);
|
|
||||||
require_once('loader.inc');
|
|
||||||
chdir($oldDir);
|
|
||||||
|
|
||||||
require('./defines.php');
|
|
||||||
require('./queue.php');
|
|
||||||
require('./module.php');
|
|
||||||
require('./irc.php');
|
|
||||||
require('./socket.php');
|
|
||||||
require('./timers.php');
|
|
||||||
require('./dcc.php');
|
|
||||||
require('./chat.php');
|
|
||||||
require('./file.php');
|
|
||||||
require('./parser.php');
|
|
||||||
require('./databases/ini.php');
|
|
||||||
require('./error.php');
|
|
||||||
require('./connection.php');
|
|
||||||
require('./remote.php');
|
|
||||||
|
|
||||||
|
|
||||||
final class bot {
|
|
||||||
|
|
||||||
/* Global socket class used by all bots */
|
|
||||||
private $socketClass;
|
|
||||||
|
|
||||||
/* Global process Queue used by all bots, timers, dcc classes */
|
|
||||||
private $procQueue;
|
|
||||||
|
|
||||||
/* Whether we are running in background mode or not. (not sure if this is used anymore */
|
|
||||||
private $background = 0;
|
|
||||||
|
|
||||||
//contain all the bots
|
|
||||||
private $bots = array();
|
|
||||||
|
|
||||||
// save the only one instance of bot (singleton)
|
|
||||||
private static $_instance;
|
|
||||||
|
|
||||||
public static function getInstance()
|
|
||||||
{
|
|
||||||
if (!isset (self :: $_instance))
|
|
||||||
{
|
|
||||||
self :: $_instance = new bot();
|
|
||||||
}
|
|
||||||
return self :: $_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Main Method
|
|
||||||
private function __construct()
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->socketClass = new socket();
|
|
||||||
$this->procQueue = new processQueue();
|
|
||||||
|
|
||||||
$this->socketClass->setProcQueue($this->procQueue);
|
|
||||||
|
|
||||||
$this->readConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function launch(){
|
|
||||||
|
|
||||||
foreach($this->bots as $bot)
|
|
||||||
{
|
|
||||||
$this->createBot($bot);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Main program loop */
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
//Get data from sockets, and trigger procQueue's for new data to be read
|
|
||||||
$this->socketClass->handle();
|
|
||||||
|
|
||||||
//The bots main process loop. Run everything we need to!
|
|
||||||
$timeout = $this->procQueue->handle();
|
|
||||||
|
|
||||||
//Okay, set the socketclass timeout based on the next applicable process
|
|
||||||
if ($timeout !== true)
|
|
||||||
{
|
|
||||||
$this->socketClass->setTimeout($timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
//echo $this->procQueue->getNumQueued() . "\n";
|
|
||||||
//$this->procQueue->displayQueue();
|
|
||||||
|
|
||||||
//Aight, if we don't have any sockets open/in use, and
|
|
||||||
//we have no processes in the process queue, then there are
|
|
||||||
//obviously no bots running, so just exit!
|
|
||||||
if ($this->socketClass->getNumSockets() == 0 && $this->procQueue->getNumQueued() == 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception $e)
|
|
||||||
{
|
|
||||||
$this->ircClass->log($e->_toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static function addBot($filename){
|
|
||||||
$bot = bot::getInstance();
|
|
||||||
$config = bot::parseConfig($filename);
|
|
||||||
if ($config == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$newBot = new botClass();
|
|
||||||
$newBot->config = $config;
|
|
||||||
$newBot->configFilename = $filename;
|
|
||||||
|
|
||||||
$bot->bots[] = $newBot;
|
|
||||||
$bot->createBot($newBot);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function createBot($bot)
|
|
||||||
{
|
|
||||||
$this->connectToDatabase($bot);
|
|
||||||
|
|
||||||
$bot->socketClass = $this->socketClass;
|
|
||||||
$bot->timerClass = new timers();
|
|
||||||
$bot->parserClass = new parser();
|
|
||||||
|
|
||||||
$bot->dccClass = new dcc();
|
|
||||||
$bot->ircClass = new irc();
|
|
||||||
|
|
||||||
$bot->ircClass->setConfig($bot->config, $bot->configFilename);
|
|
||||||
$bot->ircClass->setSocketClass($this->socketClass);
|
|
||||||
$bot->ircClass->setParserClass($bot->parserClass);
|
|
||||||
$bot->ircClass->setDccClass($bot->dccClass);
|
|
||||||
$bot->ircClass->setTimerClass($bot->timerClass);
|
|
||||||
$bot->ircClass->setProcQueue($this->procQueue);
|
|
||||||
|
|
||||||
$bot->dccClass->setSocketClass($this->socketClass);
|
|
||||||
$bot->dccClass->setTimerClass($bot->timerClass);
|
|
||||||
$bot->dccClass->setParserClass($bot->parserClass);
|
|
||||||
$bot->dccClass->setProcQueue($this->procQueue);
|
|
||||||
|
|
||||||
$bot->parserClass->setTimerClass($bot->timerClass);
|
|
||||||
$bot->parserClass->setSocketClass($this->socketClass);
|
|
||||||
$bot->parserClass->setDatabase($bot->db);
|
|
||||||
|
|
||||||
$bot->timerClass->setIrcClass($bot->ircClass);
|
|
||||||
$bot->timerClass->setSocketClass($this->socketClass);
|
|
||||||
$bot->timerClass->setProcQueue($this->procQueue);
|
|
||||||
|
|
||||||
$bot->parserClass->init();
|
|
||||||
|
|
||||||
//Okay, this function adds the connect timer and starts up this bot class.
|
|
||||||
$bot->ircClass->init();
|
|
||||||
|
|
||||||
bot::createChannelArray($bot->ircClass);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function readConfig()
|
|
||||||
{
|
|
||||||
global $argc, $argv;
|
|
||||||
|
|
||||||
if ($argc < 2) {
|
|
||||||
$args = array(config::$main['scriptdir'] . "/../ircbot/bot.conf");
|
|
||||||
} else {
|
|
||||||
$args = $argv;
|
|
||||||
array_shift($args);
|
|
||||||
}
|
|
||||||
|
|
||||||
$isPasswordEncrypt = false;
|
|
||||||
|
|
||||||
foreach ($args AS $filename)
|
|
||||||
{
|
|
||||||
if ($filename == "")
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($isPasswordEncrypt == true)
|
|
||||||
{
|
|
||||||
die("Encrypted Password: " . md5($filename) . "\nReplace this as 'dccadminpass' in bot.conf!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($filename == "-c")
|
|
||||||
{
|
|
||||||
$isPasswordEncrypt = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($filename == "-b" && $this->background != 1)
|
|
||||||
{
|
|
||||||
$this->background = 1;
|
|
||||||
$this->doBackground();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$config = bot::parseConfig($filename);
|
|
||||||
|
|
||||||
if ($config == false)
|
|
||||||
{
|
|
||||||
echo "Could not spawn bot $filename";
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
|
|
||||||
$bot = new botClass();
|
|
||||||
$bot->config = $config;
|
|
||||||
$bot->configFilename = $filename;
|
|
||||||
|
|
||||||
$this->bots[] = $bot;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($isPasswordEncrypt == true) {
|
|
||||||
die("No password submitted on command line! Syntax: bot.php -c <new admin password>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $this->background && PID != '') {
|
|
||||||
$file = fopen(PID, "w+");
|
|
||||||
fwrite($file, getmypid());
|
|
||||||
fclose($file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private function connectToDatabase($bot)
|
|
||||||
{
|
|
||||||
if (isset($bot->config['usedatabase']))
|
|
||||||
{
|
|
||||||
if (!file_exists("./databases/" . $bot->config['usedatabase']. ".php"))
|
|
||||||
{
|
|
||||||
die("Couldn't find the database file! Make sure it exists!");
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once("./databases/" . $bot->config['usedatabase']. ".php");
|
|
||||||
|
|
||||||
$dbType = $bot->config['usedatabase'];
|
|
||||||
|
|
||||||
if (!isset($bot->config['dbhost']))
|
|
||||||
$bot->config['dbhost'] = "localhost";
|
|
||||||
if (!isset($bot->config['dbuser']))
|
|
||||||
$bot->config['dbuser'] = "root";
|
|
||||||
if (!isset($bot->config['dbpass']))
|
|
||||||
$bot->config['dbpass'] = "";
|
|
||||||
if (!isset($bot->config['db']))
|
|
||||||
$bot->config['db'] = "test";
|
|
||||||
if (!isset($bot->config['dbprefix']))
|
|
||||||
$bot->config['dbprefix'] = "";
|
|
||||||
if (!isset($bot->config['dbport']))
|
|
||||||
{
|
|
||||||
$bot->db = new $dbType($bot->config['dbhost'],
|
|
||||||
$bot->config['db'],
|
|
||||||
$bot->config['dbuser'],
|
|
||||||
$bot->config['dbpass'],
|
|
||||||
$bot->config['dbprefix']);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$bot->db = new $dbType($bot->config['dbhost'],
|
|
||||||
$bot->config['db'],
|
|
||||||
$bot->config['dbuser'],
|
|
||||||
$bot->config['dbpass'],
|
|
||||||
$bot->config['dbprefix'],
|
|
||||||
$bot->config['dbport']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$bot->db->isConnected())
|
|
||||||
{
|
|
||||||
die("Couldn't connect to database...");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static function createChannelArray($ircClass)
|
|
||||||
{
|
|
||||||
$channels = $ircClass->getClientConf('channel');
|
|
||||||
|
|
||||||
if ($channels != "")
|
|
||||||
{
|
|
||||||
if (!is_array($channels))
|
|
||||||
{
|
|
||||||
$channels = array($channels);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($channels AS $channel)
|
|
||||||
{
|
|
||||||
$chan = $channel;
|
|
||||||
$key = "";
|
|
||||||
|
|
||||||
if (strpos($channel, chr(32)) !== false)
|
|
||||||
{
|
|
||||||
$channelVars = explode(chr(32), $channel);
|
|
||||||
$chan = $channelVars[0];
|
|
||||||
$key = $channelVars[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
$ircClass->maintainChannel($chan, $key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function parseConfig($filename)
|
|
||||||
{
|
|
||||||
$configFPtr = @fopen($filename, "rt");
|
|
||||||
|
|
||||||
if ($configFPtr == null)
|
|
||||||
{
|
|
||||||
// echo "Could not find config file '".$filename."'\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$configRaw = "";
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
|
|
||||||
while (!feof($configFPtr))
|
|
||||||
{
|
|
||||||
$configRaw .= fgets($configFPtr, 1024);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose($configFPtr);
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception $e)
|
|
||||||
{
|
|
||||||
// echo "A fatal IO Exception occured.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$config = array();
|
|
||||||
|
|
||||||
$configRaw = str_replace("\r", "", $configRaw);
|
|
||||||
|
|
||||||
$confLines = explode("\n", $configRaw);
|
|
||||||
|
|
||||||
foreach ($confLines AS $line)
|
|
||||||
{
|
|
||||||
$line = trim($line);
|
|
||||||
|
|
||||||
if ($line == "" || substr($line, 0, 1) == ";")
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$offsetA = strpos($line, chr(32));
|
|
||||||
|
|
||||||
if ($offsetA != false)
|
|
||||||
{
|
|
||||||
$confVar = substr($line, 0, $offsetA);
|
|
||||||
$confParams = substr($line, $offsetA + 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$confVar = $line;
|
|
||||||
$confParams = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preg_match('/__CFG:([a-zA-Z_]+)__/', $confParams, $matches)) {
|
|
||||||
$src = array(); $dst = array();
|
|
||||||
array_shift($matches);
|
|
||||||
foreach ($matches as $cfgSubst) {
|
|
||||||
array_push($src, "/__CFG:{$cfgSubst}__/");
|
|
||||||
array_push($dst, config::$main[$cfgSubst]);
|
|
||||||
}
|
|
||||||
$confParams = preg_replace($src, $dst, $confParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($config[$confVar]))
|
|
||||||
{
|
|
||||||
if (!is_array($config[$confVar]))
|
|
||||||
{
|
|
||||||
$prevParam = $config[$confVar];
|
|
||||||
$config[$confVar] = array();
|
|
||||||
$config[$confVar][] = $prevParam;
|
|
||||||
}
|
|
||||||
|
|
||||||
$config[$confVar][] = $confParams;
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$config[$confVar] = $confParams;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $config;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function doBackground()
|
|
||||||
{
|
|
||||||
$pid = pcntl_fork();
|
|
||||||
if ($pid == -1) {
|
|
||||||
die("Error: could not fork\n");
|
|
||||||
} else if ($pid) {
|
|
||||||
if (PID != "") {
|
|
||||||
$file = fopen(PID, "w+");
|
|
||||||
fwrite($file, $pid);
|
|
||||||
fclose($file);
|
|
||||||
}
|
|
||||||
|
|
||||||
exit(); // Parent
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!posix_setsid()) {
|
|
||||||
die("Error: Could not detach from terminal\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(STDIN);
|
|
||||||
fclose(STDOUT);
|
|
||||||
fclose(STDERR);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$ircBot = bot::getInstance();
|
|
||||||
$ircBot->launch();
|
|
||||||
|
|
||||||
?>
|
|
364
ircbot/chat.php
364
ircbot/chat.php
|
@ -1,364 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2004 by http://www.phpbots.org/
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > dcc chat module
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.2.1 beta
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
class chat {
|
|
||||||
|
|
||||||
/* Chat specific Data */
|
|
||||||
public $id;
|
|
||||||
public $status;
|
|
||||||
public $sockInt;
|
|
||||||
public $isAdmin;
|
|
||||||
public $timeConnected;
|
|
||||||
public $verified;
|
|
||||||
public $readQueue;
|
|
||||||
public $floodQueue;
|
|
||||||
public $floodQueueTime;
|
|
||||||
public $port;
|
|
||||||
public $type;
|
|
||||||
public $nick;
|
|
||||||
public $timeOutLevel;
|
|
||||||
public $removed;
|
|
||||||
public $connection;
|
|
||||||
|
|
||||||
public $handShakeSent;
|
|
||||||
public $handShakeTime;
|
|
||||||
public $reverse;
|
|
||||||
public $connectHost;
|
|
||||||
|
|
||||||
/* Classes */
|
|
||||||
private $dccClass;
|
|
||||||
private $parserClass;
|
|
||||||
private $ircClass;
|
|
||||||
private $socketClass;
|
|
||||||
private $timerClass;
|
|
||||||
|
|
||||||
//class handler
|
|
||||||
private $handler;
|
|
||||||
|
|
||||||
/* Constructor */
|
|
||||||
public function __construct($id, $nick, $admin, $sockInt, $host, $port, $handler, $reverse)
|
|
||||||
{
|
|
||||||
$this->id = $id;
|
|
||||||
$this->handler = $handler;
|
|
||||||
$this->nick = $nick;
|
|
||||||
$this->isAdmin = $admin;
|
|
||||||
$this->sockInt = $sockInt;
|
|
||||||
$this->port = $port;
|
|
||||||
$this->connectHost = $host;
|
|
||||||
$this->reverse = $reverse;
|
|
||||||
$this->handShakeSent = false;
|
|
||||||
|
|
||||||
$this->sendQueue = array();
|
|
||||||
$this->sendQueueCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setIrcClass($class)
|
|
||||||
{
|
|
||||||
$this->ircClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setDccClass($class)
|
|
||||||
{
|
|
||||||
$this->dccClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setSocketClass($class)
|
|
||||||
{
|
|
||||||
$this->socketClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setParserClass($class)
|
|
||||||
{
|
|
||||||
$this->parserClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTimerClass($class)
|
|
||||||
{
|
|
||||||
$this->timerClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function sendUserGreeting()
|
|
||||||
{
|
|
||||||
if ($this->verified == true)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->dccSend("Welcome to " . $this->ircClass->getNick());
|
|
||||||
$this->dccSend("PHP-iRC v". VERSION ." [". VERSION_DATE ."]");
|
|
||||||
$time = $this->ircClass->timeFormat($this->ircClass->getRunTime(), "%d days, %h hrs, %m min, %s sec");
|
|
||||||
$this->dccSend("running " . $time);
|
|
||||||
$this->dccSend("You are currently in the dcc chat interface. Type 'help' to begin.");
|
|
||||||
}
|
|
||||||
|
|
||||||
private function sendAdminGreeting()
|
|
||||||
{
|
|
||||||
if ($this->verified == true)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->dccSend("Welcome to " . $this->ircClass->getNick());
|
|
||||||
$this->dccSend("PHP-iRC v". VERSION ." [". VERSION_DATE ."]");
|
|
||||||
$time = $this->ircClass->timeFormat($this->ircClass->getRunTime(), "%d days, %h hrs, %m min, %s sec");
|
|
||||||
$this->dccSend("running " . $time);
|
|
||||||
$this->dccSend("Enter Your Password:");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dccSend($data, $to = null)
|
|
||||||
{
|
|
||||||
if ($this->status != DCC_CONNECTED)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($to == null)
|
|
||||||
{
|
|
||||||
$to = $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->dccClass->dccSend($to, "--> " . $data . "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dccSendRaw($data, $to = null)
|
|
||||||
{
|
|
||||||
if ($this->status != DCC_CONNECTED)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($to == null)
|
|
||||||
{
|
|
||||||
$to = $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->dccClass->dccSend($to, $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function disconnect($msg = "")
|
|
||||||
{
|
|
||||||
|
|
||||||
$msg = str_replace("\r", "", $msg);
|
|
||||||
$msg = str_replace("\n", "", $msg);
|
|
||||||
|
|
||||||
if (is_object($this->handler) && $this->status == DCC_CONNECTED)
|
|
||||||
{
|
|
||||||
$this->handler->disconnected($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->status = false;
|
|
||||||
|
|
||||||
if ($msg != "")
|
|
||||||
{
|
|
||||||
$this->dccClass->dccInform("DCC: " . $this->nick . " closed DCC Chat (" . $msg . ")", $this);
|
|
||||||
$this->ircClass->notice($this->nick, "DCC session ended: " . $msg, 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->dccClass->dccInform("DCC: " . $this->nick . " closed DCC Chat", $this);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->dccClass->disconnect($this);
|
|
||||||
|
|
||||||
$this->connection = null;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private function doHandShake()
|
|
||||||
{
|
|
||||||
$this->dccSendRaw("100 ".$this->ircClass->getNick()."\n");
|
|
||||||
$this->handShakeSent = true;
|
|
||||||
$this->timerClass->addTimer(irc::randomHash(), $this, "handShakeTimeout", "", 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function processHandShake()
|
|
||||||
{
|
|
||||||
if ($this->readQueue == "")
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = $this->readQueue;
|
|
||||||
$this->readQueue = "";
|
|
||||||
$responseArray = explode(chr(32), $response);
|
|
||||||
if ($responseArray[0] == "101")
|
|
||||||
{
|
|
||||||
$this->reverse = false;
|
|
||||||
$this->onConnect($this->connection);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->disconnect("DCC Client Server reported error on attempt to start chat");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handShakeTimeout()
|
|
||||||
{
|
|
||||||
if ($this->status != false)
|
|
||||||
{
|
|
||||||
if ($this->reverse == true)
|
|
||||||
{
|
|
||||||
$this->disconnect("DCC Reverse handshake timed out");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Main events */
|
|
||||||
public function onTimeout($conn)
|
|
||||||
{
|
|
||||||
$this->disconnect("Connection transfer timed out");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onDead($conn)
|
|
||||||
{
|
|
||||||
$this->disconnect($this->connection->getErrorMsg());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onRead($conn)
|
|
||||||
{
|
|
||||||
if ($this->socketClass->hasLine($this->sockInt))
|
|
||||||
{
|
|
||||||
$this->readQueue .= $this->socketClass->getQueueLine($this->sockInt);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->status == DCC_CONNECTED)
|
|
||||||
{
|
|
||||||
if ($this->reverse != false)
|
|
||||||
{
|
|
||||||
if ($this->handShakeSent != false)
|
|
||||||
{
|
|
||||||
$this->processHandShake();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($this->readQueue != "")
|
|
||||||
{
|
|
||||||
$this->parserClass->parseDcc($this, $this->handler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->socketClass->hasLine($this->sockInt))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onWrite($conn)
|
|
||||||
{
|
|
||||||
//do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onAccept($oldConn, $newConn)
|
|
||||||
{
|
|
||||||
$this->dccClass->accepted($oldConn, $newConn);
|
|
||||||
$this->connection = $newConn;
|
|
||||||
$oldConn->disconnect();
|
|
||||||
$this->sockInt = $newConn->getSockInt();
|
|
||||||
$this->onConnect($newConn);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onConnectTimeout($conn)
|
|
||||||
{
|
|
||||||
$this->disconnect("Connection attempt timed out");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onConnect($conn)
|
|
||||||
{
|
|
||||||
$this->status = DCC_CONNECTED;
|
|
||||||
|
|
||||||
if ($this->reverse != false)
|
|
||||||
{
|
|
||||||
$this->dccClass->dccInform("DCC CHAT: " . $this->nick . " handling dcc server request");
|
|
||||||
$this->doHandShake();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->dccClass->dccInform("DCC CHAT: " . $this->nick . " connection established");
|
|
||||||
|
|
||||||
if ($this->handler === false || $this->handler == null)
|
|
||||||
{
|
|
||||||
if ($this->isAdmin == true)
|
|
||||||
{
|
|
||||||
$this->sendAdminGreeting();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->sendUserGreeting();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
if (is_object($this->handler))
|
|
||||||
{
|
|
||||||
$this->handler->connected($this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function initialize()
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->dccClass->dccInform("DCC: " . $this->nick . " is attempting to login");
|
|
||||||
|
|
||||||
if ($this->status == DCC_LISTENING)
|
|
||||||
{
|
|
||||||
$this->ircClass->privMsg($this->nick, "\1DCC CHAT chat " . $this->ircClass->getClientIP(1) . " " . $this->port . "\1", 0);
|
|
||||||
$this->ircClass->notice($this->nick, "DCC Chat (" . $this->ircClass->getClientIP(0) . ")", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->timeConnected = time();
|
|
||||||
$this->timeOutLevel = 0;
|
|
||||||
$this->verified = 0;
|
|
||||||
$this->readQueue = "";
|
|
||||||
$this->floodQueue = "";
|
|
||||||
$this->floodQueueTime = 0;
|
|
||||||
$this->type = CHAT;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
|
@ -1,870 +0,0 @@
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2006 by http://www.phpbots.org/
|
|
||||||
| Contact: manick@manekian.net
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > Module Command Reference
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
The following file is a quickly put together command reference of all the functions that you can use to complement the php scripting language while writing your modules.
|
|
||||||
|
|
||||||
===============
|
|
||||||
Quick Reference (See below the quick reference for function descriptions)
|
|
||||||
===============
|
|
||||||
|
|
||||||
irc.php (Accessed with $this->ircClass->)
|
|
||||||
-----------------------------------------
|
|
||||||
array parseModes($modeString)
|
|
||||||
array getMaintainedChannels()
|
|
||||||
string getClientConf($var = "")
|
|
||||||
string getNick()
|
|
||||||
string getServerConf($var)
|
|
||||||
string getStatusString($status)
|
|
||||||
string getClientIP($long = 1)
|
|
||||||
class getChannelData($channel)
|
|
||||||
class getUserData($user, $channel = "")
|
|
||||||
void disconnect()
|
|
||||||
void setClientConfigVar($var, $value)
|
|
||||||
void joinChannel($chan)
|
|
||||||
void sendRaw($text, $force = false)
|
|
||||||
void privMsg($who, $msg, $queue = 1)
|
|
||||||
void action($who, $msg, $queue = 1)
|
|
||||||
void notice($who, $msg, $queue = 1)
|
|
||||||
void log($text)
|
|
||||||
void maintainChannel($channel, $key = "")
|
|
||||||
void removeMaintain($channel)
|
|
||||||
void addQuery($host, $port, $query, $line, $class, $function)
|
|
||||||
int getStatusRaw()
|
|
||||||
bool changeMode($chan, $act, $mode, $user)
|
|
||||||
bool isOnline($nick, $chan)
|
|
||||||
bool isMode($nick, $channel, $mode)
|
|
||||||
bool isChanMode($channel, $mode, $extra = "")
|
|
||||||
bool hasModeSet($chan, $user, $modes);
|
|
||||||
bool hostMasksMatch($mask1, $mask2)
|
|
||||||
bool checkIgnore($mask)
|
|
||||||
|
|
||||||
socket.php (Accessed with $this->socketClass->)
|
|
||||||
-----------------------------------------------
|
|
||||||
string getHost($sockInt)
|
|
||||||
string getQueue($sockInt)
|
|
||||||
string getQueueLine($sockInt)
|
|
||||||
int sendSocket($sockInt, $data)
|
|
||||||
int getSockStatus($sockInt)
|
|
||||||
object getSockData($sockInt)
|
|
||||||
bool hasWriteQueue($sockInt)
|
|
||||||
bool hasLine($sockInt)
|
|
||||||
|
|
||||||
timers.php (Accessed with $this->timerClass->)
|
|
||||||
----------------------------------------------
|
|
||||||
class addTimer($name, $class, $function, $args, $interval, $runRightAway = false)
|
|
||||||
class getTimers()
|
|
||||||
void removeTimer($timer) (MUST be name)
|
|
||||||
|
|
||||||
mysql/postgre.php (Accessed with $this->db->)
|
|
||||||
---------------------------------------------
|
|
||||||
array queryFetch($query)
|
|
||||||
array fetchArray($object)
|
|
||||||
array fetchRow($object)
|
|
||||||
string getError()
|
|
||||||
bool isConnected()
|
|
||||||
int lastID()
|
|
||||||
int numRows($toFetch)
|
|
||||||
int numQueries()
|
|
||||||
void close()
|
|
||||||
object query($query)
|
|
||||||
|
|
||||||
dcc.php (Accessed with $this->dccClass->)
|
|
||||||
-----------------------------------------
|
|
||||||
array getDccList()
|
|
||||||
int getDownloadCount()
|
|
||||||
int getUploadCount()
|
|
||||||
int getChatCount()
|
|
||||||
int getBytesDown()
|
|
||||||
int getBytesUp()
|
|
||||||
int addChat($nick, $host, $port, $admin, $handler)
|
|
||||||
int addFile($nick, $host, $port, $type, $filename, $size)
|
|
||||||
int sendFile($nick, $file)
|
|
||||||
class getDcc($dcc)
|
|
||||||
void dccInform($text, $from = null)
|
|
||||||
|
|
||||||
chat.php
|
|
||||||
----------
|
|
||||||
void disconnect($msg = "")
|
|
||||||
void dccSend($msg)
|
|
||||||
|
|
||||||
file.php
|
|
||||||
----------
|
|
||||||
void disconnect($msg = "")
|
|
||||||
|
|
||||||
ini.php
|
|
||||||
----------
|
|
||||||
bool getError()
|
|
||||||
bool sectionExists($section)
|
|
||||||
bool deleteSection($section)
|
|
||||||
bool deleteVar($section, $var)
|
|
||||||
bool setIniVal($section, $var, $val)
|
|
||||||
bool writeIni()
|
|
||||||
array getSections()
|
|
||||||
array getVars($section)
|
|
||||||
array getSection($section)
|
|
||||||
array randomSection($num = 1)
|
|
||||||
array searchSections($search, $type = EXACT_MATCH)
|
|
||||||
array searchVars($section, $search, $type = EXACT_MATCH)
|
|
||||||
array searchSectionsByVar($var, $search, $type = EXACT_MATCH)
|
|
||||||
array searchVals($section, $search, $type = EXACT_MATCH)
|
|
||||||
mixed randomVar($section, $num = 1)
|
|
||||||
mixed getIniVal($section, $var)
|
|
||||||
int numSections()
|
|
||||||
int numVars($section)
|
|
||||||
|
|
||||||
Useful Static Routines
|
|
||||||
-----------------------
|
|
||||||
string socket::generatePostQuery($query, $host, $path, $httpVersion)
|
|
||||||
string socket::generateGetQuery($query, $host, $path, $httpVersion)
|
|
||||||
string irc::intToSizeString($size)
|
|
||||||
string irc::myStrToLower($text)
|
|
||||||
string irc::myStrToUpper($text)
|
|
||||||
string irc::timeFormat($time, $format)
|
|
||||||
string irc::randomHash()
|
|
||||||
array irc::multiLine($text)
|
|
||||||
|
|
||||||
|
|
||||||
=========================
|
|
||||||
Full Function Definitions
|
|
||||||
=========================
|
|
||||||
|
|
||||||
irc.php (Accessed with $this->ircClass->)
|
|
||||||
-----------------------------------------
|
|
||||||
|
|
||||||
-------------------------------
|
|
||||||
array parseModes($modeString)
|
|
||||||
-------------------------------
|
|
||||||
|
|
||||||
Mode strings usually come from the $line['params'] variable. However, they look like this:
|
|
||||||
|
|
||||||
+o-b Manick blah!*@*
|
|
||||||
|
|
||||||
This is a real mess to parse. Thus, this function takes the line and returns an array of each mode being operated. The format is as follows:
|
|
||||||
|
|
||||||
$modesArray = array(
|
|
||||||
|
|
||||||
[0] = array( 'ACTION' => '+',
|
|
||||||
'MODE' => 'o',
|
|
||||||
'EXTRA' => 'Manick',
|
|
||||||
'TYPE' => USER_MODE,
|
|
||||||
)
|
|
||||||
|
|
||||||
[1] = array( 'ACTION' => '-',
|
|
||||||
'MODE' => 'b',
|
|
||||||
'EXTRA' => 'blah!*@*',
|
|
||||||
'TYPE' => CHANNEL_MODE,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
--------------------------------
|
|
||||||
array getMaintainedChannels()
|
|
||||||
--------------------------------
|
|
||||||
This will return an array of all the channels that php-irc will attempt to stay in. Every sixty seconds or so, the bot will attempt to join these channels if it is not currently in them. See 'maintainChannel()' and 'removeMaintain()' for more information.
|
|
||||||
|
|
||||||
|
|
||||||
--------------------------------
|
|
||||||
string getClientConf($var = "")
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
Will return the corresponding value for the setting of $var in bot.conf. If $var == "", the full configuration array is returned as an array. Also, if the setting does not exist in the configuration, this function will return an empty string, "".
|
|
||||||
|
|
||||||
|
|
||||||
--------------------------------
|
|
||||||
string getNick()
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
Returns the bots current, IRC recognized nick.
|
|
||||||
|
|
||||||
|
|
||||||
--------------------------------
|
|
||||||
string getServerConf($var)
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
When connecting to a server, it will send these lines upon connection:
|
|
||||||
NETWORK=Rizon STATUSMSG=@%+ MODES=4 CHANLIMIT=#:30 MAXCHANNELS=30 MAXLIST=beI:100 MAXBANS=100 MAXTARGETS=4 NICKLEN=30 TOPICLEN=400 KICKLEN=400 CHANNELLEN=50 AWAYLEN=90 are supported by this server
|
|
||||||
CHANTYPES=# KNOCK EXCEPTS INVEX PREFIX=(ohv)@%+ CHANMODES=eIb,k,l,cimnpstMNORZ CASEMAPPING=rfc1459 CALLERID WALLCHOPS FNC PENALTY ETRACE are supported by this server
|
|
||||||
|
|
||||||
(These are just samples). So, you can retrieve the value for say, CHANMODES by doing this:
|
|
||||||
|
|
||||||
getServerConf("CHANMODES");
|
|
||||||
|
|
||||||
This will return a string, "eIb,k,l,cimnpstMNORZ".
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
string getStatusString($status)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
After using getStatusRaw(), you can feed its value to this function, and it'll send back what it means, like "Connecting to Server..."
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
string getClientIP($long = 1)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
This function returns the IP that the bot is using. if you specify $long as 1, then the ip address converted to long integer form is returned.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
class getChannelData($channel)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
This will search the channel database for the channel $channel, and then if it finds it, it will return that channels object. See the "channelLink" class in defines.php for member information.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
class getUserData($user, $channel = "")
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
If a channel is specified, this will search the channel for the specified user's data. If it is found, it will return it as an object. See the "memberLink" class in defines.php for member information. If no channel is specified, this will search the entire channel database until the member is found, and then return that object.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void disconnect()
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Disconnect the bot from the server...
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void setClientConfigVar($var, $value)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
This will overwrite a configuration setting from bot.conf that the bot is currently using. Self-explanitory.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void joinChannel($chan)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Join the channel $chan
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void sendRaw($text, $force = false)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Send the raw text $text to the server. If $force is true, then the data is sent RIGHT away, it totally bypasses the queue, everything. It goes right to the send function, even through the socket class. Use this if you need lightning fast responses, such as writing a channel guard script.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void privMsg($who, $msg, $queue = 1)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
$who = nick of user/name of channel
|
|
||||||
|
|
||||||
Send text to a channel or user. If $queue is 1, then the data will be put at the end of the text queue, if it is 0, it'll be pushed onto the beginning of the queue.
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void action($who, $msg, $queue = 1)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Same as privMsg... emulates the /me command from mIRC
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void notice($who, $msg, $queue = 1)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Same as privMsg, except a notice.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void log($text)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Write something to the log file.
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void maintainChannel($channel, $key = "")
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Attempt to stay in channel $channel. The bot will attempt rejoining every 60 seconds. You may specify a $key or leave it blank.
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void removeMaintain($channel)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
No longer attempt to say in channel $channel.
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void addQuery($host, $port, $query, $line, $class, $function)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Also make sure you read the text about this function in the readme.txt, "Querying remote servers". This function takes 6 arguments.
|
|
||||||
|
|
||||||
$host = the host machine you want to connect to
|
|
||||||
$port = the port you want to connect to
|
|
||||||
$query = the raw data that will be sent to the server upon connection
|
|
||||||
$line = the $line argument that was passed to your module's function (just pass this right along with addQuery)
|
|
||||||
$class = usually '$this'..
|
|
||||||
$function = the function to run after the query is complete.
|
|
||||||
|
|
||||||
See sections 8 and 9 of readme.txt for information related to writing 'query' function types.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int getStatusRaw()
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Returns an integer corresponding to current server status. See defines.php for meanings
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool changeMode($chan, $act, $mode, $user)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Changes the mode of $user on $chan
|
|
||||||
|
|
||||||
$act = either "+" or "-"
|
|
||||||
$mode = some mode, like "o" (ops), or "b" (ban), or something else.
|
|
||||||
$user = whatever the mode is being applied to
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool isOnline($nick, $chan)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Send back whether the nick is on the channel $chan (true or false)
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool isMode($nick, $channel, $mode)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
See if some $user has some $mode activated on him in $channel
|
|
||||||
|
|
||||||
$user = nick of user
|
|
||||||
$mode = any mode, such as "o", "h", "v"
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool isChanMode($channel, $mode, $extra = "")
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Sends back whether a specific mode is set in a channel
|
|
||||||
|
|
||||||
$mode = "b" or "s" or any other chan mode
|
|
||||||
|
|
||||||
$extra = (if you're using "b" for $mode, specify mask here)
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool hasModeSet($chan, $nick, $modes)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
If any of the modes specified in "$modes" are set on a user in a channel, this will return true.
|
|
||||||
For instance:
|
|
||||||
|
|
||||||
If Manick is +vo in channel #manekian,
|
|
||||||
|
|
||||||
hasModeSet("#manekian", "Manick", "oh")
|
|
||||||
|
|
||||||
will return true. I'm asking php-irc if Manick is either mode o or mode h. Which he's mode o, so it returns true.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool hostMasksMatch($mask1, $mask2)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Use this to determine whether two host masks match
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool checkIgnore($mask)
|
|
||||||
----------------------------------
|
|
||||||
Check whether a hostmask is on the bot.conf ignore list.
|
|
||||||
|
|
||||||
|
|
||||||
socket.php (Accessed with $this->socketClass->)
|
|
||||||
-----------------------------------------------
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
string getHost($sockInt)
|
|
||||||
----------------------------------
|
|
||||||
Return the IP address of the current socket integer of a connection. You can use connection::getSockInt() to get the sock int.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
string getQueue($sockInt)
|
|
||||||
----------------------------------
|
|
||||||
Retrieve the current read queue for a socket. The queue is then purged.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
string getQueueLine($sockInt)
|
|
||||||
----------------------------------
|
|
||||||
Get the next line in the queue, purging it from the read buffer and returning it (without crlf)
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int sendSocket($sockInt, $data)
|
|
||||||
----------------------------------
|
|
||||||
Send data to a socket
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int getSockStatus($sockInt)
|
|
||||||
----------------------------------
|
|
||||||
Get the status of a socket. See defines.php for list of constants.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
object getSockData($sockInt)
|
|
||||||
----------------------------------
|
|
||||||
Return the object that retains all data about socket "$sockInt". This is a php-irc maintained list.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool hasWriteQueue($sockInt)
|
|
||||||
----------------------------------
|
|
||||||
Return true or false depending on whether the bot has data to write to the socket. If this is true, you should restrain yourself from sending more data to the socket. An onWrite() call will be sent every time data is written, and each time "hasWriteQueue()" should be called to see if the queue is empty before sending data.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool hasLine($sockInt)
|
|
||||||
----------------------------------
|
|
||||||
Return true or false depending on if there is a newline in the buffer.
|
|
||||||
|
|
||||||
|
|
||||||
timers.php (Accessed with $this->timerClass->)
|
|
||||||
----------------------------------------------
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
class addTimer($name, $class, $function, $args, $interval, $runRightAway = false)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Add a timer. Please view the readme.txt documentation on this.
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
class getTimers()
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
This function will return a pointer to all the active timers. See the class "timer" in defines.php for member information.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void removeTimer($timer) (MUST be timer name)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Remove a timer $timer <-- can only be the name of timer, unlike in 2.1.1 where it could be the object itself.
|
|
||||||
|
|
||||||
|
|
||||||
mysql/postgre.php (Accessed with $this->db->)
|
|
||||||
---------------------------------------------
|
|
||||||
Some items for postgre aren't fully implemented or work yet... most notably queryFetch(), and some others. See postgre.php for more details.
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
array queryFetch($query)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Runs a query and returns the first row. Basically does query() and then mysql_fetch_array()
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
array fetchArray($object)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Does mysql_fetch_array() (see php.net for help)
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
array fetchRow($object)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Does mysql_fetch_row()
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
string getError()
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Does mysql_error();
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool isConnected()
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Returns whether the database is connected
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int lastID()
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Gets the last inserted 'id' row from the database.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int numRows($toFetch)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Does mysql_num_rows()
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int numQueries()
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
sends back an integer of all the queries since the database class was spawned.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void close()
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Closes the database connection
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
object query($query)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Runs a query, and returns the result as an object.
|
|
||||||
|
|
||||||
|
|
||||||
dcc.php (Accessed with $this->dccClass->)
|
|
||||||
-----------------------------------------
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
array getDccList()
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Returns an array of all current dcc's in progress (chat and file)
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int getDownloadCount()
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Number of all current downloads
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int getUploadCount()
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Number of all current uploads
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int getChatCount()
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Number of all current dcc chat sessions
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int getBytesDown()
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Returns number of bytes downloaded since bot was started
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int getBytesUp()
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Returns number of bytes uploaded since bot was started
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int addChat($nick, $host, $port, $admin, $handler)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Use this to create a dcc chat session.
|
|
||||||
|
|
||||||
$nick = nick of user to chat with
|
|
||||||
$host = host of user to chat with
|
|
||||||
$port = port to connect to
|
|
||||||
$admin = whether the user is admin (use admin dcc chat administration)
|
|
||||||
$handler = null, usually, unless you are creating a custom dcc chat handler. See readme.txt for more information.
|
|
||||||
|
|
||||||
If $host or $port is null, then addChat will think you are setting up a listening connection, otherwise it will try to connect to the host/port specified.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int addFile($nick, $host, $port, $type, $filename, $size)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Send a file to someone, or recieve a file.
|
|
||||||
|
|
||||||
$nick = nick of person sending/receiving file
|
|
||||||
$host = host of person sending/receiving file
|
|
||||||
$port = port of transfer
|
|
||||||
$type = either UPLOAD or DOWNLOAD
|
|
||||||
$filename = full filename with full path to file
|
|
||||||
$size = size of the file, can be null if its an UPLOAD type.
|
|
||||||
|
|
||||||
See readme.txt for more information regarding file transfers.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int sendFile($nick, $file)
|
|
||||||
----------------------------------
|
|
||||||
Alias for addFile($nick, null, null, UPLOAD, $file, null)... basically just an easier way of sending files.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
class getDcc($dcc)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
$dcc = sockInt of the transfer
|
|
||||||
|
|
||||||
Returns dcc object for some sockInt, see fileserver.php for example.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void dccInform($text)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Send a message to all administrators
|
|
||||||
|
|
||||||
|
|
||||||
chat.php
|
|
||||||
----------
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void disconnect($msg = "")
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
End the chat session
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void dccSend($msg)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Send text to the user
|
|
||||||
|
|
||||||
|
|
||||||
file.php
|
|
||||||
----------
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
void disconnect($msg = "")
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
End the dcc file transfer session
|
|
||||||
|
|
||||||
|
|
||||||
ini.php
|
|
||||||
----------
|
|
||||||
Please see readme.txt for more information on create ini objects.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool getError()
|
|
||||||
----------------------------------
|
|
||||||
An ini object will not operate after a fatal error. You can use this to retrieve whether a fatal error has happened.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool sectionExists($section)
|
|
||||||
----------------------------------
|
|
||||||
Return true if the section exists, or false if it doesn't.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool deleteSection($section)
|
|
||||||
----------------------------------
|
|
||||||
Delete a section.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool deleteVar($section, $var)
|
|
||||||
----------------------------------
|
|
||||||
Delete a var in a section.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool setIniVal($section, $var, $val)
|
|
||||||
----------------------------------
|
|
||||||
Set the '$var' value '$val' in section $section.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
bool writeIni()
|
|
||||||
----------------------------------
|
|
||||||
Write all of the ini changes to a file
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
array getSections()
|
|
||||||
----------------------------------
|
|
||||||
Return an array of all the section names.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
array getVars($section)
|
|
||||||
----------------------------------
|
|
||||||
Return all the vars/vals in an associative array for $section.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
array getSection($section)
|
|
||||||
----------------------------------
|
|
||||||
Alias for getVars()
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
array randomSection($num = 1)
|
|
||||||
----------------------------------
|
|
||||||
Does same as getVars(), but returns random section. $num is the number of random sections to return. Default 1.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
array searchSections($search, $type = EXACT_MATCH)
|
|
||||||
----------------------------------
|
|
||||||
Search section names for $search, can do 4 types of searches: Exact, and, or, contains:
|
|
||||||
|
|
||||||
Exact: the section and search match completely
|
|
||||||
And: the section name contains all componants of search (separated by space)
|
|
||||||
Or: the section name contains at least one of the componants of search (separated by space)
|
|
||||||
Contains: the section contains the search string within it
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
array searchVars($section, $search, $type = EXACT_MATCH)
|
|
||||||
----------------------------------
|
|
||||||
Search the variable names of a section for $search, same as searchSections() except with vars.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
array searchSectionsByVar($var, $search, $type = EXACT_MATCH)
|
|
||||||
----------------------------------
|
|
||||||
In every section that has '$var' as a varaible, see if the var's value matches $search.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
array searchVals($section, $search, $type = EXACT_MATCH)
|
|
||||||
----------------------------------
|
|
||||||
Search all the values of a section for '$search'. Return list of vars.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
mixed randomVar($section, $num = 1)
|
|
||||||
----------------------------------
|
|
||||||
Return a random var in a section.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
mixed getIniVal($section, $var)
|
|
||||||
----------------------------------
|
|
||||||
Retrieve an ini value '$var' in section '$section'. False if non-existant.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int numSections()
|
|
||||||
----------------------------------
|
|
||||||
Return number of sections.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
int numVars($section)
|
|
||||||
----------------------------------
|
|
||||||
Return number of vars in a section.
|
|
||||||
|
|
||||||
|
|
||||||
Useful Static Routines
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
string socket::generatePostQuery($query, $host, $path, $httpVersion = "")
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Takes a query, like so:
|
|
||||||
|
|
||||||
$query = "search=blah&somesetting=5";
|
|
||||||
|
|
||||||
And turns it into a POST query you can send off to addQuery
|
|
||||||
|
|
||||||
$host = host of server you will be accessing, like "www.manekian.com"
|
|
||||||
$path = script + path of script you will be accessing, like "/search.php" or "/index.php", or just "/"
|
|
||||||
$httpVersion, you can ignore this, but sometimes you might want to set this to "1.0"
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
string socket::generateGetQuery($query, $host, $path, $httpVersion)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Same as generatePostQuery except with Get String
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
string irc::intToSizeString($size)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Takes a large size, and then changes it into MB, GB, KB, depending on the size.
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
string irc::myStrToLower($text)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
RFC1459 complient strtolower()
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
string irc::myStrToUpper($text)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
RFC1459 complient strtoupper()
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
string irc::timeFormat($time, $format)
|
|
||||||
----------------------------------
|
|
||||||
Feed this thing a timestring, and a format, and it'll send back a user friendly representation of the timestamp.
|
|
||||||
|
|
||||||
for example:
|
|
||||||
|
|
||||||
timeFormat(5, "%d days, %h hours, %m minutes, %s seconds")
|
|
||||||
|
|
||||||
This will return a string, "0 days, 0 hours, 0 minutes, 5 seconds".
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
string irc::randomHash()
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Generates a 32 char random md5 hash
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------
|
|
||||||
array irc::multiLine($text)
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Feed this a huge text string, and it will split it up into 255 max char increment lines you can send to the irc server. It returns an array of all of these.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,432 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.1.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2004 by http://www.phpbots.org/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > connection class module
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.1.2
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Connection class. A Layer between dcc/irc class and socket class. */
|
|
||||||
/* To use, simply create an object, call the calls listed under the constructor in order. */
|
|
||||||
/* Damn I'm hungry... */
|
|
||||||
|
|
||||||
class connection {
|
|
||||||
|
|
||||||
//External Classes
|
|
||||||
private $socketClass;
|
|
||||||
private $ircClass;
|
|
||||||
private $timerClass;
|
|
||||||
|
|
||||||
//Internal variables
|
|
||||||
private $callbackClass;
|
|
||||||
private $host;
|
|
||||||
private $port;
|
|
||||||
private $connTimeout;
|
|
||||||
private $transTimeout;
|
|
||||||
private $sockInt;
|
|
||||||
|
|
||||||
//Function specific
|
|
||||||
private $connected;
|
|
||||||
private $connStartTime;
|
|
||||||
private $lastTransTime;
|
|
||||||
|
|
||||||
//If this is set to true, this connection class will no longer function.
|
|
||||||
private $error;
|
|
||||||
private $errorMsg;
|
|
||||||
|
|
||||||
//Called first
|
|
||||||
function __construct($host, $port, $connTimeout)
|
|
||||||
{
|
|
||||||
$this->error = true;
|
|
||||||
$this->errorMsg = "Connection not initialized";
|
|
||||||
$this->host = $host;
|
|
||||||
$this->port = $port;
|
|
||||||
$this->connTimeout = $connTimeout;
|
|
||||||
$this->transTimeout = 0;
|
|
||||||
$this->connected = false;
|
|
||||||
$this->sockInt = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Called second
|
|
||||||
public function setSocketClass($class)
|
|
||||||
{
|
|
||||||
$this->socketClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Called third
|
|
||||||
public function setIrcClass($class)
|
|
||||||
{
|
|
||||||
$this->ircClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Called fourth
|
|
||||||
public function setCallbackClass($class)
|
|
||||||
{
|
|
||||||
$this->callbackClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Called fifth
|
|
||||||
public function setTimerClass($class)
|
|
||||||
{
|
|
||||||
$this->timerClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Called sixth
|
|
||||||
public function init()
|
|
||||||
{
|
|
||||||
$this->error = false;
|
|
||||||
|
|
||||||
if ($this->host != null)
|
|
||||||
{
|
|
||||||
if ($this->connTimeout <= 0)
|
|
||||||
{
|
|
||||||
$this->setError("Must set connection timeout > 0 for non-listening sockets");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($this->connTimeout < 0)
|
|
||||||
{
|
|
||||||
$this->setError("Must set connection timeout >= 0 for listening sockets");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_object($this->callbackClass))
|
|
||||||
{
|
|
||||||
$this->setError("Specified callback class is not an object");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_object($this->socketClass))
|
|
||||||
{
|
|
||||||
$this->setError("Specified socket class is not an object");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_object($this->ircClass))
|
|
||||||
{
|
|
||||||
$this->setError("Specified irc class is not an object");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sockInt = $this->socketClass->addSocket($this->host, $this->port); // add socket
|
|
||||||
if ($sockInt == false)
|
|
||||||
{
|
|
||||||
$this->setError("Could not create socket");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sockData = $this->socketClass->getSockData($sockInt);
|
|
||||||
|
|
||||||
$this->socketClass->setHandler($sockInt, $this->ircClass, $this, "handle");
|
|
||||||
|
|
||||||
//Set internal variables
|
|
||||||
if ($this->port == NULL)
|
|
||||||
{
|
|
||||||
$this->port = $sockData->port;
|
|
||||||
}
|
|
||||||
$this->sockInt = $sockInt;
|
|
||||||
|
|
||||||
return $this->port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function bind($ip)
|
|
||||||
{
|
|
||||||
if ($this->error != false || $this->sockInt == false)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->connected == true)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->socketClass->bindIP($this->sockInt, $ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Called to listen, only called by onAccept() function in this class
|
|
||||||
public function listen()
|
|
||||||
{
|
|
||||||
$this->error = false;
|
|
||||||
$this->connected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Called last, and only to start connection to another server
|
|
||||||
public function connect()
|
|
||||||
{
|
|
||||||
if ($this->error == true)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->connTimeout > 0)
|
|
||||||
{
|
|
||||||
$this->timerClass->addTimer(irc::randomHash(), $this, "connTimeout", "", $this->connTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->timerClass->addTimer(irc::randomHash(), $this->socketClass, "connectSocketTimer", $this->sockInt, 1);
|
|
||||||
|
|
||||||
/* $this->socketClass->beginConnect($this->sockInt); */
|
|
||||||
$this->connStartTime = time();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function disconnect()
|
|
||||||
{
|
|
||||||
unset($this->callbackClass);
|
|
||||||
$this->socketClass->killSocket($this->sockInt);
|
|
||||||
$this->socketClass->removeSocket($this->sockInt);
|
|
||||||
$this->setError("Disconnected from server");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSockInt()
|
|
||||||
{
|
|
||||||
return $this->sockInt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setSockInt($sockInt)
|
|
||||||
{
|
|
||||||
$this->sockInt = $sockInt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTransTimeout($time)
|
|
||||||
{
|
|
||||||
$this->transTimeout = ($time < 0 ? 0 : $time);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Timers */
|
|
||||||
|
|
||||||
public function connTimeout()
|
|
||||||
{
|
|
||||||
if ($this->connected == false)
|
|
||||||
{
|
|
||||||
$this->handle(CONN_CONNECT_TIMEOUT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function transTimeout()
|
|
||||||
{
|
|
||||||
if ($this->error == true)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->connected == false)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->transTimeout > 0)
|
|
||||||
{
|
|
||||||
if (time() > $this->transTimeout + $this->lastTransTime)
|
|
||||||
{
|
|
||||||
$this->handle(CONN_TRANSFER_TIMEOUT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//handle function, handles all calls from socket class, and calls appropriate
|
|
||||||
//functions in the callback class
|
|
||||||
public function handle($msg)
|
|
||||||
{
|
|
||||||
|
|
||||||
if ($this->socketClass->getSockStatus($this->sockInt) === false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$stat = false;
|
|
||||||
|
|
||||||
if ($this->error == true)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($msg)
|
|
||||||
{
|
|
||||||
case CONN_CONNECT:
|
|
||||||
$stat = $this->onConnect();
|
|
||||||
break;
|
|
||||||
case CONN_READ:
|
|
||||||
$stat = $this->onRead();
|
|
||||||
break;
|
|
||||||
case CONN_WRITE:
|
|
||||||
$stat = $this->onWrite();
|
|
||||||
break;
|
|
||||||
case CONN_ACCEPT:
|
|
||||||
$stat = $this->onAccept();
|
|
||||||
break;
|
|
||||||
case CONN_DEAD:
|
|
||||||
$stat = $this->onDead();
|
|
||||||
break;
|
|
||||||
case CONN_TRANSFER_TIMEOUT:
|
|
||||||
$stat = $this->onTransferTimeout();
|
|
||||||
break;
|
|
||||||
case CONN_CONNECT_TIMEOUT:
|
|
||||||
$stat = $this->onConnectTimeout();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $stat;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Specific handling functions */
|
|
||||||
|
|
||||||
private function onTransferTimeout()
|
|
||||||
{
|
|
||||||
$this->callbackClass->onTransferTimeout($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onConnectTimeout()
|
|
||||||
{
|
|
||||||
$this->callbackClass->onConnectTimeout($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onConnect()
|
|
||||||
{
|
|
||||||
$this->connected = true;
|
|
||||||
|
|
||||||
if ($this->transTimeout > 0)
|
|
||||||
{
|
|
||||||
$this->timerClass->addTimer(irc::randomHash(), $this, "transTimeout", "", $this->transTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->callbackClass->onConnect($this);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//For this function, true can be returned from onRead() to input more data.
|
|
||||||
private function onRead()
|
|
||||||
{
|
|
||||||
$this->lastTransTime = time();
|
|
||||||
|
|
||||||
$stat = $this->callbackClass->onRead($this);
|
|
||||||
if ($stat !== true)
|
|
||||||
{
|
|
||||||
$this->socketClass->clearReadSchedule($this->sockInt);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $stat;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onWrite()
|
|
||||||
{
|
|
||||||
$this->socketClass->clearWriteSchedule($this->sockInt);
|
|
||||||
$this->lastTransTime = time();
|
|
||||||
$this->callbackClass->onWrite($this);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onAccept()
|
|
||||||
{
|
|
||||||
//Get the sockInt from the socketClass
|
|
||||||
$newSockInt = $this->socketClass->hasAccepted($this->sockInt);
|
|
||||||
|
|
||||||
if ($newSockInt === false)
|
|
||||||
{
|
|
||||||
//False alarm.. just ignore it.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Create a new connection object for the new socket connection, then return it to onAccept
|
|
||||||
//We must assume that onAccept will handle the connection object. Otherwise it'll die, and the
|
|
||||||
//connection will be orphaned.
|
|
||||||
|
|
||||||
$newConn = new connection(null, null, 0);
|
|
||||||
$newConn->setSocketClass($this->socketClass);
|
|
||||||
$newConn->setIrcClass($this->ircClass);
|
|
||||||
$newConn->setCallbackClass($this->callbackClass); //Can be overwritten in the onAccept function
|
|
||||||
$newConn->setTimerClass($this->timerClass);
|
|
||||||
$newConn->listen();
|
|
||||||
//We don't need to call init(), we're already setup.
|
|
||||||
|
|
||||||
//Setup our connection transmission timeout thing.
|
|
||||||
if ($this->transTimeout > 0)
|
|
||||||
{
|
|
||||||
$this->timerClass->addTimer(irc::randomHash(), $newConn, "transTimeout", "", $this->transTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
$newConn->setTransTimeout($this->transTimeout);
|
|
||||||
|
|
||||||
//Set handler for our new sockInt to new connection class
|
|
||||||
$this->socketClass->setHandler($newSockInt, $this->ircClass, $newConn, "handle");
|
|
||||||
|
|
||||||
//Set our new sockInt
|
|
||||||
$newConn->setSockInt($newSockInt);
|
|
||||||
|
|
||||||
//Call our callback function for accepting with old object, and new object.
|
|
||||||
$this->callbackClass->onAccept($this, $newConn);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onDead()
|
|
||||||
{
|
|
||||||
if ($this->connected == true)
|
|
||||||
{
|
|
||||||
$this->setError("Connection is dead");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->setError("Could not connect: " . $this->socketClass->getSockStringError($this->sockInt));
|
|
||||||
}
|
|
||||||
$this->callbackClass->onDead($this);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Error handling routines */
|
|
||||||
|
|
||||||
private function setError($msg)
|
|
||||||
{
|
|
||||||
$this->error = true;
|
|
||||||
$this->errorMsg = $msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getError()
|
|
||||||
{
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getErrorMsg()
|
|
||||||
{
|
|
||||||
return $this->errorMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
|
@ -1,515 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2005 by http://phpbots.sf.net/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > ini-file database module
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.2.1 alpha
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
class ini {
|
|
||||||
|
|
||||||
private $filename;
|
|
||||||
private $error;
|
|
||||||
private $ini = array();
|
|
||||||
private $numSections;
|
|
||||||
|
|
||||||
//used in isMatched()
|
|
||||||
private $search;
|
|
||||||
private $searchParts;
|
|
||||||
|
|
||||||
|
|
||||||
//Load ini into memory
|
|
||||||
public function __construct($filename)
|
|
||||||
{
|
|
||||||
$this->error = false;
|
|
||||||
$this->filename = $filename;
|
|
||||||
|
|
||||||
$filePtr = @fopen($filename, "r");
|
|
||||||
|
|
||||||
if ($filePtr === false)
|
|
||||||
{
|
|
||||||
$filePtr = @fopen($filename, "a");
|
|
||||||
|
|
||||||
if ($filePtr === false)
|
|
||||||
{
|
|
||||||
$this->error = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fclose($filePtr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$fileData = "";
|
|
||||||
|
|
||||||
while (!feof($filePtr))
|
|
||||||
{
|
|
||||||
$fileData .= fread($filePtr, 4096);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose($filePtr);
|
|
||||||
|
|
||||||
$fileData = str_replace("\r", "", $fileData);
|
|
||||||
|
|
||||||
$lines = explode("\n", $fileData);
|
|
||||||
|
|
||||||
$currSection = "";
|
|
||||||
$this->numSections = 0;
|
|
||||||
|
|
||||||
foreach($lines AS $line)
|
|
||||||
{
|
|
||||||
$line = trim($line);
|
|
||||||
|
|
||||||
$offsetA = strpos($line, "[");
|
|
||||||
$offsetB = strpos($line, "]");
|
|
||||||
|
|
||||||
if ($offsetA === 0)
|
|
||||||
{
|
|
||||||
$currSection = substr($line, 1, $offsetB - 1);
|
|
||||||
$this->numSections++;
|
|
||||||
$this->ini[$currSection] = array();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($currSection != "")
|
|
||||||
{
|
|
||||||
$offsetC = strpos($line, "=");
|
|
||||||
|
|
||||||
if ($offsetC !== false)
|
|
||||||
{
|
|
||||||
$var = trim(substr($line, 0, $offsetC));
|
|
||||||
$val = substr($line, $offsetC + 1);
|
|
||||||
|
|
||||||
if ($var != "")
|
|
||||||
{
|
|
||||||
$this->ini[$currSection][$var] = $val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->ini[$currSection][$line] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getError()
|
|
||||||
{
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSections()
|
|
||||||
{
|
|
||||||
$sections = array();
|
|
||||||
|
|
||||||
if ($this->numSections == 0)
|
|
||||||
{
|
|
||||||
return $sections;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->ini AS $section => $vals)
|
|
||||||
{
|
|
||||||
$sections[] = $section;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $sections;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getVars($section)
|
|
||||||
{
|
|
||||||
if (!isset($this->ini[$section]))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->ini[$section];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function sectionExists($section)
|
|
||||||
{
|
|
||||||
if (isset($this->ini[$section]) && is_array($this->ini[$section]))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSection($section)
|
|
||||||
{
|
|
||||||
return $this->getVars($section);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function randomSection($num = 1)
|
|
||||||
{
|
|
||||||
if ($this->numSections == 0 || $num < 1 || $num > $this->numSections)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_rand($this->ini, $num);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function randomVar($section, $num = 1)
|
|
||||||
{
|
|
||||||
if (!isset($this->ini[$section]))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$count = count($this->ini[$section]);
|
|
||||||
|
|
||||||
if ($count == 0 || $num < 1 || $num > $count)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_rand($this->ini[$section], $num);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function searchSections($search, $type = EXACT_MATCH)
|
|
||||||
{
|
|
||||||
$results = array();
|
|
||||||
|
|
||||||
if (trim($search) == "")
|
|
||||||
{
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->numSections == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($this->ini AS $section => $vars)
|
|
||||||
{
|
|
||||||
if ($this->isMatched($search, $section, $type))
|
|
||||||
{
|
|
||||||
$results[] = $section;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function searchVars($section, $search, $type = EXACT_MATCH)
|
|
||||||
{
|
|
||||||
$results = array();
|
|
||||||
|
|
||||||
if (trim($search) == "")
|
|
||||||
{
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->ini[$section]))
|
|
||||||
{
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->numSections == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($this->ini[$section]) == 0)
|
|
||||||
{
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($this->ini[$section] AS $var => $val)
|
|
||||||
{
|
|
||||||
if ($this->isMatched($search, $var, $type))
|
|
||||||
{
|
|
||||||
$results[] = $var;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function searchSectionsByVar($var, $search, $type = EXACT_MATCH)
|
|
||||||
{
|
|
||||||
$results = array();
|
|
||||||
|
|
||||||
if ($this->numSections == 0)
|
|
||||||
{
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($this->ini AS $section => $vars)
|
|
||||||
{
|
|
||||||
if (isset($vars[$var]))
|
|
||||||
{
|
|
||||||
if ($this->isMatched($search, $vars[$var], $type))
|
|
||||||
{
|
|
||||||
$results[] = $section;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $results;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function searchVals($section, $search, $type = EXACT_MATCH)
|
|
||||||
{
|
|
||||||
$results = array();
|
|
||||||
|
|
||||||
if (trim($search) == "")
|
|
||||||
{
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->ini[$section]))
|
|
||||||
{
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->numSections == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($this->ini[$section]) == 0)
|
|
||||||
{
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($this->ini[$section] AS $var => $val)
|
|
||||||
{
|
|
||||||
if ($this->isMatched($search, $val, $type))
|
|
||||||
{
|
|
||||||
$results[] = $var;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function isMatched(&$needle, &$haystack, $type = EXACT_MATCH)
|
|
||||||
{
|
|
||||||
|
|
||||||
if ($type == EXACT_MATCH)
|
|
||||||
{
|
|
||||||
if ($haystack == $needle)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($type == CONTAINS_MATCH)
|
|
||||||
{
|
|
||||||
if (strpos(strtolower($haystack), strtolower($needle)) !== false)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($search != $this->search)
|
|
||||||
{
|
|
||||||
$this->searchParts = explode(chr(32), $search);
|
|
||||||
$this->search = $search;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($type == AND_MATCH)
|
|
||||||
{
|
|
||||||
$foundAll = true;
|
|
||||||
|
|
||||||
foreach($this->searchParts AS $part)
|
|
||||||
{
|
|
||||||
if (strpos($val, $part) === false)
|
|
||||||
{
|
|
||||||
$foundAll = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($foundAll == true)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ($type == OR_MATCH)
|
|
||||||
{
|
|
||||||
foreach($this->searchParts AS $part)
|
|
||||||
{
|
|
||||||
if (strpos($val, $part) !== false)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function deleteSection($section)
|
|
||||||
{
|
|
||||||
if (isset($this->ini[$section]))
|
|
||||||
{
|
|
||||||
unset($this->ini[$section]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function deleteVar($section, $var)
|
|
||||||
{
|
|
||||||
if (isset($this->ini[$section]))
|
|
||||||
{
|
|
||||||
if (isset($this->ini[$section][$var]))
|
|
||||||
{
|
|
||||||
unset($this->ini[$section][$var]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function numSections()
|
|
||||||
{
|
|
||||||
return $this->numSections;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function numVars($section)
|
|
||||||
{
|
|
||||||
if (isset($this->ini[$section]))
|
|
||||||
{
|
|
||||||
return count($this->ini[$section]);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setIniVal($section, $var, $val)
|
|
||||||
{
|
|
||||||
if ($this->error == true)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->ini[$section]))
|
|
||||||
{
|
|
||||||
$this->numSections++;
|
|
||||||
$this->ini[$section] = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strpos($var, "=") !== false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->ini[$section][$var] = $val;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getIniVal($section, $var)
|
|
||||||
{
|
|
||||||
if ($this->error == true)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($this->ini[$section])
|
|
||||||
&& isset($this->ini[$section][$var]))
|
|
||||||
{
|
|
||||||
return $this->ini[$section][$var];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Update and write ini to file
|
|
||||||
public function writeIni()
|
|
||||||
{
|
|
||||||
if ($this->error == true)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->numSections == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = "";
|
|
||||||
|
|
||||||
foreach ($this->ini AS $section => $vars)
|
|
||||||
{
|
|
||||||
|
|
||||||
$output .= "[" . $section . "]\n";
|
|
||||||
|
|
||||||
if (count($vars))
|
|
||||||
{
|
|
||||||
foreach ($vars AS $var => $val)
|
|
||||||
{
|
|
||||||
$output .= $var . "=" . $val . "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$filePtr = fopen($this->filename, "at");
|
|
||||||
|
|
||||||
if ($filePtr === false)
|
|
||||||
{
|
|
||||||
$this->error = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
flock($filePtr, LOCK_EX);
|
|
||||||
|
|
||||||
ftruncate($filePtr, 0);
|
|
||||||
|
|
||||||
if (fwrite($filePtr, $output) === FALSE)
|
|
||||||
{
|
|
||||||
$this->error = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
flock($filePtr, LOCK_UN);
|
|
||||||
|
|
||||||
fclose($filePtr);
|
|
||||||
|
|
||||||
return !$this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
|
@ -1,169 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2005 by http://phpbots.sf.net/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > database module
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.2.0 alpha1
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
class mysql {
|
|
||||||
|
|
||||||
private $dbIndex;
|
|
||||||
private $prefix;
|
|
||||||
private $queries = 0;
|
|
||||||
private $isConnected = false;
|
|
||||||
|
|
||||||
private $user;
|
|
||||||
private $pass;
|
|
||||||
private $database;
|
|
||||||
private $host;
|
|
||||||
private $port;
|
|
||||||
|
|
||||||
public function __construct($host, $database, $user, $pass, $prefix, $port = 3306)
|
|
||||||
{
|
|
||||||
$this->user = $user;
|
|
||||||
$this->pass = $pass;
|
|
||||||
$this->host = $host;
|
|
||||||
$this->database = $database;
|
|
||||||
$this->port = $port;
|
|
||||||
|
|
||||||
$db = mysql_connect($host . ":" . $port, $user, $pass);
|
|
||||||
|
|
||||||
if (!$db)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$dBase = mysql_select_db($database, $db);
|
|
||||||
|
|
||||||
if (!$dBase)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->prefix = $prefix;
|
|
||||||
$this->dbIndex = $db;
|
|
||||||
$this->isConnected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getError()
|
|
||||||
{
|
|
||||||
return (@mysql_error($this->dbIndex));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isConnected()
|
|
||||||
{
|
|
||||||
return $this->isConnected;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Call by reference switched to function declaration, 05/13/05
|
|
||||||
private function fixVar($id, &$values)
|
|
||||||
{
|
|
||||||
return mysql_real_escape_string($values[intval($id)-1], $this->dbIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function query($query, $values = array())
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!is_array($values))
|
|
||||||
$values = array($values);
|
|
||||||
|
|
||||||
$query = preg_replace('/\[([0-9]+)]/e', "\$this->fixVar(\\1, \$values)", $query);
|
|
||||||
|
|
||||||
$this->queries++;
|
|
||||||
|
|
||||||
$data = mysql_query($query, $this->dbIndex);
|
|
||||||
|
|
||||||
if (!$data)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function queryFetch($query, $values = array())
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!is_array($values))
|
|
||||||
$values = array($values);
|
|
||||||
|
|
||||||
$query = preg_replace('/\[([0-9]+)]/e', "\$this->fixVar(\\1, &\$values)", $query);
|
|
||||||
|
|
||||||
$this->queries++;
|
|
||||||
|
|
||||||
$data= mysql_query($query, $this->dbIndex);
|
|
||||||
|
|
||||||
if (!$data)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mysql_fetch_array($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function fetchArray($toFetch)
|
|
||||||
{
|
|
||||||
return mysql_fetch_array($toFetch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fetchRow($toFetch)
|
|
||||||
{
|
|
||||||
return mysql_fetch_row($toFetch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function close()
|
|
||||||
{
|
|
||||||
@mysql_close($this->dbIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function lastID()
|
|
||||||
{
|
|
||||||
return mysql_insert_id();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function numRows($toFetch)
|
|
||||||
{
|
|
||||||
return mysql_num_rows($toFetch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function numQueries()
|
|
||||||
{
|
|
||||||
return $this->queries;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
@ -1,162 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2005 by http://phpbots.sf.net/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > database module
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.1.1
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
class postgre {
|
|
||||||
|
|
||||||
private $dbIndex;
|
|
||||||
private $prefix;
|
|
||||||
private $queries = 0;
|
|
||||||
private $isConnected = false;
|
|
||||||
private $error;
|
|
||||||
|
|
||||||
public function __construct($host, $database, $user, $pass, $prefix, $port = 5432)
|
|
||||||
{
|
|
||||||
$this->error = true;
|
|
||||||
|
|
||||||
$connect = "host=" . $host . " ".
|
|
||||||
"port=" . $port . " ".
|
|
||||||
"dbname=" . $database . " ".
|
|
||||||
"user=" . $user . " ".
|
|
||||||
"password=" . $pass;
|
|
||||||
|
|
||||||
$this->error = pg_connect($connect);
|
|
||||||
|
|
||||||
if (!$this->error)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->prefix = $prefix;
|
|
||||||
$this->dbIndex = $this->error;
|
|
||||||
$this->isConnected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getError()
|
|
||||||
{
|
|
||||||
return $this->error === false ? true : false;
|
|
||||||
//return (@mysql_error($this->dbIndex));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isConnected()
|
|
||||||
{
|
|
||||||
return $this->isConnected;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function fixVar($id, $values)
|
|
||||||
{
|
|
||||||
return pg_escape_string($values[intval($id)-1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function query($query, $values = array())
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!is_array($values))
|
|
||||||
$values = array($values);
|
|
||||||
|
|
||||||
$query = preg_replace('/\[([0-9]+)]/e', "\$this->fixVar(\\1, &\$values)", $query);
|
|
||||||
|
|
||||||
$this->queries++;
|
|
||||||
|
|
||||||
$data = pg_query($this->dbIndex, $query);
|
|
||||||
|
|
||||||
if (!$data)
|
|
||||||
{
|
|
||||||
$this->error = $data;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function queryFetch($query, $values = array())
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!is_array($values))
|
|
||||||
$values = array($values);
|
|
||||||
|
|
||||||
$query = preg_replace('/\[([0-9]+)]/e', "\$this->fixVar(\\1, &\$values)", $query);
|
|
||||||
|
|
||||||
$this->queries++;
|
|
||||||
|
|
||||||
$data = pg_query($query, $this->dbIndex);
|
|
||||||
|
|
||||||
if (!$data)
|
|
||||||
{
|
|
||||||
$this->error = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pg_fetch_array($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function fetchArray($toFetch)
|
|
||||||
{
|
|
||||||
return pg_fetch_array($toFetch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fetchRow($toFetch)
|
|
||||||
{
|
|
||||||
return pg_fetch_row($toFetch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function close()
|
|
||||||
{
|
|
||||||
@pg_close($this->dbIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function lastID()
|
|
||||||
{
|
|
||||||
//ehhh. don't use this.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function numRows($toFetch)
|
|
||||||
{
|
|
||||||
return pg_num_rows($toFetch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function numQueries()
|
|
||||||
{
|
|
||||||
return $this->queries;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
@ -1,148 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2005 by http://phpbots.sf.net/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > database module
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.1.1
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
// *** Modified by Nemesis128_at_atarax_dot_org
|
|
||||||
|
|
||||||
class postgresql {
|
|
||||||
|
|
||||||
private $dbRes;
|
|
||||||
private $prefix;
|
|
||||||
private $numQueries = 0;
|
|
||||||
private $isConnected = false;
|
|
||||||
private $error = false;
|
|
||||||
|
|
||||||
private $user;
|
|
||||||
private $pswd;
|
|
||||||
private $dbase;
|
|
||||||
private $host;
|
|
||||||
private $port;
|
|
||||||
|
|
||||||
public function __construct ($user,$pswd,$dbase,$prefix,$host = null,$port = 5432) {
|
|
||||||
|
|
||||||
$this->user = $user;
|
|
||||||
$this->pswd = $pswd;
|
|
||||||
$this->dbase = $dbase;
|
|
||||||
$this->prefix = $prefix;
|
|
||||||
$this->host = $host;
|
|
||||||
$this->port = $port;
|
|
||||||
|
|
||||||
$conn_str = '';
|
|
||||||
|
|
||||||
if (!is_null($host)) { // connect thru TCP/IP
|
|
||||||
$conn_str .= 'host='.$host;
|
|
||||||
$conn_str .= ' port='.$port;
|
|
||||||
} // else thru intern sockets
|
|
||||||
$conn_str .= ' user='.$user;
|
|
||||||
$conn_str .= ' password='.$pswd;
|
|
||||||
$conn_str .= ' dbname='.$dbase;
|
|
||||||
|
|
||||||
$this->dbRes = pg_connect($conn_str);
|
|
||||||
|
|
||||||
if (!is_resource($this->dbRes)) {
|
|
||||||
$this->error = 'PgSQL Connection error';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->isConnected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getError () {
|
|
||||||
if ($this->error) {
|
|
||||||
$err = $this->error."\n\n";
|
|
||||||
return ($err.@pg_last_error($this->dbIndex));
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isConnected () {
|
|
||||||
return $this->isConnected;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function esc ( $var ) {
|
|
||||||
return pg_escape_string ( $var );
|
|
||||||
}
|
|
||||||
|
|
||||||
public function query ( $query_str ) {
|
|
||||||
|
|
||||||
if (pg_connection_status($this->dbRes) === PGSQL_CONNECTION_BAD) {
|
|
||||||
if (!pg_connection_reset($this->dbRes)) {
|
|
||||||
$this->error = 'Connection lost';
|
|
||||||
$this->isConnected = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->numQueries++;
|
|
||||||
|
|
||||||
$res = @pg_query($this->dbRes,$query_str);
|
|
||||||
|
|
||||||
if (!$res) {
|
|
||||||
$this->error = 'Query failed: '.pg_last_error().' ('.$query_str.')';
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fetchArray ( $toFetch ) {
|
|
||||||
return pg_fetch_assoc($toFetch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fetchObject ( $toFetch ) {
|
|
||||||
return pg_fetch_object($toFetch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fetchRow ( $toFetch ) {
|
|
||||||
return pg_fetch_row($toFetch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function numRows ( $toFetch ) {
|
|
||||||
return pg_num_rows($toFetch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function numQueries () {
|
|
||||||
return $this->numQueries;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function close () {
|
|
||||||
@pg_close($this->dbRes);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
579
ircbot/dcc.php
579
ircbot/dcc.php
|
@ -1,579 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2005 by http://www.phpbots.org/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > dcc module
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.2.0
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
class dcc {
|
|
||||||
|
|
||||||
private $dccList = array(); //holds all connected sockets
|
|
||||||
private $dccChangedList = array();
|
|
||||||
private $dccChangedCount = 0;
|
|
||||||
|
|
||||||
private $fileDlCount = 0;
|
|
||||||
private $fileUlCount = 0;
|
|
||||||
private $chatCount = 0;
|
|
||||||
|
|
||||||
//Classes
|
|
||||||
private $timerClass;
|
|
||||||
private $socketClass;
|
|
||||||
private $ircClass;
|
|
||||||
private $parserClass;
|
|
||||||
|
|
||||||
//Bytes Transferred
|
|
||||||
private $bytesUp = 0;
|
|
||||||
private $bytesDown = 0;
|
|
||||||
|
|
||||||
//Process Queue
|
|
||||||
private $procQueue;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
// do nothing...
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setProcQueue($class)
|
|
||||||
{
|
|
||||||
$this->procQueue = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setIrcClass($class)
|
|
||||||
{
|
|
||||||
$this->ircClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setParserClass($class)
|
|
||||||
{
|
|
||||||
$this->parserClass = $class;
|
|
||||||
$this->parserClass->setDccClass($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setSocketClass($class)
|
|
||||||
{
|
|
||||||
$this->socketClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTimerClass($class)
|
|
||||||
{
|
|
||||||
$this->timerClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDownloadCount()
|
|
||||||
{
|
|
||||||
return $this->fileDlCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUploadCount()
|
|
||||||
{
|
|
||||||
return $this->fileUlCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getChatCount()
|
|
||||||
{
|
|
||||||
return $this->chatCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function closeAll()
|
|
||||||
{
|
|
||||||
foreach ($this->dccList AS $dcc)
|
|
||||||
{
|
|
||||||
$dcc->disconnect("Owner Requsted Close");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addBytesUp($num)
|
|
||||||
{
|
|
||||||
$this->bytesUp += $num;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addBytesDown($num)
|
|
||||||
{
|
|
||||||
$this->bytesDown += $num;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getBytesDown()
|
|
||||||
{
|
|
||||||
return $this->bytesDown;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getBytesUp()
|
|
||||||
{
|
|
||||||
return $this->bytesUp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function getDcc($someDcc)
|
|
||||||
{
|
|
||||||
if (isset($this->dccList[$someDcc]))
|
|
||||||
{
|
|
||||||
return $this->dccList[$someDcc];
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function dccInform($data, $from = null)
|
|
||||||
{
|
|
||||||
foreach ($this->dccList AS $dcc)
|
|
||||||
{
|
|
||||||
if ($dcc->type == CHAT && $dcc->verified == true && $dcc->isAdmin == true)
|
|
||||||
{
|
|
||||||
if ($from != null)
|
|
||||||
{
|
|
||||||
if ($dcc->sockInt != $from->sockInt)
|
|
||||||
{
|
|
||||||
$dcc->dccSend($data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$dcc->dccSend($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Works in conjunction with $oldConn->connected
|
|
||||||
public function accepted($oldConn, $newConn)
|
|
||||||
{
|
|
||||||
$sockInt = $oldConn->getSockInt();
|
|
||||||
$hasAccepted = $newConn->getSockInt();
|
|
||||||
|
|
||||||
$dcc = $this->dccList[$sockInt];
|
|
||||||
$this->dccList[$hasAccepted] = $dcc;
|
|
||||||
$dcc->status = DCC_CONNECTED;
|
|
||||||
$dcc->sockInt = $hasAccepted;
|
|
||||||
unset($this->dccList[$sockInt]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//CheckDccTimeout function
|
|
||||||
public function checkDccTimeout($dcc)
|
|
||||||
{
|
|
||||||
if (!is_object($dcc) || $dcc->removed == true)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($dcc->status != DCC_LISTENING)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($dcc->timeOutLevel)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
$dcc->timeOutLevel++;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
$dcc->timeOutLevel++;
|
|
||||||
$this->ircClass->notice($dcc->nick, "You have a DCC session pending. Set your client to connect. 60 seconds before timeout.", 1);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
$dcc->timeOutLevel++;
|
|
||||||
$this->ircClass->notice($dcc->nick, "You have a DCC session pending. Set your client to connect. 30 seconds before timeout.", 1);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
$dcc->timeOutLevel = 0;
|
|
||||||
$dcc->disconnect("DCC Session timed out (90 Seconds)");
|
|
||||||
return false;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDccList()
|
|
||||||
{
|
|
||||||
return $this->dccList;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function removeDcc($dcc)
|
|
||||||
{
|
|
||||||
$sockInt = $dcc->sockInt;
|
|
||||||
unset($this->dccList[$sockInt]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dccSend($to, $data)
|
|
||||||
{
|
|
||||||
if (($len = $this->socketClass->sendSocket($to->sockInt, $data)) === false)
|
|
||||||
{
|
|
||||||
$to->disconnect();
|
|
||||||
}
|
|
||||||
return $len;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function highestId()
|
|
||||||
{
|
|
||||||
$highest = 0;
|
|
||||||
|
|
||||||
foreach ($this->dccList AS $index => $dcc)
|
|
||||||
{
|
|
||||||
$highest = ($dcc->id > $highest ? $dcc->id : $highest);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $highest + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function addChat($nick, $host, $port, $admin, $handler, $fromTimer = false)
|
|
||||||
{
|
|
||||||
$lnick = irc::myStrToLower($nick);
|
|
||||||
|
|
||||||
foreach ($this->dccList AS $index => $dcc)
|
|
||||||
{
|
|
||||||
if ($dcc->type == CHAT)
|
|
||||||
{
|
|
||||||
if (irc::myStrToLower($dcc->nick) == $lnick)
|
|
||||||
{
|
|
||||||
$dcc->disconnect();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$reverse = false;
|
|
||||||
|
|
||||||
if ($this->ircClass->getClientConf("mircdccreverse") != "" && $fromTimer == false)
|
|
||||||
{
|
|
||||||
$port = intval($this->ircClass->getClientConf("mircdccreverse"));
|
|
||||||
if ($port == 0)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
$args = new argClass;
|
|
||||||
|
|
||||||
$args->arg1 = $nick;
|
|
||||||
$args->arg2 = $host;
|
|
||||||
$args->arg3 = $port;
|
|
||||||
$args->arg4 = $admin;
|
|
||||||
$args->arg5 = $handler;
|
|
||||||
$args->arg7 = time();
|
|
||||||
$args->arg8 = CHAT;
|
|
||||||
|
|
||||||
$this->ircClass->notice($nick, "DCC: NOTICE: This server is using the mIRC Chat Server Protocol. Please use ' /dccserver +c on " . $this->ircClass->getClientConf("mircdccreverse") . " ' to chat with me! Starting 6 second delay...", 0);
|
|
||||||
|
|
||||||
$this->ircClass->sendRaw("WHOIS " . $nick);
|
|
||||||
$this->timerClass->addTimer(irc::randomHash(), $this, "reverseTimer", $args, 6, false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($fromTimer == true)
|
|
||||||
{
|
|
||||||
$reverse = DCC_REVERSE; // using mIRC dcc reverse protocol
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($host == NULL || $port == NULL)
|
|
||||||
{
|
|
||||||
$conn = new connection(null, null, 0);
|
|
||||||
$listening = true;
|
|
||||||
$status = DCC_LISTENING;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$conn = new connection($host, $port, CONNECT_TIMEOUT);
|
|
||||||
$listening = false;
|
|
||||||
$status = DCC_CONNECTING;
|
|
||||||
}
|
|
||||||
|
|
||||||
$conn->setSocketClass($this->socketClass);
|
|
||||||
$conn->setIrcClass($this->ircClass);
|
|
||||||
$conn->setCallbackClass($this);
|
|
||||||
$conn->setTimerClass($this->timerClass);
|
|
||||||
$port = $conn->init();
|
|
||||||
|
|
||||||
if ($conn->getError())
|
|
||||||
{
|
|
||||||
$this->ircClass->log("Start Chat Error: " . $conn->getErrorMsg());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sockInt = $conn->getSockInt();
|
|
||||||
|
|
||||||
$this->chatCount++;
|
|
||||||
|
|
||||||
$id = $this->highestId();
|
|
||||||
|
|
||||||
$chat = new chat($id, $nick, $admin, $sockInt, $host, $port, $handler, $reverse);
|
|
||||||
$chat->setIrcClass($this->ircClass);
|
|
||||||
$chat->setDccClass($this);
|
|
||||||
$chat->setParserClass($this->parserClass);
|
|
||||||
$chat->setSocketClass($this->socketClass);
|
|
||||||
$chat->setTimerClass($this->timerClass);
|
|
||||||
$chat->connection = $conn;
|
|
||||||
$chat->status = $status;
|
|
||||||
$chat->removed = false;
|
|
||||||
|
|
||||||
$this->dccList[$sockInt] = $chat;
|
|
||||||
|
|
||||||
$chat->initialize();
|
|
||||||
|
|
||||||
$conn->setCallbackClass($chat);
|
|
||||||
|
|
||||||
if ($listening == true)
|
|
||||||
{
|
|
||||||
$this->timerClass->addTimer(irc::randomHash(), $this, "checkDccTimeout", $chat, 30, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$conn->connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addFile($nick, $host, $port, $type, $filename, $size, $fromTimer = false) // <-- ignore fromTimer, it is sent by reverseTimer() above
|
|
||||||
{
|
|
||||||
$reverse = false;
|
|
||||||
|
|
||||||
if ($this->ircClass->getClientConf("mircdccreverse") != "" && $fromTimer == false && $type != DOWNLOAD)
|
|
||||||
{
|
|
||||||
$port = intval($this->ircClass->getClientConf("mircdccreverse"));
|
|
||||||
if ($port == 0)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
$args = new argClass;
|
|
||||||
|
|
||||||
$args->arg1 = $nick;
|
|
||||||
$args->arg2 = $host;
|
|
||||||
$args->arg3 = $port;
|
|
||||||
$args->arg4 = $type;
|
|
||||||
$args->arg5 = $filename;
|
|
||||||
$args->arg6 = $size;
|
|
||||||
$args->arg7 = time();
|
|
||||||
$args->arg8 = FILE;
|
|
||||||
|
|
||||||
$this->ircClass->notice($nick, "DCC: NOTICE: This server is using the mIRC File Server Protocol. Please use ' /dccserver +s on " . $this->ircClass->getClientConf("mircdccreverse") . " ' to recieve files from me! Starting 6 second delay...", 0);
|
|
||||||
|
|
||||||
$this->ircClass->sendRaw("WHOIS " . $nick);
|
|
||||||
$this->timerClass->addTimer(irc::randomHash(), $this, "reverseTimer", $args, 6);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($fromTimer == true)
|
|
||||||
{
|
|
||||||
$reverse = DCC_REVERSE; // using mIRC dcc reverse protocol
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($host == NULL || $port == NULL)
|
|
||||||
{
|
|
||||||
$conn = new connection(null, null, 0);
|
|
||||||
$listening = true;
|
|
||||||
$status = DCC_LISTENING;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$conn = new connection($host, $port, CONNECT_TIMEOUT);
|
|
||||||
$listening = false;
|
|
||||||
$status = DCC_CONNECTING;
|
|
||||||
}
|
|
||||||
|
|
||||||
$conn->setSocketClass($this->socketClass);
|
|
||||||
$conn->setIrcClass($this->ircClass);
|
|
||||||
$conn->setCallbackClass($this);
|
|
||||||
$conn->setTransTimeout(30);
|
|
||||||
$conn->setTimerClass($this->timerClass);
|
|
||||||
$port = $conn->init();
|
|
||||||
|
|
||||||
if ($conn->getError())
|
|
||||||
{
|
|
||||||
$this->ircClass->log("File transfer start error: " . $conn->getErrorMsg());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sockInt = $conn->getSockInt();
|
|
||||||
|
|
||||||
$id = $this->highestId();
|
|
||||||
|
|
||||||
$file = new file($id, $nick, $sockInt, $host, $port, $type, $reverse);
|
|
||||||
|
|
||||||
if ($file->transferType == UPLOAD)
|
|
||||||
{
|
|
||||||
$this->fileUlCount++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->fileDlCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$file->setIrcClass($this->ircClass);
|
|
||||||
$file->setDccClass($this);
|
|
||||||
$file->setSocketClass($this->socketClass);
|
|
||||||
$file->setProcQueue($this->procQueue);
|
|
||||||
$file->setTimerClass($this->timerClass);
|
|
||||||
$file->connection = $conn;
|
|
||||||
$file->status = $status;
|
|
||||||
$file->removed = false;
|
|
||||||
|
|
||||||
$this->dccList[$sockInt] = $file;
|
|
||||||
|
|
||||||
$file->initialize($filename, $size);
|
|
||||||
|
|
||||||
$conn->setCallbackClass($file);
|
|
||||||
|
|
||||||
if ($listening == true)
|
|
||||||
{
|
|
||||||
$this->timerClass->addTimer(irc::randomHash(), $this, "checkDccTimeout", $file, 30, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($reverse == true)
|
|
||||||
{
|
|
||||||
$conn->connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $port;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function alterSocket($sockInt, $level, $opt, $val)
|
|
||||||
{
|
|
||||||
return $this->socketClass->alterSocket($sockInt, $level, $opt, $val);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function reverseTimer($args)
|
|
||||||
{
|
|
||||||
$memData = $this->ircClass->getUserData($args->arg1);
|
|
||||||
|
|
||||||
if ($memData == NULL || ($memData->host == "" || $memData->host == NULL))
|
|
||||||
{
|
|
||||||
$this->ircClass->notice($args->arg1, "DCC: ERROR: Couldn't resolve your hostname. Try again?");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
if ($args->arg8 == FILE)
|
|
||||||
{
|
|
||||||
$this->addFile( $args->arg1,
|
|
||||||
$memData->host,
|
|
||||||
$this->ircClass->getClientConf("mircdccreverse"),
|
|
||||||
$args->arg4,
|
|
||||||
$args->arg5,
|
|
||||||
$args->arg6,
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->addChat( $args->arg1,
|
|
||||||
$memData->host,
|
|
||||||
$this->ircClass->getClientConf("mircdccreverse"),
|
|
||||||
$args->arg4,
|
|
||||||
$args->arg5,
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function sendFile($nick, $file)
|
|
||||||
{
|
|
||||||
return $this->addFile($nick, null, null, UPLOAD, $file, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function dccResume($port, $size)
|
|
||||||
{
|
|
||||||
foreach ($this->dccList AS $dcc)
|
|
||||||
{
|
|
||||||
if ($dcc->type == FILE)
|
|
||||||
{
|
|
||||||
if ($dcc->port == $port)
|
|
||||||
{
|
|
||||||
$dcc->resume($size);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dccAccept($port)
|
|
||||||
{
|
|
||||||
foreach ($this->dccList AS $dcc)
|
|
||||||
{
|
|
||||||
if ($dcc->type == FILE)
|
|
||||||
{
|
|
||||||
if ($dcc->port == $port)
|
|
||||||
{
|
|
||||||
$dcc->accepted();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function disconnect($dcc)
|
|
||||||
{
|
|
||||||
|
|
||||||
switch ($dcc->type)
|
|
||||||
{
|
|
||||||
case CHAT:
|
|
||||||
$this->chatCount--;
|
|
||||||
break;
|
|
||||||
case FILE:
|
|
||||||
switch($dcc->transferType)
|
|
||||||
{
|
|
||||||
case UPLOAD:
|
|
||||||
$this->fileUlCount--;
|
|
||||||
break;
|
|
||||||
case DOWNLOAD:
|
|
||||||
$this->fileDlCount--;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$dcc->removed = true;
|
|
||||||
|
|
||||||
$dcc->connection->disconnect();
|
|
||||||
$this->removeDcc($dcc);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
|
@ -1,314 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2005 by http://www.phpbots.org/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > defines module
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.2.0
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Debug Mode
|
|
||||||
define('DEBUG', 1);
|
|
||||||
|
|
||||||
// PID file
|
|
||||||
define('PID', config::$main['cs_path'] . "/ircbot.pid");
|
|
||||||
|
|
||||||
// OS Type (windows/unix/linux/freebsd/unknown/auto)
|
|
||||||
define('OS', 'auto');
|
|
||||||
|
|
||||||
//YOU SHOULD NOT HAVE TO EDIT BELOW THIS POINT UNLESS YOU SPECIFY "unknown" AS OS!
|
|
||||||
|
|
||||||
if (OS == "auto")
|
|
||||||
{
|
|
||||||
switch (PHP_OS)
|
|
||||||
{
|
|
||||||
case "Windows NT":
|
|
||||||
$OS = "windows";
|
|
||||||
break;
|
|
||||||
case "Linux":
|
|
||||||
$OS = "linux";
|
|
||||||
break;
|
|
||||||
case "FreeBSD":
|
|
||||||
$OS = "freebsd";
|
|
||||||
break;
|
|
||||||
case "Unix":
|
|
||||||
$OS = "unix";
|
|
||||||
break;
|
|
||||||
//Thx OrochiTux for below
|
|
||||||
case "Darwin":
|
|
||||||
$OS = "freebsd";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$OS = "windows";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$OS = OS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($OS == 'unknown')
|
|
||||||
{
|
|
||||||
define('EAGAIN', 0); /* Try again */
|
|
||||||
define('EISCONN', 0); /* Transport endpoint is already connected */
|
|
||||||
define('EALREADY', 0); /* Operation already in progress */
|
|
||||||
define('EINPROGRESS', 0); /* Operation now in progress */
|
|
||||||
}
|
|
||||||
else if ($OS == 'windows')
|
|
||||||
{
|
|
||||||
//http://developer.novell.com/support/winsock/doc/appenda.htm
|
|
||||||
define('EAGAIN', 10035); //EWOULDBLOCK.. kinda like EAGAIN in windows?
|
|
||||||
define('EISCONN', 10056); /* Transport endpoint is already connected */
|
|
||||||
define('EALREADY', 10037); /* Operation already in progress */
|
|
||||||
define('EINPROGRESS', 10036); /* Operation now in progress */
|
|
||||||
}
|
|
||||||
else if ($OS == 'freebsd')
|
|
||||||
{
|
|
||||||
//Thanks to ryguy@efnet
|
|
||||||
///usr/include/errno.h (freebsd)
|
|
||||||
define('EAGAIN', 35); /* Try again */
|
|
||||||
define('EISCONN', 56); /* Transport endpoint is already connected */
|
|
||||||
define('EALREADY', 37); /* Operation already in progress */
|
|
||||||
define('EINPROGRESS', 36); /* Operation now in progress */
|
|
||||||
}
|
|
||||||
else if ($OS == 'linux')
|
|
||||||
{
|
|
||||||
///usr/include/sys/errno.h (sparc)
|
|
||||||
define('EAGAIN', 11); /* Try again */
|
|
||||||
define('EISCONN', 106); /* Transport endpoint is already connected */
|
|
||||||
define('EALREADY', 114); /* Operation already in progress */
|
|
||||||
define('EINPROGRESS', 115); /* Operation now in progress */
|
|
||||||
}
|
|
||||||
else if ($OS == 'unix')
|
|
||||||
{
|
|
||||||
///usr/include/asm/errno.h (mandrake 9.0)
|
|
||||||
define('EAGAIN', 11); /* Try again */
|
|
||||||
define('EISCONN', 133); /* Transport endpoint is already connected */
|
|
||||||
define('EALREADY', 149); /* Operation already in progress */
|
|
||||||
define('EINPROGRESS', 150); /* Operation now in progress */
|
|
||||||
}
|
|
||||||
|
|
||||||
// Version Definition
|
|
||||||
define('VERSION', '2.2.1');
|
|
||||||
define('VERSION_DATE', '04/08/06');
|
|
||||||
|
|
||||||
// Timer declarations
|
|
||||||
define('NICK_CHECK_TIMEOUT', 120); //seconds
|
|
||||||
define('CHAN_CHECK_TIMEOUT', 60); //seconds
|
|
||||||
define('PING_TIMEOUT', 130); //seconds (check every 130 seconds if we're still connected)
|
|
||||||
|
|
||||||
// Parser definitions
|
|
||||||
define('MAX_ARGS', 4);
|
|
||||||
|
|
||||||
// Status definitions
|
|
||||||
define('STATUS_IDLE', 0);
|
|
||||||
define('STATUS_ERROR', 1);
|
|
||||||
define('STATUS_CONNECTING', 2);
|
|
||||||
define('STATUS_CONNECTED', 3);
|
|
||||||
define('STATUS_CONNECTED_SENTREGDATA', 4);
|
|
||||||
define('STATUS_CONNECTED_REGISTERED', 5);
|
|
||||||
|
|
||||||
// Constant Definitions
|
|
||||||
define('ERROR_TIMEOUT', 60);
|
|
||||||
define('CONNECT_TIMEOUT', 45);
|
|
||||||
define('REGISTRATION_TIMEOUT', 60);
|
|
||||||
define('TIMEOUT_CHECK_TIME', 85); //85
|
|
||||||
|
|
||||||
//Constants for Channel Modes
|
|
||||||
define('BY_MASK', 0);
|
|
||||||
define('BY_STRING', 1);
|
|
||||||
define('BY_INT', 2);
|
|
||||||
define('BY_NONE', 3);
|
|
||||||
|
|
||||||
//Used with $ircClass->parseMode
|
|
||||||
define('USER_MODE', 0);
|
|
||||||
define('CHANNEL_MODE', 1);
|
|
||||||
|
|
||||||
//Random Vars
|
|
||||||
define('STATUS_JUST_BANNED', 1);
|
|
||||||
define('STATUS_ALREADY_BANNED', 2);
|
|
||||||
define('STATUS_NOT_BANNED', 3);
|
|
||||||
|
|
||||||
//Socket Class defines
|
|
||||||
define('SOCK_DEAD', 1);
|
|
||||||
define('SOCK_CONNECTING', 2);
|
|
||||||
define('SOCK_LISTENING', 3);
|
|
||||||
define('SOCK_ACCEPTED', 4);
|
|
||||||
define('SOCK_ACCEPTING', 5);
|
|
||||||
define('SOCK_CONNECTED', 6);
|
|
||||||
define('HIGHEST_PORT', 1000); // this is tcpRangeStart + HIGHEST_PORT
|
|
||||||
|
|
||||||
//DCC Class defines
|
|
||||||
define('FILE', 0);
|
|
||||||
define('CHAT', 1);
|
|
||||||
define('DCC_WAITING', 3);
|
|
||||||
define('DCC_REVERSE', 4);
|
|
||||||
define('DCC_CONNECTING', 0);
|
|
||||||
define('DCC_CONNECTED', 1);
|
|
||||||
define('DCC_LISTENING', 2);
|
|
||||||
|
|
||||||
//Connection class defines
|
|
||||||
define('CONN_READ', 0);
|
|
||||||
define('CONN_WRITE', 1);
|
|
||||||
define('CONN_ACCEPT', 2);
|
|
||||||
define('CONN_CONNECT', 3);
|
|
||||||
define('CONN_DEAD', 4);
|
|
||||||
define('CONN_CONNECT_TIMEOUT', 5);
|
|
||||||
define('CONN_TRANSFER_TIMEOUT', 6);
|
|
||||||
|
|
||||||
//Parser Class defines
|
|
||||||
define('BRIGHT', chr(3) . "13");
|
|
||||||
define('DARK', chr(3) . "03");
|
|
||||||
define('NORMAL', chr(16));
|
|
||||||
define('BOLD', chr(2));
|
|
||||||
define('UNDERLINE', chr(31));
|
|
||||||
define('PRIV', 1);
|
|
||||||
define('DCC', 2);
|
|
||||||
|
|
||||||
//File Class defines
|
|
||||||
define('UPLOAD', 0);
|
|
||||||
define('DOWNLOAD', 1);
|
|
||||||
|
|
||||||
//Used with $ircClass->addQuery
|
|
||||||
define('QUERY_SUCCESS', 0);
|
|
||||||
define('QUERY_ERROR', 1);
|
|
||||||
|
|
||||||
//Used in ini
|
|
||||||
define('EXACT_MATCH', 0);
|
|
||||||
define('AND_MATCH', 1);
|
|
||||||
define('OR_MATCH', 2);
|
|
||||||
define('CONTAINS_MATCH', 3);
|
|
||||||
|
|
||||||
//Used in socket class to keep track of sockets
|
|
||||||
|
|
||||||
class socketInfo {
|
|
||||||
public $socket;
|
|
||||||
public $status;
|
|
||||||
public $readQueue;
|
|
||||||
public $readLength;
|
|
||||||
public $writeQueue;
|
|
||||||
public $writeLength;
|
|
||||||
public $host;
|
|
||||||
public $port;
|
|
||||||
public $newSockInt;
|
|
||||||
public $listener;
|
|
||||||
public $owner;
|
|
||||||
public $class;
|
|
||||||
public $func;
|
|
||||||
public $readScheduled; //Used so we don't add infinite queues to the process queue.
|
|
||||||
public $writeScheduled;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Channel and Username Linked List (Links) Definitions
|
|
||||||
|
|
||||||
class channelLink {
|
|
||||||
public $name;
|
|
||||||
public $count;
|
|
||||||
public $memberList = array();
|
|
||||||
public $banList = array();
|
|
||||||
public $whoComplete;
|
|
||||||
public $banComplete;
|
|
||||||
public $modes;
|
|
||||||
public $created;
|
|
||||||
public $topic;
|
|
||||||
public $topicBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
class memberLink {
|
|
||||||
public $nick;
|
|
||||||
public $realNick;
|
|
||||||
public $host;
|
|
||||||
public $ident;
|
|
||||||
public $banned;
|
|
||||||
public $bantime;
|
|
||||||
public $status;
|
|
||||||
public $ignored;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used in timer class
|
|
||||||
|
|
||||||
class timer {
|
|
||||||
public $name;
|
|
||||||
public $class;
|
|
||||||
public $args;
|
|
||||||
public $interval;
|
|
||||||
public $lastTimeRun;
|
|
||||||
public $nextRunTime;
|
|
||||||
public $func;
|
|
||||||
}
|
|
||||||
|
|
||||||
class usageLink {
|
|
||||||
public $isBanned;
|
|
||||||
public $timeBanned;
|
|
||||||
public $lastTimeUsed;
|
|
||||||
public $timesUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Useful for sending arguments with timers
|
|
||||||
class argClass
|
|
||||||
{
|
|
||||||
public $arg1;
|
|
||||||
public $arg2;
|
|
||||||
public $arg3;
|
|
||||||
public $arg4;
|
|
||||||
public $arg5;
|
|
||||||
public $arg6;
|
|
||||||
public $arg7;
|
|
||||||
public $arg8;
|
|
||||||
public $timer;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used to instantiate a bot
|
|
||||||
class botClass {
|
|
||||||
public $timerClass;
|
|
||||||
public $ircClass;
|
|
||||||
public $dccClass;
|
|
||||||
public $parserClass;
|
|
||||||
public $socketClass;
|
|
||||||
public $configFilename;
|
|
||||||
public $db;
|
|
||||||
public $config;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used with processQueue
|
|
||||||
class queueItem {
|
|
||||||
public $owner; //IRC Class of owner
|
|
||||||
public $callBack_class; //CALL BACK class/function to use
|
|
||||||
public $callBack_function;
|
|
||||||
public $nextRunTime; //The next getMicroTime() time to run
|
|
||||||
public $removed;
|
|
||||||
public $next;
|
|
||||||
public $prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
107
ircbot/error.php
107
ircbot/error.php
|
@ -1,107 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2005 by http://www.phpbots.org/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > error module
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.2.0
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
class ConnectException extends Exception {
|
|
||||||
|
|
||||||
private $exceptionTime = 0;
|
|
||||||
|
|
||||||
function __construct($message)
|
|
||||||
{
|
|
||||||
parent::__construct($message);
|
|
||||||
$this->exceptionTime = time();
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTime()
|
|
||||||
{
|
|
||||||
return $this->exceptionTime;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class SendDataException extends Exception {
|
|
||||||
|
|
||||||
private $exceptionTime = 0;
|
|
||||||
|
|
||||||
function __construct($message)
|
|
||||||
{
|
|
||||||
parent::__construct($message);
|
|
||||||
$this->exceptionTime = time();
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTime()
|
|
||||||
{
|
|
||||||
return $this->exceptionTime;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ConnectionTimeout extends Exception {
|
|
||||||
|
|
||||||
private $exceptionTime = 0;
|
|
||||||
|
|
||||||
function __construct($message)
|
|
||||||
{
|
|
||||||
parent::__construct($message);
|
|
||||||
$this->exceptionTime = time();
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTime()
|
|
||||||
{
|
|
||||||
return $this->exceptionTime;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ReadException extends Exception {
|
|
||||||
|
|
||||||
private $exceptionTime = 0;
|
|
||||||
|
|
||||||
function __construct($message)
|
|
||||||
{
|
|
||||||
parent::__construct($message);
|
|
||||||
$this->exceptionTime = time();
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTime()
|
|
||||||
{
|
|
||||||
return $this->exceptionTime;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
663
ircbot/file.php
663
ircbot/file.php
|
@ -1,663 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2005 by http://www.phpbots.org/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > dcc chat module
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.2.0
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
class file {
|
|
||||||
|
|
||||||
/* Chat specific Data */
|
|
||||||
public $id;
|
|
||||||
public $status;
|
|
||||||
public $sockInt;
|
|
||||||
public $timeConnected;
|
|
||||||
public $readQueue;
|
|
||||||
public $port;
|
|
||||||
public $dccString;
|
|
||||||
public $type;
|
|
||||||
public $transferType;
|
|
||||||
public $nick;
|
|
||||||
public $timeOutLevel;
|
|
||||||
public $removed;
|
|
||||||
public $connection;
|
|
||||||
|
|
||||||
public $reverse; // reverse dcc?
|
|
||||||
private $handShakeSent;
|
|
||||||
private $handShakeTime;
|
|
||||||
|
|
||||||
public $filename;
|
|
||||||
public $filenameNoDir;
|
|
||||||
public $filePointer;
|
|
||||||
public $filesize;
|
|
||||||
public $bytesTransfered;
|
|
||||||
public $resumedSize;
|
|
||||||
public $completed;
|
|
||||||
public $reportedRecieved;
|
|
||||||
|
|
||||||
public $connectHost;
|
|
||||||
|
|
||||||
//private $resumed;
|
|
||||||
private $started;
|
|
||||||
|
|
||||||
private $sendQueue;
|
|
||||||
private $sendQueueCount;
|
|
||||||
|
|
||||||
//keep track of speed;
|
|
||||||
private $speed_sec_add;
|
|
||||||
public $speed_lastavg;
|
|
||||||
private $speed_starttime;
|
|
||||||
|
|
||||||
/* Classes */
|
|
||||||
private $dccClass;
|
|
||||||
private $ircClass;
|
|
||||||
private $socketClass;
|
|
||||||
private $procQueue;
|
|
||||||
private $timerClass;
|
|
||||||
|
|
||||||
/* Constructor */
|
|
||||||
public function __construct($id, $nick, $sockInt, $host, $port, $type, $reverse)
|
|
||||||
{
|
|
||||||
$this->id = $id;
|
|
||||||
$this->nick = $nick;
|
|
||||||
$this->sockInt = $sockInt;
|
|
||||||
$this->connectHost = $host;
|
|
||||||
$this->port = $port;
|
|
||||||
$this->transferType = $type;
|
|
||||||
$this->filesize = 0;
|
|
||||||
$this->bytesTransfered = 0;
|
|
||||||
$this->resumedSize = 0;
|
|
||||||
$this->started = false;
|
|
||||||
$this->status = DCC_WAITING;
|
|
||||||
$this->reverse = $reverse;
|
|
||||||
$this->handShakeSent = false;
|
|
||||||
|
|
||||||
$this->speed_sec_add = 0;
|
|
||||||
$this->speed_lastavg = 0;
|
|
||||||
$this->speed_starttime = 0;
|
|
||||||
|
|
||||||
if ($type == UPLOAD)
|
|
||||||
{
|
|
||||||
$this->dccString = "DCC UPLOAD[".$this->id."]: ";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->dccString = "DCC DOWNLOAD[".$this->id."]: ";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setProcQueue($class)
|
|
||||||
{
|
|
||||||
$this->procQueue = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setSocketClass($class)
|
|
||||||
{
|
|
||||||
$this->socketClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setIrcClass($class)
|
|
||||||
{
|
|
||||||
$this->ircClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTimerClass($class)
|
|
||||||
{
|
|
||||||
$this->timerClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setDccClass($class)
|
|
||||||
{
|
|
||||||
$this->dccClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dccSend($data)
|
|
||||||
{
|
|
||||||
return $this->dccClass->dccSend($this, $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function disconnect($msg = "")
|
|
||||||
{
|
|
||||||
|
|
||||||
$msg = str_replace("\r", "", $msg);
|
|
||||||
$msg = str_replace("\n", "", $msg);
|
|
||||||
|
|
||||||
if ($this->started == true)
|
|
||||||
{
|
|
||||||
fclose($this->filePointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($msg != "")
|
|
||||||
{
|
|
||||||
$this->dccClass->dccInform($this->dccString . "DCC session ended with " . $this->nick . " (" . $msg . ")", $this);
|
|
||||||
$this->ircClass->notice($this->nick, "DCC session ended: " . $msg, 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->dccClass->dccInform($this->dccString . "DCC session ended with " . $this->nick, $this);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->status = false;
|
|
||||||
|
|
||||||
$this->dccClass->disconnect($this);
|
|
||||||
|
|
||||||
$this->connection = null;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function xferUpload()
|
|
||||||
{
|
|
||||||
|
|
||||||
while ($this->readQueue != "")
|
|
||||||
{
|
|
||||||
$unsignedLong = substr($this->readQueue, 0, 4);
|
|
||||||
|
|
||||||
if (strlen($unsignedLong) < 4)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sizeArray = unpack("N", $unsignedLong);
|
|
||||||
|
|
||||||
$this->reportedRecieved = $sizeArray[1];
|
|
||||||
|
|
||||||
$this->readQueue = substr($this->readQueue, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->completed == 1)
|
|
||||||
{
|
|
||||||
if ($this->reportedRecieved >= $this->filesize)
|
|
||||||
{
|
|
||||||
$avgspeed = "";
|
|
||||||
if ($this->speed_lastavg != 0)
|
|
||||||
{
|
|
||||||
$size = irc::intToSizeString($this->speed_lastavg);
|
|
||||||
$avgspeed = " (" . $size . "/s)";
|
|
||||||
}
|
|
||||||
|
|
||||||
$totalTime = $this->ircClass->timeFormat(time() - $this->timeConnected, "%h hrs, %m min, %s sec");
|
|
||||||
$size = irc::intToSizeString($this->bytesTransfered - $this->resumedSize);
|
|
||||||
$this->disconnect("Transfer Completed, Sent " . $size . " in " . $totalTime . $avgspeed);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->status != DCC_CONNECTED)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->socketClass->hasWriteQueue($this->sockInt))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->bytesTransfered >= $this->filesize)
|
|
||||||
{
|
|
||||||
$this->completed = 1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (time() >= $this->speed_starttime + 3)
|
|
||||||
{
|
|
||||||
$this->speed_lastavg = $this->speed_sec_add / 3.0;
|
|
||||||
$this->speed_sec_add = 0;
|
|
||||||
$this->speed_starttime = time();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_resource($this->filePointer))
|
|
||||||
{
|
|
||||||
$this->disconnect("File pointer is not a resource");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ($i = 0; $i < 30; $i++)
|
|
||||||
{
|
|
||||||
if (($data = fread($this->filePointer, 4096)) === false)
|
|
||||||
{
|
|
||||||
$this->disconnect("Read error: Could not access file");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->dccSend($data);
|
|
||||||
|
|
||||||
$dataSize = strlen($data);
|
|
||||||
|
|
||||||
$this->bytesTransfered += $dataSize;
|
|
||||||
$this->dccClass->addBytesUp($dataSize);
|
|
||||||
$this->speed_sec_add += $dataSize;
|
|
||||||
|
|
||||||
if ($this->socketClass->hasWriteQueue($this->sockInt))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function xferDownload()
|
|
||||||
{
|
|
||||||
|
|
||||||
if ($this->status != DCC_CONNECTED)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$readQueueSize = strlen($this->readQueue);
|
|
||||||
|
|
||||||
if ($readQueueSize <= 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fwrite($this->filePointer, $this->readQueue, $readQueueSize) === false)
|
|
||||||
{
|
|
||||||
$this->disconnect("Write error: Could not access file");
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->speed_sec_add += $readQueueSize;
|
|
||||||
$this->dccClass->addBytesDown($readQueueSize);
|
|
||||||
$this->bytesTransfered += $readQueueSize;
|
|
||||||
$this->readQueue = "";
|
|
||||||
|
|
||||||
$this->dccSend(pack("N", $this->bytesTransfered));
|
|
||||||
|
|
||||||
if ($this->bytesTransfered >= $this->filesize)
|
|
||||||
{
|
|
||||||
$avgspeed = "";
|
|
||||||
if ($this->speed_lastavg != 0)
|
|
||||||
{
|
|
||||||
$size = irc::intToSizeString($this->speed_lastavg);
|
|
||||||
$avgspeed = " (" . $size . "/s)";
|
|
||||||
}
|
|
||||||
|
|
||||||
$totalTime = $this->ircClass->timeFormat(time() - $this->timeConnected, "%h hrs, %m min, %s sec");
|
|
||||||
$size = irc::intToSizeString($this->bytesTransfered - $this->resumedSize);
|
|
||||||
$this->disconnect("Transfer Completed, Recieved " . $size . " in " . $totalTime . $avgspeed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (time() >= $this->speed_starttime + 3)
|
|
||||||
{
|
|
||||||
$this->speed_lastavg = $this->speed_sec_add / 3.0;
|
|
||||||
$this->speed_sec_add = 0;
|
|
||||||
$this->speed_starttime = time();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function doHandShake()
|
|
||||||
{
|
|
||||||
$this->dccSend("120 ".$this->ircClass->getNick()." ".$this->filesize." ".$this->filenameNoDir."\n");
|
|
||||||
$this->handShakeSent = true;
|
|
||||||
$this->timerClass->addTimer(irc::randomHash(), $this, "handShakeTimeout", "", 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function processHandShake()
|
|
||||||
{
|
|
||||||
if ($this->readQueue == "")
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = $this->readQueue;
|
|
||||||
$this->readQueue = "";
|
|
||||||
$responseArray = explode(chr(32), $response);
|
|
||||||
if ($responseArray[0] == "121")
|
|
||||||
{
|
|
||||||
$this->resumedSize = intval($responseArray[2]);
|
|
||||||
$this->reverse = false;
|
|
||||||
$this->onConnect($conn);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->disconnect("DCC Client Server reported error on attempt to send file");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handShakeTimeout()
|
|
||||||
{
|
|
||||||
if ($this->status != false)
|
|
||||||
{
|
|
||||||
if ($this->reverse == true)
|
|
||||||
{
|
|
||||||
$this->disconnect("DCC Reverse handshake timed out");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Main events */
|
|
||||||
public function onDead($conn)
|
|
||||||
{
|
|
||||||
if ($this->completed == 1)
|
|
||||||
{
|
|
||||||
$avgspeed = "";
|
|
||||||
if ($this->speed_lastavg != 0)
|
|
||||||
{
|
|
||||||
$size = irc::intToSizeString($this->speed_lastavg);
|
|
||||||
$avgspeed = " (" . $size . "/s)";
|
|
||||||
}
|
|
||||||
|
|
||||||
$totalTime = $this->ircClass->timeFormat(time() - $this->timeConnected, "%h hrs, %m min, %s sec");
|
|
||||||
$size = irc::intToSizeString($this->bytesTransfered - $this->resumedSize);
|
|
||||||
$this->disconnect("Transfer Completed, Sent " . $size . " in " . $totalTime . $avgspeed);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->disconnect($this->connection->getErrorMsg());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onRead($conn)
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->readQueue .= $this->socketClass->getQueue($this->sockInt);
|
|
||||||
|
|
||||||
if ($this->status == DCC_CONNECTED)
|
|
||||||
{
|
|
||||||
|
|
||||||
if ($this->transferType == UPLOAD)
|
|
||||||
{
|
|
||||||
if ($this->reverse != false)
|
|
||||||
{
|
|
||||||
if ($this->handShakeSent != false)
|
|
||||||
{
|
|
||||||
$this->processHandShake();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->xferDownload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onWrite($conn)
|
|
||||||
{
|
|
||||||
if ($this->status == DCC_CONNECTED && $this->reverse == false)
|
|
||||||
{
|
|
||||||
$this->xferUpload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onAccept($oldConn, $newConn)
|
|
||||||
{
|
|
||||||
$this->dccClass->accepted($oldConn, $newConn);
|
|
||||||
$this->connection = $newConn;
|
|
||||||
$oldConn->disconnect();
|
|
||||||
$this->sockInt = $newConn->getSockInt();
|
|
||||||
$this->onConnect($newConn);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onTransferTimeout($conn)
|
|
||||||
{
|
|
||||||
$this->disconnect("Transfer timed out");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onConnectTimeout($conn)
|
|
||||||
{
|
|
||||||
$this->disconnect("Connection attempt timed out");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onConnect($conn)
|
|
||||||
{
|
|
||||||
$this->status = DCC_CONNECTED;
|
|
||||||
|
|
||||||
$this->dccClass->dccInform($this->dccString . $this->nick . " connection established");
|
|
||||||
|
|
||||||
if ($this->reverse != false)
|
|
||||||
{
|
|
||||||
$this->doHandShake();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->transferType == UPLOAD)
|
|
||||||
{
|
|
||||||
$this->dccClass->alterSocket($this->sockInt, SOL_SOCKET, SO_SNDBUF, 32768);
|
|
||||||
|
|
||||||
$this->filePointer = fopen($this->filename, "rb");
|
|
||||||
|
|
||||||
if ($this->filePointer === false)
|
|
||||||
{
|
|
||||||
$this->disconnect("Error opening local file for reading");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->resumedSize > 0)
|
|
||||||
{
|
|
||||||
if (fseek($this->filePointer, $this->resumedSize, SEEK_SET) == -1)
|
|
||||||
{
|
|
||||||
$this->disconnect("Error seeking to resumed file position in file");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->xferUpload();
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->dccClass->alterSocket($this->sockInt, SOL_SOCKET, SO_RCVBUF, 32768);
|
|
||||||
|
|
||||||
$this->filePointer = fopen($this->filename, "ab");
|
|
||||||
|
|
||||||
$this->ircClass->notice($this->nick, "DCC: Upload connection established", 0);
|
|
||||||
|
|
||||||
if ($this->filePointer === false)
|
|
||||||
{
|
|
||||||
$this->disconnect("Error opening local file for writing");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->started = true;
|
|
||||||
$this->speed_starttime = time();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function initialize($filename, $size = 0)
|
|
||||||
{
|
|
||||||
$this->reportedRecieved = 0;
|
|
||||||
$this->completed = 0;
|
|
||||||
$this->filesize = $size;
|
|
||||||
$this->timeConnected = time();
|
|
||||||
$this->timeOutLevel = 0;
|
|
||||||
$this->readQueue = "";
|
|
||||||
$this->type = FILE;
|
|
||||||
|
|
||||||
if ($this->transferType == UPLOAD)
|
|
||||||
{
|
|
||||||
$this->filename = $filename;
|
|
||||||
|
|
||||||
if (strpos($filename, "/") !== false)
|
|
||||||
{
|
|
||||||
$filenameArray = explode("/", $filename);
|
|
||||||
$this->filenameNoDir = $filenameArray[count($filenameArray) - 1];
|
|
||||||
}
|
|
||||||
else if (strpos($filename, "\\") !== false)
|
|
||||||
{
|
|
||||||
$filenameArray = explode("\\", $filename);
|
|
||||||
$this->filenameNoDir = $filenameArray[count($filenameArray) - 1];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->filenameNoDir = $filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->filenameNoDir = $this->cleanFilename($this->filenameNoDir);
|
|
||||||
|
|
||||||
$this->dccClass->dccInform($this->dccString . "Initiating file transfer of (".$this->filenameNoDir.") to " . $this->nick);
|
|
||||||
|
|
||||||
if (!$this->file_exists($this->filename))
|
|
||||||
{
|
|
||||||
$this->disconnect("File does not exist");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$fileSize = $this->filesize($this->filename);
|
|
||||||
if ($fileSize === false)
|
|
||||||
{
|
|
||||||
$this->disconnect("File does not exist");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->filesize = $fileSize;
|
|
||||||
|
|
||||||
|
|
||||||
$kbSize = irc::intToSizeString($fileSize);
|
|
||||||
|
|
||||||
if ($this->reverse == false)
|
|
||||||
{
|
|
||||||
$this->ircClass->privMsg($this->nick, "\1DCC SEND " . $this->filenameNoDir . " " . $this->ircClass->getClientIP(1) . " " . $this->port . " " . $fileSize . "\1", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->ircClass->notice($this->nick, "DCC: Sending you (\"" . $this->filenameNoDir . "\") which is " . $kbSize . " (resume supported)", 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$uldir = $this->ircClass->getClientConf('uploaddir');
|
|
||||||
|
|
||||||
$lastChar = substr($uldir, strlen($uldir) - 1, 1);
|
|
||||||
|
|
||||||
if ($lastChar != "\\" || $lastChar != "/")
|
|
||||||
{
|
|
||||||
$uldir .= "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
$filename = $this->cleanFilename($filename);
|
|
||||||
|
|
||||||
$this->filename = $uldir . $filename;
|
|
||||||
$this->dccClass->dccInform($this->dccString . "Initiating file transfer of (".$filename.") from " . $this->nick);
|
|
||||||
|
|
||||||
if ($this->file_exists($this->filename))
|
|
||||||
{
|
|
||||||
$bytesFinished = $this->filesize($this->filename);
|
|
||||||
if ($bytesFinished >= $this->filesize)
|
|
||||||
{
|
|
||||||
$this->disconnect("Connection aborted. I already have that file.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->status = DCC_WAITING;
|
|
||||||
$this->bytesTransfered = $bytesFinished;
|
|
||||||
$this->resumedSize = $bytesFinished;
|
|
||||||
$this->ircClass->privMsg($this->nick, "\1DCC RESUME file.ext " . $this->port . " " . $bytesFinished . "\1", 0);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->ircClass->notice($this->nick, "DCC: Upload accepted, connecting to you (" . $this->connectHost . ") on port " . $this->port . ".",0);
|
|
||||||
|
|
||||||
|
|
||||||
$this->status = DCC_CONNECTING;
|
|
||||||
$this->connection->connect();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function accepted()
|
|
||||||
{
|
|
||||||
$this->status = DCC_CONNECTING;
|
|
||||||
$this->connection->connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function resume($size)
|
|
||||||
{
|
|
||||||
$this->resumedSize = $size;
|
|
||||||
$this->bytesTransfered = $size;
|
|
||||||
|
|
||||||
$resumePlace = round($size / 1000, 0);
|
|
||||||
$this->dccClass->dccInform($this->dccString . "Resumed at " . $resumePlace . "K");
|
|
||||||
$this->ircClass->privMsg($this->nick, "\1DCC ACCEPT file.ext " . $this->port . " " . $size . "\1", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function cleanFilename($filename)
|
|
||||||
{
|
|
||||||
$filename = str_replace("..", "__", $filename);
|
|
||||||
$filename = str_replace(chr(47), "_", $filename);
|
|
||||||
$filename = str_replace(chr(92), "_", $filename);
|
|
||||||
$filename = str_replace(chr(58), "_", $filename);
|
|
||||||
$filename = str_replace(chr(63), "_", $filename);
|
|
||||||
$filename = str_replace(chr(34), "_", $filename);
|
|
||||||
$filename = str_replace(chr(62), "_", $filename);
|
|
||||||
$filename = str_replace(chr(60), "_", $filename);
|
|
||||||
$filename = str_replace(chr(124), "_", $filename);
|
|
||||||
$filename = str_replace(chr(32), "_", $filename);
|
|
||||||
|
|
||||||
return $filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function file_exists($filename)
|
|
||||||
{
|
|
||||||
$fp = @fopen($filename, "rb");
|
|
||||||
if ($fp === false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fclose($fp);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function filesize($filename)
|
|
||||||
{
|
|
||||||
|
|
||||||
$fp = @fopen($filename, "rb");
|
|
||||||
if ($fp === false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$fstat = fstat($fp);
|
|
||||||
fclose($fp);
|
|
||||||
return $fstat['size'];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
|
@ -1,58 +0,0 @@
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
;| PHP-IRC v2.2.1 Service Release
|
|
||||||
;| =======================================================
|
|
||||||
;| by Manick
|
|
||||||
;| (c) 2001-2006 by http://www.phpbots.org/
|
|
||||||
;| Contact: manick@manekian.com
|
|
||||||
;| irc: #manekian@irc.rizon.net
|
|
||||||
;| ========================================
|
|
||||||
;| Special Contributions were made by:
|
|
||||||
;| cortex
|
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
;| > Function File
|
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
;| > This program is free software; you can redistribute it and/or
|
|
||||||
;| > modify it under the terms of the GNU General Public License
|
|
||||||
;| > as published by the Free Software Foundation; either version 2
|
|
||||||
;| > of the License, or (at your option) any later version.
|
|
||||||
;| >
|
|
||||||
;| > This program is distributed in the hope that it will be useful,
|
|
||||||
;| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;| > GNU General Public License for more details.
|
|
||||||
;| >
|
|
||||||
;| > You should have received a copy of the GNU General Public License
|
|
||||||
;| > along with this program; if not, write to the Free Software
|
|
||||||
;| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
;| Changes
|
|
||||||
;| =======-------
|
|
||||||
;| > If you wish to suggest or submit an update/change to the source
|
|
||||||
;| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
;| > will look to adding it in as soon as I can.
|
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
; some notes:
|
|
||||||
; the ~ operater spans definitions over multiple lines. the ; operator
|
|
||||||
; denotes a comment. it can be placed anywhere. you must escape
|
|
||||||
; your single quotes in quoted entries with a backslash \. the first
|
|
||||||
; type of every statement is explained
|
|
||||||
|
|
||||||
; NOTE: as of 2.2.0, all function configuration was moved to specific files using
|
|
||||||
; the 'include' function. General type definitions can be found in typedefs.conf
|
|
||||||
|
|
||||||
include typedefs.conf
|
|
||||||
|
|
||||||
include modules/lw/lw_mod.conf
|
|
||||||
;include modules/default/priv_mod.conf
|
|
||||||
;include modules/default/dcc_mod.conf
|
|
||||||
;include modules/bad_words/bad_words.conf
|
|
||||||
;include modules/peak_mod/peak_mod.conf
|
|
||||||
;include modules/seen/seen_mod.conf
|
|
||||||
;include modules/news/news_mod.conf
|
|
||||||
;include modules/imdb/imdb_mod.conf
|
|
||||||
;include modules/quotes_ini/quote_mod.conf
|
|
||||||
;include modules/quotes_sql/quote_mod.conf
|
|
||||||
;include modules/httpd/httpd_mod.conf
|
|
||||||
;include modules/fileserver/fileserver.conf
|
|
||||||
;include modules/bash/bash_mod.conf
|
|
2501
ircbot/irc.php
2501
ircbot/irc.php
File diff suppressed because it is too large
Load diff
|
@ -1,126 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2005 by http://www.phpbots.org/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > module class
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.2.0
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
abstract class module {
|
|
||||||
|
|
||||||
public $title = "<title>";
|
|
||||||
public $author = "<author>";
|
|
||||||
public $version = "<version>";
|
|
||||||
public $dontShow = false;
|
|
||||||
|
|
||||||
public $ircClass;
|
|
||||||
public $dccClass;
|
|
||||||
public $timerClass;
|
|
||||||
public $parserClass;
|
|
||||||
public $socketClass;
|
|
||||||
public $db;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
//Nothing here...
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __destruct()
|
|
||||||
{
|
|
||||||
$this->ircClass = null;
|
|
||||||
$this->dccClass = null;
|
|
||||||
$this->timerClass = null;
|
|
||||||
$this->parserClass = null;
|
|
||||||
$this->socketClass = null;
|
|
||||||
$this->db = null;
|
|
||||||
//Nothing here
|
|
||||||
}
|
|
||||||
|
|
||||||
public final function __setClasses($ircClass, $dccClass, $timerClass, $parserClass,
|
|
||||||
$socketClass, $db)
|
|
||||||
{
|
|
||||||
$this->ircClass = $ircClass;
|
|
||||||
$this->dccClass = $dccClass;
|
|
||||||
$this->timerClass = $timerClass;
|
|
||||||
$this->parserClass = $parserClass;
|
|
||||||
$this->socketClass = $socketClass;
|
|
||||||
$this->db = $db;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final function getModule($modName)
|
|
||||||
{
|
|
||||||
$mods = $this->parserClass->getCmdList("file");
|
|
||||||
|
|
||||||
if ($mods === false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($mods[$modName]))
|
|
||||||
{
|
|
||||||
return $mods[$modName]['class'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handle($chat, $args)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function connected($chat)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function main($line, $args)
|
|
||||||
{
|
|
||||||
$port = $this->dccClass->addChat($line['fromNick'], null, null, false, $this);
|
|
||||||
|
|
||||||
if ($port === false)
|
|
||||||
{
|
|
||||||
$this->ircClass->notice($line['fromNick'], "Error starting chat, please try again.", 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function init()
|
|
||||||
{
|
|
||||||
//Global.. this needs to be overwritten
|
|
||||||
}
|
|
||||||
|
|
||||||
public function destroy()
|
|
||||||
{
|
|
||||||
//Global.. this needs to be overwritten
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
|
@ -1,81 +0,0 @@
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
;| PHP-IRC Internal DCC Function Configuration File
|
|
||||||
;| ========================================================
|
|
||||||
;| by Manick
|
|
||||||
;| (c) 2001-2004 by http://phpbots.sf.net
|
|
||||||
;| Contact: manick@manekian.com
|
|
||||||
;| irc: #manekian@irc.rizon.net
|
|
||||||
;| ========================================
|
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
;| > This program is free software; you can redistribute it and/or
|
|
||||||
;| > modify it under the terms of the GNU General Public License
|
|
||||||
;| > as published by the Free Software Foundation; either version 2
|
|
||||||
;| > of the License, or (at your option) any later version.
|
|
||||||
;| >
|
|
||||||
;| > This program is distributed in the hope that it will be useful,
|
|
||||||
;| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;| > GNU General Public License for more details.
|
|
||||||
;| >
|
|
||||||
;| > You should have received a copy of the GNU General Public License
|
|
||||||
;| > along with this program; if not, write to the Free Software
|
|
||||||
;| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
file dcc_mod modules/default/dcc_mod.php
|
|
||||||
|
|
||||||
privmsg dcc_mod monitor_check
|
|
||||||
mode dcc_mod monitor_check
|
|
||||||
join dcc_mod monitor_check
|
|
||||||
kick dcc_mod monitor_check
|
|
||||||
part dcc_mod monitor_check
|
|
||||||
|
|
||||||
;new feature in 2.2.0, section definitions
|
|
||||||
section standard "Standard Functions"
|
|
||||||
section channel "Channel Functions"
|
|
||||||
section dcc "DCC Functions"
|
|
||||||
section info "Information Functions"
|
|
||||||
section admin "Administrative Functions"
|
|
||||||
section comm "IRC/Communication Functions"
|
|
||||||
|
|
||||||
dcc monitor ~; command text (typed in dcc iface)
|
|
||||||
0 ~; number of required arguments
|
|
||||||
"<channel>" ~; argument descriptions <arg1> <arg2> (or however you damn well please to do it hehe ;)
|
|
||||||
"Show messages from channel in dcc chat interface" ~; description of command
|
|
||||||
true ~; must be admin to use this command?
|
|
||||||
dcc_mod ~; class name (see file import section above)
|
|
||||||
dcc_monitor ~; function name
|
|
||||||
channel ; section name
|
|
||||||
|
|
||||||
dcc exit 0 "" "Exits the DCC interface" false dcc_mod dcc_exit standard
|
|
||||||
dcc raw 1 "<raw query>" "Sends raw query to server" true dcc_mod dcc_raw comm
|
|
||||||
dcc who 0 "" "See who\'s online" false dcc_mod dcc_who standard
|
|
||||||
dcc ignore 0 "" "View ignore list" true dcc_mod dcc_ignore admin
|
|
||||||
dcc rignore 1 "<host>" "Remove ignore for a specified host" true dcc_mod dcc_rignore admin
|
|
||||||
dcc clearqueue 0 "<user>" "Removes all text queues, or queues for a specified user." true dcc_mod dcc_clearqueue admin
|
|
||||||
dcc server 1 "<server> <port>" "Change server to specified server" true dcc_mod dcc_server admin
|
|
||||||
dcc chat 1 "<text>" "Sends message to all admin users using the DCC interface" true dcc_mod dcc_chat comm
|
|
||||||
dcc restart 0 "" "Reconnect to the current server" true dcc_mod dcc_restart admin
|
|
||||||
dcc say 2 "<channel> <text>" "Sends text to some channel" true dcc_mod dcc_say comm
|
|
||||||
dcc action 2 "<channel> <text>" "Sends text to some channel in /me format" true dcc_mod dcc_action comm
|
|
||||||
dcc users 0 "" "Shows users in all channels" true dcc_mod dcc_users info
|
|
||||||
dcc maintain 0 "<channel> <key>" "Shows maintained channels, and adds or removes one" true dcc_mod dcc_maintain channel
|
|
||||||
dcc help 0 "" "Get information about command(s)" false dcc_mod dcc_help standard
|
|
||||||
dcc join 1 "<channel>" "Join a channel" true dcc_mod dcc_join channel
|
|
||||||
dcc part 1 "<channel>" "Part a channel" true dcc_mod dcc_part channel
|
|
||||||
dcc rejoin 1 "<channel>" "Rejoin a channel" true dcc_mod dcc_rejoin channel
|
|
||||||
dcc status 0 "" "Get status of bot, same as 5 minute status update" true dcc_mod dcc_status info
|
|
||||||
dcc function 0 "<activate/deactivate> <function>" "See which functions are activated, or activate/deactivate a function" true dcc_mod dcc_function admin
|
|
||||||
dcc reloadfunc 0 "" "Reloads function definition file" true dcc_mod dcc_reloadfunc admin
|
|
||||||
dcc shutdown 0 "" "Shuts the bot down" true dcc_mod dcc_shutdown admin
|
|
||||||
dcc connect 0 "" "Force connection to server when disconnected" true dcc_mod dcc_connect admin
|
|
||||||
dcc rehash 0 "" "Reload the configuration file" true dcc_mod dcc_rehash admin
|
|
||||||
dcc send 2 "<nick> <file>" "Send a user a file" true dcc_mod dcc_send dcc
|
|
||||||
dcc dcc 0 "" "Check current dcc status" true dcc_mod dcc_dccs dcc
|
|
||||||
dcc close 1 "<id>" "Close a download, upload, or chat window" true dcc_mod dcc_close dcc
|
|
||||||
dcc upload 1 "<yes/no>" "Allow files to be sent to this bot" true dcc_mod dcc_upload dcc
|
|
||||||
dcc botinfo 0 "" "View information about the bot" true dcc_mod dcc_botinfo info
|
|
||||||
dcc timers 0 "" "View active timer information" true dcc_mod dcc_timers info
|
|
||||||
dcc listul 0 "" "List upload directory contents" true dcc_mod dcc_listul dcc
|
|
||||||
dcc modules 0 "" "List installed modules" true dcc_mod dcc_modules info
|
|
||||||
dcc spawn 1 "<config file>" "Spawn a new bot in this process" true dcc_mod dcc_spawn admin
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,35 +0,0 @@
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
;| PHP-IRC Internal PRIVMSG Function Configuration File
|
|
||||||
;| ========================================================
|
|
||||||
;| by Manick
|
|
||||||
;| (c) 2001-2004 by http://phpbots.sf.net
|
|
||||||
;| Contact: manick@manekian.com
|
|
||||||
;| irc: #manekian@irc.rizon.net
|
|
||||||
;| ========================================
|
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
;| > This program is free software; you can redistribute it and/or
|
|
||||||
;| > modify it under the terms of the GNU General Public License
|
|
||||||
;| > as published by the Free Software Foundation; either version 2
|
|
||||||
;| > of the License, or (at your option) any later version.
|
|
||||||
;| >
|
|
||||||
;| > This program is distributed in the hope that it will be useful,
|
|
||||||
;| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;| > GNU General Public License for more details.
|
|
||||||
;| >
|
|
||||||
;| > You should have received a copy of the GNU General Public License
|
|
||||||
;| > along with this program; if not, write to the Free Software
|
|
||||||
;| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
;+---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
file priv_mod modules/default/priv_mod.php
|
|
||||||
|
|
||||||
priv admin ~; text typed in the channel/pm (admin)
|
|
||||||
true ~; active command on statup?
|
|
||||||
false ~; inform admins in dcc chat iface if this command is used
|
|
||||||
false ~; can be deactivated with 'function' dcc command
|
|
||||||
0 ~; times used.. just leave this 0 (its for stats).
|
|
||||||
priv_mod ~; class name (see file import section above)
|
|
||||||
priv_admin ; function name
|
|
||||||
|
|
||||||
priv !ad true true true 0 priv_mod priv_ad
|
|
|
@ -1,315 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.0
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2005 by http://phpbots.sf.net/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > priv_mod module
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.2.0
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
class priv_mod extends module {
|
|
||||||
|
|
||||||
public $title = "Privmsg Utils";
|
|
||||||
public $author = "Manick";
|
|
||||||
public $version = "2.1.1";
|
|
||||||
public $dontShow = true;
|
|
||||||
|
|
||||||
private $ads;
|
|
||||||
|
|
||||||
public function init()
|
|
||||||
{
|
|
||||||
$this->loadAds();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function destroy()
|
|
||||||
{
|
|
||||||
$this->destroyAds();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function loadAds()
|
|
||||||
{
|
|
||||||
$ads = new ini("./modules/default/ads.ini");
|
|
||||||
|
|
||||||
if ($ads->getError())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sections = $ads->getSections();
|
|
||||||
|
|
||||||
foreach ($sections AS $ad)
|
|
||||||
{
|
|
||||||
|
|
||||||
$int = $ads->getIniVal($ad, "int");
|
|
||||||
$channel = $ads->getIniVal($ad, "chan");
|
|
||||||
$msg = $ads->getIniVal($ad, "msg");
|
|
||||||
|
|
||||||
$argArray = array('msg' => $msg, 'channel' => $channel);
|
|
||||||
|
|
||||||
$this->timerClass->addTimer($ad, $this, "misc_adTimer", $argArray, $int);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->ads = $ads;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private function destroyAds()
|
|
||||||
{
|
|
||||||
$sections = $this->ads->getSections();
|
|
||||||
|
|
||||||
foreach ($sections AS $ad)
|
|
||||||
{
|
|
||||||
$this->timerClass->removeTimer($ad);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Misc Timer
|
|
||||||
|
|
||||||
public function misc_adTimer($msg)
|
|
||||||
{
|
|
||||||
|
|
||||||
$ad = DARK . "[" . BRIGHT . "Request" . DARK . "] - [" . BRIGHT .
|
|
||||||
$msg['msg'] . DARK .
|
|
||||||
"] - PHP-IRC v" . VERSION;
|
|
||||||
|
|
||||||
$raw = "PRIVMSG " . $msg['channel'] . " :" . $ad;
|
|
||||||
|
|
||||||
$this->ircClass->sendRaw($raw);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* public Message/Channel Functions */
|
|
||||||
|
|
||||||
// This function is an example, it will display an add with timer
|
|
||||||
public function priv_ad($line, $args)
|
|
||||||
{
|
|
||||||
$channel = irc::myStrToLower($line['to']);
|
|
||||||
if ($channel == $this->ircClass->getNick())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!$this->ircClass->isMode($line['fromNick'], $channel, "o"))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($args['nargs'] == 0)
|
|
||||||
{
|
|
||||||
$timerString = "";
|
|
||||||
$timers = $this->timerClass->getTimers();
|
|
||||||
foreach ($timers AS $timer)
|
|
||||||
{
|
|
||||||
if (substr($timer->name, 0, 2) == "ad")
|
|
||||||
{
|
|
||||||
if ($timer->args['channel'] == $channel)
|
|
||||||
{
|
|
||||||
$timerString .= $timer->name . " ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($timerString == "")
|
|
||||||
{
|
|
||||||
$this->ircClass->notice($line['fromNick'], "No ads currently for " . $channel . ".");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->ircClass->notice($line['fromNick'], "Current ads for " . $channel .":");
|
|
||||||
$this->ircClass->notice($line['fromNick'], $timerString);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->ircClass->notice($line['fromNick'], "Type !ad <interval(seconds)> <msg> to add an ad, or !ad <ad[id]> to view an ad.");
|
|
||||||
}
|
|
||||||
else if ($args['nargs'] >= 1)
|
|
||||||
{
|
|
||||||
if (substr($args['arg1'], 0, 2) == "ad" && strlen($args['arg1']) > 2)
|
|
||||||
{
|
|
||||||
$id = $args['arg1'];
|
|
||||||
|
|
||||||
$timers = $this->timerClass->getTimers();
|
|
||||||
foreach ($timers AS $timer)
|
|
||||||
{
|
|
||||||
if ($timer->name == $id)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($timer == null || $channel != $timer->args['channel'])
|
|
||||||
{
|
|
||||||
$this->ircClass->notice($line['fromNick'], "There is no ad by that id.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($args['nargs'] >= 2)
|
|
||||||
{
|
|
||||||
if (irc::myStrToLower($args['arg2']) == "delete")
|
|
||||||
{
|
|
||||||
$this->ads->deleteSection($timer->name);
|
|
||||||
$this->ads->writeIni();
|
|
||||||
|
|
||||||
$this->timerClass->removeTimer($timer->name);
|
|
||||||
|
|
||||||
$this->ircClass->notice($line['fromNick'], "Ad successfully deleted.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->ircClass->notice($line['fromNick'], "Invalid option. Valid options: delete");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->ircClass->notice($line['fromNick'], "Ad: " . $timer->name);
|
|
||||||
$this->ircClass->notice($line['fromNick'], $timer->args['msg']);
|
|
||||||
$this->ircClass->notice($line['fromNick'], "Use '!ad " . $timer->name . " delete' to delete this ad.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($args['nargs'] == 1)
|
|
||||||
{
|
|
||||||
$this->ircClass->notice($line['fromNick'], "You must specify a message!");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$int = intval($args['arg1']);
|
|
||||||
|
|
||||||
if ($int <= 5)
|
|
||||||
{
|
|
||||||
$this->ircClass->notice($line['fromNick'], "Invalid Interval. Interval must be greater than 5 seconds.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$ad = substr($args['query'], strlen($args['arg1']) + 1);
|
|
||||||
|
|
||||||
$argArray = array('msg' => $ad, 'channel' => $channel);
|
|
||||||
|
|
||||||
//Find next id
|
|
||||||
$highest = 0;
|
|
||||||
$timers = $this->timerClass->getTimers();
|
|
||||||
foreach ($timers AS $timer)
|
|
||||||
{
|
|
||||||
if (substr($timer->name, 0, 2) == "ad")
|
|
||||||
{
|
|
||||||
$id = intval(substr($timer->name, 2));
|
|
||||||
if ($id > $highest)
|
|
||||||
{
|
|
||||||
$highest = $id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$highest++;
|
|
||||||
|
|
||||||
$this->timerClass->addTimer('ad' . $highest, $this, "misc_adTimer", $argArray, $int, true);
|
|
||||||
$this->ircClass->notice($line['fromNick'], "The ad was successfully added.");
|
|
||||||
|
|
||||||
$this->ads->setIniVal('ad' . $highest, "int", $int);
|
|
||||||
$this->ads->setIniVal('ad' . $highest, "chan", $channel);
|
|
||||||
$this->ads->setIniVal('ad' . $highest, "msg", $ad);
|
|
||||||
$this->ads->writeIni();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function priv_admin($line, $args)
|
|
||||||
{
|
|
||||||
if ($args['nargs'] < 2)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->ircClass->getClientConf('dccadminpass') == "")
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (md5($args['arg1']) != $this->ircClass->getClientConf('dccadminpass'))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = substr($args['query'], strlen($args['arg1']) + 1);
|
|
||||||
$myArgs = parser::createLine($query);
|
|
||||||
|
|
||||||
switch ($args['arg2'])
|
|
||||||
{
|
|
||||||
case "chatme":
|
|
||||||
$port = $this->dccClass->addChat($line['fromNick'], null, null, true, null);
|
|
||||||
if ($port === false)
|
|
||||||
{
|
|
||||||
$this->ircClass->notice($line['fromNick'], "Error starting chat, please try again.", 1);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$chat = new chat_wrapper($line['fromNick'], $this->ircClass);
|
|
||||||
|
|
||||||
$cmdList = $this->parserClass->getCmdList();
|
|
||||||
|
|
||||||
$cmdLower = $myArgs['cmd'];
|
|
||||||
|
|
||||||
if (isset($cmdList['dcc'][$cmdLower]))
|
|
||||||
{
|
|
||||||
|
|
||||||
if ($myArgs['nargs'] < $cmdList['dcc'][$cmdLower]['numArgs'])
|
|
||||||
{
|
|
||||||
$chat->dccSend("Usage: " . $cmdLower . " " . $cmdList['dcc'][$cmdLower]['usage']);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$module = $cmdList['dcc'][$cmdLower]['module'];
|
|
||||||
$class = $cmdList['file'][$module]['class'];
|
|
||||||
$func = $cmdList['dcc'][$cmdLower]['function'];
|
|
||||||
|
|
||||||
$class->$func($chat, $myArgs);
|
|
||||||
|
|
||||||
$chat->dccSend("ADMIN " . irc::myStrToUpper($cmdLower) . " Requested");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$chat->dccSend("Invalid Command: " . $myArgs['cmd']);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,21 +0,0 @@
|
||||||
file lw_mod modules/lw/lw_mod.php
|
|
||||||
|
|
||||||
priv !r true false false 0 lw_mod getRank
|
|
||||||
priv !rank true false false 0 lw_mod getRank
|
|
||||||
|
|
||||||
priv !civ true false false 0 lw_mod getCivRank
|
|
||||||
priv !mil true false false 0 lw_mod getMilRank
|
|
||||||
priv !fin true false false 0 lw_mod getFinRank
|
|
||||||
priv !idr true false false 0 lw_mod getIDR
|
|
||||||
|
|
||||||
priv !a true false false 0 lw_mod getAllianceRank
|
|
||||||
priv !arank true false false 0 lw_mod getAllianceRank
|
|
||||||
|
|
||||||
priv !t true false false 0 lw_mod nextTick
|
|
||||||
priv !tick true false false 0 lw_mod nextTick
|
|
||||||
|
|
||||||
priv !g true false false 0 lw_mod listGames
|
|
||||||
priv !games true false false 0 lw_mod listGames
|
|
||||||
|
|
||||||
priv !h true false false 0 lw_mod help
|
|
||||||
priv !help true false false 0 lw_mod help
|
|
|
@ -1,438 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
class lw_mod extends module {
|
|
||||||
|
|
||||||
public function init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public function destroy() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public function nextTick($line, $args) {
|
|
||||||
$gameID = $args['nargs'] == 1 ? $args['query'] : null;
|
|
||||||
|
|
||||||
// Get the game
|
|
||||||
$game = is_null($gameID) ? config::getDefaultGame() : config::getGame($gameID);
|
|
||||||
if (is_null($game)) {
|
|
||||||
$msg = "Game ID '" . BOLD . $gameID . BOLD . "' not found";
|
|
||||||
} else {
|
|
||||||
// Try finding public ticks
|
|
||||||
$minTick = null;
|
|
||||||
foreach ($game->ticks as $tick) {
|
|
||||||
if (! $tick->definition->public) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$tick->computeNext();
|
|
||||||
if (is_null($tick->next)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (is_null($minTick) || $minTick->next > $tick->next) {
|
|
||||||
$minTick = $tick;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_null($minTick)) {
|
|
||||||
$msg = "[" . BOLD . $game->text . BOLD . "] No more ticks on this game";
|
|
||||||
} else {
|
|
||||||
$msg = "[" . BOLD . $game->text . BOLD . "] Next tick: " . BOLD
|
|
||||||
. $minTick->definition->getName('en') . BOLD . " at " . BOLD
|
|
||||||
. gmstrftime("%H:%M:%S", $minTick->next) . BOLD;
|
|
||||||
if (gmstrftime("%Y-%m-%d", $minTick->next) != gmstrftime("%Y-%m-%d", time())) {
|
|
||||||
$msg .= " on " . BOLD . gmstrftime("%d/%m/%Y", $minTick->next) . BOLD;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($line['to'] == $this->ircClass->getClientConf('nick')) {
|
|
||||||
$to = $line['fromNick'];
|
|
||||||
} else {
|
|
||||||
$to = $line['to'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->ircClass->sendRaw("PRIVMSG $to :$msg");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function listGames($line, $args) {
|
|
||||||
static $statusText = array(
|
|
||||||
"READY" => "open for registration",
|
|
||||||
"RUNNING" => "running",
|
|
||||||
"VICTORY" => "victory conditions reached",
|
|
||||||
"ENDING" => "being terminated",
|
|
||||||
"FINISHED" => "terminated"
|
|
||||||
);
|
|
||||||
|
|
||||||
$to = $line['fromNick'];
|
|
||||||
|
|
||||||
dbConnect();
|
|
||||||
foreach (config::getGames() as $game) {
|
|
||||||
if ($game->name == 'main' || $game->status() == 'PRE') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$msg = "(" . BOLD . $game->name . BOLD . ") " . BOLD . $game->text . BOLD . " - Status: "
|
|
||||||
. BOLD . $statusText[$game->status()] . BOLD;
|
|
||||||
if ($game->status() == "READY") {
|
|
||||||
$msg .= " - Starting at " . BOLD . gmstrftime("%H:%M:%S", $game->firstTick())
|
|
||||||
. BOLD . " on " . BOLD . gmstrftime("%d/%m/%Y", $game->firstTick()) . BOLD;
|
|
||||||
} elseif ($game->status() == "ENDING") {
|
|
||||||
$msg .= " - Ending at " . BOLD . gmstrftime("%H:%M:%S", $game->lastTick())
|
|
||||||
. BOLD . " on " . BOLD . gmstrftime("%d/%m/%Y", $game->lastTick()) . BOLD;
|
|
||||||
}
|
|
||||||
$this->ircClass->sendRaw("PRIVMSG $to :$msg");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRank($line, $args) {
|
|
||||||
list($player, $game) = $this->getParams($line, $args);
|
|
||||||
|
|
||||||
dbConnect();
|
|
||||||
$rv = $this->fetchGenRank($player, $game);
|
|
||||||
dbClose();
|
|
||||||
|
|
||||||
if ($line['to'] == $this->ircClass->getClientConf('nick')) {
|
|
||||||
$to = $line['fromNick'];
|
|
||||||
} else {
|
|
||||||
$to = $line['to'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($rv)) {
|
|
||||||
$msg = "[" . BOLD . $rv[0] . BOLD . "] Player " . BOLD . $player . BOLD
|
|
||||||
. ": " . BOLD . "#{$rv[1]['ranking']}" . BOLD . " (" . BOLD
|
|
||||||
. number_format($rv[1]['points']) . BOLD . " points)";
|
|
||||||
if (! is_null($rv[2])) {
|
|
||||||
$msg .= " - Overall round ranking: " . BOLD . "#{$rv[2]['ranking']}"
|
|
||||||
. BOLD . " (" . BOLD . number_format($rv[2]['points'])
|
|
||||||
. BOLD . " points)";
|
|
||||||
}
|
|
||||||
} elseif ($rv == 1) {
|
|
||||||
$msg = "Game ID '" . BOLD . $game . BOLD . "' not found";
|
|
||||||
} elseif ($rv == 2) {
|
|
||||||
$msg = "Player " . BOLD . $player . BOLD . " not found";
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->ircClass->sendRaw("PRIVMSG $to :$msg");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCivRank($line, $args) {
|
|
||||||
list($player, $game) = $this->getParams($line, $args);
|
|
||||||
|
|
||||||
dbConnect();
|
|
||||||
$rv = $this->fetchDetRank($player, $game, 'p_civ');
|
|
||||||
dbClose();
|
|
||||||
|
|
||||||
if ($line['to'] == $this->ircClass->getClientConf('nick')) {
|
|
||||||
$to = $line['fromNick'];
|
|
||||||
} else {
|
|
||||||
$to = $line['to'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($rv)) {
|
|
||||||
$msg = "[" . BOLD . $rv[0] . BOLD . "] Player " . BOLD . $player . BOLD
|
|
||||||
. " (civilisation): " . BOLD . "#{$rv[1]['ranking']}" . BOLD . " (" . BOLD
|
|
||||||
. number_format($rv[1]['points']) . BOLD . " points)";
|
|
||||||
} elseif ($rv == 1) {
|
|
||||||
$msg = "Game ID '" . BOLD . $game . BOLD . "' not found";
|
|
||||||
} elseif ($rv == 2) {
|
|
||||||
$msg = "Player " . BOLD . $player . BOLD . " not found";
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->ircClass->sendRaw("PRIVMSG $to :$msg");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFinRank($line, $args) {
|
|
||||||
list($player, $game) = $this->getParams($line, $args);
|
|
||||||
|
|
||||||
dbConnect();
|
|
||||||
$rv = $this->fetchDetRank($player, $game, 'p_financial');
|
|
||||||
dbClose();
|
|
||||||
|
|
||||||
if ($line['to'] == $this->ircClass->getClientConf('nick')) {
|
|
||||||
$to = $line['fromNick'];
|
|
||||||
} else {
|
|
||||||
$to = $line['to'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($rv)) {
|
|
||||||
$msg = "[" . BOLD . $rv[0] . BOLD . "] Player " . BOLD . $player . BOLD
|
|
||||||
. " (financial): " . BOLD . "#{$rv[1]['ranking']}" . BOLD . " (" . BOLD
|
|
||||||
. number_format($rv[1]['points']) . BOLD . " points)";
|
|
||||||
} elseif ($rv == 1) {
|
|
||||||
$msg = "Game ID '" . BOLD . $game . BOLD . "' not found";
|
|
||||||
} elseif ($rv == 2) {
|
|
||||||
$msg = "Player " . BOLD . $player . BOLD . " not found";
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->ircClass->sendRaw("PRIVMSG $to :$msg");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMilRank($line, $args) {
|
|
||||||
list($player, $game) = $this->getParams($line, $args);
|
|
||||||
|
|
||||||
dbConnect();
|
|
||||||
$rv = $this->fetchDetRank($player, $game, 'p_military');
|
|
||||||
dbClose();
|
|
||||||
|
|
||||||
if ($line['to'] == $this->ircClass->getClientConf('nick')) {
|
|
||||||
$to = $line['fromNick'];
|
|
||||||
} else {
|
|
||||||
$to = $line['to'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($rv)) {
|
|
||||||
$msg = "[" . BOLD . $rv[0] . BOLD . "] Player " . BOLD . $player . BOLD
|
|
||||||
. " (military): " . BOLD . "#{$rv[1]['ranking']}" . BOLD . " (" . BOLD
|
|
||||||
. number_format($rv[1]['points']) . BOLD . " points)";
|
|
||||||
} elseif ($rv == 1) {
|
|
||||||
$msg = "Game ID '" . BOLD . $game . BOLD . "' not found";
|
|
||||||
} elseif ($rv == 2) {
|
|
||||||
$msg = "Player " . BOLD . $player . BOLD . " not found";
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->ircClass->sendRaw("PRIVMSG $to :$msg");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getIDR($line, $args) {
|
|
||||||
list($player, $game) = $this->getParams($line, $args);
|
|
||||||
|
|
||||||
dbConnect();
|
|
||||||
$rv = $this->fetchDetRank($player, $game, 'p_idr');
|
|
||||||
dbClose();
|
|
||||||
|
|
||||||
if ($line['to'] == $this->ircClass->getClientConf('nick')) {
|
|
||||||
$to = $line['fromNick'];
|
|
||||||
} else {
|
|
||||||
$to = $line['to'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($rv)) {
|
|
||||||
$msg = "[" . BOLD . $rv[0] . BOLD . "] Player " . BOLD . $player . BOLD
|
|
||||||
. " (inflicted damage): " . BOLD . "#{$rv[1]['ranking']}" . BOLD . " (" . BOLD
|
|
||||||
. number_format($rv[1]['points']) . BOLD . " points)";
|
|
||||||
} elseif ($rv == 1) {
|
|
||||||
$msg = "Game ID '" . BOLD . $game . BOLD . "' not found";
|
|
||||||
} elseif ($rv == 2) {
|
|
||||||
$msg = "Player " . BOLD . $player . BOLD . " not found";
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->ircClass->sendRaw("PRIVMSG $to :$msg");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function getParams($line, $args) {
|
|
||||||
if ($args['nargs'] == 0) {
|
|
||||||
$player = $line['fromNick'];
|
|
||||||
$game = null;
|
|
||||||
} else {
|
|
||||||
$query = explode(' ', trim(preg_replace('/\s+/', ' ', $args['query'])));
|
|
||||||
if (preg_match('/^{[a-z0-9]+}$/', $query[0], $matches)) {
|
|
||||||
$game = preg_replace('/[{}]/', '', array_shift($query));
|
|
||||||
} else {
|
|
||||||
$game = null;
|
|
||||||
}
|
|
||||||
$player = join(' ', $query);
|
|
||||||
if ($player == '') {
|
|
||||||
$player = $line['fromNick'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return array($player, $game);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function fetchGenRank($player, $gameID) {
|
|
||||||
// Get the game
|
|
||||||
$game = is_null($gameID) ? config::getDefaultGame() : config::getGame($gameID);
|
|
||||||
if (is_null($game)) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Access the rankings library
|
|
||||||
$rLib = $game->getLib('main/rankings');
|
|
||||||
|
|
||||||
// Get player ranking
|
|
||||||
$rType = $rLib->call('getType', 'p_general');
|
|
||||||
$genRank = $rLib->call('get', $rType, $player);
|
|
||||||
if (is_null($genRank['points'])) {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try getting the overall round rankings
|
|
||||||
$rType = $rLib->call('getType', 'p_round');
|
|
||||||
$orRank = $rLib->call('get', $rType, $player);
|
|
||||||
if (is_null($orRank['points'])) {
|
|
||||||
$orRank = null;
|
|
||||||
}
|
|
||||||
return array($game->text, $genRank, $orRank);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function fetchDetRank($player, $gameID, $type) {
|
|
||||||
// Get the game
|
|
||||||
$game = is_null($gameID) ? config::getDefaultGame() : config::getGame($gameID);
|
|
||||||
if (is_null($game)) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Access the rankings library
|
|
||||||
$rLib = $game->getLib('main/rankings');
|
|
||||||
|
|
||||||
// Get player ranking
|
|
||||||
$rType = $rLib->call('getType', $type);
|
|
||||||
$rank = $rLib->call('get', $rType, $player);
|
|
||||||
if (is_null($rank['points'])) {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
return array($game->text, $rank);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function getAllianceRank($line, $args) {
|
|
||||||
list($alliance, $game) = $this->getParams($line, $args);
|
|
||||||
|
|
||||||
dbConnect();
|
|
||||||
$rv = $this->fetchDetRank($alliance, $game, 'a_general');
|
|
||||||
dbClose();
|
|
||||||
|
|
||||||
if ($line['to'] == $this->ircClass->getClientConf('nick')) {
|
|
||||||
$to = $line['fromNick'];
|
|
||||||
} else {
|
|
||||||
$to = $line['to'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($rv)) {
|
|
||||||
$msg = "[" . BOLD . $rv[0] . BOLD . "] Alliance " . BOLD . $alliance . BOLD
|
|
||||||
. ": " . BOLD . "#{$rv[1]['ranking']}" . BOLD . " (" . BOLD
|
|
||||||
. number_format($rv[1]['points']) . BOLD . " points)";
|
|
||||||
} elseif ($rv == 1) {
|
|
||||||
$msg = "Game ID '" . BOLD . $game . BOLD . "' not found";
|
|
||||||
} elseif ($rv == 2) {
|
|
||||||
$msg = "Alliance " . BOLD . $alliance . BOLD . " not found";
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->ircClass->sendRaw("PRIVMSG $to :$msg");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function help($line, $args) {
|
|
||||||
$help = array(
|
|
||||||
"" => array(
|
|
||||||
"This bot allows you to get some information from the",
|
|
||||||
"Legacy Worlds game directly here, on IRC!",
|
|
||||||
" ",
|
|
||||||
"You can use any of the following commands:",
|
|
||||||
" ",
|
|
||||||
" " . BOLD . "Displaying rankings" . BOLD,
|
|
||||||
" " . BOLD . "rank" . BOLD . " - displays players' general and round rankings",
|
|
||||||
" " . BOLD . "civ" . BOLD . " - displays players' civilian rankings",
|
|
||||||
" " . BOLD . "mil" . BOLD . " - displays players' military rankings",
|
|
||||||
" " . BOLD . "fin" . BOLD . " - displays players' financial rankings",
|
|
||||||
" " . BOLD . "idr" . BOLD . " - displays players' inflicted damage rankings",
|
|
||||||
" " . BOLD . "arank" . BOLD . " - displays alliances' rankings",
|
|
||||||
" ",
|
|
||||||
" " . BOLD . "General information" . BOLD,
|
|
||||||
" " . BOLD . "games" . BOLD . " - lists available games",
|
|
||||||
" " . BOLD . "tick" . BOLD . " - displays the time and date of the next tick",
|
|
||||||
" " . BOLD . "help" . BOLD . " - help access",
|
|
||||||
" ",
|
|
||||||
"All commands must start with the '!' character. To get more",
|
|
||||||
"information on a specific command, type '!help <command>'"
|
|
||||||
),
|
|
||||||
"arank" => array(
|
|
||||||
"Syntax: " . BOLD . "!arank [{game}] tag",
|
|
||||||
" " . BOLD . "!a [{game}] tag",
|
|
||||||
" ",
|
|
||||||
"This command gives information about an alliance's ranking.",
|
|
||||||
" ",
|
|
||||||
"It is possible to select the game by adding the game's ID between",
|
|
||||||
"brackets just before the player's name.",
|
|
||||||
),
|
|
||||||
"rank" => array(
|
|
||||||
"Syntax: " . BOLD . "!rank [{game}] [player]",
|
|
||||||
" " . BOLD . "!r [{game}] [player]",
|
|
||||||
" ",
|
|
||||||
"This command gives information about a player's general ranking",
|
|
||||||
"as well as his round ranking if he has one.",
|
|
||||||
" ",
|
|
||||||
"Using the command without parameters will cause the bot to look",
|
|
||||||
"for your current nick, if it's the same as your in-game name.",
|
|
||||||
" ",
|
|
||||||
"It is possible to select the game by adding the game's ID between",
|
|
||||||
"brackets just before the player's name.",
|
|
||||||
" ",
|
|
||||||
"Examples: !r TSeeker",
|
|
||||||
" -> Displays TSeeker's rankings in the default game",
|
|
||||||
" !r {b5m2}",
|
|
||||||
" -> Displays your rankings in Match 2",
|
|
||||||
),
|
|
||||||
"civ" => array(
|
|
||||||
"Syntax: " . BOLD . "!civ [{game}] [player]",
|
|
||||||
" ",
|
|
||||||
"This command gives information about a player's civilisation",
|
|
||||||
"ranking.",
|
|
||||||
" ",
|
|
||||||
"Using the command without parameters will cause the bot to look",
|
|
||||||
"for your current nick, if it's the same as your in-game name.",
|
|
||||||
" ",
|
|
||||||
"It is possible to select the game by adding the game's ID between",
|
|
||||||
"brackets just before the player's name.",
|
|
||||||
" ",
|
|
||||||
"See also: " . BOLD . "!help rank" . BOLD
|
|
||||||
),
|
|
||||||
"mil" => array(
|
|
||||||
"Syntax: " . BOLD . "!mil [{game}] [player]",
|
|
||||||
" ",
|
|
||||||
"This command gives information about a player's military",
|
|
||||||
"ranking.",
|
|
||||||
" ",
|
|
||||||
"Using the command without parameters will cause the bot to look",
|
|
||||||
"for your current nick, if it's the same as your in-game name.",
|
|
||||||
" ",
|
|
||||||
"It is possible to select the game by adding the game's ID between",
|
|
||||||
"brackets just before the player's name.",
|
|
||||||
" ",
|
|
||||||
"See also: " . BOLD . "!help rank" . BOLD
|
|
||||||
),
|
|
||||||
"fin" => array(
|
|
||||||
"Syntax: " . BOLD . "!fin [{game}] [player]",
|
|
||||||
" ",
|
|
||||||
"This command gives information about a player's financial",
|
|
||||||
"ranking.",
|
|
||||||
" ",
|
|
||||||
"Using the command without parameters will cause the bot to look",
|
|
||||||
"for your current nick, if it's the same as your in-game name.",
|
|
||||||
" ",
|
|
||||||
"It is possible to select the game by adding the game's ID between",
|
|
||||||
"brackets just before the player's name.",
|
|
||||||
" ",
|
|
||||||
"See also: " . BOLD . "!help rank" . BOLD
|
|
||||||
),
|
|
||||||
"tick" => array(
|
|
||||||
"Syntax: " . BOLD . "!tick [game]",
|
|
||||||
" " . BOLD . "!t [game]",
|
|
||||||
" ",
|
|
||||||
"This command displays the next tick.",
|
|
||||||
" ",
|
|
||||||
"It is possible to select the game by adding the game's ID",
|
|
||||||
"after the command.",
|
|
||||||
),
|
|
||||||
"games" => array(
|
|
||||||
"Syntax: " . BOLD . "!games",
|
|
||||||
" " . BOLD . "!g",
|
|
||||||
" ",
|
|
||||||
"This command displays the list of available games.",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
$topic = $args['query'];
|
|
||||||
if (! array_key_exists($topic, $help)) {
|
|
||||||
$topic = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
$to = $line['fromNick'];
|
|
||||||
for ($i = 0; $i < count($help[$topic]); $i ++) {
|
|
||||||
$this->ircClass->privMsg($to, $help[$topic][$i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
For More Modules, see the website: http://www.phpbots.org
|
|
|
@ -1,11 +0,0 @@
|
||||||
|
|
||||||
file seen_mod modules/seen/seen_mod.php
|
|
||||||
|
|
||||||
privmsg seen_mod seen
|
|
||||||
;notice seen_mod seen
|
|
||||||
join seen_mod seen
|
|
||||||
kick seen_mod seen
|
|
||||||
part seen_mod seen
|
|
||||||
quit seen_mod seen
|
|
||||||
|
|
||||||
priv !seen true true true 0 seen_mod priv_seen
|
|
|
@ -1,234 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.0
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2005 by http://phpbots.sf.net/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > Seen Mod
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 0.1
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
class seen_mod extends module {
|
|
||||||
|
|
||||||
public $title = "Seen Mod";
|
|
||||||
public $author = "Manick";
|
|
||||||
public $version = "0.1";
|
|
||||||
|
|
||||||
private $seen;
|
|
||||||
|
|
||||||
public function init()
|
|
||||||
{
|
|
||||||
$this->timerClass->addTimer("seen_mod_updateini", $this, "seen_update", "", 60*15, false);
|
|
||||||
$this->seen = new ini("modules/seen/seen.ini");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function destroy()
|
|
||||||
{
|
|
||||||
$this->timerClass->removeTimer("seen_mod_updateini");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write to file
|
|
||||||
public function seen_update($args)
|
|
||||||
{
|
|
||||||
if ($this->seen->getError())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->seen->writeIni();
|
|
||||||
$this->dccClass->dccSend("Updated Seen Mod ini database file");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update actions
|
|
||||||
public function seen($line, $args)
|
|
||||||
{
|
|
||||||
if ($this->seen->getError())
|
|
||||||
{
|
|
||||||
if (DEBUG == 1)
|
|
||||||
{
|
|
||||||
echo "Seen error!\n";
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strtolower($line['cmd']) == "join")
|
|
||||||
{
|
|
||||||
$line['text'] = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strtolower($line['cmd']) == "kick")
|
|
||||||
{
|
|
||||||
$offsetA = strpos($line['params'], chr(32));
|
|
||||||
|
|
||||||
$act = "kick";
|
|
||||||
$user = substr($line['params'], $offsetA + 1);
|
|
||||||
|
|
||||||
$this->addLast($user, $act, $line['text']);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->addLast($line['fromNick'], strtolower($line['cmd']), $line['text']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->getLast($line['fromNick']);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getLast($user)
|
|
||||||
{
|
|
||||||
$user = irc::myStrToLower($user);
|
|
||||||
|
|
||||||
if (!$this->seen->sectionExists("seen"))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$var = $this->seen->getIniVal("seen", $user);
|
|
||||||
|
|
||||||
if ($var == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$offsetA = strpos($var, "=");
|
|
||||||
$offsetB = strpos($var, "=", $offsetA + 1);
|
|
||||||
$offsetC = strpos($var, "=", $offsetB + 1);
|
|
||||||
|
|
||||||
$info = array();
|
|
||||||
|
|
||||||
$info['user'] = substr($var, 0, $offsetA);
|
|
||||||
$info['time'] = substr($var, $offsetA + 1, $offsetB - $offsetA - 1);
|
|
||||||
$info['act'] = substr($var, $offsetB + 1, $offsetC - $offsetB - 1);
|
|
||||||
$info['txt'] = substr($var, $offsetC + 1);
|
|
||||||
|
|
||||||
return $info;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addLast($user, $act, $txt)
|
|
||||||
{
|
|
||||||
$Suser = irc::myStrToLower($user);
|
|
||||||
|
|
||||||
$tAction = $user . "=" . time() . "=" . irc::myStrToLower($act) . "=" . $txt;
|
|
||||||
$this->seen->setIniVal("seen", $Suser, $tAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
// User interface
|
|
||||||
public function priv_seen($line, $args)
|
|
||||||
{
|
|
||||||
if ($this->seen->getError())
|
|
||||||
{
|
|
||||||
$this->ircClass->notice($line['fromNick'], "There was an error while attempting to access the seen database.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($line['to'] == $this->ircClass->getNick())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($args['nargs'] <= 0)
|
|
||||||
{
|
|
||||||
$this->ircClass->notice($line['fromNick'], "Usage: !seen <nick>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = irc::myStrToLower($args['arg1']);
|
|
||||||
|
|
||||||
if ($user == irc::myStrToLower($line['fromNick']))
|
|
||||||
{
|
|
||||||
$this->ircClass->privMsg($line['to'], $line['fromNick'] . ", umm... O..kay...");
|
|
||||||
$this->ircClass->action($line['to'], "points at " . $line['fromNick'] . "...");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = $this->getLast($user);
|
|
||||||
|
|
||||||
if ($data === false)
|
|
||||||
{
|
|
||||||
$this->ircClass->privMsg($line['to'], $line['fromNick'] . ", I have never seen " . $args['arg1'] . " before.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$time = time() - $data['time'];
|
|
||||||
|
|
||||||
if ($time > 3600*24)
|
|
||||||
{
|
|
||||||
$timeString = irc::timeFormat($time, "%d days %h hours %m min %s sec");
|
|
||||||
}
|
|
||||||
else if ($time > 3600)
|
|
||||||
{
|
|
||||||
$timeString = irc::timeFormat($time, "%h hours %m min %s sec");
|
|
||||||
}
|
|
||||||
else if ($time > 60)
|
|
||||||
{
|
|
||||||
$timeString = irc::timeFormat($time, "%m min %s sec");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$timeString = irc::timeFormat($time, "%s sec");
|
|
||||||
}
|
|
||||||
|
|
||||||
$action = "";
|
|
||||||
|
|
||||||
switch ($data['act'])
|
|
||||||
{
|
|
||||||
case "privmsg":
|
|
||||||
$action = "saying in a channel";
|
|
||||||
break;
|
|
||||||
case "notice":
|
|
||||||
$action = "noticing a channel";
|
|
||||||
break;
|
|
||||||
case "join":
|
|
||||||
$action = "joining a channel";
|
|
||||||
break;
|
|
||||||
case "kick":
|
|
||||||
$action = "being kicked from a channel";
|
|
||||||
break;
|
|
||||||
case "part":
|
|
||||||
$action = "parting a channel";
|
|
||||||
break;
|
|
||||||
case "quit":
|
|
||||||
$action = "quitting";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($data['txt'] != "")
|
|
||||||
{
|
|
||||||
$action .= ": " . $data['txt'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->ircClass->privMsg($line['to'], $line['fromNick'] . ", I last saw " . $data['user'] . " " . $timeString . " ago " . $action . ".");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
|
@ -1,39 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
|
|
||||||
Change:
|
|
||||||
|
|
||||||
'class_name' to the name of your module (specified in function.conf)
|
|
||||||
|
|
||||||
Add:
|
|
||||||
|
|
||||||
Your functions after "//Methods here:"
|
|
||||||
|
|
||||||
Add:
|
|
||||||
|
|
||||||
Timer declarations and other general startup stuff to be run when the bot starts up in the init() function
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
class class_name extends module {
|
|
||||||
|
|
||||||
public $title = "<title>";
|
|
||||||
public $author = "<author>";
|
|
||||||
public $version = "<version>";
|
|
||||||
|
|
||||||
public function init()
|
|
||||||
{
|
|
||||||
// Add your timer declarations and whatever
|
|
||||||
// else here...
|
|
||||||
}
|
|
||||||
|
|
||||||
public function destroy()
|
|
||||||
{
|
|
||||||
// Put code here to destroy the timers that you created in init()
|
|
||||||
// and whatever else cleanup code you want.
|
|
||||||
}
|
|
||||||
|
|
||||||
//Methods here:
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
1143
ircbot/parser.php
1143
ircbot/parser.php
File diff suppressed because it is too large
Load diff
339
ircbot/queue.php
339
ircbot/queue.php
|
@ -1,339 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2005 by http://www.phpbots.org/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > queue module
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.2.0
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* This module is my response to a big problem. PHP-IRC, on idling, would use
|
|
||||||
* 2.0% or more of the CPU on a 500mhz machine. This annoyed me, and I decided
|
|
||||||
* to do something about it. So, I changed the way that PHP-IRC works, from a
|
|
||||||
* "round-robin" approach to an "interrupt" type approach. Whenever something
|
|
||||||
* happens, say, new data is read from a socket, a process Queue is added with
|
|
||||||
* a pointer to the function that reads input for that socket; or for
|
|
||||||
* another example, if a file transfer is in effect, and new data is read from
|
|
||||||
* that socket, but we also have a dcc chat going, we will only handle data for
|
|
||||||
* the file transfer, instead of wasting CPU cycles on the dcc chat, like is
|
|
||||||
* currently done in <=2.1.1. I've learned a bit more about timers and socket
|
|
||||||
* timeouts since then. Also, we have to handle timers in a different way now.
|
|
||||||
* There will still be a "timers" class, for re-occuring processes, but the
|
|
||||||
* next timer is inserted into this process queue, and the callback for the timer
|
|
||||||
* will be a pointer to the timer class which handles the timer. Then, the timer
|
|
||||||
* class will do the appropriate stuff for the timer, and then add the next timer
|
|
||||||
* into the process Queue. --Manick
|
|
||||||
*
|
|
||||||
* P.S.; I never knew this would change so much code... I figured adding in select()
|
|
||||||
* timeouts would be a piece of cake... until I realized that my whole framework
|
|
||||||
* was incompatible with the idea. What a pain in the ass -_-.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Module Written 11/30/04 by Manick */
|
|
||||||
|
|
||||||
class processQueue {
|
|
||||||
|
|
||||||
private $numQueued;
|
|
||||||
private $queuedItems;
|
|
||||||
private $currProc;
|
|
||||||
|
|
||||||
function __construct()
|
|
||||||
{
|
|
||||||
$this->queuedItemsArray = array();
|
|
||||||
$this->queuedItems = NULL;
|
|
||||||
$this->currProc = NULL;
|
|
||||||
$this->numQueued = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNumQueued()
|
|
||||||
{
|
|
||||||
return $this->numQueued;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getMicroTime()
|
|
||||||
{
|
|
||||||
return microtime(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Only allow removal of entire irc class (as in we shut down the bot.. otherwise, we don't
|
|
||||||
want to deal with shutting down specific queues during the queueing process. Have the callbacks
|
|
||||||
handle that themselves. We only have to worry when the callbacks won't exist anymore, as when an
|
|
||||||
irc bot is shut down, and the ircclass is discarded
|
|
||||||
*/
|
|
||||||
public function removeOwner($class)
|
|
||||||
{
|
|
||||||
$next = NULL;
|
|
||||||
|
|
||||||
for ($queue = $this->queuedItems; $queue != NULL; )
|
|
||||||
{
|
|
||||||
$next = $queue->next;
|
|
||||||
|
|
||||||
if ($queue->owner === $class)
|
|
||||||
{
|
|
||||||
$this->removeQueue($queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
$queue = $next;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Remove reference to queued item, let PHP5 do the rest */
|
|
||||||
private function removeQueue($item)
|
|
||||||
{
|
|
||||||
if ($item->prev == NULL)
|
|
||||||
{
|
|
||||||
$this->queuedItems = $item->next;
|
|
||||||
|
|
||||||
if ($item->next != NULL)
|
|
||||||
{
|
|
||||||
$item->next->prev = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$item->prev->next = $item->next;
|
|
||||||
|
|
||||||
if ($item->next != NULL)
|
|
||||||
{
|
|
||||||
$item->next->prev = $item->prev;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$item->removed = true;
|
|
||||||
|
|
||||||
unset($item->args);
|
|
||||||
unset($item->owner);
|
|
||||||
unset($item->callBack_class);
|
|
||||||
unset($item->next);
|
|
||||||
unset($item->prev);
|
|
||||||
|
|
||||||
unset($item);
|
|
||||||
|
|
||||||
$this->numQueued--;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add an item to the process queue */
|
|
||||||
public function addQueue($owner, $class, $function, $args, $nextRunTime)
|
|
||||||
{
|
|
||||||
// echo "Queue Added: $function with $nextRunTime\n";
|
|
||||||
|
|
||||||
if ($function == "" || $function == NULL)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_object($class))
|
|
||||||
{
|
|
||||||
$class = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$nextRunTime = floatval($nextRunTime);
|
|
||||||
|
|
||||||
$queue = new queueItem;
|
|
||||||
|
|
||||||
$queue->args = $args;
|
|
||||||
$queue->owner = $owner;
|
|
||||||
$queue->removed = false;
|
|
||||||
$queue->callBack_class = $class;
|
|
||||||
$queue->callBack_function = $function;
|
|
||||||
$queue->nextRunTime = self::getMicroTime() + $nextRunTime;
|
|
||||||
|
|
||||||
//Now insert as sorted into queue
|
|
||||||
|
|
||||||
$prev = NULL;
|
|
||||||
|
|
||||||
for ($item = $this->queuedItems; $item != NULL; $item = $item->next)
|
|
||||||
{
|
|
||||||
if ($queue->nextRunTime < $item->nextRunTime)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$prev = $item;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($item == NULL)
|
|
||||||
{
|
|
||||||
if ($prev == NULL)
|
|
||||||
{
|
|
||||||
$queue->next = NULL;
|
|
||||||
$queue->prev = NULL;
|
|
||||||
$this->queuedItems = $queue;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$queue->next = NULL;
|
|
||||||
$queue->prev = $prev;
|
|
||||||
$prev->next = $queue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($item->prev == NULL)
|
|
||||||
{
|
|
||||||
$queue->next = $this->queuedItems;
|
|
||||||
$queue->prev = NULL;
|
|
||||||
|
|
||||||
$item->prev = $queue;
|
|
||||||
$this->queuedItems = $queue;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$queue->next = $item;
|
|
||||||
$queue->prev = $item->prev;
|
|
||||||
|
|
||||||
$item->prev = $queue;
|
|
||||||
$queue->prev->next = $queue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Okay, we're inserted, return true;
|
|
||||||
|
|
||||||
$this->numQueued++;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function displayQueue()
|
|
||||||
{
|
|
||||||
//Used for debug
|
|
||||||
echo "Current Time: " . self::getMicroTime() . "\n";
|
|
||||||
|
|
||||||
echo "\n\n";
|
|
||||||
for ($i = $this->queuedItems; $i != NULL; $i = $i->next)
|
|
||||||
{
|
|
||||||
echo $i->callBack_function . "-" . $i->nextRunTime . "\n";
|
|
||||||
echo "---" . "Prev: " . $i->prev . " Next: " . $i->next . " Me: " . $i . "\n";
|
|
||||||
}
|
|
||||||
echo "\n\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Handle the process queue, return the time until the next item */
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
// Handle all items with $queue->nextRunTime < getMicroTime(), then return with time until next item must
|
|
||||||
// be run
|
|
||||||
|
|
||||||
// Populate a runQueue with all current items that need to be run. We need to do this because some of these
|
|
||||||
// callback functions might add another process to the queue, and if the runtime is < 0, we would run that item
|
|
||||||
// instead of timing out before we do. If we have something like a file transfer, this could be a bad thing.
|
|
||||||
$runQueue = array();
|
|
||||||
|
|
||||||
$time = self::getMicroTime();
|
|
||||||
|
|
||||||
for ($item = $this->queuedItems; $item != NULL; $item = $item->next)
|
|
||||||
{
|
|
||||||
if ($item->nextRunTime <= $time)
|
|
||||||
{
|
|
||||||
$runQueue[] = $item;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Okay, now run each item.
|
|
||||||
|
|
||||||
foreach ($runQueue AS $index => $item)
|
|
||||||
{
|
|
||||||
if (!is_object($item) || $item->removed === true)
|
|
||||||
{
|
|
||||||
if (is_object($item))
|
|
||||||
{
|
|
||||||
unset($item);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
self::handleQueueItem($item);
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($runQueue);
|
|
||||||
|
|
||||||
//Return time until next item needs to be run, or true if there are no queued items
|
|
||||||
//Hmm, true returned here, means we'll just sleep for like an hour or something until data
|
|
||||||
//is recieved from the sockets, because we have no active timers
|
|
||||||
if ($this->queuedItems == null)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get new time
|
|
||||||
$time = self::getMicroTime();
|
|
||||||
|
|
||||||
$timeTillNext = $this->queuedItems->nextRunTime - $time;
|
|
||||||
|
|
||||||
if ($timeTillNext < 0)
|
|
||||||
{
|
|
||||||
$timeTillNext = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//When zero is returned, we'll always sleep at least 50000 usec in the socket class anyway
|
|
||||||
return $timeTillNext;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Specific function to deal with queued items */
|
|
||||||
private function handleQueueItem($item)
|
|
||||||
{
|
|
||||||
$this->currTimer = $item;
|
|
||||||
|
|
||||||
$class = $item->callBack_class;
|
|
||||||
$func = $item->callBack_function;
|
|
||||||
|
|
||||||
//Call the callback function! Now the callback function will check all possible triggers,
|
|
||||||
//such as socket input, etc, and add new queued items if it needs more processing/other processing
|
|
||||||
|
|
||||||
if ($class == null)
|
|
||||||
{
|
|
||||||
$status = $func($item->args);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$status = $class->$func($item->args);
|
|
||||||
}
|
|
||||||
|
|
||||||
//If true is returned from the function, then keep the bitch in the queue. This is useful when a
|
|
||||||
//function has not completed processing (i.e., irc->connection waiting on socket class to return
|
|
||||||
//the fact that its connected.
|
|
||||||
|
|
||||||
if ($item->removed !== true && $status !== true)
|
|
||||||
{
|
|
||||||
self::removeQueue($item);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
1364
ircbot/readme.txt
1364
ircbot/readme.txt
File diff suppressed because it is too large
Load diff
|
@ -1,213 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2005 by http://www.phpbots.org/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > remote class module
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.2.0
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Remote, a class to handle addQuery connection from ircClass */
|
|
||||||
|
|
||||||
class remote {
|
|
||||||
|
|
||||||
//External Classes
|
|
||||||
private $socketClass;
|
|
||||||
private $ircClass;
|
|
||||||
private $timerClass;
|
|
||||||
|
|
||||||
//Internal variables
|
|
||||||
private $host;
|
|
||||||
private $port;
|
|
||||||
private $query;
|
|
||||||
private $line;
|
|
||||||
private $class;
|
|
||||||
private $function;
|
|
||||||
private $connTimeout;
|
|
||||||
private $transTimeout;
|
|
||||||
private $sockInt;
|
|
||||||
private $connection;
|
|
||||||
private $connected;
|
|
||||||
|
|
||||||
//Output internal variables
|
|
||||||
private $response;
|
|
||||||
private $type;
|
|
||||||
|
|
||||||
function __construct($host, $port, $query, $line, $class, $function, $transTimeout)
|
|
||||||
{
|
|
||||||
$this->host = $host;
|
|
||||||
$this->port = $port;
|
|
||||||
$this->query = $query;
|
|
||||||
$this->line = $line;
|
|
||||||
$this->class = $class;
|
|
||||||
$this->function = $function;
|
|
||||||
$this->transTimeout = $transTimeout;
|
|
||||||
$this->response = "";
|
|
||||||
$this->connected = false;
|
|
||||||
$this->type = QUERY_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setSocketClass($class)
|
|
||||||
{
|
|
||||||
$this->socketClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setIrcClass($class)
|
|
||||||
{
|
|
||||||
$this->ircClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTimerClass($class)
|
|
||||||
{
|
|
||||||
$this->timerClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function connect()
|
|
||||||
{
|
|
||||||
if ($this->host == null || $this->port == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_object($this->socketClass))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_object($this->ircClass))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$conn = new connection($this->host, $this->port, CONNECT_TIMEOUT);
|
|
||||||
|
|
||||||
$conn->setSocketClass($this->socketClass);
|
|
||||||
$conn->setIrcClass($this->ircClass);
|
|
||||||
$conn->setCallbackClass($this);
|
|
||||||
$conn->setTimerClass($this->timerClass);
|
|
||||||
|
|
||||||
/* Set Timeouts */
|
|
||||||
$conn->setTransTimeout($this->transTimeout);
|
|
||||||
|
|
||||||
$conn->init();
|
|
||||||
|
|
||||||
if ($conn->getError())
|
|
||||||
{
|
|
||||||
$this->setError("Could not allocate socket");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->sockInt = $conn->getSockInt();
|
|
||||||
$conn->connect();
|
|
||||||
|
|
||||||
$this->connection = $conn;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function disconnect()
|
|
||||||
{
|
|
||||||
$this->connection->disconnect();
|
|
||||||
$this->setError("Manual disconnect");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Specific handling functions */
|
|
||||||
|
|
||||||
public function onTransferTimeout($conn)
|
|
||||||
{
|
|
||||||
$this->connection->disconnect();
|
|
||||||
$this->setError("The connection timed out");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onConnectTimeout($conn)
|
|
||||||
{
|
|
||||||
$this->connection->disconnect();
|
|
||||||
$this->setError("Connection attempt timed out");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onConnect($conn)
|
|
||||||
{
|
|
||||||
$this->connected = true;
|
|
||||||
$this->socketClass->sendSocket($this->sockInt, $this->query);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onRead($conn)
|
|
||||||
{
|
|
||||||
$this->response .= $this->socketClass->getQueue($this->sockInt);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onWrite($conn)
|
|
||||||
{
|
|
||||||
// do nothing, we really don't care about this
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onDead($conn)
|
|
||||||
{
|
|
||||||
$this->connection->disconnect();
|
|
||||||
|
|
||||||
if ($this->connected === true)
|
|
||||||
{
|
|
||||||
$this->doCallback();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->setError($this->connection->getErrorMsg());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Error handling */
|
|
||||||
|
|
||||||
private function setError($msg)
|
|
||||||
{
|
|
||||||
$this->response = $msg;
|
|
||||||
$this->type = QUERY_ERROR;
|
|
||||||
$this->doCallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function doCallback()
|
|
||||||
{
|
|
||||||
if ($this->line != null && is_array($this->line) && isset($this->line['text']))
|
|
||||||
{
|
|
||||||
$lineArgs = parser::createLine($this->line['text']);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$lineArgs = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$func = $this->function;
|
|
||||||
$this->class->$func($this->line, $lineArgs, $this->type, $this->response);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
1010
ircbot/socket.php
1010
ircbot/socket.php
File diff suppressed because it is too large
Load diff
|
@ -1,235 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| PHP-IRC v2.2.1 Service Release
|
|
||||||
| ========================================================
|
|
||||||
| by Manick
|
|
||||||
| (c) 2001-2005 by http://www.phpbots.org/
|
|
||||||
| Contact: manick@manekian.com
|
|
||||||
| irc: #manekian@irc.rizon.net
|
|
||||||
| ========================================
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > timers module
|
|
||||||
| > Module written by Manick
|
|
||||||
| > Module Version Number: 2.2.0
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| > This program is free software; you can redistribute it and/or
|
|
||||||
| > modify it under the terms of the GNU General Public License
|
|
||||||
| > as published by the Free Software Foundation; either version 2
|
|
||||||
| > of the License, or (at your option) any later version.
|
|
||||||
| >
|
|
||||||
| > This program is distributed in the hope that it will be useful,
|
|
||||||
| > but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
| > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
| > GNU General Public License for more details.
|
|
||||||
| >
|
|
||||||
| > You should have received a copy of the GNU General Public License
|
|
||||||
| > along with this program; if not, write to the Free Software
|
|
||||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
| Changes
|
|
||||||
| =======-------
|
|
||||||
| > If you wish to suggest or submit an update/change to the source
|
|
||||||
| > code, email me at manick@manekian.com with the change, and I
|
|
||||||
| > will look to adding it in as soon as I can.
|
|
||||||
+---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Redesigned 12/22/04... Yes... this file sucks. I basically am going to
|
|
||||||
* do a few things here. I have been stuck on this file for the past 2 weeks,
|
|
||||||
* trying to come up with some ideas to handle the hopeless situation which
|
|
||||||
* faced me. With the new queue system, this timer class became very interesting
|
|
||||||
* to handle. I had to decide how I would add proc queues to the queue class
|
|
||||||
* to handle specific timers in this file. Say, for instance, that a timer
|
|
||||||
* is added, and then another is added that has a shorter time than that one.
|
|
||||||
* The first one will have a proc queue added into the queue class, but then
|
|
||||||
* the second one will have to add another proc queue. But hold on a second,
|
|
||||||
* the way this works right now, after a timer is done running, the next one
|
|
||||||
* is added to the process queue. I handled this by keeping track of how
|
|
||||||
* many processes were in the queue, and didn't add one if there were more than
|
|
||||||
* one, and the call to setCurrentTimer was from handle(). This worked, unless
|
|
||||||
* you have a timer that repeats. Then the problem comes in, as it will not be
|
|
||||||
* added to the proc queue until the next timer is complete. To just handle
|
|
||||||
* this problem, I'm just going to add a proc to the queue for every timer
|
|
||||||
* that is added, and then every timer will have a queue in the procqueue.
|
|
||||||
* that way, we don't have to worry about anything.
|
|
||||||
*
|
|
||||||
* Also, I added a "timerStack" so that I could have reserved names and what
|
|
||||||
* not. Each timer gets a unique name or ID, and that is added to the stack,
|
|
||||||
* as well as sorted into the timerList.
|
|
||||||
*
|
|
||||||
* Okay, way that timers are handled... has changed, if you want a timer to
|
|
||||||
* repeat, you must return true from the timer, runOnce was removed.
|
|
||||||
*
|
|
||||||
* Ooohh oohh ohh! Idea. screw linked lists and shit. I'll just add each
|
|
||||||
* timer to the proc queue, and then have them call handle() with the timer
|
|
||||||
* referenced! This solves all problems, and is incredibly more efficient!
|
|
||||||
* This officially takes the last linked list out of my bot. I have NO IDEA
|
|
||||||
* why I even used them in the first place, as php already has associative arrays
|
|
||||||
* which are a lot better! GEEZ!
|
|
||||||
*/
|
|
||||||
|
|
||||||
class timers {
|
|
||||||
|
|
||||||
//Local variables
|
|
||||||
private $timerStack = array(); //list of all timers indexed by name
|
|
||||||
|
|
||||||
//External Classes
|
|
||||||
private $procQueue;
|
|
||||||
private $socketClass;
|
|
||||||
private $ircClass;
|
|
||||||
|
|
||||||
//Private list of reserved php-irc timer names (please do not
|
|
||||||
//use these names)
|
|
||||||
private $reserved = array( "listening_timer_[0-9]*",
|
|
||||||
"check_nick_timer",
|
|
||||||
"check_channels_timer",
|
|
||||||
"check_ping_timeout_timer",
|
|
||||||
);
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->time = time();
|
|
||||||
$this->timerStack = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setSocketClass($class)
|
|
||||||
{
|
|
||||||
$this->socketClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setIrcClass($class)
|
|
||||||
{
|
|
||||||
$this->ircClass = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setProcQueue($class)
|
|
||||||
{
|
|
||||||
$this->procQueue = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getMicroTime()
|
|
||||||
{
|
|
||||||
return microtime(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTimers()
|
|
||||||
{
|
|
||||||
return $this->timerStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handle($timer)
|
|
||||||
{
|
|
||||||
$microTime = self::getMicroTime();
|
|
||||||
|
|
||||||
if (!isset($this->timerStack[$timer->name]))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->timerStack[$timer->name] !== $timer)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$timer->lastTimeRun = $microTime;
|
|
||||||
$timer->nextRunTime = $microTime + $timer->interval;
|
|
||||||
|
|
||||||
if ($timer->class != null)
|
|
||||||
{
|
|
||||||
$theFunc = $timer->func;
|
|
||||||
$status = $timer->class->$theFunc($timer->args);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$theFunc = $timer->func;
|
|
||||||
$status = $theFunc($timer->args);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($status != true)
|
|
||||||
{
|
|
||||||
$this->removeTimer($timer->name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->procQueue->addQueue($this->ircClass, $this, "handle", $timer, $timer->interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function removeAllTimers()
|
|
||||||
{
|
|
||||||
foreach ($this->timerStack AS $timer)
|
|
||||||
{
|
|
||||||
$this->removeTimer($timer->name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function addTimer($name, $class, $function, $args, $interval, $runRightAway = false)
|
|
||||||
{
|
|
||||||
if (trim($name) == "")
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($this->timerStack[$name]))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$newTimer = new timer;
|
|
||||||
|
|
||||||
$newTimer->name = $name;
|
|
||||||
$newTimer->class = $class;
|
|
||||||
$newTimer->func = $function;
|
|
||||||
$newTimer->args = $args;
|
|
||||||
$newTimer->interval = $interval;
|
|
||||||
$newTimer->removed = false;
|
|
||||||
|
|
||||||
if ($runRightAway == false)
|
|
||||||
{
|
|
||||||
$newTimer->lastTimeRun = $this->getMicroTime();
|
|
||||||
$newTimer->nextRunTime = $this->getMicroTime() + $interval;
|
|
||||||
$tInterval = $interval;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$newTimer->lastTimeRun = 0;
|
|
||||||
$newTimer->nextRunTime = $this->getMicroTime();
|
|
||||||
$tInterval = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->procQueue->addQueue($this->ircClass, $this, "handle", $newTimer, $tInterval);
|
|
||||||
|
|
||||||
$this->timerStack[$newTimer->name] = $newTimer;
|
|
||||||
|
|
||||||
return $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Remove the current timer from both the list and stack, changed in 2.1.2, can only call by
|
|
||||||
* timer name now.
|
|
||||||
*/
|
|
||||||
public function removeTimer($name)
|
|
||||||
{
|
|
||||||
if (!isset($this->timerStack[$name]))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Set removed flag,
|
|
||||||
$this->timerStack[$name]->removed = true;
|
|
||||||
|
|
||||||
//Remove from stack
|
|
||||||
unset($this->timerStack[$name]->args);
|
|
||||||
unset($this->timerStack[$name]->class);
|
|
||||||
unset($this->timerStack[$name]);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
|
@ -1,75 +0,0 @@
|
||||||
type file ~ ;----Used to import files
|
|
||||||
name ~ ;----the module name
|
|
||||||
filename
|
|
||||||
|
|
||||||
type section ~ ;----Used to section functions in dcc chat (used with 'help')
|
|
||||||
name ~ ;-id name to specify with dcc function
|
|
||||||
longname ~ ;-section name displayed when 'help' is pressed
|
|
||||||
|
|
||||||
type ctcp ~ ;----handle all ctcp commands
|
|
||||||
name ~ ;----the command typed (or trigger, like !list)
|
|
||||||
module ~
|
|
||||||
function
|
|
||||||
|
|
||||||
type priv ~ ;----Used to process input of users in channels
|
|
||||||
name ~
|
|
||||||
active ~
|
|
||||||
inform ~
|
|
||||||
canDeactivate ~
|
|
||||||
usage ~
|
|
||||||
module ~
|
|
||||||
function
|
|
||||||
|
|
||||||
type dcc ~ ;----Used to process input of users in dcc interface
|
|
||||||
name ~
|
|
||||||
numArgs ~
|
|
||||||
usage ~
|
|
||||||
help ~
|
|
||||||
admin ~
|
|
||||||
module ~
|
|
||||||
function ~
|
|
||||||
section ;--added 2.2.0
|
|
||||||
|
|
||||||
type privmsg ~ ;----Used to process privmsg irc command
|
|
||||||
module ~
|
|
||||||
function
|
|
||||||
|
|
||||||
type notice ~ ;----Used to process notice irc command
|
|
||||||
module ~
|
|
||||||
function
|
|
||||||
|
|
||||||
type mode ~ ;----Used to process mode irc command
|
|
||||||
module ~
|
|
||||||
function
|
|
||||||
|
|
||||||
type join ~ ;----Used to process join irc command
|
|
||||||
module ~
|
|
||||||
function
|
|
||||||
|
|
||||||
type kick ~ ;----Used to process kick irc command
|
|
||||||
module ~
|
|
||||||
function
|
|
||||||
|
|
||||||
type part ~ ;----Used to process part irc command
|
|
||||||
module ~
|
|
||||||
function
|
|
||||||
|
|
||||||
type quit ~ ;----Used to process quit irc command
|
|
||||||
module ~
|
|
||||||
function
|
|
||||||
|
|
||||||
type connect ~ ;----Perform on connect
|
|
||||||
module ~ ;----Note this is really 004 from irc
|
|
||||||
function
|
|
||||||
|
|
||||||
type disconnect ~ ;----Perform on disconnect $line['text'] holds reason
|
|
||||||
module ~ ;----Note, this is really ERROR from irc
|
|
||||||
function
|
|
||||||
|
|
||||||
type raw ~
|
|
||||||
module ~
|
|
||||||
function
|
|
||||||
|
|
||||||
type action ~
|
|
||||||
module ~
|
|
||||||
function
|
|
Loading…
Add table
Reference in a new issue