Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

C++ IRC bot


ghost's Avatar
0 0

Right. Here we are.

I've been working on this bot for about an hour, and I can't for the life of me work out how to get it to respond to PINGs.

Anyone who can get it to do that will get my undying respect.

*include <iostream> 
*include <string> 
*include <sys/types.h> 
*include <sys/socket.h> 
*include <netinet/in.h> 
*include <arpa/inet.h> 

using namespace std; 

class connection 
{ 
    public: 
    connection(int sock=0):sockfd(sock) 
    {} 
    int connecting() 
    { 
        target.sin_family = AF_INET; 
        target.sin_addr.s_addr = inet_addr("193.138.229.11");
        target.sin_port = htons(6667); 
        memset(&(target.sin_zero), '&*92;0', 8); 
        testcon = connect(sockfd, (struct sockaddr *)&target, sizeof(struct sockaddr)); 
        if(testcon != 0) 
        { 
            cout << "Unable to establish connection to server" << endl; 
        } 
        else 
        { 
            cout << "Connection established" << endl; 
        }     
        return testcon; 
    } 
    void joinroom() 
    { 
    a = 0; 
        get = -1; 
        while(1) 
        { 
            get = recv(sockfd, buf, 8192, 0); 
            cout << buf; 
            if(a == 1) 
            { 
                send(sockfd, "USER BobbyBot 8 * :BobbyBot&*92;r&*92;n", 30, 0); 
                cout << "Sent User" << endl; 
                a++; 
            } 
            if(a == 0) 
            { 
                send(sockfd, "NICK BobbyBot&*92;r&*92;n", 16, 0); 
                cout << "Sent Nick" << endl; 
                a++; 
            } 
            if (strstr(buf, "PING") != 0) 
            { 
                buf[1] = 79; 
                ponged = send(sockfd, buf, strlen(buf), 0); 
                cout << buf; 
                cout << ponged << endl; 
            } 
            memset (buf, '&*92;0', 8192); 
        } 
    }         
    ~connection() 
    {} 
    private: 
    int a, testcon, get, sockfd, ponged; 
    struct sockaddr_in target; 
    char buf[8192]; 
}; 
     
int main() 
{ 
    int connected; 
    connection * con = new connection(socket(PF_INET, SOCK_STREAM, 0)); 
    if(con->connecting() != 0) 
    { 
        return -1; 
    } 
    con->joinroom(); 
    return 0; 
} ```

For some reason, the hashes came out as asterisks, but you get the gist.

ghost's Avatar
0 0

no, "but I just saved a bunch of money on my car insurance using Geico."


ghost's Avatar
0 0

Wtf kinda post was that? And ill look for you bro.


ghost's Avatar
0 0

Why C++?


ghost's Avatar
0 0

to my humble opinion using JAVA or Python to make IRC bots are the best languages to use.


ghost's Avatar
0 0

DONT REPLY IF YOU HAVE NOTHING CONSTRUCTIVE TO SAY MORONS


ghost's Avatar
0 0

It's more to do with my unjustified disdain for interpreted languages. C++/C is just THAT much faster, and it's the language I've been programming in for ages.

The most annoying part is that I've done this before with no difficulty, but I'm tired and I'm making some stupid mistake.

DOn't worry guys, I'll feel more awake inn the morning and I'll sort this out.


ghost's Avatar
0 0

Willeh I'm sorry if my post did not educate you in any way. But I do not feel that EVERY SINGLE post in this forum has to be useful or "CONSTRUCTIVE" in your eyes some people (like myself) did not know what the advantages of coding the IRC bot in C++ were over PHP or Perl. So if you think I am a "MORON" for asking a simple question, I really wonder what your definition of a moron actually is.:(


ghost's Avatar
0 0

Oh and BobbyB I hope you manage to get it to respond to PINGs. Good Luck.