From c2f6086b1969f542459a1b685552d58a4d631f4b Mon Sep 17 00:00:00 2001 From: Haru Date: Wed, 1 Jan 2014 01:38:56 +0100 Subject: 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 --- src/map/npc.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/map/npc.c') 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,17 +1461,23 @@ 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. **/ @@ -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; } -- cgit v1.2.3-60-g2f50