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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Tue Jun 6 03:41:37 2006 UTC (19 years, 9 months ago) by sysadm
Branch: MAIN
Branch point for: GNU
Content type: text/x-csrc
Initial revision

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

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