diff options
author | gepard1984 <gepard1984@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-01-18 00:45:35 +0000 |
---|---|---|
committer | gepard1984 <gepard1984@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-01-18 00:45:35 +0000 |
commit | 7bdb98374ade0b0d2aad8e2f85b0c799112c170d (patch) | |
tree | 25b738619cf960e7bfc933cf5beecd958cf240f8 /src/map | |
parent | c3743d84907e4aea48a02d43f453b957287238e4 (diff) | |
download | hercules-7bdb98374ade0b0d2aad8e2f85b0c799112c170d.tar.gz hercules-7bdb98374ade0b0d2aad8e2f85b0c799112c170d.tar.bz2 hercules-7bdb98374ade0b0d2aad8e2f85b0c799112c170d.tar.xz hercules-7bdb98374ade0b0d2aad8e2f85b0c799112c170d.zip |
Reorganized picklog functions a bit to reuse some common code.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@15486 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/log.c | 128 | ||||
-rw-r--r-- | src/map/log.h | 5 | ||||
-rw-r--r-- | src/map/mob.c | 9 | ||||
-rw-r--r-- | src/map/pc.c | 14 | ||||
-rw-r--r-- | src/map/script.c | 4 | ||||
-rw-r--r-- | src/map/skill.c | 4 |
6 files changed, 34 insertions, 130 deletions
diff --git a/src/map/log.c b/src/map/log.c index 4da060fe1..fb1aa11a1 100644 --- a/src/map/log.c +++ b/src/map/log.c @@ -167,40 +167,26 @@ void log_branch(struct map_session_data* sd) } } - -/// logs item transactions (players) -void log_pick_pc(struct map_session_data* sd, e_log_pick_type type, int nameid, int amount, struct item* itm) +/// logs item transactions (generic) +void log_pick(int id, int m, e_log_pick_type type, int amount, struct item* itm) { - nullpo_retv(sd); - + nullpo_retv(itm); if( ( log_config.enable_logs&type ) == 0 ) {// disabled return; } - if( !should_log_item(nameid, amount, itm ? itm->refine : 0) ) + if( !should_log_item(itm->nameid, amount, itm->refine) ) return; //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, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `map`) VALUES (NOW(), '%d', '%c', '%d', '%d', '%s')", - log_config.log_pick, sd->status.char_id, log_picktype2char(type), nameid, amount, mapindex_id2name(sd->mapindex)) ) - { - Sql_ShowDebug(logmysql_handle); - 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', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s')", - log_config.log_pick, 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)) ) - { - Sql_ShowDebug(logmysql_handle); - return; - } + 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')", + 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:"") ) + { + Sql_ShowDebug(logmysql_handle); + return; } } else @@ -214,104 +200,26 @@ void log_pick_pc(struct map_session_data* sd, e_log_pick_type type, int nameid, return; time(&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%c\t%d,%d,%s\n", timestring, sd->status.char_id, log_picktype2char(type), nameid, amount, mapindex_id2name(sd->mapindex)); - } - else - {//We log Extended item - 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)); - } + fprintf(logfp,"%s - %d\t%c\t%d,%d,%d,%d,%d,%d,%d,%s\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:""); fclose(logfp); } } - -/// logs item transactions (monsters) -void log_pick_mob(struct mob_data* md, e_log_pick_type type, int nameid, int amount, struct item* itm) +/// logs item transactions (players) +void log_pick_pc(struct map_session_data* sd, e_log_pick_type type, int amount, struct item* itm) { - char* mapname; - - nullpo_retv(md); - - if( ( log_config.enable_logs&type ) == 0 ) - {// disabled - return; - } - - if( !should_log_item(nameid, amount, itm ? itm->refine : 0) ) - 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; - 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, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `map`) VALUES (NOW(), '%d', '%c', '%d', '%d', '%s')", - log_config.log_pick, md->class_, log_picktype2char(type), nameid, amount, mapname) ) - { - Sql_ShowDebug(logmysql_handle); - 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', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s')", - log_config.log_pick, md->class_, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname) ) - { - Sql_ShowDebug(logmysql_handle); - return; - } - } - } - else -#endif - { - 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)); - - if( itm == NULL ) - {//We log common item - fprintf(logfp,"%s - %d\t%c\t%d,%d,%s\n", timestring, md->class_, log_picktype2char(type), nameid, amount, mapname); - } - else - {//We log Extended item - 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); - } - fclose(logfp); - } + nullpo_retv(sd); + log_pick(sd->status.char_id, sd->bl.m, type, amount, itm); } -/// logs item transactions -void log_pick(struct block_list* bl, e_log_pick_type type, int nameid, int amount, struct item* itm) +/// logs item transactions (monsters) +void log_pick_mob(struct mob_data* md, e_log_pick_type type, int amount, struct item* itm) { - if( bl == NULL ) - { - ShowError("log_pick: bl == NULL\n"); - } - else switch( bl->type ) - { - case BL_PC: log_pick_pc((TBL_PC*)bl, type, nameid, amount, itm); break; - case BL_MOB: log_pick_mob((TBL_MOB*)bl, type, nameid, amount, itm); break; - default: - ShowDebug("log_pick: Unhandled bl type %d.\n", bl->type); - } + nullpo_retv(md); + log_pick(md->class_, md->bl.m, type, amount, itm); } - /// logs zeny transactions void log_zeny(struct map_session_data* sd, e_log_pick_type type, struct map_session_data* src_sd, int amount) { diff --git a/src/map/log.h b/src/map/log.h index 114e71177..7c46712cf 100644 --- a/src/map/log.h +++ b/src/map/log.h @@ -53,9 +53,8 @@ e_log_pick_type; /// new logs -void log_pick_pc(struct map_session_data* sd, e_log_pick_type type, int nameid, int amount, struct item* itm); -void log_pick_mob(struct mob_data* md, e_log_pick_type type, int nameid, int amount, struct item* itm); -void log_pick(struct block_list* bl, e_log_pick_type type, int nameid, int amount, struct item* itm); +void log_pick_pc(struct map_session_data* sd, 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); void log_zeny(struct map_session_data* sd, e_log_pick_type type, struct map_session_data* src_sd, int amount); void log_npc(struct map_session_data* sd, const char *message); diff --git a/src/map/mob.c b/src/map/mob.c index 3d48ba9ba..7b5e0265c 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -1490,7 +1490,7 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick) fitem = (struct flooritem_data *)tbl; //Logs items, taken by (L)ooter Mobs [Lupus] - log_pick_mob(md, LOG_TYPE_LOOT, fitem->item_data.nameid, fitem->item_data.amount, &fitem->item_data); + log_pick_mob(md, LOG_TYPE_LOOT, fitem->item_data.amount, &fitem->item_data); if (md->lootitem_count < LOOTITEM_SIZE) { memcpy (&md->lootitem[md->lootitem_count++], &fitem->item_data, sizeof(md->lootitem[0])); @@ -1731,10 +1731,7 @@ static void mob_item_drop(struct mob_data *md, struct item_drop_list *dlist, str TBL_PC* sd; //Logs items, dropped by mobs [Lupus] - if (loot) - log_pick_mob(md, LOG_TYPE_LOOT, ditem->item_data.nameid, -ditem->item_data.amount, &ditem->item_data); - else - log_pick_mob(md, LOG_TYPE_PICKDROP_MONSTER, ditem->item_data.nameid, -ditem->item_data.amount, NULL); + log_pick_mob(md, loot?LOG_TYPE_LOOT:LOG_TYPE_PICKDROP_MONSTER, -ditem->item_data.amount, &ditem->item_data); sd = map_charid2sd(dlist->first_charid); if( sd == NULL ) sd = map_charid2sd(dlist->second_charid); @@ -2410,7 +2407,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) } //Logs items, MVP prizes [Lupus] - log_pick_mob(md, LOG_TYPE_PICKDROP_MONSTER, item.nameid, -1, NULL); + log_pick_mob(md, LOG_TYPE_PICKDROP_MONSTER, -1, &item); break; } diff --git a/src/map/pc.c b/src/map/pc.c index 398a77b65..386ea68a3 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -3282,9 +3282,9 @@ int pc_insert_card(struct map_session_data* sd, int idx_card, int idx_equip) } else {// success - log_pick_pc(sd, LOG_TYPE_OTHER, sd->status.inventory[idx_equip].nameid, -1, &sd->status.inventory[idx_equip]); + log_pick_pc(sd, LOG_TYPE_OTHER, -1, &sd->status.inventory[idx_equip]); sd->status.inventory[idx_equip].card[i] = nameid; - log_pick_pc(sd, LOG_TYPE_OTHER, sd->status.inventory[idx_equip].nameid, 1, &sd->status.inventory[idx_equip]); + log_pick_pc(sd, LOG_TYPE_OTHER, 1, &sd->status.inventory[idx_equip]); clif_insert_card(sd,idx_equip,idx_card,0); } @@ -3587,7 +3587,7 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_l sd->inventory_data[i] = data; clif_additem(sd,i,amount,0); } - log_pick_pc(sd, log_type, sd->status.inventory[i].nameid, amount, &sd->status.inventory[i]); + log_pick_pc(sd, log_type, amount, &sd->status.inventory[i]); sd->weight += w; clif_updatestatus(sd,SP_WEIGHT); @@ -3606,7 +3606,7 @@ int pc_delitem(struct map_session_data *sd,int n,int amount,int type, short reas if(sd->status.inventory[n].nameid==0 || amount <= 0 || sd->status.inventory[n].amount<amount || sd->inventory_data[n] == NULL) return 1; - log_pick_pc(sd, log_type, sd->status.inventory[n].nameid, -amount, &sd->status.inventory[n]); + log_pick_pc(sd, log_type, -amount, &sd->status.inventory[n]); sd->status.inventory[n].amount -= amount; sd->weight -= sd->inventory_data[n]->weight*amount ; @@ -4039,7 +4039,7 @@ int pc_cart_additem(struct map_session_data *sd,struct item *item_data,int amoun sd->cart_num++; clif_cart_additem(sd,i,amount,0); } - log_pick_pc(sd, log_type, sd->status.cart[i].nameid, amount, &sd->status.cart[i]); + log_pick_pc(sd, log_type, amount, &sd->status.cart[i]); sd->cart_weight += w; clif_updatestatus(sd,SP_CARTINFO); @@ -4058,7 +4058,7 @@ int pc_cart_delitem(struct map_session_data *sd,int n,int amount,int type,e_log_ sd->status.cart[n].amount<amount) return 1; - log_pick_pc(sd, log_type, sd->status.cart[n].nameid, -amount, &sd->status.cart[n]); + log_pick_pc(sd, log_type, -amount, &sd->status.cart[n]); sd->status.cart[n].amount -= amount; sd->cart_weight -= itemdb_weight(sd->status.cart[n].nameid)*amount ; @@ -4226,7 +4226,7 @@ int pc_steal_item(struct map_session_data *sd,struct block_list *bl, int lv) party_foreachsamemap(pc_show_steal,sd,AREA_SIZE,sd,tmp_item.nameid); //Logs items, Stolen from mobs [Lupus] - log_pick_mob(md, LOG_TYPE_PICKDROP_MONSTER, itemid, -1, NULL); + log_pick_mob(md, LOG_TYPE_PICKDROP_MONSTER, -1, &tmp_item); //A Rare Steal Global Announce by Lupus if(md->db->dropitem[i].p<=battle_config.rare_drop_announce) { diff --git a/src/map/script.c b/src/map/script.c index ca29ebb71..c06a69a60 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -6907,7 +6907,7 @@ BUILDIN_FUNC(successrefitem) ep=sd->status.inventory[i].equip; //Logs items, got from (N)PC scripts [Lupus] - log_pick_pc(sd, LOG_TYPE_SCRIPT, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]); + log_pick_pc(sd, LOG_TYPE_SCRIPT, -1, &sd->status.inventory[i]); sd->status.inventory[i].refine++; pc_unequipitem(sd,i,2); // status calc will happen in pc_equipitem() below @@ -6916,7 +6916,7 @@ BUILDIN_FUNC(successrefitem) clif_delitem(sd,i,1,3); //Logs items, got from (N)PC scripts [Lupus] - log_pick_pc(sd, LOG_TYPE_SCRIPT, sd->status.inventory[i].nameid, 1, &sd->status.inventory[i]); + log_pick_pc(sd, LOG_TYPE_SCRIPT, 1, &sd->status.inventory[i]); clif_additem(sd,i,1,0); pc_equipitem(sd,i,ep); diff --git a/src/map/skill.c b/src/map/skill.c index ad9580f5a..bd3bf3571 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -11779,9 +11779,9 @@ void skill_weaponrefine (struct map_session_data *sd, int idx) pc_delitem(sd, i, 1, 0, 0, LOG_TYPE_OTHER); if (per > rnd() % 100) { - log_pick_pc(sd, LOG_TYPE_OTHER, item->nameid, -1, item); + log_pick_pc(sd, LOG_TYPE_OTHER, -1, item); item->refine++; - log_pick_pc(sd, LOG_TYPE_OTHER, item->nameid, 1, item); + log_pick_pc(sd, LOG_TYPE_OTHER, 1, item); if(item->equip) { ep = item->equip; pc_unequipitem(sd,idx,3); |