Skip to content

Commit

Permalink
Merge pull request KillahPotatoes#560 from KillahPotatoes/v0.97S9-541
Browse files Browse the repository at this point in the history
Permission system Part 1
  • Loading branch information
Dubjunk authored Dec 30, 2018
2 parents 04a7533 + b5537d0 commit 5cbbec4
Show file tree
Hide file tree
Showing 35 changed files with 1,332 additions and 21 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"KPLIB_param_timeMulti",
"KPLIB_param_zeusFobIcons",
"KPLIB_param_zeusLocationIcons",
"KPLIB_param_permission",
"KPLIB_plm_groups",
"KPLIB_preset_addBoatE",
"KPLIB_preset_addBoatF",
Expand Down
6 changes: 3 additions & 3 deletions Missionframework/KPGUI/KPGUI_classes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
File: KPGUI_classes.hpp
Author: Wyqer - https://github.com/KillahPotatoes
Date: 2018-09-13
Last Update: 2018-12-09
Last Update: 2018-12-14
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Description:
Expand Down Expand Up @@ -35,8 +36,7 @@
*/

// Scrollbar
class KPGUI_PRE_ScrollBar
{
class KPGUI_PRE_ScrollBar {
color[] = {1, 1, 1, 0.6};
colorActive[] = {1, 1, 1, 1};
colorDisabled[] = {1, 1, 1, 0.3};
Expand Down
5 changes: 1 addition & 4 deletions Missionframework/KPGUI/KPGUI_defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
File: KPGUI_defines.hpp
Author: Wyqer - https://github.com/KillahPotatoes
Date: 2018-07-10
Last Update: 2018-12-05
Last Update: 2018-12-14
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Description:
Expand Down Expand Up @@ -141,6 +141,3 @@

#define KP_WIDTH_VAL_LP 0.2
#define KP_HEIGHT_VAL_LP (1 - 2 * KP_Y_VAL_LP - KP_HEIGTH_TITLE - KP_HEIGTH_BUTTON - 2 * KP_SPACING_Y)

// Classes include
#include "KPGUI_classes.hpp"
2 changes: 2 additions & 0 deletions Missionframework/KPLIB_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2017-10-16
Last Update: 2018-12-13
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Description:
Expand All @@ -19,6 +20,7 @@ class KPLIB {
#include "modules\03_respawn\functions.hpp"
#include "modules\04_adm\functions.hpp"
#include "modules\10_resources\functions.hpp"
#include "modules\11_permission\functions.hpp"
#include "modules\12_arsenal\functions.hpp"
#include "modules\13_plm\functions.hpp"
#include "modules\14_virtual\functions.hpp"
Expand Down
4 changes: 3 additions & 1 deletion Missionframework/KPLIB_ui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
File: KPLIB_ui.hpp
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2017-10-16
Last Update: 2018-11-24
Last Update: 2018-12-14
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Description:
Includes all ui defines, dialogs and elements from each module.
*/

#include "KPGUI\KPGUI_defines.hpp"
#include "KPGUI\KPGUI_classes.hpp"
#include "modules\00_init\ui.hpp"
#include "modules\02_core\ui.hpp"
#include "modules\03_respawn\ui.hpp"
#include "modules\04_adm\ui.hpp"
#include "modules\11_permission\ui.hpp"
#include "modules\12_arsenal\ui.hpp"
#include "modules\13_plm\ui.hpp"
#include "modules\14_virtual\ui.hpp"
Expand Down
99 changes: 99 additions & 0 deletions Missionframework/modules/11_permission/README.md
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]
]],
];
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
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
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)
Loading

0 comments on commit 5cbbec4

Please sign in to comment.