/* read in programming for the channel from "channel" */ /* also some of the ban stuff is here */ /* totally different format for startup file now (27jan94) */ /* most of this stuff isn't really used if you compile with Tcl */ #include #include #include #include "eggdrop.h" extern int serv; extern int shtime; extern int op_on_join; extern int revenge; extern int telnet_port; extern int min_servs; extern int curserv; extern char botname[]; extern char origbotname[]; extern char botuser[]; extern char bothost[]; extern char botrealname[]; extern char botserver[]; extern char botchan[]; extern char curchan[]; extern char configfile[]; extern char dccdir[]; extern char dccin[]; extern char motdfile[]; extern char admin[]; extern char gainops[]; extern char userfile[]; extern char helpbot[]; extern char helpserver[]; extern char helpdir[]; extern char initserver[]; extern char chankey[]; extern char notify_new[]; extern char tempdir[]; extern char ctcp_version[]; extern char ctcp_finger[]; extern char textdir[]; extern char owner[]; extern int botserverport; extern int dcc_total; extern int use_stderr; extern int greet; extern int learn_users; extern int helpserverport; extern int helpserv; extern int flood_thr; extern int flood_pub_thr; extern int flood_join_thr; extern int require_x; extern int enforce_bans; extern int share_users; extern int use_info; extern int passive; extern int strict_host; extern int noshare; extern int require_p; extern int isolate; extern int conmask; extern int default_flags; extern int keep_all_logs; extern int chan_updates; extern int raw_files; extern int perm_bans; extern int ban_time; extern int ignore_time; extern int make_userfile; extern int upload_to_cd; extern int dcc_limit; extern int idle_kick; extern int bitch; extern int never_give_up; extern int protect_ops; extern int allow_new_telnets; extern int forbid_bans; extern int dcc_block; extern int dcc_maxsize; extern struct dcc_t dcc[]; extern char *logfile[]; extern int logmask[]; extern char cx_file[]; extern int cx_line; extern struct userrec *userlist; char oldchan[121]=""; char oldnick[10]=""; /* clear old bans from the channel when we get ops? */ int clearbans=0; /* where to store notes */ char notefile[121]; /* old-style queue, still used by server list */ struct queue { char *item; struct queue *next; } *serverlist=NULL; struct userrec *adduser(); /* remove space characters from beginning and end of string */ /* (more efficent by Fred1) */ void rmspace(s) char *s; { char *p; /* wipe end of string */ for (p=s+strlen(s)-1; ((*p<=32)&&(p>=s)); p--); if (p!=s+strlen(s)-1) *(p+1)=0; for (p=s; ((*p<=32) && (*p)); p++); if (p!=s) strcpy(s,p); } /* memory we should be using */ int expmem_chanprog() { int i,tot; struct queue *s=serverlist; tot=0; while (s!=NULL) { tot+=strlen(s->item)+1; tot+=sizeof(struct queue); s=s->next; } #ifndef TCL for (i=0; inext=q; x->item=(char *)nmalloc(strlen(s)+1); strcpy(x->item,s); s[0]=0; strcpy(s,s1); } while (s[0]); return x; } /* remove someone from a queue */ struct queue *delq(s,q,ok) char *s; struct queue *q; int *ok; { struct queue *x,*x1,*ret,*old; x=q; ret=q; old=q; *ok=0; while (x!=NULL) { if (strcasecmp(x->item,s)==0) { if (x==ret) { ret=(x->next); nfree(x->item); nfree(x); x=ret; } else { old->next=x->next; nfree(x->item); nfree(x); x=old->next; } *ok=1; } else { old=x; x=x->next; } } return ret; } /* clear out a list */ void clearq(xx) struct queue *xx; { struct queue *x,*x1; x=xx; while (x!=NULL) { x1=x->next; nfree(x->item); nfree(x); x=x1; } } /* new server to the list */ prog_server(s) char *s; { serverlist=addq(s,serverlist); } int unprog_server(s) char *s; { int i; serverlist=delq(s,serverlist,&i); return i; } /* set botserver to the next available server */ /* we gotta move through the queue from end to front, cos the entries were */ /* pushed on from the config file stack-fashion, with the last entry ending */ /* up as the head of the queue */ /* -> if (*ptr == -1) then jump to that particular server */ void next_server(ptr,serv,port) int *ptr,*port; char *serv; { struct queue *x=serverlist; int ok=1,i; char s[121]; context; if (x==NULL) return; /* -1 --> go to specified server */ if (*ptr == -1) { char sv[121]; int p; ok=0; i=0; while ((x!=NULL) && (!ok)) { strcpy(s,x->item); splitc(sv,s,':'); if (!sv[0]) { strcpy(sv,s); p=6667; } else { p=atoi(s); } if ((strcasecmp(sv,serv)==0) && (p==*port)) ok=1; else { x=x->next; i++; } } if (ok) { *ptr=i; return; } /* requested server is valid */ /* gotta add it : */ sprintf(s,"%s:%d",serv,*port); serverlist=addq(s,serverlist); *ptr=0; return; } /* if it's the queue head, go to the end and start back again */ else if (*ptr == 0) { while (x->next!=NULL) { (*ptr)++; x=x->next; } strcpy(s,x->item); splitc(serv,s,':'); if (!serv[0]) { strcpy(serv,s); *port=6667; } else { *port=atoi(s); } return; } i=(*ptr)-1; *ptr=i; if (x->next==NULL) ok=0; else while ((i>0) && (ok)) { x=x->next; i--; if (x->next==NULL) ok=0; /* not in list, so just start at beginning */ } if (i) *ptr=(*ptr)-i; /* in case was past end of list */ strcpy(s,x->item); splitc(serv,s,':'); if (!serv[0]) { strcpy(serv,s); *port=6667; } else { *port=atoi(s); } } /* show server list, and point out which ones the bot and helpbot are on */ void tell_servers(z) int z; { struct queue *x=serverlist; int i,sp; char s[141],sv[121]; context; if (x==NULL) { tprintf(z,"No servers.\n"); return; } tprintf(z,"My server list:\n"); i=0; while (x!=NULL) { strcpy(s,x->item); splitc(sv,s,':'); if (!sv[0]) { strcpy(sv,s); sp=6667; } else sp=atoi(s); sprintf(s," %s:%d",sv,sp); if (i==curserv) strcat(s," <- I am here."); if ((helpbot[0]) && (i==helpserv)) strcat(s," <- The helpbot is here."); tprintf(z,"%s\n",s); x=x->next; i++; } } void wipe_serverlist() { if (serverlist==NULL) return; clearq(serverlist); serverlist=NULL; } /* revenge tactic: person did something bad */ /* if they're oplisted, remove them from the op list */ /* otherwise, deop them */ void unprog_op_and_deop(who,reason) char *who; char *reason; { char nick[10],s[121],s1[121],*p,*q; int i,atr; context; atr=get_attr_handle(who); if (atr & USER_FRIEND) { log(LOG_MISC,"%s is a friend (%s)",who,reason); return; /* argh! */ } if (change_attr(who,'-',USER_OP)) { log(LOG_MISC,"No longer opping %s (%s)",who,reason); return; } if (match_ban(who)) { /* what more can we do? */ return; } if (atr & USER_DEOP) { /* this is out of control: BAN THEM */ log(LOG_MISC,"Now banning %s (%s)",who,reason); strcpy(s1,who); splitnick(nick,s1); maskhost(s1,s); strcpy(s1,"*!*"); strcat(s1,&s[2]); /* add extra * for ban */ prog_ban(s1,time(NULL),reason); return; } if (change_attr(who,'+',USER_DEOP)) { /* in the user list already, cool :) */ log(LOG_MISC,"Now deopping %s (%s)",who,reason); return; } strcpy(s1,who); splitnick(nick,s1); maskhost(s1,s); while (is_user(nick)) { if (strncmp(nick,"bad",3)==0) { i=atoi(&nick[3]); sprintf(nick,"bad%d",i+1); } else strcpy(nick,"bad1"); } userlist=adduser(userlist,nick,s,"nopass",USER_DEOP); sprintf(s,"%s (%s)",who,reason); set_handle_comment(userlist,nick,s); log(LOG_MISC,"Now deopping %s (%s)",who,reason); } /* got 368: end of ban list */ void got368(from,msg) char *from,*msg; { /* add bans that should be there but aren't */ context; if (clearbans) resetbans(); else { kill_bogus_bans(); recheck_bans(); } context; /* ^this also flushes the deban if i found myself in the list */ /* (see got367 in chan.c) */ } /* clear out the programming */ void clearprog() { context; clear_userlist(userlist); userlist=NULL; clearq(serverlist); serverlist=NULL; strcpy(oldchan,curchan); strcpy(oldnick,botname); } /* Tcl has its own much simpler 'set' */ #ifndef TCL #define PSET(x) { (x)=ans; \ if (z) tprintf(z,"Set %s %s.\n",which,ans?"on":"off"); } #define ONOFF(z,x,y,x1,y1) tprintf(z,"%-15s %3s %-15s %3s\n",x,y? \ "ON":"OFF",x1,(y1==(-1)?"":(y1?"ON":"OFF"))) /* set an on/off switch */ void prog_set(this,z) char *this; int z; { char which[41]; int ans; context; if (this[0]==0) { if (z) { ONOFF(z,"log-time",shtime,"passive",passive); ONOFF(z,"clear-bans",clearbans,"strict-host",strict_host); ONOFF(z,"op-on-join",op_on_join,"isolate",isolate); ONOFF(z,"revenge",revenge,"keep-all-logs",keep_all_logs); ONOFF(z,"greet",greet,"chan-updates",chan_updates); ONOFF(z,"learn-users",learn_users,"raw-files",raw_files); ONOFF(z,"require-x",require_x,"perm-bans",perm_bans); ONOFF(z,"require-p",require_p,"upload-to-cd",upload_to_cd); ONOFF(z,"enforce-bans",enforce_bans,"bitch",bitch); ONOFF(z,"use-info",use_info,"never-give-up",never_give_up); ONOFF(z,"share-users",share_users,"protect_ops",protect_ops); ONOFF(z,"open-telnets",allow_new_telnets,"forbid-bans",forbid_bans); } return; } split(which,this); if (strcasecmp(this,"on")==0) ans=1; else if (strcasecmp(this,"off")==0) ans=0; else if ((this[0]=='Y') || (this[0]=='y') || (this[0]=='t') || (this[0]=='T')) ans=1; else if ((this[0]=='n') || (this[0]=='N') || (this[0]=='F') || (this[0]=='f')) ans=0; else return; if (strcasecmp(which,"log-time")==0) PSET(shtime) else if (strcasecmp(which,"clear-bans")==0) PSET(clearbans) else if (strcasecmp(which,"op-on-join")==0) PSET(op_on_join) else if (strcasecmp(which,"revenge")==0) PSET(revenge) else if (strcasecmp(which,"greet")==0) PSET(greet) else if (strcasecmp(which,"learn-users")==0) PSET(learn_users) else if (strcasecmp(which,"require-x")==0) PSET(require_x) else if (strcasecmp(which,"require-p")==0) PSET(require_p) else if (strcasecmp(which,"enforce-bans")==0) PSET(enforce_bans) else if (strcasecmp(which,"use-info")==0) PSET(use_info) else if (strcasecmp(which,"share-users")==0) PSET(share_users) else if (strcasecmp(which,"passive")==0) PSET(passive) else if (strcasecmp(which,"strict-host")==0) PSET(strict_host) else if (strcasecmp(which,"keep-all-logs")==0) PSET(keep_all_logs) else if (strcasecmp(which,"chan-updates")==0) PSET(chan_updates) else if (strcasecmp(which,"raw-files")==0) PSET(raw_files) else if (strcasecmp(which,"perm-bans")==0) PSET(perm_bans) else if (strcasecmp(which,"upload-to-cd")==0) PSET(upload_to_cd) else if (strcasecmp(which,"bitch")==0) PSET(bitch) else if (strcasecmp(which,"never-give-up")==0) PSET(never_give_up) else if (strcasecmp(which,"protect-ops")==0) PSET(protect_ops) else if (strcasecmp(which,"open-telnets")==0) PSET(allow_new_telnets) else if (strcasecmp(which,"forbid_bans")==0) PSET(forbid_bans) else if (strcasecmp(which,"isolate")==0) { PSET(isolate) if (z) { if (isolate) chatout("*** Party line is now isolated.\n"); else chatout("*** Party line is now open.\n"); if (isolate) tandout("chat %s Isolating my party line.\n",origbotname); else tandout("chat %s Merging my party line.\n",origbotname); } } else { if (z) tprintf(z,"No such variable.\n"); else { if (use_stderr) fprintf(stderr,"* Warning: Unknown set variable '%s'\n",which); } return; } } #endif (!defined TCL) int logmodes(s) char *s; { int i; int res=0; for (i=0; i