8
|
1 /*--------------------------------------------------------------------------
|
|
2 NETREK II -- Paradise
|
|
3
|
|
4 Permission to use, copy, modify, and distribute this software and its
|
|
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL
|
|
6 purpose and without fee is hereby granted, provided that this copyright
|
|
7 notice appear in all copies. No representations are made about the
|
|
8 suitability of this software for any purpose. This software is provided
|
|
9 "as is" without express or implied warranty.
|
|
10
|
|
11 Xtrek Copyright 1986 Chris Guthrie
|
|
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
|
|
13 Scott Silvey
|
|
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
|
|
15 Kurt Olsen
|
|
16 Brandon Gillespie
|
|
17 --------------------------------------------------------------------------*/
|
|
18
|
|
19 #include "config.h"
|
|
20
|
|
21 #include <stdio.h>
|
|
22 #include "data.h"
|
|
23 #include "defs.h"
|
|
24 #include "shmem.h"
|
|
25 #include "tool-util.h"
|
|
26
|
|
27 /* ------------------------------------------------------------------- */
|
|
28 char *statnames[] = {"F", "O", "A", "E", "D", "Q"};
|
|
29
|
|
30 char *oldranknames[] = {
|
|
31 "Ensign", "Lieutenan",
|
|
32 "Lt. Cmdr.", "Commander",
|
|
33 "Captain", "Flt. Capt",
|
|
34 "Commodore", "Rear Adml",
|
|
35 "Admiral"
|
|
36 };
|
|
37
|
|
38 char *oldshiptypes[] = {"SC", "DD", "CA", "BB", "AS", "SB"};
|
|
39
|
|
40 /* ------------------------------------------------------------------- */
|
|
41 char *maprank(struct player * p);
|
|
42 char *mapshiptype(struct player * p);
|
|
43 char *mapname(char *s);
|
|
44 char *fillcH(int width, char fchar);
|
|
45 char *typestat(struct player * p);
|
|
46
|
|
47 /* -------------------------------[ Main ]----------------------------- */
|
|
48 main(int argc, char **argv)
|
|
49 {
|
|
50 int mode;
|
|
51 char monitor[17];
|
|
52 char fh[33];
|
|
53 int teams[9];
|
|
54 int i, count;
|
|
55 struct player *j;
|
|
56 int usage = 0;
|
|
57
|
|
58 argv0 = argv[0];
|
|
59
|
|
60 if (argc > 1)
|
|
61 {
|
|
62 if (argv[1][0] != '-')
|
|
63 {
|
|
64 usage++;
|
|
65 }
|
|
66 else
|
|
67 {
|
|
68 switch (argv[1][1])
|
|
69 {
|
|
70 case 'h':
|
|
71 usage++;
|
|
72 break;
|
|
73 case 'd':
|
|
74 case 'r':
|
|
75 case 'l':
|
|
76 case 'o':
|
|
77 case 'M':
|
|
78 case 'p':
|
|
79 mode = argv[1][1];
|
|
80 break;
|
|
81 default:
|
|
82 usage++;
|
|
83 break;
|
|
84 }
|
|
85 }
|
|
86 }
|
|
87 else
|
|
88 {
|
|
89 mode = '\0';
|
|
90 }
|
|
91
|
|
92 if (usage)
|
|
93 {
|
|
94 char *message[255] = {
|
|
95 "\n\t'%s [option]'\n",
|
|
96 "\nOptions:\n",
|
|
97 "\t-h help (this usage description)\n",
|
|
98 "\t-d Damage Status.\n",
|
|
99 "\t-r ?\n",
|
|
100 "\t-l Lag Statistics\n",
|
|
101 "\t-o Old style (NetrekI Ranks/ships)\n",
|
|
102 "\t-M Default (Metaserver)\n",
|
|
103 "\t-p PID\n\n",
|
|
104 "\0"
|
|
105 };
|
|
106
|
|
107 fprintf(stderr, "-- NetrekII (Paradise), %s --\n", PARAVERS);
|
|
108 for (i = 0; *message[i] != '\0'; i++)
|
|
109 fprintf(stderr, message[i], argv0);
|
|
110
|
|
111 exit(1);
|
|
112 }
|
|
113
|
|
114 openmem(0);
|
|
115
|
|
116 for (count = 0, i = 0, j = players; i < MAXPLAYER; i++, j++)
|
|
117 {
|
|
118 if (j->p_status == PFREE)
|
|
119 continue;
|
|
120 count++;
|
|
121 }
|
|
122
|
|
123 if (!count)
|
|
124 {
|
|
125 printf("No one is playing.\n");
|
|
126 exit(0);
|
|
127 }
|
|
128
|
|
129 for (i = 0; i < 9; i++)
|
|
130 teams[i] = 0;
|
|
131
|
|
132 for (i = 0, j = players; i < MAXPLAYER; i++, j++)
|
|
133 {
|
|
134 if (j->p_status == PFREE)
|
|
135 {
|
|
136 continue;
|
|
137 }
|
|
138 teams[j->p_team]++;
|
|
139 }
|
|
140
|
|
141 /* print the header #1 */
|
|
142 printf("--==[ %d Player%s", count,
|
|
143 (count == 1 ? " ]=====[" : (count > 9 ? "s ]===[" : "s ]====[")));
|
|
144 printf(" Feds: %d ]=[ Roms: %d ]=[ Kli: %d ]=[ Ori: %d ]=====--\n",
|
|
145 teams[FED], teams[ROM], teams[KLI], teams[ORI]);
|
|
146
|
|
147 /* print the header #2 */
|
|
148 switch (mode)
|
|
149 {
|
|
150 case 'd':
|
|
151 printf("--==[ Name ]=========[ Type Kills Damage Shields Armies Fuel ]======--\n");
|
|
152 break;
|
|
153 case 'r':
|
|
154 printf("--==[ Name ]=========[ Status Type Genocides MaxKills DI ]====--\n");
|
|
155 break;
|
|
156 case 'l':
|
|
157 printf("--==[ Name ]============[ Average Stnd Dev Loss ]==================--\n");
|
|
158 break;
|
|
159 case 'M':
|
|
160 case 'o':
|
|
161 case '\0':
|
|
162 printf("--=======[ Rank ]====[ Name ]=========[ Address ]======================--\n");
|
|
163 break;
|
|
164 case 'p':
|
|
165 printf("--========[ PID ]===[ Name ]==========[ Address ]======================--\n");
|
|
166 break;
|
|
167 }
|
|
168
|
|
169 for (i = 0, j = players; i < MAXPLAYER; i++, j++)
|
|
170 {
|
|
171 if (j->p_status == PFREE)
|
|
172 {
|
|
173 continue;
|
|
174 }
|
|
175 switch (mode)
|
|
176 {
|
|
177 case 'd':
|
|
178 printf(" %2s: %-16s %2s %6.2f %6d %7d %6d %6d\n",
|
|
179 twoletters(j), j->p_name,
|
|
180 typestat(j),
|
|
181 j->p_kills,
|
|
182 j->p_damage,
|
|
183 j->p_shield,
|
|
184 j->p_armies,
|
|
185 j->p_fuel);
|
|
186 break;
|
|
187 case 'r':
|
|
188 printf(" %2s: %-16s %s/%-4d %2s %7d %9.1f %10.2f\n",
|
|
189 twoletters(j),
|
|
190 j->p_name,
|
|
191 statnames[j->p_status],
|
|
192 j->p_ghostbuster,
|
|
193 typestat(j),
|
|
194 j->p_stats.st_genocides,
|
|
195 j->p_stats.st_tmaxkills,
|
|
196 j->p_stats.st_di);
|
|
197 break;
|
|
198 case 'l':
|
|
199 printf(" %2s: %-16s %7d ms %7d ms %5d%%\n",
|
|
200 twoletters(j),
|
|
201 j->p_name,
|
|
202 j->p_avrt,
|
|
203 j->p_stdv,
|
|
204 j->p_pkls);
|
|
205 break;
|
|
206 case 'o':
|
|
207 if (i > 19)
|
|
208 continue; /* show only first 20 */
|
|
209
|
|
210 strncpy(fh, j->p_full_hostname, 32);
|
|
211 fh[32] = 0;
|
|
212 printf(" %2s: %2s %-9.9s %-16s %s@%s\n",
|
|
213 twoletters(j), mapshiptype(j), maprank(j),
|
|
214 mapname(j->p_name), j->p_login, fh);
|
|
215 break;
|
|
216 case 'p':
|
|
217 strncpy(fh, j->p_full_hostname, 32);
|
|
218 fh[32] = 0;
|
|
219 printf(" %c%2s: %2s %-9d %-16s %s@%s\n",
|
|
220 (j->p_stats.st_flags & ST_CYBORG) ? '*' : ' ',
|
|
221 twoletters(j), typestat(j),
|
|
222 j->p_ntspid,
|
|
223 j->p_name,
|
|
224 j->p_login,
|
|
225 fh);
|
|
226 break;
|
|
227 case 'M':
|
|
228 case '\0':
|
|
229 strncpy(fh, j->p_full_hostname, 32);
|
|
230 fh[32] = 0;
|
|
231 printf(" %c%2s: %2s %-11.11s %-16s %s@%s\n",
|
|
232 (j->p_stats.st_flags & ST_CYBORG) ? '*' : ' ',
|
|
233 twoletters(j), typestat(j),
|
|
234 j->p_stats.st_royal ? royal[j->p_stats.st_royal].name
|
|
235 : ranks[j->p_stats.st_rank].name,
|
|
236 j->p_name,
|
|
237 j->p_login,
|
|
238 fh);
|
|
239 break;
|
|
240 }
|
|
241 }
|
|
242
|
|
243 printf("--==[ NetrekII (Paradise), %s ]%s--\n", PARAVERS, fillcH((63 - strlen(PARAVERS)), '='));
|
|
244 }
|
|
245
|
|
246 /* ---------------------------[ Functions ]--------------------------- */
|
|
247
|
|
248 /*
|
|
249 * map rank into one of the original netrek rank names for compatibility with
|
|
250 * the metaserver
|
|
251 */
|
|
252 char *
|
|
253 maprank(struct player * p)
|
|
254 {
|
|
255 int r;
|
|
256
|
|
257 r = (int) (10 * (p->p_stats.st_rank / (float) NUMRANKS));
|
|
258 if (r < 0)
|
|
259 r = 0;
|
|
260 if (r > 8)
|
|
261 r = 8;
|
|
262 return oldranknames[r];
|
|
263 }
|
|
264
|
|
265 char *
|
|
266 mapshiptype(struct player * p)
|
|
267 {
|
|
268 int n;
|
|
269
|
|
270 n = p->p_ship.s_alttype;
|
|
271 if (n > 5)
|
|
272 n = 5;
|
|
273
|
|
274 return oldshiptypes[n];
|
|
275 }
|
|
276
|
|
277 char *
|
|
278 mapname(char *s)
|
|
279 {
|
|
280 char newname[17];
|
|
281
|
|
282 if (*s == ' ')
|
|
283 {
|
|
284 strncpy(newname, s, 16);
|
|
285 newname[0] = '_';
|
|
286 return newname;
|
|
287 }
|
|
288 else
|
|
289 return s;
|
|
290 }
|
|
291
|
|
292 /* fills with fchar up to width (width must be less than 255) */
|
|
293 char *
|
|
294 fillcH(int width, char fchar)
|
|
295 {
|
|
296 char buf[width];
|
|
297 int i;
|
|
298
|
|
299 for (i = 0; i < width; i++)
|
|
300 buf[i] = fchar;
|
|
301
|
|
302 return buf;
|
|
303 }
|
|
304
|
|
305 char *
|
|
306 typestat(struct player * p)
|
|
307 {
|
|
308 char str[3];
|
|
309
|
|
310 switch (p->p_status)
|
|
311 {
|
|
312 case PALIVE:
|
|
313 case PEXPLODE:
|
|
314 str[0] = p->p_ship.s_desig1;
|
|
315 str[1] = p->p_ship.s_desig2;
|
|
316 str[3] = 0;
|
|
317 return str;
|
|
318 case PTQUEUE:
|
|
319 return "tq";
|
|
320 case POBSERVE:
|
|
321 return "ob";
|
|
322 case POUTFIT:
|
|
323 return "of";
|
|
324 case PDEAD:
|
|
325 default:
|
|
326 return "--";
|
|
327 }
|
|
328 }
|