diff options
author | eathenabot <eathenabot@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2011-12-19 21:37:55 +0000 |
---|---|---|
committer | eathenabot <eathenabot@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2011-12-19 21:37:55 +0000 |
commit | 5019704630e86a940669b44da6b1d824d8c1577f (patch) | |
tree | a8c226f6faf31dd59c92161f8733b08baf0c705b /src/map | |
parent | c2e9e54896c22a6c20c7be20d6068d63ac2294cb (diff) | |
download | hercules-5019704630e86a940669b44da6b1d824d8c1577f.tar.gz hercules-5019704630e86a940669b44da6b1d824d8c1577f.tar.bz2 hercules-5019704630e86a940669b44da6b1d824d8c1577f.tar.xz hercules-5019704630e86a940669b44da6b1d824d8c1577f.zip |
* Merged changes up to eAthena 15035.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@15166 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/log.c | 163 | ||||
-rw-r--r-- | src/map/log.h | 28 |
2 files changed, 103 insertions, 88 deletions
diff --git a/src/map/log.c b/src/map/log.c index 53738f045..cf10fdfd7 100644 --- a/src/map/log.c +++ b/src/map/log.c @@ -19,8 +19,6 @@ struct Log_Config log_config; -char timestring[255]; -time_t curtime; #ifdef SQL_INNODB // database is using an InnoDB engine so do not use DELAYED @@ -48,10 +46,10 @@ time_t curtime; //12 - Log rare items (if their drop chance <= rare_log ) //check if this item should be logged according the settings -int should_log_item(int filter, int nameid, int amount) +bool should_log_item(int filter, int nameid, int amount) { struct item_data *item_data; - if ((item_data= itemdb_exists(nameid)) == NULL) return 0; + if ((item_data= itemdb_exists(nameid)) == NULL) return false; if ((filter&1) || // Filter = 1, we log any item (filter&2 && item_data->type == IT_HEALING ) || (filter&4 && (item_data->type == IT_ETC || item_data->type == IT_AMMO) ) || @@ -63,17 +61,18 @@ int should_log_item(int filter, int nameid, int amount) (filter&256 && item_data->value_buy >= log_config.price_items_log ) || //expensive items (filter&512 && abs(amount) >= log_config.amount_items_log ) || //big amount of items (filter&2048 && ((item_data->maxchance != -1 && item_data->maxchance <= log_config.rare_items_log) || item_data->nameid == 714) ) //Rare items or Emperium - ) return item_data->nameid; + ) return true; - return 0; + return false; } -int log_branch(struct map_session_data *sd) + +void log_branch(struct map_session_data *sd) { if(!log_config.enable_logs) - return 0; + return; - nullpo_ret(sd); + nullpo_retv(sd); #ifndef TXT_ONLY if( log_config.sql_logs ) @@ -86,32 +85,33 @@ int log_branch(struct map_session_data *sd) { SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); - return 0; + return; } SqlStmt_Free(stmt); } else #endif { + char timestring[255]; + time_t curtime; FILE* logfp; + if((logfp = fopen(log_config.log_branch, "a+")) == NULL) - return 0; + return; time(&curtime); - strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&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); } - - return 1; } -int log_pick_pc(struct map_session_data *sd, const char *type, int nameid, int amount, struct item *itm) +void log_pick_pc(struct map_session_data *sd, const char *type, int nameid, int amount, struct item *itm) { - nullpo_ret(sd); + nullpo_retv(sd); if (!should_log_item(log_config.filter, nameid, amount)) - return 0; //we skip logging this item set - it doesn't meet our logging conditions [Lupus] + return; //we skip logging this item set - it doesn't meet our logging conditions [Lupus] #ifndef TXT_ONLY if( log_config.sql_logs ) @@ -121,26 +121,28 @@ int log_pick_pc(struct map_session_data *sd, const char *type, int nameid, int a log_config.log_pick_db, sd->status.char_id, type, nameid, amount, mapindex_id2name(sd->mapindex)) ) { Sql_ShowDebug(logmysql_handle); - return 0; + return; } } else { //We log Extended item if (SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`) VALUES (NOW(), '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s')", log_config.log_pick_db, sd->status.char_id, type, itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapindex_id2name(sd->mapindex)) ) { Sql_ShowDebug(logmysql_handle); - return 0; + return; } } } else #endif { + char timestring[255]; + time_t curtime; FILE* logfp; if((logfp = fopen(log_config.log_pick, "a+")) == NULL) - return 0; + return; time(&curtime); - strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime)); + strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); if( itm == NULL ) { //We log common item fprintf(logfp,"%s - %d\t%s\t%d,%d,%s\n", timestring, sd->status.char_id, type, nameid, amount, mapindex_id2name(sd->mapindex)); @@ -149,19 +151,18 @@ int log_pick_pc(struct map_session_data *sd, const char *type, int nameid, int a } fclose(logfp); } - - return 1; //Logged } + //Mob picked item -int log_pick_mob(struct mob_data *md, const char *type, int nameid, int amount, struct item *itm) +void log_pick_mob(struct mob_data *md, const char *type, int nameid, int amount, struct item *itm) { char* mapname; - nullpo_ret(md); + nullpo_retv(md); if (!should_log_item(log_config.filter, nameid, amount)) - return 0; //we skip logging this item set - it doesn't meet our logging conditions [Lupus] + return; //we skip logging this item set - it doesn't meet our logging conditions [Lupus] //either PLAYER or MOB (here we get map name and objects ID) mapname = map[md->bl.m].name; @@ -176,26 +177,28 @@ int log_pick_mob(struct mob_data *md, const char *type, int nameid, int amount, log_config.log_pick_db, md->class_, type, nameid, amount, mapname) ) { Sql_ShowDebug(logmysql_handle); - return 0; + return; } } else { //We log Extended item if (SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`) VALUES (NOW(), '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s')", log_config.log_pick_db, md->class_, type, itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname) ) { Sql_ShowDebug(logmysql_handle); - return 0; + return; } } } else #endif { + char timestring[255]; + time_t curtime; FILE *logfp; if((logfp=fopen(log_config.log_pick,"a+")) == NULL) - return 0; + return; time(&curtime); - strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime)); + strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); if( itm == NULL ) { //We log common item fprintf(logfp,"%s - %d\t%s\t%d,%d,%s\n", timestring, md->class_, type, nameid, amount, mapname); @@ -204,16 +207,15 @@ int log_pick_mob(struct mob_data *md, const char *type, int nameid, int amount, } fclose(logfp); } - - return 1; //Logged } -int log_zeny(struct map_session_data *sd, char *type, struct map_session_data *src_sd, int amount) + +void log_zeny(struct map_session_data *sd, char *type, struct map_session_data *src_sd, int amount) { if(!log_config.enable_logs || (log_config.zeny != 1 && abs(amount) < log_config.zeny)) - return 0; + return; - nullpo_ret(sd); + nullpo_retv(sd); #ifndef TXT_ONLY if( log_config.sql_logs ) @@ -222,30 +224,32 @@ int log_zeny(struct map_session_data *sd, char *type, struct map_session_data *s log_config.log_zeny_db, sd->status.char_id, src_sd->status.char_id, type, amount, mapindex_id2name(sd->mapindex)) ) { Sql_ShowDebug(logmysql_handle); - return 0; + return; } } else #endif { + char timestring[255]; + time_t curtime; FILE* logfp; + if((logfp=fopen(log_config.log_zeny,"a+")) == NULL) - return 0; + return; time(&curtime); - strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&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); } - - return 1; } -int log_mvpdrop(struct map_session_data *sd, int monster_id, int *log_mvp) + +void log_mvpdrop(struct map_session_data *sd, int monster_id, int *log_mvp) { if(!log_config.enable_logs) - return 0; + return; - nullpo_ret(sd); + nullpo_retv(sd); #ifndef TXT_ONLY if( log_config.sql_logs ) @@ -254,31 +258,32 @@ int log_mvpdrop(struct map_session_data *sd, int monster_id, int *log_mvp) log_config.log_mvpdrop_db, sd->status.char_id, monster_id, log_mvp[0], log_mvp[1], mapindex_id2name(sd->mapindex)) ) { Sql_ShowDebug(logmysql_handle); - return 0; + return; } } else #endif { + char timestring[255]; + time_t curtime; FILE* logfp; + if((logfp=fopen(log_config.log_mvpdrop,"a+")) == NULL) - return 0; + return; time(&curtime); - strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&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); } - - return 1; } -int log_atcommand(struct map_session_data* sd, const char* message) +void log_atcommand(struct map_session_data* sd, const char* message) { if(!log_config.enable_logs) - return 0; + return; - nullpo_ret(sd); + nullpo_retv(sd); #ifndef TXT_ONLY if( log_config.sql_logs ) @@ -293,31 +298,33 @@ int log_atcommand(struct map_session_data* sd, const char* message) { SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); - return 0; + return; } SqlStmt_Free(stmt); } else #endif { + char timestring[255]; + time_t curtime; FILE* logfp; + if((logfp = fopen(log_config.log_gm, "a+")) == NULL) - return 0; + return; time(&curtime); - strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&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 1; } -int log_npc(struct map_session_data* sd, const char* message) + +void log_npc(struct map_session_data* sd, const char* message) { if(!log_config.enable_logs) - return 0; + return; - nullpo_ret(sd); + nullpo_retv(sd); #ifndef TXT_ONLY if( log_config.sql_logs ) @@ -331,26 +338,28 @@ int log_npc(struct map_session_data* sd, const char* message) { SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); - return 0; + return; } SqlStmt_Free(stmt); } else #endif { + char timestring[255]; + time_t curtime; FILE* logfp; + if((logfp = fopen(log_config.log_npc, "a+")) == NULL) - return 0; + return; time(&curtime); - strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&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 1; } -int log_chat(const char* type, int type_id, int src_charid, int src_accid, const char* map, int x, int y, const char* dst_charname, const char* message) + +void log_chat(const char* type, int type_id, int src_charid, int src_accid, const char* map, int x, int y, const char* dst_charname, const char* message) { // Log CHAT (Global, Whisper, Party, Guild, Main chat) // LOGGING FILTERS [Lupus] @@ -367,13 +376,13 @@ int log_chat(const char* type, int type_id, int src_charid, int src_accid, const //Check ON/OFF if(log_config.chat <= 0) - return 0; //Deactivated + return; //Deactivated #ifndef TXT_ONLY if( log_config.sql_logs ) { 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(), '%s', '%d', '%d', '%d', '%s', '%d', '%d', ?, ?)", log_config.log_chat_db, 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)) @@ -382,23 +391,24 @@ int log_chat(const char* type, int type_id, int src_charid, int src_accid, const { SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); - return 0; + return; } SqlStmt_Free(stmt); } else #endif { + char timestring[255]; + time_t curtime; FILE* logfp; + if((logfp = fopen(log_config.log_chat, "a+")) == NULL) - return 0; + return; time(&curtime); - strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime)); + strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime)); fprintf(logfp, "%s - %s,%d,%d,%d,%s,%d,%d,%s,%s\n", timestring, type, type_id, src_charid, src_accid, map, x, y, dst_charname, message); fclose(logfp); } - - return 1; } @@ -410,9 +420,10 @@ void log_set_defaults(void) log_config.refine_items_log = 5; //log refined items, with refine >= +7 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; + log_config.amount_items_log = 100; } + int log_config_read(char *cfgName) { static int count = 0; @@ -420,13 +431,13 @@ int log_config_read(char *cfgName) FILE *fp; if ((count++) == 0) - log_set_defaults(); + log_set_defaults(); if((fp = fopen(cfgName, "r")) == NULL) { ShowError("Log configuration file not found at: %s\n", cfgName); return 1; - } + } while(fgets(line, sizeof(line), fp)) { @@ -525,7 +536,7 @@ int log_config_read(char *cfgName) ShowNotice("Logging NPC 'logmes' to file `%s`\n", w2); } else if(strcmpi(w1, "log_chat_file") == 0) { strcpy(log_config.log_chat, w2); - if(log_config.chat > 0 && !log_config.sql_logs) + if(log_config.chat > 0 && !log_config.sql_logs) ShowNotice("Logging CHAT to file `%s`\n", w2); //support the import command, just like any other config } else if(strcmpi(w1,"import") == 0) { diff --git a/src/map/log.h b/src/map/log.h index f88236489..66375ea4a 100644 --- a/src/map/log.h +++ b/src/map/log.h @@ -10,21 +10,22 @@ struct mob_data; struct item; //New logs -int log_pick_pc(struct map_session_data *sd, const char *type, int nameid, int amount, struct item *itm); -int log_pick_mob(struct mob_data *md, const char *type, int nameid, int amount, struct item *itm); -int log_zeny(struct map_session_data *sd, char *type, struct map_session_data *src_sd, int amount); +void log_pick_pc(struct map_session_data *sd, const char *type, int nameid, int amount, struct item *itm); +void log_pick_mob(struct mob_data *md, const char *type, int nameid, int amount, struct item *itm); +void log_zeny(struct map_session_data *sd, char *type, struct map_session_data *src_sd, int amount); -int log_npc(struct map_session_data *sd, const char *message); -int log_chat(const char* type, int type_id, int src_charid, int src_accid, const char* map, int x, int y, const char* dst_charname, const char* message); -int log_atcommand(struct map_session_data *sd, const char *message); +void log_npc(struct map_session_data *sd, const char *message); +void log_chat(const char* type, int type_id, int src_charid, int src_accid, const char* map, int x, int y, const char* dst_charname, const char* message); +void log_atcommand(struct map_session_data *sd, const char *message); //Old, but useful logs -int log_branch(struct map_session_data *sd); -int log_mvpdrop(struct map_session_data *sd, int monster_id, int *log_mvp); +void log_branch(struct map_session_data *sd); +void log_mvpdrop(struct map_session_data *sd, int monster_id, int *log_mvp); int log_config_read(char *cfgName); -typedef enum log_what { +typedef enum log_what +{ LOG_ALL = 0xFFFF, LOG_TRADES = 0x0002, LOG_VENDING = 0x0004, @@ -40,9 +41,11 @@ typedef enum log_what { LOG_GSTORAGE_ITEMS = 0x1000, // placed/retrieved from guild storage LOG_MAILS = 0x2000, // mail system transactions LOG_BUYING_STORE = 0x4000, // buying store transactions -} log_what; +} +log_what; -extern struct Log_Config { +extern struct Log_Config +{ enum log_what enable_logs; int filter; bool sql_logs; @@ -50,6 +53,7 @@ extern struct Log_Config { int branch, drop, mvpdrop, zeny, gm, npc, chat; char log_branch[64], log_pick[64], log_zeny[64], log_mvpdrop[64], log_gm[64], log_npc[64], log_chat[64]; char log_branch_db[32], log_pick_db[32], log_zeny_db[32], log_mvpdrop_db[32], log_gm_db[32], log_npc_db[32], log_chat_db[32]; -} log_config; +} +log_config; #endif /* _LOG_H_ */ |