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