UID155280
帖子
精華
主題
積分265
現金
積極性
威望
違規
熱心
推廣次數
閱讀權限5
註冊時間2009-5-13
在線時間 小時
最後登錄1970-1-1
TA的每日心情 | 擦汗 2010-7-29 11:52 PM |
---|
簽到天數: 6 天 連續簽到: 0 天 [LV.2]偶爾看看I
|

樓主 |
發表於 2009-8-17 20:16:48
|
顯示全部樓層
在這裡附上我的原碼(其實沒動過)
-
- log.c
- // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
- // For more information, see LICENCE in the main folder
- #include "../common/strlib.h"
- #include "../common/nullpo.h"
- #include "../common/showmsg.h"
- #include "battle.h"
- #include "itemdb.h"
- #include "log.h"
- #include "map.h"
- #include "mob.h"
- #include "pc.h"
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- struct Log_Config log_config;
- char timestring[255];
- time_t curtime;
- //FILTER OPTIONS
- //0 = Don't log
- //1 = Log any item
- //Bits: ||
- //2 - Healing items (0)
- //3 - Etc Items(3) + Arrows (10)
- //4 - Usable Items(2) + Scrolls,Lures(11)
- //5 - Weapon(4)
- //6 - Shields,Armor,Headgears,Accessories,etc(5)
- //7 - Cards(6)
- //8 - Pet Accessories(8) + Eggs(7) (well, monsters don't drop 'em but we'll use the same system for ALL logs)
- //9 - Log expensive items ( >= price_log)
- //10 - Log big amount of items ( >= amount_log)
- //11 - Log refined items (if their refine >= refine_log )
- //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)
- {
- struct item_data *item_data;
- if ((item_data= itemdb_exists(nameid)) == NULL) return 0;
- 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) ) ||
- (filter&8 && item_data->type == IT_USABLE ) ||
- (filter&16 && item_data->type == IT_WEAPON ) ||
- (filter&32 && item_data->type == IT_ARMOR ) ||
- (filter&64 && item_data->type == IT_CARD ) ||
- (filter&128 && (item_data->type == IT_PETEGG || item_data->type == IT_PETARMOR) ) ||
- (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 <= log_config.rare_items_log) || item_data->nameid == 714) ) //Rare items or Emperium
- ) return item_data->nameid;
- return 0;
- }
- int log_branch(struct map_session_data *sd)
- {
- if(!log_config.enable_logs)
- return 0;
- nullpo_retr(0, sd);
- #ifndef TXT_ONLY
- if( log_config.sql_logs )
- {
- SqlStmt* stmt;
- stmt = SqlStmt_Malloc(logmysql_handle);
- if( SQL_SUCCESS != SqlStmt_Prepare(stmt, "INSERT DELAYED 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) )
- || 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 0;
- }
- SqlStmt_Free(stmt);
- }
- else
- #endif
- {
- FILE* logfp;
- if((logfp = fopen(log_config.log_branch, "a+")) == NULL)
- return 0;
- time(&curtime);
- strftime(timestring, 254, "%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)
- {
- nullpo_retr(0, 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]
- #ifndef TXT_ONLY
- if( log_config.sql_logs )
- {
- if( itm == NULL ) { //We log common item
- if (SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `map`) VALUES (NOW(), '%d', '%s', '%d', '%d', '%s')",
- log_config.log_pick_db, sd->status.char_id, type, nameid, amount, mapindex_id2name(sd->mapindex)) )
- {
- Sql_ShowDebug(logmysql_handle);
- return 0;
- }
- } else { //We log Extended item
- if (SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED 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;
- }
- }
- }
- else
- #endif
- {
- FILE* logfp;
- if((logfp = fopen(log_config.log_pick, "a+")) == NULL)
- return 0;
- time(&curtime);
- strftime(timestring, 254, "%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));
- } else { //We log Extended item
- fprintf(logfp,"%s - %d\t%s\t%d,%d,%d,%d,%d,%d,%d,%s\n", timestring, 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));
- }
- 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)
- {
- char* mapname;
- nullpo_retr(0, 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]
- //either PLAYER or MOB (here we get map name and objects ID)
- mapname = map[md->bl.m].name;
- if(mapname==NULL)
- mapname="";
- #ifndef TXT_ONLY
- if( log_config.sql_logs )
- {
- if( itm == NULL ) { //We log common item
- if (SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `map`) VALUES (NOW(), '%d', '%s', '%d', '%d', '%s')",
- log_config.log_pick_db, md->class_, type, nameid, amount, mapname) )
- {
- Sql_ShowDebug(logmysql_handle);
- return 0;
- }
- } else { //We log Extended item
- if (SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED 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;
- }
- }
- }
- else
- #endif
- {
- FILE *logfp;
- if((logfp=fopen(log_config.log_pick,"a+")) == NULL)
- return 0;
- time(&curtime);
- strftime(timestring, 254, "%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);
- } else { //We log Extended item
- fprintf(logfp,"%s - %d\t%s\t%d,%d,%d,%d,%d,%d,%d,%s\n", timestring, md->class_, type, itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname);
- }
- fclose(logfp);
- }
-
- return 1; //Logged
- }
複製代碼 |
|