/* dcc shtuff */ #include #include #include #include #include #include "eggdrop.h" #define STDOUT 1 /* dcc list */ struct dcc_t dcc[MAXDCC]; /* total dcc's */ int dcc_total=0; /* root dcc directory */ char dccdir[121]=""; /* directory to put incoming dcc's into */ char dccin[121]=""; /* if non-zero, accept telnets at this port */ int telnet_port=0; /* file where the motd for dcc chat is stored */ char motdfile[121]="motd"; extern int serv; extern char botname[]; extern char version[]; unsigned long getmyip(); /* show motd to dcc chatter */ void show_motd(z) int z; { FILE *vv; char s[81]; vv=fopen(motdfile,"r"); if (vv!=NULL) { tprintf(z,"\n"); while (!feof(vv)) { fgets(s,80,vv); if (!feof(vv)) tprintf(z,"%s",s); } fclose(vv); tprintf(z,"\n"); } } void tell_who(z) int z; { int i,j; char s[121]; for (j=0; dcc[j].sock!=z; j++); tprintf(z,"Party line members: (* = master)\n"); for (i=0; i 3) { /* FLOOD */ tprintf(dcc[idx].sock,"*** FLOOD: Goodbye.\n"); for (i=0; i=dcc_total) { console("*** Receiving data from closed socket (flushing)"); return; } if (dcc[idx].type==DCC_CHAT_PASS) { if (pass_match_by_handle(buf,dcc[idx].nick)) { dcc[idx].type=DCC_CHAT; dcc_chatter(z); } else { tprintf(z,"Authentification failed.\n"); console("Bad password: DCC chat [%s]%s",dcc[idx].nick,dcc[idx].host); close(z); lostdcc(idx); } } else if (dcc[idx].type==DCC_EDIT) { cmd_edit(idx,z,buf); } else if (dcc[idx].type==DCC_CHAT) { if (!detect_dcc_flood(idx)) { if (dcc[idx].status&STAT_ECHO) tprintf(z,"%s\n",buf); if (buf[0]=='.') { if (got_dcc_cmd(idx,z,&buf[1])) { tprintf(z,"Thanks! Bye!\n"); console("DCC connection closed (%s!%s)",dcc[idx].nick,dcc[idx].host); for (i=0; i %s\n",dcc[idx].nick,buf); } } } else if (dcc[idx].type==DCC_FILES) { if (!detect_dcc_flood(idx)) { if (dcc[idx].status&STAT_ECHO) tprintf(z,"%s\n",buf); if (got_files_cmd(idx,z,buf)) { tprintf(z,"Thanks! Bye!\n"); console("DCC user [%s]%s left file system",dcc[idx].nick, dcc[idx].host); set_handle_dccdir(dcc[idx].nick,dcc[idx].param); if (dcc[idx].status&STAT_CHAT) { tprintf(z,"Returning you to command mode...\n"); if (dcc[idx].status&STAT_TALK) { tprintf(z,"/// PROMPT \n"); tprintf(z,"/// ECHO OFF\n"); } for (i=0; i dcc[idx].status) l=dcc[idx].status-dcc[idx].used; bf=(char *)nmalloc(l+1); fread(bf,l,1,f); write(dcc[idx].sock,bf,l); nfree(bf); dcc[idx].used+=l; } } } } else if (dcc[idx].type==DCC_TELNET) { i=dcc_total; if (i+1>MAXDCC) { j=answer(dcc[idx].sock,s); if (j!=-1) { tprintf(j,"Sorry, too many connections already.\n"); close(j); } } else { dcc[i].sock=answer(dcc[idx].sock,s); if (dcc[i].sock!=-1) { dcc[i].addr=0L; dcc[i].port=dcc[idx].port; sprintf(dcc[i].host,"telnet from %s",s); dcc[i].param[0]=0; dcc[i].type=DCC_TELNET_ID; dcc[i].used=time(NULL); dcc[i].status=STAT_CR; tprintf(dcc[i].sock,"\n\n%s (%s)\n\n",botname,version); tprintf(dcc[i].sock,"Identify yourself (nickname).\n"); dcc_total++; console("TELNET connection: %s",s); } else { neterror(s1); console("Failed TELNET connection %s (%s)",s,s1); close(dcc[idx].sock); /* start over listening - might help? */ dcc[idx].sock=open_listen(&telnet_port); } } } else if (dcc[idx].type==DCC_TELNET_ID) { if ((!match_attr_handle(buf,USER_MASTER)) && (!match_attr_handle(buf,USER_OP))) { tprintf(dcc[idx].sock,"You don't have access.\n"); console("Refused telnet from %s (invalid handle: %s)",dcc[idx].host,buf); close(dcc[idx].sock); lostdcc(idx); } else if (pass_match_by_handle("nopass",buf)) { tprintf(dcc[idx].sock,"Can't telnet until you have a password set.\n"); console("Refused telnet from [%s]%s (no password)",buf,dcc[idx].host); close(dcc[idx].sock); lostdcc(idx); } else { dcc[idx].type=DCC_CHAT_PASS; if (match_attr_handle(buf,USER_MASTER)) dcc[idx].status|=STAT_MASTER; strcpy(dcc[idx].nick,buf); tprintf(dcc[idx].sock,"\nEnter your password.\n"); console("Telnet -> DCC chat: [%s]%s",dcc[idx].nick,dcc[idx].host); } } } /* eof from dcc goes here from I/O... */ void eof_dcc(z) int z; { int idx,i; char s[121]; for (idx=0; dcc[idx].sock!=z; idx++); if ((dcc[idx].type==DCC_CHAT) || (dcc[idx].type==DCC_CHAT_PASS) || (dcc[idx].type==DCC_EDIT)) { dcc[idx].status&=~STAT_CONSOLE; /* don't try to send them this: */ console("Lost dcc connection to %s!%s/%d",dcc[idx].nick,dcc[idx].host, dcc[idx].port); if ((dcc[idx].type==DCC_CHAT) || (dcc[idx].type==DCC_EDIT)) for (i=0; i 300) { strcpy(xx,dcc[i].param); p=strrchr(xx,'/'); mprintf(serv,"NOTICE %s :Timeout on dcc send %s.\n",dcc[i].nick,p+1); console("DCC timeout: GET %s (%s!%s)",dcc[i].param,dcc[i].nick, dcc[i].host); close(dcc[i].sock); lostdcc(i); i--; } } else if (dcc[i].type==DCC_CHAT_PASS) { if (now-dcc[i].used > 180) { tprintf(dcc[i].sock,"Timeout.\n"); console("Password timeout on dcc chat: [%s]%s",dcc[i].nick, dcc[i].host); close(dcc[i].sock); lostdcc(i); i--; } } else if (dcc[i].type==DCC_TELNET_ID) { if (now-dcc[i].used > 180) { tprintf(dcc[i].sock,"Timeout.\n"); console("Ident timeout on telnet: %s",dcc[i].host); close(dcc[i].sock); lostdcc(i); i--; } } } }