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 ++++++++++++++------- src/map/npc.h | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'src') 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; } 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] **/ -- cgit v1.2.3-70-g09d2