Home | History | Annotate | Line # | Download | only in larn
      1 /*	$NetBSD: bill.c,v 1.11 2011/08/29 20:30:37 joerg Exp $	 */
      2 
      3 /*-
      4  * Copyright (c) 1991 The Regents of the University of California.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 #ifndef lint
     34 #if 0
     35 static char sccsid[] = "@(#)bill.c	5.2 (Berkeley) 5/28/91";
     36 #else
     37 __RCSID("$NetBSD: bill.c,v 1.11 2011/08/29 20:30:37 joerg Exp $");
     38 #endif
     39 #endif /* not lint */
     40 
     41 #include <sys/file.h>
     42 #include <sys/wait.h>
     43 #include <stdio.h>
     44 #include <string.h>
     45 #include <stdlib.h>
     46 #include <unistd.h>
     47 #include <paths.h>
     48 #include "header.h"
     49 #include "extern.h"
     50 
     51 /* bill.c		 Larn is copyrighted 1986 by Noah Morgan. */
     52 
     53 static const char *mail[] = {
     54 	"From: the LRS (Larn Revenue Service)\n",
     55 	"~s undeclared income\n",
     56 	"\n   We have heard you survived the caverns of Larn.  Let me be the",
     57 	"\nfirst to congratulate you on your success.  It was quite a feat.",
     58 	"\nIt was also very profitable for you...",
     59 	"\n\n   The Dungeon Master has informed us that you brought",
     60 	"1",
     61 	"\ncounty of Larn is in dire need of funds, we have spared no time",
     62 	"2",
     63 	"\nof this notice, and is due within 5 days.  Failure to pay will",
     64 	"\nmean penalties.  Once again, congratulations, We look forward",
     65 	"\nto your future successful expeditions.\n",
     66 	NULL,
     67 	"From: His Majesty King Wilfred of Larndom\n",
     68 	"~s a noble deed\n",
     69 	"\n   I have heard of your magnificent feat, and I, King Wilfred,",
     70 	"\nforthwith declare today to be a national holiday.  Furthermore,",
     71 	"\nhence three days, ye be invited to the castle to receive the",
     72 	"\nhonour of Knight of the realm.  Upon thy name shall it be written...",
     73 	"\n\nBravery and courage be yours.",
     74 	"\n\nMay you live in happiness forevermore...\n",
     75 	NULL,
     76 	"From: Count Endelford\n",
     77 	"~s You Bastard!\n",
     78 	"\n   I have heard (from sources) of your journey.  Congratulations!",
     79 	"\nYou Bastard!  With several attempts I have yet to endure the",
     80 	" caves,\nand you, a nobody, makes the journey!  From this time",
     81 	" onward, bewarned\nupon our meeting you shall pay the price!\n",
     82 	NULL,
     83 	"From: Mainair, Duke of Larnty\n",
     84 	"~s High Praise\n",
     85 	"\n   With certainty, a hero I declare to be amongst us!  A nod of",
     86 	"\nfavour I send to thee.  Me thinks Count Endelford this day of",
     87 	"\nright breath'eth fire as of dragon of whom ye are slayer.  I",
     88 	"\nyearn to behold his anger and jealously.  Should ye choose to",
     89 	"\nunleash some of thy wealth upon those who be unfortunate, I,",
     90 	"\nDuke Mainair, shall equal thy gift also.\n",
     91 	NULL,
     92 	"From: St. Mary's Children's Home\n",
     93 	"~s these poor children\n",
     94 	"\n   News of your great conquests has spread to all of Larndom.",
     95 	"\nMight I have a moment of a great adventurers's time?  We here at",
     96 	"\nSt. Mary's Children's Home are very poor, and many children are",
     97 	"\nstarving.  Disease is widespread and very often fatal without",
     98 	"\ngood food.  Could you possibly find it in your heart to help us",
     99 	"\nin our plight?  Whatever you could give will help much.",
    100 	"\n(your gift is tax deductible)\n",
    101 	NULL,
    102 	"From: The National Cancer Society of Larn\n",
    103 	"~s hope\n",
    104 	"\nCongratulations on your successful expedition.  We are sure much",
    105 	"\ncourage and determination were needed on your quest.  There are",
    106 	"\nmany though, that could never hope to undertake such a journey",
    107 	"\ndue to an enfeebling disease -- cancer.  We at the National",
    108 	"\nCancer Society of Larn wish to appeal to your philanthropy in",
    109 	"\norder to save many good people -- possibly even yourself a few",
    110 	"\nyears from now.  Much work needs to be done in researching this",
    111 	"\ndreaded disease, and you can help today.  Could you please see it",
    112 	"\nin your heart to give generously?  Your continued good health",
    113 	"\ncan be your everlasting reward.\n",
    114 	NULL
    115 };
    116 
    117 /*
    118  * function to mail the letters to the player if a winner
    119  */
    120 
    121 void
    122 mailbill(void)
    123 {
    124 	int    i;
    125 	char   fname[32];
    126 	char   buf[128];
    127 	const char **cp;
    128 	int    fd;
    129 
    130 	wait(0);
    131 	if (fork() == 0) {
    132 		resetscroll();
    133 		cp = mail;
    134 		snprintf(fname, sizeof(fname), "%slarnmail.XXXXXX", _PATH_TMP);
    135 		for (i = 0; i < 6; i++) {
    136 			if ((fd = mkstemp(fname)) == -1)
    137 				exit(0);
    138 			while (*cp != NULL) {
    139 				if (*cp[0] == '1') {
    140 					snprintf(buf, sizeof(buf),
    141 		"\n%ld gold pieces back with you from your journey.  As the",
    142 						(long) c[GOLD]);
    143 					write(fd, buf, strlen(buf));
    144 				} else if (*cp[0] == '2') {
    145 					snprintf(buf, sizeof(buf),
    146 		"\nin preparing your tax bill.  You owe %ld gold pieces as",
    147 					    (long) c[GOLD] * TAXRATE);
    148 					write(fd, buf, strlen(buf));
    149 				} else
    150 					write(fd, *cp, strlen(*cp));
    151 				cp++;
    152 			}
    153 			cp++;
    154 
    155 			close(fd);
    156 			snprintf(buf, sizeof(buf),
    157 			    "mail -I %s < %s > /dev/null", loginname, fname);
    158 			system(buf);
    159 			unlink(fname);
    160 		}
    161 	}
    162 	exit(0);
    163 }
    164