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