| 1 |
sysadm |
1.1 |
/*
|
| 2 |
|
|
* Copyright (C) 2000,2001 Onlyer (onlyer@263.net)
|
| 3 |
|
|
* Copyright (C) 2001 sousou (liupeng.cs@263.net)
|
| 4 |
|
|
*
|
| 5 |
|
|
* This program is free software; you can redistribute it and/or
|
| 6 |
|
|
* modify it under the terms of the GNU General Public License
|
| 7 |
|
|
* as published by the Free Software Foundation; either version 2
|
| 8 |
|
|
* of the License, or (at your option) any later version.
|
| 9 |
|
|
*
|
| 10 |
|
|
* This program is distributed in the hope that it will be useful,
|
| 11 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
|
|
* GNU General Public License for more details.
|
| 14 |
|
|
*
|
| 15 |
|
|
* You should have received a copy of the GNU General Public License
|
| 16 |
|
|
* along with this program; if not, write to the Free Software
|
| 17 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 18 |
|
|
*/
|
| 19 |
|
|
#include "common/setup_before.h"
|
| 20 |
|
|
#include "setup.h"
|
| 21 |
|
|
|
| 22 |
|
|
#ifdef HAVE_STDDEF_H
|
| 23 |
|
|
# include <stddef.h>
|
| 24 |
|
|
#else
|
| 25 |
|
|
# ifndef NULL
|
| 26 |
|
|
# define NULL ((void *)0)
|
| 27 |
|
|
# endif
|
| 28 |
|
|
#endif
|
| 29 |
|
|
#ifdef HAVE_STRING_H
|
| 30 |
|
|
# include <string.h>
|
| 31 |
|
|
#else
|
| 32 |
|
|
# ifdef HAVE_STRINGS_H
|
| 33 |
|
|
# include <strings.h>
|
| 34 |
|
|
# endif
|
| 35 |
|
|
# ifdef HAVE_MEMORY_H
|
| 36 |
|
|
# include <memory.h>
|
| 37 |
|
|
# endif
|
| 38 |
|
|
#endif
|
| 39 |
|
|
|
| 40 |
|
|
#include "prefs.h"
|
| 41 |
|
|
#include "d2cs/conf.h"
|
| 42 |
|
|
#include "common/eventlog.h"
|
| 43 |
|
|
#include "common/setup_after.h"
|
| 44 |
|
|
|
| 45 |
|
|
static t_conf_table prefs_conf_table[]={
|
| 46 |
|
|
{ "logfile", offsetof(t_prefs,logfile), conf_type_str, 0, DEFAULT_LOG_FILE },
|
| 47 |
|
|
{ "logfile-gs", offsetof(t_prefs,logfile_gs), conf_type_str, 0, DEFAULT_LOG_FILE_GS },
|
| 48 |
|
|
{ "loglevels", offsetof(t_prefs,loglevels), conf_type_str, 0, DEFAULT_LOG_LEVELS },
|
| 49 |
|
|
{ "servaddrs", offsetof(t_prefs,servaddrs), conf_type_str, 0, D2DBS_SERVER_ADDRS },
|
| 50 |
|
|
{ "gameservlist", offsetof(t_prefs,gameservlist), conf_type_str, 0, D2GS_SERVER_LIST },
|
| 51 |
|
|
{ "charsavedir", offsetof(t_prefs,charsavedir), conf_type_str, 0, D2DBS_CHARSAVE_DIR },
|
| 52 |
|
|
{ "charinfodir", offsetof(t_prefs,charinfodir), conf_type_str, 0, D2DBS_CHARINFO_DIR },
|
| 53 |
|
|
{ "bak_charsavedir", offsetof(t_prefs,charsavebakdir), conf_type_str, 0, D2DBS_CHARSAVEBAK_DIR},
|
| 54 |
|
|
{ "bak_charinfodir", offsetof(t_prefs,charinfobakdir), conf_type_str, 0, D2DBS_CHARINFOBAK_DIR},
|
| 55 |
|
|
{ "ladderdir", offsetof(t_prefs,ladderdir), conf_type_str, 0, D2DBS_LADDER_DIR },
|
| 56 |
|
|
{ "laddersave_interval", offsetof(t_prefs,laddersave_interval), conf_type_int, 3600, NULL },
|
| 57 |
|
|
{ "ladderinit_time", offsetof(t_prefs,ladderinit_time), conf_type_int, 0, NULL },
|
| 58 |
|
|
{ "shutdown_delay", offsetof(t_prefs,shutdown_delay), conf_type_int, DEFAULT_SHUTDOWN_DELAY, NULL },
|
| 59 |
|
|
{ "shutdown_decr", offsetof(t_prefs,shutdown_decr), conf_type_int, DEFAULT_SHUTDOWN_DECR, NULL },
|
| 60 |
|
|
{ "idletime", offsetof(t_prefs,idletime), conf_type_int, DEFAULT_IDLETIME, NULL },
|
| 61 |
|
|
{ "keepalive_interval", offsetof(t_prefs,keepalive_interval), conf_type_int, DEFAULT_KEEPALIVE_INTERVAL, NULL },
|
| 62 |
|
|
{ "timeout_checkinterval", offsetof(t_prefs,timeout_checkinterval), conf_type_int, DEFAULT_TIMEOUT_CHECKINTERVAL, NULL },
|
| 63 |
|
|
{ "XML_ladder_output" , offsetof(t_prefs,XML_ladder_output), conf_type_int, 0, NULL },
|
| 64 |
|
|
{ "ladderupdate_threshold",offsetof(t_prefs,ladderupdate_threshold),conf_type_int, DEFAULT_LADDERUPDATE_THRESHOLD,NULL },
|
| 65 |
|
|
{ "ladder_chars_only", offsetof(t_prefs,ladder_chars_only), conf_type_int, 0, NULL },
|
| 66 |
|
|
{ "difficulty_hack", offsetof(t_prefs,difficulty_hack), conf_type_int, 0, NULL },
|
| 67 |
|
|
{ NULL, 0, conf_type_none,0, NULL }
|
| 68 |
|
|
};
|
| 69 |
|
|
|
| 70 |
|
|
static t_prefs prefs_conf;
|
| 71 |
|
|
|
| 72 |
|
|
extern int d2dbs_prefs_load(char const * filename)
|
| 73 |
|
|
{
|
| 74 |
|
|
memset(&prefs_conf,0,sizeof(prefs_conf));
|
| 75 |
|
|
if (conf_load_file(filename,prefs_conf_table,&prefs_conf,sizeof(prefs_conf))<0) {
|
| 76 |
|
|
return -1;
|
| 77 |
|
|
}
|
| 78 |
|
|
return 0;
|
| 79 |
|
|
}
|
| 80 |
|
|
|
| 81 |
|
|
extern int d2dbs_prefs_reload(char const * filename)
|
| 82 |
|
|
{
|
| 83 |
|
|
d2dbs_prefs_unload();
|
| 84 |
|
|
if (d2dbs_prefs_load(filename)<0) return -1;
|
| 85 |
|
|
return 0;
|
| 86 |
|
|
}
|
| 87 |
|
|
|
| 88 |
|
|
extern int d2dbs_prefs_unload(void)
|
| 89 |
|
|
{
|
| 90 |
|
|
return conf_cleanup(prefs_conf_table, &prefs_conf, sizeof(prefs_conf));
|
| 91 |
|
|
}
|
| 92 |
|
|
|
| 93 |
|
|
extern char const * d2dbs_prefs_get_servaddrs(void)
|
| 94 |
|
|
{
|
| 95 |
|
|
return prefs_conf.servaddrs;
|
| 96 |
|
|
}
|
| 97 |
|
|
|
| 98 |
|
|
extern char const * d2dbs_prefs_get_charsave_dir(void)
|
| 99 |
|
|
{
|
| 100 |
|
|
return prefs_conf.charsavedir;
|
| 101 |
|
|
}
|
| 102 |
|
|
|
| 103 |
|
|
extern char const * d2dbs_prefs_get_charinfo_dir(void)
|
| 104 |
|
|
{
|
| 105 |
|
|
return prefs_conf.charinfodir;
|
| 106 |
|
|
}
|
| 107 |
|
|
|
| 108 |
|
|
extern char const * d2dbs_prefs_get_d2gs_list(void)
|
| 109 |
|
|
{
|
| 110 |
|
|
return prefs_conf.gameservlist;
|
| 111 |
|
|
}
|
| 112 |
|
|
|
| 113 |
|
|
extern char const * d2dbs_prefs_get_ladder_dir(void)
|
| 114 |
|
|
{
|
| 115 |
|
|
return prefs_conf.ladderdir;
|
| 116 |
|
|
}
|
| 117 |
|
|
|
| 118 |
|
|
extern char const * d2dbs_prefs_get_logfile(void)
|
| 119 |
|
|
{
|
| 120 |
|
|
return prefs_conf.logfile;
|
| 121 |
|
|
}
|
| 122 |
|
|
|
| 123 |
|
|
extern char const * prefs_get_logfile_gs(void)
|
| 124 |
|
|
{
|
| 125 |
|
|
return prefs_conf.logfile_gs;
|
| 126 |
|
|
}
|
| 127 |
|
|
|
| 128 |
|
|
extern char const * prefs_get_charsave_bak_dir(void)
|
| 129 |
|
|
{
|
| 130 |
|
|
return prefs_conf.charsavebakdir;
|
| 131 |
|
|
}
|
| 132 |
|
|
|
| 133 |
|
|
extern char const * prefs_get_charinfo_bak_dir(void)
|
| 134 |
|
|
{
|
| 135 |
|
|
return prefs_conf.charinfobakdir;
|
| 136 |
|
|
}
|
| 137 |
|
|
|
| 138 |
|
|
extern unsigned int prefs_get_laddersave_interval(void)
|
| 139 |
|
|
{
|
| 140 |
|
|
return prefs_conf.laddersave_interval;
|
| 141 |
|
|
}
|
| 142 |
|
|
|
| 143 |
|
|
extern unsigned int prefs_get_ladderinit_time(void)
|
| 144 |
|
|
{
|
| 145 |
|
|
return prefs_conf.ladderinit_time;
|
| 146 |
|
|
}
|
| 147 |
|
|
|
| 148 |
|
|
extern char const * d2dbs_prefs_get_loglevels(void)
|
| 149 |
|
|
{
|
| 150 |
|
|
return prefs_conf.loglevels;
|
| 151 |
|
|
}
|
| 152 |
|
|
|
| 153 |
|
|
extern unsigned int d2dbs_prefs_get_shutdown_delay(void)
|
| 154 |
|
|
{
|
| 155 |
|
|
return prefs_conf.shutdown_delay;
|
| 156 |
|
|
}
|
| 157 |
|
|
|
| 158 |
|
|
extern unsigned int d2dbs_prefs_get_shutdown_decr(void)
|
| 159 |
|
|
{
|
| 160 |
|
|
return prefs_conf.shutdown_decr;
|
| 161 |
|
|
}
|
| 162 |
|
|
|
| 163 |
|
|
extern unsigned int prefs_get_keepalive_interval(void)
|
| 164 |
|
|
{
|
| 165 |
|
|
return prefs_conf.keepalive_interval;
|
| 166 |
|
|
}
|
| 167 |
|
|
|
| 168 |
|
|
extern unsigned int d2dbs_prefs_get_idletime(void)
|
| 169 |
|
|
{
|
| 170 |
|
|
return prefs_conf.idletime;
|
| 171 |
|
|
}
|
| 172 |
|
|
|
| 173 |
|
|
extern unsigned int d2dbs_prefs_get_timeout_checkinterval(void)
|
| 174 |
|
|
{
|
| 175 |
|
|
return prefs_conf.timeout_checkinterval;
|
| 176 |
|
|
}
|
| 177 |
|
|
|
| 178 |
|
|
extern unsigned int d2dbs_prefs_get_XML_output_ladder(void)
|
| 179 |
|
|
{
|
| 180 |
|
|
return prefs_conf.XML_ladder_output;
|
| 181 |
|
|
}
|
| 182 |
|
|
|
| 183 |
|
|
extern unsigned int prefs_get_ladderupdate_threshold(void)
|
| 184 |
|
|
{
|
| 185 |
|
|
return prefs_conf.ladderupdate_threshold;
|
| 186 |
|
|
}
|
| 187 |
|
|
|
| 188 |
|
|
extern unsigned int prefs_get_ladder_chars_only(void)
|
| 189 |
|
|
{
|
| 190 |
|
|
return prefs_conf.ladder_chars_only;
|
| 191 |
|
|
}
|
| 192 |
|
|
|
| 193 |
|
|
extern unsigned int prefs_get_difficulty_hack(void)
|
| 194 |
|
|
{
|
| 195 |
|
|
return prefs_conf.difficulty_hack;
|
| 196 |
|
|
}
|