home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 024 / psi110g.zip / CHAT.C < prev    next >
C/C++ Source or Header  |  1994-04-17  |  3KB  |  102 lines

  1. /* Peek into a user's actions on the bbs.
  2.  * Early version that only provides chat capabilities.
  3.  * (C) 1993, Johan. K. Reinalda, WG7J
  4.  */
  5. #include "global.h"
  6. #ifdef LOOKSESSION
  7. #include "socket.h"
  8. #include "session.h"
  9. #include "mailbox.h"
  10.   
  11. void look_input __ARGS((int unused,void *p1,void *p2));
  12.   
  13. int dolook(int argc, char *argv[],void *p) {
  14.     struct session *sp;
  15.     int s,index;
  16.     char c,*cp;
  17.     struct mbx *m;
  18.   
  19.     /* Check if this comes from console - WG7J*/
  20.     if(Curproc->input != Command->input)
  21.         return 0;
  22.   
  23.     if((sp = newsession(argv[1],LOOK,1)) == NULLSESSION)
  24.         return 1;
  25.   
  26.     /* Find the user ! */
  27.     for(m=Mbox;m;m=m->next)
  28.         if(!stricmp(m->name,argv[1]))
  29.             break;
  30.     if(!m) {
  31.         tprintf("%s not a mailbox user!\n",argv[1]);
  32.         keywait(NULLCHAR,1);
  33.         freesession(sp);
  34.         return 0;
  35.     }
  36.   
  37.     index = sp - Sessions;
  38.     sp->s = sp->input;      /* so that doclose() will work ! */
  39.   
  40.     /* Now we need to redirect the network input
  41.      * from the user's socket to our socket...
  42.      */
  43.     sp->proc1 = newproc("look_in",1024,look_input,0,
  44.     (void *)sp,(void *)m,0);
  45.   
  46.     /* Tell the user we are talking to them... */
  47.     usputs(m->user,"\007*** SYSOP Initiated CHAT...\n");
  48.     usflush(m->user);
  49.   
  50.     /* Send whatever's typed on the terminal */
  51.     while(((c = recvchar(sp->input)) != -1) && (usputc(m->user,(char)c) != -1))
  52.         if(c == '\n')
  53.             usflush(m->user);
  54.   
  55.     /* A 'close' command was given, or user disconnected.
  56.      * Notify the user, kill the receiver input task and wait for a response
  57.      * from the user before freeing the session.
  58.      */
  59.     cp = sockerr(sp->input);
  60.     tprintf("%s session %u", Sestypes[sp->type],index);
  61.     tprintf(" closed: %s\n", cp != NULLCHAR ? cp : "EOF");
  62.     if(sp->proc1 != NULLPROC) {
  63.         /* kill the receive process */
  64.         killproc(sp->proc1);
  65.         sp->proc1 = NULLPROC;
  66.         /* restart the mailbox process */
  67.         usputs(m->user,"*** Back in mailbox\n");
  68.         usflush(m->user);
  69.         resume(m->proc);
  70.     }
  71.     keywait(NULLCHAR,1);
  72.     freesession(sp);
  73.     return 0;
  74. }
  75.   
  76. /* User telnet output task, started by user telnet command */
  77. void
  78. look_input(unused,p1,p2)
  79. int unused;
  80. void *p1;
  81. void *p2;
  82. {
  83.     struct session *sp;
  84.     struct mbx *m;
  85.     int input,output,c;
  86.   
  87.     sp = (struct session *)p1;
  88.     m = (struct mbx *)p2;
  89.   
  90.     /* Process input on the users socket connection */
  91.     suspend(m->proc);
  92.     while((c = recvchar(m->user)) != -1)
  93.         tputc((char)c);
  94.     resume(m->proc);
  95.   
  96.     /* Make sure our parent doesn't try to kill us after we exit */
  97.     sp->proc1 = NULLPROC;
  98. }
  99.   
  100. #endif /* LOOKSESSION */
  101.   
  102.