Annotation of sbbs/sbbs2/main_ovl.c, revision 1.1.1.1

1.1       root        1: #line 1 "MAIN_OVL.C"
                      2: 
                      3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
                      4: 
                      5: #include "sbbs.h"
                      6: #include "etext.h"
                      7: #include <signal.h>
                      8: 
                      9: #ifndef __FLAT__
                     10: #include "spawno.h"
                     11: #endif
                     12: 
                     13: uint asmrev;           // RCIOL.OBJ revision
                     14: char llo=0                     // Local logon only
                     15:        ,nmi=0;                 // No modem init
                     16: char cidarg[65];       // Caller ID arguments
                     17: uint addrio;           // Additional RIOCTL call on init
                     18: 
                     19: FILE *nodefile_fp,*node_ext_fp,*logfile_fp;
                     20: 
                     21: char prompt[128];
                     22: 
                     23: extern char *compile_time,*compile_date;
                     24: 
                     25: #ifdef __FLAT__
                     26: int mswtyp=0;
                     27: #else
                     28: extern mswtyp;
                     29: extern uint riobp;
                     30: #endif
                     31: 
                     32: extern char onquiet;
                     33: extern char term_ret;
                     34: extern ulong connect_rate;      /* already connected at xbps */
                     35: extern char *wday[],*mon[];
                     36: 
                     37: #ifdef __OS2__
                     38: extern long _timezone=0L;
                     39: extern int _daylight=0L;
                     40: #else
                     41: extern long timezone=0L;
                     42: extern int     daylight=0L;
                     43: #endif
                     44: 
                     45: #ifdef __OS2__
                     46:        extern HEV con_out_sem;
                     47:        void con_out_thread(void *);
                     48: #endif
                     49: 
                     50: 
                     51: #ifdef __OS2__
                     52: void cbreakh(int sig);
                     53: #else
                     54: int cbreakh();
                     55: #endif
                     56: 
                     57: void reset_logon_vars(void);
                     58: 
                     59: time_t checktime(void)
                     60: {
                     61:        struct tm tm;
                     62: 
                     63: memset(&tm,0,sizeof(tm));
                     64: tm.tm_year=94;
                     65: tm.tm_mday=1;
                     66: return(mktime(&tm)^0x2D24BD00L);
                     67: }
                     68: 
                     69: void console_test(void)
                     70: {
                     71:        int i;
                     72:        time_t start=time(NULL);;
                     73: 
                     74: lclxy(1,1);
                     75: online=ON_LOCAL;
                     76: console=CON_L_ECHO;
                     77: useron.misc=ANSI|COLOR;
                     78: for(i=0;i<500;i++)
                     79:        bprintf("\1n%05d\t\1hWhite\1rRed\1bBlue\1gGreen\001\x82"
                     80:                "\1mMagenta\t\b\b\1cCyan\1nNormal\1gGreen"
                     81:                "\1yBrown\1hYellow\1rR\1gG\1bB\1cC\1mM\1yY\1kK"
                     82:                "\1>\r\n"
                     83:                ,i);
                     84: bprintf("\r\n%lu secs\r\n",time(NULL)-start);
                     85: getch();
                     86: lputc(FF);
                     87: }
                     88: 
                     89: 
                     90: 
                     91: 
                     92: void  startup(int argc, char *argv[])
                     93: {
                     94:        char str[256],HUGE16 *buf,c;
                     95:     void *v;
                     96:        int i,j,events_only=0;
                     97:     int file;
                     98:     ulong l;
                     99:        node_t node;
                    100:     struct ffblk ff;
                    101:     struct tm *gm;
                    102: #ifdef __FLAT__
                    103:        uchar *cptab;   /* unused */
                    104: #else
                    105:        uchar cptab[1024];
                    106:     union REGS reg;
                    107: #endif
                    108: 
                    109: #ifdef __MSDOS__
                    110: setcbrk(0);
                    111: #endif
                    112: 
                    113: #ifndef __FLAT__
                    114: if((asmrev=*(&riobp-1))!=23) {
                    115:     printf("Wrong rciol.obj\n");
                    116:     exit(1); }
                    117: #endif
                    118: 
                    119: #ifdef __OS2__
                    120: signal(SIGINT,cbreakh);
                    121: signal(SIGBREAK,cbreakh);
                    122: fixkbdmode();
                    123: #elif defined(__MSDOS__)
                    124: ctrlbrk(cbreakh);
                    125: #endif
                    126: 
                    127: #ifndef __FLAT__                               /* no DESQview under OS/2 */
                    128: inDV = 0;
                    129: _CX = 0x4445; /* 'DE' */        /* set CX to 4445H; DX to 5351H     */
                    130: _DX = 0x5351; /* 'SQ' */        /* (an invalid date)                */
                    131: _AX = 0x2B01;                                  /* DOS' set data function           */
                    132: geninterrupt( 0x21 );                  /* call DOS                                             */
                    133: if ( _AL != 0xFF )                             /* if DOS didn't see as invalid     */
                    134:        _AX = _BX;                                      /* AH=major ver; AL=minor ver           */
                    135: else                                                   /* DOS saw as invalid                           */
                    136:        _AX = 0;                                        /* no desqview                                          */
                    137: inDV = _AX;                                    /* Save version in inDV flag            */
                    138: #endif
                    139: 
                    140: #ifdef __FLAT__
                    141: if(putenv("TZ=UCT0"))
                    142:        printf("putenv() failed!\n");
                    143: tzset();
                    144: #endif
                    145: 
                    146: if((l=checktime())!=0) {   /* Check binary time */
                    147:        printf("Time problem (%08lx)\n",l);
                    148:        exit(1); }
                    149: 
                    150: directvideo=1;  /* default to direct video */
                    151: 
                    152: _fmode=O_BINARY;
                    153: nulstr="";
                    154: crlf="\r\n";
                    155: strcpy(cap_fname,"CAPTURE.TXT");
                    156: sys_status=lncntr=tos=criterrs=keybufbot=keybuftop=lbuflen=slcnt=0L;
                    157: debug=1;
                    158: curatr=LIGHTGRAY;
                    159: errorlevel=0;
                    160: logcol=1;
                    161: next_event=0;
                    162: lastuseron[0]=0;
                    163: emsver=0;
                    164: emshandle=0xffff;
                    165: randomize();
                    166: srand(clock());
                    167: 
                    168: for(i=0;i<127 && environ[i];i++)  /* save original environment for execl() */
                    169:        envp[i]=environ[i];
                    170: envp[i]=0;
                    171: 
                    172: strcpy(str,getenv("PROMPT"));
                    173: if(!strstr(str,"[SBBS]")) {
                    174:        sprintf(prompt,"PROMPT=[SBBS] %s",str);
                    175:        putenv(prompt); }
                    176: 
                    177: comspec=getenv("COMSPEC");
                    178: 
                    179: lputc(FF);
                    180: 
                    181: #ifndef __FLAT__
                    182: node_scrnlen=lclini(0xd<<8);      /* Tab expansion, no CRLF expansion */
                    183: #else
                    184: node_scrnlen=25;
                    185: #endif
                    186: lclini(node_scrnlen);
                    187: lclatr(LIGHTGRAY);
                    188: 
                    189: #ifdef __OS2__ // Test console speed
                    190: 
                    191: if(DosCreateEventSem(NULL,&con_out_sem,0,0)) {
                    192:        printf("Can't create console output semaphore.\n");
                    193:        exit(2); }
                    194: 
                    195: if(_beginthread(con_out_thread,1024,NULL)==-1) {
                    196:        printf("Can't start console output thread.\n");
                    197:        exit(3); }
                    198: //console_test();
                    199: #endif
                    200: 
                    201: #if defined(__OS2__)
                    202: lputs(decrypt(VersionNoticeOS2,0));
                    203: #elif defined(__WIN32__)
                    204: lputs(decrypt(VersionNoticeW32,0));
                    205: #else
                    206: lputs(decrypt(VersionNoticeDOS,0));
                    207: #endif
                    208: lputs(decrypt(CopyrightNotice,0));      /* display copyright notice */
                    209: lputc(CR);
                    210: lputc(LF);
                    211: cidarg[0]=0;
                    212: addrio=0;
                    213: strcpy(orgcmd,argv[0]);     /* build up original command line */
                    214: strcat(orgcmd," ");
                    215: for(i=1;i<argc;i++) {
                    216:     for(c=0;c<strlen(argv[i]);c++)
                    217:         switch(toupper(argv[i][c])) {
                    218:             case '/':   /* ignore these characters */
                    219:             case '-':
                    220:                 break;
                    221:             case 'B':   /* desqview or other that needs bios video only */
                    222:                 directvideo=0;
                    223:                 strcat(orgcmd,"B");
                    224:                 break;
                    225:             case 'C':   /* connected at xbps */
                    226:                                connect_rate=atol(argv[i]+c+1);
                    227:                 c=strlen(argv[i]);
                    228:                 break;
                    229:                        case 'D':   /* assume DCD is always high */
                    230:                                sys_status|=SS_DCDHIGH;
                    231:                                strcat(orgcmd,"D");
                    232:                                break;
                    233:                        case 'E':
                    234:                                next_event=time(NULL)+(atol(argv[i]+c+1)*60L);
                    235:                                c=strlen(argv[i]);
                    236:                                break;
                    237:                        case 'F':
                    238:                                sys_status|=SS_DAILY;
                    239:                                break;
                    240: #ifdef __OS2__
                    241:                        case 'H':
                    242:                                rio_handle=atoi(argv[i]+c+1);
                    243:                                c=strlen(argv[i]);
                    244:                                break;
                    245: #endif
                    246:                        case 'I':   /* no modem init */
                    247:                                strcat(orgcmd,"I");
                    248:                                nmi=1;
                    249:                                break;
                    250:                        case 'L':   /* local logon only */
                    251:                                strcat(orgcmd,"L");
                    252:                                llo=1;
                    253:                                break;
                    254:                        case 'M':   /* modem debug info */
                    255:                                strcat(orgcmd,"M");
                    256:                                sys_status|=SS_MDMDEBUG;
                    257:                                break;
                    258:                        case 'O':   /* execute events only */
                    259:                                events_only=1;
                    260:                                break;
                    261:             case 'Q':   /* quit after one caller - phone off hook */
                    262:                 strcat(orgcmd,"Q");
                    263:                 qoc=1;
                    264:                 break;
                    265:                        case 'R':   /* additional rioctl call */
                    266:                                addrio=ahtoul(argv[i]+c+1);
                    267:                                c=strlen(argv[i]);
                    268:                                break;
                    269:             case 'X':   /* quit after one caller - phone on hook */
                    270:                 strcat(orgcmd,"X");
                    271:                 qoc=2;
                    272:                 break;
                    273:                        case 'Z':
                    274:                                sprintf(cidarg,"%-.64s",argv[i]+c+1);
                    275:                 c=strlen(argv[i]);
                    276:                                break;
                    277:                        case 'V':
                    278:                                lputs(crlf);
                    279:                                lprintf("Revision %c%s %s %.5s  "
                    280:                                #ifdef __FLAT__
                    281:                                        "RIOLIB %u.%02u"
                    282:                                #else
                    283:                                        "RCIOL %u"
                    284:                                #endif
                    285:                                        "  SMBLIB %s  BCC %X.%02X"
                    286:                                        ,REVISION,BETA,compile_date,compile_time
                    287:                                #ifdef __FLAT__
                    288:                                        ,rioctl(GVERS)/100,rioctl(GVERS)%100
                    289:                                #else
                    290:                                        ,rioctl(GVERS)
                    291:                                #endif
                    292:                                        ,SMBLIB_VERSION
                    293:                                        ,__BORLANDC__>>8
                    294:                                        ,__BORLANDC__&0xff);
                    295:                                lputs(crlf);
                    296:                                bail(0);
                    297:             default:
                    298:                                lputs("\r\nusage: sbbs [bdmoqxfliv] [c#] [e#] [zs] [r#] [h#]"
                    299:                                        "\r\n\r\n"
                    300:                     "b  = use bios for video\r\n"
                    301:                                        "d  = assume DCD is always high\r\n"
                    302:                                        "m  = modem debug output\r\n"
                    303:                     "q  = quit after one call (phone off hook)\r\n"
                    304:                     "x  = quit after one call\r\n"
                    305:                                        "o  = execute events only and then quit\r\n"
                    306:                                        "c# = connected at # bps (ex: c2400)\r\n"
                    307:                                        "e# = external event in # minutes (ex: e30)\r\n"
                    308:                                        "f  = force daily event\r\n"
                    309:                                        "l  = local logon only\r\n"
                    310:                                        "i  = no modem initialization\r\n"
                    311:                                        "zs = use s for caller-id information\r\n"
                    312:                                        "r# = additional rioctl call during port init\r\n"
                    313:                                        "h# = open port handle (SBBS4OS2 only)\r\n"
                    314:                                        "v  = version information\r\n"
                    315:                                        );
                    316:                 bail(0); } }
                    317: 
                    318: 
                    319: node_disk=getdisk();
                    320: getcwd(node_dir,MAXDIR);        /* Get current Directory    */
                    321: if(strlen(node_dir)>40) {
                    322:     lputs("\r\n\7Current Directory is too long for bbs to run reliably.\r\n");
                    323:     bail(1); }
                    324: strcat(node_dir,"\\");
                    325: initdata();                     /* auto-sense scrnlen can be overridden */
                    326: 
                    327: mswtyp=0;
                    328: if(node_misc&NM_INT28)
                    329:        mswtyp|=TS_INT28;
                    330: if(node_misc&NM_WINOS2)
                    331:        mswtyp|=TS_WINOS2;
                    332: if(node_misc&NM_NODV)
                    333:        mswtyp|=TS_NODV;
                    334: 
                    335: #ifndef __FLAT__
                    336: 
                    337: __spawn_ext = (node_swap & SWAP_EXT) != 0 ;
                    338: __spawn_ems = (node_swap & SWAP_EMS) != 0 ;
                    339: __spawn_xms = (node_swap & SWAP_XMS) != 0 ;
                    340: 
                    341: #endif
                    342: 
                    343: #ifndef __FLAT__                                /* no EMS under OS/2 */
                    344: if(node_misc&NM_EMSOVL) {
                    345:        lputs("\r\nEMS: ");
                    346:        if((i=open("EMMXXXX0",O_RDONLY))==-1)
                    347:                lputs("not installed.");
                    348:        else {
                    349:                close(i);
                    350:                reg.h.ah=0x46;                  /* Get EMS version */
                    351:                int86(0x67,&reg,&reg);
                    352:                if(reg.h.ah)
                    353:                        lputs("\7error getting version.");
                    354:                else {
                    355:                        lprintf("Version %u.%u ",(reg.h.al&0xf0)>>4,reg.h.al&0xf);
                    356:                        emsver=reg.h.al;
                    357:                        reg.h.ah=0x4b;          /* get handle count */
                    358:                        int86(0x67,&reg,&reg);
                    359:                        if(reg.h.ah)
                    360:                                lputs("\7error getting handle count.");
                    361:                        else {
                    362:                                if(_OvrInitEms(0,0,23))    /* use up to 360K */
                    363:                                        lprintf("allocation failed.");
                    364:                                else
                    365:                                        emshandle=reg.x.bx; } } } }
                    366: #endif
                    367: 
                    368: sprintf(str,"%s%s",ctrl_dir,"NODE.DAB");
                    369: if((nodefile_fp=fnopen(&nodefile,str
                    370:        ,O_DENYNONE|O_RDWR|O_CREAT))==NULL) {
                    371:     lprintf("\r\n\7Error opening/creating %s\r\n",str);
                    372:     exit(1); }
                    373: sprintf(str,"%s%s",ctrl_dir,"NODE.EXB");
                    374: if((node_ext_fp=fnopen(&node_ext,str,O_DENYNONE|O_RDWR|O_CREAT))==NULL) {
                    375:     lprintf("\r\n\7Error opening/creating %s\r\n",str);
                    376:     exit(1); }
                    377: memset(&node,0,sizeof(node_t));  /* write NULL to node struct */
                    378: node.status=NODE_OFFLINE;
                    379: while(filelength(nodefile)<sys_nodes*sizeof(node_t)) {
                    380:     lseek(nodefile,0L,SEEK_END);
                    381:     write(nodefile,&node,sizeof(node_t)); }
                    382: if(lock(nodefile,(node_num-1)*sizeof(node_t),sizeof(node_t))
                    383:        || unlock(nodefile,(node_num-1)*sizeof(node_t),sizeof(node_t))) {
                    384:     lprintf("\r\n\7File locking failed.\r\n");
                    385: 
                    386: #ifndef __FLAT__                        /* no SHARE under Win32 and OS/2 */
                    387:     reg.x.ax=0x1000;
                    388:     int86(0x2f,&reg,&reg);
                    389:        if(!reg.h.al) {
                    390:         lputs("SHARE is not installed. Must run SHARE before SBBS.\r\n");
                    391:                lputs("SHARE.EXE is included with DOS v3.0 and higher.\r\n"); }
                    392:     else if(reg.h.al==1)
                    393:         lputs("SHARE is not installed and NOT OKAY to install.\r\n");
                    394:     else if(reg.h.al==0xff)
                    395:         lputs("SHARE is installed.\r\n");
                    396:     else
                    397:         lprintf("INT 2F returned %xh in AL.\r\n",reg.h.al);
                    398: #endif
                    399: 
                    400:     bail(1); }
                    401: sys_status|=SS_NODEDAB; /* says that node.dab is okay to use */
                    402: getnodedat(node_num,&thisnode,1);
                    403: 
                    404: /* if not returning, clear node.dab record */
                    405: if(!connect_rate) {
                    406:        thisnode.status=thisnode.action=thisnode.useron=0;
                    407:     thisnode.aux=0; /* use to always clear */
                    408:     thisnode.misc&=NODE_EVENT; }    /* turn off all misc bits but event */
                    409: criterrs=thisnode.errors;
                    410: putnodedat(node_num,thisnode);
                    411: 
                    412: if(com_base==0xb)
                    413:        rioctl(I14PC);
                    414: else if(com_base==0xd)
                    415:        rioctl(I14DB);
                    416: else if(com_base==0xe)
                    417:        rioctl(I14PS);
                    418: else if(com_base==0xf)
                    419:        rioctl(I14FO);
                    420: if(com_port) {
                    421:     comini();
                    422:        setrate(); }
                    423: 
                    424: for(i=0;i<total_qhubs;i++) {
                    425:        if(qhub[i]->node!=node_num)
                    426:                continue;
                    427:        for(j=0;j<10;j++) {
                    428:                sprintf(str,"%s%s.QW%c",data_dir,qhub[i]->id,j ? (j-1)+'0' : 'K');
                    429:                if(fexist(str)) {
                    430:                        lclini(node_scrnlen-1);
                    431:                        delfiles(temp_dir,"*.*");
                    432:                        unpack_qwk(str,i); } } }
                    433: 
                    434: sprintf(str,"%sTIME.DAB",ctrl_dir);
                    435: if((file=nopen(str,O_RDWR|O_CREAT))==-1) {
                    436:     lprintf("Error opening/creating %s\r\n",str);
                    437:     bail(1); }
                    438: for(i=0;i<total_events;i++) {
                    439:        event[i]->last=0;
                    440:        if(filelength(file)<sizeof(time_t)*(i+1))
                    441:                write(file,&event[i]->last,sizeof(time_t));
                    442:        else
                    443:                read(file,&event[i]->last,sizeof(time_t)); }
                    444: 
                    445: close(file);
                    446: 
                    447: sprintf(str,"%sQNET.DAB",ctrl_dir);
                    448: if((file=nopen(str,O_RDWR|O_CREAT))==-1) {
                    449:     lprintf("Error opening/creating %s\r\n",str);
                    450:     bail(1); }
                    451: 
                    452: for(i=0;i<total_qhubs;i++) {
                    453:        qhub[i]->last=0;
                    454:        if(filelength(file)<sizeof(time_t)*(i+1))
                    455:                write(file,&qhub[i]->last,sizeof(time_t));
                    456:     else
                    457:                read(file,&qhub[i]->last,sizeof(time_t)); }
                    458: 
                    459: close(file);
                    460: 
                    461: sprintf(str,"%sPNET.DAB",ctrl_dir);
                    462: if((file=nopen(str,O_RDWR|O_CREAT))==-1) {
                    463:     lprintf("Error opening/creating %s\r\n",str);
                    464:     bail(1); }
                    465: 
                    466: for(i=0;i<total_phubs;i++) {
                    467:        phub[i]->last=0;
                    468:        if(filelength(file)<sizeof(time_t)*(i+1))
                    469:         write(file,&phub[i]->last,sizeof(time_t));
                    470:     else
                    471:         read(file,&phub[i]->last,sizeof(time_t)); }
                    472: 
                    473: close(file);
                    474: 
                    475: sprintf(str,"%sNODE.LOG",node_dir);
                    476: lprintf("\r\nOpening %s...",str);
                    477: if((logfile_fp=fnopen(&logfile,str,O_WRONLY|O_CREAT|O_APPEND|O_DENYALL))==NULL) {
                    478:        lprintf("\r\n\7Error opening %s\r\n\r\n"
                    479:                "Perhaps this node is already running.\r\n",str);
                    480:     bail(1); }
                    481: lprintf("\r%s opened.",str);
                    482: sys_status|=SS_LOGOPEN;
                    483: if(filelength(logfile)) {
                    484:        log(crlf);
                    485:        now=time(NULL);
                    486:     gm=localtime(&now);
                    487:        sprintf(str,"%02d:%02d%c  %s %s %02d %u  "
                    488:                "End of preexisting log entry (possible crash)"
                    489:                ,gm->tm_hour>12 ? gm->tm_hour-12 : gm->tm_hour==0 ? 12 : gm->tm_hour
                    490:                ,gm->tm_min,gm->tm_hour>=12 ? 'p' : 'a',wday[gm->tm_wday]
                    491:                ,mon[gm->tm_mon],gm->tm_mday,gm->tm_year+1900);
                    492:        logline("L!",str);
                    493:        log(crlf);
                    494:        catsyslog(1); }
                    495: lputc(CLREOL);
                    496: sprintf(dszlog,"DSZLOG=%sPROTOCOL.LOG",node_dir);
                    497: putenv(dszlog);                /* Makes the DSZ LOG active */
                    498: sprintf(sbbsnode,"SBBSNODE=%s",node_dir);
                    499: putenv(sbbsnode);              /* create enviornment var to contain node num */
                    500: sprintf(sbbsnnum,"SBBSNNUM=%d",node_num);
                    501: putenv(sbbsnnum);         /* create enviornment var to contain node num */
                    502: backout();
                    503: if(events_only) {
                    504:        reset_logon_vars();
                    505:        while(!wfc_events(time(NULL)))
                    506:                ;
                    507:        bail(0); }
                    508: }
                    509: 
                    510: /****************************************************************************/
                    511: /* Reads data from DSTS.DAB into stats structure                            */
                    512: /* If node is zero, reads from ctrl\dsts.dab, otherwise from each node         */
                    513: /****************************************************************************/
                    514: void getstats(char node,stats_t *stats)
                    515: {
                    516:     char str[256];
                    517:     int file;
                    518: 
                    519: sprintf(str,"%sDSTS.DAB",node ? node_path[node-1] : ctrl_dir);
                    520: if((file=nopen(str,O_RDONLY))==-1) {
                    521:        errormsg(WHERE,ERR_OPEN,str,O_RDONLY);
                    522:     return; }
                    523: lseek(file,4L,SEEK_SET);    /* Skip update time/date */
                    524: read(file,stats,sizeof(stats_t));
                    525: close(file);
                    526: }
                    527: 
                    528: 
                    529: /****************************************************************************/
                    530: /* Updates dstst.dab file upon user logoff.                                                            */
                    531: /* First node, then system stats.                                           */
                    532: /****************************************************************************/
                    533: void logoffstats()
                    534: {
                    535:     char str[256];
                    536:     int i,file;
                    537:     stats_t stats;
                    538: 
                    539: for(i=0;i<2;i++) {
                    540:     sprintf(str,"%sDSTS.DAB",i ? ctrl_dir : node_dir);
                    541:     if((file=nopen(str,O_RDWR))==-1) {
                    542:                errormsg(WHERE,ERR_OPEN,str,O_RDWR);
                    543:         return; }
                    544:     lseek(file,12L,SEEK_SET);   /* Skip timestamp, logons and logons today */
                    545:     read(file,&stats.timeon,4);   /* Total time on system  */
                    546:        stats.timeon+=(now-logontime)/60;
                    547:     read(file,&stats.ttoday,4); /* Time today on system  */
                    548:        stats.ttoday+=(now-logontime)/60;
                    549:     read(file,&stats.uls,4);        /* Uploads today         */
                    550:     stats.uls+=logon_uls;
                    551:     read(file,&stats.ulb,4);        /* Upload bytes today    */
                    552:     stats.ulb+=logon_ulb;
                    553:     read(file,&stats.dls,4);        /* Downloads today       */
                    554:     stats.dls+=logon_dls;
                    555:     read(file,&stats.dlb,4);        /* Download bytes today  */
                    556:     stats.dlb+=logon_dlb;
                    557:        read(file,&stats.ptoday,4);     /* Posts today                   */
                    558:        if(!(useron.rest&FLAG('Q')))
                    559:                stats.ptoday+=logon_posts;
                    560:     read(file,&stats.etoday,4); /* Emails today          */
                    561:     stats.etoday+=logon_emails;
                    562:     read(file,&stats.ftoday,4); /* Feedback sent today  */
                    563:     stats.ftoday+=logon_fbacks;
                    564:        read(file,&stats.nusers,2); /* New users today          */
                    565:        if(sys_status&SS_NEWUSER)
                    566:                stats.nusers++;
                    567:     lseek(file,12L,SEEK_SET);
                    568:        write(file,&stats.timeon,4);    /* Total time on system  */
                    569:     write(file,&stats.ttoday,4);    /* Time today on system  */
                    570:     write(file,&stats.uls,4);       /* Uploads today         */
                    571:     write(file,&stats.ulb,4);       /* Upload bytes today    */
                    572:     write(file,&stats.dls,4);       /* Downloads today       */
                    573:     write(file,&stats.dlb,4);       /* Download bytes today  */
                    574:     write(file,&stats.ptoday,4);    /* Posts today           */
                    575:     write(file,&stats.etoday,4);    /* Emails today          */
                    576:        write(file,&stats.ftoday,4);    /* Feedback sent today   */
                    577:        write(file,&stats.nusers,2);    /* New users today               */
                    578:     close(file); }
                    579: 
                    580: }
                    581: 
                    582: /****************************************************************************/
                    583: /* Lists system statistics for everyday the bbs has been running.           */
                    584: /* Either for the current node (node=1) or the system (node=0)              */
                    585: /****************************************************************************/
                    586: void printstatslog(uint node)
                    587: {
                    588:     char str[256];
                    589:     uchar *buf;
                    590:     int file;
                    591:     time_t timestamp;
                    592:     long l;
                    593:     ulong   length,
                    594:             logons,
                    595:             timeon,
                    596:             posts,
                    597:             emails,
                    598:             fbacks,
                    599:             ulb,
                    600:             uls,
                    601:             dlb,
                    602:             dls;
                    603: 
                    604: if(node)
                    605:     bprintf(text[NodeStatsLogHdr],node);
                    606: else
                    607:     bputs(text[SysStatsLogHdr]);
                    608: sprintf(str,"%sCSTS.DAB",node ? node_path[node-1] : ctrl_dir);
                    609: if((file=nopen(str,O_RDONLY))==-1)
                    610:     return;
                    611: length=filelength(file);
                    612: if(length<40) {
                    613:     close(file);
                    614:     return; }
                    615: if((buf=(char *)MALLOC(length))==0) {
                    616:     close(file);
                    617:        errormsg(WHERE,ERR_ALLOC,str,length);
                    618:     return; }
                    619: read(file,buf,length);
                    620: close(file);
                    621: l=length-4;
                    622: while(l>-1L && !msgabort()) {
                    623:     fbacks=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
                    624:         |((long)buf[l+3]<<24);
                    625:     l-=4;
                    626:     emails=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
                    627:         |((long)buf[l+3]<<24);
                    628:     l-=4;
                    629:     posts=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
                    630:         |((long)buf[l+3]<<24);
                    631:     l-=4;
                    632:     dlb=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
                    633:         |((long)buf[l+3]<<24);
                    634:     l-=4;
                    635:     dls=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
                    636:         |((long)buf[l+3]<<24);
                    637:     l-=4;
                    638:     ulb=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
                    639:         |((long)buf[l+3]<<24);
                    640:     l-=4;
                    641:     uls=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
                    642:         |((long)buf[l+3]<<24);
                    643:     l-=4;
                    644:     timeon=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
                    645:         |((long)buf[l+3]<<24);
                    646:     l-=4;
                    647:     logons=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
                    648:         |((long)buf[l+3]<<24);
                    649:     l-=4;
                    650:     timestamp=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
                    651:         |((long)buf[l+3]<<24);
                    652:     l-=4;
                    653:     unixtodos(timestamp-(24*60*60),&date,&curtime); /* 1 day less than stamp */
                    654:     bprintf(text[SlogFmt]
                    655:         ,date.da_mon,date.da_day,date.da_year-1900,timeon,logons,posts,emails
                    656:         ,fbacks,ulb/1024,uls,dlb/1024,dls); }
                    657: FREE(buf);
                    658: }
                    659: 
                    660: #ifdef __OS2__
                    661: #define INPUT_LOOP 1000
                    662: #else
                    663: #define INPUT_LOOP 1000
                    664: #endif
                    665: 
                    666: /****************************************************************************/
                    667: /* Terminal mode                                                            */
                    668: /* Returns 1 if it is to logon locally, 0 if it is done.                    */
                    669: /****************************************************************************/
                    670: char terminal()
                    671: {
                    672:     char str[256],c,x,y,*p;
                    673:        int file;
                    674:        uint i,l;
                    675: 
                    676: lclini(node_scrnlen-1);
                    677: statline=-1;
                    678: statusline();
                    679: if(!term_ret) {
                    680: #ifdef __FLAT__
                    681:        setbaud(com_rate);
                    682: #else
                    683:        setbaud((uint)(com_rate&0xffffL));
                    684: #endif
                    685:        mdmcmd(mdm_term); }
                    686: else
                    687:     lputs("\r\nReturned.\r\n");
                    688: 
                    689: l=0;    /* l is the ansi response code counter */
                    690: 
                    691: while(1) {
                    692:     if(lkbrd(1)) {
                    693:         i=lkbrd(0);
                    694:         if((i&0xff)==0) {
                    695:             i>>=8;
                    696:                        if(i==45) {                     /* Alt-X */
                    697:                 rioctl(0x11);
                    698:                                if(DCDHIGH) {
                    699:                     lputs("\r\nHang up (Yes/No/Abort) ? ");
                    700:                                        c=toupper(getch());
                    701:                                        if(c!='Y' && c!='N') {  /* Hang-up Y/N/Abort */
                    702:                         lputs("Abort\r\n");
                    703:                         continue; }
                    704:                                        if(c=='Y') {    /* Yes, hang-up */
                    705:                                                if(mdm_misc&MDM_NODTR)
                    706:                                                        mdmcmd(mdm_hang);
                    707:                                                else
                    708:                                                        if(dtr(15))
                    709:                                                                lputs("Dropping DTR Failed"); } }
                    710:                 break; }
                    711:                        else if(i==35) {                /* Alt-H */
                    712:                                if(mdm_misc&MDM_NODTR)
                    713:                                        mdmcmd(mdm_hang);
                    714:                                else
                    715:                                        if(dtr(15))
                    716:                                                lputs("Dropping DTR Failed\r\n");
                    717:                 dtr(1); }
                    718:                        else if((i>=0x3b &&i<=0x44) || (i>=0x54 &&i<=0x71)
                    719:                                || (i>=0x85 &&i<=0x8c)) {
                    720:                 sprintf(str,"%s%sF%d.MAC",text_dir
                    721:                     ,i<0x45 || (i>=0x85 && i<=0x86) ? nulstr
                    722:                     :i<0x5e || (i>=0x87 && i<=0x88) ? "SHFT-"
                    723:                     :i<0x68 || (i>=0x89 && i<=0x8a) ? "CTRL-" : "ALT-"
                    724:                     ,i<0x45 ? i-0x3a : i<0x5e ? i-0x53 : i<0x68 ? i-0x5d
                    725:                     :i<0x72 ? i-0x67 : i<0x87 ? i-0x7a : i<0x89 ? i-0x7c
                    726:                     :i<0x8b ? i-0x7e : i-0x80);
                    727:                 if((file=nopen(str,O_RDONLY))==-1)
                    728:                     continue;
                    729:                 i=filelength(file);
                    730:                 while(i--) {
                    731:                     read(file,&c,1);
                    732:                     if(c!=LF)
                    733:                         putcomch(c); }
                    734:                 close(file); }
                    735:                        else if(i==0x48)        /* up arrow */
                    736:                                putcom("\x1b[A");
                    737:                        else if(i==0x50)        /* dn arrow */
                    738:                                putcom("\x1b[B");
                    739:                        else if(i==0x4b)        /* left */
                    740:                                putcom("\x1b[D");
                    741:                        else if(i==0x4d)        /* right */
                    742:                                putcom("\x1b[C");
                    743:             else if(i==0x16) {  /* Alt-U User Edit */
                    744:                                if((p=MALLOC((node_scrnlen*80)*2))==NULL) {
                    745:                     lputs("Allocation error.\r\n");
                    746:                     continue; }
                    747:                 gettext(1,1,80,node_scrnlen,p);
                    748:                 x=lclwx();
                    749:                 y=lclwy();
                    750:                 quicklogonstuff();
                    751:                                useredit(0,1);
                    752:                 puttext(1,1,80,node_scrnlen,p);
                    753:                                FREE(p);
                    754:                 lclxy(x,y); }
                    755:             else if(i==0x26) { /* Alt-L logon locally */
                    756:                 lputc(FF);
                    757:                 quicklogonstuff();
                    758:                 if(!useron.number) {
                    759:                     lputc(7);
                    760:                     lputs("A Sysop account hasn't been created");
                    761:                     continue; }
                    762:                 term_ret=1;
                    763:                 return(1); }
                    764:             else if(i==0x20) {  /* Alt-D Shell to DOS */
                    765:                                if((p=MALLOC((node_scrnlen*80)*2))==NULL) {
                    766:                     lputs("Allocation error.\r\n");
                    767:                     continue; }
                    768:                 gettext(1,1,80,node_scrnlen,p);
                    769:                 x=lclwx();
                    770:                 y=lclwy();
                    771:                 lclini(node_scrnlen);
                    772:                 lputc(FF);
                    773:                                external(comspec,0);
                    774:                 puttext(1,1,80,node_scrnlen,p);
                    775:                                FREE(p);
                    776:                 lclxy(x,y); } }
                    777:                else {
                    778:                        putcomch(i);
                    779:                        continue; } }
                    780:        for(i=0;i<INPUT_LOOP;i++) {
                    781:         if((c=incom())!=0) {
                    782:                        if(c==ESC)
                    783:                 l=!l;
                    784:             else if(l) {
                    785:                 if(c=='[') {
                    786:                     if(l!=1) l=0; else l++; }
                    787:                 else if(c=='6') {
                    788:                     if(l!=2) l=0; else l++; }
                    789:                 else if(c=='n') {
                    790:                     if(l==3) {
                    791:                                                sprintf(str,"\x1b[%u;%uR"
                    792:                             ,lclwy(),lclwx());
                    793:                         putcom(str); }
                    794:                     l=0; }
                    795:                 else l=0; }
                    796:                        outcon(c); }
                    797:                else
                    798:                        break; }
                    799:        if(!c)
                    800:                mswait(0); }
                    801: term_ret=0;
                    802: return(0);
                    803: }
                    804: 
                    805: 
                    806: /****************************************************************************/
                    807: /* Exits bbs to DOS with appropriate error code after setting COM port isr  */
                    808: /* back to normal.                                                          */
                    809: /****************************************************************************/
                    810: void bail(int code)
                    811: {
                    812: 
                    813: if(sys_status&SS_COMISR)
                    814:     rioini(0,0);
                    815: 
                    816: lclatr(LIGHTGRAY);
                    817: if(code) {
                    818:        getnodedat(node_num,&thisnode,1);
                    819:        criterrs=++thisnode.errors;
                    820:        putnodedat(node_num,thisnode);
                    821:     now=time(NULL);
                    822:     lprintf("\r\nExiting with errorlevel (%d) on %s\r\n",code,timestr(&now));
                    823:     if(sys_misc&SM_ERRALARM) {
                    824:                beep(500,220); beep(250,220);
                    825:                beep(500,220); beep(250,220);
                    826:                beep(500,220); beep(250,220);
                    827:         nosound(); } }
                    828: 
                    829: if(sys_status&SS_INITIAL) {
                    830:     getnodedat(node_num,&thisnode,1);
                    831:     thisnode.status=NODE_OFFLINE;
                    832:     putnodedat(node_num,thisnode);
                    833:     close(nodefile);
                    834:     close(node_ext); }
                    835: 
                    836: exit(code);
                    837: }
                    838: 
                    839: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.