Skip to content

Commit

Permalink
Followup with review edits.
Browse files Browse the repository at this point in the history
  • Loading branch information
sagunkho committed Dec 26, 2017
1 parent 3035907 commit e82ebd0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 29 deletions.
18 changes: 15 additions & 3 deletions src/map/atcommand.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,11 @@ ACMD(storage)
}

sd->storage.access = STORAGE_ACCESS_ALL; // Default storage access for atcommands.
stor = storage->ensure(sd, storage_id);

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) {
safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 27), storage_name);
Expand Down Expand Up @@ -5208,7 +5212,11 @@ ACMD(storeall)
}

sd->storage.access = STORAGE_ACCESS_ALL; // Default storage access for atcommands.
stor = storage->ensure(sd, storage_id);

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.
Expand Down Expand Up @@ -5270,7 +5278,11 @@ ACMD(clearstorage)
}

sd->storage.access = STORAGE_ACCESS_ALL; // Default storage access for atcommands.
stor = storage->ensure(sd, storage_id);

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) {
clif->message(fd, msg_fd(fd, 27)); // "Storage has not been loaded yet"
Expand Down
16 changes: 11 additions & 5 deletions src/map/clif.c
Original file line number Diff line number Diff line change
Expand Up @@ -8594,7 +8594,9 @@ void clif_refresh_storagewindow(struct map_session_data *sd)

if (stst == NULL) return;

stor = storage->ensure(sd, sd->storage.current);
if ((stor = storage->ensure(sd, sd->storage.current)) == NULL) {
return;
}

if (stor->aggregate > 0) {
storage->sortitem(VECTOR_DATA(stor->item), VECTOR_LENGTH(stor->item));
Expand Down Expand Up @@ -12020,7 +12022,8 @@ void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)

if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) {
struct storage_data *stor = storage->ensure(sd, sd->storage.current);
storage->add(sd, stor, item_index, item_amount);
if (stor != NULL)
storage->add(sd, stor, item_index, item_amount);
} else if (sd->state.storage_flag == STORAGE_FLAG_GUILD) {
gstorage->add(sd, item_index, item_amount);
}
Expand All @@ -12041,7 +12044,8 @@ void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)

if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) {
struct storage_data *stor = storage->ensure(sd, sd->storage.current);
storage->get(sd, stor, item_index, item_amount);
if (stor != NULL)
storage->get(sd, stor, item_index, item_amount);
} else if(sd->state.storage_flag == STORAGE_FLAG_GUILD) {
gstorage->get(sd, item_index, item_amount);
}
Expand All @@ -12060,7 +12064,8 @@ void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)

if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) {
struct storage_data *stor = storage->ensure(sd, sd->storage.current);
storage->addfromcart(sd, stor, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
if (stor != NULL)
storage->addfromcart(sd, stor, RFIFOW(fd, 2) - 2, RFIFOL(fd, 4));
} else if (sd->state.storage_flag == STORAGE_FLAG_GUILD) {
gstorage->addfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
}
Expand All @@ -12079,7 +12084,8 @@ void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)

if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) {
struct storage_data *stor = storage->ensure(sd, sd->storage.current);
storage->gettocart(sd, stor, RFIFOW(fd,2)-1, RFIFOL(fd,4));
if (stor != NULL)
storage->gettocart(sd, stor, RFIFOW(fd,2) - 1, RFIFOL(fd, 4));
} else if (sd->state.storage_flag == STORAGE_FLAG_GUILD) {
gstorage->gettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
}
Expand Down
9 changes: 6 additions & 3 deletions src/map/intif.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ void intif_parse_account_storage(int fd)
return;
}

stor = storage->ensure(sd, RFIFOW(fd, 8));
if ((stor = storage->ensure(sd, RFIFOW(fd, 8))) == NULL)
return;

if (stor->received == true) {
ShowError("intif_parse_account_storage: Multiple calls from the inter-server received.\n");
Expand Down Expand Up @@ -525,7 +526,8 @@ void intif_send_account_storage(struct map_session_data *sd, int storage_id)

nullpo_retv(sd);

stor = storage->ensure(sd, storage_id);
if ((stor = storage->ensure(sd, storage_id)) == NULL)
return;

// Assert that at this point in the code, both flags are true.
Assert_retv(stor->save == true);
Expand Down Expand Up @@ -578,7 +580,8 @@ void intif_parse_account_storage_save_ack(int fd)
return;
}

stor = storage->ensure(sd, storage_id);
if ((stor = storage->ensure(sd, storage_id)) == NULL)
return;

stor->save = false; // Storage has been saved.
}
Expand Down
9 changes: 6 additions & 3 deletions src/map/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -10482,16 +10482,19 @@ BUILDIN(openstorage)
struct storage_data *stor = NULL;
const struct storage_settings *stst = NULL;

if (sd == NULL)
nullpo_retr(false, sd);

if ((stor = storage->ensure(sd, storage_id)) == NULL) {
script_pushint(st, 0);
ShowError("buildin_openstorage: Error ensuring storage for player aid %d, storage id %d.\n", sd->bl.id, storage_id);
return false;
}

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;
}

stor = storage->ensure(sd, storage_id);

if (stor->received == false) {
script_pushint(st, 0);
Expand Down
32 changes: 17 additions & 15 deletions src/map/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ const struct storage_settings *storage_get_settings(int storage_id)
*------------------------------------------*/
int storage_storageopen(struct map_session_data *sd, struct storage_data *stor)
{
const struct storage_settings *stst = storage->get_settings(stor->uid);
const struct storage_settings *stst = NULL;

nullpo_ret(sd);
nullpo_ret(stst);

nullpo_ret(stor);
Assert_ret(stor->received == true); // Assert the availability of data.
nullpo_ret(stst = storage->get_settings(stor->uid));

if (sd->state.storage_flag != STORAGE_FLAG_CLOSED)
return 1; // Storage is already open.
Expand Down Expand Up @@ -228,14 +228,16 @@ int storage_additem(struct map_session_data* sd, struct storage_data *stor, stru
{
struct item_data *data = NULL;
struct item *it = NULL;
const struct storage_settings *stst = storage->get_settings(stor->uid);
const struct storage_settings *stst = NULL;
int i;

nullpo_retr(1, sd);
nullpo_retr(1, stst); // Assert existence of storage configuration.
nullpo_retr(1, stor);
Assert_retr(1, stor->received == true); // Assert the availability of the storage.
Assert_ret(stst = storage->get_settings(stor->uid)); // Assert existence of storage configuration.
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.

data = itemdb->search(item_data->nameid);
Expand Down Expand Up @@ -308,12 +310,13 @@ int storage_additem(struct map_session_data* sd, struct storage_data *stor, stru
*------------------------------------------*/
int storage_delitem(struct map_session_data* sd, struct storage_data *stor, int n, int amount)
{
const struct storage_settings *stst = storage->get_settings(stor->uid);
struct item *it = NULL;
const struct storage_settings *stst = NULL;

nullpo_retr(1, sd);
Assert_retr(1, stst);
nullpo_retr(1, stor);
Assert_retr(1, stor->received == true);
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);
Expand Down Expand Up @@ -345,13 +348,12 @@ int storage_delitem(struct map_session_data* sd, struct storage_data *stor, int
*------------------------------------------*/
int storage_add_from_inventory(struct map_session_data* sd, struct storage_data *stor, int index, int amount)
{
const struct storage_settings *stst = storage->get_settings(stor->uid);
const struct storage_settings *stst = NULL;

nullpo_ret(sd);
nullpo_ret(stst);
nullpo_ret(stor);

Assert_ret(stor->received == true);
nullpo_ret(stst = storage->get_settings(stor->uid));

if ((sd->storage.access & STORAGE_ACCESS_PUT) == 0) {
clif->delitem(sd, index, amount, DELITEM_NORMAL);
Expand Down Expand Up @@ -427,13 +429,12 @@ int storage_add_to_inventory(struct map_session_data* sd, struct storage_data *s
*------------------------------------------*/
int storage_storageaddfromcart(struct map_session_data* sd, struct storage_data *stor, int index, int amount)
{
const struct storage_settings *stst = storage->get_settings(stor->uid);
const struct storage_settings *stst = NULL;

nullpo_ret(sd);
nullpo_ret(stst);
nullpo_ret(stor);

Assert_ret(stor->received == true);
nullpo_ret(stst = storage->get_settings(stor->uid));


if ((sd->storage.access & STORAGE_ACCESS_PUT) == 0) {
Expand Down Expand Up @@ -473,7 +474,7 @@ int storage_storagegettocart(struct map_session_data* sd, struct storage_data *s
struct item *it = NULL;

nullpo_ret(sd);

nullpo_ret(stor);
Assert_ret(stor->received == true);

if ((sd->storage.access & STORAGE_ACCESS_GET) == 0)
Expand Down Expand Up @@ -511,7 +512,8 @@ void storage_storageclose(struct map_session_data* sd)

nullpo_retv(sd);

curr_stor = storage->ensure(sd, sd->storage.current);
if ((curr_stor = storage->ensure(sd, sd->storage.current)) == NULL)
return;

clif->storageclose(sd);

Expand Down

0 comments on commit e82ebd0

Please sign in to comment.