home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / LO241SRV.ZIP / lnetmgr.c < prev    next >
Text File  |  1998-08-01  |  13KB  |  387 lines

  1.  
  2. // LoraBBS Version 2.41 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include <stdio.h>
  20. #include <ctype.h>
  21. #include <mem.h>
  22. #include <alloc.h>
  23. #include <string.h>
  24. #include <io.h>
  25. #include <dos.h>
  26. #include <conio.h>
  27. #include <fcntl.h>
  28. #include <time.h>
  29. #include <share.h>
  30. #include <sys\stat.h>
  31.  
  32. #define shopen(path,access)       open(path,(access)|SH_DENYNONE)
  33. #define cshopen(path,access,mode) open(path,(access)|SH_DENYNONE,mode)
  34.  
  35. #include <cxl\cxlvid.h>
  36. #include <cxl\cxlwin.h>
  37. #include <cxl\cxlstr.h>
  38.  
  39. #include "lora.h"
  40. #include "timer.h"
  41. #include "version.h"
  42.  
  43. long timerset(int);
  44. int timeup(long);
  45. void dostime (int *, int *, int *, int *);
  46. void dosdate (int *, int *, int *, int *);
  47. void mtask_find (void);
  48. void mtask_find(void);
  49. int dv_get_version(void);
  50. int ddos_active(void);
  51. int tv_get_version(void);
  52. int ml_active(void);
  53. int windows_active (void);
  54. void dv_pause(void);
  55. void ddos_pause(void);
  56. void tv_pause(void);
  57. void ml_pause(void);
  58. void msdos_pause(void);
  59. void windows_pause (void);
  60.  
  61. char have_dv = 0, have_ml = 0, have_tv = 0, have_ddos = 0;
  62.  
  63. void main (void)
  64. {
  65.    FILE *fp;
  66.    int fd, i, line, x, y, mainview, status, task[20], nd;
  67.    char linea[128], *p, c, *names[20], msgs[3][70];
  68.    long t, cl;
  69.    struct _useron useron;
  70.    struct time timep;
  71.  
  72.    mtask_find ();
  73.    videoinit ();
  74.    hidecur ();
  75.    readcur (&x, &y);
  76.  
  77.    for (i = 0; i < 17; i++)
  78.       names[i] = (char *)malloc (36);
  79.    names[i] = NULL;
  80.  
  81.    mainview = wopen (3, 0, 23, 79, 0, LBLUE|_BLACK, LGREY|_BLACK);
  82.    wactiv (mainview);
  83.    whline (1, 0, 79, 0, LBLUE|_BLACK);
  84.    wvline (0, 32, 20, 0, LBLUE|_BLACK);
  85.    wvline (0, 36, 20, 0, LBLUE|_BLACK);
  86.    wvline (0, 42, 20, 0, LBLUE|_BLACK);
  87.    wvline (0, 63, 20, 0, LBLUE|_BLACK);
  88.    wvline (0, 66, 20, 0, LBLUE|_BLACK);
  89.    wvline (0, 75, 20, 0, LBLUE|_BLACK);
  90.    wprints (0, 0, WHITE|_BLACK, "Name");
  91.    wprints (0, 33, WHITE|_BLACK, "Tsk");
  92.    wprints (0, 37, WHITE|_BLACK, "Speed");
  93.    wprints (0, 43, WHITE|_BLACK, "Location");
  94.    wprints (0, 64, WHITE|_BLACK, "DC");
  95.    wprints (0, 67, WHITE|_BLACK, "Status");
  96.    wprints (0, 76, WHITE|_BLACK, "CB#");
  97.  
  98.    i = wopen (24, 0, 24, 79, 5, LBLUE|_BLACK, BLACK|_LGREY);
  99.    wactiv (i);
  100.  
  101.    sprintf (linea, "LoraBBS-OS/2 Network Manager %s - Copyright (c) 1992-96 by Marco Maccaferri", LNETMGR_VERSION);
  102.    wcenters (0, BLACK|_LGREY, linea);
  103.  
  104.    status = wopen (0, 0, 2, 79, 1, LGREEN|_BLACK, LGREY|_BLACK);
  105.    wactiv (status);
  106.    wprints (0, 1, WHITE|_BLACK, "Shut down node   Broadcat   Message    Quit             ");
  107.    wprintc (0, 1, YELLOW|_BLACK, 'S');
  108.    wprintc (0, 18, YELLOW|_BLACK, 'B');
  109.    wprintc (0, 29, YELLOW|_BLACK, 'M');
  110.    wprintc (0, 40, YELLOW|_BLACK, 'Q');
  111.  
  112.    cl = t = timerset (0);
  113.    wactiv (mainview);
  114.  
  115.    do {
  116.       if (timeup (t)) {
  117.          t = timerset (300);
  118.          fd = shopen ("USERON.BBS", O_RDONLY|O_BINARY);
  119.  
  120.          for (line = 2; line < 19; line++) {
  121.             if (read(fd, (char *)&useron, sizeof(struct _useron)) != sizeof(struct _useron))
  122.                memset ((char *)&useron, 0, sizeof (struct _useron));
  123.  
  124.             useron.city[21] = '\0';
  125.  
  126.             sprintf (names[line - 2], "%-30.30s", useron.name);
  127.             task[line - 2] = useron.line;
  128.  
  129.             if (useron.name[0]) {
  130.                sprintf (linea, "%-31.31s", useron.name);
  131.                wprints (line, 0, YELLOW|_BLACK, linea);
  132.                sprintf (linea, "%3d", useron.line);
  133.                wprints (line, 33, YELLOW|_BLACK, linea);
  134.                sprintf (linea, "%5lu", useron.baud);
  135.                wprints (line, 37, YELLOW|_BLACK, linea);
  136.                sprintf (linea, "%-20.20s", useron.city);
  137.                wprints (line, 43, YELLOW|_BLACK, linea);
  138.                sprintf (linea, "%c%c", useron.donotdisturb ? 'D' : ' ', useron.priv_chat ? 'C' : ' ');
  139.                wprints (line, 64, YELLOW|_BLACK, linea);
  140.                sprintf (linea, "%-8.8s", useron.status);
  141.                wprints (line, 67, YELLOW|_BLACK, linea);
  142.                sprintf (linea, "%3d", useron.cb_channel);
  143.                wprints (line, 76, YELLOW|_BLACK, linea);
  144.             }
  145.             else if (useron.line_status) {
  146.                if (useron.line_status != WFC)
  147.                   wprints (line, 0, YELLOW|_BLACK, "                               ");
  148.                else {
  149.                   sprintf (linea, "%-31.31s", "Waiting for call");
  150.                   wprints (line, 0, YELLOW|_BLACK, linea);
  151.                }
  152.                sprintf (linea, "%3d", useron.line);
  153.                wprints (line, 33, YELLOW|_BLACK, linea);
  154.                wprints (line, 37, YELLOW|_BLACK, "     ");
  155.                wprints (line, 43, YELLOW|_BLACK, "                    ");
  156.                wprints (line, 64, YELLOW|_BLACK, "  ");
  157.                if (useron.line_status != WFC) {
  158.                   sprintf (linea, "%-8.8s", useron.status);
  159.                   wprints (line, 67, YELLOW|_BLACK, linea);
  160.                }
  161.                else
  162.                   wprints (line, 67, YELLOW|_BLACK, "        ");
  163.                wprints (line, 76, YELLOW|_BLACK, "   ");
  164.             }
  165.             else {
  166.                wprints (line, 0, YELLOW|_BLACK, "                               ");
  167.                wprints (line, 33, YELLOW|_BLACK, "   ");
  168.                wprints (line, 37, YELLOW|_BLACK, "     ");
  169.                wprints (line, 43, YELLOW|_BLACK, "                    ");
  170.                wprints (line, 64, YELLOW|_BLACK, "  ");
  171.                wprints (line, 67, YELLOW|_BLACK, "        ");
  172.                wprints (line, 76, YELLOW|_BLACK, "   ");
  173.             }
  174.          }
  175.  
  176.          close(fd);
  177.       }
  178.  
  179.       if (timeup (cl)) {
  180.          cl = timerset (100);
  181.          gettime((struct time *)&timep);
  182.  
  183.          wactiv(status);
  184.  
  185.          sprintf(linea, "%02d:%02d:%02d", timep.ti_hour % 24, timep.ti_min % 60, timep.ti_sec % 60);
  186.          wprints (0, 69, WHITE|_BLACK, linea);
  187.  
  188.          wactiv (mainview);
  189.       }
  190.  
  191.       c = 0;
  192.       if (kbhit ())
  193.          c = toupper(getch ());
  194.  
  195.       if (c == 'S') {
  196.      wactiv (status);
  197.      wprints (0, 1, WHITE|_BLACK, "Select the node to shut down then <enter>, <esc> to exit");
  198.      i = wpickstr (6, 1, 22, 30, 5, LGREY|_BLACK, YELLOW|_BLACK, BLACK|_CYAN, names, 0, NULL);
  199.      if (i != -1 && task[i]) {
  200.             sprintf (linea, "LEXIT%d.1", task[i]);
  201.             i = open (linea, O_WRONLY|O_CREAT|O_TRUNC, S_IREAD|S_IWRITE);
  202.             close (i);
  203.          }
  204.          wactiv (status);
  205.          wprints (0, 1, WHITE|_BLACK, "Shut down node   Broadcat   Message    Quit                ");
  206.          wprintc (0, 1, YELLOW|_BLACK, 'S');
  207.          wprintc (0, 18, YELLOW|_BLACK, 'B');
  208.          wprintc (0, 29, YELLOW|_BLACK, 'M');
  209.          wprintc (0, 40, YELLOW|_BLACK, 'Q');
  210.          wactiv (mainview);
  211.       }
  212.       else if (c == 'B') {
  213.          i = wopen (11, 5, 16, 74, 1, YELLOW|_BLUE, BLACK|_BLUE);
  214.          wactiv (i);
  215.          wprints (0, 1, WHITE|_BLUE, "Write your message, <esc> exit");
  216.          winpbeg (WHITE|_RED, WHITE|_RED);
  217.  
  218.          winpdef (1, 1, msgs[0], "??????????????????????????????????????????????????????????????????", '?', 0, NULL, 0);
  219.          winpdef (2, 1, msgs[1], "??????????????????????????????????????????????????????????????????", '?', 0, NULL, 0);
  220.          winpdef (3, 1, msgs[2], "??????????????????????????????????????????????????????????????????", '?', 0, NULL, 0);
  221.          showcur ();
  222.  
  223.          if (winpread () != W_ESCPRESS) {
  224.             strtrim (msgs[0]);
  225.             strtrim (msgs[1]);
  226.             strtrim (msgs[2]);
  227.  
  228.             if ((fd = shopen ("USERON.BBS", O_RDONLY|O_BINARY)) != -1) {
  229.                for (line = 2; line < 19; line++) {
  230.                   if (read(fd, (char *)&useron, sizeof(struct _useron)) != sizeof(struct _useron))
  231.                      break;
  232.  
  233.                    if (useron.status == 0)
  234.                       continue;
  235.  
  236.                    sprintf(linea, "LINE%d.BBS", useron.line);
  237.                    fp = fopen(linea, "at");
  238.  
  239.                    fprintf(fp, "\n\n ** MESSAGE **\n");
  240.                    fprintf(fp, "From:  System Manager\n");
  241.                    fprintf(fp, "\n\"%s", msgs[0]);
  242.                    if (msgs[1][0])
  243.                       fprintf (fp, "\n%s", msgs[1]);
  244.                    if (msgs[2][0])
  245.                       fprintf (fp, "\n%s", msgs[2]);
  246.                    fprintf (fp, "\".\n\n", msgs[0], msgs[1], msgs[2]);
  247.                    fprintf(fp, "ì\001");
  248.  
  249.                    fclose(fp);
  250.                }
  251.  
  252.                close(fd);
  253.             }
  254.          }
  255.  
  256.          hidecur ();
  257.          wactiv (mainview);
  258.       }
  259.       else if (c == 'M') {
  260.          wactiv (status);
  261.          wprints (0, 1, WHITE|_BLACK, "Select the node to send message then <enter>, <esc> to exit");
  262.          nd = wpickstr (6, 1, 22, 30, 5, LGREY|_BLACK, YELLOW|_BLACK, BLACK|_CYAN, names, 0, NULL);
  263.          if (nd != -1 && task[nd]) {
  264.             i = wopen (11, 5, 16, 74, 1, YELLOW|_BLUE, BLACK|_BLUE);
  265.             wactiv (i);
  266.             wprints (0, 1, WHITE|_BLUE, "Write your message, <esc> exit");
  267.             winpbeg (WHITE|_RED, WHITE|_RED);
  268.  
  269.             winpdef (1, 1, msgs[0], "??????????????????????????????????????????????????????????????????", '?', 0, NULL, 0);
  270.             winpdef (2, 1, msgs[1], "??????????????????????????????????????????????????????????????????", '?', 0, NULL, 0);
  271.             winpdef (3, 1, msgs[2], "??????????????????????????????????????????????????????????????????", '?', 0, NULL, 0);
  272.             showcur ();
  273.  
  274.             if (winpread () != W_ESCPRESS) {
  275.                strtrim (msgs[0]);
  276.                strtrim (msgs[1]);
  277.                strtrim (msgs[2]);
  278.  
  279.                 sprintf(linea, "LINE%d.BBS", task[nd]);
  280.                 fp = fopen(linea, "at");
  281.  
  282.                 fprintf(fp, "\n\n ** MESSAGE **\n");
  283.                 fprintf(fp, "From:  System Manager\n");
  284.                 fprintf(fp, "\n\"%s", msgs[0]);
  285.                 if (msgs[1][0])
  286.                    fprintf (fp, "\n%s", msgs[1]);
  287.                 if (msgs[2][0])
  288.                    fprintf (fp, "\n%s", msgs[2]);
  289.                 fprintf (fp, "\".\n\n", msgs[0], msgs[1], msgs[2]);
  290.                 fprintf(fp, "ì\001");
  291.  
  292.                 fclose(fp);
  293.             }
  294.  
  295.             hidecur ();
  296.          }
  297.  
  298.          wactiv (status);
  299.          wprints (0, 1, WHITE|_BLACK, "Shut down node   Broadcat   Message    Quit                ");
  300.          wprintc (0, 1, YELLOW|_BLACK, 'S');
  301.          wprintc (0, 18, YELLOW|_BLACK, 'B');
  302.          wprintc (0, 29, YELLOW|_BLACK, 'M');
  303.          wprintc (0, 40, YELLOW|_BLACK, 'Q');
  304.          wactiv (mainview);
  305.       }
  306.  
  307.    } while (c != 'Q');
  308.  
  309.    wcloseall ();
  310.    gotoxy_ (x, y);
  311.    showcur ();
  312. }
  313.  
  314. long timerset (t)
  315. int t;
  316. {
  317.    long l;
  318.    struct time timep;
  319.  
  320. #ifdef HIGH_OVERHEAD
  321.    int l2;
  322.  
  323. #endif
  324.    int hours, mins, secs, ths;
  325.  
  326. #ifdef HIGH_OVERHEAD
  327.    extern int week_day ();
  328.  
  329. #endif
  330.  
  331.    /* Get the DOS time and day of week */
  332.    gettime (&timep);
  333.    hours = timep.ti_hour;
  334.    mins = timep.ti_min;
  335.    secs = timep.ti_sec;
  336.    ths = timep.ti_hund;
  337.  
  338. #ifdef HIGH_OVERHEAD
  339.    l2 = week_day ();
  340. #endif
  341.  
  342.    /* Figure out the hundredths of a second so far this week */
  343.    l =
  344.  
  345. #ifdef HIGH_OVERHEAD
  346.       l2 * PER_DAY +
  347.       (hours % 24) * PER_HOUR +
  348. #endif
  349.       (mins % 60) * PER_MINUTE +
  350.       (secs % 60) * PER_SECOND +
  351.       ths;
  352.  
  353.    /* Add in the timer value */
  354.    l += t;
  355.  
  356.    /* Return the alarm off time */
  357.    return (l);
  358. }
  359.  
  360. int timeup (t)
  361. long t;
  362. {
  363.    long l;
  364.  
  365.    /* Get current time in hundredths */
  366.    l = timerset (0);
  367.  
  368.    /* If current is less then set by more than max int, then adjust */
  369.    if (l < (t - 65536L))
  370.       {
  371. #ifdef HIGH_OVERHEAD
  372.       l += PER_WEEK;
  373. #else
  374.       l += PER_HOUR;
  375. #endif
  376.       }
  377.  
  378.    /* Return whether the current is greater than the timer variable */
  379.    return ((l - t) >= 0L);
  380. }
  381.  
  382.  
  383. void mtask_find ()
  384. {
  385. }
  386.  
  387.