summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-02-11 18:53:58 +0100
committerHaru <haru@dotalux.com>2016-08-19 21:32:21 +0200
commit17466273cf9abba44129d73a801b8ed714484e72 (patch)
treeec9dfc58a9e2ac96b63c8a6022ef0270840a191c
parent998b48e2d582e666a4afad21dd28f50fbb9eedb5 (diff)
downloadhercules-17466273cf9abba44129d73a801b8ed714484e72.tar.gz
hercules-17466273cf9abba44129d73a801b8ed714484e72.tar.bz2
hercules-17466273cf9abba44129d73a801b8ed714484e72.tar.xz
hercules-17466273cf9abba44129d73a801b8ed714484e72.zip
Ported logs.conf to libconfig
Ported to modern Hercules and cleaned up from Panikon's commits: 2a7c931b9b4e0f9c6e7766cb25701514230ec7e3, f5b1ee3df777ba7e69f1f99abaf0d00b987fc0e3, 6d1f8f50b0e7349bdab2c53bb172d0b036e47c04 Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r--.gitignore1
-rw-r--r--conf/import-tmpl/log_conf.txt0
-rw-r--r--conf/import-tmpl/logs.conf32
-rw-r--r--conf/logs.conf134
-rw-r--r--conf/map/logs.conf172
-rw-r--r--src/map/log.c323
-rw-r--r--src/map/log.h7
-rw-r--r--src/map/map.c7
-rwxr-xr-xtools/configconverter.pl27
9 files changed, 468 insertions, 235 deletions
diff --git a/.gitignore b/.gitignore
index eaf7a3aa3..84eb50456 100644
--- a/.gitignore
+++ b/.gitignore
@@ -61,7 +61,6 @@ Thumbs.db
# /conf/
/conf/import/*.conf
/conf/import/battle_conf.txt
-/conf/import/log_conf.txt
/conf/import/msg_conf.txt
/conf/import/packet_conf.txt
/conf/import/script_conf.txt
diff --git a/conf/import-tmpl/log_conf.txt b/conf/import-tmpl/log_conf.txt
deleted file mode 100644
index e69de29bb..000000000
--- a/conf/import-tmpl/log_conf.txt
+++ /dev/null
diff --git a/conf/import-tmpl/logs.conf b/conf/import-tmpl/logs.conf
new file mode 100644
index 000000000..99e666d96
--- /dev/null
+++ b/conf/import-tmpl/logs.conf
@@ -0,0 +1,32 @@
+//================= Hercules Configuration ================================
+//= _ _ _
+//= | | | | | |
+//= | |_| | ___ _ __ ___ _ _| | ___ ___
+//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __|
+//= | | | | __/ | | (__| |_| | | __/\__ \
+//= \_| |_/\___|_| \___|\__,_|_|\___||___/
+//================= License ===============================================
+//= This file is part of Hercules.
+//= http://herc.ws - http://github.com/HerculesWS/Hercules
+//=
+//= Copyright (C) 2014-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
+//= the Free Software Foundation, either version 3 of the License, or
+//= (at your option) any later version.
+//=
+//= This program is distributed in the hope that it will be useful,
+//= but WITHOUT ANY WARRANTY; without even the implied warranty of
+//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//= GNU General Public License for more details.
+//=
+//= You should have received a copy of the GNU General Public License
+//= along with this program. If not, see <http://www.gnu.org/licenses/>.
+//=========================================================================
+//= Hercules Log local configuration file.
+//=========================================================================
+
+map_log: {
+ // See conf/map/logs.conf for details
+}
diff --git a/conf/logs.conf b/conf/logs.conf
deleted file mode 100644
index 6933e84fe..000000000
--- a/conf/logs.conf
+++ /dev/null
@@ -1,134 +0,0 @@
-//--------------------------------------------------------------
-// Hercules Log Configuration File
-//--------------------------------------------------------------
-// Note 1: Value is a config switch (on/off, yes/no or 1/0)
-// Note 2: Value is in percents (100 means 100%)
-// Note 3: Value is a bit field. If no description is given,
-// assume unit types (1: Pc, 2: Mob, 4: Pet, 8: Homun)
-//--------------------------------------------------------------
-
-// Enable Logs? (Note 3)
-// 0x00000 - Don't log at all
-// 0x00001 - (T) Log trades
-// 0x00002 - (V) Log vending transactions
-// 0x00004 - (P) Log items drop/picked by players
-// 0x00008 - (L) Log items drop/looted by monsters
-// 0x00010 - (S) Log NPC transactions (buy/sell)
-// 0x00020 - (N) Log Script transactions (items deleted/acquired through quests)
-// 0x00040 - (D) Log items stolen from mobs (Steal/Gank)
-// 0x00080 - (C) Log player-used items (consumables/pet&hom&merc food/items used for skills&attacks)
-// 0x00100 - (O) Log produced/ingredient items
-// 0x00200 - (U) Log MVP prize items
-// 0x00400 - (A) Log player created/deleted items (through @/# commands)
-// 0x00800 - (R) Log items placed/retrieved from storage.
-// 0x01000 - (G) Log items placed/retrieved from guild storage.
-// 0x02000 - (E) Log mail system transactions.
-// 0x04000 - (I) Log auction system transactions.
-// 0x08000 - (B) Log buying store transactions
-// 0x20000 - (K) Log account bank transactions
-// 0x10000 - (X) Log all other transactions (rentals expiring/inserting cards/items removed by item_check/
-// rings deleted by divorce/pet egg (un)hatching/pet armor (un)equipping/Weapon Refine skill/Remove Trap skill)
-// Example: Log trades+vending+script items+created items: 1+2+32+1024 = 1059
-// Please note that moving items from inventory to cart and back is not logged by design.
-enable_logs: 0xFFFFF
-
-// Use MySQL Logs? [SQL Version Only] (Note 1)
-sql_logs: yes
-
-// LOGGING FILTERS
-// =============================================================
-// if any condition is true then the item will be logged
-// 0 = Don't log at all
-// 1 = Log any item
-// Advanced Filter Bits by item type: ||
-// 0002 - Healing items (0)
-// 0004 - Etc Items(3) + Arrows (10)
-// 0008 - Usable Items(2) + Lures,Scrolls(11) + Usable Cash Items(18)
-// 0016 - Weapon(4)
-// 0032 - Shields,Armor,Headgears,Accessories,etc(5)
-// 0064 - Cards(6)
-// 0128 - Pet Accessories(8) + Eggs(7) (well, monsters don't drop 'em but we'll use the same system for ALL logs)
-// 0256 - Log expensive items ( >= price_items_log)
-// 0512 - Log big amount of items ( >= amount_items_log)
-// 1024 - Log refined items (if their refine >= refine_items_log )
-// 2048 - Log rare items (if their drop chance <= rare_items_log )
-
-// Examples: (log filters)
-// log_filter: 1 = logs ANY items
-// log_filter: 2 = logs only HEALING items
-// log_filter: 4 = logs only Etc Items and Arrows
-// log_filter: 64 = logs only Cards
-// log_filter: 322 = logs only Healing items, Cards and those items which price is >= price_items_log
-// log_filter: 4080 = logs all items (including all rare, big amount) exept healing, etc, arrows and useble ones
-log_filter: 1
-
-// Log Items which Refine >= refine_items_log
-refine_items_log: 5
-// Log Items whith min drop rate <= rare_items_log
-// 1 = 0.01%, 100 = 1% drop chance, etc
-rare_items_log: 100
-// don't log it if the current item buy price < price_items_log
-price_items_log: 1000
-// don't log it if the current item amount < amount_items_log
-amount_items_log: 100
-//=============================================================
-
-// Log Dead Branch Usage (Note 1)
-log_branch: no
-
-// Track Zeny Changes
-// Filter settings
-// 0 - don't log; 1 - log any zeny changes; 2.....1000000 - minimal absolute logging zeny value
-log_zeny: 0
-
-// Log MVP Monster Drops (Note 1)
-// Outdated. Use Pick_Log instead. But this log could be useful to keep track slayed MVPs
-log_mvpdrop: no
-
-// Log AtCommands & Charcommands (Note 1)
-// Only commands issued by player groups ('conf/groups.conf') with
-// 'log_commands' setting set to 'true' will be logged.
-log_commands: yes
-
-// Log NPC 'logmes' commands (Note 1)
-log_npc: no
-
-// Log CHAT (Global, Whisper, Party, Guild, Main chat) (Note 3)
-// LOGGING FILTERS
-// =============================================================
-// 0 = Don't log at all
-// 1 - Log Global messages
-// 2 - Log Whisper messages
-// 4 - Log Party messages
-// 8 - Log Guild messages
-// 16 - Log Main chat messages
-// Example:
-// log_chat: 5 = logs both Whisper & Party messages
-// log_chat: 8 = logs only Guild messages
-// log_chat: 31 = logs everything
-log_chat: 0
-
-// Disable chat logging when WoE is running? (Note 1)
-log_chat_woe_disable: no
-
-// Logging files/tables
-// Following settings specify where to log to. If 'sql_logs' is
-// enabled, SQL tables are assumed, otherwise flat files.
-
-// log_gm_db: log/atcommandlog.log
-// log_branch_db: log/branchlog.log
-// log_chat_db: log/chatlog.log
-// log_mvpdrop_db: log/mvplog.log
-// log_npc_db: log/npclog.log
-// log_pick_db: log/picklog.log
-// log_zeny_db: log/zenylog.log
-
-log_gm_db: atcommandlog
-log_branch_db: branchlog
-log_chat_db: chatlog
-log_mvpdrop_db: mvplog
-log_npc_db: npclog
-log_pick_db: picklog
-log_zeny_db: zenylog
-
-import: conf/import/log_conf.txt
diff --git a/conf/map/logs.conf b/conf/map/logs.conf
new file mode 100644
index 000000000..aa4e16e95
--- /dev/null
+++ b/conf/map/logs.conf
@@ -0,0 +1,172 @@
+//================= Hercules Configuration ================================
+//= _ _ _
+//= | | | | | |
+//= | |_| | ___ _ __ ___ _ _| | ___ ___
+//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __|
+//= | | | | __/ | | (__| |_| | | __/\__ \
+//= \_| |_/\___|_| \___|\__,_|_|\___||___/
+//================= License ===============================================
+//= This file is part of Hercules.
+//= http://herc.ws - http://github.com/HerculesWS/Hercules
+//=
+//= Copyright (C) 2014-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
+//= the Free Software Foundation, either version 3 of the License, or
+//= (at your option) any later version.
+//=
+//= This program is distributed in the hope that it will be useful,
+//= but WITHOUT ANY WARRANTY; without even the implied warranty of
+//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//= GNU General Public License for more details.
+//=
+//= You should have received a copy of the GNU General Public License
+//= along with this program. If not, see <http://www.gnu.org/licenses/>.
+//=========================================================================
+//= Hercules Log configuration file.
+//=========================================================================
+// Note 1: Value is a config switch (on/off, yes/no or 1/0)
+// Note 2: Value is in percents (100 means 100%)
+// Note 3: Value is a bit field. If no description is given, assume unit
+// types (1: Pc, 2: Mob, 4: Pet, 8: Homun)
+//=========================================================================
+
+map_log: {
+ // Enable Logs? (Note 3)
+ // 0x00000 - Don't log at all
+ // 0x00001 - (T) Log trades
+ // 0x00002 - (V) Log vending transactions
+ // 0x00004 - (P) Log items drop/picked by players
+ // 0x00008 - (L) Log items drop/looted by monsters
+ // 0x00010 - (S) Log NPC transactions (buy/sell)
+ // 0x00020 - (N) Log Script transactions (items deleted/acquired through quests)
+ // 0x00040 - (D) Log items stolen from mobs (Steal/Gank)
+ // 0x00080 - (C) Log player-used items (consumables/pet&hom&merc food/items used for skills&attacks)
+ // 0x00100 - (O) Log produced/ingredient items
+ // 0x00200 - (U) Log MVP prize items
+ // 0x00400 - (A) Log player created/deleted items (through @/# commands)
+ // 0x00800 - (R) Log items placed/retrieved from storage.
+ // 0x01000 - (G) Log items placed/retrieved from guild storage.
+ // 0x02000 - (E) Log mail system transactions.
+ // 0x04000 - (I) Log auction system transactions.
+ // 0x08000 - (B) Log buying store transactions
+ // 0x20000 - (K) Log account bank transactions
+ // 0x10000 - (X) Log all other transactions (rentals expiring/inserting cards/items removed by item_check/
+ // rings deleted by divorce/pet egg (un)hatching/pet armor (un)equipping/Weapon Refine skill/Remove Trap skill)
+ // Example: Log trades+vending+script items+created items: 1+2+32+1024 = 1059
+ // Please note that moving items from inventory to cart and back is not logged by design.
+ enable: 0xFFFFF
+
+ // Logging files/tables
+ // Following settings specify where to log to. If 'use_sql' is
+ // true, SQL tables are assumed, otherwise flat files.
+ database: {
+ // Use MySQL Logs? (Note 1)
+ use_sql: true
+
+ // Flat files
+ // log_gm_db: "log/atcommandlog.log"
+ // log_branch_db: "log/branchlog.log"
+ // log_chat_db: "log/chatlog.log"
+ // log_mvpdrop_db: "log/mvplog.log"
+ // log_npc_db: "log/npclog.log"
+ // log_pick_db: "log/picklog.log"
+ // log_zeny_db: "log/zenylog.log"
+ // SQL tables
+ log_gm_db: "atcommandlog"
+ log_branch_db: "branchlog"
+ log_chat_db: "chatlog"
+ log_mvpdrop_db: "mvplog"
+ log_npc_db: "npclog"
+ log_pick_db: "picklog"
+ log_zeny_db: "zenylog"
+ }
+
+ // Log Dead Branch Usage (Note 1)
+ log_branch: false
+
+ // Track Zeny Changes
+ // Filter settings
+ // 0 - don't log; 1 - log any zeny changes; 2.....1000000 - minimal absolute logging zeny value
+ log_zeny: 0
+
+ // Log MVP Monster Drops (Note 1)
+ // Outdated. Use Pick_Log instead. But this log could be useful to keep track slayed MVPs
+ log_mvpdrop: false
+
+ // Log AtCommands & Charcommands (Note 1)
+ // Only commands issued by player groups ('conf/groups.conf') with
+ // 'log_commands' setting set to 'true' will be logged.
+ log_commands: true
+
+ // Log NPC 'logmes' commands (Note 1)
+ log_npc: false
+
+ // Logging filters
+ filter: {
+ item: {
+ // Filters
+ // if any condition is true then the item will be logged
+ // 0 = Don't log at all
+ // 1 = Log any item
+ // Advanced Filter Bits by item type: ||
+ // 0x002 - Healing items (0)
+ // 0x004 - Etc Items(3) + Arrows (10)
+ // 0x008 - Usable Items(2) + Lures,Scrolls(11) + Usable Cash Items(18)
+ // 0x010 - Weapon(4)
+ // 0x020 - Shields,Armor,Headgears,Accessories,etc(5)
+ // 0x040 - Cards(6)
+ // 0x080 - Pet Accessories(8) + Eggs(7) (well, monsters don't drop 'em but we'll use the same system for ALL logs)
+ // 0x100 - Log expensive items ( >= price_items_log)
+ // 0x200 - Log big amount of items ( >= amount_items_log)
+ // 0x400 - Log refined items (if their refine >= refine_items_log )
+ // 0x800 - Log rare items (if their drop chance <= rare_items_log )
+ // Examples: (log filters)
+ // log_filter: 1 = logs ANY items
+ // log_filter: 0x2 = logs only HEALING items
+ // log_filter: 0x4 = logs only Etc Items and Arrows
+ // log_filter: 0x40 = logs only Cards
+ // log_filter: 0x142 = logs only Healing items, Cards and those items which price is >= price_items_log
+ // log_filter: 0xff0 = logs all items (including all rare, big amount) except healing, etc, arrows and useble ones
+ log_filter: 1
+
+ // Log Items which Refine >= refine_items_log
+ refine_items_log: 5
+
+ // Log Items whith min drop rate <= rare_items_log
+ // 1 = 0.01%, 100 = 1% drop chance, etc
+ rare_items_log: 100
+
+ // don't log it if the current item buy price < price_items_log
+ price_items_log: 1000
+
+ // don't log it if the current item amount < amount_items_log
+ amount_items_log: 100
+ } // item
+
+ chat: {
+ // Log CHAT (Global, Whisper, Party, Guild, Main chat) (Note 3)
+ // LOGGING FILTERS
+ // =============================================================
+ // 0x00 = Don't log at all
+ // 0x01 - Log Global messages
+ // 0x02 - Log Whisper messages
+ // 0x04 - Log Party messages
+ // 0x08 - Log Guild messages
+ // 0x10 - Log Main chat messages
+ // Example:
+ // log_chat: 0x5 = logs both Whisper & Party messages
+ // log_chat: 0x8 = logs only Guild messages
+ // log_chat: 0x1f = logs everything
+ // FIXME: This isn't fully functional, as of now it's only checking
+ // if the log is active or not [Panikon]
+ log_chat: 0x1f
+
+ // Disable chat logging when WoE is running? (Note 1)
+ log_chat_woe_disable: false
+ } // chat
+ } // filter
+}
+
+import: "conf/import/logs.conf"
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 a6e19d88f..9be68bdf5 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -6365,7 +6365,7 @@ int do_init(int argc, char *argv[])
map_load_defaults();
map->INTER_CONF_NAME = aStrdup("conf/common/inter-server.conf");
- map->LOG_CONF_NAME = aStrdup("conf/logs.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/battle.conf");
map->ATCOMMAND_CONF_FILENAME = aStrdup("conf/atcommand.conf");
@@ -6399,6 +6399,7 @@ int do_init(int argc, char *argv[])
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");
#undef CHECK_OLD_LOCAL_CONF
}
@@ -6432,7 +6433,7 @@ int do_init(int argc, char *argv[])
battle->config_read(map->BATTLE_CONF_FILENAME);
atcommand->msg_read(map->MSG_CONF_NAME, false);
map->inter_config_read(map->INTER_CONF_NAME, false);
- logs->config_read(map->LOG_CONF_NAME);
+ logs->config_read(map->LOG_CONF_NAME, false);
}
script->config_read(map->SCRIPT_CONF_NAME);
@@ -6591,7 +6592,7 @@ void map_defaults(void) {
map->enable_spy = 0; //To enable/disable @spy commands, which consume too much cpu time when sending packets. [Skotlex]
map->INTER_CONF_NAME="conf/common/inter-server.conf";
- map->LOG_CONF_NAME="conf/logs.conf";
+ map->LOG_CONF_NAME="conf/map/logs.conf";
map->MAP_CONF_NAME = "conf/map/map-server.conf";
map->BATTLE_CONF_FILENAME = "conf/battle.conf";
map->ATCOMMAND_CONF_FILENAME = "conf/atcommand.conf";
diff --git a/tools/configconverter.pl b/tools/configconverter.pl
index 2d5eebe72..db34de2fd 100755
--- a/tools/configconverter.pl
+++ b/tools/configconverter.pl
@@ -475,6 +475,33 @@ my @defaults = (
import => {parse => \&parsecfg_stringarr, print => \&printcfg_nil, path => "", default => ["conf/maps.conf", "conf/import/map_conf.txt"]},
}
},
+ {
+ files => ['logs.conf', 'import/log_conf.txt'],
+ settings => {
+ enable_logs => {parse => \&parsecfg_int, print => \&printcfg_hexint, path => "logs:map_log/enable", default => 0xFFFFF},
+ sql_logs => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "logs:map_log/database/use_sql", default => "true"},
+ log_filter => {parse => \&parsecfg_int, print => \&printcfg_int, path => "logs:map_log/filter/item/", default => 1},
+ refine_items_log => {parse => \&parsecfg_int, print => \&printcfg_int, path => "logs:map_log/filter/item/", default => 5},
+ rare_items_log => {parse => \&parsecfg_int, print => \&printcfg_int, path => "logs:map_log/filter/item/", default => 100},
+ price_items_log => {parse => \&parsecfg_int, print => \&printcfg_int, path => "logs:map_log/filter/item/", default => 1000},
+ amount_items_log => {parse => \&parsecfg_int, print => \&printcfg_int, path => "logs:map_log/filter/item/", default => 100},
+ log_branch => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "logs:map_log/", default => "false"},
+ log_zeny => {parse => \&parsecfg_int, print => \&printcfg_int, path => "logs:map_log/", default => 0},
+ log_mvpdrop => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "logs:map_log/", default => "false"},
+ log_commands => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "logs:map_log/", default => "true"},
+ log_npc => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "logs:map_log/", default => "false"},
+ log_chat => {parse => \&parsecfg_int, print => \&printcfg_int, path => "logs:map_log/filter/chat/", default => 0},
+ log_chat_woe_disable => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "logs:map_log/filter/chat/", default => "false"},
+ log_gm_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "logs:map_log/database/", default => "atcommandlog"},
+ log_branch_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "logs:map_log/database/", default => "branchlog"},
+ log_chat_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "logs:map_log/database/", default => "chatlog"},
+ log_mvpdrop_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "logs:map_log/database/", default => "mvplog"},
+ log_npc_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "logs:map_log/database/", default => "npclog"},
+ log_pick_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "logs:map_log/database/", default => "picklog"},
+ log_zeny_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "logs:map_log/database/", default => "zenylog"},
+ import => {parse => \&parsecfg_string, print => \&printcfg_nil, path => "", default => "conf/import/log_conf.txt"},
+ }
+ },
);
for (@ARGV) {