/* utilities for eggdrop */ #include #include #include /* the configfile */ char configfile[121]="egg.config"; void rmspace(s) char *s; { while ((s[strlen(s)-1]<=32) && (s[0]!=0)) s[strlen(s)-1]=0; while ((s[0]<=32) && (s[0]!=0)) strcpy(s,&s[1]); } /* split first word off of rest and put it in first */ void splitc(first,rest,divider) char *first,*rest; char divider; { char *p; p=strchr(rest,divider); if (p==NULL) { if ((first!=rest)&&(first!=NULL)) first[0]=0; return; } *p=0; if (first!=NULL) strcpy(first,rest); if (first!=rest) strcpy(rest,p+1); } void split(first,rest) char *first,*rest; { splitc(first,rest,' '); } void create_userfile() { FILE *f; char s[121],userfile[121],code[121]; f=fopen(configfile,"r"); userfile[0]=0; if (f==NULL) { printf("\nCould not open your config file.\n"); return; } while (!feof(f)) { fgets(s,120,f); if (!feof(f)) { if (s[strlen(s)-1]=='\n') s[strlen(s)-1]=0; rmspace(s); split(code,s); rmspace(code); rmspace(s); if (strcasecmp(code,"userfile")==0) strcpy(userfile,s); } } fclose(f); if (!userfile[0]) { printf("\nYou have no userfile defined!\n"); printf("Go edit your config file, then come back.\n"); return; } f=fopen(userfile,"r"); if (f!=NULL) { printf("\nYou already have a user file!\n"); printf("If you REALLY want to remove all your users, erase the file,\n"); printf("and run this program again.\n"); return; } f=fopen(userfile,"w"); if (f==NULL) { printf("\nCan't create the user file.\n"); return; } s[0]=0; printf("\nCreating the user file '%s' ...\n",userfile); while(!s[0]) { printf("\nEnter the name you would like the bot to know you by.\n"); printf("This should typically be your IRC nickname.\n: "); scanf("%s",s); rmspace(s); } strcpy(code,s); s[0]=0; while (!s[0]) { printf("\nEnter the hostmask which will match you, in the form:\n"); printf("*!username@*host.domain\n"); printf("An example: *!goshguys@*clemson.edu\n: "); scanf("%s",s); rmspace(s); } fprintf(f,"%s %s nopass omf 0\n",code,s); fclose(f); printf("\nOkay, your user file has been created.\n"); printf("Currently, you are the only user, and you are an op, master, and\n"); printf("friend. You need to set a password for yourself once the bot is\n"); printf("running. (/msg botname help)\n\n"); } main(argc,argv) int argc; char **argv; { int i; if (argc>=2) strcpy(configfile,argv[1]); printf("(using configfile '%s')\n",configfile); i=999; while (i) { printf("\n\nEGGDROP OFFLINE UTILITIES\n\n"); printf(" (1) Create user file\n"); printf(" (0) Quit\n"); printf("\n--> "); scanf("%d",&i); if (i==1) create_userfile(); } printf("\n\n"); }