/* responses to message commands from people */ /* hash.c points here */ #include #include #include #ifdef AIX #include #endif #include "eggdrop.h" /* let unknown users greet us and become known */ int learn_users=0; /* new server? */ char newserver[121]; /* new server port? */ int newserverport=0; /* refuse access to non-masters who don't have 'x' flag? */ int require_x=0; /* enable the info subsystem? */ int use_info=1; /* person to send a note to for new users */ char notify_new[121]=""; /* default user flags for people who say 'hello' */ int default_flags=0; extern int serv; extern char botname[]; extern int use_info; extern char origbotname[]; extern char helpdir[]; extern int helpsock; extern char curchan[]; extern char helpbot[]; extern int periodic_save; int msg_hello(n,nick,h,p) char *n,*nick,*h,*p; { char host[120],s[120],s1[120]; char *p1; if (!learn_users) return 0; if (n[0]=='*') { if (is_user(nick)) { showhelp(nick,"badhost",0,0); } else{ sprintf(s,"%s!%s",nick,h); maskhost(s,host); adduser(nick,host,"nopass",default_flags); log(LOG_MISC,"Introduced to %s (%s)",nick,host); if (helpbot[0]) hprintf(helpsock,"NOTICE %s :Hi %s! I'm %s, the helpbot for %s.\n", nick,nick,helpbot,botname); else hprintf(helpsock,"NOTICE %s :Hi %s! I'm %s, an eggdrop bot.\n",nick, nick,botname); hprintf(helpsock,"NOTICE %s :I'll recognize you by hostmask '%s'%s\n", nick,host," from now on."); showhelp(nick,"intro",0,0); if (notify_new[0]) { sprintf(s,"Introduced to %s from %s",nick,host); strcpy(s1,notify_new); while (s1[0]) { p1=strchr(s1,','); if (p1!=NULL) { *p1=0; p1++; rmspace(p1); } rmspace(s1); add_note(s1,origbotname,s,-1); if (p1==NULL) s1[0]=0; else strcpy(s1,p1); } } } } else mprintf(serv,"NOTICE %s :Hi, %s.\n",nick,n); return 1; } int msg_pass(hand,nick,host,par) char *hand,*nick,*host,*par; { char old[120]; split(old,par); if (!is_user(hand)) { mprintf(serv,"NOTICE %s :I don't know you.\n",nick); return 1; } if (!par[0]) { mprintf(serv,"NOTICE %s :You %s a password set.\n",nick, pass_match_by_handle("nopass",hand)?"don't have":"have"); log(LOG_CMDS,"(%s!%s) !%s! PASS?",nick,host,hand); return 1; } if ((!pass_match_by_handle("nopass",hand)) && (!old[0])) { mprintf(serv,"NOTICE %s :You already have a password set.\n",nick); return 1; } if (!old[0]) { log(LOG_CMDS,"(%s!%s) !%s! PASS...",nick,host,hand); if (strlen(par)>9) par[9]=0; change_pass_by_handle(hand,par); mprintf(serv,"NOTICE %s :Password set to '%s'\n",nick,par); return 1; } if (!pass_match_by_handle(old,hand)) { mprintf(serv,"NOTICE %s :Incorrect password.\n",hand); return 1; } log(LOG_CMDS,"(%s!%s) !%s! PASS...",nick,host,hand); if (strlen(par)>9) par[9]=0; change_pass_by_handle(hand,par); mprintf(serv,"NOTICE %s :Password changed to '%s'.\n",nick,par); return 1; } int msg_ident(hand,nick,host,par) char *hand,*nick,*host,*par; { char s[121],s1[121]; if (!is_user(nick)) { mprintf(serv,"NOTICE %s :I don't know you.\n",nick); return 1; } if (pass_match_by_handle("nopass",nick)) { mprintf(serv,"NOTICE %s :You have no password set.\n",nick); return 1; } if (!pass_match_by_handle(par,nick)) { mprintf(serv,"NOTICE %s :Access denied.\n",nick); return 1; } if (strcasecmp(hand,nick)==0) { mprintf(serv,"NOTICE %s :I recognize you there.\n",nick); return 1; } if (strcasecmp(hand,"*")!=0) { mprintf(serv,"NOTICE %s :Wrong nickname.\n",nick); return 1; } log(LOG_CMDS,"(%s!%s) !%s! IDENT",nick,host,nick); sprintf(s,"%s!%s",nick,host); maskhost(s,s1); mprintf(serv,"NOTICE %s :Added hostmask: %s\n",nick,s1); addhost_by_handle(nick,s1); return 1; } int msg_email(hand,nick,host,par) char *hand,*nick,*host,*par; { char s[161]; if (strcasecmp(hand,"*")==0) { mprintf(serv,"NOTICE %s :I don't know who you are.\n",nick); return 1; } if (par[0]) { get_handle_email(hand,s); if (strcasecmp(par,"none")==0) { log(LOG_CMDS,"(%s!%s) !%s! EMAIL NONE",nick,host,hand); par[0]=0; set_handle_email(hand,par); mprintf(serv,"NOTICE %s :Removed your email address.\n",nick); } else { log(LOG_CMDS,"(%s!%s) !%s! EMAIL...",nick,host,hand); set_handle_email(hand,par); mprintf(serv,"NOTICE %s :Now: %s\n",nick,par); } return 1; } log(LOG_CMDS,"(%s!%s) !%s! EMAIL?",nick,host,hand); get_handle_email(hand,s); if (s[0]) { mprintf(serv,"NOTICE %s :Currently: %s\n",nick,s); mprintf(serv,"NOTICE %s :To remove it: /msg %s email none\n",nick,botname); } else mprintf(serv,"NOTICE %s :You have no email address set.\n",nick); return 1; } int msg_info(hand,nick,host,par) char *hand,*nick,*host,*par; { char s[121]; if (strcasecmp(hand,"*")==0) { mprintf(serv,"NOTICE %s :I don't know who you are.\n",nick); return 1; } if (!use_info) { mprintf(serv,"NOTICE %s :Info is currently disabled.\n",nick); return 1; } if (par[0]) { get_handle_info(hand,s); if (s[0]=='@') mprintf(serv,"NOTICE %s :Your info line is locked.\n",nick); else if (strcasecmp(par,"none")==0) { log(LOG_CMDS,"(%s!%s) !%s! INFO NONE",nick,host,hand); par[0]=0; set_handle_info(hand,par); mprintf(serv,"NOTICE %s :Removed your info line.\n",nick); } else { log(LOG_CMDS,"(%s!%s) !%s! INFO...",nick,host,hand); if (par[0]=='@') strcpy(par,&par[1]); set_handle_info(hand,par); mprintf(serv,"NOTICE %s :Now: %s\n",nick,par); } return 1; } log(LOG_CMDS,"(%s!%s) !%s! INFO?",nick,host,hand); get_handle_info(hand,s); if (s[0]) { mprintf(serv,"NOTICE %s :Currently: %s\n",nick,s); mprintf(serv,"NOTICE %s :To remove it: /msg %s info none\n",nick,botname); } else mprintf(serv,"NOTICE %s :You have no info set.\n",nick); return 1; } int msg_who(hand,nick,host,par) char *hand,*nick,*host,*par; { if (strcasecmp(hand,"*")==0) return 0; if (!use_info) { mprintf(serv,"NOTICE %s :Info is disabled.\n",nick); return 1; } log(LOG_CMDS,"(%s!%s) !%s! WHO",nick,host,hand); show_all_info(nick); return 1; } int msg_whois(hand,nick,host,par) char *hand,*nick,*host,*par; { time_t tt; char s[81],s1[81]; if (strcasecmp(hand,"*")==0) return 0; log(LOG_CMDS,"(%s!%s) !%s! WHOIS %s",nick,host,hand,par); get_handle_info(par,s); get_handle_laston(par,&tt); if (s[0]=='@') strcpy(s,&s[1]); if (s[0]) hprintf(helpsock,"NOTICE %s :[%s] %s\n",nick,par,s); get_handle_email(par,s); if (s[0]) hprintf(helpsock,"NOTICE %s :[%s] email: %s\n",nick,par,s); if (on_chan(par)) sprintf(s1,"NOTICE %s :[%s] On %s now.",nick,par,curchan); else if (tt) { strcpy(s,ctime(&tt)); strcpy(s,&s[4]); s[12]=0; sprintf(s1,"NOTICE %s :[%s] Last seen %s",nick,par,s); } else sprintf(s1,"NOTICE %s :[%s] No user record.",nick,par); if (match_attr_handle(par,USER_OP)) strcat(s1," (is an op)"); if (match_attr_handle(par,USER_TANDEM)) strcat(s1," (is a bot)"); hprintf(helpsock,"%s\n",s1); } int msg_help(hand,nick,host,par) char *hand,*nick,*host,*par; { int i; char s[121]; sprintf(s,"%s!%s",nick,host); if (strcasecmp(hand,"*")==0) { if (learn_users) { hprintf(helpsock,"NOTICE %s :'/msg %s hello' to introduce yourself.\n", nick,botname); return 1; } else return 0; } if (helpdir[0]) { if (!par[0]) showhelp(nick,"help",match_op(s),match_master(s)); else { for (i=0; i='A') && (par[i]<='Z')) par[i]+=('a'-'A'); showhelp(nick,par,match_op(s),match_master(s)); } } else hprintf(helpsock,"NOTICE %s :No help.\n",nick); return 1; } int msg_op(hand,nick,host,par) char *hand,*nick,*host,*par; { if (pass_match_by_handle(par,hand)) { add_mode('+','o',nick); log(LOG_CMDS,"(%s!%s) !%s! OP",nick,host,hand); return 1; } log(LOG_CMDS,"(%s!%s) !%s! failed OP",nick,host,hand); return 1; } int msg_invite(hand,nick,host,par) char *hand,*nick,*host,*par; { if (pass_match_by_handle(par,hand)) { mprintf(serv,"INVITE %s %s\n",nick,curchan); log(LOG_CMDS,"(%s!%s) !%s! INVITE",nick,host,hand); return 1; } log(LOG_CMDS,"(%s!%s) !%s! failed INVITE",nick,host,hand); return 1; } int msg_status(hand,nick,host,par) char *hand,*nick,*host,*par; { log(LOG_CMDS,"(%s!%s) !%s! STATUS",nick,host,hand); tell_chan_info(nick); return 1; } int msg_memory(hand,nick,host,par) char *hand,*nick,*host,*par; { log(LOG_CMDS,"(%s!%s) !%s! MEMORY",nick,host,hand); tell_mem_status(nick); return 1; } int msg_die(hand,nick,host,par) char *hand,*nick,*host,*par; { char s[121]; if (pass_match_by_handle(par,hand)) { log(LOG_CMDS,"(%s!%s) !%s! DIE",nick,host,hand); tprintf(serv,"NOTICE %s :Dying.\n",nick); chatout("*** BOT SHUTDOWN (authorized by %s)\n",hand); tandout("chat %s BOT SHUTDOWN (authorized by %s)\n",origbotname,hand); tandout("bye\n"); tprintf(serv,"QUIT :Dead by request of %s\n",nick); if (periodic_save) write_userfile(); sleep(1); /* give the server time to understand */ sprintf(s,"DEAD BY REQUEST OF %s!%s",nick,host); fatal(s,0); } log(LOG_CMDS,"(%s!%s) !%s! failed DIE",nick,host,hand); return 1; } int msg_rehash(hand,nick,host,par) char *hand,*nick,*host,*par; { if (pass_match_by_handle(par,hand)) { log(LOG_CMDS,"(%s!%s) !%s! REHASH",nick,host,hand); mprintf(serv,"NOTICE %s :Rehashing...\n",nick); rehash(); return 1; } log(LOG_CMDS,"(%s!%s) !%s! failed REHASH",nick,host,hand); return 1; } int msg_reset(hand,nick,host,par) char *hand,*nick,*host,*par; { log(LOG_CMDS,"(%s!%s) !%s! RESET",nick,host,hand); mprintf(serv,"NOTICE %s :Resetting channel info...\n",nick); reset_chan_info(); return 1; } int msg_jump(hand,nick,host,par) char *hand,*nick,*host,*par; { char s[181]; if (par[0]) { nsplit(s,par); if (!par[0]) strcpy(par,"6667"); log(LOG_CMDS,"(%s!%s) !%s! JUMP %s %s",nick,host,hand,s,par); strcpy(newserver,s); newserverport=atoi(par); } else log(LOG_CMDS,"(%s!%s) !%s! JUMP",nick,host,hand); mprintf(serv,"NOTICE %s :Jumping servers...\n",nick); mprintf(serv,"QUIT :jumping servers\n"); }