summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c1083
-rw-r--r--src/char/char.h34
-rw-r--r--src/char/int_elemental.c4
-rw-r--r--src/char/int_guild.c28
-rw-r--r--src/char/int_homun.c4
-rw-r--r--src/char/int_mercenary.c4
-rw-r--r--src/char/int_party.c6
-rw-r--r--src/char/int_pet.c6
-rw-r--r--src/char/inter.c117
-rw-r--r--src/char/inter.h9
-rw-r--r--src/char/pincode.c68
-rw-r--r--src/char/pincode.h6
-rw-r--r--src/common/HPM.c52
-rw-r--r--src/common/HPM.h6
-rw-r--r--src/common/HPMi.h16
-rw-r--r--src/common/mmo.h6
-rw-r--r--src/common/socket.c314
-rw-r--r--src/common/sql.c96
-rw-r--r--src/common/sql.h2
-rw-r--r--src/login/account.h10
-rw-r--r--src/login/account_sql.c243
-rw-r--r--src/login/ipban.h9
-rw-r--r--src/login/ipban_sql.c281
-rw-r--r--src/login/login.c548
-rw-r--r--src/login/login.h17
-rw-r--r--src/login/loginlog.h4
-rw-r--r--src/login/loginlog_sql.c198
-rw-r--r--src/map/atcommand.c2
-rw-r--r--src/map/battle.c156
-rw-r--r--src/map/battle.h9
-rw-r--r--src/map/log.c323
-rw-r--r--src/map/log.h7
-rw-r--r--src/map/map.c759
-rw-r--r--src/map/map.h17
-rw-r--r--src/map/mapreg.h6
-rw-r--r--src/map/mapreg_sql.c21
-rw-r--r--src/map/script.c85
-rw-r--r--src/map/script.h8
-rw-r--r--src/plugins/HPMHooking/HPMHooking.Defs.inc98
-rw-r--r--src/plugins/HPMHooking/HPMHooking_char.HPMHooksCore.inc76
-rw-r--r--src/plugins/HPMHooking/HPMHooking_char.HookingPoints.inc19
-rw-r--r--src/plugins/HPMHooking/HPMHooking_char.Hooks.inc530
-rw-r--r--src/plugins/HPMHooking/HPMHooking_login.Hooks.inc14
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc24
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc6
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.Hooks.inc223
-rw-r--r--src/plugins/sample.c5
47 files changed, 3819 insertions, 1740 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 2851d3eba..6f79a55e3 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -42,6 +42,7 @@
#include "common/HPM.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/console.h"
#include "common/core.h"
#include "common/db.h"
@@ -61,6 +62,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
+#include <sys/stat.h> // stat()
#if MAX_MAP_SERVERS > 1
# ifdef _MSC_VER
@@ -110,9 +112,6 @@ char char_reg_num_db[32] = "char_reg_num_db";
struct char_interface char_s;
struct char_interface *chr;
-// show loading/saving messages
-int save_log = 1;
-
char db_path[1024] = "db";
char wisp_server_name[NAME_LENGTH] = "Server";
@@ -123,7 +122,7 @@ char char_ip_str[128];
char bind_ip_str[128];
uint32 bind_ip = INADDR_ANY;
int char_maintenance_min_group_id = 0;
-bool char_new = true;
+bool enable_char_creation = true; ///< Whether to allow character creation.
bool name_ignoring_case = false; // Allow or not identical name for characters but with a different case by [Yor]
int char_name_option = 0; // Option to know which letters/symbols are authorized in the name of a character (0: all, 1: only those in char_name_letters, 2: all EXCEPT those in char_name_letters) by [Yor]
@@ -131,19 +130,24 @@ char unknown_char_name[NAME_LENGTH] = "Unknown"; // Name to use when the request
#define TRIM_CHARS "\255\xA0\032\t\x0A\x0D " //The following characters are trimmed regardless because they cause confusion and problems on the servers. [Skotlex]
char char_name_letters[1024] = ""; // list of letters/symbols allowed (or not) in a character name. by [Yor]
-int char_del_level = 0; //From which level u can delete character [Lupus]
+int char_del_level = 0; ///< From which level you can delete character [Lupus]
int char_del_delay = 86400;
-
-int log_char = 1; // logging char or not [devil]
-int log_inter = 1; // logging inter or not [devil]
-
-int char_aegis_delete = 0; // Verify if char is in guild/party or char and reacts as Aegis does (doesn't allow deletion), see chr->delete2_req for more information
+bool char_aegis_delete = false; ///< Verify if char is in guild/party or char and reacts as Aegis does (disallow deletion), @see chr->delete2_req.
int max_connect_user = -1;
int gm_allow_group = -1;
int autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
int start_zeny = 0;
-int start_items[MAX_START_ITEMS*3];
+
+/// Start items for new characters
+struct start_item_s {
+ int id;
+ int amount;
+ int loc;
+ bool stackable;
+};
+VECTOR_DECL(struct start_item_s) start_items;
+
int guild_exp_rate = 100;
//Custom limits for the fame lists. [Skotlex]
@@ -690,7 +694,7 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p)
#endif
StrBuf->Destroy(&buf);
- if (save_status[0]!='\0' && save_log)
+ if (chr->show_save_log && save_status[0] != '\0')
ShowInfo("Saved char %d - %s:%s.\n", char_id, p->name, save_status);
if (!errors)
memcpy(cp, p, sizeof(struct mmo_charstatus));
@@ -1043,7 +1047,8 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every
memset(p, 0, sizeof(struct mmo_charstatus));
- if (save_log) ShowInfo("Char load request (%d)\n", char_id);
+ if (chr->show_save_log)
+ ShowInfo("Char load request (%d)\n", char_id);
stmt = SQL->StmtMalloc(inter->sql_handle);
if( stmt == NULL )
@@ -1336,7 +1341,8 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every
if( SQL_SUCCESS == SQL->StmtNextRow(stmt) )
strcat(t_msg, " accdata");
- if (save_log) ShowInfo("Loaded char (%d - %s): %s\n", char_id, p->name, t_msg); //ok. all data load successfully!
+ if (chr->show_save_log)
+ ShowInfo("Loaded char (%d - %s): %s\n", char_id, p->name, t_msg); //ok. all data load successfully!
SQL->StmtFree(stmt);
StrBuf->Destroy(&buf);
@@ -1463,12 +1469,11 @@ int char_rename_char_sql(struct char_session_data *sd, int char_id)
memset(sd->new_name,0,sizeof(sd->new_name));
// log change
- if( log_char )
- {
- if( SQL_ERROR == SQL->Query(inter->sql_handle,
- "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)"
- "VALUES (NOW(), '%s', '%d', '%d', '%d', '%s', '0', '0', '0', '0', '0', '0', '0', '0')",
- charlog_db, "change char name", sd->account_id, char_dat.char_id, char_dat.slot, esc_name) )
+ if (chr->enable_logs) {
+ if (SQL_ERROR == SQL->Query(inter->sql_handle,
+ "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)"
+ "VALUES (NOW(), '%s', '%d', '%d', '%d', '%s', '0', '0', '0', '0', '0', '0', '0', '0')",
+ charlog_db, "change char name", sd->account_id, char_dat.char_id, char_dat.slot, esc_name))
Sql_ShowDebug(inter->sql_handle);
}
@@ -1543,7 +1548,7 @@ int char_make_new_char_sql(struct char_session_data *sd, const char *name_, int
{
char name[NAME_LENGTH];
char esc_name[NAME_LENGTH*2+1];
- int char_id, flag, k, l;
+ int char_id, flag, i;
nullpo_retr(-2, sd);
nullpo_retr(-2, name_);
@@ -1606,32 +1611,29 @@ int char_make_new_char_sql(struct char_session_data *sd, const char *name_, int
return -2;
// Validation success, log result
- if (log_char) {
- if( SQL_ERROR == SQL->Query(inter->sql_handle, "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)"
- "VALUES (NOW(), '%s', '%d', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
- charlog_db, "make new char", sd->account_id, char_id, slot, esc_name, str, agi, vit, int_, dex, luk, hair_style, hair_color) )
+ if (chr->enable_logs) {
+ if (SQL_ERROR == SQL->Query(inter->sql_handle,
+ "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)"
+ "VALUES (NOW(), '%s', '%d', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
+ charlog_db, "make new char", sd->account_id, char_id, slot, esc_name, str, agi, vit, int_, dex, luk, hair_style, hair_color))
Sql_ShowDebug(inter->sql_handle);
}
//Give the char the default items
- for (k = 0; k < ARRAYLENGTH(start_items) && start_items[k] != 0; k += 3) {
- // FIXME: How to define if an item is stackable without having to lookup itemdb? [panikon]
- if( start_items[k+2] == 1 )
- {
- if( SQL_ERROR == SQL->Query(inter->sql_handle,
- "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `identify`) VALUES ('%d', '%d', '%d', '%d')",
- inventory_db, char_id, start_items[k], start_items[k + 1], 1) )
- Sql_ShowDebug(inter->sql_handle);
- }
- else if( start_items[k+2] == 0 )
- {
+ for (i = 0; i < VECTOR_LENGTH(start_items); i++) {
+ struct start_item_s *item = &VECTOR_INDEX(start_items, i);
+ if (item->stackable) {
+ if (SQL_ERROR == SQL->Query(inter->sql_handle,
+ "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `identify`) VALUES ('%d', '%d', '%d', '%d')",
+ inventory_db, char_id, item->id, item->amount, 1))
+ Sql_ShowDebug(inter->sql_handle);
+ } else {
// Non-stackable items should have their own entries (issue: 7279)
- for( l = 0; l < start_items[k+1]; l++ )
- {
- if( SQL_ERROR == SQL->Query(inter->sql_handle,
- "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `identify`) VALUES ('%d', '%d', '%d', '%d')",
- inventory_db, char_id, start_items[k], 1, 1)
- )
+ int l, loc = item->loc;
+ for (l = 0; l < item->amount; l++) {
+ if (SQL_ERROR == SQL->Query(inter->sql_handle,
+ "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `equip`, `identify`) VALUES ('%d', '%d', '%d', '%d', '%d')",
+ inventory_db, char_id, item->id, 1, loc, 1))
Sql_ShowDebug(inter->sql_handle);
}
}
@@ -1804,13 +1806,13 @@ int char_delete_char_sql(int char_id)
#endif
/* delete character */
- if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", char_db, char_id) )
+ if (SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", char_db, char_id)) {
Sql_ShowDebug(inter->sql_handle);
- else if( log_char ) {
- if( SQL_ERROR == SQL->Query(inter->sql_handle,
- "INSERT INTO `%s`(`time`, `account_id`, `char_id`, `char_num`, `char_msg`, `name`)"
- " VALUES (NOW(), '%d', '%d', '%d', 'Deleted character', '%s')",
- charlog_db, account_id, char_id, 0, esc_name) )
+ } else if (chr->enable_logs) {
+ if (SQL_ERROR == SQL->Query(inter->sql_handle,
+ "INSERT INTO `%s`(`time`, `account_id`, `char_id`, `char_num`, `char_msg`, `name`)"
+ " VALUES (NOW(), '%d', '%d', '%d', 'Deleted character', '%s')",
+ charlog_db, account_id, char_id, 0, esc_name))
Sql_ShowDebug(inter->sql_handle);
}
@@ -2015,7 +2017,7 @@ int char_mmo_char_send_characters(int fd, struct char_session_data* sd)
#if PACKETVER >= 20100413
offset += 3;
#endif
- if (save_log)
+ if (chr->show_save_log)
ShowInfo("Loading Char Data ("CL_BOLD"%d"CL_RESET")\n",sd->account_id);
j = 24 + offset; // offset
@@ -2181,7 +2183,7 @@ int char_parse_fromlogin_connection_state(int fd)
ShowError("Can not connect to login-server.\n");
ShowError("The server communication passwords (default s1/p1) are probably invalid.\n");
ShowError("Also, please make sure your login db has the correct communication username/passwords and the gender of the account is S.\n");
- ShowError("The communication passwords are set in /conf/map-server.conf and /conf/char-server.conf\n");
+ ShowError("The communication passwords are set in /conf/map-server.conf and /conf/char/char-server.conf\n");
sockt->eof(fd);
return 1;
} else {
@@ -4516,13 +4518,13 @@ void char_parse_char_select(int fd, struct char_session_data* sd, uint32 ipl)
if( cd->sex == 99 )
cd->sex = sd->sex;
- if (log_char) {
+ if (chr->enable_logs) {
char esc_name[NAME_LENGTH*2+1];
// FIXME: Why are we re-escaping the name if it was already escaped in rename/make_new_char? [Panikon]
SQL->EscapeStringLen(inter->sql_handle, esc_name, char_dat.name, strnlen(char_dat.name, NAME_LENGTH));
- if( SQL_ERROR == SQL->Query(inter->sql_handle,
- "INSERT INTO `%s`(`time`, `account_id`, `char_id`, `char_num`, `name`) VALUES (NOW(), '%d', '%d', '%d', '%s')",
- charlog_db, sd->account_id, cd->char_id, slot, esc_name) )
+ if (SQL_ERROR == SQL->Query(inter->sql_handle,
+ "INSERT INTO `%s`(`time`, `account_id`, `char_id`, `char_num`, `name`) VALUES (NOW(), '%d', '%d', '%d', '%s')",
+ charlog_db, sd->account_id, cd->char_id, slot, esc_name))
Sql_ShowDebug(inter->sql_handle);
}
ShowInfo("Selected char: (Account %d: %d - %s)\n", sd->account_id, slot, char_dat.name);
@@ -4615,7 +4617,7 @@ void char_parse_char_create_new_char(int fd, struct char_session_data* sd) __att
void char_parse_char_create_new_char(int fd, struct char_session_data* sd)
{
int result;
- if( !char_new ) {
+ if (!enable_char_creation) {
//turn character creation on/off [Kevin]
result = -2;
} else {
@@ -5348,304 +5350,673 @@ static int char_online_data_cleanup(int tid, int64 tick, int id, intptr_t data)
return 0;
}
-void char_sql_config_read(const char* cfgName)
+/**
+ * Reads the 'inter_configuration' config file and initializes required variables.
+ *
+ * @param filename Path to configuration file
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool char_sql_config_read(const char *filename, bool imported)
{
- char line[1024], w1[1024], w2[1024];
- FILE* fp;
+ struct config_t config;
+ const struct config_setting_t *setting = NULL;
+ const char *import = NULL;
+ bool retval = true;
- if ((fp = fopen(cfgName, "r")) == NULL) {
- ShowError("File not found: %s\n", cfgName);
- return;
+ nullpo_retr(false, filename);
+
+ if (!libconfig->load_file(&config, filename))
+ return false; // Error message is already shown by libconfig->load_file
+
+ if ((setting = libconfig->lookup(&config, "inter_configuration/database_names")) == NULL) {
+ libconfig->destroy(&config);
+ if (imported)
+ return true;
+ ShowError("sql_config_read: inter_configuration/database_names was not found in %s!\n", filename);
+ return false;
+ }
+ libconfig->setting_lookup_mutable_string(setting, "char_db", char_db, sizeof(char_db));
+ libconfig->setting_lookup_mutable_string(setting, "interlog_db", interlog_db, sizeof(interlog_db));
+ libconfig->setting_lookup_mutable_string(setting, "ragsrvinfo_db", ragsrvinfo_db, sizeof(ragsrvinfo_db));
+
+ if (!chr->sql_config_read_registry(filename, &config, imported))
+ retval = false;
+ if (!chr->sql_config_read_pc(filename, &config, imported))
+ retval = false;
+ if (!chr->sql_config_read_guild(filename, &config, imported))
+ retval = false;
+
+ ShowInfo("Done reading %s.\n", filename);
+ // import should overwrite any previous configuration, so it should be called last
+ if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) {
+ if (strcmp(import, filename) == 0 || strcmp(import, chr->SQL_CONF_NAME) == 0) {
+ ShowWarning("sql_config_read: Loop detected in %s! Skipping 'import'...\n", filename);
+ } else {
+ if (!chr->sql_config_read(import, true))
+ retval = false;
+ }
}
- while(fgets(line, sizeof(line), fp))
- {
- if(line[0] == '/' && line[1] == '/')
- continue;
+ // TODO HPM->parseConf(w1, w2, HPCT_CHAR_INTER);
- if (sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) != 2)
- continue;
+ libconfig->destroy(&config);
+ return retval;
+}
- if(!strcmpi(w1,"char_db"))
- safestrncpy(char_db, w2, sizeof(char_db));
- else if(!strcmpi(w1,"scdata_db"))
- safestrncpy(scdata_db, w2, sizeof(scdata_db));
- else if(!strcmpi(w1,"cart_db"))
- safestrncpy(cart_db, w2, sizeof(cart_db));
- else if(!strcmpi(w1,"inventory_db"))
- safestrncpy(inventory_db, w2, sizeof(inventory_db));
- else if(!strcmpi(w1,"charlog_db"))
- safestrncpy(charlog_db, w2, sizeof(charlog_db));
- else if(!strcmpi(w1,"storage_db"))
- safestrncpy(storage_db, w2, sizeof(storage_db));
- else if(!strcmpi(w1,"skill_db"))
- safestrncpy(skill_db, w2, sizeof(skill_db));
- else if(!strcmpi(w1,"interlog_db"))
- safestrncpy(interlog_db, w2, sizeof(interlog_db));
- else if(!strcmpi(w1,"memo_db"))
- safestrncpy(memo_db, w2, sizeof(memo_db));
- else if(!strcmpi(w1,"guild_db"))
- safestrncpy(guild_db, w2, sizeof(guild_db));
- else if(!strcmpi(w1,"guild_alliance_db"))
- safestrncpy(guild_alliance_db, w2, sizeof(guild_alliance_db));
- else if(!strcmpi(w1,"guild_castle_db"))
- safestrncpy(guild_castle_db, w2, sizeof(guild_castle_db));
- else if(!strcmpi(w1,"guild_expulsion_db"))
- safestrncpy(guild_expulsion_db, w2, sizeof(guild_expulsion_db));
- else if(!strcmpi(w1,"guild_member_db"))
- safestrncpy(guild_member_db, w2, sizeof(guild_member_db));
- else if(!strcmpi(w1,"guild_skill_db"))
- safestrncpy(guild_skill_db, w2, sizeof(guild_skill_db));
- else if(!strcmpi(w1,"guild_position_db"))
- safestrncpy(guild_position_db, w2, sizeof(guild_position_db));
- else if(!strcmpi(w1,"guild_storage_db"))
- safestrncpy(guild_storage_db, w2, sizeof(guild_storage_db));
- else if(!strcmpi(w1,"party_db"))
- safestrncpy(party_db, w2, sizeof(party_db));
- else if(!strcmpi(w1,"pet_db"))
- safestrncpy(pet_db, w2, sizeof(pet_db));
- else if(!strcmpi(w1,"mail_db"))
- safestrncpy(mail_db, w2, sizeof(mail_db));
- else if(!strcmpi(w1,"auction_db"))
- safestrncpy(auction_db, w2, sizeof(auction_db));
- else if(!strcmpi(w1,"friend_db"))
- safestrncpy(friend_db, w2, sizeof(friend_db));
- else if(!strcmpi(w1,"hotkey_db"))
- safestrncpy(hotkey_db, w2, sizeof(hotkey_db));
- else if(!strcmpi(w1,"quest_db"))
- safestrncpy(quest_db,w2,sizeof(quest_db));
- else if(!strcmpi(w1,"homunculus_db"))
- safestrncpy(homunculus_db,w2,sizeof(homunculus_db));
- else if(!strcmpi(w1,"skill_homunculus_db"))
- safestrncpy(skill_homunculus_db,w2,sizeof(skill_homunculus_db));
- else if(!strcmpi(w1,"mercenary_db"))
- safestrncpy(mercenary_db,w2,sizeof(mercenary_db));
- else if(!strcmpi(w1,"mercenary_owner_db"))
- safestrncpy(mercenary_owner_db,w2,sizeof(mercenary_owner_db));
- else if(!strcmpi(w1,"ragsrvinfo_db"))
- safestrncpy(ragsrvinfo_db,w2,sizeof(ragsrvinfo_db));
- else if(!strcmpi(w1,"elemental_db"))
- safestrncpy(elemental_db,w2,sizeof(elemental_db));
- else if(!strcmpi(w1,"account_data_db"))
- safestrncpy(account_data_db,w2,sizeof(account_data_db));
- else if(!strcmpi(w1,"char_reg_num_db"))
- safestrncpy(char_reg_num_db, w2, sizeof(char_reg_num_db));
- else if(!strcmpi(w1,"char_reg_str_db"))
- safestrncpy(char_reg_str_db, w2, sizeof(char_reg_str_db));
- else if(!strcmpi(w1,"acc_reg_str_db"))
- safestrncpy(acc_reg_str_db, w2, sizeof(acc_reg_str_db));
- else if(!strcmpi(w1,"acc_reg_num_db"))
- safestrncpy(acc_reg_num_db, w2, sizeof(acc_reg_num_db));
- //support the import command, just like any other config
- else if(!strcmpi(w1,"import"))
- chr->sql_config_read(w2);
- else
- HPM->parseConf(w1, w2, HPCT_CHAR_INTER);
+/**
+ * Reads the 'inter_configuration/database_names/registry' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool char_sql_config_read_registry(const char *filename, const struct config_t *config, bool imported)
+{
+ const struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "inter_configuration/database_names/registry")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("sql_config_read: inter_configuration/database_names/registry was not found in %s!\n", filename);
+ return false;
}
- fclose(fp);
- ShowInfo("Done reading %s.\n", cfgName);
+ // Not all registries are read by char-server
+ libconfig->setting_lookup_mutable_string(setting, "char_reg_num_db", char_reg_num_db, sizeof(char_reg_num_db));
+ libconfig->setting_lookup_mutable_string(setting, "char_reg_str_db", char_reg_str_db, sizeof(char_reg_str_db));
+ libconfig->setting_lookup_mutable_string(setting, "acc_reg_str_db", acc_reg_str_db, sizeof(acc_reg_str_db));
+ libconfig->setting_lookup_mutable_string(setting, "acc_reg_num_db", acc_reg_num_db, sizeof(acc_reg_num_db));
+
+ return true;
}
-void char_config_dispatch(char *w1, char *w2) {
- bool (*dispatch_to[]) (char *w1, char *w2) = {
- /* as many as it needs */
- pincode->config_read
- };
- int i, len = ARRAYLENGTH(dispatch_to);
- for(i = 0; i < len; i++) {
- if( (*dispatch_to[i])(w1,w2) )
- break;/* we found who this belongs to, can stop */
+/**
+ * Reads the 'inter_configuration/database_names/pc' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool char_sql_config_read_pc(const char *filename, const struct config_t *config, bool imported)
+{
+ const struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "inter_configuration/database_names/pc")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("sql_config_read: inter_configuration/database_names/pc was not found in %s!\n", filename);
+ return false;
}
- if (i == len)
- HPM->parseConf(w1, w2, HPCT_CHAR);
+ libconfig->setting_lookup_mutable_string(setting, "hotkey_db", hotkey_db, sizeof(hotkey_db));
+ libconfig->setting_lookup_mutable_string(setting, "scdata_db", scdata_db, sizeof(scdata_db));
+ libconfig->setting_lookup_mutable_string(setting, "inventory_db", inventory_db, sizeof(inventory_db));
+ libconfig->setting_lookup_mutable_string(setting, "cart_db", cart_db, sizeof(cart_db));
+ libconfig->setting_lookup_mutable_string(setting, "charlog_db", charlog_db, sizeof(charlog_db));
+ libconfig->setting_lookup_mutable_string(setting, "storage_db", storage_db, sizeof(storage_db));
+ libconfig->setting_lookup_mutable_string(setting, "skill_db", skill_db, sizeof(skill_db));
+ libconfig->setting_lookup_mutable_string(setting, "memo_db", memo_db, sizeof(memo_db));
+ libconfig->setting_lookup_mutable_string(setting, "party_db", party_db, sizeof(party_db));
+ libconfig->setting_lookup_mutable_string(setting, "pet_db", pet_db, sizeof(pet_db));
+ libconfig->setting_lookup_mutable_string(setting, "friend_db", friend_db, sizeof(friend_db));
+ libconfig->setting_lookup_mutable_string(setting, "mail_db", mail_db, sizeof(mail_db));
+ libconfig->setting_lookup_mutable_string(setting, "auction_db", auction_db, sizeof(auction_db));
+ libconfig->setting_lookup_mutable_string(setting, "quest_db", quest_db, sizeof(quest_db));
+ libconfig->setting_lookup_mutable_string(setting, "homunculus_db", homunculus_db, sizeof(homunculus_db));
+ libconfig->setting_lookup_mutable_string(setting, "skill_homunculus_db", skill_homunculus_db, sizeof(skill_homunculus_db));
+ libconfig->setting_lookup_mutable_string(setting, "mercenary_db", mercenary_db, sizeof(mercenary_db));
+ libconfig->setting_lookup_mutable_string(setting, "mercenary_owner_db", mercenary_owner_db, sizeof(mercenary_owner_db));
+ libconfig->setting_lookup_mutable_string(setting, "elemental_db", elemental_db, sizeof(elemental_db));
+ libconfig->setting_lookup_mutable_string(setting, "account_data_db", account_data_db, sizeof(account_data_db));
+
+ return true;
}
-int char_config_read(const char* cfgName)
+/**
+ * Reads the 'inter_configuration/database_names/guild' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool char_sql_config_read_guild(const char *filename, const struct config_t *config, bool imported)
{
- char line[1024], w1[1024], w2[1024];
- FILE* fp = fopen(cfgName, "r");
+ const struct config_setting_t *setting = NULL;
- if (fp == NULL) {
- ShowError("Configuration file not found: %s.\n", cfgName);
- return 1;
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "inter_configuration/database_names/guild")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("sql_config_read: inter_configuration/database_names/guild was not found in %s!\n", filename);
+ return false;
+ }
+
+ libconfig->setting_lookup_mutable_string(setting, "main_db", guild_db, sizeof(guild_db));
+ libconfig->setting_lookup_mutable_string(setting, "alliance_db", guild_alliance_db, sizeof(guild_alliance_db));
+ libconfig->setting_lookup_mutable_string(setting, "castle_db", guild_castle_db, sizeof(guild_castle_db));
+ libconfig->setting_lookup_mutable_string(setting, "expulsion_db", guild_expulsion_db, sizeof(guild_expulsion_db));
+ libconfig->setting_lookup_mutable_string(setting, "member_db", guild_member_db, sizeof(guild_member_db));
+ libconfig->setting_lookup_mutable_string(setting, "skill_db", guild_skill_db, sizeof(guild_skill_db));
+ libconfig->setting_lookup_mutable_string(setting, "position_db", guild_position_db, sizeof(guild_position_db));
+ libconfig->setting_lookup_mutable_string(setting, "storage_db", guild_storage_db, sizeof(guild_storage_db));
+
+ return true;
+}
+
+/**
+ * Reads the 'char_configuration' config file and initializes required variables.
+ *
+ * @param filename Path to configuration file.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool char_config_read(const char *filename, bool imported)
+{
+ struct config_t config;
+ const char *import = NULL;
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+
+ if (!libconfig->load_file(&config, filename))
+ return false; // Error message is already shown by libconfig->load_file
+
+ if (!chr->config_read_top(filename, &config, imported))
+ retval = false;
+ if (!chr->config_read_inter(filename, &config, imported))
+ retval = false;
+ if (!chr->config_read_permission(filename, &config, imported))
+ retval = false;
+ if (!chr->config_read_player(filename, &config, imported))
+ retval = false;
+ if (!chr->config_read_console(filename, &config, imported))
+ retval = false;
+ if (!chr->config_read_database(filename, &config, imported))
+ retval = false;
+ if (!inter->config_read_connection(filename, &config, imported))
+ retval = false;
+ if (!pincode->config_read(filename, &config, imported))
+ retval = false;
+
+ // TODO HPM->parseConf(w1, w2, HPCT_CHAR);
+
+ ShowInfo("Done reading %s.\n", filename);
+
+ // import should overwrite any previous configuration, so it should be called last
+ if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) {
+ if (strcmp(import, filename) == 0 || strcmp(import, chr->CHAR_CONF_NAME) == 0) {
+ ShowWarning("char_config_read: Loop detected in %s! Skipping 'import'...\n", filename);
+ } else {
+ if (!chr->config_read(import, true))
+ retval = false;
+ }
}
- while(fgets(line, sizeof(line), fp)) {
- if (line[0] == '/' && line[1] == '/')
+ libconfig->destroy(&config);
+ return retval;
+}
+
+/**
+ * Reads the 'char_configuration' top level config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool char_config_read_top(const char *filename, const struct config_t *config, bool imported)
+{
+ const struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "char_configuration")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("char_config_read: char_configuration was not found in %s!\n", filename);
+ return false;
+ }
+
+ // char_configuration/server_name
+ if (libconfig->setting_lookup_mutable_string(setting, "server_name", chr->server_name, sizeof(chr->server_name)) == CONFIG_TRUE) {
+ ShowInfo("server name %s\n", chr->server_name);
+ } else if (!imported) {
+ ShowWarning("char_config_read: server_name was not set! Defaulting to 'Hercules'.\n");
+ safestrncpy(chr->server_name, "Hercules", sizeof(chr->server_name));
+ }
+ // char_configuration/wisp_server_name
+ if (libconfig->setting_lookup_mutable_string(setting, "wisp_server_name", wisp_server_name, sizeof(wisp_server_name)) == CONFIG_TRUE) {
+ // wisp_server_name should _always_ be equal or bigger than 4 characters!
+ if (strlen(wisp_server_name) < 4) { // TODO: This length should be a #define (i.e. MIN_NAME_LENGTH)
+ ShowWarning("char_config_read: char_configuration/wisp_server_name is too small! Defaulting to: Server.\n");
+ safestrncpy(chr->server_name, "Server", sizeof(chr->server_name));
+ }
+ }
+ // char_configuration/guild_exp_rate
+ libconfig->setting_lookup_int(setting, "guild_exp_rate", &guild_exp_rate);
+
+ return true;
+}
+
+/**
+ * Reads the 'char_configuration/inter' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool char_config_read_inter(const char *filename, const struct config_t *config, bool imported)
+{
+ const struct config_setting_t *setting = NULL;
+ const char *str = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "char_configuration/inter")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("char_config_read: char_configuration/inter was not found in %s!\n", filename);
+ return false;
+ }
+
+ // Login information
+ libconfig->setting_lookup_mutable_string(setting, "userid", chr->userid, sizeof(chr->userid));
+ libconfig->setting_lookup_mutable_string(setting, "passwd", chr->passwd, sizeof(chr->passwd));
+
+ // Login-server and character-server information
+ if (libconfig->setting_lookup_string(setting, "login_ip", &str) == CONFIG_TRUE)
+ chr->config_set_ip("Login server", str, &login_ip, login_ip_str);
+
+ if (libconfig->setting_lookup_string(setting, "char_ip", &str) == CONFIG_TRUE)
+ chr->config_set_ip("Character server", str, &chr->ip, char_ip_str);
+
+ if (libconfig->setting_lookup_string(setting, "bind_ip", &str) == CONFIG_TRUE)
+ chr->config_set_ip("Character server binding", str, &bind_ip, bind_ip_str);
+
+ libconfig->setting_lookup_uint16(setting, "login_port", &login_port);
+ libconfig->setting_lookup_uint16(setting, "char_port", &chr->port);
+
+ return true;
+}
+
+/**
+ * Reads the 'char_configuration/database' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool char_config_read_database(const char *filename, const struct config_t *config, bool imported)
+{
+ const struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "char_configuration/database")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("char_config_read: char_configuration/database was not found in %s!\n", filename);
+ return false;
+ }
+ if (libconfig->setting_lookup_int(setting, "autosave_time", &autosave_interval) == CONFIG_TRUE) {
+ autosave_interval *= 1000;
+ 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_bool_real(setting, "log_char", &chr->enable_logs);
+ return true;
+}
+
+/**
+ * Reads the 'char_configuration/console' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool char_config_read_console(const char *filename, const struct config_t *config, bool imported)
+{
+ const struct config_setting_t *setting;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "char_configuration/console")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("char_config_read: char_configuration/console was not found in %s!\n", filename);
+ return false;
+ }
+ libconfig->setting_lookup_bool_real(setting, "stdout_with_ansisequence", &showmsg->stdout_with_ansisequence);
+ libconfig->setting_lookup_bool_real(setting, "save_log", &chr->show_save_log);
+ if (libconfig->setting_lookup_int(setting, "console_silent", &showmsg->silent) == CONFIG_TRUE) {
+ if (showmsg->silent) // only bother if its actually enabled
+ ShowInfo("Console Silent Setting: %d\n", showmsg->silent);
+ }
+ libconfig->setting_lookup_mutable_string(setting, "timestamp_format", showmsg->timestamp_format, sizeof(showmsg->timestamp_format));
+
+ return true;
+}
+
+/**
+ * Reads the 'char_configuration/player' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool char_config_read_player(const char *filename, const struct config_t *config, bool imported)
+{
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if (!chr->config_read_player_new(filename, config, imported))
+ retval = false;
+ if (!chr->config_read_player_name(filename, config, imported))
+ retval = false;
+ if (!chr->config_read_player_deletion(filename, config, imported))
+ retval = false;
+ if (!chr->config_read_player_fame(filename, config, imported))
+ retval = false;
+
+ return retval;
+}
+
+/**
+ * Reads the 'char_configuration/player/fame' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool char_config_read_player_fame(const char *filename, const struct config_t *config, bool imported)
+{
+ const struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "char_configuration/player/fame")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("char_config_read: char_configuration/player/fame was not found in %s!\n", filename);
+ return false;
+ }
+
+ libconfig->setting_lookup_int(setting, "alchemist", &fame_list_size_chemist);
+ if (fame_list_size_chemist > MAX_FAME_LIST) {
+ ShowWarning("Max fame list size is %d (fame_list_alchemist)\n", MAX_FAME_LIST);
+ fame_list_size_chemist = MAX_FAME_LIST;
+ }
+
+ libconfig->setting_lookup_int(setting, "blacksmith", &fame_list_size_smith);
+ if (fame_list_size_smith > MAX_FAME_LIST) {
+ ShowWarning("Max fame list size is %d (fame_list_blacksmith)\n", MAX_FAME_LIST);
+ fame_list_size_smith = MAX_FAME_LIST;
+ }
+
+ libconfig->setting_lookup_int(setting, "taekwon", &fame_list_size_taekwon);
+ if (fame_list_size_taekwon > MAX_FAME_LIST) {
+ ShowWarning("Max fame list size is %d (fame_list_taekwon)\n", MAX_FAME_LIST);
+ fame_list_size_taekwon = MAX_FAME_LIST;
+ }
+
+ return true;
+}
+
+/**
+ * Reads the 'char_configuration/player/deletion' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool char_config_read_player_deletion(const char *filename, const struct config_t *config, bool imported)
+{
+ const struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "char_configuration/player/deletion")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("char_config_read: char_configuration/player/deletion was not found in %s!\n", filename);
+ return false;
+ }
+ libconfig->setting_lookup_int(setting, "level", &char_del_level);
+ libconfig->setting_lookup_int(setting, "delay", &char_del_delay);
+ libconfig->setting_lookup_bool_real(setting, "use_aegis_delete", &char_aegis_delete);
+
+ return true;
+}
+
+/**
+ * Reads the 'char_configuration/player/name' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool char_config_read_player_name(const char *filename, const struct config_t *config, bool imported)
+{
+ const struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "char_configuration/player/name")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("char_config_read: char_configuration/player/name was not found in %s!\n", filename);
+ return false;
+ }
+ libconfig->setting_lookup_mutable_string(setting, "unknown_char_name", unknown_char_name, sizeof(unknown_char_name));
+ libconfig->setting_lookup_mutable_string(setting, "name_letters", char_name_letters, sizeof(char_name_letters));
+ libconfig->setting_lookup_int(setting, "name_option", &char_name_option);
+ libconfig->setting_lookup_bool_real(setting, "name_ignoring_case", &name_ignoring_case);
+
+ return true;
+}
+
+/**
+ * Defines start_items based on '(...)/player/new/start_item'.
+ *
+ * @param setting The already retrieved start_item setting.
+ */
+void char_config_set_start_item(const struct config_setting_t *setting)
+{
+ int i, count;
+
+ nullpo_retv(setting);
+
+ VECTOR_CLEAR(start_items);
+
+ count = libconfig->setting_length(setting);
+ if (!count)
+ return;
+
+ VECTOR_ENSURE(start_items, count, 1);
+
+ for (i = 0; i < count; i++) {
+ const struct config_setting_t *t = libconfig->setting_get_elem(setting, i);
+ struct start_item_s start_item = { 0 };
+
+ if (t == NULL)
continue;
- if (sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) != 2)
+ if (libconfig->setting_lookup_int(t, "id", &start_item.id) != CONFIG_TRUE) {
+ ShowWarning("char_config_read: entry (%d) is missing id! Ignoring...\n", i);
+ continue;
+ }
+ if (libconfig->setting_lookup_int(t, "amount", &start_item.amount) != CONFIG_TRUE) {
+ ShowWarning("char_config_read: entry (%d) is missing amount! Defaulting to 1...\n", i);
+ start_item.amount = 1;
+ }
+ if (libconfig->setting_lookup_bool_real(t, "stackable", &start_item.stackable) != CONFIG_TRUE) {
+ // Without knowing if the item is stackable or not we can't add it!
+ ShowWarning("char_config_read: entry (%d) is missing stackable! Ignoring...\n", i);
continue;
+ }
+ if (libconfig->setting_lookup_int(t, "loc", &start_item.loc) != CONFIG_TRUE)
+ start_item.loc = 0;
+ VECTOR_PUSH(start_items, start_item);
+ }
+}
- remove_control_chars(w1);
- remove_control_chars(w2);
- if(strcmpi(w1,"timestamp_format") == 0) {
- safestrncpy(showmsg->timestamp_format, w2, sizeof(showmsg->timestamp_format));
- } else if(strcmpi(w1,"console_silent")==0){
- showmsg->silent = atoi(w2);
- if (showmsg->silent) /* only bother if its actually enabled */
- ShowInfo("Console Silent Setting: %d\n", atoi(w2));
- } else if(strcmpi(w1,"stdout_with_ansisequence")==0){
- showmsg->stdout_with_ansisequence = config_switch(w2) ? true : false;
- } else if (strcmpi(w1, "userid") == 0) {
- safestrncpy(chr->userid, w2, sizeof(chr->userid));
- } else if (strcmpi(w1, "passwd") == 0) {
- safestrncpy(chr->passwd, w2, sizeof(chr->passwd));
- } else if (strcmpi(w1, "server_name") == 0) {
- safestrncpy(chr->server_name, w2, sizeof(chr->server_name));
- } else if (strcmpi(w1, "wisp_server_name") == 0) {
- if (strlen(w2) >= 4) {
- safestrncpy(wisp_server_name, w2, sizeof(wisp_server_name));
- }
- } else if (strcmpi(w1, "login_ip") == 0) {
- login_ip = sockt->host2ip(w2);
- if (login_ip) {
- char ip_str[16];
- safestrncpy(login_ip_str, w2, sizeof(login_ip_str));
- ShowStatus("Login server IP address : %s -> %s\n", w2, sockt->ip2str(login_ip, ip_str));
- }
- } else if (strcmpi(w1, "login_port") == 0) {
- login_port = atoi(w2);
- } else if (strcmpi(w1, "char_ip") == 0) {
- chr->ip = sockt->host2ip(w2);
- if (chr->ip) {
- char ip_str[16];
- safestrncpy(char_ip_str, w2, sizeof(char_ip_str));
- ShowStatus("Character server IP address : %s -> %s\n", w2, sockt->ip2str(chr->ip, ip_str));
- }
- } else if (strcmpi(w1, "bind_ip") == 0) {
- bind_ip = sockt->host2ip(w2);
- if (bind_ip) {
- char ip_str[16];
- safestrncpy(bind_ip_str, w2, sizeof(bind_ip_str));
- ShowStatus("Character server binding IP address : %s -> %s\n", w2, sockt->ip2str(bind_ip, ip_str));
- }
- } else if (strcmpi(w1, "char_port") == 0) {
- chr->port = atoi(w2);
- } else if (strcmpi(w1, "char_server_type") == 0) {
- chr->server_type = atoi(w2);
- } else if (strcmpi(w1, "char_new") == 0) {
- char_new = (bool)atoi(w2);
- } else if (strcmpi(w1, "char_new_display") == 0) {
- chr->new_display = atoi(w2);
- } else if (strcmpi(w1, "max_connect_user") == 0) {
- max_connect_user = atoi(w2);
- if (max_connect_user < -1)
- max_connect_user = -1; // unlimited online players
- } else if(strcmpi(w1, "gm_allow_group") == 0) {
- gm_allow_group = atoi(w2);
- } else if (strcmpi(w1, "autosave_time") == 0) {
- autosave_interval = atoi(w2) * 1000;
- if (autosave_interval <= 0)
- autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
- } else if (strcmpi(w1, "save_log") == 0) {
- save_log = config_switch(w2);
+/**
+ * Reads the 'char_configuration/player/new' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool char_config_read_player_new(const char *filename, const struct config_t *config, bool imported)
+{
+ const struct config_setting_t *setting = NULL, *setting2 = NULL;
+#ifdef RENEWAL
+ const char *start_point_setting = "start_point_re";
+#else
+ const char *start_point_setting = "start_point_pre";
+#endif
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "char_configuration/player/new")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("char_config_read: char_configuration/player/new was not found in %s!\n", filename);
+ return false;
+ }
+
+ if (libconfig->setting_lookup_int(setting, "zeny", &start_zeny) == CONFIG_TRUE) {
+ if (start_zeny > MAX_ZENY) {
+ ShowWarning("char_config_read: player/new/zeny is too big! Capping to MAX_ZENY.\n");
+ start_zeny = MAX_ZENY;
}
- #ifdef RENEWAL
- else if (strcmpi(w1, "start_point_re") == 0) {
- char map[MAP_NAME_LENGTH_EXT];
- int x, y;
- if (sscanf(w2, "%15[^,],%d,%d", map, &x, &y) < 3)
- continue;
- start_point.map = mapindex->name2id(map);
- if (!start_point.map)
- ShowError("Specified start_point_re '%s' not found in map-index cache.\n", map);
- start_point.x = x;
- start_point.y = y;
- }
- #else
- else if (strcmpi(w1, "start_point_pre") == 0) {
- char map[MAP_NAME_LENGTH_EXT];
- int x, y;
- if (sscanf(w2, "%15[^,],%d,%d", map, &x, &y) < 3)
- continue;
- start_point.map = mapindex->name2id(map);
- if (!start_point.map)
- ShowError("Specified start_point_pre '%s' not found in map-index cache.\n", map);
- start_point.x = x;
- start_point.y = y;
- }
- #endif
- else if (strcmpi(w1, "start_items") == 0) {
- int i;
- char *split;
+ }
- i = 0;
- split = strtok(w2, ",");
- while (split != NULL && i < MAX_START_ITEMS * 3) {
- char *split2 = split;
- split = strtok(NULL, ",");
- start_items[i] = atoi(split2);
+ if ((setting2 = libconfig->setting_get_member(setting, "start_items")))
+ chr->config_set_start_item(setting2);
- if (start_items[i] < 0)
- start_items[i] = 0;
+ // start_point / start_point_pre
+ if ((setting2 = libconfig->setting_get_member(setting, start_point_setting))) {
+ const char *str = NULL;
+ if (libconfig->setting_lookup_string(setting2, "map", &str) == CONFIG_TRUE) {
+ start_point.map = mapindex->name2id(str);
+ if (start_point.map == 0)
+ ShowError("char_config_read_player_new: Specified start_point %s not found in map-index cache.\n", str);
+ libconfig->setting_lookup_int16(setting2, "x", &start_point.x);
+ libconfig->setting_lookup_int16(setting2, "y", &start_point.y);
+ }
+ }
- ++i;
- }
+ return true;
+}
- // Format is: id1,quantity1,stackable1,idN,quantityN,stackableN
- if( i%3 )
- {
- ShowWarning("chr->config_read: There are not enough parameters in start_items, ignoring last item...\n");
- if( i%3 == 1 )
- start_items[i-1] = 0;
- else
- start_items[i-2] = 0;
- }
- } else if (strcmpi(w1, "start_zeny") == 0) {
- start_zeny = atoi(w2);
- if (start_zeny < 0)
- start_zeny = 0;
- } else if(strcmpi(w1,"log_char")==0) {
- log_char = atoi(w2); //log char or not [devil]
- } else if (strcmpi(w1, "unknown_char_name") == 0) {
- safestrncpy(unknown_char_name, w2, sizeof(unknown_char_name));
- unknown_char_name[NAME_LENGTH-1] = '\0';
- } else if (strcmpi(w1, "name_ignoring_case") == 0) {
- name_ignoring_case = (bool)config_switch(w2);
- } else if (strcmpi(w1, "char_name_option") == 0) {
- char_name_option = atoi(w2);
- } else if (strcmpi(w1, "char_name_letters") == 0) {
- safestrncpy(char_name_letters, w2, sizeof(char_name_letters));
- } else if (strcmpi(w1, "char_del_level") == 0) { //disable/enable char deletion by its level condition [Lupus]
- char_del_level = atoi(w2);
- } else if (strcmpi(w1, "char_del_delay") == 0) {
- char_del_delay = atoi(w2);
- } else if (strcmpi(w1, "char_aegis_delete") == 0) {
- char_aegis_delete = atoi(w2);
- } else if(strcmpi(w1,"db_path")==0) {
- safestrncpy(db_path, w2, sizeof(db_path));
- } else if (strcmpi(w1, "fame_list_alchemist") == 0) {
- fame_list_size_chemist = atoi(w2);
- if (fame_list_size_chemist > MAX_FAME_LIST) {
- ShowWarning("Max fame list size is %d (fame_list_alchemist)\n", MAX_FAME_LIST);
- fame_list_size_chemist = MAX_FAME_LIST;
- }
- } else if (strcmpi(w1, "fame_list_blacksmith") == 0) {
- fame_list_size_smith = atoi(w2);
- if (fame_list_size_smith > MAX_FAME_LIST) {
- ShowWarning("Max fame list size is %d (fame_list_blacksmith)\n", MAX_FAME_LIST);
- fame_list_size_smith = MAX_FAME_LIST;
- }
- } else if (strcmpi(w1, "fame_list_taekwon") == 0) {
- fame_list_size_taekwon = atoi(w2);
- if (fame_list_size_taekwon > MAX_FAME_LIST) {
- ShowWarning("Max fame list size is %d (fame_list_taekwon)\n", MAX_FAME_LIST);
- fame_list_size_taekwon = MAX_FAME_LIST;
- }
- } else if (strcmpi(w1, "guild_exp_rate") == 0) {
- guild_exp_rate = atoi(w2);
- } else if (strcmpi(w1, "char_maintenance_min_group_id") == 0) {
- char_maintenance_min_group_id = atoi(w2);
- } else if (strcmpi(w1, "import") == 0) {
- chr->config_read(w2);
- } else
- chr->config_dispatch(w1,w2);
+/**
+ * Reads the 'char_configuration/permission' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool char_config_read_permission(const char *filename, const struct config_t *config, bool imported)
+{
+ const struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "char_configuration/permission")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("char_config_read: char_configuration/permission was not found in %s!\n", filename);
+ return false;
}
- fclose(fp);
- ShowInfo("Done reading %s.\n", cfgName);
- return 0;
+ libconfig->setting_lookup_bool_real(setting, "enable_char_creation", &enable_char_creation);
+ libconfig->setting_lookup_int16(setting, "display_new", &chr->new_display);
+ libconfig->setting_lookup_int(setting, "max_connect_user", &max_connect_user);
+ libconfig->setting_lookup_int(setting, "gm_allow_group", &gm_allow_group);
+ libconfig->setting_lookup_int(setting, "maintenance_min_group_id", &char_maintenance_min_group_id);
+ if (libconfig->setting_lookup_int(setting, "server_type", &chr->server_type) == CONFIG_TRUE) {
+ if (chr->server_type < CST_NORMAL || chr->server_type >= CST_MAX) {
+ ShowWarning("char_config_read: Invalid permission/server_type %d, defaulting to CST_NORMAL.\n", chr->server_type);
+ chr->server_type = CST_NORMAL;
+ }
+ }
+
+ return true;
+}
+
+/**
+ * Loads an IP into 'out_ip' and shows status.
+ *
+ * @param type[in] String containing the type of IP being set (for logging purposes).
+ * @param value[in] New ip value to parse.
+ * @param out_ip[in] Pointer to numeric value that will be changed.
+ * @param out_ip_str[in,out] Pointer to str value that will be changed (expected to be already initialized, to display previous value, if any).
+ *
+ * @retval false in case of error.
+ */
+bool char_config_set_ip(const char *type, const char *value, uint32 *out_ip, char *out_ip_str)
+{
+ uint32 ip = 0;
+
+ nullpo_retr(false, type);
+ nullpo_retr(false, value);
+ nullpo_retr(false, out_ip);
+ nullpo_retr(false, out_ip_str);
+
+ if ((ip = sockt->host2ip(value)) == 0)
+ return false;
+ *out_ip = ip;
+
+ ShowStatus("%s IP address : %s -> %s\n", type, out_ip_str[0] ? out_ip_str : "0.0.0.0", sockt->ip2str(ip, NULL));
+ safestrncpy(out_ip_str, value, sizeof(out_ip_str));
+ return true;
}
int do_final(void) {
@@ -5685,6 +6056,8 @@ int do_final(void) {
for (i = 0; i < MAX_MAP_SERVERS; i++)
VECTOR_CLEAR(chr->server[i].maps);
+ VECTOR_CLEAR(start_items);
+
aFree(chr->CHAR_CONF_NAME);
aFree(chr->NET_CONF_NAME);
aFree(chr->SQL_CONF_NAME);
@@ -5791,10 +6164,12 @@ int do_init(int argc, char **argv) {
char_load_defaults();
- chr->CHAR_CONF_NAME = aStrdup("conf/char-server.conf");
+ chr->CHAR_CONF_NAME = aStrdup("conf/char/char-server.conf");
chr->NET_CONF_NAME = aStrdup("conf/network.conf");
- chr->SQL_CONF_NAME = aStrdup("conf/inter-server.conf");
- chr->INTER_CONF_NAME = aStrdup("conf/inter-server.conf");
+ chr->SQL_CONF_NAME = aStrdup("conf/common/inter-server.conf");
+ chr->INTER_CONF_NAME = aStrdup("conf/common/inter-server.conf");
+
+ VECTOR_INIT(start_items);
for (i = 0; i < MAX_MAP_SERVERS; i++)
VECTOR_INIT(chr->server[i].maps);
@@ -5813,16 +6188,39 @@ int do_init(int argc, char **argv) {
start_point.map = mapindex->name2id("new_1-1");
#endif
+ safestrncpy(chr->userid, "s1", sizeof(chr->userid));
+ safestrncpy(chr->passwd, "p1", sizeof(chr->passwd));
+
cmdline->exec(argc, argv, CMDLINE_OPT_NORMAL);
- chr->config_read(chr->CHAR_CONF_NAME);
+ chr->config_read(chr->CHAR_CONF_NAME, false);
sockt->net_config_read(chr->NET_CONF_NAME);
- chr->sql_config_read(chr->SQL_CONF_NAME);
+ chr->sql_config_read(chr->SQL_CONF_NAME, false);
+
+ {
+ // TODO: Remove this when no longer needed.
+#define CHECK_OLD_LOCAL_CONF(oldname, newname) do { \
+ if (stat((oldname), &fileinfo) == 0 && fileinfo.st_size > 0) { \
+ ShowWarning("An old configuration file \"%s\" was found.\n", (oldname)); \
+ ShowWarning("If it contains settings you wish to keep, please merge them into \"%s\".\n", (newname)); \
+ ShowWarning("Otherwise, just delete it.\n"); \
+ ShowInfo("Resuming in 10 seconds...\n"); \
+ HSleep(10); \
+ } \
+} while (0)
+ struct stat fileinfo;
+
+ CHECK_OLD_LOCAL_CONF("conf/import/char_conf.txt", "conf/import/char-server.conf");
+ CHECK_OLD_LOCAL_CONF("conf/import/inter_conf.txt", "conf/import/inter-server.conf");
+ CHECK_OLD_LOCAL_CONF("conf/import/packet_conf.txt", "conf/import/socket.conf");
+
+#undef CHECK_OLD_LOCAL_CONF
+ }
#ifndef BUILDBOT
if (strcmp(chr->userid, "s1")==0 && strcmp(chr->passwd, "p1")==0) {
ShowWarning("Using the default user/password s1/p1 is NOT RECOMMENDED.\n");
ShowNotice("Please edit your 'login' table to create a proper inter-server user/password (gender 'S')\n");
- ShowNotice("And then change the user/password to use in conf/char-server.conf (or conf/import/char_conf.txt)\n");
+ ShowNotice("And then change the user/password to use in conf/char/char-server.conf (or conf/import/char-server.conf)\n");
}
#endif
@@ -5947,6 +6345,9 @@ void char_defaults(void)
chr->server_type = 0;
chr->new_display = 0;
+ chr->show_save_log = true;
+ chr->enable_logs = true;
+
chr->waiting_disconnect = char_waiting_disconnect;
chr->delete_char_sql = char_delete_char_sql;
chr->create_online_char_data = char_create_online_char_data;
@@ -6103,6 +6504,20 @@ void char_defaults(void)
chr->online_data_cleanup_sub = char_online_data_cleanup_sub;
chr->online_data_cleanup = char_online_data_cleanup;
chr->sql_config_read = char_sql_config_read;
- chr->config_dispatch = char_config_dispatch;
+ chr->sql_config_read_registry = char_sql_config_read_registry;
+ chr->sql_config_read_pc = char_sql_config_read_pc;
+ chr->sql_config_read_guild = char_sql_config_read_guild;
chr->config_read = char_config_read;
+ chr->config_read_database = char_config_read_database;
+ chr->config_read_console = char_config_read_console;
+ chr->config_read_player_fame = char_config_read_player_fame;
+ chr->config_read_player_deletion = char_config_read_player_deletion;
+ chr->config_read_player_name = char_config_read_player_name;
+ chr->config_set_start_item = char_config_set_start_item;
+ chr->config_read_player_new = char_config_read_player_new;
+ chr->config_read_player = char_config_read_player;
+ chr->config_read_permission = char_config_read_permission;
+ chr->config_set_ip = char_config_set_ip;
+ chr->config_read_inter = char_config_read_inter;
+ chr->config_read_top = char_config_read_top;
}
diff --git a/src/char/char.h b/src/char/char.h
index a0cfb3bd7..4dbdfd9db 100644
--- a/src/char/char.h
+++ b/src/char/char.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -26,6 +26,10 @@
#include "common/db.h"
#include "common/mmo.h"
+/* Forward Declarations */
+struct config_setting_t; // common/conf.h
+struct config_t; // common/conf.h
+
enum E_CHARSERVER_ST {
CHARSERVER_ST_RUNNING = CORE_ST_LAST,
CHARSERVER_ST_SHUTDOWN,
@@ -110,13 +114,16 @@ struct char_interface {
uint32 ip;
uint16 port;
int server_type;
- int new_display;
+ int16 new_display; ///< Display 'New' in the server list.
char *CHAR_CONF_NAME;
char *NET_CONF_NAME; ///< Network config filename
char *SQL_CONF_NAME;
char *INTER_CONF_NAME;
+ bool show_save_log; ///< Show loading/saving messages.
+ bool enable_logs; ///< Whether to log char server operations.
+
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);
@@ -272,9 +279,24 @@ struct char_interface {
int (*check_connect_login_server) (int tid, int64 tick, int id, intptr_t data);
int (*online_data_cleanup_sub) (union DBKey key, struct DBData *data, va_list ap);
int (*online_data_cleanup) (int tid, int64 tick, int id, intptr_t data);
- void (*sql_config_read) (const char* cfgName);
- void (*config_dispatch) (char *w1, char *w2);
- int (*config_read) (const char* cfgName);
+
+ bool (*sql_config_read) (const char *filename, bool imported);
+ bool (*sql_config_read_registry) (const char *filename, const struct config_t *config, bool imported);
+ bool (*sql_config_read_pc) (const char *filename, const struct config_t *config, bool imported);
+ bool (*sql_config_read_guild) (const char *filename, const struct config_t *config, bool imported);
+ bool (*config_read) (const char *filename, bool imported);
+ bool (*config_read_database) (const char *filename, const struct config_t *config, bool imported);
+ bool (*config_read_console) (const char *filename, const struct config_t *config, bool imported);
+ bool (*config_read_player_fame) (const char *filename, const struct config_t *config, bool imported);
+ bool (*config_read_player_deletion) (const char *filename, const struct config_t *config, bool imported);
+ bool (*config_read_player_name) (const char *filename, const struct config_t *config, bool imported);
+ void (*config_set_start_item) (const struct config_setting_t *setting);
+ bool (*config_read_player_new) (const char *filename, const struct config_t *config, bool imported);
+ bool (*config_read_player) (const char *filename, const struct config_t *config, bool imported);
+ bool (*config_read_permission) (const char *filename, const struct config_t *config, bool imported);
+ bool (*config_set_ip) (const char *type, const char *value, uint32 *out_ip, char *out_ip_str);
+ bool (*config_read_inter) (const char *filename, const struct config_t *config, bool imported);
+ bool (*config_read_top) (const char *filename, const struct config_t *config, bool imported);
};
#ifdef HERCULES_CORE
@@ -282,7 +304,6 @@ extern int char_name_option;
extern char char_name_letters[];
extern bool char_gm_read;
extern int autosave_interval;
-extern int save_log;
extern char db_path[];
extern char char_db[256];
extern char scdata_db[256];
@@ -318,7 +339,6 @@ extern char char_reg_str_db[32];
extern char char_reg_num_db[32];
extern int guild_exp_rate;
-extern int log_inter;
void char_load_defaults(void);
void char_defaults(void);
diff --git a/src/char/int_elemental.c b/src/char/int_elemental.c
index c25cfa5c8..aed25febd 100644
--- a/src/char/int_elemental.c
+++ b/src/char/int_elemental.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -128,7 +128,7 @@ bool mapif_elemental_load(int ele_id, int char_id, struct s_elemental *ele) {
SQL->GetData(inter->sql_handle, 13, &data, NULL); ele->hit = atoi(data);
SQL->GetData(inter->sql_handle, 14, &data, NULL); ele->life_time = atoi(data);
SQL->FreeResult(inter->sql_handle);
- if( save_log )
+ if (chr->show_save_log)
ShowInfo("Elemental loaded (%d - %d).\n", ele->elemental_id, ele->char_id);
return true;
diff --git a/src/char/int_guild.c b/src/char/int_guild.c
index d2507a2f9..dcc1ed7cb 100644
--- a/src/char/int_guild.c
+++ b/src/char/int_guild.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -83,9 +83,9 @@ int inter_guild_save_timer(int tid, int64 tick, int id, intptr_t data) {
state++;
}
- if( g->save_flag == GS_REMOVE )
- {// Nothing to save, guild is ready for removal.
- if (save_log)
+ if (g->save_flag == GS_REMOVE) {
+ // Nothing to save, guild is ready for removal.
+ if (chr->show_save_log)
ShowInfo("Guild Unloaded (%d - %s)\n", g->guild_id, g->name);
db_remove(inter_guild->guild_db, key);
}
@@ -337,8 +337,8 @@ int inter_guild_tosql(struct guild *g,int flag)
}
}
- if (save_log)
- ShowInfo("Saved guild (%d - %s):%s\n",g->guild_id,g->name,t_info);
+ if (chr->show_save_log)
+ ShowInfo("Saved guild (%d - %s):%s\n", g->guild_id, g->name, t_info);
return 1;
}
@@ -525,7 +525,7 @@ struct guild * inter_guild_fromsql(int guild_id)
idb_put(inter_guild->guild_db, guild_id, g); //Add to cache
g->save_flag |= GS_REMOVE; //But set it to be removed, in case it is not needed for long.
- if (save_log)
+ if (chr->show_save_log)
ShowInfo("Guild loaded (%d - %s)\n", guild_id, g->name);
return g;
@@ -548,7 +548,7 @@ int inter_guild_castle_tosql(struct guild_castle *gc)
if (SQL_ERROR == SQL->QueryStr(inter->sql_handle, StrBuf->Value(&buf)))
Sql_ShowDebug(inter->sql_handle);
- else if(save_log)
+ else if (chr->show_save_log)
ShowInfo("Saved guild castle (%d)\n", gc->castle_id);
StrBuf->Destroy(&buf);
@@ -600,7 +600,7 @@ struct guild_castle* inter_guild_castle_fromsql(int castle_id)
idb_put(inter_guild->castle_db, castle_id, gc);
- if (save_log)
+ if (chr->show_save_log)
ShowInfo("Loaded guild castle (%d - guild %d)\n", castle_id, gc->guild_id);
return gc;
@@ -1233,9 +1233,9 @@ int mapif_parse_CreateGuild(int fd, int account_id, const char *name, const stru
mapif->guild_created(fd,account_id,g);
mapif->guild_info(fd,g);
- if(log_inter)
+ if (inter->enable_logs)
inter->log("guild %s (id=%d) created by master %s (id=%d)\n",
- name, g->guild_id, master->name, master->account_id );
+ name, g->guild_id, master->name, master->account_id);
return 0;
}
@@ -1442,8 +1442,8 @@ int mapif_parse_BreakGuild(int fd, int guild_id)
mapif->guild_broken(guild_id,0);
- if(log_inter)
- inter->log("guild %s (id=%d) broken\n",g->name,guild_id);
+ if (inter->enable_logs)
+ inter->log("guild %s (id=%d) broken\n", g->name, guild_id);
//Remove the guild from memory. [Skotlex]
idb_remove(inter_guild->guild_db, guild_id);
@@ -1821,7 +1821,7 @@ int mapif_parse_GuildCastleDataSave(int fd, int castle_id, int index, int value)
switch (index) {
case 1:
- if (log_inter && gc->guild_id != value) {
+ if (inter->enable_logs && gc->guild_id != value) {
int gid = (value) ? value : gc->guild_id;
struct guild *g = idb_get(inter_guild->guild_db, gid);
inter->log("guild %s (id=%d) %s castle id=%d\n",
diff --git a/src/char/int_homun.c b/src/char/int_homun.c
index 90643699c..04f4c8f21 100644
--- a/src/char/int_homun.c
+++ b/src/char/int_homun.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -262,7 +262,7 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
}
SQL->FreeResult(inter->sql_handle);
- if( save_log )
+ if (chr->show_save_log)
ShowInfo("Homunculus loaded (%d - %s).\n", hd->hom_id, hd->name);
return true;
diff --git a/src/char/int_mercenary.c b/src/char/int_mercenary.c
index 0bc3c0909..f96e45a50 100644
--- a/src/char/int_mercenary.c
+++ b/src/char/int_mercenary.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -168,7 +168,7 @@ bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc)
SQL->GetData(inter->sql_handle, 3, &data, NULL); merc->kill_count = atoi(data);
SQL->GetData(inter->sql_handle, 4, &data, NULL); merc->life_time = atoi(data);
SQL->FreeResult(inter->sql_handle);
- if( save_log )
+ if (chr->show_save_log)
ShowInfo("Mercenary loaded (%d - %d).\n", merc->mercenary_id, merc->char_id);
return true;
diff --git a/src/char/int_party.c b/src/char/int_party.c
index 684d846d4..e2be9f3ca 100644
--- a/src/char/int_party.c
+++ b/src/char/int_party.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -190,7 +190,7 @@ int inter_party_tosql(struct party *p, int flag, int index)
Sql_ShowDebug(inter->sql_handle);
}
- if( save_log )
+ if (chr->show_save_log)
ShowInfo("Party Saved (%d - %s)\n", party_id, p->name);
return 1;
}
@@ -257,7 +257,7 @@ struct party_data *inter_party_fromsql(int party_id)
}
SQL->FreeResult(inter->sql_handle);
- if( save_log )
+ if (chr->show_save_log)
ShowInfo("Party loaded (%d - %s).\n", party_id, p->party.name);
//Add party to memory.
CREATE(p, struct party_data, 1);
diff --git a/src/char/int_pet.c b/src/char/int_pet.c
index eb9bda8d0..489b10e3e 100644
--- a/src/char/int_pet.c
+++ b/src/char/int_pet.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -85,7 +85,7 @@ int inter_pet_tosql(const struct s_pet *p)
pet_id = p->pet_id;
}
- if (save_log)
+ if (chr->show_save_log)
ShowInfo("Pet saved %d - %s.\n", pet_id, p->name);
return pet_id;
@@ -130,7 +130,7 @@ int inter_pet_fromsql(int pet_id, struct s_pet* p)
p->hungry = cap_value(p->hungry, 0, 100);
p->intimate = cap_value(p->intimate, 0, 1000);
- if( save_log )
+ if (chr->show_save_log)
ShowInfo("Pet loaded (%d - %s).\n", pet_id, p->name);
}
return 0;
diff --git a/src/char/inter.c b/src/char/inter.c
index 5fb35e6aa..4c5eb05e5 100644
--- a/src/char/inter.c
+++ b/src/char/inter.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -36,6 +36,7 @@
#include "char/int_storage.h"
#include "char/mapif.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/db.h"
#include "common/memmgr.h"
#include "common/mmo.h"
@@ -62,7 +63,7 @@ char char_server_pw[100] = "ragnarok";
char char_server_db[32] = "ragnarok";
char default_codepage[32] = ""; //Feature by irmin.
-unsigned int party_share_level = 10;
+int party_share_level = 10;
// recv. packet list
int inter_recv_packet_length[] = {
@@ -791,50 +792,84 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type)
return 1;
}
-/*==========================================
- * read config file
- *------------------------------------------*/
-static int inter_config_read(const char* cfgName)
+/**
+ * Reads the 'char_configuration/sql_connection' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool inter_config_read_connection(const char *filename, const struct config_t *config, bool imported)
{
- char line[1024], w1[1024], w2[1024];
- FILE* fp;
+ const struct config_setting_t *setting = NULL;
- nullpo_retr(1, cfgName);
- fp = fopen(cfgName, "r");
- if(fp == NULL) {
- ShowError("File not found: %s\n", cfgName);
- return 1;
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "char_configuration/sql_connection")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("char_config_read: char_configuration/sql_connection was not found in %s!\n", filename);
+ ShowWarning("inter_config_read_connection: Defaulting sql_connection...\n");
+ return false;
}
- while (fgets(line, sizeof(line), fp)) {
- int i = sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2);
- if(i != 2)
- continue;
+ libconfig->setting_lookup_int(setting, "db_port", &char_server_port);
+ libconfig->setting_lookup_mutable_string(setting, "db_hostname", char_server_ip, sizeof(char_server_ip));
+ libconfig->setting_lookup_mutable_string(setting, "db_username", char_server_id, sizeof(char_server_id));
+ libconfig->setting_lookup_mutable_string(setting, "db_password", char_server_pw, sizeof(char_server_pw));
+ libconfig->setting_lookup_mutable_string(setting, "db_database", char_server_db, sizeof(char_server_db));
+ libconfig->setting_lookup_mutable_string(setting, "default_codepage", default_codepage, sizeof(default_codepage));
+
+ return true;
+}
- if(!strcmpi(w1,"char_server_ip")) {
- safestrncpy(char_server_ip, w2, sizeof(char_server_ip));
- } else if(!strcmpi(w1,"char_server_port")) {
- char_server_port = atoi(w2);
- } else if(!strcmpi(w1,"char_server_id")) {
- safestrncpy(char_server_id, w2, sizeof(char_server_id));
- } else if(!strcmpi(w1,"char_server_pw")) {
- safestrncpy(char_server_pw, w2, sizeof(char_server_pw));
- } else if(!strcmpi(w1,"char_server_db")) {
- safestrncpy(char_server_db, w2, sizeof(char_server_db));
- } else if(!strcmpi(w1,"default_codepage")) {
- safestrncpy(default_codepage, w2, sizeof(default_codepage));
- } else if(!strcmpi(w1,"party_share_level"))
- party_share_level = atoi(w2);
- else if(!strcmpi(w1,"log_inter"))
- log_inter = atoi(w2);
- else if(!strcmpi(w1,"import"))
- inter->config_read(w2);
+/**
+ * Reads the 'inter_configuration' config file and initializes required variables.
+ *
+ * @param filename Path to configuration file
+ * @param imported Whether the current config is from an imported file.
+ *
+ * @retval false in case of error.
+ */
+bool inter_config_read(const char *filename, bool imported)
+{
+ struct config_t config;
+ const struct config_setting_t *setting = NULL;
+ const char *import = NULL;
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+
+ if (!libconfig->load_file(&config, filename))
+ return false;
+
+ if ((setting = libconfig->lookup(&config, "inter_configuration")) == NULL) {
+ libconfig->destroy(&config);
+ if (imported)
+ return true;
+ ShowError("inter_config_read: inter_configuration was not found in %s!\n", filename);
+ return false;
}
- fclose(fp);
+ libconfig->setting_lookup_int(setting, "party_share_level", &party_share_level);
+ libconfig->setting_lookup_bool_real(setting, "log_inter", &inter->enable_logs);
- ShowInfo ("Done reading %s.\n", cfgName);
+ ShowInfo("Done reading %s.\n", filename);
- return 0;
+ // import should overwrite any previous configuration, so it should be called last
+ if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) {
+ if (strcmp(import, filename) == 0 || strcmp(import, chr->INTER_CONF_NAME) == 0) {
+ ShowWarning("inter_config_read: Loop detected in %s! Skipping 'import'...\n", filename);
+ } else {
+ if (!inter->config_read(import, true))
+ retval = false;
+ }
+ }
+
+ libconfig->destroy(&config);
+ return retval;
}
/**
@@ -879,9 +914,7 @@ int inter_log(char* fmt, ...)
// initialize
int inter_init_sql(const char *file)
{
- //int i;
-
- inter->config_read(file);
+ inter->config_read(file, false);
//DB connection initialized
inter->sql_handle = SQL->Malloc();
@@ -1364,6 +1397,7 @@ void inter_defaults(void)
{
inter = &inter_s;
+ inter->enable_logs = true;
inter->sql_handle = NULL;
inter->msg_txt = inter_msg_txt;
@@ -1384,4 +1418,5 @@ void inter_defaults(void)
inter->check_length = inter_check_length;
inter->parse_frommap = inter_parse_frommap;
inter->final = inter_final;
+ inter->config_read_connection = inter_config_read_connection;
}
diff --git a/src/char/inter.h b/src/char/inter.h
index 4e8d113ce..57d1db86c 100644
--- a/src/char/inter.h
+++ b/src/char/inter.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -28,11 +28,13 @@
/* Forward Declarations */
struct Sql; // common/sql.h
+struct config_t; // common/conf.h
/**
* inter interface
**/
struct inter_interface {
+ bool enable_logs; ///< Whether to log inter-server operations.
struct Sql *sql_handle;
const char* (*msg_txt) (int msg_number);
bool (*msg_config_read) (const char *cfg_name, bool allow_override);
@@ -42,7 +44,6 @@ struct inter_interface {
void (*msg_to_fd) (int fd, int u_fd, int aid, char *msg, ...) __attribute__((format(printf, 4, 5)));
void (*savereg) (int account_id, int char_id, const char *key, unsigned int index, intptr_t val, bool is_string);
int (*accreg_fromsql) (int account_id,int char_id, int fd, int type);
- int (*config_read) (const char* cfgName);
int (*vlog) (char* fmt, va_list ap);
int (*log) (char* fmt, ...);
int (*init_sql) (const char *file);
@@ -52,10 +53,12 @@ struct inter_interface {
int (*check_length) (int fd, int length);
int (*parse_frommap) (int fd);
void (*final) (void);
+ bool (*config_read) (const char *filename, bool imported);
+ bool (*config_read_connection) (const char *filename, const struct config_t *config, bool imported);
};
#ifdef HERCULES_CORE
-extern unsigned int party_share_level;
+extern int party_share_level; ///< Share range for parties.
void inter_defaults(void);
#endif // HERCULES_CORE
diff --git a/src/char/pincode.c b/src/char/pincode.c
index 6930a7a57..fc1a4c037 100644
--- a/src/char/pincode.c
+++ b/src/char/pincode.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -24,6 +24,7 @@
#include "char/char.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/db.h"
#include "common/mmo.h"
#include "common/nullpo.h"
@@ -178,33 +179,52 @@ void pincode_decrypt(unsigned int userSeed, char* pin) {
sprintf(pin, "%d%d%d%d", pin[0], pin[1], pin[2], pin[3]);
}
-bool pincode_config_read(char *w1, char *w2) {
+/**
+ * Reads the 'char_configuration/pincode' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool pincode_config_read(const char *filename, const struct config_t *config, bool imported)
+{
+ const struct config_setting_t *setting = NULL;
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "char_configuration/pincode")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("char_config_read: char_configuration/pincode was not found in %s!\n", filename);
+ return false;
+ }
- nullpo_ret(w1);
- nullpo_ret(w2);
- while ( true ) {
- if ( strcmpi(w1, "pincode_enabled") == 0 ) {
- pincode->enabled = atoi(w2);
+ if (libconfig->setting_lookup_bool(setting, "enabled", &pincode->enabled) == CONFIG_TRUE) {
#if PACKETVER < 20110309
- if( pincode->enabled ) {
- ShowWarning("pincode_enabled requires PACKETVER 20110309 or higher. disabling...\n");
- pincode->enabled = 0;
- }
+ if (pincode->enabled) {
+ ShowWarning("pincode_enabled requires PACKETVER 20110309 or higher. disabling...\n");
+ pincode->enabled = 0;
+ }
#endif
- } else if ( strcmpi(w1, "pincode_changetime") == 0 ) {
- pincode->changetime = atoi(w2)*60;
- } else if ( strcmpi(w1, "pincode_maxtry") == 0 ) {
- pincode->maxtry = atoi(w2);
- if( pincode->maxtry > 3 ) {
- ShowWarning("pincode_maxtry is too high (%d); maximum allowed: 3! capping to 3...\n", pincode->maxtry);
- pincode->maxtry = 3;
- }
- } else if ( strcmpi(w1, "pincode_charselect") == 0 ) {
- pincode->charselect = atoi(w2);
- } else {
- return false;
+ }
+
+ if (libconfig->setting_lookup_int(setting, "change_time", &pincode->changetime) == CONFIG_TRUE)
+ pincode->changetime *= 60;
+
+ if (libconfig->setting_lookup_int(setting, "max_tries", &pincode->maxtry) == CONFIG_TRUE) {
+ if (pincode->maxtry > 3) {
+ ShowWarning("pincode_maxtry is too high (%d); Maximum allowed: 3! Capping to 3...\n",pincode->maxtry);
+ pincode->maxtry = 3;
+ }
+ }
+
+ if (libconfig->setting_lookup_int(setting, "request", &pincode->charselect) == CONFIG_TRUE) {
+ if (pincode->charselect != 1 && pincode->charselect != 0) {
+ ShowWarning("Invalid pincode/request! Defaulting to 0\n");
+ pincode->charselect = 0;
}
- break;
}
return true;
diff --git a/src/char/pincode.h b/src/char/pincode.h
index fb0c1a9c4..cffaa3054 100644
--- a/src/char/pincode.h
+++ b/src/char/pincode.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -23,7 +23,9 @@
#include "common/hercules.h"
+/* Forward Declarations */
struct char_session_data;
+struct config_t; // common/conf.h
enum PincodeResponseCode {
PINCODE_OK = 0,
@@ -55,7 +57,7 @@ struct pincode_interface {
void (*change) (int fd, struct char_session_data* sd);
int (*compare) (int fd, struct char_session_data* sd, char* pin);
void (*check) (int fd, struct char_session_data* sd);
- bool (*config_read) (char *w1, char *w2);
+ bool (*config_read) (const char *filename, const struct config_t *config, bool imported);
};
#ifdef HERCULES_CORE
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 8e0bbe992..a134a4822 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2013-2015 Hercules Dev Team
+ * Copyright (C) 2013-2016 Hercules Dev Team
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -407,7 +407,7 @@ bool hpm_add_arg(unsigned int pluginID, char *name, bool has_param, CmdlineExecF
* @retval true if the listener was added successfully.
* @retval false in case of error.
*/
-bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *name, void (*parse_func) (const char *key, const char *val), int (*return_func) (const char *key))
+bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *name, void (*parse_func) (const char *key, const char *val), int (*return_func) (const char *key), bool required)
{
struct HPConfListenStorage *conf;
int i;
@@ -442,6 +442,7 @@ bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *na
safestrncpy(conf->key, name, HPM_ADDCONF_LENGTH);
conf->parse_func = parse_func;
conf->return_func = return_func;
+ conf->required = required;
return true;
}
@@ -859,6 +860,52 @@ bool hplugins_get_battle_conf(const char *w1, int *value)
}
/**
+ * Parses battle config entries registered by plugins.
+ *
+ * @param config The configuration file to parse.
+ * @param filename Path to configuration file.
+ * @param imported Whether the current config is imported from another file.
+ * @retval false in case of error.
+ */
+bool hplugins_parse_battle_conf(const struct config_t *config, const char *filename, bool imported)
+{
+ const struct config_setting_t *setting = NULL;
+ int i, val, type;
+ char str[1024];
+ bool retval = true;
+
+ nullpo_retr(false, config);
+
+ for (i = 0; i < VECTOR_LENGTH(HPM->config_listeners[HPCT_BATTLE]); i++) {
+ const struct HPConfListenStorage *entry = &VECTOR_INDEX(HPM->config_listeners[HPCT_BATTLE], i);
+ const char *config_name = entry->key;
+ if ((setting = libconfig->lookup(config, config_name)) == NULL) {
+ if (!imported && entry->required) {
+ ShowWarning("Missing configuration '%s' in file %s!\n", config_name, filename);
+ retval = false;
+ }
+ continue;
+ }
+
+ switch ((type = config_setting_type(setting))) {
+ case CONFIG_TYPE_INT:
+ val = libconfig->setting_get_int(setting);
+ break;
+ case CONFIG_TYPE_BOOL:
+ val = libconfig->setting_get_bool(setting);
+ break;
+ default: // Unsupported type
+ ShowWarning("Setting %s has unsupported type %d, ignoring...\n", config_name, type);
+ retval = false;
+ continue;
+ }
+ sprintf(str, "%d", val); // FIXME: Remove this when support to int's as value is added
+ entry->parse_func(config_name, str);
+ }
+ return retval;
+}
+
+/**
* Helper to destroy an interface's hplugin_data store and release any owned memory.
*
* The pointer will be cleared.
@@ -1074,6 +1121,7 @@ void hpm_defaults(void)
HPM->parse_packets = hplugins_parse_packets;
HPM->load_sub = NULL;
HPM->parseConf = hplugins_parse_conf;
+ HPM->parse_battle_conf = hplugins_parse_battle_conf;
HPM->getBattleConf = hplugins_get_battle_conf;
HPM->DataCheck = HPM_DataCheck;
HPM->datacheck_init = HPM_datacheck_init;
diff --git a/src/common/HPM.h b/src/common/HPM.h
index 0b1275fde..43f610a6a 100644
--- a/src/common/HPM.h
+++ b/src/common/HPM.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2013-2015 Hercules Dev Team
+ * Copyright (C) 2013-2016 Hercules Dev Team
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -65,7 +65,9 @@
#endif // WIN32
+/* Forward Declarations */
struct HPMHooking_core_interface;
+struct config_t;
struct hplugin {
DLL dll;
@@ -121,6 +123,7 @@ struct HPConfListenStorage {
char key[HPM_ADDCONF_LENGTH];
void (*parse_func) (const char *key, const char *val);
int (*return_func) (const char *key);
+ bool required;
};
/* Hercules Plugin Manager Interface */
@@ -155,6 +158,7 @@ struct HPM_interface {
void *(*import_symbol) (char *name, unsigned int pID);
void (*share) (void *value, const char *name);
void (*config_read) (void);
+ bool (*parse_battle_conf) (const struct config_t *config, const char *filename, bool imported);
char *(*pid2name) (unsigned int pid);
unsigned char (*parse_packets) (int fd, int packet_id, enum HPluginPacketHookingPoints point);
void (*load_sub) (struct hplugin *plugin);
diff --git a/src/common/HPMi.h b/src/common/HPMi.h
index e16eb1d75..19b9b20a5 100644
--- a/src/common/HPMi.h
+++ b/src/common/HPMi.h
@@ -188,19 +188,19 @@ enum HPluginConfType {
/* HPMi->addPacket */
#define addPacket(cmd,len,receive,point) HPMi->addPacket(cmd,len,receive,point,HPMi->pid)
/* HPMi->addBattleConf */
-#define addBattleConf(bcname,funcname,returnfunc) HPMi->addConf(HPMi->pid,HPCT_BATTLE,bcname,funcname,returnfunc)
+#define addBattleConf(bcname, funcname, returnfunc, required) HPMi->addConf(HPMi->pid, HPCT_BATTLE, bcname, funcname, returnfunc, required)
/* HPMi->addLogin */
-#define addLoginConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_LOGIN,bcname,funcname,NULL)
+#define addLoginConf(bcname, funcname) HPMi->addConf(HPMi->pid, HPCT_LOGIN, bcname, funcname, NULL, false)
/* HPMi->addChar */
-#define addCharConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_CHAR,bcname,funcname,NULL)
+#define addCharConf(bcname, funcname) HPMi->addConf(HPMi->pid, HPCT_CHAR, bcname, funcname, NULL, false)
/* HPMi->addCharInter */
-#define addCharInterConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_CHAR_INTER,bcname,funcname,NULL)
+#define addCharInterConf(bcname, funcname) HPMi->addConf(HPMi->pid, HPCT_CHAR_INTER, bcname, funcname, NULL, false)
/* HPMi->addMapInter */
-#define addMapInterConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_MAP_INTER,bcname,funcname,NULL)
+#define addMapInterConf(bcname, funcname) HPMi->addConf(HPMi->pid, HPCT_MAP_INTER, bcname, funcname, NULL, false)
/* HPMi->addLog */
-#define addLogConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_LOG,bcname,funcname,NULL)
+#define addLogConf(bcname, funcname) HPMi->addConf(HPMi->pid, HPCT_LOG, bcname, funcname, NULL, false)
/* HPMi->addScript */
-#define addScriptConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_SCRIPT,bcname,funcname,NULL)
+#define addScriptConf(bcname, funcname) HPMi->addConf(HPMi->pid, HPCT_SCRIPT, bcname, funcname, NULL, false)
/* HPMi->addPCGPermission */
#define addGroupPermission(pcgname,maskptr) HPMi->addPCGPermission(HPMi->pid,pcgname,&maskptr)
@@ -223,7 +223,7 @@ struct HPMi_interface {
/* program --arg/-a */
bool (*addArg) (unsigned int pluginID, char *name, bool has_param, CmdlineExecFunc func, const char *help);
/* battle-config recv param */
- bool (*addConf) (unsigned int pluginID, enum HPluginConfType type, char *name, void (*parse_func) (const char *key, const char *val), int (*return_func) (const char *key));
+ bool (*addConf) (unsigned int pluginID, enum HPluginConfType type, char *name, void (*parse_func) (const char *key, const char *val), int (*return_func) (const char *key), bool required);
/* pc group permission */
void (*addPCGPermission) (unsigned int pluginID, char *name, unsigned int *mask);
diff --git a/src/common/mmo.h b/src/common/mmo.h
index 0a5d9d053..77f706f0d 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -185,9 +185,6 @@
#ifndef MAX_QUEST_OBJECTIVES
#define MAX_QUEST_OBJECTIVES 3 // Max quest objectives for a quest
#endif
-#ifndef MAX_START_ITEMS
-#define MAX_START_ITEMS 32 // Max number of items allowed to be given to a char whenever it's created. [mkbu95]
-#endif
// for produce
#define MIN_ATTRIBUTE 0
@@ -360,7 +357,7 @@ enum equip_pos {
struct point {
unsigned short map;
- short x,y;
+ int16 x, y;
};
enum e_skill_flag
@@ -1068,6 +1065,7 @@ enum e_char_server_type {
CST_OVER18 = 2,
CST_PAYING = 3,
CST_F2P = 4,
+ CST_MAX,
};
enum e_pc_reg_loading {
diff --git a/src/common/socket.c b/src/common/socket.c
index af5e8aa73..cee2875d5 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -80,6 +80,8 @@ struct socket_interface *sockt;
struct socket_data **session;
+const char *SOCKET_CONF_FILENAME = "conf/common/socket.conf";
+
#ifdef SEND_SHORTLIST
// Add a fd to the shortlist so that it'll be recognized as a fd that needs
// sending done on it.
@@ -1059,17 +1061,19 @@ int do_sockets(int next)
//////////////////////////////
// IP rules and DDoS protection
-typedef struct connect_history {
+struct connect_history {
uint32 ip;
int64 tick;
int count;
unsigned ddos : 1;
-} ConnectHistory;
+};
-typedef struct access_control {
+struct access_control {
uint32 ip;
uint32 mask;
-} AccessControl;
+};
+
+VECTOR_STRUCT_DECL(access_control_list, struct access_control);
enum aco {
ACO_DENY_ALLOW,
@@ -1077,11 +1081,9 @@ enum aco {
ACO_MUTUAL_FAILURE
};
-static AccessControl* access_allow = NULL;
-static AccessControl* access_deny = NULL;
+static struct access_control_list access_allow;
+static struct access_control_list access_deny;
static int access_order = ACO_DENY_ALLOW;
-static int access_allownum = 0;
-static int access_denynum = 0;
static int access_debug = 0;
static int ddos_count = 10;
static int ddos_interval = 3*1000;
@@ -1106,33 +1108,35 @@ static int connect_check(uint32 ip)
/// 1 or 2 : Connection Accepted
static int connect_check_(uint32 ip)
{
- ConnectHistory* hist = NULL;
+ struct connect_history *hist = NULL;
int i;
int is_allowip = 0;
int is_denyip = 0;
int connect_ok = 0;
// Search the allow list
- for( i=0; i < access_allownum; ++i ){
- if (SUBNET_MATCH(ip, access_allow[i].ip, access_allow[i].mask)) {
- if( access_debug ){
+ for (i = 0; i < VECTOR_LENGTH(access_allow); ++i) {
+ struct access_control *entry = &VECTOR_INDEX(access_allow, i);
+ if (SUBNET_MATCH(ip, entry->ip, entry->mask)) {
+ if (access_debug) {
ShowInfo("connect_check: Found match from allow list:%u.%u.%u.%u IP:%u.%u.%u.%u Mask:%u.%u.%u.%u\n",
CONVIP(ip),
- CONVIP(access_allow[i].ip),
- CONVIP(access_allow[i].mask));
+ CONVIP(entry->ip),
+ CONVIP(entry->mask));
}
is_allowip = 1;
break;
}
}
// Search the deny list
- for( i=0; i < access_denynum; ++i ){
- if (SUBNET_MATCH(ip, access_deny[i].ip, access_deny[i].mask)) {
- if( access_debug ){
+ for (i = 0; i < VECTOR_LENGTH(access_deny); ++i) {
+ struct access_control *entry = &VECTOR_INDEX(access_deny, i);
+ if (SUBNET_MATCH(ip, entry->ip, entry->mask)) {
+ if (access_debug) {
ShowInfo("connect_check: Found match from deny list:%u.%u.%u.%u IP:%u.%u.%u.%u Mask:%u.%u.%u.%u\n",
CONVIP(ip),
- CONVIP(access_deny[i].ip),
- CONVIP(access_deny[i].mask));
+ CONVIP(entry->ip),
+ CONVIP(entry->mask));
}
is_denyip = 1;
break;
@@ -1187,7 +1191,7 @@ static int connect_check_(uint32 ip)
}
}
// IP not found, add to history
- CREATE(hist, ConnectHistory, 1);
+ CREATE(hist, struct connect_history, 1);
hist->ip = ip;
hist->tick = timer->gettick();
uidb_put(connect_history, ip, hist);
@@ -1199,7 +1203,7 @@ static int connect_check_(uint32 ip)
static int connect_check_clear(int tid, int64 tick, int id, intptr_t data) {
int clear = 0;
int list = 0;
- ConnectHistory *hist = NULL;
+ struct connect_history *hist = NULL;
struct DBIterator *iter;
if( !db_size(connect_history) )
@@ -1227,7 +1231,7 @@ static int connect_check_clear(int tid, int64 tick, int id, intptr_t data) {
/// Parses the ip address and mask and puts it into acc.
/// Returns 1 is successful, 0 otherwise.
-int access_ipmask(const char* str, AccessControl* acc)
+int access_ipmask(const char *str, struct access_control *acc)
{
uint32 ip;
uint32 mask;
@@ -1270,82 +1274,210 @@ int access_ipmask(const char* str, AccessControl* acc)
acc->mask = mask;
return 1;
}
+
+/**
+ * Adds an entry to the access list.
+ *
+ * @param setting The setting to read from.
+ * @param list_name The list name (used in error messages).
+ * @param access_list The access list to edit.
+ *
+ * @retval false in case of failure
+ */
+bool access_list_add(struct config_setting_t *setting, const char *list_name, struct access_control_list *access_list)
+{
+ const char *temp = NULL;
+ int i, setting_length;
+
+ nullpo_retr(false, setting);
+ nullpo_retr(false, list_name);
+ nullpo_retr(false, access_list);
+
+ if ((setting_length = libconfig->setting_length(setting)) <= 0)
+ return false;
+
+ VECTOR_ENSURE(*access_list, setting_length, 1);
+ for (i = 0; i < setting_length; i++) {
+ struct access_control acc;
+ if ((temp = libconfig->setting_get_string_elem(setting, i)) == NULL) {
+ continue;
+ }
+
+ if (!access_ipmask(temp, &acc)) {
+ ShowError("access_list_add: Invalid ip or ip range %s '%d'!\n", list_name, i);
+ continue;
+ }
+ VECTOR_PUSH(*access_list, acc);
+ }
+
+ return true;
+}
+
//////////////////////////////
#endif // MINICORE
//////////////////////////////
-int socket_config_read(const char* cfgName)
+/**
+ * Reads 'socket_configuration/ip_rules' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool socket_config_read_iprules(const char *filename, struct config_t *config, bool imported)
{
- char line[1024],w1[1024],w2[1024];
- FILE *fp;
+#ifndef MINICORE
+ struct config_setting_t *setting = NULL;
+ const char *temp = NULL;
- fp = fopen(cfgName, "r");
- if(fp == NULL) {
- ShowError("File not found: %s\n", cfgName);
- return 1;
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "socket_configuration/ip_rules")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("socket_config_read: socket_configuration/ip_rules was not found in %s!\n", filename);
+ return false;
}
+ libconfig->setting_lookup_bool(setting, "enable", &ip_rules);
- while (fgets(line, sizeof(line), fp)) {
- if(line[0] == '/' && line[1] == '/')
- continue;
- if (sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) != 2)
- continue;
+ if (!ip_rules)
+ return true;
- if (!strcmpi(w1, "stall_time")) {
- sockt->stall_time = atoi(w2);
- if( sockt->stall_time < 3 )
- sockt->stall_time = 3;/* a minimum is required to refrain it from killing itself */
- }
-#ifdef SOCKET_EPOLL
- else if(!strcmpi(w1, "epoll_maxevents")) {
- epoll_maxevents = atoi(w2);
- if(epoll_maxevents < 16){
- epoll_maxevents = 16; // minimum that seems to be useful
- }
+ if (libconfig->setting_lookup_string(setting, "order", &temp) == CONFIG_TRUE) {
+ if (strcmpi(temp, "deny,allow" ) == 0) {
+ access_order = ACO_DENY_ALLOW;
+ } else if (strcmpi(temp, "allow, deny") == 0) {
+ access_order = ACO_ALLOW_DENY;
+ } else if (strcmpi(temp, "mutual-failure") == 0) {
+ access_order = ACO_MUTUAL_FAILURE;
+ } else {
+ ShowWarning("socket_config_read: invalid value '%s' for socket_configuration/ip_rules/order.\n", temp);
}
+ }
+
+ if ((setting = libconfig->lookup(config, "socket_configuration/ip_rules/allow_list")) == NULL) {
+ if (!imported)
+ ShowError("socket_config_read: socket_configuration/ip_rules/allow_list was not found in %s!\n", filename);
+ } else {
+ access_list_add(setting, "allow_list", &access_allow);
+ }
+
+ if ((setting = libconfig->lookup(config, "socket_configuration/ip_rules/deny_list")) == NULL) {
+ if (!imported)
+ ShowError("socket_config_read: socket_configuration/ip_rules/deny_list was not found in %s!\n", filename);
+ } else {
+ access_list_add(setting, "deny_list", &access_deny);
+ }
+#endif // ! MINICORE
+
+ return true;
+}
+
+/**
+ * Reads 'socket_configuration/ddos' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool socket_config_read_ddos(const char *filename, struct config_t *config, bool imported)
+{
+#ifndef MINICORE
+ struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "socket_configuration/ddos")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("socket_config_read: socket_configuration/ddos was not found in %s!\n", filename);
+ return false;
+ }
+
+ libconfig->setting_lookup_int(setting, "interval", &ddos_interval);
+ libconfig->setting_lookup_int(setting, "count", &ddos_count);
+ libconfig->setting_lookup_int(setting, "autoreset", &ddos_autoreset);
+
+#endif // ! MINICORE
+ return true;
+}
+
+/**
+ * Reads 'socket_configuration' and initializes required variables.
+ *
+ * @param filename Path to configuration file.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool socket_config_read(const char *filename, bool imported)
+{
+ struct config_t config;
+ struct config_setting_t *setting = NULL;
+ const char *import;
+ int i32 = 0;
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+
+ if (!libconfig->load_file(&config, filename))
+ return false;
+
+ if ((setting = libconfig->lookup(&config, "socket_configuration")) == NULL) {
+ libconfig->destroy(&config);
+ if (imported)
+ return true;
+ ShowError("socket_config_read: socket_configuration was not found in %s!\n", filename);
+ return false;
+ }
+
+ if (libconfig->setting_lookup_int(setting, "stall_time", &i32) == CONFIG_TRUE) {
+ if (i32 < 3)
+ i32 = 3; /* a minimum is required in order to refrain from killing itself */
+ sockt->stall_time = i32;
+ }
+
+#ifdef SOCKET_EPOLL
+ if (libconfig->setting_lookup_int(setting, "epoll_maxevents", &i32) == CONFIG_TRUE) {
+ if (i32 < 16)
+ i32 = 16; // minimum that seems to be useful
+ epoll_maxevents = i32;
+ }
#endif // SOCKET_EPOLL
+
#ifndef MINICORE
- else if (!strcmpi(w1, "enable_ip_rules")) {
- ip_rules = config_switch(w2);
- } else if (!strcmpi(w1, "order")) {
- if (!strcmpi(w2, "deny,allow"))
- access_order = ACO_DENY_ALLOW;
- else if (!strcmpi(w2, "allow,deny"))
- access_order = ACO_ALLOW_DENY;
- else if (!strcmpi(w2, "mutual-failure"))
- access_order = ACO_MUTUAL_FAILURE;
- } else if (!strcmpi(w1, "allow")) {
- RECREATE(access_allow, AccessControl, access_allownum+1);
- if (access_ipmask(w2, &access_allow[access_allownum]))
- ++access_allownum;
- else
- ShowError("socket_config_read: Invalid ip or ip range '%s'!\n", line);
- } else if (!strcmpi(w1, "deny")) {
- RECREATE(access_deny, AccessControl, access_denynum+1);
- if (access_ipmask(w2, &access_deny[access_denynum]))
- ++access_denynum;
- else
- ShowError("socket_config_read: Invalid ip or ip range '%s'!\n", line);
+ {
+ uint32 ui32 = 0;
+ libconfig->setting_lookup_bool(setting, "debug", &access_debug);
+ if (libconfig->setting_lookup_uint32(setting, "socket_max_client_packet", &ui32) == CONFIG_TRUE) {
+ socket_max_client_packet = ui32;
}
- else if (!strcmpi(w1,"ddos_interval"))
- ddos_interval = atoi(w2);
- else if (!strcmpi(w1,"ddos_count"))
- ddos_count = atoi(w2);
- else if (!strcmpi(w1,"ddos_autoreset"))
- ddos_autoreset = atoi(w2);
- else if (!strcmpi(w1,"debug"))
- access_debug = config_switch(w2);
- else if (!strcmpi(w1,"socket_max_client_packet"))
- socket_max_client_packet = strtoul(w2, NULL, 0);
-#endif // MINICORE
- else if (!strcmpi(w1, "import"))
- socket_config_read(w2);
- else
- ShowWarning("Unknown setting '%s' in file %s\n", w1, cfgName);
}
- fclose(fp);
- return 0;
+ if (!socket_config_read_iprules(filename, &config, imported))
+ retval = false;
+ if (!socket_config_read_ddos(filename, &config, imported))
+ retval = false;
+#endif // MINICORE
+
+ // import should overwrite any previous configuration, so it should be called last
+ if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) {
+ if (strcmp(import, filename) == 0 || strcmp(import, SOCKET_CONF_FILENAME) == 0) {
+ ShowWarning("socket_config_read: Loop detected! Skipping 'import'...\n");
+ } else {
+ if (!socket_config_read(import, true))
+ retval = false;
+ }
+ }
+
+ libconfig->destroy(&config);
+ return retval;
}
void socket_final(void)
@@ -1354,10 +1486,8 @@ void socket_final(void)
#ifndef MINICORE
if( connect_history )
db_destroy(connect_history);
- if( access_allow )
- aFree(access_allow);
- if( access_deny )
- aFree(access_deny);
+ VECTOR_CLEAR(access_allow);
+ VECTOR_CLEAR(access_deny);
#endif // MINICORE
for( i = 1; i < sockt->fd_max; i++ )
@@ -1496,7 +1626,6 @@ int socket_getips(uint32* ips, int max)
void socket_init(void)
{
- char *SOCKET_CONF_FILENAME = "conf/packet.conf";
uint64 rlim_cur = FD_SETSIZE;
#ifdef WIN32
@@ -1544,10 +1673,15 @@ void socket_init(void)
}
#endif // defined(HAVE_SETRLIMIT) && !defined(CYGWIN)
+#ifndef MINICORE
+ VECTOR_INIT(access_allow);
+ VECTOR_INIT(access_deny);
+#endif // ! MINICORE
+
// Get initial local ips
sockt->naddr_ = sockt->getips(sockt->addr_,16);
- socket_config_read(SOCKET_CONF_FILENAME);
+ socket_config_read(SOCKET_CONF_FILENAME, false);
#ifndef SOCKET_EPOLL
// Select based Event Dispatcher:
diff --git a/src/common/sql.c b/src/common/sql.c
index 9a90f9807..be0bd43e3 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -23,7 +23,9 @@
#include "sql.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/memmgr.h"
+#include "common/nullpo.h"
#include "common/showmsg.h"
#include "common/strlib.h"
#include "common/timer.h"
@@ -37,8 +39,8 @@
void hercules_mysql_error_handler(unsigned int ecode);
-int mysql_reconnect_type;
-unsigned int mysql_reconnect_count;
+int mysql_reconnect_type = 2;
+int mysql_reconnect_count = 1;
struct sql_interface sql_s;
struct sql_interface *SQL;
@@ -868,55 +870,67 @@ void hercules_mysql_error_handler(unsigned int ecode) {
switch( ecode ) {
case 2003:/* Can't connect to MySQL (this error only happens here when failing to reconnect) */
if( mysql_reconnect_type == 1 ) {
- static unsigned int retry = 1;
+ static int retry = 1;
if( ++retry > mysql_reconnect_count ) {
- ShowFatalError("MySQL has been unreachable for too long, %u reconnects were attempted. Shutting Down\n", retry);
+ ShowFatalError("MySQL has been unreachable for too long, %d reconnects were attempted. Shutting Down\n", retry);
exit(EXIT_FAILURE);
}
}
break;
}
}
-void Sql_inter_server_read(const char* cfgName, bool first) {
- char line[1024], w1[1024], w2[1024];
- FILE* fp;
-
- fp = fopen(cfgName, "r");
- if(fp == NULL) {
- if( first ) {
- ShowFatalError("File not found: %s\n", cfgName);
- exit(EXIT_FAILURE);
- } else
- ShowError("File not found: %s\n", cfgName);
- return;
+
+/**
+ * Parses mysql_reconnect from inter_configuration.
+ *
+ * @param filename Path to configuration file.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool Sql_inter_server_read(const char *filename, bool imported)
+{
+ struct config_t config;
+ const struct config_setting_t *setting = NULL;
+ const char *import = NULL;
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+
+ if (!libconfig->load_file(&config, filename))
+ return false;
+
+ if ((setting = libconfig->lookup(&config, "inter_configuration/mysql_reconnect")) == NULL) {
+ config_destroy(&config);
+ if (imported)
+ return true;
+ ShowError("Sql_inter_server_read: inter_configuration/mysql_reconnect was not found in %s!\n", filename);
+ return false;
}
- while (fgets(line, sizeof(line), fp)) {
- int i = sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2);
- if (i != 2)
- continue;
+ if (libconfig->setting_lookup_int(setting, "type", &mysql_reconnect_type) == CONFIG_TRUE) {
+ if (mysql_reconnect_type != 1 && mysql_reconnect_type != 2) {
+ ShowError("%s::inter_configuration/mysql_reconnect/type is set to %d which is not valid, defaulting to 1...\n", filename, mysql_reconnect_type);
+ mysql_reconnect_type = 1;
+ }
+ }
+ if (libconfig->setting_lookup_int(setting, "count", &mysql_reconnect_count) == CONFIG_TRUE) {
+ if (mysql_reconnect_count < 1)
+ mysql_reconnect_count = 1;
+ }
- if(!strcmpi(w1,"mysql_reconnect_type")) {
- mysql_reconnect_type = atoi(w2);
- switch( mysql_reconnect_type ) {
- case 1:
- case 2:
- break;
- default:
- ShowError("%s::mysql_reconnect_type is set to %d which is not valid, defaulting to 1...\n", cfgName, mysql_reconnect_type);
- mysql_reconnect_type = 1;
- break;
- }
- } else if(!strcmpi(w1,"mysql_reconnect_count")) {
- mysql_reconnect_count = atoi(w2);
- if( mysql_reconnect_count < 1 )
- mysql_reconnect_count = 1;
- } else if(!strcmpi(w1,"import"))
- Sql_inter_server_read(w2,false);
+ // import should overwrite any previous configuration, so it should be called last
+ if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) {
+ if (strcmp(import, filename) == 0 || strcmp(import, "conf/common/inter-server.conf") == 0) { // FIXME: Hardcoded path
+ ShowWarning("Sql_inter_server_read: Loop detected in %s! Skipping 'import'...\n", filename);
+ } else {
+ if (!Sql_inter_server_read(import, true))
+ retval = false;
+ }
}
- fclose(fp);
- return;
+ libconfig->destroy(&config);
+ return retval;
}
void Sql_HerculesUpdateCheck(struct Sql *self)
@@ -1019,7 +1033,7 @@ void Sql_HerculesUpdateSkip(struct Sql *self, const char *filename)
}
void Sql_Init(void) {
- Sql_inter_server_read("conf/inter-server.conf",true);
+ Sql_inter_server_read("conf/common/inter-server.conf", false); // FIXME: Hardcoded path
}
void sql_defaults(void) {
SQL = &sql_s;
diff --git a/src/common/sql.h b/src/common/sql.h
index 07be829fc..4d9a12cc1 100644
--- a/src/common/sql.h
+++ b/src/common/sql.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
diff --git a/src/login/account.h b/src/login/account.h
index 7e1930ad4..9bb07fda3 100644
--- a/src/login/account.h
+++ b/src/login/account.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -27,6 +27,9 @@
/* Forward declarations */
struct Sql; // common/sql.h
+/* Forward Declarations */
+struct config_t; // common/conf.h
+
typedef struct AccountDB AccountDB;
typedef struct AccountDBIterator AccountDBIterator;
@@ -107,10 +110,9 @@ struct AccountDB
/// Sets a property in this database.
///
/// @param self Database
- /// @param key Property name
- /// @param value Property value
+ /// @param config Configuration node
/// @return true if successful
- bool (*set_property)(AccountDB* self, const char* key, const char* value);
+ bool (*set_property)(AccountDB* self, struct config_t *config, bool imported);
/// Creates a new account in this database.
/// If acc->account_id is not -1, the provided value will be used.
diff --git a/src/login/account_sql.c b/src/login/account_sql.c
index 2e128e8bf..70d4f3dfb 100644
--- a/src/login/account_sql.c
+++ b/src/login/account_sql.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -24,6 +24,7 @@
#include "account.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/console.h"
#include "common/memmgr.h"
#include "common/mmo.h"
@@ -45,14 +46,7 @@ typedef struct AccountDB_SQL
struct Sql *accounts; // SQL accounts storage
- // global sql settings
- char global_db_hostname[32];
- uint16 global_db_port;
- char global_db_username[32];
- char global_db_password[100];
- char global_db_database[32];
- char global_codepage[32];
- // local sql settings
+ // Sql settings
char db_hostname[32];
uint16 db_port;
char db_username[32];
@@ -81,7 +75,7 @@ typedef struct AccountDBIterator_SQL
static bool account_db_sql_init(AccountDB* self);
static void account_db_sql_destroy(AccountDB* self);
static bool account_db_sql_get_property(AccountDB* self, const char* key, char* buf, size_t buflen);
-static bool account_db_sql_set_property(AccountDB* self, const char* option, const char* value);
+static bool account_db_sql_set_property(AccountDB* self, struct config_t *config, bool imported);
static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc);
static bool account_db_sql_remove(AccountDB* self, const int account_id);
static bool account_db_sql_save(AccountDB* self, const struct mmo_account* acc);
@@ -113,19 +107,12 @@ AccountDB* account_db_sql(void)
// initialize to default values
db->accounts = NULL;
- // global sql settings
- safestrncpy(db->global_db_hostname, "127.0.0.1", sizeof(db->global_db_hostname));
- db->global_db_port = 3306;
- safestrncpy(db->global_db_username, "ragnarok", sizeof(db->global_db_username));
- safestrncpy(db->global_db_password, "ragnarok", sizeof(db->global_db_password));
- safestrncpy(db->global_db_database, "ragnarok", sizeof(db->global_db_database));
- safestrncpy(db->global_codepage, "", sizeof(db->global_codepage));
- // local sql settings
- safestrncpy(db->db_hostname, "", sizeof(db->db_hostname));
+ // Sql settings
+ safestrncpy(db->db_hostname, "127.0.0.1", sizeof(db->db_hostname));
db->db_port = 3306;
- safestrncpy(db->db_username, "", sizeof(db->db_username));
- safestrncpy(db->db_password, "", sizeof(db->db_password));
- safestrncpy(db->db_database, "", sizeof(db->db_database));
+ safestrncpy(db->db_username, "ragnarok", sizeof(db->db_username));
+ safestrncpy(db->db_password, "ragnarok", sizeof(db->db_password));
+ safestrncpy(db->db_database, "ragnarok", sizeof(db->db_database));
safestrncpy(db->codepage, "", sizeof(db->codepage));
// other settings
db->case_sensitive = false;
@@ -144,46 +131,22 @@ AccountDB* account_db_sql(void)
static bool account_db_sql_init(AccountDB* self)
{
AccountDB_SQL* db = (AccountDB_SQL*)self;
- struct Sql *sql_handle;
- const char* username;
- const char* password;
- const char* hostname;
- uint16 port;
- const char* database;
- const char* codepage;
+ struct Sql *sql_handle = NULL;
nullpo_ret(db);
+
db->accounts = SQL->Malloc();
sql_handle = db->accounts;
- if( db->db_hostname[0] != '\0' )
- {// local settings
- username = db->db_username;
- password = db->db_password;
- hostname = db->db_hostname;
- port = db->db_port;
- database = db->db_database;
- codepage = db->codepage;
- }
- else
- {// global settings
- username = db->global_db_username;
- password = db->global_db_password;
- hostname = db->global_db_hostname;
- port = db->global_db_port;
- database = db->global_db_database;
- codepage = db->global_codepage;
- }
-
- if( SQL_ERROR == SQL->Connect(sql_handle, username, password, hostname, port, database) )
- {
+ if (SQL_ERROR == SQL->Connect(sql_handle, db->db_username, db->db_password,
+ db->db_hostname, db->db_port, db->db_database)) {
Sql_ShowDebug(sql_handle);
SQL->Free(db->accounts);
db->accounts = NULL;
return false;
}
- if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) )
+ if (db->codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, db->codepage))
Sql_ShowDebug(sql_handle);
Sql_HerculesUpdateCheck(db->accounts);
@@ -207,6 +170,15 @@ static void account_db_sql_destroy(AccountDB* self)
/// Gets a property from this database.
static bool account_db_sql_get_property(AccountDB* self, const char* key, char* buf, size_t buflen)
{
+ /* TODO:
+ * This functionality is not being used as of now, it was removed in
+ * commit 5479f9631f8579d03fbfd14d8a49c7976226a156, it is meant to get
+ * engine properties when more than one engine is available. I'll
+ * re-add it as soon as I can, following the new standards. If anyone
+ * is interested in this functionality you can contact me in our boards
+ * and I'll try to add it sooner (Pan) [Panikon]
+ */
+#if 0
AccountDB_SQL* db = (AccountDB_SQL*)self;
const char* signature;
@@ -230,32 +202,6 @@ static bool account_db_sql_get_property(AccountDB* self, const char* key, char*
return true;
}
- signature = "sql.";
- if( strncmpi(key, signature, strlen(signature)) == 0 )
- {
- key += strlen(signature);
- if( strcmpi(key, "db_hostname") == 0 )
- safesnprintf(buf, buflen, "%s", db->global_db_hostname);
- else
- if( strcmpi(key, "db_port") == 0 )
- safesnprintf(buf, buflen, "%d", db->global_db_port);
- else
- if( strcmpi(key, "db_username") == 0 )
- safesnprintf(buf, buflen, "%s", db->global_db_username);
- else
- if( strcmpi(key, "db_password") == 0 )
- safesnprintf(buf, buflen, "%s", db->global_db_password);
- else
- if( strcmpi(key, "db_database") == 0 )
- safesnprintf(buf, buflen, "%s", db->global_db_database);
- else
- if( strcmpi(key, "codepage") == 0 )
- safesnprintf(buf, buflen, "%s", db->global_codepage);
- else
- return false;// not found
- return true;
- }
-
signature = "account.sql.";
if( strncmpi(key, signature, strlen(signature)) == 0 )
{
@@ -295,82 +241,91 @@ static bool account_db_sql_get_property(AccountDB* self, const char* key, char*
}
return false;// not found
+#endif // 0
+ return false;
}
-/// if the option is supported, adjusts the internal state
-static bool account_db_sql_set_property(AccountDB* self, const char* key, const char* value)
+/**
+ * Reads the 'inter_configuration' config file and initializes required variables.
+ *
+ * @param db Self.
+ * @param filename Path to configuration file
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool account_db_read_inter(AccountDB_SQL *db, const char *filename, bool imported)
+{
+ struct config_t config;
+ struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, db);
+ nullpo_retr(false, filename);
+
+ if (!libconfig->load_file(&config, filename))
+ return false; // Error message is already shown by libconfig->load_file
+
+ if ((setting = libconfig->lookup(&config, "inter_configuration/database_names")) == NULL) {
+ libconfig->destroy(&config);
+ if (imported)
+ return true;
+ ShowError("account_db_sql_set_property: inter_configuration/database_names was not found!\n");
+ return false;
+ }
+ libconfig->setting_lookup_mutable_string(setting, "account_db", db->account_db, sizeof(db->account_db));
+
+ if ((setting = libconfig->lookup(&config, "inter_configuration/database_names/registry")) == NULL) {
+ libconfig->destroy(&config);
+ if (imported)
+ return true;
+ ShowError("account_db_sql_set_property: inter_configuration/database_names/registry was not found!\n");
+ return false;
+ }
+ libconfig->setting_lookup_mutable_string(setting, "global_acc_reg_str_db", db->global_acc_reg_str_db, sizeof(db->global_acc_reg_str_db));
+ libconfig->setting_lookup_mutable_string(setting, "global_acc_reg_num_db", db->global_acc_reg_num_db, sizeof(db->global_acc_reg_num_db));
+
+ // TODO: Proper import mechanism for this file
+
+ libconfig->destroy(&config);
+ return true;
+}
+
+/**
+ * Loads the sql configuration.
+ *
+ * @param self Self.
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+static bool account_db_sql_set_property(AccountDB* self, struct config_t *config, bool imported)
{
AccountDB_SQL* db = (AccountDB_SQL*)self;
- const char* signature;
+ struct config_setting_t *setting = NULL;
nullpo_ret(db);
- nullpo_ret(key);
- nullpo_ret(value);
- signature = "sql.";
- if( strncmp(key, signature, strlen(signature)) == 0 )
- {
- key += strlen(signature);
- if( strcmpi(key, "db_hostname") == 0 )
- safestrncpy(db->global_db_hostname, value, sizeof(db->global_db_hostname));
- else
- if( strcmpi(key, "db_port") == 0 )
- db->global_db_port = (uint16)strtoul(value, NULL, 10);
- else
- if( strcmpi(key, "db_username") == 0 )
- safestrncpy(db->global_db_username, value, sizeof(db->global_db_username));
- else
- if( strcmpi(key, "db_password") == 0 )
- safestrncpy(db->global_db_password, value, sizeof(db->global_db_password));
- else
- if( strcmpi(key, "db_database") == 0 )
- safestrncpy(db->global_db_database, value, sizeof(db->global_db_database));
- else
- if( strcmpi(key, "codepage") == 0 )
- safestrncpy(db->global_codepage, value, sizeof(db->global_codepage));
- else
- return false;// not found
- return true;
- }
+ nullpo_ret(config);
- signature = "account.sql.";
- if( strncmp(key, signature, strlen(signature)) == 0 )
- {
- key += strlen(signature);
- if( strcmpi(key, "db_hostname") == 0 )
- safestrncpy(db->db_hostname, value, sizeof(db->db_hostname));
- else
- if( strcmpi(key, "db_port") == 0 )
- db->db_port = (uint16)strtoul(value, NULL, 10);
- else
- if( strcmpi(key, "db_username") == 0 )
- safestrncpy(db->db_username, value, sizeof(db->db_username));
- else
- if( strcmpi(key, "db_password") == 0 )
- safestrncpy(db->db_password, value, sizeof(db->db_password));
- else
- if( strcmpi(key, "db_database") == 0 )
- safestrncpy(db->db_database, value, sizeof(db->db_database));
- else
- if( strcmpi(key, "codepage") == 0 )
- safestrncpy(db->codepage, value, sizeof(db->codepage));
- else
- if( strcmpi(key, "case_sensitive") == 0 )
- db->case_sensitive = (bool)config_switch(value);
- else
- if( strcmpi(key, "account_db") == 0 )
- safestrncpy(db->account_db, value, sizeof(db->account_db));
- else
- if( strcmpi(key, "global_acc_reg_str_db") == 0 )
- safestrncpy(db->global_acc_reg_str_db, value, sizeof(db->global_acc_reg_str_db));
- else
- if( strcmpi(key, "global_acc_reg_num_db") == 0 )
- safestrncpy(db->global_acc_reg_num_db, value, sizeof(db->global_acc_reg_num_db));
- else
- return false;// not found
- return true;
+ if ((setting = libconfig->lookup(config, "login_configuration/account/sql_connection")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("account_db_sql_set_property: login_configuration/account/sql_connection was not found!\n");
+ ShowWarning("account_db_sql_set_property: Defaulting sql_connection...\n");
+ return false;
}
- return false;// not found
+ libconfig->setting_lookup_mutable_string(setting, "db_hostname", db->db_hostname, sizeof(db->db_hostname));
+ libconfig->setting_lookup_mutable_string(setting, "db_username", db->db_username, sizeof(db->db_username));
+ libconfig->setting_lookup_mutable_string(setting, "db_password", db->db_password, sizeof(db->db_password));
+ libconfig->setting_lookup_mutable_string(setting, "db_database", db->db_database, sizeof(db->db_database));
+ libconfig->setting_lookup_mutable_string(setting, "codepage", db->codepage, sizeof(db->codepage)); // FIXME: Why do we need both codepage and default_codepage?
+ libconfig->setting_lookup_uint16(setting, "db_port", &db->db_port);
+ libconfig->setting_lookup_bool_real(setting, "case_sensitive", &db->case_sensitive);
+
+ account_db_read_inter(db, "conf/common/inter-server.conf", imported);
+
+ return true;
}
/// create a new account entry
diff --git a/src/login/ipban.h b/src/login/ipban.h
index 85cf3873c..104e3a8a3 100644
--- a/src/login/ipban.h
+++ b/src/login/ipban.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -23,6 +23,9 @@
#include "common/cbasetypes.h"
+/* Forward Declarations */
+struct config_t; // common/conf.h
+
#ifdef HERCULES_CORE
// TODO: Interface
// initialize
@@ -37,8 +40,8 @@ bool ipban_check(uint32 ip);
// increases failure count for the specified IP
void ipban_log(uint32 ip);
-// parses configuration option
-bool ipban_config_read(const char *key, const char* value);
+// parses configuration options
+bool ipban_config_read(const char *filename, struct config_t *config, bool imported);
#endif // HERCULES_CORE
#endif /* LOGIN_IPBAN_H */
diff --git a/src/login/ipban_sql.c b/src/login/ipban_sql.c
index bec0217f4..d74e6c4fa 100644
--- a/src/login/ipban_sql.c
+++ b/src/login/ipban_sql.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -25,26 +25,21 @@
#include "login/login.h"
#include "login/loginlog.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/nullpo.h"
+#include "common/showmsg.h"
#include "common/sql.h"
#include "common/strlib.h"
#include "common/timer.h"
#include <stdlib.h>
-// global sql settings
-static char global_db_hostname[32] = "127.0.0.1";
-static uint16 global_db_port = 3306;
-static char global_db_username[32] = "ragnarok";
-static char global_db_password[100] = "ragnarok";
-static char global_db_database[32] = "ragnarok";
-static char global_codepage[32] = "";
-// local sql settings
-static char ipban_db_hostname[32] = "";
-static uint16 ipban_db_port = 0;
-static char ipban_db_username[32] = "";
-static char ipban_db_password[100] = "";
-static char ipban_db_database[32] = "";
+// Sql settings
+static char ipban_db_hostname[32] = "127.0.0.1";
+static uint16 ipban_db_port = 3306;
+static char ipban_db_username[32] = "ragnarok";
+static char ipban_db_password[100] = "ragnarok";
+static char ipban_db_database[32] = "ragnarok";
static char ipban_codepage[32] = "";
static char ipban_table[32] = "ipbanlist";
@@ -59,54 +54,30 @@ int ipban_cleanup(int tid, int64 tick, int id, intptr_t data);
// initialize
void ipban_init(void)
{
- const char* username;
- const char* password;
- const char* hostname;
- uint16 port;
- const char* database;
- const char* codepage;
-
ipban_inited = true;
if (!login->config->ipban)
return;// ipban disabled
- if( ipban_db_hostname[0] != '\0' )
- {// local settings
- username = ipban_db_username;
- password = ipban_db_password;
- hostname = ipban_db_hostname;
- port = ipban_db_port;
- database = ipban_db_database;
- codepage = ipban_codepage;
- }
- else
- {// global settings
- username = global_db_username;
- password = global_db_password;
- hostname = global_db_hostname;
- port = global_db_port;
- database = global_db_database;
- codepage = global_codepage;
- }
-
// establish connections
sql_handle = SQL->Malloc();
- if( SQL_ERROR == SQL->Connect(sql_handle, username, password, hostname, port, database) )
- {
+ if (SQL_ERROR == SQL->Connect(sql_handle, ipban_db_username, ipban_db_password,
+ ipban_db_hostname, ipban_db_port, ipban_db_database)) {
Sql_ShowDebug(sql_handle);
SQL->Free(sql_handle);
exit(EXIT_FAILURE);
}
- if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) )
+ if (ipban_codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, ipban_codepage))
Sql_ShowDebug(sql_handle);
- if (login->config->ipban_cleanup_interval > 0)
- { // set up periodic cleanup of connection history and active bans
+ if (login->config->ipban_cleanup_interval > 0) {
+ // set up periodic cleanup of connection history and active bans
timer->add_func_list(ipban_cleanup, "ipban_cleanup");
cleanup_timer_id = timer->add_interval(timer->gettick()+10, ipban_cleanup, 0, 0, login->config->ipban_cleanup_interval*1000);
- } else // make sure it gets cleaned up on login-server start regardless of interval-based cleanups
+ } else {
+ // make sure it gets cleaned up on login-server start regardless of interval-based cleanups
ipban_cleanup(0,0,0,0);
+ }
}
// finalize
@@ -126,95 +97,153 @@ void ipban_final(void)
sql_handle = NULL;
}
-// load configuration options
-bool ipban_config_read(const char* key, const char* value)
+/**
+ * Reads 'inter_configuration' and initializes required variables/Sets global
+ * configuration.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+
+ */
+bool ipban_config_read_inter(const char *filename, bool imported)
{
- const char* signature;
+ struct config_t config;
+ struct config_setting_t *setting = NULL;
+ const char *import = NULL;
+ bool retval = true;
- nullpo_ret(key);
- nullpo_ret(value);
- if( ipban_inited )
- return false;// settings can only be changed before init
+ nullpo_retr(false, filename);
- signature = "sql.";
- if( strncmpi(key, signature, strlen(signature)) == 0 )
- {
- key += strlen(signature);
- if( strcmpi(key, "db_hostname") == 0 )
- safestrncpy(global_db_hostname, value, sizeof(global_db_hostname));
- else
- if( strcmpi(key, "db_port") == 0 )
- global_db_port = (uint16)strtoul(value, NULL, 10);
- else
- if( strcmpi(key, "db_username") == 0 )
- safestrncpy(global_db_username, value, sizeof(global_db_username));
- else
- if( strcmpi(key, "db_password") == 0 )
- safestrncpy(global_db_password, value, sizeof(global_db_password));
- else
- if( strcmpi(key, "db_database") == 0 )
- safestrncpy(global_db_database, value, sizeof(global_db_database));
- else
- if( strcmpi(key, "codepage") == 0 )
- safestrncpy(global_codepage, value, sizeof(global_codepage));
- else
- return false;// not found
- return true;
+ if (!libconfig->load_file(&config, filename))
+ return false; // Error message is already shown by libconfig->read_file
+
+ if ((setting = libconfig->lookup(&config, "inter_configuration/database_names")) == NULL) {
+ libconfig->destroy(&config);
+ if (imported)
+ return true;
+ ShowError("ipban_config_read: inter_configuration/database_names was not found!\n");
+ return false;
+ }
+ libconfig->setting_lookup_mutable_string(setting, "ipban_table", ipban_table, sizeof(ipban_table));
+
+ // import should overwrite any previous configuration, so it should be called last
+ if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) {
+ if (strcmp(import, filename) == 0 || strcmp(import, "conf/common/inter-server.conf") == 0) {
+ ShowWarning("ipban_config_read_inter: Loop detected! Skipping 'import'...\n");
+ } else {
+ if (!ipban_config_read_inter(import, true))
+ retval = false;
+ }
}
- signature = "ipban.sql.";
- if( strncmpi(key, signature, strlen(signature)) == 0 )
- {
- key += strlen(signature);
- if( strcmpi(key, "db_hostname") == 0 )
- safestrncpy(ipban_db_hostname, value, sizeof(ipban_db_hostname));
- else
- if( strcmpi(key, "db_port") == 0 )
- ipban_db_port = (uint16)strtoul(value, NULL, 10);
- else
- if( strcmpi(key, "db_username") == 0 )
- safestrncpy(ipban_db_username, value, sizeof(ipban_db_username));
- else
- if( strcmpi(key, "db_password") == 0 )
- safestrncpy(ipban_db_password, value, sizeof(ipban_db_password));
- else
- if( strcmpi(key, "db_database") == 0 )
- safestrncpy(ipban_db_database, value, sizeof(ipban_db_database));
- else
- if( strcmpi(key, "codepage") == 0 )
- safestrncpy(ipban_codepage, value, sizeof(ipban_codepage));
- else
- if( strcmpi(key, "ipban_table") == 0 )
- safestrncpy(ipban_table, value, sizeof(ipban_table));
- else
- return false;// not found
- return true;
+ libconfig->destroy(&config);
+ return retval;
+}
+
+/**
+ * Reads login_configuration/account/ipban/sql_connection and loads configuration options.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool ipban_config_read_connection(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "login_configuration/account/ipban/sql_connection")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("account_db_sql_set_property: login_configuration/account/ipban/sql_connection was not found in %s!\n", filename);
+ return false;
}
- signature = "ipban.";
- if( strncmpi(key, signature, strlen(signature)) == 0 )
- {
- key += strlen(signature);
- if( strcmpi(key, "enable") == 0 )
- login->config->ipban = (bool)config_switch(value);
- else
- if( strcmpi(key, "dynamic_pass_failure_ban") == 0 )
- login->config->dynamic_pass_failure_ban = (bool)config_switch(value);
- else
- if( strcmpi(key, "dynamic_pass_failure_ban_interval") == 0 )
- login->config->dynamic_pass_failure_ban_interval = atoi(value);
- else
- if( strcmpi(key, "dynamic_pass_failure_ban_limit") == 0 )
- login->config->dynamic_pass_failure_ban_limit = atoi(value);
- else
- if( strcmpi(key, "dynamic_pass_failure_ban_duration") == 0 )
- login->config->dynamic_pass_failure_ban_duration = atoi(value);
- else
- return false;// not found
- return true;
+ libconfig->setting_lookup_mutable_string(setting, "db_hostname", ipban_db_hostname, sizeof(ipban_db_hostname));
+ libconfig->setting_lookup_mutable_string(setting, "db_database", ipban_db_database, sizeof(ipban_db_database));
+
+ libconfig->setting_lookup_mutable_string(setting, "db_username", ipban_db_username, sizeof(ipban_db_username));
+ libconfig->setting_lookup_mutable_string(setting, "db_password", ipban_db_password, sizeof(ipban_db_password));
+ libconfig->setting_lookup_mutable_string(setting, "codepage", ipban_codepage, sizeof(ipban_codepage));
+ libconfig->setting_lookup_uint16(setting, "db_port", &ipban_db_port);
+
+ return true;
+}
+
+/**
+ * Reads login_configuration/account/ipban/dynamic_pass_failure and loads configuration options.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool ipban_config_read_dynamic(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "login_configuration/account/ipban/dynamic_pass_failure")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("account_db_sql_set_property: login_configuration/account/ipban/dynamic_pass_failure was not found in %s!\n", filename);
+ return false;
+ }
+
+ libconfig->setting_lookup_bool_real(setting, "enabled", &login->config->dynamic_pass_failure_ban);
+ libconfig->setting_lookup_uint32(setting, "ban_interval", &login->config->dynamic_pass_failure_ban_interval);
+ libconfig->setting_lookup_uint32(setting, "ban_limit", &login->config->dynamic_pass_failure_ban_limit);
+ libconfig->setting_lookup_uint32(setting, "ban_duration", &login->config->dynamic_pass_failure_ban_duration);
+
+ return true;
+}
+
+/**
+ * Reads login_configuration.account.ipban and loads configuration options.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool ipban_config_read(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if (ipban_inited)
+ return false; // settings can only be changed before init
+
+ if ((setting = libconfig->lookup(config, "login_configuration/account/ipban")) == NULL) {
+ if (!imported)
+ ShowError("login_config_read: login_configuration/log was not found in %s!\n", filename);
+ return false;
}
- return false;// not found
+ libconfig->setting_lookup_bool_real(setting, "enabled", &login->config->ipban);
+ libconfig->setting_lookup_uint32(setting, "cleanup_interval", &login->config->ipban_cleanup_interval);
+
+ if (!ipban_config_read_inter("conf/common/inter-server.conf", imported))
+ retval = false;
+ if (!ipban_config_read_connection(filename, config, imported))
+ retval = false;
+ if (!ipban_config_read_dynamic(filename, config, imported))
+ retval = false;
+
+ return retval;
}
// check ip against active bans list
diff --git a/src/login/login.c b/src/login/login.c
index 6b422eef2..19293d61b 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -29,6 +29,7 @@
#include "login/lclif.h"
#include "common/HPM.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/core.h"
#include "common/db.h"
#include "common/memmgr.h"
@@ -43,6 +44,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <sys/stat.h> // stat()
/** @file
* Implementation of the login interface.
@@ -1064,13 +1066,14 @@ int login_mmo_auth(struct login_session_data* sd, bool isServer) {
if (login->config->use_dnsbl) {
char r_ip[16];
char ip_dnsbl[256];
- char* dnsbl_serv;
uint8* sin_addr = (uint8*)&sockt->session[sd->fd]->client_addr;
+ int i;
sprintf(r_ip, "%u.%u.%u.%u", sin_addr[0], sin_addr[1], sin_addr[2], sin_addr[3]);
- for (dnsbl_serv = strtok(login->config->dnsbl_servs,","); dnsbl_serv != NULL; dnsbl_serv = strtok(NULL,",")) {
- sprintf(ip_dnsbl, "%s.%s", r_ip, trim(dnsbl_serv));
+ for (i = 0; i < VECTOR_LENGTH(login->config->dnsbl_servers); i++) {
+ char *dnsbl_server = VECTOR_INDEX(login->config->dnsbl_servers, i);
+ sprintf(ip_dnsbl, "%s.%s", r_ip, trim(dnsbl_server));
if (sockt->host2ip(ip_dnsbl)) {
ShowInfo("DNSBL: (%s) Blacklisted. User Kicked.\n", r_ip);
return 3;
@@ -1450,150 +1453,431 @@ void login_config_set_defaults(void)
login->config->dynamic_pass_failure_ban_limit = 7;
login->config->dynamic_pass_failure_ban_duration = 5;
login->config->use_dnsbl = false;
- safestrncpy(login->config->dnsbl_servs, "", sizeof(login->config->dnsbl_servs));
+ VECTOR_INIT(login->config->dnsbl_servers);
login->config->client_hash_check = 0;
login->config->client_hash_nodes = NULL;
}
-//-----------------------------------
-// Reading main configuration file
-//-----------------------------------
-int login_config_read(const char *cfgName)
+/**
+ * Reads 'login_configuration/inter' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool login_config_read_inter(const char *filename, struct config_t *config, bool imported)
{
- char line[1024], w1[1024], w2[1024];
- FILE* fp;
- nullpo_retr(1, cfgName);
- fp = fopen(cfgName, "r");
- if (fp == NULL) {
- ShowError("Configuration file (%s) not found.\n", cfgName);
- return 1;
+ struct config_setting_t *setting = NULL;
+ const char *str = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "login_configuration/inter")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("login_config_read: login_configuration/inter was not found in %s!\n", filename);
+ return false;
}
- while(fgets(line, sizeof(line), fp)) {
- if (line[0] == '/' && line[1] == '/')
- continue;
- if (sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) < 2)
+ libconfig->setting_lookup_uint16(setting, "login_port", &login->config->login_port);
+
+ if (libconfig->setting_lookup_uint32(setting, "ip_sync_interval", &login->config->ip_sync_interval) == CONFIG_TRUE)
+ login->config->ip_sync_interval *= 1000*60; // In minutes
+
+ if (libconfig->setting_lookup_string(setting, "bind_ip", &str) == CONFIG_TRUE) {
+ char old_ip_str[16];
+ sockt->ip2str(login->config->login_ip, old_ip_str);
+
+ if ((login->config->login_ip = sockt->host2ip(str)) != 0)
+ ShowStatus("Login server binding IP address : %s -> %s\n", old_ip_str, str);
+ }
+
+ return true;
+}
+
+/**
+ * Reads 'login_configuration.console' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool login_config_read_console(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "login_configuration/console")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("login_config_read: login_configuration/console was not found in %s!\n", filename);
+ return false;
+ }
+
+ libconfig->setting_lookup_bool_real(setting, "stdout_with_ansisequence", &showmsg->stdout_with_ansisequence);
+ if (libconfig->setting_lookup_int(setting, "console_silent", &showmsg->silent) == CONFIG_TRUE) {
+ if (showmsg->silent) // only bother if its actually enabled
+ ShowInfo("Console Silent Setting: %d\n", showmsg->silent);
+ }
+ libconfig->setting_lookup_mutable_string(setting, "timestamp_format", showmsg->timestamp_format, sizeof(showmsg->timestamp_format));
+
+ return true;
+}
+
+/**
+ * Reads 'login_configuration.log' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool login_config_read_log(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "login_configuration/log")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("login_config_read: login_configuration/log was not found in %s!\n", filename);
+ return false;
+ }
+
+ libconfig->setting_lookup_bool_real(setting, "log_login", &login->config->log_login);
+ libconfig->setting_lookup_mutable_string(setting, "date_format", login->config->date_format, sizeof(login->config->date_format));
+ return true;
+}
+
+/**
+ * Reads 'login_configuration.account' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool login_config_read_account(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+ AccountDB *db = account_engine[0].db;
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "login_configuration/account")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("login_config_read: login_configuration/account was not found in %s!\n", filename);
+ return false;
+ }
+
+ libconfig->setting_lookup_bool_real(setting, "new_account", &login->config->new_account_flag);
+ libconfig->setting_lookup_bool_real(setting, "new_acc_length_limit", &login->config->new_acc_length_limit);
+
+ libconfig->setting_lookup_int(setting, "allowed_regs", &login->config->allowed_regs);
+ libconfig->setting_lookup_int(setting, "time_allowed", &login->config->time_allowed);
+ libconfig->setting_lookup_int(setting, "start_limited_time", &login->config->start_limited_time);
+ libconfig->setting_lookup_bool_real(setting, "use_MD5_passwords", &login->config->use_md5_passwds);
+
+ if (!db->set_property(db, config, imported))
+ retval = false;
+ if (!ipban_config_read(filename, config, imported))
+ retval = false;
+
+ return retval;
+}
+
+/**
+ * Frees login->config->client_hash_nodes
+ **/
+void clear_client_hash_nodes(void)
+{
+ struct client_hash_node *node = login->config->client_hash_nodes;
+
+ while (node != NULL) {
+ struct client_hash_node *next = node->next;
+ aFree(node);
+ node = next;
+ }
+
+ login->config->client_hash_nodes = NULL;
+}
+
+/**
+ * Reads information from login_configuration.permission.hash.md5_hashes.
+ *
+ * @param setting The setting to read from.
+ */
+void login_config_set_md5hash(struct config_setting_t *setting)
+{
+ int i;
+ int count = libconfig->setting_length(setting);
+
+ clear_client_hash_nodes();
+
+ // There's no need to parse if it's disabled or if there's no list
+ if (count <= 0 || !login->config->client_hash_check)
+ return;
+
+ for (i = 0; i < count; i++) {
+ int j;
+ int group_id = 0;
+ char md5hash[33];
+ struct client_hash_node *nnode = NULL;
+ struct config_setting_t *item = libconfig->setting_get_elem(setting, i);
+
+ if (item == NULL)
continue;
- if(!strcmpi(w1,"timestamp_format"))
- safestrncpy(showmsg->timestamp_format, w2, 20);
- else if(!strcmpi(w1,"stdout_with_ansisequence"))
- showmsg->stdout_with_ansisequence = config_switch(w2) ? true : false;
- else if(!strcmpi(w1,"console_silent")) {
- showmsg->silent = atoi(w2);
- if (showmsg->silent) /* only bother if we actually have this enabled */
- ShowInfo("Console Silent Setting: %d\n", atoi(w2));
- }
- else if( !strcmpi(w1, "bind_ip") ) {
- login->config->login_ip = sockt->host2ip(w2);
- if (login->config->login_ip) {
- char ip_str[16];
- ShowStatus("Login server binding IP address : %s -> %s\n", w2, sockt->ip2str(login->config->login_ip, ip_str));
- }
+ if (libconfig->setting_lookup_int(item, "group_id", &group_id) != CONFIG_TRUE) {
+ ShowWarning("login_config_set_md5hash: entry (%d) is missing group_id! Ignoring...\n", i);
+ continue;
}
- else if( !strcmpi(w1, "login_port") ) {
- login->config->login_port = (uint16)atoi(w2);
+
+ if (libconfig->setting_lookup_mutable_string(item, "hash", md5hash, sizeof(md5hash)) != CONFIG_TRUE) {
+ ShowWarning("login_config_set_md5hash: entry (%d) is missing hash! Ignoring...\n", i);
+ continue;
}
- else if(!strcmpi(w1, "log_login"))
- login->config->log_login = (bool)config_switch(w2);
-
- else if(!strcmpi(w1, "new_account"))
- login->config->new_account_flag = (bool)config_switch(w2);
- else if(!strcmpi(w1, "new_acc_length_limit"))
- login->config->new_acc_length_limit = (bool)config_switch(w2);
- else if(!strcmpi(w1, "start_limited_time"))
- login->config->start_limited_time = atoi(w2);
- else if(!strcmpi(w1, "check_client_version"))
- login->config->check_client_version = (bool)config_switch(w2);
- else if(!strcmpi(w1, "client_version_to_connect"))
- login->config->client_version_to_connect = (unsigned int)strtoul(w2, NULL, 10);
- else if(!strcmpi(w1, "use_MD5_passwords"))
- login->config->use_md5_passwds = (bool)config_switch(w2);
- else if(!strcmpi(w1, "group_id_to_connect"))
- login->config->group_id_to_connect = atoi(w2);
- else if(!strcmpi(w1, "min_group_id_to_connect"))
- login->config->min_group_id_to_connect = atoi(w2);
- else if(!strcmpi(w1, "date_format"))
- safestrncpy(login->config->date_format, w2, sizeof(login->config->date_format));
- else if(!strcmpi(w1, "allowed_regs")) //account flood protection system
- login->config->allowed_regs = atoi(w2);
- else if(!strcmpi(w1, "time_allowed"))
- login->config->time_allowed = atoi(w2);
- else if(!strcmpi(w1, "use_dnsbl"))
- login->config->use_dnsbl = (bool)config_switch(w2);
- else if(!strcmpi(w1, "dnsbl_servers"))
- safestrncpy(login->config->dnsbl_servs, w2, sizeof(login->config->dnsbl_servs));
- else if(!strcmpi(w1, "ipban_cleanup_interval"))
- login->config->ipban_cleanup_interval = (unsigned int)atoi(w2);
- else if(!strcmpi(w1, "ip_sync_interval"))
- login->config->ip_sync_interval = (unsigned int)1000*60*atoi(w2); //w2 comes in minutes.
- else if(!strcmpi(w1, "client_hash_check"))
- login->config->client_hash_check = config_switch(w2);
- else if(!strcmpi(w1, "client_hash")) {
- int group = 0;
- char md5hash[33];
- memset(md5hash, '\0', 33);
-
- if (sscanf(w2, "%d, %32s", &group, md5hash) == 2) {
- struct client_hash_node *nnode;
- CREATE(nnode, struct client_hash_node, 1);
-
- if (strcmpi(md5hash, "disabled") == 0) {
- nnode->hash[0] = '\0';
- } else {
- int i;
- for (i = 0; i < 32; i += 2) {
- char buf[3];
- unsigned int byte;
-
- memcpy(buf, &md5hash[i], 2);
- buf[2] = 0;
-
- sscanf(buf, "%x", &byte);
- nnode->hash[i / 2] = (uint8)(byte & 0xFF);
- }
- }
-
- nnode->group_id = group;
- nnode->next = login->config->client_hash_nodes;
-
- login->config->client_hash_nodes = nnode;
+
+ CREATE(nnode, struct client_hash_node, 1);
+ if (strcmpi(md5hash, "disabled") == 0) {
+ nnode->hash[0] = '\0';
+ } else {
+ for (j = 0; j < 32; j += 2) {
+ char buf[3];
+ unsigned int byte;
+
+ memcpy(buf, &md5hash[j], 2);
+ buf[2] = 0;
+
+ sscanf(buf, "%x", &byte);
+ nnode->hash[j / 2] = (uint8)(byte & 0xFF);
}
}
- else if(!strcmpi(w1, "import"))
- login_config_read(w2);
- else
- {
- AccountDB* db = account_engine[0].db;
- if (db)
- db->set_property(db, w1, w2);
- ipban_config_read(w1, w2);
- loginlog_config_read(w1, w2);
- HPM->parseConf(w1, w2, HPCT_LOGIN);
+ nnode->group_id = group_id;
+ nnode->next = login->config->client_hash_nodes; // login->config->client_hash_nodes is initialized before calling this function
+ login->config->client_hash_nodes = nnode;
+ }
+
+ return;
+}
+
+/**
+ * Reads 'login_configuration/permission/hash' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool login_config_read_permission_hash(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "login_configuration/permission/hash")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("login_config_read: login_configuration/permission/hash was not found in %s!\n", filename);
+ return false;
+ }
+
+ libconfig->setting_lookup_bool_real(setting, "enabled", &login->config->client_hash_check);
+
+ if ((setting = libconfig->lookup(config, "login_configuration/permission/hash/MD5_hashes")) != NULL)
+ login_config_set_md5hash(setting);
+
+ return true;
+}
+
+/**
+ * Clears login->config->dnsbl_servers, freeing any allocated memory.
+ */
+void clear_dnsbl_servers(void)
+{
+ while (VECTOR_LENGTH(login->config->dnsbl_servers) > 0) {
+ aFree(&VECTOR_POP(login->config->dnsbl_servers));
+ }
+ VECTOR_CLEAR(login->config->dnsbl_servers);
+}
+
+/**
+ * Reads information from login_config/permission/DNS_blacklist/dnsbl_servers.
+ *
+ * @param setting The configuration setting to read from.
+ */
+void login_config_set_dnsbl_servers(struct config_setting_t *setting)
+{
+ int i;
+ int count = libconfig->setting_length(setting);
+
+ clear_dnsbl_servers();
+
+ // There's no need to parse if it's disabled
+ if (count <= 0 || !login->config->use_dnsbl)
+ return;
+
+ VECTOR_ENSURE(login->config->dnsbl_servers, count, 1);
+
+ for (i = 0; i < count; i++) {
+ const char *string = libconfig->setting_get_string_elem(setting, i);
+
+ if (string == NULL || string[0] == '\0')
+ continue;
+
+ VECTOR_PUSH(login->config->dnsbl_servers, aStrdup(string));
+ }
+}
+
+/**
+ * Reads 'login_configuration/permission/DNS_blacklist' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool login_config_read_permission_blacklist(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "login_configuration/permission/DNS_blacklist")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("login_config_read: login_configuration/permission/DNS_blacklist was not found in %s!\n", filename);
+ return false;
+ }
+
+ libconfig->setting_lookup_bool_real(setting, "enabled", &login->config->use_dnsbl);
+
+ if ((setting = libconfig->lookup(config, "login_configuration/permission/DNS_blacklist/dnsbl_servers")) != NULL)
+ login_config_set_dnsbl_servers(setting);
+
+ return true;
+}
+
+/**
+ * Reads 'login_configuration.permission' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool login_config_read_permission(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "login_configuration/permission")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("login_config_read: login_configuration/permission was not found in %s!\n", filename);
+ return false;
+ }
+
+ libconfig->setting_lookup_int(setting, "group_id_to_connect", &login->config->group_id_to_connect);
+ libconfig->setting_lookup_int(setting, "min_group_id_to_connect", &login->config->min_group_id_to_connect);
+ libconfig->setting_lookup_bool_real(setting, "check_client_version", &login->config->check_client_version);
+ libconfig->setting_lookup_uint32(setting, "client_version_to_connect", &login->config->client_version_to_connect);
+
+ if (!login_config_read_permission_hash(filename, config, imported))
+ retval = false;
+ if (!login_config_read_permission_blacklist(filename, config, imported))
+ retval = false;
+
+ return retval;
+}
+
+/**
+ * Reads the 'login-config' configuration file and initializes required variables.
+ *
+ * @param filename Path to configuration file.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ **/
+bool login_config_read(const char *filename, bool imported)
+{
+ struct config_t config;
+ const char *import = NULL;
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+
+ if (!libconfig->load_file(&config, filename))
+ return false; // Error message is already shown by libconfig->load_file
+
+ if (!login_config_read_inter(filename, &config, imported))
+ retval = false;
+ if (!login_config_read_console(filename, &config, imported))
+ retval = false;
+ if (!login_config_read_log(filename, &config, imported))
+ retval = false;
+ if (!login_config_read_account(filename, &config, imported))
+ retval = false;
+ if (!login_config_read_permission(filename, &config, imported))
+ retval = false;
+
+ if (!loginlog_config_read("conf/common/inter-server.conf", imported)) // Only inter-server
+ retval = false;
+
+ // TODO HPM->parseConf(w1, w2, HPCT_LOGIN);
+
+ ShowInfo("Finished reading %s.\n", filename);
+
+ // import should overwrite any previous configuration, so it should be called last
+ if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) {
+ if (strcmp(import, filename) == 0 || strcmp(import, login->LOGIN_CONF_NAME) == 0) {
+ ShowWarning("login_config_read: Loop detected in %s! Skipping 'import'...\n", filename);
+ } else {
+ if (!login->config_read(import, true))
+ retval = false;
}
}
- fclose(fp);
- ShowInfo("Finished reading %s.\n", cfgName);
- return 0;
+
+ config_destroy(&config);
+ return retval;
}
//--------------------------------------
// Function called at exit of the server
//--------------------------------------
-int do_final(void) {
+int do_final(void)
+{
int i;
- struct client_hash_node *hn = login->config->client_hash_nodes;
ShowStatus("Terminating...\n");
HPM->event(HPET_FINAL);
- while (hn) {
- struct client_hash_node *tmp = hn;
- hn = hn->next;
- aFree(tmp);
- }
+ clear_client_hash_nodes();
+ clear_dnsbl_servers();
login_log(0, "login server", 100, "login server shutdown");
@@ -1730,9 +2014,29 @@ int do_init(int argc, char** argv)
// read login-server configuration
login->config_set_defaults();
- login->LOGIN_CONF_NAME = aStrdup("conf/login-server.conf");
+ login->LOGIN_CONF_NAME = aStrdup("conf/login/login-server.conf");
login->NET_CONF_NAME = aStrdup("conf/network.conf");
+ {
+ // TODO: Remove this when no longer needed.
+#define CHECK_OLD_LOCAL_CONF(oldname, newname) do { \
+ if (stat((oldname), &fileinfo) == 0 && fileinfo.st_size > 0) { \
+ ShowWarning("An old configuration file \"%s\" was found.\n", (oldname)); \
+ ShowWarning("If it contains settings you wish to keep, please merge them into \"%s\".\n", (newname)); \
+ ShowWarning("Otherwise, just delete it.\n"); \
+ ShowInfo("Resuming in 10 seconds...\n"); \
+ HSleep(10); \
+ } \
+} while (0)
+ struct stat fileinfo;
+
+ CHECK_OLD_LOCAL_CONF("conf/import/login_conf.txt", "conf/import/login-server.conf");
+ CHECK_OLD_LOCAL_CONF("conf/import/inter_conf.txt", "conf/import/inter-server.conf");
+ CHECK_OLD_LOCAL_CONF("conf/import/packet_conf.txt", "conf/import/socket.conf");
+
+#undef CHECK_OLD_LOCAL_CONF
+ }
+
lclif->init();
HPM_login_do_init();
@@ -1741,7 +2045,7 @@ int do_init(int argc, char** argv)
HPM->event(HPET_PRE_INIT);
cmdline->exec(argc, argv, CMDLINE_OPT_NORMAL);
- login_config_read(login->LOGIN_CONF_NAME);
+ login->config_read(login->LOGIN_CONF_NAME, false);
sockt->net_config_read(login->NET_CONF_NAME);
for( i = 0; i < ARRAYLENGTH(server); ++i )
diff --git a/src/login/login.h b/src/login/login.h
index 36085ae91..5632e6529 100644
--- a/src/login/login.h
+++ b/src/login/login.h
@@ -97,8 +97,8 @@ struct Login_Config {
uint32 login_ip; ///< the address to bind to
uint16 login_port; ///< the port to bind to
- unsigned int ipban_cleanup_interval; ///< interval (in seconds) to clean up expired IP bans
- unsigned int ip_sync_interval; ///< interval (in minutes) to execute a DNS/IP update (for dynamic IPs)
+ uint32 ipban_cleanup_interval; ///< interval (in seconds) to clean up expired IP bans
+ uint32 ip_sync_interval; ///< interval (in minutes) to execute a DNS/IP update (for dynamic IPs)
bool log_login; ///< whether to log login server actions or not
char date_format[32]; ///< date format used in messages
bool new_account_flag,new_acc_length_limit; ///< auto-registration via _M/_F ? / if yes minimum length is 4?
@@ -113,13 +113,14 @@ struct Login_Config {
bool ipban; ///< perform IP blocking (via contents of `ipbanlist`) ?
bool dynamic_pass_failure_ban; ///< automatic IP blocking due to failed login attemps ?
- unsigned int dynamic_pass_failure_ban_interval; ///< how far to scan the loginlog for password failures
- unsigned int dynamic_pass_failure_ban_limit; ///< number of failures needed to trigger the ipban
- unsigned int dynamic_pass_failure_ban_duration; ///< duration of the ipban
+ uint32 dynamic_pass_failure_ban_interval; ///< how far to scan the loginlog for password failures
+ uint32 dynamic_pass_failure_ban_limit; ///< number of failures needed to trigger the ipban
+ uint32 dynamic_pass_failure_ban_duration; ///< duration of the ipban
bool use_dnsbl; ///< dns blacklist blocking ?
- char dnsbl_servs[1024]; ///< comma-separated list of dnsbl servers
+ VECTOR_DECL(char *) dnsbl_servers; ///< dnsbl servers
- int client_hash_check; ///< flags for checking client md5
+ bool client_hash_check; ///< flags for checking client md5
+ // TODO: VECTOR candidate
struct client_hash_node *client_hash_nodes; ///< linked list containg md5 hash for each gm group
};
@@ -207,7 +208,7 @@ struct login_interface {
void (*char_server_connection_status) (int fd, struct login_session_data* sd, uint8 status);
void (*parse_request_connection) (int fd, struct login_session_data* sd, const char *ip, uint32 ipl);
void (*config_set_defaults) (void);
- int (*config_read) (const char *cfgName);
+ bool (*config_read) (const char *filename, bool included);
char *LOGIN_CONF_NAME;
char *NET_CONF_NAME; ///< Network configuration filename
};
diff --git a/src/login/loginlog.h b/src/login/loginlog.h
index efb0873bd..589bc4fa1 100644
--- a/src/login/loginlog.h
+++ b/src/login/loginlog.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -29,7 +29,7 @@ unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes);
void login_log(uint32 ip, const char* username, int rcode, const char* message);
bool loginlog_init(void);
bool loginlog_final(void);
-bool loginlog_config_read(const char* w1, const char* w2);
+bool loginlog_config_read(const char *filename, bool imported);
#endif // HERCULES_CORE
#endif /* LOGIN_LOGINLOG_H */
diff --git a/src/login/loginlog_sql.c b/src/login/loginlog_sql.c
index 16accfada..7dff14990 100644
--- a/src/login/loginlog_sql.c
+++ b/src/login/loginlog_sql.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -23,27 +23,22 @@
#include "loginlog.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/mmo.h"
#include "common/nullpo.h"
+#include "common/showmsg.h"
#include "common/socket.h"
#include "common/sql.h"
#include "common/strlib.h"
#include <stdlib.h> // exit
-// global sql settings (in ipban_sql.c)
-static char global_db_hostname[32] = "127.0.0.1";
-static uint16 global_db_port = 3306;
-static char global_db_username[32] = "ragnarok";
-static char global_db_password[100] = "ragnarok";
-static char global_db_database[32] = "ragnarok";
-static char global_codepage[32] = "";
-// local sql settings
-static char log_db_hostname[32] = "";
-static uint16 log_db_port = 0;
-static char log_db_username[32] = "";
-static char log_db_password[100] = "";
-static char log_db_database[32] = "";
+// Sql settings
+static char log_db_hostname[32] = "127.0.0.1";
+static uint16 log_db_port = 3306;
+static char log_db_username[32] = "ragnarok";
+static char log_db_password[100] = "ragnarok";
+static char log_db_database[32] = "ragnarok";
static char log_codepage[32] = "";
static char log_login_db[256] = "loginlog";
@@ -102,42 +97,16 @@ void login_log(uint32 ip, const char* username, int rcode, const char* message)
bool loginlog_init(void)
{
- const char* username;
- const char* password;
- const char* hostname;
- uint16 port;
- const char* database;
- const char* codepage;
-
- if( log_db_hostname[0] != '\0' )
- {// local settings
- username = log_db_username;
- password = log_db_password;
- hostname = log_db_hostname;
- port = log_db_port;
- database = log_db_database;
- codepage = log_codepage;
- }
- else
- {// global settings
- username = global_db_username;
- password = global_db_password;
- hostname = global_db_hostname;
- port = global_db_port;
- database = global_db_database;
- codepage = global_codepage;
- }
-
sql_handle = SQL->Malloc();
- if( SQL_ERROR == SQL->Connect(sql_handle, username, password, hostname, port, database) )
- {
+ if (SQL_ERROR == SQL->Connect(sql_handle, log_db_username, log_db_password,
+ log_db_hostname, log_db_port, log_db_database)) {
Sql_ShowDebug(sql_handle);
SQL->Free(sql_handle);
exit(EXIT_FAILURE);
}
- if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) )
+ if (log_codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, log_codepage))
Sql_ShowDebug(sql_handle);
enabled = true;
@@ -152,60 +121,105 @@ bool loginlog_final(void)
return true;
}
-bool loginlog_config_read(const char* key, const char* value)
+/**
+ * Reads 'inter_configuration/database_names' and initializes required
+ * variables/Sets global configuration.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool loginlog_config_read_names(const char *filename, struct config_t *config, bool imported)
{
- const char* signature;
+ struct config_setting_t *setting = NULL;
- nullpo_ret(key);
- nullpo_ret(value);
- signature = "sql.";
- if( strncmpi(key, signature, strlen(signature)) == 0 )
- {
- key += strlen(signature);
- if( strcmpi(key, "db_hostname") == 0 )
- safestrncpy(global_db_hostname, value, sizeof(global_db_hostname));
- else
- if( strcmpi(key, "db_port") == 0 )
- global_db_port = (uint16)strtoul(value, NULL, 10);
- else
- if( strcmpi(key, "db_username") == 0 )
- safestrncpy(global_db_username, value, sizeof(global_db_username));
- else
- if( strcmpi(key, "db_password") == 0 )
- safestrncpy(global_db_password, value, sizeof(global_db_password));
- else
- if( strcmpi(key, "db_database") == 0 )
- safestrncpy(global_db_database, value, sizeof(global_db_database));
- else
- if( strcmpi(key, "codepage") == 0 )
- safestrncpy(global_codepage, value, sizeof(global_codepage));
- else
- return false;// not found
- return true;
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "inter_configuration/database_names")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("loginlog_config_read: inter_configuration/database_names was not found in %s!\n", filename);
+ return false;
}
- if( strcmpi(key, "log_db_ip") == 0 )
- safestrncpy(log_db_hostname, value, sizeof(log_db_hostname));
- else
- if( strcmpi(key, "log_db_port") == 0 )
- log_db_port = (uint16)strtoul(value, NULL, 10);
- else
- if( strcmpi(key, "log_db_id") == 0 )
- safestrncpy(log_db_username, value, sizeof(log_db_username));
- else
- if( strcmpi(key, "log_db_pw") == 0 )
- safestrncpy(log_db_password, value, sizeof(log_db_password));
- else
- if( strcmpi(key, "log_db_db") == 0 )
- safestrncpy(log_db_database, value, sizeof(log_db_database));
- else
- if( strcmpi(key, "log_codepage") == 0 )
- safestrncpy(log_codepage, value, sizeof(log_codepage));
- else
- if( strcmpi(key, "log_login_db") == 0 )
- safestrncpy(log_login_db, value, sizeof(log_login_db));
- else
+ libconfig->setting_lookup_mutable_string(setting, "login_db", log_login_db, sizeof(log_login_db));
+
+ return true;
+}
+
+/**
+ * Reads 'inter_configuration.log' and initializes required variables/Sets
+ * global configuration.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool loginlog_config_read_log(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "inter_configuration/log/sql_connection")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("loginlog_config_read: inter_configuration/log/sql_connection was not found in %s!\n", filename);
return false;
+ }
+
+ libconfig->setting_lookup_mutable_string(setting, "db_hostname", log_db_hostname, sizeof(log_db_hostname));
+ libconfig->setting_lookup_mutable_string(setting, "db_database", log_db_database, sizeof(log_db_database));
+ libconfig->setting_lookup_mutable_string(setting, "db_username", log_db_username, sizeof(log_db_username));
+ libconfig->setting_lookup_mutable_string(setting, "db_password", log_db_password, sizeof(log_db_password));
+
+ libconfig->setting_lookup_uint16(setting, "db_port", &log_db_port);
+ libconfig->setting_lookup_mutable_string(setting, "codepage", log_codepage, sizeof(log_codepage));
return true;
}
+
+/**
+ * Reads 'inter_configuration' and initializes required variables/Sets global
+ * configuration.
+ *
+ * @param filename Path to configuration file.
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ **/
+bool loginlog_config_read(const char *filename, bool imported)
+{
+ struct config_t config;
+ const char *import = NULL;
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+
+ if (!libconfig->load_file(&config, filename))
+ return false; // Error message is already shown by libconfig->load_file
+
+ if (!loginlog_config_read_names(filename, &config, imported))
+ retval = false;
+ if (!loginlog_config_read_log(filename, &config, imported))
+ retval = false;
+
+ if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) {
+ if (strcmp(import, filename) == 0 || strcmp(import, "conf/common/inter-server.conf") == 0) {
+ ShowWarning("inter_config_read: Loop detected! Skipping 'import'...\n");
+ } else {
+ if (!loginlog_config_read(import, true))
+ retval = false;
+ }
+ }
+
+ libconfig->destroy(&config);
+ return retval;
+}
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 8d4aa317f..3f916eb42 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -3611,7 +3611,7 @@ ACMD(reloadbattleconf)
struct Battle_Config prev_config;
memcpy(&prev_config, &battle_config, sizeof(prev_config));
- battle->config_read(map->BATTLE_CONF_FILENAME);
+ battle->config_read(map->BATTLE_CONF_FILENAME, false);
if (prev_config.feature_roulette == 0 && battle_config.feature_roulette == 1 && !clif->parse_roulette_db())
battle_config.feature_roulette = 0;
diff --git a/src/map/battle.c b/src/map/battle.c
index 908f0364b..c564b81cd 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -41,6 +41,7 @@
#include "map/status.h"
#include "common/HPM.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/ers.h"
#include "common/memmgr.h"
#include "common/nullpo.h"
@@ -7018,7 +7019,7 @@ static const struct battle_data {
{ "show_steal_in_same_party", &battle_config.show_steal_in_same_party, 0, 0, 1, },
{ "party_hp_mode", &battle_config.party_hp_mode, 0, 0, 1, },
{ "show_party_share_picker", &battle_config.party_show_share_picker, 1, 0, 1, },
- { "show_picker.item_type", &battle_config.show_picker_item_type, 112, 0, INT_MAX, },
+ { "show_picker_item_type", &battle_config.show_picker_item_type, 112, 0, INT_MAX, },
{ "party_update_interval", &battle_config.party_update_interval, 1000, 100, INT_MAX, },
{ "party_item_share_type", &battle_config.party_share_type, 0, 0, 1|2|3, },
{ "attack_attr_none", &battle_config.attack_attr_none, ~BL_PC, BL_NUL, BL_ALL, },
@@ -7177,14 +7178,14 @@ static const struct battle_data {
{ "display_status_timers", &battle_config.display_status_timers, 1, 0, 1, },
{ "skill_add_heal_rate", &battle_config.skill_add_heal_rate, 7, 0, INT_MAX, },
{ "eq_single_target_reflectable", &battle_config.eq_single_target_reflectable, 1, 0, 1, },
- { "invincible.nodamage", &battle_config.invincible_nodamage, 0, 0, 1, },
+ { "invincible_nodamage", &battle_config.invincible_nodamage, 0, 0, 1, },
{ "mob_slave_keep_target", &battle_config.mob_slave_keep_target, 0, 0, 1, },
{ "autospell_check_range", &battle_config.autospell_check_range, 0, 0, 1, },
{ "knockback_left", &battle_config.knockback_left, 1, 0, 1, },
{ "client_reshuffle_dice", &battle_config.client_reshuffle_dice, 0, 0, 1, },
{ "client_sort_storage", &battle_config.client_sort_storage, 0, 0, 1, },
- { "feature.buying_store", &battle_config.feature_buying_store, 1, 0, 1, },
- { "feature.search_stores", &battle_config.feature_search_stores, 1, 0, 1, },
+ { "features/buying_store", &battle_config.feature_buying_store, 1, 0, 1, },
+ { "features/search_stores", &battle_config.feature_search_stores, 1, 0, 1, },
{ "searchstore_querydelay", &battle_config.searchstore_querydelay, 10, 0, INT_MAX, },
{ "searchstore_maxresults", &battle_config.searchstore_maxresults, 30, 1, INT_MAX, },
{ "display_party_name", &battle_config.display_party_name, 0, 0, 1, },
@@ -7204,7 +7205,7 @@ static const struct battle_data {
{ "atcommand_max_stat_bypass", &battle_config.atcommand_max_stat_bypass, 0, 0, 100, },
{ "skill_amotion_leniency", &battle_config.skill_amotion_leniency, 90, 0, 300 },
{ "mvp_tomb_enabled", &battle_config.mvp_tomb_enabled, 1, 0, 1 },
- { "feature.atcommand_suggestions", &battle_config.atcommand_suggestions_enabled, 0, 0, 1 },
+ { "features/atcommand_suggestions", &battle_config.atcommand_suggestions_enabled, 0, 0, 1 },
{ "min_npc_vendchat_distance", &battle_config.min_npc_vendchat_distance, 3, 0, 100 },
{ "vendchat_near_hiddennpc", &battle_config.vendchat_near_hiddennpc, 0, 0, 1 },
{ "atcommand_mobinfo_type", &battle_config.atcommand_mobinfo_type, 0, 0, 1 },
@@ -7225,8 +7226,8 @@ static const struct battle_data {
{ "client_accept_chatdori", &battle_config.client_accept_chatdori, 0, 0, INT_MAX, },
{ "snovice_call_type", &battle_config.snovice_call_type, 0, 0, 1, },
{ "guild_notice_changemap", &battle_config.guild_notice_changemap, 2, 0, 2, },
- { "feature.banking", &battle_config.feature_banking, 1, 0, 1, },
- { "feature.auction", &battle_config.feature_auction, 0, 0, 2, },
+ { "features/banking", &battle_config.feature_banking, 1, 0, 1, },
+ { "features/auction", &battle_config.feature_auction, 0, 0, 2, },
{ "idletime_criteria", &battle_config.idletime_criteria, 0x25, 1, INT_MAX, },
{ "mon_trans_disable_in_gvg", &battle_config.mon_trans_disable_in_gvg, 0, 0, 1, },
{ "case_sensitive_aegisnames", &battle_config.case_sensitive_aegisnames, 1, 0, 1, },
@@ -7238,7 +7239,7 @@ static const struct battle_data {
{ "monster_chase_refresh", &battle_config.mob_chase_refresh, 1, 0, 30, },
{ "mob_icewall_walk_block", &battle_config.mob_icewall_walk_block, 75, 0, 255, },
{ "boss_icewall_walk_block", &battle_config.boss_icewall_walk_block, 0, 0, 255, },
- { "feature.roulette", &battle_config.feature_roulette, 1, 0, 1, },
+ { "features/roulette", &battle_config.feature_roulette, 1, 0, 1, },
{ "show_monster_hp_bar", &battle_config.show_monster_hp_bar, 1, 0, 1, },
{ "fix_warp_hit_delay_abuse", &battle_config.fix_warp_hit_delay_abuse, 0, 0, 1, },
{ "costume_refine_def", &battle_config.costume_refine_def, 1, 0, 1, },
@@ -7413,28 +7414,36 @@ static int Hercules_report_timer(int tid, int64 tick, int id, intptr_t data) {
}
#endif
-int battle_set_value(const char* w1, const char* w2)
+bool battle_set_value_sub(int index, int value)
{
- int val = config_switch(w2);
+ Assert_retr(false, index >= 0);
+ if (value < battle_data[index].min || value > battle_data[index].max) {
+ ShowWarning("Value for setting '%s': %d is invalid (min:%d max:%d)! Defaulting to %d...\n",
+ battle_data[index].str, value, battle_data[index].min, battle_data[index].max, battle_data[index].defval);
+ value = battle_data[index].defval;
+ }
+ *battle_data[index].val = value;
+ return true;
+}
+
+bool battle_set_value(const char *param, const char *value)
+{
+ int val;
int i;
- nullpo_retr(1, w1);
- nullpo_retr(1, w2);
- ARR_FIND(0, ARRAYLENGTH(battle_data), i, strcmpi(w1, battle_data[i].str) == 0);
- if (i == ARRAYLENGTH(battle_data)) {
- if( HPM->parseConf(w1,w2,HPCT_BATTLE) ) /* if plugin-owned, succeed */
- return 1;
- return 0; // not found
- }
+ nullpo_retr(false, param);
+ nullpo_retr(false, value);
- if (val < battle_data[i].min || val > battle_data[i].max)
- {
- ShowWarning("Value for setting '%s': %s is invalid (min:%i max:%i)! Defaulting to %i...\n", w1, w2, battle_data[i].min, battle_data[i].max, battle_data[i].defval);
- val = battle_data[i].defval;
+ val = config_switch(value);
+
+ ARR_FIND(0, ARRAYLENGTH(battle_data), i, strcmpi(param, battle_data[i].str) == 0);
+ if (i == ARRAYLENGTH(battle_data)) {
+ if (HPM->parseConf(param, value, HPCT_BATTLE)) /* if plugin-owned, succeed */
+ return true;
+ return false; // not found
}
- *battle_data[i].val = val;
- return 1;
+ return battle->config_set_value_sub(i, val);
}
bool battle_get_value(const char *w1, int *value)
@@ -7485,36 +7494,36 @@ void battle_adjust_conf(void) {
#if PACKETVER < 20100427
if( battle_config.feature_buying_store ) {
- ShowWarning("conf/battle/feature.conf buying_store is enabled but it requires PACKETVER 2010-04-27 or newer, disabling...\n");
+ ShowWarning("conf/map/battle/feature.conf buying_store is enabled but it requires PACKETVER 2010-04-27 or newer, disabling...\n");
battle_config.feature_buying_store = 0;
}
#endif
#if PACKETVER < 20100803
if( battle_config.feature_search_stores ) {
- ShowWarning("conf/battle/feature.conf search_stores is enabled but it requires PACKETVER 2010-08-03 or newer, disabling...\n");
+ ShowWarning("conf/map/battle/feature.conf search_stores is enabled but it requires PACKETVER 2010-08-03 or newer, disabling...\n");
battle_config.feature_search_stores = 0;
}
#endif
#if PACKETVER < 20130724
if( battle_config.feature_banking ) {
- ShowWarning("conf/battle/feature.conf banking is enabled but it requires PACKETVER 2013-07-24 or newer, disabling...\n");
+ ShowWarning("conf/map/battle/feature.conf banking is enabled but it requires PACKETVER 2013-07-24 or newer, disabling...\n");
battle_config.feature_banking = 0;
}
#endif
#if PACKETVER < 20141022
if( battle_config.feature_roulette ) {
- ShowWarning("conf/battle/feature.conf roulette is enabled but it requires PACKETVER 2014-10-22 or newer, disabling...\n");
+ ShowWarning("conf/map/battle/feature.conf roulette is enabled but it requires PACKETVER 2014-10-22 or newer, disabling...\n");
battle_config.feature_roulette = 0;
}
#endif
#if PACKETVER > 20120000 && PACKETVER < 20130515 /* exact date (when it started) not known */
if( battle_config.feature_auction == 1 ) {
- ShowWarning("conf/battle/feature.conf:feature.auction is enabled but it is not stable on PACKETVER "EXPAND_AND_QUOTE(PACKETVER)", disabling...\n");
- ShowWarning("conf/battle/feature.conf:feature.auction change value to '2' to silence this warning and maintain it enabled\n");
+ ShowWarning("conf/map/battle/feature.conf:features/auction is enabled but it is not stable on PACKETVER "EXPAND_AND_QUOTE(PACKETVER)", disabling...\n");
+ ShowWarning("conf/map/battle/feature.conf:features/auction change value to '2' to silence this warning and maintain it enabled\n");
battle_config.feature_auction = 0;
}
#endif
@@ -7525,48 +7534,78 @@ void battle_adjust_conf(void) {
#endif
}
-int battle_config_read(const char* cfgName)
+/**
+ * Dynamically reads battle configuration and initializes required variables.
+ *
+ * @param filename Path to configuration file.
+ * @param imported Whether the current config is imported from another file.
+ * @retval false in case of error.
+ */
+bool battle_config_read(const char *filename, bool imported)
{
- FILE* fp;
- static int count = 0;
+ struct config_t config;
+ const struct config_setting_t *setting = NULL;
+ int i;
+ const char *import = NULL;
+ bool retval = true;
+
+ nullpo_retr(false, filename);
- nullpo_ret(cfgName);
+ if (!libconfig->load_file(&config, filename))
+ return false; // Error message is already shown by libconfig->load_file()
- if (count == 0)
+ if (!imported)
battle->config_set_defaults();
- count++;
+ for (i = 0; i < ARRAYLENGTH(battle_data); i++) {
+ int type, val;
+ char config_name[256];
+ safesnprintf(config_name, sizeof config_name, "battle_configuration/%s", battle_data[i].str);
- fp = fopen(cfgName,"r");
- if (fp == NULL)
- ShowError("File not found: %s\n", cfgName);
- else
- {
- char line[1024], w1[1024], w2[1024];
- while(fgets(line, sizeof(line), fp))
- {
- if (line[0] == '/' && line[1] == '/')
- continue;
- if (sscanf(line, "%1023[^:]:%1023s", w1, w2) != 2)
- continue;
- if (strcmpi(w1, "import") == 0)
- battle->config_read(w2);
- else
- if (battle->config_set_value(w1, w2) == 0)
- ShowWarning("Unknown setting '%s' in file %s\n", w1, cfgName);
+ if ((setting = libconfig->lookup(&config, config_name)) == NULL) {
+ if (!imported) {
+ ShowWarning("Missing configuration '%s' in file %s!\n", config_name, filename);
+ retval = false;
+ }
+ continue;
}
- fclose(fp);
+ switch ((type = config_setting_type(setting))) {
+ case CONFIG_TYPE_INT:
+ val = libconfig->setting_get_int(setting);
+ break;
+ case CONFIG_TYPE_BOOL:
+ val = libconfig->setting_get_bool(setting);
+ break;
+ default: // Unsupported type
+ ShowWarning("Setting %s has unsupported type %d, ignoring...\n", config_name, type);
+ retval = false;
+ continue;
+ }
+
+ if (!battle->config_set_value_sub(i, val))
+ retval = false;
}
- count--;
+ if (!HPM->parse_battle_conf(&config, filename, imported))
+ retval = false;
+
+ // import should overwrite any previous configuration, so it should be called last
+ if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) {
+ if (strcmp(import, filename) == 0 || strcmp(import, map->BATTLE_CONF_FILENAME) == 0) {
+ ShowWarning("battle_config_read: Loop detected! Skipping 'import'...\n");
+ } else {
+ if (!battle->config_read(import, true))
+ retval = false;
+ }
+ }
- if (count == 0) {
+ libconfig->destroy(&config);
+ if (!imported) {
battle->config_adjust();
clif->bc_ready();
}
-
- return 0;
+ return retval;
}
void do_init_battle(bool minimal) {
@@ -7645,6 +7684,7 @@ void battle_defaults(void) {
battle->calc_drain = battle_calc_drain;
battle->config_read = battle_config_read;
battle->config_set_defaults = battle_set_defaults;
+ battle->config_set_value_sub = battle_set_value_sub;
battle->config_set_value = battle_set_value;
battle->config_get_value = battle_get_value;
battle->config_adjust = battle_adjust_conf;
diff --git a/src/map/battle.h b/src/map/battle.h
index e04a713ae..ebfa0e305 100644
--- a/src/map/battle.h
+++ b/src/map/battle.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -663,10 +663,11 @@ struct battle_interface {
int (*adjust_skill_damage) (int m, unsigned short skill_id);
int64 (*add_mastery) (struct map_session_data *sd,struct block_list *target,int64 dmg,int type);
int (*calc_drain) (int64 damage, int rate, int per);
- /* - battle_config */
- int (*config_read) (const char *cfgName);
+ /* battle_config */
+ bool (*config_read) (const char *filename, bool imported);
void (*config_set_defaults) (void);
- int (*config_set_value) (const char *w1, const char *w2);
+ bool (*config_set_value_sub) (int index, int value);
+ bool (*config_set_value) (const char *param, const char *value);
bool (*config_get_value) (const char *w1, int *value);
void (*config_adjust) (void);
/* ----------------------------------------- */
diff --git a/src/map/log.c b/src/map/log.c
index c19190d90..6131f9cf4 100644
--- a/src/map/log.c
+++ b/src/map/log.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -28,6 +28,7 @@
#include "map/mob.h"
#include "map/pc.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/nullpo.h"
#include "common/showmsg.h"
#include "common/sql.h" // SQL_INNODB
@@ -479,119 +480,250 @@ void log_sql_final(void) {
logs->mysql_handle = NULL;
}
-void log_set_defaults(void) {
+/**
+ * Initializes logs->config variables
+ */
+void log_set_defaults(void)
+{
memset(&logs->config, 0, sizeof(logs->config));
- //LOG FILTER Default values
+ //map_log default values
+ logs->config.enable_logs = 0xFFFFF;
+ logs->config.commands = true;
+
+ //map_log/database default values
+ logs->config.sql_logs = true;
+ // file/table names defaults are defined inside log_config_read_database
+
+ //map_log/filter/item default values
+ logs->config.filter = 1; // logs any item
logs->config.refine_items_log = 5; // log refined items, with refine >= +5
logs->config.rare_items_log = 100; // log rare items. drop chance <= 1%
logs->config.price_items_log = 1000; // 1000z
logs->config.amount_items_log = 100;
}
-int log_config_read(const char* cfgName) {
- static int count = 0;
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
+/**
+ * Reads 'map_log/database' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool log_config_read_database(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "map_log/database")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("log_config_read: map_log/database was not found in %s!\n", filename);
+ return false;
+ }
+ libconfig->setting_lookup_bool_real(setting, "use_sql", &logs->config.sql_logs);
+
+ // map_log.database defaults are defined in order to not make unecessary calls to safestrncpy [Panikon]
+ if (libconfig->setting_lookup_mutable_string(setting, "log_branch_db",
+ logs->config.log_branch, sizeof(logs->config.log_branch)) == CONFIG_FALSE)
+ safestrncpy(logs->config.log_branch, "branchlog", sizeof(logs->config.log_branch));
+
+ if (libconfig->setting_lookup_mutable_string(setting, "log_pick_db",
+ logs->config.log_pick, sizeof(logs->config.log_pick)) == CONFIG_FALSE)
+ safestrncpy(logs->config.log_pick, "picklog", sizeof(logs->config.log_pick));
+
+ if (libconfig->setting_lookup_mutable_string(setting, "log_zeny_db",
+ logs->config.log_zeny, sizeof(logs->config.log_zeny)) == CONFIG_FALSE)
+ safestrncpy(logs->config.log_zeny, "zenylog", sizeof(logs->config.log_zeny));
+
+ if (libconfig->setting_lookup_mutable_string(setting, "log_mvpdrop_db",
+ logs->config.log_mvpdrop, sizeof(logs->config.log_mvpdrop)) == CONFIG_FALSE)
+ safestrncpy(logs->config.log_mvpdrop, "mvplog", sizeof(logs->config.log_mvpdrop));
+
+ if (libconfig->setting_lookup_mutable_string(setting, "log_gm_db",
+ logs->config.log_gm, sizeof(logs->config.log_gm)) == CONFIG_FALSE)
+ safestrncpy(logs->config.log_gm, "atcommandlog", sizeof(logs->config.log_gm));
+
+ if (libconfig->setting_lookup_mutable_string(setting, "log_npc_db",
+ logs->config.log_npc, sizeof(logs->config.log_npc)) == CONFIG_FALSE)
+ safestrncpy(logs->config.log_npc, "npclog", sizeof(logs->config.log_npc));
+
+ if (libconfig->setting_lookup_mutable_string(setting, "log_chat_db",
+ logs->config.log_chat, sizeof(logs->config.log_chat)) == CONFIG_FALSE)
+ safestrncpy(logs->config.log_chat, "chatlog", sizeof(logs->config.log_chat));
+
+ return true;
+}
+
+/**
+ * Reads 'map_log/filter/item' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool log_config_read_filter_item(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
- nullpo_retr(1, cfgName);
- if( count++ == 0 )
+ if ((setting = libconfig->lookup(config, "map_log/filter/item")) == NULL) {
+ if (!imported)
+ ShowError("log_config_read: map_log/filter/item was not found in %s!\n", filename);
+ return false;
+ }
+ libconfig->setting_lookup_int(setting, "log_filter", &logs->config.filter);
+ libconfig->setting_lookup_int(setting, "refine_items_log", &logs->config.refine_items_log);
+ libconfig->setting_lookup_int(setting, "rare_items_log", &logs->config.rare_items_log);
+ libconfig->setting_lookup_int(setting, "price_items_log", &logs->config.price_items_log);
+ libconfig->setting_lookup_int(setting, "amount_items_log", &logs->config.amount_items_log);
+ return true;
+}
+
+/**
+ * Reads 'map_log.filter.chat' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool log_config_read_filter_chat(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "map_log/filter/chat")) == NULL) {
+ if (!imported)
+ ShowError("log_config_read: map_log/filter/chat was not found in %s!\n", filename);
+ return false;
+ }
+ libconfig->setting_lookup_int(setting, "log_chat", &logs->config.chat);
+ libconfig->setting_lookup_bool_real(setting, "log_chat_woe_disable", &logs->config.log_chat_woe_disable);
+ return true;
+}
+
+/**
+ * Reads 'map_log.filter' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool log_config_read_filter(const char *filename, struct config_t *config, bool imported)
+{
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if (!log_config_read_filter_item(filename, config, imported))
+ retval = false;
+ if (!log_config_read_filter_chat(filename, config, imported))
+ retval = false;
+
+ return retval;
+}
+
+/**
+ * Reads 'map_log' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool log_config_read(const char *filename, bool imported)
+{
+ struct config_t config;
+ struct config_setting_t *setting = NULL;
+ const char *import;
+ const char *target; // Type of storage 'file'/'table'
+ int temp;
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+
+ if (!imported)
log_set_defaults();
- if( ( fp = fopen(cfgName, "r") ) == NULL ) {
- ShowError("Log configuration file not found at: %s\n", cfgName);
- return 1;
+ if (!libconfig->load_file(&config, filename))
+ return false;
+
+ if ((setting = libconfig->lookup(&config, "map_log")) == NULL) {
+ libconfig->destroy(&config);
+ if (imported)
+ return true;
+ ShowError("log_config_read: map_log was not found in %s!\n", filename);
+ return false;
}
- while (fgets(line, sizeof(line), fp)) {
- if (line[0] == '/' && line[1] == '/')
- continue;
-
- if (sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) == 2) {
- if( strcmpi(w1, "enable_logs") == 0 )
- logs->config.enable_logs = (e_log_pick_type)config_switch(w2);
- else if( strcmpi(w1, "sql_logs") == 0 )
- logs->config.sql_logs = (bool)config_switch(w2);
-//start of common filter settings
- else if( strcmpi(w1, "rare_items_log") == 0 )
- logs->config.rare_items_log = atoi(w2);
- else if( strcmpi(w1, "refine_items_log") == 0 )
- logs->config.refine_items_log = atoi(w2);
- else if( strcmpi(w1, "price_items_log") == 0 )
- logs->config.price_items_log = atoi(w2);
- else if( strcmpi(w1, "amount_items_log") == 0 )
- logs->config.amount_items_log = atoi(w2);
-//end of common filter settings
- else if( strcmpi(w1, "log_branch") == 0 )
- logs->config.branch = config_switch(w2);
- else if( strcmpi(w1, "log_filter") == 0 )
- logs->config.filter = config_switch(w2);
- else if( strcmpi(w1, "log_zeny") == 0 )
- logs->config.zeny = config_switch(w2);
- else if( strcmpi(w1, "log_commands") == 0 )
- logs->config.commands = config_switch(w2);
- else if( strcmpi(w1, "log_npc") == 0 )
- logs->config.npc = config_switch(w2);
- else if( strcmpi(w1, "log_chat") == 0 )
- logs->config.chat = config_switch(w2);
- else if( strcmpi(w1, "log_mvpdrop") == 0 )
- logs->config.mvpdrop = config_switch(w2);
- else if( strcmpi(w1, "log_chat_woe_disable") == 0 )
- logs->config.log_chat_woe_disable = (bool)config_switch(w2);
- else if( strcmpi(w1, "log_branch_db") == 0 )
- safestrncpy(logs->config.log_branch, w2, sizeof(logs->config.log_branch));
- else if( strcmpi(w1, "log_pick_db") == 0 )
- safestrncpy(logs->config.log_pick, w2, sizeof(logs->config.log_pick));
- else if( strcmpi(w1, "log_zeny_db") == 0 )
- safestrncpy(logs->config.log_zeny, w2, sizeof(logs->config.log_zeny));
- else if( strcmpi(w1, "log_mvpdrop_db") == 0 )
- safestrncpy(logs->config.log_mvpdrop, w2, sizeof(logs->config.log_mvpdrop));
- else if( strcmpi(w1, "log_gm_db") == 0 )
- safestrncpy(logs->config.log_gm, w2, sizeof(logs->config.log_gm));
- else if( strcmpi(w1, "log_npc_db") == 0 )
- safestrncpy(logs->config.log_npc, w2, sizeof(logs->config.log_npc));
- else if( strcmpi(w1, "log_chat_db") == 0 )
- safestrncpy(logs->config.log_chat, w2, sizeof(logs->config.log_chat));
- //support the import command, just like any other config
- else if( strcmpi(w1,"import") == 0 )
- logs->config_read(w2);
- else if (HPM->parseConf(w1, w2, HPCT_LOG))
- ; // handled by plugins
- else
- ShowWarning("Unknown setting '%s' in file %s\n", w1, cfgName);
- }
+ if (libconfig->setting_lookup_int(setting, "enable", &temp) == CONFIG_TRUE) {
+ logs->config.enable_logs = temp&LOG_TYPE_ALL; // e_log_pick_type
}
+ libconfig->setting_lookup_int(setting, "log_zeny", &logs->config.zeny);
+ libconfig->setting_lookup_bool_real(setting, "log_branch", &logs->config.branch);
+ libconfig->setting_lookup_bool_real(setting, "log_mvpdrop", &logs->config.mvpdrop);
+ libconfig->setting_lookup_bool_real(setting, "log_commands", &logs->config.commands);
+ libconfig->setting_lookup_bool_real(setting, "log_npc", &logs->config.npc);
- fclose(fp);
+ if (!log_config_read_database(filename, &config, imported))
+ retval = false;
+ if (!log_config_read_filter(filename, &config, imported))
+ retval = false;
- if( --count == 0 ) {// report final logging state
- const char* target = logs->config.sql_logs ? "table" : "file";
+ // TODO HPM->parseConf(w1, w2, HPCT_LOG);
- if( logs->config.enable_logs && logs->config.filter ) {
- ShowInfo("Logging item transactions to %s '%s'.\n", target, logs->config.log_pick);
- }
- if( logs->config.branch ) {
- ShowInfo("Logging monster summon item usage to %s '%s'.\n", target, logs->config.log_pick);
- }
- if( logs->config.chat ) {
- ShowInfo("Logging chat to %s '%s'.\n", target, logs->config.log_chat);
- }
- if( logs->config.commands ) {
- ShowInfo("Logging commands to %s '%s'.\n", target, logs->config.log_gm);
- }
- if( logs->config.mvpdrop ) {
- ShowInfo("Logging MVP monster rewards to %s '%s'.\n", target, logs->config.log_mvpdrop);
- }
- if( logs->config.npc ) {
- ShowInfo("Logging 'logmes' messages to %s '%s'.\n", target, logs->config.log_npc);
- }
- if( logs->config.zeny ) {
- ShowInfo("Logging Zeny transactions to %s '%s'.\n", target, logs->config.log_zeny);
+ target = logs->config.sql_logs ? "table" : "file";
+
+ if (logs->config.enable_logs && logs->config.filter)
+ ShowInfo("Logging item transactions to %s '%s'.\n", target, logs->config.log_pick);
+
+ if (logs->config.branch)
+ ShowInfo("Logging monster summon item usage to %s '%s'.\n", target, logs->config.log_branch);
+
+ if (logs->config.chat)
+ ShowInfo("Logging chat to %s '%s'.\n", target, logs->config.log_chat);
+
+ if (logs->config.commands)
+ ShowInfo("Logging commands to %s '%s'.\n", target, logs->config.log_gm);
+
+ if (logs->config.mvpdrop)
+ ShowInfo("Logging MVP monster rewards to %s '%s'.\n", target, logs->config.log_mvpdrop);
+
+ if (logs->config.npc)
+ ShowInfo("Logging 'logmes' messages to %s '%s'.\n", target, logs->config.log_npc);
+
+ if (logs->config.zeny)
+ ShowInfo("Logging Zeny transactions to %s '%s'.\n", target, logs->config.log_zeny);
+
+ logs->config_done();
+
+ // import should overwrite any previous configuration, so it should be called last
+ if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) {
+ if (strcmp(import, filename) == 0 || strcmp(import, map->LOG_CONF_NAME) == 0) {
+ ShowWarning("log_config_read: Loop detected! Skipping 'import'...\n");
+ } else {
+ if (!logs->config_read(import, true))
+ retval = false;
}
- logs->config_done();
}
- return 0;
+ libconfig->destroy(&config);
+ return retval;
}
void log_config_complete(void) {
@@ -606,6 +738,9 @@ void log_config_complete(void) {
}
}
+/**
+ * Initializes the log interface to the default values.
+ */
void log_defaults(void) {
logs = &log_s;
diff --git a/src/map/log.h b/src/map/log.h
index 0a5e13208..7ff36d126 100644
--- a/src/map/log.h
+++ b/src/map/log.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -118,7 +118,8 @@ struct log_interface {
bool sql_logs;
bool log_chat_woe_disable;
int rare_items_log,refine_items_log,price_items_log,amount_items_log;
- int branch, mvpdrop, zeny, commands, npc, chat;
+ int zeny, chat;
+ bool branch, mvpdrop, commands, npc;
char log_branch[64], log_pick[64], log_zeny[64], log_mvpdrop[64], log_gm[64], log_npc[64], log_chat[64];
} config;
/* */
@@ -146,7 +147,7 @@ struct log_interface {
void (*branch_sub) (struct map_session_data* sd);
void (*mvpdrop_sub) (struct map_session_data* sd, int monster_id, int* log_mvp);
- int (*config_read) (const char* cfgName);
+ bool (*config_read) (const char *filename, bool imported);
void (*config_done) (void);
void (*sql_init) (void);
void (*sql_final) (void);
diff --git a/src/map/map.c b/src/map/map.c
index d6425b94e..40bcd9263 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -79,6 +79,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
#ifndef _WIN32
#include <unistd.h>
#endif
@@ -3330,20 +3331,42 @@ int map_readfromcache(struct map_data *m, char *buffer) {
return 0; // Not found
}
-int map_addmap(const char* mapname) {
+/**
+ * Adds a new empty map to the map list.
+ *
+ * Assumes that there's enough space in the map list.
+ *
+ * @param mapname The new map's name.
+ * @return success state.
+ */
+int map_addmap(const char *mapname)
+{
map->list[map->count].instance_id = -1;
mapindex->getmapname(mapname, map->list[map->count++].name);
return 0;
}
-void map_delmapid(int id) {
+/**
+ * Removes a map from the map list.
+ *
+ * @param id The map ID.
+ */
+void map_delmapid(int id)
+{
Assert_retv(id >= 0 && id < map->count);
ShowNotice("Removing map [ %s ] from maplist"CL_CLL"\n",map->list[id].name);
memmove(map->list+id, map->list+id+1, sizeof(map->list[0])*(map->count-id-1));
map->count--;
}
-int map_delmap(char* mapname) {
+/**
+ * Removes a map fromt he map list.
+ *
+ * @param mapname The name of the map to remove.
+ * @return the number of removed maps.
+ */
+int map_delmap(const char *mapname)
+{
int i;
char map_name[MAP_NAME_LENGTH];
@@ -3798,181 +3821,383 @@ int map_readallmaps (void) {
return 0;
}
-/*==========================================
- * Read map server configuration files (conf/map_server.conf...)
- *------------------------------------------*/
-int map_config_read(char *cfgName) {
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
+/**
+ * Reads 'map_configuration/console' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool map_config_read_console(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
- nullpo_retr(1, cfgName);
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
- fp = fopen(cfgName,"r");
- if( fp == NULL ) {
- ShowError("Map configuration file not found at: %s\n", cfgName);
- return 1;
+ if ((setting = libconfig->lookup(config, "map_configuration/console")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("map_config_read: map_configuration/console was not found in %s!\n", filename);
+ return false;
}
- while (fgets(line, sizeof(line), fp)) {
- char* ptr;
+ libconfig->setting_lookup_bool_real(setting, "stdout_with_ansisequence", &showmsg->stdout_with_ansisequence);
+ if (libconfig->setting_lookup_int(setting, "console_silent", &showmsg->silent) == CONFIG_TRUE) {
+ if (showmsg->silent) // only bother if its actually enabled
+ ShowInfo("Console Silent Setting: %d\n", showmsg->silent);
+ }
+ libconfig->setting_lookup_mutable_string(setting, "timestamp_format", showmsg->timestamp_format, sizeof(showmsg->timestamp_format));
+ libconfig->setting_lookup_int(setting, "console_msg_log", &showmsg->console_log);
- if (line[0] == '/' && line[1] == '/')
- continue;
- if ((ptr = strstr(line, "//")) != NULL)
- *ptr = '\n'; //Strip comments
- if (sscanf(line, "%1023[^:]: %1023[^\t\r\n]", w1, w2) < 2)
- continue;
+ return true;
+}
- //Strip trailing spaces
- ptr = w2 + strlen(w2);
- while (--ptr >= w2 && *ptr == ' ');
- ptr++;
- *ptr = '\0';
-
- if(strcmpi(w1,"timestamp_format")==0)
- safestrncpy(showmsg->timestamp_format, w2, 20);
- else if(strcmpi(w1,"stdout_with_ansisequence")==0)
- showmsg->stdout_with_ansisequence = config_switch(w2) ? true : false;
- else if(strcmpi(w1,"console_silent")==0) {
- showmsg->silent = atoi(w2);
- if (showmsg->silent) // only bother if its actually enabled
- ShowInfo("Console Silent Setting: %d\n", atoi(w2));
- } else if (strcmpi(w1, "userid")==0)
- chrif->setuserid(w2);
- else if (strcmpi(w1, "passwd") == 0)
- chrif->setpasswd(w2);
- else if (strcmpi(w1, "char_ip") == 0)
- map->char_ip_set = chrif->setip(w2);
- else if (strcmpi(w1, "char_port") == 0)
- chrif->setport(atoi(w2));
- else if (strcmpi(w1, "map_ip") == 0)
- map->ip_set = clif->setip(w2);
- else if (strcmpi(w1, "bind_ip") == 0)
- clif->setbindip(w2);
- else if (strcmpi(w1, "map_port") == 0) {
- clif->setport(atoi(w2));
- map->port = (atoi(w2));
- } else if (strcmpi(w1, "map") == 0)
- map->count++;
- else if (strcmpi(w1, "delmap") == 0)
- map->count--;
- else if (strcmpi(w1, "npc") == 0)
- npc->addsrcfile(w2);
- else if (strcmpi(w1, "delnpc") == 0)
- npc->delsrcfile(w2);
- else if (strcmpi(w1, "autosave_time") == 0) {
- map->autosave_interval = atoi(w2);
- if (map->autosave_interval < 1) //Revert to default saving.
- map->autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
- else
- map->autosave_interval *= 1000; //Pass from sec to ms
- } else if (strcmpi(w1, "minsave_time") == 0) {
- map->minsave_interval= atoi(w2);
- if (map->minsave_interval < 1)
- map->minsave_interval = 1;
- } else if (strcmpi(w1, "save_settings") == 0)
- map->save_settings = atoi(w2);
- else if (strcmpi(w1, "help_txt") == 0)
- strcpy(map->help_txt, w2);
- else if (strcmpi(w1, "help2_txt") == 0)
- strcpy(map->help2_txt, w2);
- else if (strcmpi(w1, "charhelp_txt") == 0)
- strcpy(map->charhelp_txt, w2);
- else if(strcmpi(w1,"db_path") == 0)
- safestrncpy(map->db_path,w2,255);
- else if (strcmpi(w1, "enable_spy") == 0)
- map->enable_spy = config_switch(w2);
- else if (strcmpi(w1, "use_grf") == 0)
- map->enable_grf = config_switch(w2);
- else if (strcmpi(w1, "console_msg_log") == 0)
- showmsg->console_log = atoi(w2);//[Ind]
- else if (strcmpi(w1, "default_language") == 0)
- safestrncpy(map->default_lang_str, w2, sizeof(map->default_lang_str));
- else if (strcmpi(w1, "import") == 0)
- map->config_read(w2);
+/**
+ * Reads 'map_configuration/sql_connection' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool map_config_read_connection(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "map_configuration/sql_connection")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("map_config_read: map_configuration/sql_connection was not found in %s!\n", filename);
+ ShowWarning("map_config_read_connection: Defaulting sql_connection...\n");
+ return false;
+ }
+
+ libconfig->setting_lookup_int(setting, "db_port", &map->server_port);
+ libconfig->setting_lookup_mutable_string(setting, "db_hostname", map->server_ip, sizeof(map->server_ip));
+ libconfig->setting_lookup_mutable_string(setting, "db_username", map->server_id, sizeof(map->server_id));
+ libconfig->setting_lookup_mutable_string(setting, "db_password", map->server_pw, sizeof(map->server_pw));
+ libconfig->setting_lookup_mutable_string(setting, "db_database", map->server_db, sizeof(map->server_db));
+ libconfig->setting_lookup_mutable_string(setting, "default_codepage", map->default_codepage, sizeof(map->default_codepage));
+ return true;
+}
+
+/**
+ * Reads 'map_configuration/inter' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool map_config_read_inter(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+ const char *str = NULL;
+ char temp[24];
+ uint16 port;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "map_configuration/inter")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("map_config_read: map_configuration/inter was not found in %s!\n", filename);
+ return false;
+ }
+
+ // Login information
+ if (libconfig->setting_lookup_mutable_string(setting, "userid", temp, sizeof(temp)) == CONFIG_TRUE)
+ chrif->setuserid(temp);
+ if (libconfig->setting_lookup_mutable_string(setting, "passwd", temp, sizeof(temp)) == CONFIG_TRUE)
+ chrif->setpasswd(temp);
+
+ // Char and map-server information
+ if (libconfig->setting_lookup_string(setting, "char_ip", &str) == CONFIG_TRUE)
+ map->char_ip_set = chrif->setip(str);
+ if (libconfig->setting_lookup_uint16(setting, "char_port", &port) == CONFIG_TRUE)
+ chrif->setport(port);
+
+ if (libconfig->setting_lookup_string(setting, "map_ip", &str) == CONFIG_TRUE)
+ map->ip_set = clif->setip(str);
+ if (libconfig->setting_lookup_uint16(setting, "map_port", &port) == CONFIG_TRUE) {
+ clif->setport(port);
+ map->port = port;
+ }
+ if (libconfig->setting_lookup_string(setting, "bind_ip", &str) == CONFIG_TRUE)
+ clif->setbindip(str);
+
+ return true;
+}
+
+/**
+ * Reads 'map_configuration/database' and initializes required variables
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool map_config_read_database(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "map_configuration/database")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("map_config_read: map_configuration/database was not found in %s!\n", filename);
+ return false;
+ }
+ libconfig->setting_lookup_mutable_string(setting, "db_path", map->db_path, sizeof(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) {
+ if (map->autosave_interval < 1) // Revert to default saving
+ map->autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
else
- ShowWarning("Unknown setting '%s' in file %s\n", w1, cfgName);
+ map->autosave_interval *= 1000; // Pass from s to ms
+ }
+ if (libconfig->setting_lookup_int(setting, "minsave_time", &map->minsave_interval) == CONFIG_TRUE) {
+ if (map->minsave_interval < 1)
+ map->minsave_interval = 1;
}
- fclose(fp);
- return 0;
+ return true;
}
-int map_config_read_sub(char *cfgName) {
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
- nullpo_retr(1, cfgName);
- fp = fopen(cfgName,"r");
- if (fp == NULL) {
- ShowError("Map configuration file not found at: %s\n", cfgName);
- return 1;
+/**
+ * Reads 'map_configuration/map_list'/'map_configuration/map_removed' and adds
+ * or removes maps from map-server.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool map_config_read_map_list(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+ int i, count = 0;
+ struct DBMap *deleted_maps;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ deleted_maps = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_KEY, MAP_NAME_LENGTH);
+
+ // Remove maps
+ if ((setting = libconfig->lookup(config, "map_configuration/map_removed")) != NULL) {
+ count = libconfig->setting_length(setting);
+ for (i = 0; i < count; i++) {
+ const char *mapname;
+
+ if ((mapname = libconfig->setting_get_string_elem(setting, i)) == NULL || mapname[0] == '\0')
+ continue;
+
+ strdb_put(deleted_maps, mapname, NULL);
+
+ if (imported) // Map list is empty on the first run, only do this for imported files.
+ map->delmap(mapname);
+ }
+ }
+
+ if ((setting = libconfig->lookup(config, "map_configuration/map_list")) == NULL) {
+ db_destroy(deleted_maps);
+ if (imported)
+ return true;
+ ShowError("map_config_read_map_list: map_configuration/map_list was not found in %s!\n", filename);
+ return false;
}
- while (fgets(line, sizeof(line), fp)) {
- char* ptr;
+ // Add maps to map->list
+ count = libconfig->setting_length(setting);
- if (line[0] == '/' && line[1] == '/')
+ if (count <= 0) {
+ db_destroy(deleted_maps);
+ if (imported)
+ return true;
+ ShowWarning("map_config_read_map_list: no maps found in %s!\n", filename);
+ return false;
+ }
+
+ RECREATE(map->list, struct map_data, map->count + count); // TODO: VECTOR candidate
+
+ for (i = 0; i < count; i++) {
+ const char *mapname;
+
+ if ((mapname = libconfig->setting_get_string_elem(setting, i)) == NULL || mapname[0] == '\0')
continue;
- if ((ptr = strstr(line, "//")) != NULL)
- *ptr = '\n'; //Strip comments
- if (sscanf(line, "%1023[^:]: %1023[^\t\r\n]", w1, w2) < 2)
+
+ if (strdb_exists(deleted_maps, mapname))
continue;
- //Strip trailing spaces
- ptr = w2 + strlen(w2);
- while (--ptr >= w2 && *ptr == ' ');
- ptr++;
- *ptr = '\0';
+ map->addmap(mapname);
+ }
+
+ RECREATE(map->list, struct map_data, map->count);
+
+ db_destroy(deleted_maps);
+ return true;
+}
+
+/**
+ * Reads map-server configuration files (map-server.conf) and initialises
+ * required variables.
+ *
+ * @param filename Path to configuration file.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool map_config_read(const char *filename, bool imported)
+{
+ struct config_t config;
+ struct config_setting_t *setting = NULL;
+ const char *import = NULL;
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+
+ if (!libconfig->load_file(&config, filename))
+ return false;
- if (strcmpi(w1, "map") == 0)
- map->addmap(w2);
- else if (strcmpi(w1, "delmap") == 0)
- map->delmap(w2);
- else if (strcmpi(w1, "import") == 0)
- map->config_read_sub(w2);
+ if ((setting = libconfig->lookup(&config, "map_configuration")) == NULL) {
+ libconfig->destroy(&config);
+ if (imported)
+ return true;
+ ShowError("map_config_read: map_configuration was not found in %s!\n", filename);
+ return false;
}
- fclose(fp);
- return 0;
+ libconfig->setting_lookup_mutable_string(setting, "help_txt", map->help_txt, sizeof(map->help_txt));
+ libconfig->setting_lookup_mutable_string(setting, "charhelp_txt", map->charhelp_txt, sizeof(map->charhelp_txt));
+ libconfig->setting_lookup_bool(setting, "enable_spy", &map->enable_spy);
+ libconfig->setting_lookup_bool(setting, "use_grf", &map->enable_grf);
+ libconfig->setting_lookup_mutable_string(setting, "default_language", map->default_lang_str, sizeof(map->default_lang_str));
+
+ if (!map_config_read_console(filename, &config, imported))
+ retval = false;
+ if (!map_config_read_connection(filename, &config, imported))
+ retval = false;
+ if (!map_config_read_inter(filename, &config, imported))
+ retval = false;
+ if (!map_config_read_database(filename, &config, imported))
+ retval = false;
+ if (!map_config_read_map_list(filename, &config, imported))
+ retval = false;
+
+ // import should overwrite any previous configuration, so it should be called last
+ if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) {
+ if (strcmp(import, filename) == 0 || strcmp(import, map->MAP_CONF_NAME) == 0) {
+ ShowWarning("map_config_read: Loop detected! Skipping 'import'...\n");
+ } else {
+ if (!map->config_read(import, true))
+ retval = false;
+ }
+ }
+
+ libconfig->destroy(&config);
+ return retval;
}
-void map_reloadnpc_sub(char *cfgName) {
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
- nullpo_retv(cfgName);
- fp = fopen(cfgName,"r");
- if (fp == NULL) {
- ShowError("Map configuration file not found at: %s\n", cfgName);
- return;
+/**
+ * Reads 'npc_global_list'/'npc_removed_list' and adds or removes NPC sources
+ * from map-server.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool map_read_npclist(const char *filename, bool imported)
+{
+ struct config_t config;
+ struct config_setting_t *setting = NULL;
+ const char *import = NULL;
+ bool retval = true;
+
+ struct DBMap *deleted_npcs;
+
+ nullpo_retr(false, filename);
+
+ if (!libconfig->load_file(&config, filename))
+ return false;
+
+ deleted_npcs = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_KEY, MAP_NAME_LENGTH);
+
+ // Remove maps
+ if ((setting = libconfig->lookup(&config, "npc_removed_list")) != NULL) {
+ int i, del_count = libconfig->setting_length(setting);
+ for (i = 0; i < del_count; i++) {
+ const char *scriptname;
+
+ if ((scriptname = libconfig->setting_get_string_elem(setting, i)) == NULL || scriptname[0] == '\0')
+ continue;
+
+ strdb_put(deleted_npcs, scriptname, NULL);
+
+ if (imported) // Map list is empty on the first run, only do this for imported files.
+ npc->delsrcfile(scriptname);
+ }
}
- while (fgets(line, sizeof(line), fp)) {
- char* ptr;
+ if ((setting = libconfig->lookup(&config, "npc_global_list")) != NULL) {
+ int i, count = libconfig->setting_length(setting);
+ if (count <= 0) {
+ if (!imported) {
+ ShowWarning("map_read_npclist: no NPCs found in %s!\n", filename);
+ retval = false;
+ }
+ }
+ for (i = 0; i < count; i++) {
+ const char *scriptname;
- if (line[0] == '/' && line[1] == '/')
- continue;
- if ((ptr = strstr(line, "//")) != NULL)
- *ptr = '\n'; //Strip comments
- if (sscanf(line, "%1023[^:]: %1023[^\t\r\n]", w1, w2) < 2)
- continue;
+ if ((scriptname = libconfig->setting_get_string_elem(setting, i)) == NULL || scriptname[0] == '\0')
+ continue;
- //Strip trailing spaces
- ptr = w2 + strlen(w2);
- while (--ptr >= w2 && *ptr == ' ');
- ptr++;
- *ptr = '\0';
-
- if (strcmpi(w1, "npc") == 0)
- npc->addsrcfile(w2);
- else if (strcmpi(w1, "import") == 0)
- map->reloadnpc_sub(w2);
- else if (strcmpi(w1, "delnpc") == 0)
- npc->delsrcfile(w2);
- else
- ShowWarning("Unknown setting '%s' in file %s\n", w1, cfgName);
+ if (strdb_exists(deleted_npcs, scriptname))
+ continue;
+
+ npc->addsrcfile(scriptname);
+ }
+ } else {
+ ShowError("map_read_npclist: npc_global_list was not found in %s!\n", filename);
+ retval = false;
}
- fclose(fp);
+ db_destroy(deleted_npcs);
+
+ // import should overwrite any previous configuration, so it should be called last
+ if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) {
+ const char *base_npclist = NULL;
+#ifdef RENEWAL
+ base_npclist = "npc/re/scripts_main.conf";
+#else
+ base_npclist = "npc/pre-re/scripts_main.conf";
+#endif
+ if (strcmp(import, filename) == 0 || strcmp(import, base_npclist) == 0) {
+ ShowWarning("map_read_npclist: Loop detected! Skipping 'import'...\n");
+ } else {
+ if (!map->read_npclist(import, true))
+ retval = false;
+ }
+ }
+
+ libconfig->destroy(&config);
+ return retval;
}
/**
@@ -3986,9 +4211,9 @@ void map_reloadnpc(bool clear) {
npc->addsrcfile("clear"); // this will clear the current script list
#ifdef RENEWAL
- map->reloadnpc_sub("npc/re/scripts_main.conf");
+ map->read_npclist("npc/re/scripts_main.conf", false);
#else
- map->reloadnpc_sub("npc/pre-re/scripts_main.conf");
+ map->read_npclist("npc/pre-re/scripts_main.conf", false);
#endif
// Append extra scripts
@@ -3997,63 +4222,125 @@ void map_reloadnpc(bool clear) {
}
}
-int inter_config_read(char *cfgName) {
- char line[1024],w1[1024],w2[1024];
- FILE *fp;
+/**
+ * Reads inter-server.conf and initializes required variables.
+ *
+ * @param filename Path to configuration file
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool inter_config_read(const char *filename, bool imported)
+{
+ struct config_t config;
+ const struct config_setting_t *setting = NULL;
+ const char *import = NULL;
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+
+ if (!libconfig->load_file(&config, filename))
+ return false;
+
+ if ((setting = libconfig->lookup(&config, "inter_configuration")) == NULL) {
+ libconfig->destroy(&config);
+ if (imported)
+ return true;
+ ShowError("inter_config_read: inter_configuration was not found in %s!\n", filename);
+ return false;
+ }
+
+ if (!map->inter_config_read_database_names(filename, &config, imported))
+ retval = false;
+ if (!map->inter_config_read_connection(filename, &config, imported))
+ retval = false;
+
+ // TODO HPM->parseConf(w1, w2, HPCT_MAP_INTER);
+
+ // import should overwrite any previous configuration, so it should be called last
+ if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) {
+ if (strcmp(import, filename) == 0 || strcmp(import, map->INTER_CONF_NAME) == 0) {
+ ShowWarning("inter_config_read: Loop detected in %s! Skipping 'import'...\n", filename);
+ } else {
+ if (!map->inter_config_read(import, true))
+ retval = false;
+ }
+ }
+
+ libconfig->destroy(&config);
+ return retval;
+}
+
+/**
+ * Reads the 'inter_configuration/log/sql_connection' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool inter_config_read_connection(const char *filename, const struct config_t *config, bool imported)
+{
+ const struct config_setting_t *setting = NULL;
- nullpo_retr(1, cfgName);
- if (!(fp = fopen(cfgName,"r"))) {
- ShowError("File not found: %s\n",cfgName);
- return 1;
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "inter_configuration/log/sql_connection")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("inter_config_read: inter_configuration/log/sql_connection was not found in %s!\n", filename);
+ return false;
}
- while (fgets(line, sizeof(line), fp)) {
- if (line[0] == '/' && line[1] == '/')
- continue;
- if (sscanf(line,"%1023[^:]: %1023[^\r\n]", w1, w2) < 2)
- continue;
- /* map sql stuff */
- if(strcmpi(w1,"map_server_ip")==0)
- safestrncpy(map->server_ip, w2, sizeof(map->server_ip));
- else if(strcmpi(w1,"map_server_port")==0)
- map->server_port=atoi(w2);
- else if(strcmpi(w1,"map_server_id")==0)
- safestrncpy(map->server_id, w2, sizeof(map->server_id));
- else if(strcmpi(w1,"map_server_pw")==0)
- safestrncpy(map->server_pw, w2, sizeof(map->server_pw));
- else if(strcmpi(w1,"map_server_db")==0)
- safestrncpy(map->server_db, w2, sizeof(map->server_db));
- else if(strcmpi(w1,"default_codepage")==0)
- safestrncpy(map->default_codepage, w2, sizeof(map->default_codepage));
- else if(strcmpi(w1,"autotrade_merchants_db")==0)
- safestrncpy(map->autotrade_merchants_db, w2, sizeof(map->autotrade_merchants_db));
- else if(strcmpi(w1,"autotrade_data_db")==0)
- safestrncpy(map->autotrade_data_db, w2, sizeof(map->autotrade_data_db));
- else if(strcmpi(w1,"npc_market_data_db")==0)
- safestrncpy(map->npc_market_data_db, w2, sizeof(map->npc_market_data_db));
- /* sql log db */
- else if(strcmpi(w1,"log_db_ip")==0)
- safestrncpy(logs->db_ip, w2, sizeof(logs->db_ip));
- else if(strcmpi(w1,"log_db_id")==0)
- safestrncpy(logs->db_id, w2, sizeof(logs->db_id));
- else if(strcmpi(w1,"log_db_pw")==0)
- safestrncpy(logs->db_pw, w2, sizeof(logs->db_pw));
- else if(strcmpi(w1,"log_db_port")==0)
- logs->db_port = atoi(w2);
- else if(strcmpi(w1,"log_db_db")==0)
- safestrncpy(logs->db_name, w2, sizeof(logs->db_name));
- /* mapreg */
- else if( mapreg->config_read(w1,w2) )
- continue;
- /* import */
- else if(strcmpi(w1,"import")==0)
- map->inter_config_read(w2);
- else
- HPM->parseConf(w1, w2, HPCT_MAP_INTER);
+ libconfig->setting_lookup_int(setting, "port", &logs->db_port);
+ libconfig->setting_lookup_mutable_string(setting, "db_hostname", logs->db_ip, sizeof(logs->db_ip));
+ libconfig->setting_lookup_mutable_string(setting, "db_username", logs->db_id, sizeof(logs->db_id));
+ libconfig->setting_lookup_mutable_string(setting, "db_password", logs->db_pw, sizeof(logs->db_pw));
+ libconfig->setting_lookup_mutable_string(setting, "db_database", logs->db_name, sizeof(logs->db_name));
+
+ return true;
+}
+
+/**
+ * Reads the 'inter_configuration/database_names' config entry and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool inter_config_read_database_names(const char *filename, const struct config_t *config, bool imported)
+{
+ const struct config_setting_t *setting = NULL;
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "inter_configuration/database_names")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("inter_config_read: inter_configuration/database_names was not found in %s!\n", filename);
+ return false;
}
- fclose(fp);
- return 0;
+ libconfig->setting_lookup_mutable_string(setting, "autotrade_merchants_db", map->autotrade_merchants_db, sizeof(map->autotrade_merchants_db));
+ libconfig->setting_lookup_mutable_string(setting, "autotrade_data_db", map->autotrade_data_db, sizeof(map->autotrade_data_db));
+ libconfig->setting_lookup_mutable_string(setting, "npc_market_data_db", map->npc_market_data_db, sizeof(map->npc_market_data_db));
+
+ if (!mapreg->config_read(filename, setting, imported))
+ retval = false;
+
+ if ((setting = libconfig->lookup(config, "inter_configuration/database_names/registry")) == NULL) {
+ if (imported)
+ return retval;
+ ShowError("inter_config_read: inter_configuration/database_names/registry was not found in %s!\n", filename);
+ return false;
+ }
+ return retval;
}
/*=======================================
@@ -6077,12 +6364,12 @@ int do_init(int argc, char *argv[])
map_load_defaults();
- map->INTER_CONF_NAME = aStrdup("conf/inter-server.conf");
- map->LOG_CONF_NAME = aStrdup("conf/logs.conf");
- map->MAP_CONF_NAME = aStrdup("conf/map-server.conf");
- map->BATTLE_CONF_FILENAME = aStrdup("conf/battle.conf");
+ map->INTER_CONF_NAME = aStrdup("conf/common/inter-server.conf");
+ map->LOG_CONF_NAME = aStrdup("conf/map/logs.conf");
+ map->MAP_CONF_NAME = aStrdup("conf/map/map-server.conf");
+ map->BATTLE_CONF_FILENAME = aStrdup("conf/map/battle.conf");
map->ATCOMMAND_CONF_FILENAME = aStrdup("conf/atcommand.conf");
- map->SCRIPT_CONF_NAME = aStrdup("conf/script.conf");
+ map->SCRIPT_CONF_NAME = aStrdup("conf/map/script.conf");
map->MSG_CONF_NAME = aStrdup("conf/messages.conf");
map->GRF_PATH_FILENAME = aStrdup("conf/grf-files.txt");
@@ -6095,10 +6382,30 @@ int do_init(int argc, char *argv[])
cmdline->exec(argc, argv, CMDLINE_OPT_NORMAL);
minimal = map->minimal;/* temp (perhaps make minimal a mask with options of what to load? e.g. plugin 1 does minimal |= mob_db; */
if (!minimal) {
- map->config_read(map->MAP_CONF_NAME);
- CREATE(map->list,struct map_data,map->count);
- map->count = 0;
- map->config_read_sub(map->MAP_CONF_NAME);
+ map->config_read(map->MAP_CONF_NAME, false);
+
+ {
+ // TODO: Remove this when no longer needed.
+#define CHECK_OLD_LOCAL_CONF(oldname, newname) do { \
+ if (stat((oldname), &fileinfo) == 0 && fileinfo.st_size > 0) { \
+ ShowWarning("An old configuration file \"%s\" was found.\n", (oldname)); \
+ ShowWarning("If it contains settings you wish to keep, please merge them into \"%s\".\n", (newname)); \
+ ShowWarning("Otherwise, just delete it.\n"); \
+ ShowInfo("Resuming in 10 seconds...\n"); \
+ HSleep(10); \
+ } \
+} while (0)
+ struct stat fileinfo;
+
+ CHECK_OLD_LOCAL_CONF("conf/import/map_conf.txt", "conf/import/map-server.conf");
+ CHECK_OLD_LOCAL_CONF("conf/import/inter_conf.txt", "conf/import/inter-server.conf");
+ CHECK_OLD_LOCAL_CONF("conf/import/log_conf.txt", "conf/import/logs.conf");
+ CHECK_OLD_LOCAL_CONF("conf/import/script_conf.txt", "conf/import/script.conf");
+ CHECK_OLD_LOCAL_CONF("conf/import/packet_conf.txt", "conf/import/socket.conf");
+ CHECK_OLD_LOCAL_CONF("conf/import/battle_conf.txt", "conf/import/battle.conf");
+
+#undef CHECK_OLD_LOCAL_CONF
+ }
// loads npcs
map->reloadnpc(false);
@@ -6110,7 +6417,7 @@ int do_init(int argc, char *argv[])
sockt->ip2str(sockt->addr_[0], ip_str);
#ifndef BUILDBOT
- ShowWarning("Not all IP addresses in /conf/map-server.conf configured, auto-detecting...\n");
+ ShowWarning("Not all IP addresses in /conf/map/map-server.conf configured, auto-detecting...\n");
#endif
if (sockt->naddr_ == 0)
@@ -6126,12 +6433,12 @@ int do_init(int argc, char *argv[])
chrif->setip(ip_str);
}
- battle->config_read(map->BATTLE_CONF_FILENAME);
+ battle->config_read(map->BATTLE_CONF_FILENAME, false);
atcommand->msg_read(map->MSG_CONF_NAME, false);
- map->inter_config_read(map->INTER_CONF_NAME);
- logs->config_read(map->LOG_CONF_NAME);
+ map->inter_config_read(map->INTER_CONF_NAME, false);
+ logs->config_read(map->LOG_CONF_NAME, false);
}
- script->config_read(map->SCRIPT_CONF_NAME);
+ script->config_read(map->SCRIPT_CONF_NAME, false);
map->id_db = idb_alloc(DB_OPT_BASE);
map->pc_db = idb_alloc(DB_OPT_BASE); //Added for reliable map->id2sd() use. [Skotlex]
@@ -6275,7 +6582,6 @@ void map_defaults(void) {
sprintf(map->db_path ,"db");
sprintf(map->help_txt ,"conf/help.txt");
- sprintf(map->help2_txt ,"conf/help2.txt");
sprintf(map->charhelp_txt ,"conf/charhelp.txt");
sprintf(map->wisp_server_name ,"Server"); // can be modified in char-server configuration file
@@ -6288,12 +6594,12 @@ void map_defaults(void) {
map->night_flag = 0; // 0=day, 1=night [Yor]
map->enable_spy = 0; //To enable/disable @spy commands, which consume too much cpu time when sending packets. [Skotlex]
- map->INTER_CONF_NAME="conf/inter-server.conf";
- map->LOG_CONF_NAME="conf/logs.conf";
- map->MAP_CONF_NAME = "conf/map-server.conf";
- map->BATTLE_CONF_FILENAME = "conf/battle.conf";
+ map->INTER_CONF_NAME="conf/common/inter-server.conf";
+ map->LOG_CONF_NAME="conf/map/logs.conf";
+ map->MAP_CONF_NAME = "conf/map/map-server.conf";
+ map->BATTLE_CONF_FILENAME = "conf/map/battle.conf";
map->ATCOMMAND_CONF_FILENAME = "conf/atcommand.conf";
- map->SCRIPT_CONF_NAME = "conf/script.conf";
+ map->SCRIPT_CONF_NAME = "conf/map/script.conf";
map->MSG_CONF_NAME = "conf/messages.conf";
map->GRF_PATH_FILENAME = "conf/grf-files.txt";
@@ -6499,9 +6805,10 @@ void map_defaults(void) {
map->readgat = map_readgat;
map->readallmaps = map_readallmaps;
map->config_read = map_config_read;
- map->config_read_sub = map_config_read_sub;
- map->reloadnpc_sub = map_reloadnpc_sub;
+ map->read_npclist = map_read_npclist;
map->inter_config_read = inter_config_read;
+ map->inter_config_read_database_names = inter_config_read_database_names;
+ map->inter_config_read_connection = inter_config_read_connection;
map->sql_init = map_sql_init;
map->sql_close = map_sql_close;
map->zone_mf_cache = map_zone_mf_cache;
diff --git a/src/map/map.h b/src/map/map.h
index dbd30febf..723691971 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -33,6 +33,7 @@
/* Forward Declarations */
struct Sql; // common/sql.h
+struct config_t; // common/conf.h
struct mob_data;
struct npc_data;
struct channel_data;
@@ -967,7 +968,6 @@ struct map_interface {
char db_path[256];
char help_txt[256];
- char help2_txt[256];
char charhelp_txt[256];
char wisp_server_name[NAME_LENGTH];
@@ -996,7 +996,7 @@ struct map_interface {
char server_db[32];
struct Sql *mysql_handle;
- int port;
+ uint16 port;
int users;
int enable_grf; //To enable/disable reading maps from GRF files, bypassing mapcache [blackhole89]
bool ip_set;
@@ -1147,7 +1147,7 @@ END_ZEROED_BLOCK;
int (*cleanup_sub) (struct block_list *bl, va_list ap);
- int (*delmap) (char* mapname);
+ int (*delmap) (const char *mapname);
void (*flags_init) (void);
bool (*iwall_set) (int16 m, int16 x, int16 y, int size, int8 dir, bool shootable, const char* wall_name);
@@ -1187,10 +1187,11 @@ END_ZEROED_BLOCK;
int (*waterheight) (char *mapname);
int (*readgat) (struct map_data *m);
int (*readallmaps) (void);
- int (*config_read) (char *cfgName);
- int (*config_read_sub) (char *cfgName);
- void (*reloadnpc_sub) (char *cfgName);
- int (*inter_config_read) (char *cfgName);
+ bool (*config_read) (const char *filename, bool imported);
+ bool (*read_npclist) (const char *filename, bool imported);
+ bool (*inter_config_read) (const char *filename, bool imported);
+ bool (*inter_config_read_database_names) (const char *filename, const struct config_t *config, bool imported);
+ bool (*inter_config_read_connection) (const char *filename, const struct config_t *config, bool imported);
int (*sql_init) (void);
int (*sql_close) (void);
bool (*zone_mf_cache) (int m, char *flag, char *params);
diff --git a/src/map/mapreg.h b/src/map/mapreg.h
index d19b2bb80..642bce48e 100644
--- a/src/map/mapreg.h
+++ b/src/map/mapreg.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -25,6 +25,8 @@
#include "common/hercules.h"
#include "common/db.h"
+/* Forward Declarations */
+struct config_setting_t; // common/conf.h
struct eri;
/** Container for a mapreg value */
@@ -61,7 +63,7 @@ struct mapreg_interface {
int (*save_timer) (int tid, int64 tick, int id, intptr_t data);
int (*destroyreg) (union DBKey key, struct DBData *data, va_list ap);
void (*reload) (void);
- bool (*config_read) (const char *w1, const char *w2);
+ bool (*config_read) (const char *filename, const struct config_setting_t *config, bool imported);
};
#ifdef HERCULES_CORE
diff --git a/src/map/mapreg_sql.c b/src/map/mapreg_sql.c
index 82ce39d64..4cdb91b21 100644
--- a/src/map/mapreg_sql.c
+++ b/src/map/mapreg_sql.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -25,6 +25,7 @@
#include "map/map.h" // map-"mysql_handle
#include "map/script.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/db.h"
#include "common/ers.h"
#include "common/memmgr.h"
@@ -349,13 +350,19 @@ void mapreg_init(void) {
/**
* Loads the mapreg configuration file.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
*/
-bool mapreg_config_read(const char* w1, const char* w2) {
- nullpo_retr(false, w1);
- nullpo_retr(false, w2);
- if(!strcmpi(w1, "mapreg_db"))
- safestrncpy(mapreg->table, w2, sizeof(mapreg->table));
- else
+bool mapreg_config_read(const char *filename, const struct config_setting_t *config, bool imported)
+{
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if (libconfig->setting_lookup_mutable_string(config, "mapreg_db", mapreg->table, sizeof(mapreg->table)) != CONFIG_TRUE)
return false;
return true;
diff --git a/src/map/script.c b/src/map/script.c
index 353d57a67..09cefa500 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -4521,52 +4521,55 @@ void run_script_main(struct script_state *st) {
}
}
-int script_config_read(char *cfgName) {
- int i;
- char line[1024],w1[1024],w2[1024];
- FILE *fp;
+/**
+ * Reads 'script_configuration' and initializes required variables.
+ *
+ * @param filename Path to configuration file.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool script_config_read(const char *filename, bool imported)
+{
+ struct config_t config;
+ struct config_setting_t * setting = NULL;
+ const char *import = NULL;
+ bool retval = true;
- if( !( fp = fopen(cfgName,"r") ) ) {
- ShowError("File not found: %s\n", cfgName);
- return 1;
+ nullpo_retr(false, filename);
+
+ if (!libconfig->load_file(&config, filename))
+ return false;
+
+ if ((setting = libconfig->lookup(&config, "script_configuration")) == NULL) {
+ libconfig->destroy(&config);
+ if (imported)
+ return true;
+ ShowError("script_config_read: script_configuration was not found in %s!\n", filename);
+ return false;
}
- while (fgets(line, sizeof(line), fp)) {
- if (line[0] == '/' && line[1] == '/')
- continue;
- i = sscanf(line,"%1023[^:]: %1023[^\r\n]", w1, w2);
- if(i!=2)
- continue;
- if(strcmpi(w1,"warn_func_mismatch_paramnum")==0) {
- script->config.warn_func_mismatch_paramnum = config_switch(w2);
- }
- else if(strcmpi(w1,"check_cmdcount")==0) {
- script->config.check_cmdcount = config_switch(w2);
- }
- else if(strcmpi(w1,"check_gotocount")==0) {
- script->config.check_gotocount = config_switch(w2);
- }
- else if(strcmpi(w1,"input_min_value")==0) {
- script->config.input_min_value = config_switch(w2);
- }
- else if(strcmpi(w1,"input_max_value")==0) {
- script->config.input_max_value = config_switch(w2);
- }
- else if(strcmpi(w1,"warn_func_mismatch_argtypes")==0) {
- script->config.warn_func_mismatch_argtypes = config_switch(w2);
- }
- else if(strcmpi(w1,"import")==0) {
- script->config_read(w2);
- }
- else if(HPM->parseConf(w1, w2, HPCT_SCRIPT)) {
- ; // handled by plugin
+ libconfig->setting_lookup_bool_real(setting, "warn_func_mismatch_paramnum", &script->config.warn_func_mismatch_paramnum);
+ libconfig->setting_lookup_bool_real(setting, "warn_func_mismatch_argtypes", &script->config.warn_func_mismatch_argtypes);
+ libconfig->setting_lookup_int(setting, "check_cmdcount", &script->config.check_cmdcount);
+ libconfig->setting_lookup_int(setting, "check_gotocount", &script->config.check_gotocount);
+ libconfig->setting_lookup_int(setting, "input_min_value", &script->config.input_min_value);
+ libconfig->setting_lookup_int(setting, "input_max_value", &script->config.input_max_value);
+
+ // TODO HPM->parseConf(w1, w2, HPCT_SCRIPT));
+
+ // import should overwrite any previous configuration, so it should be called last
+ if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) {
+ if (strcmp(import, filename) == 0 || strcmp(import, map->SCRIPT_CONF_NAME) == 0) {
+ ShowWarning("script_config_read: Loop detected! Skipping 'import'...\n");
} else {
- ShowWarning("Unknown setting '%s' in file %s\n", w1, cfgName);
+ if (!script->config_read(import, true))
+ retval = false;
}
}
- fclose(fp);
- return 0;
+ libconfig->destroy(&config);
+ return retval;
}
/**
@@ -21449,8 +21452,8 @@ void script_defaults(void) {
script->getfuncname = script_getfuncname;
/* script_config base */
- script->config.warn_func_mismatch_argtypes = 1;
- script->config.warn_func_mismatch_paramnum = 1;
+ script->config.warn_func_mismatch_argtypes = true;
+ script->config.warn_func_mismatch_paramnum = true;
script->config.check_cmdcount = 65535;
script->config.check_gotocount = 2048;
script->config.input_min_value = 0;
diff --git a/src/map/script.h b/src/map/script.h
index 86cb20226..c4c082263 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -343,8 +343,8 @@ enum {
**/
struct Script_Config {
- unsigned warn_func_mismatch_argtypes : 1;
- unsigned warn_func_mismatch_paramnum : 1;
+ bool warn_func_mismatch_argtypes;
+ bool warn_func_mismatch_paramnum;
int check_cmdcount;
int check_gotocount;
int input_min_value;
@@ -692,7 +692,7 @@ struct script_interface {
void (*run_autobonus) (const char *autobonus,int id, int pos);
void (*cleararray_pc) (struct map_session_data* sd, const char* varname, void* value);
void (*setarray_pc) (struct map_session_data* sd, const char* varname, uint32 idx, void* value, int* refcache);
- int (*config_read) (char *cfgName);
+ bool (*config_read) (const char *filename, bool imported);
int (*add_str) (const char* p);
const char* (*get_str) (int id);
int (*search_str) (const char* p);
diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc
index 2023730f7..4061bd4d4 100644
--- a/src/plugins/HPMHooking/HPMHooking.Defs.inc
+++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc
@@ -198,12 +198,14 @@ typedef int64 (*HPMHOOK_pre_battle_add_mastery) (struct map_session_data **sd, s
typedef int64 (*HPMHOOK_post_battle_add_mastery) (int64 retVal___, struct map_session_data *sd, struct block_list *target, int64 dmg, int type);
typedef int (*HPMHOOK_pre_battle_calc_drain) (int64 *damage, int *rate, int *per);
typedef int (*HPMHOOK_post_battle_calc_drain) (int retVal___, int64 damage, int rate, int per);
-typedef int (*HPMHOOK_pre_battle_config_read) (const char **cfgName);
-typedef int (*HPMHOOK_post_battle_config_read) (int retVal___, const char *cfgName);
+typedef bool (*HPMHOOK_pre_battle_config_read) (const char **filename, bool *imported);
+typedef bool (*HPMHOOK_post_battle_config_read) (bool retVal___, const char *filename, bool imported);
typedef void (*HPMHOOK_pre_battle_config_set_defaults) (void);
typedef void (*HPMHOOK_post_battle_config_set_defaults) (void);
-typedef int (*HPMHOOK_pre_battle_config_set_value) (const char **w1, const char **w2);
-typedef int (*HPMHOOK_post_battle_config_set_value) (int retVal___, const char *w1, const char *w2);
+typedef bool (*HPMHOOK_pre_battle_config_set_value_sub) (int *index, int *value);
+typedef bool (*HPMHOOK_post_battle_config_set_value_sub) (bool retVal___, int index, int value);
+typedef bool (*HPMHOOK_pre_battle_config_set_value) (const char **param, const char **value);
+typedef bool (*HPMHOOK_post_battle_config_set_value) (bool retVal___, const char *param, const char *value);
typedef bool (*HPMHOOK_pre_battle_config_get_value) (const char **w1, int **value);
typedef bool (*HPMHOOK_post_battle_config_get_value) (bool retVal___, const char *w1, int *value);
typedef void (*HPMHOOK_pre_battle_config_adjust) (void);
@@ -658,12 +660,40 @@ typedef int (*HPMHOOK_pre_chr_online_data_cleanup_sub) (union DBKey *key, struct
typedef int (*HPMHOOK_post_chr_online_data_cleanup_sub) (int retVal___, union DBKey key, struct DBData *data, va_list ap);
typedef int (*HPMHOOK_pre_chr_online_data_cleanup) (int *tid, int64 *tick, int *id, intptr_t *data);
typedef int (*HPMHOOK_post_chr_online_data_cleanup) (int retVal___, int tid, int64 tick, int id, intptr_t data);
-typedef void (*HPMHOOK_pre_chr_sql_config_read) (const char **cfgName);
-typedef void (*HPMHOOK_post_chr_sql_config_read) (const char *cfgName);
-typedef void (*HPMHOOK_pre_chr_config_dispatch) (char **w1, char **w2);
-typedef void (*HPMHOOK_post_chr_config_dispatch) (char *w1, char *w2);
-typedef int (*HPMHOOK_pre_chr_config_read) (const char **cfgName);
-typedef int (*HPMHOOK_post_chr_config_read) (int retVal___, const char *cfgName);
+typedef bool (*HPMHOOK_pre_chr_sql_config_read) (const char **filename, bool *imported);
+typedef bool (*HPMHOOK_post_chr_sql_config_read) (bool retVal___, const char *filename, bool imported);
+typedef bool (*HPMHOOK_pre_chr_sql_config_read_registry) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_chr_sql_config_read_registry) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+typedef bool (*HPMHOOK_pre_chr_sql_config_read_pc) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_chr_sql_config_read_pc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+typedef bool (*HPMHOOK_pre_chr_sql_config_read_guild) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_chr_sql_config_read_guild) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+typedef bool (*HPMHOOK_pre_chr_config_read) (const char **filename, bool *imported);
+typedef bool (*HPMHOOK_post_chr_config_read) (bool retVal___, const char *filename, bool imported);
+typedef bool (*HPMHOOK_pre_chr_config_read_database) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_chr_config_read_database) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+typedef bool (*HPMHOOK_pre_chr_config_read_console) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_chr_config_read_console) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+typedef bool (*HPMHOOK_pre_chr_config_read_player_fame) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_chr_config_read_player_fame) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+typedef bool (*HPMHOOK_pre_chr_config_read_player_deletion) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_chr_config_read_player_deletion) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+typedef bool (*HPMHOOK_pre_chr_config_read_player_name) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_chr_config_read_player_name) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+typedef void (*HPMHOOK_pre_chr_config_set_start_item) (const struct config_setting_t **setting);
+typedef void (*HPMHOOK_post_chr_config_set_start_item) (const struct config_setting_t *setting);
+typedef bool (*HPMHOOK_pre_chr_config_read_player_new) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_chr_config_read_player_new) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+typedef bool (*HPMHOOK_pre_chr_config_read_player) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_chr_config_read_player) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+typedef bool (*HPMHOOK_pre_chr_config_read_permission) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_chr_config_read_permission) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+typedef bool (*HPMHOOK_pre_chr_config_set_ip) (const char **type, const char **value, uint32 **out_ip, char **out_ip_str);
+typedef bool (*HPMHOOK_post_chr_config_set_ip) (bool retVal___, const char *type, const char *value, uint32 *out_ip, char *out_ip_str);
+typedef bool (*HPMHOOK_pre_chr_config_read_inter) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_chr_config_read_inter) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+typedef bool (*HPMHOOK_pre_chr_config_read_top) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_chr_config_read_top) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
#endif // CHAR_CHAR_H
#ifdef MAP_CHAT_H /* chat */
typedef bool (*HPMHOOK_pre_chat_create_pc_chat) (struct map_session_data **sd, const char **title, const char **pass, int *limit, bool *pub);
@@ -2828,8 +2858,6 @@ typedef void (*HPMHOOK_pre_inter_savereg) (int *account_id, int *char_id, const
typedef void (*HPMHOOK_post_inter_savereg) (int account_id, int char_id, const char *key, unsigned int index, intptr_t val, bool is_string);
typedef int (*HPMHOOK_pre_inter_accreg_fromsql) (int *account_id, int *char_id, int *fd, int *type);
typedef int (*HPMHOOK_post_inter_accreg_fromsql) (int retVal___, int account_id, int char_id, int fd, int type);
-typedef int (*HPMHOOK_pre_inter_config_read) (const char **cfgName);
-typedef int (*HPMHOOK_post_inter_config_read) (int retVal___, const char *cfgName);
typedef int (*HPMHOOK_pre_inter_vlog) (char **fmt, va_list ap);
typedef int (*HPMHOOK_post_inter_vlog) (int retVal___, char *fmt, va_list ap);
typedef int (*HPMHOOK_pre_inter_init_sql) (const char **file);
@@ -2846,6 +2874,10 @@ typedef int (*HPMHOOK_pre_inter_parse_frommap) (int *fd);
typedef int (*HPMHOOK_post_inter_parse_frommap) (int retVal___, int fd);
typedef void (*HPMHOOK_pre_inter_final) (void);
typedef void (*HPMHOOK_post_inter_final) (void);
+typedef bool (*HPMHOOK_pre_inter_config_read) (const char **filename, bool *imported);
+typedef bool (*HPMHOOK_post_inter_config_read) (bool retVal___, const char *filename, bool imported);
+typedef bool (*HPMHOOK_pre_inter_config_read_connection) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_inter_config_read_connection) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
#endif // CHAR_INTER_H
#ifdef CHAR_INT_MAIL_H /* inter_mail */
typedef int (*HPMHOOK_pre_inter_mail_sql_init) (void);
@@ -3588,8 +3620,8 @@ typedef void (*HPMHOOK_pre_logs_branch_sub) (struct map_session_data **sd);
typedef void (*HPMHOOK_post_logs_branch_sub) (struct map_session_data *sd);
typedef void (*HPMHOOK_pre_logs_mvpdrop_sub) (struct map_session_data **sd, int *monster_id, int **log_mvp);
typedef void (*HPMHOOK_post_logs_mvpdrop_sub) (struct map_session_data *sd, int monster_id, int *log_mvp);
-typedef int (*HPMHOOK_pre_logs_config_read) (const char **cfgName);
-typedef int (*HPMHOOK_post_logs_config_read) (int retVal___, const char *cfgName);
+typedef bool (*HPMHOOK_pre_logs_config_read) (const char **filename, bool *imported);
+typedef bool (*HPMHOOK_post_logs_config_read) (bool retVal___, const char *filename, bool imported);
typedef void (*HPMHOOK_pre_logs_config_done) (void);
typedef void (*HPMHOOK_post_logs_config_done) (void);
typedef void (*HPMHOOK_pre_logs_sql_init) (void);
@@ -3700,8 +3732,8 @@ typedef void (*HPMHOOK_pre_login_parse_request_connection) (int *fd, struct logi
typedef void (*HPMHOOK_post_login_parse_request_connection) (int fd, struct login_session_data *sd, const char *ip, uint32 ipl);
typedef void (*HPMHOOK_pre_login_config_set_defaults) (void);
typedef void (*HPMHOOK_post_login_config_set_defaults) (void);
-typedef int (*HPMHOOK_pre_login_config_read) (const char **cfgName);
-typedef int (*HPMHOOK_post_login_config_read) (int retVal___, const char *cfgName);
+typedef bool (*HPMHOOK_pre_login_config_read) (const char **filename, bool *included);
+typedef bool (*HPMHOOK_post_login_config_read) (bool retVal___, const char *filename, bool included);
#endif // LOGIN_LOGIN_H
#ifdef CHAR_LOGINIF_H /* loginif */
typedef void (*HPMHOOK_pre_loginif_init) (void);
@@ -3936,8 +3968,8 @@ typedef int (*HPMHOOK_pre_map_random_dir) (struct block_list **bl, short **x, sh
typedef int (*HPMHOOK_post_map_random_dir) (int retVal___, struct block_list *bl, short *x, short *y);
typedef int (*HPMHOOK_pre_map_cleanup_sub) (struct block_list **bl, va_list ap);
typedef int (*HPMHOOK_post_map_cleanup_sub) (int retVal___, struct block_list *bl, va_list ap);
-typedef int (*HPMHOOK_pre_map_delmap) (char **mapname);
-typedef int (*HPMHOOK_post_map_delmap) (int retVal___, char *mapname);
+typedef int (*HPMHOOK_pre_map_delmap) (const char **mapname);
+typedef int (*HPMHOOK_post_map_delmap) (int retVal___, const char *mapname);
typedef void (*HPMHOOK_pre_map_flags_init) (void);
typedef void (*HPMHOOK_post_map_flags_init) (void);
typedef bool (*HPMHOOK_pre_map_iwall_set) (int16 *m, int16 *x, int16 *y, int *size, int8 *dir, bool *shootable, const char **wall_name);
@@ -4006,14 +4038,16 @@ typedef int (*HPMHOOK_pre_map_readgat) (struct map_data **m);
typedef int (*HPMHOOK_post_map_readgat) (int retVal___, struct map_data *m);
typedef int (*HPMHOOK_pre_map_readallmaps) (void);
typedef int (*HPMHOOK_post_map_readallmaps) (int retVal___);
-typedef int (*HPMHOOK_pre_map_config_read) (char **cfgName);
-typedef int (*HPMHOOK_post_map_config_read) (int retVal___, char *cfgName);
-typedef int (*HPMHOOK_pre_map_config_read_sub) (char **cfgName);
-typedef int (*HPMHOOK_post_map_config_read_sub) (int retVal___, char *cfgName);
-typedef void (*HPMHOOK_pre_map_reloadnpc_sub) (char **cfgName);
-typedef void (*HPMHOOK_post_map_reloadnpc_sub) (char *cfgName);
-typedef int (*HPMHOOK_pre_map_inter_config_read) (char **cfgName);
-typedef int (*HPMHOOK_post_map_inter_config_read) (int retVal___, char *cfgName);
+typedef bool (*HPMHOOK_pre_map_config_read) (const char **filename, bool *imported);
+typedef bool (*HPMHOOK_post_map_config_read) (bool retVal___, const char *filename, bool imported);
+typedef bool (*HPMHOOK_pre_map_read_npclist) (const char **filename, bool *imported);
+typedef bool (*HPMHOOK_post_map_read_npclist) (bool retVal___, const char *filename, bool imported);
+typedef bool (*HPMHOOK_pre_map_inter_config_read) (const char **filename, bool *imported);
+typedef bool (*HPMHOOK_post_map_inter_config_read) (bool retVal___, const char *filename, bool imported);
+typedef bool (*HPMHOOK_pre_map_inter_config_read_database_names) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_map_inter_config_read_database_names) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+typedef bool (*HPMHOOK_pre_map_inter_config_read_connection) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_map_inter_config_read_connection) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
typedef int (*HPMHOOK_pre_map_sql_init) (void);
typedef int (*HPMHOOK_post_map_sql_init) (int retVal___);
typedef int (*HPMHOOK_pre_map_sql_close) (void);
@@ -4448,8 +4482,8 @@ typedef int (*HPMHOOK_pre_mapreg_destroyreg) (union DBKey *key, struct DBData **
typedef int (*HPMHOOK_post_mapreg_destroyreg) (int retVal___, union DBKey key, struct DBData *data, va_list ap);
typedef void (*HPMHOOK_pre_mapreg_reload) (void);
typedef void (*HPMHOOK_post_mapreg_reload) (void);
-typedef bool (*HPMHOOK_pre_mapreg_config_read) (const char **w1, const char **w2);
-typedef bool (*HPMHOOK_post_mapreg_config_read) (bool retVal___, const char *w1, const char *w2);
+typedef bool (*HPMHOOK_pre_mapreg_config_read) (const char **filename, const struct config_setting_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_mapreg_config_read) (bool retVal___, const char *filename, const struct config_setting_t *config, bool imported);
#endif // MAP_MAPREG_H
#ifdef COMMON_MD5CALC_H /* md5 */
typedef void (*HPMHOOK_pre_md5_string) (const char **string, char **output);
@@ -5682,8 +5716,8 @@ typedef int (*HPMHOOK_pre_pincode_compare) (int *fd, struct char_session_data **
typedef int (*HPMHOOK_post_pincode_compare) (int retVal___, int fd, struct char_session_data *sd, char *pin);
typedef void (*HPMHOOK_pre_pincode_check) (int *fd, struct char_session_data **sd);
typedef void (*HPMHOOK_post_pincode_check) (int fd, struct char_session_data *sd);
-typedef bool (*HPMHOOK_pre_pincode_config_read) (char **w1, char **w2);
-typedef bool (*HPMHOOK_post_pincode_config_read) (bool retVal___, char *w1, char *w2);
+typedef bool (*HPMHOOK_pre_pincode_config_read) (const char **filename, const struct config_t **config, bool *imported);
+typedef bool (*HPMHOOK_post_pincode_config_read) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
#endif // CHAR_PINCODE_H
#ifdef MAP_QUEST_H /* quest */
typedef void (*HPMHOOK_pre_quest_init) (bool *minimal);
@@ -5840,8 +5874,8 @@ typedef void (*HPMHOOK_pre_script_cleararray_pc) (struct map_session_data **sd,
typedef void (*HPMHOOK_post_script_cleararray_pc) (struct map_session_data *sd, const char *varname, void *value);
typedef void (*HPMHOOK_pre_script_setarray_pc) (struct map_session_data **sd, const char **varname, uint32 *idx, void **value, int **refcache);
typedef void (*HPMHOOK_post_script_setarray_pc) (struct map_session_data *sd, const char *varname, uint32 idx, void *value, int *refcache);
-typedef int (*HPMHOOK_pre_script_config_read) (char **cfgName);
-typedef int (*HPMHOOK_post_script_config_read) (int retVal___, char *cfgName);
+typedef bool (*HPMHOOK_pre_script_config_read) (const char **filename, bool *imported);
+typedef bool (*HPMHOOK_post_script_config_read) (bool retVal___, const char *filename, bool imported);
typedef int (*HPMHOOK_pre_script_add_str) (const char **p);
typedef int (*HPMHOOK_post_script_add_str) (int retVal___, const char *p);
typedef const char* (*HPMHOOK_pre_script_get_str) (int *id);
diff --git a/src/plugins/HPMHooking/HPMHooking_char.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_char.HPMHooksCore.inc
index f51ddcffc..44b56143f 100644
--- a/src/plugins/HPMHooking/HPMHooking_char.HPMHooksCore.inc
+++ b/src/plugins/HPMHooking/HPMHooking_char.HPMHooksCore.inc
@@ -344,10 +344,38 @@ struct {
struct HPMHookPoint *HP_chr_online_data_cleanup_post;
struct HPMHookPoint *HP_chr_sql_config_read_pre;
struct HPMHookPoint *HP_chr_sql_config_read_post;
- struct HPMHookPoint *HP_chr_config_dispatch_pre;
- struct HPMHookPoint *HP_chr_config_dispatch_post;
+ struct HPMHookPoint *HP_chr_sql_config_read_registry_pre;
+ struct HPMHookPoint *HP_chr_sql_config_read_registry_post;
+ struct HPMHookPoint *HP_chr_sql_config_read_pc_pre;
+ struct HPMHookPoint *HP_chr_sql_config_read_pc_post;
+ struct HPMHookPoint *HP_chr_sql_config_read_guild_pre;
+ struct HPMHookPoint *HP_chr_sql_config_read_guild_post;
struct HPMHookPoint *HP_chr_config_read_pre;
struct HPMHookPoint *HP_chr_config_read_post;
+ struct HPMHookPoint *HP_chr_config_read_database_pre;
+ struct HPMHookPoint *HP_chr_config_read_database_post;
+ struct HPMHookPoint *HP_chr_config_read_console_pre;
+ struct HPMHookPoint *HP_chr_config_read_console_post;
+ struct HPMHookPoint *HP_chr_config_read_player_fame_pre;
+ struct HPMHookPoint *HP_chr_config_read_player_fame_post;
+ struct HPMHookPoint *HP_chr_config_read_player_deletion_pre;
+ struct HPMHookPoint *HP_chr_config_read_player_deletion_post;
+ struct HPMHookPoint *HP_chr_config_read_player_name_pre;
+ struct HPMHookPoint *HP_chr_config_read_player_name_post;
+ struct HPMHookPoint *HP_chr_config_set_start_item_pre;
+ struct HPMHookPoint *HP_chr_config_set_start_item_post;
+ struct HPMHookPoint *HP_chr_config_read_player_new_pre;
+ struct HPMHookPoint *HP_chr_config_read_player_new_post;
+ struct HPMHookPoint *HP_chr_config_read_player_pre;
+ struct HPMHookPoint *HP_chr_config_read_player_post;
+ struct HPMHookPoint *HP_chr_config_read_permission_pre;
+ struct HPMHookPoint *HP_chr_config_read_permission_post;
+ struct HPMHookPoint *HP_chr_config_set_ip_pre;
+ struct HPMHookPoint *HP_chr_config_set_ip_post;
+ struct HPMHookPoint *HP_chr_config_read_inter_pre;
+ struct HPMHookPoint *HP_chr_config_read_inter_post;
+ struct HPMHookPoint *HP_chr_config_read_top_pre;
+ struct HPMHookPoint *HP_chr_config_read_top_post;
struct HPMHookPoint *HP_cmdline_init_pre;
struct HPMHookPoint *HP_cmdline_init_post;
struct HPMHookPoint *HP_cmdline_final_pre;
@@ -506,8 +534,6 @@ struct {
struct HPMHookPoint *HP_inter_savereg_post;
struct HPMHookPoint *HP_inter_accreg_fromsql_pre;
struct HPMHookPoint *HP_inter_accreg_fromsql_post;
- struct HPMHookPoint *HP_inter_config_read_pre;
- struct HPMHookPoint *HP_inter_config_read_post;
struct HPMHookPoint *HP_inter_vlog_pre;
struct HPMHookPoint *HP_inter_vlog_post;
struct HPMHookPoint *HP_inter_init_sql_pre;
@@ -524,6 +550,10 @@ struct {
struct HPMHookPoint *HP_inter_parse_frommap_post;
struct HPMHookPoint *HP_inter_final_pre;
struct HPMHookPoint *HP_inter_final_post;
+ struct HPMHookPoint *HP_inter_config_read_pre;
+ struct HPMHookPoint *HP_inter_config_read_post;
+ struct HPMHookPoint *HP_inter_config_read_connection_pre;
+ struct HPMHookPoint *HP_inter_config_read_connection_post;
struct HPMHookPoint *HP_inter_mail_sql_init_pre;
struct HPMHookPoint *HP_inter_mail_sql_init_post;
struct HPMHookPoint *HP_inter_mail_sql_final_pre;
@@ -1817,10 +1847,38 @@ struct {
int HP_chr_online_data_cleanup_post;
int HP_chr_sql_config_read_pre;
int HP_chr_sql_config_read_post;
- int HP_chr_config_dispatch_pre;
- int HP_chr_config_dispatch_post;
+ int HP_chr_sql_config_read_registry_pre;
+ int HP_chr_sql_config_read_registry_post;
+ int HP_chr_sql_config_read_pc_pre;
+ int HP_chr_sql_config_read_pc_post;
+ int HP_chr_sql_config_read_guild_pre;
+ int HP_chr_sql_config_read_guild_post;
int HP_chr_config_read_pre;
int HP_chr_config_read_post;
+ int HP_chr_config_read_database_pre;
+ int HP_chr_config_read_database_post;
+ int HP_chr_config_read_console_pre;
+ int HP_chr_config_read_console_post;
+ int HP_chr_config_read_player_fame_pre;
+ int HP_chr_config_read_player_fame_post;
+ int HP_chr_config_read_player_deletion_pre;
+ int HP_chr_config_read_player_deletion_post;
+ int HP_chr_config_read_player_name_pre;
+ int HP_chr_config_read_player_name_post;
+ int HP_chr_config_set_start_item_pre;
+ int HP_chr_config_set_start_item_post;
+ int HP_chr_config_read_player_new_pre;
+ int HP_chr_config_read_player_new_post;
+ int HP_chr_config_read_player_pre;
+ int HP_chr_config_read_player_post;
+ int HP_chr_config_read_permission_pre;
+ int HP_chr_config_read_permission_post;
+ int HP_chr_config_set_ip_pre;
+ int HP_chr_config_set_ip_post;
+ int HP_chr_config_read_inter_pre;
+ int HP_chr_config_read_inter_post;
+ int HP_chr_config_read_top_pre;
+ int HP_chr_config_read_top_post;
int HP_cmdline_init_pre;
int HP_cmdline_init_post;
int HP_cmdline_final_pre;
@@ -1979,8 +2037,6 @@ struct {
int HP_inter_savereg_post;
int HP_inter_accreg_fromsql_pre;
int HP_inter_accreg_fromsql_post;
- int HP_inter_config_read_pre;
- int HP_inter_config_read_post;
int HP_inter_vlog_pre;
int HP_inter_vlog_post;
int HP_inter_init_sql_pre;
@@ -1997,6 +2053,10 @@ struct {
int HP_inter_parse_frommap_post;
int HP_inter_final_pre;
int HP_inter_final_post;
+ int HP_inter_config_read_pre;
+ int HP_inter_config_read_post;
+ int HP_inter_config_read_connection_pre;
+ int HP_inter_config_read_connection_post;
int HP_inter_mail_sql_init_pre;
int HP_inter_mail_sql_init_post;
int HP_inter_mail_sql_final_pre;
diff --git a/src/plugins/HPMHooking/HPMHooking_char.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_char.HookingPoints.inc
index 4371cf81a..35f9044d5 100644
--- a/src/plugins/HPMHooking/HPMHooking_char.HookingPoints.inc
+++ b/src/plugins/HPMHooking/HPMHooking_char.HookingPoints.inc
@@ -187,8 +187,22 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(chr->online_data_cleanup_sub, HP_chr_online_data_cleanup_sub) },
{ HP_POP(chr->online_data_cleanup, HP_chr_online_data_cleanup) },
{ HP_POP(chr->sql_config_read, HP_chr_sql_config_read) },
- { HP_POP(chr->config_dispatch, HP_chr_config_dispatch) },
+ { HP_POP(chr->sql_config_read_registry, HP_chr_sql_config_read_registry) },
+ { HP_POP(chr->sql_config_read_pc, HP_chr_sql_config_read_pc) },
+ { HP_POP(chr->sql_config_read_guild, HP_chr_sql_config_read_guild) },
{ HP_POP(chr->config_read, HP_chr_config_read) },
+ { HP_POP(chr->config_read_database, HP_chr_config_read_database) },
+ { HP_POP(chr->config_read_console, HP_chr_config_read_console) },
+ { HP_POP(chr->config_read_player_fame, HP_chr_config_read_player_fame) },
+ { HP_POP(chr->config_read_player_deletion, HP_chr_config_read_player_deletion) },
+ { HP_POP(chr->config_read_player_name, HP_chr_config_read_player_name) },
+ { HP_POP(chr->config_set_start_item, HP_chr_config_set_start_item) },
+ { HP_POP(chr->config_read_player_new, HP_chr_config_read_player_new) },
+ { HP_POP(chr->config_read_player, HP_chr_config_read_player) },
+ { HP_POP(chr->config_read_permission, HP_chr_config_read_permission) },
+ { HP_POP(chr->config_set_ip, HP_chr_config_set_ip) },
+ { HP_POP(chr->config_read_inter, HP_chr_config_read_inter) },
+ { HP_POP(chr->config_read_top, HP_chr_config_read_top) },
/* cmdline_interface */
{ HP_POP(cmdline->init, HP_cmdline_init) },
{ HP_POP(cmdline->final, HP_cmdline_final) },
@@ -279,7 +293,6 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(inter->vmsg_to_fd, HP_inter_vmsg_to_fd) },
{ HP_POP(inter->savereg, HP_inter_savereg) },
{ HP_POP(inter->accreg_fromsql, HP_inter_accreg_fromsql) },
- { HP_POP(inter->config_read, HP_inter_config_read) },
{ HP_POP(inter->vlog, HP_inter_vlog) },
{ HP_POP(inter->init_sql, HP_inter_init_sql) },
{ HP_POP(inter->mapif_init, HP_inter_mapif_init) },
@@ -288,6 +301,8 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(inter->check_length, HP_inter_check_length) },
{ HP_POP(inter->parse_frommap, HP_inter_parse_frommap) },
{ HP_POP(inter->final, HP_inter_final) },
+ { HP_POP(inter->config_read, HP_inter_config_read) },
+ { HP_POP(inter->config_read_connection, HP_inter_config_read_connection) },
/* inter_mail_interface */
{ HP_POP(inter_mail->sql_init, HP_inter_mail_sql_init) },
{ HP_POP(inter_mail->sql_final, HP_inter_mail_sql_final) },
diff --git a/src/plugins/HPMHooking/HPMHooking_char.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_char.Hooks.inc
index aecffbecd..3669b2da8 100644
--- a/src/plugins/HPMHooking/HPMHooking_char.Hooks.inc
+++ b/src/plugins/HPMHooking/HPMHooking_char.Hooks.inc
@@ -4216,67 +4216,123 @@ int HP_chr_online_data_cleanup(int tid, int64 tick, int id, intptr_t data) {
}
return retVal___;
}
-void HP_chr_sql_config_read(const char *cfgName) {
+bool HP_chr_sql_config_read(const char *filename, bool imported) {
int hIndex = 0;
+ bool retVal___ = false;
if( HPMHooks.count.HP_chr_sql_config_read_pre ) {
- void (*preHookFunc) (const char **cfgName);
+ bool (*preHookFunc) (const char **filename, bool *imported);
*HPMforce_return = false;
for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_sql_config_read_pre; hIndex++ ) {
preHookFunc = HPMHooks.list.HP_chr_sql_config_read_pre[hIndex].func;
- preHookFunc(&cfgName);
+ retVal___ = preHookFunc(&filename, &imported);
}
if( *HPMforce_return ) {
*HPMforce_return = false;
- return;
+ return retVal___;
}
}
{
- HPMHooks.source.chr.sql_config_read(cfgName);
+ retVal___ = HPMHooks.source.chr.sql_config_read(filename, imported);
}
if( HPMHooks.count.HP_chr_sql_config_read_post ) {
- void (*postHookFunc) (const char *cfgName);
+ bool (*postHookFunc) (bool retVal___, const char *filename, bool imported);
for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_sql_config_read_post; hIndex++ ) {
postHookFunc = HPMHooks.list.HP_chr_sql_config_read_post[hIndex].func;
- postHookFunc(cfgName);
+ retVal___ = postHookFunc(retVal___, filename, imported);
}
}
- return;
+ return retVal___;
}
-void HP_chr_config_dispatch(char *w1, char *w2) {
+bool HP_chr_sql_config_read_registry(const char *filename, const struct config_t *config, bool imported) {
int hIndex = 0;
- if( HPMHooks.count.HP_chr_config_dispatch_pre ) {
- void (*preHookFunc) (char **w1, char **w2);
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_chr_sql_config_read_registry_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
*HPMforce_return = false;
- for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_dispatch_pre; hIndex++ ) {
- preHookFunc = HPMHooks.list.HP_chr_config_dispatch_pre[hIndex].func;
- preHookFunc(&w1, &w2);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_sql_config_read_registry_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_chr_sql_config_read_registry_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
}
if( *HPMforce_return ) {
*HPMforce_return = false;
- return;
+ return retVal___;
}
}
{
- HPMHooks.source.chr.config_dispatch(w1, w2);
+ retVal___ = HPMHooks.source.chr.sql_config_read_registry(filename, config, imported);
}
- if( HPMHooks.count.HP_chr_config_dispatch_post ) {
- void (*postHookFunc) (char *w1, char *w2);
- for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_dispatch_post; hIndex++ ) {
- postHookFunc = HPMHooks.list.HP_chr_config_dispatch_post[hIndex].func;
- postHookFunc(w1, w2);
+ if( HPMHooks.count.HP_chr_sql_config_read_registry_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_sql_config_read_registry_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_chr_sql_config_read_registry_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
}
}
- return;
+ return retVal___;
}
-int HP_chr_config_read(const char *cfgName) {
+bool HP_chr_sql_config_read_pc(const char *filename, const struct config_t *config, bool imported) {
int hIndex = 0;
- int retVal___ = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_chr_sql_config_read_pc_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_sql_config_read_pc_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_chr_sql_config_read_pc_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.chr.sql_config_read_pc(filename, config, imported);
+ }
+ if( HPMHooks.count.HP_chr_sql_config_read_pc_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_sql_config_read_pc_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_chr_sql_config_read_pc_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
+ }
+ }
+ return retVal___;
+}
+bool HP_chr_sql_config_read_guild(const char *filename, const struct config_t *config, bool imported) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_chr_sql_config_read_guild_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_sql_config_read_guild_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_chr_sql_config_read_guild_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.chr.sql_config_read_guild(filename, config, imported);
+ }
+ if( HPMHooks.count.HP_chr_sql_config_read_guild_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_sql_config_read_guild_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_chr_sql_config_read_guild_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
+ }
+ }
+ return retVal___;
+}
+bool HP_chr_config_read(const char *filename, bool imported) {
+ int hIndex = 0;
+ bool retVal___ = false;
if( HPMHooks.count.HP_chr_config_read_pre ) {
- int (*preHookFunc) (const char **cfgName);
+ bool (*preHookFunc) (const char **filename, bool *imported);
*HPMforce_return = false;
for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_pre; hIndex++ ) {
preHookFunc = HPMHooks.list.HP_chr_config_read_pre[hIndex].func;
- retVal___ = preHookFunc(&cfgName);
+ retVal___ = preHookFunc(&filename, &imported);
}
if( *HPMforce_return ) {
*HPMforce_return = false;
@@ -4284,13 +4340,336 @@ int HP_chr_config_read(const char *cfgName) {
}
}
{
- retVal___ = HPMHooks.source.chr.config_read(cfgName);
+ retVal___ = HPMHooks.source.chr.config_read(filename, imported);
}
if( HPMHooks.count.HP_chr_config_read_post ) {
- int (*postHookFunc) (int retVal___, const char *cfgName);
+ bool (*postHookFunc) (bool retVal___, const char *filename, bool imported);
for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_post; hIndex++ ) {
postHookFunc = HPMHooks.list.HP_chr_config_read_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, cfgName);
+ retVal___ = postHookFunc(retVal___, filename, imported);
+ }
+ }
+ return retVal___;
+}
+bool HP_chr_config_read_database(const char *filename, const struct config_t *config, bool imported) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_chr_config_read_database_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_database_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_chr_config_read_database_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.chr.config_read_database(filename, config, imported);
+ }
+ if( HPMHooks.count.HP_chr_config_read_database_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_database_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_chr_config_read_database_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
+ }
+ }
+ return retVal___;
+}
+bool HP_chr_config_read_console(const char *filename, const struct config_t *config, bool imported) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_chr_config_read_console_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_console_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_chr_config_read_console_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.chr.config_read_console(filename, config, imported);
+ }
+ if( HPMHooks.count.HP_chr_config_read_console_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_console_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_chr_config_read_console_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
+ }
+ }
+ return retVal___;
+}
+bool HP_chr_config_read_player_fame(const char *filename, const struct config_t *config, bool imported) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_chr_config_read_player_fame_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_player_fame_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_chr_config_read_player_fame_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.chr.config_read_player_fame(filename, config, imported);
+ }
+ if( HPMHooks.count.HP_chr_config_read_player_fame_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_player_fame_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_chr_config_read_player_fame_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
+ }
+ }
+ return retVal___;
+}
+bool HP_chr_config_read_player_deletion(const char *filename, const struct config_t *config, bool imported) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_chr_config_read_player_deletion_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_player_deletion_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_chr_config_read_player_deletion_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.chr.config_read_player_deletion(filename, config, imported);
+ }
+ if( HPMHooks.count.HP_chr_config_read_player_deletion_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_player_deletion_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_chr_config_read_player_deletion_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
+ }
+ }
+ return retVal___;
+}
+bool HP_chr_config_read_player_name(const char *filename, const struct config_t *config, bool imported) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_chr_config_read_player_name_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_player_name_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_chr_config_read_player_name_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.chr.config_read_player_name(filename, config, imported);
+ }
+ if( HPMHooks.count.HP_chr_config_read_player_name_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_player_name_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_chr_config_read_player_name_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
+ }
+ }
+ return retVal___;
+}
+void HP_chr_config_set_start_item(const struct config_setting_t *setting) {
+ int hIndex = 0;
+ if( HPMHooks.count.HP_chr_config_set_start_item_pre ) {
+ void (*preHookFunc) (const struct config_setting_t **setting);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_set_start_item_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_chr_config_set_start_item_pre[hIndex].func;
+ preHookFunc(&setting);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return;
+ }
+ }
+ {
+ HPMHooks.source.chr.config_set_start_item(setting);
+ }
+ if( HPMHooks.count.HP_chr_config_set_start_item_post ) {
+ void (*postHookFunc) (const struct config_setting_t *setting);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_set_start_item_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_chr_config_set_start_item_post[hIndex].func;
+ postHookFunc(setting);
+ }
+ }
+ return;
+}
+bool HP_chr_config_read_player_new(const char *filename, const struct config_t *config, bool imported) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_chr_config_read_player_new_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_player_new_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_chr_config_read_player_new_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.chr.config_read_player_new(filename, config, imported);
+ }
+ if( HPMHooks.count.HP_chr_config_read_player_new_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_player_new_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_chr_config_read_player_new_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
+ }
+ }
+ return retVal___;
+}
+bool HP_chr_config_read_player(const char *filename, const struct config_t *config, bool imported) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_chr_config_read_player_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_player_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_chr_config_read_player_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.chr.config_read_player(filename, config, imported);
+ }
+ if( HPMHooks.count.HP_chr_config_read_player_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_player_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_chr_config_read_player_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
+ }
+ }
+ return retVal___;
+}
+bool HP_chr_config_read_permission(const char *filename, const struct config_t *config, bool imported) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_chr_config_read_permission_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_permission_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_chr_config_read_permission_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.chr.config_read_permission(filename, config, imported);
+ }
+ if( HPMHooks.count.HP_chr_config_read_permission_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_permission_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_chr_config_read_permission_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
+ }
+ }
+ return retVal___;
+}
+bool HP_chr_config_set_ip(const char *type, const char *value, uint32 *out_ip, char *out_ip_str) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_chr_config_set_ip_pre ) {
+ bool (*preHookFunc) (const char **type, const char **value, uint32 **out_ip, char **out_ip_str);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_set_ip_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_chr_config_set_ip_pre[hIndex].func;
+ retVal___ = preHookFunc(&type, &value, &out_ip, &out_ip_str);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.chr.config_set_ip(type, value, out_ip, out_ip_str);
+ }
+ if( HPMHooks.count.HP_chr_config_set_ip_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *type, const char *value, uint32 *out_ip, char *out_ip_str);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_set_ip_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_chr_config_set_ip_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, type, value, out_ip, out_ip_str);
+ }
+ }
+ return retVal___;
+}
+bool HP_chr_config_read_inter(const char *filename, const struct config_t *config, bool imported) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_chr_config_read_inter_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_inter_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_chr_config_read_inter_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.chr.config_read_inter(filename, config, imported);
+ }
+ if( HPMHooks.count.HP_chr_config_read_inter_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_inter_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_chr_config_read_inter_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
+ }
+ }
+ return retVal___;
+}
+bool HP_chr_config_read_top(const char *filename, const struct config_t *config, bool imported) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_chr_config_read_top_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_top_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_chr_config_read_top_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.chr.config_read_top(filename, config, imported);
+ }
+ if( HPMHooks.count.HP_chr_config_read_top_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_chr_config_read_top_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_chr_config_read_top_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
}
}
return retVal___;
@@ -6427,33 +6806,6 @@ int HP_inter_accreg_fromsql(int account_id, int char_id, int fd, int type) {
}
return retVal___;
}
-int HP_inter_config_read(const char *cfgName) {
- int hIndex = 0;
- int retVal___ = 0;
- if( HPMHooks.count.HP_inter_config_read_pre ) {
- int (*preHookFunc) (const char **cfgName);
- *HPMforce_return = false;
- for(hIndex = 0; hIndex < HPMHooks.count.HP_inter_config_read_pre; hIndex++ ) {
- preHookFunc = HPMHooks.list.HP_inter_config_read_pre[hIndex].func;
- retVal___ = preHookFunc(&cfgName);
- }
- if( *HPMforce_return ) {
- *HPMforce_return = false;
- return retVal___;
- }
- }
- {
- retVal___ = HPMHooks.source.inter.config_read(cfgName);
- }
- if( HPMHooks.count.HP_inter_config_read_post ) {
- int (*postHookFunc) (int retVal___, const char *cfgName);
- for(hIndex = 0; hIndex < HPMHooks.count.HP_inter_config_read_post; hIndex++ ) {
- postHookFunc = HPMHooks.list.HP_inter_config_read_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, cfgName);
- }
- }
- return retVal___;
-}
int HP_inter_vlog(char *fmt, va_list ap) {
int hIndex = 0;
int retVal___ = 0;
@@ -6681,6 +7033,60 @@ void HP_inter_final(void) {
}
return;
}
+bool HP_inter_config_read(const char *filename, bool imported) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_inter_config_read_pre ) {
+ bool (*preHookFunc) (const char **filename, bool *imported);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_inter_config_read_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_inter_config_read_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &imported);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.inter.config_read(filename, imported);
+ }
+ if( HPMHooks.count.HP_inter_config_read_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_inter_config_read_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_inter_config_read_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, imported);
+ }
+ }
+ return retVal___;
+}
+bool HP_inter_config_read_connection(const char *filename, const struct config_t *config, bool imported) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_inter_config_read_connection_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_inter_config_read_connection_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_inter_config_read_connection_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.inter.config_read_connection(filename, config, imported);
+ }
+ if( HPMHooks.count.HP_inter_config_read_connection_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_inter_config_read_connection_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_inter_config_read_connection_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
+ }
+ }
+ return retVal___;
+}
/* inter_mail_interface */
int HP_inter_mail_sql_init(void) {
int hIndex = 0;
@@ -15726,15 +16132,15 @@ void HP_pincode_check(int fd, struct char_session_data *sd) {
}
return;
}
-bool HP_pincode_config_read(char *w1, char *w2) {
+bool HP_pincode_config_read(const char *filename, const struct config_t *config, bool imported) {
int hIndex = 0;
bool retVal___ = false;
if( HPMHooks.count.HP_pincode_config_read_pre ) {
- bool (*preHookFunc) (char **w1, char **w2);
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
*HPMforce_return = false;
for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_config_read_pre; hIndex++ ) {
preHookFunc = HPMHooks.list.HP_pincode_config_read_pre[hIndex].func;
- retVal___ = preHookFunc(&w1, &w2);
+ retVal___ = preHookFunc(&filename, &config, &imported);
}
if( *HPMforce_return ) {
*HPMforce_return = false;
@@ -15742,13 +16148,13 @@ bool HP_pincode_config_read(char *w1, char *w2) {
}
}
{
- retVal___ = HPMHooks.source.pincode.config_read(w1, w2);
+ retVal___ = HPMHooks.source.pincode.config_read(filename, config, imported);
}
if( HPMHooks.count.HP_pincode_config_read_post ) {
- bool (*postHookFunc) (bool retVal___, char *w1, char *w2);
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
for(hIndex = 0; hIndex < HPMHooks.count.HP_pincode_config_read_post; hIndex++ ) {
postHookFunc = HPMHooks.list.HP_pincode_config_read_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, w1, w2);
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
}
}
return retVal___;
diff --git a/src/plugins/HPMHooking/HPMHooking_login.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_login.Hooks.inc
index 013a56104..290c2283a 100644
--- a/src/plugins/HPMHooking/HPMHooking_login.Hooks.inc
+++ b/src/plugins/HPMHooking/HPMHooking_login.Hooks.inc
@@ -4689,15 +4689,15 @@ void HP_login_config_set_defaults(void) {
}
return;
}
-int HP_login_config_read(const char *cfgName) {
+bool HP_login_config_read(const char *filename, bool included) {
int hIndex = 0;
- int retVal___ = 0;
+ bool retVal___ = false;
if( HPMHooks.count.HP_login_config_read_pre ) {
- int (*preHookFunc) (const char **cfgName);
+ bool (*preHookFunc) (const char **filename, bool *included);
*HPMforce_return = false;
for(hIndex = 0; hIndex < HPMHooks.count.HP_login_config_read_pre; hIndex++ ) {
preHookFunc = HPMHooks.list.HP_login_config_read_pre[hIndex].func;
- retVal___ = preHookFunc(&cfgName);
+ retVal___ = preHookFunc(&filename, &included);
}
if( *HPMforce_return ) {
*HPMforce_return = false;
@@ -4705,13 +4705,13 @@ int HP_login_config_read(const char *cfgName) {
}
}
{
- retVal___ = HPMHooks.source.login.config_read(cfgName);
+ retVal___ = HPMHooks.source.login.config_read(filename, included);
}
if( HPMHooks.count.HP_login_config_read_post ) {
- int (*postHookFunc) (int retVal___, const char *cfgName);
+ bool (*postHookFunc) (bool retVal___, const char *filename, bool included);
for(hIndex = 0; hIndex < HPMHooks.count.HP_login_config_read_post; hIndex++ ) {
postHookFunc = HPMHooks.list.HP_login_config_read_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, cfgName);
+ retVal___ = postHookFunc(retVal___, filename, included);
}
}
return retVal___;
diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
index 06c4acc50..0845d8cdd 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
@@ -198,6 +198,8 @@ struct {
struct HPMHookPoint *HP_battle_config_read_post;
struct HPMHookPoint *HP_battle_config_set_defaults_pre;
struct HPMHookPoint *HP_battle_config_set_defaults_post;
+ struct HPMHookPoint *HP_battle_config_set_value_sub_pre;
+ struct HPMHookPoint *HP_battle_config_set_value_sub_post;
struct HPMHookPoint *HP_battle_config_set_value_pre;
struct HPMHookPoint *HP_battle_config_set_value_post;
struct HPMHookPoint *HP_battle_config_get_value_pre;
@@ -3234,12 +3236,14 @@ struct {
struct HPMHookPoint *HP_map_readallmaps_post;
struct HPMHookPoint *HP_map_config_read_pre;
struct HPMHookPoint *HP_map_config_read_post;
- struct HPMHookPoint *HP_map_config_read_sub_pre;
- struct HPMHookPoint *HP_map_config_read_sub_post;
- struct HPMHookPoint *HP_map_reloadnpc_sub_pre;
- struct HPMHookPoint *HP_map_reloadnpc_sub_post;
+ struct HPMHookPoint *HP_map_read_npclist_pre;
+ struct HPMHookPoint *HP_map_read_npclist_post;
struct HPMHookPoint *HP_map_inter_config_read_pre;
struct HPMHookPoint *HP_map_inter_config_read_post;
+ struct HPMHookPoint *HP_map_inter_config_read_database_names_pre;
+ struct HPMHookPoint *HP_map_inter_config_read_database_names_post;
+ struct HPMHookPoint *HP_map_inter_config_read_connection_pre;
+ struct HPMHookPoint *HP_map_inter_config_read_connection_post;
struct HPMHookPoint *HP_map_sql_init_pre;
struct HPMHookPoint *HP_map_sql_init_post;
struct HPMHookPoint *HP_map_sql_close_pre;
@@ -6249,6 +6253,8 @@ struct {
int HP_battle_config_read_post;
int HP_battle_config_set_defaults_pre;
int HP_battle_config_set_defaults_post;
+ int HP_battle_config_set_value_sub_pre;
+ int HP_battle_config_set_value_sub_post;
int HP_battle_config_set_value_pre;
int HP_battle_config_set_value_post;
int HP_battle_config_get_value_pre;
@@ -9285,12 +9291,14 @@ struct {
int HP_map_readallmaps_post;
int HP_map_config_read_pre;
int HP_map_config_read_post;
- int HP_map_config_read_sub_pre;
- int HP_map_config_read_sub_post;
- int HP_map_reloadnpc_sub_pre;
- int HP_map_reloadnpc_sub_post;
+ int HP_map_read_npclist_pre;
+ int HP_map_read_npclist_post;
int HP_map_inter_config_read_pre;
int HP_map_inter_config_read_post;
+ int HP_map_inter_config_read_database_names_pre;
+ int HP_map_inter_config_read_database_names_post;
+ int HP_map_inter_config_read_connection_pre;
+ int HP_map_inter_config_read_connection_post;
int HP_map_sql_init_pre;
int HP_map_sql_init_post;
int HP_map_sql_close_pre;
diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
index 2cef7f135..30ede196a 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
@@ -115,6 +115,7 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(battle->calc_drain, HP_battle_calc_drain) },
{ HP_POP(battle->config_read, HP_battle_config_read) },
{ HP_POP(battle->config_set_defaults, HP_battle_config_set_defaults) },
+ { HP_POP(battle->config_set_value_sub, HP_battle_config_set_value_sub) },
{ HP_POP(battle->config_set_value, HP_battle_config_set_value) },
{ HP_POP(battle->config_get_value, HP_battle_config_get_value) },
{ HP_POP(battle->config_adjust, HP_battle_config_adjust) },
@@ -1659,9 +1660,10 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(map->readgat, HP_map_readgat) },
{ HP_POP(map->readallmaps, HP_map_readallmaps) },
{ HP_POP(map->config_read, HP_map_config_read) },
- { HP_POP(map->config_read_sub, HP_map_config_read_sub) },
- { HP_POP(map->reloadnpc_sub, HP_map_reloadnpc_sub) },
+ { HP_POP(map->read_npclist, HP_map_read_npclist) },
{ HP_POP(map->inter_config_read, HP_map_inter_config_read) },
+ { HP_POP(map->inter_config_read_database_names, HP_map_inter_config_read_database_names) },
+ { HP_POP(map->inter_config_read_connection, HP_map_inter_config_read_connection) },
{ HP_POP(map->sql_init, HP_map_sql_init) },
{ HP_POP(map->sql_close, HP_map_sql_close) },
{ HP_POP(map->zone_mf_cache, HP_map_zone_mf_cache) },
diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
index 9ef56800f..819c3b28c 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
@@ -2335,15 +2335,15 @@ int HP_battle_calc_drain(int64 damage, int rate, int per) {
}
return retVal___;
}
-int HP_battle_config_read(const char *cfgName) {
+bool HP_battle_config_read(const char *filename, bool imported) {
int hIndex = 0;
- int retVal___ = 0;
+ bool retVal___ = false;
if( HPMHooks.count.HP_battle_config_read_pre ) {
- int (*preHookFunc) (const char **cfgName);
+ bool (*preHookFunc) (const char **filename, bool *imported);
*HPMforce_return = false;
for(hIndex = 0; hIndex < HPMHooks.count.HP_battle_config_read_pre; hIndex++ ) {
preHookFunc = HPMHooks.list.HP_battle_config_read_pre[hIndex].func;
- retVal___ = preHookFunc(&cfgName);
+ retVal___ = preHookFunc(&filename, &imported);
}
if( *HPMforce_return ) {
*HPMforce_return = false;
@@ -2351,13 +2351,13 @@ int HP_battle_config_read(const char *cfgName) {
}
}
{
- retVal___ = HPMHooks.source.battle.config_read(cfgName);
+ retVal___ = HPMHooks.source.battle.config_read(filename, imported);
}
if( HPMHooks.count.HP_battle_config_read_post ) {
- int (*postHookFunc) (int retVal___, const char *cfgName);
+ bool (*postHookFunc) (bool retVal___, const char *filename, bool imported);
for(hIndex = 0; hIndex < HPMHooks.count.HP_battle_config_read_post; hIndex++ ) {
postHookFunc = HPMHooks.list.HP_battle_config_read_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, cfgName);
+ retVal___ = postHookFunc(retVal___, filename, imported);
}
}
return retVal___;
@@ -2388,15 +2388,42 @@ void HP_battle_config_set_defaults(void) {
}
return;
}
-int HP_battle_config_set_value(const char *w1, const char *w2) {
+bool HP_battle_config_set_value_sub(int index, int value) {
int hIndex = 0;
- int retVal___ = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_battle_config_set_value_sub_pre ) {
+ bool (*preHookFunc) (int *index, int *value);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_battle_config_set_value_sub_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_battle_config_set_value_sub_pre[hIndex].func;
+ retVal___ = preHookFunc(&index, &value);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.battle.config_set_value_sub(index, value);
+ }
+ if( HPMHooks.count.HP_battle_config_set_value_sub_post ) {
+ bool (*postHookFunc) (bool retVal___, int index, int value);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_battle_config_set_value_sub_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_battle_config_set_value_sub_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, index, value);
+ }
+ }
+ return retVal___;
+}
+bool HP_battle_config_set_value(const char *param, const char *value) {
+ int hIndex = 0;
+ bool retVal___ = false;
if( HPMHooks.count.HP_battle_config_set_value_pre ) {
- int (*preHookFunc) (const char **w1, const char **w2);
+ bool (*preHookFunc) (const char **param, const char **value);
*HPMforce_return = false;
for(hIndex = 0; hIndex < HPMHooks.count.HP_battle_config_set_value_pre; hIndex++ ) {
preHookFunc = HPMHooks.list.HP_battle_config_set_value_pre[hIndex].func;
- retVal___ = preHookFunc(&w1, &w2);
+ retVal___ = preHookFunc(&param, &value);
}
if( *HPMforce_return ) {
*HPMforce_return = false;
@@ -2404,13 +2431,13 @@ int HP_battle_config_set_value(const char *w1, const char *w2) {
}
}
{
- retVal___ = HPMHooks.source.battle.config_set_value(w1, w2);
+ retVal___ = HPMHooks.source.battle.config_set_value(param, value);
}
if( HPMHooks.count.HP_battle_config_set_value_post ) {
- int (*postHookFunc) (int retVal___, const char *w1, const char *w2);
+ bool (*postHookFunc) (bool retVal___, const char *param, const char *value);
for(hIndex = 0; hIndex < HPMHooks.count.HP_battle_config_set_value_post; hIndex++ ) {
postHookFunc = HPMHooks.list.HP_battle_config_set_value_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, w1, w2);
+ retVal___ = postHookFunc(retVal___, param, value);
}
}
return retVal___;
@@ -38818,15 +38845,15 @@ void HP_logs_mvpdrop_sub(struct map_session_data *sd, int monster_id, int *log_m
}
return;
}
-int HP_logs_config_read(const char *cfgName) {
+bool HP_logs_config_read(const char *filename, bool imported) {
int hIndex = 0;
- int retVal___ = 0;
+ bool retVal___ = false;
if( HPMHooks.count.HP_logs_config_read_pre ) {
- int (*preHookFunc) (const char **cfgName);
+ bool (*preHookFunc) (const char **filename, bool *imported);
*HPMforce_return = false;
for(hIndex = 0; hIndex < HPMHooks.count.HP_logs_config_read_pre; hIndex++ ) {
preHookFunc = HPMHooks.list.HP_logs_config_read_pre[hIndex].func;
- retVal___ = preHookFunc(&cfgName);
+ retVal___ = preHookFunc(&filename, &imported);
}
if( *HPMforce_return ) {
*HPMforce_return = false;
@@ -38834,13 +38861,13 @@ int HP_logs_config_read(const char *cfgName) {
}
}
{
- retVal___ = HPMHooks.source.logs.config_read(cfgName);
+ retVal___ = HPMHooks.source.logs.config_read(filename, imported);
}
if( HPMHooks.count.HP_logs_config_read_post ) {
- int (*postHookFunc) (int retVal___, const char *cfgName);
+ bool (*postHookFunc) (bool retVal___, const char *filename, bool imported);
for(hIndex = 0; hIndex < HPMHooks.count.HP_logs_config_read_post; hIndex++ ) {
postHookFunc = HPMHooks.list.HP_logs_config_read_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, cfgName);
+ retVal___ = postHookFunc(retVal___, filename, imported);
}
}
return retVal___;
@@ -41774,11 +41801,11 @@ int HP_map_cleanup_sub(struct block_list *bl, va_list ap) {
}
return retVal___;
}
-int HP_map_delmap(char *mapname) {
+int HP_map_delmap(const char *mapname) {
int hIndex = 0;
int retVal___ = 0;
if( HPMHooks.count.HP_map_delmap_pre ) {
- int (*preHookFunc) (char **mapname);
+ int (*preHookFunc) (const char **mapname);
*HPMforce_return = false;
for(hIndex = 0; hIndex < HPMHooks.count.HP_map_delmap_pre; hIndex++ ) {
preHookFunc = HPMHooks.list.HP_map_delmap_pre[hIndex].func;
@@ -41793,7 +41820,7 @@ int HP_map_delmap(char *mapname) {
retVal___ = HPMHooks.source.map.delmap(mapname);
}
if( HPMHooks.count.HP_map_delmap_post ) {
- int (*postHookFunc) (int retVal___, char *mapname);
+ int (*postHookFunc) (int retVal___, const char *mapname);
for(hIndex = 0; hIndex < HPMHooks.count.HP_map_delmap_post; hIndex++ ) {
postHookFunc = HPMHooks.list.HP_map_delmap_post[hIndex].func;
retVal___ = postHookFunc(retVal___, mapname);
@@ -42734,15 +42761,15 @@ int HP_map_readallmaps(void) {
}
return retVal___;
}
-int HP_map_config_read(char *cfgName) {
+bool HP_map_config_read(const char *filename, bool imported) {
int hIndex = 0;
- int retVal___ = 0;
+ bool retVal___ = false;
if( HPMHooks.count.HP_map_config_read_pre ) {
- int (*preHookFunc) (char **cfgName);
+ bool (*preHookFunc) (const char **filename, bool *imported);
*HPMforce_return = false;
for(hIndex = 0; hIndex < HPMHooks.count.HP_map_config_read_pre; hIndex++ ) {
preHookFunc = HPMHooks.list.HP_map_config_read_pre[hIndex].func;
- retVal___ = preHookFunc(&cfgName);
+ retVal___ = preHookFunc(&filename, &imported);
}
if( *HPMforce_return ) {
*HPMforce_return = false;
@@ -42750,26 +42777,26 @@ int HP_map_config_read(char *cfgName) {
}
}
{
- retVal___ = HPMHooks.source.map.config_read(cfgName);
+ retVal___ = HPMHooks.source.map.config_read(filename, imported);
}
if( HPMHooks.count.HP_map_config_read_post ) {
- int (*postHookFunc) (int retVal___, char *cfgName);
+ bool (*postHookFunc) (bool retVal___, const char *filename, bool imported);
for(hIndex = 0; hIndex < HPMHooks.count.HP_map_config_read_post; hIndex++ ) {
postHookFunc = HPMHooks.list.HP_map_config_read_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, cfgName);
+ retVal___ = postHookFunc(retVal___, filename, imported);
}
}
return retVal___;
}
-int HP_map_config_read_sub(char *cfgName) {
+bool HP_map_read_npclist(const char *filename, bool imported) {
int hIndex = 0;
- int retVal___ = 0;
- if( HPMHooks.count.HP_map_config_read_sub_pre ) {
- int (*preHookFunc) (char **cfgName);
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_map_read_npclist_pre ) {
+ bool (*preHookFunc) (const char **filename, bool *imported);
*HPMforce_return = false;
- for(hIndex = 0; hIndex < HPMHooks.count.HP_map_config_read_sub_pre; hIndex++ ) {
- preHookFunc = HPMHooks.list.HP_map_config_read_sub_pre[hIndex].func;
- retVal___ = preHookFunc(&cfgName);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_map_read_npclist_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_map_read_npclist_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &imported);
}
if( *HPMforce_return ) {
*HPMforce_return = false;
@@ -42777,52 +42804,53 @@ int HP_map_config_read_sub(char *cfgName) {
}
}
{
- retVal___ = HPMHooks.source.map.config_read_sub(cfgName);
+ retVal___ = HPMHooks.source.map.read_npclist(filename, imported);
}
- if( HPMHooks.count.HP_map_config_read_sub_post ) {
- int (*postHookFunc) (int retVal___, char *cfgName);
- for(hIndex = 0; hIndex < HPMHooks.count.HP_map_config_read_sub_post; hIndex++ ) {
- postHookFunc = HPMHooks.list.HP_map_config_read_sub_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, cfgName);
+ if( HPMHooks.count.HP_map_read_npclist_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_map_read_npclist_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_map_read_npclist_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, imported);
}
}
return retVal___;
}
-void HP_map_reloadnpc_sub(char *cfgName) {
+bool HP_map_inter_config_read(const char *filename, bool imported) {
int hIndex = 0;
- if( HPMHooks.count.HP_map_reloadnpc_sub_pre ) {
- void (*preHookFunc) (char **cfgName);
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_map_inter_config_read_pre ) {
+ bool (*preHookFunc) (const char **filename, bool *imported);
*HPMforce_return = false;
- for(hIndex = 0; hIndex < HPMHooks.count.HP_map_reloadnpc_sub_pre; hIndex++ ) {
- preHookFunc = HPMHooks.list.HP_map_reloadnpc_sub_pre[hIndex].func;
- preHookFunc(&cfgName);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_map_inter_config_read_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_map_inter_config_read_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &imported);
}
if( *HPMforce_return ) {
*HPMforce_return = false;
- return;
+ return retVal___;
}
}
{
- HPMHooks.source.map.reloadnpc_sub(cfgName);
+ retVal___ = HPMHooks.source.map.inter_config_read(filename, imported);
}
- if( HPMHooks.count.HP_map_reloadnpc_sub_post ) {
- void (*postHookFunc) (char *cfgName);
- for(hIndex = 0; hIndex < HPMHooks.count.HP_map_reloadnpc_sub_post; hIndex++ ) {
- postHookFunc = HPMHooks.list.HP_map_reloadnpc_sub_post[hIndex].func;
- postHookFunc(cfgName);
+ if( HPMHooks.count.HP_map_inter_config_read_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_map_inter_config_read_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_map_inter_config_read_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, imported);
}
}
- return;
+ return retVal___;
}
-int HP_map_inter_config_read(char *cfgName) {
+bool HP_map_inter_config_read_database_names(const char *filename, const struct config_t *config, bool imported) {
int hIndex = 0;
- int retVal___ = 0;
- if( HPMHooks.count.HP_map_inter_config_read_pre ) {
- int (*preHookFunc) (char **cfgName);
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_map_inter_config_read_database_names_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
*HPMforce_return = false;
- for(hIndex = 0; hIndex < HPMHooks.count.HP_map_inter_config_read_pre; hIndex++ ) {
- preHookFunc = HPMHooks.list.HP_map_inter_config_read_pre[hIndex].func;
- retVal___ = preHookFunc(&cfgName);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_map_inter_config_read_database_names_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_map_inter_config_read_database_names_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
}
if( *HPMforce_return ) {
*HPMforce_return = false;
@@ -42830,13 +42858,40 @@ int HP_map_inter_config_read(char *cfgName) {
}
}
{
- retVal___ = HPMHooks.source.map.inter_config_read(cfgName);
+ retVal___ = HPMHooks.source.map.inter_config_read_database_names(filename, config, imported);
}
- if( HPMHooks.count.HP_map_inter_config_read_post ) {
- int (*postHookFunc) (int retVal___, char *cfgName);
- for(hIndex = 0; hIndex < HPMHooks.count.HP_map_inter_config_read_post; hIndex++ ) {
- postHookFunc = HPMHooks.list.HP_map_inter_config_read_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, cfgName);
+ if( HPMHooks.count.HP_map_inter_config_read_database_names_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_map_inter_config_read_database_names_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_map_inter_config_read_database_names_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
+ }
+ }
+ return retVal___;
+}
+bool HP_map_inter_config_read_connection(const char *filename, const struct config_t *config, bool imported) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if( HPMHooks.count.HP_map_inter_config_read_connection_pre ) {
+ bool (*preHookFunc) (const char **filename, const struct config_t **config, bool *imported);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_map_inter_config_read_connection_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_map_inter_config_read_connection_pre[hIndex].func;
+ retVal___ = preHookFunc(&filename, &config, &imported);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.map.inter_config_read_connection(filename, config, imported);
+ }
+ if( HPMHooks.count.HP_map_inter_config_read_connection_post ) {
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_t *config, bool imported);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_map_inter_config_read_connection_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_map_inter_config_read_connection_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
}
}
return retVal___;
@@ -44050,15 +44105,15 @@ void HP_mapreg_reload(void) {
}
return;
}
-bool HP_mapreg_config_read(const char *w1, const char *w2) {
+bool HP_mapreg_config_read(const char *filename, const struct config_setting_t *config, bool imported) {
int hIndex = 0;
bool retVal___ = false;
if( HPMHooks.count.HP_mapreg_config_read_pre ) {
- bool (*preHookFunc) (const char **w1, const char **w2);
+ bool (*preHookFunc) (const char **filename, const struct config_setting_t **config, bool *imported);
*HPMforce_return = false;
for(hIndex = 0; hIndex < HPMHooks.count.HP_mapreg_config_read_pre; hIndex++ ) {
preHookFunc = HPMHooks.list.HP_mapreg_config_read_pre[hIndex].func;
- retVal___ = preHookFunc(&w1, &w2);
+ retVal___ = preHookFunc(&filename, &config, &imported);
}
if( *HPMforce_return ) {
*HPMforce_return = false;
@@ -44066,13 +44121,13 @@ bool HP_mapreg_config_read(const char *w1, const char *w2) {
}
}
{
- retVal___ = HPMHooks.source.mapreg.config_read(w1, w2);
+ retVal___ = HPMHooks.source.mapreg.config_read(filename, config, imported);
}
if( HPMHooks.count.HP_mapreg_config_read_post ) {
- bool (*postHookFunc) (bool retVal___, const char *w1, const char *w2);
+ bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_setting_t *config, bool imported);
for(hIndex = 0; hIndex < HPMHooks.count.HP_mapreg_config_read_post; hIndex++ ) {
postHookFunc = HPMHooks.list.HP_mapreg_config_read_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, w1, w2);
+ retVal___ = postHookFunc(retVal___, filename, config, imported);
}
}
return retVal___;
@@ -62196,15 +62251,15 @@ void HP_script_setarray_pc(struct map_session_data *sd, const char *varname, uin
}
return;
}
-int HP_script_config_read(char *cfgName) {
+bool HP_script_config_read(const char *filename, bool imported) {
int hIndex = 0;
- int retVal___ = 0;
+ bool retVal___ = false;
if( HPMHooks.count.HP_script_config_read_pre ) {
- int (*preHookFunc) (char **cfgName);
+ bool (*preHookFunc) (const char **filename, bool *imported);
*HPMforce_return = false;
for(hIndex = 0; hIndex < HPMHooks.count.HP_script_config_read_pre; hIndex++ ) {
preHookFunc = HPMHooks.list.HP_script_config_read_pre[hIndex].func;
- retVal___ = preHookFunc(&cfgName);
+ retVal___ = preHookFunc(&filename, &imported);
}
if( *HPMforce_return ) {
*HPMforce_return = false;
@@ -62212,13 +62267,13 @@ int HP_script_config_read(char *cfgName) {
}
}
{
- retVal___ = HPMHooks.source.script.config_read(cfgName);
+ retVal___ = HPMHooks.source.script.config_read(filename, imported);
}
if( HPMHooks.count.HP_script_config_read_post ) {
- int (*postHookFunc) (int retVal___, char *cfgName);
+ bool (*postHookFunc) (bool retVal___, const char *filename, bool imported);
for(hIndex = 0; hIndex < HPMHooks.count.HP_script_config_read_post; hIndex++ ) {
postHookFunc = HPMHooks.list.HP_script_config_read_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, cfgName);
+ retVal___ = postHookFunc(retVal___, filename, imported);
}
}
return retVal___;
diff --git a/src/plugins/sample.c b/src/plugins/sample.c
index b1ff4b39f..b37f7c4f7 100644
--- a/src/plugins/sample.c
+++ b/src/plugins/sample.c
@@ -213,11 +213,12 @@ HPExport void plugin_init (void) {
}
}
/* triggered when server starts loading, before any server-specific data is set */
-HPExport void server_preinit (void) {
+HPExport void server_preinit(void)
+{
/* makes map server listen to mysetting:value in any "battleconf" file (including imported or custom ones) */
/* value is not limited to numbers, its passed to our plugins handler (parse_my_setting) as const char *,
* however for battle config to be returned to our script engine we need it to be number (int) so keep use it as int only */
- addBattleConf("my_setting",parse_my_setting,return_my_setting);
+ addBattleConf("my_setting", parse_my_setting, return_my_setting, false);
}
/* run when server is ready (online) */
HPExport void server_online (void) {