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