Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstring>
- #include <WinSock2.h>
- #include <stdio.h>
- #include <iostream>
- #define isme() (strstr(word[0], "!MarioAweso@") && strstr(word[0], ".dc.dc.cox.net"))
- #define isdragonite() (strstr(word[0], "!Dragonite@") && strstr(word[0], ".lightspeed.bcvloh.sbcglobal.net"))
- #define isumlautbanana() (strstr(word[0], "!What@") && strstr(word[0], ".This.Blasphemy"))
- #define ismolsno() (strstr(word[0], "!MolSno@") && strstr(word[0], ".nap.wideopenwest.com"))
- #define say(str) sprintf(tmpSprintf, "%s %s :%s\n", word[1], word[2], str); sendData(tmpSprintf)
- #define die(str) say(str); return
- #define onlyme() if (!isme() && !isdragonite() && !isumlautbanana() && !ismolsno()) { die("Access denied."); }
- #pragma warning(disable:4996)
- #pragma comment(lib, "ws2_32.lib")
- using namespace std;
- string nick;
- bool kickmanoccuring;
- string setword;
- string guessword;
- char * word[512];
- char * word_eol[512];
- char nullStr[1]="";
- bool hasPinged=false;
- char tmpSprintf[8192];
- SOCKET mySocket;
- #define bufSize 8192
- char rcvBuf[bufSize];
- char rcvLine[bufSize];
- char wordLine[bufSize];
- void HandleMsg();
- void GetWordArrays()//create word[] and word_eol[] arrays
- {
- strcpy(wordLine,rcvLine);//copy word_eol[]'s memory to word[]'s memory
- char* placeInWordEol=rcvLine;
- char* placeInWord=wordLine;
- int NumWords;
- for (NumWords=0;placeInWordEol[0] && strchr(placeInWordEol,' ') && NumWords<28;NumWords++)
- {
- word_eol[NumWords]=placeInWordEol;
- placeInWordEol=strchr(placeInWordEol,' ')+1;//go to next word
- word[NumWords]=placeInWord;
- placeInWord=strchr(placeInWord,' ');//go to next space...
- placeInWord[0]=0;//change it to a NULL character...
- placeInWord++;//and go to next word
- if (!word[NumWords][0])//remove empty words
- {
- NumWords--;
- }
- }
- word_eol[NumWords]=placeInWordEol;//the last words won't get added otherwise for some reason
- word[NumWords]=placeInWord;
- word_eol[NumWords+1]=nullStr;//add empty strings to the end of the word lists
- word[NumWords+1]=nullStr;
- for (int tmp=0;rcvLine[tmp];tmp++)//remove CRLF's
- {
- char temp=rcvLine[tmp];
- if (temp=='\r' || temp=='\n')
- {
- if (rcvLine[tmp-1]==1 && tmp)
- {
- rcvLine[tmp-1]=0;
- wordLine[tmp-1]=0;
- }
- rcvLine[tmp]=0;
- wordLine[tmp]=0;
- }
- }
- }
- void HandleRecived(char * input)
- {
- char * placeInInput=input;
- char * nextNewline;
- while (nextNewline=strchr(placeInInput,'\n'))
- {
- nextNewline[0]=0;
- strcat(rcvLine,placeInInput);
- nextNewline[0]='\n';
- rcvLine[strlen(rcvLine)+1]=0;
- rcvLine[strlen(rcvLine)]='\n';
- placeInInput=nextNewline+1;
- HandleMsg();
- rcvLine[0]=0;
- }
- if (strlen(placeInInput))
- {
- strcat(rcvLine, placeInInput);
- }
- }
- inline void sendData(const char * data)
- {
- cout<<"<< "<<data;
- send(mySocket, data, strlen(data), 0);
- }
- void HandleMsg()
- {
- GetWordArrays();
- cout<<">> "<<word_eol[0]<<endl;
- hasPinged=false;
- if (!stricmp(word[0], "PING"))
- {
- word_eol[0][1]='O';
- int tmp=strlen(word_eol[0]);
- word_eol[0][tmp]='\n';
- word_eol[0][tmp+1]=0;
- sendData(word_eol[0]);
- }
- else if (!stricmp(word[1], "001"))
- {
- sendData("NS identify password denied\n");
- sendData("JOIN #wordgames,#seriousbusiness,#teamgame,#MATheHackTester,#grills,#dummies,#glitch,#randomness,#TheGag96,#kaizo,#moltensnow\n");
- }
- else if (!stricmp(word[2], "PONG"))
- {
- sprintf(tmpSprintf, "nick %s_\n", word[3]);
- sendData(tmpSprintf);
- }
- else if (!stricmp(word[1], "PRIVMSG"))
- {
- if (stricmp(word[3]+1, "!gm")) return;
- {
- if (word[2][0]!='#')
- {
- static char name[256];
- strcpy(name, word[0]+1);
- if (strchr(name, '!')) *strchr(name, '!')=0;
- word[2]=name;
- }
- if (!stricmp(word[4], "SAY"))
- {
- if (word[5][0] == '#') {
- sprintf(tmpSprintf, "privmsg %s :%s\n", word[5], word_eol[6]);
- }
- else {
- sprintf(tmpSprintf, "privmsg %s :%s\n", word[2], word_eol[5]);
- }
- sendData(tmpSprintf);
- }
- else if (!stricmp(word[4], "LARD"))
- {
- if (word[5][0] == '#') {
- sprintf(tmpSprintf, "privmsg %s :What, dude, did you want to grease something????\n", word[5]);
- }
- else {
- sprintf(tmpSprintf, "privmsg %s :What, dude, did you want to grease something????\n", word[2]);
- sendData(tmpSprintf);
- }
- }
- else if (!stricmp(word[4], "JOIN"))
- {
- onlyme();
- sprintf(tmpSprintf, "join %s :\n", word[5]);
- sendData(tmpSprintf);
- }
- else if (!stricmp(word[4], "PART"))
- {
- onlyme();
- sprintf(tmpSprintf, "part %s :%s\n", word[5], word_eol[6]);
- sendData(tmpSprintf);
- }
- else if (!stricmp(word[4], "NICK"))
- {
- onlyme();
- sprintf(tmpSprintf, "nick %s :\n", word[5]);
- sendData(tmpSprintf);
- nick=word[5];
- }
- else if (!stricmp(word[4], "KICK"))
- {
- onlyme();
- if (!stricmp(word[6], nick.c_str())) {
- die("WHY WOULD YOU MAKE ME DO THIS?");
- }
- if (word[5][0] == '#') {
- sprintf(tmpSprintf, "kick %s %s :%s\n", word[5], word[6],word_eol[7]);
- }
- else {
- sprintf(tmpSprintf, "kick %s %s :%s\n", word[2], word[5],word_eol[6]);
- }
- sendData(tmpSprintf);
- }
- else if (!stricmp(word[4], "BAN"))
- {
- onlyme();
- sprintf(tmpSprintf, "mode %s +b %s", word[5], word_eol[6]);
- sendData(tmpSprintf);
- }
- else if (!stricmp(word[4], "FIXNICK"))
- {
- onlyme();
- sendData("NICK GameMaster\n");
- sendData("NS identify password denied\n");
- sendData("NS update\n");
- nick = "GameMaster";
- }
- else if (!stricmp(word[4], "UNO"))
- {
- if (word[5][0] == '#') {
- sprintf(tmpSprintf, "privmsg %s :Uno start! Time to... to... lashdfkljashkldfjhaslkdjfhlkjdshflkjdshf\n", word[5]);
- }
- else {
- sprintf(tmpSprintf, "privmsg %s :Uno start! Time to... to... lashdfkljashkldfjhaslkdjfhlkjdshflkjdshf\n", word[2]);
- }
- sendData(tmpSprintf);
- sendData("quit :FATAL ERROR. RESTARTING...\n");
- }
- else if (!stricmp(word[4], "RAW"))
- {
- onlyme();
- sprintf(tmpSprintf, "%s\n", word_eol[5]);
- sendData(tmpSprintf);
- }
- else if (!stricmp(word[4], "CUSS"))
- {
- if (word[5][0] == '#') {
- sprintf(tmpSprintf, "privmsg %s :FUCK YEAH YOU MOTHERFUCKING SHITBALL CUNT CRAP MOTHERFUCKING GODDAMN DICK!\n", word[5]);
- }
- else {
- sprintf(tmpSprintf, "privmsg %s :FUCK YEAH YOU MOTHERFUCKING SHITBALL CUNT CRAP MOTHERFUCKING GODDAMN DICK!\n", word[2]);
- }
- sendData(tmpSprintf);
- }
- else if (!stricmp(word[4], "HELP"))
- {
- if (word[5][0] == '#') {
- sprintf(tmpSprintf, "privmsg %s :Commands usable by anyone: uno, say, lard, cuss, spin\n", word[5]);
- }
- else {
- sprintf(tmpSprintf, "privmsg %s :Commands usable by anyone: uno, say, lard, cuss, spin, set, help\n", word[2]);
- }
- sendData(tmpSprintf);
- }
- else if (!stricmp(word[4], "SPIN"))
- {
- if (word[5][0] == '#') {
- sprintf(tmpSprintf, "privmsg %s :you spin me right round baby right round like a record baby right round round round\n", word[5]);
- }
- else {
- sprintf(tmpSprintf, "privmsg %s :you spin me right round baby right round like a record baby right round round round\n", word[2]);
- }
- sendData(tmpSprintf);
- }
- else if (!stricmp(word[4], "SET"))
- {
- if (word[5][0] == '#') {
- sprintf(tmpSprintf, "privmsg %s :the word has been set: %s\n", word[5], word_eol[6]);
- setword = word_eol[6];
- for (int i = 0; setword[i] != '#'; i++)
- {
- if (setword[i] != ' ')
- {
- guessword[i] = '-';
- }
- else {
- guessword[i] = ' ';
- }
- }
- }
- else {
- sprintf(tmpSprintf, "privmsg %s :the word has been set: %s\n", word[2], word_eol[5]);
- setword = word_eol[5];
- for (int i = 0; setword[i] != '#'; i++)
- {
- if (setword[i] != ' ')
- {
- guessword[i] = '-';
- }
- else {
- guessword[i] = ' ';
- }
- }
- }
- sendData(tmpSprintf);
- }
- else if (!stricmp(word[4], "GUESSLETTER"))
- {
- if (word[5][0] == '#') {
- sprintf(tmpSprintf, "privmsg %s :DEBUG: %s\n", word[5], word[6]);
- }
- else {
- sprintf(tmpSprintf, "privmsg %s :DEBUG: %s\n", word[2], word[5]);
- }
- sendData(tmpSprintf);
- }
- else if (!stricmp(word[4], "GUESSWORD"))
- {
- if (word[5][0] == '#') {
- sprintf(tmpSprintf, "privmsg %s :DEBUG: %s\n", word[5], word_eol[6]);
- }
- else {
- sprintf(tmpSprintf, "privmsg %s :DEBUG: %s\n", word[2], word_eol[5]);
- }
- sendData(tmpSprintf);
- }
- }
- }
- }
- SOCKET NewConnection(unsigned long serv, int port)
- {
- SOCKET myTempSocket;
- WSAData wsaData;
- if (WSAStartup(MAKEWORD(2,2), &wsaData) == SOCKET_ERROR)
- return 0;
- myTempSocket = socket(AF_INET, SOCK_STREAM, 0);
- SOCKADDR_IN server;
- server.sin_port = htons(port);
- server.sin_family = AF_INET;
- server.sin_addr.s_addr = serv;
- if (connect(myTempSocket, (SOCKADDR*)&server, sizeof(server)) == SOCKET_ERROR)
- return 0;
- return myTempSocket;
- }
- int main()
- {
- Failed:
- WSAData wsaData;
- if (WSAStartup(MAKEWORD(2,2), &wsaData) == SOCKET_ERROR)
- {
- cout << "Socket Failed!\n";
- Sleep(2000);
- return 0;
- }
- mySocket=NewConnection(inet_addr("92.246.28.59"), 6667);
- while (!mySocket || mySocket==SOCKET_ERROR)
- {
- Sleep(1000);
- mySocket=NewConnection(inet_addr("92.246.28.59"), 6667);
- }
- sendData("USER GameMaster lol wut :I'm a bot!\n");
- sendData("NICK GameMaster\n");
- nick = "GameMaster";
- fd_set Sockets;
- timeval time;
- time.tv_sec=45;
- time.tv_usec=0;
- for (int i=0;i<32;i++) { word[i]=nullStr; word_eol[i]=nullStr; }
- while (true)
- {
- Sockets.fd_array[0]=mySocket;
- Sockets.fd_count=1;
- select(0, &Sockets, 0, 0, &time);
- if (!Sockets.fd_count)
- {
- if (hasPinged)
- {
- sendData("QUIT :Ping timeout\n");
- closesocket(mySocket);
- hasPinged=false;
- goto Failed;
- }
- sendData("ping a\n");
- hasPinged=true;
- continue;
- }
- int byteRcv = recv(mySocket, rcvBuf, bufSize, 0);
- if (byteRcv <= 0 || byteRcv > 9000)
- {
- rcvBuf[0]=0;
- goto Failed;
- }
- rcvBuf[byteRcv]=0;//null terminate it, it's easier that way when handling ascii data
- HandleRecived(rcvBuf);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement