/[LeafOK_CVS]/pvpgn-1.7.4/src/bnetd/prefs.c
ViewVC logotype

Contents of /pvpgn-1.7.4/src/bnetd/prefs.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Thu Jun 22 05:33:55 2006 UTC (19 years, 9 months ago) by sysadm
Branch: MAIN
CVS Tags: pvpgn_1-7-4-0_MIL, HEAD
Changes since 1.1: +7 -0 lines
Content type: text/x-csrc
Account verification

1 /*
2 * Copyright (C) 1998,1999,2000,2001 Ross Combs (rocombs@cs.nmsu.edu)
3 * Copyright (C) 1999 Rob Crittenden (rcrit@greyoak.com)
4 * Copyright (C) 1999 Mark Baysinger (mbaysing@ucsd.edu)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20 #define PREFS_INTERNAL_ACCESS
21 #include "common/setup_before.h"
22 #include <stdio.h>
23 #ifdef HAVE_STDDEF_H
24 # include <stddef.h>
25 #else
26 # ifndef NULL
27 # define NULL ((void *)0)
28 # endif
29 #endif
30 #ifdef STDC_HEADERS
31 # include <stdlib.h>
32 #else
33 # ifdef HAVE_MALLOC_H
34 # include <malloc.h>
35 # endif
36 #endif
37 #ifdef HAVE_STRING_H
38 # include <string.h>
39 #else
40 # ifdef HAVE_STRINGS_H
41 # include <strings.h>
42 # endif
43 #endif
44 #include "compat/strdup.h"
45 #include "compat/strcasecmp.h"
46 #include <errno.h>
47 #include "compat/strerror.h"
48 #include <ctype.h>
49 #include "common/util.h"
50 #include "common/eventlog.h"
51 #include "common/xalloc.h"
52 #include "prefs.h"
53 #include "common/setup_after.h"
54
55 static int processDirective(char const * directive, char const * value, unsigned int curLine);
56
57 #define NONE 0
58
59 static struct {
60 /* files and paths */
61 char const * filedir;
62 char const * storage_path;
63 char const * logfile;
64 char const * loglevels;
65 char const * motdfile;
66 char const * newsfile;
67 char const * channelfile;
68 char const * pidfile;
69 char const * adfile;
70 char const * topicfile;
71 char const * DBlayoutfile;
72 char const * verify_dir;
73
74 unsigned int usersync;
75 unsigned int userflush;
76 unsigned int userstep;
77
78 char const * servername;
79
80 unsigned int track;
81 char const * location;
82 char const * description;
83 char const * url;
84 char const * contact_name;
85 char const * contact_email;
86 unsigned int latency;
87 unsigned int irc_latency;
88 unsigned int shutdown_delay;
89 unsigned int shutdown_decr;
90 unsigned int new_accounts;
91 unsigned int max_accounts;
92 unsigned int kick_old_login;
93 unsigned int ask_new_channel;
94 unsigned int hide_pass_games;
95 unsigned int hide_started_games;
96 unsigned int hide_temp_channels;
97 unsigned int hide_addr;
98 unsigned int enable_conn_all;
99 unsigned int extra_commands;
100 char const * reportdir;
101 unsigned int report_all_games;
102 unsigned int report_diablo_games;
103 char const * iconfile;
104 char const * war3_iconfile;
105 char const * star_iconfile;
106 char const * tosfile;
107 char const * mpqfile;
108 char const * trackaddrs;
109 char const * servaddrs;
110 char const * w3routeaddr;
111 char const * ircaddrs;
112 unsigned int use_keepalive;
113 unsigned int udptest_port;
114 char const * ipbanfile;
115 unsigned int disc_is_loss;
116 char const * helpfile;
117 char const * fortunecmd;
118 char const * transfile;
119 unsigned int chanlog;
120 char const * chanlogdir;
121 unsigned int quota;
122 unsigned int quota_lines;
123 unsigned int quota_time;
124 unsigned int quota_wrapline;
125 unsigned int quota_maxline;
126 unsigned int ladder_init_rating;
127 unsigned int quota_dobae;
128 char const * realmfile;
129 char const * issuefile;
130 char const * effective_user;
131 char const * effective_group;
132 unsigned int nullmsg;
133 unsigned int mail_support;
134 unsigned int mail_quota;
135 char const * maildir;
136 char const * log_notice;
137 unsigned int savebyname;
138 unsigned int skip_versioncheck;
139 unsigned int allow_bad_version;
140 unsigned int allow_unknown_version;
141 char const * versioncheck_file;
142 unsigned int d2cs_version;
143 unsigned int allow_d2cs_setname;
144 unsigned int hashtable_size;
145 char const * telnetaddrs;
146 unsigned int ipban_check_int;
147 char const * version_exeinfo_match;
148 unsigned int version_exeinfo_maxdiff;
149 unsigned int max_concurrent_logins;
150 unsigned int identify_timeout_secs;
151 char const * server_info;
152 char const * mapsfile;
153 char const * xplevelfile;
154 char const * xpcalcfile;
155 unsigned int initkill_timer;
156 unsigned int war3_ladder_update_secs;
157 unsigned int output_update_secs;
158 char const * ladderdir;
159 char const * statusdir;
160 unsigned int XML_output_ladder;
161 unsigned int XML_status_output;
162 char const * account_allowed_symbols;
163 char const * command_groups_file;
164 char const * tournament_file;
165 char const * aliasfile;
166 char const * anongame_infos_file;
167 unsigned int max_conns_per_IP;
168 unsigned int max_friends;
169 unsigned int clan_newer_time;
170 unsigned int clan_max_members;
171 unsigned int clan_channel_default_private;
172 unsigned int passfail_count;
173 unsigned int passfail_bantime;
174 unsigned int maxusers_per_channel;
175 char const * supportfile;
176 char const * allowed_clients;
177 char const * ladder_games;
178 char const * ladder_prefix;
179 unsigned int max_connections;
180 unsigned int sync_on_logoff;
181 } prefs_runtime_config;
182
183 /* directive type defcharval defintval */
184 static Bconf_t conf_table[] =
185 {
186 { "filedir", conf_type_char, BNETD_FILE_DIR, NONE , (void *)&prefs_runtime_config.filedir},
187 { "storage_path", conf_type_char, BNETD_STORAGE_PATH, NONE , (void *)&prefs_runtime_config.storage_path},
188 { "logfile", conf_type_char, BNETD_LOG_FILE, NONE , (void *)&prefs_runtime_config.logfile},
189 { "loglevels", conf_type_char, BNETD_LOG_LEVELS, NONE , (void *)&prefs_runtime_config.loglevels},
190 { "motdfile", conf_type_char, BNETD_MOTD_FILE, NONE , (void *)&prefs_runtime_config.motdfile},
191 { "newsfile", conf_type_char, BNETD_NEWS_DIR, NONE , (void *)&prefs_runtime_config.newsfile},
192 { "channelfile", conf_type_char, BNETD_CHANNEL_FILE, NONE , (void *)&prefs_runtime_config.channelfile},
193 { "pidfile", conf_type_char, BNETD_PID_FILE, NONE , (void *)&prefs_runtime_config.pidfile},
194 { "adfile", conf_type_char, BNETD_AD_FILE, NONE , (void *)&prefs_runtime_config.adfile},
195 { "topicfile", conf_type_char, BNETD_TOPIC_FILE, NONE , (void *)&prefs_runtime_config.topicfile},
196 { "DBlayoutfile", conf_type_char, BNETD_DBLAYOUT_FILE, NONE , (void *)&prefs_runtime_config.DBlayoutfile},
197 { "supportfile", conf_type_char, BNETD_SUPPORT_FILE, NONE , (void *)&prefs_runtime_config.supportfile},
198 { "usersync", conf_type_int, NULL, BNETD_USERSYNC , (void *)&prefs_runtime_config.usersync},
199 { "userflush", conf_type_int, NULL, BNETD_USERFLUSH , (void *)&prefs_runtime_config.userflush},
200 { "userstep", conf_type_int, NULL, BNETD_USERSTEP , (void *)&prefs_runtime_config.userstep},
201 { "servername", conf_type_char, "", NONE , (void *)&prefs_runtime_config.servername},
202 { "track", conf_type_int, NULL, BNETD_TRACK_TIME , (void *)&prefs_runtime_config.track},
203 { "location", conf_type_char, "", NONE , (void *)&prefs_runtime_config.location},
204 { "description", conf_type_char, "", NONE , (void *)&prefs_runtime_config.description},
205 { "url", conf_type_char, "", NONE , (void *)&prefs_runtime_config.url},
206 { "contact_name", conf_type_char, "", NONE , (void *)&prefs_runtime_config.contact_name},
207 { "contact_email", conf_type_char, "", NONE , (void *)&prefs_runtime_config.contact_email},
208 { "latency", conf_type_int, NULL, BNETD_LATENCY , (void *)&prefs_runtime_config.latency},
209 { "irc_latency", conf_type_int, NULL, BNETD_IRC_LATENCY , (void *)&prefs_runtime_config.irc_latency},
210 { "shutdown_delay", conf_type_int, NULL, BNETD_SHUTDELAY , (void *)&prefs_runtime_config.shutdown_delay},
211 { "shutdown_decr", conf_type_int, NULL, BNETD_SHUTDECR , (void *)&prefs_runtime_config.shutdown_decr},
212 { "new_accounts", conf_type_bool, NULL, 1 , (void *)&prefs_runtime_config.new_accounts},
213 { "max_accounts", conf_type_int, NULL, 0 , (void *)&prefs_runtime_config.max_accounts},
214 { "kick_old_login", conf_type_bool, NULL, 1 , (void *)&prefs_runtime_config.kick_old_login},
215 { "ask_new_channel", conf_type_bool, NULL, 1 , (void *)&prefs_runtime_config.ask_new_channel},
216 { "hide_pass_games", conf_type_bool, NULL, 1 , (void *)&prefs_runtime_config.hide_pass_games},
217 { "hide_started_games", conf_type_bool, NULL, 1 , (void *)&prefs_runtime_config.hide_started_games},
218 { "hide_temp_channels", conf_type_bool, NULL, 1 , (void *)&prefs_runtime_config.hide_temp_channels},
219 { "hide_addr", conf_type_bool, NULL, 1 , (void *)&prefs_runtime_config.hide_addr},
220 { "enable_conn_all", conf_type_bool, NULL, 0 , (void *)&prefs_runtime_config.enable_conn_all},
221 { "extra_commands", conf_type_bool, NULL, 0 , (void *)&prefs_runtime_config.extra_commands},
222 { "reportdir", conf_type_char, BNETD_REPORT_DIR, NONE , (void *)&prefs_runtime_config.reportdir},
223 { "report_all_games", conf_type_bool, NULL, 0 , (void *)&prefs_runtime_config.report_all_games},
224 { "report_diablo_games", conf_type_bool, NULL, 0 , (void *)&prefs_runtime_config.report_diablo_games},
225 { "iconfile", conf_type_char, BNETD_ICON_FILE, NONE , (void *)&prefs_runtime_config.iconfile},
226 { "war3_iconfile", conf_type_char, BNETD_WAR3_ICON_FILE, NONE , (void *)&prefs_runtime_config.war3_iconfile},
227 { "star_iconfile", conf_type_char, BNETD_STAR_ICON_FILE, NONE , (void *)&prefs_runtime_config.star_iconfile},
228 { "tosfile", conf_type_char, BNETD_TOS_FILE, NONE , (void *)&prefs_runtime_config.tosfile},
229 { "mpqfile", conf_type_char, BNETD_MPQ_FILE, NONE , (void *)&prefs_runtime_config.mpqfile},
230 { "trackaddrs", conf_type_char, BNETD_TRACK_ADDRS, NONE , (void *)&prefs_runtime_config.trackaddrs},
231 { "servaddrs", conf_type_char, BNETD_SERV_ADDRS, NONE , (void *)&prefs_runtime_config.servaddrs},
232 { "w3routeaddr", conf_type_char, BNETD_W3ROUTE_ADDR, NONE , (void *)&prefs_runtime_config.w3routeaddr},
233 { "ircaddrs", conf_type_char, BNETD_IRC_ADDRS, NONE , (void *)&prefs_runtime_config.ircaddrs},
234 { "use_keepalive", conf_type_bool, NULL, 0 , (void *)&prefs_runtime_config.use_keepalive},
235 { "udptest_port", conf_type_int, NULL, BNETD_DEF_TEST_PORT , (void *)&prefs_runtime_config.udptest_port},
236 { "ipbanfile", conf_type_char, BNETD_IPBAN_FILE, NONE , (void *)&prefs_runtime_config.ipbanfile},
237 { "disc_is_loss", conf_type_bool, NULL, 0 , (void *)&prefs_runtime_config.disc_is_loss},
238 { "helpfile", conf_type_char, BNETD_HELP_FILE, NONE , (void *)&prefs_runtime_config.helpfile},
239 { "fortunecmd", conf_type_char, BNETD_FORTUNECMD, NONE , (void *)&prefs_runtime_config.fortunecmd},
240 { "transfile", conf_type_char, BNETD_TRANS_FILE, NONE , (void *)&prefs_runtime_config.transfile},
241 { "chanlog", conf_type_bool, NULL , BNETD_CHANLOG , (void *)&prefs_runtime_config.chanlog},
242 { "chanlogdir", conf_type_char, BNETD_CHANLOG_DIR, NONE , (void *)&prefs_runtime_config.chanlogdir},
243 { "quota", conf_type_bool, NULL, 0 , (void *)&prefs_runtime_config.quota},
244 { "quota_lines", conf_type_int, NULL, BNETD_QUOTA_LINES , (void *)&prefs_runtime_config.quota_lines},
245 { "quota_time", conf_type_int, NULL, BNETD_QUOTA_TIME , (void *)&prefs_runtime_config.quota_time},
246 { "quota_wrapline", conf_type_int, NULL, BNETD_QUOTA_WLINE , (void *)&prefs_runtime_config.quota_wrapline},
247 { "quota_maxline", conf_type_int, NULL, BNETD_QUOTA_MLINE , (void *)&prefs_runtime_config.quota_maxline},
248 { "ladder_init_rating", conf_type_int, NULL, BNETD_LADDER_INIT_RAT , (void *)&prefs_runtime_config.ladder_init_rating},
249 { "quota_dobae", conf_type_int, NULL, BNETD_QUOTA_DOBAE , (void *)&prefs_runtime_config.quota_dobae},
250 { "realmfile", conf_type_char, BNETD_REALM_FILE, NONE , (void *)&prefs_runtime_config.realmfile},
251 { "issuefile", conf_type_char, BNETD_ISSUE_FILE, NONE , (void *)&prefs_runtime_config.issuefile},
252 { "effective_user", conf_type_char, NULL, NONE , (void *)&prefs_runtime_config.effective_user},
253 { "effective_group", conf_type_char, NULL, NONE , (void *)&prefs_runtime_config.effective_group},
254 { "nullmsg", conf_type_int, NULL, BNETD_DEF_NULLMSG , (void *)&prefs_runtime_config.nullmsg},
255 { "mail_support", conf_type_bool, NULL, BNETD_MAIL_SUPPORT , (void *)&prefs_runtime_config.mail_support},
256 { "mail_quota", conf_type_int, NULL, BNETD_MAIL_QUOTA , (void *)&prefs_runtime_config.mail_quota},
257 { "maildir", conf_type_char, BNETD_MAIL_DIR, NONE , (void *)&prefs_runtime_config.maildir},
258 { "log_notice", conf_type_char, BNETD_LOG_NOTICE, NONE , (void *)&prefs_runtime_config.log_notice},
259 { "savebyname", conf_type_bool, NULL, 1 , (void *)&prefs_runtime_config.savebyname},
260 { "skip_versioncheck", conf_type_bool, NULL, 0 , (void *)&prefs_runtime_config.skip_versioncheck},
261 { "allow_bad_version", conf_type_bool, NULL, 0 , (void *)&prefs_runtime_config.allow_bad_version},
262 { "allow_unknown_version", conf_type_bool, NULL, 0 , (void *)&prefs_runtime_config.allow_unknown_version},
263 { "versioncheck_file", conf_type_char, PVPGN_VERSIONCHECK, NONE , (void *)&prefs_runtime_config.versioncheck_file},
264 { "d2cs_version", conf_type_int, NULL, 0 , (void *)&prefs_runtime_config.d2cs_version},
265 { "allow_d2cs_setname", conf_type_bool, NULL, 1 , (void *)&prefs_runtime_config.allow_d2cs_setname},
266 { "hashtable_size", conf_type_int, NULL, BNETD_HASHTABLE_SIZE , (void *)&prefs_runtime_config.hashtable_size},
267 { "telnetaddrs", conf_type_char, BNETD_TELNET_ADDRS, NONE , (void *)&prefs_runtime_config.telnetaddrs},
268 { "ipban_check_int", conf_type_int, NULL, 30 , (void *)&prefs_runtime_config.ipban_check_int},
269 { "version_exeinfo_match", conf_type_char, BNETD_EXEINFO_MATCH, NONE , (void *)&prefs_runtime_config.version_exeinfo_match},
270 { "version_exeinfo_maxdiff",conf_type_int, NULL, PVPGN_VERSION_TIMEDIV , (void *)&prefs_runtime_config.version_exeinfo_maxdiff},
271 { "max_concurrent_logins", conf_type_int, NULL, 0 , (void *)&prefs_runtime_config.max_concurrent_logins},
272 { "identify_timeout_secs", conf_type_int, NULL, W3_IDENTTIMEOUT , (void *)&prefs_runtime_config.identify_timeout_secs},
273 { "server_info", conf_type_char, "", NONE , (void *)&prefs_runtime_config.server_info},
274 { "mapsfile", conf_type_char, NULL, 0 , (void *)&prefs_runtime_config.mapsfile},
275 { "xplevelfile", conf_type_char, NULL, 0 , (void *)&prefs_runtime_config.xplevelfile},
276 { "xpcalcfile", conf_type_char, NULL, 0 , (void *)&prefs_runtime_config.xpcalcfile},
277 { "initkill_timer", conf_type_int, NULL, 0 , (void *)&prefs_runtime_config.initkill_timer},
278 { "war3_ladder_update_secs",conf_type_int, NULL, 0 , (void *)&prefs_runtime_config.war3_ladder_update_secs},
279 { "output_update_secs", conf_type_int, NULL, 0 , (void *)&prefs_runtime_config.output_update_secs},
280 { "ladderdir", conf_type_char, BNETD_LADDER_DIR, NONE , (void *)&prefs_runtime_config.ladderdir},
281 { "statusdir", conf_type_char, BNETD_STATUS_DIR, NONE , (void *)&prefs_runtime_config.statusdir},
282 { "XML_output_ladder", conf_type_bool, NULL, 0 , (void *)&prefs_runtime_config.XML_output_ladder},
283 { "XML_status_output", conf_type_bool, NULL, 0 , (void *)&prefs_runtime_config.XML_status_output},
284 { "account_allowed_symbols",conf_type_char, PVPGN_DEFAULT_SYMB, NONE , (void *)&prefs_runtime_config.account_allowed_symbols},
285 { "command_groups_file", conf_type_char, BNETD_COMMAND_GROUPS_FILE, NONE , (void *)&prefs_runtime_config.command_groups_file},
286 { "tournament_file", conf_type_char, BNETD_TOURNAMENT_FILE,NONE , (void *)&prefs_runtime_config.tournament_file},
287 { "aliasfile" , conf_type_char, BNETD_ALIASFILE , NONE , (void *)&prefs_runtime_config.aliasfile},
288 { "anongame_infos_file", conf_type_char, PVPGN_AINFO_FILE, NONE , (void *)&prefs_runtime_config.anongame_infos_file},
289 { "max_conns_per_IP", conf_type_int, NULL, 0 , (void *)&prefs_runtime_config.max_conns_per_IP},
290 { "max_friends", conf_type_int, NULL, MAX_FRIENDS , (void *)&prefs_runtime_config.max_friends},
291 { "clan_newer_time", conf_type_int, NULL, CLAN_NEWER_TIME , (void *)&prefs_runtime_config.clan_newer_time},
292 { "clan_max_members", conf_type_int, NULL, CLAN_MAX_MEMBERS , (void *)&prefs_runtime_config.clan_max_members},
293 { "clan_channel_default_private", conf_type_bool, NULL, 0 , (void *)&prefs_runtime_config.clan_channel_default_private},
294 { "passfail_count", conf_type_int, NULL, 0 , (void *)&prefs_runtime_config.passfail_count},
295 { "passfail_bantime", conf_type_int, NULL, 300 , (void *)&prefs_runtime_config.passfail_bantime},
296 { "maxusers_per_channel", conf_type_int, NULL, 0 , (void *)&prefs_runtime_config.maxusers_per_channel},
297 { "allowed_clients", conf_type_char, NULL, 0 , (void *)&prefs_runtime_config.allowed_clients},
298 { "ladder_games", conf_type_char, NULL, NONE , (void *)&prefs_runtime_config.ladder_games},
299 { "ladder_prefix", conf_type_char, NULL, NONE , (void *)&prefs_runtime_config.ladder_prefix},
300 { "max_connections", conf_type_int, NULL, BNETD_MAX_SOCKETS , (void *)&prefs_runtime_config.max_connections},
301 { "sync_on_logoff", conf_type_bool, NULL, 0 , (void *)&prefs_runtime_config.sync_on_logoff},
302 { "verify_dir", conf_type_char, BNETD_VERIFY_DIR, NONE , (void *)&prefs_runtime_config.verify_dir},
303 { NULL, conf_type_none, NULL, NONE , NULL},
304 };
305
306 #define PREFS_STORE_UINT(addr) (*((unsigned int *)(addr)))
307 #define PREFS_STORE_CHAR(addr) (*((char const **)(addr)))
308
309 char const * preffile=NULL;
310
311 static int processDirective(char const * directive, char const * value, unsigned int curLine)
312 {
313 unsigned int i;
314
315 if (!directive)
316 {
317 eventlog(eventlog_level_error,__FUNCTION__,"got NULL directive");
318 return -1;
319 }
320 if (!value)
321 {
322 eventlog(eventlog_level_error,__FUNCTION__,"got NULL value");
323 return -1;
324 }
325
326 for (i=0; conf_table[i].directive; i++)
327 if (strcasecmp(conf_table[i].directive,directive)==0)
328 {
329 switch (conf_table[i].type)
330 {
331 case conf_type_char:
332 {
333 char const * temp;
334
335 temp = xstrdup(value);
336 if (PREFS_STORE_CHAR(conf_table[i].store))
337 xfree((void *)PREFS_STORE_CHAR(conf_table[i].store)); /* avoid warning */
338 PREFS_STORE_CHAR(conf_table[i].store) = temp;
339 }
340 break;
341
342 case conf_type_int:
343 {
344 unsigned int temp;
345
346 if (str_to_uint(value,&temp)<0)
347 eventlog(eventlog_level_error,__FUNCTION__,"invalid integer value \"%s\" for element \"%s\" at line %u",value,directive,curLine);
348 else
349 PREFS_STORE_UINT(conf_table[i].store) = temp;
350 }
351 break;
352
353 case conf_type_bool:
354 switch (str_get_bool(value))
355 {
356 case 1:
357 PREFS_STORE_UINT(conf_table[i].store) = 1;
358 break;
359 case 0:
360 PREFS_STORE_UINT(conf_table[i].store) = 0;
361 break;
362 default:
363 eventlog(eventlog_level_error,__FUNCTION__,"invalid boolean value for element \"%s\" at line %u",directive,curLine);
364 }
365 break;
366
367 default:
368 eventlog(eventlog_level_error,__FUNCTION__,"invalid type %d in table",(int)conf_table[i].type);
369 }
370 return 0;
371 }
372
373 eventlog(eventlog_level_error,__FUNCTION__,"unknown element \"%s\" at line %u",directive,curLine);
374 return -1;
375 }
376
377
378 extern int prefs_load(char const * filename)
379 {
380 /* restore defaults */
381 {
382 unsigned int i;
383
384 for (i=0; conf_table[i].directive; i++)
385 switch (conf_table[i].type)
386 {
387 case conf_type_int:
388 case conf_type_bool:
389 PREFS_STORE_UINT(conf_table[i].store) = conf_table[i].defintval;
390 break;
391
392 case conf_type_char:
393 if (PREFS_STORE_CHAR(conf_table[i].store))
394 xfree((void *)PREFS_STORE_CHAR(conf_table[i].store)); /* avoid warning */
395 if (!conf_table[i].defcharval)
396 PREFS_STORE_CHAR(conf_table[i].store) = NULL;
397 else
398 PREFS_STORE_CHAR(conf_table[i].store) = xstrdup(conf_table[i].defcharval);
399 break;
400
401 default:
402 eventlog(eventlog_level_error,__FUNCTION__,"invalid type %d in table",(int)conf_table[i].type);
403 return -1;
404 }
405 }
406
407 /* load file */
408 if (filename)
409 {
410 FILE * fp;
411 char * buff;
412 char * cp;
413 char * temp;
414 unsigned int currline;
415 unsigned int j;
416 char const * directive;
417 char const * value;
418 char * rawvalue;
419 unsigned cflag;
420
421 if (!(fp = fopen(filename,"r")))
422 {
423 eventlog(eventlog_level_error,__FUNCTION__,"could not open file \"%s\" for reading (fopen: %s)",filename,pstrerror(errno));
424 return -1;
425 }
426
427 /* Read the configuration file */
428 for (currline=1; (buff = file_get_line(fp)); currline++)
429 {
430 cflag = 1;
431 for(cp = buff; *cp; cp++) {
432 switch(*cp) {
433 case '\\':
434 if (!*(++cp)) cflag = 0; /* end of string, exit the loop */
435 break;
436 case '"':
437 switch(cflag) {
438 case 1: cflag = 2; break;
439 case 2: cflag = 1; break;
440 }
441 break;
442 case '#':
443 if (cflag == 1) cflag = 0; /* comment outside quotes found, exit the loop */
444 break;
445 }
446 if (!cflag) break;
447 }
448 if (*cp == '#') *cp = '\0';
449
450 cp = buff;
451
452 while (*cp=='\t' || *cp==' ') cp++;
453 if (*cp=='\0')
454 {
455 continue;
456 }
457 temp = cp;
458 while (*cp!='\t' && *cp!=' ' && *cp!='\0') cp++;
459 if (*cp!='\0')
460 {
461 *cp = '\0';
462 cp++;
463 }
464 directive = xstrdup(temp);
465 while (*cp=='\t' || *cp==' ') cp++;
466 if (*cp!='=')
467 {
468 eventlog(eventlog_level_error,__FUNCTION__,"missing = on line %u",currline);
469 xfree((void *)directive); /* avoid warning */
470 continue;
471 }
472 cp++;
473 while (*cp=='\t' || *cp==' ') cp++;
474 if (*cp=='\0')
475 {
476 eventlog(eventlog_level_error,__FUNCTION__,"missing value after = on line %u",currline);
477 xfree((void *)directive); /* avoid warning */
478 continue;
479 }
480 rawvalue = xstrdup(cp);
481
482 if (rawvalue[0]=='"')
483 {
484 char prev;
485
486 for (j=1,prev='\0'; rawvalue[j]!='\0'; j++)
487 {
488 switch (rawvalue[j])
489 {
490 case '"':
491 if (prev!='\\')
492 break;
493 prev = '"';
494 continue;
495 case '\\':
496 if (prev=='\\')
497 prev = '\0';
498 else
499 prev = '\\';
500 continue;
501 default:
502 prev = rawvalue[j];
503 continue;
504 }
505 break;
506 }
507 if (rawvalue[j]!='"')
508 {
509 eventlog(eventlog_level_error,__FUNCTION__,"missing end quote for value of element \"%s\" on line %u",directive,currline);
510 xfree(rawvalue);
511 xfree((void *)directive); /* avoid warning */
512 continue;
513 }
514 rawvalue[j] = '\0';
515 if (rawvalue[j+1]!='\0')
516 {
517 eventlog(eventlog_level_error,__FUNCTION__,"extra characters after the value for element \"%s\" on line %u",directive,currline);
518 xfree(rawvalue);
519 xfree((void *)directive); /* avoid warning */
520 continue;
521 }
522 value = &rawvalue[1];
523 }
524 else
525 {
526 unsigned int k;
527
528 for (j=0; rawvalue[j]!='\0' && rawvalue[j]!=' ' && rawvalue[j]!='\t'; j++);
529 k = j;
530 while (rawvalue[k]==' ' || rawvalue[k]=='\t') k++;
531 if (rawvalue[k]!='\0')
532 {
533 eventlog(eventlog_level_error,__FUNCTION__,"extra characters after the value for element \"%s\" on line %u (%s)",directive,currline,&rawvalue[k]);
534 xfree(rawvalue);
535 xfree((void *)directive); /* avoid warning */
536 continue;
537 }
538 rawvalue[j] = '\0';
539 value = rawvalue;
540 }
541
542 processDirective(directive,value,currline);
543
544 xfree(rawvalue);
545 xfree((void *)directive); /* avoid warning */
546 }
547 file_get_line(NULL); // clear file_get_line buffer
548 if (fclose(fp)<0)
549 eventlog(eventlog_level_error,__FUNCTION__,"could not close prefs file \"%s\" after reading (fclose: %s)",filename,pstrerror(errno));
550 }
551
552 return 0;
553 }
554
555
556 extern void prefs_unload(void)
557 {
558 unsigned int i;
559
560 for (i=0; conf_table[i].directive; i++)
561 switch (conf_table[i].type)
562 {
563 case conf_type_int:
564 case conf_type_bool:
565 break;
566
567 case conf_type_char:
568 if (PREFS_STORE_CHAR(conf_table[i].store))
569 {
570 xfree((void *)PREFS_STORE_CHAR(conf_table[i].store)); /* avoid warning */
571 PREFS_STORE_CHAR(conf_table[i].store) = NULL;
572 }
573 break;
574
575 default:
576 eventlog(eventlog_level_error,__FUNCTION__,"invalid type %d in table",(int)conf_table[i].type);
577 break;
578 }
579 }
580
581 extern char const * prefs_get_storage_path(void)
582 {
583 return prefs_runtime_config.storage_path;
584 }
585
586
587 extern char const * prefs_get_filedir(void)
588 {
589 return prefs_runtime_config.filedir;
590 }
591
592
593 extern char const * prefs_get_logfile(void)
594 {
595 return prefs_runtime_config.logfile;
596 }
597
598
599 extern char const * prefs_get_loglevels(void)
600 {
601 return prefs_runtime_config.loglevels;
602 }
603
604
605 extern char const * prefs_get_motdfile(void)
606 {
607 return prefs_runtime_config.motdfile;
608 }
609
610
611 extern char const * prefs_get_newsfile(void)
612 {
613 return prefs_runtime_config.newsfile;
614 }
615
616
617 extern char const * prefs_get_adfile(void)
618 {
619 return prefs_runtime_config.adfile;
620 }
621
622 extern char const * prefs_get_topicfile(void)
623 {
624 return prefs_runtime_config.topicfile;
625 }
626
627 extern char const * prefs_get_DBlayoutfile(void)
628 {
629 return prefs_runtime_config.DBlayoutfile;
630 }
631
632
633 extern unsigned int prefs_get_user_sync_timer(void)
634 {
635 return prefs_runtime_config.usersync;
636 }
637
638
639 extern unsigned int prefs_get_user_flush_timer(void)
640 {
641 return prefs_runtime_config.userflush;
642 }
643
644
645 extern unsigned int prefs_get_user_step(void)
646 {
647 return prefs_runtime_config.userstep;
648 }
649
650
651 extern char const * prefs_get_servername(void)
652 {
653 return prefs_runtime_config.servername;
654 }
655
656 extern unsigned int prefs_get_track(void)
657 {
658 unsigned int rez;
659
660 rez = prefs_runtime_config.track;
661 if (rez>0 && rez<60) rez = 60;
662 return rez;
663 }
664
665
666 extern char const * prefs_get_location(void)
667 {
668 return prefs_runtime_config.location;
669 }
670
671
672 extern char const * prefs_get_description(void)
673 {
674 return prefs_runtime_config.description;
675 }
676
677
678 extern char const * prefs_get_url(void)
679 {
680 return prefs_runtime_config.url;
681 }
682
683
684 extern char const * prefs_get_contact_name(void)
685 {
686 return prefs_runtime_config.contact_name;
687 }
688
689
690 extern char const * prefs_get_contact_email(void)
691 {
692 return prefs_runtime_config.contact_email;
693 }
694
695
696 extern unsigned int prefs_get_latency(void)
697 {
698 return prefs_runtime_config.latency;
699 }
700
701
702 extern unsigned int prefs_get_irc_latency(void)
703 {
704 return prefs_runtime_config.irc_latency;
705 }
706
707
708 extern unsigned int prefs_get_shutdown_delay(void)
709 {
710 return prefs_runtime_config.shutdown_delay;
711 }
712
713
714 extern unsigned int prefs_get_shutdown_decr(void)
715 {
716 return prefs_runtime_config.shutdown_decr;
717 }
718
719
720 extern unsigned int prefs_get_allow_new_accounts(void)
721 {
722 return prefs_runtime_config.new_accounts;
723 }
724
725
726 extern unsigned int prefs_get_max_accounts(void)
727 {
728 return prefs_runtime_config.max_accounts;
729 }
730
731
732 extern unsigned int prefs_get_kick_old_login(void)
733 {
734 return prefs_runtime_config.kick_old_login;
735 }
736
737
738 extern char const * prefs_get_channelfile(void)
739 {
740 return prefs_runtime_config.channelfile;
741 }
742
743
744 extern unsigned int prefs_get_ask_new_channel(void)
745 {
746 return prefs_runtime_config.ask_new_channel;
747 }
748
749
750 extern unsigned int prefs_get_hide_pass_games(void)
751 {
752 return prefs_runtime_config.hide_pass_games;
753 }
754
755
756 extern unsigned int prefs_get_hide_started_games(void)
757 {
758 return prefs_runtime_config.hide_started_games;
759 }
760
761
762 extern unsigned int prefs_get_hide_temp_channels(void)
763 {
764 return prefs_runtime_config.hide_temp_channels;
765 }
766
767
768 extern unsigned int prefs_get_hide_addr(void)
769 {
770 return prefs_runtime_config.hide_addr;
771 }
772
773
774 extern unsigned int prefs_get_enable_conn_all(void)
775 {
776 return prefs_runtime_config.enable_conn_all;
777 }
778
779
780 extern unsigned int prefs_get_extra_commands(void)
781 {
782 return prefs_runtime_config.extra_commands;
783 }
784
785
786 extern char const * prefs_get_reportdir(void)
787 {
788 return prefs_runtime_config.reportdir;
789 }
790
791
792 extern unsigned int prefs_get_report_all_games(void)
793 {
794 return prefs_runtime_config.report_all_games;
795 }
796
797 extern unsigned int prefs_get_report_diablo_games(void)
798 {
799 return prefs_runtime_config.report_diablo_games;
800 }
801
802 extern char const * prefs_get_pidfile(void)
803 {
804 return prefs_runtime_config.pidfile;
805 }
806
807
808 extern char const * prefs_get_iconfile(void)
809 {
810 return prefs_runtime_config.iconfile;
811 }
812
813 extern char const * prefs_get_war3_iconfile(void)
814 {
815 return prefs_runtime_config.war3_iconfile;
816 }
817
818 extern char const * prefs_get_star_iconfile(void)
819 {
820 return prefs_runtime_config.star_iconfile;
821 }
822
823
824 extern char const * prefs_get_tosfile(void)
825 {
826 return prefs_runtime_config.tosfile;
827 }
828
829
830 extern char const * prefs_get_mpqfile(void)
831 {
832 return prefs_runtime_config.mpqfile;
833 }
834
835
836 extern char const * prefs_get_trackserv_addrs(void)
837 {
838 return prefs_runtime_config.trackaddrs;
839 }
840
841 extern char const * prefs_get_bnetdserv_addrs(void)
842 {
843 return prefs_runtime_config.servaddrs;
844 }
845
846 extern char const * prefs_get_w3route_addr(void)
847 {
848 return prefs_runtime_config.w3routeaddr;
849 }
850
851 extern char const * prefs_get_irc_addrs(void)
852 {
853 return prefs_runtime_config.ircaddrs;
854 }
855
856
857 extern unsigned int prefs_get_use_keepalive(void)
858 {
859 return prefs_runtime_config.use_keepalive;
860 }
861
862
863 extern unsigned int prefs_get_udptest_port(void)
864 {
865 return prefs_runtime_config.udptest_port;
866 }
867
868
869 extern char const * prefs_get_ipbanfile(void)
870 {
871 return prefs_runtime_config.ipbanfile;
872 }
873
874
875 extern unsigned int prefs_get_discisloss(void)
876 {
877 return prefs_runtime_config.disc_is_loss;
878 }
879
880
881 extern char const * prefs_get_helpfile(void)
882 {
883 return prefs_runtime_config.helpfile;
884 }
885
886
887 extern char const * prefs_get_fortunecmd(void)
888 {
889 return prefs_runtime_config.fortunecmd;
890 }
891
892
893 extern char const * prefs_get_transfile(void)
894 {
895 return prefs_runtime_config.transfile;
896 }
897
898
899 extern unsigned int prefs_get_chanlog(void)
900 {
901 return prefs_runtime_config.chanlog;
902 }
903
904
905 extern char const * prefs_get_chanlogdir(void)
906 {
907 return prefs_runtime_config.chanlogdir;
908 }
909
910
911 extern unsigned int prefs_get_quota(void)
912 {
913 return prefs_runtime_config.quota;
914 }
915
916
917 extern unsigned int prefs_get_quota_lines(void)
918 {
919 unsigned int rez;
920
921 rez=prefs_runtime_config.quota_lines;
922 if (rez<1) rez = 1;
923 if (rez>100) rez = 100;
924 return rez;
925 }
926
927
928 extern unsigned int prefs_get_quota_time(void)
929 {
930 unsigned int rez;
931
932 rez=prefs_runtime_config.quota_time;
933 if (rez<1) rez = 1;
934 if (rez>10) rez = 60;
935 return rez;
936 }
937
938
939 extern unsigned int prefs_get_quota_wrapline(void)
940 {
941 unsigned int rez;
942
943 rez=prefs_runtime_config.quota_wrapline;
944 if (rez<1) rez = 1;
945 if (rez>256) rez = 256;
946 return rez;
947 }
948
949
950 extern unsigned int prefs_get_quota_maxline(void)
951 {
952 unsigned int rez;
953
954 rez=prefs_runtime_config.quota_maxline;
955 if (rez<1) rez = 1;
956 if (rez>256) rez = 256;
957 return rez;
958 }
959
960
961 extern unsigned int prefs_get_ladder_init_rating(void)
962 {
963 return prefs_runtime_config.ladder_init_rating;
964 }
965
966
967 extern unsigned int prefs_get_quota_dobae(void)
968 {
969 unsigned int rez;
970
971 rez=prefs_runtime_config.quota_dobae;
972 if (rez<1) rez = 1;
973 if (rez>100) rez = 100;
974 return rez;
975 }
976
977
978 extern char const * prefs_get_realmfile(void)
979 {
980 return prefs_runtime_config.realmfile;
981 }
982
983
984 extern char const * prefs_get_issuefile(void)
985 {
986 return prefs_runtime_config.issuefile;
987 }
988
989
990 extern char const * prefs_get_effective_user(void)
991 {
992 return prefs_runtime_config.effective_user;
993 }
994
995
996 extern char const * prefs_get_effective_group(void)
997 {
998 return prefs_runtime_config.effective_group;
999 }
1000
1001
1002 extern unsigned int prefs_get_nullmsg(void)
1003 {
1004 return prefs_runtime_config.nullmsg;
1005 }
1006
1007
1008 extern unsigned int prefs_get_mail_support(void)
1009 {
1010 return prefs_runtime_config.mail_support;
1011 }
1012
1013
1014 extern unsigned int prefs_get_mail_quota(void)
1015 {
1016 unsigned int rez;
1017
1018 rez=prefs_runtime_config.mail_quota;
1019 if (rez<1) rez = 1;
1020 if (rez>30) rez = 30;
1021 return rez;
1022 }
1023
1024
1025 extern char const * prefs_get_maildir(void)
1026 {
1027 return prefs_runtime_config.maildir;
1028 }
1029
1030
1031 extern char const * prefs_get_log_notice(void)
1032 {
1033 return prefs_runtime_config.log_notice;
1034 }
1035
1036
1037 extern unsigned int prefs_get_savebyname(void)
1038 {
1039 return prefs_runtime_config.savebyname;
1040 }
1041
1042
1043 extern unsigned int prefs_get_skip_versioncheck(void)
1044 {
1045 return prefs_runtime_config.skip_versioncheck;
1046 }
1047
1048
1049 extern unsigned int prefs_get_allow_bad_version(void)
1050 {
1051 return prefs_runtime_config.allow_bad_version;
1052 }
1053
1054
1055 extern unsigned int prefs_get_allow_unknown_version(void)
1056 {
1057 return prefs_runtime_config.allow_unknown_version;
1058 }
1059
1060
1061 extern char const * prefs_get_versioncheck_file(void)
1062 {
1063 return prefs_runtime_config.versioncheck_file;
1064 }
1065
1066
1067 extern unsigned int prefs_allow_d2cs_setname(void)
1068 {
1069 return prefs_runtime_config.allow_d2cs_setname;
1070 }
1071
1072
1073 extern unsigned int prefs_get_d2cs_version(void)
1074 {
1075 return prefs_runtime_config.d2cs_version;
1076 }
1077
1078
1079 extern unsigned int prefs_get_hashtable_size(void)
1080 {
1081 return prefs_runtime_config.hashtable_size;
1082 }
1083
1084
1085 extern char const * prefs_get_telnet_addrs(void)
1086 {
1087 return prefs_runtime_config.telnetaddrs;
1088 }
1089
1090
1091 extern unsigned int prefs_get_ipban_check_int(void)
1092 {
1093 return prefs_runtime_config.ipban_check_int;
1094 }
1095
1096
1097 extern char const * prefs_get_version_exeinfo_match(void)
1098 {
1099 return prefs_runtime_config.version_exeinfo_match;
1100 }
1101
1102
1103 extern unsigned int prefs_get_version_exeinfo_maxdiff(void)
1104 {
1105 return prefs_runtime_config.version_exeinfo_maxdiff;
1106 }
1107
1108 // added by NonReal
1109 extern unsigned int prefs_get_max_concurrent_logins(void)
1110 {
1111 return prefs_runtime_config.max_concurrent_logins;
1112 }
1113
1114 /* ADDED BY UNDYING SOULZZ 4/9/02 */
1115 extern unsigned int prefs_get_identify_timeout_secs(void)
1116 {
1117 return prefs_runtime_config.identify_timeout_secs;
1118 }
1119
1120 extern char const * prefs_get_server_info( void )
1121 {
1122 return prefs_runtime_config.server_info;
1123 }
1124
1125 extern char const * prefs_get_mapsfile(void)
1126 {
1127 return prefs_runtime_config.mapsfile;
1128 }
1129
1130 extern char const * prefs_get_xplevel_file(void)
1131 {
1132 return prefs_runtime_config.xplevelfile;
1133 }
1134
1135 extern char const * prefs_get_xpcalc_file(void)
1136 {
1137 return prefs_runtime_config.xpcalcfile;
1138 }
1139
1140 extern int prefs_get_initkill_timer(void)
1141 {
1142 return prefs_runtime_config.initkill_timer;
1143 }
1144
1145 extern int prefs_get_war3_ladder_update_secs(void)
1146 {
1147 return prefs_runtime_config.war3_ladder_update_secs;
1148 }
1149
1150 extern int prefs_get_output_update_secs(void)
1151 {
1152 return prefs_runtime_config.output_update_secs;
1153 }
1154
1155 extern char const * prefs_get_ladderdir(void)
1156 {
1157 return prefs_runtime_config.ladderdir;
1158 }
1159
1160 extern char const * prefs_get_outputdir(void)
1161 {
1162 return prefs_runtime_config.statusdir;
1163 }
1164
1165 extern int prefs_get_XML_output_ladder(void)
1166 {
1167 return prefs_runtime_config.XML_output_ladder;
1168 }
1169
1170 extern int prefs_get_XML_status_output(void)
1171 {
1172 return prefs_runtime_config.XML_status_output;
1173 }
1174
1175 extern char const * prefs_get_account_allowed_symbols(void)
1176 {
1177 return prefs_runtime_config.account_allowed_symbols;
1178 }
1179
1180 extern char const * prefs_get_command_groups_file(void)
1181 {
1182 return prefs_runtime_config.command_groups_file;
1183 }
1184
1185 extern char const * prefs_get_tournament_file(void)
1186 {
1187 return prefs_runtime_config.tournament_file;
1188 }
1189
1190 extern char const * prefs_get_aliasfile(void)
1191 {
1192 return prefs_runtime_config.aliasfile;
1193 }
1194
1195 extern char const * prefs_get_anongame_infos_file(void)
1196 {
1197 return prefs_runtime_config.anongame_infos_file;
1198 }
1199
1200 extern unsigned int prefs_get_max_conns_per_IP(void)
1201 {
1202 return prefs_runtime_config.max_conns_per_IP;
1203 }
1204
1205 extern int prefs_get_max_friends(void)
1206 {
1207 return prefs_runtime_config.max_friends;
1208 }
1209
1210 extern unsigned int prefs_get_clan_newer_time(void)
1211 {
1212 return prefs_runtime_config.clan_newer_time;
1213 }
1214
1215 extern unsigned int prefs_get_clan_max_members(void)
1216 {
1217 return prefs_runtime_config.clan_max_members;
1218 }
1219
1220 extern unsigned int prefs_get_clan_channel_default_private(void)
1221 {
1222 return prefs_runtime_config.clan_channel_default_private;
1223 }
1224
1225 extern unsigned int prefs_get_passfail_count(void)
1226 {
1227 return prefs_runtime_config.passfail_count;
1228 }
1229
1230 extern unsigned int prefs_get_passfail_bantime(void)
1231 {
1232 return prefs_runtime_config.passfail_bantime;
1233 }
1234
1235 extern unsigned int prefs_get_maxusers_per_channel(void)
1236 {
1237 return prefs_runtime_config.maxusers_per_channel;
1238 }
1239
1240 extern char const * prefs_get_supportfile(void)
1241 {
1242 return prefs_runtime_config.supportfile;
1243 }
1244
1245 extern char const * prefs_get_allowed_clients(void)
1246 {
1247 return prefs_runtime_config.allowed_clients;
1248 }
1249
1250 extern char const * prefs_get_ladder_games(void)
1251 {
1252 return prefs_runtime_config.ladder_games;
1253 }
1254
1255 extern char const * prefs_get_ladder_prefix(void)
1256 {
1257 return prefs_runtime_config.ladder_prefix;
1258 }
1259
1260 extern unsigned int prefs_get_max_connections(void)
1261 {
1262 return prefs_runtime_config.max_connections;
1263 }
1264
1265 extern unsigned int prefs_get_sync_on_logoff(void)
1266 {
1267 return prefs_runtime_config.sync_on_logoff;
1268 }
1269
1270 extern char const * prefs_get_verify_dir(void)
1271 {
1272 return prefs_runtime_config.verify_dir;
1273 }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1