/*
Bryan
Exile Server Manager
Fires from a request from the website. Fired when we want to add or kick a player
*/
_option = _this select 0;
_flagID = parseNumber(_this select 1);
_playerUID = _this select 2;
_playerToBeProcessedUID = _this select 3;
try
{
_flagObject = _flagID call ExileServerManager_util_getFlagObject;
if (isNull _flagObject) then
{
throw format["Could not find territory flag for %1", _flagID];
};
_territoryID = _flagObject getVariable ["ExileDatabaseID", -1];
// If some stranger fucked something up, he will see that message:
if (_territoryID isEqualTo -1) then
{
throw "Territory has no database ID.";
};
// get the owners uid
_ownerUID = _flagObject getVariable ["ExileOwnerUID", ""];
// Kick or add?
if (_option isEqualTo "kick") then
{
if (_playerToBeProcessedUID isEqualTo _ownerUID) then
{
throw "Owners cannot leave territories.";
};
_moderators = _flagObject getVariable ["ExileTerritoryModerators", []];
_buildRights = _flagObject getVariable ["ExileTerritoryBuildRights", []];
// Leave always works
if (_playerToBeProcessedUID isEqualTo _playerUID) then
{
throw "Cannot kick yourself";
};
if !(_playerUID in _moderators) then
{
throw "Only moderators can kick.";
};
_moderators = _moderators - [_playerToBeProcessedUID];
_buildRights = _buildRights - [_playerToBeProcessedUID];
// Update the build rights in the flag pole
_flagObject setVariable ["ExileTerritoryModerators", _moderators, true];
_flagObject setVariable ["ExileTerritoryBuildRights", _buildRights, true];
// Update the build rights / Moderators in the database (NOW!)
format["updateTerritoryBuildRights:%1:%2", _buildRights, _territoryID] call ExileServer_system_database_query_fireAndForget;
format["updateTerritoryModerators:%1:%2", _moderators, _territoryID] call ExileServer_system_database_query_fireAndForget;
if (ESM_DebugEnabled) then
{
format["%1 kicked %2 from %3", _playerUID, _playerToBeProcessedUID, _territoryID] call ExileServerManager_util_log;
};
}
else
{
// One cannot add herself/himself
if (_playerUID isEqualTo _playerToBeProcessedUID) then
{
throw "Trying to add yourself, huh?";
};
// If the guy we wants to add is the owner, skip here since he has already uber rights
if (_ownerUID isEqualTo _playerToBeProcessedUID) then
{
throw "The owner of this territory, you dont need build rights.";
};
// Get the current rights
_currentBuildRights = _flagObject getVariable ["ExileTerritoryBuildRights", []];
// Do not add em twice to the build rights
if (_playerToBeProcessedUID in _currentBuildRights) then
{
throw "This player already has build rights.";
};
// Everything seems to be okay. Lets find out the territory ID
_territoryID = _flagObject getVariable ["ExileDatabaseID", -1];
_territoryName = _flagObject getVariable ["ExileTerritoryName", ""];
// If some stranger fucked something up, he will see that message:
if (_territoryID isEqualTo -1) then
{
throw "Territory has no database ID.";
};
// Add the build rights to the flag pole
_currentBuildRights pushBack _playerToBeProcessedUID;
// Update the build rights in the flag pole
_flagObject setVariable ["ExileTerritoryBuildRights", _currentBuildRights, true];
// Update the build rights in the database (NOW!)
format["updateTerritoryBuildRights:%1:%2", _currentBuildRights, _territoryID] call ExileServer_system_database_query_fireAndForget;
if (ESM_DebugEnabled) then
{
format["%1 added %2 to %3", _playerUID, _playerToBeProcessedUID, _territoryID] call ExileServerManager_util_log;
};
};
}
catch
{
// Send a whoops message to the sender
//[_sessionID, "toastRequest", ["ErrorTitleAndText", ["Failed to remove!", _exception]]] call ExileServer_system_network_send_to;
// Log the error message in the database so we know whats up
_exception call ExileServerManager_util_log;
};
true