home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / fido / pup_v2b.zip / LOGIN.C < prev    next >
C/C++ Source or Header  |  1988-01-28  |  6KB  |  232 lines

  1. #include <puppy.h>
  2. #include <pupmem.h>
  3. #include <ascii.h>
  4.  
  5. /*
  6.     Pups caller login process.
  7.  
  8. openclr()    Open the caller file. Must be done before any 
  9.         login functions are called.
  10.  
  11. closeclr()    Close the caller file. This should be called when
  12.         the caller is logged off or carrier is lost; if
  13.         a caller was on, their record is updated. 
  14.  
  15. getclr(n)    Retrieve caller record #n. It is assumed that
  16.         the record number is valid; no checks are done.
  17.  
  18. oldest(t)    Return the date of the oldest topic of those specified.
  19.  
  20. updclr(m,t)    Update the callers record to record the newest message
  21.         read in the specified topic(s). There may be more
  22.         than one topic selected, and a given message may belong
  23.          to more than one topic.
  24.  
  25. login()        Locate and sign in a caller, and set all the
  26.         vital statistics. This sets limits in force,
  27.         prompts for screen size for new callers, displays
  28.         the welcome message, gives a quotation, etc.
  29.  
  30. stuff(f)    Various user type commands; display welcome file, 
  31.         get screen width/length, etc. If f is zero, then
  32.         the caller gets to see WELCOME.PUP regardless; other
  33.         wise it asks.
  34.  
  35. */
  36.  
  37. static int clrfile;        /* open caller file */
  38. static int clrno;        /* currently open caller record or -1 if none */
  39.  
  40.  
  41. login() {
  42. char full_name[SS];        /* callers full name */
  43. char *cp,buff[SS];        /* working space */
  44. int n,i,f;
  45. int hash;            /* hash code from the name */
  46.  
  47.     limit= pup.nlimit;
  48.     klimit= pup.klimit;                /* set limits */
  49.  
  50.     caller.cols= 40; 
  51.     caller.lines= 24;                /* std. screen */
  52.     column= line= 0;                /* sync up "more" stuff, */
  53.  
  54.     mprintf("\r\nPup says: \"Hello!\"\r\n");
  55.     while (1) {
  56.         full_name[0]= NUL;            /* no name yet */
  57.         cp= getarg("Your name please (short & simple): ");
  58.         while (*cp) {
  59.             cpyarg(buff,cp);        /* copy each word */
  60.             strcat(full_name,buff);        /* to eliminiate excess */
  61.             cp= next_arg(cp);        /* spaces and such */
  62.             if (*cp) strcat(full_name," ");
  63.         }
  64.         if (! *full_name) continue;        /* must enter something */
  65.         full_name[sizeof(caller.name)]= NUL;    /* maximum length pleez */
  66.         if (ask(full_name)) break;        /* verify it */
  67.     }
  68.  
  69.  
  70. /* Now try to locate this caller in the file. */
  71.  
  72.     mprintf("Wait ...\r\n");            /* search for it */
  73.     strcpy(buff,full_name);                /* make a clean copy */
  74.     stolower(buff);                    /* for comparision */
  75.     cp= buff; clrcrc();                /* generate a hash code */
  76.     while (*cp) updcrc(*cp++);
  77.     hash= fincrc() % pup.callsize;            /* well distributed */
  78.  
  79.     for (i= 0; i < 10; i++) {            /* make a number of attempts */
  80.         n= (hash + i) % pup.callsize;        /* fudge the hash code */
  81.         getclr(n);                /* iteration */
  82.         stolower(caller.name);            /* for comparision. */
  83.         if (strcmp(caller.name,buff) == 0) {    /* if a match, */
  84.             mprintf("Hello again\r\n");    /* case may have changed */
  85.             i= 0;                /* mark as logged in */
  86.             break;
  87.         }
  88.     }
  89.  
  90. /* If the login fails, this person was never on, or their record got hashed
  91. out by someone else. Do it all again. New callers have a blank date; this
  92. makes all messages newer than they are. */
  93.  
  94.     if (i) {
  95.         cp= (char *) &caller;                /* clear the record */
  96.         for (i= 0; i < sizeof(struct _clr); i++) *cp++= NUL;    
  97.         caller.cols= 40; 
  98.         caller.lines= 24;                /* std. screen */
  99.         mprintf("\r\nUmm, excuse me. Would you mind coming with me. ");
  100.         mprintf("We want to ask you a few questions. This will only ");
  101.         mprintf("take a few minutes. (he he)\r\n\r\n");
  102.         setscreen();
  103.     }
  104.     ++caller.calls;
  105.     strcpy(caller.name,full_name);                /* set the name, */
  106.     clrno= hash;                        /* login complete */
  107.     dspfile("welcome.pup");
  108.     stuff();                        /* show other stuff */
  109.     quote();                        /* do a quotation */
  110.     mprintf("\r\nYou are caller #%,lu\r\n\r\n",++pup.callers);
  111. }
  112.  
  113. /* Set screen stuff. */
  114.  
  115. setscreen() {
  116. char *cp;
  117.  
  118.     cp= getarg("How wide is your screen? (CR=80): ");
  119.     if (*cp) caller.cols= atoi(cp);
  120.     else caller.cols= 80;
  121.     if ((caller.cols < 20) || (caller.cols > 80)) caller.cols= 40;
  122.  
  123.     cp= getarg("Pause after how many lines? (CR=24, 0=DONT): ");
  124.     if (*cp) caller.lines= atoi(cp);    /* assume its a number, */
  125.     else caller.lines= 24;            /* else CR is 24, */
  126.     if ((caller.lines < 4) || (caller.lines > 66)) caller.lines= 0;
  127. }
  128. /* Display stuff. */
  129.  
  130. stuff() {
  131. char *cp;
  132. int i;
  133. WORD time,date;
  134.  
  135.     date= gdate(); time= gtime();            /* get time, */
  136.     mputs("It is now: "); mputs(str_date(date)); mputs(str_time(time)); mputs("\r\n");
  137.     mprintf("You have been on for %d minutes, %d left\r\n",minutes,limit - minutes);
  138.  
  139.     mprintf("Topic    last read on\r\n");
  140.     for (i= 0; i < 16; i++) {
  141.         if (*pup.topic[i].name) {
  142.             mprintf("%-8s ",pup.topic[i].name);
  143.             if (caller.date[i]) mputs(str_date(caller.date[i]));
  144.             else mputs("Never");
  145.             mputs("\r\n");
  146.         }
  147.     }
  148. }
  149.  
  150. /* Open the caller file. */
  151.  
  152. openclr() {
  153.  
  154.     clrfile= open("puppy.clr",2);
  155.     if (clrfile == -1) printf("THE CALLER FILE IS MISSING!\r\n");
  156.     clrno= -1;
  157. }
  158.  
  159. /* Close the caller file. */
  160.  
  161. closeclr() {
  162.     if (clrno) {
  163.         posclr(clrno);                /* position there, */
  164.         write(clrfile,&caller,sizeof(struct _clr)); /* write it, */
  165.     }
  166.     if (clrfile != -1) close(clrfile);        /* close the file */
  167.     clrfile= -1;
  168. }
  169.  
  170. /* Get caller #n in the list. */
  171.  
  172. getclr(n)
  173. int n;
  174. {
  175.     posclr(n);
  176.     read(clrfile,&caller,sizeof(struct _clr));
  177. }
  178.  
  179. /* Position to caller record. */
  180.  
  181. posclr(n)
  182. int n;
  183. {
  184. long o;
  185.     o= 0L + n;
  186.     o *= sizeof(struct _clr);
  187.     lseek(clrfile,o,0);
  188. }
  189.  
  190. /* Return the oldest date of all the specified topics from the caller record. */
  191.  
  192. oldest(t)
  193. WORD t;
  194. {
  195. WORD d;
  196. int i;
  197.  
  198.     d= gdate();
  199.     for (i= 0; i < BITSWORD; i++) {        /* for each possible topic, */
  200.         if ((t & 1) && (caller.date[i] < d)) /* if this is older */
  201.             d= caller.date[i];    /* remember it */
  202.         t >>= 1;
  203.     }
  204.     return(d);
  205. }
  206.  
  207. /* Update the dates in the caller record to reflect the most recently
  208. read message. Since there may be more than one topic selected, and a
  209. given message can belong to more than one message, this could possibly 
  210. set more than one date. 
  211.  
  212.     message        selected topics        caller dates updated:
  213.     1 2 4        1 2 3 4 5 6        1 2 4
  214. */
  215.  
  216. updclr(msgnbr,t)
  217. int msgnbr;
  218. WORD t;
  219. {
  220. WORD d;
  221. int i;
  222.  
  223.     t &= getmsg(msgnbr)-> topic;            /* topic(s) to update */
  224.     d= getmsg(msgnbr)-> date;            /* messages date */
  225.  
  226.     for (i= 0; i < BITSWORD; i++) {            /* now check each */
  227.         if ((t & 1) && (d > caller.date[i]))    /* if newer, */
  228.             caller.date[i]= d;        /* remember it */
  229.         t >>= 1;                /* next topic ... */
  230.     }
  231. }
  232.