home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 5 / QRZ Ham Radio Callsign Database - Volume 5.iso / files / amiga / csrc720j.lzh / mbcmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-15  |  10.2 KB  |  441 lines

  1. /*
  2.  *  MBCMD.C - 9/20/92 - Command parser and dispatch.
  3.  */
  4.  
  5. #include "mb.h"
  6.  
  7. docmd()
  8. {
  9.   typedef struct
  10.   {
  11.     char  n1, n2;    /* The two command letters        */
  12.     byte  args;      /* Number of arguments required   */
  13.     word  mode;      /* Bitmask of allowed port modes  */
  14.     int   (*fp)();   /* Pointer to function return int */
  15.   } CMDDEF;
  16.  
  17.   register CMDDEF *cp;
  18.   register int status;
  19.  
  20. /*
  21.  *  The functions that do the commands.
  22.  */
  23.  
  24. #ifdef MCH_AMIGA
  25.    extern char fbb_direction;
  26.    extern int donefunc();
  27.    extern int flipdebug();
  28.    extern int kill_list();
  29.    extern int srpmsg();
  30.    extern int opchange();
  31. #endif
  32. #ifndef MCH_AMIGA
  33.   extern int find_call();
  34.   extern int w_lock();
  35. #endif
  36. #ifdef MCH_SYSOP
  37.   extern int all_fwd();
  38. #endif
  39.   extern int klmult();
  40.   extern int klmsg();
  41.   extern int lstmsg();
  42.   extern int rdmult();
  43.   extern int rdmsg();
  44.   extern int sndmlt();
  45.   extern int sndmsg();
  46. #ifndef MCH_SYSOP
  47.   extern int fwdcmd();
  48. #endif
  49.   extern int done();
  50.   extern int help();
  51.   extern int klmsgm();
  52.   extern int mkrem();
  53.   extern int mksys();
  54.   extern int makmlt();
  55.   extern int makmsg();
  56.   extern int dupmsg();
  57.   extern int filmsg();
  58.   extern int setunt();
  59.   extern int edmsg();
  60.   extern int edtfc();
  61.   extern int copfil();
  62.   extern int renfil();
  63.   extern int kilfil();
  64.   extern int uloadl();
  65.   extern int uloadr();
  66.   extern int dloads();
  67.   extern int dloadi();
  68.   extern int dloadl();
  69.   extern int dloadr();
  70.   extern int bye();
  71.   extern int lterm();
  72.   extern int setime();
  73.   extern int chguser();
  74.   extern int chgparam();
  75.   extern int utalk();
  76.   extern int rdmsgm();
  77.   extern int duser();
  78.   extern int dwuser();
  79.   extern int edport();
  80.   extern int eduser();
  81.   extern int edusera();
  82.   extern int puser();
  83.   extern int sfwd();
  84.   extern int newfwd();
  85.   extern int prthrd();
  86.   extern int prtdir();
  87.   extern int prtver();
  88.   extern int dosys();
  89.  
  90. /*
  91.  *  Command char 1, char 2, # args, modes allowed, function
  92.  */
  93.  
  94. static CMDDEF cmds[] =
  95. {
  96.  
  97.   '!', ' ', 2, local,          dosys,
  98.   '!', ' ', 3, local,          dosys,
  99.   '!', ' ', 4, local,          dosys,
  100.   '!', ' ', 5, local,          dosys,
  101. #ifndef MCH_SYSOP
  102.   '@', ' ', 1, remote,         mksys,
  103.   '@', ' ', 1, sysop,          mkrem,
  104. #endif
  105.   '?', ' ', 1, all,            help,
  106.   '?', ' ', 2, all,            help,
  107.  
  108. #ifndef MCH_AMIGA
  109.   'A', 'H', 1, ops,            w_lock,
  110. #endif
  111. #ifdef MCH_SYSOP
  112.   'A', '*', 1, ops,            all_fwd,
  113. #endif
  114.  
  115.   'B', ' ', 1, all,            bye,
  116.  
  117. #ifndef MCH_AMIGA
  118.   'C', ' ', 3, ops,            setime,
  119.   'C', 'B', 2, all,            find_call,
  120. #endif
  121.   'C', 'M', 3, ops,            dupmsg,
  122.   'C', 'M', 5, ops,            dupmsg,
  123.   'C', 'M', 7, ops,            dupmsg,
  124.  
  125. #ifndef MCH_AMIGA
  126.   'C', '*', 1, remote,         utncv,
  127.   'C', '*', 2, remote,         ctncv,
  128.   'C', '*', 4, remote,         ctncv,
  129. #endif
  130.  
  131. #ifdef MCH_AMIGA
  132.   'D', 'B', 1, ops,            flipdebug,
  133. #endif
  134.   'D', 'L', 1, ops,            duser,
  135.   'D', 'L', 2, ops,            duser,
  136.   'D', 'M', 1, ops,            duser,
  137.   'D', 'M', 2, ops,            duser,
  138.   'D', 'S', 1, ops,            duser,
  139.   'D', 'S', 2, ops,            duser,
  140.   'D', 'U', 1, ops,            duser,
  141.   'D', 'U', 2, ops,            duser,
  142.   'D', 'W', 1, ops,            dwuser,
  143.   'D', 'W', 2, ops,            dwuser,
  144.   'D', 'X', 1, ops,            duser,
  145.   'D', 'X', 2, ops,            duser,
  146.   'D', '*', 2, local,          dloadl,
  147.   'D', '*', 2, remote,         dloadr,
  148.   'D', '*', 2, sysop,          dloads,
  149.  
  150.   'E', ' ', 2, ops,            edmsg,
  151.   'E', 'P', 2, ops,            edport,
  152.   'E', 'S', 1, ops,            chgparam,
  153.   'E', 'T', 2, all,            edtfc,
  154.   'E', 'U', 1, ops,            edusera,
  155.   'E', 'U', 2, ops,            eduser,
  156.  
  157. #ifndef MCH_SYSOP
  158.   'F', '>', 1, remote,         fwdcmd,
  159. #endif
  160.   'F', '*', 3, ops,            filmsg,
  161.   'F', '*', 4, ops,            filmsg,
  162.  
  163.   'G', 'M', 1, ops,            setunt,
  164.   'G', 'R', 1, ops,            setunt,
  165.   'G', 'R', 2, ops,            setunt,
  166.   'G', 'U', 1, ops,            setunt,
  167.  
  168.   'H', ' ', 1, all,            help,
  169.   'H', ' ', 2, all,            help,
  170.  
  171.   'I', ' ', 1, all,            dloadi,
  172. #ifndef MCH_SYSOP
  173.   'J', '*', 1, all,            prthrd,
  174. #endif
  175.  
  176.   'K', ' ', 2, all,            klmsg,
  177.   'K', ' ', 3, ops,            klmult,
  178.   'K', ' ', 4, ops,            klmult,
  179.   'K', ' ', 5, ops,            klmult,
  180.   'K', 'A', 2, ops,            klmsg,
  181.   'K', 'A', 3, ops,            klmult,
  182.   'K', 'A', 4, ops,            klmult,
  183.   'K', 'A', 5, ops,            klmult,
  184.   'K', 'A', 6, ops,            klmult,
  185.   'K', 'F', 1, ops,            klmsgm,
  186.   'K', 'F', 2, ops,            klmsgm,
  187. #ifdef MCH_AMIGA
  188.   'K', 'L', 3, local,          kill_list,
  189. #endif
  190.   'K', 'M', 1, all,            klmsgm,
  191.   'K', 'O', 1, ops,            klmsgm,
  192.   'K', 'O', 2, ops,            klmsgm,
  193.   'K', 'T', 2, all,            klmsg,
  194.   'K', 'Y', 1, ops,            klmsgm,
  195.   'K', 'Y', 2, ops,            klmsgm,
  196.  
  197.   'L', '*', 1, all,            lstmsg,
  198.   'L', '*', 2, all,            lstmsg,
  199.   'L', '*', 3, all,            lstmsg,
  200.   'L', '*', 4, all,            lstmsg,
  201.  
  202.   'M', 'M', 3, ops,            makmlt,
  203.   'M', 'M', 4, ops,            makmlt,
  204.   'M', '*', 3, ops,            makmsg,
  205.   'M', '*', 4, ops,            makmsg,
  206.   'M', '*', 5, ops,            makmsg,
  207.   'M', '*', 6, ops,            makmsg,
  208.   'M', '*', 7, ops,            makmsg,
  209.   'M', '*', 8, ops,            makmsg,
  210.  
  211.   'N', ' ', 2, all,            chguser,
  212.   'N', ' ', 3, ops,            renfil,
  213.   'N', 'E', 1, all,            chguser,
  214.   'N', 'H', 2, all,            chguser,
  215.   'N', 'P', 1, all,            chguser,
  216.   'N', 'Q', 2, all,            chguser,
  217.   'N', 'Q', 3, all,            chguser,
  218.   'N', 'Z', 2, all,            chguser,
  219.  
  220. #ifdef MCH_AMIGA
  221.   'O', 'P', 2, local,          opchange,
  222. #endif
  223.  
  224.   'P', ' ', 2, all,            puser,
  225.  
  226. #ifndef MCH_AMIGA
  227.   'Q', ' ', 1, local,          done,
  228. #else
  229.   'Q', ' ', 1, local,          donefunc,
  230. #endif
  231.  
  232.   'R', ' ', 2, all,            rdmsg,
  233.   'R', ' ', 3, all,            rdmult,
  234.   'R', ' ', 4, all,            rdmult,
  235.   'R', ' ', 5, all,            rdmult,
  236.   'R', ' ', 6, all,            rdmult,
  237.   'R', 'H', 2, all,            rdmsg,
  238.   'R', 'H', 3, all,            rdmult,
  239.   'R', 'H', 4, all,            rdmult,
  240.   'R', 'H', 5, all,            rdmult,
  241.   'R', 'H', 6, all,            rdmult,
  242.   'R', 'M', 1, all,            rdmsgm,
  243.  
  244.   'S', 'M', 2, ops,            sndmlt,
  245.   'S', 'M', 3, ops,            sndmlt,
  246. #ifdef MCH_AMIGA
  247. /* Send Reply command
  248.   all it does it say the command has been removed until it works properly.
  249. */
  250.   'S', 'R', 1, all,            srpmsg,
  251. #endif
  252.   'S', '!', 2, all,            sndmlt,
  253.   'S', '*', 2, all,            sndmsg,
  254.   'S', '*', 3, all,            sndmsg,
  255.   'S', '*', 4, all,            sndmsg,
  256.   'S', '*', 5, all,            sndmsg,
  257.   'S', '*', 6, all,            sndmsg,
  258.   'S', '*', 7, all,            sndmsg,
  259. #ifdef MCH_AMIGA
  260.   'S', '*', 8, all,            sndmsg,
  261. #endif
  262.  
  263. #ifndef MCH_SYSOP
  264.   'T', ' ', 1, remote,         utalk,
  265.   'T', '*', 1, local,          lterm,
  266.   'T', '*', 2, local,          lterm,
  267.  
  268.   'U', '*', 2, ops,            uloadl,
  269.   'U', '*', 2, remote,         uloadr,
  270. #endif
  271.  
  272.   'V', ' ', 1, all,            prtver,
  273.   'V', ' ', 3, ops,            copfil,
  274.  
  275.   'W', '*', 1, all,            prtdir,
  276.   'W', '*', 2, all,            prtdir,
  277.  
  278. #ifndef MCH_SYSOP
  279.   'X', '*', 1, ops,            sfwd,
  280.   'X', '*', 2, ops,            sfwd,
  281.   'X', '*', 3, ops,            sfwd,
  282.  
  283.   'Y', 'F', 1, ops,            newfwd,
  284.   'Y', 'F', 2, ops,            newfwd,
  285. #endif
  286.  
  287.   'Z', '*', 2, ops,            kilfil,
  288.  
  289.   '\0', ' ', 0, 0, 0, 0
  290. };
  291.  
  292.   port->cmdcnt++;
  293.   pgst(NULL);
  294. #ifdef MCH_AMIGA
  295. /* If the line begins with ## then it is probably a disconnect message
  296.    from a distant ka-node or a retry out message. So might as well
  297.    say bye
  298. */
  299.    if((port->opt1 == '#') && (port->opt2 == '#')) {
  300.       bye();
  301.       return;
  302.    }
  303. #endif
  304.  
  305.   if (strlen(port->fld[0]) < 3)
  306.     for (cp = cmds; cp->n1; cp++)
  307.     if (port->mode & cp->mode)
  308.     if (port->opt1 is cp->n1)
  309.     if ((port->opt2 is cp->n2) or (cp->n2 is '*'))
  310. #ifndef MCH_AMIGA
  311.     if (port->flds is cp->args) { status = (*cp->fp)(); return; }
  312. #else
  313. /* If the last message was not a read command then clear the message
  314.    type so that if the user then does a 'SR' command, it will fail
  315. */
  316.    if(port->flds is cp->args) {
  317.       status = (*cp->fp)();
  318.       if(port->opt1 != 'R')last_msg.type = 0;
  319.       return;
  320.     }
  321. #endif
  322.  
  323. #ifndef MCH_AMIGA
  324.   if ((port->opt1 is '[') and (port->cmdcnt is 1)) { isbid(); return;}
  325. #else
  326.    if((port->opt1 is '[') and (port->cmdcnt is 1)) {
  327.       isbid();
  328.       if(s_mart & fbbok) {
  329.          port->flags setbit p_dofwd;
  330.          port->mode = remote;
  331.          fbb_direction = 1;
  332.          fwdcmd();
  333.          port->flags clrbit p_dofwd;
  334.          bye();
  335.       }
  336.       return;
  337.   }
  338. #endif
  339.   port->msg = mwhat;
  340.   port->errors++;
  341. }
  342.  
  343. /*
  344.  *  User wants to log out.
  345.  *  Set the flag so they will be logged out.
  346.  */
  347.  
  348. bye()
  349. {
  350.   pt_flag = 0;
  351.   port->mode = logout;
  352. }
  353.  
  354. /*
  355.  *  User done being remote sysop.
  356.  *  Make them normal user again.
  357.  */
  358.  
  359. mkrem()
  360. {
  361. #ifndef MCH_SYSOP
  362.   port->flags clrbit p_clrsys;
  363.   port->mode = remote;
  364.   if (!port->tmode)
  365.   {
  366.      cmdtnc();
  367.      onetnc("cr on\n");
  368.      onetnc("cp of\n");
  369.      onetnc("se $0d\n");
  370.      convtnc();
  371.   }
  372. #endif
  373. }
  374.  
  375. /*
  376.  *  User wants to be remote sysop.
  377.  *  Let them, if they are allowed to.
  378.  */
  379.  
  380. mksys()
  381. {
  382. #ifndef MCH_SYSOP
  383.   if (!(port->priv & p_sysop) or !(port->user->options & u_sysop)or!(pass()))
  384.     { port->msg = mwhat; return; }
  385.  
  386.   port->flags setbit p_clrsys;
  387.   port->mode = sysop;
  388.   if (!port->tmode)
  389.   {
  390.      cmdtnc();
  391.      onetnc("cr of\n");
  392.      onetnc("cp on\n");
  393.      onetnc("se $7f\n");
  394.      convtnc();
  395.   }
  396. #endif
  397. }
  398.  
  399. #ifdef MCH_AMIGA
  400. #endif
  401. #ifndef NEWPASS
  402. pass()
  403. {
  404.   int count,psn,lpsn;
  405.   char temp[4], pword[5];
  406.   for (count = 0, lpsn = 0; count < 4; count++)
  407.     {
  408.       while ((psn=(rand()/512))== lpsn);
  409.       sprintf (temp, "%3u", psn+1);
  410.       outstr(temp);
  411.       pword[count] = *(keylst+psn);
  412.       lpsn = psn;
  413.     }
  414.     outstr("\n");
  415.     getdat();
  416.     if (matchn(port->line, pword, 4)) return true;
  417.     return false;
  418.  }
  419. #endif
  420.  
  421. /*
  422.  *  Lock up the current window for no more than 180 seconds.
  423.  */
  424.  
  425. #ifndef MCH_AMIGA
  426. w_lock()
  427. {
  428.   long l;
  429.   if (!(s_flag & s_dv)) return;
  430.   outstr("\nWindow locked");
  431.   while (true)
  432.   {
  433.     getcomd(); if (port->opt2 isnt 'H') break;
  434.     switchw();
  435.   }
  436.   outstr("-unLOCKED\n");
  437.   return;
  438. }
  439. #endif
  440.  
  441.