int main_debug(S_robot* r) { _tic(); ROBOT_initLifeDebug(r); fprintf(r->flcd, "Init="); _tocPrint(r->flcd); mswait(400); LCD_clear(r->lcd); ROBOT_START(r); uint32_t period = 10; uint32_t prStart = _tic(); uint8_t q=0; //uint32_t ocval = 0; S_robot_dcmotors* ds = 0; ds = &(r->dcs); S_actuator_dcmotor* m = 0; m = ds->m[q]; float dcadd = 0.00001; mswait(1000); while(1) { CLOCK_digiPrint(r); if(m->dutyCycle >= 1.0) m->dutyCycle = 0.0; DCMOT_SET_dutyCycle(m, m->dutyCycle+dcadd); } while (1) { /** DO not debug inside this while! Make a separate function like DBG_tryADC(void), and call it from here :) */ // DBG_testButtonState(r,100,10); // DBG_testUltraDistanceOld(r,100); //TRY_buzzer(); //LCD_displayWriteCheck(r->lcd); //dev_LCD_checkSeek(flcd); //DBG_tryADC(r); //DBG_tryCNY70(r //DBG_testUltraDistance(r,0xFFFF); //DBG_testAllUltraDistance(r,0xFFFF); DBG_testActuators(r,0xFFFFFF); //INIT_tim(r); } return 0; }
void waitturn() { time_t start,now; start=now=time(NULL); getgamedat(1); status[node_num-1]=WAIT; putgamedat(); while(curplayer!=node_num) { chat(); mswait(100); getgamedat(0); if(curplayer && !node[curplayer-1] /* || status[curplayer-1]==BET */ ) nextplayer(); /* current player is not playing? */ if(!node[node_num-1]) { /* current node not in game? */ getgamedat(1); node[node_num-1]=user_number; /* fix it */ putgamedat(); } now=time(NULL); if(now-start>300) { /* only wait upto 5 minutes */ bputs("\r\nwaitturn: timeout\r\n"); break; } } getgamedat(1); status[node_num-1]=PLAY; putgamedat(); }
void DBG_testUltraDistanceOld2(S_robot* r,uint32_t repeats) { S_sensor_ultra* u ; uint8_t a =0; FILE* f = r->fus; // for output on uart //FILE* f = r->flcd; // for output on lcd // INIT_ultraTimer(r,0); while(repeats>1) { repeats--; fprintf(f,"ULTRAS[0-3]:"); for(a=0;a<ROB_ULTRA_COUNT;a++) { u = r->ults.u[a]; if(u->ticksStart == 0) ULTRA_signalSend(u); fprintf(f, "[%u]=%3lu|%5.2f[cm]", a, u->nTicks, u->dist); } fprintf(f, "\n"); //LCD_clear(r->lcd); //fprintf(f, "%lu|%.2f[cm]", u->nTicks, u->dist); //fprintf(f, "%lu|%.2f[cm]\n", u->nTicks, u->dist); mswait(200); }
#if __NOT_IMPLEMENTED_YET void DBG_debug_try(void) { uint8_t i_ultra = 0; INIT_ultraPredef(i_ultra ,0); uint8_t ilcd = 0; S_dev_lcd* lcd_dev = &(predef_lcds[ilcd]); S_sensor_ultra* ultra = &(predef_ultras[i_ultra]); ULTRA_signalSend(ultra); while(1) { ultra->dist = 0; while( !gpio_get(ultra->rxport,ultra->rxpin) ) { __asm__("nop"); } while( gpio_get(ultra->rxport,ultra->rxpin) ) { (ultra->dist)++; } //u30+4;u10+1 ultra->dist *= 1.1;//1.111;//1.33333333;//(1 + 4.0/30); LCD_clear(r->lcd); fprintf(flcd, "dist[cm]=%.2f", ultra->dist/100);//ULTRA_getDist(i_ultra)); mswait(500); }
void DBG_testButtonState(S_robot* r, uint32_t repeats,uint32_t ms) { while(repeats>1) { repeats--; S_robot_buttons * b = &(r->btns); REFRESH_buttonState(b->bStart); REFRESH_buttonState(b->bLine); REFRESH_buttonState(b->bSumo); gpio_clear(PLED,LEDGREEN0|LEDORANGE1|LEDRED2|LEDBLUE3); LCD_clear(r->lcd); LCD_gotoxy(r->lcd,0,0); fprintf(R.flcd, "%x|%x|%x", b->bStart->state, b->bLine->state, b->bSumo->state ); if(b->bStart->state) gpio_set(PLED,LEDGREEN0); if(b->bLine->state) gpio_set(PLED,LEDBLUE3); if(b->bSumo->state) gpio_set(PLED,LEDRED2); mswait(ms); } gpio_clear(PLED,LEDGREEN0|LEDORANGE1|LEDRED2|LEDBLUE3);
void DBG_tryCNY70(S_robot* r) { LCD_clear(r->lcd); fprintf(r->flcd,"PC0=%7.2f \r\n", r->infs.i[0]->val); gpio_toggle(PLED,LED0); mswait(500);
void DBG_ticTocSumoWait(S_robot* r) { while(1) { _tic(); uint8_t a=0; for(a=0; a<5; a++) SUMO_wait5secAndSample(r); _tocPrint(r->flcd); mswait(300); }
//--------------------------------------------------------------------------- void __fastcall TMainForm::FormShow(TObject *Sender) { char* p; char path[MAX_PATH+1]; Caption="Waiting for " +AnsiString(user_name)+" on Node "+AnsiString(node_num); wsprintf(node_path,"%sNODE.DAB",ctrl_dir); nodedab=_sopen(node_path,O_RDWR|O_BINARY|O_CREAT, SH_DENYNONE,S_IREAD|S_IWRITE); if(nodedab==-1) { Remote->Lines->Add("!Error opening " + AnsiString(node_path)); return; } ToggleChat(true); wsprintf(out_path,"%sLCHAT.DAB",node_dir); if((out=_sopen(out_path,O_RDWR|O_CREAT|O_BINARY,O_DENYNONE ,S_IREAD|S_IWRITE))==-1) { Remote->Lines->Add("!Error opening " + AnsiString(out_path)); return; } wsprintf(path,"%sCHAT.DAB",node_dir); #if 0 if(!fexist(path)) /* Wait while it's created for the first time */ mswait(2000); #endif if((in=_sopen(path,O_RDWR|O_CREAT|O_BINARY,O_DENYNONE ,S_IREAD|S_IWRITE))==-1) { close(out); Remote->Lines->Add("!Error opening CHAT.DAB"); return; } if((p=(char *)malloc(PCHAT_LEN))==NULL) { close(in); close(out); Remote->Lines->Add("!Error allocating memory"); return; } memset(p,0,PCHAT_LEN); write(in,p,PCHAT_LEN); write(out,p,PCHAT_LEN); free(p); lseek(in,0L,SEEK_SET); lseek(out,0L,SEEK_SET); Timer->Enabled=true; }
void DBG_testActuators(S_robot*r, uint32_t reps) { uint32_t period = 10; uint32_t prStart = _tic(); uint8_t q=0; //uint32_t ocval = 0; S_robot_dcmotors* ds = 0; ds = &(r->dcs); S_actuator_dcmotor* m = 0; m = ds->m[q]; float dcadd = 0.00001; mswait(1000); while(1) { CLOCK_digiPrint(r); if(m->dutyCycle >= 1.0) m->dutyCycle = 0.0; DCMOT_SET_dutyCycle(m, m->dutyCycle+dcadd); } while(reps>1) { CLOCK_digiPrint(r); if( _tocFrom(prStart) > period ) { // cycle dutyCycle if(m->dutyCycle >= 1.0) m->dutyCycle = 0.0; DCMOT_SET_dutyCycle(m, m->dutyCycle+0.02); TIM_CCR1(m->TIMX) = m->OCval; //ocval += 10; //model_timer_SET_outputCompare(TIM2,TIM_OC2,ocval); // printit LCD_gotoxy(r->lcd,0,0); fprintf(r->flcd, "%.0f%%", ds->m[q]->dutyCycle*100); LCD_gotoxy(r->lcd,0,1); //fprintf(r->flcd, ""); //for(q=0;q<ROB_MOTOR_COUNT;q++) fprintf(r->flcd, "%lu/%lu|", ds->m[q]->OCval, ds->m[q]->tim_s->period ); //fprintf(r->flcd, "oc=%lu=%lu", ocval, m->OCval ); prStart = _tic(); } reps--; } gpio_toggle(PLED,LEDORANGE1);
void sbbs_t::badlogin(char* user, char* passwd) { char reason[128]; ulong count; SAFEPRINTF(reason,"%s LOGIN", connection); count=loginFailure(startup->login_attempt_list, &client_addr, connection, user, passwd); if(startup->login_attempt_hack_threshold && count>=startup->login_attempt_hack_threshold) ::hacklog(&cfg, reason, user, passwd, client_name, &client_addr); if(startup->login_attempt_filter_threshold && count>=startup->login_attempt_filter_threshold) filter_ip(&cfg, connection, "- TOO MANY CONSECUTIVE FAILED LOGIN ATTEMPTS" ,client_name, client_ipaddr, user, /* fname: */NULL); mswait(startup->login_attempt_delay); }
bool sbbs_t::trashcan(char *insearchof, char *name) { char str[MAX_PATH+1]; bool result; result=::trashcan(&cfg, insearchof, name) ? true:false; // This is a dumb bool conversion to make BC++ happy if(result) { sprintf(str,"%sbad%s.msg",cfg.text_dir,name); if(fexistcase(str)) { printfile(str,0); mswait(500); // give time for tx buffer to clear before disconnect } } return(result); }
void syncdealer() { char *Dealing="\1n\1hDealing...\r\n\1n"; int i; time_t start,now; status[node_num-1]=SYNC_D; putgamedat(); start=now=time(NULL); // fdelay(1000); /* wait for stragglers to join game v1.02 */ getgamedat(0); while(total_players) { for(i=0;i<total_nodes;i++) if(i!=node_num-1 && node[i] && status[i]!=SYNC_P) break; if(i==total_nodes) /* all player nodes are waiting */ break; chat(); mswait(100); getgamedat(0); if(!node[node_num-1]) { /* current node not in game? */ getgamedat(1); node[node_num-1]=user_number; /* fix it */ putgamedat(); } now=time(NULL); if(now-start>300) { /* only wait upto 5 minutes */ bputs("\r\nsyncdealer: timeout\r\n"); break; } } getgamedat(1); misc|=INPLAY; curplayer=firstplayer(); putgamedat(); getnodemsg(); bputs(Dealing); putallnodemsg(Dealing); getgamedat(1); for(i=0;i<total_nodes;i++) /* release player nodes */ if(node[i]) status[i]=PLAY; putgamedat(); }
void syncplayer() { time_t start,now; status[node_num-1]=SYNC_P; putgamedat(); start=now=time(NULL); while(node[node_num-1] && status[node_num-1]==SYNC_P) { chat(); mswait(100); getgamedat(0); if(!node[node_num-1]) { /* current node not in game? */ getgamedat(1); node[node_num-1]=user_number; /* fix it */ putgamedat(); } now=time(NULL); if(now-start>300) { /* only wait upto 5 minutes */ bputs("\r\nsyncplayer: timeout\r\n"); break; } } }
} void DBG_tryADC(S_robot* r) { //uint16_t input_adc0 = INFRA_readNaiive(10); //uint16_t input_adc1 = INFRA_readNaiive(11); // uint16_t input_adc1 = r->infs.iFL->val; LCD_clear(r->lcd); fprintf(r->flcd,"%7.2f %7.2f\n%7.2f %7.2f\n", r->infs.iFL->val, r->infs.iFR->val, r->infs.iBL->val, r->infs.iBR->val ); gpio_toggle(PLED,LED0); mswait(500); //fprintf(r->fus,"ADC=%u\n\r", r->infs.iFL->val); //LCD_clear(r->lcd); //fprintf(r->flcd,"ADC=%u", r->infs.iFL->val);
void wrong(char action) { #ifdef __16BIT__ sound(100); mswait(500); nosound(); #endif bputs("Dealer says you should have "); switch(action) { case 'H': bputs("hit"); break; case 'S': bputs("stood"); break; case 'D': bputs("doubled"); break; case 'P': bputs("split"); break; } bputs("\r\n"); }
int main(void) { /** If you look here and hope to find out how this program works, you should look inside headerfiles for function headers to know what they do mainly look inside the robot_config.c and inside the struct S_robot. S_robot is is the core of everything */ S_robot* r = &R; // global= extern S_robot R; INIT_clk(); INIT_leds(); r->STARTED = 0; ROBOT_initButtons(r); // Chose a program to run E_lifeStyleSelector life = ROBOT_getLifeStyle(&R); switch(life) { case(IAM_BUGGED_ROBOT): main_debug(r); break; case(IAM_SUMO_WARRIOR): main_sumo(r); break; case(IAM_LINE_SNIFFER): //main_line(r); break; default: main_debug(r); } // followin' code could not ever been executed INIT_leds(); while (1) { gpio_toggle(PLED,LEDGREEN0|LEDORANGE1|LEDRED2|LEDBLUE3); mswait(500); } return 0; }
void getgamedat(char lockit) { int i=0; /* retry 100 times taking at least 3 seconds */ while(lock(gamedab,0L,filelength(gamedab))==-1 && i++<100) mswait(30); /* lock the whole thing */ if(i>=100) { // printf("gamedab=%d %04X:%p %04X\r\n",gamedab,_psp,&gamedab,_DS); printf("\7getgamedat: error locking game.dab\r\n"); } lseek(gamedab,0L,SEEK_SET); read(gamedab,&misc,1); read(gamedab,&curplayer,1); read(gamedab,&total_nodes,1); read(gamedab,node,total_nodes*2); /* user number playing for each node */ read(gamedab,status,total_nodes); /* the status of the player */ total_players=0; for(i=0;i<total_nodes;i++) if(node[i]) total_players++; if(!lockit) unlock(gamedab,0L,filelength(gamedab)); }
void sbbs_t::logout() { char str[256]; char tmp[512]; int i,j; ushort ttoday; node_t node; struct tm tm; now=time(NULL); if(localtime_r(&now,&tm)==NULL) return; if(!useron.number) { /* Not logged in, so do nothing */ if(!online) { sprintf(str,"%s T:%3u sec\r\n" ,hhmmtostr(&cfg,&tm,tmp) ,(uint)(now-answertime)); logline("@-",str); } return; } strcpy(lastuseron,useron.alias); /* for use with WFC status display */ if(useron.rest&FLAG('G')) { /* Reset guest's msg scan cfg */ putuserrec(&cfg,useron.number,U_NAME,LEN_NAME,nulstr); batdn_total=0; } batch_create_list(); if(sys_status&SS_USERON && thisnode.status!=NODE_QUIET && !(useron.rest&FLAG('Q'))) for(i=1;i<=cfg.sys_nodes;i++) if(i!=cfg.node_num) { getnodedat(i,&node,0); if((node.status==NODE_INUSE || node.status==NODE_QUIET) && !(node.misc&NODE_AOFF) && node.useron!=useron.number) { sprintf(str,text[NodeLoggedOff],cfg.node_num ,thisnode.misc&NODE_ANON ? text[UNKNOWN_USER] : useron.alias); putnmsg(&cfg,i,str); } } if(!online) { /* NOT re-login */ #if 0 /* too soon, handled in node_thread */ getnodedat(cfg.node_num,&thisnode,1); thisnode.status=NODE_WFC; thisnode.misc&=~(NODE_INTR|NODE_MSGW|NODE_NMSG |NODE_UDAT|NODE_POFF|NODE_AOFF|NODE_EXT); putnodedat(cfg.node_num,&thisnode); #endif #if 0 /* beep? */ if(sys_status&SS_SYSALERT) { mswait(500); offhook(); CLS; lputs("\r\n\r\nAlerting Sysop..."); while(!lkbrd(1)) { sbbs_beep(1000,200); nosound(); mswait(200); } lkbrd(0); } #endif sys_status&=~SS_SYSALERT; if(cfg.sys_logout[0]) /* execute system logout event */ external(cmdstr(cfg.sys_logout,nulstr,nulstr,NULL),EX_OUTL|EX_OFFLINE); } if(cfg.logout_mod[0]) exec_bin(cfg.logout_mod,&main_csi); backout(); sprintf(str,"%smsgs/%4.4u.msg",cfg.data_dir,useron.number); if(!flength(str)) /* remove any 0 byte message files */ remove(str); delfiles(cfg.temp_dir,ALLFILES); putmsgptrs(); if(!REALSYSOP) logofflist(); useron.laston=(time32_t)now; ttoday=useron.ttoday-useron.textra; /* billable time used prev calls */ if(ttoday>=cfg.level_timeperday[useron.level]) i=0; else i=cfg.level_timeperday[useron.level]-ttoday; if(i>cfg.level_timepercall[useron.level]) /* i=amount of time without min */ i=cfg.level_timepercall[useron.level]; j=(int)(now-starttime)/60; /* j=billable time online in min */ if(i<0) i=0; if(j<0) j=0; if(useron.min && j>i) { j-=i; /* j=time to deduct from min */ sprintf(str,"Minute Adjustment: %d",-j); logline(">>",str); if(useron.min>(ulong)j) useron.min-=j; else useron.min=0L; putuserrec(&cfg,useron.number,U_MIN,10,ultoa(useron.min,str,10)); } if(timeleft>0 && starttime-logontime>0) /* extra time */ useron.textra+=(ushort)((starttime-logontime)/60); putuserrec(&cfg,useron.number,U_TEXTRA,5,ultoa(useron.textra,str,10)); putuserrec(&cfg,useron.number,U_NS_TIME,8,ultoa((ulong)last_ns_time,str,16)); logoutuserdat(&cfg, &useron, now, logontime); getusrsubs(); getusrdirs(); if(usrgrps>0) putuserrec(&cfg,useron.number,U_CURSUB,0,cfg.sub[usrsub[curgrp][cursub[curgrp]]]->code); if(usrlibs>0) putuserrec(&cfg,useron.number,U_CURDIR,0,cfg.dir[usrdir[curlib][curdir[curlib]]]->code); hhmmtostr(&cfg,&tm,str); strcat(str," "); if(sys_status&SS_USERON) sprintf(tmp,"T:%3u R:%3lu P:%3lu E:%3lu F:%3lu " "U:%3luk %lu D:%3luk %lu" ,(uint)(now-logontime)/60,posts_read,logon_posts ,logon_emails,logon_fbacks,logon_ulb/1024UL,logon_uls ,logon_dlb/1024UL,logon_dls); else sprintf(tmp,"T:%3u sec",(uint)(now-answertime)); strcat(str,tmp); strcat(str,"\r\n"); logline("@-",str); sys_status&=~SS_USERON; answertime=now; // Incase we're relogging on }
void sbbs_t::ctrl_a(char x) { char tmp1[128],atr=curatr; struct tm tm; if(x && (uchar)x<=CTRL_Z) { /* Ctrl-A through Ctrl-Z for users with MF only */ if(!(useron.flags1&FLAG(x+64))) console^=(CON_ECHO_OFF); return; } if((uchar)x>0x7f) { cursor_right((uchar)x-0x7f); return; } switch(toupper(x)) { case '!': /* level 10 or higher */ if(useron.level<10) console^=CON_ECHO_OFF; break; case '@': /* level 20 or higher */ if(useron.level<20) console^=CON_ECHO_OFF; break; case '#': /* level 30 or higher */ if(useron.level<30) console^=CON_ECHO_OFF; break; case '$': /* level 40 or higher */ if(useron.level<40) console^=CON_ECHO_OFF; break; case '%': /* level 50 or higher */ if(useron.level<50) console^=CON_ECHO_OFF; break; case '^': /* level 60 or higher */ if(useron.level<60) console^=CON_ECHO_OFF; break; case '&': /* level 70 or higher */ if(useron.level<70) console^=CON_ECHO_OFF; break; case '*': /* level 80 or higher */ if(useron.level<80) console^=CON_ECHO_OFF; break; case '(': /* level 90 or higher */ if(useron.level<90) console^=CON_ECHO_OFF; break; case ')': /* turn echo back on */ console&=~CON_ECHO_OFF; break; case '+': /* push current attribte */ if(attr_sp<(int)sizeof(attr_stack)) attr_stack[attr_sp++]=curatr; break; case '-': /* pop current attribute OR optimized "normal" */ if(attr_sp>0) attr(attr_stack[--attr_sp]); else /* turn off all attributes if */ if(atr&(HIGH|BLINK|BG_LIGHTGRAY)) /* high intensity, blink or */ attr(LIGHTGRAY); /* background bits are set */ break; case '_': /* turn off all attributes if */ if(atr&(BLINK|BG_LIGHTGRAY)) /* blink or background is set */ attr(LIGHTGRAY); break; case 'P': /* Pause */ pause(); break; case 'Q': /* Pause reset */ lncntr=0; break; case 'T': /* Time */ now=time(NULL); localtime_r(&now,&tm); if(cfg.sys_misc&SM_MILITARY) bprintf("%02u:%02u:%02u" ,tm.tm_hour, tm.tm_min, tm.tm_sec); else bprintf("%02d:%02d %s" ,tm.tm_hour==0 ? 12 : tm.tm_hour>12 ? tm.tm_hour-12 : tm.tm_hour, tm.tm_min, tm.tm_hour>11 ? "pm":"am"); break; case 'D': /* Date */ now=time(NULL); bputs(unixtodstr(&cfg,(time32_t)now,tmp1)); break; case ',': /* Delay 1/10 sec */ mswait(100); break; case ';': /* Delay 1/2 sec */ mswait(500); break; case '.': /* Delay 2 secs */ mswait(2000); break; case 'S': /* Synchronize */ ASYNC; break; case 'L': /* CLS (form feed) */ CLS; break; case '>': /* CLREOL */ cleartoeol(); break; case '<': /* Non-destructive backspace */ outchar(BS); break; case '[': /* Carriage return */ outchar(CR); break; case ']': /* Line feed */ outchar(LF); break; case 'A': /* Ctrl-A */ outchar(CTRL_A); break; case 'H': /* High intensity */ atr|=HIGH; attr(atr); break; case 'I': /* Blink */ atr|=BLINK; attr(atr); break; case 'N': /* Normal */ attr(LIGHTGRAY); break; case 'R': atr=(atr&0xf8)|RED; attr(atr); break; case 'G': atr=(atr&0xf8)|GREEN; attr(atr); break; case 'B': atr=(atr&0xf8)|BLUE; attr(atr); break; case 'W': /* White */ atr=(atr&0xf8)|LIGHTGRAY; attr(atr); break; case 'C': atr=(atr&0xf8)|CYAN; attr(atr); break; case 'M': atr=(atr&0xf8)|MAGENTA; attr(atr); break; case 'Y': /* Yellow */ atr=(atr&0xf8)|BROWN; attr(atr); break; case 'K': /* Black */ atr=(atr&0xf8)|BLACK; attr(atr); break; case '0': /* Black Background */ atr=(atr&0x8f); attr(atr); break; case '1': /* Red Background */ atr=(atr&0x8f)|(uchar)BG_RED; attr(atr); break; case '2': /* Green Background */ atr=(atr&0x8f)|(uchar)BG_GREEN; attr(atr); break; case '3': /* Yellow Background */ atr=(atr&0x8f)|(uchar)BG_BROWN; attr(atr); break; case '4': /* Blue Background */ atr=(atr&0x8f)|(uchar)BG_BLUE; attr(atr); break; case '5': /* Magenta Background */ atr=(atr&0x8f)|(uchar)BG_MAGENTA; attr(atr); break; case '6': /* Cyan Background */ atr=(atr&0x8f)|(uchar)BG_CYAN; attr(atr); break; case '7': /* White Background */ atr=(atr&0x8f)|(uchar)BG_LIGHTGRAY; attr(atr); break; } }
void sbbs_t::outchar(char ch) { int i; if(console&CON_ECHO_OFF) return; if(ch==ESC) outchar_esc=1; else if(outchar_esc==1) { if(ch=='[') outchar_esc++; else outchar_esc=0; } else if(outchar_esc==2) { if(ch>='@' && ch<='~') outchar_esc++; } else outchar_esc=0; if(term_supports(NO_EXASCII) && ch&0x80) ch=exascii_to_ascii_char(ch); /* seven bit table */ if(ch==FF && lncntr>1 && !tos) { lncntr=0; CRLF; if(!(sys_status&SS_PAUSEOFF)) { pause(); while(lncntr && online && !(sys_status&SS_ABORT)) pause(); } } if(online==ON_REMOTE && console&CON_R_ECHO) { if(console&CON_R_ECHOX && (uchar)ch>=' ' && !outchar_esc) { ch=text[YN][3]; if(text[YN][2]==0 || ch==0) ch='X'; } if(ch==FF && term_supports(ANSI)) { putcom("\x1b[2J\x1b[H"); /* clear screen, home cursor */ } else { if(ch==(char)TELNET_IAC && !(telnet_mode&TELNET_MODE_OFF)) outcom(TELNET_IAC); /* Must escape Telnet IAC char (255) */ i=0; while(outcom(ch)&TXBOF && i<1440) { /* 3 minute pause delay */ if(!online) break; i++; if(sys_status&SS_SYSPAGE) sbbs_beep(i,80); else mswait(80); } if(i==1440) { /* timeout - beep flush outbuf */ i=rioctl(TXBC); lprintf(LOG_NOTICE,"timeout(outchar) %04X %04X\r\n",i,rioctl(IOFO)); outcom(BEL); rioctl(IOCS|PAUSE); } } } if(!outchar_esc) { if((uchar)ch>=' ') column++; else if(ch=='\r') column=0; else if(ch=='\b') { if(column) column--; } } if(ch==LF || column>=cols) { lncntr++; lbuflen=0; tos=0; column=0; } else if(ch==FF) { lncntr=0; lbuflen=0; tos=1; column=0; } else { if(!lbuflen) latr=curatr; if(lbuflen<LINE_BUFSIZE) lbuf[lbuflen++]=ch; } if(outchar_esc==3) outchar_esc=0; if(lncntr==rows-1 && ((useron.misc&UPAUSE) || sys_status&SS_PAUSEON) && !(sys_status&SS_PAUSEOFF)) { lncntr=0; pause(); } }
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); } }
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; } } }
void flash(void) { // NIGHTRIDER PORTB = 0xEE; mswait(150); PORTB = 0XDD; mswait(150); PORTB = 0XBB; mswait(150); PORTB = 0X77; mswait(150); PORTB = 0XBB; mswait(150); PORTB = 0XDD; mswait(150); PORTB = 0xEE; mswait(150); PORTB = 0XDD; mswait(150); PORTB = 0XBB; mswait(150); PORTB = 0X77; mswait(150); PORTB = 0XBB; mswait(150); PORTB = 0XDD; mswait(150); }
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); }
void main(void) { char i, cntas, temp, b1;//, small, great; unsigned int vals[AMOUNT]; int check; unsigned int great, small; PUCR = 0X02; DDRB = 0XF0; DDRP = 0X00; TimerInit (); //while(1) // uncomment for awesomeness flash(); cntas = AMOUNT; b1 = PTIP; for(i = 0; i < AMOUNT; i++) { while((PTIP & 1)) { temp = PORTB; temp = temp << 4; PORTB = temp; } vals[i] = PORTB;// >> 4; flash(); } great = vals[0]; small = vals[0]; for(i=0; i<AMOUNT; i++){ if(vals[i] > great){ great = vals[i]; } if(vals[i] < small) { small = vals[i]; } } PORTB = great;// << 4; mswait(1000); flash(); PORTB = small;// << 4; mswait(1000); flash(); for(i = AMOUNT - 1; i >= 0; i--) { PORTB = vals[i]; mswait(500); } }
bool sbbs_t::answer() { char str[MAX_PATH+1],str2[MAX_PATH+1],c; char tmp[(MAX_PATH > CRYPT_MAX_TEXTSIZE ? MAX_PATH:CRYPT_MAX_TEXTSIZE)+1]; char tmpname[CRYPT_MAX_TEXTSIZE+1]; char path[MAX_PATH+1]; int i,l,in; struct tm tm; useron.number=0; answertime=logontime=starttime=now=time(NULL); /* Caller ID is IP address */ SAFECOPY(cid,client_ipaddr); memset(&tm,0,sizeof(tm)); localtime_r(&now,&tm); safe_snprintf(str,sizeof(str),"%s %s %s %02d %u Node %3u" ,hhmmtostr(&cfg,&tm,str2) ,wday[tm.tm_wday] ,mon[tm.tm_mon],tm.tm_mday,tm.tm_year+1900,cfg.node_num); logline("@ ",str); safe_snprintf(str,sizeof(str),"%s %s [%s]", connection, client_name, cid); logline("@+:",str); if(client_ident[0]) { safe_snprintf(str,sizeof(str),"Identity: %s",client_ident); logline("@*",str); } online=ON_REMOTE; if(sys_status&SS_RLOGIN) { if(incom(1000)==0) { for(i=0;i<(int)sizeof(str)-1;i++) { in=incom(1000); if(in==0 || in==NOINP) break; str[i]=in; } str[i]=0; for(i=0;i<(int)sizeof(str2)-1;i++) { in=incom(1000); if(in==0 || in==NOINP) break; str2[i]=in; } str2[i]=0; for(i=0;i<(int)sizeof(terminal)-1;i++) { in=incom(1000); if(in==0 || in==NOINP) break; terminal[i]=in; } terminal[i]=0; lprintf(LOG_DEBUG,"Node %d RLogin: '******' / '%.*s' / '%s'" ,cfg.node_num ,LEN_ALIAS*2,str ,LEN_ALIAS*2,str2 ,terminal); SAFECOPY(rlogin_term, terminal); SAFECOPY(rlogin_name, str2); SAFECOPY(rlogin_pass, str); /* Truncate terminal speed (e.g. "/57600") from terminal-type string (but keep full terminal type/speed string in rlogin_term): */ truncstr(terminal,"/"); useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, rlogin_name); if(useron.number) { getuserdat(&cfg,&useron); useron.misc&=~TERM_FLAGS; SAFEPRINTF(path,"%srlogin.cfg",cfg.ctrl_dir); if(!findstr(client.addr,path)) { SAFECOPY(tmp, rlogin_pass); for(i=0;i<3;i++) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); rioctl(IOFI); /* flush input buffer */ bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); logline(LOG_NOTICE,"+!",str); bputs(text[PasswordPrompt]); console|=CON_R_ECHOX; getstr(tmp,LEN_PASS*2,K_UPPER|K_LOWPRIO|K_TAB); console&=~(CON_R_ECHOX|CON_L_ECHOX); } else { if(REALSYSOP) { rioctl(IOFI); /* flush input buffer */ if(!chksyspass()) bputs(text[InvalidLogon]); else { i=0; break; } } else break; } } if(i) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); logline(LOG_NOTICE,"+!",str); } lprintf(LOG_WARNING,"Node %d !CLIENT IP NOT LISTED in %s" ,cfg.node_num,path); useron.number=0; hangup(); } } } else lprintf(LOG_INFO,"Node %d RLogin: Unknown user: %s",cfg.node_num,rlogin_name); } if(rlogin_name[0]==0) { lprintf(LOG_NOTICE,"Node %d !RLogin: No user name received",cfg.node_num); sys_status&=~SS_RLOGIN; } } if(!(telnet_mode&TELNET_MODE_OFF)) { /* Disable Telnet Terminal Echo */ request_telnet_opt(TELNET_WILL,TELNET_ECHO); /* Will suppress Go Ahead */ request_telnet_opt(TELNET_WILL,TELNET_SUP_GA); /* Retrieve terminal type and speed from telnet client --RS */ request_telnet_opt(TELNET_DO,TELNET_TERM_TYPE); request_telnet_opt(TELNET_DO,TELNET_TERM_SPEED); request_telnet_opt(TELNET_DO,TELNET_SEND_LOCATION); request_telnet_opt(TELNET_DO,TELNET_NEGOTIATE_WINDOW_SIZE); request_telnet_opt(TELNET_DO,TELNET_NEW_ENVIRON); } #ifdef USE_CRYPTLIB if(sys_status&SS_SSH) { pthread_mutex_lock(&ssh_mutex); cryptGetAttributeString(ssh_session, CRYPT_SESSINFO_USERNAME, tmpname, &i); tmpname[i]=0; SAFECOPY(rlogin_name, tmpname); cryptGetAttributeString(ssh_session, CRYPT_SESSINFO_PASSWORD, tmp, &i); tmp[i]=0; SAFECOPY(rlogin_pass, tmp); pthread_mutex_unlock(&ssh_mutex); lprintf(LOG_DEBUG,"Node %d SSH login: '******'" ,cfg.node_num, tmpname); useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, tmpname); if(useron.number) { getuserdat(&cfg,&useron); useron.misc&=~TERM_FLAGS; for(i=0;i<3;i++) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); rioctl(IOFI); /* flush input buffer */ bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); /* crash here Sept-12-2010 str 0x06b3fc4c "(0000) Guest FAILED Password attempt: '*****@*****.**'" and Oct-6-2010 str 0x070ffc4c "(0000) Woot903 FAILED Password attempt: 'p67890pppsdsjhsdfhhfhnhnfhfhfdhjksdjkfdskw3902391=`'" char [261] */ logline(LOG_NOTICE,"+!",str); bputs(text[PasswordPrompt]); console|=CON_R_ECHOX; getstr(tmp,LEN_PASS*2,K_UPPER|K_LOWPRIO|K_TAB); console&=~(CON_R_ECHOX|CON_L_ECHOX); } else { if(REALSYSOP) { rioctl(IOFI); /* flush input buffer */ if(!chksyspass()) bputs(text[InvalidLogon]); else { i=0; break; } } else break; } } if(i) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); logline(LOG_NOTICE,"+!",str); } useron.number=0; hangup(); } } else lprintf(LOG_INFO,"Node %d SSH: Unknown user: %s",cfg.node_num,rlogin_name); } #endif /* Detect terminal type */ mswait(200); rioctl(IOFI); /* flush input buffer */ putcom( "\r\n" /* locate cursor at column 1 */ "\x1b[s" /* save cursor position (necessary for HyperTerm auto-ANSI) */ "\x1b[255B" /* locate cursor as far down as possible */ "\x1b[255C" /* locate cursor as far right as possible */ "\b_" /* need a printable at this location to actually move cursor */ "\x1b[6n" /* Get cursor position */ "\x1b[u" /* restore cursor position */ "\x1b[!_" /* RIP? */ "\x1b[30;40m\xc2\x9f""Zuul.connection.write('\\x1b""Are you the gatekeeper?')\xc2\x9c" /* ZuulTerm? */ "\x1b[0m_" /* "Normal" colors */ "\x1b[2J" /* clear screen */ "\x1b[H" /* home cursor */ "\xC" /* clear screen (in case not ANSI) */ "\r" /* Move cursor left (in case previous char printed) */ ); i=l=0; tos=1; lncntr=0; safe_snprintf(str, sizeof(str), "%s %s", VERSION_NOTICE, COPYRIGHT_NOTICE); strip_ctrl(str, str); center(str); while(i++<50 && l<(int)sizeof(str)-1) { /* wait up to 5 seconds for response */ c=incom(100)&0x7f; if(c==0) continue; i=0; if(l==0 && c!=ESC) // response must begin with escape char continue; str[l++]=c; if(c=='R') { /* break immediately if ANSI response */ mswait(500); break; } } while((c=(incom(100)&0x7f))!=0 && l<(int)sizeof(str)-1) str[l++]=c; str[l]=0; if(l) { c_escape_str(str,tmp,sizeof(tmp),TRUE); lprintf(LOG_DEBUG,"Node %d received terminal auto-detection response: '%s'" ,cfg.node_num,tmp); if(str[0]==ESC && str[1]=='[' && str[l-1]=='R') { int x,y; if(terminal[0]==0) SAFECOPY(terminal,"ANSI"); autoterm|=(ANSI|COLOR); if(sscanf(str+2,"%u;%u",&y,&x)==2) { lprintf(LOG_DEBUG,"Node %d received ANSI cursor position report: %ux%u" ,cfg.node_num, x, y); /* Sanity check the coordinates in the response: */ if(x>=40 && x<=255) cols=x; if(y>=10 && y<=255) rows=y; } } truncsp(str); if(strstr(str,"RIPSCRIP")) { if(terminal[0]==0) SAFECOPY(terminal,"RIP"); logline("@R",strstr(str,"RIPSCRIP")); autoterm|=(RIP|COLOR|ANSI); } else if(strstr(str,"Are you the gatekeeper?")) { if(terminal[0]==0) SAFECOPY(terminal,"HTML"); logline("@H",strstr(str,"Are you the gatekeeper?")); autoterm|=HTML; } } else if(terminal[0]==0) SAFECOPY(terminal,"DUMB"); rioctl(IOFI); /* flush left-over or late response chars */ if(!autoterm && str[0]) { c_escape_str(str,tmp,sizeof(tmp),TRUE); lprintf(LOG_NOTICE,"Node %d terminal auto-detection failed, response: '%s'" ,cfg.node_num, tmp); } /* AutoLogon via IP or Caller ID here */ if(!useron.number && !(sys_status&SS_RLOGIN) && (startup->options&BBS_OPT_AUTO_LOGON) && cid[0]) { useron.number=userdatdupe(0, U_NOTE, LEN_NOTE, cid); if(useron.number) { getuserdat(&cfg, &useron); if(!(useron.misc&AUTOLOGON) || !(useron.exempt&FLAG('V'))) useron.number=0; } } if(!online) return(false); if(stricmp(terminal,"sexpots")==0) { /* dial-up connection (via SexPOTS) */ SAFEPRINTF2(str,"%s connection detected at %lu bps", terminal, cur_rate); logline("@S",str); node_connection = (ushort)cur_rate; SAFEPRINTF(connection,"%lu",cur_rate); SAFECOPY(cid,"Unknown"); SAFECOPY(client_name,"Unknown"); if(telnet_location[0]) { /* Caller-ID info provided */ SAFEPRINTF(str, "CID: %s", telnet_location); logline("@*",str); SAFECOPY(cid,telnet_location); truncstr(cid," "); /* Only include phone number in CID */ char* p=telnet_location; FIND_WHITESPACE(p); SKIP_WHITESPACE(p); if(*p) { SAFECOPY(client_name,p); /* CID name, if provided (maybe 'P' or 'O' if private or out-of-area) */ } } SAFECOPY(client.addr,cid); SAFECOPY(client.host,client_name); client_on(client_socket,&client,TRUE /* update */); } else { if(telnet_location[0]) { /* Telnet Location info provided */ SAFEPRINTF(str, "Telnet Location: %s", telnet_location); logline("@*",str); } } useron.misc&=~TERM_FLAGS; useron.misc|=autoterm; SAFECOPY(useron.comp,client_name); if(!useron.number && rlogin_name[0]!=0 && !(cfg.sys_misc&SM_CLOSED) && !matchuser(&cfg, rlogin_name, /* Sysop alias: */FALSE)) { lprintf(LOG_INFO,"Node %d UNKNOWN %s-specified USERNAME: %s, starting new user signup",cfg.node_num,client.protocol,rlogin_name); bprintf("%s: %s\r\n", text[UNKNOWN_USER], rlogin_name); newuser(); } if(!useron.number) { /* manual/regular logon */ /* Display ANSWER screen */ rioctl(IOSM|PAUSE); sys_status|=SS_PAUSEON; SAFEPRINTF(str,"%sanswer",cfg.text_dir); SAFEPRINTF(path,"%s.rip",str); if((autoterm&RIP) && fexistcase(path)) printfile(path,P_NOABORT); else { SAFEPRINTF(path,"%s.html",str); if((autoterm&HTML) && fexistcase(path)) printfile(path,P_NOABORT); else { SAFEPRINTF(path,"%s.ans",str); if((autoterm&ANSI) && fexistcase(path)) printfile(path,P_NOABORT); else { SAFEPRINTF(path,"%s.asc",str); if(fexistcase(path)) printfile(path, P_NOABORT); } } } sys_status&=~SS_PAUSEON; exec_bin(cfg.login_mod,&main_csi); } else /* auto logon here */ if(logon()==false) return(false); if(!useron.number) hangup(); /* Save the IP to the user's note */ if(cid[0]) { SAFECOPY(useron.note,cid); putuserrec(&cfg,useron.number,U_NOTE,LEN_NOTE,useron.note); } /* Save host name to the user's computer description */ if(client_name[0]) { SAFECOPY(useron.comp,client_name); putuserrec(&cfg,useron.number,U_COMP,LEN_COMP,useron.comp); } if(!online) return(false); if(!(sys_status&SS_USERON)) { errormsg(WHERE,ERR_CHK,"User not logged on",0); hangup(); return(false); } if(useron.pass[0]) loginSuccess(startup->login_attempt_list, &client_addr); return(true); }
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); }