]> git.pond.sub.org Git - empserver/blob - src/lib/commands/upda.c
ec80aaabd59c24b2215d4159735b8aa91608c309
[empserver] / src / lib / commands / upda.c
1 /*
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
5  *
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.
10  *
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.
15  *
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
19  *
20  *  ---
21  *
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.
25  *
26  *  ---
27  *
28  *  upda.c: Give the time of the next update
29  * 
30  *  Known contributors to this file:
31  *  
32  */
33
34 #include <stdio.h>
35 #include <sys/types.h>
36 #include "misc.h"
37 #include "player.h"
38 #include "commands.h"
39 #include "optlist.h"
40 #include "keyword.h"
41 #include "wantupd.h"
42 #include "server.h"
43
44 /*
45  * Tell what the update policy is, and when the next update
46  * is likely to be.
47  */
48 int
49 upda(void)
50 {
51     FILE *fp;
52     struct mob_acc_globals timestamps;
53
54     if (opt_MOB_ACCESS) {
55 #if !defined(_WIN32)
56         if ((fp = fopen(timestampfil, "r")) == NULL) {
57 #else
58         if ((fp = fopen(timestampfil, "rb")) == NULL) {
59 #endif
60             logerror("Unable to open timestamp file.");
61         } else {
62             rewind(fp);
63             fread(&timestamps, sizeof(timestamps), 1, fp);
64             fclose(fp);
65             if (updating_mob)
66                 pr("Mobility updating is enabled.\n\n");
67             else {
68                 pr("Mobility updating will come back on around %s",
69                    ctime(&timestamps.starttime));
70                 pr("game time, within 3 minutes, depending on when the server checks.\n\n");
71             }
72         }
73     }
74     if (opt_UPDATESCHED) {
75         time_t now, next, delta;
76
77         if (updates_disabled())
78             pr("UPDATES ARE DISABLED!\n");
79
80         (void)time(&now);
81         switch (update_policy) {
82         case UDP_NORMAL:
83             next_update_time(&now, &next, &delta);
84             pr("\nUpdates occur at times specified by the ETU rates.\n\n");
85             pr("The next update is at %19.19s.\n", ctime(&next));
86             break;
87         case UDP_TIMES:
88             next_update_time(&now, &next, &delta);
89             pr("\nUpdates occur at scheduled times.\n\n");
90             pr("The next update is at %19.19s.\n", ctime(&next));
91             break;
92         case UDP_BLITZ:
93             next_update_time(&now, &next, &delta);
94             pr("\nBlitz Updates occur every %d minutes. \n\n", blitz_time);
95             pr("The next update is at %19.19s.\n", ctime(&next));
96             break;
97         case UDP_NOREG:
98             pr("There are no regularly scheduled updates.\n");
99             break;
100         default:
101             pr("Update policy is inconsistent.\n");
102         }
103         pr("The current time is   %19.19s.\n\n", ctime(&now));
104
105         if (update_window) {
106             now = update_time - update_window;
107             next_update_time(&now, &next, &delta);
108             pr("The next update window starts at %19.19s.\n",
109                ctime(&next));
110             next += update_window;
111             pr("The next update window stops at %19.19s.\n", ctime(&next));
112         }
113         if (opt_DEMANDUPDATE) {
114             if (update_demandpolicy != UDDEM_DISABLE) {
115                 switch (update_demandpolicy) {
116                 case UDDEM_TMCHECK:
117                     next_update_check_time(&now, &next, &delta);
118                     pr("Demand updates occur at update CHECK times.\n");
119                     pr("The next update check is at %19.19s.\n",
120                        ctime(&next));
121                     break;
122                 case UDDEM_COMSET:
123                     pr("Demand updates occur right after the demand is set.\n");
124                     break;
125                 default:
126                     pr("Update demand policy is inconsistent.\n");
127                 }
128             }
129         }
130
131         if ((update_policy == UDP_TIMES) ||
132             ((update_demandpolicy == UDDEM_TMCHECK) && opt_DEMANDUPDATE)) {
133             if (*update_times != 0)
134                 pr("The update schedule is: %s\n", update_times);
135         }
136         if (opt_DEMANDUPDATE) {
137             if (update_demandpolicy != UDDEM_DISABLE) {
138                 if (*update_demandtimes != 0)
139                     pr("Demand updates are allowed during: %s\n",
140                        update_demandtimes);
141                 if (update_wantmin == 0) {
142                     pr("Demand updates are disabled by a mininum of 0\n");
143                 } else {
144                     pr("Demand updates require %d country(s) to want one.\n", update_wantmin);
145                 }
146             }
147         }
148         if (*game_days != 0)
149             pr("Game days are: %s\n", game_days);
150         if (*game_hours != 0)
151             pr("Game hours are: %s\n", game_hours);
152
153         return (0);
154     } else {
155         time_t now;
156         time_t upd_time;
157         time_t next_update;
158         int secs_per_update;
159         int delta;
160
161         (void)time(&now);
162         upd_time = now + adj_update;
163         secs_per_update = etu_per_update * s_p_etu;
164         delta = secs_per_update - (upd_time % secs_per_update);
165         next_update = now + delta;
166         pr("The next update is at %19.19s.\n", ctime(&next_update));
167         pr("The current time is %19.19s.\n", ctime(&now));
168         if (update_window) {
169             pr("Update times are variable, update window is +/- %d minutes %d seconds.\n", update_window / 60, update_window % 60);
170         }
171         return 0;
172     }
173 }