prefs.c
上传用户:tany51
上传日期:2013-06-12
资源大小:1397k
文件大小:7k
源码类别:

MySQL数据库

开发平台:

Visual C++

  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. #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 "prefs.h"
  39. #include "d2cs/conf.h"
  40. #include "common/eventlog.h"
  41. #include "common/setup_after.h"
  42. static t_conf_table prefs_conf_table[]={
  43.     { "logfile",               offsetof(t_prefs,logfile),               conf_type_str, 0,                             DEFAULT_LOG_FILE     },
  44.     { "logfile-gs",            offsetof(t_prefs,logfile_gs),            conf_type_str, 0,                             DEFAULT_LOG_FILE_GS  },
  45.     { "loglevels",             offsetof(t_prefs,loglevels),             conf_type_str, 0,                             DEFAULT_LOG_LEVELS   },
  46.     { "servaddrs",             offsetof(t_prefs,servaddrs),             conf_type_str, 0,                             D2DBS_SERVER_ADDRS   },
  47.     { "gameservlist",          offsetof(t_prefs,gameservlist),          conf_type_str, 0,                             D2GS_SERVER_LIST     },
  48.     { "charsavedir",           offsetof(t_prefs,charsavedir),           conf_type_str, 0,                             D2DBS_CHARSAVE_DIR   },
  49.     { "charinfodir",           offsetof(t_prefs,charinfodir),           conf_type_str, 0,                             D2DBS_CHARINFO_DIR   },
  50.     { "bak_charsavedir",       offsetof(t_prefs,charsavebakdir),        conf_type_str, 0,                             D2DBS_CHARSAVEBAK_DIR},
  51.     { "bak_charinfodir",       offsetof(t_prefs,charinfobakdir),        conf_type_str, 0,                             D2DBS_CHARINFOBAK_DIR},
  52.     { "ladderdir",             offsetof(t_prefs,ladderdir),             conf_type_str, 0,                             D2DBS_LADDER_DIR     },
  53.     { "laddersave_interval",   offsetof(t_prefs,laddersave_interval),   conf_type_int, 3600,                          NULL                 },
  54.     { "ladderinit_time",       offsetof(t_prefs,ladderinit_time),       conf_type_int, 0,                             NULL                 },
  55.     { "shutdown_delay",        offsetof(t_prefs,shutdown_delay),        conf_type_int, DEFAULT_SHUTDOWN_DELAY,        NULL                 },
  56.     { "shutdown_decr",         offsetof(t_prefs,shutdown_decr),         conf_type_int, DEFAULT_SHUTDOWN_DECR,         NULL                 },
  57.     { "idletime",              offsetof(t_prefs,idletime),              conf_type_int, DEFAULT_IDLETIME,              NULL                 },
  58.     { "keepalive_interval",    offsetof(t_prefs,keepalive_interval),    conf_type_int, DEFAULT_KEEPALIVE_INTERVAL,    NULL                 },
  59.     { "timeout_checkinterval", offsetof(t_prefs,timeout_checkinterval), conf_type_int, DEFAULT_TIMEOUT_CHECKINTERVAL, NULL                 },
  60.     { "XML_ladder_output"    , offsetof(t_prefs,XML_ladder_output),     conf_type_int, 0,                             NULL                 },
  61.     { "ladderupdate_threshold",offsetof(t_prefs,ladderupdate_threshold),conf_type_int, DEFAULT_LADDERUPDATE_THRESHOLD,NULL                 },
  62.     { "ladder_chars_only",     offsetof(t_prefs,ladder_chars_only),     conf_type_int, 0,                             NULL                 },
  63.     { NULL,                   0,                                        conf_type_none,0,                             NULL                 }
  64. };
  65. static t_prefs prefs_conf;
  66. extern int d2dbs_prefs_load(char const * filename)
  67. {
  68. memset(&prefs_conf,0,sizeof(prefs_conf));
  69. if (conf_load_file(filename,prefs_conf_table,&prefs_conf,sizeof(prefs_conf))<0) {
  70. return -1;
  71. }
  72. return 0;
  73. }
  74. extern int d2dbs_prefs_reload(char const * filename)
  75. {
  76.         d2dbs_prefs_unload();
  77.         if (d2dbs_prefs_load(filename)<0) return -1;
  78.         return 0;
  79. }
  80. extern int d2dbs_prefs_unload(void)
  81. {
  82. return conf_cleanup(prefs_conf_table, &prefs_conf, sizeof(prefs_conf));
  83. }
  84. extern char const * d2dbs_prefs_get_servaddrs(void)
  85. {
  86. return prefs_conf.servaddrs;
  87. }
  88. extern char const * d2dbs_prefs_get_charsave_dir(void)
  89. {
  90. return prefs_conf.charsavedir;
  91. }
  92. extern char const * d2dbs_prefs_get_charinfo_dir(void)
  93. {
  94. return prefs_conf.charinfodir;
  95. }
  96. extern char const * d2dbs_prefs_get_d2gs_list(void)
  97. {
  98. return prefs_conf.gameservlist;
  99. }
  100. extern char const * d2dbs_prefs_get_ladder_dir(void)
  101. {
  102. return prefs_conf.ladderdir;
  103. }
  104. extern char const * d2dbs_prefs_get_logfile(void)
  105. {
  106. return prefs_conf.logfile;
  107. }
  108. extern char const * prefs_get_logfile_gs(void)
  109. {
  110. return prefs_conf.logfile_gs;
  111. }
  112. extern char const * prefs_get_charsave_bak_dir(void)
  113. {
  114. return prefs_conf.charsavebakdir;
  115. }
  116. extern char const * prefs_get_charinfo_bak_dir(void)
  117. {
  118. return prefs_conf.charinfobakdir;
  119. }
  120. extern unsigned int prefs_get_laddersave_interval(void)
  121. {
  122. return prefs_conf.laddersave_interval;
  123. }
  124. extern unsigned int prefs_get_ladderinit_time(void)
  125. {
  126. return prefs_conf.ladderinit_time;
  127. }
  128. extern char const * d2dbs_prefs_get_loglevels(void)
  129. {
  130. return prefs_conf.loglevels;
  131. }
  132. extern unsigned int d2dbs_prefs_get_shutdown_delay(void)
  133. {
  134.         return prefs_conf.shutdown_delay;
  135. }
  136. extern unsigned int d2dbs_prefs_get_shutdown_decr(void)
  137. {
  138.         return prefs_conf.shutdown_decr;
  139. }
  140. extern unsigned int prefs_get_keepalive_interval(void)
  141. {
  142.         return prefs_conf.keepalive_interval;
  143. }
  144. extern unsigned int d2dbs_prefs_get_idletime(void)
  145. {
  146.         return prefs_conf.idletime;
  147. }
  148. extern unsigned int d2dbs_prefs_get_timeout_checkinterval(void)
  149. {
  150. return prefs_conf.timeout_checkinterval;
  151. }
  152. extern unsigned int d2dbs_prefs_get_XML_output_ladder(void)
  153. {
  154.         return prefs_conf.XML_ladder_output;
  155. }
  156. extern unsigned int prefs_get_ladderupdate_threshold(void)
  157. {
  158. return prefs_conf.ladderupdate_threshold;
  159. }
  160. extern unsigned int prefs_get_ladder_chars_only(void)
  161. {
  162. return prefs_conf.ladder_chars_only;
  163. }