/* deal with msgs from people */ #include #include #include #include "eggdrop.h" #include "hash.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); atr=get_attr_host(s); nsplit(code,msg); get_handle_by_host(hand,s); #ifdef TCL if (check_tcl_msg(code,nick,from,hand,msg)) return; if (check_tcl_msgm(code,nick,from,hand,msg)) return; #endif cnt=0; ok=0; ans=(-1); f=0; 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 (x&NEED_FLAG1) if (!(atr & USER_FLAG1)) ok=0; if (x&NEED_FLAG2) if (!(atr & USER_FLAG2)) ok=0; if (x&NEED_FLAG3) if (!(atr & USER_FLAG3)) 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); } /* 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); nsplit(code,msg); #ifdef TCL if (check_tcl_dcc(code,idx,msg)) return 0; #endif 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 (!(dcc[idx].u.chat->status&STAT_XFER)) ok=0; if (x&NEED_OP) if (!(atr & USER_OP)) ok=0; if (x&NEED_MASTER) if (!(dcc[idx].u.chat->status&STAT_MASTER)) ok=0; if (x&NEED_FLAG1) if (!(atr & USER_FLAG1)) ok=0; if (x&NEED_FLAG2) if (!(atr & USER_FLAG2)) ok=0; if (x&NEED_FLAG3) if (!(atr & USER_FLAG3)) ok=0; if (dcc[idx].u.chat->status&STAT_MASTER) ok=1; 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; } /* 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); nsplit(code,msg); #ifdef TCL if (check_tcl_fil(code,idx,msg)) return 0; #endif 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 (!(dcc[idx].u.file->chat->status&STAT_XFER)) ok=0; if (x&NEED_OP) if (!(atr & USER_OP)) ok=0; if (x&NEED_MASTER) if (!(dcc[idx].u.file->chat->status&STAT_MASTER)) ok=0; if (x&NEED_FLAG1) if (!(atr & USER_FLAG1)) ok=0; if (x&NEED_FLAG2) if (!(atr & USER_FLAG2)) ok=0; if (x&NEED_FLAG3) if (!(atr & USER_FLAG3)) ok=0; if (dcc[idx].u.chat->status&STAT_MASTER) ok=1; 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; } /* 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; }