/* tcluser.c -- handles: Tcl stubs for the user-record-oriented commands dprintf'ized, 1aug96 */ #if HAVE_CONFIG_H #include #endif #include #include #include #include #include "../lush.h" #include "eggdrop.h" #include "users.h" #include "proto.h" #include "cmdt.h" #include "tclegg.h" /* eggdrop always uses the same interpreter */ extern Tcl_Interp *interp; extern struct userrec *userlist; extern int default_flags; extern struct dcc_t dcc[]; extern int dcc_total; extern char origbotname[]; extern int ignore_time; extern char cx_file[]; extern int cx_line; /***********************************************************************/ int tcl_countusers STDVAR { char s[40]; BADARGS(1,1,""); sprintf(s,"%d",count_users(userlist)); Tcl_AppendResult(irp,s,NULL); return TCL_OK; } int tcl_validuser STDVAR { BADARGS(2,2," handle"); if (is_user(argv[1])) Tcl_AppendResult(irp,"1",NULL); else Tcl_AppendResult(irp,"0",NULL); return TCL_OK; } int tcl_finduser STDVAR { char s[20]; BADARGS(2,2," nick!user@host"); get_handle_by_host(s,argv[1]); Tcl_AppendResult(irp,s,NULL); return TCL_OK; } int tcl_passwdOk STDVAR { BADARGS(3,3," handle passwd"); if (pass_match_by_handle(argv[2],argv[1])) Tcl_AppendResult(irp,"1",NULL); else Tcl_AppendResult(irp,"0",NULL); return TCL_OK; } int tcl_chattr STDVAR { int atr,oatr,f,i,pos=1,recheck=0; char s[20]; BADARGS(2,3," handle ?changes?"); if ((argv[1][0]=='*') || (!is_user(argv[1]))) { Tcl_AppendResult(irp,"*",NULL); return TCL_OK; } oatr=atr=get_attr_handle(argv[1]); if (argc==3) { /* make changes */ for (i=0; iflags & f)==f) Tcl_AppendElement(interp,u->handle); u=u->next; } return TCL_OK; } int tcl_save STDVAR { write_userfile(); return TCL_OK; } int tcl_reload STDVAR { reload(); return TCL_OK; } int tcl_gethosts STDVAR { struct userrec *u; struct eggqueue *q; BADARGS(2,2," handle"); u=get_user_by_handle(userlist,argv[1]); if (u==NULL) return TCL_OK; q=u->host; while (q!=NULL) { Tcl_AppendElement(irp,q->item); q=q->next; } return TCL_OK; } int tcl_chpass STDVAR { char par[10],pass[10]; BADARGS(3,3," handle password"); strncpy(par,argv[2],9); par[9]=0; nsplit(pass,par); change_pass_by_handle(argv[1],pass); return TCL_OK; } int tcl_chhandle STDVAR { char hand[10]; int x=1,i; BADARGS(3,3," oldhandle newhandle"); strncpy(hand,argv[2],9); hand[9]=0; for (i=0; i=127) || (hand[i]=='@')) hand[i]='?'; if (strlen(hand)<1) x=0; else if (is_user(hand)) x=0; if (hand[0]=='*') x=0; if (x) { x=change_handle(argv[1],hand); if (x) { notes_change(-1,argv[1],hand); for (i=0; ichannel>=0)) { chanout2(dcc[i].u.chat->channel,"Nick change: %s -> %s\n",s,hand); tandout("part %s %s\n",origbotname,s); tandout("join %s %s %d %c %s\n",origbotname,s, dcc[i].u.chat->channel,geticon(i),dcc[i].host); } } } } } sprintf(hand,"%d",x); Tcl_AppendResult(irp,hand,NULL); return TCL_OK; } int tcl_getting_users STDVAR { int i; BADARGS(1,1,""); for (i=0; istatus&STAT_GETTING)) { Tcl_AppendResult(irp,"1",NULL); return TCL_OK; } } Tcl_AppendResult(irp,"0",NULL); return TCL_OK; } int tcl_addignore STDVAR { BADARGS(2,2," nick!user@host"); warn_obsolete(argv[0]); addignore(argv[1],origbotname,"",time(NULL)+(60*ignore_time)); return TCL_OK; } int tcl_addpermignore STDVAR { BADARGS(2,2," nick!user@host"); warn_obsolete(argv[0]); addignore(argv[1],origbotname,"",0L); return TCL_OK; } int tcl_delignore STDVAR { int x; BADARGS(2,2," nick!user@host"); warn_obsolete(argv[0]); x=delignore(argv[1]); if (x) Tcl_AppendResult(irp,"1",NULL); else Tcl_AppendResult(irp,"0",NULL); return TCL_OK; } int tcl_isignore STDVAR { int x; BADARGS(2,2," nick!user@host"); x=match_ignore(argv[1]); if (x) Tcl_AppendResult(irp,"1",NULL); else Tcl_AppendResult(irp,"0",NULL); return TCL_OK; } int tcl_newignore STDVAR { time_t now=time(NULL),expire_time; char ign[UHOSTLEN],cmt[66],from[10]; BADARGS(4,5," hostmask creator comment ?lifetime?"); strncpy(ign,argv[1],UHOSTLEN-1); ign[UHOSTLEN-1]=0; strncpy(from,argv[2],9); from[9]=0; strncpy(cmt,argv[3],65); cmt[65]=0; if (argc==4) expire_time=now+(60*ignore_time); else { if (atol(argv[4])==0) expire_time=0L; else expire_time=now+(60*atol(argv[4])); } addignore(ign,from,cmt,expire_time); return TCL_OK; } int tcl_killignore STDVAR { int x; BADARGS(2,2," hostmask"); x=delignore(argv[1]); if (x) Tcl_AppendResult(irp,"1",NULL); else Tcl_AppendResult(irp,"0",NULL); return TCL_OK; } /* { hostmask note expire-time create-time creator } */ int tcl_ignorelist STDVAR { struct userrec *u; struct eggqueue *q; time_t t; char s[256],host[UHOSTLEN],ts[21],ts1[21],from[81],*list[5],*p; context; BADARGS(1,1,""); u=get_user_by_handle(userlist,IGNORE_NAME); if (u==NULL) return TCL_OK; q=u->host; while ((q!=NULL) && (strcmp(q->item,"none")!=0)) { strcpy(s,q->item); splitc(host,s,':'); splitc(ts,s,':'); if (ts[0]=='+') { /* new-style expiration */ strcpy(ts,&ts[1]); } else { /* old-style (convert) */ t=(time_t)atol(ts); if (t!=0L) t+=(60*ignore_time); sprintf(ts,"%lu",t); } splitc(from,s,':'); if (!from[0]) { /* very old */ strcpy(from,s); s[0]=0; strcpy(ts1,"0"); } else splitc(ts1,s,':'); if (s[0]) { /* decode gibberish stuff */ p=strchr(s,'~'); while (p!=NULL) { *p=' '; p=strchr(s,'~'); } p=strchr(s,'`'); while (p!=NULL) { *p=','; p=strchr(s,'`'); } } list[0]=host; list[1]=s; list[2]=ts; list[3]=ts1; list[4]=from; p=Tcl_Merge(5,list); Tcl_AppendElement(irp,p); n_free(p,"",0); q=q->next; } return TCL_OK; }