C++ IRC bot
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.
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.
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.:(