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 34 #ifndef lint 35 #if 0 36 static char sccsid[] = "@(#)bill.c 5.2 (Berkeley) 5/28/91"; 37 #endif 38 static const char rcsid[] = 39 "$FreeBSD: src/games/larn/bill.c,v 1.6 1999/11/30 03:48:58 billf Exp $"; 40 #endif /* not lint */ 41 42 #include <sys/file.h> 43 #include <sys/wait.h> 44 #include <stdio.h> 45 #include "header.h" 46 47 /* bill.c Larn is copyrighted 1986 by Noah Morgan. */ 48 49 char *mail[] = { 50 "From: dev-null (the LRS - Larn Revenue Service)\n", 51 "Subject: undeclared income\n", 52 "\n We have heard you survived the caverns of Larn. Let me be the", 53 "\nfirst to congratulate you on your success. It was quite a feat.", 54 "\nIt was also very profitable for you...", 55 "\n\n The Dungeon Master has informed us that you brought", 56 "1", 57 "\ncounty of Larn is in dire need of funds, we have spared no time", 58 "2", 59 "\nof this notice, and is due within 5 days. Failure to pay will", 60 "\nmean penalties. Once again, congratulations, We look forward", 61 "\nto your future successful expeditions.\n", 62 NULL, 63 "From: dev-null (His Majesty King Wilfred of Larndom)\n", 64 "Subject: a noble deed\n", 65 "\n I have heard of your magnificent feat, and I, King Wilfred,", 66 "\nforthwith declare today to be a national holiday. Furthermore,", 67 "\nhence three days, ye be invited to the castle to receive the", 68 "\nhonour of Knight of the realm. Upon thy name shall it be written...", 69 "\n\nBravery and courage be yours.", 70 "\n\nMay you live in happiness forevermore...\n", 71 NULL, 72 "From: dev-null (Count Endelford)\n", 73 "Subject: You Bastard!\n", 74 "\n I have heard (from sources) of your journey. Congratulations!", 75 "\nYou Bastard! With several attempts I have yet to endure the", 76 " caves,\nand you, a nobody, makes the journey! From this time", 77 " onward, bewarned\nupon our meeting you shall pay the price!\n", 78 NULL, 79 "From: dev-null (Mainair, Duke of Larnty)\n", 80 "Subject: High Praise\n", 81 "\n With certainty, a hero I declare to be amongst us! A nod of", 82 "\nfavour I send to thee. Me thinks Count Endelford this day of", 83 "\nright breath'eth fire as of dragon of whom ye are slayer. I", 84 "\nyearn to behold his anger and jealously. Should ye choose to", 85 "\nunleash some of thy wealth upon those who be unfortunate, I,", 86 "\nDuke Mainair, shall equal thy gift also.\n", 87 NULL, 88 "From: dev-null (St. Mary's Children's Home)\n", 89 "Subject: these poor children\n", 90 "\n News of your great conquests has spread to all of Larndom.", 91 "\nMight I have a moment of a great adventurers's time? We here at", 92 "\nSt. Mary's Children's Home are very poor, and many children are", 93 "\nstarving. Disease is widespread and very often fatal without", 94 "\ngood food. Could you possibly find it in your heart to help us", 95 "\nin our plight? Whatever you could give will help much.", 96 "\n(your gift is tax deductible)\n", 97 NULL, 98 "From: dev-null (The National Cancer Society of Larn)\n", 99 "Subject: hope\n", 100 "\nCongratulations on your successful expedition. We are sure much", 101 "\ncourage and determination were needed on your quest. There are", 102 "\nmany though, that could never hope to undertake such a journey", 103 "\ndue to an enfeebling disease -- cancer. We at the National", 104 "\nCancer Society of Larn wish to appeal to your philanthropy in", 105 "\norder to save many good people -- possibly even yourself a few", 106 "\nyears from now. Much work needs to be done in researching this", 107 "\ndreaded disease, and you can help today. Could you please see it", 108 "\nin your heart to give generously? Your continued good health", 109 "\ncan be your everlasting reward.\n", 110 NULL 111 }; 112 113 /* 114 * function to mail the letters to the player if a winner 115 */ 116 117 void 118 mailbill() 119 { 120 int i; 121 char fname[32]; 122 char buf[128]; 123 char **cp; 124 int fd; 125 126 wait(0); 127 if (fork() == 0) { 128 resetscroll(); 129 cp = mail; 130 sprintf(fname, "/tmp/#%dlarnmail", getpid()); 131 for (i = 0; i < 6; i++) { 132 if ((fd = open(fname, O_WRONLY | O_TRUNC | O_CREAT), 133 0660) == -1) 134 exit(0); 135 while (*cp != NULL) { 136 if (*cp[0] == '1') { 137 sprintf(buf, "\n%ld gold pieces back with you from your journey. As the", 138 (long)c[GOLD]); 139 write(fd, buf, strlen(buf)); 140 } else if (*cp[0] == '2') { 141 sprintf(buf, "\nin preparing your tax bill. You owe %ld gold pieces as", (long)c[GOLD]*TAXRATE); 142 write(fd, buf, strlen(buf)); 143 } else 144 write(fd, *cp, strlen(*cp)); 145 cp++; 146 } 147 cp++; 148 149 close(fd); 150 sprintf(buf, "/usr/sbin/sendmail %s < %s > /dev/null", 151 loginname, fname); 152 system(buf); 153 unlink(fname); 154 } 155 } 156 exit(0); 157 } 158