annotate src/daemonII.c @ 14:b7fe2e0e4b86

Added #defines which hold the chance of nebulous terrain affecting your weapons systems.
author darius
date Sat, 06 Dec 1997 06:27:50 +0000
parents 2719a89505ba
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1 /*--------------------------------------------------------------------------
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
2 NETREK II -- Paradise
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
3
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
4 Permission to use, copy, modify, and distribute this software and its
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
6 purpose and without fee is hereby granted, provided that this copyright
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
7 notice appear in all copies. No representations are made about the
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
8 suitability of this software for any purpose. This software is provided
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
9 "as is" without express or implied warranty.
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
10
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
11 Xtrek Copyright 1986 Chris Guthrie
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
13 Scott Silvey
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
15 Kurt Olsen
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
16 Brandon Gillespie
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
17 --------------------------------------------------------------------------*/
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
18 char binary[] = "@(#)daemonII";
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
19
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
20 #define DAEMONII 1 /* to tell daemonII.h we are in this file */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
21
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
22 #include "config.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
23 #include <stdio.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
24 #include <signal.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
25 #include <sys/time.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
26 #include <sys/file.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
27 #include <setjmp.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
28 #include <sys/ioctl.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
29 #include <sys/wait.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
30 #ifndef ULTRIX
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
31 #include <sys/fcntl.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
32 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
33 #include <string.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
34
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
35 #include <sys/types.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
36 #include <sys/ipc.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
37 #include <sys/shm.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
38 #include <math.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
39 #include <errno.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
40
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
41 #include "defs.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
42 #include "struct.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
43 #include "data.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
44 #include "planets.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
45 #include "terrain.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
46 #include "conquer.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
47 #include "daemonII.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
48 #include "getship.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
49 #include "weapons.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
50 #include "player.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
51 #include "misc.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
52 #include "shmem.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
53 #include "path.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
54
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
55 #define TellERR(x) fprintf(stderr, "! %s: %s\n", argv0, x)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
56 #define TellERRf(x, y) { \
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
57 sprintf(buf, x, y); \
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
58 fprintf(stderr, "! %s: %s\n", argv0, buf); \
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
59 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
60 /*--------------------------FUNCTION PROTOTYPES---------------------------*/
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
61 #ifndef FreeBSD
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
62 long lseek();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
63 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
64
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
65 typedef void sig_ret_t;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
66
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
67 void move();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
68 sig_ret_t reaper();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
69 sig_ret_t setflag();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
70 sig_ret_t freemem();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
71 char *getenv();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
72 char *twoletters();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
73 void starttimer();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
74 void stoptimer();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
75 void printdaemonIIUsage();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
76 void check_load();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
77 void rescue();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
78 void teamtimers();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
79 void shipbuild_timers();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
80 extern void (*r_signal()) ();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
81
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
82 /*------------------------------------------------------------------------*/
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
83
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
84
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
85
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
86
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
87
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
88
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
89
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
90 /*---------------------------MODULE VARIABLES-----------------------------*/
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
91
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
92 int dietime = -1; /* to decide whether the deamon has been */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
93 /* inactive for one minute. Set to -1 so */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
94 /* the deamon will not immediately quit */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
95
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
96 int ticks = 0; /* counting ticks for game timing */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
97
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
98 jmp_buf env; /* to hold long jump back into main */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
99
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
100 static int debug = 0; /* set if an arg is passed to main on the
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
101 * command line, this var gets set to 1 and
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
102 * debuf info is printed. */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
103
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
104 static int doMove; /* indicates whether it's time to call move() */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
105
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
106 int plfd; /* for the planet file */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
107 int glfd; /* for the status file */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
108
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
109 /* The name of the four teams */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
110
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
111 /* The verbage to use in sentences such as 'the XXXXX have/has' */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
112 char *teamVerbage[9] = {"", "has", "have", "", "have", "", "", "", "have"};
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
113
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
114 int tourntimestamp = 0; /* ticks since t-mode started */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
115
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
116
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
117 /*------------------------------------------------------------------------*/
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
118
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
119
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
120
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
121
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
122
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
123
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
124
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
125
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
126 /*----------------------------------MAIN-----------------------------------*/
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
127 /*
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
128 * Well, this is it. The big Kahuna. The main function of daemonII. If an
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
129 * arg is passed to main, then debug info is printed. What is passed in does
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
130 * not matter. Personally, I am fond of running it with: daemonII fungus.
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
131 * But maybe that's just me. Important: An environment variable is read in
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
132 * from the user. It is called NETREKDIR. This variable needs to be a path
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
133 * to where the '.' (dot) files are to be found. Kurt added this to make
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
134 * things a hell of a lot easier.
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
135 */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
136
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
137 int
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
138 main(argc, argv)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
139 int argc;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
140 char **argv;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
141 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
142 register int i; /* looping var */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
143 int jjk; /* looping var */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
144 char buf[255]; /* Temp buffer */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
145 char *paths; /* to form path with */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
146 char *ptr; /* get get path env var */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
147
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
148 int x = 0; /* for delay in debugging messages */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
149 #ifdef LEAGUE_SUPPORT
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
150 int configleague = 0; /* if nonzero, set configvals->league to 1 */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
151 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
152 int attach = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
153 int nogo = 0; /* for the usage flag/case */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
154
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
155 argv0 = argv[0];
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
156
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
157 i = 1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
158 while (argv[i])
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
159 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
160 if (argv[i][0] == '-')
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
161 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
162 ptr = &argv[i][1];
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
163 while (*ptr)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
164 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
165 switch (*ptr)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
166 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
167 case 'l':
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
168 #ifdef LEAGUE_SUPPORT
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
169 configleague = 1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
170 #else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
171 TellERR("daemon not compiled with league support.");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
172 TellERR("Edit config.h and reinstall.");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
173 TellERR("Continuing anyway.");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
174 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
175 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
176 case 'd':
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
177 debug = 1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
178 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
179 case 'a':
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
180 attach = 1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
181 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
182 case 'h':
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
183 case 'u': /* for old times sake */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
184 case '-': /* this allows for --help people */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
185 nogo++;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
186 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
187 case 'v': /* version, what the hell */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
188 fprintf(stderr, "-- NetrekII (Paradise), %s --\n", PARAVERS);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
189 exit(0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
190 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
191 default:
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
192 TellERRf("Unknown flag '%c'.", *ptr);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
193 nogo++;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
194 /* fprintf(stderr, "Unknown flag '%c'\n", *ptr); */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
195 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
196 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
197 ptr++;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
198 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
199 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
200 #if 0 /* this is goofy, just use -d */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
201 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
202 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
203 TelLERR("Backward compatibility: activating debugging mode.");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
204 debug = 1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
205 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
206 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
207 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
208 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
209 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
210 TellERRf("Invalid option format '%s'.", argv[i]);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
211 nogo++;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
212 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
213 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
214 i++;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
215 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
216
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
217 if (nogo)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
218 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
219 printdaemonIIUsage(argv0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
220 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
221 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
222 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
223 /* log the PID */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
224 char *fname;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
225 FILE *fptr;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
226
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
227 fname = build_path("logs/daemonII.pid");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
228 fptr = fopen(fname, "w+");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
229 fprintf(fptr, "%d", getpid());
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
230 fclose(fptr);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
231 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
232
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
233 fprintf(stderr, "Daemon says 'hello!'\n"); /* say hi */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
234 srand48(getpid()); /* seed random # gen */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
235
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
236 openmem(attach ? 0 : 2, 0); /* create shared memory */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
237
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
238 /* my daemonII has been dumping core a lot in readsysdefaults */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
239 if (!debug)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
240 { /* setup signals if not debugging */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
241 for (i = 0; i < NSIG; i++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
242 r_signal(i, freemem);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
243 r_signal(SIGSTOP, SIG_DFL); /* accept SIGSTOP? 3/6/92 TC */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
244 r_signal(SIGTSTP, SIG_DFL); /* accept SIGTSTP? 3/6/92 TC */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
245 r_signal(SIGCONT, SIG_DFL); /* accept SIGCONT? 3/6/92 TC */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
246 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
247
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
248 #ifdef LEAGUE_SUPPORT
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
249 if (configleague && !attach)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
250 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
251 status2->league = 1; /* configure for league play */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
252 /* .sysdef will be ignored */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
253
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
254 /* haven't chosen teams yet */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
255 status2->home.index = status2->away.index = -1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
256
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
257 /* haven't chosen captains either */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
258 status2->home.captain = status2->away.captain = -1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
259
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
260 /* no names for the team */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
261 status2->home.name[0] = status2->away.name[0] = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
262
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
263 status2->home.ready = status2->away.ready = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
264
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
265 status2->home.desirepause = status2->away.desirepause = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
266
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
267 /* away has NOT passed team choice */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
268 status2->awaypassed = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
269
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
270 status2->paused = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
271
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
272 /* clear out the temporary player file */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
273 paths = build_path(PLAYERFILE);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
274 if (0 != unlink(paths) && errno != ENOENT)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
275 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
276 perror("zeroing tourney temporary player file");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
277 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
278
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
279 status2->home.desired.galaxyreset = status2->away.desired.galaxyreset
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
280 = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
281 status2->home.desired.restart = status2->away.desired.restart
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
282 = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
283 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
284 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
285
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
286 if (!attach)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
287 readsysdefaults(); /* go get sysdefaults */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
288
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
289 #ifdef LEAGUE_SUPPORT
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
290 if (configleague && !attach)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
291 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
292 status2->home.timeouts_left = status2->away.timeouts_left =
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
293 configvals->timeouts;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
294
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
295 status2->home.desired.regulation = status2->away.desired.regulation
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
296 = configvals->regulation_minutes;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
297 status2->home.desired.overtime = status2->away.desired.overtime
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
298 = configvals->overtime_minutes;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
299 status2->home.desired.maxplayers = status2->away.desired.maxplayers
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
300 = configvals->playersperteam;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
301 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
302 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
303
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
304
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
305 if (!attach)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
306 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
307 for (i = 0; i < MAXPLAYER; i++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
308 { /* go through all players */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
309 players[i].p_status = PFREE; /* set slot free */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
310 players[i].p_no = i; /* set his player number */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
311 players[i].p_ntspid = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
312 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
313 status2->nontteamlock = ALLTEAM;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
314 status2->starttourn = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
315 } /* !attach */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
316
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
317 paths = build_path(PLFILE);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
318 plfd = open(paths, O_RDWR, 0744); /* open planets file */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
319 if (!attach)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
320 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
321 #if 1
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
322 gen_planets(); /* generate a new galaxy every time */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
323 status->time = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
324 #else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
325 if (plfd < 0)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
326 { /* oopen failed? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
327 fprintf(stderr, "No planet file. Restarting galaxy\n");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
328 gen_planets(); /* yup, go to it */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
329 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
330 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
331 { /* try to read in planets */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
332 if (read(plfd, (char *) planets, sizeof(struct planet) * MAXPLANETS) !=
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
333 sizeof(struct planet) * MAXPLANETS)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
334 { /* if wrong size */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
335 fprintf(stderr, "Planet file wrong size. Restarting galaxy\n");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
336 gen_planets(); /* then regenerate galaxy */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
337 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
338 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
339 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
340 } /* !attach */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
341 paths = build_path(GLOBAL);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
342
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
343 glfd = open(paths, O_RDWR, 0744); /* try to open file */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
344
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
345 if (!attach)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
346 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
347 if (glfd < 0)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
348 { /* if could not open */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
349 fprintf(stderr, "No global file. Resetting all stats\n");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
350 memset((char *) status, 0, sizeof(struct status));
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
351 glfd = open(paths, O_RDWR | O_CREAT, 0744); /* try to create file */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
352 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
353 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
354 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
355 if (read(glfd, (char *) status, sizeof(struct status)) !=
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
356 sizeof(struct status))
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
357 { /* try to read file */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
358 fprintf(stderr, "Global file wrong size. Resetting all stats\n");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
359 memset((char *) status, 0, sizeof(struct status));
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
360 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
361 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
362 if (status->time == 0)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
363 { /* do stats need resetting */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
364 status->dooshes = 1500; /* yup, then reset them */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
365 status->armsbomb = 4000; /* set them to something other than */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
366 status->resbomb = 1200; /* zeroes and ones so that the */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
367 status->planets = 1000; /* globals are not totally whacked */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
368 status->kills = 1; /* when we first start */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
369 status->losses = 1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
370 status->genocides = 10;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
371 status->sbkills = 1200;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
372 status->sblosses = 30;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
373 status->sbtime = 720000;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
374 status->wbkills = 1200;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
375 status->wblosses = 40;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
376 status->wbtime = 360000;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
377 status->jsplanets = 400;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
378 status->jstime = 240000;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
379 status->time = 1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
380 status->timeprod = 1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
381 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
382
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
383 /* wait queue stuff */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
384 status->wait = 0; /* invocation of the */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
385 status->count = 0; /* daemon */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
386 status->request = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
387
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
388 } /* !attach */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
389 status->active = 0; /* set stats that deal with this */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
390 status->gameup = 1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
391 status->nukegame = getpid();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
392 status->timeprod = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
393
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
394 setjmp(env); /* set the loooong jump */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
395
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
396 r_signal(SIGCHLD, reaper); /* set reaper and setflag signal */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
397 r_signal(SIGALRM, setflag); /* handlers */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
398
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
399 if (!attach)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
400 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
401 for (i = 0; i <= MAXTEAM; i++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
402 { /* reset some team vars */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
403 teams[i].s_surrender = 0; /* reset surrender timers */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
404 for (jjk = 0; jjk < NUM_TYPES; jjk++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
405 teams[i].s_turns[jjk] = 0; /* reset all ship construction timers */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
406 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
407 } /* !attach */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
408
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
409 status2->newgalaxy = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
410 for (i = 0; i < MAXPLAYER; i++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
411 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
412 galaxyValid[i] = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
413 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
414
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
415 check_load(); /* check the load on machine */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
416
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
417 starttimer(); /* start interval timer */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
418 doMove = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
419
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
420 while (1)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
421 { /* do forever */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
422 if (!doMove)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
423 pause(); /* wait for signal */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
424
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
425 if (doMove)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
426 { /* if it's time */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
427 doMove = 0; /* reset the flag */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
428 move(); /* then do the update */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
429
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
430 if (debug)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
431 { /* if in debug mode */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
432 if (!(++x % 50)) /* print 'mark' as we wait */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
433 printf("Mark %d\n", x);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
434 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
435 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
436 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
437 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
438 /*---------------------[ prints the usage of daemonII ]---------------------*/
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
439
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
440 void
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
441 printdaemonIIUsage(char *myname)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
442 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
443 int x;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
444 char message[][255] = {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
445 "\n\t'%s [options]'\n\n",
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
446 "Options:\n",
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
447 "\t-h help (this usage message)\n",
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
448 "\t-l configures as a League server (usually run by listen)\n",
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
449 "\t-d debug\n",
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
450 "\t-a attach to a crashed daemon's memory segment\n",
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
451 "\nNOTE: %s is designed to be launched by the startup process.\n\n",
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
452 "\0"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
453 };
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
454
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
455 fprintf(stderr, "-- NetrekII (Paradise), %s --\n", PARAVERS);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
456 for (x = 0; *message[x] != '\0'; x++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
457 fprintf(stderr, message[x], myname);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
458
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
459 exit(1);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
460 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
461
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
462 /*--------------------------[ printdaemonIIUsage ]--------------------------*/
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
463
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
464 /* signal handler for SIGALRM */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
465 sig_ret_t
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
466 setflag()
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
467 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
468 doMove = 1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
469 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
470
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
471 void
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
472 starttimer()
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
473 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
474 struct itimerval udt;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
475
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
476 udt.it_interval.tv_sec = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
477 udt.it_interval.tv_usec = UPDATE;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
478 udt.it_value.tv_sec = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
479 udt.it_value.tv_usec = UPDATE;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
480 setitimer(ITIMER_REAL, &udt, (struct itimerval *) 0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
481 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
482
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
483 void
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
484 stoptimer()
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
485 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
486 struct itimerval udt;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
487
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
488 udt.it_interval.tv_sec = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
489 udt.it_interval.tv_usec = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
490 udt.it_value.tv_sec = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
491 udt.it_value.tv_usec = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
492 setitimer(ITIMER_REAL, &udt, (struct itimerval *) 0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
493 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
494
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
495 #ifdef LEAGUE_SUPPORT
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
496 static void
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
497 handle_pause_goop()
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
498 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
499 if (status2->paused)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
500 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
501 if (!status2->home.desirepause && !status2->away.desirepause)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
502 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
503 /* countdown to game resumption */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
504 status2->paused--;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
505 if (status2->paused)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
506 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
507 if (status2->paused % TICKSPERSEC == 0)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
508 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
509 char buf[80];
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
510 sprintf(buf, "Game will resume in %d seconds",
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
511 status2->paused / TICKSPERSEC);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
512 pmessage(buf, -1, MALL, UMPIRE);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
513 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
514 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
515 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
516 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
517 pmessage("Let the carnage resume!", -1, MALL, UMPIRE);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
518 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
519 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
520 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
521 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
522 status2->pausemsgfuse++;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
523 if (status2->pausemsgfuse > SECONDS(15))
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
524 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
525 status2->pausemsgfuse = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
526 pmessage("Game is PAUSEd. Captains `LEAGUE CONTINUE' to resume play.",
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
527 -1, MALL, UMPIRE);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
528 if (!status2->home.desirepause)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
529 pmessage("The home team wishes to CONTINUE the game.",
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
530 -1, MALL, UMPIRE);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
531 if (!status2->away.desirepause)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
532 pmessage("The away team wishes to CONTINUE the game.",
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
533 -1, MALL, UMPIRE);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
534 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
535 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
536 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
537 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
538 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
539 if (!status2->home.desirepause && !status2->away.desirepause)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
540 return;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
541
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
542 status2->pausemsgfuse++;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
543 if (status2->pausemsgfuse > SECONDS(15))
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
544 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
545 char buf[80];
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
546 status2->pausemsgfuse = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
547 sprintf(buf, "The %s team wishes to PAUSE the game!",
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
548 status2->home.desirepause ? "home" : "away");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
549 pmessage(buf, -1, MALL, UMPIRE);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
550 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
551 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
552 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
553 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
554
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
555 /*---------------------------------MOVE-----------------------------------*/
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
556 /*
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
557 * This is the main loop for the program. It is called every 1/10th of a
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
558 * second. It decides which functions of the deamon need to be run.
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
559 */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
560
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
561 void
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
562 move()
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
563 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
564 static int oldtourn = 0; /* are we in t-mode or not */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
565 int i, j; /* looping vars */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
566 struct planet *pl;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
567
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
568 if (++ticks == dietime)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
569 { /* no player for 1 minute. kill self */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
570 if (debug) /* do not quit if debug mode */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
571 fprintf(stderr, "Ho hum. 1 minute, no activity...\n");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
572 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
573 { /* quit if not debug mode */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
574 fprintf(stderr, "Self-destructing the daemon!\n");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
575 freemem(0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
576 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
577 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
578
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
579 if ((FUSE(300)) && update_sys_defaults()) /* check to load system
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
580 * defualts */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
581 /* This message tells players that new defaults have been */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
582 /* loaded and the message triggers the ntserv processes */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
583 /* to check new defaults. */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
584 pmessage("Loading new server configuration.", 0, MALL, MSERVA);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
585
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
586 if (FUSE(SECONDS(1)))
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
587 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
588 if (tournamentMode())
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
589 { /* are we in tournament mode */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
590 if (!oldtourn)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
591 { /* is this a new condition */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
592 if (!status2->starttourn)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
593 { /* fresh t-mode */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
594 if (configvals->gamestartnuke)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
595 explode_everyone(KTOURNSTART, 20);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
596 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
597 status2->starttourn = configvals->nottimeout ? configvals->nottimeout : -1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
598 warmessage(); /* go print war message */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
599 for (i = 0, pl = &planets[i]; i < NUMPLANETS; i++, pl++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
600 for (j = 0; j < MAXTEAM + 1; j++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
601 pl->pl_tinfo[j].timestamp = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
602 status->clock = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
603 tourntimestamp = ticks; /* take a timestamp */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
604 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
605 oldtourn = 1; /* record that we have printed warmsg */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
606 status->tourn = 1; /* set the game status to t-mode */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
607 status->time++; /* inc time in t-mode */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
608 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
609 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
610 { /* else we are not in t-mode */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
611 if (oldtourn)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
612 { /* if previously in t-mode */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
613 tourntimestamp = ticks; /* record t-mode ending */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
614 peacemessage(); /* send peace message */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
615 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
616 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
617 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
618 static fuse = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
619 fuse++;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
620 if (fuse > 60 && status2->starttourn > 0)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
621 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
622 fuse = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
623 status2->starttourn--;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
624 switch (status2->starttourn)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
625 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
626 case 0:
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
627 status2->newgalaxy = 1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
628 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
629 case 1:
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
630 case 3:
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
631 case 5:
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
632 case 15:
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
633 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
634 static char buf[120];
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
635 sprintf(buf, "Warning!! Galaxy will be reset in %d minute%s due to inactivity.", status2->starttourn, (status2->starttourn == 1) ? "" : "s");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
636 pmessage(buf, 0, MALL, MSERVA);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
637 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
638 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
639 pmessage("Warning!! Galaxy will be reset in one minute due to inactivity.", 0, MALL, MSERVA);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
640 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
641 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
642 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
643 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
644 oldtourn = 0; /* set we are not in t-mode */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
645 status->tourn = 0; /* record in stats */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
646 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
647 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
648
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
649 #if 0
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
650 if (status->nukegame)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
651 { /* if daemon should die then */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
652 freemem(0); /* nuke shared memory */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
653 exit(0); /* kill daemon */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
654 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
655 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
656
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
657 parse_godmessages(); /* log any messages to god */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
658
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
659 #ifdef LEAGUE_SUPPORT
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
660 handle_pause_goop(); /* print any messages related to pausing the
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
661 * game */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
662 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
663
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
664 #ifdef LEAGUE_SUPPORT
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
665 if (!status2->paused)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
666 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
667 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
668 if (FUSE(PLAYERFUSE)) /* time to update players? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
669 udplayers();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
670
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
671 if (FUSE(TORPFUSE)) /* time to update torps? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
672 udtorps();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
673 if (FUSE(MISSILEFUSE)) /* time to update missiles? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
674 udmissiles();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
675 if (FUSE(PLASMAFUSE)) /* time to update plasma? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
676 udplasmatorps();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
677 if (FUSE(PHASERFUSE)) /* time to update phasers? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
678 udphaser();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
679
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
680
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
681 if (FUSE(CLOAKFUSE)) /* time to update cloaking? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
682 udcloak();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
683
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
684 if (FUSE(TEAMFUSE)) /* time to update team timers? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
685 teamtimers();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
686
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
687 if (FUSE(PLFIGHTFUSE)) /* time to update planets? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
688 plfight();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
689
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
690 if (FUSE(TERRAINFUSE)) /* time to do terrain effects? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
691 doTerrainEffects();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
692
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
693 if (FUSE(BEAMFUSE)) /* time to update beaming */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
694 beam();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
695
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
696 if (FUSE(SYNCFUSE)) /* time to save planets? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
697 save_planets();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
698
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
699
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
700 if (FUSE(topgun ? HOSEFUSE2 : HOSEFUSE)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
701 #if !defined(AEDILE) || !defined(IGGY_IN_T)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
702 && status->tourn != 1 /* no Iggy during T-mode */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
703 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
704 #ifdef LEAGUE_SUPPORT
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
705 && status2->league == 0
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
706 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
707 ) /* no Iggy during league games */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
708 rescue(HUNTERKILLER, 0, -1); /* send in iggy-- no team, no target */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
709
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
710 if (status->tourn)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
711 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
712 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
713 static int spinner = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
714
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
715 for (spinner += configvals->popspeed; spinner >= 100; spinner -= 100)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
716 popplanets(); /* increase population */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
717 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
718
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
719 if (FUSE(PLANETFUSE)) /* time to grow resources */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
720 growplanets();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
721
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
722 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
723 /*
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
724 * check for revolts. Each planet is checked on average once every
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
725 * PLANETFUSE.
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
726 */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
727 static int spinner = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
728 for (spinner += configvals->numplanets;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
729 spinner >= PLANETFUSE;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
730 spinner -= PLANETFUSE)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
731 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
732 check_revolt();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
733 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
734 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
735 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
736 /* planet moving */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
737 if (configvals->planupdspd > 0 && FUSE(4))
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
738 moveplanets();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
739
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
740 if (FUSE(MINUTEFUSE) && status->tourn)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
741 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
742
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
743 shipbuild_timers();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
744
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
745 #ifdef LEAGUE_SUPPORT
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
746 if (!status2->league)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
747 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
748 udsurrend(); /* update surrender every minute unless
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
749 * playing league */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
750
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
751 status->clock++; /* increment the timestamp clock */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
752
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
753 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
754 /* update the tournament clock, maybe print messages */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
755 #ifdef LEAGUE_SUPPORT
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
756 udtourny();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
757 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
758 } /* end if !paused */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
759
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
760 if (FUSE(MINUTEFUSE))
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
761 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
762 int i, c;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
763 c = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
764 for (i = 0; i < MAXPLAYER; i++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
765 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
766 if (players[i].p_status != PFREE)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
767 c++;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
768 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
769 #ifdef COUNTFILENAME
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
770 if (c)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
771 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
772 char *paths;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
773 FILE *logfile;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
774 paths = build_path(COUNTFILENAME);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
775 logfile = fopen(paths, "a");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
776 if (logfile)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
777 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
778 struct tm *tp;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
779 char buf[50];
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
780 time_t cal;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
781
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
782 cal = time(0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
783 tp = localtime(&cal);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
784 strftime(buf, 50, "%m/%d %H:%M", tp);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
785
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
786 fprintf(logfile, "%s : %2d ", buf, c);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
787 for (i = 0; i < c; i++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
788 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
789 putc('*', logfile);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
790 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
791 putc('\n', logfile);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
792 fclose(logfile);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
793 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
794 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
795 #else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
796 #ifdef UFL
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
797 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
798 char *paths;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
799 FILE *logfile;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
800 paths = build_path(LOGFILENAME);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
801 logfile = fopen(paths, "a");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
802 if (logfile)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
803 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
804 fprintf(logfile, "Count: %d players\n", c);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
805 fclose(logfile);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
806 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
807 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
808 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
809 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
810 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
811
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
812 #if 0
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
813 /* well, this may cause blocked pipes if too many */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
814 /* processes, the file said before I hacked it. */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
815 /* So this is disabled. */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
816 if (FUSE(CHECKLOADFUSE)) /* time to check load? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
817 check_load();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
818 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
819
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
820
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
821 if (status2->newgalaxy)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
822 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
823
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
824 /* Disable the game timer. It'll be set again after the longjmp() */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
825 stoptimer();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
826
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
827 status2->nontteamlock = ALLTEAM; /* allow all teams again */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
828 status2->starttourn = 0; /* fresh galaxy */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
829
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
830 gen_planets();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
831
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
832 for (i = 0; i < MAXPLAYER; i++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
833 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
834 galaxyValid[i] = 0; /* force download of new galaxy map */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
835 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
836 longjmp(env, 0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
837 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
838 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
839
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
840
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
841 sig_ret_t
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
842 freemem(sig)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
843 int sig;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
844 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
845 register int i;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
846 register struct player *j;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
847
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
848 if (sig)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
849 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
850 fprintf(stderr, "Daemon: Caught signal %d\n", sig);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
851 /* U_STACK_TRACE(); */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
852 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
853
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
854 /* Blow players out of the game */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
855 for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
856 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
857 j->p_status = POUTFIT;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
858 j->p_whydead = KDAEMON;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
859 j->p_ntorp = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
860 j->p_nplasmatorp = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
861 j->p_explode = 600 / PLAYERFUSE; /* ghost buster was leaving players
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
862 * in */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
863 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
864 /* Kill waiting players */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
865 status->gameup = 0; /* say goodbye to xsg et. al. 4/10/92 TC */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
866 status->count = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
867 save_planets();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
868 sleep(2);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
869 blast_shmem();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
870 exit(0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
871 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
872
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
873
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
874 void
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
875 check_load()
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
876 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
877 #ifndef hpux /* breaks under hpux... it's fixable, though */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
878 FILE *fp, *popen();
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
879 char buf[100];
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
880 char *s;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
881 float load;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
882
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
883 #if defined(SYSV) || defined(Linux) || defined(FreeBSD)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
884 #if defined(sgi)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
885 fp = popen("/usr/bsd/uptime", "r"); /* sigh. */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
886 #else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
887 fp = popen("/usr/bin/uptime", "r");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
888 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
889 #else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
890 fp = popen("/usr/ucb/uptime", "r");
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
891 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
892 if (fp == NULL)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
893 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
894 /* status->gameup=0; */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
895 return;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
896 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
897 fgets(buf, 99, fp);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
898 s = strrchr(buf, ':');
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
899 if (s == NULL)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
900 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
901 /* status->gameup=0; */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
902 pclose(fp);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
903 return;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
904 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
905 if (sscanf(s + 1, " %f", &load) == 1)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
906 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
907 sprintf(buf, "NetrekII (Paradise), %s", PARAVERS);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
908 pmessage(buf, 0, MALL, MSERVA);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
909 if (load >= configvals->maxload && status->gameup == 1)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
910 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
911 status->gameup = 0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
912 sprintf(buf, "The load is %f, this game is going down", load);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
913 pmessage(buf, 0, MALL, MSERVA);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
914 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
915 else if (load < configvals->maxload && status->gameup == 0)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
916 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
917 status->gameup = 1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
918 sprintf(buf, "The load is %f, this game is coming up", load);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
919 pmessage(buf, 0, MALL, MSERVA);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
920 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
921 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
922 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
923 sprintf(buf, "Load check: %-7.2f", load);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
924 buf[strlen(buf) - 1] = '\0';
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
925 pmessage(buf, 0, MALL, MSERVA);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
926 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
927 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
928 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
929 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
930 /* status->gameup=0; */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
931 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
932 r_signal(SIGCHLD, SIG_DFL);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
933 pclose(fp);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
934 r_signal(SIGCHLD, reaper);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
935 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
936 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
937
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
938 void
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
939 ghostmess(victim)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
940 struct player *victim;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
941 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
942 char buf[80];
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
943 static float ghostkills = 0.0;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
944 int i, k;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
945
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
946 ghostkills += 1.0 + victim->p_armies * 0.1 + victim->p_kills * 0.1;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
947 sprintf(buf, "%s (%s) was kill %0.2f for the GhostBusters",
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
948 victim->p_name, twoletters(victim),
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
949 ghostkills);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
950 pmessage(buf, 0, MALL, MSERVA);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
951 #if 1
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
952 if (victim->p_armies > 0)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
953 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
954 k = 10 * (remap[victim->p_team] - 1);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
955 if (k >= 0 && k <= 30)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
956 for (i = 0; i < 10; i++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
957 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
958 if (planets[i + k].pl_owner == victim->p_team)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
959 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
960 planets[i + k].pl_armies += victim->p_armies;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
961 sprintf(buf, "%s's %d armies placed on %s",
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
962 victim->p_name, victim->p_armies, planets[k + i].pl_name);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
963 pmessage(buf, 0, MALL | MGHOST, MSERVA);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
964 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
965 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
966 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
967 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
968 #else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
969 if (victim->p_armies > 0)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
970 PlaceLostArmies(victim); /* not working yet */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
971 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
972 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
973
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
974 void
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
975 saveplayer(victim)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
976 struct player *victim;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
977 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
978 int fd;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
979 char *paths;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
980
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
981 if (victim->p_pos < 0)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
982 return;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
983 if (victim->p_stats.st_lastlogin == 0)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
984 return;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
985 #ifndef ROBOTSTATS
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
986 if (victim->p_flags & PFROBOT)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
987 return;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
988 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
989
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
990 paths = build_path(PLAYERFILE);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
991 fd = open(paths, O_WRONLY, 0644);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
992 if (fd >= 0)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
993 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
994 lseek(fd, 32 + victim->p_pos * sizeof(struct statentry), 0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
995 write(fd, (char *) &victim->p_stats, sizeof(struct stats));
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
996 close(fd);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
997 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
998 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
999
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1000
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1001 /* Send in a robot to avenge the aggrieved team */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1002 /* -1 for HK, -2 for Terminator, -3 for sticky Terminator */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1003
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1004 /* if team in { FED, ROM, KLI, ORI }, a nonzero target means "fleet" mode */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1005 /* CRD feature: number (or -1) for starting planet - MAK, 2-Jun-93 */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1006
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1007 void
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1008 rescue(team, target, planet)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1009 int team;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1010 int target;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1011 int planet;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1012 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1013 char *arg1, argp[5];
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1014 int pid;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1015 char *paths; /* added 1/18/93 KAO */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1016
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1017 #ifdef LEAGUE_SUPPORT
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1018 if (status2->league)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1019 return; /* no robots during league play */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1020 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1021
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1022 sprintf(argp, "-S%d", planet);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1023
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1024 if ((pid = fork()) == 0)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1025 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1026 /* underscore is just a place holder */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1027 static char termbuf[] = "-Tt_";
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1028 if (!debug)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1029 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1030 close(0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1031 close(1);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1032 close(2);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1033 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1034 r_signal(SIGALRM, SIG_DFL);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1035 paths = build_path(ROBOT);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1036 switch (team)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1037 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1038 case FED:
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1039 arg1 = "-Tf";
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1040 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1041 case ROM:
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1042 arg1 = "-Tr";
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1043 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1044 case KLI:
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1045 arg1 = "-Tk";
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1046 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1047 case ORI:
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1048 arg1 = "-To";
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1049 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1050 case HUNTERKILLER:
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1051 arg1 = "-Ti"; /* -1 means independent robot */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1052 if (!debug)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1053 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1054 execl(paths, "robot", arg1, "-P", argp, 0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1055 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1056 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1057 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1058 execl(paths, "robot", arg1, "-P", argp, "-d", 0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1059 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1060 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1061 case TERMINATOR: /* Terminator */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1062 arg1 = termbuf;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1063 arg1[3] = twoletters(&players[target])[1];
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1064 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1065 case STERMINATOR: /* sticky Terminator */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1066 arg1 = termbuf;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1067 arg1[3] = twoletters(&players[target])[1];
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1068 if (!debug)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1069 execl(paths, "robot", arg1, "-s", argp, 0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1070 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1071 execl(paths, "robot", arg1, "-s", argp, "-d", 0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1072 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1073 default:
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1074 arg1 = "-Ti";
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1075 break;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1076 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1077 if (target > 0) /* be fleet 8/28/91 TC */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1078 execl(paths, "robot", arg1, "-f", argp, 0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1079 else if (!debug)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1080 { /* Make these fleet, too - MAK, 4-Jun-93 */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1081 execl(paths, "snake", arg1, argp, 0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1082 /* execl (paths, "robot", arg1, "-f", argp, 0); */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1083 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1084 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1085 { /* Make these fleet, too - MAK, 4-Jun-93 */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1086 execl(paths, "snake", arg1, argp, "-d", 0);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1087 /* execl (paths, "snake", arg1, "-f", argp, "-d", 0); */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1088 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1089 /* If we get here, we are hosed anyway */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1090 fprintf(stderr, "Failed to exec robot %s.\n", paths);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1091 exit(1);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1092 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1093 else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1094 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1095 if (debug)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1096 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1097 fprintf(stderr, "Forking robot: pid is %d\n", pid);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1098 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1099 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1100 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1101
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1102 #include <sys/resource.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1103
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1104 /* ARGSUSED */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1105
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1106 /* Don't fear the ... */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1107
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1108 sig_ret_t
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1109 reaper(sig)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1110 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1111 static int status;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1112 static int pid;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1113
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1114 #ifndef SVR4
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1115 while ((pid = wait3((union wait *) & status, WNOHANG, (struct rusage *) 0)) > 0)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1116 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1117 #else /* note: no status info */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1118 while ((pid = waitpid(0, 0, WNOHANG)) > 0)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1119 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1120 #endif /* SVR4 */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1121 if (debug)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1122 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1123 fprintf(stderr, "Reaping: pid is %d (status: %X)\n",
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1124 pid, status);
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1125 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1126 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1127 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1128
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1129 unsigned char
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1130 getcourse(x, y, xme, yme)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1131 int x, y, xme, yme;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1132 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1133 return ((unsigned char) (int) (atan2((double) (x - xme),
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1134 (double) (yme - y)) / 3.14159 * 128.));
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1135 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1136
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1137 int tm_robots[MAXTEAM + 1]; /* To limit the number of robots */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1138
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1139 void
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1140 teamtimers()
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1141 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1142 register int i;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1143 for (i = 0; i <= MAXTEAM; i++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1144 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1145 if (tm_robots[i] > 0)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1146 tm_robots[i]--;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1147 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1148 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1149
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1150 void
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1151 shipbuild_timers()
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1152 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1153 int i, t;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1154
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1155 for (i = 0; i <= MAXTEAM; i++)/* go through all teams */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1156 for (t = 0; t < NUM_TYPES; t++) /* and each ship type */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1157 if (teams[i].s_turns[t] > 0) /* and if need be, then dec */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1158 teams[i].s_turns[t]--; /* the construction timer */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1159 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1160
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1161
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1162 #undef D