All pastes #495767 Raw Edit

ircbot skeleton try

public c v1 · immutable
·published 2007-05-18 22:15 UTC
rendered paste body
/***************************************//*NanoIRCBot by nano a.k.a Quan Chi2   *//*(c) 2007                             *//***************************************//*                                     *//*    usage: NanoIRCBot <serverip>     *//*                                     */ /***************************************/ /* C:\Program Files\Microsoft Visual Studio\MyProjects\NanoIRCBot\Debug */#include <winsock2.h>#include <stdio.h>#include <windows.h>#include <stdlib.h>#include <iostream.h>#define PORT 6667int main(int argc, char *argv[]){	char *nick		= "NICK nanobot\r\n"; //bot name	char *channel	= "JOIN #social\r\n";  //channel the bot will join	char *user      = "USER nano d d :nano\r\n";	char buf[512];//	char outbuf[512];	if (argc != 2)	{		fprintf(stderr,"[-]Usage: NanoIRCBot <serverip>\n");		exit(1);	}/*===========Initialize Winsock and declare connection variables.===========*/	WSADATA WSAData;	WSAStartup(MAKEWORD(2,0), &WSAData);  //Winsock 2.0	SOCKET connection;//this is a socket named 'connection'	SOCKADDR_IN sin;		connection = socket(AF_INET, SOCK_STREAM, 0); //'connection' is a stream socket	struct hostent *he;	if ((he = gethostbyname(argv[1])) == NULL) //get the ip of parameter 1 in command prompt	{		perror("gethostbyname"); //if there is a problem in gethostbyname, print the error		exit(EXIT_FAILURE);	}/*=================================Lets Get Busy=============================*/	int tries;	for(tries = 1;;tries++)	{		sin.sin_addr			= *((struct in_addr *)he->h_addr); //address to connect to		sin.sin_family			= AF_INET;						   //potocol AF_INET is everything		sin.sin_port			= htons(PORT);                     //the port the irc server has open for connections	    		printf("[-]Connecting...\n");				               //some stupid message.		Sleep(1000);		connect(connection, (SOCKADDR*)&sin, sizeof(sin));         //connect to the server		printf("[-]Connected!\n");		Sleep(100);		send(connection,nick,strlen(nick),0);		printf("[-]%s",nick);		send(connection,user,strlen(user),0);		printf("[-]%s",user);		send(connection,channel,strlen(channel),0);		printf("[-]%s",channel);				while(1) 		{			//memset(buf, 0, 512);			//memset(outbuf, 0, 512);			int stuff;			stuff = recv(connection,buf,sizeof(buf)-1,0);			int therappa;			int blahk;			therappa = sscanf(buf,"%25",0,&buf);			int pa;			pa = recv(connection,"PING : ",sizeof(buf), 0);			if(stuff = pa)			{				send(connection,"PONG : ",sizeof(buf),0);			}			//Sleep(100);						int parse;			parse = recv(connection, buf, strlen(buf), 0);			if(parse == 0)			{				return(0);	}	printf("\nRecieved : %d",parse);		}	}		return 0;}