1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include "stdafx.h"
char *server = "69.162.163.86";
int port = 6667;
int numb;
char *nick = "IrcBot";
char *chan = "#locked";
char buff[4096];
char tmp[4096];
int main()
{
srand(time(0));
numb = rand()%99+1;
WSADATA WSAData;
WSAStartup(MAKEWORD(2,0), &WSAData);
SOCKADDR_IN sin;
SOCKET sock;
sock = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_addr.s_addr = inet_addr(server);
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
connect(sock, (SOCKADDR *)&sin, sizeof(sin));
memset(tmp,0,255);
sprintf(tmp,"USER LockBot \"\" \"127.0.0.1\" :%s%i%c",nick,numb,10);
send(sock,tmp,strlen(tmp),0);
memset(tmp,0,255);
sprintf(tmp,"NICK %s%i%c",nick,numb,10);
send(sock,tmp,strlen(tmp),0);
Sleep(100);
memset(tmp,0,255);
sprintf(tmp,"JOIN %s%c",chan,10);
send(sock,tmp,strlen(tmp),0);
while(1){
memset(buff,0,255);
recv( sock,buff,255,0);
cout << buff <<endl;
if ( strstr(buff,"PING") != 0 )
{
send(sock,"PONG :\r\n",6,0);
sprintf(tmp,"PRIVMSG %s : Pong!%c",chan,10);
send(sock,tmp,strlen(tmp),0);
cout << tmp;
}
else if ( strstr(buff,"!bot quit") !=0){
sprintf(tmp,"QUIT :Leaving... %c",10);
send(sock,tmp,strlen(tmp),0);
cout << tmp ;
}
};
}
|