From 19b8cbb835e867febb597b34187f6bbca48cbe7b Mon Sep 17 00:00:00 2001 From: shennetsind Date: Mon, 22 Apr 2013 18:28:18 -0300 Subject: Hercules April 22 MEGA-ULTRA-LONG Patch~! http://hercules.ws/board/topic/470-hercules-april-22-patch/ Signed-off-by: shennetsind --- src/map/log.c | 608 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 276 insertions(+), 332 deletions(-) (limited to 'src/map/log.c') diff --git a/src/map/log.c b/src/map/log.c index ca10c97ab..1cca0a098 100644 --- a/src/map/log.c +++ b/src/map/log.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/cbasetypes.h" #include "../common/sql.h" // SQL_INNODB @@ -19,8 +20,7 @@ /// filters for item logging -typedef enum e_log_filter -{ +typedef enum e_log_filter { LOG_FILTER_NONE = 0x000, LOG_FILTER_ALL = 0x001, // bits @@ -38,10 +38,6 @@ typedef enum e_log_filter } e_log_filter; - -struct Log_Config log_config; - - #ifdef SQL_INNODB // database is using an InnoDB engine so do not use DELAYED #define LOG_QUERY "INSERT" @@ -52,10 +48,8 @@ struct Log_Config log_config; /// obtain log type character for item/zeny logs -static char log_picktype2char(e_log_pick_type type) -{ - switch( type ) - { +static char log_picktype2char(e_log_pick_type type) { + switch( type ) { case LOG_TYPE_TRADE: return 'T'; // (T)rade case LOG_TYPE_VENDING: return 'V'; // (V)ending case LOG_TYPE_PICKDROP_PLAYER: return 'P'; // (P)player @@ -83,10 +77,8 @@ static char log_picktype2char(e_log_pick_type type) /// obtain log type character for chat logs -static char log_chattype2char(e_log_chat_type type) -{ - switch( type ) - { +static char log_chattype2char(e_log_chat_type type) { + switch( type ) { case LOG_CHAT_GLOBAL: return 'O'; // Gl(O)bal case LOG_CHAT_WHISPER: return 'W'; // (W)hisper case LOG_CHAT_PARTY: return 'P'; // (P)arty @@ -101,12 +93,10 @@ static char log_chattype2char(e_log_chat_type type) /// check if this item should be logged according the settings -static bool should_log_item(int nameid, int amount, int refine) -{ - int filter = log_config.filter; - struct item_data* id; +static bool should_log_item(int nameid, int amount, int refine, struct item_data *id) { + int filter = logs->config.filter; - if( ( id = itemdb_exists(nameid) ) == NULL ) + if( id == NULL ) return false; if( ( filter&LOG_FILTER_ALL ) || @@ -117,360 +107,289 @@ static bool should_log_item(int nameid, int amount, int refine) ( filter&LOG_FILTER_ARMOR && id->type == IT_ARMOR ) || ( filter&LOG_FILTER_CARD && id->type == IT_CARD ) || ( filter&LOG_FILTER_PETITEM && ( id->type == IT_PETEGG || id->type == IT_PETARMOR ) ) || - ( filter&LOG_FILTER_PRICE && id->value_buy >= log_config.price_items_log ) || - ( filter&LOG_FILTER_AMOUNT && abs(amount) >= log_config.amount_items_log ) || - ( filter&LOG_FILTER_REFINE && refine >= log_config.refine_items_log ) || - ( filter&LOG_FILTER_CHANCE && ( ( id->maxchance != -1 && id->maxchance <= log_config.rare_items_log ) || id->nameid == ITEMID_EMPERIUM ) ) + ( filter&LOG_FILTER_PRICE && id->value_buy >= logs->config.price_items_log ) || + ( filter&LOG_FILTER_AMOUNT && abs(amount) >= logs->config.amount_items_log ) || + ( filter&LOG_FILTER_REFINE && refine >= logs->config.refine_items_log ) || + ( filter&LOG_FILTER_CHANCE && ( ( id->maxchance != -1 && id->maxchance <= logs->config.rare_items_log ) || id->nameid == ITEMID_EMPERIUM ) ) ) return true; return false; } - +void log_branch_sub_sql(struct map_session_data* sd) { + SqlStmt* stmt; + stmt = SqlStmt_Malloc(logmysql_handle); + if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`branch_date`, `account_id`, `char_id`, `char_name`, `map`) VALUES (NOW(), '%d', '%d', ?, '%s')", logs->config.log_branch, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) ) + || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH)) + || SQL_SUCCESS != SqlStmt_Execute(stmt) ) + { + SqlStmt_ShowDebug(stmt); + SqlStmt_Free(stmt); + return; + } + SqlStmt_Free(stmt); +} +void log_branch_sub_txt(struct map_session_data* sd) { + char timestring[255]; + time_t curtime; + FILE* logfp; + + if( ( logfp = fopen(logs->config.log_branch, "a") ) == NULL ) + return; + time(&curtime); + strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); + fprintf(logfp,"%s - %s[%d:%d]\t%s\n", timestring, sd->status.name, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex)); + fclose(logfp); +} /// logs items, that summon monsters -void log_branch(struct map_session_data* sd) -{ +void log_branch(struct map_session_data* sd) { nullpo_retv(sd); - if( !log_config.branch ) + if( !logs->config.branch ) return; - if( log_config.sql_logs ) { -#ifdef BETA_THREAD_TEST - char entry[512]; - int e_length = 0; - e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`branch_date`, `account_id`, `char_id`, `char_name`, `map`) VALUES (NOW(), '%d', '%d', '%s', '%s')", log_config.log_branch, sd->status.account_id, sd->status.char_id, sd->status.name, mapindex_id2name(sd->mapindex)); - queryThread_log(entry,e_length); -#else - SqlStmt* stmt; - stmt = SqlStmt_Malloc(logmysql_handle); - if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`branch_date`, `account_id`, `char_id`, `char_name`, `map`) VALUES (NOW(), '%d', '%d', ?, '%s')", log_config.log_branch, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) ) - || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH)) - || SQL_SUCCESS != SqlStmt_Execute(stmt) ) - { - SqlStmt_ShowDebug(stmt); - SqlStmt_Free(stmt); - return; - } - SqlStmt_Free(stmt); -#endif - } - else + logs->branch_sub(sd); +} +void log_pick_sub_sql(int id, int16 m, e_log_pick_type type, int amount, struct item* itm, struct item_data *data) { + if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`) VALUES (NOW(), '%d', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%"PRIu64"')", + logs->config.log_pick, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->unique_id) ) { - char timestring[255]; - time_t curtime; - FILE* logfp; - - if( ( logfp = fopen(log_config.log_branch, "a") ) == NULL ) - return; - time(&curtime); - strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); - fprintf(logfp,"%s - %s[%d:%d]\t%s\n", timestring, sd->status.name, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex)); - fclose(logfp); + Sql_ShowDebug(logmysql_handle); + return; } } - +void log_pick_sub_txt(int id, int16 m, e_log_pick_type type, int amount, struct item* itm, struct item_data *data) { + char timestring[255]; + time_t curtime; + FILE* logfp; + + if( ( logfp = fopen(logs->config.log_pick, "a") ) == NULL ) + return; + time(&curtime); + strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); + fprintf(logfp,"%s - %d\t%c\t%d,%d,%d,%d,%d,%d,%d,%s,'%"PRIu64"'\n", timestring, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->unique_id); + fclose(logfp); +} /// logs item transactions (generic) -void log_pick(int id, int16 m, e_log_pick_type type, int amount, struct item* itm) -{ +void log_pick(int id, int16 m, e_log_pick_type type, int amount, struct item* itm, struct item_data *data) { nullpo_retv(itm); - if( ( log_config.enable_logs&type ) == 0 ) - {// disabled + if( ( logs->config.enable_logs&type ) == 0 ) {// disabled return; } - if( !should_log_item(itm->nameid, amount, itm->refine) ) + if( !should_log_item(itm->nameid, amount, itm->refine, data) ) return; //we skip logging this item set - it doesn't meet our logging conditions [Lupus] - if( log_config.sql_logs ) - { -#ifdef BETA_THREAD_TEST - char entry[512]; - int e_length = 0; - e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`) VALUES (NOW(), '%d', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%"PRIu64"')", - log_config.log_pick, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->unique_id); - queryThread_log(entry,e_length); -#else - if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`) VALUES (NOW(), '%d', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%"PRIu64"')", - log_config.log_pick, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->unique_id) ) - { - Sql_ShowDebug(logmysql_handle); - return; - } -#endif - } - else - { - char timestring[255]; - time_t curtime; - FILE* logfp; - - if( ( logfp = fopen(log_config.log_pick, "a") ) == NULL ) - return; - time(&curtime); - strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); - fprintf(logfp,"%s - %d\t%c\t%d,%d,%d,%d,%d,%d,%d,%s,'%"PRIu64"'\n", timestring, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->unique_id); - fclose(logfp); - } + logs->pick_sub(id,m,type,amount,itm,data); } /// logs item transactions (players) -void log_pick_pc(struct map_session_data* sd, e_log_pick_type type, int amount, struct item* itm) -{ +void log_pick_pc(struct map_session_data* sd, e_log_pick_type type, int amount, struct item* itm, struct item_data *data) { nullpo_retv(sd); - log_pick(sd->status.char_id, sd->bl.m, type, amount, itm); + log_pick(sd->status.char_id, sd->bl.m, type, amount, itm, data ? data : itemdb_exists(itm->nameid)); } /// logs item transactions (monsters) -void log_pick_mob(struct mob_data* md, e_log_pick_type type, int amount, struct item* itm) -{ +void log_pick_mob(struct mob_data* md, e_log_pick_type type, int amount, struct item* itm, struct item_data *data) { nullpo_retv(md); - log_pick(md->class_, md->bl.m, type, amount, itm); + log_pick(md->class_, md->bl.m, type, amount, itm, data ? data : itemdb_exists(itm->nameid)); +} +void log_zeny_sub_sql(struct map_session_data* sd, e_log_pick_type type, struct map_session_data* src_sd, int amount) { + if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `src_id`, `type`, `amount`, `map`) VALUES (NOW(), '%d', '%d', '%c', '%d', '%s')", + logs->config.log_zeny, sd->status.char_id, src_sd->status.char_id, log_picktype2char(type), amount, mapindex_id2name(sd->mapindex)) ) + { + Sql_ShowDebug(logmysql_handle); + return; + } +} +void log_zeny_sub_txt(struct map_session_data* sd, e_log_pick_type type, struct map_session_data* src_sd, int amount) { + char timestring[255]; + time_t curtime; + FILE* logfp; + + if( ( logfp = fopen(logs->config.log_zeny, "a") ) == NULL ) + return; + time(&curtime); + strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); + fprintf(logfp, "%s - %s[%d]\t%s[%d]\t%d\t\n", timestring, src_sd->status.name, src_sd->status.account_id, sd->status.name, sd->status.account_id, amount); + fclose(logfp); } - /// logs zeny transactions void log_zeny(struct map_session_data* sd, e_log_pick_type type, struct map_session_data* src_sd, int amount) { nullpo_retv(sd); - if( !log_config.zeny || ( log_config.zeny != 1 && abs(amount) < log_config.zeny ) ) + if( !logs->config.zeny || ( logs->config.zeny != 1 && abs(amount) < logs->config.zeny ) ) return; - if( log_config.sql_logs ) - { -#ifdef BETA_THREAD_TEST - char entry[512]; - int e_length = 0; - e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`time`, `char_id`, `src_id`, `type`, `amount`, `map`) VALUES (NOW(), '%d', '%d', '%c', '%d', '%s')", - log_config.log_zeny, sd->status.char_id, src_sd->status.char_id, log_picktype2char(type), amount, mapindex_id2name(sd->mapindex)); - queryThread_log(entry,e_length); -#else - if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `src_id`, `type`, `amount`, `map`) VALUES (NOW(), '%d', '%d', '%c', '%d', '%s')", - log_config.log_zeny, sd->status.char_id, src_sd->status.char_id, log_picktype2char(type), amount, mapindex_id2name(sd->mapindex)) ) - { - Sql_ShowDebug(logmysql_handle); - return; - } -#endif - } - else + logs->zeny_sub(sd,type,src_sd,amount); +} +void log_mvpdrop_sub_sql(struct map_session_data* sd, int monster_id, int* log_mvp) { + if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`mvp_date`, `kill_char_id`, `monster_id`, `prize`, `mvpexp`, `map`) VALUES (NOW(), '%d', '%d', '%d', '%d', '%s') ", + logs->config.log_mvpdrop, sd->status.char_id, monster_id, log_mvp[0], log_mvp[1], mapindex_id2name(sd->mapindex)) ) { - char timestring[255]; - time_t curtime; - FILE* logfp; - - if( ( logfp = fopen(log_config.log_zeny, "a") ) == NULL ) - return; - time(&curtime); - strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); - fprintf(logfp, "%s - %s[%d]\t%s[%d]\t%d\t\n", timestring, src_sd->status.name, src_sd->status.account_id, sd->status.name, sd->status.account_id, amount); - fclose(logfp); + Sql_ShowDebug(logmysql_handle); + return; } } - - +void log_mvpdrop_sub_txt(struct map_session_data* sd, int monster_id, int* log_mvp) { + char timestring[255]; + time_t curtime; + FILE* logfp; + + if( ( logfp = fopen(logs->config.log_mvpdrop,"a") ) == NULL ) + return; + time(&curtime); + strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); + fprintf(logfp,"%s - %s[%d:%d]\t%d\t%d,%d\n", timestring, sd->status.name, sd->status.account_id, sd->status.char_id, monster_id, log_mvp[0], log_mvp[1]); + fclose(logfp); +} /// logs MVP monster rewards void log_mvpdrop(struct map_session_data* sd, int monster_id, int* log_mvp) { nullpo_retv(sd); - if( !log_config.mvpdrop ) + if( !logs->config.mvpdrop ) return; - if( log_config.sql_logs ) - { -#ifdef BETA_THREAD_TEST - char entry[512]; - int e_length = 0; - e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`mvp_date`, `kill_char_id`, `monster_id`, `prize`, `mvpexp`, `map`) VALUES (NOW(), '%d', '%d', '%d', '%d', '%s') ", - log_config.log_mvpdrop, sd->status.char_id, monster_id, log_mvp[0], log_mvp[1], mapindex_id2name(sd->mapindex)); - queryThread_log(entry,e_length); -#else - if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`mvp_date`, `kill_char_id`, `monster_id`, `prize`, `mvpexp`, `map`) VALUES (NOW(), '%d', '%d', '%d', '%d', '%s') ", - log_config.log_mvpdrop, sd->status.char_id, monster_id, log_mvp[0], log_mvp[1], mapindex_id2name(sd->mapindex)) ) - { - Sql_ShowDebug(logmysql_handle); - return; - } -#endif - } - else + logs->mvpdrop_sub(sd,monster_id,log_mvp); +} + +void log_atcommand_sub_sql(struct map_session_data* sd, const char* message) { + SqlStmt* stmt; + + stmt = SqlStmt_Malloc(logmysql_handle); + if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`atcommand_date`, `account_id`, `char_id`, `char_name`, `map`, `command`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", logs->config.log_gm, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) ) + || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH)) + || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255)) + || SQL_SUCCESS != SqlStmt_Execute(stmt) ) { - char timestring[255]; - time_t curtime; - FILE* logfp; - - if( ( logfp = fopen(log_config.log_mvpdrop,"a") ) == NULL ) - return; - time(&curtime); - strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); - fprintf(logfp,"%s - %s[%d:%d]\t%d\t%d,%d\n", timestring, sd->status.name, sd->status.account_id, sd->status.char_id, monster_id, log_mvp[0], log_mvp[1]); - fclose(logfp); + SqlStmt_ShowDebug(stmt); + SqlStmt_Free(stmt); + return; } + SqlStmt_Free(stmt); +} +void log_atcommand_sub_txt(struct map_session_data* sd, const char* message) { + char timestring[255]; + time_t curtime; + FILE* logfp; + + if( ( logfp = fopen(logs->config.log_gm, "a") ) == NULL ) + return; + time(&curtime); + strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); + fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message); + fclose(logfp); } - - /// logs used atcommands void log_atcommand(struct map_session_data* sd, const char* message) { nullpo_retv(sd); - if( !log_config.commands || + if( !logs->config.commands || !pc_should_log_commands(sd) ) return; - if( log_config.sql_logs ) + logs->atcommand_sub(sd,message); +} + +void log_npc_sub_sql(struct map_session_data *sd, const char *message) { + SqlStmt* stmt; + stmt = SqlStmt_Malloc(logmysql_handle); + if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", logs->config.log_npc, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) ) + || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH)) + || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255)) + || SQL_SUCCESS != SqlStmt_Execute(stmt) ) { -#ifdef BETA_THREAD_TEST - char entry[512]; - int e_length = 0; - e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`atcommand_date`, `account_id`, `char_id`, `char_name`, `map`, `command`) VALUES (NOW(), '%d', '%d', '%s', '%s', '%s')", log_config.log_gm, sd->status.account_id, sd->status.char_id, sd->status.name ,mapindex_id2name(sd->mapindex), message); - queryThread_log(entry,e_length); -#else - SqlStmt* stmt; - - stmt = SqlStmt_Malloc(logmysql_handle); - if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`atcommand_date`, `account_id`, `char_id`, `char_name`, `map`, `command`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", log_config.log_gm, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) ) - || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH)) - || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255)) - || SQL_SUCCESS != SqlStmt_Execute(stmt) ) - { - SqlStmt_ShowDebug(stmt); - SqlStmt_Free(stmt); - return; - } + SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); -#endif - } - else - { - char timestring[255]; - time_t curtime; - FILE* logfp; - - if( ( logfp = fopen(log_config.log_gm, "a") ) == NULL ) - return; - time(&curtime); - strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); - fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message); - fclose(logfp); + return; } + SqlStmt_Free(stmt); +} +void log_npc_sub_txt(struct map_session_data *sd, const char *message) { + char timestring[255]; + time_t curtime; + FILE* logfp; + + if( ( logfp = fopen(logs->config.log_npc, "a") ) == NULL ) + return; + time(&curtime); + strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); + fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message); + fclose(logfp); } - - /// logs messages passed to script command 'logmes' void log_npc(struct map_session_data* sd, const char* message) { nullpo_retv(sd); - if( !log_config.npc ) + if( !logs->config.npc ) return; - if( log_config.sql_logs ) + logs->npc_sub(sd,message); +} + +void log_chat_sub_sql(e_log_chat_type type, int type_id, int src_charid, int src_accid, const char* map, int x, int y, const char* dst_charname, const char* message) { + SqlStmt* stmt; + + stmt = SqlStmt_Malloc(logmysql_handle); + if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`time`, `type`, `type_id`, `src_charid`, `src_accountid`, `src_map`, `src_map_x`, `src_map_y`, `dst_charname`, `message`) VALUES (NOW(), '%c', '%d', '%d', '%d', '%s', '%d', '%d', ?, ?)", logs->config.log_chat, log_chattype2char(type), type_id, src_charid, src_accid, map, x, y) + || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, (char*)dst_charname, safestrnlen(dst_charname, NAME_LENGTH)) + || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, CHAT_SIZE_MAX)) + || SQL_SUCCESS != SqlStmt_Execute(stmt) ) { -#ifdef BETA_THREAD_TEST - char entry[512]; - int e_length = 0; - e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes`) VALUES (NOW(), '%d', '%d', '%s', '%s', '%s')", log_config.log_npc, sd->status.account_id, sd->status.char_id, sd->status.name, mapindex_id2name(sd->mapindex), message ); - queryThread_log(entry,e_length); -#else - SqlStmt* stmt; - stmt = SqlStmt_Malloc(logmysql_handle); - if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", log_config.log_npc, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) ) - || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH)) - || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255)) - || SQL_SUCCESS != SqlStmt_Execute(stmt) ) - { - SqlStmt_ShowDebug(stmt); - SqlStmt_Free(stmt); - return; - } + SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); -#endif - } - else - { - char timestring[255]; - time_t curtime; - FILE* logfp; - - if( ( logfp = fopen(log_config.log_npc, "a") ) == NULL ) - return; - time(&curtime); - strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); - fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message); - fclose(logfp); + return; } + SqlStmt_Free(stmt); +} +void log_chat_sub_txt(e_log_chat_type type, int type_id, int src_charid, int src_accid, const char* map, int x, int y, const char* dst_charname, const char* message) { + char timestring[255]; + time_t curtime; + FILE* logfp; + + if( ( logfp = fopen(logs->config.log_chat, "a") ) == NULL ) + return; + time(&curtime); + strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); + fprintf(logfp, "%s - %c,%d,%d,%d,%s,%d,%d,%s,%s\n", timestring, log_chattype2char(type), type_id, src_charid, src_accid, map, x, y, dst_charname, message); + fclose(logfp); } - /// logs chat void log_chat(e_log_chat_type type, int type_id, int src_charid, int src_accid, const char* map, int x, int y, const char* dst_charname, const char* message) { - if( ( log_config.chat&type ) == 0 ) + if( ( logs->config.chat&type ) == 0 ) {// disabled return; } - if( log_config.log_chat_woe_disable && ( agit_flag || agit2_flag ) ) + if( logs->config.log_chat_woe_disable && ( agit_flag || agit2_flag ) ) {// no chat logging during woe return; } - if( log_config.sql_logs ) { -#ifdef BETA_THREAD_TEST - char entry[512]; - int e_length = 0; - e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`time`, `type`, `type_id`, `src_charid`, `src_accountid`, `src_map`, `src_map_x`, `src_map_y`, `dst_charname`, `message`) VALUES (NOW(), '%c', '%d', '%d', '%d', '%s', '%d', '%d', '%s', '%s')", log_config.log_chat, log_chattype2char(type), type_id, src_charid, src_accid, map, x, y, dst_charname, message ); - queryThread_log(entry,e_length); -#else - SqlStmt* stmt; - - stmt = SqlStmt_Malloc(logmysql_handle); - if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`time`, `type`, `type_id`, `src_charid`, `src_accountid`, `src_map`, `src_map_x`, `src_map_y`, `dst_charname`, `message`) VALUES (NOW(), '%c', '%d', '%d', '%d', '%s', '%d', '%d', ?, ?)", log_config.log_chat, log_chattype2char(type), type_id, src_charid, src_accid, map, x, y) - || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, (char*)dst_charname, safestrnlen(dst_charname, NAME_LENGTH)) - || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, CHAT_SIZE_MAX)) - || SQL_SUCCESS != SqlStmt_Execute(stmt) ) - { - SqlStmt_ShowDebug(stmt); - SqlStmt_Free(stmt); - return; - } - SqlStmt_Free(stmt); -#endif - } - else - { - char timestring[255]; - time_t curtime; - FILE* logfp; - - if( ( logfp = fopen(log_config.log_chat, "a") ) == NULL ) - return; - time(&curtime); - strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); - fprintf(logfp, "%s - %c,%d,%d,%d,%s,%d,%d,%s,%s\n", timestring, log_chattype2char(type), type_id, src_charid, src_accid, map, x, y, dst_charname, message); - fclose(logfp); - } + logs->chat_sub(type,type_id,src_charid,src_accid,map,x,y,dst_charname,message); } -void log_set_defaults(void) -{ - memset(&log_config, 0, sizeof(log_config)); +void log_set_defaults(void) { + memset(&logs->config, 0, sizeof(logs->config)); //LOG FILTER Default values - log_config.refine_items_log = 5; // log refined items, with refine >= +5 - log_config.rare_items_log = 100; // log rare items. drop chance <= 1% - log_config.price_items_log = 1000; // 1000z - log_config.amount_items_log = 100; + 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) -{ +int log_config_read(const char* cfgName) { static int count = 0; char line[1024], w1[1024], w2[1024]; FILE *fp; @@ -478,63 +397,60 @@ int log_config_read(const char* cfgName) if( count++ == 0 ) log_set_defaults(); - if( ( fp = fopen(cfgName, "r") ) == NULL ) - { + if( ( fp = fopen(cfgName, "r") ) == NULL ) { ShowError("Log configuration file not found at: %s\n", cfgName); return 1; } - while( fgets(line, sizeof(line), fp) ) - { + while( fgets(line, sizeof(line), fp) ) { if( line[0] == '/' && line[1] == '/' ) continue; - if( sscanf(line, "%[^:]: %[^\r\n]", w1, w2) == 2 ) - { + if( sscanf(line, "%[^:]: %[^\r\n]", w1, w2) == 2 ) { if( strcmpi(w1, "enable_logs") == 0 ) - log_config.enable_logs = (e_log_pick_type)config_switch(w2); + logs->config.enable_logs = (e_log_pick_type)config_switch(w2); else if( strcmpi(w1, "sql_logs") == 0 ) - log_config.sql_logs = (bool)config_switch(w2); + logs->config.sql_logs = (bool)config_switch(w2); //start of common filter settings else if( strcmpi(w1, "rare_items_log") == 0 ) - log_config.rare_items_log = atoi(w2); + logs->config.rare_items_log = atoi(w2); else if( strcmpi(w1, "refine_items_log") == 0 ) - log_config.refine_items_log = atoi(w2); + logs->config.refine_items_log = atoi(w2); else if( strcmpi(w1, "price_items_log") == 0 ) - log_config.price_items_log = atoi(w2); + logs->config.price_items_log = atoi(w2); else if( strcmpi(w1, "amount_items_log") == 0 ) - log_config.amount_items_log = atoi(w2); + logs->config.amount_items_log = atoi(w2); //end of common filter settings else if( strcmpi(w1, "log_branch") == 0 ) - log_config.branch = config_switch(w2); + logs->config.branch = config_switch(w2); else if( strcmpi(w1, "log_filter") == 0 ) - log_config.filter = config_switch(w2); + logs->config.filter = config_switch(w2); else if( strcmpi(w1, "log_zeny") == 0 ) - log_config.zeny = config_switch(w2); + logs->config.zeny = config_switch(w2); else if( strcmpi(w1, "log_commands") == 0 ) - log_config.commands = config_switch(w2); + logs->config.commands = config_switch(w2); else if( strcmpi(w1, "log_npc") == 0 ) - log_config.npc = config_switch(w2); + logs->config.npc = config_switch(w2); else if( strcmpi(w1, "log_chat") == 0 ) - log_config.chat = config_switch(w2); + logs->config.chat = config_switch(w2); else if( strcmpi(w1, "log_mvpdrop") == 0 ) - log_config.mvpdrop = config_switch(w2); + logs->config.mvpdrop = config_switch(w2); else if( strcmpi(w1, "log_chat_woe_disable") == 0 ) - log_config.log_chat_woe_disable = (bool)config_switch(w2); + logs->config.log_chat_woe_disable = (bool)config_switch(w2); else if( strcmpi(w1, "log_branch_db") == 0 ) - safestrncpy(log_config.log_branch, w2, sizeof(log_config.log_branch)); + safestrncpy(logs->config.log_branch, w2, sizeof(logs->config.log_branch)); else if( strcmpi(w1, "log_pick_db") == 0 ) - safestrncpy(log_config.log_pick, w2, sizeof(log_config.log_pick)); + safestrncpy(logs->config.log_pick, w2, sizeof(logs->config.log_pick)); else if( strcmpi(w1, "log_zeny_db") == 0 ) - safestrncpy(log_config.log_zeny, w2, sizeof(log_config.log_zeny)); + safestrncpy(logs->config.log_zeny, w2, sizeof(logs->config.log_zeny)); else if( strcmpi(w1, "log_mvpdrop_db") == 0 ) - safestrncpy(log_config.log_mvpdrop, w2, sizeof(log_config.log_mvpdrop)); + safestrncpy(logs->config.log_mvpdrop, w2, sizeof(logs->config.log_mvpdrop)); else if( strcmpi(w1, "log_gm_db") == 0 ) - safestrncpy(log_config.log_gm, w2, sizeof(log_config.log_gm)); + safestrncpy(logs->config.log_gm, w2, sizeof(logs->config.log_gm)); else if( strcmpi(w1, "log_npc_db") == 0 ) - safestrncpy(log_config.log_npc, w2, sizeof(log_config.log_npc)); + safestrncpy(logs->config.log_npc, w2, sizeof(logs->config.log_npc)); else if( strcmpi(w1, "log_chat_db") == 0 ) - safestrncpy(log_config.log_chat, w2, sizeof(log_config.log_chat)); + 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 ) log_config_read(w2); @@ -545,39 +461,67 @@ int log_config_read(const char* cfgName) fclose(fp); - if( --count == 0 ) - {// report final logging state - const char* target = log_config.sql_logs ? "table" : "file"; + if( --count == 0 ) {// report final logging state + const char* target = logs->config.sql_logs ? "table" : "file"; - if( log_config.enable_logs && log_config.filter ) - { - ShowInfo("Logging item transactions to %s '%s'.\n", target, log_config.log_pick); + if( logs->config.enable_logs && logs->config.filter ) { + ShowInfo("Logging item transactions to %s '%s'.\n", target, logs->config.log_pick); } - if( log_config.branch ) - { - ShowInfo("Logging monster summon item usage to %s '%s'.\n", target, log_config.log_pick); + if( logs->config.branch ) { + ShowInfo("Logging monster summon item usage to %s '%s'.\n", target, logs->config.log_pick); } - if( log_config.chat ) - { - ShowInfo("Logging chat to %s '%s'.\n", target, log_config.log_chat); + if( logs->config.chat ) { + ShowInfo("Logging chat to %s '%s'.\n", target, logs->config.log_chat); } - if( log_config.commands ) - { - ShowInfo("Logging commands to %s '%s'.\n", target, log_config.log_gm); + if( logs->config.commands ) { + ShowInfo("Logging commands to %s '%s'.\n", target, logs->config.log_gm); } - if( log_config.mvpdrop ) - { - ShowInfo("Logging MVP monster rewards to %s '%s'.\n", target, log_config.log_mvpdrop); + if( logs->config.mvpdrop ) { + ShowInfo("Logging MVP monster rewards to %s '%s'.\n", target, logs->config.log_mvpdrop); } - if( log_config.npc ) - { - ShowInfo("Logging 'logmes' messages to %s '%s'.\n", target, log_config.log_npc); + if( logs->config.npc ) { + ShowInfo("Logging 'logmes' messages to %s '%s'.\n", target, logs->config.log_npc); } - if( log_config.zeny ) - { - ShowInfo("Logging Zeny transactions to %s '%s'.\n", target, log_config.log_zeny); + if( logs->config.zeny ) { + ShowInfo("Logging Zeny transactions to %s '%s'.\n", target, logs->config.log_zeny); } + logs->config_done(); } return 0; } +void log_config_complete(void) { + if( logs->config.sql_logs ) { + logs->pick_sub = log_pick_sub_sql; + logs->zeny_sub = log_zeny_sub_sql; + logs->npc_sub = log_npc_sub_sql; + logs->chat_sub = log_chat_sub_sql; + logs->atcommand_sub = log_atcommand_sub_sql; + logs->branch_sub = log_branch_sub_sql; + logs->mvpdrop_sub = log_mvpdrop_sub_sql; + } +} +void log_defaults(void) { + logs = &log_s; + + logs->pick_pc = log_pick_pc; + logs->pick_mob = log_pick_mob; + logs->zeny = log_zeny; + logs->npc = log_npc; + logs->chat = log_chat; + logs->atcommand = log_atcommand; + logs->branch = log_branch; + logs->mvpdrop = log_mvpdrop; + logs->config_read = log_config_read; + logs->config_done = log_config_complete; + + /* will be modified in a few seconds once loading is complete. */ + logs->pick_sub = log_pick_sub_txt; + logs->zeny_sub = log_zeny_sub_txt; + logs->npc_sub = log_npc_sub_txt; + logs->chat_sub = log_chat_sub_txt; + logs->atcommand_sub = log_atcommand_sub_txt; + logs->branch_sub = log_branch_sub_txt; + logs->mvpdrop_sub = log_mvpdrop_sub_txt; + +} -- cgit v1.2.3-60-g2f50