diff --git a/sql-files/main.sql b/sql-files/main.sql index 54bb2f33996..05b86563b1b 100644 --- a/sql-files/main.sql +++ b/sql-files/main.sql @@ -961,7 +961,7 @@ INSERT IGNORE INTO `sql_updates` (`timestamp`) VALUES (1597467600); -- 2020-08-1 CREATE TABLE IF NOT EXISTS `storage` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `account_id` INT UNSIGNED NOT NULL DEFAULT '0', - `storage_id` INT(11) UNSIGNED NOT NULL DEFAULT '1', + `storage_id` INT UNSIGNED NOT NULL DEFAULT '1', `nameid` INT UNSIGNED NOT NULL DEFAULT '0', `amount` SMALLINT UNSIGNED NOT NULL DEFAULT '0', `equip` INT UNSIGNED NOT NULL DEFAULT '0', diff --git a/sql-files/upgrades/2020-05-16--17-12.sql b/sql-files/upgrades/2020-05-16--17-12.sql index 8a7f542c405..4abb212eaf5 100644 --- a/sql-files/upgrades/2020-05-16--17-12.sql +++ b/sql-files/upgrades/2020-05-16--17-12.sql @@ -18,6 +18,6 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -ALTER TABLE `storage` ADD `storage_id` INT(11) UNSIGNED NOT NULL DEFAULT '1' AFTER `account_id`; +ALTER TABLE `storage` ADD `storage_id` INT UNSIGNED NOT NULL DEFAULT '1' AFTER `account_id`; INSERT INTO `sql_updates` (`timestamp`) VALUES (1589649120); diff --git a/src/char/int_storage.c b/src/char/int_storage.c index 0ac2896b171..eff2ba6d474 100644 --- a/src/char/int_storage.c +++ b/src/char/int_storage.c @@ -43,27 +43,22 @@ struct inter_storage_interface *inter_storage; /// Save storage data to sql static int inter_storage_tosql(int account_id, int storage_id, const struct storage_data *p) { - int i = 0, j = 0; - bool *matched_p = NULL; - int *delete = NULL; - int total_deletes = 0, total_updates = 0, total_inserts = 0; - int cp_size = 0; - struct storage_data cp = { 0 }; - StringBuf buf; - nullpo_ret(p); + struct storage_data cp = { 0 }; VECTOR_INIT(cp.item); - cp_size = inter_storage->fromsql(account_id, storage_id, &cp, 0); + int cp_size = inter_storage->fromsql(account_id, storage_id, &cp, 0); - matched_p = aCalloc(VECTOR_LENGTH(p->item), sizeof(bool)); + bool *matched_p = aCalloc(VECTOR_LENGTH(p->item), sizeof(bool)); + StringBuf buf; StrBuf->Init(&buf); + int total_deletes = 0, total_updates = 0, total_inserts = 0; + int i = 0, j = 0; if (VECTOR_LENGTH(cp.item) > 0) { - - delete = aCalloc(cp_size, sizeof(int)); + int *delete = aCalloc(cp_size, sizeof(int)); /** * Compare and update items, if any. diff --git a/src/char/mapif.c b/src/char/mapif.c index 38cb10b1c56..450da230793 100644 --- a/src/char/mapif.c +++ b/src/char/mapif.c @@ -1816,9 +1816,12 @@ static int mapif_save_guild_storage_ack(int fd, int account_id, int guild_id, in /** * Loads the account storage and send to the map server. - * @packet 0x3805 [out] .W .L .W .P - * @param fd [in] file/socket descriptor. - * @param account_id [in] account id of the session. + * + * @packet 0x3805 [out] .W .L .W .P + * @param fd [in] file/socket descriptor. + * @param account_id [in] account id of the session. + * @param storage_id [in] storage id to load + * @param storage_size [in] size of storage * @return 1 on success, 0 on failure. */ static int mapif_account_storage_load(int fd, int account_id, int storage_id, int storage_size) @@ -1855,7 +1858,8 @@ static int mapif_account_storage_load(int fd, int account_id, int storage_id, in */ static int mapif_parse_AccountStorageLoad(int fd) { - int account_id = RFIFOL(fd, 2), storage_id = RFIFOW(fd, 6); + int account_id = RFIFOL(fd, 2); + int storage_id = RFIFOW(fd, 6); int storage_size = RFIFOW(fd, 8); Assert_ret(fd > 0); @@ -1876,8 +1880,9 @@ static int mapif_parse_AccountStorageLoad(int fd) */ static int mapif_parse_AccountStorageSave(int fd) { - int payload_size = RFIFOW(fd, 2) - 10, account_id = RFIFOL(fd, 4); - short storage_id = RFIFOW(fd, 8); + int payload_size = RFIFOW(fd, 2) - 10; + int account_id = RFIFOL(fd, 4); + int storage_id = RFIFOW(fd, 8); int i = 0, count = 0; struct storage_data p_stor = { 0 }; @@ -1913,9 +1918,11 @@ static int mapif_parse_AccountStorageSave(int fd) /** * Sends an acknowledgement for the save * status of the account storage. + * * @packet 0x3808 [out] .L .W .B * @param fd [in] File/Socket Descriptor. * @param account_id [in] Account ID of the storage in question. + * @param storage_id [in] acknowledgement of storage id. * @param flag [in] Save flag, true for success and false for failure. */ static void mapif_send_AccountStorageSaveAck(int fd, int account_id, int storage_id, bool flag) diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 13644dc8253..b4ab16fc688 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -871,16 +871,15 @@ ACMD(storage) { char storage_name[NAME_LENGTH] = ""; int storage_id = 0, intval = 0; - struct storage_data *stor = NULL; - if (*message && sscanf(message, "%12d", &intval) == 1) { + if (*message != '\0' && sscanf(message, "%12d", &intval) == 1) { if (storage->get_settings(intval) == NULL) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 67), storage_name); clif->message(fd, atcmd_output); // Invalid storage name or ID. return false; } storage_id = intval; - } else if (*message && sscanf(message, "%23s", storage_name) == 1) { + } else if (*message != '\0' && sscanf(message, "%23s", storage_name) == 1) { if ((storage_id = storage->get_id_by_name(storage_name)) == -1) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 67), storage_name); clif->message(fd, atcmd_output); // Invalid storage name or ID. @@ -893,12 +892,13 @@ ACMD(storage) sd->storage.access = STORAGE_ACCESS_ALL; // Default storage access for atcommands. + struct storage_data *stor = NULL; if ((stor = storage->ensure(sd, storage_id)) == NULL) { ShowError("atcommand_storage: Error ensuring storage for player %d, storage_id %d\n", sd->bl.id, storage_id); return false; } - if (stor->received == false) { + if (!stor->received) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 27), storage_name); clif->message(fd, atcmd_output); // -- Storage '%s' has not been loaded yet. return false; @@ -5528,16 +5528,15 @@ ACMD(storeall) { char storage_name[NAME_LENGTH] = ""; int storage_id = 0, intval = 0; - struct storage_data *stor = NULL; - if (*message && sscanf(message, "%12d", &intval) == 1) { + if (*message != '\0' && sscanf(message, "%12d", &intval) == 1) { if (storage->get_settings(intval) == NULL) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 67), storage_name); clif->message(fd, atcmd_output); // Invalid storage name or ID. return false; } storage_id = intval; - } else if (*message && sscanf(message, "%23s", storage_name) == 1) { + } else if (*message != '\0' && sscanf(message, "%23s", storage_name) == 1) { if ((storage_id = storage->get_id_by_name(storage_name)) == -1) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 67), storage_name); clif->message(fd, atcmd_output); // Invalid storage name or ID. @@ -5550,6 +5549,7 @@ ACMD(storeall) sd->storage.access = STORAGE_ACCESS_ALL; // Default storage access for atcommands. + struct storage_data *stor = NULL; if ((stor = storage->ensure(sd, storage_id)) == NULL) { ShowError("atcommand_storeall: Error ensuring storage for player %d, storage_id %d\n", sd->bl.id, storage_id); return false; @@ -5563,7 +5563,7 @@ ACMD(storeall) } } - if (stor->received == false) { + if (!stor->received) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 27), storage_name); clif->message(fd, atcmd_output); // -- Storage '%s' has not been loaded yet. return false; @@ -5589,16 +5589,15 @@ ACMD(clearstorage) int i = 0; char storage_name[NAME_LENGTH] = ""; int storage_id = 0, intval = 0; - struct storage_data *stor = NULL; - if (*message && sscanf(message, "%12d", &intval) == 1) { + if (*message != '\0' && sscanf(message, "%12d", &intval) == 1) { if (storage->get_settings(intval) == NULL) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 67), storage_name); clif->message(fd, atcmd_output); // Invalid storage name or ID. return false; } storage_id = intval; - } else if (*message && sscanf(message, "%23s", storage_name) == 1) { + } else if (*message != '\0' && sscanf(message, "%23s", storage_name) == 1) { if ((storage_id = storage->get_id_by_name(storage_name)) == -1) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 67), storage_name); clif->message(fd, atcmd_output); // Invalid storage name or ID. @@ -5616,12 +5615,13 @@ ACMD(clearstorage) sd->storage.access = STORAGE_ACCESS_ALL; // Default storage access for atcommands. + struct storage_data *stor = NULL; if ((stor = storage->ensure(sd, storage_id)) == NULL) { ShowError("atcommand_clearstorage: Error ensuring storage for player %d, storage_id %d\n", sd->bl.id, storage_id); return false; } - if (stor->received == false) { + if (!stor->received) { clif->message(fd, msg_fd(fd, 27)); // "Storage has not been loaded yet" return false; } @@ -8690,11 +8690,11 @@ ACMD(itemlist) int size; StringBuf buf; - if( strcmpi(info->command, "cartlist") == 0 ) { + if (strcmpi(info->command, "cartlist") == 0) { location = "cart"; items = sd->status.cart; size = MAX_CART; - } else if( strcmpi(info->command, "itemlist") == 0 ) { + } else if (strcmpi(info->command, "itemlist") == 0) { location = "inventory"; items = sd->status.inventory; size = sd->status.inventorySize; diff --git a/src/map/chrif.c b/src/map/chrif.c index 89a54462457..b409d4ff104 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -310,12 +310,11 @@ static bool chrif_save(struct map_session_data *sd, int flag) if (sd->state.storage_flag == STORAGE_FLAG_GUILD) gstorage->save(sd->status.account_id, sd->status.guild_id, flag); - if (flag && sd->state.storage_flag != STORAGE_FLAG_CLOSED) { - if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) { + if (flag != 0 && sd->state.storage_flag != STORAGE_FLAG_CLOSED) { + if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) storage->close(sd); - } else if (sd->state.storage_flag == STORAGE_FLAG_GUILD) { + else if (sd->state.storage_flag == STORAGE_FLAG_GUILD) gstorage->close(sd); - } } //Saving of registry values. @@ -345,7 +344,7 @@ static bool chrif_save(struct map_session_data *sd, int flag) intif->achievements_save(sd); for (int i = 0; i < VECTOR_LENGTH(sd->storage.list); i++) - if (VECTOR_INDEX(sd->storage.list, i).received == true && VECTOR_INDEX(sd->storage.list, i).save == true) + if (VECTOR_INDEX(sd->storage.list, i).received && VECTOR_INDEX(sd->storage.list, i).save) intif->send_account_storage(sd, VECTOR_INDEX(sd->storage.list, i).uid); return true; diff --git a/src/map/clif.c b/src/map/clif.c index 783a9ed00a5..fe42e2d4bf1 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -2955,15 +2955,11 @@ static void clif_equipItems(struct map_session_data *sd, enum inventory_type typ static void clif_storageList(struct map_session_data *sd, struct item *items, int items_length) { - const struct storage_settings* stst; - struct storage_data* stor = NULL; nullpo_retv(sd); - stst = storage->get_settings(sd->storage.current); + const struct storage_settings *stst = storage->get_settings(sd->storage.current); nullpo_retv(stst); - stor = storage->ensure(sd, sd->storage.current); + struct storage_data *stor = storage->ensure(sd, sd->storage.current); nullpo_retv(stor); - - clif->inventoryStart(sd, INVTYPE_STORAGE, stst->name); if (stor->aggregate > 0) @@ -9385,19 +9381,15 @@ static void clif_refresh_storagewindow(struct map_session_data *sd) // Notify the client that the storage is open if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) { const struct storage_settings* stst = storage->get_settings(sd->storage.current); - struct storage_data* stor = NULL; - nullpo_retv(stst); - if ((stor = storage->ensure(sd, sd->storage.current)) == NULL) { + struct storage_data* stor = NULL; + if ((stor = storage->ensure(sd, sd->storage.current)) == NULL) return; - } - nullpo_retv(stor); - - if (stor->aggregate > 0) { + if (stor->aggregate > 0) storage->sortitem(VECTOR_DATA(stor->item), VECTOR_LENGTH(stor->item)); - } + clif->storageList(sd, VECTOR_DATA(stor->item), VECTOR_LENGTH(stor->item)); clif->updatestorageamount(sd, stor->aggregate, MAX_STORAGE); @@ -13801,7 +13793,7 @@ static void clif_parse_MoveFromKafra(int fd, struct map_session_data *sd) struct storage_data *stor = storage->ensure(sd, sd->storage.current); if (stor != NULL) storage->get(sd, stor, item_index, item_amount); - } else if(sd->state.storage_flag == STORAGE_FLAG_GUILD) { + } else if (sd->state.storage_flag == STORAGE_FLAG_GUILD) { gstorage->get(sd, item_index, item_amount); } } diff --git a/src/map/clif.h b/src/map/clif.h index 2488fcbbc9c..6a0b9ed7079 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -1130,7 +1130,7 @@ struct clif_interface { /* storage handling */ void (*storageList) (struct map_session_data* sd, struct item* items, int items_length); void (*guildStorageList) (struct map_session_data* sd, struct item* items, int items_length); - void (*storageItems) (struct map_session_data* sd, enum inventory_type type, struct item* items, int items_length, const char *name); + void (*storageItems) (struct map_session_data *sd, enum inventory_type type, struct item *items, int items_length, const char *name); void (*inventoryStart) (struct map_session_data* sd, enum inventory_type type, const char* name); void (*inventoryEnd) (struct map_session_data* sd, enum inventory_type type); void (*updatestorageamount) (struct map_session_data* sd, int amount, int max_amount); diff --git a/src/map/intif.c b/src/map/intif.c index ea338ce8fd2..260f0da64a8 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -297,14 +297,16 @@ static int intif_request_registry(struct map_session_data *sd, int flag) /** * Request the inter-server for a character's storage data. - * @packet 0x3010 [out] .L .W .W - * @param sd [in] pointer to session data. + * + * @packet 0x3010 [out] .L .W .W + * @param sd [in] pointer to session data. + * @param storage_id [in] storage id to retrieve */ static void intif_request_account_storage(const struct map_session_data *sd, int storage_id) { - const struct storage_settings *stst = storage->get_settings(storage_id); - nullpo_retv(sd); + + const struct storage_settings *stst = storage->get_settings(storage_id); nullpo_retv(stst); /* Check for character server availability */ @@ -329,7 +331,6 @@ static void intif_parse_account_storage(int fd) int account_id = 0, payload_size = 0, storage_count = 0; int i = 0; struct map_session_data *sd = NULL; - struct storage_data *stor = NULL; Assert_retv(fd > 0); @@ -340,12 +341,11 @@ static void intif_parse_account_storage(int fd) return; } + struct storage_data *stor = NULL; if ((stor = storage->ensure(sd, RFIFOW(fd, 8))) == NULL) return; - Assert_retv(stor != NULL); - - if (stor->received == true) { + if (stor->received) { ShowError("intif_parse_account_storage: Multiple calls from the inter-server received.\n"); return; } @@ -369,23 +369,24 @@ static void intif_parse_account_storage(int fd) /** * Send account storage information for saving. - * @packet 0x3011 [out] .W .L .W .P - * @param sd [in] pointer to session data. + * + * @packet 0x3011 [out] .W .L .W .P + * @param sd [in] pointer to session data. + * @param storage_id [in] storage id to be saved. */ static void intif_send_account_storage(struct map_session_data *sd, int storage_id) { int len = 0, i = 0, c = 0; - struct storage_data *stor = NULL; nullpo_retv(sd); + struct storage_data *stor = NULL; if ((stor = storage->ensure(sd, storage_id)) == NULL) return; // Assert that at this point in the code, both flags are true. - Assert_retv(stor != NULL); - Assert_retv(stor->save == true); - Assert_retv(stor->received == true); + Assert_retv(stor->save); + Assert_retv(stor->received); if (intif->CheckForCharServer()) return; @@ -421,13 +422,12 @@ static void intif_parse_account_storage_save_ack(int fd) int account_id = RFIFOL(fd, 2); int storage_id = RFIFOW(fd, 6); char saved = RFIFOB(fd, 8); - struct map_session_data *sd = NULL; - struct storage_data *stor = NULL; Assert_retv(account_id > 0); Assert_retv(fd > 0); Assert_retv(storage_id >= 0); + struct map_session_data *sd = NULL; if ((sd = map->id2sd(account_id)) == NULL) return; // character is most probably offline. @@ -436,11 +436,10 @@ static void intif_parse_account_storage_save_ack(int fd) return; } + struct storage_data *stor = NULL; if ((stor = storage->ensure(sd, storage_id)) == NULL) return; - Assert_retv(stor != NULL); - stor->save = false; // Storage has been saved. } diff --git a/src/map/pc.c b/src/map/pc.c index 40e5ccd2c56..edd1f1f48f3 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -10837,7 +10837,7 @@ static int pc_checkitem(struct map_session_data *sd) sd->itemcheck &= ~PCCHECKITEM_CART; } - if (sd->itemcheck & PCCHECKITEM_STORAGE) { + if ((sd->itemcheck & PCCHECKITEM_STORAGE) != 0) { for (i = 0; i < VECTOR_LENGTH(sd->storage.list); i++) { struct storage_data *stor = &VECTOR_INDEX(sd->storage.list, i); @@ -10847,7 +10847,7 @@ static int pc_checkitem(struct map_session_data *sd) if ((id = it->nameid) == 0) continue; - if (!itemdb_available(id)) { + if (itemdb_available(id) == 0) { ShowWarning("pc_checkitem: Removed invalid/disabled item id %d from storage %d (amount=%d, char_id=%d).\n", id, stor->uid, it->amount, sd->status.char_id); storage->delitem(sd, stor, i, it->amount); continue; diff --git a/src/map/pc.h b/src/map/pc.h index 26fe9a5cca3..354f5359b27 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -40,7 +40,6 @@ #include "common/hercules.h" #include "common/mmo.h" // JOB_*, MAX_FAME_LIST, struct fame_list, struct mmo_charstatus, NEW_CARTS, struct s_achievement - /** * Defines **/ diff --git a/src/map/script.c b/src/map/script.c index f41ba1a7ce6..559397e2e9a 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -11373,11 +11373,14 @@ static BUILDIN(openstorage) { struct map_session_data *sd = script->rid2sd(st); int storage_id = script_getnum(st, 2); + if (sd == NULL) { + script_pushint(st, 0); + ShowWarning("buildin_openstorage: Player not attached for Storage with ID %d!\n", storage_id); + return false; + } + int storage_access = script_hasdata(st, 3) ? script_getnum(st, 3) : STORAGE_ACCESS_ALL; struct storage_data *stor = NULL; - const struct storage_settings *stst = NULL; - - nullpo_retr(false, sd); if ((stor = storage->ensure(sd, storage_id)) == NULL) { script_pushint(st, 0); @@ -11385,13 +11388,14 @@ static BUILDIN(openstorage) return false; } + const struct storage_settings *stst = NULL; if ((stst = storage->get_settings(storage_id)) == NULL) { script_pushint(st, 0); ShowWarning("buildin_openstorage: Storage with ID %d was not found!\n", storage_id); return false; } - if (stor == NULL || stor->received == false) { + if (stor == NULL || !stor->received) { script_pushint(st, 0); ShowWarning("buildin_openstorage: Storage data for AID %d has not been loaded.\n", sd->bl.id); return false; @@ -11405,9 +11409,11 @@ static BUILDIN(openstorage) sd->storage.access = storage_access; // Set storage access level. [Smokexyz/Hercules] - storage->open(sd, stor); // Open storage! - - script_pushint(st, 1); // success flag. + if (storage->open(sd, stor) == 0) { + script_pushint(st, 1); // success + } else { + script_pushint(st, 0); + } return true; } diff --git a/src/map/storage.c b/src/map/storage.c index e320eb46d0b..27caba85a92 100644 --- a/src/map/storage.c +++ b/src/map/storage.c @@ -99,6 +99,7 @@ static void do_reconnect_storage(void) /** * Get a storage id by its name (through @commands etc...) + * * @param[in] storage_name pointer to the storage name char array. * @return id of the storage or -1 if not found. */ @@ -117,16 +118,17 @@ int storage_get_id_by_name(const char *storage_name) /** * Get storage with a particular ID from a player. + * * @param[in] sd pointer to map session data. * @param[in] storage_id ID of the storage to receive. * @return pointer to player's storage data structure or null if not found. */ struct storage_data *storage_ensure(struct map_session_data *sd, int storage_id) { + nullpo_retr(NULL, sd); + int i = 0; struct storage_data *stor = NULL; - - nullpo_retr(NULL, sd); ARR_FIND(0, VECTOR_LENGTH(sd->storage.list), i, (stor = &VECTOR_INDEX(sd->storage.list, i)) != NULL && stor->uid == storage_id); @@ -145,16 +147,17 @@ struct storage_data *storage_ensure(struct map_session_data *sd, int storage_id) /** * Get a storage's settings through its ID. + * * @param[in] storage_id the ID of the storage to find. * @return storage settings of the storage in question. */ const struct storage_settings *storage_get_settings(int storage_id) { int i = 0; - struct storage_settings *tmp_stor = NULL; ARR_FIND(0, VECTOR_LENGTH(storage->configuration), i, VECTOR_INDEX(storage->configuration, i).uid == storage_id); + struct storage_settings *tmp_stor = NULL; if (i < VECTOR_LENGTH(storage->configuration)) tmp_stor = &VECTOR_INDEX(storage->configuration, i); @@ -168,12 +171,13 @@ const struct storage_settings *storage_get_settings(int storage_id) *------------------------------------------*/ static int storage_storageopen(struct map_session_data *sd, struct storage_data *stor) { + nullpo_retr(1, sd); + nullpo_retr(1, stor); + Assert_retr(1, stor->received); // Assert the availability of data. + const struct storage_settings *stst = NULL; - nullpo_ret(sd); - nullpo_ret(stor); - Assert_ret(stor->received == true); // Assert the availability of data. - nullpo_ret(stst = storage->get_settings(stor->uid)); + nullpo_retr(1, stst = storage->get_settings(stor->uid)); if (sd->state.storage_flag != STORAGE_FLAG_CLOSED) return 1; // Storage is already open. @@ -225,23 +229,19 @@ static int compare_item(struct item *a, struct item *b) /*========================================== * Internal add-item function. *------------------------------------------*/ -static int storage_additem(struct map_session_data* sd, struct storage_data *stor, struct item* item_data, int amount) +static int storage_additem(struct map_session_data *sd, struct storage_data *stor, struct item* item_data, int amount) { - struct item_data *data = NULL; - struct item *it = NULL; - const struct storage_settings *stst = NULL; - int i; - nullpo_retr(1, sd); nullpo_retr(1, stor); // Assert Storage - Assert_retr(1, stor->received == true); // Assert the availability of the storage. + Assert_retr(1, stor->received); // Assert the availability of the storage. nullpo_retr(1, item_data); // Assert availability of item data. Assert_retr(1, item_data->nameid > 0); // Assert existence of item in the database. - Assert_retr(1, amount > 0); // Assert quantity of item. + + const struct storage_settings *stst = NULL; nullpo_retr(1, (stst = storage->get_settings(stor->uid))); // Assert existence of storage configuration. - data = itemdb->search(item_data->nameid); + struct item_data *data = itemdb->search(item_data->nameid); if (data->stack.storage && amount > data->stack.amount) // item stack limitation return 1; @@ -257,7 +257,9 @@ static int storage_additem(struct map_session_data* sd, struct storage_data *sto return 1; } + int i; if (itemdb->isstackable2(data)) {//Stackable + struct item *it = NULL; for (i = 0; i < VECTOR_LENGTH(stor->item); i++) { it = &VECTOR_INDEX(stor->item, i); @@ -309,18 +311,19 @@ static int storage_additem(struct map_session_data* sd, struct storage_data *sto /*========================================== * Internal del-item function *------------------------------------------*/ -static int storage_delitem(struct map_session_data* sd, struct storage_data *stor, int n, int amount) +static int storage_delitem(struct map_session_data *sd, struct storage_data *stor, int n, int amount) { - const struct storage_settings* stst = NULL; - struct item *it = NULL; nullpo_retr(1, sd); nullpo_retr(1, stor); - Assert_retr(1, stor->received == true); + Assert_retr(1, stor->received); + + const struct storage_settings* stst = NULL; nullpo_retr(1, (stst = storage->get_settings(stor->uid))); + Assert_retr(1, n >= 0 && n < VECTOR_LENGTH(stor->item)); - it = &VECTOR_INDEX(stor->item, n); + struct item *it = &VECTOR_INDEX(stor->item, n); Assert_retr(1, amount <= it->amount); Assert_retr(1, it->nameid > 0); @@ -347,14 +350,14 @@ static int storage_delitem(struct map_session_data* sd, struct storage_data *sto * 0 : fail * 1 : success *------------------------------------------*/ -static int storage_add_from_inventory(struct map_session_data* sd, struct storage_data *stor, int index, int amount) +static int storage_add_from_inventory(struct map_session_data *sd, struct storage_data *stor, int index, int amount) { - const struct storage_settings *stst = NULL; + nullpo_retr(0, sd); + nullpo_retr(0, stor); + Assert_retr(0, stor->received); - nullpo_ret(sd); - nullpo_ret(stor); - Assert_ret(stor->received == true); - nullpo_ret((stst = storage->get_settings(stor->uid))); + const struct storage_settings *stst = NULL; + nullpo_retr(0, (stst = storage->get_settings(stor->uid))); if ((sd->storage.access & STORAGE_ACCESS_PUT) == 0) { clif->delitem(sd, index, amount, DELITEM_NORMAL); @@ -389,15 +392,12 @@ static int storage_add_from_inventory(struct map_session_data* sd, struct storag * 0 : fail * 1 : success *------------------------------------------*/ -static int storage_add_to_inventory(struct map_session_data* sd, struct storage_data *stor, int index, int amount) +static int storage_add_to_inventory(struct map_session_data *sd, struct storage_data *stor, int index, int amount) { - int flag; - struct item *it = NULL; - nullpo_ret(sd); nullpo_ret(stor); - Assert_ret(stor->received == true); + Assert_ret(stor->received); if ((sd->storage.access & STORAGE_ACCESS_GET) == 0) return 0; @@ -405,7 +405,7 @@ static int storage_add_to_inventory(struct map_session_data* sd, struct storage_ if (index < 0 || index >= VECTOR_LENGTH(stor->item)) return 0; - it = &VECTOR_INDEX(stor->item, index); + struct item *it = &VECTOR_INDEX(stor->item, index); if (it->nameid <= 0) return 0; //Nothing there @@ -413,6 +413,7 @@ static int storage_add_to_inventory(struct map_session_data* sd, struct storage_ if (amount < 1 || amount > it->amount) return 0; + int flag; if ((flag = pc->additem(sd, it, amount, LOG_TYPE_STORAGE)) == 0) storage->delitem(sd, stor, index, amount); else @@ -428,13 +429,13 @@ static int storage_add_to_inventory(struct map_session_data* sd, struct storage_ * 0 : fail * 1 : success *------------------------------------------*/ -static int storage_storageaddfromcart(struct map_session_data* sd, struct storage_data *stor, int index, int amount) +static int storage_storageaddfromcart(struct map_session_data *sd, struct storage_data *stor, int index, int amount) { - const struct storage_settings *stst = NULL; - nullpo_ret(sd); nullpo_ret(stor); - Assert_ret(stor->received == true); + Assert_ret(stor->received); + + const struct storage_settings *stst = NULL; nullpo_ret(stst = storage->get_settings(stor->uid)); @@ -469,15 +470,11 @@ static int storage_storageaddfromcart(struct map_session_data* sd, struct storag * 0 : fail * 1 : success *------------------------------------------*/ -static int storage_storagegettocart(struct map_session_data* sd, struct storage_data *stor, int index, int amount) +static int storage_storagegettocart(struct map_session_data *sd, struct storage_data *stor, int index, int amount) { - int flag = 0; - struct item *it = NULL; - - nullpo_ret(sd); - - nullpo_ret(stor); - Assert_ret(stor->received == true); + nullpo_retr(0, sd); + nullpo_retr(0, stor); + Assert_retr(0, stor->received); if ((sd->storage.access & STORAGE_ACCESS_GET) == 0) return 0; @@ -485,7 +482,7 @@ static int storage_storagegettocart(struct map_session_data* sd, struct storage_ if (index < 0 || index >= VECTOR_LENGTH(stor->item)) return 0; - it = &VECTOR_INDEX(stor->item, index); + struct item *it = &VECTOR_INDEX(stor->item, index); if (it->nameid <= 0) return 0; //Nothing there. @@ -493,6 +490,7 @@ static int storage_storagegettocart(struct map_session_data* sd, struct storage_ if (amount < 1 || amount > it->amount) return 0; + int flag = 0; if ((flag = pc->cart_additem(sd, it, amount, LOG_TYPE_STORAGE)) == 0) storage->delitem(sd, stor, index, amount); else { @@ -511,11 +509,9 @@ static int storage_storagegettocart(struct map_session_data* sd, struct storage_ *------------------------------------------*/ static void storage_storageclose(struct map_session_data *sd) { - int i = 0; - struct storage_data *curr_stor = NULL; - nullpo_retv(sd); + struct storage_data *curr_stor = NULL; if ((curr_stor = storage->ensure(sd, sd->storage.current)) == NULL) return; @@ -527,8 +523,8 @@ static void storage_storageclose(struct map_session_data *sd) /* Erase deleted account storage items from memory * and resize the vector. */ - - while (curr_stor != NULL && i < VECTOR_LENGTH(curr_stor->item)) { + int i = 0; + while (i < VECTOR_LENGTH(curr_stor->item)) { if (VECTOR_INDEX(curr_stor->item, i).nameid == 0) { VECTOR_ERASE(curr_stor->item, i); } else { @@ -947,6 +943,7 @@ static int storage_guild_storage_quit(struct map_session_data *sd, int flag) /** * Read additional storage configuration fields for plugins. + * * @param t [in] pointer to the config element being parsed. * @param s_conf [in] pointer to the config struct being written to. * @param filename [in] pointer to the filename string. @@ -965,37 +962,34 @@ static void storage_config_read_additional_fields(struct config_setting_t *t, st */ static bool storage_config_read(const char *filename, bool imported) { - struct config_t stor_libconf; - const struct config_setting_t *setting = NULL, *t = NULL; - int i = 0; - const char *import = NULL; - nullpo_retr(false, filename); if (!imported) VECTOR_INIT(storage->configuration); - if (libconfig->load_file(&stor_libconf, filename) == 0) + struct config_t stor_libconf; + if (libconfig->load_file(&stor_libconf, filename) == CONFIG_FALSE) return false; // Error message is already shown by libconfig->load_file() + const struct config_setting_t *setting = NULL; if ((setting = libconfig->setting_get_member(stor_libconf.root, "storage_conf")) == NULL && !imported) { ShowError("storage_config_read: Error in reading file '%s'\n", filename); libconfig->destroy(&stor_libconf); return false; } + struct config_setting_t *t = NULL; while ((t = libconfig->setting_get_elem(setting, i++)) != NULL) { - struct config_setting_t *tt = NULL; struct storage_settings s_conf = { 0 }; - int d = 0; /* Id */ - if (libconfig->setting_lookup_int(t, "Id", &s_conf.uid) == 0) { + if (libconfig->setting_lookup_int(t, "Id", &s_conf.uid) == CONFIG_FALSE) { ShowError("storage_config_read: Id field not found for storage configuration in '%s'. Skipping...\n", filename); continue; } // Duplicate ID search and report... + int d = 0; ARR_FIND(0, VECTOR_LENGTH(storage->configuration), d, VECTOR_INDEX(storage->configuration, d).uid == s_conf.uid); if (d < VECTOR_LENGTH(storage->configuration)) { ShowError("storage_config_read: Duplicate ID %d for storage. Skipping...\n", s_conf.uid); @@ -1009,21 +1003,23 @@ static bool storage_config_read(const char *filename, bool imported) } /* Name */ - if (libconfig->setting_lookup_mutable_string(t, "Name", s_conf.name, NAME_LENGTH) == 0) { + if (libconfig->setting_lookup_mutable_string(t, "Name", s_conf.name, NAME_LENGTH) == CONFIG_FALSE) { ShowError("storage_config_read: Name field not found for storage configuration (Id: %d) in '%s'. Skipping...\n", s_conf.uid, filename); continue; } /* Capacity */ - if (libconfig->setting_lookup_int(t, "Capacity", &s_conf.capacity) == 0) { + if (libconfig->setting_lookup_int(t, "Capacity", &s_conf.capacity) == CONFIG_FALSE) { ShowError("storage_config_read: Capacity field not found for storage configuration (Id: %d) in '%s'. Skipping...\n", s_conf.uid, filename); continue; } /* Additional Fields */ + struct config_setting_t *tt = NULL; storage->config_read_additional_fields(tt, &s_conf, filename); if (imported) { + int i = 0; ARR_FIND(0, VECTOR_LENGTH(storage->configuration), i, VECTOR_INDEX(storage->configuration, i).uid == s_conf.uid); if (i < VECTOR_LENGTH(storage->configuration)) VECTOR_ERASE(storage->configuration, i); @@ -1034,6 +1030,7 @@ static bool storage_config_read(const char *filename, bool imported) } // import should overwrite any previous configuration, so it should be called last + const char *import = NULL; if (libconfig->lookup_string(&stor_libconf, "import", &import) == CONFIG_TRUE) { if (strcmp(import, filename) == 0 || strcmp(import, map->STORAGE_CONF_FILENAME) == 0) { ShowWarning("battle_config_read: Loop detected! Skipping 'import'...\n"); diff --git a/src/map/storage.h b/src/map/storage.h index 2268c1a0bfa..4c0324ac488 100644 --- a/src/map/storage.h +++ b/src/map/storage.h @@ -60,17 +60,17 @@ struct storage_interface { int (*get_id_by_name) (const char *storage_name); struct storage_data *(*ensure) (struct map_session_data *sd, int storage_id); const struct storage_settings *(*get_settings) (int storage_id); - int (*delitem) (struct map_session_data* sd, struct storage_data *stor, int n, int amount); + int (*delitem) (struct map_session_data *sd, struct storage_data *stor, int n, int amount); int (*open) (struct map_session_data *sd, struct storage_data *stor); int (*add) (struct map_session_data *sd, struct storage_data *stor, int index, int amount); int (*get) (struct map_session_data *sd, struct storage_data *stor, int index, int amount); - int (*additem) (struct map_session_data* sd, struct storage_data *stor, struct item* item_data, int amount); + int (*additem) (struct map_session_data *sd, struct storage_data *stor, struct item* item_data, int amount); int (*addfromcart) (struct map_session_data *sd, struct storage_data *stor, int index,int amount); int (*gettocart) (struct map_session_data *sd, struct storage_data *stor, int index,int amount); void (*close) (struct map_session_data *sd); void (*pc_quit) (struct map_session_data *sd, int flag); int (*comp_item) (const void *i1_, const void *i2_); - void (*sortitem) (struct item* items, unsigned int size); + void (*sortitem) (struct item *items, unsigned int size); int (*reconnect_sub) (union DBKey key, struct DBData *data, va_list ap); }; diff --git a/src/map/unit.c b/src/map/unit.c index 21dd31cb039..f8e48e8ba79 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -2882,7 +2882,7 @@ static int unit_free(struct block_list *bl, enum clr_type clrtype) sd->combo_count = 0; /* [Ind/Hercules] */ if( sd->sc_display_count ) { - for(int i = 0; i < sd->sc_display_count; i++) { + for (int i = 0; i < sd->sc_display_count; i++) { ers_free(pc->sc_display_ers, sd->sc_display[i]); } sd->sc_display_count = 0; @@ -2899,7 +2899,6 @@ static int unit_free(struct block_list *bl, enum clr_type clrtype) VECTOR_CLEAR(sd->auto_cast); // Clear auto-cast vector. VECTOR_CLEAR(sd->channels); VECTOR_CLEAR(sd->script_queues); - VECTOR_CLEAR(sd->achievement); // Achievement [Smokexyz/Hercules] VECTOR_CLEAR(sd->hatEffectId); VECTOR_CLEAR(sd->title_ids); // Title [Dastgir/Hercules]