home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 September / PCO_0998.ISO / filesbbs / dos / sbbs_src.exe / SBBS / PUTNODE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-13  |  4.2 KB  |  136 lines

  1. #line 1 "PUTNODE.C"
  2.  
  3. /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
  4.  
  5. #include "sbbs.h"
  6.  
  7. /****************************************************************************/
  8. /* Write the data from the structure 'node' into NODE.DAB                      */
  9. /* getnodedat(num,&node,1); must have been called before calling this func  */
  10. /*          NOTE: ------^   the indicates the node record has been locked   */
  11. /****************************************************************************/
  12. void putnodedat(uint number, node_t node)
  13. {
  14.     char str[256],firston[25];
  15.  
  16. if(!(sys_status&SS_NODEDAB))
  17.     return;
  18. if(!number || number>sys_nodes) {
  19.     errormsg(WHERE,ERR_CHK,"node number",number);
  20.     return; }
  21. if(number==node_num) {
  22.     if((node.status==NODE_INUSE || node.status==NODE_QUIET)
  23.         && text[NodeActionMain+node.action][0]) {
  24.         node.misc|=NODE_EXT;
  25.         memset(str,0,128);
  26.         sprintf(str,text[NodeActionMain+node.action]
  27.             ,useron.alias
  28.             ,useron.level
  29.             ,getage(useron.birth)
  30.             ,useron.sex
  31.             ,useron.comp
  32.             ,useron.note
  33.             ,unixtodstr(useron.firston,firston)
  34.             ,node.aux&0xff
  35.             ,node.connection
  36.             );
  37.         putnodeext(number,str); }
  38.     else
  39.         node.misc&=~NODE_EXT; }
  40. number--;    /* make zero based */
  41. lseek(nodefile,(long)number*sizeof(node_t),SEEK_SET);
  42. if(write(nodefile,&node,sizeof(node_t))!=sizeof(node_t)) {
  43.     unlock(nodefile,(long)number*sizeof(node_t),sizeof(node_t));
  44.     errormsg(WHERE,ERR_WRITE,"nodefile",number+1);
  45.     return; }
  46. unlock(nodefile,(long)number*sizeof(node_t),sizeof(node_t));
  47. }
  48.  
  49. /****************************************************************************/
  50. /* Creates a short message for node 'num' than contains 'strin'             */
  51. /****************************************************************************/
  52. void putnmsg(int num, char *strin)
  53. {
  54.     char str[256];
  55.     int file,i;
  56.     node_t node;
  57.  
  58. sprintf(str,"%sMSGS\\N%3.3u.MSG",data_dir,num);
  59. if((file=nopen(str,O_WRONLY|O_CREAT))==-1) {
  60.     errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT);
  61.     return; }
  62. lseek(file,0L,SEEK_END);    // Instead of opening with O_APPEND
  63. i=strlen(strin);
  64. if(write(file,strin,i)!=i) {
  65.     close(file);
  66.     errormsg(WHERE,ERR_WRITE,str,i);
  67.     return; }
  68. close(file);
  69. getnodedat(num,&node,0);
  70. if((node.status==NODE_INUSE || node.status==NODE_QUIET)
  71.     && !(node.misc&NODE_NMSG)) {
  72.     getnodedat(num,&node,1);
  73.     node.misc|=NODE_NMSG;
  74.     putnodedat(num,node); }
  75. }
  76.  
  77. void putnodeext(uint number, char *ext)
  78. {
  79.     char str[256];
  80.     int count=0;
  81.  
  82. if(!(sys_status&SS_NODEDAB))
  83.     return;
  84. if(!number || number>sys_nodes) {
  85.     errormsg(WHERE,ERR_CHK,"node number",number);
  86.     return; }
  87. number--;   /* make zero based */
  88. while(count<LOOP_NODEDAB) {
  89.     if(count>10)
  90.         mswait(55);
  91.     lseek(node_ext,(long)number*128L,SEEK_SET);
  92.     if(lock(node_ext,(long)number*128L,128)==-1) {
  93.         count++;
  94.         continue; }
  95.     if(write(node_ext,ext,128)==128)
  96.         break;
  97.     count++; }
  98. unlock(node_ext,(long)number*128L,128);
  99. if(count>(LOOP_NODEDAB/2) && count!=LOOP_NODEDAB) {
  100.     sprintf(str,"NODE.EXB COLLISION - Count: %d",count);
  101.     logline("!!",str); }
  102. if(count==LOOP_NODEDAB) {
  103.     errormsg(WHERE,ERR_WRITE,"NODE.EXB",number+1);
  104.     return; }
  105. }
  106.  
  107. /****************************************************************************/
  108. /* Creates a short message for 'usernumber' than contains 'strin'           */
  109. /****************************************************************************/
  110. void putsmsg(int usernumber, char *strin)
  111. {
  112.     char str[256];
  113.     int file,i;
  114.     node_t node;
  115.  
  116. sprintf(str,"%sMSGS\\%4.4u.MSG",data_dir,usernumber);
  117. if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1) {
  118.     errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_APPEND);
  119.     return; }
  120. i=strlen(strin);
  121. if(write(file,strin,i)!=i) {
  122.     close(file);
  123.     errormsg(WHERE,ERR_WRITE,str,i);
  124.     return; }
  125. close(file);
  126. for(i=1;i<=sys_nodes;i++) {     /* flag node if user on that msg waiting */
  127.     getnodedat(i,&node,0);
  128.     if(node.useron==usernumber
  129.         && (node.status==NODE_INUSE || node.status==NODE_QUIET)
  130.         && !(node.misc&NODE_MSGW)) {
  131.         getnodedat(i,&node,1);
  132.         node.misc|=NODE_MSGW;
  133.         putnodedat(i,node); } }
  134. }
  135.  
  136.