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