
All checks were successful
Build / Build (push) Successful in 26s
This commit refactors the database system to improve persistence, functionality, and code clarity. The key changes include: - **Removed direct store access:** Removed `createStore`, `getFromStore`, and `getStore` PREP macros. - **Centralized store management:** Introduced a central store registry (`FORGE_STORE_REG`) managed by the database interface. - **Namespace-based persistence:** Stores are now persisted in mission and profile namespaces instead of a global store. - **Simplified load/save functions:** `loadFromMission`, `loadFromProfile`, `saveToMission`, `saveToProfile`, and `saveToTemp` functions are updated to use the new namespace-based persistence. They now accept a `keyField` parameter for retrieving specific fields within a key's data. - **Refactored `processDBRequest`:** Updated to handle new request types and parameters, aligning with the refactored load/save functions. - **Improved error handling:** Added more robust error handling and logging, including checks for empty store names and missing keys. - **Removed client registration:** Removed client registration and cleanup logic as it's no longer needed with the new persistence model. - **Updated `verifyDB`:** Simplified to directly return the store registry. - **Updated `initDB`:** Refactored to use a HashMap object for the store interface and added more database functions. - **Added .gitignore entries:** Added entries for Visual Studio and other common build artifacts. - **Updated `loadGameState` and `saveGameState`:** Updated to support loading and saving game state to either mission or profile namespace.
79 lines
2.3 KiB
Plaintext
79 lines
2.3 KiB
Plaintext
#include "..\script_component.hpp"
|
|
|
|
/*
|
|
* Function: forge_server_db_fnc_processDBRequest
|
|
* Author: J. Schmidt
|
|
*
|
|
* Description:
|
|
* Processes database requests
|
|
*
|
|
* Arguments:
|
|
* 0: _type - Type of database operation <STRING>
|
|
* 1: _name - Name of the store <STRING>
|
|
* 2: _key - Key of the store <STRING>
|
|
* 3: _keyField - Field of the key to update <STRING>
|
|
* 4: _data - Data for the operation <STRING, ARRAY, NUMBER, BOOLEAN, HASHMAP>
|
|
*
|
|
* Return Value:
|
|
* None
|
|
*/
|
|
|
|
params [["_type", "", [""]], ["_name", "", [""]], ["_key", "", [""]], ["_keyField", "", [""]], ["_data", "", ["", [], 0, true, createHashMap]]];
|
|
|
|
private _store = call FUNC(verifyDB);
|
|
|
|
switch (_type) do {
|
|
case "createStore": {
|
|
params ["_name"];
|
|
_store call ["_create", [_name]];
|
|
};
|
|
case "getStore": {
|
|
params ["_name"];
|
|
_store call ["_read", [_name]];
|
|
};
|
|
case "saveToMission": {
|
|
params ["_name", "_key", "_data"];
|
|
[_name, _key, _data] call FUNC(saveToMission);
|
|
};
|
|
case "saveToProfile": {
|
|
params ["_name", "_key", "_data"];
|
|
[_name, _key, _data] call FUNC(saveToProfile);
|
|
};
|
|
case "saveToStore": {
|
|
params ["_name", "_data"];
|
|
_store call ["_write", [_name, _data]];
|
|
};
|
|
case "saveToTemp": {
|
|
params ["_name", "_key", "_data"];
|
|
[_name, _key, _data] call FUNC(saveToTemp);
|
|
};
|
|
case "getFromMission": {
|
|
params ["_name", "_key", "_keyField"];
|
|
[_name, _key, _keyField] call FUNC(loadFromMission);
|
|
};
|
|
case "getFromProfile": {
|
|
params ["_name", "_key", "_keyField"];
|
|
[_name, _key, _keyField] call FUNC(loadFromProfile);
|
|
};
|
|
case "getFromStore": {
|
|
params ["_name", "_key"];
|
|
_store call ["_read", [_name, _key]];
|
|
};
|
|
case "getFromTemp": {
|
|
params ["_name", "_key", "_keyField"];
|
|
[_name, _key, _keyField] call FUNC(loadFromTemp);
|
|
};
|
|
case "updateStore": {
|
|
params ["_name", "_key", "_keyField", "_data"];
|
|
_store call ["_update", [_name, _key, _keyField, _data]];
|
|
};
|
|
case "loadGameState": {
|
|
[] call FUNC(loadGameState);
|
|
};
|
|
case "saveGameState": {
|
|
[] call FUNC(saveGameState);
|
|
};
|
|
default {
|
|
WARNING_1("Unknown database request type: %1",_type)
|
|
};
|
|
}; |