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