diff options
Diffstat (limited to 'src/map/atcommand.c')
-rw-r--r-- | src/map/atcommand.c | 131 |
1 files changed, 115 insertions, 16 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 6dae53720..540cea620 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -870,6 +870,41 @@ ACMD(speed) *------------------------------------------*/ ACMD(storage) { + char storage_name[NAME_LENGTH] = ""; + int storage_id = 0, intval = 0; + + 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 != '\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. + return false; + } + } else { + clif->message(fd, msg_fd(fd, 68)); // Please specify a storage name (usage: @storage <storage name>). + return false; + } + + 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) { + 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; + } + if (sd->npc_id || sd->state.vending || sd->state.prevend || sd->state.buyingstore || sd->state.trading || sd->state.storage_flag) return false; @@ -878,12 +913,14 @@ ACMD(storage) return false; } - if (storage->open(sd) == 1) { //Already open. - clif->message(fd, msg_fd(fd,250)); // You have already opened your storage. Close it first. + if (storage->open(sd, stor) == 1) { // Already open. + clif->message(fd, msg_fd(fd, 250)); // You have already opened your storage. Close it first. return false; } - clif->message(fd, msg_fd(fd,919)); // Storage opened. + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 919), storage_id); + + clif->message(fd, atcmd_output); // Storage #%d opened. return true; } @@ -5422,16 +5459,46 @@ ACMD(dropall) *------------------------------------------*/ ACMD(storeall) { + char storage_name[NAME_LENGTH] = ""; + int storage_id = 0, intval = 0; + + 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 != '\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. + return false; + } + } else { + clif->message(fd, msg_fd(fd, 65)); // Please specify a storage name (usage: @storeall <storage name>). + return false; + } + + 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; + } + if (sd->state.storage_flag != STORAGE_FLAG_NORMAL) { //Open storage. - if (storage->open(sd) == 1) { - clif->message(fd, msg_fd(fd,1161)); // You currently cannot open your storage. + if (storage->open(sd, stor) == 1) { + clif->message(fd, msg_fd(fd, 1161)); // You currently cannot open your storage. return false; } } - if (sd->storage.received == false) { - clif->message(fd, msg_fd(fd, 27)); // "Storage has not been loaded yet" + 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; } @@ -5439,39 +5506,70 @@ ACMD(storeall) if (sd->status.inventory[i].amount) { if(sd->status.inventory[i].equip != 0) pc->unequipitem(sd, i, PCUNEQUIPITEM_RECALC|PCUNEQUIPITEM_FORCE); - storage->add(sd, i, sd->status.inventory[i].amount); + storage->add(sd, stor, i, sd->status.inventory[i].amount); } } + storage->close(sd); clif->message(fd, msg_fd(fd,1162)); // All items stored. + return true; } ACMD(clearstorage) { - int i; + int i = 0; + char storage_name[NAME_LENGTH] = ""; + int storage_id = 0, intval = 0; + + 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 != '\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. + return false; + } + } else { + clif->message(fd, msg_fd(fd, 66)); // Please specify a storage name (usage: @clearstorage <skill name>). + return false; + } if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) { - clif->message(fd, msg_fd(fd,250)); + clif->message(fd, msg_fd(fd, 250)); // You have already opened your storage. Close it first. + return false; + } + + 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 (sd->storage.received == false) { + if (!stor->received) { clif->message(fd, msg_fd(fd, 27)); // "Storage has not been loaded yet" return false; } - for (i = 0; i < VECTOR_LENGTH(sd->storage.item); ++i) { - if (VECTOR_INDEX(sd->storage.item, i).nameid == 0) + for (i = 0; i < VECTOR_LENGTH(stor->item); ++i) { + if (VECTOR_INDEX(stor->item, i).nameid == 0) continue; // we skip the already deleted items. - storage->delitem(sd, i, VECTOR_INDEX(sd->storage.item, i).amount); + storage->delitem(sd, stor, i, VECTOR_INDEX(stor->item, i).amount); } storage->close(sd); clif->message(fd, msg_fd(fd,1394)); // Your storage was cleaned. + return true; } @@ -8391,8 +8489,9 @@ ACMD(itemlist) if( strcmpi(info->command, "storagelist") == 0 ) { location = "storage"; - items = VECTOR_DATA(sd->storage.item); - size = VECTOR_LENGTH(sd->storage.item); + struct storage_data *stor = storage->ensure(sd, 1); + items = VECTOR_DATA(stor->item); + size = VECTOR_LENGTH(stor->item); } else if( strcmpi(info->command, "cartlist") == 0 ) { location = "cart"; items = sd->status.cart; |