Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-06-2009, 07:10 PM   PM User | #1
CyberPirate
Regular Coder

 
Join Date: Jan 2009
Location: Norway
Posts: 118
Thanks: 8
Thanked 2 Times in 2 Posts
CyberPirate is an unknown quantity at this point
IRC Bot issues.

Hello, I'm currently working on my IRC bot and it was all thanks to this script that I started this project.

After managing to connect to the server using that script, I converted it to OOP, because I need training in that department as well and now I'm stuck. At first I wanted to know how I could get the bot to send commands to the server when it was in an infinite loop, but I put that sort of on hold after a guy on Daniweb gave me a new piece of code to try out in order to read output from the server and do actions based on that.

The thread is here:
http://www.daniweb.com/forums/thread243489.html

If you read that thread you'd be able to understand more of my problem I think. So, as of now, I'm stuck with two issues at hand. After trying the new code the guy over at Daniweb gave me, I can't seem to connect to the server and I don't really know how to use the code he gave me, I tried to, but I don't know whether failed or not.

Here is my current script:
PHP Code:
<?php
    
class irc
    
{
        
// server connect
        
public $host "irc.freenode.net";
        public 
$port 6665;
        public 
$channel "#dinksmallwood";
        public 
$greetName;
        
        
// client-side
        
public $username "Dink_Smallwood";
        public 
$hostname "ti0184a340-0784.bb.online.no";
        public 
$server = array();
        public 
$crap 0;
        
        public function 
__construct()
        {
            
error_reporting(E_ALL);
            
ignore_user_abort(true);
            
set_time_limit(0);
        }
        
        public function 
ircConnect()
        {
            
// Connect to IRC server
            
$this->server['SOCKET'] = fsockopen($this->host$this->port$errno$errstr2);
            
// Needed headers in order to connect, otherwise we recieve error.
            
$this->server['HEADERS'] .= "NICK " $this->username "\n\r";
            
$this->server['HEADERS'] .= "USER " $this->username ' ' $this->hostname ' ' $this->host ' :' $this->username "\n\r";
            
// Sending headers.
            
$this->sendCmd($this->server['HEADERS'], true);
        }
        
        public function 
irc_loop()
        {
            if(
$this->server['SOCKET'])
            {
                while(!
feof($this->server['SOCKET']))
                {        
                    
$this->server['CMD_BUFFER'] = explode (" "trim(fgets($this->server['SOCKET'], 1024)));
                    
$this->server['RAW_BUFFER'] = fgets($this->server['SOCKET'], 1024);
                    echo 
"[RECEIVE] ".$this->server['RAW_BUFFER']."\n\r";

                    if (
strpos($this->server['RAW_BUFFER'], "End of /MODT command"))
                    {
                        
$this->sendCmd("JOIN ".$this->channel." \n\r"true);
                        
$this->sendCmd("PRIVMSG" " #dinksmallwood :" "Hello, I'm Dink Smallwood. I defeated Seth!" "\n\r"true);
                    }
                    
                    switch (
$this->server["CMD_BUFFER"][2])
                    {
                        case 
":JOIN":
                            
preg_match("(:([^!]+)!)"$this->server['READ_BUFFER'], $this->greetName);
                            
$this->sendCmd("PRIVMSG" " #dinksmallwood :" "Welcome ".$this->greetName[1]." to the Dink Smallwood IRC chat" "\n\r"true);
                            break;
                    }
                                        
                    if(
substr($this->server['CMD_BUFFER'][3], 06) == "PING :"
                    {
                        
$this->sendCmd("PONG :".substr($this->server['READ_BUFFER'][0], 6)."\n\r"true);
                    }
                    
flush(); 
                }
            }
        }
        
        public function 
sendCmd($command$showConsole false)
        {
            @
fputs($this->server['SOCKET'], $commandstrlen($command));
            if (
$showConsole == true)
            {
                echo 
"[SEND] ".$command." <br>";
            }
        }
    }
?>
Any help on this topic at hand will be appreciated!
CyberPirate is offline   Reply With Quote
Old 12-07-2009, 05:34 PM   PM User | #2
CyberPirate
Regular Coder

 
Join Date: Jan 2009
Location: Norway
Posts: 118
Thanks: 8
Thanked 2 Times in 2 Posts
CyberPirate is an unknown quantity at this point
Anyone? I'd really like some help on this.
CyberPirate is offline   Reply With Quote
Reply

Bookmarks

Tags
bot, commands, irc, output, server

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:14 AM.


Advertisement
Log in to turn off these ads.