Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.48 KB | None | 0 0
  1.       #include <cstring>
  2.       #include <WinSock2.h>
  3.       #include <stdio.h>
  4.       #include <iostream>
  5.       #define isme() (strstr(word[0], "!MarioAweso@") && strstr(word[0], ".dc.dc.cox.net"))
  6.       #define isdragonite() (strstr(word[0], "!Dragonite@") && strstr(word[0], ".lightspeed.bcvloh.sbcglobal.net"))
  7.       #define isumlautbanana() (strstr(word[0], "!What@") && strstr(word[0], ".This.Blasphemy"))
  8.       #define ismolsno() (strstr(word[0], "!MolSno@") && strstr(word[0], ".nap.wideopenwest.com"))
  9.       #define say(str) sprintf(tmpSprintf, "%s %s :%s\n", word[1], word[2], str); sendData(tmpSprintf)
  10.       #define die(str) say(str); return
  11.       #define onlyme() if (!isme() && !isdragonite() && !isumlautbanana() && !ismolsno()) { die("Access denied."); }
  12.       #pragma warning(disable:4996)
  13.       #pragma comment(lib, "ws2_32.lib")
  14.       using namespace std;
  15.       string nick;
  16.       bool kickmanoccuring;
  17.       string setword;
  18.       string guessword;
  19.       char * word[512];
  20.       char * word_eol[512];
  21.       char nullStr[1]="";
  22.       bool hasPinged=false;
  23.       char tmpSprintf[8192];
  24.       SOCKET mySocket;
  25.       #define bufSize 8192
  26.       char rcvBuf[bufSize];
  27.       char rcvLine[bufSize];
  28.       char wordLine[bufSize];
  29.       void HandleMsg();
  30.       void GetWordArrays()//create word[] and word_eol[] arrays
  31.       {
  32.               strcpy(wordLine,rcvLine);//copy word_eol[]'s memory to word[]'s memory
  33.               char* placeInWordEol=rcvLine;          
  34.               char* placeInWord=wordLine;
  35.               int NumWords;
  36.               for (NumWords=0;placeInWordEol[0] && strchr(placeInWordEol,' ') && NumWords<28;NumWords++)
  37.               {
  38.                       word_eol[NumWords]=placeInWordEol;
  39.                       placeInWordEol=strchr(placeInWordEol,' ')+1;//go to next word
  40.                       word[NumWords]=placeInWord;
  41.                       placeInWord=strchr(placeInWord,' ');//go to next space...
  42.                       placeInWord[0]=0;//change it to a NULL character...
  43.                       placeInWord++;//and go to next word
  44.                       if (!word[NumWords][0])//remove empty words
  45.                       {
  46.                               NumWords--;
  47.                       }
  48.               }
  49.               word_eol[NumWords]=placeInWordEol;//the last words won't get added otherwise for some reason
  50.               word[NumWords]=placeInWord;
  51.               word_eol[NumWords+1]=nullStr;//add empty strings to the end of the word lists
  52.               word[NumWords+1]=nullStr;
  53.               for (int tmp=0;rcvLine[tmp];tmp++)//remove CRLF's
  54.               {
  55.                       char temp=rcvLine[tmp];
  56.                       if (temp=='\r' || temp=='\n')
  57.                       {
  58.                               if (rcvLine[tmp-1]==1 && tmp)
  59.                               {
  60.                                       rcvLine[tmp-1]=0;
  61.                                       wordLine[tmp-1]=0;
  62.                               }
  63.                               rcvLine[tmp]=0;
  64.                               wordLine[tmp]=0;
  65.                       }
  66.               }
  67.       }
  68.       void HandleRecived(char * input)
  69.       {
  70.               char * placeInInput=input;
  71.               char * nextNewline;
  72.               while (nextNewline=strchr(placeInInput,'\n'))
  73.               {
  74.                       nextNewline[0]=0;
  75.                       strcat(rcvLine,placeInInput);
  76.                       nextNewline[0]='\n';
  77.                       rcvLine[strlen(rcvLine)+1]=0;
  78.                       rcvLine[strlen(rcvLine)]='\n';
  79.                       placeInInput=nextNewline+1;
  80.                       HandleMsg();
  81.                       rcvLine[0]=0;
  82.               }
  83.               if (strlen(placeInInput))
  84.               {
  85.                       strcat(rcvLine, placeInInput);
  86.               }
  87.       }
  88.       inline void sendData(const char * data)
  89.       {
  90.               cout<<"<< "<<data;
  91.               send(mySocket, data, strlen(data), 0);
  92.       }
  93.       void HandleMsg()
  94.       {
  95.               GetWordArrays();
  96.               cout<<">> "<<word_eol[0]<<endl;
  97.               hasPinged=false;
  98.               if (!stricmp(word[0], "PING"))
  99.           {
  100.                       word_eol[0][1]='O';
  101.               int tmp=strlen(word_eol[0]);
  102.               word_eol[0][tmp]='\n';
  103.               word_eol[0][tmp+1]=0;
  104.               sendData(word_eol[0]);
  105.               }
  106.               else if (!stricmp(word[1], "001"))
  107.           {
  108.                       sendData("NS identify password denied\n");
  109.                       sendData("JOIN #wordgames,#seriousbusiness,#teamgame,#MATheHackTester,#grills,#dummies,#glitch,#randomness,#TheGag96,#kaizo,#moltensnow\n");
  110.           }
  111.               else if (!stricmp(word[2], "PONG"))
  112.           {
  113.                       sprintf(tmpSprintf, "nick %s_\n", word[3]);
  114.               sendData(tmpSprintf);
  115.           }
  116.               else if (!stricmp(word[1], "PRIVMSG"))
  117.               {
  118.                       if (stricmp(word[3]+1, "!gm")) return;
  119.                       {
  120.                               if (word[2][0]!='#')
  121.                               {
  122.                                       static char name[256];
  123.                                       strcpy(name, word[0]+1);
  124.                                       if (strchr(name, '!')) *strchr(name, '!')=0;
  125.                                       word[2]=name;
  126.                               }
  127.                               if (!stricmp(word[4], "SAY"))
  128.                               {
  129.                                       if (word[5][0] == '#') {
  130.                                       sprintf(tmpSprintf, "privmsg %s :%s\n", word[5], word_eol[6]);
  131.                                       }
  132.                                       else {
  133.                                       sprintf(tmpSprintf, "privmsg %s :%s\n", word[2], word_eol[5]);
  134.                                       }
  135.                                       sendData(tmpSprintf);
  136.                               }
  137.                               else if (!stricmp(word[4], "LARD"))
  138.                               {
  139.                                       if (word[5][0] == '#') {
  140.                                       sprintf(tmpSprintf, "privmsg %s :What, dude, did you want to grease something????\n", word[5]);
  141.                                       }
  142.                                       else {
  143.                                       sprintf(tmpSprintf, "privmsg %s :What, dude, did you want to grease something????\n", word[2]);
  144.                                       sendData(tmpSprintf);
  145.                                       }
  146.                               }
  147.                               else if (!stricmp(word[4], "JOIN"))
  148.                               {
  149.                               onlyme();
  150.                               sprintf(tmpSprintf, "join %s :\n", word[5]);
  151.                               sendData(tmpSprintf);
  152.                               }
  153.                               else if (!stricmp(word[4], "PART"))
  154.                               {
  155.                               onlyme();
  156.                               sprintf(tmpSprintf, "part %s :%s\n", word[5], word_eol[6]);
  157.                               sendData(tmpSprintf);
  158.                               }
  159.                               else if (!stricmp(word[4], "NICK"))
  160.                               {
  161.                               onlyme();
  162.                               sprintf(tmpSprintf, "nick %s :\n", word[5]);
  163.                               sendData(tmpSprintf);
  164.                               nick=word[5];
  165.                               }
  166.                               else if (!stricmp(word[4], "KICK"))
  167.                               {
  168.                               onlyme();
  169.                               if (!stricmp(word[6], nick.c_str())) {
  170.                                                     die("WHY WOULD YOU MAKE ME DO THIS?");
  171.                                                     }
  172.                               if (word[5][0] == '#') {
  173.                               sprintf(tmpSprintf, "kick %s %s :%s\n", word[5], word[6],word_eol[7]);
  174.                               }
  175.                               else {
  176.                                    sprintf(tmpSprintf, "kick %s %s :%s\n", word[2], word[5],word_eol[6]);
  177.                                    }
  178.                                          sendData(tmpSprintf);
  179.                                          }
  180.                               else if (!stricmp(word[4], "BAN"))
  181.                               {
  182.                               onlyme();
  183.                               sprintf(tmpSprintf, "mode %s +b %s", word[5], word_eol[6]);
  184.                               sendData(tmpSprintf);
  185.                               }
  186.                               else if (!stricmp(word[4], "FIXNICK"))
  187.                               {
  188.                               onlyme();
  189.                               sendData("NICK GameMaster\n");
  190.                               sendData("NS identify password denied\n");
  191.                               sendData("NS update\n");
  192.                               nick = "GameMaster";
  193.                               }
  194.                               else if (!stricmp(word[4], "UNO"))
  195.                               {
  196.                               if (word[5][0] == '#') {
  197.                               sprintf(tmpSprintf, "privmsg %s :Uno start! Time to... to... lashdfkljashkldfjhaslkdjfhlkjdshflkjdshf\n", word[5]);
  198.                               }
  199.                               else {
  200.                               sprintf(tmpSprintf, "privmsg %s :Uno start! Time to... to... lashdfkljashkldfjhaslkdjfhlkjdshflkjdshf\n", word[2]);
  201.                               }
  202.                               sendData(tmpSprintf);
  203.                               sendData("quit :FATAL ERROR. RESTARTING...\n");
  204.                               }
  205.                               else if (!stricmp(word[4], "RAW"))
  206.                               {
  207.                               onlyme();
  208.                               sprintf(tmpSprintf, "%s\n", word_eol[5]);
  209.                               sendData(tmpSprintf);
  210.                               }
  211.                               else if (!stricmp(word[4], "CUSS"))
  212.                               {
  213.                               if (word[5][0] == '#') {
  214.                               sprintf(tmpSprintf, "privmsg %s :FUCK YEAH YOU MOTHERFUCKING SHITBALL CUNT CRAP MOTHERFUCKING GODDAMN DICK!\n", word[5]);
  215.                               }
  216.                               else {
  217.                               sprintf(tmpSprintf, "privmsg %s :FUCK YEAH YOU MOTHERFUCKING SHITBALL CUNT CRAP MOTHERFUCKING GODDAMN DICK!\n", word[2]);
  218.                               }
  219.                               sendData(tmpSprintf);
  220.                               }
  221.                               else if (!stricmp(word[4], "HELP"))
  222.                               {
  223.                                    if (word[5][0] == '#') {
  224.                               sprintf(tmpSprintf, "privmsg %s :Commands usable by anyone: uno, say, lard, cuss, spin\n", word[5]);
  225.                               }
  226.                               else {
  227.                               sprintf(tmpSprintf, "privmsg %s :Commands usable by anyone: uno, say, lard, cuss, spin, set, help\n", word[2]);
  228.                               }
  229.                               sendData(tmpSprintf);
  230.                               }
  231.                               else if (!stricmp(word[4], "SPIN"))
  232.                               {
  233.                               if (word[5][0] == '#') {
  234.                               sprintf(tmpSprintf, "privmsg %s :you spin me right round baby right round like a record baby right round round round\n", word[5]);
  235.                               }
  236.                               else {
  237.                               sprintf(tmpSprintf, "privmsg %s :you spin me right round baby right round like a record baby right round round round\n", word[2]);
  238.                               }
  239.                               sendData(tmpSprintf);
  240.                               }
  241.                               else if (!stricmp(word[4], "SET"))
  242.                               {
  243.                               if (word[5][0] == '#') {
  244.                               sprintf(tmpSprintf, "privmsg %s :the word has been set: %s\n", word[5], word_eol[6]);
  245.                               setword = word_eol[6];
  246.                               for (int i = 0; setword[i] != '#'; i++)
  247.                               {
  248.                                   if (setword[i] != ' ')
  249.                                   {
  250.                                   guessword[i] = '-';
  251.                                   }
  252.                                   else {
  253.                                   guessword[i] = ' ';
  254.                                   }
  255.                               }
  256.                               }
  257.                               else {
  258.                               sprintf(tmpSprintf, "privmsg %s :the word has been set: %s\n", word[2], word_eol[5]);
  259.                               setword = word_eol[5];
  260.                               for (int i = 0; setword[i] != '#'; i++)
  261.                               {
  262.                                   if (setword[i] != ' ')
  263.                                   {
  264.                                   guessword[i] = '-';
  265.                                   }
  266.                                   else {
  267.                                   guessword[i] = ' ';
  268.                                   }
  269.                               }
  270.                               }
  271.                               sendData(tmpSprintf);
  272.                               }
  273.                               else if (!stricmp(word[4], "GUESSLETTER"))
  274.                               {
  275.                               if (word[5][0] == '#') {
  276.                               sprintf(tmpSprintf, "privmsg %s :DEBUG: %s\n", word[5], word[6]);
  277.                               }
  278.                               else {
  279.                               sprintf(tmpSprintf, "privmsg %s :DEBUG: %s\n", word[2], word[5]);
  280.                               }
  281.                               sendData(tmpSprintf);
  282.                               }
  283.                               else if (!stricmp(word[4], "GUESSWORD"))
  284.                               {
  285.                               if (word[5][0] == '#') {
  286.                               sprintf(tmpSprintf, "privmsg %s :DEBUG: %s\n", word[5], word_eol[6]);
  287.                               }
  288.                               else {
  289.                               sprintf(tmpSprintf, "privmsg %s :DEBUG: %s\n", word[2], word_eol[5]);
  290.                               }
  291.                               sendData(tmpSprintf);
  292.                               }
  293.                       }
  294.               }
  295.       }
  296.       SOCKET NewConnection(unsigned long serv, int port)
  297.       {
  298.               SOCKET myTempSocket;
  299.               WSAData wsaData;
  300.               if (WSAStartup(MAKEWORD(2,2), &wsaData) == SOCKET_ERROR)
  301.                       return 0;
  302.               myTempSocket = socket(AF_INET, SOCK_STREAM, 0);
  303.               SOCKADDR_IN server;
  304.               server.sin_port = htons(port);
  305.               server.sin_family = AF_INET;
  306.               server.sin_addr.s_addr = serv;
  307.               if (connect(myTempSocket, (SOCKADDR*)&server, sizeof(server)) == SOCKET_ERROR)
  308.                       return 0;
  309.               return myTempSocket;
  310.       }
  311.       int main()
  312. {
  313.     Failed:
  314.     WSAData wsaData;
  315.     if (WSAStartup(MAKEWORD(2,2), &wsaData) == SOCKET_ERROR)
  316.     {
  317.         cout << "Socket Failed!\n";
  318.         Sleep(2000);
  319.         return 0;
  320.     }
  321.  
  322.     mySocket=NewConnection(inet_addr("92.246.28.59"), 6667);
  323.     while (!mySocket || mySocket==SOCKET_ERROR)
  324.     {
  325.         Sleep(1000);
  326.         mySocket=NewConnection(inet_addr("92.246.28.59"), 6667);
  327.     }
  328.     sendData("USER GameMaster lol wut :I'm a bot!\n");
  329.     sendData("NICK GameMaster\n");
  330.     nick = "GameMaster";
  331.     fd_set Sockets;
  332.     timeval time;
  333.     time.tv_sec=45;
  334.     time.tv_usec=0;
  335.     for (int i=0;i<32;i++) { word[i]=nullStr; word_eol[i]=nullStr; }
  336.         while (true)
  337.     {
  338.         Sockets.fd_array[0]=mySocket;
  339.         Sockets.fd_count=1;
  340.         select(0, &Sockets, 0, 0, &time);
  341.         if (!Sockets.fd_count)
  342.         {
  343.             if (hasPinged)
  344.             {
  345.                 sendData("QUIT :Ping timeout\n");
  346.                 closesocket(mySocket);
  347.                 hasPinged=false;
  348.                 goto Failed;
  349.             }
  350.             sendData("ping a\n");
  351.             hasPinged=true;
  352.             continue;
  353.         }
  354.         int byteRcv = recv(mySocket, rcvBuf, bufSize, 0);
  355.         if (byteRcv <= 0 || byteRcv > 9000)
  356.         {
  357.             rcvBuf[0]=0;
  358.             goto Failed;
  359.         }
  360.         rcvBuf[byteRcv]=0;//null terminate it, it's easier that way when handling ascii data
  361.         HandleRecived(rcvBuf);
  362.     }
  363.     return 0;
  364. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement