Commit 8212b6e4 authored by Razer's avatar Razer
Browse files

Updated DB clan functions

parent 87f30d16
......@@ -7,6 +7,11 @@
PARAMS:
1 - STRING or OBJECT: Object oUUID or object.
USAGE:
_clanUUID = ([_object] call DB_fnc_getClanObject) select 1;
_objectOwnerUUID = ([_oUUID] call DB_fnc_getClanObject) select 0;
RETURNS:
NIL = error
["oOWNER","clanUUID"]
......
......@@ -11,7 +11,7 @@
/*
DESCRIPTION:
This function is used to add player in clan.
This function is used to add player to clan.
PARAMS:
1 - OBJECT or STRING: Player object or pUUID
......@@ -22,8 +22,8 @@
USAGE:
_success = [_pUUID,_clanUUID,_rank,_comment] call DB_fnc_addClanPlayer; // Adds player to a clan even if player is offline
RETURNS:
TRUE of success FALSE, if failed
RETURNS:
TRUE of success FALSE, if failed
*/
#include "\ApmsDB\constants.hpp"
......@@ -33,7 +33,7 @@ params [["_player",objNull,[objNull,""]],["_clanUUID","",[""]],["_rank",100,[0]]
if(_player isEqualTo objNull || _clanUUID == "") exitWith {diag_log "<ApmsDB>: ERROR: Cannot add player to clan, invalid params!";false};
private _pUUID = if (_player isEqualType objNull) then {_player getVariable ["pUUID",""]} else {_player};
if (_pUUID == "") exitWith {diag_log "<ApmsDB>: ERROR: Unable to add player to clan, no pUUID found!"}; // Make sure player object has pUUID
if (_pUUID == "") exitWith {diag_log "<ApmsDB>: ERROR: Unable to add player to clan, no pUUID found!"};
private _request = [PROTOCOL_DBCALL_FUNCTION_ADD_CLAN_PLAYER,[
PROTOCOL_DBCALL_ARGUMENT_CLAN_UUID,_clanUUID,
......@@ -43,8 +43,7 @@ private _request = [PROTOCOL_DBCALL_FUNCTION_ADD_CLAN_PLAYER,[
]];
private _return = [_request] call DB_fnc_sendRequest;
if (_return isEqualType [] && {(_return select 0) isEqualTo "error"}) exitWith {false}; // Use select 1 for "real" error code?
if (_return isEqualType [] && {(_return select 0) isEqualTo "error"}) exitWith {false};
// Get player object from pUUID
if(_player isEqualType "") then {
......
/*
* Desolation Redux
* http://desolationredux.com/
* © 2016 - 2020 Desolation Dev Team
*
* This work is licensed under the Arma Public License Share Alike (APL-SA) + Bohemia monetization rights.
* To view a copy of this license, visit:
* https://www.bistudio.com/community/licenses/arma-public-license-share-alike/
* https://www.bistudio.com/monetization/
*/
// TODO
/*
DESCRIPTION:
This function is used to update players previous clan data (Rank or Comment), or to add player in clan.
PARAMS:
1 - OBJECT or ARRAY: Player object or array (pUUID and clanUUID)
2 - NUMBER or STRING: Player rank or comment.
3 - STRING (Optional): Player comment.
USAGE:
[player,_rank] call DB_fnc_updateClanPlayer; // Updates players current clan rank
[player,_comment] call DB_fnc_updateClanPlayer; // Updates players current clan comment
[player,_rank,_comment] call DB_fnc_updateClanPlayer; // Updates players current clan rank and comment
[[_pUUID,_clanUUID],_rank,_comment] call DB_fnc_updateClanPlayer; // Update player clan data, even is player offline
RETURNS:
TRUE of success FALSE, if failed
*/
#include "\ApmsDB\constants.hpp"
params [["_player",objNull,[objNull,[]]],"_rankParam","_commentParam"];
if(_player isEqualTo objNull) exitWith {diag_log "<ApmsDB>: ERROR: Cannot update player's clan data. Player object is null!";false};
if(isNil "_rankParam") exitWith {false}; // No params to update
private _pUUID = "";
private _clanUUID = "";
// Is player object (Update previous clan)
if(_player isEqualType objNull) then {
_pUUID = _player getVariable ["pUUID",""];
_clanUUID = _player getVariable ["clanUUID",""];
} else {
// Is array of strings
if (count _player != 2 || !(_player isEqualTypeAll "")) exitWith {};
_pUUID = _player select 0;
_clanUUID = _player select 1;
};
// Check data again
if(_pUUID isEqualTo "" || _clanUUID isEqualTo "") exitWith {diag_log "<ApmsDB>: ERROR: Unable to get player's clanUUID or pUUID!";false};
private _request = [PROTOCOL_DBCALL_ARGUMENT_CLAN_UUID,_clanUUID,PROTOCOL_DBCALL_ARGUMENT_PLAYER_UUID,_pUUID];
// Parse params
private _rank = [nil,_rankParam] select (_rankParam isEqualType 0);
private _comment = [([nil,_commentParam] select (_commentParam isEqualType "")),_rankParam] select (_rankParam isEqualType "");
if(isNil "_rank" && isNil "_comment") exitWith {false}; // Invalid param types
// Update request array
if!(isNil "_rank") then {_request append [PROTOCOL_DBCALL_ARGUMENT_RANK,_rank]};
if!(isNil "_comment") then {_request append [PROTOCOL_DBCALL_ARGUMENT_COMMENT,_comment]};
private _return = [[PROTOCOL_DBCALL_FUNCTION_UPDATE_CLAN_PLAYER,_request]] call DB_fnc_sendRequest;
if (_return isEqualType [] && {(_return select 0) isEqualTo "error"}) exitWith {false};
// Define player object if online
if(_player isEqualType []) then {
private _playerObj = allPlayers select {_x getVariable ["pUUID",""] == _pUUID};
// Return objNull for scripted events if player is not online
_player = [objNull,_playerObj select 0] select (count _playerObj > 0);
};
["DB_onClanPlayerUpdated",[_clanUUID,_pUUID,_player]] spawn BASE_fnc_addEventHandler;
true
\ No newline at end of file
/*
* Desolation Redux
* http://desolationredux.com/
* © 2016 - 2020 Desolation Dev Team
*
* This work is licensed under the Arma Public License Share Alike (APL-SA) + Bohemia monetization rights.
* To view a copy of this license, visit:
* https://www.bistudio.com/community/licenses/arma-public-license-share-alike/
* https://www.bistudio.com/monetization/
*/
// Check if player x is in the same clan as player y
/*
DESCRIPTION:
Check if player x is in the same clan as player y
PARAMS:
1 - OBJECT or STRING: Target Clan Player object or pUUID
2 - OBJECT or STRING: Player object or pUUID
USAGE:
_isclanMember = [_player] call DB_fnc_isClanMember;
_isclanMember = [_target,player] call DB_fnc_isClanMember;
_isclanMember = [_targetUUID,player] call DB_fnc_isClanMember;
_isclanMember = [_targetUUID,_pUUID] call DB_fnc_isClanMember;
RETURNS:
TRUE if member FALSE if not
*/
// Client request
if(!isServer) exitWith {_this call DB_fnc_serverRequest};
params [["_target","",[objNull,""]],["_player","",[objNull,""]]];
private _playerClan = if (_player isEqualType "") then {_player} else {_player getVariable ["clanUUID",""]};
if (_playerClan == "") exitWith {false};
private _targetClan = if (_target isEqualType "") then {_target} else {_target getVariable ["clanUUID",""]};
if (_targetClan == "") exitWith {false};
// Return data to client
if(isRemoteExecuted && {remoteExecutedOwner != 2}) exitWith {
[missionNamespace,[("DB_var_response_" + _fnc_scriptName),((_clanData select 2) == _pUUID)]] remoteExecCall ["setVariable",remoteExecutedOwner];
};
(_playerClan == _targetClan);
\ No newline at end of file
......@@ -9,15 +9,32 @@
* https://www.bistudio.com/monetization/
*/
/*
DESCRIPTION:
This function us used to check if player is clan owner.
TODO: Add clan UUID as optional param
PARAMS:
1 - OBJECT or STRING: Player object or pUUID
USAGE:
_isclanOwner = [_player] call DB_fnc_isClanOwner;
RETURNS:
TRUE if owner FALSE if not
*/
// Client request
if(!isServer) exitWith {_this call DB_fnc_serverRequest};
params [["_player",objNull,[objNull,""]]];
if(_player isEqualTo objNull) exitWith {};
if(_player isEqualTo objNull) exitWith {false};
private _pUUID = if (_player isEqualType objNull) then {_player getVariable ["pUUID",""]} else {_player};
if(_pUUID == "") exitWith {};
if(_pUUID == "") exitWith {false};
private _clanUUID = if(_player isEqualType "") then {
......@@ -40,9 +57,14 @@ private _clanUUID = if(_player isEqualType "") then {
_player getVariable ["clanUUID",""];
};
if (_clanUUID == "") exitWith {}; // Unable to get player clan
if (_clanUUID == "") exitWith {false}; // Unable to get player clan
private _clanData = [_clanUUID] call DB_fnc_getClanData;
if (isNil "_clanData") exitWith {};
if (isNil "_clanData") exitWith {false};
// Return data to client
if(isRemoteExecuted && {remoteExecutedOwner != 2}) exitWith {
[missionNamespace,[("DB_var_response_" + _fnc_scriptName),((_clanData select 2) == _pUUID)]] remoteExecCall ["setVariable",remoteExecutedOwner];
};
(_clanData select 1) == _pUUID
\ No newline at end of file
(_clanData select 2) == _pUUID
\ No newline at end of file
......@@ -10,6 +10,13 @@
*/
/*
DESCRIPTION:
This function is used to remove player from clan.
PARAMS:
1 - OBJECT or STRING: Player object or pUUID
2 - STRING (Optional): Clan UUID (Required if pUUID is used!)
USAGE:
[playerObject] call DB_fnc_removeClanPlayer;
[_pUUID,_clanUUID] call DB_fnc_removeClanPlayer;
......@@ -37,14 +44,6 @@ private _pUUID = if(_player isEqualType objNull) then {
// Check data again
if(_pUUID isEqualTo "" || _clanUUID isEqualTo "") exitWith {diag_log "<ApmsDB>: ERROR: Unable to get player's current clanUUID or pUUID!";false};
// Unlink clan
private _request = [PROTOCOL_DBCALL_FUNCTION_DELETE_CLAN_PLAYER,[
PROTOCOL_DBCALL_ARGUMENT_CLAN_UUID,_clanUUID,
PROTOCOL_DBCALL_ARGUMENT_PLAYER_UUID,_pUUID
]];
private _return = [_request] call DB_fnc_sendRequest;
// Remove mainclan link
private _request = [PROTOCOL_DBCALL_FUNCTION_UPDATE_PLAYER_MAIN_CLAN,[
PROTOCOL_DBCALL_ARGUMENT_CLAN_UUID,"",
......@@ -52,7 +51,13 @@ private _request = [PROTOCOL_DBCALL_FUNCTION_UPDATE_PLAYER_MAIN_CLAN,[
]];
[_request] call DB_fnc_sendRequest;
if (_return isEqualType [] && {(_return select 0) isEqualTo "error"}) exitWith {false}; // Use select 1 for "real" error code?
// Unlink clan link
_request = [PROTOCOL_DBCALL_FUNCTION_DELETE_CLAN_PLAYER,[
PROTOCOL_DBCALL_ARGUMENT_CLAN_UUID,_clanUUID,
PROTOCOL_DBCALL_ARGUMENT_PLAYER_UUID,_pUUID
]];
private _return = [_request] call DB_fnc_sendRequest;
if (_return isEqualType [] && {(_return select 0) isEqualTo "error"}) exitWith {false};
// Get player object from pUUID
......
......@@ -13,12 +13,14 @@
This function is used to create clan.
PARAMS:
1 - STRING or OBJECT: Player UUID or player object.
2 - STRING: Clan name.
1 - STRING or OBJECT: Player UUID or player object
2 - STRING: Clan name
EXAMPLES:
[playerObject,"ClanName"] call DB_fnc_createClan;
["pUUID","ClanName"] call DB_fnc_createClan;
_pUUID = (allPlayers select 0) getVariable ["pUUID",""];
[_pUUID,"ClanName"] call DB_fnc_createClan;
RETURNS:
["CLANUUID"] - ARRAY <-- if works
......@@ -73,11 +75,11 @@ if!(isNull _player) then {
};
// Update mainclan
private _request = [PROTOCOL_DBCALL_FUNCTION_UPDATE_PLAYER_MAIN_CLAN,[
_request = [PROTOCOL_DBCALL_FUNCTION_UPDATE_PLAYER_MAIN_CLAN,[
PROTOCOL_DBCALL_ARGUMENT_CLAN_UUID,_clanUUID,
PROTOCOL_DBCALL_ARGUMENT_PLAYER_UUID,_pUUID
]];
[_request] call DB_fnc_sendRequest;
_return = [_request] call DB_fnc_sendRequest;
["DB_onClanCreated",[_clanUUID,_clanName]] spawn BASE_fnc_addEventHandler; // Execute on failed also? (with params: [])
......
......@@ -28,7 +28,7 @@
_array = [_clanUUID,"members"] call DB_fnc_updateClanPlayer;
RETURNS:
- "all": (ARRAY) --> [name, owners uuid, owners steamid, owners lastnick, [members],[variables]]
- "all": (ARRAY) --> [clan uuid, name, owners uuid, owners steamid, owners lastnick, [members],[variables]]
- "name": (STRING) --> "MyClan"
- "members": (ARRAY) --> [[player uuid, steamid, lastnick, rank, comment], [player uuid, steamid, lastnick, rank, comment]]
- "variables": (ARRAY) --> [["varName1",data],["varName2",data]]
......@@ -37,6 +37,9 @@
WARNING: In case of error, NIL will be returned!
*/
// Client request
if(!isServer) exitWith {_this call DB_fnc_serverRequest};
#include "\ApmsDB\constants.hpp"
params [["_clanUUID","",[""]],["_option","",[""]]];
......@@ -44,22 +47,25 @@ params [["_clanUUID","",[""]],["_option","",[""]]];
if(_clanUUID == "") exitWith {};
private _request = [PROTOCOL_DBCALL_FUNCTION_GET_CLAN,[PROTOCOL_DBCALL_ARGUMENT_CLAN_UUID,_clanUUID]];
private _data = [_request] call DB_fnc_sendRequest;
private _return = [_request] call DB_fnc_sendRequest;
// Make sure data is correct
if (_data isEqualType [] && {_data select 0 isEqualTo "error"}) exitWith {};
_data deleteAt 0; // Delete clan UUID since its useless :/
if (_return isEqualType [] && {_return select 0 isEqualTo "error"}) exitWith {};
// Redefine data based on settings (if used)
if (_option != "" && _option != "all") then {
_data = switch (toLower(_option)) do {
case "name": {_data select 0};
case "members": {_data select 4};
case "variables": {_data select 5};
case "owner": {_data select [1,3]};
default {_data};
_return = switch (toLower(_option)) do {
case "name": {_return select 1};
case "members": {_return select 5};
case "variables": {_return select 6};
case "owner": {_return select [2,4]};
default {_return};
};
};
_data
\ No newline at end of file
// Return data to client
if(isRemoteExecuted && {remoteExecutedOwner != 2}) exitWith {
[missionNamespace,[("DB_var_response_" + _fnc_scriptName),_return]] remoteExecCall ["setVariable",remoteExecutedOwner];
};
_return
\ No newline at end of file
......@@ -27,6 +27,9 @@
WARNING: Returns NIL if error occured!
*/
// Client request
if(!isServer) exitWith {_this call DB_fnc_serverRequest};
params [["_clanUUID","",[""]],["_varName","",[""]],"_default"];
if(_clanUUID == "" || _varName == "") exitWith {}; // UKNOWN PARAMS
......@@ -37,4 +40,11 @@ if(isNil "_variables") exitWith {}; // ERROR
private _varIndex = _variables findIf {_x select 0 == _varName};
[(_variables select _varIndex) select _varIndex,_default] select (_varIndex == -1);
\ No newline at end of file
private _return = [(_variables select _varIndex) select 1,_default] select (_varIndex == -1);
// Return data to client
if(isRemoteExecuted && {remoteExecutedOwner != 2}) exitWith {
[missionNamespace,[("DB_var_response_" + _fnc_scriptName),_return]] remoteExecCall ["setVariable",remoteExecutedOwner];
};
_return
\ No newline at end of file
......@@ -26,12 +26,12 @@
TRUE if success, FALSE if failed
*/
#include "\ApmsDB\constants.hpp"
params [["_clanUUID","",[""]],["_varName","",[""]],"_data"];
if(_clanUUID == "" || _varName == "" || isNil "_data") exitWith {false}; // UKNOWN PARAMS
private _variables = [_clanUUID,"variables"] call DB_fnc_getClanData;
if(isNil "_variables") exitWith {false}; // ERROR
......
......@@ -145,37 +145,48 @@ class CfgFunctions
class deleteClan {};
class setClanVariable {};
class getClanVariable {};
class getClanVariable {isGlobal = 1;};
class updateClanName {};
class updateClanOwner {};
class getClanData {};
class getClanData {isGlobal = 1;};
};
class Functions_Clans_Players
{
file = "ApmsDB\Functions\Clans\Objects";
class getClanObject {};
};
class Functions_Clans_Objects
{
file = "ApmsDB\Functions\Clans\Players";
class addClanPlayer {};
class removeClanPlayer {};
class updateClanPlayer {};
class isClanOwner {isGlobal = 1;};
class isClanMember {isGlobal = 1;};
};
class Functions_World {
file = "ApmsDB\Functions\World";
class getWorldUUID {};
class getLinkedWorlds {};
class getWorldVariable {};
class setWorldVariable {};
};
class Functions_Misc
{
file = "ApmsDB\Functions\Misc";
class createWorldDataObject {};
class getWorldData {};
class setWorldData {};
class whitelist {};
class unwhitelist {};
class getLinkedWorlds {};
class getWorldUUID {};
class hpFloatArray {};
class getServerTime {isGlobal = 1;};
class shutdown {};
class serverRequest {isGlobal = 1;};
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment