Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hercules Ultimate Storage System #2724

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

dastgirp
Copy link
Member

Pull Request Prelude

Changes Proposed

Design

Implementation of the Hercules Ultimate Storage System
Storages can now be created through a configuration file that describes their attributes.
Example storage configuration:

{
        Id: (int)                              (required|unique) Unique Identifier
        Name: (string)                         (required) Name of the storage sent to the client.
        Capacity: (int)                        (required) Maximum capacity of the storage.
}

Additional storages are handled with dynamic arrays that will save a tonne of memory when created, as opposed to a design in which they were implemented using fixed length arrays. In simple terms, a storage of 600 items would approximately cost the same amount of memory as 600 storages with 1 item each.
They are saved in the same storage database (SQL) as the original separating them by a storage identifier.
An infinite number of storages can be created, there are no limits.
The current design implementation only allow saving/loading of approximately 1600 items per storage due to packet size limits.

PS. Make sure you apply SQL upgrades for this patch!

Access Modes

Storage access modes can be set through the openstorage builtin command.

	STORAGE_ACCESS_VIEW     // View storage only
	STORAGE_ACCESS_GET      // Allow getting items from storage.
	STORAGE_ACCESS_PUT      // Allow putting items to storage.
	STORAGE_ACCESS_ALL      // Allow all actions.

Default storage mode : STORAGE_ACCESS_ALL

Script Commands

Changed: openstorage(<storage_id>{, <storage_mode>})

Issues addressed:

@dastgirp dastgirp requested review from Kenpachi2k13 and 4144 and removed request for Kenpachi2k13 May 16, 2020 18:02
@4144
Copy link
Contributor

4144 commented May 16, 2020

from ci, look like shadow variable i

@dastgirp
Copy link
Member Author

Windows compile fine for now, will be checking linux warnings and errors soon.

Copy link
Contributor

@4144 4144 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some checks probably already added in last commit, but i checked commit by commit from start

conf/messages.conf Outdated Show resolved Hide resolved
conf/messages.conf Outdated Show resolved Hide resolved
src/map/clif.c Show resolved Hide resolved
src/map/clif.c Show resolved Hide resolved
src/map/clif.c Show resolved Hide resolved
src/map/intif.c Outdated Show resolved Hide resolved
src/map/intif.c Outdated Show resolved Hide resolved
src/map/script.c Outdated Show resolved Hide resolved
src/map/storage.c Outdated Show resolved Hide resolved
db/constants.conf Outdated Show resolved Hide resolved
@Kenpachi2k13
Copy link
Member

In my opinion the Xcode upgrade should not be part of this PR since it's not required.

@dastgirp
Copy link
Member Author

In my opinion the Xcode upgrade should not be part of this PR since it's not required.

Ok, will remove it, I had just migrated it from old code to new code

@dastgirp dastgirp force-pushed the sStorage branch 3 times, most recently from ab0a8dc to 772ff5e Compare May 24, 2020 06:09
@dastgirp dastgirp requested a review from 4144 May 24, 2020 06:11
@dastgirp dastgirp force-pushed the sStorage branch 2 times, most recently from 14871b7 to 274ec5b Compare May 24, 2020 06:24
@dastgirp dastgirp marked this pull request as ready for review May 24, 2020 06:24
@dastgirp
Copy link
Member Author

@4144 @Kenpachi2k13 can you review again?

src/map/atcommand.c Outdated Show resolved Hide resolved
src/map/clif.c Outdated
return;
}

nullpo_retv(stor);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this nullpo probably need move into if block, because after if block, stor is non null

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/map/clif.c Outdated
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be else if (sd->...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/map/intif.c Outdated
if ((stor = storage->ensure(sd, RFIFOW(fd, 8))) == NULL)
return;

Assert_retv(stor != NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here stor is not null

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/map/intif.c Outdated
if ((stor = storage->ensure(sd, storage_id)) == NULL)
return;

Assert_retv(stor != NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here stor is not null

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@bWolfie
Copy link
Contributor

bWolfie commented Jun 8, 2020

nice bro

@bWolfie
Copy link
Contributor

bWolfie commented Jun 9, 2020

Anyone currently using this on their server?

@4144
Copy link
Contributor

4144 commented Jul 26, 2020

@dastgirp you can complete this?

@Vaans
Copy link

Vaans commented Oct 28, 2020

dreams come true :D?

src/map/unit.c Outdated
@@ -2875,8 +2875,7 @@ static int unit_free(struct block_list *bl, enum clr_type clrtype)
sd->combo_count = 0;
/* [Ind/Hercules] */
if( sd->sc_display_count ) {
int i;
for(i = 0; i < sd->sc_display_count; i++) {
for(int i = 0; i < sd->sc_display_count; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after for and the curly brackets could be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/map/unit.c Outdated
@@ -2891,11 +2890,18 @@ static int unit_free(struct block_list *bl, enum clr_type clrtype)
}
VECTOR_CLEAR(sd->channels);
VECTOR_CLEAR(sd->script_queues);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this empty line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, might be due to merge from old commit to here

@@ -95,37 +97,105 @@ static void do_reconnect_storage(void)
gstorage->db->foreach(gstorage->db, storage->reconnect_sub);
}

/**
* Get a storage id by its name (through @commands etc...)
* @param[in] storage_name pointer to the storage name char array.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please separate the description and the parameter list with an empty comment line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


/**
* Get storage with a particular ID from a player.
* @param[in] sd pointer to map session data.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please separate the description and the parameter list with an empty comment line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

int i = 0;
struct storage_data *stor = NULL;

nullpo_retr(NULL, sd);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the NULL pointer check prior to declaring/initialising the variables.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/char/mapif.c Outdated
* @param fd [in] file/socket descriptor.
* @return 1 on success, 0 on failure.
*/
static int mapif_parse_AccountStorageSave(int fd)
{
int payload_size = RFIFOW(fd, 2) - 8, account_id = RFIFOL(fd, 4);
int payload_size = RFIFOW(fd, 2) - 10, account_id = RFIFOL(fd, 4);
short storage_id = RFIFOW(fd, 8);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
short storage_id = RFIFOW(fd, 8);
int storage_id = RFIFOW(fd, 8);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is of 2 bytes, only, but as I see other are using int, changed it. done


return 1;
}

/**
* Sends an acknowledgement for the save
* status of the account storage.
* @packet 0x3808 [out] <account_id>.L <save_flag>.B
* @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 flag [in] Save flag, true for success and false for failure.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add parameter storage_id.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 47 to 50
bool *matched_p = NULL;
int *delete = NULL;
int total_deletes = 0, total_updates = 0, total_inserts = 0;
int total_changes = 0;
int cp_size = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix variable scopes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -947,6 +948,7 @@ INSERT IGNORE INTO `sql_updates` (`timestamp`) VALUES (1588301040); -- 2020-05-0
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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`storage_id` INT(11) UNSIGNED NOT NULL DEFAULT '1',
`storage_id` INT UNSIGNED NOT NULL DEFAULT '1',

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

-- 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`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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`;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@SombraRO
Copy link

@dastgirp something about that?

sagunkho and others added 10 commits November 28, 2020 18:14
Storages can now be created through a configuration file that describes their attributes.

Example storage configuration:

```
{
	Id: (int)                              (required|unique) Unique Identifier
	Name: (string)                         (required) Name of the storage sent to the client.
	Capacity: (int)                        (required) Maximum capacity of the storage.
}
```

Additional storages are handled with dynamic arrays that will save a tonne of memory when created.
They are saved in the same storage database (SQL) as the original.
An infinite number of storages can be created, there are no limits.
The current design implementation only allow saving/loading of approximately 1600 items per storage due to packet size limits.

PS. Make sure you apply SQL upgrades for this patch!
Added support for storage modes:
STORAGE_ACCESS_VIEW
STORAGE_ACCESS_GET
STORAGE_ACCESS_PUT
STORAGE_ACCESS_ALL
@dastgirp
Copy link
Member Author

@Kenpachi2k13 updated to latest commit and made all changes that were mentioned by you.

@4144
Copy link
Contributor

4144 commented Nov 28, 2020

look like compilation errors in all or most jobs

@dastgirp
Copy link
Member Author

look like compilation errors in all or most jobs

was problem with scope, fixed it.

@pazkero
Copy link
Contributor

pazkero commented Feb 15, 2021

@dastgirp Can you complete this? Seems to be having conflicts again... =(

@dastgirp
Copy link
Member Author

@dastgirp Can you complete this? Seems to be having conflicts again... =(

It was already completed but for some reason not merged,
If it is going to be merged in next cycle, I can fix the conflicts again, but without confirmation, it would just keep on conflicting with every new release, so, I won't be fixing conflict as of now until confirmation is received or some changes are requested.

@pazkero
Copy link
Contributor

pazkero commented Feb 16, 2021 via email

@@ -11372,10 +11372,30 @@ static BUILDIN(gettimestr)
static BUILDIN(openstorage)
{
struct map_session_data *sd = script->rid2sd(st);
if (sd == NULL)
int storage_id = script_getnum(st, 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not making this optional, as you need to have a storage 1 configured (SQL, for example) and considering it would improve compatibility?

Suggested change
int storage_id = script_getnum(st, 2);
int storage_id = script_hasdata(st, 2) ? script_getnum(st, 2) : 1;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this as optional is a way, but it won't tell others something is wrong.
Specifying storage id is better as it's clear that storage 1 will be used.
You can have any id you want, (even remove the Id 1), so having this optional would make it more confusing

@sgsilva
Copy link

sgsilva commented Jul 1, 2021

Does anyone have any news about?

@pazkero
Copy link
Contributor

pazkero commented Jul 1, 2021 via email

@waken22
Copy link

waken22 commented Nov 5, 2021

Any news about this?

@bWolfie
Copy link
Contributor

bWolfie commented Nov 12, 2021

One day it will become a reality. Lol.

@csnv
Copy link
Contributor

csnv commented Sep 19, 2023

@dastgirp @MishimaHaruna can we have a definitive merging window and finish this?

@Vaans
Copy link

Vaans commented Feb 16, 2024

Four years already :'(

@Samuel23 Samuel23 mentioned this pull request Jun 18, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet