home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / WWIVMODS / MODSUNKN.ZIP / WWIVBANK.C < prev    next >
Text File  |  1989-02-13  |  6KB  |  267 lines

  1. #include "vardec.h"
  2. #include "fcns.h"
  3. #include <string.h>
  4. #include <fcntl.h>
  5. #include <sys\stat.h>
  6. #include <io.h>
  7.  
  8. /* WWIV BANK version 1.2 8/17/88 by Doug Fields
  9.                                     100 Midwood Road
  10. Bug Fix: No negative numbers        Greenwich, CT 06830
  11. allowed now.                        voice: 203-661-2967
  12.                                     Feel free to call. */
  13.  
  14. /* Copyright 1988 by DOUG FIELDS. No distribition allowed except by me, no modified copies
  15. of this souce code allowed to be distributed. Please read the accompanying documentation
  16. file, WBNKSRC.DOC, for more information. */
  17.  
  18. typedef struct {
  19.    char         uname[31];                   /* name */
  20.    int          timeinacct;                  /* amount of minutes in account */
  21.    } wwivbankrec;
  22.  
  23. extern userrec thisuser;
  24. extern configrec syscfg;
  25. extern int hangup;
  26. extern double extratimecall;
  27.  
  28. wwivbankrec bankee;
  29. int bankeenum;
  30.  
  31. #define maxminsinacct 60
  32.  
  33. void find_acct()
  34. {
  35. int bankeefile;
  36. char s[81];
  37.  
  38.   strcpy(s, syscfg.datadir);
  39.   strcat(s, "WWIVBANK.DAT");
  40.   if ((bankeefile = open(s, (O_RDONLY | O_BINARY))) == -1)
  41.     {
  42.     /* Check for new file. */
  43.     bankeenum = 0;
  44.     nl();
  45.     prt(3, "Making bank data file. Please hold..."); nl();
  46.     bankeefile = open(s, (O_RDWR | O_BINARY | O_CREAT), (S_IREAD | S_IWRITE));
  47.     close(bankeefile);
  48.     prt(3, "Finished."); nl();
  49.     nl();
  50.     bankee.timeinacct = 0;
  51.     strcpy(bankee.uname, thisuser.name);
  52.     return;
  53.     }
  54.   bankeenum = 0;
  55.   do
  56.     {
  57.     /* Find the user. */
  58.     lseek(bankeefile, (bankeenum * sizeof(wwivbankrec)), SEEK_SET);
  59.     read(bankeefile, (void *)&bankee, sizeof(wwivbankrec));
  60.     /* If found, then return. */
  61.     if (strcmp(bankee.uname, thisuser.name)==0)
  62.       {
  63.       close(bankeefile);
  64.       return;
  65.       }
  66.     bankeenum++;
  67.     }
  68.   while (!(eof(bankeefile)));
  69.   /* Not found, make new user. */
  70.   nl();
  71.   prt(5, "You are a new bankee at the Sanctuary. Creating your account.");
  72.   nl();
  73.   strcpy(bankee.uname, thisuser.name);
  74.   bankee.timeinacct = 0;
  75.   pausescr();
  76.   close(bankeefile);
  77. }
  78.  
  79. void save_acct()
  80. {
  81. int bankeefile;
  82. char s[81];
  83.  
  84.   strcpy(s, syscfg.datadir);
  85.   strcat(s, "WWIVBANK.DAT");
  86.   bankeefile = open(s, (O_BINARY | O_WRONLY));
  87.   lseek(bankeefile, (bankeenum * sizeof(wwivbankrec)), SEEK_SET);
  88.   write(bankeefile, (void *)&bankee, sizeof(wwivbankrec));
  89.   close(bankeefile);
  90. }
  91.  
  92. void add_time()
  93. {
  94. int minutes;
  95. char s[81];
  96.  
  97.   nl(); nl();
  98.   prt(1, "Deposit time, time left: ");
  99.   print(ctim(nsl()), ".","");
  100.   nl();
  101.   ansic(0);
  102.   print("How many minutes would you like to deposit?","");
  103.   prompt(": ","");
  104.   ansic(4);
  105.   inputl(s,3);
  106.   minutes = atoi(s);
  107.   if (minutes<1) return;
  108.  
  109.   if (hangup) return;
  110.  
  111.   if (minutes > (int)((nsl() - 20.0)/60.0))
  112.     {
  113.     nl(); nl();
  114.     prt(3, "You do not have enough time left to deposit that much.");
  115.     nl(); nl();
  116.     pausescr();
  117.     return;
  118.     }
  119.   if ((minutes + bankee.timeinacct) > maxminsinacct)
  120.     {
  121.     nl(); nl();
  122.     sprintf(s, "You may only have up to %d minutes in the account", maxminsinacct);
  123.     print(s,"");
  124.     print("at one time.","");
  125.     nl(); nl();
  126.     pausescr();
  127.     return;
  128.     }
  129.   if (so())
  130.     {
  131.     nl(); nl();
  132.     prt(6, "Sysops not allowed!");
  133.     nl(); nl();
  134.     pausescr();
  135.     return;
  136.     }
  137.   if ((thisuser.sl<=19)) {
  138.     nl(); nl();
  139.     prt(6," Validated Users Only.");
  140.     nl(); nl();
  141.     pausescr();
  142.     return;
  143.     }
  144.   /* Actually remove the time now. */
  145.   bankee.timeinacct += minutes;
  146.   save_acct();
  147.   sprintf(s, "- Deposit %d minutes.", minutes);
  148.   sysoplog(s);
  149.   nl();
  150.   sprintf(s, "%d minute%c deposited.", minutes,
  151.     ((minutes > 1) ? 's' : ''));
  152.   prt(4, s);
  153.   nl();
  154.  
  155.   if (extratimecall > 0)
  156.     {
  157.     if (extratimecall >= (double)(minutes * 60))
  158.       {
  159.       extratimecall -= (double)(minutes * 60);
  160.       return;
  161.       }
  162.     minutes -= (int)(extratimecall / 60.0);
  163.     extratimecall = 0.0;
  164.     }
  165.   thisuser.extratime -= (float)(minutes * 60);
  166.   pausescr();
  167. }
  168.  
  169. void remove_time()
  170. {
  171. char s[81];
  172. int minutes;
  173.  
  174.   nl(); nl();
  175.   sprintf(s, "Withdraw time, time in account: %d minutes.", bankee.timeinacct);
  176.   print(s,"");
  177.   nl();
  178.   ansic(0);
  179.   print("How many minutes would you like to withdraw?","");
  180.   prompt(": ","");
  181.   ansic(4);
  182.   inputl(s,3);
  183.   minutes = atoi(s);
  184.   if (minutes<1) return;
  185.  
  186.   if (hangup) return;
  187.   if (so())
  188.     {
  189.     nl(); nl();
  190.     prt(6, "Sysops not allowed!!");
  191.     nl(); nl();
  192.     pausescr();
  193.     return;
  194.     }
  195.   if ((thisuser.sl<=19)){
  196.     nl(); nl();
  197.     prt(6, "Validated Users Only.");
  198.     nl(); nl();
  199.     pausescr();
  200.     return;
  201.     }
  202.   if (minutes > bankee.timeinacct)
  203.     {
  204.     nl(); nl();
  205.     prt(6, "You don't have that much time in the account!");
  206.     nl();
  207.     nl();
  208.     pausescr();
  209.     return;
  210.     }
  211.   sprintf(s, "- Withdrew %d minutes.", minutes);
  212.   sysoplog(s);
  213.   thisuser.extratime += (float)(minutes * 60);
  214.   bankee.timeinacct -= minutes;
  215.   save_acct();
  216.   nl(); nl();
  217.   sprintf(s, "%d minute%c withdrawn.", minutes,
  218.     ((minutes > 1) ? 's' : ''));
  219.   prt(4, s);
  220.   nl(); nl();
  221.   pausescr();
  222. }
  223.  
  224. void wwivbank()
  225. {
  226. int done = 0;
  227. char s[81], ch;
  228.  
  229.   sysoplog("- Went to the WWIV Bank.");
  230.   find_acct();
  231.   do
  232.     {
  233.     tleft(0);
  234.     prt(0, "\x0c");
  235.     prt(4, "+----------------------------------+"); nl();
  236.     sprintf(s, "|        Time in account: %-4d     |", bankee.timeinacct);
  237.     prt(4, s); nl();
  238.     prt(4, "|                                  |"); nl();
  239.     prt(4, "| A) Add time to account           |"); nl();
  240.     prt(4, "| R) Remove time from account      |"); nl();
  241.     prt(4, "| Q) Leave the bank                |"); nl();
  242.     prt(4, "| ?) Get help                      |"); nl();
  243.     prt(4, "+----------------------------------+"); nl();
  244.     nl();
  245.     ansic(3);
  246.     print("T - ",ctim(nsl()),"");
  247.     ansic(2);
  248.     prompt("[WWIV Bank] : ", "");
  249.     ch = onek("QAR?");
  250.     switch (ch)
  251.       {
  252.       case 'Q': done = 1;
  253.                 break;
  254.       case 'A': add_time();
  255.                 break;
  256.       case 'R': remove_time();
  257.                 break;
  258.       case '?': printfile("WWIVBANK.MSG");
  259.                 pausescr();
  260.                 break;
  261.     }
  262.   }
  263.   while ((!hangup) && (!done));
  264.   nl();
  265.   prt(3, "Thank you for banking at the WWIV Bank at the Sanctuary.");
  266.   nl();
  267. }