简体   繁体   中英

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.

Usually IRC servers have a service called NICKSERV which allows you to identify your account:

You specify the following command:

 /nickserv identify [nickname] password

So in your C++ program you would have to send:

 send(cSock, "NICKSERV IDENTIFY SuperNickofAnAdmin SuperPasswordOfAnAdmin");

For QBOT you can do:

/msg Q@CServe.quakenet.org AUTH username password

So in your C++ program you send:

 send(cSock, "MSG Q@CServe.quakenet.org AUTH SuperNickofAnAdmin SuperPasswordOfAnAdmin");

To grant the user operator status on IRC you will have to send the command:

 MODE #Channel +o username

+o is the operator status and will display the '@' before the user's alias.

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

You can use a telnet client to speak directly with the server. This will require you to use all of the behind-the-scenes commands, which may help familiarize you with the required I/O needed for a running bot.

Source is the top rated answer on this question: How do i program a simple IRC bot in python?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM