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.
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
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.
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?
Related
Im trying to send an email in C++. I found the class CSmtp which looks like a fine one.So I tried out the example project but it gives the ErrorCode :
Error: Undefined error id.
Now I tried to find out where the problem is because the errorcode is too general.I Debuged the project find this Errorcode
ErrorCode WSA_SELECT (109) ECSmtp::CSmtpError
I googled after it but found no answer.Someone can help ?
Link for class : CSmtp with SSL/TLS
Code:
#include "CSmtp.h"
#include <iostream>
int main()
{
bool bError = false;
try
{
CSmtp mail;
#define test_gmail_tls
#if defined(test_gmail_tls)
mail.SetSMTPServer("smtp.gmail.com",587);
mail.SetSecurityType(USE_TLS);
#elif defined(test_gmail_ssl)
mail.SetSMTPServer("smtp.gmail.com",465);
mail.SetSecurityType(USE_SSL);
#elif defined(test_hotmail_TLS)
mail.SetSMTPServer("smtp.live.com",25);
mail.SetSecurityType(USE_TLS);
#elif defined(test_aol_tls)
mail.SetSMTPServer("smtp.aol.com",587);
mail.SetSecurityType(USE_TLS);
#elif defined(test_yahoo_ssl)
mail.SetSMTPServer("plus.smtp.mail.yahoo.com",465);
mail.SetSecurityType(USE_SSL);
#endif
mail.SetLogin("* My Email Adress *");
mail.SetPassword("*Password*");
mail.SetSenderName("User");
mail.SetSenderMail("* My Email Adress *");
mail.SetReplyTo("* Email Adress of my friend *");
mail.SetSubject("The message");
mail.SetXPriority(XPRIORITY_NORMAL);
mail.SetXMailer("The Bat! (v3.02) Professional");
mail.AddMsgLine("Hello,");
mail.AddMsgLine("");
mail.AddMsgLine("...");
mail.AddMsgLine("How are you today?");
mail.AddMsgLine("");
mail.AddMsgLine("Regards");
mail.ModMsgLine(5,"regards");
mail.DelMsgLine(2);
mail.AddMsgLine("User");
//mail.AddAttachment("../test1.jpg");
//mail.AddAttachment("c:\\test2.exe");
//mail.AddAttachment("c:\\test3.txt");
mail.Send();
}
catch(ECSmtp e)
{
std::cout << "Error: " << e.GetErrorText().c_str() << ".\n";
bError = true;
}
if(!bError)
std::cout << "Mail was send successfully.\n";
return 0;
}
I would suggest you to go with powershell script for sending email and then call that script from your c++ program. Use smtp.gmail.com as server & 465 port. :)
This can help..
https://github.com/udit043/Send-email-using-powershell
Standard C++11 does not have such facilities (but your particular OS might provide additional SMTP client libraries). Maybe you want a library like vmime or a framework like POCO
Notice that the very ability of email is operating system specific.
Also, most SMTP servers are configured to reject open mail relaying (otherwise, they would be used by spam bots, and emails going thru them would be rejected since blacklisted).
You could for example configure some SMTP service on your local machine or server, and programmatically send email thru localhost (then the SMTP server would spool and relay the email, etc.) - or to some specific and well-defined "smarthost" if your system and network has one; you probably don't want to wire-in some SMTP relay host names in your program, and you do want the email to be spooled (not lost!) if the recipient SMTP server is down or unreachable; in other words, you need some SMTP server.
You certainly don't want to code your SMTP server from scratch!
Hence, your program should only send SMTP to some trusted host, which is correctly configured to avoid spamming (then you might need to set some From or Reply-To SMTP header to something appropriate for your SMTP host). Be sure that major Internet companies like Google, Yahoo, AOL etc... are configuring carefully their SMTP service to disallow open relay spamming. Often, they accept SMTP relay connections only from their business clients (and they would cut a client doing automated spamming). So you should send SMTP to your ISP's SMTP server (or to some local or near SMTP server).
Notice that spamming is usually forbidden by law or by your ISP terms of service.
You could also run some command (e.g. using popen) to send mail ...
I'm working on a project that uses Mongoose, and I need to make a POST request to another server. I don't see an example of how to do this in their examples list, does anyone know how to do this?
EDIT to add more detail:
I'm working within a larger C++ app and need to create a simple server such that a user can query the app for information. Right now, I start the server like this:
Status sampleCmd::startServer()
{
Status stat = MS::kSuccess;
struct mg_server *server;
// Create and configure the server
server = mg_create_server(NULL, ev_handler);
mg_set_option(server, "listening_port", "8080");
stopServer = false;
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
while (!stopServer) //for (;;)
{
mg_poll_server(server, 1000);
}
// Cleanup, and free server instance
mg_destroy_server(&server);
return stat;
}
In my event handler, I parse the provided URI for a particular one and then run some commands with the application's API. I need to send these results back to a server for the user to see. It's this latter step that is unclear to me. It seems odd that a web server library wouldn't have some client functionality, don't servers need to talk to other servers?
Okay, it turns out I was thinking about this wrong. I needed to respond to the POST request I was getting. So using mg_printf_data(...) with the connection object worked for me.
Iam trying to send a message to activemq using pythons stompclient.
https://bitbucket.org/hozn/stompclient/wiki/User%20Documentation
If there is a better library for this Im open to suggestions.
If i change to ip or port it will fail to connect so im assuming that the connection is working. There are no errors when I run this code its just that I see no messages on the queue. I think the destination path is possibly where it is failing the PhysicalName of the activemq queue is in this pattern 'abc.queue_name'.
I've tried the following destinations
/queue/abc/queue_name
/queue/abc.queue_name
abc.queue_name
Any suggestions are greatly appreciated.
Thanks
from stompclient import PublishClient
client = PublishClient('IP', 53680)
response = client.connect('defaultPassword', 'defaultUser')
reponse1 = client.send('/queue/abc/queue_name', 'bla')
time.sleep(5)
Have you checked the webconsole to see if your Queue was created by the send?
You should also try adding a request id onto the send and waiting for a response, this will ensure that the broker has enough time to get the sent data before you client code disconnects.
You might also want to check the Broker logs to see if any errors are logged or any security warnings in case the user doesn't have publish rights.
Added this property to the activemq.xml file and im now seeing messages on the queue via the web console.
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613"/>
So I'm trying to make an IRC bot that can connect to the Twitch.tv IRC servers using C++. So far, I've managed to get this bot to connect to IRC servers that don't require any sort of password, but I'm getting tripped up at the part where I need the bot to provide a password. So what I've currently got is:
(Connecting to the server)
send(cSock, "USER custom 0 0 <bot_name>\r\n", strlen("USER custom 0 0 <bot_name>\r\n"), NULL);
send(cSock, "PASS <twitch_oauth_token>\r\n", strlen("PASS <twitch_oauth_token>\r\n"), NULL);
send(cSock, "NICK <bot_name>\r\n", strlen("NICK <name>\r\n"), NULL);
(Joining a channel)
send(cSock, "JOIN #<channel_name>\r\n", strlen("JOIN #<channel_name>\r\n"), NULL);
send(cSock, "PRIVMSG #<channel_name> :Message\r\n", strlen("PRIVMSG #<channel_name> :Message\r\n"), NULL);
The bot will say a message upon joining a channel. I've tested this bot without the line containing PASS to connect to irc.quakenet.org without needing to provide authentication information, but I want to be able to have the bot provide authentication information to irc.twitch.tv so that I can use it on a registered account there.
What am I doing wrong?
Update:
Never mind...I figured out what I did wrong. Apparently I had to send the PASS before I sent the USER or NICK. Everything seems to be working alright at this point.
Thanks for all your help anyway.
What are you doing wrong?
Presumably, the server is telling you. Did you look at the conversation it's having with your bot? I'm assuming no, since you didn't paste it here.
Get a log of the conversation. Either have the bot print it out, or use a network packet sniffer such as tcpdump or Wireshark.
You must send the oauth password before you send the user.
[edit] saw where you updated[/edit]
I send mail from vmime using the following code:
vmime::string urlString;
urlString="smtp://outgoing.verizon.net";
vmime::utility::url url(urlString);
vmime::ref <vmime::net::transport> tr =
g_session->getTransport(url,vmime::create <interactiveAuthenticator>());
// You can also set some properties (see example7 to know the properties
// available for each service). For example, for SMTP:
tr->setProperty("options.need-authentication", true);
tr->setProperty("auth.username", userName);
tr->setProperty("auth.password", password);
fromString=userName+"#verizon.net";
vmime::mailbox from(fromString);
vmime::mailboxList to;
toString = toUserName+"#verizon.net";
to.appendMailbox(vmime::create <vmime::mailbox>(toString));
std::ostringstream data;
data<<subjectId;
// Connect to server
tr->connect();
// Send the message
vmime::string msgData = data.str();
vmime::utility::inputStreamStringAdapter vis(msgData);
tr->send(from, to, vis, msgData.length());
logMsg(DEBUG,2,"Thread Id: %ld,Sent the data in the transaction",pthread_self());
I see that the sent data is succesful from the log.
But when i connect to the box[to which the mail was sent] and check the inbox, i see 0 mails to that inbox.
There is no excepton or error from vmime.
when i connect to the web version of the mail box.Iam unable to see any transactions is sent box, even for the succesful mails.Can anyone help how i can see the mails sent in the sent box?
Thanks in advance.
use any sniffer to catch SMTP traffic from your host. if everything looks good (i.e. SMTP session correct), then it's not a problem of your host, but remote MTA (make sure your email wasn't detected as SPAM & etc)