Advertisement
NovaYoshi

New NovaBot's ExtCmdPack

Jul 1st, 2011
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 21.05 KB | None | 0 0
  1. /*
  2.  
  3.   External commands pack
  4.  
  5. */
  6.  
  7. #include "xchat-plugin.h"
  8.  
  9. #include <stdio.h>
  10.  
  11. #include <string.h>
  12.  
  13. #include <stdlib.h>
  14.  
  15. #include <ctype.h>
  16.  
  17.  
  18.  
  19. #define PNAME "External commands pack"
  20.  
  21. #define PDESC "8====D~~~~~~"
  22.  
  23. #define PVERSION "0.05"
  24.  
  25.  
  26.  
  27. static xchat_plugin *ph;   /* plugin handle */
  28.  
  29.  
  30.  
  31. #define any_lowercase_letter  case 'a':case 'b':case'c':case'd':case'e':case'f':case 'g':case 'h':case 'i':case 'j':case 'k':case 'l':case'm':case'n':case'o':case'p':case 'q':case 'r':case 's':case 't':case 'u':case 'v':case'w':case'x':case'y':case'z':
  32.  
  33. #define any_decimal_digit    case '0':case '1':case'2':case'3':case'4':case'5':case '6':case '7': case '8':case '9':
  34.  
  35. #include "rscript.c"
  36.  
  37.  
  38.  
  39. int ReadDate3(char *Peek) {
  40.  
  41.   if(!strcasecmp(Peek, "now"))
  42.  
  43.     return time(NULL);
  44.  
  45.   int Month, Day, Year;
  46.  
  47.  
  48.  
  49.   if(!Peek[0]) return -1;
  50.  
  51.   Month = strtol(Peek, &Peek, 10);
  52.  
  53.   if(*Peek=='/') Peek++;
  54.  
  55.   if(!Peek[0]) return -1;
  56.  
  57.   Day = strtol(Peek, &Peek, 10);
  58.  
  59.   if(*Peek=='/') Peek++;
  60.  
  61.   if(!Peek[0]) return -1;
  62.  
  63.   Year = strtol(Peek, NULL, 10);
  64.  
  65.  
  66.  
  67.   time_t RawTime;
  68.  
  69.   struct tm *TimeInfo;
  70.  
  71.   time( &RawTime );
  72.  
  73.   TimeInfo = localtime ( &RawTime );
  74.  
  75.   TimeInfo->tm_year = Year - 1900;
  76.  
  77.   TimeInfo->tm_mon = Month - 1;
  78.  
  79.   TimeInfo->tm_mday = Day;
  80.  
  81.   return mktime(TimeInfo);
  82.  
  83. }
  84.  
  85.  
  86.  
  87. char *BruteforceKrypto(int n1, int n2, int n3, int n4, int n5, int Desired, char *Poke) {
  88.  
  89.   int N[5] = {n1,n2,n3,n4,n5};
  90.  
  91.   int A,B,C,D,E,i;
  92.  
  93.   int Op[5];
  94.  
  95.   const char OpChar[4] = {'+', '-', '*', '/'};
  96.  
  97.  
  98.  
  99.   for(A=0;A<5;A++) {
  100.  
  101.     for(B=0;B<5;B++) {
  102.  
  103.       if(B==A)
  104.  
  105.         continue;
  106.  
  107.       for(C=0;C<5;C++) {
  108.  
  109.         if(C==A || C==B)
  110.  
  111.           continue;
  112.  
  113.         for(D=0;D<5;D++) {
  114.  
  115.           if(D==A || D==B || D==C)
  116.  
  117.             continue;
  118.  
  119.           for(E=0;E<5;E++) {
  120.  
  121.             if(E==A || E==B || E==C || E==D)
  122.  
  123.               continue;
  124.  
  125.             // will loop 120 times
  126.  
  127.  
  128.  
  129.             float W[5] = {N[A], N[B], N[C], N[D], N[E]};
  130.  
  131.             float Val=W[0];
  132.  
  133.             for(Op[0]=0;Op[0]<4;Op[0]++)
  134.  
  135.               for(Op[1]=0;Op[1]<4;Op[1]++)
  136.  
  137.                 for(Op[2]=0;Op[2]<4;Op[2]++)
  138.  
  139.                   for(Op[3]=0;Op[3]<4;Op[3]++) {
  140.  
  141.                     for(Val=W[0], i=0; i<4; i++)
  142.  
  143.                       switch(Op[i]) {
  144.  
  145.                         case 0:
  146.  
  147.                           Val += W[i+1];
  148.  
  149.                           break;
  150.  
  151.                         case 1:
  152.  
  153.                           Val -= W[i+1];
  154.  
  155.                           break;
  156.  
  157.                         case 2:
  158.  
  159.                           Val *= W[i+1];
  160.  
  161.                           break;
  162.  
  163.                         case 3:
  164.  
  165.                           Val /= W[i+1];
  166.  
  167.                           break;
  168.  
  169.                       }
  170.  
  171.                     if(Val == Desired) {
  172.  
  173.                       sprintf(Poke, "%2i %c %2i %c %2i %c %2i %c %2i = %2i \n",
  174.  
  175.                      (int)W[0], OpChar[Op[0]], (int)W[1], OpChar[Op[1]], (int)W[2], OpChar[Op[2]],
  176.  
  177.                      (int)W[3], OpChar[Op[3]], (int)W[4], Desired);
  178.  
  179.                       return Poke;
  180.  
  181.                     }
  182.  
  183.                   }
  184.  
  185.           }
  186.  
  187.         }
  188.  
  189.       }
  190.  
  191.     }
  192.  
  193.   }
  194.  
  195.   return "No solutions?";
  196.  
  197. }
  198.  
  199.  
  200.  
  201. //Convert a string to an integer, and notes a '%' or '$' starting a number
  202.  
  203. int ConvertCA65Num(char *In, char **Out) {
  204.  
  205.   char *Peek=In;                //Start at the input string
  206.  
  207.   while(isspace(*Peek)) {       //Skip to the end of any leading whitespace before the number
  208.  
  209.     Peek++;                                        
  210.  
  211.     if(*Peek=='\0')                    //Handle the whole string being whitespace, if it happens
  212.  
  213.       return(0);
  214.  
  215.   }
  216.  
  217.   if(*Peek=='$')                       //Prefixed with a '$' = Hexadecimal
  218.  
  219.     return(strtol(Peek+1, Out, 16 ));
  220.  
  221.   if(*Peek=='%')                       //Prefixed with a '%' = Binary
  222.  
  223.     return(strtol(Peek+1, Out, 2 ));
  224.  
  225.   return(strtol(Peek, Out, 10 ));      //Not prefixed with anything = Decimal
  226.  
  227. }
  228.  
  229.  
  230.  
  231. static char *z80FakeMultiply(char *Result, int Find) { // nb.zmulbyadd
  232.  
  233.   char Temp[100];
  234.  
  235.   Temp[99]=0;     // String end
  236.  
  237.   if(Find==-1){strcpy(Result,"neg");    return(Result);}
  238.  
  239.   if(Find==0){strcpy(Result,"xor a");   return(Result);}
  240.  
  241.   if(Find==1){strcpy(Result,"nop");     return(Result);}
  242.  
  243.   if(Find<0){strcpy(Result,"Only positive numbers, please");  return(Result);}
  244.  
  245.  
  246.  
  247.   char *Poke = Temp+98;
  248.  
  249.   while(Find != 1) {
  250.  
  251.     if(Find & 1) {
  252.  
  253.       Find--;
  254.  
  255.       *(Poke--) = 'y';
  256.  
  257.     } else {
  258.  
  259.       Find>>=1;
  260.  
  261.       *(Poke--) = 'x';
  262.  
  263.     }
  264.  
  265.     printf("%i ", Find);
  266.  
  267.   }
  268.  
  269.   strcpy(Result, ++Poke);
  270.  
  271.   printf("\nResult is %s \n", Poke);
  272.  
  273.   return(Result);
  274.  
  275. }
  276.  
  277.  
  278.  
  279. static void z80Asm(char *Input, char *Output) {
  280.  
  281.   remove("lazyass.bin");
  282.  
  283.   // First we need to create a file to feed z80asm
  284.  
  285.   FILE *MyFile = fopen("lazyass.asm","w");
  286.  
  287.   if(MyFile==NULL) {
  288.  
  289.     strcpy(Output,"unable to open lazyass.asm");
  290.  
  291.     return;
  292.  
  293.   }
  294.  
  295.  
  296.  
  297.   // Intercept all '\'s and turn them into newlines
  298.  
  299.   char *Peek = Input;
  300.  
  301.   while(*Peek) {
  302.  
  303.     char got = *Peek;
  304.  
  305.     if(got == '\\') { // new line
  306.  
  307.       fputc('\r',MyFile);
  308.  
  309.       fputc('\n',MyFile);
  310.  
  311.     }
  312.  
  313.     else
  314.  
  315.       fputc(got, MyFile);
  316.  
  317.     Peek++;
  318.  
  319.   }
  320.  
  321.  
  322.  
  323.   // Now we have a file to feed z80asm
  324.  
  325.   fclose(MyFile);
  326.  
  327.  
  328.  
  329.   char Command[512];
  330.  
  331.   sprintf(Command, "z80asm -i lazyass.asm -o lazyass.bin");
  332.  
  333.   int Status = system(Command);
  334.  
  335.  
  336.  
  337.   // Open the assembled code
  338.  
  339.   MyFile = fopen("lazyass.bin","rb");
  340.  
  341.   if(MyFile==NULL) {
  342.  
  343.     sprintf(Output,"Unable to open lazyass.bin. (system() returned %i) I'm guessing you made a mistake in your code", Status);
  344.  
  345.     return;
  346.  
  347.   }
  348.  
  349.  
  350.  
  351.   // Now get the hex values from the compiled code
  352.  
  353.   strcpy(Output,"");
  354.  
  355.   char *Poke = Output;
  356.  
  357.   // int len=0; // code length
  358.  
  359.   int ch;
  360.  
  361.   do {
  362.  
  363.     char Small[7];
  364.  
  365.     ch = fgetc(MyFile);
  366.  
  367.     if(ch==EOF)
  368.  
  369.       break;
  370.  
  371.     if(ch < 16)
  372.  
  373.       sprintf(Small, "0%x ",ch);
  374.  
  375.     else
  376.  
  377.       sprintf(Small, "%x ",ch);
  378.  
  379.  
  380.  
  381.     strcat(Poke,Small);
  382.  
  383.   } while(ch != EOF);
  384.  
  385. }
  386.  
  387.  
  388.  
  389. static void NBFalse(char *Input, char *Output) {
  390.  
  391.   remove("/home/joshua/Desktop/NovaBot/lazyass.txt");
  392.  
  393.   // First we need to create a file to feed z80asm
  394.  
  395.   FILE *MyFile = fopen("/home/joshua/Desktop/NovaBot/lazyass.f","w");
  396.  
  397.   if(MyFile==NULL) {
  398.  
  399.     strcpy(Output,"unable to open lazyass.f");
  400.  
  401.     return;
  402.  
  403.   }
  404.  
  405.  
  406.  
  407.   char *Peek = Input;
  408.  
  409.   while(*Peek) {
  410.  
  411.     fputc(*(Peek++), MyFile);
  412.  
  413.   }
  414.  
  415.  
  416.  
  417.   // Now we have a file to feed nbfalse
  418.  
  419.   fclose(MyFile);
  420.  
  421.  
  422.  
  423.   int Status = system("PATH=\"$HOME/bin:$PATH\"");
  424.  
  425.   //sprintf(Command, "/home/joshua/Desktop/NovaBot/nbfalse lazyass.f > lasyass.txt");
  426.  
  427.   //Status = system("nbfalse lazyass.f > lazyass.txt");
  428.  
  429.   Status = system("/home/joshua/Desktop/NovaBot/nbfalse /home/joshua/Desktop/NovaBot/lazyass.f > /home/joshua/Desktop/NovaBot/lazyass.txt");
  430.  
  431.  
  432.  
  433.   // Open the assembled code
  434.  
  435.   MyFile = fopen("/home/joshua/Desktop/NovaBot/lazyass.txt","rb");
  436.  
  437.   if(MyFile==NULL) {
  438.  
  439.     sprintf(Output,"Unable to open lazyass.txt. (%i)", Status);
  440.  
  441.     return;
  442.  
  443.   }
  444.  
  445.  
  446.  
  447.   strcpy(Output,"");
  448.  
  449.   char *Poke = Output;
  450.  
  451.   // int len=0; // code length
  452.  
  453.   int ch;
  454.  
  455.   do {
  456.  
  457.     ch = fgetc(MyFile);
  458.  
  459.     if(ch==EOF)
  460.  
  461.       break;
  462.  
  463.     if(ch=='\n' || ch=='\r')
  464.  
  465.       ch = '|';
  466.  
  467.     *(Poke++) = ch;
  468.  
  469.   } while(ch != EOF);
  470.  
  471.  
  472.  
  473.   *Poke = 0;
  474.  
  475. }
  476.  
  477.  
  478.  
  479. //"/home/joshua/Desktop/NovaBot/data/"
  480.  
  481.  
  482.  
  483. static int RequiresArgument(char *ReplyCmd, char *Msg) {
  484.  
  485.   if(Msg != NULL)
  486.  
  487.     xchat_commandf(ph, "%s %s", ReplyCmd, Msg);
  488.  
  489.   else
  490.  
  491.     xchat_commandf(ph, "%s Hey! You forgot to put something after the command. >_>", ReplyCmd);  
  492.  
  493.   return XCHAT_EAT_ALL;
  494.  
  495. }
  496.  
  497. // 1         2        3       4    (search for -A and begin from there)
  498.  
  499. // NB_ExtCmd replycmd command nick -A arguments
  500.  
  501. static int nb_extcmdtest_cb(char *word[], char *word_eol[], void *userdata) {
  502.  
  503.   if(word[2] == NULL && word[3] == NULL && word[4] == NULL)
  504.  
  505.     return XCHAT_EAT_NONE; // oops
  506.  
  507.   char Temp[512];
  508.  
  509.   char *ReplyCmd = word[2];
  510.  
  511.   char *NBCmd = word[3];
  512.  
  513.   char *Nick=word[4];
  514.  
  515.  
  516.  
  517.   int i;
  518.  
  519.   int ArgPtrIndex = -1;
  520.  
  521.   char *ArgPtr = NULL;
  522.  
  523.   for(i=4;i<10 && (word[i]!=NULL);i++) {
  524.  
  525.     if(!strcasecmp(word[i],"-A"))
  526.  
  527.       if(word[++i]!=NULL)
  528.  
  529.         if(strcasecmp(word[i],"")) {
  530.  
  531.           ArgPtr = word_eol[i];
  532.  
  533.           ArgPtrIndex = i;
  534.  
  535.           break;
  536.  
  537.         }
  538.  
  539.   }
  540.  
  541.   if(!strcasecmp(NBCmd,"rot13") && NULL!=ArgPtr) {
  542.  
  543.     return XCHAT_EAT_ALL;
  544.  
  545.   }
  546.  
  547.  
  548.  
  549.  
  550.  
  551.   if(!strcasecmp(NBCmd,"allcaps") && NULL!=ArgPtr) {
  552.  
  553.     xchat_commandf(ph, "spark allcaps %s", ArgPtr);
  554.  
  555.     return XCHAT_EAT_ALL;
  556.  
  557.   }
  558.  
  559.  
  560.  
  561.   if(!strcasecmp(NBCmd,"altcaps") && NULL!=ArgPtr) {
  562.  
  563.     xchat_commandf(ph, "spark altcaps %s", ArgPtr);
  564.  
  565.     return XCHAT_EAT_ALL;
  566.  
  567.   }
  568.  
  569.   if(!strcasecmp(NBCmd,"randcaps") && NULL!=ArgPtr) {
  570.  
  571.     xchat_commandf(ph, "spark randcaps %s", ArgPtr);
  572.  
  573.     return XCHAT_EAT_ALL;
  574.  
  575.   }
  576.  
  577.   if(!strcasecmp(NBCmd,"bouncycaps") && NULL!=ArgPtr) {
  578.  
  579.     xchat_commandf(ph, "spark bouncycaps %s", ArgPtr);
  580.  
  581.     return XCHAT_EAT_ALL;
  582.  
  583.   }
  584.  
  585.   if(!strcasecmp(NBCmd,"rainbow") && NULL!=ArgPtr) {
  586.  
  587.     xchat_commandf(ph, "spark rainbow %s", ArgPtr);
  588.  
  589.     return XCHAT_EAT_ALL;
  590.  
  591.   }
  592.  
  593.   if(!strcasecmp(NBCmd,"rainbow4") && NULL!=ArgPtr) {
  594.  
  595.     xchat_commandf(ph, "spark rainbow4 %s", ArgPtr);
  596.  
  597.     return XCHAT_EAT_ALL;
  598.  
  599.   }
  600.  
  601.   if(!strcasecmp(NBCmd,"rainbowcaps") && NULL!=ArgPtr) {
  602.  
  603.     xchat_commandf(ph, "spark rainbowcaps %s", ArgPtr);
  604.  
  605.     return XCHAT_EAT_ALL;
  606.  
  607.   }
  608.  
  609.   if(!strcasecmp(NBCmd,"hstroll") && NULL!=ArgPtr) {
  610.  
  611.     xchat_commandf(ph, "spark hstroll %s", ArgPtr);
  612.  
  613.     return XCHAT_EAT_ALL;
  614.  
  615.   }
  616.  
  617.  
  618.  
  619.   if(!strcasecmp(NBCmd,"echo") && NULL!=ArgPtr) {
  620.  
  621.     xchat_commandf(ph, "%s %s", ReplyCmd, ArgPtr);
  622.  
  623.     return XCHAT_EAT_ALL;
  624.  
  625.   }
  626.  
  627.   if(!strcasecmp(NBCmd,"backwards") && NULL!=ArgPtr) {
  628.  
  629.     xchat_commandf(ph, "spark backwards %s", ArgPtr);
  630.  
  631.     return XCHAT_EAT_ALL;
  632.  
  633.   }
  634.  
  635.   if(!strcasecmp(NBCmd,"strlen") && NULL!=ArgPtr) {
  636.  
  637.     xchat_commandf(ph, "%s strlen is %i", ReplyCmd, strlen(ArgPtr));
  638.  
  639.     return XCHAT_EAT_ALL;
  640.  
  641.   }
  642.  
  643.   if(!strcasecmp(NBCmd,"datediff") && NULL!=ArgPtr) {
  644.  
  645.     int Days = abs(ReadDate3(word[i])-ReadDate3(word[i+1])) / 86400;
  646.  
  647.     xchat_commandf(ph, "%s %i days (%i weeks and %i days)", ReplyCmd, Days, Days/7, Days%7);
  648.  
  649.     return XCHAT_EAT_ALL;
  650.  
  651.   }
  652.  
  653.   if(!strcasecmp(NBCmd,"curtime")) {
  654.  
  655.     time_t rawtime;
  656.  
  657.     struct tm * timeinfo;
  658.  
  659.     time (&rawtime);
  660.  
  661.     timeinfo = localtime(&rawtime);
  662.  
  663.     strftime(Temp,80,"Now it's %x, %I:%M %p (%Z)",timeinfo);
  664.  
  665.     xchat_commandf(ph, "%s %s", ReplyCmd, Temp);
  666.  
  667.     return XCHAT_EAT_ALL;
  668.  
  669.   }
  670.  
  671.  
  672.  
  673.  
  674.  
  675.   if(!strcasecmp(NBCmd,"krypto") && NULL!=ArgPtr) {
  676.  
  677.     char *Get = BruteforceKrypto(strtol(word[i],NULL,10), strtol(word[i+1],NULL,10), strtol(word[i+2],NULL,10), strtol(word[i+3],NULL,10), strtol(word[i+4],NULL,10), strtol(word[i+5],NULL,10), Temp);
  678.  
  679.     xchat_commandf(ph, "%s %s", ReplyCmd, Get);
  680.  
  681.     return XCHAT_EAT_ALL;
  682.  
  683.   }
  684.  
  685.  
  686.  
  687.   if(!strcasecmp(NBCmd,"davyiff") && NULL!=ArgPtr) {
  688.  
  689.     xchat_commandf(ph, "spark davyiff %s", ArgPtr);
  690.  
  691.     return XCHAT_EAT_ALL;
  692.  
  693.   }
  694.  
  695.   if(!strcasecmp(NBCmd,"givejuice") && NULL!=ArgPtr) {
  696.  
  697.     if(strlen(ArgPtr)<50) {
  698.  
  699.       if(strcasecmp(ArgPtr,"Nova")) {
  700.  
  701.         xchat_commandf(ph, "me hands %s a cup of %s juice :3", Nick, ArgPtr);
  702.  
  703.       } else {
  704.  
  705.         xchat_commandf(ph, "say Why don't you just ask hir for some?",word[1]);
  706.  
  707.       }
  708.  
  709.     }
  710.  
  711.    return XCHAT_EAT_ALL;
  712.  
  713.   }
  714.  
  715.   if(!strcasecmp(NBCmd,"ppuaddris") && NULL!=ArgPtr) {
  716.  
  717.     char tiny[74];
  718.  
  719.     int Address = strtol(ArgPtr,NULL,16);
  720.  
  721.       strcpy(Temp,"(I don't know ;-;)");
  722.  
  723.       if(Address < 0x2000) {
  724.  
  725.         sprintf(Temp, "CHR tile page %i, number %i/$%x", Address / 0x1000, (Address / 16) & 255, (Address/16)&255);
  726.  
  727.         int Row = Address % 8;
  728.  
  729.         int Plane = Address & 8;
  730.  
  731.         if(Plane != 0)
  732.  
  733.           strcat(Temp, ", second plane");
  734.  
  735.         if(Row != 0) {
  736.  
  737.           sprintf(tiny,", row %i", Row);
  738.  
  739.           strcat(Temp,tiny);
  740.  
  741.         }
  742.  
  743.       }
  744.  
  745.       else if(Address <= 0x2fff && Address >= 0x2000) { // &&!already
  746.  
  747.         int tile = Address & 1023;
  748.  
  749.       if(tile < 0x3c0)
  750.  
  751.         sprintf(Temp, "Nametable %i, tile %i,%i", (Address-0x2000)/1024, tile&31, (tile/32)&31);
  752.  
  753.       else {
  754.  
  755.         sprintf(Temp, "Nametable %i, attribute %i,%i", (Address-0x2000)/1024, (tile & 7), (tile/8)&7);
  756.  
  757.       }
  758.  
  759.     }
  760.  
  761.     if(Address <= 0x301f && Address >= 0x3000) { // &&!already
  762.  
  763.       sprintf(Temp, "%s palette %i, (color %i in palette)", (Address>=0x3010 ?"sprite":"background"), (Address>>2)&3, Address & 3);
  764.  
  765.     }
  766.  
  767.     xchat_commandf(ph, "%s PPU address is: %s", ReplyCmd, Temp);
  768.  
  769.     return XCHAT_EAT_ALL;
  770.  
  771.   }
  772.  
  773.   if(!strcasecmp(NBCmd,"abuse")) {
  774.  
  775.     xchat_commandf(ph, "%s DO NOT ABUSE THE BOT. IF YOU ABUSE THE BOT, PINKIE PIE **WILL** FUCK YOUR SHIT UP! THEN SHE WILL VIOLATE YOU WITH CUPCAKES. TASTY, RAINBOW DASH FLAVOUR CUPCAKES!", ReplyCmd);
  776.  
  777.     return XCHAT_EAT_ALL;
  778.  
  779.   }
  780.  
  781.   if(!strcasecmp(NBCmd,"yiffisillegal")) {
  782.  
  783.     xchat_commandf(ph, "%s Now I'm not horny anymore. Thanks for ruining it, %s! >:(", ReplyCmd, Nick);
  784.  
  785.     return XCHAT_EAT_ALL;
  786.  
  787.   }
  788.  
  789.   if(!strcasecmp(NBCmd,"help")) {
  790.  
  791.     xchat_commandf(ph, "%s Check http://www.smwiki.net/wiki/NovaBot", ReplyCmd);
  792.  
  793.     return XCHAT_EAT_ALL;
  794.  
  795.   }
  796.  
  797.   if(!strcasecmp(NBCmd,"myiff")) {
  798.  
  799.     NBCmd = "pyiff";
  800.  
  801.     ArgPtr = Nick;
  802.  
  803.   }
  804.  
  805.   if(!strcasecmp(NBCmd,"syiff")) {
  806.  
  807.     NBCmd = "pyiff";
  808.  
  809.     ArgPtr = "NovaBot";
  810.  
  811.   }
  812.  
  813.   if((!strcasecmp(NBCmd,"pyiff")||!strcasecmp(NBCmd,"yiff")) && NULL!=ArgPtr) {
  814.  
  815.        xchat_commandf(ph, "YIFF %s", ArgPtr);
  816.  
  817.     return XCHAT_EAT_ALL;
  818.  
  819.   }
  820.  
  821.  
  822.  
  823.   if(!strcasecmp(NBCmd,"zas") && NULL!=ArgPtr) {
  824.  
  825.     char Lower[512];
  826.  
  827.     int i=0;
  828.  
  829.     for(i=0;;) {
  830.  
  831.       Lower[i]=tolower(ArgPtr[i]);
  832.  
  833.       if(0==ArgPtr[i++])
  834.  
  835.         break;
  836.  
  837.     }
  838.  
  839.     if(strlen(ArgPtr) > 150)
  840.  
  841.       xchat_commandf(ph,"%s Too many chars of ASM given",ReplyCmd);
  842.  
  843.     else if(strstr(Lower, "incbin"))
  844.  
  845.       xchat_commandf(ph,"%s incbin disabled to avoid crashes",ReplyCmd);    
  846.  
  847.     else if(strstr(Lower, "include"))
  848.  
  849.       xchat_commandf(ph,"%s include disabled to avoid crashes",ReplyCmd);
  850.  
  851.     else {
  852.  
  853.       char Hex[2048];
  854.  
  855.       z80Asm(ArgPtr,Hex);
  856.  
  857.       if(strlen(Hex)>400) {
  858.  
  859.         xchat_commandf(ph, "%s Assembled program is too many chars to read out",ReplyCmd);
  860.  
  861.       }
  862.  
  863.       else
  864.  
  865.         xchat_commandf(ph, "%s %s",ReplyCmd, Hex);
  866.  
  867.     }
  868.  
  869.     return XCHAT_EAT_ALL;
  870.  
  871.   }
  872.  
  873.  
  874.  
  875.   if(!strcasecmp(NBCmd,"false") && NULL!=ArgPtr) {
  876.  
  877.     if(strlen(ArgPtr) > 150)
  878.  
  879.       xchat_commandf(ph,"%s Too many chars given",ReplyCmd);
  880.  
  881.     else {
  882.  
  883.       char Hex[2048];
  884.  
  885.       NBFalse(ArgPtr,Hex);
  886.  
  887.       if(strlen(Hex)>400) {
  888.  
  889.         xchat_commandf(ph, "%s Output is too many chars",ReplyCmd);
  890.  
  891.       }
  892.  
  893.       else
  894.  
  895.         xchat_commandf(ph, "%s %s",ReplyCmd, Hex);
  896.  
  897.     }
  898.  
  899.     return XCHAT_EAT_ALL;
  900.  
  901.   }
  902.  
  903.  
  904.  
  905.   if(!strcasecmp(NBCmd,"rand") && NULL!=ArgPtr) {
  906.  
  907.     int max = strtol(ArgPtr, NULL, 10);
  908.  
  909.     if(max != 0)
  910.  
  911.       xchat_commandf(ph, "%s Here's your random number (modulo %i, +1): %i",ReplyCmd,max,1+rand()%max);
  912.  
  913.     else
  914.  
  915.       xchat_commandf(ph, "%s I'm not going to divide by zero, sorry",ReplyCmd);
  916.  
  917.     return XCHAT_EAT_ALL;
  918.  
  919.   }
  920.  
  921.   if(!strcasecmp(NBCmd,"rand")) {
  922.  
  923.     sprintf(Temp,"%s Here's your random number: %i",ReplyCmd,rand());
  924.  
  925.     xchat_command(ph, Temp);
  926.  
  927.     return XCHAT_EAT_ALL;
  928.  
  929.   }
  930.  
  931.   if(!strcasecmp(NBCmd,"dice") && NULL!=ArgPtr) {
  932.  
  933.     int dice = strtol(ArgPtr, &ArgPtr, 10);
  934.  
  935.     if(NULL != ArgPtr) {
  936.  
  937.       int sides = strtol(ArgPtr, &ArgPtr, 10);
  938.  
  939.       int total = 0;
  940.  
  941.       int num;    
  942.  
  943.  
  944.  
  945.       if(dice > 300)
  946.  
  947.         xchat_commandf(ph, "%s I know better than to lag myself trying to roll that many", ReplyCmd);
  948.  
  949.       else if (sides == 0)
  950.  
  951.         xchat_commandf(ph, "%s I don't have any dice with zero sides", ReplyCmd);
  952.  
  953.       else if (dice < 1)
  954.  
  955.         xchat_commandf(ph, "%s I can't roll a negative number of dice", ReplyCmd);
  956.  
  957.       else {
  958.  
  959.         for(num = 0; num < dice; num++)
  960.  
  961.           total+=1+(rand()*sides/RAND_MAX);
  962.  
  963.         char *DiceWord = "dice";
  964.  
  965.         if(sides == 2) DiceWord = "coins";
  966.  
  967.         if(sides == 1) DiceWord = "spheres";
  968.  
  969.         if(sides < 0) DiceWord = "negative dice";
  970.  
  971.         xchat_commandf(ph, "%s I %s %i %s, each with %i sides and got: %i",ReplyCmd,(sides!=2?"rolled":"flipped"),dice,DiceWord, sides, total);
  972.  
  973.       }
  974.  
  975.     }
  976.  
  977.     return XCHAT_EAT_ALL;
  978.  
  979.   }
  980.  
  981.  
  982.  
  983.   if(!strcasecmp(NBCmd,"zmulbyadd") && NULL!=ArgPtr) {
  984.  
  985.        z80FakeMultiply(Temp, strtol(ArgPtr,NULL,10));
  986.  
  987.     xchat_commandf(ph, "%s List: %s", ReplyCmd, Temp);
  988.  
  989.     return XCHAT_EAT_ALL;
  990.  
  991.   }
  992.  
  993.   if(!strcasecmp(NBCmd,"clean") && NULL!=ArgPtr) {
  994.  
  995.     xchat_commandf(ph, "me produces a hose and sprays down %s", ArgPtr); //Message+9);
  996.  
  997.     return XCHAT_EAT_ALL;
  998.  
  999.   }  
  1000.  
  1001.   if(!strcasecmp(NBCmd,"convbase") && NULL!=ArgPtr) {
  1002.  
  1003.     int whatever;
  1004.  
  1005.     switch(*ArgPtr) {
  1006.  
  1007.       case '$':
  1008.  
  1009.         whatever = strtol(ArgPtr+1,NULL,16);
  1010.  
  1011.         break;
  1012.  
  1013.       case '%':
  1014.  
  1015.         whatever = strtol(ArgPtr+1,NULL,2);
  1016.  
  1017.         break;
  1018.  
  1019.       default:
  1020.  
  1021.         whatever = strtol(ArgPtr,NULL,10);
  1022.  
  1023.         break;
  1024.  
  1025.     }
  1026.  
  1027.     xchat_commandf(ph, "%s %i == $%x",ReplyCmd,whatever, whatever);
  1028.  
  1029.     return XCHAT_EAT_ALL;
  1030.  
  1031.   }
  1032.  
  1033.   if(!strcasecmp(NBCmd,"calc") && NULL!=ArgPtr) {
  1034.  
  1035.     if(!strcasecmp(ArgPtr, "tragedy time +") || !strcasecmp(ArgPtr, "time tragedy +")) {
  1036.  
  1037.       xchat_commandf(ph,"%s calc: comedy", ReplyCmd);
  1038.  
  1039.       return XCHAT_EAT_ALL;
  1040.  
  1041.     }
  1042.  
  1043.     if(strlen(ArgPtr) > 100) {
  1044.  
  1045.       xchat_commandf(ph,"%s Equation's too long",ReplyCmd);
  1046.  
  1047.       return XCHAT_EAT_ALL;
  1048.  
  1049.     }
  1050.  
  1051.     else {
  1052.  
  1053.       InfoQuit Test = RunRetardScript(ArgPtr,0,1);
  1054.  
  1055.       if(strlen(Test.Text) < 400)
  1056.  
  1057.         xchat_commandf(ph, "%s calc: %s", ReplyCmd, Test.Text);
  1058.  
  1059.       else
  1060.  
  1061.         xchat_commandf(ph, "%s calc - too much on the stack to display (%i chars)", ReplyCmd, Test.Text, strlen(Test.Text));
  1062.  
  1063.     }
  1064.  
  1065.     return XCHAT_EAT_ALL;
  1066.  
  1067.   }
  1068.  
  1069.   if(!strcasecmp(NBCmd,"jumpengine")) {
  1070.  
  1071.     xchat_commandf(ph, "%s asl \\ tay \\ pla \\ sta 4 \\ pla \\ sta 5 \\ iny \\ lda (4),y \\ sta 6 \\ iny \\ lda (4),y \\ sta 7 \\ jmp (6)", ReplyCmd);
  1072.  
  1073.     return XCHAT_EAT_ALL;
  1074.  
  1075.   }
  1076.  
  1077.   if(!strcasecmp(NBCmd,"beep")) {
  1078.  
  1079.     xchat_commandf(ph, "%s beep! \a",ReplyCmd);
  1080.  
  1081.     return XCHAT_EAT_ALL;
  1082.  
  1083.   }
  1084.  
  1085.   if(!strcasecmp(NBCmd,"wtf")) {
  1086.  
  1087.     xchat_commandf(ph, "%s Don't worry about it, go back to bed",ReplyCmd);
  1088.  
  1089.     return XCHAT_EAT_ALL;
  1090.  
  1091.   }
  1092.  
  1093.   if(!strcasecmp(NBCmd,"getmeasoda")) {
  1094.  
  1095.     xchat_commandf(ph, "me hands %s a soda",Nick);
  1096.  
  1097.     return XCHAT_EAT_ALL;
  1098.  
  1099.   }
  1100.  
  1101.   if(!strcasecmp(NBCmd,"getmeafuckingsoda")) {
  1102.  
  1103.     xchat_commandf(ph, "me hands %s a soda which then fucks %s really hard",Nick, Nick);
  1104.  
  1105.     return XCHAT_EAT_ALL;
  1106.  
  1107.   }
  1108.  
  1109.   if(!strcasecmp(NBCmd,"getmeasexysoda")) {
  1110.  
  1111.     xchat_commandf(ph, "me hands %s a soda which then has sex with %s", Nick, Nick);
  1112.  
  1113.     return XCHAT_EAT_ALL;
  1114.  
  1115.   }
  1116.  
  1117.  
  1118.  
  1119.   if(!strcasecmp(NBCmd, "allcaps") || !strcasecmp(NBCmd, "altcaps") ||
  1120.  
  1121.     !strcasecmp(NBCmd, "bouncycaps") || !strcasecmp(NBCmd, "rainbow") ||
  1122.  
  1123.     !strcasecmp(NBCmd, "rainbow4") || !strcasecmp(NBCmd, "rainbowcaps") ||
  1124.  
  1125.     !strcasecmp(NBCmd, "echo") || !strcasecmp(NBCmd, "backwards") ||
  1126.  
  1127.     !strcasecmp(NBCmd, "strlen") || !strcasecmp(NBCmd, "clean") ||
  1128.  
  1129.     !strcasecmp(NBCmd, "calc") || !strcasecmp(NBCmd, "convbase") ||
  1130.  
  1131.     !strcasecmp(NBCmd, "strlen") || !strcasecmp(NBCmd, "clean") ||
  1132.  
  1133.     !strcasecmp(NBCmd, "givejuice") || !strcasecmp(NBCmd, "zmulbyadd") ||
  1134.  
  1135.     !strcasecmp(NBCmd, "ppuaddris") || !strcasecmp(NBCmd, "randcaps") ||
  1136.  
  1137.     !strcasecmp(NBCmd, "zas") || !strcasecmp(NBCmd, "false") ||
  1138.  
  1139.     !strcasecmp(NBCmd, "hstroll") || !strcasecmp(NBCmd, "dice") ||
  1140.  
  1141.     !strcasecmp(NBCmd, "yiff") || !strcasecmp(NBCmd, "davyiff") ||
  1142.  
  1143.     !strcasecmp(NBCmd, "krypto") || !strcasecmp(NBCmd, "datediff"))
  1144.  
  1145.     return RequiresArgument(ReplyCmd, NULL);
  1146.  
  1147.      
  1148.  
  1149.   return XCHAT_EAT_NONE; // let other plugins see it
  1150.  
  1151. }
  1152.  
  1153.  
  1154.  
  1155. void xchat_plugin_get_info(char **name, char **desc, char **version, void **reserved) {
  1156.  
  1157.    *name = PNAME;
  1158.  
  1159.    *desc = PDESC;
  1160.  
  1161.    *version = PVERSION;
  1162.  
  1163. }
  1164.  
  1165.  
  1166.  
  1167. int xchat_plugin_deinit() {
  1168.  
  1169.    return 1;
  1170.  
  1171. }
  1172.  
  1173. int xchat_plugin_init(xchat_plugin *plugin_handle,
  1174.  
  1175.                       char **plugin_name,
  1176.  
  1177.                       char **plugin_desc,
  1178.  
  1179.                       char **plugin_version,
  1180.  
  1181.                       char *arg) {
  1182.  
  1183.    /* we need to save this for use with any xchat_* functions */
  1184.  
  1185.    ph = plugin_handle;
  1186.  
  1187.  
  1188.  
  1189.    /* tell xchat our info */
  1190.  
  1191.    *plugin_name = PNAME;   *plugin_desc = PDESC;   *plugin_version = PVERSION;
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197.    xchat_hook_command(ph, "NB_ExtCmd", XCHAT_PRI_NORM, nb_extcmdtest_cb, NULL, 0);
  1198.  
  1199.    return 1;       /* return 1 for success */
  1200.  
  1201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement