Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 6th, 2005, 5:14 PM   #1
FoZ
Newbie
 
Join Date: Oct 2004
Posts: 20
Rep Power: 0 FoZ is on a distinguished road
My IRC bot

I have decided to make a simple IRC bot and slowly add more and more features to it. At the moment tho im just trying to get it to sit in a channel and then when I get it to do that it will basically act as a chat logger and keep itself alive replying to pings. Here is the code....
#include <iostream>
#include <winsock2.h>
#include <windows.h>

using namespace std;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
char buf[4096];
char mini[32];
char info[255] = "USER mytestapp test testing :my realname\r\nNICK MyIRC\r\n";
char channel[255] = "JOIN #chat\r\n";
char channelB[255] = "JOIN #myircchan\r\n";
char msg[255] = "PRIVMSG #chat :personal IRC client test\r\n";
char msgB[255] = "PRIVMSG FoZ :personal IRC client test\r\n";
char version[255] = "NOTICE Defender : VERSION MyOwnIRCImTrynaTest\r\n";
WSADATA wsadata;
SOCKET sock;
struct sockaddr_in addr;
struct hostent *host;
WSAStartup(514,&wsadata);
sock = socket(AF_INET,SOCK_STREAM,0);
host = gethostbyname("65.110.55.91");
memcpy(&addr.sin_addr.s_addr, host->h_addr,host->h_length);
addr.sin_family = AF_INET;
addr.sin_port = htons(6667);
int error;
int amnt = 0;
retry:
error = connect(sock,(sockaddr*)&addr,sizeof(addr));
cout << "HOST==" << host->h_addr << " .. " << host ->h_length << endl;
if (error==0) {
cout << "Connected!!!!" << endl;
}
else if (error!=0) {
closesocket(sock);
WSACleanup();
amnt++;
if (amnt>5) {
    goto quit;
    }
goto retry;
}
recv(sock,buf,sizeof(buf),0);
cout << buf << endl;
send(sock,info,sizeof(info),0);
cout << info << endl;
Sleep(2000);
memset(buf,0,sizeof(buf));

recv(sock,buf,sizeof(buf),0);
cout << buf << endl;
send(sock,channel,sizeof(channel),0);
cout << channel << endl;
Sleep(2000);
memset(buf,0,sizeof(buf));

recv(sock,buf,sizeof(buf),0);
cout << buf << endl;
send(sock,channelB,sizeof(channelB),0);
cout << channelB << endl;
Sleep(2000);
memset(buf,0,sizeof(buf));

recv(sock,buf,sizeof(buf),0);
cout << buf << endl;
send(sock,msg,sizeof(msg),0);
cout << msg << endl;
Sleep(2000);
memset(buf,0,sizeof(buf));

recv(sock,buf,sizeof(buf),0);
cout << buf << endl;
send(sock,msgB,sizeof(msgB),0);
cout << msgB << endl;
Sleep(2000);
memset(buf,0,sizeof(buf));

for (;;) {
recv(sock,buf,sizeof(buf),0);
cout << buf << endl;
if((buf[0] == 'P')	&& (buf[1] == 'I')	&& (buf[2] == 'N')	&& (buf[3] == 'G')) {
                    buf[1] = 'O';
					send(sock,buf,sizeof(buf),0);
					cout << buf << endl;
				}
Sleep(500);
memset(buf,0,sizeof(buf));
}

getchar();
closesocket(sock);
WSACleanup();
getchar();
quit:
return 0;
}

These are my current problems...

1) Getting it to receive the right amount of data after the nick etc has been sent because the amount ranges from server to server. So not receiving too much and then timing out because it is waiting for something that isn't coming and not receiving too little so it sends the message to join a channel half way through the server sending out its information.

2) Getting it to join a channel. Im not sure why it doesn't. It just doesn't.

There maybe more but i can't think of them right now. Can anyone help me sort these out?
FoZ is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:00 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC