/* 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 n,i,f,x,ok,ans,cnt; cmd_t *c; context; sprintf(s,"%s!%s",nick,from); strcpy(total,msg); nsplit(code,msg); get_handle_by_host(hand,s); /* count total commands now */ n=0; while (C_msg[n].access != -1) n++; cnt=0; ans=-1; ok=0; f=0; n--; /* first and last possible entries */ while ((n>=f) && (!ok)) { i=((n-f)/2)+f; x=strncasecmp(code,C_msg[i].name,strlen(code)); if (x<0) n=i-1; else if (x>0) f=i+1; else { /* found a match */ x=C_msg[i].access; ok=1; if (x&NEED_PARTY) if (!match_party(s)) ok=0; if (x&NEED_XFER) if (!match_xfer(s)) ok=0; if (x&NEED_OP) if (!match_op(s)) ok=0; if (x&NEED_MASTER) if (!match_master(s)) ok=0; if (ok) { ans=i; cnt++; ok=0; x=strcasecmp(code,C_msg[i].name); if (x==0) { /* perfect match: this is the one */ ok=1; cnt=1; ans=i; f=n+1; /* stop here */ } else { n=0; while (C_msg[n].access != -1) n++; cnt=0; for (i=0; (i=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 n,i,f,x,ok,ans,cnt; cmd_t *c; context; strcpy(total,msg); nsplit(code,msg); 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; if (x&NEED_PARTY) if (!match_attr_handle(dcc[idx].nick,USER_PARTY)) ok=0; if (x&NEED_XFER) if (!(dcc[idx].u.chat->status&STAT_XFER)) ok=0; if (x&NEED_OP) if (!match_attr_handle(dcc[idx].nick,USER_OP)) ok=0; if (x&NEED_MASTER) if (!(dcc[idx].u.chat->status&STAT_MASTER)) 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 n,i,f,x,ok,ans,cnt; cmd_t *c; context; if (msg[0]=='.') strcpy(msg,&msg[1]); strcpy(total,msg); nsplit(code,msg); /* count total commands now */ n=0; while (C_file[n].access != -1) n++; ans=-1; cnt=0; ok=0; f=0; n--; /* first and last possible entries */ while ((n>=f) && (!ok)) { i=((n-f)/2)+f; x=strncasecmp(code,C_file[i].name,strlen(code)); if (x<0) n=i-1; else if (x>0) f=i+1; else { /* found a match */ x=C_file[i].access; ok=1; if (x&NEED_PARTY) if (!match_attr_handle(dcc[idx].nick,USER_PARTY)) ok=0; if (x&NEED_XFER) if (!(dcc[idx].u.file->chat->status&STAT_XFER)) ok=0; if (x&NEED_OP) if (!match_attr_handle(dcc[idx].nick,USER_OP)) ok=0; if (x&NEED_MASTER) if (!(dcc[idx].u.file->chat->status&STAT_MASTER)) ok=0; if (dcc[idx].u.chat->status&STAT_MASTER) ok=1; if (ok) { ans=i; cnt++; ok=0; x=strcasecmp(code,C_file[i].name); if (x==0) { /* perfect match: this is the one */ ok=1; cnt=1; ans=i; f=n+1; /* stop here */ } else { n=0; while (C_file[n].access != -1) n++; cnt=0; for (i=0; (i=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 n,i,f,x,ok; cmd_t *c; context; strcpy(total,msg); nsplit(code,msg); n=0; while (C_tand[n].access != -1) n++; ok=0; f=0; n--; while ((n>=f) && (!ok)) { i=((n-f)/2)+f; x=strcasecmp(code,C_tand[i].name); if (x<0) n=i-1; else if (x>0) f=i+1; else ok=1; } if (ok) (C_tand[i].func)(idx,z,msg); else log(LOG_MISC,"Unknown tandem cmd: [%s] %s",dcc[idx].nick,total); return 0; }