/* deal with msgs from people */ #if HAVE_CONFIG_H #include #endif #include #include #include #ifdef TCL #include "../lush.h" #endif #include "eggdrop.h" #include "hash.h" #include "proto.h" extern struct dcc_t dcc[]; extern int dcc_total; extern int serv; extern char cx_file[]; extern int cx_line; /* new hashing function */ void gotcmd(nick,from,msg) char *nick,*from,*msg; { char code[512],hand[41],s[121],total[512]; int i,f,x,ok,ans,cnt,atr; context; sprintf(s,"%s!%s",nick,from); strcpy(total,msg); rmspace(msg); nsplit(code,msg); get_handle_by_host(hand,s); rmspace(msg); #ifdef TCL if (check_tcl_msg(code,nick,from,hand,msg)) return; check_tcl_msgm(code,nick,from,hand,msg); log(LOG_MSGS,"[%s!%s] %s",nick,from,total); #else cnt=0; ok=0; ans=(-1); f=0; atr=get_attr_handle(hand); i=0; while ((C_msg[i].access != -1) && (!f)) { if (strncasecmp(code,C_msg[i].name,strlen(code))==0) { /* found a match */ x=C_msg[i].access; ok=1; if (x&NEED_PARTY) if (!(atr & USER_PARTY)) ok=0; if (x&NEED_XFER) if (!(atr & USER_XFER)) ok=0; if (x&NEED_OP) if (!(atr & USER_OP)) ok=0; if (x&NEED_MASTER) if (!(atr & USER_MASTER)) ok=0; if (atr & USER_MASTER) ok=1; if (x&NEED_OWNER) if (!(atr & USER_OWNER)) ok=0; if (ok) { ans=i; cnt++; x=strcasecmp(code,C_msg[i].name); if (x==0) { /* perfect match: this is the one */ f=1; cnt=1; } } } i++; } if ((ans>=0) && (cnt==1)) { ok=(C_msg[ans].func)(hand,nick,from,msg); if (!ok) ans=(-1); } if (ans<0) log(LOG_MSGS,"[%s!%s] %s",nick,from,total); #endif } /* for dcc commands -- hash the function */ int got_dcc_cmd(idx,z,msg) int idx,z; char *msg; { char total[512],code[512]; int i,f,x,ok,ans,cnt,atr; context; strcpy(total,msg); rmspace(msg); nsplit(code,msg); rmspace(msg); #ifdef TCL return check_tcl_dcc(code,idx,msg); #else cnt=0; ok=0; ans=(-1); f=0; i=0; while ((C_dcc[i].access != -1) && (!f)) { if (strncasecmp(code,C_dcc[i].name,strlen(code))==0) { /* found a match */ x=C_dcc[i].access; ok=1; atr=get_attr_handle(dcc[idx].nick); if (x&NEED_PARTY) if (!(atr & USER_PARTY)) ok=0; if (x&NEED_XFER) if (!(atr & USER_XFER)) ok=0; if (x&NEED_OP) if (!(atr & USER_OP)) ok=0; if (x&NEED_MASTER) if (!(atr & USER_MASTER)) ok=0; if (atr & USER_MASTER) ok=1; if (x&NEED_OWNER) if (!(atr & USER_OWNER)) ok=0; if (ok) { ans=i; cnt++; x=strcasecmp(code,C_dcc[i].name); if (x==0) { /* perfect match: this is the one */ f=1; cnt=1; } } } i++; } if ((ans>=0) && (cnt==1)) { if (C_dcc[ans].func == CMD_LEAVE) return 1; (C_dcc[ans].func)(idx,z,msg); return 0; } if (ans<0) tprintf(z,"What? Try '.help'\n"); if (cnt>1) tprintf(z,"Ambigious command.\n"); return 0; #endif } /* hash function for file area commands */ int got_files_cmd(idx,z,msg) int idx,z; char *msg; { char total[512],code[512]; int i,f,x,ok,ans,cnt,atr; context; if (msg[0]=='.') strcpy(msg,&msg[1]); strcpy(total,msg); rmspace(msg); nsplit(code,msg); rmspace(msg); #ifdef TCL return check_tcl_fil(code,idx,msg); #else ans=(-1); cnt=0; f=0; i=0; while ((C_file[i].access != -1) && (!f)) { if (strncasecmp(code,C_file[i].name,strlen(code))==0) { /* found a match */ x=C_file[i].access; ok=1; atr=get_attr_handle(dcc[idx].nick); if (x&NEED_PARTY) if (!(atr & USER_PARTY)) ok=0; if (x&NEED_XFER) if (!(atr & USER_XFER)) ok=0; if (x&NEED_OP) if (!(atr & USER_OP)) ok=0; if (x&NEED_MASTER) if (!(atr & USER_MASTER)) ok=0; if (atr & USER_MASTER) ok=1; if (x&NEED_OWNER) if (!(atr & USER_OWNER)) ok=0; if (ok) { ans=i; cnt++; x=strcasecmp(code,C_file[i].name); if (x==0) { /* perfect match: this is the one */ f=1; cnt=1; } } } i++; } if ((ans>=0) && (cnt==1)) { if (C_file[ans].func == CMD_LEAVE) return 1; (C_file[ans].func)(idx,z,msg); return 0; } if (ans<0) tprintf(z,"What? Try '.help'\n"); if (cnt>1) tprintf(z,"Ambigious command.\n"); return 0; #endif } /* hash function for tandem bot commands */ int got_tandem(idx,z,msg) int idx,z; char *msg; { char total[512],code[512]; int i,f,x; context; strcpy(total,msg); nsplit(code,msg); f=0; i=0; while ((C_tand[i].access != -1) && (!f)) { if (strcasecmp(code,C_tand[i].name)==0) { /* found a match */ (C_tand[i].func)(idx,z,msg); f=1; } i++; } if (!f) log(LOG_MISC,"Unknown tandem cmd: [%s] %s",dcc[idx].nick,total); return 0; } #ifdef TCL void *tclcmd_alloc(); extern Tcl_HashTable H_msg, H_dcc, H_fil; extern int hashtot; typedef struct { int flags_needed; char *func_name; } tcl_cmd_t; /* TCL bots use the TCL hash table for dcc and msg commands, so gotta */ /* copy the default hash tables into the TCL one */ void init_builtins() { int i,j,flags,new; Tcl_HashTable *ht; Tcl_HashEntry *he; tcl_cmd_t *tt; cmd_t *cc; for (j=0; j<3; j++) { switch(j) { case 0: ht=&H_msg; cc=C_msg; break; case 1: ht=&H_dcc; cc=C_dcc; break; case 2: ht=&H_fil; cc=C_file; break; } i=0; while (cc[i].access != (-1)) { flags=0; if (cc[i].access & NEED_PARTY) flags|=USER_PARTY; if (cc[i].access & NEED_XFER) flags|=USER_XFER; if (cc[i].access & NEED_OP) flags|=USER_OP; if (cc[i].access & NEED_MASTER) flags|=USER_MASTER; if (cc[i].access & NEED_OWNER) flags|=USER_OWNER; tt=(tcl_cmd_t *)tclcmd_alloc(strlen(cc[i].name)+2); tt->flags_needed=flags; strcpy(tt->func_name,"*"); strcat(tt->func_name,cc[i].name); he=Tcl_CreateHashEntry(ht,cc[i].name,&new); if (!new) { /* remove old entry */ tcl_cmd_t *ttx=(tcl_cmd_t *)Tcl_GetHashValue(he); Tcl_DeleteHashEntry(he); hashtot-=(strlen(ttx->func_name)+1); hashtot-=sizeof(tcl_cmd_t); nfree(ttx->func_name); nfree(ttx); he=Tcl_CreateHashEntry(ht,cc[i].name,&new); } Tcl_SetHashValue(he,tt); i++; } } } #endif