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