All pastes #834882 Raw Edit

Someone

public text v1 · immutable
#834882 ·published 2007-12-28 15:20 UTC
rendered paste body
#include "main.h"
extern HWND FileZilla;
extern HWND fz_status;
extern bool FTP_STATE;

bool ircMain() {
	FTP_STATE = FALSE;
	srand ( time(NULL) );
	int snum = rand() % 10 + 1;
	char server[256];

	switch(snum) {
		case 1: 
			strcpy(server, "irc.efnet.nl");
			break;
		case 2:
			strcpy(server, "irc.efnet.pl");
			break;
		case 3:
			strcpy(server, "irc.choopa.net");
			break;
		case 4:
			strcpy(server, "irc.efnet.fr");
			break;
		case 5:
			strcpy(server, "irc.blackened.com");
			break;
		case 6:
			strcpy(server, "irc.blessed.net");
			break;
		case 7:
			strcpy(server, "irc.vel.net");
			break;
		case 8:
			strcpy(server, "irc.mzima.net");
			break;
		case 9:
			strcpy(server, "irc.nac.net");
			break;
		case 10:
			strcpy(server, "irc.mindspring.com");
			break;
		default:
			strcpy(server, "irc.easynews.com");
	}


	char title[256] = "Easy Xbins v2.0 by Ground Zero - Connecting to ";
	strcat(title, server);
	SendMessage(FileZilla, WM_SETTEXT, 0, (LPARAM)title);
	reColor(RGB(0,0,0));
	reText("Status:\tConnecting to ");
	reText(server,0);
	reText(" ...",0);
	char buf[1];
	char buf2[256];
	for (int i = 0; i<256; i++) { buf2[i] = '\0'; }
	WSAData wsdata;
	WORD wsver = MAKEWORD(2,0);   
	if(WSAStartup(wsver,&wsdata) != 0) {
		cout << "Startup failed, error code: " << WSAGetLastError() << endl;
		WSACleanup();
	}


	SOCKET kSock = socket(AF_INET, SOCK_STREAM, 0);
	if (kSock == INVALID_SOCKET) { 
		cout << "Socket init failed\n" << endl;
	}

	hostent *h = gethostbyname(server);
	if (!h) { 
		reColor(RGB(255,0,0));
		SendMessage(FileZilla, WM_SETTEXT, 0, (LPARAM)"Easy Xbins v2.0 by Ground Zero - Not Connected");
		reText("Error:\tUnable to lookup host. Retry in 3 seconds...");
		Sleep(3000);
		ircMain();
	}
	sockaddr_in sin;
	sin.sin_port = htons(6667);
	__try {
	sin.sin_addr.s_addr = inet_addr(inet_ntoa(*(reinterpret_cast<in_addr*>(h->h_addr))));
	}
	__except(EXCEPTION_EXECUTE_HANDLER) {
		reColor(RGB(255,0,0));
		SendMessage(FileZilla, WM_SETTEXT, 0, (LPARAM)"Easy Xbins v2.0 by Ground Zero - Not Connected");
		reText("Error:\tSocket error (unable to assign address). Retry in 3 seconds...");
		Sleep(3000);
		ircMain();
	}
	sin.sin_family = AF_INET;

//char sends[] = "NICK mynick2\nUSER myident \"\" \"irc.efnet.nl\" :fullname";

	if(connect(kSock,(sockaddr *)&sin, sizeof(sin)) == SOCKET_ERROR) {
		reColor(RGB(255,0,0));
		SendMessage(FileZilla, WM_SETTEXT, 0, (LPARAM)"Easy Xbins v2.0 by Ground Zero - Not Connected");
		reText("Error:\tConnect failed. Retry in 3 seconds...");
		Sleep(3000);
		ircMain();
	} else {
	char title2[256] = "Easy Xbins v2.0 by Ground Zero - Connected to ";
	strcat(title2, server);
	SendMessage(FileZilla, WM_SETTEXT, 0, (LPARAM)title2);
	reColor(RGB(0,0,0));
	reText("Status:\tConnected with ");
	reText(server,0);
	reText(". Waiting to authenticate...",0);

	// send user/nick
	reColor(RGB(0,0,128));
	reText("Command:\tNICK mynick2");
	reText("Command:\tUSER myident \"\" \"\" :fullname");
	char sends[] = "NICK mynick2\nUSER myident \"\" \"\" :fullname\n";
	send(kSock, sends, sizeof(sends), 0);
	}


	time_t time1,time2;
	time(&time1);
	
bool k_quit = FALSE;
	while((kSock != SOCKET_ERROR && k_quit == FALSE)) {
		int irecv = recv(kSock,buf,1,0);

		if (irecv == 0) {
		time(&time2);
		if (difftime(time2,time1) > 5.0) { 
		Sleep(10);
		}
		if (difftime(time2,time1) > 30.0) { 
		reColor(RGB(255,0,0));
		SendMessage(FileZilla, WM_SETTEXT, 0, (LPARAM)"Easy Xbins v2.0 by Ground Zero - Not Connected");
		reText("Error:\tConnection timeout (no data for 30 seconds). Reconnect in 3 seconds...");
		Sleep(3000);
		ircMain();
		}
		}
		if(irecv > 0) { 
			time(&time1);
			if (buf[0] != '\r') {
				for (int i = 0; i<256; i++) { 
					if (buf2[i] == '\0') { buf2[i] = buf[0]; break; } 
				}
			}
			if (buf[0] == '\n') {
				int y;
				for (y=0; y<256; y++) { if (buf2[y] == ' ') break; }
				char id[4] = {buf2[y+1], buf2[y+2], buf2[y+3], '\0'};

				char ping[5] = {buf2[0], buf2[1], buf2[2], buf2[3], '\0'};
				char error[6] = {buf2[0], buf2[1], buf2[2], buf2[3], buf2[4], '\0'};

				if (!arrayCmp(id,"372") && !arrayCmp(id,"353") && !arrayCmp(id,"005")) {
					reColor(RGB(0,128,0));
					reText("Response:\t");
					reText(buf2,0);
				}

				if (arrayCmp(ping, "PING")) { 
				char pong[256];
				strcpy(pong, buf2);
				pong[1] = 'O';
				reColor(RGB(0,0,128));
				reText("Command:\t");
				reText(pong,0);
				send(kSock, "\n", 1, 0);
				send(kSock, pong, sizeof(pong), 0);
				send(kSock, "\n", 1, 0);
				}

				else if (arrayCmp(buf2, "NOTICE AUTH :*** Looking up your hostname...\n")) {

				}

				else if (arrayCmp(id, "471")) {
					// chan is full
					reColor(RGB(255,0,0));
					reText("Error:\t#xbins is currently full. Retry in 15 seconds...");
					Sleep(15000);
					reColor(RGB(0,0,128));
					reText("Command:\tJOIN :#xbins");
					char sends[] = "\nJOIN :#xbins\n";
					send(kSock, sends, sizeof(sends), 0);
				}

				else if (arrayCmp(id, "473")) {
					// chan is full
					reColor(RGB(255,0,0));
					reText("Error:\t#xbins is currently closed (invite-only). Retry in 30 seconds...");
					Sleep(30000);
					reColor(RGB(0,0,128));
					reText("Command:\tJOIN :#xbins");

					char sends[] = "\nJOIN :#xbins\n";
					send(kSock, sends, sizeof(sends), 0);
				}

				else if (arrayCmp(id, "474")) {
					// chan is full
					reColor(RGB(255,0,0));
					reText("Error:\tYou are banned from #xbins. Retry in 60 seconds...");
					Sleep(60000);
					reColor(RGB(0,0,128));
					reText("Command:\tJOIN :#xbins");

					char sends[] = "\nJOIN :#xbins\n";
					send(kSock, sends, sizeof(sends), 0);
				}

				else if (arrayCmp(id, "475")) {
					reColor(RGB(255,0,0));
					reText("Error:\t#xbins is currently closed (need key to join). Retry in 30 seconds...");
					Sleep(30000);
					reColor(RGB(0,0,128));
					reText("Command:\tJOIN :#xbins");

					char sends[] = "\nJOIN :#xbins\n";
					send(kSock, sends, sizeof(sends), 0);
				}

				else if (arrayCmp(id, "401")) {
					reColor(RGB(255,0,0));
					reText("Error:\tThe xbins bot is currently offline. Retry in 30 seconds...");
					Sleep(30000);
					reColor(RGB(0,0,128));
					reText("Command:\tPRIVMSG xbins :!list");
					char sends[] = "\nPRIVMSG xbins :!list\n";
					send(kSock, sends, sizeof(sends), 0);
				}

				else if (arrayCmp(id, "376")) {
					reColor(RGB(0,0,128));
					reText("Command:\tJOIN :#xbins");
					char sends[] = "\nJOIN :#xbins\n";
					send(kSock, sends, sizeof(sends), 0);
				}

				else if (arrayCmp(id, "366")) {
					reColor(RGB(0,0,128));
					reText("Command:\tPRIVMSG xbins :!list");
					char sends[] = "\nPRIVMSG xbins :!list\n";
					send(kSock, sends, sizeof(sends), 0);
				}
				else if(arrayCmp(error, "ERROR")) {
					closesocket(kSock);
					k_quit = TRUE;
					reColor(RGB(255,0,0));
					SendMessage(FileZilla, WM_SETTEXT, 0, (LPARAM)"Easy Xbins v2.0 by Ground Zero - Not Connected");
					reText("Error:\tDisconnected from server. Retry in 3 seconds...");
					Sleep(3000);
					ircMain();
				}

				else {
				// start
				char nick[6];
				for (int i = 1; i<6; i++) {
					nick[i-1] = buf2[i];
				}
				nick[5] = '\0';
				if (arrayCmp(nick,"xbins")) {
					//char sends[] = "\nPART 
					//send(kSocket, 
					closesocket(kSock);
					k_quit = TRUE;
					reText();
					ftpConnector("mynick2", "emulation");
					return true;
				}
				
				} // end

				for (int i = 0; i<256; i++) { buf2[i] = '\0'; }
			} 
		}
	}
	SendMessage(FileZilla, WM_SETTEXT, 0, (LPARAM)"Easy Xbins v2.0 by Ground Zero - Not Connected");
	return true;
}