summaryrefslogtreecommitdiff
path: root/src/map/clif.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2013-10-19 03:32:28 +0200
committerHaru <haru@dotalux.com>2013-10-19 03:32:28 +0200
commit448dce82b996930e361038dd5c94dd94a6deffe7 (patch)
tree7ab0f1adb3546d4597199a9e0159ffd219d6d945 /src/map/clif.c
parent4139f240fa26ae214599774fd551d3de03ffe7be (diff)
downloadhercules-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>
Diffstat (limited to 'src/map/clif.c')
-rw-r--r--src/map/clif.c83
1 files changed, 36 insertions, 47 deletions
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 ) );