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

  1. #include "top.h"
  2.  
  3. /* Expirimental WildCat BBS interfacing. */
  4.  
  5. /*  Copyright 1993 - 2000 Paul J. Sidorsky
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License, version 2, as
  9.     published by the Free Software Foundation.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19. */
  20.  
  21. void wc_init(void)
  22. {
  23.  
  24. bbs_call_loaduseron = wc_loaduseron;
  25. bbs_call_saveuseron = wc_saveuseron;
  26. bbs_call_processmsgs = wc_processmsgs;
  27. bbs_call_page = wc_page;
  28. bbs_call_setexistbits = wc_setexistbits;
  29. bbs_call_login = wc_login;
  30. bbs_call_logout = wc_logout;
  31. bbs_call_openfiles = wc_openfiles;
  32. bbs_call_updateopenfiles = wc_updateopenfiles;
  33.  
  34. }
  35.  
  36. char wc_loaduseron(XINT nodenum, bbsnodedata_typ *userdata)
  37. { // Get rid of the n when more time is available
  38. XINT res;
  39. WC_NODEINFO_typ wcnode;
  40. long n;
  41.  
  42. n = nodenum;
  43.  
  44. if (nodenum == 0 ||
  45.     nodenum > (filelength(useronfil) / (long) sizeof(WC_NODEINFO_typ)))
  46.     {
  47.     return 1;
  48.     }
  49.  
  50. res = lseek(useronfil, n * (long) sizeof(WC_NODEINFO_typ), SEEK_SET);
  51. if (res == -1)
  52.     {
  53.     return 1;
  54.     }
  55. rec_locking(REC_LOCK, useronfil, n * (long) sizeof(WC_NODEINFO_typ),
  56.             sizeof(WC_NODEINFO_typ));
  57. res = read(useronfil, &wcnode, sizeof(WC_NODEINFO_typ));
  58. rec_locking(REC_UNLOCK, useronfil, n * (long) sizeof(WC_NODEINFO_typ),
  59.             sizeof(WC_NODEINFO_typ));
  60. if (res == -1)
  61.     {
  62.     return 1;
  63.     }
  64.  
  65. unbuild_pascal_string(35, wcnode.name);
  66. unbuild_pascal_string(35, wcnode.handle);
  67. unbuild_pascal_string(25, wcnode.city);
  68. unbuild_pascal_string(10, wcnode.statdesc);
  69.  
  70. memset(userdata, 0, sizeof(bbsnodedata_typ) - 2);
  71.  
  72. fixname(userdata->realname, wcnode.name);
  73. strncpy(userdata->handle, wcnode.handle, 30);
  74. fixname(userdata->handle, userdata->handle);
  75. userdata->node = wcnode.line;
  76. userdata->speed = wcnode.baud;
  77. strcpy(userdata->location, wcnode.city);
  78. if (wcnode.status == 255)
  79.     {
  80.     strcpy(userdata->statdesc, wcnode.statdesc);
  81.     }
  82. else
  83.     {
  84.     if (wcnode.status < 8)
  85.         {
  86.         strcpy(userdata->statdesc, wc_statustypes[wcnode.status]);
  87.         }
  88.     else
  89.         {
  90.         userdata->statdesc[0] = 0;
  91.         }
  92.     }
  93. userdata->quiet = wcnode.attribute & wc_NODISTURB;
  94. userdata->hidden = (wcnode.attribute & wc_HIDDEN) ||
  95.                    (wcnode.attribute & wc_READY) ||
  96.                    (wcnode.line == 0);
  97. userdata->attribs1 = wcnode.attribute;
  98. userdata->numcalls = wcnode.numcalls;
  99.  
  100. return 0;
  101. }
  102.  
  103. char wc_saveuseron(XINT nodenum, bbsnodedata_typ *userdata)
  104. {
  105. XINT res;
  106. WC_NODEINFO_typ wcnode;
  107. long n;
  108.  
  109. memset(&wcnode, 0, sizeof(WC_NODEINFO_typ));
  110.  
  111. strncpy(wcnode.name, userdata->realname, 35);
  112. strcpy(wcnode.handle, userdata->handle);
  113. wcnode.line = userdata->node;
  114. wcnode.baud = userdata->speed;
  115. strncpy(wcnode.city, userdata->location, 25);
  116. wcnode.status = 255;
  117. wcnode.attribute = userdata->attribs1;
  118. if (userdata->quiet)
  119.     {
  120.     wcnode.attribute |= wc_NODISTURB;
  121.     }
  122. else
  123.     {
  124.     wcnode.attribute &= (0xFF - wc_NODISTURB);
  125.     }
  126. strncpy(wcnode.statdesc, userdata->statdesc, 10);
  127. wcnode.numcalls = userdata->numcalls;
  128.  
  129. build_pascal_string(wcnode.name);
  130. build_pascal_string(wcnode.handle);
  131. build_pascal_string(wcnode.city);
  132. build_pascal_string(wcnode.statdesc);
  133.  
  134. n = nodenum;
  135. if (filelength(useronfil) < (long) nodenum * (long) sizeof(WC_NODEINFO_typ))
  136.     {
  137.     chsize(useronfil, (long) nodenum * (long) sizeof(WC_NODEINFO_typ));
  138.     }
  139.  
  140. res = lseek(useronfil, n * (long) sizeof(WC_NODEINFO_typ), SEEK_SET);
  141. if (res == -1)
  142.     {
  143.     return 1;
  144.     }
  145. rec_locking(REC_LOCK, useronfil, n * (long) sizeof(WC_NODEINFO_typ),
  146.             sizeof(WC_NODEINFO_typ));
  147. res = write(useronfil, &wcnode, sizeof(WC_NODEINFO_typ));
  148. rec_locking(REC_UNLOCK, useronfil, n * (long) sizeof(WC_NODEINFO_typ),
  149.             sizeof(WC_NODEINFO_typ));
  150. if (res == -1)
  151.     {
  152.     return 1;
  153.     }
  154.  
  155. return 0;
  156. }
  157.  
  158. XINT wc_processmsgs(void)
  159. {
  160. // This can stay streamed for a while
  161. FILE *pnfil = NULL;
  162. char filnam[256];
  163. char XFAR *buffer = NULL;
  164. XINT pos = 0, xpos = 0;
  165. XINT tmp, xh;
  166. char sbbsmsgon = 0;
  167.  
  168. switch(cfg.bbstype)
  169.     {
  170.     case BBS_RA2:
  171.         sprintf(filnam, "%sNODE%i.RA", cfg.bbsmultipath, od_control.od_node);
  172.         break;
  173.     case BBS_SBBS11:
  174.         sprintf(filnam, "%sTOLINE%i", cfg.bbsmultipath, od_control.od_node);
  175.         break;
  176.     }
  177.  
  178. if (access(filnam, 4))
  179.     {
  180.     return 0;
  181.     }
  182.  
  183. buffer = malloc(8000);
  184. if (!buffer)
  185.     {
  186.     return 0;
  187.     }
  188.  
  189.  
  190. pnfil = _fsopen(filnam, "rb", SH_DENYNONE);
  191. if (!pnfil)
  192.     {
  193.     dofree(buffer);
  194.     return 0;
  195.     }
  196.  
  197. delprompt(TRUE);
  198.  
  199. if (user.pref1 & PREF1_DUALWINDOW)
  200.     {
  201.     // Different for AVT when I find out what the store/recv codes are.
  202.     od_disp_emu("\x1B" "[u", TRUE);
  203.     top_output(OUT_SCREEN, getlang("DWOutputPrefix"));
  204.     }
  205.  
  206. top_output(OUT_SCREEN, getlang("RAPageRecvPrefix"));
  207.  
  208. do
  209.     {
  210.     memset(buffer, 0, 8000);
  211.     fseek(pnfil, (long) xpos * 7900L, SEEK_SET);
  212.     xh = fread(buffer, 1, 8000, pnfil);
  213.     if (xh > 7900)
  214.         {
  215.         xh = 7900;
  216.         }
  217.  
  218.     for (pos = 0; pos < xh; pos++)
  219.         {
  220.         if (!sbbsmsgon && cfg.bbstype == BBS_SBBS11)
  221.             {
  222.             if (!strnicmp(&buffer[pos], "/MESSAGE", 8))
  223.                 {
  224.                 unsigned char *eptr = NULL, *nptr = NULL;
  225.                 XINT fromnode;
  226.  
  227.                 pos += 9;
  228.                 eptr = strchr(&buffer[pos], ',');
  229.                 memset(outbuf, 0, 61);
  230.                 strncpy(outbuf, &buffer[pos], eptr - &buffer[pos]);
  231.                 pos += (eptr - &buffer[pos]) + 1;
  232.                 eptr = strchr(&buffer[pos], '\r');
  233.                 nptr = strchr(&buffer[pos], '\n');
  234.                 if (nptr < eptr && nptr != NULL)
  235.                     {
  236.                     eptr = nptr;
  237.                     }
  238.                 fromnode = atoi(&buffer[pos]);
  239.                 itoa(fromnode, outnum[0], 10);
  240.                 pos += (eptr - &buffer[pos]) - 1;
  241.                 top_output(OUT_SCREEN, "@c");
  242.                 top_output(OUT_SCREEN, getlang("SBBSRecvPageHdr"),
  243.                            outbuf, outnum[0]);
  244.                 sbbsmsgon = 1;
  245.                 }
  246.             continue;
  247.             }
  248.         if (sbbsmsgon && cfg.bbstype == BBS_SBBS11)
  249.             {
  250.             if (!strnicmp(&buffer[pos], "/END/", 5))
  251.                 {
  252.                 sbbsmsgon = 0;
  253.                 pos += 4;
  254.                 top_output(OUT_SCREEN, getlang("RAEnter"));
  255.                 while(od_get_key(TRUE) != 13);
  256.                 top_output(OUT_SCREEN, getlang("RAEnterSuffix"));
  257.                 continue;
  258.                 }
  259.             }
  260.         if (buffer[pos] == 1)
  261.             {
  262.             while(od_get_key(TRUE) != 13);
  263.             continue;
  264.             }
  265.         if (buffer[pos] == 11)
  266.             {
  267.             if (buffer[pos + 1] == ']')
  268.                 {
  269.                 tmp = atoi(&buffer[pos + 2]);
  270.                 pos += 4;
  271.  
  272.                 switch(tmp)
  273.                     {
  274.                     case 258: top_output(OUT_SCREEN, getlang("RAEnter")); break;
  275.                     case 496: top_output(OUT_SCREEN, getlang("RAOnNode")); break;
  276.                     case 497: top_output(OUT_SCREEN, getlang("RAMsgFrom")); break;
  277.                     case 628: top_output(OUT_SCREEN, getlang("RAJustPosted")); break;
  278.                     }
  279.                 continue;
  280.                 }
  281.             if (buffer[pos + 1] == '[')
  282.                 {
  283.                 unsigned char fgcol, bgcol;
  284.  
  285.                 bgcol = toupper(buffer[pos + 2]);
  286.                 fgcol = toupper(buffer[pos + 3]);
  287.                 pos += 3;
  288.  
  289.                 if (isxdigit(bgcol))
  290.                     {
  291.                     if (bgcol >= 'A' && bgcol <= 'F')
  292.                         {
  293.                         bgcol -= ('A' - 10);
  294.                         }
  295.                     else
  296.                         {
  297.                         bgcol -= '0';
  298.                         }
  299.                     }
  300.                 if (isxdigit(fgcol))
  301.                     {
  302.                     if (fgcol >= 'A' && fgcol <= 'F')
  303.                         {
  304.                         fgcol -= ('A' - 10);
  305.                         }
  306.                     else
  307.                         {
  308.                         fgcol -= '0';
  309.                         }
  310.                     }
  311.                 od_set_colour(fgcol, bgcol);
  312.                 continue;
  313.                 }
  314.             }
  315.         od_putch(buffer[pos]);
  316.         }
  317.     xpos++;
  318.     }
  319. while((long) xpos * 7900L < filelength(fileno(pnfil)));
  320.  
  321. closefile(pnfil);
  322.  
  323. top_output(OUT_SCREEN, getlang("RAPageRecvSuffix"));
  324. unlink(filnam);
  325.  
  326. dofree(buffer);
  327.  
  328. return 1;
  329. }
  330.  
  331. char wc_page(XINT nodenum, unsigned char *pagebuf)
  332. {
  333. FILE *rapgfil = NULL;
  334. unsigned char tmp[41];
  335.  
  336. // This all needs better errorchecking
  337. itoa(nodenum, outnum[0], 10);
  338. switch(cfg.bbstype)
  339.     {
  340.     case BBS_RA2:
  341.         rapgfil = openfile(top_output(OUT_STRING, "@1NODE@2.RA",
  342.                            cfg.bbsmultipath, outnum[0]), "at", 0);
  343.         break;
  344.     case BBS_SBBS11:
  345.         rapgfil = openfile(top_output(OUT_STRING, "@1TOLINE@2",
  346.                            cfg.bbsmultipath, outnum[0]), "at", 0);
  347.         break;
  348.     }
  349.  
  350. if (!rapgfil)
  351.     {
  352.     top_output(OUT_SCREEN, getlang("CantPage"), outnum[0]);
  353.     return 1;
  354.     }
  355.  
  356. filter_string(tmp, cfg.usehandles ? user.handle : user.realname);
  357. itoa(od_control.od_node, outnum[0], 10);
  358.  
  359. switch(cfg.bbstype)
  360.     {
  361.     case BBS_RA2:
  362.         strcpy(outbuf, top_output(OUT_STRING, getlang("RAPageHeader"),
  363.                tmp, outnum[0]));
  364.         break;
  365.     case BBS_SBBS11:
  366.         strcpy(outbuf, top_output(OUT_STRING, getlang("SBBSPageHeader"),
  367.                tmp, outnum[0]));
  368.         break;
  369.     }
  370. fputs(outbuf, rapgfil);
  371.  
  372. fputs(pagebuf, rapgfil);
  373.  
  374. switch(cfg.bbstype)
  375.     {
  376.     case BBS_RA2:
  377.         fputs(top_output(OUT_STRING, getlang("RAPageFooter")), rapgfil);
  378.         break;
  379.     case BBS_SBBS11:
  380.         fputs(top_output(OUT_STRING, getlang("SBBSPageFooter")), rapgfil);
  381.         break;
  382.     }
  383.  
  384. closefile(rapgfil);
  385.  
  386. return 0;
  387. }
  388.  
  389. void wc_setexistbits(bbsnodedata_typ *userdata)
  390. {
  391.  
  392. userdata->existbits = NEX_REALNAME |
  393.                       NEX_NODE |
  394.                       NEX_SPEED |
  395.                       NEX_LOCATION |
  396.                       NEX_STATUS;
  397.  
  398. }
  399.  
  400. void wc_login(void)
  401. {
  402. bbsnodedata_typ rutmp;
  403. XINT res;
  404.  
  405. memset(&rutmp, 0, sizeof(bbsnodedata_typ) - 2);
  406. fixname(rutmp.realname, user.realname);
  407. fixname(rutmp.handle, user.handle);
  408. rutmp.node = od_control.od_node;
  409. rutmp.speed = od_control.baud;
  410. strcpy(rutmp.location, od_control.user_location);
  411. strcpy(rutmp.statdesc, getlang("NodeStatus"));
  412. rutmp.attribs1 = 0; // change to use DND status!
  413. res = (*bbs_call_saveuseron)(od_control.od_node, &rutmp);
  414. if (!res)
  415.     {
  416.     FILE *rnfil = NULL;
  417.  
  418.     if (cfg.bbstype == BBS_RA2)
  419.         {
  420.         itoa(od_control.od_node, outnum[0], 10);
  421.         rnfil = fopen(top_output(OUT_STRING, "@1RABUSY.@2", cfg.bbsmultipath,
  422.                                  outnum[0]), "wb");
  423.         fclose(rnfil);
  424.         }
  425.     node_added = TRUE;
  426.     }
  427.  
  428. }
  429.  
  430. void wc_logout(void)
  431. {
  432. bbsnodedata_typ rutmp;
  433.  
  434. if (localmode || lanmode)
  435.     {
  436.     memset(&rutmp, 0, sizeof(bbsnodedata_typ) - 2);
  437.     rutmp.quiet = 1;
  438.     rutmp.attribs1 = wc_HIDDEN & wc_NODISTURB;
  439.     rutmp.node = 0;
  440.     (*bbs_call_saveuseron)(od_control.od_node, &rutmp);
  441.     if (cfg.bbstype == BBS_RA2)
  442.         {
  443.         itoa(od_control.od_node, outnum[0], 10);
  444.         unlink(top_output(OUT_STRING, "@1RABUSY.@2", cfg.bbsmultipath,
  445.                           outnum[0]));
  446.         }
  447.     }
  448.  
  449. }
  450.  
  451. XINT wc_openfiles(void)
  452. {
  453. XINT bbsres = 0;
  454.  
  455. switch(cfg.bbstype)
  456.     {
  457.     case BBS_RA2:
  458.         useronfil = sh_open(top_output(OUT_STRING, "@1USERON.BBS",
  459.                                        cfg.bbspath),
  460.                             O_RDWR | O_CREAT | O_BINARY, SH_DENYNONE,
  461.                             S_IREAD | S_IWRITE);
  462.         break;
  463.     case BBS_SBBS11:
  464.         return 0;
  465.     }
  466. bbsres += (useronfil == -1);
  467.  
  468. return bbsres;
  469. }
  470.  
  471. XINT wc_updateopenfiles(void)
  472. {
  473.  
  474. return 0;
  475. }
  476.  
  477.