home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / top2src.zip / BBS.C < prev    next >
C/C++ Source or Header  |  2000-07-13  |  11KB  |  355 lines

  1. /******************************************************************************
  2. BBS.C        Generic BBS functions.
  3.  
  4.     Copyright 1993 - 2000 Paul J. Sidorsky
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License, version 2, as
  8.     published by the Free Software Foundation.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19. This module contains the NODES and PAGE commands, and functions which front-end
  20. the BBS-specific calls.
  21. ******************************************************************************/
  22.  
  23. #include "top.h"
  24.  
  25. /* bbs_useron() - Displays who is logged on to the BBS.  (NODES command.)
  26.    Parameters:  endpause - TRUE to pause after displaying the list.
  27.    Returns:  Nothing.
  28.    Notes:  The code to support the endpause flag has been removed so the
  29.            parameter is effectively unused.
  30. */
  31. void bbs_useron(char endpause)
  32. {
  33. XINT d, count, key, res = 1; /* Counters, keypress holder, result code. */
  34. char nonstop = 0; /* Nonstop mode flag. */
  35. bbsnodedata_typ nodeinf; /* Buffer for BBS data. */
  36. node_idx_typ nodedat; /* Buffer for NODEIDX data. */
  37.  
  38. /* Set up and display the header. */
  39. // Should be an assertion
  40. if (bbs_call_setexistbits != NULL)
  41.     (*bbs_call_setexistbits)(&nodeinf);
  42. bbs_useronhdr(&nodeinf);
  43.  
  44. check_nodes_used(FALSE);
  45.  
  46. for (d = 0, count = 0; d < MAXNODES; d++)
  47.     {
  48.     /* Show a more prompt if 20 nodes have been shown. */
  49.     if ((count % 20 == 0) && !nonstop && count > 0) // Use screenlength!
  50.         {
  51.         nonstop = moreprompt();
  52.         if (nonstop == -1)
  53.             {
  54.             break;
  55.             }
  56.         }
  57.  
  58.     memset(&nodeinf, 0, sizeof(bbsnodedata_typ) - 2);
  59.     memset(&nodedat, 0, sizeof(node_idx_typ));
  60.     if (activenodes[d])
  61.         {
  62.         /* If the node is active in TOP then use the NODEIDX data.  This is
  63.            done because it is faster and more reliable. */
  64.         res = get_node_data(d, &nodedat);
  65.         if (!res)
  66.             {
  67.             fixname(nodeinf.handle, nodedat.handle);
  68.             fixname(nodeinf.realname, nodedat.realname);
  69.             nodeinf.node = d;
  70.             nodeinf.speed = nodedat.speed;
  71.             strcpy(nodeinf.location, nodedat.location);
  72.             strcpy(nodeinf.statdesc,
  73.                    top_output(OUT_STRING, getlang("NodeStatus")));
  74.             nodeinf.quiet = nodedat.quiet;
  75.             nodeinf.gender = nodedat.gender;
  76.             nodeinf.hidden = 0;
  77.             }
  78.         }
  79.     else
  80.         {
  81.         /* Load the data from the BBS's useron file. */
  82.         if (bbs_call_loaduseron)
  83.             res = (*bbs_call_loaduseron)(d, &nodeinf);
  84.         if (res == -2)
  85.             {
  86.             break;
  87.             }
  88.         }
  89.  
  90.     /* Display the appropriate information for the node. */
  91.     if (!nodeinf.hidden && !res)
  92.         {
  93.         if (nodeinf.existbits & NEX_NODE)
  94.             {
  95.             itoa(nodeinf.node, outnum[0], 10);
  96.             top_output(OUT_SCREEN, getlang("NodesNodeDisp"), outnum[0]);
  97.             }
  98.         if ((nodeinf.existbits & NEX_HANDLE) && cfg.usehandles)
  99.             {
  100.             top_output(OUT_SCREEN, getlang("NodesHandleDisp"),
  101.                        nodeinf.handle);
  102.             }
  103.         if ((nodeinf.existbits & NEX_REALNAME) && !cfg.usehandles)
  104.             {
  105.             top_output(OUT_SCREEN, getlang("NodesRealNameDisp"),
  106.                        nodeinf.realname);
  107.             }
  108.         if (nodeinf.existbits & NEX_SPEED)
  109.             {
  110.             ltoa(nodeinf.speed, outnum[0], 10);
  111.             top_output(OUT_SCREEN, getlang("NodesSpeedDisp"), outnum[0]);
  112.             }
  113.         if (nodeinf.existbits & NEX_LOCATION)
  114.             {
  115.             top_output(OUT_SCREEN, getlang("NodesLocationDisp"),
  116.                        nodeinf.location);
  117.             }
  118.         if (nodeinf.existbits & NEX_STATUS)
  119.             {
  120.             top_output(OUT_SCREEN, getlang("NodesStatusDisp"),
  121.                        nodeinf.statdesc);
  122.             }
  123.         if (nodeinf.existbits & NEX_PAGESTAT)
  124.             {
  125.             top_output(OUT_SCREEN, getlang("NodesPageStatDisp"),
  126.                        nodeinf.quiet ? getlang("PageStatNo") :
  127.                        getlang("PageStatYes"));
  128.             } // Also add GENDER and NUMCALLS!
  129.         top_output(OUT_SCREEN, getlang("NodesListEndLine"));
  130.         count++;
  131.         }
  132.     }
  133.  
  134. if (endpause)
  135.     {
  136.     // Language-enabled press-a-key later.
  137. //    top_output(OUT_SCREEN, getlang("NodesListAfterKey"));
  138.     }
  139.  
  140. }
  141.  
  142. /* bbs_page() - Sends a message from TOP to a user on the BBS (PAGE cmd.)
  143.    Parameters:  nodenum - Node number to page, or -1 to prompt user.
  144.                 pagebuf - String containing the page text, or NULL to use the
  145.                           editor.
  146.    Returns:  Nothing.
  147. */
  148. void bbs_page(XINT nodenum, unsigned char *pagebuf)
  149. {
  150. /* Final page buffer, string conversion of node number. */
  151. unsigned char *pagemsg = NULL, pnode[6];
  152. XINT pagenode, pres; /* Final node to page, result code. */
  153. bbsnodedata_typ pnodeinf; /* Buffer for BBS data. */
  154. node_idx_typ pnodedat; /* Buffer for NODEIDX data. */
  155.  
  156. /* Allocate an edit buffer if no string was passed. */
  157. if (pagebuf == NULL)
  158.     {
  159.     pagemsg = malloc(1601);
  160.     if (!pagemsg)
  161.         {
  162.         top_output(OUT_SCREEN, getlang("NoMemToPage"));
  163.         return;
  164.         }
  165.     }
  166.  
  167. if (nodenum < 0)
  168.     {
  169.     /* Prompt the user for a node number if none was passed. */
  170.     do
  171.         { // Need to change this back to the old way...
  172.         top_output(OUT_SCREEN, getlang("PageWho"));
  173.         od_input_str(pnode, 5, '0', '?');
  174.         if (pnode[0] == '?')
  175.             {
  176.             bbs_useron(FALSE);
  177.             top_output(OUT_SCREEN, "@c");
  178.             }
  179.         }
  180.     while(pnode[0] == '?');
  181.  
  182.     pagenode = atoi(pnode);
  183.     if (!pnode[0])
  184.         {
  185.         top_output(OUT_SCREEN, getlang("PageAborted"));
  186.         dofree(pagemsg);
  187.         return;
  188.         }
  189.     itoa(pagenode, pnode, 10);
  190.     if (pagenode < 1 || pagenode >= cfg.maxnodes)
  191.         {
  192.         itoa(cfg.maxnodes - 1, outnum[0], 10);
  193.         top_output(OUT_SCREEN, getlang("InvalidNode"), outnum[0]);
  194.         dofree(pagemsg);
  195.         return;
  196.         }
  197.     }
  198. else
  199.     {
  200.     pagenode = nodenum;
  201.     itoa(nodenum, pnode, 10);
  202.     }
  203.  
  204. pres = 0;
  205. memset(&pnodeinf, 0, sizeof(bbsnodedata_typ) - 2);
  206. memset(&pnodedat, 0, sizeof(node_idx_typ));
  207. if (activenodes[pagenode])
  208.     {
  209.     /* If the user's in TOP, use the NODEIDX data instead. */
  210.     pres = get_node_data(pagenode, &pnodedat);
  211.     pnodeinf.quiet = pnodedat.quiet;
  212.     }
  213. else
  214.     {
  215.     pres = 1;
  216.     /* Load the user's data from the BBS. */
  217.     if (bbs_call_loaduseron)
  218.         pres = (*bbs_call_loaduseron)(pagenode, &pnodeinf);
  219.     if (pres)
  220.         {
  221.         pnodeinf.hidden = 1;
  222.         }
  223.     }
  224.  
  225. /* Page is aborted if node is hidden or not in use, or if user is in Quiet
  226.    mode. */
  227. if (pnodeinf.hidden)
  228.     {
  229.     top_output(OUT_SCREEN, getlang("NodeNotInUse"), pnode);
  230.     dofree(pagemsg);
  231.     return;
  232.     }
  233. if (pnodeinf.quiet)
  234.     {
  235.     top_output(OUT_SCREEN, getlang("NodeDND"), pnode);
  236.     dofree(pagemsg);
  237.     return;
  238.     }
  239.  
  240. if (pagebuf == NULL)
  241.     {
  242.     /* Call the editor if no page was passed. */
  243.     memset(pagemsg, 0, 1601);
  244.     (*bbs_call_pageedit)(pagenode, pagemsg); // use retval later
  245.     }
  246. else
  247.     {
  248.     pagemsg = pagebuf;
  249.     }
  250.  
  251. /* Performs the actual paging of the user if that function is available. */
  252. if (bbs_call_page != NULL)
  253.     {
  254.     if ((*bbs_call_page)(pagenode, pagemsg))
  255.         {
  256.         top_output(OUT_SCREEN, getlang("Paged"), pnode);
  257.         od_log_write(top_output(OUT_STRING, getlang("LogSentPage"),
  258.                      pnode));
  259.         }
  260.     }
  261. else
  262.     {
  263.     top_output(OUT_SCREEN, getlang("CantPage"), pnode);
  264.     od_log_write(top_output(OUT_STRING, getlang("LogCantPage"), pnode));
  265.     }
  266.  
  267. // Possible else & case for errorcodes
  268.  
  269. /* Free the edit buffer if it was used. */
  270. if (pagebuf == NULL)
  271.     {
  272.     dofree(pagemsg);
  273.     }
  274.  
  275. }
  276.  
  277. /* bbs_useronhdr() - Shows the header for the NODES command.
  278.    Parameters:  ndata - Pointer to the BBS node data being used.
  279.    Returns:  Nothing.
  280.    Notes:  Only the existbits are used from ndata.  The buffer pointed to
  281.            by ndata should first be initialized using a call to the function
  282.            pointed to by bbs_call_setexistbits.
  283. */
  284. void bbs_useronhdr(bbsnodedata_typ *ndata)
  285. {
  286.  
  287. top_output(OUT_SCREEN, getlang("NodesHdrPrefix"));
  288.  
  289. /* Show only the desired fields. */
  290. if (ndata->existbits & NEX_NODE)
  291.     {
  292.     top_output(OUT_SCREEN, getlang("NodesNodeHdr"));
  293.     }
  294. if ((ndata->existbits & NEX_HANDLE) && cfg.usehandles)
  295.     {
  296.     top_output(OUT_SCREEN, getlang("NodesHandleHdr"));
  297.     }
  298. if ((ndata->existbits & NEX_REALNAME) && !cfg.usehandles)
  299.     {
  300.     top_output(OUT_SCREEN, getlang("NodesRealNameHdr"));
  301.     }
  302. if (ndata->existbits & NEX_SPEED)
  303.     {
  304.     top_output(OUT_SCREEN, getlang("NodesSpeedHdr"));
  305.     }
  306. if (ndata->existbits & NEX_LOCATION)
  307.     {
  308.     top_output(OUT_SCREEN, getlang("NodesLocationHdr"));
  309.     }
  310. if (ndata->existbits & NEX_STATUS)
  311.     {
  312.     top_output(OUT_SCREEN, getlang("NodesStatusHdr"));
  313.     }
  314. if (ndata->existbits & NEX_PAGESTAT)
  315.     {
  316.     top_output(OUT_SCREEN, getlang("NodesPageStatHdr"));
  317.     } // Also add GENDER and NUMCALLS!
  318.  
  319. top_output(OUT_SCREEN, getlang("NodesHdrSuffix"));
  320. top_output(OUT_SCREEN, getlang("NodesSepPrefix"));
  321.  
  322. /* Show separators for the desired fields. */
  323. if (ndata->existbits & NEX_NODE)
  324.     {
  325.     top_output(OUT_SCREEN, getlang("NodesNodeSep"));
  326.     }
  327. if ((ndata->existbits & NEX_HANDLE) && cfg.usehandles)
  328.     {
  329.     top_output(OUT_SCREEN, getlang("NodesHandleSep"));
  330.     }
  331. if ((ndata->existbits & NEX_REALNAME) && !cfg.usehandles)
  332.     {
  333.     top_output(OUT_SCREEN, getlang("NodesRealNameSep"));
  334.     }
  335. if (ndata->existbits & NEX_SPEED)
  336.     {
  337.     top_output(OUT_SCREEN, getlang("NodesSpeedSep"));
  338.     }
  339. if (ndata->existbits & NEX_LOCATION)
  340.     {
  341.     top_output(OUT_SCREEN, getlang("NodesLocationSep"));
  342.     }
  343. if (ndata->existbits & NEX_STATUS)
  344.     {
  345.     top_output(OUT_SCREEN, getlang("NodesStatusSep"));
  346.     }
  347. if (ndata->existbits & NEX_PAGESTAT)
  348.     {
  349.     top_output(OUT_SCREEN, getlang("NodesPageStatSep"));
  350.     } // Also add GENDER and NUMCALLS!
  351.  
  352. top_output(OUT_SCREEN, getlang("NodesSepSuffix"));
  353.  
  354. }
  355.