home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / telecomm / bbs / wwbbs26.lha / WWBBSChat / WWBBSChat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-16  |  4.0 KB  |  168 lines

  1. #include <proto/dos.h>
  2. #include <proto/exec.h>
  3. #include <exec/memory.h>
  4. #include <exec/types.h>
  5. #include <exec/execbase.h>
  6. #include <exec/exec.h>
  7. #include <dos/dostags.h>
  8. #include <dos/stdio.h>
  9. #include <dos/dos.h>
  10. #include <dos/dosextens.h>
  11. #include <dos/var.h>
  12. #include <string.h>
  13. #include <ctype.h>
  14. #include <stdarg.h>
  15. #include <stdio.h>
  16.  
  17. char user[80];
  18. char node[80];
  19. char nomeraw[200];
  20.  
  21. #define WWBBSCHATPARSER "STARTMSG,ABORTMSG,ENDMSG,WINDOW"
  22. enum typeconfig {PSTARTMSG=0,PABORTMSG,PENDMSG,PWINDOW,PCFGMAX};
  23.  
  24. struct DosLibrary *DOSBase=NULL;
  25.  
  26. __inline static LONG MyFPrintf(BPTR fh, STRPTR format, ... )
  27. {
  28.     va_list argptr;
  29.  
  30.     va_start(argptr,format);
  31.     return VFPrintf(fh,format,argptr);
  32. }
  33.  
  34. LONG __stdargs __saveds Start(void)
  35. {
  36.     struct Process *p;
  37.     struct RDArgs *RDA;
  38.     LONG error=RETURN_OK;
  39.     LONG argd[PCFGMAX];
  40.     BPTR SRaw,FIn,FOut;
  41.     LONG c,tm;
  42.     short col;
  43.     char *t;
  44.  
  45.     if((p=(struct Process *)((*((struct ExecBase **) 4L))->ThisTask))->pr_CLI!=NULL){
  46.         if((*((struct ExecBase **) 4L))->LibNode.lib_Version>=36 &&
  47.             (DOSBase=(struct DosLibrary *)OpenLibrary(DOSNAME,0))!=NULL){
  48.             memset(argd,0,sizeof(LONG)*PCFGMAX);
  49.             if((RDA=ReadArgs(WWBBSCHATPARSER,&(argd[0]),NULL))!=NULL){
  50.                 GetVar("NODE",node,79,GVF_LOCAL_ONLY|GVF_BINARY_VAR);
  51.                 GetVar("REALNAME",user,79,GVF_LOCAL_ONLY|GVF_BINARY_VAR);
  52.                 t=nomeraw;
  53.                 if(argd[PWINDOW]==NULL)
  54.                     strcpy(t,"RAW:///128/Chat ");
  55.                 else
  56.                     strcpy(t,(char *)argd[PWINDOW]);
  57.                 while(*t!='\0')t++;
  58.                 strcpy(t,user);
  59.                 while(*t!='\0')t++;
  60.                 *t++=' ';
  61.                 strcpy(t,node);
  62.                 if((SRaw=Open(nomeraw,MODE_READWRITE))!=NULL){
  63.                     MyFPrintf(SRaw,"Chat Request from %s node %s\n",user,node);
  64.                     FOut=Output();
  65.                     FIn=Input();
  66.                     SetMode(FIn,1);
  67.                     FPuts(FOut,"\r\n~sWWBBSChat v1.0\r\nby Giuseppe Vicari\r\n\r\n");
  68.                     if(argd[PSTARTMSG]==NULL)
  69.                         FPuts(FOut,"Please wait, I am calling Sysop ");
  70.                     else
  71.                         FPuts(FOut,(char *)argd[PSTARTMSG]);
  72.                     for(c=10;c!=0;c--){
  73.                         FPuts(SRaw,".\a");
  74.                         FPuts(FOut,".\a");
  75.                         Flush(FOut);Flush(SRaw);
  76.                         if(WaitForChar(SRaw,2000000L) && FGetC(SRaw)=='\r')
  77.                             break;
  78.                         if(WaitForChar(FIn,1000L) && FGetC(FIn)==3){
  79.                             c=0;
  80.                             break;
  81.                         }
  82.                     }
  83.                     if(c!=0){
  84.                         FPuts(SRaw,"\n\n");
  85.                         FPuts(FOut,"\r\n\r\n~pChat Sysop\r\n\r\n");
  86.                         col=-1;
  87.                         tm=1L;
  88.                         for(;;){
  89.                             if(WaitForChar(SRaw,tm)){
  90.                                 c=FGetC(SRaw);
  91.                                 if(c=='\033' || c==EOF)
  92.                                     break;
  93.                                 if(c=='\r'){
  94.                                     FPuts(FOut,"\r\n");
  95.                                     FPuts(SRaw,"\n");
  96.                                 } else if(c=='\b'){
  97.                                     FPuts(FOut,"\b \b");
  98.                                     FPuts(SRaw,"\b \b");
  99.                                     Flush(FOut);Flush(SRaw);
  100.                                 } else if(isprint(c)){
  101.                                     if(col!=1){
  102.                                         FPuts(FOut,"~o");
  103.                                         FPuts(SRaw,"\033[31m");
  104.                                     }
  105.                                     FPutC(FOut,c);
  106.                                     FPutC(SRaw,c);
  107.                                     Flush(FOut);Flush(SRaw);
  108.                                     col=1;
  109.                                 }
  110.                                 tm=1000L;
  111.                             } else
  112.                                 tm=100000L;
  113.                             if(WaitForChar(FIn,tm)){
  114.                                 c=FGetC(FIn);
  115.                                 if(c=='\033' || c==EOF)
  116.                                     break;
  117.                                 if(c=='\r'){
  118.                                     FPuts(FOut,"\r\n");
  119.                                     FPuts(SRaw,"\n");
  120.                                 } else if(c=='\b'){
  121.                                     FPuts(FOut,"\b \b");
  122.                                     FPuts(SRaw,"\b \b");
  123.                                     Flush(FOut);Flush(SRaw);
  124.                                 } else if(isprint(c)){
  125.                                     if(col!=0){
  126.                                         FPuts(FOut,"~i");
  127.                                         FPuts(SRaw,"\033[32m");
  128.                                     }
  129.                                     FPutC(FOut,c);
  130.                                     FPutC(SRaw,c);
  131.                                     Flush(FOut);Flush(SRaw);
  132.                                     col=0;
  133.                                 }
  134.                                 tm=1000L;
  135.                             } else
  136.                                 tm=100000L;
  137.                         }
  138.                         if(argd[PENDMSG]==NULL)
  139.                             FPuts(FOut,"\r\n\r\n~pEnd Chat Sysop\r\n");
  140.                         else
  141.                             FPuts(FOut,(char *)argd[PENDMSG]);
  142.                     } else {
  143.                         FPuts(SRaw,"\n\n");
  144.                         if(argd[PABORTMSG]==NULL)
  145.                             FPuts(FOut,"\r\n\r\nAbort\r\n");
  146.                         else
  147.                             FPuts(FOut,(char *)argd[PABORTMSG]);
  148.                     }
  149.                     Flush(FOut);
  150.                     SetMode(FIn,0);
  151.                     Close(SRaw);
  152.                 }
  153.                 FreeArgs(RDA);
  154.             } else {
  155.                 PrintFault(IoErr(),NULL);
  156.                 error=RETURN_ERROR;
  157.             }
  158.             CloseLibrary((struct Library *)DOSBase);
  159.         }
  160.     } else {
  161.         WaitPort(&(p->pr_MsgPort));
  162.         Forbid();
  163.         ReplyMsg(GetMsg(&(p->pr_MsgPort)));
  164.         error=RETURN_FAIL;
  165.     }
  166.     return error;
  167. }
  168.