diff options
author | Haru <haru@dotalux.com> | 2013-10-19 03:32:28 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2013-10-19 03:32:28 +0200 |
commit | 448dce82b996930e361038dd5c94dd94a6deffe7 (patch) | |
tree | 7ab0f1adb3546d4597199a9e0159ffd219d6d945 | |
parent | 4139f240fa26ae214599774fd551d3de03ffe7be (diff) | |
download | hercules-448dce82b996930e361038dd5c94dd94a6deffe7.tar.gz hercules-448dce82b996930e361038dd5c94dd94a6deffe7.tar.bz2 hercules-448dce82b996930e361038dd5c94dd94a6deffe7.tar.xz hercules-448dce82b996930e361038dd5c94dd94a6deffe7.zip |
Added support for missing or empty categories in cashshop_db.conf
- If a category in cashshop_db.conf is empty or missing, it will no
longer show an error and/or insert an apple (dummy item).
- Corrected a mapserver startup crash in case cashshop_db is missing
elements.
- Special thanks to Ind for providing official server/client info to
handle the case of empty categories.
Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r-- | db/cashshop_db.conf | 4 | ||||
-rw-r--r-- | src/map/clif.c | 83 |
2 files changed, 40 insertions, 47 deletions
diff --git a/db/cashshop_db.conf b/db/cashshop_db.conf index 8273b133e..7f1d4f5d6 100644 --- a/db/cashshop_db.conf +++ b/db/cashshop_db.conf @@ -14,6 +14,10 @@ // add in any amount of items you like within each category. // Please keep in mind that the Cashshop does not work // with ragexere clients. +// Categories can be empty or even missing, but, if +// present, their names must be kept as cat_<n>, where +// <n> is a valid tab index, as descripbed in 'enum +// CASH_SHOP_TABS' in clif.c (normally 0 through 7) //==================================================== cash_shop: ( diff --git a/src/map/clif.c b/src/map/clif.c index 060509807..82eb01ca9 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -17247,9 +17247,9 @@ void clif_parse_MoveItem(int fd, struct map_session_data *sd) { /* [Ind/Hercules] */ void clif_cashshop_db(void) { config_t cashshop_conf; - config_setting_t *cashshop = NULL; + config_setting_t *cashshop = NULL, *cats = NULL; const char *config_filename = "db/cashshop_db.conf"; // FIXME hardcoded name - int i; + int i, item_count_t = 0; for( i = 0; i < CASHSHOP_TAB_MAX; i++ ) { CREATE(clif->cs.data[i], struct hCSData *, 1); clif->cs.item_count[i] = 0; @@ -17262,67 +17262,53 @@ void clif_cashshop_db(void) { cashshop = config_lookup(&cashshop_conf, "cash_shop"); - if (cashshop != NULL) { - config_setting_t *cats = config_setting_get_elem(cashshop, 0); - config_setting_t *cat; - int k, item_count_t = 0; - + if( cashshop != NULL && (cats = config_setting_get_elem(cashshop, 0)) != NULL ) { for(i = 0; i < CASHSHOP_TAB_MAX; i++) { + config_setting_t *cat; char entry_name[10]; sprintf(entry_name,"cat_%d",i); if( (cat = config_setting_get_member(cats, entry_name)) != NULL ) { - int item_count = config_setting_length(cat); + int k, item_count = config_setting_length(cat); - if( item_count == 0 ) { - ShowWarning("cashshop_db: category '%s' is empty! adding dull apple!\n", entry_name); - RECREATE(clif->cs.data[i], struct hCSData *, ++clif->cs.item_count[i]); - CREATE(clif->cs.data[i][ clif->cs.item_count[i] - 1 ], struct hCSData , 1); - - clif->cs.data[i][ clif->cs.item_count[i] - 1 ]->id = UNKNOWN_ITEM_ID; - clif->cs.data[i][ clif->cs.item_count[i] - 1 ]->price = 999; - } else { - for(k = 0; k < item_count; k++) { - config_setting_t *entry = config_setting_get_elem(cat,k); - const char *name = config_setting_name(entry); - int price = config_setting_get_int(entry); - struct item_data * data = NULL; - - if( price < 1 ) { - ShowWarning("cashshop_db: unsupported price '%d' for entry named '%s' in category '%s'\n", price, name, entry_name); + for(k = 0; k < item_count; k++) { + config_setting_t *entry = config_setting_get_elem(cat,k); + const char *name = config_setting_name(entry); + int price = config_setting_get_int(entry); + struct item_data * data = NULL; + + if( price < 1 ) { + ShowWarning("cashshop_db: unsupported price '%d' for entry named '%s' in category '%s'\n", price, name, entry_name); + continue; + } + + if( name[0] == 'I' && name[1] == 'D' && strlen(name) <= 7 ) { + if( !( data = itemdb->exists(atoi(name+2))) ) { + ShowWarning("cashshop_db: unknown item id '%s' in category '%s'\n", name+2, entry_name); continue; } - - if( name[0] == 'I' && name[1] == 'D' && strlen(name) <= 7 ) { - if( !( data = itemdb->exists(atoi(name+2))) ) { - ShowWarning("cashshop_db: unknown item id '%s' in category '%s'\n", name+2, entry_name); - continue; - } - } else { - if( !( data = itemdb->search_name(name) ) ) { - ShowWarning("cashshop_db: unknown item name '%s' in category '%s'\n", name, entry_name); - continue; - } + } else { + if( !( data = itemdb->search_name(name) ) ) { + ShowWarning("cashshop_db: unknown item name '%s' in category '%s'\n", name, entry_name); + continue; } - - - RECREATE(clif->cs.data[i], struct hCSData *, ++clif->cs.item_count[i]); - CREATE(clif->cs.data[i][ clif->cs.item_count[i] - 1 ], struct hCSData , 1); - - clif->cs.data[i][ clif->cs.item_count[i] - 1 ]->id = data->nameid; - clif->cs.data[i][ clif->cs.item_count[i] - 1 ]->price = price; - item_count_t++; } + + + RECREATE(clif->cs.data[i], struct hCSData *, ++clif->cs.item_count[i]); + CREATE(clif->cs.data[i][ clif->cs.item_count[i] - 1 ], struct hCSData , 1); + + clif->cs.data[i][ clif->cs.item_count[i] - 1 ]->id = data->nameid; + clif->cs.data[i][ clif->cs.item_count[i] - 1 ]->price = price; + item_count_t++; } - } else { - ShowError("cashshop_db: category '%s' (%d) not found!!\n",entry_name,i); } } - ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", item_count_t, config_filename); config_destroy(&cashshop_conf); } + ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", item_count_t, config_filename); } /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE). /// 0900 <index>.W <favorite>.B @@ -17377,6 +17363,9 @@ void clif_parse_CashShopSchedule(int fd, struct map_session_data *sd) { int i, j = 0; for( i = 0; i < CASHSHOP_TAB_MAX; i++ ) { + if( clif->cs.item_count[i] == 0 ) + continue; // Skip empty tabs, the client only expects filled ones + WFIFOHEAD(fd, 8 + ( clif->cs.item_count[i] * 6 ) ); WFIFOW(fd, 0) = 0x8ca; WFIFOW(fd, 2) = 8 + ( clif->cs.item_count[i] * 6 ); @@ -17478,7 +17467,7 @@ void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) { short tab = RFIFOW(fd, 2); int j; - if( tab < 0 || tab > CASHSHOP_TAB_MAX ) + if( tab < 0 || tab > CASHSHOP_TAB_MAX || clif->cs.item_count[tab] == 0 ) return; WFIFOHEAD(fd, 10 + ( clif->cs.item_count[tab] * 6 ) ); |