#pragma comment(lib, "ws2_32") #include #include #include //structure of the bot info typedef struct BotInfo{ SOCKET BotSock; char *szServer; char *szChannel; char *szNick; char *szPong; char *szRecvBuff; int nPort; char *EntryMsg; }BOTINFO, *PBOTINFO; //the receive and functions part - change this part to costumize it DWORD WINAPI Recieve(LPVOID lpParam) { PBOTINFO dibi = (PBOTINFO)lpParam; char *szCmd = (char*)malloc(513); char *szStr; while(TRUE){ Sleep(4); recv(dibi->BotSock, szCmd, strlen(szCmd), 0); if((szStr = strstr(szCmd, ":DaBuKe!"))){ //checks if the person speaking is ME, as in ME MYSELF AND I, change it to :[insert username here]! for it to adapt //now, the list of commands received if((szStr = strstr(szCmd, ":!nick"))) { char *szCom = (char*)malloc(513); //creates space for buffer to be sent to irc sprintf(szCom, "NICK %s\r\n\0", szStr + 7); //put's in those things into the buffer send(dibi->BotSock, szCom, strlen(szCom), 0); //sends the buffer through the dibi socket, strlen(szCom) to prevent overflow /* the same type of lines except with different commands. Refer to http://www.irchelp.org/irchelp/rfc/rfc.html for irc protocol reference. */ } else if((szStr = strstr(szCmd, ":!op"))) { char *szCom = (char*)malloc(513); sprintf(szCom, "MODE %s +o %s\r\n\0", dibi->szChannel, szStr+5); send(dibi->BotSock, szCom, strlen(szCom), 0); } else if((szStr = strstr(szCmd, ":!deop"))) { char *szCom = (char*)malloc(513); sprintf(szCom, "MODE %s -o %s\r\n0", dibi->szChannel, szStr+7); send(dibi->BotSock, szCom, strlen(szCom), 0); } else if((szStr = strstr(szCmd, ":!hop"))) { char *szCom = (char*)malloc(513); sprintf(szCom, "MODE %s +h %s\r\n\0", dibi->szChannel, szStr+6); send(dibi->BotSock, szCom, strlen(szCom), 0); } else if((szStr = strstr(szCmd, ":!dehop"))) { char *szCom = (char*)malloc(513); sprintf(szCom, "MODE %s -h %s\r\n\0", dibi->szChannel, szStr+6); send(dibi->BotSock, szCom, strlen(szCom), 0); } else if((szStr = strstr(szCmd, ":!kick"))) { char *szCom = (char*)malloc(513); sprintf(szCom, "KICK %s %s :You just got owned by DaBuKe\r\n\0", dibi->szChannel, szStr+7); send(dibi->BotSock, szCom, strlen(szCom), 0); } else if((szStr = strstr(szCmd, ":!password"))) { char *szCom = (char*)malloc(513); sprintf(szCom, "MODE %s +k %s\r\n\0", dibi->szChannel, szStr+11); send(dibi->BotSock, szCom, strlen(szCom), 0); } else if((szStr = strstr(szCmd, ":!nopassword"))) { char *szCom = (char*)malloc(513); sprintf(szCom, "MODE %s -k\r\n\0", dibi->szChannel); send(dibi->BotSock, szCom, strlen(szCom), 0); } else if((szStr = strstr(szCmd, ":!topic"))) { char *szCom = (char*)malloc(513); sprintf(szCom, "TOPIC %s :%s\r\n\0", dibi->szChannel, szStr+8); send(dibi->BotSock, szCom, strlen(szCom), 0); } else if((szStr = strstr(szCmd, ":!leave"))) { char *szCom = (char*)malloc(513); sprintf(szCom, "PART %s\r\n\0", dibi->szChannel); send(dibi->BotSock, szCom, strlen(szCom), 0); } else if((szStr = strstr(szCmd, ":!ban"))) { char *szCom = (char*)malloc(513); sprintf(szCom, "MODE %s +b %s\r\n\0", dibi->szChannel, szStr+6); send(dibi->BotSock, szCom, strlen(szCom), 0); } else if((szStr = strstr(szCmd, ":!unban"))) { char *szCom = (char*)malloc(513); sprintf(szCom, "MODE %s -b %s\r\n\0", dibi->szChannel, szStr+8); send(dibi->BotSock, szCom, strlen(szCom), 0); } else if((szStr = strstr(szCmd, ":!stfu"))) { char *szCom = (char*)malloc(513); sprintf(szCom, "MODE %s -v %s\r\n\0", dibi->szChannel, szStr+7); send(dibi->BotSock, szCom, strlen(szCom), 0); } else if((szStr = strstr(szCmd, ":!unstfu"))) { char *szCom = (char*)malloc(513); sprintf(szCom, "MODE %s +v %s\r\n\0", dibi->szChannel, szStr+9); send(dibi->BotSock, szCom, strlen(szCom), 0); } else if((szStr = strstr(szCmd, ":!version"))) { char *szCom = (char*)malloc(513); sprintf(szCom, "PRIVMSG %s his is %s talking in %s. Version: 0.1 SF OWNS JALL", dibi->szChannel, dibi->szNick, dibi->szChannel); send(dibi->BotSock, szCom, strlen(szCom), 0); } else if((szStr = strstr(szCmd, ":!cycle"))){ char *szCom = (char*)malloc(513); sprintf(szCom, "PART %s\r\n\0", szStr + 7); send(dibi->BotSock, szCom, strlen(szCom), 0); sprintf(szCom, "JOIN %s\r\n\0", szStr + 7); send(dibi->BotSock, szCom, strlen(szCom), 0); } else if((szStr = strstr(szCmd, ":!powertrip"))) { char *szCom = (char*)malloc(513); sprintf(szCom = "MODE %s +ohv %s\r\n\0", dibi->szChannel, szStr+12); send(dibi->BotSock, szCom, strlen(szCom), 0); } /* not done yet else if((szStr = strst(szCmd, ":!talk"))) { char *szCom = (char*)mallc(513); sprintf(szCom, " } else if((szStr = strstr(szCmd, ":!ultikill"))) { char *szCom = (char*)malloc(513); sprintf(szCom, "KICK %s miniman } */ } //replies to ping, keeps the bot alive DWORD KeepAlive(LPVOID lpParam) { char *szRec = (char*)malloc(513); recv(dibi->BotSock, szRec, strlen(szRec), 0) if(szRec == PING) { szRec[1] = 'O'; send(dibi->BotSock, szRec, strlen(szRec), 0); } } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { //struct bot info for IRC server, channel, nickname , port, etc. BOTINFO dibi = { 0, "irc.srv.com", "#CPP", "CppBot", new char[513], new char[513], 6667, "SFBOT Version 1.0" }; WSADATA wsaData; WSAStartup(MAKEWORD(2, 0), &wsaData); dibi.BotSock = socket(AF_INET, SOCK_STREAM, 0); if(dibi.BotSock == INVALID_SOCKET){ Report("Failed to create Socket!"); WSACleanup(); return FALSE; } SOCKADDR_IN SockInfo; PHOSTENT pheServer = gethostbyname(dibi.szServer); SockInfo.sin_addr = *(struct in_addr *)pheServer->h_addr_list[0]; SockInfo.sin_family = AF_INET; SockInfo.sin_port = htons(dibi.nPort); int nResult = connect(dibi.BotSock, (SOCKADDR*)&SockInfo, sizeof(SockInfo)); if(nResult == SOCKET_ERROR){ Report("Failed to connect to server!"); WSACleanup(); return FALSE; } CreateThread(0, NULL, (LPTHREAD_START_ROUTINE)&Recieve, &dibi, NULL, NULL); CreateThread(0, NULL, (LPTHREAD_START_ROUTINE)&KeepAlive, &dibi, NULL, NULL); char *szConn = (char*)malloc(513); sprintf(szConn, "USER %s . . :SF\r\nNICK %s\r\n\0", dibi.szNick, dibi.szNick); send(dibi.BotSock, szConn, strlen(szConn), 0); char *szJoin = (char*)malloc(513); sprintf(szJoin, "JOIN %s\r\n\0", biMini.szChannel); send(dibi.BotSock, szJoin, strlen(szJoin), 0); Sleep(10000); char *szSay = (char*)malloc(513); sprintf(szSay, "PRIVMSG NickServ :identify operator\r\n\0", biMini.szChannel); send(dibi.BotSock, szSay, strlen(szSay), 0); char *szMsg = (char*)malloc(513); sprintf(szMsg, "PRIVMSG %s :%s\r\n\0", biMini.szChannel, biMini.EntryMsg); send(dibi.BotSock, szMsg, strlen(szMsg), 0); //msg loop MSG Msg; while(GetMessage(&Msg, NULL, 0, 0)){ TranslateMessage(&Msg); DispatchMessage(&Msg); } delete dibi.szRecvBuff, dibi.szPong; return 0; }