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 /*
|
|
20 * Kevin P. Smith 12/05/88
|
|
21 *
|
|
22 * Modified for Paradise by Rob Forsman 1993 Cleaned up by Brandon Gillespie
|
|
23 * Sept 17 1994
|
|
24 */
|
|
25
|
|
26 #include "config.h"
|
|
27
|
|
28 #include <stdio.h>
|
|
29 #include <sys/types.h>
|
|
30 #include <sys/file.h>
|
|
31 #include <pwd.h>
|
|
32 #include "defs.h"
|
|
33 #include "data.h"
|
|
34 #include "struct.h"
|
|
35
|
|
36 struct statentry player2;
|
|
37 /* struct status globals; */
|
|
38 struct rawdesc *output = NULL;
|
|
39 char mode;
|
|
40
|
|
41 /* prototypes */
|
|
42 void trimblanks2(char *str);
|
|
43 void trimblanks(char *str);
|
|
44 void usage(char *me);
|
|
45
|
|
46 main(argc, argv)
|
|
47 int argc;
|
|
48 char **argv;
|
|
49 {
|
|
50 int fd;
|
|
51 struct statentry plstats;
|
|
52 int i;
|
|
53 char buf[512];
|
|
54 int harsh = 10; /* How strict we will be with player trimming */
|
|
55 char *me;
|
|
56 char *path;
|
|
57 FILE *infile = stdin; /* these used to actually read in from the
|
|
58 * actual file, Rob changed them to
|
|
59 * stdin/out, and I don't mind them that way
|
|
60 * (it actually makes it a little easier */
|
|
61 FILE *outfile = stdout;
|
|
62
|
|
63 me = *argv;
|
|
64
|
|
65 if (argc == 2)
|
|
66 {
|
|
67 if (*argv[1] == '-')
|
|
68 usage(me);
|
|
69 else
|
|
70 harsh = atoi(argv[1]);
|
|
71 }
|
|
72
|
|
73 if (argc > 2 || harsh <= 0)
|
|
74 usage(me);
|
|
75
|
|
76 fprintf(stderr, "%s: If you do not know how to use this program, break now and type '%s -h'\n", me, me);
|
|
77
|
|
78 i = 0;
|
|
79 while (1 == fread(&plstats, sizeof(plstats), 1, infile))
|
|
80 {
|
|
81 /* Player 0 is always saved. */
|
|
82 /*
|
|
83 * This formula reads: If (deadtime - (10 + rank^2 + playtime/2.4)*n days
|
|
84 * > 0), nuke him.
|
|
85 */
|
|
86 if (i != 0
|
|
87 && harsh < 100
|
|
88 && ((time(NULL) - plstats.stats.st_lastlogin) >
|
|
89 (10 +
|
|
90 plstats.stats.st_rank * plstats.stats.st_rank +
|
|
91 (plstats.stats.st_tticks +
|
|
92 plstats.stats.st_sbticks +
|
|
93 plstats.stats.st_wbticks +
|
|
94 plstats.stats.st_jsticks) / 2.4) * harsh * 24 * 60 * 60)
|
|
95 )
|
|
96 {
|
|
97 fprintf(stderr,
|
|
98 "%-16.16s %7.2f %4d %4d %4d %4d\n",
|
|
99 plstats.name,
|
|
100 plstats.stats.st_tticks / 36000.0,
|
|
101 plstats.stats.st_tplanets,
|
|
102 player2.stats.st_tarmsbomb,
|
|
103 player2.stats.st_tkills,
|
|
104 player2.stats.st_tlosses);
|
|
105 continue;
|
|
106 }
|
|
107 if (outfile)
|
|
108 {
|
|
109 fwrite(&plstats, sizeof(plstats), 1, outfile);
|
|
110 }
|
|
111 i++;
|
|
112 }
|
|
113 exit(0);
|
|
114 }
|
|
115
|
|
116 void
|
|
117 usage(char *me)
|
|
118 {
|
|
119 int x;
|
|
120 char message[][255] = {
|
|
121 "\n\t'%s [n] < old-playerdb > new-playerdb'\n",
|
|
122 "\nThis program trims a player database file. The level of niceness is\n",
|
|
123 "determined by 'n' (default: 10). The old player database is read from stdin,\n",
|
|
124 "the new player database is written to stdout, a quick description of players\n",
|
|
125 "who were removed is written to stderr. It will remove any character who\n",
|
|
126 "has not played for n*10 days, as well as giving some other consideration\n",
|
|
127 "to their varied statistics. The actual formula is:\n\n",
|
|
128 "\tIf (deadtime - (10 + rank^2 + playtime/2.4)*n days > 0), nuke him.\n\n"
|
|
129 };
|
|
130
|
|
131 fprintf(stderr, "-- NetrekII (Paradise), %s --\n", PARAVERS);
|
|
132 for (x = 0; *message[x] != '\0'; x++)
|
|
133 fprintf(stderr, message[x], me);
|
|
134
|
|
135 exit(0);
|
|
136 }
|
|
137
|
|
138 void
|
|
139 trimblanks2(char *str)
|
|
140 {
|
|
141 *str = 0;
|
|
142 str--;
|
|
143 while (*str == ' ')
|
|
144 {
|
|
145 *str = 0;
|
|
146 str--;
|
|
147 }
|
|
148 if (*str == '_')
|
|
149 *str = 0;
|
|
150 }
|
|
151
|
|
152 void
|
|
153 trimblanks(char *str)
|
|
154 {
|
|
155 *str = 0;
|
|
156 str--;
|
|
157 while (*str == ' ')
|
|
158 {
|
|
159 *str = 0;
|
|
160 str--;
|
|
161 }
|
|
162 }
|