diff options
author | Haru <haru@dotalux.com> | 2014-01-01 01:38:56 +0100 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2014-01-01 01:38:56 +0100 |
commit | c2f6086b1969f542459a1b685552d58a4d631f4b (patch) | |
tree | 10fe9f39fcb132078600d8348e0fb7c2f1346afe /src/map | |
parent | 58e082d9d4dad54fd5f2f577fc4c7a49c0db6502 (diff) | |
download | hercules-c2f6086b1969f542459a1b685552d58a4d631f4b.tar.gz hercules-c2f6086b1969f542459a1b685552d58a4d631f4b.tar.bz2 hercules-c2f6086b1969f542459a1b685552d58a4d631f4b.tar.xz hercules-c2f6086b1969f542459a1b685552d58a4d631f4b.zip |
Correctly removed persistent database entries for disabled NPC Market scripts
- When a Market script is disabled or removed, its database entries are
now correctly cleared upon reloadscript and/or server restart.
- Special thanks to ossi0110.
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/npc.c | 21 | ||||
-rw-r--r-- | src/map/npc.h | 1 |
2 files changed, 15 insertions, 7 deletions
diff --git a/src/map/npc.c b/src/map/npc.c index dc29f04aa..9ed6d2a7e 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -1426,9 +1426,11 @@ void npc_market_fromsql(void) { if( !(nd = npc->name2id(name)) ) { ShowError("npc_market_fromsql: NPC '%s' not found! skipping...\n",name); + npc->market_delfromsql_sub(name, USHRT_MAX); continue; } else if ( nd->subtype != SCRIPT || !nd->u.scr.shop || !nd->u.scr.shop->items || nd->u.scr.shop->type != NST_MARKET ) { ShowError("npc_market_fromsql: NPC '%s' is not proper for market, skipping...\n",name); + npc->market_delfromsql_sub(name, USHRT_MAX); continue; } @@ -1441,9 +1443,7 @@ void npc_market_fromsql(void) { if( i == nd->u.scr.shop->items ) { ShowError("npc_market_fromsql: NPC '%s' does not sell item %d (qty %d), deleting...\n",name,itemid,amount); - /* TODO inter-server.conf npc_market_data */ - if( SQL_ERROR == SQL->Query(map->mysql_handle, "DELETE FROM `npc_market_data` WHERE `name`='%s' AND `itemid`='%d' LIMIT 1", name,itemid) ) - Sql_ShowDebug(map->mysql_handle); + npc->market_delfromsql_sub(name, itemid); continue; } @@ -1461,18 +1461,24 @@ void npc_market_tosql(struct npc_data *nd, unsigned short index) { } /** * Removes persistent NPC Market Data from SQL - **/ -void npc_market_delfromsql(struct npc_data *nd, unsigned short index) { + */ +void npc_market_delfromsql_sub(const char *npcname, unsigned short index) { /* TODO inter-server.conf npc_market_data */ if( index == USHRT_MAX ) { - if( SQL_ERROR == SQL->Query(map->mysql_handle, "DELETE FROM `npc_market_data` WHERE `name`='%s'", nd->exname) ) + if( SQL_ERROR == SQL->Query(map->mysql_handle, "DELETE FROM `npc_market_data` WHERE `name`='%s'", npcname) ) Sql_ShowDebug(map->mysql_handle); } else { - if( SQL_ERROR == SQL->Query(map->mysql_handle, "DELETE FROM `npc_market_data` WHERE `name`='%s' AND `itemid`='%d' LIMIT 1", nd->exname, nd->u.scr.shop->item[index].nameid) ) + if( SQL_ERROR == SQL->Query(map->mysql_handle, "DELETE FROM `npc_market_data` WHERE `name`='%s' AND `itemid`='%d' LIMIT 1", npcname, index) ) Sql_ShowDebug(map->mysql_handle); } } /** + * Removes persistent NPC Market Data from SQL + **/ +void npc_market_delfromsql(struct npc_data *nd, unsigned short index) { + npc->market_delfromsql_sub(nd->exname, index == USHRT_MAX ? index : nd->u.scr.shop->item[index].nameid); +} +/** * Judges whether to allow and spawn a trader's window. **/ bool npc_trader_open(struct map_session_data *sd, struct npc_data *nd) { @@ -4579,4 +4585,5 @@ void npc_defaults(void) { npc->market_fromsql = npc_market_fromsql; npc->market_tosql = npc_market_tosql; npc->market_delfromsql = npc_market_delfromsql; + npc->market_delfromsql_sub = npc_market_delfromsql_sub; } diff --git a/src/map/npc.h b/src/map/npc.h index 792d85d59..a3f07e79c 100644 --- a/src/map/npc.h +++ b/src/map/npc.h @@ -268,6 +268,7 @@ struct npc_interface { void (*market_fromsql) (void); void (*market_tosql) (struct npc_data *nd, unsigned short index); void (*market_delfromsql) (struct npc_data *nd, unsigned short index); + void (*market_delfromsql_sub) (const char *npcname, unsigned short index); /** * For the Secure NPC Timeout option (check config/Secure.h) [RR] **/ |