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