Commit 1b0b97bb authored by Razer's avatar Razer
Browse files

Updated Clan functions

parent f1d0afea
......@@ -48,7 +48,7 @@ if (_return isEqualType [] && {(_return select 0) isEqualTo "error"}) exitWith {
private _clanUUID = _return select 0;
// Return data to client
if(isRemoteExecuted && {remoteExecutedOwner != 2}) exitWith {
if(isRemoteExecuted && (_fnc_scriptName == _fnc_scriptNameParent) && remoteExecutedOwner != 2) exitWith {
[missionNamespace,[("DB_var_response_" + _fnc_scriptName),_clanUUID]] remoteExecCall ["setVariable",remoteExecutedOwner];
};
......
......@@ -40,9 +40,11 @@ if (_playerClan == "") exitWith {false};
private _targetClan = if (_targetParam isEqualType "") then {_targetParam} else {_targetParam getVariable ["clanUUID",""]};
if (_targetClan == "") exitWith {false};
private _result = (_playerClan == _targetClan);
// Return data to client
if(isRemoteExecuted && {remoteExecutedOwner != 2}) exitWith {
[missionNamespace,[("DB_var_response_" + _fnc_scriptName),((_clanData select 2) == _pUUID)]] remoteExecCall ["setVariable",remoteExecutedOwner];
if(isRemoteExecuted && (_fnc_scriptName == _fnc_scriptNameParent) && remoteExecutedOwner != 2) exitWith {
[missionNamespace,[("DB_var_response_" + _fnc_scriptName),_result]] remoteExecCall ["setVariable",remoteExecutedOwner];
};
(_playerClan == _targetClan);
\ No newline at end of file
_result
\ No newline at end of file
......@@ -63,7 +63,7 @@ if (isNil "_clanData") exitWith {false};
private _result = (_clanData select 2) == _pUUID;
// Return data to client
if(isRemoteExecuted && {remoteExecutedOwner != 2}) exitWith {
if(isRemoteExecuted && (_fnc_scriptName == _fnc_scriptNameParent) && remoteExecutedOwner != 2) exitWith {
[missionNamespace,[("DB_var_response_" + _fnc_scriptName),_result]] remoteExecCall ["setVariable",remoteExecutedOwner];
};
......
......@@ -10,10 +10,50 @@
*/
/*
DESCRIPTION:
This function is used to delete clan.
Players of this clan will be kicked and the clan will be "deleted"
WARNING:
Clan doesent actually get deleted. Only the name will be updated!
This is to keep ability to read old clans data in future.
PARAMS:
1 - STRING: Clan UUID
USAGE:
_success = [_clanUUID] call DB_fnc_deleteClan;
RETURNS:
TRUE if success FALSE if failed
*/
#include "\ApmsDB\constants.hpp"
params [["_clanUUID","",[""]]];
if (_clanUUID == "") exitWith {false};
// Run events before the clan is actually deleted
["DB_onClanDeleted",[_clanUUID]] call BASE_fnc_addEventHandler;
// Kick all players
private _members = [_clanUUID,"members"] call DB_fnc_getClanData;
if !(_members isEqualTo []) then {
_members apply {
[_x select 0,_clanUUID] call DB_fnc_removeClanPlayer;
};
};
// How is this used?
// Rename clan and mark as "deleted"
private _name = format ["DELETEDCLAN_%1",floor (random 999999)];
// Automatically remove all players from clan?
// This means pUUID.s have to be saved to clanList variable?
private _request = [PROTOCOL_DBCALL_FUNCTION_UPDATE_CLAN,[
PROTOCOL_DBCALL_ARGUMENT_CLAN_UUID,_clanUUID,
PROTOCOL_DBCALL_ARGUMENT_CLANNAME,_name
]];
private _return = [_request] call DB_fnc_sendRequest;
if(_return isEqualType [] && {(_return select 0) isEqualTo "error"}) exitWith {false};
["DB_onClanDeleted",[_clanUUID,_pUUID]] spawn BASE_fnc_addEventHandler;
\ No newline at end of file
true
\ No newline at end of file
......@@ -64,7 +64,7 @@ if (_option != "" && _option != "all") then {
};
// Return data to client
if(isRemoteExecuted && {remoteExecutedOwner != 2}) exitWith {
if(isRemoteExecuted && (_fnc_scriptName == _fnc_scriptNameParent) && remoteExecutedOwner != 2) exitWith {
[missionNamespace,[("DB_var_response_" + _fnc_scriptName),_return]] remoteExecCall ["setVariable",remoteExecutedOwner];
};
......
......@@ -43,7 +43,7 @@ private _varIndex = _variables findIf {_x select 0 == _varName};
private _return = [(_variables select _varIndex) select 1,_default] select (_varIndex == -1);
// Return data to client
if(isRemoteExecuted && {remoteExecutedOwner != 2}) exitWith {
if(isRemoteExecuted && (_fnc_scriptName == _fnc_scriptNameParent) && remoteExecutedOwner != 2) exitWith {
[missionNamespace,[("DB_var_response_" + _fnc_scriptName),_return]] remoteExecCall ["setVariable",remoteExecutedOwner];
};
......
......@@ -32,7 +32,7 @@ private _request = [PROTOCOL_DTCALL_FUNCTION_GET_DATE_TIME_Array,[]];
private _return = [_request] call DB_fnc_sendRequest;
// Return data to client
if(isRemoteExecuted && {remoteExecutedOwner != 2}) exitWith {
if(isRemoteExecuted && (_fnc_scriptName == _fnc_scriptNameParent) && remoteExecutedOwner != 2) exitWith {
[missionNamespace,[("DB_var_response_" + _fnc_scriptName),_return]] remoteExecCall ["setVariable",remoteExecutedOwner];
};
......
......@@ -14,6 +14,11 @@ if(isNil _fnc_scriptNameParent || {_fnc_scriptNameParent == _fnc_scriptName}) ex
if(isServer) exitWith {_this call (missionNamespace getVariable [_fnc_scriptNameParent,{diag_log format ["<ApmsDB>: ERROR: Function: %1, not found!",_fnc_scriptNameParent]}])};
private _responseVarName = "DB_var_response_" + _fnc_scriptNameParent;
// Remove variable for security
missionNamespace setVariable [_responseVarName,nil];
// Server request
_this remoteExec [_fnc_scriptNameParent,2];
......@@ -21,10 +26,10 @@ private _timeout = 3; // 3 = default
_timeout = diag_tickTime + _timeout;
// Wait for server response
waitUntil {!(isNil {missionNamespace getVariable ("DB_var_response_" + _fnc_scriptNameParent)}) || diag_tickTime > _timeout};
waitUntil {!(isNil _responseVarName) || diag_tickTime > _timeout};
if (diag_tickTime > _timeout) exitWith {};
private _return = missionNamespace getVariable ("DB_var_response_" + _fnc_scriptNameParent);
missionNamespace setVariable [("DB_var_response_" + _fnc_scriptNameParent),nil];
private _return = missionNamespace getVariable _responseVarName;
missionNamespace setVariable [_responseVarName,nil];
_return
\ No newline at end of file
......@@ -50,7 +50,7 @@ while{_doswitchloop} do {
if(_response != PROTOCOL_MESSAGE_NOT_EXISTING) exitWith {};
if (canSuspend) then {
uiSleep 0.1;
uiSleep 0.01;
} else {
diag_log "<ApmsDB>: WARNING: Cannot sleep in context of";
diag_log _originalrequest;
......
......@@ -8,7 +8,7 @@ while{true} do {
if(!isPlayer _x && alive _x) then {
if(!(_x getVariable ["agroed",false])) then {
if([_x] call DSZ_fnc_zombieCanSmell || {{[_x] call DSZ_fnc_zombieCanSee} || {[_x] call DSZ_fnc_zombieCanHear}}) then {
if([_x] call DSZ_fnc_zombieCanSmell || {[_x] call DSZ_fnc_zombieCanSee || {[_x] call DSZ_fnc_zombieCanHear}}) then {
[_x] call DSZ_fnc_agroZombie;
};
};
......
// TODO Hide right page data unless player is selected
// TODO Update player list onkick / setrank
// TODO UPDATE LBDATA ON DATA CHANGE (kick, prmote/demote, change comment)
// TODO FIX: CANNOT DEMOTE
// TODO Onwer cannot change owner
// DS_fnc_RscDisplayDSRJournalClan = {};
params ["_mode","_params","_class"];
......@@ -9,19 +12,13 @@ switch _mode do {
_this spawn {
params ["_mode","_params","_class"];
_params params ["_display"];
// Get control classes
_titleClan = _display getVariable "TitleClan";
_TextClanPlayers = _display getVariable "TextClanPlayers";
_textClanPlayers = _display getVariable "TextClanPlayers";
_listPlayers = _display getVariable "ListPlayers";
// TODO ADD COMMANDS BASED ON RANK (DEFINE RANKS)
_textUserInfo = _display getVariable "TextUserInfo";
_textRank = _display getVariable "TextRank";
_comboRank = _display getVariable "ComboRank";
_textComment = _display getVariable "TextComment";
_editComment = _display getVariable "EditComment";
_buttonLeave = _display getVariable "ButtonLeave";
_buttonSetRank = _display getVariable "ButtonSetRank";
_buttonSaveComment = _display getVariable "ButtonSaveComment";
_buttonKick = _display getVariable "ButtonKick";
......@@ -29,6 +26,20 @@ switch _mode do {
_clanUUID = player getVariable ["clanUUID",""];
if (_clanUUID == "") exitWith {_display closeDisplay 1};
//--- Add arrow events
_leftArrowCtrl = _display getVariable "arrowLeft";
_rightArrowCtrl = _display getVariable "arrowRight";
_leftArrowCtrl ctrlSetText "Exit";
_rightArrowCtrl ctrlSetText "Notes";
// REMOVE EVERYTHING - RESTORE ON LOAD
_titleClan ctrlSetStructuredText parseText format ["<t align='center' size='1.2'>LOADING DATA...</t>"];
_buttonLeave ctrlEnable false;
_buttonSetRank ctrlEnable false;
_buttonSaveComment ctrlEnable false;
_comboRank ctrlEnable false;
_buttonKick ctrlEnable false;
// [name, owners uuid, owners steamid, owners lastnick, [members],[variables]]
// [[player uuid, steamid, lastnick, rank, comment], [player uuid, steamid, lastnick, rank, comment]]
_clanData = [_clanUUID] call DB_fnc_getClanData;
......@@ -39,17 +50,8 @@ switch _mode do {
_playerRank = (_clanMembers select (_clanMembers findIf {_x select 0 == _pUUID})) select 3;
_display setVariable ["PlayerRank",_playerRank];
// Remove Buttons from normal players
if (_playerRank == 100) then {
_buttonSetRank ctrlEnable false;
_buttonSaveComment ctrlEnable false;
_comboRank ctrlEnable false;
};
_buttonKick ctrlEnable false;
_getStatusColor = {
params ["_memberUUID"];
private _isOnline = ((allPlayers findIf {_x getVariable ["pUUID",""] == _memberUUID}) != -1);
if (_isOnline) then {
// Online
......@@ -60,10 +62,8 @@ switch _mode do {
};
};
// Set clan name
_titleClan ctrlSetStructuredText parseText format ["<t align='center' size='1.2'>Clan: %1</t>",_clanName];
_editComment ctrlSetText ""; // Restore on player select
// Add members to list (sort by rank?)
for "_i" from 0 to (count _clanMembers) - 1 do {
......@@ -71,23 +71,62 @@ switch _mode do {
_index = _listPlayers lbAdd _memberName;
_listPlayers lbSetColor [_index,[_memberUUID] call _getStatusColor];
_listPlayers lbSetData [_index,str(_clanMembers select _i)];
_listPlayers lbSetSelected [0,true]; // Select first row (owner)
};
_textClanPlayers ctrlSetText "Clan players:";
_buttonLeave ctrlSetText "-> LEAVE";
_buttonLeave ctrlEnable true;
// EVENTS
// Add event to update selected target player
_listPlayers ctrlAddEventHandler ["LBSelChanged",{
params ["_control","_selectedIndex"];
if (_selectedIndex == -1) exitWith {};
_display = ctrlParent _control;
// Get control classes
_textUserInfo = _display getVariable "TextUserInfo";
_textRank = _display getVariable "TextRank";
_comboRank = _display getVariable "ComboRank";
_textComment = _display getVariable "TextComment";
_editComment = _display getVariable "EditComment";
_buttonSetRank = _display getVariable "ButtonSetRank";
_buttonSaveComment = _display getVariable "ButtonSaveComment";
_buttonKick = _display getVariable "ButtonKick";
_playerRank = _display getVariable "playerRank";
// RESTORE UI
_editComment = _display getVariable "EditComment";
if (_playerRank < 100) then {
_buttonSaveComment ctrlEnable true;
_buttonKick ctrlEnable true;
_buttonKick ctrlSetText "-> KICK";
_comboRank ctrlEnable true;
_buttonSetRank ctrlEnable true;
_buttonSetRank ctrlSetText "-> Set rank";
_buttonSaveComment ctrlSetText "\a3\3den\data\displays\display3den\toolbar\save_ca.paa";
// Change comment to editable
_editComment ctrlShow false;
_editComment = _display getVariable "EditOwnComment";
_editComment ctrlShow true;
};
_textUserInfo ctrlSetText "User info:";
_textRank ctrlSetText "Rank:";
_textComment ctrlSetText "Comment:";
_memberData = parseSimpleArray(_control lbData _selectedIndex);
_memberData params ["_memberUUID","_memberSteamID","_memberName","_memberRank","_memberComment"];
diag_log str(_memberData);
_playerRank = _display getVariable "playerRank";
_editComment ctrlSetText _memberComment;
_pUUID = player getVariable ["pUUID",""];
// Add ability to kick
......@@ -114,7 +153,7 @@ switch _mode do {
// Add ability to change owner for owner
_rankIndexOwner = _ranks findIf {_x select 1 == 0};
if (_playerRank == 0 && _rankIndexOwner != -1) then {
_comboRank lbAdd ((_ranks select _rankIndex) select 0);
_comboRank lbAdd ((_ranks select _rankIndexOwner) select 0);
};
if (_rankIndexOwner != -1) then {_ranks deleteAt _rankIndexOwner};
......@@ -126,10 +165,6 @@ switch _mode do {
// Select current
_display setVariable ["TargetMemberData",_memberData];
// Update comment
_editComment = _display getVariable "EditComment";
_editComment ctrlSetText _memberComment;
}];
//--- Add button events
// Kick
......@@ -145,16 +180,9 @@ switch _mode do {
["setrank",_this] spawn DS_fnc_RscDisplayDSRJournalClan;
}];
// Leave
_buttonLeave = _display getVariable "ButtonLeave";
_buttonLeave ctrlAddEventHandler ["ButtonClick",{
["leave",_this] spawn DS_fnc_RscDisplayDSRJournalClan;
}];
//--- Add arrow events
_leftArrowCtrl = _display getVariable "arrowLeft";
_rightArrowCtrl = _display getVariable "arrowRight";
_leftArrowCtrl ctrlSetText "Exit";
_rightArrowCtrl ctrlSetText "Notes";
_rightArrowCtrl ctrlAddEventHandler ["ButtonClick",{
["nextpage",_this] spawn DS_fnc_RscDisplayDSRJournalClan;
}];
......@@ -164,9 +192,9 @@ switch _mode do {
};
};
case "kick":{
// TODO Update listPlayers
_params params ["_buttonKick"];
_display = ctrlParent _buttonKick;
_listPlayers = _display getVariable "ListPlayers";
_selectedPlayer = _display getVariable ["TargetMemberData",[]];
if (_selectedPlayer isEqualTo []) exitWith {};
......@@ -183,13 +211,26 @@ switch _mode do {
};
case "leave":{
_params params ["_buttonLeave"];
_display = ctrlParent _buttonLeave;
// TODO If clan owner, change owner?
if ([player] call DB_fnc_isClanOwner) exitWith {
systemChat "Change clan owner first!";
_listPlayers = _display getVariable "ListPlayers";
if ((_listPlayers lbText 1) == "") then {
// DELETE CLAN
_confirm = ["This will delete the clan, are you sure?","Confirm clan deletion",true,true] call BIS_fnc_guiMessage;
if (_confirm) then {
_clanUUID = player getVariable ["clanUUID",""];
[_clanUUID] remoteExec ["DB_fnc_deleteClan",2];
systemChat "Clan deleted!";
_display closeDisplay 1;
};
} else {
systemChat "Change clan owner first!";
};
};
_display = ctrlParent _buttonLeave;
_confirm = ["Are you sure?","Confirm leave",true,true] call BIS_fnc_guiMessage;
if (_confirm) then {
// TODO get success
......@@ -212,27 +253,34 @@ switch _mode do {
_ranks = [["Owner",0],["Admin",10],["Member",100]]; // TODO DEFINE SOMEWHERE ELSE
_targetRank = (_ranks select _currentSelected) select 1;
if (player getVariable ["pUUID",""] == _memberUUID) exitWith {
systemChat "You cannot change your own rank";
};
if (_targetRank != _memberRank) then {
// Ask from owner if that realy wants to change owner of clan
_confirm = if (_targetRank == 0) then {
_confirm = [format ["Are you sure you want to change clan owner? (%1)",_memberName],"Confirm owner change",true,true] call BIS_fnc_guiMessage;
if (_confirm) then {
// Change owners rank to admin
[[(player getVariable ["pUUID",""]),_clanUUID],10] remoteExec ["DB_fnc_updateClanPlayer",2];
};
} else {
true
};
if !(_confirm) exitWith {};
_clanUUID = player getVariable ["clanUUID",""];
// [[_memberUUID,_clanUUID],_targetRank] remoteExec ["DB_fnc_updateClanPlayer",2];
[[_memberUUID,_clanUUID],_targetRank] remoteExec ["DB_fnc_updateClanPlayer",2];
systemChat "Rank updated";
systemChat str(_targetRank);
};
};
case "savecomment":{
// DONE + tested
_params params ["_buttonSaveComment"];
_display = ctrlParent _buttonSaveComment;
_editComment = _display getVariable "EditComment";
_editComment = _display getVariable "EditOwnComment";
_currentText = ctrlText _editComment;
_selectedPlayer = _display getVariable ["TargetMemberData",[]];
......
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