Skip to content

Commit

Permalink
Code styling
Browse files Browse the repository at this point in the history
  • Loading branch information
dastgirp committed Nov 28, 2020
1 parent aa8a87e commit ebdb684
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 150 deletions.
2 changes: 1 addition & 1 deletion sql-files/main.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion sql-files/upgrades/2020-05-16--17-12.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

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);
19 changes: 7 additions & 12 deletions src/char/int_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 13 additions & 6 deletions src/char/mapif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] <packet_len>.W <account_id>.L <storage_id>.W <struct item[]>.P
* @param fd [in] file/socket descriptor.
* @param account_id [in] account id of the session.
*
* @packet 0x3805 [out] <packet_len>.W <account_id>.L <storage_id>.W <struct item[]>.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)
Expand Down Expand Up @@ -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);
Expand All @@ -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 };
Expand Down Expand Up @@ -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] <account_id>.L <storage_id>.W <save_flag>.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)
Expand Down
28 changes: 14 additions & 14 deletions src/map/atcommand.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions src/map/chrif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 7 additions & 15 deletions src/map/clif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/map/clif.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit ebdb684

Please sign in to comment.