1 | /*
2 | * $Log: conf.c,v $
3 | * Revision 1.14 2003/02/17 21:24:12 millis
4 | * Add missing quote
5 | *
6 | * Revision 1.13 2003/02/17 12:41:41 millis
7 | * Fixed Bug 108, make lines >=1024 terminate in '\n'
8 | *
9 | * Revision 1.12 2003/02/05 23:53:43 millis
10 | * Removed dipstats files.
11 | * Also added in new JUDGE_TZ variable, to specify timezone
12 | *
13 | * Revision 1.11 2003/01/16 22:51:47 millis
14 | * Removed STAT stuff
15 | *
16 | * Revision 1.10 2003/01/13 22:38:51 millis
17 | * merged in from ustv
18 | *
19 | * Revision 1.9 2002/12/22 02:00:34 millis
20 | * Added DIE_STORMS setting for new random seed for storms
21 | *
22 | * Revision 1.8 2002/08/27 22:27:45 millis
23 | * Updated for automake/autoconf functionality
24 | *
25 | * Revision 1.7 2002/04/15 12:55:41 miller
26 | * Multiple changes for blind & Colonial & setup from USTV
27 | *
28 | * Revision 1.6 2001/07/17 15:16:48 greg
29 | * added GAME_DIR
30 | *
31 | * Revision 1.5 2001/07/08 22:56:29 miller
32 | * Add TIME_TOLERANCE and WARP_FILE
33 | *
34 | * Revision 1.4 2001/07/01 23:19:29 miller
35 | * New variant guardians
36 | *
37 | * Revision 1.3 2001/01/06 18:48:07 davidn
38 | * Changes to allow game creator be automatically made master
39 | *
40 | * Revision 1.2 2000/11/14 14:27:37 miller
41 | * Added new dip.conf variables
42 | *
43 | * Revision 1.1 1998/02/28 17:49:42 david
44 | * Initial revision
45 | *
46 | * Revision 1.1 1996/10/20 12:29:45 rpaar
47 | * Morrolan v9.0
48 | */
49 |
50 | #include <ctype.h>
51 | #include <stdio.h>
52 | #include <string.h>
53 | #include <stdlib.h>
54 |
55 | #include "config.h"
56 | #include "conf.h"
57 | #include "hashtable.h"
58 |
59 | /* this file contains global variables and functions to set them
60 | * to customize judge behavior at runtime.
61 | * These are added to a global hash table, and macros are provided
62 | * in conf.h to pull them out with the appropriate type, they are
63 | * stored as strings internally
64 | * this file is public domain by nathan wagner
65 | */
66 |
67 | struct pd_ht conf_table;
68 |
69 | static int conf_doline(char *line);
70 |
71 | int conf_set(char *var, char *val)
72 | {
73 | /* if it's the judge code put it into the environment so
74 | * smail can pick it up.
75 | */
76 | if (!strcmp("JUDGE_CODE", var)) {
77 | char myline[1024];
78 | sprintf(myline, "%s=%s", var, val);
79 | putenv(myline);
80 | }
81 | return pd_ht_stash(&conf_table, var, strdup(val), free);
82 | }
83 |
84 | char *config(char *var)
85 | {
86 | return (char *) pd_ht_fetch(&conf_table, var);
87 | }
88 |
89 | /*
90 | * BN_CUSTODIAN is the Boardman Custodian, who receives game starts
91 | * and ends for standard, nongunboat games
92 | * MN_CUSTODIAN is the Miller Number Custodian, who receives the game
93 | * starts and ends for other games
94 | * Neither of these should be altered, except on test judges. These
95 | * addresses may change from time to time. Please revise if necessary.
96 | */
97 |
98 | int conf_init(void)
99 | {
100 |
101 | pd_ht_init(&conf_table, 0, NULL);
102 |
103 | /* defaults follow */
104 |
105 | /* Path for judge to reside in */
106 | conf_set("JUDGE_PATH", "/.");
107 |
108 | /* and add default commands */
109 | conf_set("SUMMARY_CMD", "./summary");
110 | conf_set("SMAIL_CMD", "./smail");
111 | conf_set("RUNLISTMAP_CMD", "./runlistmap");
112 | conf_set("RUNDIPMAP_CMD", "./rundipmap");
113 | conf_set("DIP_CMD","./dip");
114 | conf_set("ATRUN_CMD","./atrun");
115 | conf_set("LENLIMIT_CMD","./lenlimit");
116 | conf_set("GAME_DIR","D");
117 |
118 | conf_set("GAMES_MASTER", "judge_request");
119 | /* games_opener is place to send opening moves for statistics */
120 | conf_set("GAMES_OPENER", "nobody");
121 |
122 | /* hall_keeper is person who receives summaries for the Hall of Fame */
123 | conf_set("HALL_KEEPER", "nobody");
124 | conf_set("BN_CUSTODIAN", "nobody");
125 | conf_set("MN_CUSTODIAN", "nobody");
126 | conf_set("EP_CUSTODIAN","nobody");
127 | conf_set("OURSELVES", "judge");
128 | conf_set("BITNET_GATEWAY1", "");
129 | conf_set("BITNET_GATEWAY2", "");
130 | conf_set("FORWARD", "");
131 | conf_set("XFORWARD", "");
132 | conf_set("YFORWARD", "");
133 | conf_set("KEEPOUT", "");
134 | conf_set("SAVE_FILE", "saved_mail");
135 | conf_set("PLAN", "");
136 | conf_set("BAILOUT_PLAN", "");
137 | conf_set("BAILOUT_MSG", "bailout.msg");
138 | conf_set("RGD_GATEWAY", "nobody");
139 | conf_set("MIN_CONTROL", "43200");
140 | conf_set("JUDGE_CODE", "XXXX");
141 | conf_set("LOCK_TIMEOUT", "3600");
142 | conf_set("D_ONTIME", "3");
143 | conf_set("D_LATE", "-1");
144 | conf_set("D_ABANDON", "-49");
145 | conf_set("D_CD", "-100");
146 | conf_set("MAP_FILE", "data/map");
147 | conf_set("MASTER_FILE", "dip.master");
148 | conf_set("TMASTER_FILE", "dip.tmast");
149 | conf_set("NO_CREATE", "dip.nocreate");
150 | conf_set("LOG_FILE", "dip.log");
151 | conf_set("CUTOFF_LENGTH", "78"); /* Length of longest print strings */
152 | conf_set("DIE_ASSASSIN", "382204");
153 | conf_set("DIE_EXPENSE", "148741");
154 | conf_set("DIE_FAMPLAG", "995816");
155 | conf_set("DIE_STORMS", "341291");
156 | conf_set("DIE_INCOME", "66144");
157 | conf_set("CREATE_DEDICATION", "-10");
158 | conf_set("SPECIAL_PW", "default");
159 | conf_set("SYSLOG_FLAG", "0");
160 | conf_set("AUTO_MASTER","no");
161 | conf_set("TIME_TOLERANCE", "60"); /* Time drift before detecting warp */
162 | conf_set("WARP_FILE", "./dip.warp");
163 |
164 | /* Default custodians for sailho (other variants will default to nothing */
165 | conf_set("CUSTODIAN_sailho", "tarzan_monkeyman@bigfoot.com");
166 | conf_set("CUSTODIAN_sailho_crowded", "tarzan_monkeyman@bigfoot.com");
167 |
168 | conf_set("CUSTODIAN_1900_1", "VonPowell@aol.com");
169 | conf_set("CUSTODIAN_1900_2", "VonPowell@aol.com");
170 | conf_set("CUSTODIAN_1900_3", "VonPowell@aol.com");
171 |
172 | conf_set("BLIND", "./zpblind");
173 |
174 | conf_set("NOBODY", "nobody@localhost");
175 |
176 | conf_set("BLOCK_FILE", ""); /* File to block dip running */
177 |
178 | conf_set("JUDGE_TZ", ""); /* Judge timezone, if different from localtime */
179 |
180 | return 1;
181 | }
182 |
183 | void conf_cmdline(int argc, char **argv)
184 | {
185 | int c;
186 |
187 | for (c = 1; c < argc; c++) {
188 | if ((argv[c][0] == '-') && (argv[c][1] == 'c')) {
189 | conf_doline(&argv[c][2]);
190 | }
191 | }
192 | }
193 |
194 | void conf_usage(void)
195 | {
196 | fprintf(stderr, "There is an error in your command line configuration arguments.\n");
197 | exit(-2);
198 | }
199 |
200 | void conf_readfile(char *directory, char *fname)
201 | {
202 | char myline[255];
203 | char filename[255];
204 | FILE *conffile;
205 | char *tmp;
206 |
207 | fflush(stdout);
208 | fflush(stderr);
209 |
210 | sprintf(filename, "%s/%s", directory, fname);
211 |
212 | conffile = fopen(filename, "r");
213 | if (conffile == NULL) {
214 | perror("unable to open config file");
215 | perror(filename);
216 | exit(-2);
217 | }
218 | while (fgets(myline, 255, conffile) != NULL) {
219 | /* set the last newline to a null */
220 | if ((tmp = strrchr(myline, '\n'))) {
221 | *tmp = '\0';
222 | }
223 | /* skip leading whitespace */
224 | tmp = myline;
225 | while (isspace((unsigned char) *tmp)) {
226 | tmp++;
227 | }
228 |
229 | /* blank line ? */
230 | if ((*tmp == 0) || (*tmp == '#')) {
231 | continue;
232 | }
233 | /* TODO: clean up memory when we are done. i am ignoring
234 | * it for now, as the OS should reclaim the memory when we exit.
235 | */
236 |
237 | conf_doline(tmp);
238 | }
239 |
240 | fclose(conffile);
241 |
242 | return;
243 | }
244 |
245 | void conf_print(FILE * where)
246 | {
247 | struct pd_ht_search s;
248 | struct pd_ht_entry *e;
249 | for (e = pd_ht_firstentry(&conf_table, &s); e; e = pd_ht_nextentry(&s)) {
250 |
251 | fprintf(where, "%s = %s\n", (char *) e->key, (char *) e->data);
252 | }
253 | return;
254 | }
255 |
256 | static int conf_doline(char *tmp)
257 | {
258 | char conf_var[1024];
259 | char *varloc;
260 | size_t namlen;
261 |
262 | namlen = strcspn(tmp, " \t=");
263 | strncpy(conf_var, tmp, namlen);
264 | /* wierd, strncpy doesn't null terminate the string */
265 | *(conf_var + namlen) = '\0';
266 |
267 | varloc = strchr(tmp, '=') + 1;
268 | /* skip over whitespace at the start of the value */
269 | while (isspace((unsigned char) *varloc)) {
270 | varloc++;
271 | }
272 |
273 | /* put it into the config table */
274 | conf_set(conf_var, varloc);
275 |
276 | return 1;
277 | }