2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 Contains stuff related to shutdowns
24 static int shutdownTime = 0;
25 static int lastTimeLeft;
26 static int shutdownStartTime;
27 static char downer[1024];
28 static char reason[1024];
30 void output_shut_mess(void)
32 time_t shuttime = time(0);
33 d_printf( "CHESSD: Shutting down at %s\n", strltime(&shuttime));
36 static void ShutDown(void)
39 time_t shuttime = time(0);
41 for (p1 = 0; p1 < player_globals.p_num; p1++) {
42 if (player_globals.parray[p1].status != PLAYER_PROMPT)
44 pprintf(p1, "\n\n **** Server shutdown ordered by %s. ****\n",
46 if (reason[0] != '\0')
47 pprintf(p1, "\n **** We are going down because: %s. ****\n",
51 d_printf( "CHESSD: Shut down ordered at %s by %s.\n",
52 strltime(&shuttime), downer);
59 void ShutHeartBeat(void)
69 lastTimeLeft = shutdownTime;
70 timeLeft = shutdownTime - (t - shutdownStartTime);
71 if ((lastTimeLeft > 3600) && (timeLeft <= 3600))
73 if ((lastTimeLeft > 2400) && (timeLeft <= 2400))
75 if ((lastTimeLeft > 1200) && (timeLeft <= 1200))
77 if ((lastTimeLeft > 600) && (timeLeft <= 600))
79 if ((lastTimeLeft > 300) && (timeLeft <= 300))
81 if ((lastTimeLeft > 120) && (timeLeft <= 120))
83 if ((lastTimeLeft > 60) && (timeLeft <= 60))
85 if ((lastTimeLeft > 10) && (timeLeft <= 10))
89 "CHESSD: **** Server going down in %d minutes and %d seconds. ****\n\n",
91 timeLeft - ((timeLeft / 60) * 60));
92 if (reason[0] != '\0')
93 d_printf("CHESSD: We are going down because: %s.\n",reason);
94 for (p1 = 0; p1 < player_globals.p_num; p1++) {
95 if (player_globals.parray[p1].status != PLAYER_PROMPT)
98 "\n\n **** Server going down in %d minutes and %d seconds. ****\n",
100 timeLeft - ((timeLeft / 60) * 60));
101 if (reason[0] != '\0')
102 pprintf_prompt(p1,"\n **** We are going down because: %s. ****\n",reason);
104 pprintf_prompt(p1,"\n");
107 lastTimeLeft = timeLeft;
113 int check_and_print_shutdown(int p)
115 /* Tells a user if they is to be a shutdown */
116 /* returns 0 if there is not to be one, 1 if there is to be one */
117 /* for whenshut command */
126 return 0; /* no shut down */
128 timeLeft = shutdownTime - (t - shutdownStartTime);
131 "\n **** Server going down in %d minutes and %d seconds. ****\n",
133 timeLeft - ((timeLeft / 60) * 60));
134 if (reason[0] != '\0')
135 pprintf(p, "\n **** We are going down because: %s. ****\n", reason);
143 * Usage: shutdown [now,cancel,time]
145 * This command shutsdown the server. If the parameter is omitted or
146 * is 'now' then the server is immediately halted cleanly. If a time is
147 * given then a countdown commences and the server is halted when time is
148 * up. If 'cancel' is given then the countdown is stopped.
150 int com_shutdown(int p, param_list param)
152 struct player *pp = &player_globals.parray[p];
156 strcpy(downer, pp->name);
157 shutdownStartTime = time(0);
158 if (shutdownTime) { /* Cancel any pending shutdowns */
159 for (p1 = 0; p1 < player_globals.p_num; p1++) {
160 if (player_globals.parray[p1].status != PLAYER_PROMPT)
162 pprintf(p1, "\n\n **** Server shutdown canceled by %s. ****\n", downer);
165 if (param[0].type == TYPE_NULL)
168 /* Work out how soon to shut down */
169 if (param[0].type == TYPE_NULL)
172 if (!strcmp(param[0].val.word, "now"))
174 else if (!strcmp(param[0].val.word, "cancel"))
177 ptr = param[0].val.word;
178 shutdownTime = secs = 0;
192 secs = secs * 10 + *ptr - '0';
196 shutdownTime = shutdownTime * 60 + secs;
202 pprintf(p, "I don't know what you mean by %s\n", param[0].val.word);
207 shutdownTime = shutdownTime * 60 + secs;
210 if (shutdownTime <= 0)
212 if (param[1].type == TYPE_STRING)
213 strcpy (reason,param[1].val.string);
215 reason[0] = '\0'; /* No reason - perhaps admin is in a bad mood? :) */
216 for (p1 = 0; p1 < player_globals.p_num; p1++) {
217 if (player_globals.parray[p1].status != PLAYER_PROMPT)
219 pprintf(p1, "\n\n **** Server shutdown ordered by %s. ****\n", downer);
220 if (reason[0] != '\0')
221 pprintf(p1, " **** We are going down because: %s. ****\n",reason);
223 " **** Server going down in %d minutes and %d seconds. ****\n",
224 shutdownTime / 60, shutdownTime % 60);
225 if (p != p1) /* fix double prompt - DAV */
226 pprintf_prompt (p1,"\n");
234 int com_whenshut(int p, param_list param)
237 if (check_and_print_shutdown(p) == 0) {
238 pprintf (p,"No shutdown currently in progress\n");