home *** CD-ROM | disk | FTP | other *** search
/ World of Ham Radio 1994 January / AMSOFT_1994.iso / packet / pbbs / cbbs / prog / mb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-31  |  7.8 KB  |  412 lines

  1. /*
  2.  *  MB.C - 7/21/89 - MailBox mainline code.
  3.  */
  4.  
  5. /*
  6.  *  Copyright (C) 1987, 1988
  7.  *  On Modules by H. N. Oredson
  8.  *  Copyright (C) 1988, 1989
  9.  *  By the CBBS Group.
  10.  *
  11.  *  This code was originality created and distributed
  12.  *  to the packet radio community by W0RLI and VE3GYQ.
  13.  *  It is being further being developed by the CBBS Group.
  14.  *  It may be freely copied for non-commercial use,
  15.  *  as long as this notice is retained.
  16.  *
  17.  *  This notice and Copyright apply to all modules
  18.  *  referenced by this module.
  19.  *
  20.  */
  21.  
  22. #include "mb.h"
  23.  
  24. char  *ver = "\nC-BBS V6.45, 14 July 1989\n\n";
  25. char  *vers = "[CBBS-6.4-H$]\n";
  26.  
  27. char  *nullstr = "";
  28.  
  29. PORTS *porthd = NULL;
  30. PORTS *cport  = NULL;
  31. PORTS *port;
  32.  
  33. int   scrmax, dirmax, log_mon;
  34. TMP   *tmp;
  35. MLM   *motd;
  36. char  *helpfile, *infofile;
  37. char  *bbmenu, *symenu, *rmenus, *mumsg;
  38. char  *reqmsg, *qth, *keylst;
  39. char  *mcant, *mdone, *mfind, *mexst, *mnfile, *mnmsg;
  40. char  *mprot, *mtime, *mwhat, *mnport, *mndir, *minuse;
  41. char  achar, rchar, tchar, wchar;
  42. word  s_param;
  43. byte  s_flag, unt_hr, p_window, c_flag, b_flag;
  44. char  scmd[24];
  45.  
  46. main(argc, argv)
  47. int argc;
  48. char *argv[];
  49. {
  50.   if (argc > 1) init(argv[1]); else init("config.mb");
  51.  
  52.   while (true)
  53.   {
  54.     bidok = false;
  55.     hidok = false;
  56.     do_idle();
  57.     setbusy();
  58.     login();
  59.     if (!(port->mode & exclude)) do_cmds();
  60.     logo();
  61.   }
  62. }
  63.  
  64. do_cmds()
  65. {
  66.   register PORTS *p;
  67.   register char  *i, *o;
  68.  
  69.   p = port;
  70.  
  71.   while(true)
  72.   {
  73.     prompt();
  74.     getcmd();
  75.     if (p->mode & gone) return;
  76.  
  77. /*
  78.  *  Console broke in on a user?
  79.  */
  80.  
  81.     if (p->flags & p_opreq)
  82.     {
  83.       p->flags clrbit p_opreq;
  84.       prtx(talkm1);
  85.       if (p->tmode)
  86.       {
  87.          cmdtnc();
  88.          convtnc();
  89.       }
  90.       ioport(cport);
  91.       prtx(mumsg);
  92.       cport->fl = NULL;
  93.       term(p);
  94.       ioport(p);
  95.       tncstate();
  96.       if (p->tmode) trantnc(); else convtnc();
  97.       if (p->mode & gone) return;
  98.     }
  99.  
  100. /*
  101.  *  Check for LINK.
  102.  *  Require "LINKED to" to be first command.
  103.  */
  104.  
  105.     else if (islink(p->line))
  106.     {
  107.       if (p->cmdcnt) p->msg = mwhat; else
  108.       {
  109.         strcpy(p->line, p->line + 14);
  110.         logina(true);
  111.         remnl(p->line);
  112.         log('C', 'L', ' ', p->line);
  113.         if (p->mode & exclude) return;
  114.       }
  115.     }
  116.  
  117. /*
  118.  *  Must be a command.
  119.  */
  120.  
  121.     else
  122.     {
  123.       docmd();
  124.       if (p->errors > p->errmax) p->mode = forced;
  125.       if (p->mode & (gone | idle | logout)) return;
  126.     }
  127.   }
  128. }
  129.  
  130. /*
  131.  *  Q command: exit to DOS.
  132.  */
  133.  
  134. done()
  135. {
  136.   byte pflg;
  137.  
  138.   if (sure()) return;
  139.   upduser(cport->user);
  140.   log('X', 'Q', ' ', nullstr);
  141.   clslog();
  142.   clsusr();
  143.   clsmsg();
  144.   clsmon();
  145.   iooff();
  146.   clrbusy();
  147.   pflg = getp_flag();
  148.   putp_flag(pflg clrbit p_window);
  149.   exit(0);
  150. }
  151.  
  152. /*
  153.  *  Give the user a prompt.
  154.  */
  155.  
  156. prompt()
  157. {
  158.   register PORTS *p, *tp;
  159.  
  160.   p = port;
  161.   if (p->msg isnt NULL) prtx(p->msg);
  162.   p->msg = NULL;
  163.  
  164. /*
  165.  *  Tell sysop who this is.
  166.  */
  167.  
  168.   if (p isnt cport) { ioport(cport); prtx(mumsg); ioport(p); }
  169.  
  170. /*
  171.  *  Show any connect request seen on the user port.
  172.  */
  173.  
  174.   if (p->flags & p_req) prtx(reqmsg);
  175.   p->flags clrbit p_req;
  176.  
  177. /*
  178.  *  Bleed off any connect requests on other ports.
  179.  */
  180.  
  181.   for (tp = porthd; tp isnt NULL; tp = tp->next) if (tp->mode & idle)
  182.   if ((tp->dev is p_tnc) and (tp isnt p))
  183.   {
  184.     ioport(tp);
  185.     while (instat()) getdat();
  186.   }
  187.   ioport(p);
  188.  
  189. /*
  190.  *  Display the prompt.
  191.  */
  192.  
  193.   curtim();
  194.   switch (p->mode)
  195.   {
  196.     case local :
  197.     case sysop :
  198.       prtx(symenu);
  199.       break;
  200.  
  201.     case remote:
  202.       if (!(p->user->options & u_bbs))
  203.       {
  204.         if (s_param & s_p_name) if (!(p->user->state & u_name)) prtx(um[4]);
  205.         if (s_param & s_p_home) if (!(p->user->state & u_home)) prtx(um[5]);
  206.         if (s_param & s_p_zip)  if (!(p->user->state & u_zip))  prtx(um[6]);
  207.       }
  208.  
  209.       if (p->user->options & (u_bbs | u_expert)) prtx(bbmenu); else prtx(rmenus);
  210.       break;
  211.   }
  212. }
  213.  
  214. /*
  215.  *  Log the user off.
  216.  *  Do any defered remote sysop command.
  217.  */
  218.  
  219. logo()
  220. {
  221.   register PORTS *p;
  222.   register PORTS *tp;
  223.   register char t;
  224.  
  225.   p = port;
  226.  
  227.   switch(p->mode)
  228.   {
  229.     case idle   : t = 'A'; break; /* Init bbs logout */
  230.     case logout : t = 'B'; break;
  231.     case discon : t = 'D'; break;
  232.     case exclude: t = 'E'; break;
  233.     case forced : t = 'F'; distnc(); break;
  234.     case timeout: t = 'T'; prtx(mtime); break;
  235.     default     : t = '?'; break;
  236.   }
  237.  
  238.   log('X', t, ' ', nullstr);
  239.  
  240. /*
  241.  *  If any port was used in terminal mode by the console,
  242.  *  disconnect it.
  243.  */
  244.  
  245.   if (p->dev is p_console)
  246.   for (tp = porthd; tp isnt NULL; tp = tp->next)
  247.   if (tp->flags & p_term)
  248.   {
  249.     ioport(tp);
  250.     tp->mode = remote;
  251.     distnc();
  252.     tp->mode = idle;
  253.     tp->flags clrbit p_term;
  254.   }
  255.  
  256.   ioport(p);
  257.  
  258. /*
  259.  *  Change TNC back to "standard" if was in "sysop" mode.
  260.  *  May have just THOUGHT we discon, REALLY disconnect.
  261.  */
  262.  
  263.   if (p->dev is p_tnc)
  264.   {
  265.     if (p->flags & p_clrsys) mkrem();
  266.     p->mode = remote;
  267.     distnc();
  268.   }
  269.   if (p->dev is p_serial) p->flags clrbit p_trans;
  270.   p->mode = idle;
  271.  
  272.   upduser(p->user);
  273.  
  274. /*
  275.  *  If there was a "defered remote sysop command" do it.
  276.  */
  277.  
  278.   ioport(cport);
  279.   if (s_param & s_cmd)
  280.   {
  281.     s_param clrbit s_cmd;
  282.     strcpy(cport->line, scmd);
  283.     parse();
  284.     wait(10);               /* Give sysop chance to get HIS system online */
  285.     cport->mode = local;    /* Do command as if console did it */
  286.     docmd();
  287.     cport->mode = idle;
  288.   }
  289.  
  290.   clnlog();
  291.   clsusr();
  292.   setfwd();
  293.   clsmsg();
  294. }
  295.  
  296. /*
  297.  *  MailBox is idle.
  298.  *  See if there is anything to do, and do it.
  299.  *  If nothing to do, wait for connect.
  300.  */
  301.  
  302. do_idle()
  303. {
  304.   register PORTS *p;
  305.   register short curmin, lastmin, curmon;
  306.  
  307.   for (p = porthd; p isnt NULL; p = p->next) p->ec = p->ecmon;
  308.  
  309.   getc_flag();
  310.   if (c_flag & p_window) acmd();
  311.  
  312.   allon();  /* Turn on monitoring and connects */
  313.   clrbusy();
  314.   curtim();
  315.   curmin = 10 * (l_time[2] - '0') + (l_time[3] - '0');
  316.   while(true)
  317.   {
  318.  
  319. /*
  320.  *  Check the port command flag to see if another window has
  321.  *  issued a command request. If so setup and do the command.
  322.  */
  323.  
  324.     getc_flag();
  325.     if (c_flag & p_window)
  326.     {
  327.       setbusy();
  328.       alloff();
  329.       acmd();
  330.       allon();
  331.       clrbusy();
  332.     }
  333.  
  334.     lastmin = curmin;
  335.     curtim();
  336.     curmin = 10 * (l_time[2] - '0') + (l_time[3] - '0');
  337.     curmon = 10 * (l_date[2] - '0') + (l_date[3] - '0');
  338.  
  339. /*
  340.  *  Once each minute:
  341.  *  Forward now, if it is time on any port.
  342.  */
  343.  
  344.     if (curmin isnt lastmin) afwd(curmin);
  345.     if (s_param & s_log_on) if (curmon isnt log_mon) chglog();
  346.  
  347. /*
  348.  *  Look for a login.
  349.  */
  350.  
  351.     for (p = porthd; p isnt NULL; p = p->next)
  352.     {
  353.       ioport(p);
  354.       if (instat()) switch(p->dev)
  355.       {
  356.         case p_serial:
  357.           p->flags clrbit p_give;
  358.           getdat();
  359.           p->flags setbit p_give;
  360.           if (iscon(p->line)) return;
  361.           break;
  362.  
  363.         case p_tnc:
  364.           p->flags clrbit p_give;
  365.           getdat();
  366.           p->flags setbit p_give;
  367.           if (iscon(p->line)) return;
  368.           monitor();
  369.           break;
  370.  
  371.         case p_console:
  372.           if (inchar() is wchar) return;
  373.           break;
  374.       }
  375.       p->flags setbit p_give;
  376.     }
  377.   }
  378. }
  379.  
  380. /*
  381.  *  Do commands retrieved from the bios.
  382.  */
  383.  
  384. acmd()
  385. {
  386.    char need_msg = false;
  387.  
  388.    port->mode = local;
  389.    getcomd();
  390.    if (s_flag & s_dv) begin_lock();
  391.    if (port->opt1 is 'X')
  392.    {
  393.      readmsg();
  394.      readusr();
  395.      need_msg = true;
  396.    }
  397.    getc_flag();
  398.    putc_flag( c_flag clrbit p_window);
  399.    if (s_flag & s_dv) end_lock();
  400.    sprintf(port->line, "%c%c", port->opt1, port->opt2);
  401.    parse();
  402.    docmd();
  403.    if (need_msg)
  404.    {
  405.      clnlog();
  406.      setfwd();
  407.      clsmsg();
  408.      clsusr();
  409.    }
  410.    port->mode = idle;
  411. }
  412.