[Squalk-cvs] ircbot/lib class_irc.php,1.2,1.3 functions.php,1.2,1.3
Status: Inactive
Brought to you by:
mkavanagh
|
From: Matthew K. <mka...@us...> - 2004-05-01 14:07:01
|
Update of /cvsroot/squalk/ircbot/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14133/lib Modified Files: class_irc.php functions.php Log Message: functionality..of a sort ;) Index: functions.php =================================================================== RCS file: /cvsroot/squalk/ircbot/lib/functions.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** functions.php 15 Apr 2004 16:52:03 -0000 1.2 --- functions.php 1 May 2004 14:06:51 -0000 1.3 *************** *** 52,54 **** --- 52,99 ---- } } + + function parse_command($data) { + $data = explode(' ', str_replace("\r", '', str_replace("\n", '', $data))); + + $command = array(); + + $data[0] = str_replace(':', '', $data[0]); + + if(strrpos($data[0], '!') === FALSE) { + $command['type'] = 'server'; + $command['nick'] = NULL; + $command['user'] = NULL; + $command['host'] = $data[0]; + } + else { + $command['type'] = 'user'; + $data[0] = explode('!', $data[0]); + $command['nick'] = $data[0][0]; + $data[0][1] = explode('@', $data[0][1]); + $command['user'] = $data[0][1][0]; + $command['host'] = $data[0][1][1]; + } + + unset($data[0]); + + $command['command'] = $data[1]; + + unset($data[1]); + + $command['params'] = array(); + + foreach($data as $index => $datum) { + if($datum{0} === ':') { + break; + } + else { + $command['params'][] = $datum; + unset($data[$index]); + } + } + + $command['params'][] = substr(implode(' ', $data), 1); + + return $command; + } ?> \ No newline at end of file Index: class_irc.php =================================================================== RCS file: /cvsroot/squalk/ircbot/lib/class_irc.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** class_irc.php 15 Apr 2004 16:52:03 -0000 1.2 --- class_irc.php 1 May 2004 14:06:51 -0000 1.3 *************** *** 19,30 **** --- 19,52 ---- # $Id$ class irc extends irc_commands { + // Holds the socket resource for our connection. protected $socket; + + // Holds our current nickname. protected $nickname; + + // Holds our current username; cannot be changed + // while connected. protected $username; + + // Holds our current realname; cannot be changed + // while connected. protected $realname; + + // Holds the address of the server we connected + // to. protected $server; + + // Holds the number of the port we connected to + // on the server. protected $port; + + // An array of channels we are aware of. protected $channels = array(); + + // An array of users we are aware of. + protected $users = array(); + // Big nasty array of recieve and send handler + // functions. protected $handlers = array( 'recieve' => array( *************** *** 44,47 **** --- 66,73 ---- ); + // Attempts to connect to the server at $server:$port + // using a randomly generated nickname between user1000 + // and user9999, with $username and $realname as the + // username and realname respectively. public function connect($server, $port, $username, $realname) { $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); *************** *** 66,75 **** } public function register_recieve_raw_handler($handler) { $this->handlers['recieve']['raw'][] = $handler; } public function register_recieve_command_handler($command, $handler) { ! $this->handlers['recieve']['raw'][$command] = $handler; } --- 92,112 ---- } + // Registers a handler function for recieved data; + // note that this will return everything, not just + // stuff for a specific command; if you want that, + // use register_recieve_command_handler. Both will + // include the \r\n at the end. public function register_recieve_raw_handler($handler) { $this->handlers['recieve']['raw'][] = $handler; } + // Registers a handler function for a specific + // recieved command; note that this will include + // the nasty \r\n at the end. public function register_recieve_command_handler($command, $handler) { ! if(!isset($this->handlers['recieve']['raw'][$command])) { ! $this->handlers['recieve']['raw'][$command] = array(); ! } ! $this->handlers['recieve']['command'][$command][] = $handler; } *************** *** 88,91 **** --- 125,139 ---- $command = explode(' ', $data); $command = $command[1]; + + if($command == "NICK") { + $nick1 = explode('!', $data); + $nick1 = substr($nick1[0], 1); + $nick2 = explode(' ', $data); + $nick2 = substr($nick2[2], 1); + if($this->nickname == $nick1) { + $this->nickname = $nick2; + } + } + if(is_array($this->handlers['recieve']['command'][$command])) { foreach($this->handlers['recieve']['command'][$command] as $handler) { *************** *** 187,191 **** return false; } ! $command = substr($command, $written - 1, $length - $written); $totalwritten = $totalwritten + $written; } while($totalwritten != $totallength); --- 235,239 ---- return false; } ! $command = substr($command, $written - 1); $totalwritten = $totalwritten + $written; } while($totalwritten != $totallength); |