forked from KillahPotatoes/KP-Liberation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request KillahPotatoes#560 from KillahPotatoes/v0.97S9-541
Permission system Part 1
- Loading branch information
Showing
35 changed files
with
1,332 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# KP Liberation Module Description | ||
|
||
## Permission Module | ||
The permission module provides a permission framework with a dynamic dialog. | ||
There are functions to create and check the permissions. | ||
|
||
### Dependencies | ||
* Init | ||
|
||
### Consumed events | ||
**KPLIB_doLoad** (server side) | ||
Calls KPLIB_fnc_permission_loadData to process saved module data | ||
|
||
**KPLIB_doSave** (server side) | ||
Calls KPLIB_fnc_permission_saveData to add the module data to the save array | ||
|
||
### Emitted events | ||
**KPLIB_permission_newPH** (servere side) | ||
EMitted when a new permission handler is registered | ||
|
||
### Functions | ||
* KPLIB_fnc_permission_addPermissionHandler | ||
|
||
*Adds a new permission to the permission system.* | ||
|
||
* KPLIB_fnc_permission_changePermission | ||
|
||
*Changes the selected permission of the given player.* | ||
|
||
* KPLIB_fnc_permission_checkPermission | ||
|
||
*Checks the given permission and executes the registered code.* | ||
|
||
* KPLIB_fnc_permission_checkVehiclePermission | ||
|
||
*Checks the given vehicle permission and executes the registered code.* | ||
|
||
* KPLIB_fnc_permission_ejectPlayer | ||
|
||
*Ejects the player and creates a hint.* | ||
|
||
* KPLIB_fnc_permission_getPermission | ||
|
||
*Checks the given permission and returns the result.* | ||
|
||
* KPLIB_fnc_permission_initDefault | ||
|
||
*Initializes the default permissions.* | ||
|
||
* KPLIB_fnc_permission_loadData | ||
|
||
*Loads data which is bound to the this module from the given save data or initializes needed data for a new campaign.* | ||
|
||
* KPLIB_fnc_permission_openDialog | ||
|
||
*Opens the permission dialog.* | ||
|
||
* KPLIB_fnc_arsenal_postInit | ||
|
||
*Module post initialization.* | ||
|
||
* KPLIB_fnc_arsenal_preInit | ||
|
||
*Module pre initialization.* | ||
|
||
* KPLIB_fnc_permission_registerPlayer | ||
*Checks if the player is already registered to the permission system.* | ||
|
||
* KPLIB_fnc_permission_resetToDefault | ||
*Resets all permissions to default.* | ||
|
||
* KPLIB_fnc_permission_saveData | ||
*Fetches data which is bound to this module and send it to the global save data array.* | ||
|
||
* KPLIB_fnc_permission_setupPermissionControls | ||
*Reads the player permissions and applies them to the dialog controls.* | ||
|
||
* KPLIB_fnc_permission_setupplayerActions | ||
*Initialization of actions availible to players.* | ||
|
||
* KPLIB_fnc_permission_syncClients | ||
*Receive client variables and send them to all clients.* | ||
|
||
### Scripts | ||
No scripts will be started by this module | ||
|
||
### Example Permission Array | ||
KPLIB_permission_list = [ | ||
["SteamID64", "PlayerName", [ | ||
["AVehicle", true], | ||
["BVehicle", false], | ||
["CVehicle", false] | ||
]], | ||
["SteamID64", "PlayerName", [ | ||
["AVehicle", true], | ||
["BVehicle", false], | ||
["CVehicle", false] | ||
]], | ||
]; |
66 changes: 66 additions & 0 deletions
66
Missionframework/modules/11_permission/fnc/fn_permission_addPermissionHandler.sqf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
KPLIB_fnc_permission_addPermissionHandler | ||
File: fn_permission_addPermission.sqf | ||
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes | ||
Date: 2018-12-09 | ||
Last Update: 2018-12-29 | ||
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html | ||
Description: | ||
Adds a new permission to the permission system. | ||
Parameter(s): | ||
_permission - Permission name [STRING, defaults to ""] | ||
_condition - Code which is executed on permission check [CODE, defaults to {false}] | ||
_string - Permission stringtable path [STRING, defaults to ""] | ||
_default - Default permission [BOOL, defaults to false] | ||
_group - Permission group name [STRING, defaults to "Misc"] | ||
_groupString - Permission group stringtable path [STRING, defaults to "STR_KPLIB_PERMISSION_GROUPMISC"] | ||
_vehCheck - Vehicle clasnames for the check [ARRAY, defaults to []] | ||
Returns: | ||
Function reached the end [BOOL] | ||
*/ | ||
|
||
if (!isServer) exitWith {}; | ||
|
||
params [ | ||
["_permission", "", [""]], | ||
["_code", {false}, [{}]], | ||
["_string", "", [""]], | ||
["_default", false, [false]], | ||
["_group", "Misc", [""]], | ||
["_groupString", "STR_KPLIB_PERMISSION_GROUPMISC", [""]], | ||
["_vehCheck", [], [[]]] | ||
]; | ||
|
||
_permission = toLower _permission; | ||
|
||
KPLIB_permission_types pushBackUnique _permission; | ||
|
||
private _index = KPLIB_permission_groups findIf {(_x select 0) isEqualTo _group}; | ||
|
||
if (_index isEqualTo -1) then { | ||
KPLIB_permission_groups pushBack [_group, _groupString, [_permission]]; | ||
} else { | ||
((KPLIB_permission_groups select _index) select 2) pushBackUnique _permission; | ||
}; | ||
|
||
// Read the Variable | ||
private _data = [[_code], _string, _vehCheck]; | ||
(_data select 0) append ((KPLIB_permission_data getVariable [_permission, []]) select 0); | ||
|
||
if !(_string isEqualTo "") then { | ||
_data set [1, _string]; | ||
}; | ||
|
||
// Write the Variable | ||
KPLIB_permission_data setVariable [_permission, _data, true]; | ||
|
||
// Emit permissions added event | ||
["KPLIB_permission_newPH", [_permission,_default]] call CBA_fnc_globalEvent; | ||
|
||
[[], [], KPLIB_permission_types, KPLIB_permission_groups] call KPLIB_fnc_permission_syncClients; | ||
|
||
true |
73 changes: 73 additions & 0 deletions
73
Missionframework/modules/11_permission/fnc/fn_permission_changePermission.sqf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "script_component.hpp" | ||
/* | ||
KPLIB_fnc_permission_changePermission | ||
File: fn_permission_changePermission.sqf | ||
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes | ||
Date: 2018-12-16 | ||
Last Update: 2018-12-29 | ||
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html | ||
Description: | ||
Changes the selected permission of the given player. | ||
Parameter(s): | ||
_args - Provided arguments of the EH [ARRAY, defaults to []]] | ||
Returns: | ||
Function reached the end [BOOL] | ||
*/ | ||
|
||
params [ | ||
["_args", [], [[]]] | ||
]; | ||
|
||
_args params ["_control"]; | ||
|
||
// Dialog controls | ||
private _dialog = findDisplay 758011; | ||
private _ctrlPlayerList = _dialog displayCtrl 68740; | ||
|
||
// Read the control | ||
(_control getVariable ["Data", ["", false]]) params [ | ||
"_permission", | ||
"_state" | ||
]; | ||
|
||
// Get the listbox data | ||
private _index = lbCurSel _ctrlPlayerList; | ||
private _playerUID = _ctrlPlayerList lbData _index; | ||
private _playerArray = []; | ||
private _playerPermissions = []; | ||
private _permissionArray = []; | ||
_permission = toLower _permission; | ||
|
||
switch (_playerUID) do { | ||
case "default": { | ||
_index = KPLIB_permission_default findIf {(_x select 0) isEqualTo (_permission)}; | ||
(KPLIB_permission_default select _index) set [1, !_state]; | ||
}; | ||
default { | ||
// Change the player permission or apply them | ||
_index = KPLIB_permission_list findIf {(_x select 0) isEqualTo (_playerUID)}; | ||
if (_index != -1) then { | ||
// Ref to player array in permission list | ||
_playerArray = KPLIB_permission_list select _index; | ||
_index = (_playerArray select 2) findIf {(_x select 0) isEqualTo (_permission)}; | ||
|
||
// If the player already has the permission, change the state | ||
if (_index != -1) then { | ||
((_playerArray select 2) select _index) set [1, !_state]; | ||
} else { | ||
// Otherwise add the permission | ||
(_playerArray select 2) pushBack [_permission, !_state]; | ||
}; | ||
}; | ||
}; | ||
}; | ||
|
||
// Edit the control | ||
_control setVariable ["Data", [_permission, !_state]]; | ||
_control ctrlSetTextColor ([KPLIB_COLOR_GREEN, KPLIB_COLOR_RED] select _state); | ||
|
||
true |
36 changes: 36 additions & 0 deletions
36
Missionframework/modules/11_permission/fnc/fn_permission_checkPermission.sqf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
KPLIB_fnc_permission_checkPermission | ||
File: fn_permission_checkPermission.sqf | ||
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes | ||
Date: 2018-12-09 | ||
Last Update: 2018-12-28 | ||
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html | ||
Description: | ||
Checks the given permission and executes the registered code. | ||
Parameter(s): | ||
_permission - Permission name [STRING, defaults to ""] | ||
Returns: | ||
Result of the registered code [BOOL] | ||
*/ | ||
|
||
params [ | ||
["_permission", "", [""]] | ||
]; | ||
|
||
if !(KPLIB_param_permission) exitWith { | ||
true | ||
}; | ||
|
||
private _results = []; | ||
private _data = KPLIB_permission_data getVariable [toLower _permission, []]; | ||
|
||
// Execute the registered code | ||
{ | ||
_results pushBack ([] call _x); | ||
} forEach (_data select 0); | ||
|
||
(true in _results) |
Oops, something went wrong.