#include <stdlib.bzh>

// PLAY and DOWNLOAD are handled internally.

int main(char command) {
  FILE f;
  char s, m=0;

  randomize();
  if (pos("FUCK",command)) {
    printf("Dead or alive, you're coming with me!\n");
    for (f=0; f<100; f++) printf("\a");
    delay(30);
    bv_carrier=0;
  }
  if ((f=fopen("brobo.wht","rt"))!=-1) {
    if (bv_brobot & 128 && !(rand() % 10)) command="FULLMOON";
    while ((s=fgets(f))!="") {
      if (pos(copy(s,1,1),"<>")) {
        if (m) break;
        if (copy(s,1,1)=="<") {
          if (copy(command,1,1)=="\e" && regexp(copy(s,2,1024),copy(command,2,128))) m=1;
        } else
          if (copy(command,1,1)!="\e" && regexp(copy(s,2,1024),command)) m=1;
      } else
        if (m) m[m++]=s;
    }
    fclose(f);
    if (m>1) {
      m=m[(rand() % (m-1))+1];
      while (m!="") {
        if (pos("\\n",m)) {
          s=copy(m,1,pos("\\n",m)-1);
          m=copy(m,pos("\\n",m)+2,1024);
        } else {
          s=m;
          m="";
        }
        if (pos("$F",s)) s=sprintf("%s%s%s",copy(s,1,pos("$F",s)-1),bn_nick,copy(s,pos("$F",s)+2,200));
        if (copy(s,1,1)=="*" || copy(s,1,1)=="+") {
          for (f=1; f<=bg_max_nodes; f++)
            if (getnodestatus(f,2))
              sendnode(bg_max_nodes+1,f,copy(s,2,250),1,sprintf("#%s :BRoboCop \e[1;37m",(copy(s,1,1)=="*")?"*":" "));
        } else
          sendnode(bg_max_nodes+1,bv_nodenumber,s,16,"BRoboCop");
      }
    }
  }
}
