void chat() { char str1[150],str2[256],ch; int i; aborted=0; if((ch=inkey(0))!=0 || wordwrap[0]) { if(ch=='/') { bputs("\1n\1y\1hCommand: \1n"); ch=getkeys("?LS|%\r",0); switch(ch) { case CR: return; #if DEBUG case '|': debug(); return; #endif case '%': if(!com_port) /* only if local */ exit(0); break; case '?': mnemonics("\r\n~List Players"); mnemonics("\r\n~Send Private Message to Player"); bputs("\r\n"); return; case 'L': listplayers(); bprintf(ShoeStatus,cur_card,total_decks*52); return; case 'S': listplayers(); bputs("\1n\r\n\1y\1hWhich node: \1n"); i=getnum(sys_nodes); getgamedat(0); if(i>0 && i!=node_num && node[i-1]) { bputs("\r\n\1n\1y\1hMessage: "); if(getstr(str1,50,K_LINE)) { sprintf(str2,UserWhispers,user_name ,str1); putnodemsg(str2,i); } } else bputs("\1n\r\n\1r\1hInvalid node.\1n\r\n"); return; } } ungetkey(ch); if(!getstr(str1,50,K_CHAT|K_WRAP)) return; sprintf(str2,UserSays,user_name,str1); putallnodemsg(str2); } getnodemsg(); }
int sbbs_t::viewfile(file_t* f, int ext) { char ch,str[256]; char tmp[512]; curdirnum=f->dir; /* for ARS */ while(online) { if(ext) fileinfo(f); else viewfilecontents(f); ASYNC; CRLF; sprintf(str,text[FileInfoPrompt],unpadfname(f->name,tmp)); mnemonics(str); ch=(char)getkeys("BEVQ\r",0); if(ch=='Q' || sys_status&SS_ABORT) return(0); switch(ch) { case 'B': addtobatdl(f); CRLF; return(-1); case 'E': ext=1; continue; case 'V': ext=0; continue; case CR: return(1); } } return(0); }
int sbbs_t::uselect(int add, uint n, const char *title, const char *item, const uchar *ar) { char str[128]; int i; uint t,u; if(uselect_total>=sizeof(uselect_num)/sizeof(uselect_num[0])) /* out of bounds */ uselect_total=0; if(add) { if(ar && !chk_ar(ar,&useron,&client)) return(0); if(!uselect_total) bprintf(text[SelectItemHdr],title); uselect_num[uselect_total++]=n; bprintf(text[SelectItemFmt],uselect_total,item); return(0); } if(!uselect_total) return(-1); for(u=0;u<uselect_total;u++) if(uselect_num[u]==n) break; if(u==uselect_total) u=0; sprintf(str,text[SelectItemWhich],u+1); mnemonics(str); i=getnum(uselect_total); t=uselect_total; uselect_total=0; if(i<0) return(-1); if(!i) { /* User hit ENTER, use default */ for(u=0;u<t;u++) if(uselect_num[u]==n) return(uselect_num[u]); if(n<t) return(uselect_num[n]); return(-1); } return(uselect_num[i-1]); }
bool sbbs_t::email(int usernumber, const char *top, const char *subj, long mode) { char str[256],str2[256],msgpath[256],title[LEN_TITLE+1],ch ,buf[SDT_BLOCK_LEN]; char tmp[512]; char pid[128]; char* editor=NULL; ushort msgattr=0; uint16_t xlat=XLAT_NONE; ushort nettype; int i,j,x,file; long l; long length; ulong offset; uint32_t crc=0xffffffffUL; FILE* instream; node_t node; smbmsg_t msg; SAFECOPY(title,subj); if(useron.etoday>=cfg.level_emailperday[useron.level] && !SYSOP && !(useron.exempt&FLAG('M'))) { bputs(text[TooManyEmailsToday]); return(false); } if(usernumber==1 && useron.rest&FLAG('S') && (cfg.node_valuser!=1 || useron.fbacks || useron.emails)) { /* ! val fback */ bprintf(text[R_Feedback],cfg.sys_op); return(false); } if(usernumber!=1 && useron.rest&FLAG('E') && (cfg.node_valuser!=usernumber || useron.fbacks || useron.emails)) { bputs(text[R_Email]); return(false); } if(!usernumber) { bputs(text[UnknownUser]); return(false); } getuserrec(&cfg,usernumber,U_MISC,8,str); l=ahtoul(str); if(l&(DELETED|INACTIVE)) { /* Deleted or Inactive User */ bputs(text[UnknownUser]); return(false); } if((l&NETMAIL) && (cfg.sys_misc&SM_FWDTONET)) { getuserrec(&cfg,usernumber,U_NETMAIL,LEN_NETMAIL,str); bprintf(text[UserNetMail],str); if((mode & WM_FORCEFWD) || text[ForwardMailQ][0]==0 || yesno(text[ForwardMailQ])) /* Forward to netmail address */ return(netmail(str,subj,mode)); } bprintf(text[Emailing],username(&cfg,usernumber,tmp),usernumber); action=NODE_SMAL; nodesync(); sprintf(str,"%sfeedback.*", cfg.exec_dir); if(usernumber==cfg.node_valuser && useron.fbacks && fexist(str)) { exec_bin("feedback",&main_csi); if(main_csi.logic!=LOGIC_TRUE) return(false); } if(cfg.sys_misc&SM_ANON_EM && useron.exempt&FLAG('A') && !noyes(text[AnonymousQ])) msgattr|=MSG_ANONYMOUS; if(cfg.sys_misc&SM_DELREADM) msgattr|=MSG_KILLREAD; msg_tmp_fname(useron.xedit, msgpath, sizeof(msgpath)); username(&cfg,usernumber,str2); if(!writemsg(msgpath,top,title,mode,INVALID_SUB,str2,&editor)) { bputs(text[Aborted]); return(false); } if(mode&WM_FILE && !SYSOP && !(cfg.sys_misc&SM_FILE_EM)) mode&=~WM_FILE; if(mode&WM_FILE) { sprintf(str2,"%sfile/%04u.in", cfg.data_dir,usernumber); MKDIR(str2); sprintf(str2,"%sfile/%04u.in/%s", cfg.data_dir,usernumber,title); if(fexistcase(str2)) { bputs(text[FileAlreadyThere]); remove(msgpath); return(false); } { /* Remote */ xfer_prot_menu(XFER_UPLOAD); mnemonics(text[ProtocolOrQuit]); strcpy(str,"Q"); for(x=0;x<cfg.total_prots;x++) if(cfg.prot[x]->ulcmd[0] && chk_ar(cfg.prot[x]->ar,&useron,&client)) { sprintf(tmp,"%c",cfg.prot[x]->mnemonic); strcat(str,tmp); } ch=(char)getkeys(str,0); if(ch=='Q' || sys_status&SS_ABORT) { bputs(text[Aborted]); remove(msgpath); return(false); } for(x=0;x<cfg.total_prots;x++) if(cfg.prot[x]->ulcmd[0] && cfg.prot[x]->mnemonic==ch && chk_ar(cfg.prot[x]->ar,&useron,&client)) break; if(x<cfg.total_prots) /* This should be always */ protocol(cfg.prot[x],XFER_UPLOAD,str2,nulstr,true); } safe_snprintf(tmp,sizeof(tmp),"%s%s",cfg.temp_dir,title); if(!fexistcase(str2) && fexistcase(tmp)) mv(tmp,str2,0); l=(long)flength(str2); if(l>0) bprintf(text[FileNBytesReceived],title,ultoac(l,tmp)); else { bprintf(text[FileNotReceived],title); remove(msgpath); return(false); } } bputs(text[WritingIndx]); if((i=smb_stack(&smb,SMB_STACK_PUSH))!=0) { errormsg(WHERE,ERR_OPEN,"MAIL",i); return(false); } sprintf(smb.file,"%smail", cfg.data_dir); smb.retry_time=cfg.smb_retry_time; smb.subnum=INVALID_SUB; if((i=smb_open(&smb))!=0) { smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); return(false); } if(smb_fgetlength(smb.shd_fp)<1) { /* Create it if it doesn't exist */ smb.status.max_crcs=cfg.mail_maxcrcs; smb.status.max_age=cfg.mail_maxage; smb.status.max_msgs=0; smb.status.attr=SMB_EMAIL; if((i=smb_create(&smb))!=0) { smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_CREATE,smb.file,i,smb.last_error); return(false); } } if((i=smb_locksmbhdr(&smb))!=0) { smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error); return(false); } length=(long)flength(msgpath)+2; /* +2 for translation string */ if(length&0xfff00000UL) { smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_LEN,msgpath,length); return(false); } if((i=smb_open_da(&smb))!=0) { smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); return(false); } if(cfg.sys_misc&SM_FASTMAIL) offset=smb_fallocdat(&smb,length,1); else offset=smb_allocdat(&smb,length,1); smb_close_da(&smb); if((instream=fnopen(&file,msgpath,O_RDONLY|O_BINARY))==NULL) { smb_freemsgdat(&smb,offset,length,1); smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,msgpath,O_RDONLY|O_BINARY); return(false); } setvbuf(instream,NULL,_IOFBF,2*1024); smb_fseek(smb.sdt_fp,offset,SEEK_SET); xlat=XLAT_NONE; smb_fwrite(&smb,&xlat,2,smb.sdt_fp); x=SDT_BLOCK_LEN-2; /* Don't read/write more than 255 */ while(!feof(instream)) { memset(buf,0,x); j=fread(buf,1,x,instream); if(j<1) break; if(j>1 && (j!=x || feof(instream)) && buf[j-1]==LF && buf[j-2]==CR) buf[j-1]=buf[j-2]=0; if(cfg.mail_maxcrcs) { for(i=0;i<j;i++) crc=ucrc32(buf[i],crc); } smb_fwrite(&smb,buf,j,smb.sdt_fp); x=SDT_BLOCK_LEN; } smb_fflush(smb.sdt_fp); fclose(instream); crc=~crc; memset(&msg,0,sizeof(smbmsg_t)); msg.hdr.version=smb_ver(); msg.hdr.attr=msgattr; if(mode&WM_FILE) msg.hdr.auxattr|=MSG_FILEATTACH; msg.hdr.when_written.time=msg.hdr.when_imported.time=time32(NULL); msg.hdr.when_written.zone=msg.hdr.when_imported.zone=sys_timezone(&cfg); if(cfg.mail_maxcrcs) { i=smb_addcrc(&smb,crc); if(i) { smb_freemsgdat(&smb,offset,length,1); smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); attr(cfg.color[clr_err]); bputs(text[CantPostMsg]); return(false); } } msg.hdr.offset=offset; username(&cfg,usernumber,str); smb_hfield_str(&msg,RECIPIENT,str); sprintf(str,"%u",usernumber); smb_hfield_str(&msg,RECIPIENTEXT,str); SAFECOPY(str,useron.alias); smb_hfield_str(&msg,SENDER,str); sprintf(str,"%u",useron.number); smb_hfield_str(&msg,SENDEREXT,str); if(useron.misc&NETMAIL) { if(useron.rest&FLAG('G')) smb_hfield_str(&msg,REPLYTO,useron.name); nettype=smb_netaddr_type(useron.netmail); if(nettype!=NET_NONE && nettype!=NET_UNKNOWN) { smb_hfield(&msg,REPLYTONETTYPE,sizeof(nettype),&nettype); smb_hfield_str(&msg,REPLYTONETADDR,useron.netmail); } } /* Security logging */ msg_client_hfields(&msg,&client); smb_hfield_str(&msg,SENDERSERVER,startup->host_name); smb_hfield_str(&msg,SUBJECT,title); /* Generate FidoNet Program Identifier */ smb_hfield_str(&msg,FIDOPID,msg_program_id(pid)); if(editor!=NULL) smb_hfield_str(&msg,SMB_EDITOR,editor); smb_dfield(&msg,TEXT_BODY,length); i=smb_addmsghdr(&smb,&msg,SMB_SELFPACK); // calls smb_unlocksmbhdr() smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); smb_freemsgmem(&msg); if(i!=SMB_SUCCESS) { smb_freemsgdat(&smb,offset,length,1); errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error); return(false); } if(usernumber==1) logon_fbacks++; else logon_emails++; user_sent_email(&cfg, &useron, 1, usernumber==1); bprintf(text[Emailed],username(&cfg,usernumber,tmp),usernumber); safe_snprintf(str,sizeof(str),"%s sent e-mail to %s #%d" ,useron.alias,username(&cfg,usernumber,tmp),usernumber); logline("E+",str); if(mode&WM_FILE && online==ON_REMOTE) autohangup(); if(msgattr&MSG_ANONYMOUS) /* Don't tell user if anonymous */ return(true); for(i=1;i<=cfg.sys_nodes;i++) { /* Tell user, if online */ getnodedat(i,&node,0); if(node.useron==usernumber && !(node.misc&NODE_POFF) && (node.status==NODE_INUSE || node.status==NODE_QUIET)) { safe_snprintf(str,sizeof(str),text[EmailNodeMsg],cfg.node_num,useron.alias); putnmsg(&cfg,i,str); break; } } if(i>cfg.sys_nodes) { /* User wasn't online, so leave short msg */ safe_snprintf(str,sizeof(str),text[UserSentYouMail],useron.alias); putsmsg(&cfg,usernumber,str); } return(true); }
void sbbs_t::readmail(uint usernumber, int which) { char str[256],str2[256],str3[256],done=0,domsg=1 ,*p,*tp,*sp,ch; char tmp[512]; int i,j; int error; int mismatches=0,act; long length,l,lm_mode; ulong last; bool replied; file_t fd; mail_t *mail; smbmsg_t msg; if(which==MAIL_SENT && useron.rest&FLAG('K')) { bputs(text[R_ReadSentMail]); return; } msg.total_hfields=0; /* init to NULL, cause not allocated yet */ fd.dir=cfg.total_dirs+1; /* temp dir for file attachments */ if((i=smb_stack(&smb,SMB_STACK_PUSH))!=0) { errormsg(WHERE,ERR_OPEN,"MAIL",i); return; } sprintf(smb.file,"%smail",cfg.data_dir); smb.retry_time=cfg.smb_retry_time; smb.subnum=INVALID_SUB; if((i=smb_open(&smb))!=0) { smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); return; } if(cfg.sys_misc&SM_SYSVDELM && (SYSOP || cfg.sys_misc&SM_USRVDELM)) lm_mode=LM_INCDEL; else lm_mode=0; mail=loadmail(&smb,&smb.msgs,usernumber,which,lm_mode); if(!smb.msgs) { if(which==MAIL_SENT) bputs(text[NoMailSent]); else if(which==MAIL_ALL) bputs(text[NoMailOnSystem]); else bputs(text[NoMailWaiting]); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); return; } last=smb.status.last_msg; if(which==MAIL_SENT) act=NODE_RSML; else if(which==MAIL_ALL) act=NODE_SYSP; else act=NODE_RMAL; action=act; if(smb.msgs>1 && which!=MAIL_ALL) { if(which==MAIL_SENT) bputs(text[MailSentLstHdr]); else bputs(text[MailWaitingLstHdr]); for(smb.curmsg=0;smb.curmsg<smb.msgs && !msgabort();smb.curmsg++) { if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=mail[smb.curmsg].offset; if(!loadmsg(&msg,mail[smb.curmsg].number)) continue; smb_unlockmsghdr(&smb,&msg); bprintf(text[MailWaitingLstFmt],smb.curmsg+1 ,which==MAIL_SENT ? msg.to : (msg.hdr.attr&MSG_ANONYMOUS) && !SYSOP ? text[Anonymous] : msg.from ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R' : msg.hdr.attr&MSG_READ ? ' ' : msg.from_net.type || msg.to_net.type ? 'N':'*' ,msg.subj); smb_freemsgmem(&msg); msg.total_hfields=0; } ASYNC; if(!(sys_status&SS_ABORT)) { bprintf(text[StartWithN],1L); if((long)(smb.curmsg=getnum(smb.msgs))>0) smb.curmsg--; else if((long)smb.curmsg==-1) { free(mail); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); return; } } sys_status&=~SS_ABORT; } else { smb.curmsg=0; if(which==MAIL_ALL) domsg=0; } if(which==MAIL_SENT) { sprintf(str,"%s read sent mail",useron.alias); logline("E",str); } else if(which==MAIL_ALL) { sprintf(str,"%s read all mail",useron.alias); logline("S+",str); } else { sprintf(str,"%s read mail",useron.alias); logline("E",str); } if(useron.misc&RIP) { strcpy(str,which==MAIL_YOUR ? "mailread" : which==MAIL_ALL ? "allmail" : "sentmail"); menu(str); } while(online && !done) { action=act; if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=mail[smb.curmsg].offset; msg.idx.number=mail[smb.curmsg].number; msg.idx.to=mail[smb.curmsg].to; msg.idx.from=mail[smb.curmsg].from; msg.idx.subj=mail[smb.curmsg].subj; if((i=smb_locksmbhdr(&smb))!=0) { errormsg(WHERE,ERR_LOCK,smb.file,i); break; } if((i=smb_getstatus(&smb))!=0) { smb_unlocksmbhdr(&smb); errormsg(WHERE,ERR_READ,smb.file,i); break; } smb_unlocksmbhdr(&smb); if(smb.status.last_msg!=last) { /* New messages */ last=smb.status.last_msg; free(mail); mail=loadmail(&smb,&smb.msgs,usernumber,which,lm_mode); /* So re-load */ if(!smb.msgs) break; for(smb.curmsg=0;smb.curmsg<smb.msgs;smb.curmsg++) if(mail[smb.curmsg].number==msg.idx.number) break; if(smb.curmsg>=smb.msgs) smb.curmsg=(smb.msgs-1); continue; } if(!loadmsg(&msg,mail[smb.curmsg].number)) { /* Message header gone */ if(mismatches>5) { /* We can't do this too many times in a row */ errormsg(WHERE,ERR_CHK,"message number",mail[smb.curmsg].number); break; } free(mail); mail=loadmail(&smb,&smb.msgs,usernumber,which,lm_mode); if(!smb.msgs) break; if(smb.curmsg>(smb.msgs-1)) smb.curmsg=(smb.msgs-1); mismatches++; continue; } smb_unlockmsghdr(&smb,&msg); msg.idx.attr=msg.hdr.attr; mismatches=0; if(domsg && !(sys_status&SS_ABORT)) { show_msg(&msg ,msg.from_ext && msg.idx.from==1 && !msg.from_net.type ? 0:P_NOATCODES); if(msg.hdr.auxattr&MSG_FILEATTACH) { /* Attached file */ smb_getmsgidx(&smb,&msg); strcpy(str,msg.subj); /* filenames in title */ // strupr(str); tp=str; while(online) { p=strchr(tp,' '); if(p) *p=0; sp=strrchr(tp,'/'); /* sp is slash pointer */ if(!sp) sp=strrchr(tp,'\\'); if(sp) tp=sp+1; padfname(tp,fd.name); sprintf(str2,"%sfile/%04u.in/%s" /* str2 is path/fname */ ,cfg.data_dir,msg.idx.to,tp); length=flength(str2); if(length<1) bputs(text[FileNotFound]); else if(!(useron.exempt&FLAG('T')) && cur_cps && !SYSOP && length/(long)cur_cps>(time_t)timeleft) bputs(text[NotEnoughTimeToDl]); else { sprintf(str3,text[DownloadAttachedFileQ] ,tp,ultoac(length,tmp)); if(length>0L && yesno(str3)) { #if 0 /* no such thing as local logon */ if(online==ON_LOCAL) { bputs(text[EnterPath]); if(getstr(str3,60,K_LINE)) { backslashcolon(str3); sprintf(tmp,"%s%s",str3,tp); if(!mv(str2,tmp,which!=MAIL_YOUR)) { logon_dlb+=length; logon_dls++; useron.dls=(ushort)adjustuserrec(&cfg,useron.number ,U_DLS,5,1); useron.dlb=adjustuserrec(&cfg,useron.number ,U_DLB,10,length); bprintf(text[FileNBytesSent] ,fd.name,ultoac(length,tmp)); } } } else #endif { /* Remote User */ xfer_prot_menu(XFER_DOWNLOAD); mnemonics(text[ProtocolOrQuit]); strcpy(str3,"Q"); for(i=0;i<cfg.total_prots;i++) if(cfg.prot[i]->dlcmd[0] && chk_ar(cfg.prot[i]->ar,&useron)) { sprintf(tmp,"%c",cfg.prot[i]->mnemonic); strcat(str3,tmp); } ch=(char)getkeys(str3,0); for(i=0;i<cfg.total_prots;i++) if(cfg.prot[i]->dlcmd[0] && ch==cfg.prot[i]->mnemonic && chk_ar(cfg.prot[i]->ar,&useron)) break; if(i<cfg.total_prots) { error=protocol(cfg.prot[i],XFER_DOWNLOAD,str2,nulstr,false); if(checkprotresult(cfg.prot[i],error,&fd)) { if(which==MAIL_YOUR) remove(str2); logon_dlb+=length; /* Update stats */ logon_dls++; useron.dls=(ushort)adjustuserrec(&cfg,useron.number ,U_DLS,5,1); useron.dlb=adjustuserrec(&cfg,useron.number ,U_DLB,10,length); bprintf(text[FileNBytesSent] ,fd.name,ultoac(length,tmp)); sprintf(str3 ,"%s downloaded attached file: %s" ,useron.alias ,fd.name); logline("D-",str3); } autohangup(); } } } } if(!p) break; tp=p+1; while(*tp==' ') tp++; } sprintf(str,"%sfile/%04u.in",cfg.data_dir,usernumber); rmdir(str); } if(which==MAIL_YOUR && !(msg.hdr.attr&MSG_READ)) { mail[smb.curmsg].attr|=MSG_READ; if(thisnode.status==NODE_INUSE) telluser(&msg); if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=0; /* Search by number */ if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */ if(loadmsg(&msg,msg.idx.number)) { msg.hdr.attr|=MSG_READ; msg.idx.attr=msg.hdr.attr; if((i=smb_putmsg(&smb,&msg))!=0) errormsg(WHERE,ERR_WRITE,smb.file,i); smb_unlockmsghdr(&smb,&msg); } smb_unlocksmbhdr(&smb); } if(!msg.total_hfields) { /* unsuccessful reload */ domsg=0; continue; } } } else domsg=1; if(useron.misc&WIP) { strcpy(str,which==MAIL_YOUR ? "mailread" : which==MAIL_ALL ? "allmail" : "sentmail"); menu(str); } ASYNC; if(which==MAIL_SENT) bprintf(text[ReadingSentMail],smb.curmsg+1,smb.msgs); else if(which==MAIL_ALL) bprintf(text[ReadingAllMail],smb.curmsg+1,smb.msgs); else bprintf(text[ReadingMail],smb.curmsg+1,smb.msgs); sprintf(str,"ADFLNQRT?<>[]{}-+"); if(SYSOP) strcat(str,"CUSPH"); if(which!=MAIL_YOUR) strcat(str,"E"); l=getkeys(str,smb.msgs); if(l&0x80000000L) { if(l==-1) /* ctrl-c */ break; smb.curmsg=(l&~0x80000000L)-1; continue; } switch(l) { case 'A': /* Auto-reply to last piece */ case 'R': if(l==(cfg.sys_misc&SM_RA_EMU ? 'A' : 'R')) /* re-read last message */ break; if(which==MAIL_SENT) break; if((msg.hdr.attr&MSG_ANONYMOUS) && !SYSOP) { bputs(text[CantReplyToAnonMsg]); break; } quotemsg(&msg,1); if(msg.from_net.addr==NULL) SAFECOPY(str,msg.from); else if(msg.from_net.type==NET_FIDO) /* FidoNet type */ SAFEPRINTF2(str,"%s@%s",msg.from ,smb_faddrtoa((faddr_t *)msg.from_net.addr,tmp)); else if(msg.from_net.type==NET_INTERNET) { if(msg.replyto_net.type==NET_INTERNET) SAFECOPY(str,(char *)msg.replyto_net.addr); else SAFECOPY(str,(char *)msg.from_net.addr); } else SAFEPRINTF2(str,"%s@%s",msg.from,(char*)msg.from_net.addr); SAFECOPY(str2,str); bputs(text[Email]); if(!getstr(str,64,K_EDIT|K_AUTODEL)) break; msg.hdr.number=msg.idx.number; smb_getmsgidx(&smb,&msg); if(!stricmp(str2,str)) /* Reply to sender */ sprintf(str2,text[Regarding],msg.subj); else /* Reply to other */ sprintf(str2,text[RegardingByOn],msg.subj,msg.from ,timestr((time_t *)&msg.hdr.when_written.time)); p=strrchr(str,'@'); if(p) { /* name @addr */ replied=netmail(str,msg.subj,WM_QUOTE); sprintf(str2,text[DeleteMailQ],msg.from); } else { if(!msg.from_net.type && !stricmp(str,msg.from)) replied=email(msg.idx.from,str2,msg.subj,WM_EMAIL|WM_QUOTE); else if(!stricmp(str,"SYSOP")) replied=email(1,str2,msg.subj,WM_EMAIL|WM_QUOTE); else if((i=finduser(str))!=0) replied=email(i,str2,msg.subj,WM_EMAIL|WM_QUOTE); else replied=false; sprintf(str2,text[DeleteMailQ],msg.from); } if(replied==true && !(msg.hdr.attr&MSG_REPLIED)) { if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=0; if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */ if(loadmsg(&msg,msg.idx.number)) { msg.hdr.attr|=MSG_REPLIED; msg.idx.attr=msg.hdr.attr; if((i=smb_putmsg(&smb,&msg))!=0) errormsg(WHERE,ERR_WRITE,smb.file,i); smb_unlockmsghdr(&smb,&msg); } smb_unlocksmbhdr(&smb); } } if(msg.hdr.attr&MSG_DELETE || !yesno(str2)) { if(smb.curmsg<smb.msgs-1) smb.curmsg++; else done=1; break; } /* Case 'D': must follow! */ case 'D': /* Delete last piece (toggle) */ if(msg.hdr.attr&MSG_PERMANENT) { bputs("\r\nPermanent message.\r\n"); domsg=0; break; } if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=0; if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */ if(loadmsg(&msg,msg.idx.number)) { msg.hdr.attr^=MSG_DELETE; msg.idx.attr=msg.hdr.attr; // mail[smb.curmsg].attr=msg.hdr.attr; if((i=smb_putmsg(&smb,&msg))!=0) errormsg(WHERE,ERR_WRITE,smb.file,i); smb_unlockmsghdr(&smb,&msg); } smb_unlocksmbhdr(&smb); } if(smb.curmsg<smb.msgs-1) smb.curmsg++; else done=1; break; case 'F': /* Forward last piece */ domsg=0; bputs(text[ForwardMailTo]); if(!getstr(str,LEN_ALIAS,cfg.uq&UQ_NOUPRLWR ? K_NONE:K_UPRLWR)) break; i=finduser(str); if(!i) break; domsg=1; if(smb.curmsg<smb.msgs-1) smb.curmsg++; else done=1; smb_getmsgidx(&smb,&msg); forwardmail(&msg,i); if(msg.hdr.attr&MSG_PERMANENT) break; sprintf(str2,text[DeleteMailQ],msg.from); if(!yesno(str2)) break; if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=0; if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */ if(loadmsg(&msg,msg.idx.number)) { msg.hdr.attr|=MSG_DELETE; msg.idx.attr=msg.hdr.attr; // mail[smb.curmsg].attr=msg.hdr.attr; if((i=smb_putmsg(&smb,&msg))!=0) errormsg(WHERE,ERR_WRITE,smb.file,i); smb_unlockmsghdr(&smb,&msg); } smb_unlocksmbhdr(&smb); } break; case 'H': domsg=0; msghdr(&msg); break; case 'L': /* List mail */ domsg=0; bprintf(text[StartWithN],(long)smb.curmsg+1); if((i=getnum(smb.msgs))>0) i--; else if(i==-1) break; else i=smb.curmsg; if(which==MAIL_SENT) bputs(text[MailSentLstHdr]); else if(which==MAIL_ALL) bputs(text[MailOnSystemLstHdr]); else bputs(text[MailWaitingLstHdr]); for(;i<smb.msgs && !msgabort();i++) { if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=mail[i].offset; if(!loadmsg(&msg,mail[i].number)) continue; smb_unlockmsghdr(&smb,&msg); if(which==MAIL_ALL) bprintf(text[MailOnSystemLstFmt] ,i+1,msg.from,msg.to ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R' : msg.hdr.attr&MSG_READ ? ' ' : msg.from_net.type || msg.to_net.type ? 'N':'*' ,msg.subj); else bprintf(text[MailWaitingLstFmt],i+1 ,which==MAIL_SENT ? msg.to : (msg.hdr.attr&MSG_ANONYMOUS) && !SYSOP ? text[Anonymous] : msg.from ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R' : msg.hdr.attr&MSG_READ ? ' ' : msg.from_net.type || msg.to_net.type ? 'N':'*' ,msg.subj); smb_freemsgmem(&msg); msg.total_hfields=0; } break; case 'Q': done=1; break; case 'C': /* Change attributes of last piece */ i=chmsgattr(msg.hdr.attr); if(msg.hdr.attr==i) break; if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=0; if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */ if(loadmsg(&msg,msg.idx.number)) { msg.hdr.attr=msg.idx.attr=(ushort)i; if((i=smb_putmsg(&smb,&msg))!=0) errormsg(WHERE,ERR_WRITE,smb.file,i); smb_unlockmsghdr(&smb,&msg); } smb_unlocksmbhdr(&smb); } break; case '>': for(i=smb.curmsg+1;i<smb.msgs;i++) if(mail[i].subj==msg.idx.subj) break; if(i<smb.msgs) smb.curmsg=i; else domsg=0; break; case '<': /* Search Title backward */ for(i=smb.curmsg-1;i>-1;i--) if(mail[i].subj==msg.idx.subj) break; if(i>-1) smb.curmsg=i; else domsg=0; break; case '}': /* Search Author forward */ strcpy(str,msg.from); for(i=smb.curmsg+1;i<smb.msgs;i++) if(mail[i].from==msg.idx.from) break; if(i<smb.msgs) smb.curmsg=i; else domsg=0; break; case 'N': /* Got to next un-read message */ for(i=smb.curmsg+1;i<smb.msgs;i++) if(!(mail[i].attr&MSG_READ)) break; if(i<smb.msgs) smb.curmsg=i; else domsg=0; break; case '{': /* Search Author backward */ strcpy(str,msg.from); for(i=smb.curmsg-1;i>-1;i--) if(mail[i].from==msg.idx.from) break; if(i>-1) smb.curmsg=i; else domsg=0; break; case ']': /* Search To User forward */ strcpy(str,msg.to); for(i=smb.curmsg+1;i<smb.msgs;i++) if(mail[i].to==msg.idx.to) break; if(i<smb.msgs) smb.curmsg=i; else domsg=0; break; case '[': /* Search To User backward */ strcpy(str,msg.to); for(i=smb.curmsg-1;i>-1;i--) if(mail[i].to==msg.idx.to) break; if(i>-1) smb.curmsg=i; else domsg=0; break; case 0: case '+': if(smb.curmsg<smb.msgs-1) smb.curmsg++; else done=1; break; case '-': if(smb.curmsg>0) smb.curmsg--; break; case 'S': domsg=0; /* if(!yesno(text[SaveMsgToFile])) break; */ bputs(text[FileToWriteTo]); if(getstr(str,40,K_LINE)) msgtotxt(&msg,str,1,1); break; case 'E': editmsg(&msg,INVALID_SUB); break; case 'T': domsg=0; i=smb.curmsg; if(i) i++; j=i+10; if(j>smb.msgs) j=smb.msgs; if(which==MAIL_SENT) bputs(text[MailSentLstHdr]); else if(which==MAIL_ALL) bputs(text[MailOnSystemLstHdr]); else bputs(text[MailWaitingLstHdr]); for(;i<j;i++) { if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=mail[i].offset; if(!loadmsg(&msg,mail[i].number)) continue; smb_unlockmsghdr(&smb,&msg); if(which==MAIL_ALL) bprintf(text[MailOnSystemLstFmt] ,i+1,msg.from,msg.to ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R' : msg.hdr.attr&MSG_READ ? ' ' : msg.from_net.type || msg.to_net.type ? 'N':'*' ,msg.subj); else bprintf(text[MailWaitingLstFmt],i+1 ,which==MAIL_SENT ? msg.to : (msg.hdr.attr&MSG_ANONYMOUS) && !SYSOP ? text[Anonymous] : msg.from ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R' : msg.hdr.attr&MSG_READ ? ' ' : msg.from_net.type || msg.to_net.type ? 'N':'*' ,msg.subj); smb_freemsgmem(&msg); msg.total_hfields=0; } smb.curmsg=(i-1); break; case 'U': /* user edit */ msg.hdr.number=msg.idx.number; smb_getmsgidx(&smb,&msg); useredit(which==MAIL_SENT ? msg.idx.to : msg.idx.from); break; case 'P': /* Purge author and all mail to/from */ if(noyes(text[AreYouSureQ])) break; msg.hdr.number=msg.idx.number; smb_getmsgidx(&smb,&msg); purgeuser(msg.idx.from); if(smb.curmsg<smb.msgs-1) smb.curmsg++; break; case '?': strcpy(str,which==MAIL_YOUR ? "mailread" : which==MAIL_ALL ? "allmail" : "sentmail"); menu(str); if(SYSOP && which==MAIL_SENT) menu("syssmail"); else if(SYSOP && which==MAIL_YOUR) menu("sysmailr"); /* Sysop Mail Read */ domsg=0; break; } } if(msg.total_hfields) smb_freemsgmem(&msg); if(smb.msgs) free(mail); /***************************************/ /* Delete messages marked for deletion */ /***************************************/ if(cfg.sys_misc&SM_DELEMAIL) { if((i=smb_locksmbhdr(&smb))!=0) /* Lock the base, so nobody */ errormsg(WHERE,ERR_LOCK,smb.file,i); /* messes with the index */ else delmail(usernumber,which); } smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); }
int sbbs_t::exec(csi_t *csi) { char str[256],*path; char tmp[512]; uchar buf[1025],ch; int i,j,file; long l; FILE *stream; if(usrgrps) cursubnum=usrsub[curgrp][cursub[curgrp]]; /* Used for ARS */ else cursubnum=INVALID_SUB; if(usrlibs) { curdirnum=usrdir[curlib][curdir[curlib]]; /* Used for ARS */ path=cfg.dir[usrdir[curlib][curdir[curlib]]]->path; } else { curdirnum=INVALID_DIR; path=nulstr; } now=time(NULL); if(csi->ip>=csi->cs+csi->length) return(1); if(*csi->ip>=CS_FUNCTIONS) return(exec_function(csi)); /**********************************************/ /* Miscellaneous variable length instructions */ /**********************************************/ if(*csi->ip>=CS_MISC) return(exec_misc(csi,path)); /********************************/ /* ASCIIZ argument instructions */ /********************************/ if(*csi->ip>=CS_ASCIIZ) { switch(*(csi->ip++)) { case CS_STR_FUNCTION: switch(*(csi->ip++)) { case CS_LOGIN: csi->logic=login(csi->str,(char*)csi->ip); break; case CS_LOAD_TEXT: csi->logic=LOGIC_FALSE; for(i=0;i<TOTAL_TEXT;i++) if(text[i]!=text_sav[i]) { if(text[i]!=nulstr) free(text[i]); text[i]=text_sav[i]; } SAFEPRINTF2(str,"%s%s.dat" ,cfg.ctrl_dir,cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); if((stream=fnopen(&file,str,O_RDONLY))==NULL) { errormsg(WHERE,ERR_OPEN,str,O_RDONLY); break; } for(i=0;i<TOTAL_TEXT && !feof(stream);i++) { if((text[i]=readtext((long *)NULL,stream,i))==NULL) { i--; continue; } if(!strcmp(text[i],text_sav[i])) { /* If identical */ free(text[i]); /* Don't alloc */ text[i]=text_sav[i]; } else if(text[i][0]==0) { free(text[i]); text[i]=nulstr; } } if(i<TOTAL_TEXT) { fclose(stream); errormsg(WHERE,ERR_READ,str,TOTAL_TEXT); break; } fclose(stream); csi->logic=LOGIC_TRUE; break; default: errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); break; } while(*(csi->ip++)); /* Find NULL */ return(0); case CS_LOG: log(cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_GETCMD: csi->cmd=(uchar)getkeys((char*)csi->ip,0); if((char)csi->cmd==-1) csi->cmd=3; break; case CS_CMDSTR: if(stricmp(csi->str,(char*)csi->ip)) { while(*(csi->ip++)); /* Find NULL */ skipto(csi,CS_END_CMD); csi->ip++; return(0); } break; case CS_CMDKEYS: for(i=0;csi->ip[i];i++) if(csi->cmd==csi->ip[i]) break; if(!csi->ip[i]) { while(*(csi->ip++)); /* Find NULL */ skipto(csi,CS_END_CMD); csi->ip++; return(0); } break; case CS_GET_TEMPLATE: gettmplt(csi->str,(char*)csi->ip,K_LINE); if(sys_status&SS_ABORT) csi->str[0]=0; csi->cmd=csi->str[0]; break; case CS_TRASHCAN: csi->logic=!trashcan(csi->str,(char*)csi->ip); break; case CS_CREATE_SIF: create_sif_dat((char*)csi->ip,csi->str); break; case CS_READ_SIF: read_sif_dat((char*)csi->ip,csi->str); break; case CS_MNEMONICS: mnemonics((char*)csi->ip); break; case CS_PRINT: putmsg(cmdstr((char*)csi->ip,path,csi->str,(char*)buf),P_SAVEATR|P_NOABORT); break; case CS_PRINT_LOCAL: if(online==ON_LOCAL) eprintf(LOG_INFO,"%s",cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); else lputs(LOG_INFO,cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_PRINT_REMOTE: putcom(cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_PRINTFILE: printfile(cmdstr((char*)csi->ip,path,csi->str,(char*)buf),P_SAVEATR); break; case CS_PRINTFILE_REMOTE: if(online!=ON_REMOTE || !(console&CON_R_ECHO)) break; console&=~CON_L_ECHO; printfile(cmdstr((char*)csi->ip,path,csi->str,(char*)buf),P_SAVEATR); console|=CON_L_ECHO; break; case CS_PRINTFILE_LOCAL: if(!(console&CON_L_ECHO)) break; console&=~CON_R_ECHO; printfile(cmdstr((char*)csi->ip,path,csi->str,(char*)buf),P_SAVEATR); console|=CON_R_ECHO; break; case CS_CHKFILE: csi->logic=!fexistcase(cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_EXEC: external(cmdstr((char*)csi->ip,path,csi->str,(char*)buf),0); break; case CS_EXEC_INT: external(cmdstr((char*)csi->ip,path,csi->str,(char*)buf),EX_STDIO); break; case CS_EXEC_XTRN: for(i=0;i<cfg.total_xtrns;i++) if(!stricmp(cfg.xtrn[i]->code,(char*)csi->ip)) break; if(i<cfg.total_xtrns) exec_xtrn(i); break; case CS_EXEC_BIN: exec_bin(cmdstr((char*)csi->ip,path,csi->str,(char*)buf),csi,/* startup_dir: */NULL); break; case CS_YES_NO: csi->logic=!yesno(cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_NO_YES: csi->logic=!noyes(cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_MENU: menu(cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_SETSTR: strcpy(csi->str,cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_SET_MENU_DIR: cmdstr((char*)csi->ip,path,csi->str,menu_dir); break; case CS_SET_MENU_FILE: cmdstr((char*)csi->ip,path,csi->str,menu_file); break; case CS_COMPARE_STR: csi->logic=stricmp(csi->str,cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_COMPARE_KEYS: for(i=0;csi->ip[i];i++) if(csi->cmd==csi->ip[i]) break; if(csi->ip[i]) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; break; case CS_COMPARE_WORD: csi->logic=strnicmp(csi->str,(char*)csi->ip,strlen((char*)csi->ip)); break; default: errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); break; } while(*(csi->ip++)); /* Find NULL */ return(0); } if(*csi->ip>=CS_THREE_BYTE) { switch(*(csi->ip++)) { case CS_THREE_MORE_BYTES: errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); return(0); case CS_GOTO: csi->ip=csi->cs+*((ushort *)(csi->ip)); return(0); case CS_CALL: if(csi->rets<MAX_RETS) { csi->ret[csi->rets++]=csi->ip+2; csi->ip=csi->cs+*((ushort *)(csi->ip)); } return(0); case CS_MSWAIT: mswait(*(ushort *)csi->ip); csi->ip+=2; return(0); case CS_TOGGLE_NODE_MISC: if(getnodedat(cfg.node_num,&thisnode,true)==0) { thisnode.misc^=*(ushort *)csi->ip; putnodedat(cfg.node_num,&thisnode); } csi->ip+=2; return(0); case CS_COMPARE_NODE_MISC: getnodedat(cfg.node_num,&thisnode,0); if((thisnode.misc&*(ushort *)csi->ip)==*(ushort *)csi->ip) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; csi->ip+=2; return(0); case CS_ADJUST_USER_CREDITS: i=*(short *)csi->ip; l=i*1024L; if(l<0) subtract_cdt(&cfg,&useron,-l); else useron.cdt=adjustuserrec(&cfg,useron.number,U_CDT,10,l); csi->ip+=2; return(0); case CS_ADJUST_USER_MINUTES: i=*(short *)csi->ip; useron.min=adjustuserrec(&cfg,useron.number,U_MIN,10,i); csi->ip+=2; return(0); case CS_GETNUM: i=*(short *)csi->ip; csi->ip+=2; l=getnum(i); if(l<=0) { csi->str[0]=0; csi->logic=LOGIC_FALSE; } else { sprintf(csi->str,"%lu",l); csi->logic=LOGIC_TRUE; } return(0); case CS_TOGGLE_USER_FLAG: i=*(csi->ip++); ch=*(csi->ip++); switch(i) { case '1': useron.flags1^=FLAG(ch); putuserrec(&cfg,useron.number,U_FLAGS1,8 ,ultoa(useron.flags1,tmp,16)); break; case '2': useron.flags2^=FLAG(ch); putuserrec(&cfg,useron.number,U_FLAGS2,8 ,ultoa(useron.flags2,tmp,16)); break; case '3': useron.flags3^=FLAG(ch); putuserrec(&cfg,useron.number,U_FLAGS3,8 ,ultoa(useron.flags3,tmp,16)); break; case '4': useron.flags4^=FLAG(ch); putuserrec(&cfg,useron.number,U_FLAGS4,8 ,ultoa(useron.flags4,tmp,16)); break; case 'R': useron.rest^=FLAG(ch); putuserrec(&cfg,useron.number,U_REST,8 ,ultoa(useron.rest,tmp,16)); break; case 'E': useron.exempt^=FLAG(ch); putuserrec(&cfg,useron.number,U_EXEMPT,8 ,ultoa(useron.exempt,tmp,16)); break; default: errormsg(WHERE,ERR_CHK,"user flag type",*(csi->ip-2)); return(0); } return(0); case CS_REVERT_TEXT: i=*(ushort *)csi->ip; csi->ip+=2; if((ushort)i==0xffff) { for(i=0;i<TOTAL_TEXT;i++) { if(text[i]!=text_sav[i] && text[i]!=nulstr) free(text[i]); text[i]=text_sav[i]; } return(0); } i--; if(i>=TOTAL_TEXT) { errormsg(WHERE,ERR_CHK,"revert text #",i); return(0); } if(text[i]!=text_sav[i] && text[i]!=nulstr) free(text[i]); text[i]=text_sav[i]; return(0); default: errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); return(0); } } if(*csi->ip>=CS_TWO_BYTE) { switch(*(csi->ip++)) { case CS_TWO_MORE_BYTES: switch(*(csi->ip++)) { case CS_USER_EVENT: user_event((user_event_t)*(csi->ip++)); return(0); } errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); return(0); case CS_SETLOGIC: csi->logic=*csi->ip++; return(0); case CS_CMDKEY: if( ((*csi->ip)==CS_DIGIT && isdigit(csi->cmd)) || ((*csi->ip)==CS_EDIGIT && csi->cmd&0x80 && isdigit(csi->cmd&0x7f))) { csi->ip++; return(0); } if(csi->cmd!=*csi->ip) { csi->ip++; skipto(csi,CS_END_CMD); /* skip code */ } csi->ip++; /* skip key */ return(0); case CS_CMDCHAR: if(csi->cmd!=*csi->ip) { csi->ip++; skipto(csi,CS_END_CMD); /* skip code */ } csi->ip++; /* skip key */ return(0); case CS_NODE_ACTION: action=*csi->ip++; return(0); case CS_NODE_STATUS: if(getnodedat(cfg.node_num,&thisnode,true)==0) { thisnode.status=*csi->ip++; putnodedat(cfg.node_num,&thisnode); } else csi->ip++; return(0); case CS_MULTINODE_CHAT: multinodechat(*csi->ip++); return(0); case CS_GETSTR: csi->logic=LOGIC_TRUE; getstr(csi->str,*csi->ip++,0); if(sys_status&SS_ABORT) { csi->str[0]=0; csi->logic=LOGIC_FALSE; } if(csi->str[0]=='/' && csi->str[1]) csi->cmd=csi->str[1]|0x80; else csi->cmd=csi->str[0]; return(0); case CS_GETLINE: getstr(csi->str,*csi->ip++,K_LINE); if(sys_status&SS_ABORT) csi->str[0]=0; if(csi->str[0]=='/' && csi->str[1]) csi->cmd=csi->str[1]|0x80; else csi->cmd=csi->str[0]; return(0); case CS_GETSTRUPR: getstr(csi->str,*csi->ip++,K_UPPER); if(sys_status&SS_ABORT) csi->str[0]=0; if(csi->str[0]=='/' && csi->str[1]) csi->cmd=csi->str[1]|0x80; else csi->cmd=csi->str[0]; return(0); case CS_GETNAME: getstr(csi->str,*csi->ip++,K_UPRLWR); if(sys_status&SS_ABORT) csi->str[0]=0; return(0); case CS_SHIFT_STR: i=*(csi->ip++); j=strlen(csi->str); if(i>j) i=j; if(i) memmove(csi->str,csi->str+i,j+1); return(0); case CS_COMPARE_KEY: if( ((*csi->ip)==CS_DIGIT && isdigit(csi->cmd)) || ((*csi->ip)==CS_EDIGIT && csi->cmd&0x80 && isdigit(csi->cmd&0x7f))) { csi->ip++; csi->logic=LOGIC_TRUE; } else { if(csi->cmd==*(csi->ip++)) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; } return(0); case CS_COMPARE_CHAR: if(csi->cmd==*(csi->ip++)) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case CS_SET_USER_LEVEL: useron.level=*(csi->ip++); putuserrec(&cfg,useron.number,U_LEVEL,2,ultoa(useron.level,tmp,10)); return(0); case CS_SET_USER_STRING: csi->logic=LOGIC_FALSE; if(!csi->str[0]) { csi->ip++; return(0); } switch(*(csi->ip++)) { case USER_STRING_ALIAS: if(!isalpha(csi->str[0]) || trashcan(csi->str,"name")) break; i=matchuser(&cfg,csi->str,TRUE /*sysop_alias*/); if(i && i!=useron.number) break; sprintf(useron.alias,"%.*s",LEN_ALIAS,csi->str); putuserrec(&cfg,useron.number,U_ALIAS,LEN_ALIAS,useron.alias); putusername(&cfg,useron.number,useron.alias); csi->logic=LOGIC_TRUE; break; case USER_STRING_REALNAME: if(trashcan(csi->str,"name")) break; if(cfg.uq&UQ_DUPREAL && userdatdupe(useron.number,U_NAME,LEN_NAME,csi->str)) break; sprintf(useron.name,"%.*s",LEN_NAME,csi->str); putuserrec(&cfg,useron.number,U_NAME,LEN_NAME ,useron.name); csi->logic=LOGIC_TRUE; break; case USER_STRING_HANDLE: if(trashcan(csi->str,"name")) break; if(cfg.uq&UQ_DUPHAND && userdatdupe(useron.number,U_HANDLE,LEN_HANDLE,csi->str)) break; sprintf(useron.handle,"%.*s",LEN_HANDLE,csi->str); putuserrec(&cfg,useron.number,U_HANDLE,LEN_HANDLE ,useron.handle); csi->logic=LOGIC_TRUE; break; case USER_STRING_COMPUTER: sprintf(useron.comp,"%.*s",LEN_COMP,csi->str); putuserrec(&cfg,useron.number,U_COMP,LEN_COMP ,useron.comp); csi->logic=LOGIC_TRUE; break; case USER_STRING_NOTE: sprintf(useron.note,"%.*s",LEN_NOTE,csi->str); putuserrec(&cfg,useron.number,U_NOTE,LEN_NOTE ,useron.note); csi->logic=LOGIC_TRUE; break; case USER_STRING_ADDRESS: sprintf(useron.address,"%.*s",LEN_ADDRESS,csi->str); putuserrec(&cfg,useron.number,U_ADDRESS,LEN_ADDRESS ,useron.address); csi->logic=LOGIC_TRUE; break; case USER_STRING_LOCATION: sprintf(useron.location,"%.*s",LEN_LOCATION,csi->str); putuserrec(&cfg,useron.number,U_LOCATION,LEN_LOCATION ,useron.location); csi->logic=LOGIC_TRUE; break; case USER_STRING_ZIPCODE: sprintf(useron.zipcode,"%.*s",LEN_ZIPCODE,csi->str); putuserrec(&cfg,useron.number,U_ZIPCODE,LEN_ZIPCODE ,useron.zipcode); csi->logic=LOGIC_TRUE; break; case USER_STRING_PASSWORD: sprintf(useron.pass,"%.*s",LEN_PASS,csi->str); putuserrec(&cfg,useron.number,U_PASS,LEN_PASS ,useron.pass); csi->logic=LOGIC_TRUE; break; case USER_STRING_BIRTHDAY: if(!getage(&cfg,csi->str)) break; sprintf(useron.birth,"%.*s",LEN_BIRTH,csi->str); putuserrec(&cfg,useron.number,U_BIRTH,LEN_BIRTH ,useron.birth); csi->logic=LOGIC_TRUE; break; case USER_STRING_PHONE: if(trashcan(csi->str,"phone")) break; sprintf(useron.phone,"%.*s",LEN_PHONE,csi->str); putuserrec(&cfg,useron.number,U_PHONE,LEN_PHONE ,useron.phone); csi->logic=LOGIC_TRUE; break; case USER_STRING_MODEM: sprintf(useron.modem,"%.*s",LEN_MODEM,csi->str); putuserrec(&cfg,useron.number,U_MODEM,LEN_MODEM ,useron.phone); csi->logic=LOGIC_TRUE; break; case USER_STRING_COMMENT: sprintf(useron.comment,"%.*s",LEN_COMMENT,csi->str); putuserrec(&cfg,useron.number,U_COMMENT,LEN_COMMENT ,useron.comment); csi->logic=LOGIC_TRUE; break; case USER_STRING_NETMAIL: sprintf(useron.netmail,"%.*s",LEN_NETMAIL,csi->str); putuserrec(&cfg,useron.number,U_NETMAIL,LEN_NETMAIL ,useron.netmail); csi->logic=LOGIC_TRUE; break; default: errormsg(WHERE,ERR_CHK,"user string type",*(csi->ip-1)); return(0); } return(0); default: errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); return(0); } } /*********************************/ /* Single Byte Instrcutions ONLY */ /*********************************/ switch(*(csi->ip++)) { case CS_ONE_MORE_BYTE: /* Just one MORE byte */ switch(*(csi->ip++)) { case CS_OFFLINE: csi->misc|=CS_OFFLINE_EXEC; return(0); case CS_ONLINE: csi->misc&=~CS_OFFLINE_EXEC; return(0); case CS_NEWUSER: if(newuser()) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case CS_LOGON: if(logon()) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case CS_LOGOUT: logout(); return(0); case CS_EXIT: return(1); case CS_LOOP_BEGIN: if(csi->loops<MAX_LOOPDEPTH) csi->loop_home[csi->loops++]=(csi->ip-1); return(0); case CS_BREAK_LOOP: if(csi->loops) { skipto(csi,CS_END_LOOP); csi->ip+=2; csi->loops--; } return(0); case CS_END_LOOP: case CS_CONTINUE_LOOP: if(csi->loops) csi->ip=csi->loop_home[csi->loops-1]; return(0); default: errormsg(WHERE,ERR_CHK,"one byte extended function" ,*(csi->ip-1)); return(0); } case CS_CRLF: CRLF; return(0); case CS_CLS: CLS; return(0); case CS_PAUSE: pause(); return(0); case CS_PAUSE_RESET: lncntr=0; return(0); case CS_GETLINES: ansi_getlines(); return(0); case CS_HANGUP: hangup(); return(0); case CS_LOGKEY: logch(csi->cmd,0); return(0); case CS_LOGKEY_COMMA: logch(csi->cmd,1); return(0); case CS_LOGSTR: log(csi->str); return(0); case CS_CHKSYSPASS: csi->logic=!chksyspass(); return(0); case CS_PUT_NODE: if(getnodedat(cfg.node_num,&thisnode,true)==0) putnodedat(cfg.node_num,&thisnode); return(0); case CS_SYNC: SYNC; return(0); case CS_ASYNC: ASYNC; return(0); case CS_GETTIMELEFT: gettimeleft(); return(0); case CS_RETURN: if(!csi->rets) return(1); csi->ip=csi->ret[--csi->rets]; return(0); case CS_GETKEY: csi->cmd=getkey(K_UPPER); return(0); case CS_GETCHAR: csi->cmd=getkey(0); return(0); case CS_INKEY: csi->cmd=toupper(inkey(K_NONE,1)); if(csi->cmd) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case CS_INCHAR: csi->cmd=inkey(K_NONE,1); if(csi->cmd) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case CS_GETKEYE: csi->cmd=getkey(K_UPPER); if(csi->cmd=='/') { outchar('/'); csi->cmd=getkey(K_UPPER); csi->cmd|=0x80; } return(0); case CS_GETFILESPEC: if(getfilespec(csi->str)) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case CS_SAVELINE: SAVELINE; return(0); case CS_RESTORELINE: RESTORELINE; return(0); case CS_SELECT_SHELL: csi->logic=select_shell() ? LOGIC_TRUE:LOGIC_FALSE; return(0); case CS_SET_SHELL: csi->logic=LOGIC_TRUE; for(i=0;i<cfg.total_shells;i++) if(!stricmp(csi->str,cfg.shell[i]->code) && chk_ar(cfg.shell[i]->ar,&useron,&client)) break; if(i<cfg.total_shells) { useron.shell=i; putuserrec(&cfg,useron.number,U_SHELL,8,cfg.shell[i]->code); } else csi->logic=LOGIC_FALSE; return(0); case CS_SELECT_EDITOR: csi->logic=select_editor() ? LOGIC_TRUE:LOGIC_FALSE; return(0); case CS_SET_EDITOR: csi->logic=LOGIC_TRUE; for(i=0;i<cfg.total_xedits;i++) if(!stricmp(csi->str,cfg.xedit[i]->code) && chk_ar(cfg.xedit[i]->ar,&useron,&client)) break; if(i<cfg.total_xedits) { useron.xedit=i+1; putuserrec(&cfg,useron.number,U_XEDIT,8,cfg.xedit[i]->code); } else csi->logic=LOGIC_FALSE; return(0); case CS_CLEAR_ABORT: sys_status&=~SS_ABORT; return(0); case CS_FINDUSER: i=finduser(csi->str); if(i) { csi->logic=LOGIC_TRUE; username(&cfg,i,csi->str); } else csi->logic=LOGIC_FALSE; return(0); case CS_UNGETKEY: ungetkey(csi->cmd&0x7f); return(0); case CS_UNGETSTR: j=strlen(csi->str); for(i=0;i<j;i++) ungetkey(csi->str[i]); return(0); case CS_PRINTKEY: if((csi->cmd&0x7f)>=' ') outchar(csi->cmd&0x7f); return(0); case CS_PRINTSTR: putmsg(csi->str,P_SAVEATR|P_NOABORT|P_NOATCODES); return(0); case CS_CMD_HOME: if(csi->cmdrets<MAX_CMDRETS) csi->cmdret[csi->cmdrets++]=(csi->ip-1); return(0); case CS_END_CMD: if(csi->cmdrets) csi->ip=csi->cmdret[--csi->cmdrets]; return(0); case CS_CMD_POP: if(csi->cmdrets) csi->cmdrets--; return(0); case CS_IF_TRUE: if(csi->logic!=LOGIC_TRUE) { skipto(csi,CS_ELSEORENDIF); csi->ip++; } return(0); case CS_IF_GREATER: if(csi->logic!=LOGIC_GREATER) { skipto(csi,CS_ELSEORENDIF); csi->ip++; } return(0); case CS_IF_GREATER_OR_EQUAL: if(csi->logic!=LOGIC_GREATER && csi->logic!=LOGIC_EQUAL) { skipto(csi,CS_ELSEORENDIF); csi->ip++; } return(0); case CS_IF_LESS: if(csi->logic!=LOGIC_LESS) { skipto(csi,CS_ELSEORENDIF); csi->ip++; } return(0); case CS_IF_LESS_OR_EQUAL: if(csi->logic!=LOGIC_LESS && csi->logic!=LOGIC_EQUAL) { skipto(csi,CS_ELSEORENDIF); csi->ip++; } return(0); case CS_IF_FALSE: if(csi->logic==LOGIC_TRUE) { skipto(csi,CS_ELSEORENDIF); csi->ip++; } return(0); case CS_ELSE: skipto(csi,CS_ENDIF); csi->ip++; return(0); case CS_END_CASE: skipto(csi,CS_END_SWITCH); csi->misc&=~CS_IN_SWITCH; csi->ip++; return(0); case CS_DEFAULT: case CS_END_SWITCH: csi->misc&=~CS_IN_SWITCH; return(0); case CS_ENDIF: return(0); default: errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); return(0); } }
void play() { char str[256],str2[256],log[81],done,doub,dh,split_card,suggestion ,*YouWereDealt="\1n\1k\0015 You \1n\1m were dealt: %s\r\n" ,*UserWasDealt="\1n\1m\1h%s\1n\1m was dealt: %s\r\n" ,*YourHand="\1n\1k\0015 You \1n\1m (%2d) %s" ,*UserHand="\1n\1m\1h%-25s \1n\1m(%2d) %s" ,*DealerHand="\1n\1hDealer \1n\1m(%2d) " ,*Bust="\1n\1r\1hBust\1n\r\n" ,*Natural="\1g\1h\1iNatural " ,*Three7s="\1r\1h\1iThree 7's " ,*Blackjack="\1n\0011\1k Blackjack! \1n\r\n" ,*TwentyOne="\1n\0012\1k Twenty-one \1n\r\n"; int h,i,j,file; uint max; long val; time_t start,now; struct tm* tm; sprintf(str,"MESSAGE.%d",node_num); /* remove message if waiting */ if(fexist(str)) remove(str); getgamedat(0); if(node[node_num-1]) { getgamedat(1); node[node_num-1]=0; putgamedat(); getgamedat(0); } if(total_players && misc&INPLAY) { bputs("\r\n\1hWaiting for end of hand (^A to abort)...\1n"); start=now=time(NULL); getgamedat(0); while(total_players && misc&INPLAY) { if((i=inkey(0))!=0) { /* if key was hit */ if(i==1) { /* if ctrl-a */ bputs("\r\n"); return; } } /* return */ mswait(100); getgamedat(0); now=time(NULL); if(now-start>300) { /* only wait up to 5 minutes */ bputs("\r\ntimeout\r\n"); return; } } bputs("\r\n"); } getgamedat(1); node[node_num-1]=user_number; putgamedat(); if(!total_players) shuffle(); else listplayers(); sprintf(str,"\1n\1m\1h%s \1n\1m%s\r\n",user_name,joined()); putallnodemsg(str); while(1) { aborted=0; #if DEBUG debugline("top of loop"); #endif if(autoplay) lncntr=0; bprintf(ShoeStatus,cur_card,total_decks*52); if(cur_card>(total_decks*52)-(total_players*10)-10 && lastplayer()) shuffle(); getgamedat(1); misc&=~INPLAY; status[node_num-1]=BET; node[node_num-1]=user_number; putgamedat(); bprintf("\r\n\1n\1cYou have \1h%s\1n\1ck credits\r\n" ,ultoac(credits/1024L,str)); if(credits<min_bet/1024) { bprintf("\1n\1cMinimum bet: \1h%uk\r\n",min_bet); bputs("\1n\1r\1hCome back when you have more credits.\r\n"); break; } if(credits/1024L>(ulong)max_bet) max=max_bet; else max=credits/1024L; sprintf(str,"\r\nBet amount (in kilobytes) or ~Quit [%u]: " ,ibet<credits/1024L ? ibet : credits/1024L); chat(); mnemonics(str); if(autoplay && keyhit()) autoplay=0; if(autoplay) i=ibet; else i=getnum(max); if(i==-1) /* if user hit ^C or 'Q' */ break; bputs("\r\n"); if(i) /* if user entered a value */ bet[0]=i; else /* if user hit enter */ bet[0]=ibet<credits/1024L ? ibet : credits/1024L; if(bet[0]<min_bet) { bprintf("\1n\1cMinimum bet: \1h%uk\r\n",min_bet); bputs("\1n\1r\1hCome back when you're ready to bet more.\r\n"); break; } ibet=bet[0]; getgamedat(0); /* to get all new arrivals */ sprintf(str,"\1m\1h%s\1n\1m bet \1n\1h%u\1n\1mk\r\n",user_name,bet[0]); putallnodemsg(str); pc[0]=2; /* init player's 1st hand to 2 cards */ for(i=1;i<MAX_HANDS;i++) /* init player's other hands to 0 cards */ pc[i]=0; hands=1; /* init total player's hands to 1 */ getgamedat(1); /* first come first serve to be the */ for(i=0;i<total_nodes;i++) /* dealer in control of sync */ if(node[i] && status[i]==SYNC_D) break; if(i==total_nodes) { #if DEBUG debugline("syncdealer"); #endif syncdealer(); } /* all players meet here */ else { /* first player is current after here */ #if DEBUG debugline("syncplayer"); #endif syncplayer(); } /* game is closed (INPLAY) at this point */ #if DEBUG debugline("waitturn 1"); #endif waitturn(); getnodemsg(); /* Initial deal card #1 */ getcarddat(); player[0][0]=card[cur_card++]; putcarddat(); sprintf(str,YouWereDealt,cardstr(card[cur_card-1])); if(!symbols) strip_symbols(str); bputs(str); sprintf(str,UserWasDealt,user_name,cardstr(card[cur_card-1])); putallnodemsg(str); if(lastplayer()) { getcarddat(); dealer[0]=card[cur_card++]; dc=1; putcarddat(); } nextplayer(); #if DEBUG debugline("waitturn 2"); #endif waitturn(); getnodemsg(); getcarddat(); /* Initial deal card #2 */ player[0][1]=card[cur_card++]; putcarddat(); sprintf(str,YouWereDealt,cardstr(card[cur_card-1])); if(!symbols) strip_symbols(str); bputs(str); sprintf(str,UserWasDealt,user_name,cardstr(card[cur_card-1])); putallnodemsg(str); if(lastplayer()) { getcarddat(); dealer[1]=card[cur_card++]; dc=2; putcarddat(); } nextplayer(); #if DEBUG debugline("waitturn 3"); #endif waitturn(); getnodemsg(); getcarddat(); for(i=0;i<hands;i++) { if(autoplay) lncntr=0; done=doub=0; while(!done && pc[i]<MAX_CARDS && cur_card<total_decks*52) { h=hand(player[i],pc[i]); str[0]=0; for(j=0;j<pc[i];j++) { strcat(str,cardstr(player[i][j])); strcat(str," "); } j=bstrlen(str); while(j++<19) strcat(str," "); if(h>21) { strcat(str,Bust); sprintf(str2,YourHand,h,str); if(!symbols) strip_symbols(str2); bputs(str2); sprintf(str2,UserHand,user_name,h,str); putallnodemsg(str2); break; } if(h==21) { if(pc[i]==2) { /* blackjack */ if(player[i][0].suit==player[i][1].suit) strcat(str,Natural); strcat(str,Blackjack); } else { if(player[i][0].value==7 && player[i][1].value==7 && player[i][2].value==7) strcat(str,Three7s); strcat(str,TwentyOne); } sprintf(str2,YourHand,h,str); if(!symbols) strip_symbols(str2); bputs(str2); sprintf(str2,UserHand,user_name,h,str); putallnodemsg(str2); // fdelay(500); break; } strcat(str,"\r\n"); sprintf(str2,YourHand,h,str); if(!symbols) strip_symbols(str2); bputs(str2); sprintf(str2,UserHand,user_name,h,str); putallnodemsg(str2); if(doub) break; sprintf(str,"\1n\1hDealer\1n\1m card up: %s\r\n" ,cardstr(dealer[1])); if(!symbols) strip_symbols(str); bputs(str); if(tutor) { if(pc[i]==2) split_card=pair(player[i],pc[i]); else split_card=0; if(split_card==A || (split_card==9 && (dealer[1].value<7 || (dealer[1].value>7 && dealer[1].value<10))) || split_card==8 || (split_card==7 && dealer[1].value<9) || (split_card==6 && dealer[1].value<7) || (split_card==4 && dealer[1].value==5) || (split_card && split_card<4 && dealer[1].value<8)) suggestion='P'; else if(soft(player[i],pc[i])) { if(h>18) suggestion='S'; else if(pc[i]==2 && ((h==18 && dealer[1].value>3 && dealer[1].value<7) || (h==17 && dealer[1].value>2 && dealer[1].value<7) || (h>13 && dealer[1].value>3 && dealer[1].value<7) || (h==12 && dealer[1].value>4 && dealer[1].value<7))) suggestion='D'; else suggestion='H'; } else { /* hard */ if(h>16 || (h>13 && dealer[1].value<7) || (h==12 && dealer[1].value>3 && dealer[1].value<7)) suggestion='S'; else if(pc[i]==2 && (h==11 || (h==10 && dealer[1].value<10) || (h==9 && dealer[1].value<7))) suggestion='D'; else suggestion='H'; } } if(tutor==1) suggest(suggestion); strcpy(str,"\r\n~Hit"); strcpy(tmp,"H\r"); if(bet[i]+ibet<=credits/1024L && pc[i]==2) { strcat(str,", ~Double"); strcat(tmp,"D"); } if(bet[i]+ibet<=credits/1024L && pc[i]==2 && hands<MAX_HANDS && player[i][0].value==player[i][1].value) { strcat(str,", ~Split"); strcat(tmp,"S"); } strcat(str,", or [Stand]: "); chat(); mnemonics(str); if(autoplay && keyhit()) autoplay=0; if(autoplay) { lncntr=0; bputs("\r\n"); strcpy(str,stand()); bputs(str); putallnodemsg(str); done=1; } else switch(getkeys(tmp,0)) { case 'H': /* hit */ if(tutor==2 && suggestion!='H') wrong(suggestion); strcpy(str,hit()); bputs(str); putallnodemsg(str); getcarddat(); player[i][pc[i]++]=card[cur_card++]; putcarddat(); break; case 'D': /* double down */ if(tutor==2 && suggestion!='D') wrong(suggestion); strcpy(str,doubit()); bputs(str); putallnodemsg(str); getcarddat(); player[i][pc[i]++]=card[cur_card++]; putcarddat(); doub=1; bet[i]+=ibet; break; case 'S': /* split */ if(tutor==2 && suggestion!='P') wrong(suggestion); strcpy(str,split()); bputs(str); putallnodemsg(str); player[hands][0]=player[i][1]; getcarddat(); player[i][1]=card[cur_card++]; player[hands][1]=card[cur_card++]; putcarddat(); pc[hands]=2; bet[hands]=ibet; hands++; break; case CR: if(tutor==2 && suggestion!='S') wrong(suggestion); strcpy(str,stand()); bputs(str); putallnodemsg(str); done=1; break; } } } if(lastplayer()) { /* last player plays the dealer's hand */ getcarddat(); while(hand(dealer,dc)<17 && dc<MAX_CARDS && cur_card<total_decks*52) dealer[dc++]=card[cur_card++]; putcarddat(); } nextplayer(); #if DEBUG debugline("waitturn 4"); #endif waitturn(); getnodemsg(); if(firstplayer()==node_num) { strcpy(str,"\1n\0014\1h Final \1n\r\n"); bputs(str); putallnodemsg(str); } getcarddat(); dh=hand(dealer,dc); /* display dealer's hand */ sprintf(str,DealerHand,dh); for(i=0;i<dc;i++) { strcat(str,cardstr(dealer[i])); strcat(str," "); } i=bstrlen(str); while(i++<50) /* was 50 */ strcat(str," "); if(dh>21) { strcat(str,Bust); if(!symbols) strip_symbols(str); bputs(str); } else if(dh==21) { if(dc==2) { /* blackjack */ if(dealer[0].suit==dealer[1].suit) strcat(str,Natural); strcat(str,Blackjack); } else { /* twenty-one */ if(dc==3 && dealer[0].value==7 && dealer[1].value==7 && dealer[2].value==7) strcat(str,Three7s); strcat(str,TwentyOne); } if(!symbols) strip_symbols(str); bputs(str); } else { if(!symbols) strip_symbols(str); bprintf("%s\r\n",str); } for(i=0;i<hands;i++) { /* display player's hand(s) */ h=hand(player[i],pc[i]); str[0]=0; for(j=0;j<pc[i];j++) { strcat(str,cardstr(player[i][j])); strcat(str," "); } j=bstrlen(str); while(j++<19) strcat(str," "); if(logit) { now=time(NULL); tm=localtime(&now); sprintf(log,"%02d%02d%02d.log" /* log winnings */ ,tm->tm_mon+1,tm->tm_mday,tm->tm_year%100); if((file=nopen(log,O_RDONLY))!=-1) { read(file,tmp,filelength(file)); tmp[filelength(file)]=0; val=atol(tmp); close(file); } else val=0L; if((file=nopen(log,O_WRONLY|O_CREAT|O_TRUNC))==-1) { bprintf("error opening %s\r\n",log); return; } } if(h<22 && (h>dh || dh>21 /* player won */ || (h==21 && pc[i]==2 && dh==21 && dh>2))) { /* blackjack */ j=bet[i]; /* and dealer got 21 */ if(h==21 && /* natural blackjack or three 7's */ ((player[i][0].value==7 && player[i][1].value==7 && player[i][2].value==7) || (pc[i]==2 && player[i][0].suit==player[i][1].suit))) j*=2; else if(h==21 && pc[i]==2) /* regular blackjack */ j*=1.5; /* blackjack pays 1 1/2 to 1 */ sprintf(tmp,"\1n\1h\1m\1iWon!\1n\1h %u\1n\1mk",j); strcat(str,tmp); credits+=j*1024L; val-=j*1024L; moduserdat(); } else if(h<22 && h==dh) strcat(str,"\1n\1hPush"); else { strcat(str,"\1nLost"); credits-=bet[i]*1024L; val+=bet[i]*1024L; moduserdat(); } if(logit) { sprintf(tmp,"%ld",val); write(file,tmp,strlen(tmp)); close(file); } /* close winning log */ strcat(str,"\1n\r\n"); sprintf(str2,YourHand,h,str); if(!symbols) strip_symbols(str2); bputs(str2); sprintf(str2,UserHand,user_name,h,str); putallnodemsg(str2); } nextplayer(); if(!lastplayer()) { #if DEBUG debugline("lastplayer waitturn"); #endif waitturn(); nextplayer(); } #if DEBUG debugline("end of loop"); #endif getnodemsg(); } getgamedat(1); node[node_num-1]=0; putgamedat(); sprintf(str,"\1n\1m\1h%s \1n\1m%s\r\n",user_name,left()); putallnodemsg(str); }
int main(int argc, char **argv) { char str[81],compiler[32],*p; int i,file; FILE *stream; node_dir[0]=0; for(i=1;i<argc;i++) if(!stricmp(argv[i],"/L")) logit=1; else if(!stricmp(argv[i],"/T")) tutor=2; else if(!stricmp(argv[i],"/S")) tutor=1; else strcpy(node_dir,argv[i]); p=getenv("SBBSNODE"); if(!node_dir[0] && p) strcpy(node_dir,p); if(!node_dir[0]) { /* node directory not specified */ printf("usage: sbj <node directory> [/options]\r\n"); printf("\r\noptions: L = log wins/losses for each day\r\n"); getch(); return(1); } if(node_dir[strlen(node_dir)-1]!='\\' && node_dir[strlen(node_dir)-1]!='/') /* make sure node_dir ends in '\' */ strcat(node_dir,"/"); initdata(); /* read XTRN.DAT and more */ credits=user_cdt; total_nodes=sys_nodes; remove("debug.log"); if((file=nopen("sbj.cfg",O_RDONLY))==-1) { /* open config file */ bputs("Error opening sbj.cfg\r\n"); pause(); return(1); } if((stream=fdopen(file,"rb"))==NULL) { /* convert to stream */ bputs("Error converting sbj.cfg handle to stream\r\n"); pause(); return(1); } fgets(str,81,stream); /* number of decks in shoe */ total_decks=sys_decks=atoi(str); fgets(str,81,stream); /* min bet (in k) */ min_bet=atoi(str); fgets(str,81,stream); /* max bet (in k) */ max_bet=atoi(str); fgets(str,81,stream); /* default bet (in k) */ ibet=atoi(str); fclose(stream); if(!total_decks || total_decks>MAX_DECKS) { bputs("Invalid number of decks in sbj.cfg\r\n"); pause(); return(1); } if(!max_bet) { bputs("Invalid max bet in sbj.cfg\r\n"); pause(); return(1); } if(min_bet>max_bet) { bputs("Invalid min bet in sbj.cfg\r\n"); pause(); return(1); } if(ibet>max_bet || ibet<min_bet) { bputs("Invalid default bet in sbj.cfg\r\n"); pause(); return(1); } if(!fexist("card.dab")) { cur_card=0; dc=0; memset(dealer,0,sizeof(dealer)); memset(card,0,sizeof(card)); putcarddat(); } else { getcarddat(); if(total_decks!=sys_decks) { remove("card.dab"); total_decks=sys_decks; putcarddat(); } } if(!fexist("game.dab")) /* File's not there */ create_gamedab(); open_gamedab(); getgamedat(0); if(total_nodes!=sys_nodes) { /* total nodes changed */ close(gamedab); total_nodes=sys_nodes; create_gamedab(); open_gamedab(); } srand((unsigned)time(NULL)); #ifdef __16BIT__ while(_bios_keybrd(1)) /* clear input buffer */ _bios_keybrd(0); #endif putchar(5); /* ctrl-e */ mswait(500); if(keyhit()) { #ifdef __16BIT__ while(_bios_keybrd(1)) _bios_keybrd(0); #else getkey(0); #endif bputs("\r\n\1r\1h\1i*** ATTENTION ***\1n\1h\r\n"); bputs("\r\nSynchronet Blackjack uses Ctrl-E (ENQ) for the 'club' card " "symbol."); bputs("\r\nYour terminal responded to this control character with an " "answerback string."); bputs("\r\nYou will need to disable all Ctrl-E (ENQ) answerback " "strings (Including \r\nCompuserve Quick B transfers) if you wish to " "toggle card symbols on.\r\n\r\n"); symbols=0; pause(); } getgamedat(1); node[node_num-1]=0; putgamedat(); /* Override default mnemonic colors */ mnehigh=RED|HIGH; mnelow=CYAN|HIGH; /* Override default inactivity timeout values */ sec_warn=120; sec_timeout=180; COMPILER_DESC(compiler); #define SBJ_INDENT " " while(1) { cls(); sprintf(str,"\1n\1h\1cSynchronet \1rBlackjack! \1cv3.20 for %s\r\n" ,PLATFORM_DESC); center(str); sprintf(str,"\1w(XSDK v%s %s %s)\r\n\r\n" ,xsdk_ver,compiler,__DATE__); center(str); aborted=0; mnemonics(SBJ_INDENT"~Instructions\r\n"); mnemonics(SBJ_INDENT"~Join/Begin Game\r\n"); mnemonics(SBJ_INDENT"~List Players\r\n"); mnemonics(SBJ_INDENT"~Rules of the Game\r\n"); mnemonics(SBJ_INDENT"~Toggle Card Symbols\r\n"); sprintf(str,SBJ_INDENT"~Quit to %s\r\n",sys_name); mnemonics(str); nodesync(); bprintf("\1_\r\n"SBJ_INDENT"\1y\1hWhich: \1n"); switch(getkeys("IJBLRTQ|!",0)) { #if DEBUG case '!': if(!com_port) autoplay=1; break; case '|': debug(); break; #endif case 'I': cls(); printfile("sbj.msg"); break; case 'L': listplayers(); bprintf(ShoeStatus,cur_card,total_decks*52); break; case 'R': bprintf("\1n\1c\r\nMinimum bet: \1h%uk",min_bet); bprintf("\1n\1c\r\nMaximum bet: \1h%uk\r\n",max_bet); bprintf("\1w\1h\r\nCard decks in shoe: \1h%u\r\n",sys_decks); break; case 'T': symbols=!symbols; bprintf("\1_\1w\r\nCard symbols now: %s\r\n",symbols ? "ON":"OFF"); break; case 'Q': exit(0); case 'J': case 'B': sec_warn=60; /* Override default inactivity timeout values */ sec_timeout=90; play(); sec_warn=120; sec_timeout=180; break; } } }
int sbbs_t::text_sec() { char str[256],usemenu ,*file[MAX_TXTFILES],addpath[83],addstr[83],*buf,ch; char tmp[512]; long i,j,usrsec[MAX_TXTSECS],usrsecs,cursec; long l,length; FILE *stream; for(i=j=0;i<cfg.total_txtsecs;i++) { if(!chk_ar(cfg.txtsec[i]->ar,&useron,&client)) continue; usrsec[j++]=i; } usrsecs=j; if(!usrsecs) { bputs(text[NoTextSections]); return(1); } action=NODE_RTXT; while(online) { sprintf(str,"%smenu/text_sec.*",cfg.text_dir); if(fexist(str)) menu("text_sec"); else { bputs(text[TextSectionLstHdr]); for(i=0;i<usrsecs && !msgabort();i++) { sprintf(str,text[TextSectionLstFmt],i+1,cfg.txtsec[usrsec[i]]->name); if(i<9) outchar(' '); bputs(str); } } ASYNC; mnemonics(text[WhichTextSection]); if((cursec=getnum(usrsecs))<1) break; cursec--; while(online) { sprintf(str,"%smenu/text%lu.*",cfg.text_dir,cursec+1); if(fexist(str)) { sprintf(str,"text%lu",cursec+1); menu(str); usemenu=1; } else { bprintf(text[TextFilesLstHdr],cfg.txtsec[usrsec[cursec]]->name); usemenu=0; } sprintf(str,"%stext/%s.ixt",cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code); j=0; if(fexist(str)) { if((stream=fnopen((int *)&i,str,O_RDONLY))==NULL) { errormsg(WHERE,ERR_OPEN,str,O_RDONLY); return(0); } while(!ferror(stream) && !msgabort()) { /* file open too long */ if(!fgets(str,81,stream)) break; str[strlen(str)-2]=0; /* chop off CRLF */ if((file[j]=(char *)malloc(strlen(str)+1))==NULL) { errormsg(WHERE,ERR_ALLOC,nulstr,strlen(str)+1); continue; } strcpy(file[j],str); fgets(str,81,stream); if(!usemenu) bprintf(text[TextFilesLstFmt],j+1,str); j++; } fclose(stream); } ASYNC; if(SYSOP) { strcpy(str,"QARE?"); mnemonics(text[WhichTextFileSysop]); } else { strcpy(str,"Q?"); mnemonics(text[WhichTextFile]); } i=getkeys(str,j); if(!(i&0x80000000L)) { /* no file number */ for(l=0;l<j;l++) free(file[l]); if((i=='E' || i=='R') && !j) continue; } if(i=='Q' || !i) break; if(i==-1) { /* ctrl-c */ for(i=0;i<j;i++) free(file[i]); return(0); } if(i=='?') /* ? means re-list */ continue; if(i=='A') { /* Add text file */ if(j) { bputs(text[AddTextFileBeforeWhich]); i=getnum(j+1); if(i<1) continue; i--; /* number of file entries to skip */ } else i=0; bprintf(text[AddTextFilePath] ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code); if(!getstr(addpath,80,0)) continue; strcat(addpath,crlf); bputs(text[AddTextFileDesc]); if(!getstr(addstr,74,0)) continue; strcat(addstr,crlf); sprintf(str,"%stext/%s.ixt" ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code); if(i==j) { /* just add to end */ if((i=nopen(str,O_WRONLY|O_APPEND|O_CREAT))==-1) { errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_APPEND|O_CREAT); return(0); } write(i,addpath,strlen(addpath)); write(i,addstr,strlen(addstr)); close(i); continue; } j=i; /* inserting in middle of file */ if((stream=fnopen((int *)&i,str,O_RDWR))==NULL) { errormsg(WHERE,ERR_OPEN,str,O_RDWR); return(0); } length=(long)filelength(i); for(i=0;i<j;i++) { /* skip two lines for each entry */ fgets(tmp,81,stream); fgets(tmp,81,stream); } l=(long)ftell(stream); if((buf=(char *)malloc(length-l))==NULL) { fclose(stream); errormsg(WHERE,ERR_ALLOC,str,length-l); return(0); } fread(buf,1,length-l,stream); fseek(stream,l,SEEK_SET); /* go back to where we need to insert */ fputs(addpath,stream); fputs(addstr,stream); fwrite(buf,1,length-l,stream); fclose(stream); free(buf); continue; } if(i=='R' || i=='E') { /* Remove or Edit text file */ ch=(char)i; if(ch=='R') bputs(text[RemoveWhichTextFile]); else bputs(text[EditWhichTextFile]); i=getnum(j); if(i<1) continue; sprintf(str,"%stext/%s.ixt" ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code); j=i-1; if((stream=fnopen(NULL,str,O_RDONLY))==NULL) { errormsg(WHERE,ERR_OPEN,str,O_RDONLY); return(0); } for(i=0;i<j;i++) { /* skip two lines for each entry */ fgets(tmp,81,stream); fgets(tmp,81,stream); } fgets(addpath,81,stream); truncsp(addpath); fclose(stream); if(!strchr(addpath,'\\') && !strchr(addpath,'/')) sprintf(tmp,"%stext/%s/%s" ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code,addpath); else strcpy(tmp,addpath); if(ch=='R') { /* Remove */ if(fexist(tmp)) { sprintf(str,text[DeleteTextFileQ],tmp); if(!noyes(str)) if(remove(tmp)) errormsg(WHERE,ERR_REMOVE,tmp,0); } sprintf(str,"%stext/%s.ixt" ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code); removeline(str,addpath,2,0); } else { /* Edit */ strcpy(str,tmp); editfile(str); } continue; } i=(i&~0x80000000L)-1; if(!strchr(file[i],'\\') && !strchr(file[i],'/')) sprintf(str,"%stext/%s/%s" ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code,file[i]); else strcpy(str,file[i]); fexistcase(str); attr(LIGHTGRAY); printfile(str,0); sprintf(str,"%s read text file: %s" ,useron.alias,file[i]); logline("T-",str); pause(); sys_status&=~SS_ABORT; for(i=0;i<j;i++) free(file[i]); } } return(0); }
int sbbs_t::exec_file(csi_t *csi) { char str[256],ch; int s; uint i,j,x,y; file_t f; switch(*(csi->ip++)) { case CS_FILE_SELECT_AREA: csi->logic=LOGIC_FALSE; if(!usrlibs) return(0); while(online) { j=0; if(usrlibs>1) { sprintf(str,"%smenu/libs.*", cfg.text_dir); if(fexist(str)) menu("libs"); else { bputs(text[CfgLibLstHdr]); for(i=0;i<usrlibs && !msgabort();i++) { if(i==curlib) outchar('*'); else outchar(' '); if(i<9) outchar(' '); if(i<99) outchar(' '); bprintf(text[CfgLibLstFmt] ,i+1,cfg.lib[usrlib[i]]->lname); } } sprintf(str,text[JoinWhichLib],curlib+1); mnemonics(str); j=getnum(usrlibs); if((int)j==-1) return(0); if(!j) j=curlib; else j--; } sprintf(str,"%smenu/dirs%u.*", cfg.text_dir, usrlib[j]+1); if(fexist(str)) { sprintf(str,"dirs%u",usrlib[j]+1); menu(str); } else { CLS; bprintf(text[DirLstHdr], cfg.lib[usrlib[j]]->lname); for(i=0;i<usrdirs[j] && !msgabort();i++) { if(i==curdir[j]) outchar('*'); else outchar(' '); sprintf(str,text[DirLstFmt],i+1 ,cfg.dir[usrdir[j][i]]->lname,nulstr ,getfiles(&cfg,usrdir[j][i])); if(i<9) outchar(' '); if(i<99) outchar(' '); bputs(str); } } sprintf(str,text[JoinWhichDir],curdir[j]+1); mnemonics(str); i=getnum(usrdirs[j]); if((int)i==-1) { if(usrlibs==1) return(0); continue; } if(!i) i=curdir[j]; else i--; curlib=j; curdir[curlib]=i; csi->logic=LOGIC_TRUE; return(0); } return(0); case CS_FILE_GET_DIR_NUM: if(useron.misc&COLDKEYS) { i=atoi(csi->str); if(i && i<=usrdirs[curlib] && usrlibs) curdir[curlib]=i-1; return(0); } ch=getkey(K_UPPER); outchar(ch); if((ch&0xf)*10U<=usrdirs[curlib] && (ch&0xf) && usrlibs) { i=(ch&0xf)*10; ch=getkey(K_UPPER); if(!isdigit(ch) && ch!=CR) { ungetkey(ch); curdir[curlib]=(i/10)-1; return(0); } outchar(ch); if(ch==CR) { curdir[curlib]=(i/10)-1; return(0); } logch(ch,0); i+=ch&0xf; if(i*10<=usrdirs[curlib]) { /* 100+ dirs */ i*=10; ch=getkey(K_UPPER); if(!isdigit(ch) && ch!=CR) { ungetkey(ch); curdir[curlib]=(i/10)-1; return(0); } outchar(ch); if(ch==CR) { curdir[curlib]=(i/10)-1; return(0); } logch(ch,0); i+=ch&0xf; } if(i<=usrdirs[curlib]) curdir[curlib]=i-1; return(0); } if((ch&0xf)<=(int)usrdirs[curlib] && (ch&0xf) && usrlibs) curdir[curlib]=(ch&0xf)-1; return(0); case CS_FILE_GET_LIB_NUM: if(useron.misc&COLDKEYS) { i=atoi(csi->str); if(i && i<=usrlibs) curlib=i-1; return(0); } ch=getkey(K_UPPER); outchar(ch); if((ch&0xf)*10U<=usrlibs && (ch&0xf)) { i=(ch&0xf)*10; ch=getkey(K_UPPER); if(!isdigit(ch) && ch!=CR) { ungetkey(ch); curlib=(i/10)-1; return(0); } outchar(ch); if(ch==CR) { curlib=(i/10)-1; return(0); } logch(ch,0); i+=ch&0xf; if(i<=usrlibs) curlib=i-1; return(0); } if((ch&0xf)<=(int)usrlibs && (ch&0xf)) curlib=(ch&0xf)-1; return(0); case CS_FILE_SHOW_LIBRARIES: if(!usrlibs) return(0); sprintf(str,"%smenu/libs.*", cfg.text_dir); if(fexist(str)) { menu("libs"); return(0); } bputs(text[LibLstHdr]); for(i=0;i<usrlibs && !msgabort();i++) { if(i==curlib) outchar('*'); else outchar(' '); if(i<9) outchar(' '); bprintf(text[LibLstFmt],i+1 ,cfg.lib[usrlib[i]]->lname,nulstr,usrdirs[i]); } return(0); case CS_FILE_SHOW_DIRECTORIES: if(!usrlibs) return(0); sprintf(str,"%smenu/dirs%u.*", cfg.text_dir, usrlib[curlib]+1); if(fexist(str)) { sprintf(str,"dirs%u",usrlib[curlib]+1); menu(str); return(0); } CRLF; bprintf(text[DirLstHdr],cfg.lib[usrlib[curlib]]->lname); for(i=0;i<usrdirs[curlib] && !msgabort();i++) { if(i==curdir[curlib]) outchar('*'); else outchar(' '); sprintf(str,text[DirLstFmt],i+1 ,cfg.dir[usrdir[curlib][i]]->lname,nulstr ,getfiles(&cfg,usrdir[curlib][i])); if(i<9) outchar(' '); if(i<99) outchar(' '); bputs(str); } return(0); case CS_FILE_LIBRARY_UP: curlib++; if(curlib>=usrlibs) curlib=0; return(0); case CS_FILE_LIBRARY_DOWN: if(!curlib) curlib=usrlibs-1; else curlib--; return(0); case CS_FILE_DIRECTORY_UP: if(!usrlibs) return(0); curdir[curlib]++; if(curdir[curlib]>=usrdirs[curlib]) curdir[curlib]=0; return(0); case CS_FILE_DIRECTORY_DOWN: if(!usrlibs) return(0); if(!curdir[curlib]) curdir[curlib]=usrdirs[curlib]-1; else curdir[curlib]--; return(0); case CS_FILE_SET_AREA: csi->logic=LOGIC_TRUE; for(i=0;i<usrlibs;i++) for(j=0;j<usrdirs[i];j++) if(!stricmp(csi->str,cfg.dir[usrdir[i][j]]->code)) { curlib=i; curdir[i]=j; return(0); } csi->logic=LOGIC_FALSE; return(0); case CS_FILE_SET_LIBRARY: csi->logic=LOGIC_TRUE; for(i=0;i<usrlibs;i++) if(!stricmp(cfg.lib[usrlib[i]]->sname,csi->str)) break; if(i<usrlibs) curlib=i; else csi->logic=LOGIC_FALSE; return(0); case CS_FILE_UPLOAD: csi->logic=LOGIC_FALSE; if(usrlibs) { i=usrdir[curlib][curdir[curlib]]; if(cfg.upload_dir!=INVALID_DIR && !dir_op(i) && !(useron.exempt&FLAG('U')) && !chk_ar(cfg.dir[i]->ul_ar,&useron,&client)) i=cfg.upload_dir; } else i=cfg.upload_dir; csi->logic=upload(i) ? LOGIC_TRUE:LOGIC_FALSE; return(0); case CS_FILE_UPLOAD_USER: csi->logic=LOGIC_FALSE; if(cfg.user_dir==INVALID_DIR) { bputs(text[NoUserDir]); return(0); } csi->logic=upload(cfg.user_dir) ? LOGIC_TRUE:LOGIC_FALSE; return(0); case CS_FILE_UPLOAD_SYSOP: csi->logic=LOGIC_FALSE; if(cfg.sysop_dir==INVALID_DIR) { bputs(text[NoSysopDir]); return(0); } csi->logic=upload(cfg.sysop_dir) ? LOGIC_TRUE:LOGIC_FALSE; return(0); case CS_FILE_DOWNLOAD: if(!usrlibs) return(0); if(useron.rest&FLAG('D')) { bputs(text[R_Download]); return(0); } padfname(csi->str,str); strupr(str); if(!listfileinfo(usrdir[curlib][curdir[curlib]],str,FI_DOWNLOAD)) { bputs(text[SearchingAllDirs]); for(i=0;i<usrdirs[curlib];i++) if(i!=curdir[curlib] && (s=listfileinfo(usrdir[curlib][i],str,FI_DOWNLOAD))!=0) if(s==-1 || (!strchr(str,'?') && !strchr(str,'*'))) return(0); bputs(text[SearchingAllLibs]); for(i=0;i<usrlibs;i++) { if(i==curlib) continue; for(j=0;j<usrdirs[i];j++) if((s=listfileinfo(usrdir[i][j],str,FI_DOWNLOAD))!=0) if(s==-1 || (!strchr(str,'?') && !strchr(str,'*'))) return(0); } } return(0); case CS_FILE_DOWNLOAD_USER: /* Download from user dir */ csi->logic=LOGIC_FALSE; if(cfg.user_dir==INVALID_DIR) { bputs(text[NoUserDir]); return(0); } if(useron.rest&FLAG('D')) { bputs(text[R_Download]); return(0); } CRLF; if(!listfileinfo(cfg.user_dir,nulstr,FI_USERXFER)) bputs(text[NoFilesForYou]); else csi->logic=LOGIC_TRUE; return(0); case CS_FILE_DOWNLOAD_BATCH: if(batdn_total && (text[DownloadBatchQ][0]==0 || yesno(text[DownloadBatchQ]))) { start_batch_download(); csi->logic=LOGIC_TRUE; } else csi->logic=LOGIC_FALSE; return(0); case CS_FILE_BATCH_ADD_LIST: batch_add_list(csi->str); return(0); case CS_FILE_BATCH_ADD: csi->logic=LOGIC_FALSE; if(!csi->str[0]) return(0); padfname(csi->str,f.name); for(x=y=0;x<usrlibs;x++) { for(y=0;y<usrdirs[x];y++) if(findfile(&cfg,usrdir[x][y],f.name)) break; if(y<usrdirs[x]) break; } if(x>=usrlibs) return(0); f.dir=usrdir[x][y]; getfileixb(&cfg,&f); f.size=0; getfiledat(&cfg,&f); addtobatdl(&f); csi->logic=LOGIC_TRUE; return(0); case CS_FILE_BATCH_CLEAR: if(!batdn_total) { csi->logic=LOGIC_FALSE; return(0); } csi->logic=LOGIC_TRUE; for(i=0;i<batdn_total;i++) { f.dir=batdn_dir[i]; f.datoffset=batdn_offset[i]; f.size=batdn_size[i]; strcpy(f.name,batdn_name[i]); closefile(&f); } batdn_total=0; return(0); case CS_FILE_VIEW: if(!usrlibs) return(0); padfname(csi->str,str); strupr(str); csi->logic=LOGIC_TRUE; if(listfiles(usrdir[curlib][curdir[curlib]],str,0,FL_VIEW)) return(0); bputs(text[SearchingAllDirs]); for(i=0;i<usrdirs[curlib];i++) { if(i==curdir[curlib]) continue; if(listfiles(usrdir[curlib][i],str,0,FL_VIEW)) break; } if(i<usrdirs[curlib]) return(0); bputs(text[SearchingAllLibs]); for(i=0;i<usrlibs;i++) { if(i==curlib) continue; for(j=0;j<usrdirs[i];j++) if(listfiles(usrdir[i][j],str,0,FL_VIEW)) return(0); } csi->logic=LOGIC_FALSE; bputs(text[FileNotFound]); return(0); case CS_FILE_LIST: /* List files in current dir */ if(!usrlibs) return(0); csi->logic=LOGIC_FALSE; if(!getfiles(&cfg,usrdir[curlib][curdir[curlib]])) { bputs(text[EmptyDir]); return(0); } padfname(csi->str,str); strupr(str); s=listfiles(usrdir[curlib][curdir[curlib]],str,0,0); if(s>1) { bprintf(text[NFilesListed],s); } csi->logic=!s; return(0); case CS_FILE_LIST_EXTENDED: /* Extended Information on files */ if(!usrlibs) return(0); padfname(csi->str,str); strupr(str); if(!listfileinfo(usrdir[curlib][curdir[curlib]],str,FI_INFO)) { bputs(text[SearchingAllDirs]); for(i=0;i<usrdirs[curlib];i++) if(i!=curdir[curlib] && (s=listfileinfo(usrdir[curlib][i] ,str,FI_INFO))!=0) if(s==-1 || (!strchr(str,'?') && !strchr(str,'*'))) return(0); bputs(text[SearchingAllLibs]); for(i=0;i<usrlibs;i++) { if(i==curlib) continue; for(j=0;j<usrdirs[i];j++) if((s=listfileinfo(usrdir[i][j],str,FI_INFO))!=0) if(s==-1 || (!strchr(str,'?') && !strchr(str,'*'))) return(0); } } return(0); case CS_FILE_FIND_TEXT: /* Find text in descriptions */ scandirs(FL_FINDDESC); return(0); case CS_FILE_FIND_TEXT_ALL: /* Find text in descriptions */ scanalldirs(FL_FINDDESC); return(0); case CS_FILE_FIND_NAME: /* Find text in descriptions */ scandirs(FL_NO_HDR); return(0); case CS_FILE_FIND_NAME_ALL: /* Find text in descriptions */ scanalldirs(FL_NO_HDR); return(0); case CS_FILE_BATCH_SECTION: batchmenu(); return(0); case CS_FILE_TEMP_SECTION: temp_xfer(); return(0); case CS_FILE_PTRS_CFG: csi->logic=!inputnstime(&ns_time); return(0); case CS_FILE_NEW_SCAN: scandirs(FL_ULTIME); return(0); case CS_FILE_NEW_SCAN_ALL: scanalldirs(FL_ULTIME); return(0); case CS_FILE_REMOVE: if(!usrlibs) return(0); if(useron.rest&FLAG('R')) { bputs(text[R_RemoveFiles]); return(0); } padfname(csi->str,str); strupr(str); if(!listfileinfo(usrdir[curlib][curdir[curlib]],str,FI_REMOVE)) { if(cfg.user_dir!=INVALID_DIR && cfg.user_dir!=usrdir[curlib][curdir[curlib]]) if((s=listfileinfo(cfg.user_dir,str,FI_REMOVE))!=0) if(s==-1 || (!strchr(str,'?') && !strchr(str,'*'))) return(0); bputs(text[SearchingAllDirs]); for(i=0;i<usrdirs[curlib];i++) if(i!=curdir[curlib] && i!=cfg.user_dir && (s=listfileinfo(usrdir[curlib][i],str,FI_REMOVE))!=0) if(s==-1 || (!strchr(str,'?') && !strchr(str,'*'))) return(0); bputs(text[SearchingAllLibs]); for(i=0;i<usrlibs;i++) { if(i==curlib || i==cfg.user_dir) continue; for(j=0;j<usrdirs[i]; j++) if((s=listfileinfo(usrdir[i][j],str,FI_REMOVE))!=0) if(s==-1 || (!strchr(str,'?') && !strchr(str,'*'))) return(0); } } return(0); } errormsg(WHERE,ERR_CHK,"shell function",*(csi->ip-1)); return(0); }
bool sbbs_t::inetmail(char *into, char *subj, long mode) { char str[256],str2[256],msgpath[256],title[256],name[256],ch ,buf[SDT_BLOCK_LEN],*p,addr[256]; char tmp[512]; char your_addr[128]; ushort xlat=XLAT_NONE,net=NET_INTERNET; int i,j,x,file; long l; ulong length,offset; FILE *instream; smbmsg_t msg; if(useron.etoday>=cfg.level_emailperday[useron.level] && !SYSOP) { bputs(text[TooManyEmailsToday]); return(false); } strcpy(name,into); strcpy(addr,into); strcpy(title,subj); if((!SYSOP && !(cfg.inetmail_misc&NMAIL_ALLOW)) || useron.rest&FLAG('M')) { bputs(text[NoNetMailAllowed]); return(false); } if(cfg.inetmail_cost && !(useron.exempt&FLAG('S'))) { if(useron.cdt+useron.freecdt<cfg.inetmail_cost) { bputs(text[NotEnoughCredits]); return(false); } sprintf(str,text[NetMailCostContinueQ],cfg.inetmail_cost); if(noyes(str)) return(false); } /* Get destination user name */ p=strrchr(name,'@'); if(!p) p=strrchr(name,'!'); if(p) { *p=0; truncsp(name); } /* Get this user's internet mailing address */ usermailaddr(&cfg,your_addr ,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name); bprintf(text[InternetMailing],addr,your_addr); action=NODE_SMAL; nodesync(); sprintf(msgpath,"%snetmail.msg",cfg.node_dir); if(!writemsg(msgpath,nulstr,title,mode,INVALID_SUB,into)) { bputs(text[Aborted]); return(false); } if(mode&WM_FILE) { sprintf(str2,"%sfile/%04u.out",cfg.data_dir,useron.number); MKDIR(str2); sprintf(str2,"%sfile/%04u.out/%s",cfg.data_dir,useron.number,title); if(fexistcase(str2)) { bputs(text[FileAlreadyThere]); remove(msgpath); return(false); } #if 0 /* no such thing as local logon */ if(online==ON_LOCAL) { /* Local upload */ bputs(text[EnterPath]); if(!getstr(str,60,K_LINE|K_UPPER)) { bputs(text[Aborted]); remove(msgpath); return(false); } backslash(str); strcat(str,title); mv(str,str2,1); } else #endif { /* Remote */ xfer_prot_menu(XFER_UPLOAD); mnemonics(text[ProtocolOrQuit]); strcpy(str,"Q"); for(x=0;x<cfg.total_prots;x++) if(cfg.prot[x]->ulcmd[0] && chk_ar(cfg.prot[x]->ar,&useron)) { sprintf(tmp,"%c",cfg.prot[x]->mnemonic); strcat(str,tmp); } ch=(char)getkeys(str,0); if(ch=='Q' || sys_status&SS_ABORT) { bputs(text[Aborted]); remove(msgpath); return(false); } for(x=0;x<cfg.total_prots;x++) if(cfg.prot[x]->ulcmd[0] && cfg.prot[x]->mnemonic==ch && chk_ar(cfg.prot[x]->ar,&useron)) break; if(x<cfg.total_prots) /* This should be always */ protocol(cfg.prot[x],XFER_UPLOAD,str2,nulstr,true); } sprintf(tmp,"%s%s",cfg.temp_dir,title); if(!fexistcase(str2) && fexistcase(tmp)) mv(tmp,str2,0); l=flength(str2); if(l>0) bprintf(text[FileNBytesReceived],title,ultoac(l,tmp)); else { bprintf(text[FileNotReceived],title); remove(msgpath); return(false); } } if((i=smb_stack(&smb,SMB_STACK_PUSH))!=SMB_SUCCESS) { errormsg(WHERE,ERR_OPEN,"MAIL",i); return(false); } sprintf(smb.file,"%smail",cfg.data_dir); smb.retry_time=cfg.smb_retry_time; smb.subnum=INVALID_SUB; if((i=smb_open(&smb))!=SMB_SUCCESS) { smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); return(false); } if(filelength(fileno(smb.shd_fp))<1) { /* Create it if it doesn't exist */ smb.status.max_crcs=cfg.mail_maxcrcs; smb.status.max_age=cfg.mail_maxage; smb.status.max_msgs=0; smb.status.attr=SMB_EMAIL; if((i=smb_create(&smb))!=SMB_SUCCESS) { smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_CREATE,smb.file,i); return(false); } } if((i=smb_locksmbhdr(&smb))!=SMB_SUCCESS) { smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_LOCK,smb.file,i); return(false); } length=flength(msgpath)+2; /* +2 for translation string */ if(length&0xfff00000UL) { smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_LEN,msgpath,length); return(false); } if((i=smb_open_da(&smb))!=SMB_SUCCESS) { smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); return(false); } if(cfg.sys_misc&SM_FASTMAIL) offset=smb_fallocdat(&smb,length,1); else offset=smb_allocdat(&smb,length,1); smb_close_da(&smb); if((file=open(msgpath,O_RDONLY|O_BINARY))==-1 || (instream=fdopen(file,"rb"))==NULL) { smb_freemsgdat(&smb,offset,length,1); smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,msgpath,O_RDONLY|O_BINARY); return(false); } setvbuf(instream,NULL,_IOFBF,2*1024); fseek(smb.sdt_fp,offset,SEEK_SET); xlat=XLAT_NONE; fwrite(&xlat,2,1,smb.sdt_fp); x=SDT_BLOCK_LEN-2; /* Don't read/write more than 255 */ while(!feof(instream)) { memset(buf,0,x); j=fread(buf,1,x,instream); if(j<1) break; if(j>1 && (j!=x || feof(instream)) && buf[j-1]==LF && buf[j-2]==CR) buf[j-1]=buf[j-2]=0; fwrite(buf,j,1,smb.sdt_fp); x=SDT_BLOCK_LEN; } fflush(smb.sdt_fp); fclose(instream); memset(&msg,0,sizeof(smbmsg_t)); msg.hdr.version=smb_ver(); if(mode&WM_FILE) msg.hdr.auxattr|=MSG_FILEATTACH; msg.hdr.when_written.time=msg.hdr.when_imported.time=time(NULL); msg.hdr.when_written.zone=msg.hdr.when_imported.zone=sys_timezone(&cfg); msg.hdr.offset=offset; net=NET_INTERNET; smb_hfield_str(&msg,RECIPIENT,name); smb_hfield(&msg,RECIPIENTNETTYPE,sizeof(net),&net); smb_hfield_str(&msg,RECIPIENTNETADDR,addr); strcpy(str,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name); smb_hfield_str(&msg,SENDER,str); sprintf(str,"%u",useron.number); smb_hfield_str(&msg,SENDEREXT,str); /* smb_hfield(&msg,SENDERNETTYPE,sizeof(net),&net); smb_hfield(&msg,SENDERNETADDR,strlen(sys_inetaddr),sys_inetaddr); */ /* Security logging */ msg_client_hfields(&msg,&client); smb_hfield_str(&msg,SUBJECT,title); strcpy(str,title); smb_dfield(&msg,TEXT_BODY,length); i=smb_addmsghdr(&smb,&msg,SMB_SELFPACK); // calls smb_unlocksmbhdr() smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); smb_freemsgmem(&msg); if(i!=SMB_SUCCESS) { errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error); smb_freemsgdat(&smb,offset,length,1); return(false); } if(mode&WM_FILE && online==ON_REMOTE) autohangup(); if(cfg.inetmail_sem[0]) /* update semaphore file */ ftouch(cmdstr(cfg.inetmail_sem,nulstr,nulstr,NULL)); if(!(useron.exempt&FLAG('S'))) subtract_cdt(&cfg,&useron,cfg.inetmail_cost); useron.emails++; logon_emails++; putuserrec(&cfg,useron.number,U_EMAILS,5,ultoa(useron.emails,tmp,10)); useron.etoday++; putuserrec(&cfg,useron.number,U_ETODAY,5,ultoa(useron.etoday,tmp,10)); sprintf(str,"%s sent Internet Mail to %s (%s)" ,useron.alias ,name,addr); logline("EN",str); return(true); }
void sbbs_t::scansubs(long mode) { char ch,str[256]; char tmp[512]; uint i=0,found=0; ulong subs_scanned=0; mnemonics(text[SubGroupOrAll]); ch=(char)getkeys("SGA\r",0); if(sys_status&SS_ABORT || ch==CR) return; if(ch!='A' && mode&(SCAN_FIND|SCAN_TOYOU)) { if(text[DisplaySubjectsOnlyQ][0] && yesno(text[DisplaySubjectsOnlyQ])) i=1; if(mode&SCAN_FIND) { bputs(text[SearchStringPrompt]); if(!getstr(str,40,K_LINE|K_UPPER)) return; if(i) { /* if titles only */ if(ch=='S') { found=listsub(usrsub[curgrp][cursub[curgrp]],SCAN_FIND,0,str); subs_scanned++; } else if(ch=='G') for(i=0;i<usrsubs[curgrp] && !msgabort();i++) { found=listsub(usrsub[curgrp][i],SCAN_FIND,0,str); subs_scanned++; } sprintf(tmp,"%s searched %lu sub-boards for '%s'" ,useron.alias,subs_scanned,str); logline(nulstr,tmp); if(!found) CRLF; return; } } else if(mode&SCAN_TOYOU && i) { if(ch=='S') found=listsub(usrsub[curgrp][cursub[curgrp]],SCAN_TOYOU,0,NULL); else if(ch=='G') for(i=0;i<usrsubs[curgrp] && !msgabort();i++) found=listsub(usrsub[curgrp][i],SCAN_TOYOU,0,NULL); if(!found) CRLF; return; } } if(ch=='S') { if(useron.misc&(RIP|WIP|HTML) && !(useron.misc&EXPERT)) { menu("msgscan"); } i=scanposts(usrsub[curgrp][cursub[curgrp]],mode,str); subs_scanned++; bputs(text[MessageScan]); if(i) bputs(text[MessageScanAborted]); else bprintf(text[MessageScanComplete],subs_scanned); return; } if(ch=='G') { if(useron.misc&(RIP|WIP|HTML) && !(useron.misc&EXPERT)) { menu("msgscan"); } for(i=0;i<usrsubs[curgrp] && !msgabort();i++) { if(((mode&SCAN_NEW && (subscan[usrsub[curgrp][i]].cfg&SUB_CFG_NSCAN || cfg.sub[usrsub[curgrp][i]]->misc&SUB_FORCED)) || (mode&SCAN_TOYOU && subscan[usrsub[curgrp][i]].cfg&SUB_CFG_SSCAN) || mode&SCAN_FIND)) { if(scanposts(usrsub[curgrp][i],mode,str)) break; subs_scanned++; } } bputs(text[MessageScan]); if(i==usrsubs[curgrp]) bprintf(text[MessageScanComplete],subs_scanned); else bputs(text[MessageScanAborted]); return; } scanallsubs(mode); }
void sbbs_t::new_scan_cfg(ulong misc) { long s; ulong i,j; ulong t; while(online) { bputs(text[CfgGrpLstHdr]); for(i=0;i<usrgrps && !msgabort();i++) { checkline(); if(i<9) outchar(' '); if(i<99) outchar(' '); bprintf(text[CfgGrpLstFmt],i+1,cfg.grp[usrgrp[i]]->lname); } SYNC; if(misc&SUB_CFG_NSCAN) mnemonics(text[NScanCfgWhichGrp]); else mnemonics(text[SScanCfgWhichGrp]); s=getnum(i); if(s<1) break; i=s-1; while(online) { if(misc&SUB_CFG_NSCAN) misc&=~SUB_CFG_YSCAN; bprintf(text[CfgSubLstHdr],cfg.grp[usrgrp[i]]->lname); for(j=0;j<usrsubs[i] && !msgabort();j++) { checkline(); if(j<9) outchar(' '); if(j<99) outchar(' '); bprintf(text[CfgSubLstFmt],j+1 ,cfg.sub[usrsub[i][j]]->lname ,subscan[usrsub[i][j]].cfg&misc ? (misc&SUB_CFG_NSCAN && subscan[usrsub[i][j]].cfg&SUB_CFG_YSCAN) ? "To You Only" : text[On] : text[Off]); } SYNC; if(misc&SUB_CFG_NSCAN) mnemonics(text[NScanCfgWhichSub]); else mnemonics(text[SScanCfgWhichSub]); s=getkeys("AQ",usrsubs[i]); if(sys_status&SS_ABORT) { lncntr=0; return; } if(!s || s==-1 || s=='Q') break; if(s=='A') { t=subscan[usrsub[i][0]].cfg&misc; if(misc&SUB_CFG_NSCAN && !t && !(useron.misc&FLAG('Q'))) if(!noyes("Messages to you only")) misc|=SUB_CFG_YSCAN; for(j=0;j<usrsubs[i] && online;j++) { checkline(); if(t) subscan[usrsub[i][j]].cfg&=~misc; else { if(misc&SUB_CFG_NSCAN) subscan[usrsub[i][j]].cfg&=~SUB_CFG_YSCAN; subscan[usrsub[i][j]].cfg|=misc; } } continue; } j=(s&~0x80000000L)-1; if(misc&SUB_CFG_NSCAN && !(subscan[usrsub[i][j]].cfg&misc)) { if(!(useron.rest&FLAG('Q')) && !noyes("Messages to you only")) subscan[usrsub[i][j]].cfg|=SUB_CFG_YSCAN; else subscan[usrsub[i][j]].cfg&=~SUB_CFG_YSCAN; } subscan[usrsub[i][j]].cfg^=misc; } } }
void sbbs_t::new_scan_ptr_cfg() { uint i,j; long s; uint32_t l; time_t t; while(online) { bputs(text[CfgGrpLstHdr]); for(i=0;i<usrgrps && !msgabort();i++) { checkline(); if(i<9) outchar(' '); if(i<99) outchar(' '); bprintf(text[CfgGrpLstFmt],i+1,cfg.grp[usrgrp[i]]->lname); } SYNC; mnemonics(text[WhichOrAll]); s=getkeys("AQ",usrgrps); if(!s || s==-1 || s=='Q') break; if(s=='A') { mnemonics("\r\nEnter number of messages from end, ~Date, ~Quit, or" " [Last Message]: "); s=getkeys("DLQ",9999); if(s==-1 || s=='Q') continue; if(s=='D') { t=time(NULL); if(inputnstime(&t) && !(sys_status&SS_ABORT)) { bputs(text[LoadingMsgPtrs]); for(i=0;i<usrgrps && online;i++) for(j=0;j<usrsubs[i] && online;j++) { checkline(); subscan[usrsub[i][j]].ptr=getmsgnum(usrsub[i][j],t); } } continue; } if(s=='L') s=0; if(s) s&=~0x80000000L; bputs(text[LoadingMsgPtrs]); for(i=0;i<usrgrps;i++) for(j=0;j<usrsubs[i] && online;j++) { checkline(); getlastmsg(usrsub[i][j],&l,0); if(s>(long)l) subscan[usrsub[i][j]].ptr=0; else subscan[usrsub[i][j]].ptr=l-s; } continue; } i=(s&~0x80000000L)-1; while(online) { l=0; bprintf(text[CfgSubLstHdr],cfg.grp[usrgrp[i]]->lname); for(j=0;j<usrsubs[i] && !msgabort();j++) { checkline(); if(j<9) outchar(' '); if(j<99) outchar(' '); t=getmsgtime(usrsub[i][j],subscan[usrsub[i][j]].ptr); if(t>(long)l) l=(uint32_t)t; bprintf(text[SubPtrLstFmt],j+1,cfg.sub[usrsub[i][j]]->lname ,timestr(t),nulstr); } SYNC; mnemonics(text[WhichOrAll]); s=getkeys("AQ",usrsubs[i]); if(sys_status&SS_ABORT) { lncntr=0; return; } if(s==-1 || !s || s=='Q') break; if(s=='A') { /* The entire group */ mnemonics("\r\nEnter number of messages from end, ~Date, ~Quit, or" " [Last Message]: "); s=getkeys("DLQ",9999); if(s==-1 || s=='Q') continue; if(s=='D') { t=l; if(inputnstime(&t) && !(sys_status&SS_ABORT)) { bputs(text[LoadingMsgPtrs]); for(j=0;j<usrsubs[i] && online;j++) { checkline(); subscan[usrsub[i][j]].ptr=getmsgnum(usrsub[i][j],t); } } continue; } if(s=='L') s=0; if(s) s&=~0x80000000L; bputs(text[LoadingMsgPtrs]); for(j=0;j<usrsubs[i] && online;j++) { checkline(); getlastmsg(usrsub[i][j],&l,0); if(s>(long)l) subscan[usrsub[i][j]].ptr=0; else subscan[usrsub[i][j]].ptr=l-s; } continue; } else { j=(s&~0x80000000L)-1; mnemonics("\r\nEnter number of messages from end, ~Date, ~Quit, or" " [Last Message]: "); s=getkeys("DLQ",9999); if(s==-1 || s=='Q') continue; if(s=='D') { t=getmsgtime(usrsub[i][j],subscan[usrsub[i][j]].ptr); if(inputnstime(&t) && !(sys_status&SS_ABORT)) { bputs(text[LoadingMsgPtrs]); subscan[usrsub[i][j]].ptr=getmsgnum(usrsub[i][j],t); } continue; } if(s=='L') s=0; if(s) s&=~0x80000000L; getlastmsg(usrsub[i][j],&l,0); if(s>(long)l) subscan[usrsub[i][j]].ptr=0; else subscan[usrsub[i][j]].ptr=l-s; } } } }
void sbbs_t::telnet_gate(char* destaddr, ulong mode, char* client_user_name, char* server_user_name, char* term_type) { char* p; uchar buf[512]; int i; int rd; uint attempts; ulong l; bool gotline; ushort port; ulong ip_addr; ulong save_console; SOCKET remote_socket; SOCKADDR_IN addr; if(mode&TG_RLOGIN) port=513; else port=IPPORT_TELNET; p=strchr(destaddr,':'); if(p!=NULL) { *p=0; port=atoi(p+1); } ip_addr=resolve_ip(destaddr); if(ip_addr==INADDR_NONE) { lprintf(LOG_NOTICE,"!TELGATE Failed to resolve address: %s",destaddr); bprintf("!Failed to resolve address: %s\r\n",destaddr); return; } if((remote_socket = open_socket(SOCK_STREAM, client.protocol)) == INVALID_SOCKET) { errormsg(WHERE,ERR_OPEN,"socket",0); return; } memset(&addr,0,sizeof(addr)); addr.sin_addr.s_addr = htonl(startup->telnet_interface); addr.sin_family = AF_INET; if((i=bind(remote_socket, (struct sockaddr *) &addr, sizeof (addr)))!=0) { lprintf(LOG_NOTICE,"!TELGATE ERROR %d (%d) binding to socket %d",i, ERROR_VALUE, remote_socket); bprintf("!ERROR %d (%d) binding to socket\r\n",i, ERROR_VALUE); close_socket(remote_socket); return; } memset(&addr,0,sizeof(addr)); addr.sin_addr.s_addr = ip_addr; addr.sin_family = AF_INET; addr.sin_port = htons(port); if((i=connect(remote_socket, (struct sockaddr *)&addr, sizeof(addr)))!=0) { lprintf(LOG_NOTICE,"!TELGATE ERROR %d (%d) connecting to server: %s" ,i,ERROR_VALUE, destaddr); bprintf("!ERROR %d (%d) connecting to server: %s\r\n" ,i,ERROR_VALUE, destaddr); close_socket(remote_socket); return; } l=1; if((i = ioctlsocket(remote_socket, FIONBIO, &l))!=0) { lprintf(LOG_NOTICE,"!TELGATE ERROR %d (%d) disabling socket blocking" ,i, ERROR_VALUE); close_socket(remote_socket); return; } lprintf(LOG_INFO,"Node %d %s gate to %s port %u on socket %d" ,cfg.node_num ,mode&TG_RLOGIN ? "RLogin" : "Telnet" ,destaddr,port,remote_socket); if(!(mode&TG_CTRLKEYS)) console|=CON_RAW_IN; if(mode&TG_RLOGIN) { p=(char*)buf; *(p++)=0; p+=sprintf(p,"%s",client_user_name==NULL ? useron.alias : client_user_name); p++; // Add NULL p+=sprintf(p,"%s",server_user_name==NULL ? useron.name : server_user_name); p++; // Add NULL if(term_type!=NULL) p+=sprintf(p,"%s",term_type); else p+=sprintf(p,"%s/%u",terminal, cur_rate); p++; // Add NULL l=p-(char*)buf; sendsocket(remote_socket,(char*)buf,l); mode|=TG_NOLF; /* Send LF (to remote host) when Telnet client sends CRLF (when not in binary mode) */ } /* This is required for gating to Unix telnetd */ if(mode&TG_NOTERMTYPE) request_telnet_opt(TELNET_DONT,TELNET_TERM_TYPE, 3000); // Re-negotiation of terminal type /* Text/NVT mode by default */ request_telnet_opt(TELNET_DONT,TELNET_BINARY_TX, 3000); if(!(telnet_mode&TELNET_MODE_OFF) && (mode&TG_PASSTHRU)) telnet_mode|=TELNET_MODE_GATE; // Pass-through telnet commands while(online) { if(!(mode&TG_NOCHKTIME)) gettimeleft(); rd=RingBufRead(&inbuf,buf,sizeof(buf)); if(rd) { #if 0 if(memchr(buf,TELNET_IAC,rd)) { char dump[2048]; dump[0]; p=dump; for(int i=0;i<rd;i++) p+=sprintf(p,"%u ",buf[i]); lprintf(LOG_DEBUG,"Node %d Telnet cmd from client: %s", cfg.node_num, dump); } #endif if(telnet_remote_option[TELNET_BINARY_TX]!=TELNET_WILL) { if(*buf==0x1d) { // ^] save_console=console; console&=~CON_RAW_IN; // Allow Ctrl-U/Ctrl-P CRLF; while(online) { SYNC; mnemonics("\1n\r\n\1h\1bTelnet Gate: \1y~D\1wisconnect, " "\1y~E\1wcho toggle, \1y~L\1wist Users, \1y~P\1wrivate message, " "\1y~Q\1wuit: "); switch(getkeys("DELPQ",0)) { case 'D': closesocket(remote_socket); break; case 'E': mode^=TG_ECHO; bprintf(text[EchoIsNow] ,mode&TG_ECHO ? text[ON]:text[OFF]); continue; case 'L': whos_online(true); continue; case 'P': nodemsg(); continue; } break; } attr(LIGHTGRAY); console=save_console; } else if(*buf<' ' && (mode&TG_CTRLKEYS)) handle_ctrlkey(*buf, K_NONE); gotline=false; if((mode&TG_LINEMODE) && buf[0]!='\r') { ungetkey(buf[0]); l=K_CHAT; if(!(mode&TG_ECHO)) l|=K_NOECHO; rd=getstr((char*)buf,sizeof(buf)-1,l); if(!rd) continue; strcat((char*)buf,crlf); rd+=2; gotline=true; } if((mode&TG_CRLF) && buf[rd-1]=='\r') buf[rd++]='\n'; else if((mode&TG_NOLF) && buf[rd-1]=='\n') rd--; if(!gotline && (mode&TG_ECHO) && rd) { RingBufWrite(&outbuf,buf,rd); } } /* Not Telnet Binary mode */ if(rd > 0) { for(attempts=0;attempts<60 && online; attempts++) /* added retry loop here, Jan-20-2003 */ { if((i=sendsocket(remote_socket,(char*)buf,rd))>=0) break; if(ERROR_VALUE!=EWOULDBLOCK) break; mswait(500); } if(i<0) { lprintf(LOG_NOTICE,"!TELGATE ERROR %d sending on socket %d",ERROR_VALUE,remote_socket); break; } } } rd=recv(remote_socket,(char*)buf,sizeof(buf),0); if(rd<0) { if(ERROR_VALUE==EWOULDBLOCK) { if(mode&TG_NODESYNC) { SYNC; } else { // Check if the node has been interrupted getnodedat(cfg.node_num,&thisnode,0); if(thisnode.misc&NODE_INTR) break; } YIELD(); continue; } lprintf(LOG_NOTICE,"!TELGATE ERROR %d receiving on socket %d",ERROR_VALUE,remote_socket); break; } if(!rd) { lprintf(LOG_INFO,"Node %d Telnet gate disconnected",cfg.node_num); break; } #if 0 if(memchr(buf,TELNET_IAC,rd)) { char dump[2048]; dump[0]; p=dump; for(int i=0;i<rd;i++) p+=sprintf(p,"%u ",buf[i]); lprintf(LOG_DEBUG,"Node %d Telnet cmd from server: %s", cfg.node_num, dump); } #endif RingBufWrite(&outbuf,buf,rd); } console&=~CON_RAW_IN; telnet_mode&=~TELNET_MODE_GATE; /* Disable Telnet Terminal Echo */ request_telnet_opt(TELNET_WILL,TELNET_ECHO); close_socket(remote_socket); lprintf(LOG_INFO,"Node %d Telnet gate to %s finished",cfg.node_num,destaddr); }
bool sbbs_t::netmail(const char *into, const char *title, long mode) { char str[256],subj[128],to[256],fname[128],*buf,*p,ch; char tmp[512]; int file,fido,x,cc_found,cc_sent; uint i; long length,l; faddr_t addr; fmsghdr_t hdr; struct tm tm; if(useron.etoday>=cfg.level_emailperday[useron.level] && !SYSOP && !(useron.exempt&FLAG('M'))) { bputs(text[TooManyEmailsToday]); return(false); } SAFECOPY(subj,title); strcpy(to,into); lookup_netuser(to); p=strrchr(to,'@'); /* Find '@' in name@addr */ if(p && !isdigit(*(p+1)) && !strchr(p,'.') && !strchr(p,':')) { mode&=~WM_FILE; qnetmail(to,title,mode|WM_NETMAIL); return(false); } if(!cfg.total_faddrs || p==NULL || !strchr(p+1,'/')) { if(!p && cfg.dflt_faddr.zone) addr=cfg.dflt_faddr; else if(cfg.inetmail_misc&NMAIL_ALLOW) { if(mode&WM_FILE && !SYSOP && !(cfg.inetmail_misc&NMAIL_FILE)) mode&=~WM_FILE; return(inetmail(into,title,mode|WM_NETMAIL)); } else if(cfg.dflt_faddr.zone) addr=cfg.dflt_faddr; else { bputs(text[InvalidNetMailAddr]); return(false); } } else { addr=atofaddr(&cfg,p+1); /* Get fido address */ *p=0; /* Chop off address */ } if(mode&WM_FILE && !SYSOP && !(cfg.netmail_misc&NMAIL_FILE)) mode&=~WM_FILE; if((!SYSOP && !(cfg.netmail_misc&NMAIL_ALLOW)) || useron.rest&FLAG('M') || !cfg.total_faddrs) { bputs(text[NoNetMailAllowed]); return(false); } truncsp(to); /* Truncate off space */ memset(&hdr,0,sizeof(hdr)); /* Initialize header to null */ strcpy(hdr.from,cfg.netmail_misc&NMAIL_ALIAS ? useron.alias : useron.name); SAFECOPY(hdr.to,to); /* Look-up in nodelist? */ if(cfg.netmail_cost && !(useron.exempt&FLAG('S'))) { if(useron.cdt+useron.freecdt<cfg.netmail_cost) { bputs(text[NotEnoughCredits]); return(false); } sprintf(str,text[NetMailCostContinueQ],cfg.netmail_cost); if(noyes(str)) return(false); } now=time(NULL); if(localtime_r(&now,&tm)!=NULL) sprintf(hdr.time,"%02u %3.3s %02u %02u:%02u:%02u" ,tm.tm_mday,mon[tm.tm_mon],TM_YEAR(tm.tm_year) ,tm.tm_hour,tm.tm_min,tm.tm_sec); hdr.destzone =addr.zone; hdr.destnet =addr.net; hdr.destnode =addr.node; hdr.destpoint =addr.point; for(i=0;i<cfg.total_faddrs;i++) if(addr.zone==cfg.faddr[i].zone && addr.net==cfg.faddr[i].net) break; if(i==cfg.total_faddrs) { for(i=0;i<cfg.total_faddrs;i++) if(addr.zone==cfg.faddr[i].zone) break; } if(i==cfg.total_faddrs) i=0; hdr.origzone =cfg.faddr[i].zone; hdr.orignet =cfg.faddr[i].net; hdr.orignode =cfg.faddr[i].node; hdr.origpoint =cfg.faddr[i].point; smb_faddrtoa(&cfg.faddr[i],str); bprintf(text[NetMailing],hdr.to,smb_faddrtoa(&addr,tmp),hdr.from,str); hdr.attr=(FIDO_LOCAL|FIDO_PRIVATE); if(cfg.netmail_misc&NMAIL_CRASH) hdr.attr|=FIDO_CRASH; if(cfg.netmail_misc&NMAIL_HOLD) hdr.attr|=FIDO_HOLD; if(cfg.netmail_misc&NMAIL_KILL) hdr.attr|=FIDO_KILLSENT; if(mode&WM_FILE) hdr.attr|=FIDO_FILE; sprintf(str,"%sNETMAIL.MSG", cfg.node_dir); remove(str); /* Just incase it's already there */ // mode&=~WM_FILE; if(!writemsg(str,nulstr,subj,WM_NETMAIL|mode,INVALID_SUB,into)) { bputs(text[Aborted]); return(false); } if(mode&WM_FILE) { strcpy(fname,subj); sprintf(str,"%sfile/%04u.out", cfg.data_dir, useron.number); MKDIR(str); strcpy(tmp, cfg.data_dir); if(tmp[0]=='.') /* Relative path */ sprintf(tmp,"%s%s", cfg.node_dir, cfg.data_dir); sprintf(str,"%sfile/%04u.out/%s",tmp,useron.number,fname); strcpy(subj,str); if(fexistcase(str)) { bputs(text[FileAlreadyThere]); return(false); } { /* Remote */ xfer_prot_menu(XFER_UPLOAD); mnemonics(text[ProtocolOrQuit]); strcpy(str,"Q"); for(x=0;x<cfg.total_prots;x++) if(cfg.prot[x]->ulcmd[0] && chk_ar(cfg.prot[x]->ar,&useron,&client)) { sprintf(tmp,"%c",cfg.prot[x]->mnemonic); strcat(str,tmp); } ch=(char)getkeys(str,0); if(ch=='Q' || sys_status&SS_ABORT) { bputs(text[Aborted]); return(false); } for(x=0;x<cfg.total_prots;x++) if(cfg.prot[x]->ulcmd[0] && cfg.prot[x]->mnemonic==ch && chk_ar(cfg.prot[x]->ar,&useron,&client)) break; if(x<cfg.total_prots) /* This should be always */ protocol(cfg.prot[x],XFER_UPLOAD,subj,nulstr,true); } sprintf(tmp,"%s%s",cfg.temp_dir,title); if(!fexistcase(subj) && fexistcase(tmp)) mv(tmp,subj,0); l=(long)flength(subj); if(l>0) bprintf(text[FileNBytesReceived],fname,ultoac(l,tmp)); else { bprintf(text[FileNotReceived],fname); return(false); } } p=subj; if((SYSOP || useron.exempt&FLAG('F')) && !strnicmp(p,"CR:",3)) { /* Crash over-ride by sysop */ p+=3; /* skip CR: */ if(*p==' ') p++; /* skip extra space if it exists */ hdr.attr|=FIDO_CRASH; } if((SYSOP || useron.exempt&FLAG('F')) && !strnicmp(p,"FR:",3)) { /* File request */ p+=3; /* skip FR: */ if(*p==' ') p++; hdr.attr|=FIDO_FREQ; } if((SYSOP || useron.exempt&FLAG('F')) && !strnicmp(p,"RR:",3)) { /* Return receipt request */ p+=3; /* skip RR: */ if(*p==' ') p++; hdr.attr|=FIDO_RRREQ; } if((SYSOP || useron.exempt&FLAG('F')) && !strnicmp(p,"FA:",3)) { /* File Attachment */ p+=3; /* skip FA: */ if(*p==' ') p++; hdr.attr|=FIDO_FILE; } SAFECOPY(hdr.subj,p); sprintf(str,"%sNETMAIL.MSG", cfg.node_dir); if((file=nopen(str,O_RDONLY))==-1) { errormsg(WHERE,ERR_OPEN,str,O_RDONLY); return(false); } length=(long)filelength(file); if((buf=(char *)malloc(length))==NULL) { close(file); errormsg(WHERE,ERR_ALLOC,str,length); return(false); } read(file,buf,length); close(file); md(cfg.netmail_dir); cc_sent=0; while(1) { for(i=1;i;i++) { sprintf(str,"%s%u.msg", cfg.netmail_dir,i); if(!fexistcase(str)) break; } if(!i) { bputs(text[TooManyEmailsToday]); return(false); } if((fido=nopen(str,O_WRONLY|O_CREAT|O_EXCL))==-1) { errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_EXCL); return(false); } write(fido,&hdr,sizeof(hdr)); pt_zone_kludge(hdr,fido); if(cfg.netmail_misc&NMAIL_DIRECT) { SAFECOPY(str,"\1FLAGS DIR\r\n"); write(fido,str,strlen(str)); } if(mode&WM_FILE) { SAFECOPY(str,"\1FLAGS KFS\r\n"); write(fido,str,strlen(str)); } if(cc_sent) { SAFEPRINTF(str,"* Originally to: %s\r\n\r\n",into); write(fido,str,strlen(str)); } l=0L; while(l<length) { if(buf[l]==CTRL_A) { /* Ctrl-A, so skip it and the next char */ l++; if(l>=length || toupper(buf[l])=='Z') /* EOF */ break; if((ch=ctrl_a_to_ascii_char(buf[l])) != 0) write(fido,&ch,1); } else if(buf[l]!=LF) { if((uchar)buf[l]==0x8d) /* r0dent i converted to normal i */ buf[l]='i'; write(fido,buf+l,1); } l++; } l=0; write(fido,&l,1); /* Null terminator */ close(fido); useron.emails++; logon_emails++; putuserrec(&cfg,useron.number,U_EMAILS,5,ultoa(useron.emails,tmp,10)); useron.etoday++; putuserrec(&cfg,useron.number,U_ETODAY,5,ultoa(useron.etoday,tmp,10)); if(!(useron.exempt&FLAG('S'))) subtract_cdt(&cfg,&useron,cfg.netmail_cost); if(mode&WM_FILE) sprintf(str,"%s sent NetMail file attachment to %s (%s)" ,useron.alias ,hdr.to,smb_faddrtoa(&addr,tmp)); else sprintf(str,"%s sent NetMail to %s (%s)" ,useron.alias ,hdr.to,smb_faddrtoa(&addr,tmp)); logline("EN",str); cc_found=0; for(l=0;l<length && cc_found<=cc_sent;l++) if(l+3<length && !strnicmp(buf+l,"CC:",3)) { cc_found++; l+=2; } else { while(l<length && *(buf+l)!=LF) l++; } if(!cc_found) break; while(l<length && *(buf+l)==' ') l++; for(i=0;l<length && *(buf+l)!=LF && i<128;i++,l++) str[i]=buf[l]; if(!i) break; str[i]=0; p=strrchr(str,'@'); if(p) { addr=atofaddr(&cfg,p+1); *p=0; SAFECOPY(hdr.to,str); } else { atofaddr(&cfg,str); strcpy(hdr.to,"Sysop"); } hdr.destzone =addr.zone; hdr.destnet =addr.net; hdr.destnode =addr.node; hdr.destpoint =addr.point; cc_sent++; } if(cfg.netmail_sem[0]) /* update semaphore file */ ftouch(cmdstr(cfg.netmail_sem,nulstr,nulstr,NULL)); free(buf); return(true); }