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

  1. /* NODE.C */
  2.  
  3. /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
  4.  
  5. /* Synchronet BBS Node control program */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <io.h>
  10. #include <dos.h>
  11. #include <fcntl.h>
  12. #include <string.h>
  13. #include "sbbsdefs.h"
  14.  
  15. enum {
  16.      MODE_LIST
  17.     ,MODE_ANON
  18.     ,MODE_LOCK
  19.     ,MODE_INTR
  20.     ,MODE_RRUN
  21.     ,MODE_DOWN
  22.     ,MODE_EVENT
  23.     ,MODE_NOPAGE
  24.     ,MODE_NOALERTS
  25.     ,MODE_STATUS
  26.     ,MODE_USERON
  27.     ,MODE_ACTION
  28.     ,MODE_ERRORS
  29.     ,MODE_MISC
  30.     ,MODE_CONN
  31.     ,MODE_AUX
  32.     ,MODE_EXTAUX
  33.     };
  34.  
  35. char tmp[256];
  36. int nodefile;
  37.  
  38. /****************************************************************************/
  39. /* Reads the data for node number 'number' into the structure 'node'        */
  40. /* from NODE.DAB                                                            */
  41. /* if lockit is non-zero, locks this node's record. putnodedat() unlocks it */
  42. /****************************************************************************/
  43. void getnodedat(uchar number, node_t *node, char lockit)
  44. {
  45.     char str[256];
  46.     int count=0;
  47.  
  48. number--;    /* make zero based */
  49. while(count<LOOP_NODEDAB) {
  50.     lseek(nodefile,(long)number*sizeof(node_t),SEEK_SET);
  51.     if(lockit
  52.         && lock(nodefile,(long)number*sizeof(node_t),sizeof(node_t))==-1) {
  53.         count++;
  54.         continue; }
  55.     if(read(nodefile,node,sizeof(node_t))==sizeof(node_t))
  56.         break;
  57.     count++; }
  58. if(count)
  59.     printf("NODE.DAB COLLISION (READ) - Count:%d\n",count);
  60. if(count==LOOP_NODEDAB) {
  61.     printf("Error reading nodefile for node %d\n",number+1);
  62.     return; }
  63. }
  64.  
  65. /****************************************************************************/
  66. /* Write the data from the structure 'node' into NODE.DAB                      */
  67. /* getnodedat(num,&node,1); must have been called before calling this func  */
  68. /*          NOTE: ------^   the indicates the node record has been locked   */
  69. /****************************************************************************/
  70. void putnodedat(uchar number, node_t node)
  71. {
  72.     char str[256];
  73.     int count;
  74.  
  75. number--;    /* make zero based */
  76. lseek(nodefile,(long)number*sizeof(node_t),SEEK_SET);
  77. if(write(nodefile,&node,sizeof(node_t))!=sizeof(node_t)) {
  78.     unlock(nodefile,(long)number*sizeof(node_t),sizeof(node_t));
  79.     printf("Error writing to nodefile for node %d\n",number+1);
  80.     return; }
  81. unlock(nodefile,(long)number*sizeof(node_t),sizeof(node_t));
  82. }
  83.  
  84. /****************************************************************************/
  85. /* Unpacks the password 'pass' from the 5bit ASCII inside node_t. 32bits in */
  86. /* node.extaux, and the other 8bits in the upper byte of node.aux            */
  87. /****************************************************************************/
  88. char *unpackchatpass(char *pass, node_t node)
  89. {
  90.     char     bits;
  91.     int     i;
  92.  
  93. pass[0]=(node.aux&0x1f00)>>8;
  94. pass[1]=((node.aux&0xe000)>>13)|((node.extaux&0x3)<<3);
  95. bits=2;
  96. for(i=2;i<8;i++) {
  97.     pass[i]=(node.extaux>>bits)&0x1f;
  98.     bits+=5; }
  99. pass[8]=0;
  100. for(i=0;i<8;i++)
  101.     if(pass[i])
  102.         pass[i]+=64;
  103. return(pass);
  104. }
  105.  
  106. /****************************************************************************/
  107. /* Displays the information for node number 'number' contained in 'node'    */
  108. /****************************************************************************/
  109. void printnodedat(uchar number, node_t node)
  110. {
  111.     uint i;
  112.     char hour,mer[3];
  113.  
  114. printf("Node %2d: ",number);
  115. switch(node.status) {
  116.     case NODE_WFC:
  117.         printf("Waiting for call");
  118.         break;
  119.     case NODE_OFFLINE:
  120.         printf("Offline");
  121.         break;
  122.     case NODE_NETTING:
  123.         printf("Networking");
  124.         break;
  125.     case NODE_LOGON:
  126.         printf("At logon prompt");
  127.         break;
  128.     case NODE_EVENT_WAITING:
  129.         printf("Waiting for all nodes to become inactive");
  130.         break;
  131.     case NODE_EVENT_LIMBO:
  132.         printf("Waiting for node %d to finish external event",node.aux);
  133.         break;
  134.     case NODE_EVENT_RUNNING:
  135.         printf("Running external event");
  136.         break;
  137.     case NODE_NEWUSER:
  138.         printf("New user");
  139.         printf(" applying for access ");
  140.         if(!node.connection)
  141.             printf("Locally");
  142.         else
  143.             printf("at %ubps",node.connection);
  144.         break;
  145.     case NODE_QUIET:
  146.     case NODE_INUSE:
  147.         printf("User #%d",node.useron);
  148.         printf(" ");
  149.         switch(node.action) {
  150.             case NODE_MAIN:
  151.                 printf("at main menu");
  152.                 break;
  153.             case NODE_RMSG:
  154.                 printf("reading messages");
  155.                 break;
  156.             case NODE_RMAL:
  157.                 printf("reading mail");
  158.                 break;
  159.             case NODE_RSML:
  160.                 printf("reading sent mail");
  161.                 break;
  162.             case NODE_RTXT:
  163.                 printf("reading text files");
  164.                 break;
  165.             case NODE_PMSG:
  166.                 printf("posting message");
  167.                 break;
  168.             case NODE_SMAL:
  169.                 printf("sending mail");
  170.                 break;
  171.             case NODE_AMSG:
  172.                 printf("posting auto-message");
  173.                 break;
  174.             case NODE_XTRN:
  175.                 if(!node.aux)
  176.                     printf("at external program menu");
  177.                 else
  178.                     printf("running external program #%d",node.aux);
  179.                 break;
  180.             case NODE_DFLT:
  181.                 printf("changing defaults");
  182.                 break;
  183.             case NODE_XFER:
  184.                 printf("at transfer menu");
  185.                 break;
  186.             case NODE_RFSD:
  187.                 printf("retrieving from device #%d",node.aux);
  188.                 break;
  189.             case NODE_DLNG:
  190.                 printf("downloading");
  191.                 break;
  192.             case NODE_ULNG:
  193.                 printf("uploading");
  194.                 break;
  195.             case NODE_BXFR:
  196.                 printf("transferring bidirectional");
  197.                 break;
  198.             case NODE_LFIL:
  199.                 printf("listing files");
  200.                 break;
  201.             case NODE_LOGN:
  202.                 printf("logging on");
  203.                 break;
  204.             case NODE_LCHT:
  205.                 printf("in local chat with sysop");
  206.                 break;
  207.             case NODE_MCHT:
  208.                 if(node.aux) {
  209.                     printf("in multinode chat channel %d",node.aux&0xff);
  210.                     if(node.aux&0x1f00) { /* password */
  211.                         putchar('*');
  212.                         printf(" %s",unpackchatpass(tmp,node)); } }
  213.                 else
  214.                     printf("in multinode global chat channel");
  215.                 break;
  216.             case NODE_PAGE:
  217.                 printf("paging node %u for private chat",node.aux);
  218.                 break;
  219.             case NODE_PCHT:
  220.                 printf("in private chat with node %u",node.aux);
  221.                 break;
  222.             case NODE_GCHT:
  223.                 printf("chatting with The Guru");
  224.                 break;
  225.             case NODE_CHAT:
  226.                 printf("in chat section");
  227.                 break;
  228.             case NODE_TQWK:
  229.                 printf("transferring QWK packet");
  230.                 break;
  231.             case NODE_SYSP:
  232.                 printf("performing sysop activities");
  233.                 break;
  234.             default:
  235.                 printf(itoa(node.action,tmp,10));
  236.                 break;  }
  237.         if(!node.connection)
  238.             printf(" locally");
  239.         else
  240.             printf(" at %ubps",node.connection);
  241.         if(node.action==NODE_DLNG) {
  242.             if((node.aux/60)>=12) {
  243.                 if(node.aux/60==12)
  244.                     hour=12;
  245.                 else
  246.                     hour=(node.aux/60)-12;
  247.                 strcpy(mer,"pm"); }
  248.             else {
  249.                 if((node.aux/60)==0)    /* 12 midnite */
  250.                     hour=12;
  251.                 else hour=node.aux/60;
  252.                 strcpy(mer,"am"); }
  253.             printf(" ETA %02d:%02d %s"
  254.                 ,hour,node.aux-((node.aux/60)*60),mer); }
  255.         break; }
  256. if(node.misc&(NODE_LOCK|NODE_POFF|NODE_AOFF|NODE_MSGW|NODE_NMSG)) {
  257.     printf(" (");
  258.     if(node.misc&NODE_AOFF)
  259.         putchar('A');
  260.     if(node.misc&NODE_LOCK)
  261.         putchar('L');
  262.     if(node.misc&(NODE_MSGW|NODE_NMSG))
  263.         putchar('M');
  264.     if(node.misc&NODE_POFF)
  265.         putchar('P');
  266.     putchar(')'); }
  267. if(((node.misc
  268.     &(NODE_ANON|NODE_UDAT|NODE_INTR|NODE_RRUN|NODE_EVENT|NODE_DOWN))
  269.     || node.status==NODE_QUIET)) {
  270.     printf(" [");
  271.     if(node.misc&NODE_ANON)
  272.         putchar('A');
  273.     if(node.misc&NODE_INTR)
  274.         putchar('I');
  275.     if(node.misc&NODE_RRUN)
  276.         putchar('R');
  277.     if(node.misc&NODE_UDAT)
  278.         putchar('U');
  279.     if(node.status==NODE_QUIET)
  280.         putchar('Q');
  281.     if(node.misc&NODE_EVENT)
  282.         putchar('E');
  283.     if(node.misc&NODE_DOWN)
  284.         putchar('D');
  285.     putchar(']'); }
  286. if(node.errors)
  287.     printf(" %d error%c",node.errors, node.errors>1 ? 's' : '\0' );
  288. printf("\n");
  289. }
  290.  
  291.  
  292. /****************************/
  293. /* Main program entry point */
  294. /****************************/
  295. int main(int argc, char **argv)
  296. {
  297.     char str[256],ctrl_dir[41],*p,debug=0;
  298.     uchar sys_nodes,node_num=0,onoff=0;
  299.     uint i,j,mode=0,misc;
  300.     long value;
  301.     node_t node;
  302.  
  303. printf("\nSynchronet Node Display/Control Utility v1.03\n\n");
  304.  
  305. if(argc<2) {
  306.     printf("usage: node [/debug] [action [on|off]] [node numbers] [...]"
  307.         "\n\n");
  308.     printf("actions (default is list):\n\n");
  309.     printf("list        = list status\n");
  310.     printf("anon        = anonymous user\n");
  311.     printf("lock        = locked\n");
  312.     printf("intr        = interrupt\n");
  313.     printf("down        = shut-down\n");
  314.     printf("rerun       = rerun\n");
  315.     printf("event       = run event\n");
  316.     printf("nopage      = page disable\n");
  317.     printf("noalerts    = activity alerts disable\n");
  318.     printf("status=#    = set status value\n");
  319.     printf("useron=#    = set useron number\n");
  320.     printf("action=#    = set action value\n");
  321.     printf("errors=#    = set error counter\n");
  322.     printf("conn=#      = set connection value\n");
  323.     printf("misc=#      = set misc value\n");
  324.     printf("aux=#       = set aux value\n");
  325.     printf("extaux=#    = set extended aux value\n");
  326.     exit(0); }
  327.  
  328. p=getenv("SBBSCTRL");
  329. if(p==NULL) {
  330.     printf("\7\nSBBSCTRL environment variable is not set.\n");
  331.     printf("This environment variable must be set to your CTRL directory.");
  332.     printf("\nExample: SET SBBSCTRL=C:\\SBBS\\CTRL\n");
  333.     exit(1); }
  334. sprintf(ctrl_dir,"%.40s",p);
  335. strupr(ctrl_dir);
  336. if(ctrl_dir[strlen(ctrl_dir)-1]!='\\')
  337.     strcat(ctrl_dir,"\\");
  338.  
  339. sprintf(str,"%sNODE.DAB",ctrl_dir);
  340. if((nodefile=open(str,O_RDWR|O_DENYNONE|O_BINARY))==-1) {
  341.     printf("\7\nError opening %s.\n",str);
  342.     exit(1); }
  343.  
  344. sys_nodes=filelength(nodefile)/sizeof(node_t);
  345. if(!sys_nodes) {
  346.     printf("%s reflects 0 nodes!\n",str);
  347.     exit(1); }
  348.  
  349. for(i=1;i<argc;i++) {
  350.     if(isdigit(argv[i][0]))
  351.         node_num=atoi(argv[i]);
  352.     else {
  353.         node_num=onoff=value=0;
  354.         if(!stricmp(argv[i],"/DEBUG"))
  355.             debug=1;
  356.         else if(!stricmp(argv[i],"LOCK"))
  357.             mode=MODE_LOCK;
  358.         else if(!stricmp(argv[i],"ANON"))
  359.             mode=MODE_ANON;
  360.         else if(!stricmp(argv[i],"INTR"))
  361.             mode=MODE_INTR;
  362.         else if(!stricmp(argv[i],"DOWN"))
  363.             mode=MODE_DOWN;
  364.         else if(!stricmp(argv[i],"RERUN"))
  365.             mode=MODE_RRUN;
  366.         else if(!stricmp(argv[i],"EVENT"))
  367.             mode=MODE_EVENT;
  368.         else if(!stricmp(argv[i],"NOPAGE"))
  369.             mode=MODE_NOPAGE;
  370.         else if(!stricmp(argv[i],"NOALERTS"))
  371.             mode=MODE_NOALERTS;
  372.         else if(!stricmp(argv[i],"ON"))
  373.             onoff=1;
  374.         else if(!stricmp(argv[i],"OFF"))
  375.             onoff=2;
  376.         else if(!strnicmp(argv[i],"STATUS=",7)) {
  377.             mode=MODE_STATUS;
  378.             value=atoi(argv[i]+7); }
  379.         else if(!strnicmp(argv[i],"ERRORS=",7)) {
  380.             mode=MODE_ERRORS;
  381.             value=atoi(argv[i]+7); }
  382.         else if(!strnicmp(argv[i],"USERON=",7)) {
  383.             mode=MODE_USERON;
  384.             value=atoi(argv[i]+7); }
  385.         else if(!strnicmp(argv[i],"ACTION=",7)) {
  386.             mode=MODE_ACTION;
  387.             value=atoi(argv[i]+7); }
  388.         else if(!strnicmp(argv[i],"CONN=",5)) {
  389.             mode=MODE_CONN;
  390.             value=atoi(argv[i]+5); }
  391.         else if(!strnicmp(argv[i],"MISC=",5)) {
  392.             mode=MODE_MISC;
  393.             value=atoi(argv[i]+5); }
  394.         else if(!strnicmp(argv[i],"AUX=",4)) {
  395.             mode=MODE_AUX;
  396.             value=atoi(argv[i]+4); }
  397.         else if(!strnicmp(argv[i],"EXTAUX=",7)) {
  398.             mode=MODE_EXTAUX;
  399.             value=atoi(argv[i]+7); }
  400.         }
  401.     if((mode && node_num) || i+1==argc)
  402.         for(j=1;j<=sys_nodes;j++)
  403.             if(!node_num || j==node_num) {
  404.                 getnodedat(j,&node,1);
  405.                 misc=0;
  406.                 switch(mode) {
  407.                     case MODE_ANON:
  408.                         misc=NODE_ANON;
  409.                         break;
  410.                     case MODE_LOCK:
  411.                         misc=NODE_LOCK;
  412.                         break;
  413.                     case MODE_INTR:
  414.                         misc=NODE_INTR;
  415.                         break;
  416.                     case MODE_DOWN:
  417.                         misc=NODE_DOWN;
  418.                         break;
  419.                     case MODE_RRUN:
  420.                         misc=NODE_RRUN;
  421.                         break;
  422.                     case MODE_EVENT:
  423.                         misc=NODE_EVENT;
  424.                         break;
  425.                     case MODE_NOPAGE:
  426.                         misc=NODE_POFF;
  427.                         break;
  428.                     case MODE_NOALERTS:
  429.                         misc=NODE_AOFF;
  430.                         break;
  431.                     case MODE_STATUS:
  432.                         node.status=value;
  433.                         break;
  434.                     case MODE_ERRORS:
  435.                         node.errors=value;
  436.                         break;
  437.                     case MODE_ACTION:
  438.                         node.action=value;
  439.                         break;
  440.                     case MODE_USERON:
  441.                         node.useron=value;
  442.                         break;
  443.                     case MODE_MISC:
  444.                         node.misc=value;
  445.                         break;
  446.                     case MODE_CONN:
  447.                         node.connection=value;
  448.                         break;
  449.                     case MODE_AUX:
  450.                         node.aux=value;
  451.                         break;
  452.                     case MODE_EXTAUX:
  453.                         node.extaux=value;
  454.                         break; }
  455.                 if(misc) {
  456.                     if(onoff==0)
  457.                         node.misc^=misc;
  458.                     else if(onoff==1)
  459.                         node.misc|=misc;
  460.                     else if(onoff==2)
  461.                         node.misc&=~misc; }
  462.                 putnodedat(j,node);
  463.                 printnodedat(j,node);
  464.                 if(debug) {
  465.                     printf("status=%u\n",node.status);
  466.                     printf("errors=%u\n",node.errors);
  467.                     printf("action=%d\n",node.action);
  468.                     printf("useron=%u\n",node.useron);
  469.                     printf("conn=%u\n",node.connection);
  470.                     printf("misc=%u\n",node.misc);
  471.                     printf("aux=%u\n",node.aux);
  472.                     printf("extaux=%lu\n",node.extaux); } } }
  473.  
  474. close(nodefile);
  475. return(0);
  476. }
  477.