log.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "../common/sql.h" // SQL_INNODB
  4. #include "../common/strlib.h"
  5. #include "../common/nullpo.h"
  6. #include "../common/showmsg.h"
  7. #include "battle.h"
  8. #include "itemdb.h"
  9. #include "log.h"
  10. #include "map.h"
  11. #include "mob.h"
  12. #include "pc.h"
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16. struct Log_Config log_config;
  17. #ifdef SQL_INNODB
  18. // database is using an InnoDB engine so do not use DELAYED
  19. #define LOG_QUERY "INSERT"
  20. #else
  21. // database is using a MyISAM engine so use DELAYED
  22. #define LOG_QUERY "INSERT DELAYED"
  23. #endif
  24. /// obtain log type character for item/zeny logs
  25. static char log_picktype2char(e_log_pick_type type)
  26. {
  27. switch( type )
  28. {
  29. case LOG_TYPE_TRADE: return 'T'; // (T)rade
  30. case LOG_TYPE_VENDING: return 'V'; // (V)ending
  31. case LOG_TYPE_PICKDROP_PLAYER: return 'P'; // (P)player
  32. case LOG_TYPE_PICKDROP_MONSTER: return 'M'; // (M)onster
  33. case LOG_TYPE_NPC: return 'S'; // NPC (S)hop
  34. case LOG_TYPE_SCRIPT: return 'N'; // (N)PC Script
  35. //case LOG_TYPE_STEAL: return 'D'; // Steal/Snatcher
  36. case LOG_TYPE_CONSUME: return 'C'; // (C)onsumed
  37. //case LOG_TYPE_PRODUCE: return 'O'; // Pr(O)duced/Ingredients
  38. //case LOG_TYPE_MVP: return 'U'; // MVP Rewards
  39. case LOG_TYPE_COMMAND: return 'A'; // (A)dmin command
  40. case LOG_TYPE_STORAGE: return 'R'; // Sto(R)age
  41. case LOG_TYPE_GSTORAGE: return 'G'; // (G)uild storage
  42. case LOG_TYPE_MAIL: return 'E'; // (E)mail attachment
  43. //case LOG_TYPE_AUCTION: return 'I'; // Auct(I)on
  44. case LOG_TYPE_BUYING_STORE: return 'B'; // (B)uying Store
  45. case LOG_TYPE_LOOT: return 'L'; // (L)oot (consumed monster pick/drop)
  46. }
  47. // should not get here, fallback
  48. ShowDebug("log_picktype2char: Unknown pick type %d.\n", type);
  49. return 'S';
  50. }
  51. /// obtain log type character for chat logs
  52. static char log_chattype2char(e_log_chat_type type)
  53. {
  54. switch( type )
  55. {
  56. case LOG_CHAT_GLOBAL: return 'O'; // Gl(O)bal
  57. case LOG_CHAT_WHISPER: return 'W'; // (W)hisper
  58. case LOG_CHAT_PARTY: return 'P'; // (P)arty
  59. case LOG_CHAT_GUILD: return 'G'; // (G)uild
  60. case LOG_CHAT_MAINCHAT: return 'M'; // (M)ain chat
  61. }
  62. // should not get here, fallback
  63. ShowDebug("log_chattype2char: Unknown chat type %d.\n", type);
  64. return 'O';
  65. }
  66. //FILTER OPTIONS
  67. //0 = Don't log
  68. //1 = Log any item
  69. //Bits: ||
  70. //2 - Healing items (0)
  71. //3 - Etc Items(3) + Arrows (10)
  72. //4 - Usable Items(2) + Scrolls,Lures(11) + Usable Cash Items(18)
  73. //5 - Weapon(4)
  74. //6 - Shields,Armor,Headgears,Accessories,etc(5)
  75. //7 - Cards(6)
  76. //8 - Pet Accessories(8) + Eggs(7) (well, monsters don't drop 'em but we'll use the same system for ALL logs)
  77. //9 - Log expensive items ( >= price_log)
  78. //10 - Log big amount of items ( >= amount_log)
  79. //11 - Log refined items (if their refine >= refine_log )
  80. //12 - Log rare items (if their drop chance <= rare_log )
  81. //check if this item should be logged according the settings
  82. bool should_log_item(int filter, int nameid, int amount)
  83. {
  84. struct item_data *item_data;
  85. if ((item_data= itemdb_exists(nameid)) == NULL) return false;
  86. if ((filter&1) || // Filter = 1, we log any item
  87. (filter&2 && item_data->type == IT_HEALING ) ||
  88. (filter&4 && (item_data->type == IT_ETC || item_data->type == IT_AMMO) ) ||
  89. (filter&8 && (item_data->type == IT_USABLE || item_data->type == IT_CASH) ) ||
  90. (filter&16 && item_data->type == IT_WEAPON ) ||
  91. (filter&32 && item_data->type == IT_ARMOR ) ||
  92. (filter&64 && item_data->type == IT_CARD ) ||
  93. (filter&128 && (item_data->type == IT_PETEGG || item_data->type == IT_PETARMOR) ) ||
  94. (filter&256 && item_data->value_buy >= log_config.price_items_log ) || //expensive items
  95. (filter&512 && abs(amount) >= log_config.amount_items_log ) || //big amount of items
  96. (filter&2048 && ((item_data->maxchance != -1 && item_data->maxchance <= log_config.rare_items_log) || item_data->nameid == 714) ) //Rare items or Emperium
  97. ) return true;
  98. return false;
  99. }
  100. void log_branch(struct map_session_data *sd)
  101. {
  102. if( !log_config.branch )
  103. return;
  104. nullpo_retv(sd);
  105. #ifndef TXT_ONLY
  106. if( log_config.sql_logs )
  107. {
  108. SqlStmt* stmt;
  109. stmt = SqlStmt_Malloc(logmysql_handle);
  110. 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_db, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) )
  111. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH))
  112. || SQL_SUCCESS != SqlStmt_Execute(stmt) )
  113. {
  114. SqlStmt_ShowDebug(stmt);
  115. SqlStmt_Free(stmt);
  116. return;
  117. }
  118. SqlStmt_Free(stmt);
  119. }
  120. else
  121. #endif
  122. {
  123. char timestring[255];
  124. time_t curtime;
  125. FILE* logfp;
  126. if((logfp = fopen(log_config.log_branch, "a+")) == NULL)
  127. return;
  128. time(&curtime);
  129. strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime));
  130. 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));
  131. fclose(logfp);
  132. }
  133. }
  134. void log_pick_pc(struct map_session_data *sd, e_log_pick_type type, int nameid, int amount, struct item *itm)
  135. {
  136. nullpo_retv(sd);
  137. if( ( log_config.enable_logs&type ) == 0 )
  138. {// disabled
  139. return;
  140. }
  141. if (!should_log_item(log_config.filter, nameid, amount))
  142. return; //we skip logging this item set - it doesn't meet our logging conditions [Lupus]
  143. #ifndef TXT_ONLY
  144. if( log_config.sql_logs )
  145. {
  146. if( itm == NULL ) { //We log common item
  147. if (SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `map`) VALUES (NOW(), '%d', '%c', '%d', '%d', '%s')",
  148. log_config.log_pick_db, sd->status.char_id, log_picktype2char(type), nameid, amount, mapindex_id2name(sd->mapindex)) )
  149. {
  150. Sql_ShowDebug(logmysql_handle);
  151. return;
  152. }
  153. } else { //We log Extended item
  154. 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', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s')",
  155. log_config.log_pick_db, sd->status.char_id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapindex_id2name(sd->mapindex)) )
  156. {
  157. Sql_ShowDebug(logmysql_handle);
  158. return;
  159. }
  160. }
  161. }
  162. else
  163. #endif
  164. {
  165. char timestring[255];
  166. time_t curtime;
  167. FILE* logfp;
  168. if((logfp = fopen(log_config.log_pick, "a+")) == NULL)
  169. return;
  170. time(&curtime);
  171. strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime));
  172. if( itm == NULL ) { //We log common item
  173. fprintf(logfp,"%s - %d\t%c\t%d,%d,%s\n", timestring, sd->status.char_id, log_picktype2char(type), nameid, amount, mapindex_id2name(sd->mapindex));
  174. } else { //We log Extended item
  175. fprintf(logfp,"%s - %d\t%c\t%d,%d,%d,%d,%d,%d,%d,%s\n", timestring, sd->status.char_id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapindex_id2name(sd->mapindex));
  176. }
  177. fclose(logfp);
  178. }
  179. }
  180. //Mob picked item
  181. void log_pick_mob(struct mob_data *md, e_log_pick_type type, int nameid, int amount, struct item *itm)
  182. {
  183. char* mapname;
  184. nullpo_retv(md);
  185. if( ( log_config.enable_logs&type ) == 0 )
  186. {// disabled
  187. return;
  188. }
  189. if (!should_log_item(log_config.filter, nameid, amount))
  190. return; //we skip logging this item set - it doesn't meet our logging conditions [Lupus]
  191. //either PLAYER or MOB (here we get map name and objects ID)
  192. mapname = map[md->bl.m].name;
  193. if(mapname==NULL)
  194. mapname="";
  195. #ifndef TXT_ONLY
  196. if( log_config.sql_logs )
  197. {
  198. if( itm == NULL ) { //We log common item
  199. if (SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `map`) VALUES (NOW(), '%d', '%c', '%d', '%d', '%s')",
  200. log_config.log_pick_db, md->class_, log_picktype2char(type), nameid, amount, mapname) )
  201. {
  202. Sql_ShowDebug(logmysql_handle);
  203. return;
  204. }
  205. } else { //We log Extended item
  206. 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', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s')",
  207. log_config.log_pick_db, md->class_, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname) )
  208. {
  209. Sql_ShowDebug(logmysql_handle);
  210. return;
  211. }
  212. }
  213. }
  214. else
  215. #endif
  216. {
  217. char timestring[255];
  218. time_t curtime;
  219. FILE *logfp;
  220. if((logfp=fopen(log_config.log_pick,"a+")) == NULL)
  221. return;
  222. time(&curtime);
  223. strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime));
  224. if( itm == NULL ) { //We log common item
  225. fprintf(logfp,"%s - %d\t%c\t%d,%d,%s\n", timestring, md->class_, log_picktype2char(type), nameid, amount, mapname);
  226. } else { //We log Extended item
  227. fprintf(logfp,"%s - %d\t%c\t%d,%d,%d,%d,%d,%d,%d,%s\n", timestring, md->class_, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname);
  228. }
  229. fclose(logfp);
  230. }
  231. }
  232. void log_pick(struct block_list* bl, e_log_pick_type type, int nameid, int amount, struct item* itm)
  233. {
  234. if( bl == NULL )
  235. {
  236. ShowError("log_pick: bl == NULL\n");
  237. }
  238. else switch( bl->type )
  239. {
  240. case BL_PC: log_pick_pc((TBL_PC*)bl, type, nameid, amount, itm); break;
  241. case BL_MOB: log_pick_mob((TBL_MOB*)bl, type, nameid, amount, itm); break;
  242. default:
  243. ShowDebug("log_pick: Unhandled bl type %d.\n", bl->type);
  244. }
  245. }
  246. void log_zeny(struct map_session_data *sd, e_log_pick_type type, struct map_session_data *src_sd, int amount)
  247. {
  248. if( !log_config.zeny || ( log_config.zeny != 1 && abs(amount) < log_config.zeny ) )
  249. return;
  250. nullpo_retv(sd);
  251. #ifndef TXT_ONLY
  252. if( log_config.sql_logs )
  253. {
  254. 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')",
  255. log_config.log_zeny_db, sd->status.char_id, src_sd->status.char_id, log_picktype2char(type), amount, mapindex_id2name(sd->mapindex)) )
  256. {
  257. Sql_ShowDebug(logmysql_handle);
  258. return;
  259. }
  260. }
  261. else
  262. #endif
  263. {
  264. char timestring[255];
  265. time_t curtime;
  266. FILE* logfp;
  267. if((logfp=fopen(log_config.log_zeny,"a+")) == NULL)
  268. return;
  269. time(&curtime);
  270. strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime));
  271. 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);
  272. fclose(logfp);
  273. }
  274. }
  275. void log_mvpdrop(struct map_session_data *sd, int monster_id, int *log_mvp)
  276. {
  277. if( !log_config.mvpdrop )
  278. return;
  279. nullpo_retv(sd);
  280. #ifndef TXT_ONLY
  281. if( log_config.sql_logs )
  282. {
  283. 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') ",
  284. log_config.log_mvpdrop_db, sd->status.char_id, monster_id, log_mvp[0], log_mvp[1], mapindex_id2name(sd->mapindex)) )
  285. {
  286. Sql_ShowDebug(logmysql_handle);
  287. return;
  288. }
  289. }
  290. else
  291. #endif
  292. {
  293. char timestring[255];
  294. time_t curtime;
  295. FILE* logfp;
  296. if((logfp=fopen(log_config.log_mvpdrop,"a+")) == NULL)
  297. return;
  298. time(&curtime);
  299. strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime));
  300. 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]);
  301. fclose(logfp);
  302. }
  303. }
  304. void log_atcommand(struct map_session_data* sd, int cmdlvl, const char* message)
  305. {
  306. if( cmdlvl < log_config.gm )
  307. return;
  308. nullpo_retv(sd);
  309. #ifndef TXT_ONLY
  310. if( log_config.sql_logs )
  311. {
  312. SqlStmt* stmt;
  313. stmt = SqlStmt_Malloc(logmysql_handle);
  314. 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_db, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) )
  315. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH))
  316. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255))
  317. || SQL_SUCCESS != SqlStmt_Execute(stmt) )
  318. {
  319. SqlStmt_ShowDebug(stmt);
  320. SqlStmt_Free(stmt);
  321. return;
  322. }
  323. SqlStmt_Free(stmt);
  324. }
  325. else
  326. #endif
  327. {
  328. char timestring[255];
  329. time_t curtime;
  330. FILE* logfp;
  331. if((logfp = fopen(log_config.log_gm, "a+")) == NULL)
  332. return;
  333. time(&curtime);
  334. strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime));
  335. fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message);
  336. fclose(logfp);
  337. }
  338. }
  339. void log_npc(struct map_session_data* sd, const char* message)
  340. {
  341. if( !log_config.npc )
  342. return;
  343. nullpo_retv(sd);
  344. #ifndef TXT_ONLY
  345. if( log_config.sql_logs )
  346. {
  347. SqlStmt* stmt;
  348. stmt = SqlStmt_Malloc(logmysql_handle);
  349. 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_db, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) )
  350. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH))
  351. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255))
  352. || SQL_SUCCESS != SqlStmt_Execute(stmt) )
  353. {
  354. SqlStmt_ShowDebug(stmt);
  355. SqlStmt_Free(stmt);
  356. return;
  357. }
  358. SqlStmt_Free(stmt);
  359. }
  360. else
  361. #endif
  362. {
  363. char timestring[255];
  364. time_t curtime;
  365. FILE* logfp;
  366. if((logfp = fopen(log_config.log_npc, "a+")) == NULL)
  367. return;
  368. time(&curtime);
  369. strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime));
  370. fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message);
  371. fclose(logfp);
  372. }
  373. }
  374. 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)
  375. {
  376. if( (log_config.chat&type) == 0 )
  377. {// disabled
  378. return;
  379. }
  380. if( log_config.log_chat_woe_disable && ( agit_flag || agit2_flag ) )
  381. {// no chat logging during woe
  382. return;
  383. }
  384. #ifndef TXT_ONLY
  385. if( log_config.sql_logs )
  386. {
  387. SqlStmt* stmt;
  388. stmt = SqlStmt_Malloc(logmysql_handle);
  389. 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_db, log_chattype2char(type), type_id, src_charid, src_accid, map, x, y)
  390. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, (char*)dst_charname, safestrnlen(dst_charname, NAME_LENGTH))
  391. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, CHAT_SIZE_MAX))
  392. || SQL_SUCCESS != SqlStmt_Execute(stmt) )
  393. {
  394. SqlStmt_ShowDebug(stmt);
  395. SqlStmt_Free(stmt);
  396. return;
  397. }
  398. SqlStmt_Free(stmt);
  399. }
  400. else
  401. #endif
  402. {
  403. char timestring[255];
  404. time_t curtime;
  405. FILE* logfp;
  406. if((logfp = fopen(log_config.log_chat, "a+")) == NULL)
  407. return;
  408. time(&curtime);
  409. strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime));
  410. 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);
  411. fclose(logfp);
  412. }
  413. }
  414. void log_set_defaults(void)
  415. {
  416. memset(&log_config, 0, sizeof(log_config));
  417. //LOG FILTER Default values
  418. log_config.refine_items_log = 5; //log refined items, with refine >= +5
  419. log_config.rare_items_log = 100; //log rare items. drop chance <= 1%
  420. log_config.price_items_log = 1000; //1000z
  421. log_config.amount_items_log = 100;
  422. }
  423. int log_config_read(char *cfgName)
  424. {
  425. static int count = 0;
  426. char line[1024], w1[1024], w2[1024];
  427. FILE *fp;
  428. if ((count++) == 0)
  429. log_set_defaults();
  430. if((fp = fopen(cfgName, "r")) == NULL)
  431. {
  432. ShowError("Log configuration file not found at: %s\n", cfgName);
  433. return 1;
  434. }
  435. while(fgets(line, sizeof(line), fp))
  436. {
  437. if(line[0] == '/' && line[1] == '/')
  438. continue;
  439. if(sscanf(line, "%[^:]: %[^\r\n]", w1, w2) == 2)
  440. {
  441. if(strcmpi(w1,"enable_logs") == 0) {
  442. log_config.enable_logs = (e_log_pick_type)config_switch(w2);
  443. } else if(strcmpi(w1,"sql_logs") == 0) {
  444. log_config.sql_logs = (bool)config_switch(w2);
  445. //start of common filter settings
  446. } else if(strcmpi(w1,"rare_items_log") == 0) {
  447. log_config.rare_items_log = (atoi(w2));
  448. } else if(strcmpi(w1,"refine_items_log") == 0) {
  449. log_config.refine_items_log = (atoi(w2));
  450. } else if(strcmpi(w1,"price_items_log") == 0) {
  451. log_config.price_items_log = (atoi(w2));
  452. } else if(strcmpi(w1,"amount_items_log") == 0) {
  453. log_config.amount_items_log = (atoi(w2));
  454. //end of common filter settings
  455. } else if(strcmpi(w1,"log_branch") == 0) {
  456. log_config.branch = config_switch(w2);
  457. } else if(strcmpi(w1,"log_filter") == 0) {
  458. log_config.filter = config_switch(w2);
  459. } else if(strcmpi(w1,"log_zeny") == 0) {
  460. log_config.zeny = config_switch(w2);
  461. } else if(strcmpi(w1,"log_gm") == 0) {
  462. log_config.gm = config_switch(w2);
  463. } else if(strcmpi(w1,"log_npc") == 0) {
  464. log_config.npc = config_switch(w2);
  465. } else if(strcmpi(w1, "log_chat") == 0) {
  466. log_config.chat = config_switch(w2);
  467. } else if(strcmpi(w1,"log_mvpdrop") == 0) {
  468. log_config.mvpdrop = config_switch(w2);
  469. } else if(strcmpi(w1,"log_chat_woe_disable") == 0) {
  470. log_config.log_chat_woe_disable = (bool)config_switch(w2);
  471. }
  472. #ifndef TXT_ONLY
  473. else if(strcmpi(w1, "log_branch_db") == 0) {
  474. strcpy(log_config.log_branch_db, w2);
  475. if(log_config.branch == 1)
  476. ShowNotice("Logging Dead Branch Usage to table `%s`\n", w2);
  477. } else if(strcmpi(w1, "log_pick_db") == 0) {
  478. strcpy(log_config.log_pick_db, w2);
  479. if(log_config.filter)
  480. ShowNotice("Logging Item Picks to table `%s`\n", w2);
  481. } else if(strcmpi(w1, "log_zeny_db") == 0) {
  482. strcpy(log_config.log_zeny_db, w2);
  483. if(log_config.zeny == 1)
  484. ShowNotice("Logging Zeny to table `%s`\n", w2);
  485. } else if(strcmpi(w1, "log_mvpdrop_db") == 0) {
  486. strcpy(log_config.log_mvpdrop_db, w2);
  487. if(log_config.mvpdrop == 1)
  488. ShowNotice("Logging MVP Drops to table `%s`\n", w2);
  489. } else if(strcmpi(w1, "log_gm_db") == 0) {
  490. strcpy(log_config.log_gm_db, w2);
  491. if(log_config.gm > 0)
  492. ShowNotice("Logging GM Level %d Commands to table `%s`\n", log_config.gm, w2);
  493. } else if(strcmpi(w1, "log_npc_db") == 0) {
  494. strcpy(log_config.log_npc_db, w2);
  495. if(log_config.npc > 0)
  496. ShowNotice("Logging NPC 'logmes' to table `%s`\n", w2);
  497. } else if(strcmpi(w1, "log_chat_db") == 0) {
  498. strcpy(log_config.log_chat_db, w2);
  499. if(log_config.chat > 0)
  500. ShowNotice("Logging CHAT to table `%s`\n", w2);
  501. }
  502. #endif
  503. else if(strcmpi(w1, "log_branch_file") == 0) {
  504. strcpy(log_config.log_branch, w2);
  505. if(log_config.branch > 0 && !log_config.sql_logs)
  506. ShowNotice("Logging Dead Branch Usage to file `%s`\n", w2);
  507. } else if(strcmpi(w1, "log_pick_file") == 0) {
  508. strcpy(log_config.log_pick, w2);
  509. if(log_config.filter > 0 && !log_config.sql_logs)
  510. ShowNotice("Logging Item Picks to file `%s`\n", w2);
  511. } else if(strcmpi(w1, "log_zeny_file") == 0) {
  512. strcpy(log_config.log_zeny, w2);
  513. if(log_config.zeny > 0 && !log_config.sql_logs)
  514. ShowNotice("Logging Zeny to file `%s`\n", w2);
  515. } else if(strcmpi(w1, "log_mvpdrop_file") == 0) {
  516. strcpy(log_config.log_mvpdrop, w2);
  517. if(log_config.mvpdrop > 0 && !log_config.sql_logs)
  518. ShowNotice("Logging MVP Drops to file `%s`\n", w2);
  519. } else if(strcmpi(w1, "log_gm_file") == 0) {
  520. strcpy(log_config.log_gm, w2);
  521. if(log_config.gm > 0 && !log_config.sql_logs)
  522. ShowNotice("Logging GM Level %d Commands to file `%s`\n", log_config.gm, w2);
  523. } else if(strcmpi(w1, "log_npc_file") == 0) {
  524. strcpy(log_config.log_npc, w2);
  525. if(log_config.npc > 0 && !log_config.sql_logs)
  526. ShowNotice("Logging NPC 'logmes' to file `%s`\n", w2);
  527. } else if(strcmpi(w1, "log_chat_file") == 0) {
  528. strcpy(log_config.log_chat, w2);
  529. if(log_config.chat > 0 && !log_config.sql_logs)
  530. ShowNotice("Logging CHAT to file `%s`\n", w2);
  531. //support the import command, just like any other config
  532. } else if(strcmpi(w1,"import") == 0) {
  533. log_config_read(w2);
  534. }
  535. }
  536. }
  537. fclose(fp);
  538. return 0;
  539. }