2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * rea.c: Read telegrams
30 * Known contributors to this file:
33 * Steve McClure, 1998-2000
58 extern s_char *telnames[];
60 register s_char *mbox;
61 s_char mbox_buf[256]; /* Maximum path length */
75 int num = player->cnum;
76 struct natstr *np = getnatp(player->cnum);
86 if (*player->argp[0] == 'w') {
87 sprintf(kind,"announcement");
88 if (player->argp[1] && isdigit(*player->argp[1])) {
89 delta = days(atoi(player->argp[1]));
92 then = np->nat_annotim;
95 sprintf(kind,"telegram");
96 if (player->god && player->argp[1] != 0) {
97 if ((n = natarg(player->argp[1], "")) < 0)
101 mbox = mailbox(mbox_buf, num);
102 clear_telegram_is_new(player->cnum);
106 if ((telfp = fopen(mbox, "r+")) == 0) {
108 if ((telfp = fopen(mbox, "r+b")) == 0) {
110 logerror("telegram file %s", mbox);
115 size = fsize(fileno(telfp));
120 while (fread((s_char *) &tgm, sizeof(tgm), 1, telfp) == 1) {
122 if (tgm.tel_length < 0) {
123 logerror("bad telegram file header in %s", mbox);
126 if (tgm.tel_type < 0 || tgm.tel_type > TEL_LAST) {
127 pr("Bad telegram header. Skipping telegram...\n");
133 (getrejects(tgm.tel_from, np) & REJ_ANNO)) {
137 if (tgm.tel_date < then) {
142 if (first && *kind == 'a') {
143 pr("\nAnnouncements since %s", ctime(&then));
147 if (tgm.tel_type != lasttype || tgm.tel_from != lastcnum)
149 if (abs((int)(tgm.tel_date - (long)lastdate)) > TEL_SECONDS)
153 lastcnum = tgm.tel_from;
154 lasttype = tgm.tel_type;
155 pr("%s ", telnames[(int)tgm.tel_type]);
156 if ((tgm.tel_type == TEL_NORM) ||
157 (tgm.tel_type == TEL_ANNOUNCE)) {
162 if (tgm.tel_type == TEL_BULLETIN){
163 pr("from %s, (#%d)", cname(tgm.tel_from), tgm.tel_from);
165 pr(" dated %s", ctime(&tgm.tel_date));
166 lastdate = tgm.tel_date;
170 while (tgm.tel_length > 0) {
171 nbytes = tgm.tel_length;
172 if (nbytes > sizeof(buf)-1)
173 nbytes = sizeof(buf)-1;
174 (void) fread(buf, sizeof(s_char), nbytes, telfp);
178 tgm.tel_length -= nbytes;
182 if (teles > 0 && player->cnum == num) { /* } */
186 p = "Forget this one? ";
188 p = "Shall I burn it? ";
191 p = "Into the shredder, boss? ";
193 p = "Can I throw away these old love letters? ";
195 if (player->god && *kind == 't')
196 p = getstarg(player->argp[2], p, buf);
198 p = getstarg(player->argp[1], p, buf);
199 if (p && *p == 'y') {
200 if ((filelen = fsize(fileno(telfp))) > size) {
201 pr("Wait a sec! A new %s has arrived...\n", kind);
202 /* force stdio to re-read tel file */
203 (void) fflush(telfp);
205 (void) fseek(telfp, (long)size, L_SET);
207 (void) fseek(telfp, (long)size, SEEK_SET);
214 np->nat_annotim = now;
217 /* Here, we just re-open the file for "w" only,
218 and that will wipe the file clean automatically */
221 telfp = fopen((char *)mbox, "w");
223 telfp = fopen((char *)mbox, "wb");
229 if(player->cnum == num)
230 pr("No %ss for you at the moment...\n",kind);
232 pr("No %ss for %s at the moment...\n", kind,
235 (void) fclose(telfp);
236 if (np->nat_flags & NF_INFORM) {
237 pr_inform(player, "\n");