home *** CD-ROM | disk | FTP | other *** search
/ Amiga Times / AmigaTimes.iso / programme / trionbbs110 / Trion / docs / DemoDoor / DemoDoor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-06  |  4.7 KB  |  195 lines

  1.  
  2. /*  Trion DemoDoor with additional CliDoor Support code linked in   */
  3.  
  4. /*  Start this door with the tilde code ~50 after the door name !!! */
  5.  
  6. /*  27-11-'95 By Paul Spijkerman                                    */
  7.  
  8.  
  9. #include "adoor.h"        /* link code with  adoor.c !! */
  10.  
  11.  
  12.  
  13. void Chat           (struct DoorIO *pd, struct ADS_Data *pp);
  14. void TestDownload   (struct DoorIO *pd, struct ADS_Data *pp);
  15. void LogDemo        (struct DoorIO *pd, struct ADS_Data *pp);
  16.  
  17.  
  18. int main(int argc, char **argv)    /* was void */
  19. {
  20.    struct ADS_Data      port , *pport;
  21.    struct DoorIO        io   , *pio;
  22.    int    node = 0, ret = 0, ready = 0, time, sysop;
  23.    char   name[37];
  24.    UBYTE  c;
  25.  
  26.    pport = &port;
  27.    pio   = &io;
  28.  
  29.    onbreak(brk);
  30.  
  31.    SetOpIO(pio);
  32.  
  33.  
  34.    if (argc != 2){
  35.  
  36.       nprintf(pio, "Trion DemoDoor V 1.10 Copyright 1996-97 By Paul Spijkerman\r\n\r\n");
  37.       nprintf(pio, "Use:    CliDoor  \"doors:demodoor/demodoor ~50\"\r\n");
  38.       Delay(120L);
  39.  
  40.    }else{
  41.  
  42.       node = atoi( argv[1] );
  43.  
  44.       if (SetopPort( pport , node, 0 )){
  45.  
  46.          GetUserStringField(pport, UDSF_NAME , name );
  47.  
  48.          while(!ready && Carrier(pio) ){
  49.  
  50.             col(pio, HYELLOW , BLUE);
  51.             nprintf(pio, "Trion Additional (cli)Door Support Demo door\r\n\r\n");
  52.  
  53.             col(pio, HYELLOW , BLACK);
  54.             time  = GetTimeOnline(pport);
  55.             sysop = CheckSysopAvailable(pport);
  56.  
  57.             if (sysop){
  58.                nprintf(pio, "Sysop is available for a chat.\r\n");
  59.             }else{
  60.                nprintf(pio, "Sysop is not around.\r\n");
  61.             }
  62.             nprintf(pio, "Hello %s , you still have %d minutes left.\r\n\r\n", name, time);
  63.  
  64.             nprintf(pio, "Press a key ..\r\n\r\n");
  65.  
  66.             nprintf(pio, "S.  Play Sample. \r\n");
  67.             nprintf(pio, "P.  Page Sysop. \r\n");
  68.             nprintf(pio, "D.  Download startup-sequence. \r\n");
  69.             nprintf(pio, "C.  Simple chat in 2 colors. \r\n");
  70.             nprintf(pio, "L.  Write a line of text to the log. \r\n");
  71.             nprintf(pio, "+.  Increase time online. \r\n");
  72.             nprintf(pio, "-.  Decrease time online. \r\n");
  73.             nprintf(pio, "X.  Drop Carrier\r\n");
  74.             nprintf(pio, "Q.  Quit\r\n\r\n");
  75.  
  76.             c = GetCharacter(pio);
  77.  
  78.             if (c == 's' || c == 'S')   PlaySample( pport , "uhoh.8sv" );
  79.             if (c == 'p' || c == 'P'){
  80.                PageSysop(pport);
  81.                PlaySampleNum( pport , "startrek-alert", 3 );
  82.             }
  83.             if (c == 'c' || c == 'C')   Chat( pio  , pport );
  84.             if (c == 'd' || c == 'D')   TestDownload(pio , pport);
  85.             if (c == 'l' || c == 'L')   LogDemo(pio , pport);
  86.             if (c == '+')               IncreaseTimeOnline(pport , 1);
  87.             if (c == '-')               DecreaseTimeOnline(pport , 1);
  88.             if (c == 'x' || c == 'X'){
  89.                DropCarrier(pport);
  90.                ready = 1;
  91.             }
  92.  
  93.             if (c == 'q' || c == 'Q')   ready = 1;
  94.  
  95.             cls(pio);
  96.          }
  97.          nprintf(pio, "Bye !\r\n");
  98.  
  99.  
  100.       }
  101.       RemovePort( pport );
  102.    }
  103.  
  104.    RemoveIO( pio );
  105.  
  106.    return ret;
  107. }
  108.  
  109.  
  110.  
  111. void TestDownload(struct DoorIO *pd, struct ADS_Data *pp)
  112. {
  113.    nprintf(pd, "Let's mark the startup-sequence\r\n");
  114.  
  115.    /* mark as much files as needed before calling download */
  116.  
  117.    MarkFile(pp , "s:startup-sequence" );
  118.  
  119.    Delay(100);
  120.  
  121.    nprintf(pd, "Here it comes\r\n");
  122.    Download( pp );
  123.  
  124.    Delay(100);
  125. }
  126.  
  127.  
  128.  
  129.  
  130. void Chat(struct DoorIO *pd, struct ADS_Data *pp)
  131. {
  132.    UBYTE key , ID, ready = 0, prevID = 0;
  133.  
  134.    cls ( pd );
  135.    col ( pd, HGREEN , BLUE );
  136.  
  137.    nprintf(pd, "Type 'q' to Quit.\r\n");
  138.  
  139.    col ( pd, HGREEN , BLACK );
  140.  
  141.  
  142.    SplitChatMode(pp , 1);
  143.  
  144.    while ( Carrier(pd) && !ready){
  145.  
  146.       key = GetCharacter(pd);
  147.  
  148.       ID  = (key & 128) >> 7;       /* Extract ID bit   (0-1)  */
  149.       key = (key & 127);            /* Make 7 bit ASCII        */
  150.  
  151.       if (prevID != ID){
  152.          prevID = ID;
  153.          if (ID == 0)    col ( pd, HGREEN  , BLACK );
  154.          if (ID == 1)    col ( pd, HYELLOW , BLACK );
  155.       }
  156.  
  157.       if (key == 'q') ready = 1;
  158.  
  159.       if (key == '\r'){
  160.          nprintf(pd, "\r\n");
  161.       }else{
  162.          nprintf(pd, "%c" , key);
  163.       }
  164.  
  165.       /* printf("%c", key);  doesn't work because of missing \r\n  */
  166.       /*                     best to use the nprintf();            */
  167.  
  168.       /* printf("char (%c) value (%d) ID (%d)\r\n" , key , key , ID); */
  169.    }
  170.  
  171.    SplitChatMode(pp , 0);
  172. }
  173.  
  174.  
  175.  
  176.  
  177. void LogDemo(struct DoorIO *pd, struct ADS_Data *pp)
  178. {
  179.    char string[41], buf[80];
  180.  
  181.    col ( pd, HGREEN , BLUE );
  182.    nprintf(pd, "Let's type a line to the log.\r\n\r\n");
  183.  
  184.    col ( pd, HYELLOW , BLACK );
  185.    nprintf(pd, "----------------------------------------\r\n");
  186.  
  187.    if (GetString(pd, string, 41)){
  188.       sprintf(buf , "DemoDoor: %s" , string);
  189.       PrintToLog(pp, buf);
  190.    }
  191.  
  192. }
  193.  
  194.  
  195.