VortexQuake2 / Vortex

Quake 2 Vortex. vrxcl/revival.
http://q2vortex.com
GNU General Public License v2.0
15 stars 17 forks source link

Stash system #198

Closed zardoru closed 1 year ago

zardoru commented 1 year ago

This adds a stash system with support for MySQL and SQLite. It also performs important maintenance and bugfixes for MySQL support. It abstracts over most io by having a struct initialized at InitGame time that has function pointers to all operations. It updates the SQL script file to support the stash system.

The stash io works similarly, setting up a structure with all stash operations.

Because of the MySQL support for this, a "deferral" system has been added so that actions can be done in the main thread after MySQL finalizes its operations.

This also comes with a renaming of most of the io functions to adhere to the module_action convention, and modifies the menu function names as a result. Because the stash must be released when the menus close, I added an "on close" event to menus that can be cancelled by setting a flag before the optionselected handler returns. This ensures that if the player dies etc.. the stash is unlocked.

The stash also gets unlocked if a player logs out and they had a stash locked. This should reduce the need for an administrator to have to unlock a stash for either database.

This also renames "Stash this item" to "Unequip this item", and changes "Delete This Item" into "Stash This Item."

Accessing the stash is a matter of using the "stash" command after either setting a master password (reconnect if it doesn't work right away -- the DLL needs to save it) or setting an owner by using the name and master password set.

It is possible that in MySQL mode an owner will be set and a request to save the character will be performed after the owner is set on the database, but before it is stored in the myskills structure. To avoid the overwriting, there's a special exception on the query that updates the userdata table that doesn't let it change if it is already set. It is still possible to change this manually, however.

This also performs maintenance on the SQLite IO by removing redundant strdup/free calls, and making both MySQL and SQLite use prepared statements instead of hoping that the players cannot send a malicious double quote. It also removes the old file-per-character code to reduce maintenance burden.