/* File.c this file handles most of the file i/o for the bot loading users/protected users parsing the data into useful info also logging functions as well as adding a user or removing a user Thanks go out to Tychy for help in modifying the method of parsing the data into readable information. */ #include #include #include #define __MYFILE__ #include "config.h" #include "myfile.h" int user_count=0,prot_count=0; int killstatus=1; char LastComm[CMDHISTORY][1024]; extern struct aDccClient MyClient[]; extern int DccCtr; extern int NOWTIME,SITE_CLONE; extern char *SuspendChan[]; extern time_t SuspendChanTime[]; extern char *SuspendOper[]; extern time_t SuspendOperTime[]; extern char *NoGlineHost[]; extern char *GlineHost[]; extern char *MultiUserHost[]; extern char *SingleUserHost[]; extern char *operchan[]; extern char *killchan[]; struct aUser *buser; struct aHost *bhost; struct aGline Glines[MAXGLINES]; extern char buf[],sockbuf[]; extern char *token[]; extern int sevsck,botsck; FILE *logfp,*logfd=NULL; int logstats=0; int load_myuser(char *filename) { FILE *infile; char line[512]; struct aUser *tmpuser; char *tmp; int legit=0; if( (infile=fopen(filename,"r")) == NULL) return 0; for(; fgets(line,511,infile);) { line[strlen(line)-1]='\0'; if(line[0]=='#') continue; /* comment line */ tmpuser = (struct aUser *) malloc(sizeof(struct aUser)); legit=1; tmp=strtok(line,"!"); if(tmp == NULL) { free(tmpuser); continue; } tmpuser->level = atoi(tmp); tmp=strtok(NULL,"!"); if(tmp == NULL) { free(tmpuser); continue; } strcpy(tmpuser->nick,tmp); tmp=strtok(NULL,"!"); if(tmp == NULL) { free(tmpuser); continue; } strcpy(tmpuser->mask,tmp); tmp=strtok(NULL,"!"); if(tmp == NULL) strcpy(tmpuser->passwd,"*"); else strcpy(tmpuser->passwd,tmp); tmp=strtok(NULL,"!"); if(tmp != NULL) strcpy(tmpuser->comment,tmp); tmpuser->timeout=-1; tmpuser->vrfy=0; tmpuser->next=buser; buser=tmpuser; } } struct aUser *chklevel(char *fromhost) { struct aUser *tmpuser; tmpuser=buser; while(tmpuser != NULL) { if(((tmpuser->timeout < 0) || (tmpuser->timeout > NOWTIME)) && (!match(tmpuser->mask,fromhost))) { return tmpuser; } tmpuser=tmpuser->next; } return NULL; } struct aUser *vrfy_oper(char *fromhost,char *passwd) { struct aUser *tmpuser; tmpuser=buser; while(tmpuser != NULL) { if(((tmpuser->timeout < 0) || (tmpuser->timeout > NOWTIME)) && (!match(tmpuser->mask,fromhost))) { if(!strcmp(passwd,tmpuser->passwd)) { return tmpuser; } else { return NULL; } } tmpuser=tmpuser->next; } return NULL; } int add_myuser(int level, char *nick, char *mask,char *passwd, time_t timeout ,char *comment) { struct aUser *tmpuser; tmpuser = (struct aUser *) malloc(sizeof(struct aUser)); strcpy(tmpuser->nick,nick); strcpy(tmpuser->mask,mask); if((passwd != NULL) && (strlen(passwd)<9)) strcpy(tmpuser->passwd,passwd); else strcpy(tmpuser->passwd,"*"); if(comment != NULL) strcpy(tmpuser->comment,comment); else (strcpy(tmpuser->comment,nick)); tmpuser->vrfy=0; tmpuser->level = level; tmpuser->timeout=timeout; tmpuser->chanlist=NULL; tmpuser->next=buser; buser=tmpuser; } int chkchanlevel(char *fromhost,char *channel) { struct aUser *tmpuser; tmpuser=buser; while(tmpuser != NULL) { if(((tmpuser->timeout < 0) || (tmpuser->timeout > NOWTIME)) && (!match(tmpuser->mask,fromhost)) && (*tmpuser->nick == '#') && (!match(tmpuser->nick,channel))) { return tmpuser->level; } tmpuser=tmpuser->next; } return NULL; } startlog() { if((logfp = fopen(LOGFILE,"a")) == NULL) logstats = 0; else logstats = 1; if((logfd = fopen(FLOODFILE,"a")) == NULL)logfd=NULL; } writelogtel(char *cbuf) { time_t timer; struct tm *tblock; char temp[512]; char datime[64]; int j,k; if(!logstats) return; k=chk_num(0); strcpy(temp,""); for(j=3;j%s %s",cbuf,asctime(tblock))) fflush(logfp); } writelog(char *fromhost) { time_t timer; struct tm *tblock; char temp[512]; char datime[64]; int j,k; if(!logstats) return; if((token[3]) && (!strcmp(token[3],":dccwall"))) return; if((token[3]) && (!strcmp(token[3],":wall"))) return; if((token[3]) && (!strcmp(token[3],":dmsg"))) return; if((token[3]) && (!strcmp(token[3],":dlist"))) return; if((token[3]) && (!strcmp(token[3],":dwho"))) return; if((token[3]) && (!strcmp(token[3],":umode"))) return; strcpy(temp,token[3]); for(j=4;token[j];j++) { strcat(temp," "); strcat(temp,token[j]); } if(fprintf(logfp,"%ld %s->%s %s\n",NOWTIME,fromhost,token[0], temp)) fflush(logfp); return; } catfile(char *filename,char *botname) { FILE *catfp; char line[80]; if( (catfp = fopen(filename,"r")) == NULL) { sprintf(buf,":%s Privmsg %s :%s -- NOT AVAILABLE\n",botname, token[0],filename); writeln(sevsck,buf); fclose(catfp); return; } for(;fgets(line,80,catfp);) { sprintf(buf,":%s NOTICE %s :%s\n",botname,token[0],line); writeln(sevsck,buf); } fclose(catfp); return; } record_kill() { FILE *fpkill; char temp[600]; time_t timer; struct tm *tmblock; int i=0,k; if(!killstatus) return; temp[0]='\0'; k=chk_num(0); for(i=0;i%s %s",temp,asctime(tmblock))) fflush(logfp); if( (fpkill=fopen(KILLFILE,"r"))==NULL) return; fclose(fpkill); if( (fpkill=fopen(KILLFILE,"a"))==NULL) return; fprintf(fpkill,"KILL %s %s",temp,asctime(tmblock)); fclose(fpkill); } writelogflood(char *cbuf) { time_t timer; struct tm *tblock; char temp[512]; char datime[64]; int j,k; if(logfd==NULL) return; k=chk_num(0); strcpy(temp,""); for(j=3;jlevel,tmpuser->nick,tmpuser->mask, (tmpuser->timeout == -1)?-1:tmpuser->timeout - NOWTIME); writeln(sck,mybuf); tmpuser=tmpuser->next; } return( 0); } int destroy_myuser() { struct aUser *tmpuser; while(buser != NULL) { tmpuser=buser; buser=buser->next; free(tmpuser); } } int remove_myuser( char *mask) { struct aUser *tmpuser,*tmp2user; tmp2user=buser; if(tmp2user == NULL) return; if(!strcasecmp(buser->mask,mask)) { buser=buser->next; destroy_banlist(tmp2user); free(tmp2user); return 1; } tmpuser = buser->next; while(tmpuser != NULL) { if( !strcasecmp(tmpuser->mask,mask)) { tmp2user->next=tmpuser->next; destroy_banlist(tmpuser); free(tmpuser); return 1; } tmp2user=tmpuser; tmpuser=tmpuser->next; } } int timeout_myuser() { struct aUser *tmpuser,*tmp2user; tmp2user=buser; if((tmp2user == NULL) || (tmp2user->next == NULL)) return; if((buser->timeout > 0) && (buser->timeout < NOWTIME)) { buser=buser->next; destroy_banlist(tmp2user); free(tmp2user); return 1; } tmpuser = buser->next; while(tmpuser != NULL) { if((tmpuser->timeout > 0) && (tmpuser->timeout < NOWTIME)) { tmp2user->next=tmpuser->next; destroy_banlist(tmpuser); free(tmpuser); tmpuser=tmp2user->next; continue; /* return 1; */ } tmp2user=tmpuser; tmpuser=tmpuser->next; } } int showbans(char *target,int sck) {int i,j; struct aUser *tmpuser; char mybuf[512]; char lev[10]; tmpuser=buser; sprintf(mybuf,":%s NOTICE %s :%3.3s %6s %30.30s %s %s\n", CHANSVR,target,"LEV","TIME","ORIGON","MASK","COMMENT"); writeln(sck,mybuf); sprintf(mybuf, ":%s NOTICE %s :===================================================\n", CHANSVR,target); writeln(sck,mybuf); while(tmpuser != NULL) { if(tmpuser->level <= 0) { if(tmpuser->level == GLINE) strcpy(lev,"GLINE"); else if(tmpuser->level == AUTO_BAN) strcpy(lev,"AUTOBAN"); else if(tmpuser->level == RGLINE) strcpy(lev,"RGLINE"); else sprintf(lev,"%3.3d",tmpuser->level); sprintf(mybuf,":%s NOTICE %s :%2.2s %6.6ld %30.30s %s %s\n", CHANSVR,target,lev, (tmpuser->timeout == -1)?-1:tmpuser->timeout - NOWTIME, tmpuser->nick,tmpuser->mask,tmpuser->comment); writeln(sck,mybuf); } tmpuser=tmpuser->next; } sprintf(mybuf, ":%s NOTICE %s :===================================================\n", CHANSVR,target); writeln(sck,mybuf); return( 0); } int add_chan(char *name,struct aUser *myuser) { struct aChan *tmpchan; myuser->numkicks++; tmpchan=myuser->chanlist; while(tmpchan) { if(!strcasecmp(tmpchan->name,name)) return 1; tmpchan=tmpchan->next; } tmpchan= (struct aChan *) malloc(sizeof(struct aChan)); strcpy(tmpchan->name,name); tmpchan->next = myuser->chanlist; myuser->chanlist=tmpchan; myuser->numbans++; return 1; } int destroy_banlist(struct aUser *myuser) { struct aChan *tmpchan; char outbuf[512]; while(myuser->chanlist != NULL) { tmpchan=myuser->chanlist; myuser->chanlist=myuser->chanlist->next; sprintf(outbuf,":chansvr MODE %s -b %s\n",tmpchan->name,myuser->mask); writeln(sevsck,outbuf); free(tmpchan); myuser->numbans=0; } } int remove_chan( char *name,struct aUser *myuser) { struct aChan *tmpchan,*tmp2chan; tmp2chan=myuser->chanlist; if(tmp2chan == NULL) return; if(!strcasecmp(myuser->chanlist->name,name)) { myuser->chanlist=myuser->chanlist->next; /* HERE WE COULD REMOVE BAN IF WE WANT */ myuser->numbans--; free(tmp2chan); return 1; } tmpchan = myuser->chanlist->next; while(tmpchan != NULL) { if( !strcasecmp(tmpchan->name,name)) { tmp2chan->next=tmpchan->next; myuser->numbans--; /* HERE WE COULD REMOVE BAN IF WE WANT */ free(tmpchan); return 1; } tmp2chan=tmpchan; tmpchan=tmpchan->next; } } int destroy_host() { int i; struct aHost *tmphost; for(i=0;ihost[i] != NULL) { tmphost=host_hashid->host[i]; host_hashid->host[i]=host_hashid->host[i]->next; free(tmphost); } } int remove_host( char *mask) { struct aHost *tmphost,*tmp2host; int hostid=0; if(host_hashid == NULL) { host_hashid = new_hosthash(); return 0; } hostid = get_hashid(mask,HOSTHASH); tmp2host=host_hashid->host[hostid]; if(tmp2host == NULL) return; if(!strcasecmp(tmp2host->hostname,mask)) { host_hashid->host[hostid]=host_hashid->host[hostid]->next; if(tmp2host->hostname != NULL) free(tmp2host->hostname); free(tmp2host); return 1; } tmphost = host_hashid->host[hostid]->next; while(tmphost != NULL) { if( !strcasecmp(tmphost->hostname,mask)) { tmp2host->next=tmphost->next; if(tmphost->hostname != NULL) free(tmphost->hostname); free(tmphost); return 1; } tmp2host=tmphost; tmphost=tmphost->next; } } int scan_host(char *hostname,int mode) { #ifdef USE_TSC struct aHost *tmphost; int hostid=0; if(host_hashid == NULL) host_hashid = new_hosthash(); hostid = get_hashid(hostname,HOSTHASH); tmphost=host_hashid->host[hostid]; while(tmphost) { if(!strcasecmp(tmphost->hostname,hostname)) { if(mode) tmphost->count = tmphost->count+=mode; if(tmphost->count == 0) { remove_host(hostname); return 0; } return tmphost->count; } tmphost=tmphost->next; } if(!mode) return 0; tmphost = (struct aHost *) malloc(sizeof(struct aHost)); tmphost->hostname = my_strcpy(hostname); tmphost->count=mode; tmphost->next=host_hashid->host[hostid]; host_hashid->host[hostid]=tmphost; return tmphost->count; #else return 1; #endif } int show_hosts(char *target,int mode) { struct aHost *tmphost; int total_count=0; int hostid=0,i; #ifdef USE_TSC for(i=0;ihost[i]; while(tmphost) { if(tmphost->count >SITE_CLONE) { if(!mode) { sprintf(buf,":CHANSVR PRIVMSG %s :%d %s\n", target,tmphost->count, tmphost->hostname); writeln(sevsck,buf); } else { if(check_multiconnect(tmphost->hostname)) { sprintf(buf,":CHANSVR PRIVMSG %s :%d %s\n", target,tmphost->count, tmphost->hostname); writeln(sevsck,buf); } } } total_count++; tmphost=tmphost->next; } } sprintf(buf,":CHANSVR PRIVMSG %s :Total Hosts in list %d\n", target,total_count); writeln(sevsck,buf); return 1; #else sprintf(buf,":CHANSVR PRIVMSG %s :TSC Option Not available\n",target); writeln(sevsck,buf); #endif } struct aHosthash *new_hosthash() { struct aHosthash *host_hashid; int i; host_hashid=(struct aHosthash *) malloc(sizeof(struct aHosthash)); for(i=0;ihost[i]=NULL; return host_hashid; } int read_noglines(char *filename) { int i=0; char line[512]; FILE *infile; if((NoGlineHost[0]!=NULL) && (*NoGlineHost[0]!='\0')) for(i=0;*NoGlineHost[i];i++) free(NoGlineHost[i]); if( (infile=fopen(filename,"r")) == NULL) { NoGlineHost[0]=strdup("\0"); return 0; } for(i=0;fgets(line,511,infile);) { line[strlen(line)-1]='\0'; if(line[0]=='#') continue; NoGlineHost[i++]=strdup(line); if(i>MAXNOGLINES-1) break; } NoGlineHost[i]=strdup("\0"); fclose(infile); return 1; } int read_glinehost(char *filename) { int i=0; char line[512]; FILE *infile; if((GlineHost[0]!=NULL) && (*GlineHost[0]!='\0')) for(i=0;*GlineHost[i];i++) free(GlineHost[i]); if( (infile=fopen(filename,"r")) == NULL) { GlineHost[0]=strdup("\0"); return 0; } for(i=0;fgets(line,511,infile);) { line[strlen(line)-1]='\0'; if(line[0]=='#') continue; GlineHost[i++]=strdup(line); if(i>MAXGLINEHOST-1) break; } GlineHost[i]=strdup("\0"); fclose(infile); return 1; } int show_agl() { int cnt; for(cnt=0;*GlineHost[cnt];cnt++) { if(cnt>MAXGLINEHOST) break; sprintf(buf,":%s NOTICE %s :%s\n",CHANSVR,token[0],GlineHost[cnt]); writeln(sevsck,buf); } } int read_mhost(char *filename) { int i=0; char line[512]; FILE *infile; if((MultiUserHost[0]!=NULL) && (*MultiUserHost[0]!='\0')) for(i=0;*MultiUserHost[i];i++) free(MultiUserHost[i]); if( (infile=fopen(filename,"r")) == NULL) { MultiUserHost[0]=strdup("\0"); return 0; } for(i=0;fgets(line,511,infile);) { line[strlen(line)-1]='\0'; if(line[0]=='#') continue; MultiUserHost[i++]=strdup(line); if(i>MAXGLINEHOST-1) break; } MultiUserHost[i]=strdup("\0"); fclose(infile); return 1; } int show_mhost() { int cnt; for(cnt=0;*MultiUserHost[cnt];cnt++) { if(cnt>MAXMHOST) break; sprintf(buf,":%s NOTICE %s :%s\n",CHANSVR,token[0],MultiUserHost[cnt]); writeln(sevsck,buf); } } int read_shost(char *filename) { int i=0; char line[512]; FILE *infile; if((SingleUserHost[0]!=NULL) && (*SingleUserHost[0]!='\0')) for(i=0;*SingleUserHost[i];i++) free(SingleUserHost[i]); if( (infile=fopen(filename,"r")) == NULL) { SingleUserHost[0]=strdup("\0"); return 0; } for(i=0;fgets(line,511,infile);) { line[strlen(line)-1]='\0'; if(line[0]=='#') continue; SingleUserHost[i++]=strdup(line); if(i>MAXGLINEHOST-1) break; } SingleUserHost[i]=strdup("\0"); fclose(infile); return 1; } int show_shost() { int cnt; for(cnt=0;*SingleUserHost[cnt];cnt++) { if(cnt>MAXMHOST) break; sprintf(buf,":%s NOTICE %s :%s\n",CHANSVR,token[0],SingleUserHost[cnt]); writeln(sevsck,buf); } } int storecomm(char *fromhost) { char tbuf[1024]; int loop; sprintf(tbuf,"%s!%s",token[0],fromhost); for(loop=3;token[loop];loop++) { strcat(tbuf," "); strcat(tbuf,token[loop]); } for(loop=0;loopCMDHISTORY) num=CMDHISTORY; for(loop=CMDHISTORY-num;loop0)) continue; SuspendOperTime[i]=atol(ptr); } else SuspendOperTime[i]=-1; SuspendOper[i++]=strdup(line); if(i>MAXSUSPENDOPER-1) break; } SuspendOper[i]=strdup("\0"); fclose(infile); return 1; } int show_suspend() { int cnt; for(cnt=0;*SuspendOper[cnt];cnt++) { if(cnt>MAXSUSPENDOPER) break; sprintf(buf,":%s NOTICE %s :%s %ld\n",CHANSVR,token[0],SuspendOper[cnt], SuspendOperTime[cnt]); writeln(sevsck,buf); } } int save_suspend(char *filename) { int cnt; FILE *outfile; if( (outfile=fopen(filename,"w")) == NULL) return 0; for(cnt=0;*SuspendOper[cnt];cnt++) { if(cnt>MAXSUSPENDOPER) break; if((SuspendOperTime[cnt]>0) && (SuspendOperTime[cnt]NOWTIME)) continue; free(SuspendOper[cnt]); SuspendOper[cnt]=strdup(mask); SuspendOperTime[cnt]=time; save_suspend(SUSPENDFILE); return 0; } SuspendOper[cnt]=strdup(mask); SuspendOperTime[cnt++]=time; SuspendOper[cnt]=strdup("\0"); save_suspend(SUSPENDFILE); return 0; } int read_Csuspend(char *filename) { int i=0; char line[512]; FILE *infile; char *ptr; if((SuspendChan[0]!=NULL) && (*SuspendChan[0]!='\0')) for(i=0;*SuspendChan[i];i++) free(SuspendChan[i]); if( (infile=fopen(filename,"r")) == NULL) { SuspendChan[0]=strdup("\0"); return 0; } for(i=0;fgets(line,511,infile);) { line[strlen(line)-1]='\0'; /* MASK TIME */ if(line[0]!='#') continue; if((ptr=strchr(line,' ')) !=NULL) { *ptr++='\0'; if((atol(ptr) < NOWTIME) && (atol(ptr)>0)) continue; SuspendChanTime[i]=atol(ptr); } else SuspendChanTime[i]=-1; SuspendChan[i++]=strdup(line); if(i>MAXSUSPENDOPER-1) break; } SuspendChan[i]=strdup("\0"); fclose(infile); return 1; } int show_Csuspend() { int cnt; for(cnt=0;*SuspendChan[cnt];cnt++) { if(cnt>MAXSUSPENDOPER) break; sprintf(buf,":%s NOTICE %s :%s %ld\n",CHANSVR,token[0],SuspendChan[cnt], SuspendChanTime[cnt]); writeln(sevsck,buf); } } int save_Csuspend(char *filename) { int cnt; FILE *outfile; if( (outfile=fopen(filename,"w")) == NULL) return 0; for(cnt=0;*SuspendChan[cnt];cnt++) { if(cnt>MAXSUSPENDOPER) break; if((SuspendChanTime[cnt]>0) && (SuspendChanTime[cnt]NOWTIME)) continue; free(SuspendChan[cnt]); SuspendChan[cnt]=strdup(mask); SuspendChanTime[cnt]=time; save_suspend(SUSPENDFILE); return 0; } SuspendChan[cnt]=strdup(mask); SuspendChanTime[cnt++]=time; SuspendChan[cnt]=strdup("\0"); save_suspend(SUSPENDFILE); return 0; } int read_glines(char *filename) { int i=0; char line[512]; FILE *infile,*outfile; char *ptr,*cptr; if(Glines[0].mask!=NULL) for(i=0;Glines[i].mask;i++) { free(Glines[i].comment); Glines[i].comment=NULL; free(Glines[i].nick); Glines[i].nick =NULL; free(Glines[i].mask); Glines[i].mask =NULL; if(i>=MAXGLINES)break; } if( (infile=fopen(filename,"r")) == NULL) { return 0; } if(outfile) fprintf(outfile,"Debug log Opened\n"); for(i=0;fgets(line,511,infile);) { line[strlen(line)-1]='\0'; /* MASK TIME */ if(line[0]=='#') continue; /* Time mask by comment */ cptr=line; if((ptr=strchr(cptr,' ')) ==NULL) continue; *ptr++='\0'; if((atol(cptr) < NOWTIME) && (atol(cptr)>0)) continue; Glines[i].time=atol(cptr); cptr=ptr; if((ptr=strchr(cptr,' ')) ==NULL) continue; *ptr++='\0'; Glines[i].mask=strdup(cptr); cptr=ptr; if((ptr=strchr(cptr,' ')) ==NULL) continue; *ptr++='\0'; Glines[i].nick=strdup(cptr); Glines[i++].comment=strdup(ptr); if(i>=MAXGLINES) break; } fclose(infile); return 1; } int show_glines() { int cnt; for(cnt=0;Glines[cnt].mask;cnt++) { if(cnt>MAXGLINES) break; if((Glines[cnt].time >0) && (Glines[cnt].time < NOWTIME)) continue; sprintf(buf,":%s NOTICE %s :%ld %s %s %s\n",CHANSVR,token[0], Glines[cnt].time,Glines[cnt].mask, Glines[cnt].nick,Glines[cnt].comment); writeln(sevsck,buf); } } int check_glines(char *userhost) { int cnt; for(cnt=0;Glines[cnt].mask;cnt++) { if(cnt>MAXGLINES) break; if((Glines[cnt].time >0) && (Glines[cnt].time < NOWTIME)) continue; if(!match(Glines[cnt].mask,userhost)) return cnt; } return -1; } int save_glines(char *filename) { int cnt; FILE *outfile; if( (outfile=fopen(filename,"w")) == NULL) return 0; for(cnt=0;Glines[cnt].mask;cnt++) { if(cnt>MAXGLINES) break; if((Glines[cnt].time>0) && (Glines[cnt].timeNOWTIME)) continue; free(Glines[cnt].nick); free(Glines[cnt].mask); free(Glines[cnt].comment); Glines[cnt].mask=strdup(mask); Glines[cnt].nick=strdup(nick); Glines[cnt].comment=strdup(comment); Glines[cnt].time=time; save_glines(GLINEFILE); return 0; } if(cnt >= MAXGLINES) return 0; Glines[cnt].mask=strdup(mask); Glines[cnt].nick=strdup(nick); Glines[cnt].comment=strdup(comment); Glines[cnt].time=time; save_glines(GLINEFILE); return 0; } int rem_glines(char *mask) { int cnt,found=0; for(cnt=0;Glines[cnt].mask;cnt++) { if((Glines[cnt].timeMAXOPERCHAN-1) break; } fclose(infile); return 1; } int show_operchan() { int cnt; for(cnt=0;operchan[cnt];cnt++) { if(cnt>MAXOPERCHAN) break; sprintf(buf,":%s NOTICE %s :%s\n",CHANSVR,token[0],operchan[cnt]); writeln(sevsck,buf); } } int save_operchan(char *filename) { int cnt; FILE *outfile; if( (outfile=fopen(filename,"w")) == NULL) return 0; for(cnt=0;operchan[cnt];cnt++) { if(cnt>MAXOPERCHAN) break; fprintf(outfile,"%s\n",operchan[cnt]); } fclose(outfile); } int add_operchan(char *mask) { int cnt; for(cnt=0;operchan[cnt];cnt++) continue; if(cnt > MAXOPERCHAN-1) return 0; operchan[cnt]=strdup(mask); save_operchan(OPERCHANFILE); return 0; } int rem_operchan(char *mask) { int cnt,loop; for(cnt=0;operchan[cnt];cnt++) { if(!strcasecmp(operchan[cnt],mask) ) { free(operchan[cnt]); loop=cnt+1; while(operchan[loop]) operchan[cnt++]=operchan[loop++]; } } save_operchan(OPERCHANFILE); return 0; } int check_operchan(char *mask) { int cnt,loop; for(cnt=0;operchan[cnt];cnt++) { if(!strcasecmp(operchan[cnt],mask) ) return cnt+1; } return 0; } int InitOperchan() { int i; for(i=0;iMAXOPERCHAN-1) break; } fclose(infile); return 1; } int show_killchan() { int cnt; for(cnt=0;killchan[cnt];cnt++) { if(cnt>MAXOPERCHAN) break; sprintf(buf,":%s NOTICE %s :%s\n",CHANSVR,token[0],killchan[cnt]); writeln(sevsck,buf); } } int save_killchan(char *filename) { int cnt; FILE *outfile; if( (outfile=fopen(filename,"w")) == NULL) return 0; for(cnt=0;killchan[cnt];cnt++) { if(cnt>MAXOPERCHAN) break; fprintf(outfile,"%s\n",killchan[cnt]); } fclose(outfile); } int add_killchan(char *mask) { int cnt; for(cnt=0;killchan[cnt];cnt++) continue; if(cnt > MAXOPERCHAN-1) return 0; killchan[cnt]=strdup(mask); save_killchan(KILLCHANFILE); return 0; } int rem_killchan(char *mask) { int cnt,loop; for(cnt=0;killchan[cnt];cnt++) { if(!strcasecmp(killchan[cnt],mask) ) { free(killchan[cnt]); loop=cnt+1; while(killchan[loop]) killchan[cnt++]=killchan[loop++]; } } save_killchan(KILLCHANFILE); return 0; } int check_killchan(char *mask) { int cnt,loop; for(cnt=0;killchan[cnt];cnt++) { if(!strcasecmp(killchan[cnt],mask) ) return cnt+1; } return 0; } int InitKillchan() { int i; for(i=0;i