home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / XBBS7200.ZIP / XBBS7200.TAR / chatbbs / chatbbs.c < prev   
Encoding:
C/C++ Source or Header  |  1992-04-11  |  4.1 KB  |  166 lines

  1. /*
  2.  *  This program allows the "sysop" to communicate with the bbs user(s) that
  3.  *  is/are on the system. Only one chat can be performed at a time. While the
  4.  *  chat is in progress, any other user that is on the system who requests a
  5.  *  chat will automatically be notified that the sysop is presently chatting
  6.  *  or has "turned off" the chat. To turn off the chat, just generate a null
  7.  *  length file called /tmp/ttydev and the bbs software will do the rest.
  8.  * 
  9.  *  Usage of the program is as follows:   chatbbs device_name
  10.  *
  11.  *  Please note that the device_name DOES NOT include the path ( /dev/ ). An
  12.  *  example of the usage is as follows:  chatbbs tty1A
  13.  *
  14.  *  To TERMINATE the chat, just depress the ESCAPE key ( esc --- '\033' ) and
  15.  *  the chat will terminate.
  16.  *
  17.  *  The sequence that the bbs software uses is as follows:
  18.  *
  19.  *  SIGPIPE ------ Go into chat
  20.  *  SIGUSR1 ------ Exit chat
  21.  *
  22.  *  Please note that SIGUSR1 is also used to toggle the local monitoring of the
  23.  *  bbs user. The bbs software will determine what to do when it intercepts
  24.  *  SIGUSR1.
  25.  *
  26.  *
  27.  *  FOR SysV.4, compile the code using a -DES54 ( cc -DES54 chatbbs.c -o chatbbs
  28.  *
  29.  *
  30.  *  Sanford J. Zelkovitz    XBBS  714-821-9671
  31.  *
  32.  */
  33. #include <stdio.h>
  34. #include <string.h>
  35. #include <signal.h>
  36. #include "chat.h"
  37. int             kill();
  38. int             atoi();
  39. main(argc, argv) 
  40.     int        argc;
  41.     char           *argv[];
  42. {
  43.     FILE           *indev;
  44.     FILE           *outdev;
  45.     char            buffer[30];
  46.     char           *tty, *buffer_ptr, *ttyname();
  47.     char            temp[50], char_pid[30];
  48.     int             ch;
  49.     int             handle, i, pid;
  50.     int             ret_kill;
  51. #ifdef ESIX54
  52.     char        tmpbuffer[100];
  53.     FILE        *ttz;
  54.     char        x1[20], x2[20], x3[20], x4[20], x5[20], x6[20];
  55.     int        major, minor;
  56. #endif
  57.     setbuf(stdin, NULL);
  58.     setbuf(stdout, NULL);
  59.     if (argc != 2) {
  60.         printf("\nError in usage, should be: chatbbs device.\n");
  61.         exit(1);
  62.     }
  63.     strcpy(buffer, "/dev/");
  64.     strcat(buffer, argv[1]);
  65.     printf("\nDevice driver = %s\n", buffer);
  66.     tty = ttyname(1);
  67. #ifdef ESIX54
  68.     unlink("/dev/bbschatter");
  69.     sprintf(tmpbuffer, "ls -l %s > /tmp/chatinfo", tty);
  70.     system(tmpbuffer);
  71.     ttz = fopen("/tmp/chatinfo", "r");
  72.     (void) fscanf(ttz, "%s%s%s%s%s%s", x1, x2, x3, x4, x5, x6);
  73.     fclose(ttz);
  74.     major = atoi(x5);
  75.     minor = atoi(x6);
  76.     printf( "major = %d    minor = %d\n", major, minor);
  77.     sprintf(tmpbuffer, "/etc/mknod /dev/bbschatter c %d %d", major, minor);
  78.     system(tmpbuffer);
  79.     system("chmod 666 /dev/bbschatter");
  80.     system("chown bbs /dev/bbschatter");
  81. #endif
  82.     if ((indev = fopen("/tmp/ttydev", "w")) == NULL) {
  83.         printf("\nError opening /tmp/ttydev!\n");
  84.         exit(1);
  85.     }
  86. #ifdef ESIX54
  87.     (void) fprintf(indev, "%s\n", "/dev/bbschatter");
  88. #else
  89.     (void) fprintf(indev, "%s\n", tty);
  90. #endif
  91.     fclose(indev);
  92.     if ((outdev = fopen(buffer, "r+")) == NULL) {
  93.         unlink("/tmp/ttydev");
  94.         unlink("/dev/bbschatter");
  95.         printf("\nError opening BBS user's device driver!\n");
  96.         exit(1);
  97.     }
  98.     setbuf(outdev, NULL);
  99.     strcpy(temp, "/tmp/pid");
  100.     i = strlen(buffer);
  101.     buffer_ptr = buffer;
  102.     buffer_ptr = buffer_ptr + i - 2;
  103.     strcat(temp, buffer_ptr);
  104.     if ((indev = fopen(temp, "r")) == NULL) {
  105.         unlink("/tmp/ttydev");
  106.         unlink("/dev/bbschatter");
  107.         printf("\nError opening pid file!\n");
  108.         exit(1);
  109.     }
  110.     (void) fscanf(indev, "%s", char_pid);
  111.     fclose(indev);
  112.     pid = atoi(char_pid);
  113.     ret_kill = kill(pid, SIGPIPE);
  114.     if (ret_kill == -1) {
  115.         printf("\nIllegal pid????\n");
  116.         unlink("/tmp/ttydev");
  117.         unlink("/dev/bbschatter");
  118.         exit(1);
  119.     }
  120.     sleep(2);
  121.     setraw();
  122.     while (1) {
  123.         ch = getc(stdin);
  124.         ch &= '\377';
  125.         if (ch == '\033')
  126.             break;
  127.         putchar(ch);
  128.         putc(ch, outdev);
  129.         if (ch == '\n') {
  130.             ch = '\r';
  131.             putchar(ch);
  132.             putc(ch, outdev);
  133.         }
  134.         if (ch == '\r') {
  135.             ch = '\n';
  136.             putchar(ch);
  137.             putc(ch, outdev);
  138.         }
  139.         if (ch == '\b') {
  140.             ch = ' ';
  141.             putchar(ch);
  142.             putc(ch, outdev);
  143.             ch = '\b';
  144.             putchar(ch);
  145.             putc(ch, outdev);
  146.         }
  147.     }
  148.     ch = '\r';
  149.     putchar(ch);
  150.     putc(ch, outdev);
  151.     ch = '\n';
  152.     for (i = 0; i <= 5; i++) {
  153.         putchar(ch);
  154.         putc(ch, outdev);
  155.     }
  156.     fclose(outdev);
  157.     restore();
  158.     unlink("/tmp/ttydev");
  159.     unlink("/dev/bbschatter");
  160.     ret_kill = kill(pid, SIGUSR1);
  161.     if (ret_kill == -1) {
  162.         printf("\nIllegal pid????\n");
  163.         exit(1);
  164.     }
  165. }
  166.