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

  1. /******************************************************************************
  2. BBSRA.C      Implements RemoteAccess-specific 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. The module contains all of the functions for interfacing with RA v2.xx.  It is
  20. also used for some SuperBBS operations that are almost identical to RA.
  21. ******************************************************************************/
  22.  
  23. #include "top.h"
  24.  
  25. /* ra_init() - Initialize pointers to RA functions.
  26.    Paremeters:  None.
  27.    Returns:  Nothing.
  28. */
  29. void ra_init(void)
  30. {
  31.  
  32. bbs_call_loaduseron = ra_loaduseron;
  33. bbs_call_saveuseron = ra_saveuseron;
  34. bbs_call_processmsgs = ra_processmsgs;
  35. bbs_call_page = ra_page;
  36. bbs_call_setexistbits = ra_setexistbits;
  37. bbs_call_login = ra_login;
  38. bbs_call_logout = ra_logout;
  39. bbs_call_openfiles = ra_openfiles;
  40. bbs_call_updateopenfiles = ra_updateopenfiles;
  41. bbs_call_pageedit = ra_longpageeditor;
  42.  
  43. }
  44.  
  45. /* ra_loaduseron() - Loads a node status from the USERON file.
  46.    Parameters:  nodenum - Node number to load the data for.
  47.                 userdata - Pointer to generic BBS data structure to fill.
  48.    Returns:  TRUE if an error occurred, FALSE if successful.
  49. */
  50. char ra_loaduseron(XINT nodenum, bbsnodedata_typ *userdata)
  51. {
  52. XINT res; /* Result code. */
  53. RA_USERON_typ rauser; /* RA USERON record. */
  54. long n; /* 0-based node number. */
  55.  
  56. /* In the USERON file, records are 0-based (eg. node 1 is record 0). */
  57. n = nodenum - 1L;
  58.  
  59. /* Abort if node 0 is paged, or if the USERON file is not large enough that
  60.    it holds the information for the node (meaning the node doesn't exist). */
  61. if (nodenum == 0 ||
  62.     nodenum > (filelength(useronfil) / (long) sizeof(RA_USERON_typ)))
  63.     {
  64.     return 1;
  65.     }
  66.  
  67. /* Load the USERON record. */
  68. res = lseek(useronfil, n * (long) sizeof(RA_USERON_typ), SEEK_SET);
  69. if (res == -1)
  70.     {
  71.     return 1;
  72.     }
  73. rec_locking(REC_LOCK, useronfil, n * (long) sizeof(RA_USERON_typ),
  74.             sizeof(RA_USERON_typ));
  75. res = read(useronfil, &rauser, sizeof(RA_USERON_typ));
  76. rec_locking(REC_UNLOCK, useronfil, n * (long) sizeof(RA_USERON_typ),
  77.             sizeof(RA_USERON_typ));
  78. if (res == -1)
  79.     {
  80.     return 1;
  81.     }
  82.  
  83. /* Convert Pascal strings to C. */
  84. unbuild_pascal_string(35, rauser.name);
  85. unbuild_pascal_string(35, rauser.handle);
  86. unbuild_pascal_string(25, rauser.city);
  87. unbuild_pascal_string(10, rauser.statdesc);
  88.  
  89. /* Copy the information into the Generic BBS structure. */
  90. memset(userdata, 0, sizeof(bbsnodedata_typ) - 2);
  91. fixname(userdata->realname, rauser.name);
  92. strncpy(userdata->handle, rauser.handle, 30);
  93. fixname(userdata->handle, userdata->handle);
  94. userdata->node = rauser.line;
  95. userdata->speed = rauser.baud;
  96. strcpy(userdata->location, rauser.city);
  97. /* 255 indicates a user defined status type. */
  98. if (rauser.status == 255)
  99.     {
  100.     strcpy(userdata->statdesc, rauser.statdesc);
  101.     }
  102. else
  103.     {
  104.     /* Use the predefined status types from the language file. */
  105.     if (rauser.status < 8)
  106.         {
  107.         strcpy(userdata->statdesc, ra_statustypes[rauser.status]);
  108.         }
  109.     else
  110.         {
  111.         /* Status type unknown.  This would occur either with a corrupt
  112.            USERON file or with a new version of RA that uses new types. */
  113.         userdata->statdesc[0] = 0;
  114.         }
  115.     }
  116. userdata->quiet = rauser.attribute & RA_NODISTURB;
  117. userdata->hidden = (rauser.attribute & RA_HIDDEN) ||
  118.                    (rauser.attribute & RA_READY) ||
  119.                    (rauser.line == 0);
  120. userdata->attribs1 = rauser.attribute;
  121. userdata->numcalls = rauser.numcalls;
  122.  
  123. return 0;
  124. }
  125.  
  126. /* ra_saveuseron() - Saves a node status to the USERON file.
  127.    Parameters:  nodenum - Node number to save the data for.
  128.                 userdata - Pointer to generic BBS data structure to use.
  129.    Returns:  TRUE if an error occurred, FALSE if successful.
  130. */
  131. char ra_saveuseron(XINT nodenum, bbsnodedata_typ *userdata)
  132. {
  133. XINT res; /* Result code. */
  134. RA_USERON_typ rauser; /* RA USERON buffer. */
  135. long n; /* 0-based node number. */
  136.  
  137. /* Copy the data from the Generic BBS buffer to the USERON record. */
  138. memset(&rauser, 0, sizeof(RA_USERON_typ));
  139. strncpy(rauser.name, userdata->realname, 35);
  140. strcpy(rauser.handle, userdata->handle);
  141. rauser.line = userdata->node;
  142. rauser.baud = userdata->speed;
  143. strncpy(rauser.city, userdata->location, 25);
  144. rauser.status = 255;
  145. rauser.attribute = userdata->attribs1;
  146. if (userdata->quiet)
  147.     {
  148.     rauser.attribute |= RA_NODISTURB;
  149.     }
  150. else
  151.     {
  152.     rauser.attribute &= (0xFF - RA_NODISTURB);
  153.     }
  154. strncpy(rauser.statdesc, userdata->statdesc, 10);
  155. rauser.numcalls = userdata->numcalls;
  156.  
  157. /* Convert C strings to Pascal, which RA uses. */
  158. build_pascal_string(rauser.name);
  159. build_pascal_string(rauser.handle);
  160. build_pascal_string(rauser.city);
  161. build_pascal_string(rauser.statdesc);
  162.  
  163. /* Get the 0-based node number. */
  164. n = nodenum - 1;
  165.  
  166. /* Extend the USERON file if it's not long enough.  Done for safety when
  167.    record locking. */
  168. if (filelength(useronfil) < (long) nodenum * (long) sizeof(RA_USERON_typ))
  169.     {
  170.     chsize(useronfil, (long) nodenum * (long) sizeof(RA_USERON_typ));
  171.     }
  172.  
  173. /* Write the USERON data. */
  174. res = lseek(useronfil, n * (long) sizeof(RA_USERON_typ), SEEK_SET);
  175. if (res == -1)
  176.     {
  177.     return 1;
  178.     }
  179. rec_locking(REC_LOCK, useronfil, n * (long) sizeof(RA_USERON_typ),
  180.             sizeof(RA_USERON_typ));
  181. res = write(useronfil, &rauser, sizeof(RA_USERON_typ));
  182. rec_locking(REC_UNLOCK, useronfil, n * (long) sizeof(RA_USERON_typ),
  183.             sizeof(RA_USERON_typ));
  184. if (res == -1)
  185.     {
  186.     return 1;
  187.     }
  188.  
  189. return 0;
  190. }
  191.  
  192. /* ra_processmsgs() - Reads and displays messages from a NODEx.RA file.
  193.    Parameters:  None.
  194.    Returns:  Number of messages processed.  (0 on error.)
  195.    Notes:  Also handles SuperBBS TOLINEx files.
  196. */
  197. XINT ra_processmsgs(void)
  198. {
  199. FILE *pnfil = NULL; /* NODEx file stream. */
  200. char filnam[256]; /* NODEx file name. */
  201. char XFAR *buffer = NULL; /* Incoming message buffer. */
  202. XINT pos = 0, xpos = 0; /* Position, position multiplier. */
  203. XINT tmp, xh; /* ASCII-to-int conversion holder, length of message read. */
  204. char sbbsmsgon = 0; /* Flag if a SuperBBS message is being processed. */
  205.  
  206. /* Select the filename based on BBS type. */
  207. switch(cfg.bbstype)
  208.     {
  209.     case BBS_RA2:
  210.         sprintf(filnam, "%sNODE%i.RA", cfg.bbsmultipath, od_control.od_node);
  211.         break;
  212.     case BBS_SBBS11:
  213.         sprintf(filnam, "%sTOLINE%i", cfg.bbsmultipath, od_control.od_node);
  214.         break;
  215.     }
  216.  
  217. /* Abort if we don't get read access to the file. */
  218. if (access(filnam, 4))
  219.     {
  220.     return 0;
  221.     }
  222.  
  223. /* Allocate the page buffer. */
  224. buffer = malloc(8000);
  225. if (!buffer)
  226.     {
  227.     return 0;
  228.     }
  229.  
  230. /* Open the file using a shared mode. */
  231. pnfil = _fsopen(filnam, "rb", SH_DENYNONE);
  232. if (!pnfil)
  233.     {
  234.     dofree(buffer);
  235.     return 0;
  236.     }
  237.  
  238. /* Prepare the screen. */
  239. delprompt(TRUE);
  240. if (user.pref1 & PREF1_DUALWINDOW)
  241.     {
  242.     // Different for AVT when I find out what the store/recv codes are.
  243.     od_disp_emu("\x1B" "[u", TRUE);
  244.     top_output(OUT_SCREEN, getlang("DWOutputPrefix"));
  245.     }
  246. top_output(OUT_SCREEN, getlang("RAPageRecvPrefix"));
  247.  
  248. /* Loop until the whole file is processed. */
  249. do
  250.     {
  251.     memset(buffer, 0, 8000);
  252.  
  253.     /* Read the file. */
  254.     fseek(pnfil, (long) xpos * 7900L, SEEK_SET);
  255.     xh = fread(buffer, 1, 8000, pnfil);
  256.  
  257.     /* If the file is quite long, it's handled in 7900 byte chunks.  This
  258.        was done to stabilize memory requirements when I thought I was at
  259.        the 640K limit.  A better way would be to just allocate the buffer
  260.        the size of the entire file and read it all in at once.  Even in a
  261.        low-memory situation there should be plenty of memory to read even the
  262.        largest files, which rarely get above a few K. */
  263.     if (xh > 7900)
  264.         {
  265.         xh = 7900;
  266.         }
  267.  
  268.     /* Loop for each character. */
  269.     for (pos = 0; pos < xh; pos++)
  270.         {
  271.         if (!sbbsmsgon && cfg.bbstype == BBS_SBBS11)
  272.             {
  273.             /* In SuperBBS, messages start at a /MESSAGE token, so
  274.                processing doesn't begin until one is found. */
  275.             if (!strnicmp(&buffer[pos], "/MESSAGE", 8))
  276.                 {
  277.                 /* Character location pointers. */
  278.                 unsigned char *eptr = NULL, *nptr = NULL;
  279.                 XINT fromnode; /* Node that sent the page. */
  280.  
  281.                 /* The format of the message token is like this:
  282.                    /MESSAGE User Name,node */
  283.                 pos += 9;
  284.                 /* Find the comma. */
  285.                 eptr = strchr(&buffer[pos], ',');
  286.                 memset(outbuf, 0, 61);
  287.                 /* Grab the name of the sender. */
  288.                 strncpy(outbuf, &buffer[pos], eptr - &buffer[pos]);
  289.                 pos += (eptr - &buffer[pos]) + 1;
  290.                 /* Detemine where this line ends. */
  291.                 eptr = strchr(&buffer[pos], '\r');
  292.                 nptr = strchr(&buffer[pos], '\n');
  293.                 if (nptr < eptr && nptr != NULL)
  294.                     {
  295.                     eptr = nptr;
  296.                     }
  297.                 /* Get the node number. */
  298.                 fromnode = atoi(&buffer[pos]);
  299.                 itoa(fromnode, outnum[0], 10);
  300.                 /* Advance the position to the end of this line. */
  301.                 pos += (eptr - &buffer[pos]) - 1;
  302.                 /* Display the page header. */
  303.                 top_output(OUT_SCREEN, "@c");
  304.                 top_output(OUT_SCREEN, getlang("SBBSRecvPageHdr"),
  305.                            outbuf, outnum[0]);
  306.                 /* Now processing a SuperBBS message. */
  307.                 sbbsmsgon = 1;
  308.                 }
  309.             continue;
  310.             }
  311.         if (sbbsmsgon && cfg.bbstype == BBS_SBBS11)
  312.             {
  313.             /* In SuperBBS, messages end with /END/ so this needs to be
  314.                scanned for. */
  315.             if (!strnicmp(&buffer[pos], "/END/", 5))
  316.                 {
  317.                 /* No longer processing a SuperBBS message. */
  318.                 sbbsmsgon = 0;
  319.                 pos += 4;
  320.                 /* Prompt the user to continue. */
  321.                 top_output(OUT_SCREEN, getlang("RAEnter"));
  322.                 while(od_get_key(TRUE) != 13);
  323.                 top_output(OUT_SCREEN, getlang("RAEnterSuffix"));
  324.                 continue;
  325.                 }
  326.             }
  327.         /* Handle Ctrl-A codes, which mean "wait for ENTER". */
  328.         if (buffer[pos] == 1)
  329.             {
  330.             while(od_get_key(TRUE) != 13);
  331.             continue;
  332.             }
  333.         /* Ctrl-K codes display RA-specific information.  TOP only handles
  334.            colour changes and a few page-specific language items. */
  335.         if (buffer[pos] == 11)
  336.             {
  337.             /* ^K] is the language item code. */
  338.             if (buffer[pos + 1] == ']')
  339.                 {
  340.                 /* The format of these codes is ^K]nnn, where nnn is a 3
  341.                    digit number specifying the item number. */
  342.                 tmp = atoi(&buffer[pos + 2]);
  343.                 pos += 4;
  344.  
  345.                 /* Display message based on the item number.  See the RA
  346.                    language editor for the number of each item. */
  347.                 switch(tmp)
  348.                     {
  349.                     case 258: top_output(OUT_SCREEN, getlang("RAEnter")); break;
  350.                     case 496: top_output(OUT_SCREEN, getlang("RAOnNode")); break;
  351.                     case 497: top_output(OUT_SCREEN, getlang("RAMsgFrom")); break;
  352.                     case 628: top_output(OUT_SCREEN, getlang("RAJustPosted")); break;
  353.                     }
  354.                 continue;
  355.                 }
  356.             /* ^K[ is a colour change. */
  357.             if (buffer[pos + 1] == '[')
  358.                 {
  359.                 unsigned char fgcol, bgcol; /* Fore & background colours. */
  360.  
  361.                 /* The format of these codes is ^K[bf, where b is the
  362.                    background colour (in hex) and f is the foreground
  363.                    colour (also in hex). */
  364.                 bgcol = toupper(buffer[pos + 2]);
  365.                 fgcol = toupper(buffer[pos + 3]);
  366.                 pos += 3;
  367.  
  368.                 /* Process valid hex digits only. */
  369.                 if (isxdigit(bgcol))
  370.                     {
  371.                     if (bgcol >= 'A' && bgcol <= 'F')
  372.                         {
  373.                         /* A through F represent colours 10 - 15. */
  374.                         bgcol -= ('A' - 10);
  375.                         }
  376.                     else
  377.                         {
  378.                         bgcol -= '0';
  379.                         }
  380.                     }
  381.                 /* Process valid hex digits only. */
  382.                 if (isxdigit(fgcol))
  383.                     {
  384.                     if (fgcol >= 'A' && fgcol <= 'F')
  385.                         {
  386.                         /* A through F represent colours 10 - 15. */
  387.                         fgcol -= ('A' - 10);
  388.                         }
  389.                     else
  390.                         {
  391.                         fgcol -= '0';
  392.                         }
  393.                     }
  394.                 od_set_colour(fgcol, bgcol);
  395.                 continue;
  396.                 }
  397.             }
  398.         od_putch(buffer[pos]);
  399.         }
  400.     xpos++;
  401.     }
  402. while((long) xpos * 7900L < filelength(fileno(pnfil)));
  403.  
  404. closefile(pnfil);
  405.  
  406. top_output(OUT_SCREEN, getlang("RAPageRecvSuffix"));
  407. unlink(filnam);
  408.  
  409. dofree(buffer);
  410.  
  411. return 1;
  412. }
  413.  
  414. /* ra_page() - Sends a page to a RA node.
  415.    Parameters:  nodenum - Node number to page.
  416.                 pagebuf - Text to send.
  417.    Returns:  TRUE if successful, FALSE if an error occurred.
  418.    Notes:  Also pages SuperBBS nodes.
  419. */
  420. char ra_page(XINT nodenum, unsigned char *pagebuf)
  421. {
  422. FILE *rapgfil = NULL; /* File stram of the receiving NODEx file. */
  423. unsigned char tmp[41]; /* Buffer to hold the filtered username. */
  424.  
  425. /* Open the appropriate file. */
  426. // This all needs better errorchecking
  427. itoa(nodenum, outnum[0], 10);
  428. switch(cfg.bbstype)
  429.     {
  430.     case BBS_RA2:
  431.         rapgfil = openfile(top_output(OUT_STRING, "@1NODE@2.RA",
  432.                            cfg.bbsmultipath, outnum[0]), "at", 0);
  433.         break;
  434.     case BBS_SBBS11:
  435.         rapgfil = openfile(top_output(OUT_STRING, "@1TOLINE@2",
  436.                            cfg.bbsmultipath, outnum[0]), "at", 0);
  437.         break;
  438.     }
  439.  
  440. /* Abort if the file can't be opened. */
  441. if (!rapgfil)
  442.     {
  443.     top_output(OUT_SCREEN, getlang("CantPage"), outnum[0]);
  444.     return 0;
  445.     }
  446.  
  447. /* The filtered username is used because handes can contain PubColour
  448.    codes. */
  449. filter_string(tmp, cfg.usehandles ? user.handle : user.realname);
  450. itoa(od_control.od_node, outnum[0], 10);
  451.  
  452. /* Write the appropriate page header. */
  453. switch(cfg.bbstype)
  454.     {
  455.     case BBS_RA2:
  456.         strcpy(outbuf, top_output(OUT_STRING, getlang("RAPageHeader"),
  457.                tmp, outnum[0]));
  458.         break;
  459.     case BBS_SBBS11:
  460.         strcpy(outbuf, top_output(OUT_STRING, getlang("SBBSPageHeader"),
  461.                tmp, outnum[0]));
  462.         break;
  463.     }
  464. fputs(outbuf, rapgfil);
  465.  
  466. /* Write the message text. */
  467. fputs(pagebuf, rapgfil);
  468.  
  469. /* Write the appropriate page footer. */
  470. switch(cfg.bbstype)
  471.     {
  472.     case BBS_RA2:
  473.         fputs(top_output(OUT_STRING, getlang("RAPageFooter")), rapgfil);
  474.         break;
  475.     case BBS_SBBS11:
  476.         fputs(top_output(OUT_STRING, getlang("SBBSPageFooter")), rapgfil);
  477.         break;
  478.     }
  479.  
  480. closefile(rapgfil);
  481.  
  482. return 1;
  483. }
  484.  
  485. /* ra_setexistbits() - Selects the node status fields to display.
  486.    Parameters:  userdata - Pointer to generic BBS data structure to set the
  487.                            bits in.
  488.    Returns:  Nothing.
  489. */
  490. void ra_setexistbits(bbsnodedata_typ *userdata)
  491. {
  492.  
  493. userdata->existbits = NEX_HANDLE |
  494.                       NEX_REALNAME |
  495.                       NEX_NODE |
  496.                       NEX_SPEED |
  497.                       NEX_LOCATION |
  498.                       NEX_STATUS |
  499.                       NEX_PAGESTAT;
  500.  
  501. }
  502.  
  503. /* ra_login() - RA initialization when TOP is started.
  504.    Parameters:  None.
  505.    Returns:  Nothing.
  506. */
  507. void ra_login(void)
  508. {
  509. /* Generic BBS data buffer, login check BBS data buffer. */
  510. bbsnodedata_typ rutmp, logintmp;
  511. XINT res; /* Result codes. */
  512.  
  513. /* Copy the user information into the generic BBS data buffer. */
  514. memset(&rutmp, 0, sizeof(bbsnodedata_typ) - 2);
  515.  
  516. /* Check if the node is already logged in RA/SBBS. */
  517. res = (*bbs_call_loaduseron)(od_control.od_node, &logintmp);
  518. if (!res)
  519. {
  520.     if (!logintmp.hidden)
  521.     {
  522.         /* Set the do not disturb flag. */
  523.         node->quiet = rutmp.quiet = logintmp.quiet;
  524.         save_node_data(od_control.od_node, node);
  525.     }
  526. }
  527.  
  528. fixname(rutmp.realname, user.realname);
  529. fixname(rutmp.handle, user.handle);
  530. rutmp.node = od_control.od_node;
  531. rutmp.speed = od_control.baud;
  532. strcpy(rutmp.location, od_control.user_location);
  533. strcpy(rutmp.statdesc, getlang("NodeStatus"));
  534. rutmp.attribs1 = 0;
  535.  
  536. /* Update the USERON file to show the user is now in TOP. */
  537. res = (*bbs_call_saveuseron)(od_control.od_node, &rutmp);
  538. if (!res)
  539.     {
  540.     FILE *rnfil = NULL; /* RABUSY file stream. */
  541.  
  542.     /* Create RABUSY semaphore.  RA provides these for batch operations. */
  543.     if (cfg.bbstype == BBS_RA2)
  544.         {
  545.         itoa(od_control.od_node, outnum[0], 10);
  546.         rnfil = fopen(top_output(OUT_STRING, "@1RABUSY.@2", cfg.bbsmultipath,
  547.                                  outnum[0]), "wb");
  548.         fclose(rnfil);
  549.         }
  550.     node_added = TRUE;
  551.     }
  552.  
  553. }
  554.  
  555. /* ra_logout() - RA deinitialization when TOP is exited.
  556.    Parameters:  None.
  557.    Returns:  Nothing.
  558. */
  559. void ra_logout(void)
  560. {
  561. bbsnodedata_typ rutmp; /* Generic BBS data buffer. */
  562.  
  563. if (localmode || lanmode)
  564.     {
  565.     /* In local and LAN modes, TOP removes the user from the USERON file.
  566.        In remote mode, TOP assumes RA will gain control immediately after
  567.        the exit so it doesn't bother. */
  568.     memset(&rutmp, 0, sizeof(bbsnodedata_typ) - 2);
  569.     rutmp.quiet = 1;
  570.     rutmp.attribs1 = RA_HIDDEN & RA_NODISTURB;
  571.     rutmp.node = 0;
  572.     (*bbs_call_saveuseron)(od_control.od_node, &rutmp);
  573.     if (cfg.bbstype == BBS_RA2)
  574.         {
  575.         /* Remove the RABUSY semaphore. */
  576.         itoa(od_control.od_node, outnum[0], 10);
  577.         unlink(top_output(OUT_STRING, "@1RABUSY.@2", cfg.bbsmultipath,
  578.                           outnum[0]));
  579.         }
  580.     }
  581.  
  582. }
  583.  
  584. /* ra_openfiles() - Opens RA-related files.
  585.    Parameters:  None.
  586.    Returns:  Number of errors that occurred, or 0 on success.
  587. */
  588. XINT ra_openfiles(void)
  589. {
  590. XINT bbsres = 0; /* Error counter. */
  591.  
  592. switch(cfg.bbstype)
  593.     {
  594.     case BBS_RA2:
  595.         /* TOP keeps the RA USERON file open while it is running. */
  596.         useronfil = sh_open(top_output(OUT_STRING, "@1USERON.BBS",
  597.                                        cfg.bbspath),
  598.                             O_RDWR | O_CREAT | O_BINARY, SH_DENYNONE,
  599.                             S_IREAD | S_IWRITE);
  600.         break;
  601.     case BBS_SBBS11:
  602.         /* TOP does not keep the SBBS SUSERON file open because it seemed
  603.            to cause problems. */
  604.         return 0;
  605.     }
  606. bbsres += (useronfil == -1);
  607.  
  608. return bbsres;
  609. }
  610.  
  611. /* ra_updateopenfiles() - Re-opens files if the node changes in LAN mode.
  612.    Parameters:  None.
  613.    Returns:  Number of errors that occurred, or 0 on success. */
  614. XINT ra_updateopenfiles(void)
  615. {
  616.  
  617. /* As no node-specific files are kept open, nothing needs to be done. */
  618.  
  619. return 0;
  620. }
  621.  
  622. /* ra_longpageeditor() - Editor for long (multi-line) pages.
  623.    Parameters:  nodenum - Node number being paged.
  624.                 pagebuf - Pointer to buffer to hold the page text.
  625.    Returns:  TRUE if a page was entered, FALSE if the user aborted.
  626.    Notes:  Can be used with any BBS type that can handle long pages.
  627. */
  628. char ra_longpageeditor(XINT nodenum, unsigned char *pagebuf)
  629.     {
  630. #ifndef __OS2__
  631.     tODEditOptions edop; /* OpenDoors editor options. */
  632. #endif
  633.     unsigned char linebuf[81]; /* Line input buffer. */
  634.     XINT writecount = 0; /* Write count, used to limit page length. */
  635.  
  636. /* Under DOS and Win32, OpenDoors provides a sophisticated text editor so
  637.    TOP will take advantage of that. */
  638. #ifndef __OS2__
  639.     if (od_control.user_ansi || od_control.user_avatar)
  640.         {
  641.         /* The OpenDoors editor only works in ANSI and AVATAR modes. */
  642.  
  643.         /* Prepare the screen. */
  644.         od_clr_scr();
  645.         itoa(nodenum, outnum[0], 10);
  646.         top_output(OUT_SCREEN, getlang("EnterPageFS"), outnum[0]);
  647.         top_output(OUT_SCREEN, getlang("EnterPageFSSep"));
  648.  
  649.         /* Initialize the OpenDoors editor data. */
  650.         edop.nAreaLeft = 1;
  651.         edop.nAreaTop = 4;
  652.         edop.nAreaRight = 80;
  653.         edop.nAreaBottom = 23;
  654.         edop.TextFormat = FORMAT_LINE_BREAKS;
  655.         edop.pfMenuCallback = NULL;
  656.         edop.pfBufferRealloc = NULL;
  657.         edop.dwEditFlags = 0;
  658.  
  659.         /* Call the editor. */
  660.         if (od_multiline_edit(pagebuf, 1600, &edop) ==
  661.             OD_MULTIEDIT_SUCCESS)
  662.             {
  663.             /* The profanity censor can currently only handle strings of
  664.                less than 256 characters. */
  665.             if (strlen(pagebuf) < 256)
  666.                 {
  667.                 if (censorinput(pagebuf))
  668.                     {
  669.                     return 0;
  670.                     }
  671.                 }
  672.             return 1;
  673.             }
  674.         else
  675.             {
  676.             return 0;
  677.             }
  678.         }
  679.     else
  680. /* TOP/2 uses an older port of OpenDoors which does not have the fancy page
  681.    editor, so TOP uses less sophisticated line-by-line editor. */
  682. #endif
  683.         {
  684.         /* The line editor is also used if the user is in ASCII mode. */
  685.  
  686.         /* Prepare the screen. */
  687.         itoa(nodenum, outnum[0], 10);
  688.         top_output(OUT_SCREEN, getlang("EnterPage"), outnum[0]);
  689.         top_output(OUT_SCREEN, getlang("EnterPageSep"));
  690.         /* Put something in the input buffer to engage the loop. */
  691.         linebuf[0] = '.';
  692.         /* Loop until the message is too long or the user just hits ENTER. */
  693.         while(writecount < (1600 - 81) && linebuf[0])
  694.             {
  695.             memset(linebuf, 0, 80);
  696.             /* Get one line at a time.  Repeat if the input needs to be
  697.                censored. */
  698.             do
  699.                 {
  700.                 od_input_str(linebuf, 79, ' ',
  701.                              MAXASCII);
  702.                 }
  703.             while(censorinput(linebuf));
  704.             if (linebuf[0])
  705.                 {
  706.                 /* Copy the line to the page buffer. */
  707.                 memcpy(&pagebuf[writecount], linebuf, strlen(linebuf));
  708.                 writecount += strlen(linebuf);
  709.                 memcpy(&pagebuf[writecount], "\n", 2);
  710.                 writecount++;
  711.                 }
  712.             }
  713.         return 1;
  714.         }
  715.     }
  716.  
  717.