socket = fsockopen($config['server'], $config['port']); $this->login($config); $this->main($config); } /* Logs the bot in on the server @param array */ function login($config) { $this->send_data('USER', $config['nick'].' wildphp.com '.$config['nick'].' :'.$config['name']); $this->send_data('NICK', $config['nick']); $this->join_channel($config['channel']); } /* This is the workhorse function, grabs the data from the server and displays on the browser */ function main($config) { $data = fgets($this->socket); echo $data; flush(); $this->ex = explode(' ', trim($data)); if($this->ex[0] == 'PING') { $this->send_data('PONG', $this->ex[1]); //Plays ping-pong with the server to stay connected. } $this->main($config); } function send_data($cmd, $msg = null) //displays stuff to the broswer and sends data to the server. { if($msg == null) { fputs($this->socket, $cmd."\r\n"); echo "-> $cmd\n"; } else { fputs($this->socket, $cmd.' '.$msg."\r\n"); echo "-> $cmd $msg\n"; } } function join_channel($channel) //Joins a channel, used in the join function. { if(is_array($channel)) { foreach($channel as $chan) { $this->send_data('JOIN', $chan); } } else { $this->send_data('JOIN', $channel); } } } //Start the bot $bot = new IRC($config); ?>