]> git.pond.sub.org Git - empserver/blob - src/lib/commands/upda.c
New update scheduler:
[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  *     Markus Armbruster, 2007
32  */
33
34 #include <config.h>
35
36 #include "commands.h"
37 #include "optlist.h"
38 #include "server.h"
39
40 /*
41  * Tell what the update policy is, and when the next update
42  * is likely to be.
43  */
44 int
45 upda(void)
46 {
47     FILE *fp;
48     struct mob_acc_globals timestamps;
49     time_t now, next, stop;
50
51     if (opt_MOB_ACCESS) {
52         if ((fp = fopen(timestampfil, "rb")) == NULL)
53             logerror("Unable to open timestamp file.");
54         else {
55             rewind(fp);
56             fread(&timestamps, sizeof(timestamps), 1, fp);
57             fclose(fp);
58             if (updating_mob)
59                 pr("Mobility updating is enabled.\n\n");
60             else {
61                 pr("Mobility updating will come back on around %s",
62                    ctime(&timestamps.starttime));
63                 pr("game time, within 3 minutes, depending on when the server checks.\n\n");
64             }
65         }
66     }
67
68     if (updates_disabled())
69         pr("UPDATES ARE DISABLED!\n");
70
71     (void)time(&now);
72     next = update_time[0];
73     if (next) {
74         pr("\nUpdates occur at times specified by the ETU rates.\n\n");
75         pr("The next update is at %19.19s.\n", ctime(&next));
76     } else {
77         pr("There are no regularly scheduled updates.\n");
78     }
79     pr("The current time is   %19.19s.\n\n", ctime(&now));
80
81     if (next && update_window) {
82         pr("The next update window starts at %19.19s.\n",
83            ctime(&next));
84         stop = next + update_window;
85         pr("The next update window stops at %19.19s.\n", ctime(&stop));
86     }
87
88     switch (update_demand) {
89     case UPD_DEMAND_NONE:
90     default:
91         break;
92     case UPD_DEMAND_SCHED:
93         pr("Demand updates occur at update CHECK times.\n");
94         if (next) {
95             pr("The next update check is at %19.19s.\n",
96                ctime(&next));
97         }
98         pr("Demand updates require %d country(s) to want one.\n",
99            update_wantmin);
100         break;
101     case UPD_DEMAND_ASYNC:
102         pr("Demand updates occur right after the demand is set.\n");
103         if (*update_demandtimes != 0) {
104             pr("Demand updates are allowed during: %s\n",
105                update_demandtimes);
106         }
107         pr("Demand updates require %d country(s) to want one.\n",
108            update_wantmin);
109     }
110
111     if (*game_days != 0)
112         pr("Game days are: %s\n", game_days);
113     if (*game_hours != 0)
114         pr("Game hours are: %s\n", game_hours);
115
116     return 0;
117 }