home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / c / crcbbs.arc / CRCPC0D.C < prev    next >
Text File  |  1985-10-22  |  11KB  |  309 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include "crcpchdr.h"
  4.  
  5. int initialize(argc,argv)
  6. int argc;
  7. char *argv[];
  8. {
  9. char c, d;
  10. char *options, *getenv();
  11. int gn_fl;
  12.             /* Initialize defaults which options can change */
  13. if ((options=getenv(HPATH))==NULL) stccpy(hpath,HELP_PATH,sizeof(hpath));
  14. else stccpy(hpath,options,sizeof(hpath));
  15. if ((options=getenv(IPATH))==NULL) stccpy(ipath,INFO_PATH,sizeof(ipath));
  16. else stccpy(ipath,options,sizeof(ipath));
  17. if ((options=getenv(FPATH))==NULL) stccpy(fpath,FORT_PATH,sizeof(fpath));
  18. else stccpy(fpath,options,sizeof(fpath));
  19. if ((options=getenv(EDIT1))==NULL) stccpy(sys_editor,SYS_EDITOR,sizeof(sys_editor));
  20. else stccpy(sys_editor,options,sizeof(sys_editor));
  21. if ((options=getenv(EDIT2))==NULL) stccpy(alt_editor,ALT_EDITOR,sizeof(alt_editor));
  22. else stccpy(alt_editor,options,sizeof(alt_editor));
  23.  
  24. stccpy(exit_pw,EXIT_PW,PWDLEN);
  25. stccpy(suspend_pw,SUSPW,PWDLEN);
  26.  
  27. if (debug) printf("hpath,ipath,fpath,seditor,aeditor=%s,%s,%s,%s,%s\r\n",
  28.            hpath,ipath,fpath,sys_editor,alt_editor);
  29.  
  30. /* Process options, if any */
  31. if (argc>1) while (--argc) {
  32.     if (argv[argc][0]=='?') {
  33.         option_ins();
  34.         return 1000;
  35.         }
  36.     uppercase(argv[argc]);
  37.     gn_fl = TRUE;
  38.  
  39.     if (argv[argc][0]=='-') {
  40.         switch(argv[argc][1]) {
  41.             case 'H': stccpy(hpath,argv[argc]+2,sizeof(hpath)); 
  42.                   break;
  43.             case 'F': stccpy(fpath,argv[argc]+2,sizeof(fpath)); 
  44.                   break;
  45.             case 'I': stccpy(ipath,argv[argc]+2,sizeof(ipath)); 
  46.                   break;
  47.             case 'P': switch(argv[argc][2]) {
  48.                 case 'X': stccpy(exit_pw,argv[argc]+3,sizeof(exit_pw));
  49.                       break;
  50.                 case 'S': stccpy(suspend_pw,argv[argc]+3,sizeof(suspend_pw));
  51.                       break;
  52.                 default:  gn_fl = FALSE;
  53.                 }
  54.             case 'D': if (argv[argc][2]=='O') deftflag = FALSE;
  55.                   break;
  56.             default: gn_fl = FALSE;
  57.             }
  58.         }
  59.     else if (!strcmp(argv[argc],"OFFLINE")) sys_test = TRUE;
  60.     else if (!strcmp(argv[argc],"EXPERT")) defbeginner = FALSE;
  61.     else if (!strcmp(argv[argc],"NOTIMEOUT")) notimeout = TRUE;
  62.     else if (!strcmp(argv[argc],"FORK")) fork_allowed = TRUE;
  63.     else if (!strcmp(argv[argc],"WILDCARDS")) wildcards = TRUE;
  64.     else if (!strcmp(argv[argc],"AVAILABLE")) sysop_there = TRUE;
  65.     else if (!strcmp(argv[argc],"PRTON")) prton = TRUE;
  66.     else if (!strcmp(argv[argc],"DEBUG")) debug = TRUE;
  67.     else if (!strcmp(argv[argc],"DEF300")) cb = 1;
  68.     else gn_fl = FALSE;
  69.  
  70.     if (gn_fl) ;
  71.     else if (!strcmp(argv[argc],"NEWLOG")) newlog = TRUE;
  72.     else if (!strcmp(argv[argc],"NOLOG")) nolog = TRUE;
  73.     else if (!strcmp(argv[argc],"NONEWS")) nonews = TRUE;
  74.     else if (!strcmp(argv[argc],"FORTUNE")) fort_une = TRUE;
  75.     else if (!strcmp(argv[argc],"TERMWIDTH")) termwidth = worknum;
  76.     else if (!strcmp(argv[argc],"FORTGAP")) fort_gap = worknum;
  77.     else if (!strcmp(argv[argc],"NOINTRO")) intro = FALSE;
  78.     else if (!strcmp(argv[argc],"AUTOFB")) autofb = TRUE;
  79.     else if (!strcmp(argv[argc],"1200B")) h1200b = TRUE;
  80.     else if (!strcmp(argv[argc],"NOALTBAUD")) altbd = FALSE;
  81.     else if (worknum=stoi(argv[argc]));
  82.     else printf("Invalid option '%s' ignored.\r\n",argv[argc]);
  83.     }
  84.  
  85.             /* Try to read command table from disk file */
  86. if ((commands=read_cmds())==NULL) {
  87.     printf("Can't read command table file: '%s'\r\n",CMDFILE);
  88.     return 8;
  89.     }
  90.  
  91.             /* Check integrity of system directories */
  92. if (sysdir("",MAILBOX)) exit(baddir(MAILBOX));
  93. else if (sysdir("",MESSAGES)) exit(baddir(MESSAGES));
  94. else if (sysdir("",USR_ROOT)) exit(baddir(USR_ROOT));
  95. else if (sysdir("",hpath)) exit(baddir(hpath));
  96. else if (sysdir("",ipath)) exit(baddir(ipath));
  97.             /* Able to CHDIR to all of them, proceed */
  98.  
  99.             /* Get pointer array for message system */
  100. if ((list=(struct dir_entry **)getmem(999*2))==NULL) {
  101.     printf("Can't allocate memory for msg array.\r\n");
  102.     return 9;
  103.     }
  104.  
  105. stccpy(user_root,USR_ROOT,sizeof(user_root));    /* ONE AND ONLY DEFINITION OF user_root */
  106.  
  107.     /* Cut off access from local printer and BREAK interrupt */
  108. if (!sys_test) brkset(OFF);
  109. if (!prton) printer(OFF);
  110. if (newlog) eraselog();
  111. openlog();
  112. logevent("LOG OPENED");
  113. if (fort_une) reset_fortf();        /* Open fortune file if selected */
  114. return 0;
  115. }
  116.  
  117. int log_on()
  118. {
  119. char c, d;
  120.             /* Wait for caller or local keyboard function */
  121. logon:
  122. init_vars();        /* Initialize/refresh/default system variables */
  123. baud="(system-test)";
  124. parity="N";
  125. wordlen="*";
  126.  
  127. reset:    baud = bdt[cb];        /* Default (last) baud rate */
  128. parity = "N";        /* Try no parity first */
  129. stopbits = "1";        /* Always one stop bit */
  130. wordlen = "8";        /* And eight bit word */
  131.     
  132.                 /* Install trial modem settings */
  133. minit(baud,parity,wordlen,stopbits,h1200b?"h":"");    
  134. if (!dsr()) printf("\r\n*USER DISCONNECT AT %s*\r\n",timedate());
  135. while(!dsr()) {                /* Wait for phone call */
  136.     if (bdos(KBHIT)) {
  137.         if (!bdos(CONSINP)) local_function(bdos(CONSINP));
  138.         else breakin_ins();
  139.         }    
  140.     }                /* Below logic auto-baud detect. */
  141.                     /* Stolen from RBBS-PC (BASIC) pgm */
  142. /* In either case, we read a CR to detect parity */
  143. while (dsr()) {                    /* While someone on the line */
  144.     if (bdos(KBHIT)) {            /* If a key typed, */
  145.         if ((c=bdos(CONSINP))!='\r') {  /* Get and see if CR */
  146.                         /* Nop -- not a CR */
  147.                         /* See what user typed */
  148.             if (debug) printf("usrtyp:`%c'=%d\r\n",c,c);
  149.                         /* Look for carriage return with */
  150.             if (c==('\r'|0x80)) {    /* high bit on? if so, */
  151.                 baud=bdt[cb];    /* try current baud rate, */
  152.                 parity = "E";    /* Using Even parity */
  153.                 wordlen = "7";    /* and seven bits */
  154.                 }
  155.             else {
  156.                 if (altbd) baud=bdt[cb=cb?0:1]; /* Toggle baud rate */
  157.                 parity = "N";    /* Using No parity */
  158.                 wordlen = "8";    /* and eight bits */
  159.                 }
  160.             minit(baud,parity,wordlen,stopbits,h1200b?"h":"");/* Change UART */
  161.             if (debug) printf("%s,%s,%s,%s\r\n",baud,parity,wordlen,stopbits);
  162.             } /* END Character not CR */
  163.         else break;    /* Character was CR */
  164.         }    /* Key was pressed */
  165.     } /* While dsr() */
  166.  
  167.  
  168. if (debug) {            /* Peek & Say real baud if debug */
  169.     c = inp(LCR);
  170.     printf("LCR=%x\r\n",c);
  171.     outp(LCR,c|0x80);    /* SET DLAB */
  172.     printf("rb:%x%x\r\n",inp(DLM),inp(DLL));
  173.     outp(LCR,c);
  174.     }
  175.  
  176. if (!dsr()) goto reset;        /* If he hung up, forget him! */
  177.     
  178. systime(&login_hh,&login_mm,&login_ss,&login_ms);  /* Get time of call */
  179. printf("\r\n\r\n%s online\r\n\n",SYSNAME);
  180. if (intro) help(SYSNEWS,"t");
  181. cr();
  182. trynpw:
  183. quit = FALSE;
  184. output = TRUE;
  185. printf("Enter %s ID or hit <ENTER>: ",SYSNAME);
  186. disp_reply("",user_id,sizeof(user_id));
  187. seek_user:
  188. stptok(user_id,workstr,9,BADUSRCHRS);
  189. stccpy(user_id,workstr,sizeof(user_id));
  190. uppercase(user_id);
  191. if (user_id[0]=='\0') {
  192.     help(HLP_LOGON,"t");
  193.     if (dsr()) goto trynpw;
  194.     else goto logon;
  195.     }
  196. else if (sysdir(user_id,user_root)) {
  197.     printf("You said: %s.\r\nPress <ENTER> if correct, or re-type:\r\n",
  198.         user_id);
  199.     disp_reply("",workstr,sizeof(user_id));
  200.     if (workstr[0]=='\0') {
  201.         printf("Ok %s, you will be placed on the %s directory.\r\n",
  202.             user_id,DEFLT_DIR);
  203.         sysdir(DEFLT_DIR,user_root);
  204.         stccpy(home_dir,DEFLT_DIR,sizeof(home_dir));
  205.         mputs("Read the HELP section in order to obtain your own,\r\n");
  206.         mputs("private directory.\r\n");
  207.         cr();
  208.         }
  209.     else {
  210.         stccpy(user_id,workstr,sizeof(user_id));
  211.         goto seek_user;
  212.         }
  213.     }
  214. else stccpy(home_dir,user_id,sizeof(home_dir));
  215.  
  216. uppercase(home_dir);
  217. no_account = !strcmp(home_dir,DEFLT_DIR);  /* NO_ACCOUNT TRUE iff on PUBLIC */
  218.  
  219. read_userfile();            /* Go read user info file */
  220. if (!test_password()) {            /* If password, ask for it */
  221.     printf("Incorrect password.\r\n");
  222.     printf("If you are a newcomer, please type '%s'.\r\n",DEFLT_DIR);
  223.     goto trynpw;
  224.     }
  225. systime(&login_hh,&login_mm,&login_ss,&login_ms);  /* Reset to time of logon */
  226. noforcenow = nousrto;        /* We are timing him from now unless NOUSRTO */
  227. sysdir(home_dir,user_root);    /* Come back to home directory */
  228. stccpy(cur_dir,home_dir,sizeof(cur_dir));/* record this as current directory */
  229. stccpy(cur_root,user_root,sizeof(cur_root));/* Make sure we're in right world */
  230.                 
  231. cls();                /* Clear user's screen if we know how */
  232. if (not_terminal) {        /* THIS USER WAS NOT SUSPENDED */
  233.     if (no_account) {        /* Is this the PUBLIC acct ? */
  234.         beginner = TRUE;    /* Set beginner for him */
  235.         printf("%s and welcome to %s!\r\n",good_morning(),SYSNAME);
  236.         sprintf(workstr,"VISITOR: %s",user_id);
  237.         }
  238.     else if (timeson>1) {
  239.         printf("%s and welcome back %s!\r\n",good_morning(),usname());
  240.         if (strcmp(laston,date())) printf("You last called on %s",laston);
  241.         else printf("You called earlier today");
  242.         printf("; %d total calls.\r\n",timeson);
  243.         expertstatus();
  244.         cr();
  245.         sprintf(workstr,"LOGON: %s",user_id);
  246.         }
  247.     else {
  248.         printf("%s, %s!\r\nWelcome to your new account.\r\n",good_morning(),user_id);
  249.         printf("Forward all system correspondence to %s.  Enjoy.\r\n",SYSOP);
  250.         sprintf(workstr,"LOGON: %s <-- new user",user_id);
  251.         typeifexist(ipath,FIRSTMSG_MSG,FALSE);
  252.         }
  253.     }
  254. else sprintf(workstr,"LOGON: *%s*",user_id);
  255.  
  256. logevent(workstr);
  257. if (not_terminal) return 0;
  258. else {
  259.     printf("\r\nSorry, this account is no longer active.\r\n");
  260.     printf("Please contact %s.\r\n",SYSOP);
  261.     stccpy(syspw,suspend_pw,sizeof(syspw));
  262.     log_off('T',"",FALSE);
  263.     return 1;            /* COULDNT LOG THIS GUY ON */
  264.     }
  265. }
  266.  
  267. log_off(c,options,quiet)
  268. char c;
  269. int quiet;
  270. char *options;
  271. {
  272. char d;
  273. int gn_fl;
  274.  
  275. write_userfile();            /* Write user info back to disk */
  276. logevent("LOGOFF");
  277. if (dsr()) {
  278.     noforcenow = TRUE;            /* Don't force during LOGOFF */
  279.     if (c=='Q') {
  280.         cls();
  281.         printf("\r\n\r\n      Goodbye!\r\n");
  282.         printf("\r\n(hang up or press ENTER)\r\n\r\n");
  283.         return;        /* Quit quickly if 'Q' used */
  284.         }
  285.     else if (c=='T') goto quick_off;    /* Or shoo him off if Terminal */
  286.     gn_fl = FALSE;
  287.     if (dsr() && ((autofb && !quiet) || (gn_fl=find_option(options,'f')))) {
  288.         if (gn_fl) d='Y';
  289.         else d=*disp_reply("Wish to leave feedback ? ",file_buffer,4);
  290.         if (toupper(d)=='Y') ask_sysop('Q',"","fq");
  291.         }
  292.     if (c=='X') goodbye(user_id);         /* Leave if 'X' cmmd was used */
  293.     cls();
  294.     printf("Goodbye %s! Call again soon.\r\n\n",strcmp(user_id,DEFLT_DIR)?user_id:"");
  295.     printf("%s: %s\r\n\n",SYSNAME,SYSOWNER); /* Say goodbye */
  296.     sprintf(workstr,"Off at: %s\r\n",timedate());
  297.     printf(workstr);
  298.              printf("Connect time: %s\r\n\n\n",elapsed_time(cnct_seconds()));
  299.     any_last_news();    /* Whatever we may want to publish before logoff */
  300.     if (fort_une && !nousrfort) fortune(randint(fort_gap));    /* Do fortune if requested */
  301.     }
  302. quick_off:
  303. hangup();                /* Hangup if 'Q' not used */
  304. closelog();            /* Close out the log for safety */
  305. openlog();
  306. return;
  307. }
  308. 
  309.