summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c7
-rw-r--r--src/char/char.h2
-rw-r--r--src/char/geoip.c5
-rw-r--r--src/char/int_guild.c2
-rw-r--r--src/common/conf.c30
-rw-r--r--src/common/conf.h4
-rw-r--r--src/config/const.h7
-rw-r--r--src/map/achievement.c6
-rw-r--r--src/map/clif.c9
-rw-r--r--src/map/guild.c3
-rw-r--r--src/map/itemdb.c24
-rw-r--r--src/map/map.c10
-rw-r--r--src/map/mob.c4
-rw-r--r--src/map/pc.c9
-rw-r--r--src/map/script.c3
-rw-r--r--src/map/skill.c2
-rw-r--r--src/map/status.c6
-rw-r--r--src/map/stylist.c3
18 files changed, 87 insertions, 49 deletions
diff --git a/src/char/char.c b/src/char/char.c
index c5afc0f63..66ca0b317 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -120,8 +120,6 @@ char char_achievement_db[256] = "char_achievements";
static struct char_interface char_s;
struct char_interface *chr;
-char db_path[1024] = "db";
-
static char wisp_server_name[NAME_LENGTH] = "Server";
static char login_ip_str[128];
static uint32 login_ip = 0;
@@ -5791,7 +5789,8 @@ static bool char_config_read_database(const char *filename, const struct config_
if (autosave_interval <= 0)
autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
}
- libconfig->setting_lookup_mutable_string(setting, "db_path", db_path, sizeof(db_path));
+ libconfig->setting_lookup_mutable_string(setting, "db_path", chr->db_path, sizeof(chr->db_path));
+ libconfig->set_db_path(chr->db_path);
libconfig->setting_lookup_bool_real(setting, "log_char", &chr->enable_logs);
return true;
}
@@ -6453,6 +6452,8 @@ void char_defaults(void)
chr = &char_s;
memset(chr->server, 0, sizeof(chr->server));
+ sprintf(chr->db_path, "db");
+ libconfig->set_db_path(chr->db_path);
chr->login_fd = 0;
chr->char_fd = -1;
diff --git a/src/char/char.h b/src/char/char.h
index 5de3e2a80..3b8bcff2e 100644
--- a/src/char/char.h
+++ b/src/char/char.h
@@ -124,6 +124,8 @@ struct char_interface {
bool show_save_log; ///< Show loading/saving messages.
bool enable_logs; ///< Whether to log char server operations.
+ char db_path[256]; //< Database directory (db)
+
int (*waiting_disconnect) (int tid, int64 tick, int id, intptr_t data);
int (*delete_char_sql) (int char_id);
struct DBData (*create_online_char_data) (union DBKey key, va_list args);
diff --git a/src/char/geoip.c b/src/char/geoip.c
index 2870e5f0c..67c057aff 100644
--- a/src/char/geoip.c
+++ b/src/char/geoip.c
@@ -23,6 +23,7 @@
#include "geoip.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/memmgr.h"
#include "common/showmsg.h"
@@ -141,7 +142,9 @@ static void geoip_init(void)
geoip->data->active = true;
- db = fopen("./db/GeoIP.dat","rb");
+ char file_path[256];
+ libconfig->format_db_path("GeoIP.dat", file_path, sizeof(file_path));
+ db = fopen(file_path, "rb");
if (db == NULL) {
ShowError("geoip_readdb: Error reading GeoIP.dat!\n");
geoip->final(false);
diff --git a/src/char/int_guild.c b/src/char/int_guild.c
index 87cb3bee0..3e9d50f8d 100644
--- a/src/char/int_guild.c
+++ b/src/char/int_guild.c
@@ -747,7 +747,7 @@ static int inter_guild_sql_init(void)
inter_guild->castle_db = idb_alloc(DB_OPT_RELEASE_DATA);
//Read exp file
- sv->readdb("db", DBPATH"exp_guild.txt", ',', 1, 1, MAX_GUILDLEVEL, inter_guild->exp_parse_row);
+ sv->readdb(chr->db_path, DBPATH"exp_guild.txt", ',', 1, 1, MAX_GUILDLEVEL, inter_guild->exp_parse_row);
timer->add_func_list(inter_guild->save_timer, "inter_guild->save_timer");
timer->add(timer->gettick() + 10000, inter_guild->save_timer, 0, 0);
diff --git a/src/common/conf.c b/src/common/conf.c
index 0ad350057..d81a6636b 100644
--- a/src/common/conf.c
+++ b/src/common/conf.c
@@ -22,6 +22,7 @@
#include "conf.h"
+#include "common/nullpo.h" // nullpo_retv
#include "common/showmsg.h" // ShowError
#include "common/strlib.h" // safestrncpy
#include "common/utils.h" // exists
@@ -33,6 +34,31 @@ static struct libconfig_interface libconfig_s;
struct libconfig_interface *libconfig;
/**
+ * Sets the server's db_path to be used by config_format_db_path
+ * @param db_path path to the folder where the db files are at
+ */
+static void config_set_db_path(const char *db_path)
+{
+ nullpo_retv(db_path);
+ safestrncpy(libconfig->db_path, db_path, sizeof(libconfig->db_path));
+}
+
+/**
+ * Writes into path_buf the fullpath to the db file in filename.
+ * Basically this prepends map->db_path to filename.
+ * @param filename File name to format (e.g. re/item_db.conf)
+ * @param path_buf Where to save the path to
+ * @param buffer_len Maximun length of path_buf
+ */
+static void config_format_db_path(const char *filename, char *path_buf, int buffer_len)
+{
+ nullpo_retv(filename);
+ nullpo_retv(path_buf);
+
+ safesnprintf(path_buf, buffer_len, "%s/%s", libconfig->db_path, filename);
+}
+
+/**
* Initializes 'config' and loads a configuration file.
*
* Shows error and destroys 'config' in case of failure.
@@ -450,6 +476,10 @@ static int config_lookup_int64_real(const struct config_t *config, const char *f
void libconfig_defaults(void) {
libconfig = &libconfig_s;
+ snprintf(libconfig->db_path, sizeof(libconfig->db_path), "db");
+ libconfig->set_db_path = config_set_db_path;
+ libconfig->format_db_path = config_format_db_path;
+ /* */
libconfig->read = config_read;
libconfig->write = config_write;
/* */
diff --git a/src/common/conf.h b/src/common/conf.h
index 66960c0ec..ccab6dc17 100644
--- a/src/common/conf.h
+++ b/src/common/conf.h
@@ -29,6 +29,10 @@
* The libconfig interface -- specially for plugins, but we enforce it throughout the core to be consistent
**/
struct libconfig_interface {
+ char db_path[256];
+ void (*set_db_path) (const char *db_path);
+ void (*format_db_path) (const char *filename, char *path_buf, int buffer_len);
+ /* */
int (*read) (struct config_t *config, FILE *stream);
void (*write) (const struct config_t *config, FILE *stream);
/* */
diff --git a/src/config/const.h b/src/config/const.h
index 4767b5721..df8c07b67 100644
--- a/src/config/const.h
+++ b/src/config/const.h
@@ -49,10 +49,13 @@
/**
* Path within the /db folder to (non-)renewal specific db files
**/
+#define DBPATH_RE "re/"
+#define DBPATH_PRE "pre-re/"
+
#ifdef RENEWAL
- #define DBPATH "re/"
+ #define DBPATH DBPATH_RE
#else
- #define DBPATH "pre-re/"
+ #define DBPATH DBPATH_PRE
#endif
/**
diff --git a/src/map/achievement.c b/src/map/achievement.c
index 7ab80e183..c2ebb5fdd 100644
--- a/src/map/achievement.c
+++ b/src/map/achievement.c
@@ -1099,7 +1099,8 @@ static bool achievement_get_rewards(struct map_session_data *sd, const struct ac
*/
static void achievement_readdb_ranks(void)
{
- const char *filename = "db/achievement_rank_db.conf";
+ char filename[256];
+ libconfig->format_db_path("achievement_rank_db.conf", filename, sizeof(filename));
struct config_t ar_conf = { 0 };
struct config_setting_t *ardb = NULL, *conf = NULL;
int entry = 0;
@@ -1777,7 +1778,8 @@ static void achievement_readdb_additional_fields(const struct config_setting_t *
*/
static void achievement_readb(void)
{
- const char *filename = "db/"DBPATH"achievement_db.conf";
+ char filename[256];
+ libconfig->format_db_path(DBPATH"achievement_db.conf", filename, sizeof(filename));
struct config_t ach_conf = { 0 };
struct config_setting_t *achdb = NULL, *conf = NULL;
int entry = 0, count = 0;
diff --git a/src/map/clif.c b/src/map/clif.c
index f6caa502e..f8e2b63a2 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -19784,7 +19784,8 @@ static void clif_cashshop_db(void)
{
struct config_t cashshop_conf;
struct config_setting_t *cashshop = NULL, *cats = NULL;
- const char *config_filename = "db/cashshop_db.conf"; // FIXME hardcoded name
+ char config_filename[256];
+ libconfig->format_db_path("cashshop_db.conf", config_filename, sizeof(config_filename));
int i, item_count_t = 0;
for( i = 0; i < CASHSHOP_TAB_MAX; i++ ) {
CREATE(clif->cs.data[i], struct hCSData *, 1);
@@ -21055,7 +21056,8 @@ static bool clif_parse_roulette_db(void)
{
struct config_t roulette_conf;
struct config_setting_t *roulette = NULL, *levels = NULL;
- const char *config_filename = "db/roulette_db.conf"; // FIXME hardcoded name
+ char config_filename[256];
+ libconfig->format_db_path("roulette_db.conf", config_filename, sizeof(config_filename));
int i, j, item_count_t = 0;
for( i = 0; i < MAX_ROULETTE_LEVEL; i++ ) {
@@ -22539,7 +22541,8 @@ static bool clif_parse_attendance_db(void)
{
struct config_t attendance_conf;
struct config_setting_t *attendance = NULL, *it = NULL;
- const char *config_filename = "db/attendance_db.conf"; // FIXME hardcoded name
+ char config_filename[256];
+ libconfig->format_db_path("attendance_db.conf", config_filename, sizeof(config_filename));
int i = 0;
if (!libconfig->load_file(&attendance_conf, config_filename))
diff --git a/src/map/guild.c b/src/map/guild.c
index 2faf60e2b..edd74a776 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -152,7 +152,8 @@ static bool guild_read_castledb_libconfig(void)
{
struct config_t castle_conf;
struct config_setting_t *castle_db = NULL, *it = NULL;
- const char *config_filename = "db/castle_db.conf"; // FIXME hardcoded name
+ char config_filename[256];
+ libconfig->format_db_path("castle_db.conf", config_filename, sizeof(config_filename));
int i = 0;
if (libconfig->load_file(&castle_conf, config_filename) == 0)
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index a97325e57..5dc3d9317 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -846,11 +846,8 @@ static void itemdb_read_groups(void)
{
struct config_t item_group_conf;
struct config_setting_t *itg = NULL, *it = NULL;
-#ifdef RENEWAL
- const char *config_filename = "db/re/item_group.conf"; // FIXME hardcoded name
-#else
- const char *config_filename = "db/pre-re/item_group.conf"; // FIXME hardcoded name
-#endif
+ char config_filename[256];
+ libconfig->format_db_path(DBPATH"item_group.conf", config_filename, sizeof(config_filename));
const char *itname;
int i = 0, count = 0, c;
unsigned int *gsize = NULL;
@@ -1144,11 +1141,8 @@ static void itemdb_read_packages(void)
{
struct config_t item_packages_conf;
struct config_setting_t *itg = NULL, *it = NULL, *t = NULL;
-#ifdef RENEWAL
- const char *config_filename = "db/re/item_packages.conf"; // FIXME hardcoded name
-#else
- const char *config_filename = "db/pre-re/item_packages.conf"; // FIXME hardcoded name
-#endif
+ char config_filename[256];
+ libconfig->format_db_path(DBPATH"item_packages.conf", config_filename, sizeof(config_filename));
const char *itname;
int i = 0, count = 0, c = 0, highest_gcount = 0;
unsigned int *must = NULL, *random = NULL, *rgroup = NULL, **rgroups = NULL;
@@ -1393,7 +1387,8 @@ static void itemdb_read_options(void)
struct config_t item_options_db;
struct config_setting_t *ito = NULL, *conf = NULL;
int index = 0, count = 0;
- const char *filepath = "db/item_options.conf";
+ char filepath[256];
+ libconfig->format_db_path("item_options.conf", filepath, sizeof(filepath));
VECTOR_DECL(int) duplicate_id;
if (!libconfig->load_file(&item_options_db, filepath))
@@ -1494,11 +1489,8 @@ static void itemdb_read_chains(void)
{
struct config_t item_chain_conf;
struct config_setting_t *itc = NULL;
-#ifdef RENEWAL
- const char *config_filename = "db/re/item_chain.conf"; // FIXME hardcoded name
-#else
- const char *config_filename = "db/pre-re/item_chain.conf"; // FIXME hardcoded name
-#endif
+ char config_filename[256];
+ libconfig->format_db_path(DBPATH"item_chain.conf", config_filename, sizeof(config_filename));
int i = 0, count = 0;
if (!libconfig->load_file(&item_chain_conf, config_filename))
diff --git a/src/map/map.c b/src/map/map.c
index 332bbe75f..ebd5b068c 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -4055,6 +4055,7 @@ static bool map_config_read_database(const char *filename, struct config_t *conf
return false;
}
libconfig->setting_lookup_mutable_string(setting, "db_path", map->db_path, sizeof(map->db_path));
+ libconfig->set_db_path(map->db_path);
libconfig->setting_lookup_int(setting, "save_settings", &map->save_settings);
if (libconfig->setting_lookup_int(setting, "autosave_time", &map->autosave_interval) == CONFIG_TRUE) {
@@ -5574,12 +5575,8 @@ static void read_map_zone_db(void)
{
struct config_t map_zone_db;
struct config_setting_t *zones = NULL;
- /* TODO: #ifndef required for re/pre-re */
-#ifdef RENEWAL
- const char *config_filename = "db/re/map_zone_db.conf"; // FIXME hardcoded name
-#else
- const char *config_filename = "db/pre-re/map_zone_db.conf"; // FIXME hardcoded name
-#endif
+ char config_filename[256];
+ libconfig->format_db_path(DBPATH"map_zone_db.conf", config_filename, sizeof(config_filename));
if (!libconfig->load_file(&map_zone_db, config_filename))
return;
@@ -6774,6 +6771,7 @@ void map_defaults(void)
map->extra_scripts_count = 0;
sprintf(map->db_path ,"db");
+ libconfig->set_db_path(map->db_path);
sprintf(map->help_txt ,"conf/help.txt");
sprintf(map->charhelp_txt ,"conf/charhelp.txt");
diff --git a/src/map/mob.c b/src/map/mob.c
index e04d6944e..a9d6c8a51 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -4078,10 +4078,8 @@ static bool mob_read_optdrops_group(struct config_setting_t *group, int n)
*/
static bool mob_read_optdrops_db(void)
{
- const char *filename = "option_drop_groups.conf"; // FIXME hardcoded name
-
char filepath[256];
- safesnprintf(filepath, sizeof(filepath), "%s/%s", map->db_path, filename);
+ libconfig->format_db_path("option_drop_groups.conf", filepath, sizeof(filepath));
struct config_t option_groups;
if (libconfig->load_file(&option_groups, filepath) == CONFIG_FALSE) {
diff --git a/src/map/pc.c b/src/map/pc.c
index 2cefa7674..3192690eb 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -11533,12 +11533,9 @@ static bool pc_read_exp_db(void)
struct config_t exp_db_conf;
struct config_setting_t *edb = NULL;
int entry_count = 0;
-
-#ifdef RENEWAL
- const char *config_filename = "db/re/exp_group_db.conf";
-#else
- const char *config_filename = "db/pre-re/exp_group_db.conf";
-#endif
+ char config_filename[256];
+
+ libconfig->format_db_path(DBPATH"exp_group_db.conf", config_filename, sizeof(config_filename));
if (!libconfig->load_file(&exp_db_conf, config_filename))
return false;
diff --git a/src/map/script.c b/src/map/script.c
index 0fe97574c..557fada9f 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -5150,7 +5150,8 @@ static uint8 script_add_language(const char *name)
static void script_load_translations(void)
{
struct config_t translations_conf;
- const char *config_filename = "db/translations.conf"; // FIXME hardcoded name
+ char config_filename[256];
+ libconfig->format_db_path("translations.conf", config_filename, sizeof(config_filename));
struct config_setting_t *translations = NULL;
int i, size;
int total = 0;
diff --git a/src/map/skill.c b/src/map/skill.c
index ad27ef0e3..dc710eadf 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -21105,7 +21105,7 @@ static bool skill_read_skilldb(const char *filename)
nullpo_retr(false, filename);
- sprintf(filepath,"db/%s",filename);
+ libconfig->format_db_path(filename, filepath, sizeof(filepath));
if (!libconfig->load_file(&skilldb, filepath)) {
return false; // Libconfig error report.
diff --git a/src/map/status.c b/src/map/status.c
index 71cce28c5..83b94b955 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -13339,10 +13339,12 @@ static void status_read_job_db(void)
int i = 0;
struct config_t job_db_conf;
struct config_setting_t *jdb = NULL;
+ char config_filename[256];
+
#ifdef RENEWAL_ASPD
- const char *config_filename = "db/re/job_db.conf";
+ libconfig->format_db_path(DBPATH_RE"job_db.conf", config_filename, sizeof(config_filename));
#else
- const char *config_filename = "db/pre-re/job_db.conf";
+ libconfig->format_db_path(DBPATH_PRE"job_db.conf", config_filename, sizeof(config_filename));
#endif
if (!libconfig->load_file(&job_db_conf, config_filename))
diff --git a/src/map/stylist.c b/src/map/stylist.c
index 7e7c13bf7..438302214 100644
--- a/src/map/stylist.c
+++ b/src/map/stylist.c
@@ -40,7 +40,8 @@ static bool stylist_read_db_libconfig(void)
{
struct config_t stylist_conf;
struct config_setting_t *stylist_db = NULL, *it = NULL;
- const char *config_filename = "db/stylist_db.conf"; // FIXME hardcoded name
+ char config_filename[256];
+ libconfig->format_db_path("stylist_db.conf", config_filename, sizeof(config_filename));
int i = 0;
if (!libconfig->load_file(&stylist_conf, config_filename))