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

1.1       root        1: #line 1 "GETNODE.C"
                      2: 
                      3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
                      4: 
                      5: #include "sbbs.h"
                      6: #include "cmdshell.h"
                      7: 
                      8: /****************************************************************************/
                      9: /* Reads the data for node number 'number' into the structure 'node'        */
                     10: /* from NODE.DAB                                                                                                                       */
                     11: /* if lockit is non-zero, locks this node's record. putnodedat() unlocks it */
                     12: /****************************************************************************/
                     13: void getnodedat(uint number, node_t *node, char lockit)
                     14: {
                     15:        char str[256];
                     16:        int count=0;
                     17: 
                     18: if(!(sys_status&SS_NODEDAB))
                     19:        return;
                     20: if(!number || number>sys_nodes) {
                     21:        errormsg(WHERE,ERR_CHK,"node number",number);
                     22:        return; }
                     23: number--;      /* make zero based */
                     24: while(count<LOOP_NODEDAB) {
                     25:        if(count>10)
                     26:                mswait(55);
                     27:        lseek(nodefile,(long)number*sizeof(node_t),SEEK_SET);
                     28:        if(lockit
                     29:                && lock(nodefile,(long)number*sizeof(node_t),sizeof(node_t))==-1) {
                     30:                count++;
                     31:                continue; }
                     32:        if(read(nodefile,node,sizeof(node_t))==sizeof(node_t))
                     33:                break;
                     34:        count++; }
                     35: if(count>(LOOP_NODEDAB/2) && count!=LOOP_NODEDAB) {
                     36:        sprintf(str,"NODE.DAB COLLISION - Count: %d",count);
                     37:        logline("!!",str); }
                     38: if(count==LOOP_NODEDAB) {
                     39:        errormsg(WHERE,ERR_READ,"NODE.DAB",number+1);
                     40:        return; }
                     41: }
                     42: 
                     43: /****************************************************************************/
                     44: /* Synchronizes all the nodes knowledge of the other nodes' actions, mode,  */
                     45: /* status and other flags.                                                  */
                     46: /* Assumes that getnodedat(node_num,&thisnode,0) was called right before it */
                     47: /* is called.                                                                                                                                  */
                     48: /****************************************************************************/
                     49: void nodesync()
                     50: {
                     51:        static user_t user;
                     52:        static int inside;
                     53:        char str[256],today[32];
                     54:        int i,j,atr=curatr; /* was lclatr(-1) 01/29/96 */
                     55:        node_t node;
                     56: 
                     57: if(inside) return;
                     58: inside=1;
                     59: 
                     60: if(thisnode.action!=action) {
                     61:        getnodedat(node_num,&thisnode,1);
                     62:        thisnode.action=action;
                     63:        putnodedat(node_num,thisnode); }
                     64: 
                     65: criterrs=thisnode.errors;
                     66: 
                     67: if(sys_status&SS_USERON) {
                     68:        if(!(sys_status&SS_NEWDAY)) {
                     69:                now=time(NULL);
                     70:                unixtodstr(logontime,str);
                     71:                unixtodstr(now,today);
                     72:                if(strcmp(str,today)) { /* New day, clear "today" user vars */
                     73:                        sys_status|=SS_NEWDAY;  // So we don't keep doing this over&over
                     74:                        putuserrec(useron.number,U_ETODAY,5,"0");
                     75:                        putuserrec(useron.number,U_PTODAY,5,"0");
                     76:                        putuserrec(useron.number,U_TTODAY,5,"0");
                     77:                        putuserrec(useron.number,U_LTODAY,5,"0");
                     78:                        putuserrec(useron.number,U_TEXTRA,5,"0");
                     79:                        putuserrec(useron.number,U_FREECDT,10
                     80:                                ,ultoa(level_freecdtperday[useron.level],str,10));
                     81:                        getuserdat(&useron); } }
                     82:        if(thisnode.misc&NODE_UDAT && !(useron.rest&FLAG('G'))) {   /* not guest */
                     83:                getuserdat(&useron);
                     84:                getnodedat(node_num,&thisnode,1);
                     85:                thisnode.misc&=~NODE_UDAT;
                     86:                putnodedat(node_num,thisnode); }
                     87:        if(thisnode.misc&NODE_MSGW)
                     88:                getsmsg(useron.number);         /* getsmsg clears MSGW flag */
                     89:        if(thisnode.misc&NODE_NMSG)
                     90:                getnmsg(); }                            /* getnmsg clears NMSG flag */
                     91: 
                     92: if(sync_mod[0])
                     93:        exec_bin(sync_mod,&main_csi);
                     94: 
                     95: if(thisnode.misc&NODE_INTR) {
                     96:     bputs(text[NodeLocked]);
                     97:        logline(nulstr,"Interrupted");
                     98:     hangup();
                     99:        inside=0;
                    100:     return; }
                    101: 
                    102: if(sys_status&SS_USERON && memcmp(&user,&useron,sizeof(user_t))) {
                    103: //       lputc(7);
                    104:     getusrdirs();
                    105:     getusrsubs();
                    106:     user=useron; }
                    107: 
                    108: if(sys_status&SS_USERON && online && (timeleft/60)<(5-timeleft_warn)
                    109:        && !SYSOP) {
                    110:        timeleft_warn=5-(timeleft/60);
                    111:        attr(LIGHTGRAY);
                    112:        bprintf(text[OnlyXminutesLeft]
                    113:                ,((ushort)timeleft/60)+1,(timeleft/60) ? "s" : nulstr); }
                    114: 
                    115: attr(atr);     /* replace original attributes */
                    116: inside=0;
                    117: }
                    118: 
                    119: /****************************************************************************/
                    120: /* Prints short messages waiting for this node, if any...                   */
                    121: /****************************************************************************/
                    122: void getnmsg()
                    123: {
                    124:        char str[256], HUGE16 *buf;
                    125:        int file;
                    126:        long length;
                    127: 
                    128: getnodedat(node_num,&thisnode,1);
                    129: thisnode.misc&=~NODE_NMSG;          /* clear the NMSG flag */
                    130: putnodedat(node_num,thisnode);
                    131: 
                    132: #if 0
                    133: /* Only for v1b rev 2-5 and XSDK v2.1x compatibility */
                    134: sprintf(str,"%sMSGS\\N%3.3u.IXB",data_dir,node_num);
                    135: if((ixb=nopen(str,O_RDONLY))!=-1) {
                    136:     read(ixb,&offset,4);
                    137:     chsize(ixb,0L);
                    138:     close(ixb);
                    139:     remove(str); }
                    140: #endif
                    141: 
                    142: sprintf(str,"%sMSGS\\N%3.3u.MSG",data_dir,node_num);
                    143: if(flength(str)<1L)
                    144:        return;
                    145: if((file=nopen(str,O_RDWR))==-1) {
                    146:        /**
                    147:                errormsg(WHERE,ERR_OPEN,str,O_RDWR);
                    148:        **/
                    149:     return; }
                    150: length=filelength(file);
                    151: if(!length) {
                    152:        close(file);
                    153:        return; }
                    154: if((buf=LMALLOC(length+1))==NULL) {
                    155:     close(file);
                    156:     errormsg(WHERE,ERR_ALLOC,str,length+1);
                    157:     return; }
                    158: if(lread(file,buf,length)!=length) {
                    159:     close(file);
                    160:     FREE(buf);
                    161:     errormsg(WHERE,ERR_READ,str,length);
                    162:     return; }
                    163: chsize(file,0L);
                    164: close(file);
                    165: buf[length]=0;
                    166: 
                    167: if(thisnode.action==NODE_MAIN || thisnode.action==NODE_XFER
                    168:     || sys_status&SS_IN_CTRLP) {
                    169:     CRLF; }
                    170: putmsg(buf,P_NOATCODES);
                    171: LFREE(buf);
                    172: }
                    173: 
                    174: /****************************************************************************/
                    175: /* 'ext' must be at least 128 bytes!                                        */
                    176: /****************************************************************************/
                    177: void getnodeext(uint number, char *ext)
                    178: {
                    179:     char str[256];
                    180:     int count=0;
                    181: 
                    182: if(!(sys_status&SS_NODEDAB))
                    183:     return;
                    184: if(!number || number>sys_nodes) {
                    185:     errormsg(WHERE,ERR_CHK,"node number",number);
                    186:     return; }
                    187: number--;   /* make zero based */
                    188: while(count<LOOP_NODEDAB) {
                    189:     if(count>10)
                    190:         mswait(55);
                    191:     if(lock(node_ext,(long)number*128L,128)==-1) {
                    192:         count++;
                    193:         continue; }
                    194:     lseek(node_ext,(long)number*128L,SEEK_SET);
                    195:     if(read(node_ext,ext,128)==128)
                    196:         break;
                    197:     count++; }
                    198: unlock(node_ext,(long)number*128L,128);
                    199: if(count>(LOOP_NODEDAB/2) && count!=LOOP_NODEDAB) {
                    200:     sprintf(str,"NODE.EXB COLLISION - Count: %d",count);
                    201:     logline("!!",str); }
                    202: if(count==LOOP_NODEDAB) {
                    203:     errormsg(WHERE,ERR_READ,"NODE.EXB",number+1);
                    204:     return; }
                    205: }
                    206: 
                    207: 
                    208: /****************************************************************************/
                    209: /* Prints short messages waiting for 'usernumber', if any...                */
                    210: /* then deletes them.                                                       */
                    211: /****************************************************************************/
                    212: void getsmsg(int usernumber)
                    213: {
                    214:        char str[256], HUGE16 *buf;
                    215:     int file;
                    216:     long length;
                    217: 
                    218: sprintf(str,"%sMSGS\\%4.4u.MSG",data_dir,usernumber);
                    219: if(flength(str)<1L)
                    220:     return;
                    221: if((file=nopen(str,O_RDWR))==-1) {
                    222:     errormsg(WHERE,ERR_OPEN,str,O_RDWR);
                    223:     return; }
                    224: length=filelength(file);
                    225: if((buf=LMALLOC(length+1))==NULL) {
                    226:     close(file);
                    227:     errormsg(WHERE,ERR_ALLOC,str,length+1);
                    228:     return; }
                    229: if(lread(file,buf,length)!=length) {
                    230:     close(file);
                    231:     FREE(buf);
                    232:     errormsg(WHERE,ERR_READ,str,length);
                    233:     return; }
                    234: chsize(file,0L);
                    235: close(file);
                    236: buf[length]=0;
                    237: getnodedat(node_num,&thisnode,0);
                    238: if(thisnode.action==NODE_MAIN || thisnode.action==NODE_XFER
                    239:     || sys_status&SS_IN_CTRLP) {
                    240:     CRLF; }
                    241: if(thisnode.misc&NODE_MSGW) {
                    242:     getnodedat(node_num,&thisnode,1);
                    243:     thisnode.misc&=~NODE_MSGW;
                    244:     putnodedat(node_num,thisnode); }
                    245: putmsg(buf,P_NOATCODES);
                    246: LFREE(buf);
                    247: }
                    248: 

unix.superglobalmegacorp.com

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