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

  1. /******************************************************************************
  2. BBSSBBS.C    Implements SuperBBS-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 specific to interfacing with SuperBBS
  20. v1.1x.  The rest of the SuperBBS interfacing uses RA calls.
  21. ******************************************************************************/
  22.  
  23. #include "top.h"
  24.  
  25. /* sbbs_init() - Initialize pointers to SuperBBS functions.
  26.    Paremeters:  None.
  27.    Returns:  Nothing.
  28. */
  29. void sbbs_init(void)
  30. {
  31.  
  32. bbs_call_loaduseron = sbbs_loaduseron;
  33. bbs_call_saveuseron = sbbs_saveuseron;
  34. bbs_call_processmsgs = ra_processmsgs;
  35. bbs_call_page = ra_page;
  36. bbs_call_setexistbits = sbbs_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. /* sbbs_loaduseron() - Loads a node status from the SUSERON 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 sbbs_loaduseron(XINT nodenum, bbsnodedata_typ *userdata)
  51. {
  52. XINT res; /* Result code. */
  53. SBBS_USERON_typ sbbsuser; /* SBBS SUSERON record. */
  54. long n; /* 0-based node number. */
  55.  
  56. /* Open the SUSERON file, which TOP does not keep open due to apparent
  57.    conflicts. */
  58. useronfil = sh_open(top_output(OUT_STRING, "@1SUSERON.BBS",
  59.                                cfg.bbspath),
  60.                     O_RDWR | O_CREAT | O_BINARY, SH_DENYNONE,
  61.                     S_IREAD | S_IWRITE);
  62. if (useronfil == -1)
  63.     {
  64.     return 1;
  65.     }
  66.  
  67. /* In the SUSERON file, records are 0-based (eg. node 1 is record 0). */
  68. n = nodenum - 1L;
  69.  
  70. /* Abort if node 0 is paged, or if the SUSERON file is not large enough that
  71.    it holds the information for the node (meaning the node doesn't exist). */
  72. if (nodenum == 0 ||
  73.     nodenum > (filelength(useronfil) / (long) sizeof(SBBS_USERON_typ)))
  74.     {
  75.     close(useronfil);
  76.     return 1;
  77.     }
  78.  
  79. /* Load the SUSERON record. */
  80. res = lseek(useronfil, n * (long) sizeof(SBBS_USERON_typ), SEEK_SET);
  81. if (res == -1)
  82.     {
  83.     close(useronfil);
  84.     return 1;
  85.     }
  86. rec_locking(REC_LOCK, useronfil, n * (long) sizeof(SBBS_USERON_typ),
  87.             sizeof(SBBS_USERON_typ));
  88. res = read(useronfil, &sbbsuser, sizeof(SBBS_USERON_typ));
  89. rec_locking(REC_UNLOCK, useronfil, n * (long) sizeof(SBBS_USERON_typ),
  90.             sizeof(SBBS_USERON_typ));
  91. if (res == -1)
  92.     {
  93.     close(useronfil);
  94.     return 1;
  95.     }
  96.  
  97. /* Convert Pascal strings to C. */
  98. unbuild_pascal_string(35, sbbsuser.name);
  99. unbuild_pascal_string(25, sbbsuser.city);
  100.  
  101. /* Copy the information into the Generic BBS structure. */
  102. memset(userdata, 0, sizeof(bbsnodedata_typ) - 2);
  103. fixname(userdata->realname, sbbsuser.name);
  104. strncpy(userdata->handle, sbbsuser.name, 30);
  105. fixname(userdata->handle, userdata->handle);
  106. userdata->quiet = sbbsuser.attribute & SBBS_NODISTURB;
  107. userdata->hidden = (sbbsuser.attribute & SBBS_HIDDEN) ||
  108.                    !(sbbsuser.attribute & SBBS_INUSE);
  109. userdata->attribs1 = sbbsuser.attribute;
  110. if (sbbsuser.status < 11)
  111.     {
  112.     /* Use the predefined status types from the language file. */
  113.     strcpy(userdata->statdesc, sbbs_statustypes[sbbsuser.status]);
  114.     }
  115. else
  116.     {
  117.     /* Status type unknown.  This would occur either with a corrupt
  118.        SUSERON file or with a new version of SBBS that uses new types. */
  119.     userdata->statdesc[0] = 0;
  120.     }
  121. userdata->speed = sbbsuser.baud;
  122. strcpy(userdata->location, sbbsuser.city);
  123. userdata->infobyte = sbbsuser.infobyte;
  124. userdata->node = nodenum;
  125. userdata->numcalls = 1;
  126.  
  127. close(useronfil);
  128.  
  129. return 0;
  130. }
  131.  
  132. /* sbbs_saveuseron() - Saves a node status to the SUSERON file.
  133.    Parameters:  nodenum - Node number to save the data for.
  134.                 userdata - Pointer to generic BBS data structure to use.
  135.    Returns:  TRUE if an error occurred, FALSE if successful.
  136. */
  137. char sbbs_saveuseron(XINT nodenum, bbsnodedata_typ *userdata)
  138. {
  139. XINT res; /* Result code. */
  140. SBBS_USERON_typ sbbsuser; /* SBBS SUSERON buffer. */
  141. long n; /* 0-based node number. */
  142.  
  143. /* Open the SUSERON file, which TOP does not keep open due to apparent
  144.    conflicts. */
  145. useronfil = sh_open(top_output(OUT_STRING, "@1SUSERON.BBS",
  146.                                cfg.bbspath),
  147.                     O_RDWR | O_CREAT | O_BINARY, SH_DENYNONE,
  148.                     S_IREAD | S_IWRITE);
  149. if (useronfil == -1)
  150.     {
  151.     return 1;
  152.     }
  153.  
  154. /* Copy the data from the Generic BBS buffer to the SUSERON record. */
  155. memset(&sbbsuser, 0, sizeof(SBBS_USERON_typ));
  156. strncpy(sbbsuser.name, userdata->realname, 35);
  157. sbbsuser.attribute = userdata->attribs1;
  158. if (userdata->quiet)
  159.     {
  160.     sbbsuser.attribute |= SBBS_NODISTURB;
  161.     }
  162. else
  163.     {
  164.     sbbsuser.attribute &= (0xFF - SBBS_NODISTURB);
  165.     }
  166. sbbsuser.attribute |= SBBS_INUSE;
  167. sbbsuser.status = 6;
  168. /* Asceratin the status number since SBBS doesn't support custom statuses. */
  169. for (res = 0; res < 11; res++)
  170.     {
  171.     if (!stricmp(userdata->statdesc, sbbs_statustypes[res]))
  172.         {
  173.         sbbsuser.status = res;
  174.         break;
  175.         }
  176.     }
  177. sbbsuser.baud = userdata->speed;
  178. strncpy(sbbsuser.city, userdata->location, 25);
  179. sbbsuser.infobyte = userdata->infobyte;
  180.  
  181. /* Convert C strings to Pascal, which SBBS uses. */
  182. build_pascal_string(sbbsuser.name);
  183. build_pascal_string(sbbsuser.city);
  184.  
  185. /* Get the 0-based node number. */
  186. n = nodenum - 1;
  187.  
  188. /* Extend the SUSERON file if it's not long enough.  Done for safety when
  189.    record locking. */
  190. if (filelength(useronfil) < (long) nodenum * (long) sizeof(SBBS_USERON_typ))
  191.     {
  192.     chsize(useronfil, (long) nodenum * (long) sizeof(SBBS_USERON_typ));
  193.     }
  194.  
  195. /* Write the SUSERON data. */
  196. res = lseek(useronfil, n * (long) sizeof(SBBS_USERON_typ), SEEK_SET);
  197. if (res == -1)
  198.     {
  199.     close(useronfil);
  200.     return 1;
  201.     }
  202. rec_locking(REC_LOCK, useronfil, n * (long) sizeof(SBBS_USERON_typ),
  203.             sizeof(SBBS_USERON_typ));
  204. res = write(useronfil, &sbbsuser, sizeof(SBBS_USERON_typ));
  205. rec_locking(REC_UNLOCK, useronfil, n * (long) sizeof(SBBS_USERON_typ),
  206.             sizeof(SBBS_USERON_typ));
  207. if (res == -1)
  208.     {
  209.     close(useronfil);
  210.     return 1;
  211.     }
  212.  
  213. close(useronfil);
  214.  
  215. return 0;
  216. }
  217.  
  218. /* sbbs_setexistbits() - Selects the node status fields to display.
  219.    Parameters:  userdata - Pointer to generic BBS data structure to set the
  220.                            bits in.
  221.    Returns:  Nothing.
  222. */
  223. void sbbs_setexistbits(bbsnodedata_typ *userdata)
  224. {
  225.  
  226. userdata->existbits = NEX_HANDLE |
  227.                       NEX_REALNAME |
  228.                       NEX_NODE |
  229.                       NEX_LOCATION |
  230.                       NEX_STATUS |
  231.                       NEX_PAGESTAT;
  232.  
  233. }
  234.