annotate src/shmem.c @ 19:de685799a432

Made torps wobbly when going through nebulous terrain. Only happens if nebula_effect contains photon.
author darius
date Wed, 24 Dec 1997 12:40:04 +0000
parents 8c6d5731234d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1 /*--------------------------------------------------------------------------
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
2 NETREK II -- Paradise
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
3
8c6d5731234d 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
8c6d5731234d 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
8c6d5731234d 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
8c6d5731234d 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
8c6d5731234d 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
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
9 "as is" without express or implied warranty.
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
10
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
11 Xtrek Copyright 1986 Chris Guthrie
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
13 Scott Silvey
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
15 Kurt Olsen
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
16 Brandon Gillespie
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
17 --------------------------------------------------------------------------*/
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
18
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
19 #include "config.h"
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
20 #include <stdio.h>
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
21 #include <sys/types.h>
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
22 #include <sys/ipc.h>
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
23 #include <sys/shm.h>
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
24 #include <errno.h>
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
25 #include <signal.h>
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
26
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
27 #include "shmem.h"
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
28 #include "path.h"
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
29 #include "data.h"
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
30
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
31 /*---------------------------SHARED MEMORY STRUCTURE----------------------*/
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
32
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
33 #include "shmemP.h"
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
34
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
35 /*-------------------------------------------------------------------------*/
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
36
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
37 struct player *players;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
38 struct torp *torps;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
39 struct missile *missiles;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
40 struct thingy *thingies;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
41 struct plasmatorp *plasmatorps;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
42 struct status *status;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
43 struct status2 *status2;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
44 struct planet *planets;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
45 struct t_unit *terrain_grid;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
46 struct phaser *phasers;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
47 int *stars;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
48 struct mctl *mctl;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
49 struct message *messages;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
50 struct team *teams;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
51
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
52 struct ship *shipvals;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
53 struct configuration *configvals;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
54 int *shipsallowed; /* points inside configvals */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
55 int *weaponsallowed; /* ditto */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
56 int *sun_effect;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
57 int *ast_effect;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
58 int *neb_effect;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
59 int *wh_effect;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
60 int *num_nebula;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
61 int *nebula_density;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
62 int *nebula_subclouds;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
63 int *num_asteroid;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
64 float *asteroid_thickness;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
65 int *asteroid_density;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
66 int *asteroid_radius;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
67 float *asteroid_thick_variance;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
68 int *asteroid_dens_variance;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
69 int *asteroid_rad_variance;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
70 int *improved_tracking;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
71 int *tstart;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
72 int *newgalaxy;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
73 int *nontteamlock;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
74 char *cluephrase_storage;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
75
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
76 static int PKEY = 128;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
77
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
78 /*------------------------------STARTDAEMON---------------------------------*/
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
79 /*
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
80 * This function starts the daemon. It get the path to where the daemon
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
81 * resides, then tries to start it up.
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
82 */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
83
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
84
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
85 #ifndef SYSV /* HP/UX hates this */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
86 extern int fprintf();
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
87 #endif
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
88 extern pid_t fork();
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
89 extern int execl();
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
90 extern void perror();
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
91 extern int shmget();
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
92 #ifndef IRIX
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
93 extern int shmctl();
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
94 #endif
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
95 extern unsigned int sleep();
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
96 extern uid_t geteuid();
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
97
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
98 void
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
99 startdaemon(leagueflag, restart)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
100 int leagueflag, restart;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
101 {
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
102 int i; /* temp var */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
103 char *hell; /* to hold path to daemon */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
104
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
105 if (restart)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
106 {
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
107 fprintf(stderr, "RE-");
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
108 kill(status->nukegame, SIGKILL); /* daemon is killed without giving it
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
109 * a chance to blast the shmem */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
110 sleep(2);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
111 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
112 fprintf(stderr, "Starting daemon...\n"); /* record that deaemon is */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
113 i = fork(); /* starting */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
114 if (i == 0)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
115 { /* if successful */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
116 char *nargv[10];
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
117 int argc = 0;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
118 hell = build_path(DAEMON);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
119 nargv[argc++] = "daemon";
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
120 if (leagueflag)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
121 nargv[argc++] = "-l";
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
122 if (restart)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
123 nargv[argc++] = "-a";
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
124 nargv[argc] = 0;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
125 execv(hell, nargv);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
126
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
127 perror(hell); /* did it work */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
128 fprintf(stderr, "Couldn't start daemon!!!\n");
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
129 _exit(1); /* let's get out of here */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
130 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
131 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
132
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
133
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
134
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
135 static int shmid = -1; /* ID number of shared mem */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
136
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
137
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
138 /*--------------------------------OPENMEM----------------------------------*/
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
139 /*
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
140 * if code is 0, openmem will exit(1) upon finding the memory gone. if code
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
141 * is 1, openmem will fork a netrek daemon and retry. if code is 2, openmem
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
142 * will blast any already existing shared memory.
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
143 */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
144
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
145 void
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
146 openmem(code, leagueflag)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
147 int code;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
148 int leagueflag; /* only used if code==1 */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
149 {
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
150 extern int errno; /* to get error number */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
151 key_t shmemKey = PKEY; /* shared memory's key */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
152 struct memory *sharedMemory; /* to point to shared memory */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
153 char *k;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
154
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
155 k = getenv("TREKSHMKEY"); /* grab shared mem id environment variable */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
156 if (k)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
157 { /* if it's set... */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
158 int i;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
159 if (sscanf(k, "%d", &i) > 0 && i > 0) /* ...grab its value... */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
160 shmemKey = i; /* ...and use it */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
161 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
162
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
163 errno = 0; /* clear error number */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
164 shmid = shmget(shmemKey, 0, 0); /* get id of shared mem */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
165 if (code == 2)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
166 {
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
167 if (shmid >= 0)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
168 {
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
169 /* If we're in daemon mode and we opened the memory */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
170 /* "There can be only one". */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
171 fprintf(stderr, "Killing existing segment\n");
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
172 shmctl(shmid, IPC_RMID, (struct shmid_ds *) 0);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
173 /* create a new one */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
174 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
175 shmid = shmget(shmemKey, sizeof(struct memory), IPC_CREAT | 0666);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
176 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
177 if (shmid < 0)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
178 { /* if shared mem does not exist */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
179 switch (code)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
180 {
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
181 case 0:
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
182 if (errno != ENOENT)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
183 { /* catastrophic, sell all your stock */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
184 perror("shmget"); /* and leave the country type of */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
185 exit(1); /* error--suicide */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
186 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
187 fprintf(stderr, "Daemon not running (err:%d)\n", errno);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
188 exit(1);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
189 case 1:
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
190 if (errno != ENOENT)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
191 { /* catastrophic, sell all your stock */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
192 perror("shmget"); /* and leave the country type of */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
193 exit(1); /* error--suicide */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
194 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
195 startdaemon(leagueflag, 0); /* try to start the daemon */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
196 sleep(2); /* wait for a sec for deamon to start */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
197 shmid = shmget(shmemKey, 0, 0); /* try again to get shared mem */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
198 if (shmid < 0)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
199 { /* failure again then get out of here */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
200 fprintf(stderr, "Daemon not running (err:%d)\n", errno);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
201 exit(1);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
202 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
203 break;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
204 case 2:
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
205 perror("daemon: can't open shared memory");
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
206 exit(1);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
207 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
208 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
209 if (code == 2)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
210 {
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
211 struct shmid_ds smbuf;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
212
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
213 shmctl(shmid, IPC_STAT, &smbuf); /* Hose Ed's robots */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
214 smbuf.shm_perm.uid = geteuid();
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
215 smbuf.shm_perm.mode = 0666;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
216 shmctl(shmid, IPC_SET, &smbuf);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
217 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
218 sharedMemory = (struct memory *) shmat(shmid, (char *) 0, 0);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
219 if (sharedMemory == (struct memory *) - 1)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
220 {
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
221 perror("shared memory");
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
222 exit(1);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
223 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
224 if (code == 2)
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
225 {
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
226 /* set the magic number */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
227 sharedMemory->shmem_size = sizeof(struct memory);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
228 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
229 else
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
230 {
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
231 if (sharedMemory->shmem_size != sizeof(struct memory))
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
232 {
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
233 fprintf(stderr, "shared memory segment magic number mismatch!\
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
234 (%d != %ld)\n aborting to prevent corruption of game data\n",
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
235 sharedMemory->shmem_size, (long) sizeof(struct memory));
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
236 exit(1);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
237 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
238 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
239 players = sharedMemory->players; /* set pointer to fields */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
240 torps = sharedMemory->torps; /* in shared memory structure */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
241 missiles = sharedMemory->missiles; /* for easy access */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
242 thingies = sharedMemory->thingies;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
243 plasmatorps = sharedMemory->plasmatorps;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
244 status = &sharedMemory->status;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
245 status2 = &sharedMemory->status2;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
246 planets = sharedMemory->planets;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
247 terrain_grid = sharedMemory->terrain_grid;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
248 phasers = sharedMemory->phasers;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
249 stars = sharedMemory->stars;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
250 mctl = &sharedMemory->mctl;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
251 messages = sharedMemory->messages;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
252 teams = sharedMemory->teams;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
253 shipvals = sharedMemory->shipvals;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
254 configvals = &sharedMemory->configvals;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
255 galaxyValid = &sharedMemory->galaxyValid;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
256 /* configvals->gwidth = 200000; *//* pick up from galaxy generator later */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
257 /* configvals->numplanets = 60; *//* this too */
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
258
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
259 shipsallowed = configvals->shipsallowed;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
260 weaponsallowed = configvals->weaponsallowed;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
261 sun_effect = configvals->sun_effect;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
262 ast_effect = configvals->ast_effect;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
263 neb_effect = configvals->neb_effect;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
264 wh_effect = configvals->wh_effect;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
265 num_nebula = &(configvals->num_nebula);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
266 nebula_density = &(configvals->nebula_density);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
267 nebula_subclouds = &(configvals->nebula_subclouds);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
268 num_asteroid = &(configvals->num_asteroid);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
269 asteroid_thickness = &(configvals->asteroid_thickness);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
270 asteroid_density = &(configvals->asteroid_density);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
271 asteroid_radius = &(configvals->asteroid_radius);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
272 asteroid_thick_variance = &(configvals->asteroid_thick_variance);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
273 asteroid_dens_variance = &(configvals->asteroid_dens_variance);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
274 asteroid_rad_variance = &(configvals->asteroid_rad_variance);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
275 improved_tracking = configvals->improved_tracking;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
276
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
277 cluephrase_storage = sharedMemory->cluephrase_storage;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
278
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
279 stars[1] = -1;
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
280 }
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
281
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
282 void
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
283 blast_shmem()
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
284 {
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
285 shmctl(shmid, IPC_RMID, (struct shmid_ds *) 0);
8c6d5731234d First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
286 }