Annotation of sbbs/sbbs3/putnode.cpp, revision 1.1

1.1     ! root        1: /* putnode.cpp */
        !             2: 
        !             3: /* Synchronet node information writing routines */
        !             4: 
        !             5: /* $Id: putnode.cpp,v 1.4 2000/11/14 01:24:21 rswindell Exp $ */
        !             6: 
        !             7: /****************************************************************************
        !             8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
        !             9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
        !            10:  *                                                                                                                                                     *
        !            11:  * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html         *
        !            12:  *                                                                                                                                                     *
        !            13:  * This program is free software; you can redistribute it and/or                       *
        !            14:  * modify it under the terms of the GNU General Public License                         *
        !            15:  * as published by the Free Software Foundation; either version 2                      *
        !            16:  * of the License, or (at your option) any later version.                                      *
        !            17:  * See the GNU General Public License for more details: gpl.txt or                     *
        !            18:  * http://www.fsf.org/copyleft/gpl.html                                                                                *
        !            19:  *                                                                                                                                                     *
        !            20:  * Anonymous FTP access to the most recent released source is available at     *
        !            21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
        !            22:  *                                                                                                                                                     *
        !            23:  * Anonymous CVS access to the development source and modification history     *
        !            24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
        !            25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
        !            26:  *     (just hit return, no password is necessary)                                                     *
        !            27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
        !            28:  *                                                                                                                                                     *
        !            29:  * For Synchronet coding style and modification guidelines, see                                *
        !            30:  * http://www.synchro.net/source.html                                                                          *
        !            31:  *                                                                                                                                                     *
        !            32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
        !            33:  * format) via e-mail to [email protected]                                                                      *
        !            34:  *                                                                                                                                                     *
        !            35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
        !            36:  ****************************************************************************/
        !            37: 
        !            38: #include "sbbs.h"
        !            39: 
        !            40: /****************************************************************************/
        !            41: /* Write the data from the structure 'node' into node.dab                                      */
        !            42: /* getnodedat(num,&node,1); must have been called before calling this func  */
        !            43: /*          NOTE: ------^   the indicates the node record has been locked   */
        !            44: /****************************************************************************/
        !            45: void sbbs_t::putnodedat(uint number, node_t* node)
        !            46: {
        !            47:        char str[256],firston[25];
        !            48: 
        !            49:        if(!number || number>cfg.sys_nodes) {
        !            50:                errormsg(WHERE,ERR_CHK,"node number",number);
        !            51:                return; }
        !            52:        if(number==cfg.node_num) {
        !            53:                if((node->status==NODE_INUSE || node->status==NODE_QUIET)
        !            54:                        && node->action<NODE_LAST_ACTION
        !            55:                        && text[NodeActionMain+node->action][0]) {
        !            56:                        node->misc|=NODE_EXT;
        !            57:                        memset(str,0,128);
        !            58:                        sprintf(str,text[NodeActionMain+node->action]
        !            59:                                ,useron.alias
        !            60:                                ,useron.level
        !            61:                                ,getage(&cfg,useron.birth)
        !            62:                                ,useron.sex
        !            63:                                ,useron.comp
        !            64:                                ,useron.note
        !            65:                                ,unixtodstr(&cfg,useron.firston,firston)
        !            66:                                ,node->aux&0xff
        !            67:                                ,node->connection
        !            68:                                );
        !            69:                        putnodeext(number,str); }
        !            70:                else
        !            71:                        node->misc&=~NODE_EXT; }
        !            72: 
        !            73:        if(nodefile==-1) {
        !            74:                sprintf(str,"%snode.dab",cfg.ctrl_dir);
        !            75:                if((nodefile=nopen(str,O_CREAT|O_RDWR|O_DENYNONE))==-1) {
        !            76:                        errormsg(WHERE,ERR_OPEN,str,O_CREAT|O_RDWR|O_DENYNONE);
        !            77:                        return; 
        !            78:                }
        !            79:        }
        !            80: 
        !            81:        number--;       /* make zero based */
        !            82:        lseek(nodefile,(long)number*sizeof(node_t),SEEK_SET);
        !            83:        if(write(nodefile,node,sizeof(node_t))!=sizeof(node_t)) {
        !            84:                unlock(nodefile,(long)number*sizeof(node_t),sizeof(node_t));
        !            85:                errormsg(WHERE,ERR_WRITE,"nodefile",number+1);
        !            86:                return; 
        !            87:        }
        !            88:        unlock(nodefile,(long)number*sizeof(node_t),sizeof(node_t));
        !            89:        close(nodefile);
        !            90:        nodefile=-1;
        !            91: }
        !            92: 
        !            93: /****************************************************************************/
        !            94: /* Creates a short message for node 'num' than contains 'strin'             */
        !            95: /****************************************************************************/
        !            96: void sbbs_t::putnmsg(int num, char *strin)
        !            97: {
        !            98:     char str[256];
        !            99:     int file,i;
        !           100:     node_t node;
        !           101: 
        !           102:        sprintf(str,"%smsgs/n%3.3u.msg",cfg.data_dir,num);
        !           103:        if((file=nopen(str,O_WRONLY|O_CREAT))==-1) {
        !           104:                errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT);
        !           105:                return; }
        !           106:        lseek(file,0L,SEEK_END);        // Instead of opening with O_APPEND
        !           107:        i=strlen(strin);
        !           108:        if(write(file,strin,i)!=i) {
        !           109:                close(file);
        !           110:                errormsg(WHERE,ERR_WRITE,str,i);
        !           111:                return; }
        !           112:        close(file);
        !           113:        getnodedat(num,&node,0);
        !           114:        if((node.status==NODE_INUSE || node.status==NODE_QUIET)
        !           115:                && !(node.misc&NODE_NMSG)) {
        !           116:                getnodedat(num,&node,1);
        !           117:                node.misc|=NODE_NMSG;
        !           118:                putnodedat(num,&node); }
        !           119: }
        !           120: 
        !           121: void sbbs_t::putnodeext(uint number, char *ext)
        !           122: {
        !           123:     char str[256];
        !           124:     int count=0;
        !           125: 
        !           126:        if(!number || number>cfg.sys_nodes) {
        !           127:                errormsg(WHERE,ERR_CHK,"node number",number);
        !           128:                return; }
        !           129:        number--;   /* make zero based */
        !           130: 
        !           131:        sprintf(str,"%snode.exb",cfg.ctrl_dir);
        !           132:        if((node_ext=nopen(str,O_CREAT|O_RDWR|O_DENYNONE))==-1) {
        !           133:                errormsg(WHERE,ERR_OPEN,str,O_CREAT|O_RDWR|O_DENYNONE);
        !           134:                return; 
        !           135:        }
        !           136:        while(count<LOOP_NODEDAB) {
        !           137:                if(count>10)
        !           138:                        mswait(55);
        !           139:                lseek(node_ext,(long)number*128L,SEEK_SET);
        !           140:                if(lock(node_ext,(long)number*128L,128)==-1) {
        !           141:                        count++;
        !           142:                        continue; }
        !           143:                if(write(node_ext,ext,128)==128)
        !           144:                        break;
        !           145:                count++; }
        !           146:        unlock(node_ext,(long)number*128L,128);
        !           147:        close(node_ext);
        !           148:        node_ext=-1;
        !           149: 
        !           150:        if(count>(LOOP_NODEDAB/2) && count!=LOOP_NODEDAB) {
        !           151:                sprintf(str,"NODE.EXB COLLISION - Count: %d",count);
        !           152:                logline("!!",str); 
        !           153:        }
        !           154:        if(count==LOOP_NODEDAB) {
        !           155:                errormsg(WHERE,ERR_WRITE,"NODE.EXB",number+1);
        !           156:                return; 
        !           157:        }
        !           158: }
        !           159: 
        !           160: 

unix.superglobalmegacorp.com

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