| 1 |
/*
|
| 2 |
* Copyright (C) 2000,2001 Onlyer (onlyer@263.net)
|
| 3 |
*
|
| 4 |
* This program is free software; you can redistribute it and/or
|
| 5 |
* modify it under the terms of the GNU General Public License
|
| 6 |
* as published by the Free Software Foundation; either version 2
|
| 7 |
* of the License, or (at your option) any later version.
|
| 8 |
*
|
| 9 |
* This program is distributed in the hope that it will be useful,
|
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
* GNU General Public License for more details.
|
| 13 |
*
|
| 14 |
* You should have received a copy of the GNU General Public License
|
| 15 |
* along with this program; if not, write to the Free Software
|
| 16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 17 |
*/
|
| 18 |
#include "common/setup_before.h"
|
| 19 |
#include "setup.h"
|
| 20 |
|
| 21 |
#ifdef HAVE_STDDEF_H
|
| 22 |
# include <stddef.h>
|
| 23 |
#else
|
| 24 |
# ifndef NULL
|
| 25 |
# define NULL ((void *)0)
|
| 26 |
# endif
|
| 27 |
#endif
|
| 28 |
#ifdef HAVE_STRING_H
|
| 29 |
# include <string.h>
|
| 30 |
#else
|
| 31 |
# ifdef HAVE_STRINGS_H
|
| 32 |
# include <strings.h>
|
| 33 |
# endif
|
| 34 |
# ifdef HAVE_MEMORY_H
|
| 35 |
# include <memory.h>
|
| 36 |
# endif
|
| 37 |
#endif
|
| 38 |
#include "compat/memset.h"
|
| 39 |
|
| 40 |
#include "conf.h"
|
| 41 |
#include "prefs.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 |
{ "loglevels", offsetof(t_prefs,loglevels), conf_type_str, 0, DEFAULT_LOG_LEVELS },
|
| 48 |
{ "servaddrs", offsetof(t_prefs,servaddrs), conf_type_str, 0, D2CS_SERVER_ADDRS },
|
| 49 |
{ "gameservlist", offsetof(t_prefs,gameservlist), conf_type_str, 0, D2GS_SERVER_LIST },
|
| 50 |
{ "bnetdaddr", offsetof(t_prefs,bnetdaddr), conf_type_str, 0, BNETD_SERVER_LIST },
|
| 51 |
{ "charsavedir", offsetof(t_prefs,charsavedir), conf_type_str, 0, D2CS_CHARSAVE_DIR },
|
| 52 |
{ "charinfodir", offsetof(t_prefs,charinfodir), conf_type_str, 0, D2CS_CHARINFO_DIR },
|
| 53 |
{ "bak_charsavedir", offsetof(t_prefs,bak_charsavedir), conf_type_str, 0, D2CS_BAK_CHARSAVE_DIR },
|
| 54 |
{ "bak_charinfodir", offsetof(t_prefs,bak_charinfodir), conf_type_str, 0, D2CS_BAK_CHARINFO_DIR },
|
| 55 |
{ "ladderdir", offsetof(t_prefs,ladderdir), conf_type_str, 0, D2CS_LADDER_DIR },
|
| 56 |
// FIXME: ladder_start_time should be conf_type_timestr
|
| 57 |
{ "ladder_start_time", offsetof(t_prefs,ladder_start_time), conf_type_timestr,0, NULL },
|
| 58 |
{ "ladder_refresh_interval",offsetof(t_prefs,ladder_refresh_interval),conf_type_int, 3600, NULL },
|
| 59 |
{ "newbiefile", offsetof(t_prefs,newbiefile), conf_type_str, 0, D2CS_CHARSAVE_NEWBIE },
|
| 60 |
{ "transfile", offsetof(t_prefs,transfile), conf_type_str, 0, D2CS_TRANS_FILE },
|
| 61 |
{ "motd", offsetof(t_prefs,motd), conf_type_hexstr, 0, D2CS_MOTD },
|
| 62 |
{ "realmname", offsetof(t_prefs,realmname), conf_type_str, 0, DEFAULT_REALM_NAME },
|
| 63 |
{ "maxchar", offsetof(t_prefs,maxchar), conf_type_int, MAX_CHAR_PER_ACCT, NULL },
|
| 64 |
{ "listpurgeinterval", offsetof(t_prefs,listpurgeinterval), conf_type_int, LIST_PURGE_INTERVAL, NULL },
|
| 65 |
{ "gqcheckinterval", offsetof(t_prefs,gqcheckinterval), conf_type_int, GAMEQUEUE_CHECK_INTERVAL, NULL },
|
| 66 |
{ "maxgamelist", offsetof(t_prefs,maxgamelist), conf_type_int, MAX_GAME_LIST, NULL },
|
| 67 |
{ "max_game_idletime", offsetof(t_prefs,max_game_idletime), conf_type_int, MAX_GAME_IDLE_TIME, NULL },
|
| 68 |
{ "gamelist_showall", offsetof(t_prefs,gamelist_showall), conf_type_bool, 0, NULL },
|
| 69 |
{ "game_maxlifetime", offsetof(t_prefs,game_maxlifetime), conf_type_int, 0, NULL },
|
| 70 |
{ "allow_gamelimit", offsetof(t_prefs,allow_gamelimit), conf_type_bool, 1, NULL },
|
| 71 |
{ "allow_newchar", offsetof(t_prefs,allow_newchar), conf_type_bool, 1, NULL },
|
| 72 |
{ "idletime", offsetof(t_prefs,idletime), conf_type_int, MAX_CLIENT_IDLETIME, NULL },
|
| 73 |
{ "shutdown_delay", offsetof(t_prefs,shutdown_delay), conf_type_int, DEFAULT_SHUTDOWN_DELAY, NULL },
|
| 74 |
{ "shutdown_decr", offsetof(t_prefs,shutdown_decr), conf_type_int, DEFAULT_SHUTDOWN_DECR, NULL },
|
| 75 |
{ "s2s_retryinterval", offsetof(t_prefs,s2s_retryinterval), conf_type_int, DEFAULT_S2S_RETRYINTERVAL, NULL },
|
| 76 |
{ "s2s_timeout", offsetof(t_prefs,s2s_timeout), conf_type_int, DEFAULT_S2S_TIMEOUT, NULL },
|
| 77 |
{ "sq_checkinterval", offsetof(t_prefs,sq_checkinterval), conf_type_int, DEFAULT_SQ_CHECKINTERVAL, NULL },
|
| 78 |
{ "sq_timeout", offsetof(t_prefs,sq_timeout), conf_type_int, DEFAULT_SQ_TIMEOUT, NULL },
|
| 79 |
{ "d2gs_checksum", offsetof(t_prefs,d2gs_checksum), conf_type_int, 0, NULL },
|
| 80 |
{ "d2gs_version", offsetof(t_prefs,d2gs_version), conf_type_int, 0, NULL },
|
| 81 |
{ "d2gs_password", offsetof(t_prefs,d2gs_password), conf_type_str, 0, "" },
|
| 82 |
{ "check_multilogin", offsetof(t_prefs,check_multilogin), conf_type_int, 1, NULL },
|
| 83 |
{ "s2s_idletime", offsetof(t_prefs,s2s_idletime), conf_type_int, DEFAULT_S2S_IDLETIME, NULL },
|
| 84 |
{ "s2s_keepalive_interval", offsetof(t_prefs,s2s_keepalive_interval), conf_type_int, DEFAULT_S2S_KEEPALIVE_INTERVAL,NULL },
|
| 85 |
{ "timeout_checkinterval", offsetof(t_prefs,timeout_checkinterval), conf_type_int, DEFAULT_TIMEOUT_CHECKINTERVAL, NULL },
|
| 86 |
{ "lod_realm", offsetof(t_prefs,lod_realm), conf_type_int, 2, NULL },
|
| 87 |
{ "allow_convert", offsetof(t_prefs,allow_convert), conf_type_int, 0, NULL },
|
| 88 |
{ "account_allowed_symbols",offsetof(t_prefs,account_allowed_symbols),conf_type_str, 0, DEFAULT_ACC_ALLOWED_SYMBOLS},
|
| 89 |
{ "d2gs_restart_delay", offsetof(t_prefs,d2gs_restart_delay), conf_type_int, DEFAULT_D2GS_RESTART_DELAY, NULL },
|
| 90 |
{ "char_expire_day", offsetof(t_prefs,char_expire_day), conf_type_int, 0, NULL },
|
| 91 |
{ "d2gsconffile", offsetof(t_prefs,d2gsconffile), conf_type_str, 0, "" },
|
| 92 |
{ "charlist_sort", offsetof(t_prefs,charlist_sort), conf_type_str, 0, "none" },
|
| 93 |
{ "charlist_sort_order", offsetof(t_prefs,charlist_sort_order), conf_type_str, 0, "ASC" },
|
| 94 |
{ "max_connections", offsetof(t_prefs,max_connections), conf_type_int, BNETD_MAX_SOCKETS, NULL },
|
| 95 |
/* instructions for antibot, by sowater, 20051001 */
|
| 96 |
{ "enable_antibot", offsetof(t_prefs,enable_antibot), conf_type_bool, 0, NULL},
|
| 97 |
{ "antibot_when_password", offsetof(t_prefs,antibot_when_password), conf_type_bool, 0, NULL},
|
| 98 |
{ "create_game_interval", offsetof(t_prefs,create_game_interval), conf_type_int, 60, NULL},
|
| 99 |
{ "frequently_create_limit", offsetof(t_prefs,frequently_create_limit), conf_type_int, 30, NULL},
|
| 100 |
{ "ban_bot_time", offsetof(t_prefs,ban_bot_time), conf_type_int, 3600, NULL},
|
| 101 |
{ "checknum_try_min", offsetof(t_prefs,checknum_try_min), conf_type_int, 1, NULL},
|
| 102 |
{ "checknum_try_max", offsetof(t_prefs,checknum_try_max), conf_type_int, 2, NULL},
|
| 103 |
{ "checknum_max_fail_times", offsetof(t_prefs,checknum_max_fail_times), conf_type_int, 3, NULL},
|
| 104 |
{ "charstatus_max_chars", offsetof(t_prefs,charstatus_max_chars), conf_type_int, 500, NULL},
|
| 105 |
{ "charstatus_max_life", offsetof(t_prefs,charstatus_max_life), conf_type_int, 3600, NULL},
|
| 106 |
{ "dump_charstatus_list_interval", offsetof(t_prefs,dump_charstatus_list_interval), conf_type_int, 60, NULL},
|
| 107 |
{ NULL, 0, conf_type_none, 0, NULL }
|
| 108 |
};
|
| 109 |
|
| 110 |
static t_prefs prefs_conf;
|
| 111 |
|
| 112 |
extern int d2cs_prefs_load(char const * filename)
|
| 113 |
{
|
| 114 |
memset(&prefs_conf,0,sizeof(prefs_conf));
|
| 115 |
if (conf_load_file(filename,prefs_conf_table,&prefs_conf,sizeof(prefs_conf))<0) {
|
| 116 |
return -1;
|
| 117 |
}
|
| 118 |
return 0;
|
| 119 |
}
|
| 120 |
|
| 121 |
extern int prefs_reload(char const * filename)
|
| 122 |
{
|
| 123 |
d2cs_prefs_unload();
|
| 124 |
if (d2cs_prefs_load(filename)<0) return -1;
|
| 125 |
return 0;
|
| 126 |
}
|
| 127 |
|
| 128 |
extern int d2cs_prefs_unload(void)
|
| 129 |
{
|
| 130 |
return conf_cleanup(prefs_conf_table, &prefs_conf, sizeof(prefs_conf));
|
| 131 |
}
|
| 132 |
|
| 133 |
extern char const * prefs_get_servaddrs(void)
|
| 134 |
{
|
| 135 |
return prefs_conf.servaddrs;
|
| 136 |
}
|
| 137 |
|
| 138 |
extern char const * prefs_get_charsave_dir(void)
|
| 139 |
{
|
| 140 |
return prefs_conf.charsavedir;
|
| 141 |
}
|
| 142 |
|
| 143 |
extern char const * prefs_get_charinfo_dir(void)
|
| 144 |
{
|
| 145 |
return prefs_conf.charinfodir;
|
| 146 |
}
|
| 147 |
|
| 148 |
extern char const * prefs_get_bak_charsave_dir(void)
|
| 149 |
{
|
| 150 |
return prefs_conf.bak_charsavedir;
|
| 151 |
}
|
| 152 |
|
| 153 |
extern char const * prefs_get_bak_charinfo_dir(void)
|
| 154 |
{
|
| 155 |
return prefs_conf.bak_charinfodir;
|
| 156 |
}
|
| 157 |
|
| 158 |
extern char const * prefs_get_charsave_newbie(void)
|
| 159 |
{
|
| 160 |
return prefs_conf.newbiefile;
|
| 161 |
}
|
| 162 |
|
| 163 |
extern char const * prefs_get_motd(void)
|
| 164 |
{
|
| 165 |
return prefs_conf.motd;
|
| 166 |
}
|
| 167 |
|
| 168 |
extern char const * prefs_get_d2gs_list(void)
|
| 169 |
{
|
| 170 |
return prefs_conf.gameservlist;
|
| 171 |
}
|
| 172 |
|
| 173 |
extern unsigned int prefs_get_maxchar(void)
|
| 174 |
{
|
| 175 |
return (prefs_conf.maxchar>MAX_MAX_CHAR_PER_ACCT)?MAX_MAX_CHAR_PER_ACCT:prefs_conf.maxchar;
|
| 176 |
}
|
| 177 |
|
| 178 |
extern unsigned int prefs_get_list_purgeinterval(void)
|
| 179 |
{
|
| 180 |
return prefs_conf.listpurgeinterval;
|
| 181 |
}
|
| 182 |
|
| 183 |
extern unsigned int prefs_get_gamequeue_checkinterval(void)
|
| 184 |
{
|
| 185 |
return prefs_conf.gqcheckinterval;
|
| 186 |
}
|
| 187 |
|
| 188 |
extern unsigned int prefs_get_maxgamelist(void)
|
| 189 |
{
|
| 190 |
return prefs_conf.maxgamelist;
|
| 191 |
}
|
| 192 |
|
| 193 |
extern unsigned int prefs_allow_newchar(void)
|
| 194 |
{
|
| 195 |
return prefs_conf.allow_newchar;
|
| 196 |
}
|
| 197 |
|
| 198 |
extern unsigned int prefs_get_idletime(void)
|
| 199 |
{
|
| 200 |
return prefs_conf.idletime;
|
| 201 |
}
|
| 202 |
|
| 203 |
extern char const * d2cs_prefs_get_logfile(void)
|
| 204 |
{
|
| 205 |
return prefs_conf.logfile;
|
| 206 |
}
|
| 207 |
|
| 208 |
extern unsigned int d2cs_prefs_get_shutdown_delay(void)
|
| 209 |
{
|
| 210 |
return prefs_conf.shutdown_delay;
|
| 211 |
}
|
| 212 |
|
| 213 |
extern unsigned int d2cs_prefs_get_shutdown_decr(void)
|
| 214 |
{
|
| 215 |
return prefs_conf.shutdown_decr;
|
| 216 |
}
|
| 217 |
|
| 218 |
extern char const * prefs_get_bnetdaddr(void)
|
| 219 |
{
|
| 220 |
return prefs_conf.bnetdaddr;
|
| 221 |
}
|
| 222 |
|
| 223 |
extern char const * prefs_get_realmname(void)
|
| 224 |
{
|
| 225 |
return prefs_conf.realmname;
|
| 226 |
}
|
| 227 |
|
| 228 |
extern unsigned int prefs_get_s2s_retryinterval(void)
|
| 229 |
{
|
| 230 |
return prefs_conf.s2s_retryinterval;
|
| 231 |
}
|
| 232 |
|
| 233 |
extern unsigned int prefs_get_s2s_timeout(void)
|
| 234 |
{
|
| 235 |
return prefs_conf.s2s_timeout;
|
| 236 |
}
|
| 237 |
|
| 238 |
extern unsigned int prefs_get_sq_timeout(void)
|
| 239 |
{
|
| 240 |
return prefs_conf.sq_timeout;
|
| 241 |
}
|
| 242 |
|
| 243 |
extern unsigned int prefs_get_sq_checkinterval(void)
|
| 244 |
{
|
| 245 |
return prefs_conf.sq_checkinterval;
|
| 246 |
}
|
| 247 |
|
| 248 |
extern unsigned int prefs_get_d2gs_checksum(void)
|
| 249 |
{
|
| 250 |
return prefs_conf.d2gs_checksum;
|
| 251 |
}
|
| 252 |
|
| 253 |
extern unsigned int prefs_get_d2gs_version(void)
|
| 254 |
{
|
| 255 |
return prefs_conf.d2gs_version;
|
| 256 |
}
|
| 257 |
|
| 258 |
extern unsigned int prefs_get_ladderlist_count(void)
|
| 259 |
{
|
| 260 |
return 0x10;
|
| 261 |
}
|
| 262 |
|
| 263 |
extern unsigned int prefs_get_d2ladder_refresh_interval(void)
|
| 264 |
{
|
| 265 |
return prefs_conf.ladder_refresh_interval;
|
| 266 |
}
|
| 267 |
|
| 268 |
extern unsigned int prefs_get_game_maxlifetime(void)
|
| 269 |
{
|
| 270 |
return prefs_conf.game_maxlifetime;
|
| 271 |
}
|
| 272 |
|
| 273 |
extern char const * prefs_get_ladder_dir(void)
|
| 274 |
{
|
| 275 |
return prefs_conf.ladderdir;
|
| 276 |
}
|
| 277 |
|
| 278 |
extern char const * d2cs_prefs_get_loglevels(void)
|
| 279 |
{
|
| 280 |
return prefs_conf.loglevels;
|
| 281 |
}
|
| 282 |
|
| 283 |
extern unsigned int prefs_allow_gamelist_showall(void)
|
| 284 |
{
|
| 285 |
return prefs_conf.gamelist_showall;
|
| 286 |
}
|
| 287 |
|
| 288 |
extern unsigned int prefs_allow_gamelimit(void)
|
| 289 |
{
|
| 290 |
return prefs_conf.allow_gamelimit;
|
| 291 |
}
|
| 292 |
|
| 293 |
extern unsigned int prefs_check_multilogin(void)
|
| 294 |
{
|
| 295 |
return prefs_conf.check_multilogin;
|
| 296 |
}
|
| 297 |
|
| 298 |
extern char const * prefs_get_d2gs_password(void)
|
| 299 |
{
|
| 300 |
return prefs_conf.d2gs_password;
|
| 301 |
}
|
| 302 |
|
| 303 |
extern unsigned int prefs_get_s2s_idletime(void)
|
| 304 |
{
|
| 305 |
return prefs_conf.s2s_idletime;
|
| 306 |
}
|
| 307 |
|
| 308 |
extern unsigned int prefs_get_s2s_keepalive_interval(void)
|
| 309 |
{
|
| 310 |
return prefs_conf.s2s_keepalive_interval;
|
| 311 |
}
|
| 312 |
|
| 313 |
extern unsigned int prefs_get_timeout_checkinterval(void)
|
| 314 |
{
|
| 315 |
return prefs_conf.timeout_checkinterval;
|
| 316 |
}
|
| 317 |
|
| 318 |
extern unsigned int prefs_get_max_game_idletime(void)
|
| 319 |
{
|
| 320 |
return prefs_conf.max_game_idletime;
|
| 321 |
}
|
| 322 |
|
| 323 |
extern unsigned int prefs_get_lod_realm(void)
|
| 324 |
{
|
| 325 |
return prefs_conf.lod_realm;
|
| 326 |
}
|
| 327 |
|
| 328 |
extern unsigned int prefs_get_allow_convert(void)
|
| 329 |
{
|
| 330 |
return prefs_conf.allow_convert;
|
| 331 |
}
|
| 332 |
|
| 333 |
extern char const * d2cs_prefs_get_transfile(void)
|
| 334 |
{
|
| 335 |
return prefs_conf.transfile;
|
| 336 |
}
|
| 337 |
|
| 338 |
extern char const * prefs_get_d2cs_account_allowed_symbols(void)
|
| 339 |
{
|
| 340 |
return prefs_conf.account_allowed_symbols;
|
| 341 |
}
|
| 342 |
|
| 343 |
extern unsigned int prefs_get_ladder_start_time(void)
|
| 344 |
{
|
| 345 |
return prefs_conf.ladder_start_time;
|
| 346 |
}
|
| 347 |
|
| 348 |
extern unsigned int prefs_get_d2gs_restart_delay(void)
|
| 349 |
{
|
| 350 |
return prefs_conf.d2gs_restart_delay;
|
| 351 |
}
|
| 352 |
|
| 353 |
extern unsigned int prefs_get_char_expire_time(void)
|
| 354 |
{
|
| 355 |
return prefs_conf.char_expire_day * 3600 * 24;
|
| 356 |
}
|
| 357 |
|
| 358 |
extern char const * prefs_get_d2gsconffile(void)
|
| 359 |
{
|
| 360 |
return prefs_conf.d2gsconffile;
|
| 361 |
}
|
| 362 |
|
| 363 |
extern char const * prefs_get_charlist_sort(void)
|
| 364 |
{
|
| 365 |
return prefs_conf.charlist_sort;
|
| 366 |
}
|
| 367 |
|
| 368 |
extern char const * prefs_get_charlist_sort_order(void)
|
| 369 |
{
|
| 370 |
return prefs_conf.charlist_sort_order;
|
| 371 |
}
|
| 372 |
|
| 373 |
extern unsigned int prefs_get_max_connections(void)
|
| 374 |
{
|
| 375 |
return prefs_conf.max_connections;
|
| 376 |
}
|
| 377 |
|
| 378 |
/* get values of instructions for antibot, by sowater ,20051001 */
|
| 379 |
|
| 380 |
extern unsigned int prefs_enable_antibot(void)
|
| 381 |
{
|
| 382 |
return prefs_conf.enable_antibot;
|
| 383 |
}
|
| 384 |
|
| 385 |
extern unsigned int prefs_antibot_when_password(void)
|
| 386 |
{
|
| 387 |
return prefs_conf.antibot_when_password;
|
| 388 |
}
|
| 389 |
|
| 390 |
/* by leaflet */
|
| 391 |
extern unsigned int prefs_create_game_interval(void)
|
| 392 |
{
|
| 393 |
return prefs_conf.create_game_interval;
|
| 394 |
}
|
| 395 |
|
| 396 |
extern unsigned int prefs_frequently_create_limit(void)
|
| 397 |
{
|
| 398 |
return prefs_conf.frequently_create_limit;
|
| 399 |
}
|
| 400 |
|
| 401 |
extern unsigned int prefs_ban_bot_time(void)
|
| 402 |
{
|
| 403 |
return prefs_conf.ban_bot_time;
|
| 404 |
}
|
| 405 |
|
| 406 |
extern unsigned int prefs_checknum_try_min(void)
|
| 407 |
{
|
| 408 |
return prefs_conf.checknum_try_min;
|
| 409 |
}
|
| 410 |
|
| 411 |
extern unsigned int prefs_checknum_try_max(void)
|
| 412 |
{
|
| 413 |
return prefs_conf.checknum_try_max;
|
| 414 |
}
|
| 415 |
|
| 416 |
extern unsigned int prefs_checknum_max_fail_times(void)
|
| 417 |
{
|
| 418 |
return prefs_conf.checknum_max_fail_times;
|
| 419 |
}
|
| 420 |
|
| 421 |
extern unsigned int prefs_charstatus_max_chars(void)
|
| 422 |
{
|
| 423 |
return prefs_conf.charstatus_max_chars;
|
| 424 |
}
|
| 425 |
|
| 426 |
extern unsigned int prefs_charstatus_max_life(void)
|
| 427 |
{
|
| 428 |
return prefs_conf.charstatus_max_life;
|
| 429 |
}
|
| 430 |
|
| 431 |
extern unsigned int prefs_dump_charstatus_list_interval(void)
|
| 432 |
{
|
| 433 |
return prefs_conf.dump_charstatus_list_interval;
|
| 434 |
}
|