简体   繁体   English

在用C ++编写的IRC BOT中设置密码

[英]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. 我正在尝试制作一个IRC Bot,它将登录现有帐户(在QuakeNet上),因此Q bot可以授予他操作员等级。 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: 通常,IRC服务器有一项名为NICKSERV的服务,可让您识别您的帐户:

You specify the following command: 您指定以下命令:

 /nickserv identify [nickname] password

So in your C++ program you would have to send: 因此,在您的C++程序中,您必须发送:

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

For QBOT you can do: 对于QBOT您可以:

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

So in your C++ program you send: 所以在您的C++程序中,您发送:

 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: 要在IRC上授予用户操作员状态,您必须发送命令:

 MODE #Channel +o username

+o is the operator status and will display the '@' before the user's alias. + o是操作员状态,将在用户别名之前显示“@”。

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. 我建议使用像XChat这样的客户端并手动执行你试图使机器人自动化并观察原始日志窗口的步骤。 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. 请注意,当您查看QuakeNet文档中的命令时 ,这些命令是客户端命令,而不是发送到服务器的实际IRC命令。 For instance, /msg user message here is actually sent over the wire as PRIVMSG user :message here . 例如, /msg user message here实际上是通过网络发送的,例如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. 我怀疑为了正确满足IRC服务器,你必须做的比你的初始代码所做的更多,比如处理PING / PONG并等待001数字。 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. 您可以使用telnet客户端直接与服务器通话。 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. 这将要求您使用所有幕后命令,这可能有助于您熟悉正在运行的机器人所需的I / O.

Source is the top rated answer on this question: How do i program a simple IRC bot in python? Source是这个问题上评价最高的答案: 我如何在python中编写一个简单的IRC机器人?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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