Search code examples
c++botsirc

Setting password in IRC BOT written in C++


I'm trying to make an IRC Bot that will log in to an existing account (on QuakeNet), so the Q bot can grant him the operator rank. I can successfully log in to server with a proper nick, but I don't know how to make my bot actually log in to an account. Here is the code I use:

send(cSock, "PASS SuperPasswordOfAnAdmin\r\n", strlen("PASS SuperPasswordOfAnAdmin\r\n"), NULL);
send(cSock, "USER custom 0 0 SuperUsernameOfAnAdmin\r\n", strlen("USER custom 0 0 SuperUsernameOfAnAdmin\r\n"), NULL);
send(cSock, "NICK SuperNickOfAnAdmin\r\n", strlen("NICK SuperNickOfAnAdmin\r\n"), NULL);

And it doesn't seems to work properly. Does anybody know what should I do? Thanks in advance for any replies.


Solution

  • I would suggest using a client like XChat and manually performing the steps that you're trying to have the bot automate and watching the raw log window. This will show you the commands that are being executed by your client, and anything the server is sending that you'll need to wait on or respond to.

    Note that when you're looking at the commands in the QuakeNet documentation, these are client commands, not the actual IRC commands that are sent to the server. For instance, /msg user message here is actually sent over the wire as PRIVMSG user :message here.

    I suspect you will have to do somewhat more than what your initial code suggests in order to properly satisfy the IRC server, like handling PING/PONG and waiting for the 001 numeric. In pseudocode:

    // connect
    conn := Connect("tcp", "your.irc.server:6667")
    
    // login
    Fprintf(conn, "PASS %s\r\n", server_password)
    Fprintf(conn, "USER %s . . :%s\r\n", username, realname)
    Fprintf(conn, "NICK %s\r\n", nick)
    
    forever {
      line := ReadLine(conn)
      command, args := ParseIRCLine(line)
      // welcome message, we're in!
      if command == "001" {
        break
      }
      // PING, send PONG
      if command == "PING" {
        Fprintf(conn, "PONG :%s\r\n", Join(args, " "))
      }
    }
    
    Fprintf("PRIVMSG Q@CServe.quakenet.org :AUTH %s %s\r\n", username, password)
    // wait for response from Q
    // join channels, etc
    // handle more pings, channel messages, etc