/* commands.c ** The socket's core of this code has been made by wildthang ** . You can modify it but not distribute it ** modified. This file is part of MudBot and is (C) 1997 by Drow ** all rights reserved. */ #include #include #include #include #include #include #include #include #include #include #include #include "vars.h" #include "config.h" #ifdef POSIX #include #include #endif FILE *fpalias; int do_check_command(sck,fromhost,k) int sck; char *fromhost; int k; { int level = 0; int secure = 0; int ismaster; FILE *fpa; char temp[512]=""; #ifdef INTER_WEB if(global_write_html==1) { strcpy(temp,HTMLDIR); strcat(temp,"/command.results"); if((fpa=fopen(temp,"w"))!=NULL) fputs("",fpa); if(fpa!=NULL) fclose(fpa); } #endif if(k!=(-775)) token[3]++; fpa=fopen("stats.file","a"); fputs("C\n",fpa); if(fpa!=NULL) fclose(fpa); level = chklevel(fromhost,k); #ifdef REPORTS #ifdef REPORT_COMMANDS sprintf(buf,"PRIVMSG %s :[%s] From %s[%s] Level %d\n",REPORTS,token[3],token[0],fromhost,level); writeln(sck,buf); #endif #endif #ifdef LOGFILE_CMD if(cas_cmp(token[3],"validate")) { if(cas_cmp(token[3],"unvalidate")) { writelog(fromhost,2); } } #endif if (level > -1) /* level 0 */ { if (!cas_cmp(token[3],"up")) do_up(sck); #ifdef BAR else if(!cas_cmp(token[3],"tip")) bar_tip(sck); else if(!cas_cmp(token[3],"drink")) bar_drink(sck); else if(!cas_cmp(token[3],"beer")) bar_beer(sck); else if(!cas_cmp(token[3],"fortune")) do_fortune(sck); else if(!cas_cmp(token[3],"country")) do_country(sck); else if(!cas_cmp(token[3],"ircaddict")) do_ircaddict(sck); else if(!cas_cmp(token[3],"dice")) do_dice(sck); else if(!cas_cmp(token[3],"dns")) do_dns(sck); else if(!cas_cmp(token[3],"uwhois")) do_uwhois(sck); else if(!cas_cmp(token[3],"uping")) do_uping(sck); else if(!cas_cmp(token[3],"unixtime")) do_unixtime(sck); else if(!cas_cmp(token[3],"listnames")) do_rep(sck); else if(!cas_cmp(token[3],"sv")) do_sv(sck); #endif #ifdef CHANSERV else if(!cas_cmp(token[3],"chanserv")) chanserv(sck,level,fromhost); #endif else if(!cas_cmp(token[3],"vote")) do_vote(sck, fromhost); #ifdef NICKSERV else if(!cas_cmp(token[3],"regnick")) do_regnick(sck); else if(!cas_cmp(token[3],"enforce")) do_enfnick(sck, fromhost); #endif #ifndef QUIET else if(!cas_cmp(token[3],"botauth")) do_botauth(sck); #endif #ifdef SERVICE else if(!cas_cmp(token[3],"operhelp")) do_operhelp(sck,level); #endif else if(!cas_cmp(token[3],"validate")) { do_validate(sck); return; } #ifdef SPY do_spy(sck); #endif } if(level > 0) /* level 1 */ { if(!cas_cmp(token[3],"info")) do_hi(sck); #ifndef QUIET else if(!cas_cmp(token[3],"update")) do_update(sck); else if(!cas_cmp(token[3],"help")) do_help(sck, level); #endif else if(!cas_cmp(token[3],"unvalidate")) do_unvalidate(sck); else if(!cas_cmp(token[3],"news")) do_news(sck); else if(!cas_cmp(token[3],"tell")) do_tell(sck, fromhost); else if(!cas_cmp(token[3],"readmsg")) chk_msgs(sck); else if(!cas_cmp(token[3],"finger")) do_finger(sck); else if(!cas_cmp(token[3],"clearmsg")) clr_msgs(sck); else if(!cas_cmp(token[3],"description")) do_descript(sck); /* else if(!cas_cmp(token[3],"getemail")) do_getemail(sck); */ else if(!cas_cmp(token[3],"kiss")) do_kiss(sck); else if(!cas_cmp(token[3],"access")) do_access(sck); else if(!cas_cmp(token[3],"seen")) do_seen(sck); else if(!cas_cmp(token[3],"newpass")) do_newpass(sck, level); else if(!cas_cmp(token[3],"voteresults")) do_voteresults(sck); else if(!cas_cmp(token[3],"whoami")) do_whoami(sck, level, fromhost); #ifndef BAR else if(!cas_cmp(token[3],"tip")) bar_tip(sck); else if(!cas_cmp(token[3],"drink")) bar_drink(sck); else if(!cas_cmp(token[3],"beer")) bar_beer(sck); else if(!cas_cmp(token[3],"fortune")) do_fortune(sck); else if(!cas_cmp(token[3],"country")) do_country(sck); else if(!cas_cmp(token[3],"ircaddict")) do_ircaddict(sck); else if(!cas_cmp(token[3],"dice")) do_dice(sck); else if(!cas_cmp(token[3],"dns")) do_dns(sck); else if(!cas_cmp(token[3],"uwhois")) do_uwhois(sck); else if(!cas_cmp(token[3],"uping")) do_uping(sck); else if(!cas_cmp(token[3],"unixtime")) do_unixtime(sck); else if(!cas_cmp(token[3],"listnames")) do_rep(sck); else if(!cas_cmp(token[3],"sv")) do_sv(sck); #endif } if (level > 1) /* level 2 */ { if(!cas_cmp(token[3],"uptime")) do_uptime(sck); else if(!cas_cmp(token[3],"topic")) do_topic(sck); else if(!cas_cmp(token[3],"away")) do_away(sck); else if(!cas_cmp(token[3],"invite")) do_invite(sck); else if(!cas_cmp(token[3],"stats")) do_stats(sck); else if(!cas_cmp(token[3],"insult")) do_insult(sck); } if(level > 2) /* level 3 */ { if(!cas_cmp(token[3],"kick")) do_kick(sck); else if(!cas_cmp(token[3],"ban")) do_ban(sck); else if(!cas_cmp(token[3],"unban")) do_unban(sck); else if(!cas_cmp(token[3],"voice")) do_voice(sck); else if(!cas_cmp(token[3],"unvoice")) do_unvoice(sck); else if(!cas_cmp(token[3],"kb")) do_kb(sck); else if(!cas_cmp(token[3],"teaseop")) do_tease(sck); } if (level > 3) /* level 4 */ { if(!cas_cmp(token[3],"op")) do_op(sck); else if(!cas_cmp(token[3],"deop")) do_deop(sck); else if(!cas_cmp(token[3],"msg")) do_msg(sck); else if(!cas_cmp(token[3],"status")) do_status(sck, level); else if(!cas_cmp(token[3],"updatehtml")) do_updatehtml(sck); else if(!cas_cmp(token[3],"addtimer")) do_addtimer(sck); else if(!cas_cmp(token[3],"deltimer")) do_deltimer(sck); else if(!cas_cmp(token[3],"showtimers")) do_showtimers(sck); } if (level > 4) /* level 5 */ { if(!cas_cmp(token[3],"mode")) do_mode(sck); else if(!cas_cmp(token[3],"xauth")) do_xauth(sck); else if(!cas_cmp(token[3],"wauth")) do_wauth(sck); else if(!cas_cmp(token[3],"xkick")) do_xkick(sck); else if(!cas_cmp(token[3],"wkick")) do_wkick(sck); else if(!cas_cmp(token[3],"system")) do_system(sck); else if(!cas_cmp(token[3],"netblock")) do_netblock(sck); } if (level > 5) /* level 6 */ { if(!cas_cmp(token[3],"join")) do_join(sck); else if(!cas_cmp(token[3],"part")) do_part(sck); else if(!cas_cmp(token[3],"userlist")) do_userlist(sck); else if(!cas_cmp(token[3],"addlocal")) do_addlocal(sck); else if(!cas_cmp(token[3],"remlocal")) do_remlocal(sck); else if(!cas_cmp(token[3],"findlocal")) do_findlocal(sck); else if(!cas_cmp(token[3],"locallist")) do_locallist(sck); else if(!cas_cmp(token[3],"scan")) do_scan(sck); else if(!cas_cmp(token[3],"addscan")) do_addscan(sck); else if(!cas_cmp(token[3],"clearscan")) do_clearscan(sck); } if (level > 6) /* level 7 */ { if(!cas_cmp(token[3],"nick")) do_nick(sck); else if(!cas_cmp(token[3],"play")) do_play(sck); else if(!cas_cmp(token[3],"checkpopmail")) do_getpopmail(sck); else if(!cas_cmp(token[3],"cset")) do_cset(sck); else if(!cas_cmp(token[3],"readmail")) do_readmail(sck); else if(!cas_cmp(token[3],"jumpserv")) { if(token[5]==NULL || token[4]==NULL) { sprintf(buf,"NOTICE %s :Syntax: !jumpserv \n",token[0]); writeln(sck,buf); return 0; } #ifdef CHANSERV close(chansck); #endif #ifdef SERVICE close(servsck); #endif do_jump(sck,token[4],atoi(token[5])); } else if(!cas_cmp(token[3],"autoban")) do_addban(sck,fromhost); else if(!cas_cmp(token[3],"rautoban")) do_remban(sck); else if(!cas_cmp(token[3],"listautobans")) do_listautobans(sck); else if(!cas_cmp(token[3],"clearbans")) do_clearbans(sck); else if(!cas_cmp(token[3],"clearmodes")) do_clearmodes(sck); else if(!cas_cmp(token[3],"addsilence")) do_addsilence(sck); else if(!cas_cmp(token[3],"remsilence")) do_remsilence(sck); } if (level > 7) /* level 8 */ { if(!cas_cmp(token[3],"adduser")) do_adduser(sck, level); else if(!cas_cmp(token[3],"close")) do_close(sck); else if(!cas_cmp(token[3],"operkill")) do_kill(sck); else if(!cas_cmp(token[3],"operwall")) do_wallops(sck); else if(!cas_cmp(token[3],"operup")) do_operup(sck); else if(!cas_cmp(token[3],"operrehash")) do_oprehash(sck); else if(!cas_cmp(token[3],"masskill")) do_masskill(sck); else if(!cas_cmp(token[3],"rehash")) { sprintf(buf,"NOTICE %s :Rehashing config... Don't forget to revalidate\n",token[0]); writeln(sck,buf); loadusr(USERFILE); } #ifdef SERVICE if(service_off!=1) { if(!cas_cmp(token[3],"opcom")) do_opcom(sck); if(!cas_cmp(token[3],"serverstats")) do_operstats(sck); if(!cas_cmp(token[3],"gline")) do_gline(sck,1); if(!cas_cmp(token[3],"remgline")) do_gline(sck,0); if(!cas_cmp(token[3],"clearchan")) do_clearchan(sck); if(!cas_cmp(token[3],"lock")) do_lock(sck); if(!cas_cmp(token[3],"unlock")) do_unlock(sck); if(!cas_cmp(token[3],"operin")) do_operin(sck); if(!cas_cmp(token[3],"jupe")) do_jupe(sck); if(!cas_cmp(token[3],"jupenick")) do_jupenick(sck); if(!cas_cmp(token[3],"operjoin")) do_operjoin(sck); if(!cas_cmp(token[3],"operpart")) do_operpart(sck); if(!cas_cmp(token[3],"wibble")) do_wibble(sck); if(!cas_cmp(token[3],"killservice")) close(servsck); if(!cas_cmp(token[3],"makeoperserv")) { #ifdef IRCU_2_10 sprintf(buff,"NICK OperServ 1 1 OperServ %s %s :Oper Service\n",SERVICE_SERVER_NAME,SERVICE_SERVER_NAME); #else sprintf(buff,"NICK OperServ 1 1 OperServ %s :Oper Service\n",SERVICE_SERVER_NAME); #endif writeln(servsck,buff); sprintf(buff,":OperServ MODE OperServ +ko\n"); writeln(servsck,buff); } } #endif } if (level > 8) /* level 9 */ { if(!cas_cmp(token[3],"addchan")) do_addchan(sck); else if(!cas_cmp(token[3],"remchan")) do_remchan(sck); else if(!cas_cmp(token[3],"countmail")) do_countmail(sck,NULL); else if(!cas_cmp(token[3],"remuser")) do_remuser(sck); else if(!cas_cmp(token[3],"spy")) do_spyo(sck); else if(!cas_cmp(token[3],"showaliases")) do_sa(sck); else if(!cas_cmp(token[3],"stopspy")) do_stopspy(sck); #ifdef ALLOW_EXEC else if(!cas_cmp(token[3],"exec")) do_exec(sck); #endif #ifdef FTPMGR else if(!cas_cmp(token[3],"ftp")) ftpmgr(sck); #endif } if (level > 9) /* level 10 */ { if(!cas_cmp(token[3],"do")) do_scmd(sck); #ifdef ALLOW_EXIT else if(!cas_cmp(token[3],"exit")) c_exit(sck); #endif else if(!cas_cmp(token[3],"history")) do_history(sck); else if(!cas_cmp(token[3],"cryptpass")) { if(token[4]!=NULL) { sprintf(buf,"NOTICE %s :%s\n",token[0],do_cryptpass(token[4])); writeln(sck,buf); } } else if(!cas_cmp(token[3],"clearmess")) do_clearmess(sck); else if(!cas_cmp(token[3],"notepad")) do_notepad(sck); #ifdef SHARE_USERFILE else if(!cas_cmp(token[3],"leaf")) do_leaf(sck); else if(!cas_cmp(token[3],"share")) do_share(sck); #endif } } do_close(sck) int sck; { if(token[4] == NULL) { sprintf(buf,"NOTICE %s :Syntax: close \n",token[0]); writeln(sck,buf); return 0; } sprintf(buf,"MODE %s +mints-lpr\n",token[4]); writeln(sck,buf); sprintf(buf,"TOPIC %s :Closed channel.. Please be on your way\n",token[4]); writeln(sck,buf); } do_tease(sck) int sck; { if(token[4] == NULL || token[5] == NULL) { sprintf(buf,"NOTICE %s :Syntax: teaseop \n",token[0]); writeln(sck,buf); return 0; } if(!cas_cmp(token[5],BOTNAME)|| !cas_cmp(token[5],BOTSECNAME)) { sprintf(buf,"KICK %s %s :What? You wanna tease me??\n",token[4],token[0]); writeln(sck,buf); return 0; } sprintf(buf,"MODE %s +o-o %s %s\n",token[4],token[5],token[5]); writeln(sck,buf); } do_kiss(sck) int sck; { if(token[4] == NULL || token[5] == NULL) { sprintf(buf,"NOTICE %s :Syntax: kiss \n",token[0]); writeln(sck,buf); return 0; } sprintf(buf,"PRIVMSG %s :KIIIIIIIIIIIIIIIIIISS for %s from %s :) Are you free tonight?\n",token[4],token[5],token[0]); writeln(sck,buf); } do_descript(sck) int sck; { FILE *fp; char temp[512]; strcpy(temp,""); if(token[4] == NULL) { sprintf(buf,"NOTICE %s :Syntax: !description \n",token[0]); writeln(sck,buf); return 0; } fp = fopen("channels.file","r"); while(fgets(temp,255,fp) != NULL) { if(!cas_cmp(lindex(temp,0),token[4])) { sprintf(buf,"NOTICE %s :%s\n",token[0],temp); writeln(sck,buf); } } if(fp!=NULL) fclose(fp); } do_clearbans(sck) int sck; { if(token[4] == NULL) { sprintf(buf,"NOTICE %s :Syntax: !clearbans \n",token[0]); writeln(sck,buf); return 0; } sprintf(buf,"MODE %s +b\n",token[4]); writeln(sck,buf); sprintf(buf,"NOTICE %s :Trying to clear...\n",token[0]); writeln(sck,buf); } do_clearbans2(sck) int sck; { if(token[4] != NULL) { sprintf(buf,"MODE %s -b %s\n",token[3],token[4]); writeln(sck,buf); } } do_readmsg(sck) int sck; { FILE *fp; char temp[512]; strcpy(temp,""); fp = fopen("tell.file","r"); sprintf(buf,"NOTICE %s :-Content of tell.file-\n",token[0]); writeln(sck,buf); while(fgets(temp,255,fp) != NULL) { sprintf(buf,"NOTICE %s :- %s\n",token[0],temp); writeln(sck,buf); } sprintf(buf,"NOTICE %s :-End of tell.file-\n",token[0]); writeln(sck,buf); if(fp!=NULL) fclose(fp); } do_kb(sck) int sck; { char *s; char blah[255]="1"; FILE *fp; if (token[4] == NULL) { sprintf(buf,"NOTICE %s :Syntax: !kb \n",token[0]); writeln(sck,buf); return 0; } if(token[5]==NULL) strcpy(blah,token[2]); if(token[5]!=NULL) if(!cas_cmp(token[5],BOTNAME)) { sprintf(buf,"KICK %s %s :Trying to kick me hey?\n",token[4],token[0]); writeln(sck,buf); return 0; } if (!cas_cmp(token[4],BOTNAME)) { sprintf(buf,"KICK %s %s :What?? You think I'm LAME or something?!\n",token[4],token[0]); writeln(sck,buf); return 0; } if(token[5]!=NULL) if(!cas_cmp(token[5],BOTSECNAME)) { sprintf(buf,"KICK %s %s :Trying to kick me hey?\n",token[4],token[0]); writeln(sck,buf); return 0; } if(!cas_cmp(blah,"1")) sprintf(buf,"USERHOST %s\n",token[5]); else sprintf(buf,"USERHOST %s\n",token[4]); writeln(sck,buf); fp = fopen("tempo.temp","w"); if(!cas_cmp(blah,"1")) { fputs(token[4],fp); fputs(" ",fp); fputs(token[5],fp); } else { fputs(blah,fp); fputs(" ",fp); fputs(token[4],fp); } fputs(" dummy\n",fp); if(fp!=NULL) fclose(fp); sprintf(buf,"MODE %s -o %s\n",token[4],token[5]); writeln(sck,buf); } do_userhost(sck) int sck; { FILE *fp; char s2[255]=""; char s3[255]=""; int z=0,i,j; char temp[512]; strcpy(temp,""); if(!cas_cmp(token[3],":")) return 0; /*s2 = malloc(200);*/ strcpy(s2,token[3]); for(i=0;s2[i]!='@';i++) { } i++; j=i; if((fp=fopen("tempo.temp","r"))==NULL) return 0; fgets(temp,100,fp); for(i=i;s2[i]!=NULL;i++) { if(s2[i]=='0') s2[i]='?'; if(s2[i]=='1') s2[i]='?'; if(s2[i]=='2') s2[i]='?'; if(s2[i]=='3') s2[i]='?'; if(s2[i]=='4') s2[i]='?'; if(s2[i]=='5') s2[i]='?'; if(s2[i]=='6') s2[i]='?'; if(s2[i]=='7') s2[i]='?'; if(s2[i]=='8') s2[i]='?'; if(s2[i]=='9') s2[i]='?'; } for(j=j;s2[j]!=NULL;j++) { s3[z]=s2[j]; z++; } sprintf(buf,"MODE %s +b *!*@%s\n",lindex(temp,0),s3); writeln(sck,buf); sprintf(buf,"KICK %s %s :%s\n",lindex(temp,0),lindex(temp,1),KB_MSG); writeln(sck,buf); if(fp!=NULL) fclose(fp); } do_kill(sck) int sck; { #ifdef ALLOW_KILL char temp[255]; int i; if(token[4]==NULL) return 0; strcpy(temp,""); if(token[5]!=NULL) { for(i=5;token[i]!=NULL;i++) { strcat(temp," "); strcat(temp,token[i]); } } sprintf(buf,"KILL %s :Kill requested by %s (%s )\n",token[4],token[0],temp); writeln(sck,buf); #endif } do_oprehash(sck) int sck; { #ifdef OPER_CMDS sprintf(buf,"REHASH\n"); writeln(sck,buf); #endif } do_operup(sck) int sck; { if (token[4] == NULL || token[5] == NULL) return 0; #ifdef OPER_CMDS sprintf(buf,"OPER %s %s\n",token[4],token[5]); writeln(sck,buf); #endif } do_wallops(sck) int sck; { int i,j; char temp[512]; strcpy(temp,""); j=chk_num(0); if(token[4] == NULL) return 0; if (j>3) for(i=4;i\n",token[0]); writeln(sck,buf); return 0; } fp = fopen(LOCALFILE,"r"); while(fgets(temp,255,fp) != NULL) { i=0; while(lindex(temp,i)!=NULL) { if(!cas_cmp(lindex(temp,i),token[4])) { sprintf(buf,"NOTICE %s :Found match: %s\n",token[0],temp); writeln(sck,buf); } i++; } } if(fp!=NULL) fclose(fp); } do_addban(sck, fromhost) int sck; char *fromhost; { FILE *fp; int i,j; char temp[512]; char temp2[612]; strcpy(temp,""); j=chk_num(0); if(token[4]==NULL || token[5]==NULL || token[6]==NULL || atoi(token[5])<1) { sprintf(buf,"NOTICE %s :Syntax: !autoban