diff --git a/ajax/galaxyfleet.php b/ajax/galaxyfleet.php index 69e235cfe..ee1589216 100644 --- a/ajax/galaxyfleet.php +++ b/ajax/galaxyfleet.php @@ -290,110 +290,73 @@ function CreateReturn($ReturnCode) } } -// Fleet Blockade System -$BlockFleet = false; -$SFBSelectWhere[] = "(`Type` = 1 AND (`EndTime` > UNIX_TIMESTAMP() OR `PostEndTime` > UNIX_TIMESTAMP()))"; -if($Mission == 6) -{ - if($TargetUser > 0) - { - $SFBSelectWhere[] = "(`Type` = 2 AND `ElementID` = {$TargetUser} AND `EndTime` > UNIX_TIMESTAMP())"; - } - $SFBSelectWhere[] = "(`Type` = 3 AND `ElementID` = {$TargetID} AND `EndTime` > UNIX_TIMESTAMP())"; -} -$SFBSelectWhere[] = "(`Type` = 2 AND `ElementID` = {$_User['id']} AND `EndTime` > UNIX_TIMESTAMP())"; -$SFBSelectWhere[] = "(`Type` = 3 AND `ElementID` = {$CurrentPlanet['id']} AND `EndTime` > UNIX_TIMESTAMP())"; +$smartFleetsBlockadeStateValidationResult = FlightControl\Utils\Validators\validateSmartFleetsBlockadeState([ + 'timestamp' => $Time, + 'fleetData' => [ + 'Mission' => $Mission, + ], + 'fleetOwnerDetails' => [ + 'userId' => $_User['id'], + 'planetId' => $CurrentPlanet['id'], + ], + 'targetOwnerDetails' => ( + $TargetUser > 0 ? + [ + 'userId' => $TargetUser, + 'planetId' => $TargetID, + 'onlinetime' => $HeDBRec['onlinetime'], + ] : + null + ), + 'settings' => [ + 'idleTime' => $Protections['idleTime'], + ], +]); -$SFBSelect = ''; -$SFBSelect .= "SELECT `Type`, `BlockMissions`, `Reason`, `StartTime`, `EndTime`, `PostEndTime`, `ElementID`, `DontBlockIfIdle` FROM {{table}} WHERE `StartTime` <= UNIX_TIMESTAMP() AND "; -$SFBSelect .= implode(' OR ', $SFBSelectWhere); -$SFBSelect .= " ORDER BY `Type` ASC, `EndTime` DESC;"; +if (!$smartFleetsBlockadeStateValidationResult['isValid']) { + $firstValidationError = $smartFleetsBlockadeStateValidationResult['errors']; -$SQLResult_SmartFleetBlockadeData = doquery($SFBSelect, 'smart_fleet_blockade'); + $errorMessage = null; + switch ($firstValidationError['blockType']) { + case 'GLOBAL_ENDTIME': + CreateReturn('628'); -if($SQLResult_SmartFleetBlockadeData->num_rows > 0) -{ - while($GetSFBData = $SQLResult_SmartFleetBlockadeData->fetch_assoc()) - { - $BlockedMissions = false; - if($GetSFBData['BlockMissions'] == '0') - { - $BlockedMissions = true; - $AllMissionsBlocked = true; - } - else - { - $BlockedMissions = explode(',', $GetSFBData['BlockMissions']); - } + break; + case 'GLOBAL_POSTENDTIME': + CreateReturn('635'); - if($BlockedMissions === true OR in_array($Mission, $BlockedMissions)) - { - if($GetSFBData['Type'] == 1) - { - // Global Blockade - if($GetSFBData['EndTime'] > $Time) - { - // Normal Blockade - if(!($GetSFBData['DontBlockIfIdle'] == 1 AND in_array($Mission, $_Vars_FleetMissions['military']) AND $TargetUser > 0 AND $HeDBRec['onlinetime'] <= ($Time - $Protections['idleTime']))) - { - CreateReturn('628'); - } - } - else if($GetSFBData['PostEndTime'] > $Time) - { - // Post Blockade - if(in_array($Mission, $_Vars_FleetMissions['military']) AND $TargetUser > 0 AND - ( - ($AllMissionsBlocked !== true AND $HeDBRec['onlinetime'] > ($Time - $Protections['idleTime']) AND $HeDBRec['onlinetime'] < $GetSFBData['StartTime']) - OR - ($AllMissionsBlocked === true AND $HeDBRec['onlinetime'] > ($Time - $Protections['idleTime']) AND $HeDBRec['onlinetime'] < $GetSFBData['EndTime']) - )) - { - CreateReturn('635'); - } - } - } - else if($GetSFBData['Type'] == 2) - { - // Per User Blockade - if($GetSFBData['ElementID'] == $_User['id']) - { - CreateReturn('636'); - } - else - { - CreateReturn('637'); - } + break; + case 'USER': + $errorDetails = $firstValidationError['details']; + + if ($errorDetails['userId'] == $_User['id']) { + CreateReturn('636'); } - else if($GetSFBData['Type'] == 3) - { - // Per Planet Blockade - if($GetSFBData['ElementID'] == $CurrentPlanet['id']) - { - // SFB per Planet (your) is Active - if($CurrentPlanet['planet_type'] == 1) - { - CreateReturn('638'); - } - else - { - CreateReturn('639'); - } - } - else - { - // SFB per Planet (target) is Active - if($TargetPlanetType == 1) - { - CreateReturn('640'); - } - else - { - CreateReturn('641'); - } - } + + CreateReturn('637'); + + break; + case 'PLANET': + $errorDetails = $firstValidationError['details']; + + if ($errorDetails['planetId'] == $CurrentPlanet['id']) { + CreateReturn( + ($CurrentPlanet['planet_type'] == 1) ? + '638' : + '639' + ); } - } + + CreateReturn( + ($TargetPlanetType == 1) ? + '640' : + '641' + ); + + break; + default: + CreateReturn('694'); + break; } } diff --git a/ajax/sendmissiles.php b/ajax/sendmissiles.php index aa73813dd..81bd282cd 100644 --- a/ajax/sendmissiles.php +++ b/ajax/sendmissiles.php @@ -219,96 +219,31 @@ function CreateReturn($ReturnCode, $Update = '0') } } -// Fleet Blockade System -$SFBSelectWhere[] = "(`Type` = 1 AND (`EndTime` > UNIX_TIMESTAMP() OR `PostEndTime` > UNIX_TIMESTAMP()))"; -if($PlanetData['id_owner'] > 0) -{ - $SFBSelectWhere[] = "(`Type` = 2 AND `ElementID` = {$PlanetData['id_owner']} AND `EndTime` > UNIX_TIMESTAMP())"; -} -$SFBSelectWhere[] = "(`Type` = 3 AND `ElementID` = {$PlanetData['id']} AND `EndTime` > UNIX_TIMESTAMP())"; -$SFBSelectWhere[] = "(`Type` = 2 AND `ElementID` = {$_User['id']} AND `EndTime` > UNIX_TIMESTAMP())"; -$SFBSelectWhere[] = "(`Type` = 3 AND `ElementID` = {$_Planet['id']} AND `EndTime` > UNIX_TIMESTAMP())"; - -$SFBSelect = ''; -$SFBSelect .= "SELECT `Type`, `BlockMissions`, `Reason`, `StartTime`, `EndTime`, `PostEndTime`, `ElementID`, `DontBlockIfIdle` FROM {{table}} WHERE `StartTime` <= UNIX_TIMESTAMP() AND "; -$SFBSelect .= implode(' OR ', $SFBSelectWhere); -$SFBSelect .= " ORDER BY `Type` ASC, `EndTime` DESC;"; - -$SQLResult_GetSmartFleetBlockadeData = doquery($SFBSelect, 'smart_fleet_blockade'); - -if($SQLResult_GetSmartFleetBlockadeData->num_rows > 0) -{ - while($GetSFBData = $SQLResult_GetSmartFleetBlockadeData->fetch_assoc()) - { - $BlockedMissions = false; - if($GetSFBData['BlockMissions'] == '0') - { - $BlockedMissions = true; - $AllMissionsBlocked = true; - } - else - { - $BlockedMissions = explode(',', $GetSFBData['BlockMissions']); - } - - if($BlockedMissions === true OR in_array($Mission, $BlockedMissions)) - { - if($GetSFBData['Type'] == 1) - { - // Global Blockade - if($GetSFBData['EndTime'] > $Now) - { - // Normal Blockade - if(!($GetSFBData['DontBlockIfIdle'] == 1 AND in_array($Mission, $_Vars_FleetMissions['military']) AND $PlanetData['id_owner'] > 0 AND $HeDBRec['onlinetime'] <= ($Now - $Protections['idleTime']))) - { - $BlockFleet = true; - $BlockReason = $_Lang['SFB_Stop_GlobalBlockade']; - } - } - else if($GetSFBData['PostEndTime'] > $Now) - { - // Post Blockade - if(in_array($Mission, $_Vars_FleetMissions['military']) AND $PlanetData['id_owner'] > 0 AND - ( - ($AllMissionsBlocked !== true AND $HeDBRec['onlinetime'] > ($Now - $Protections['idleTime']) AND $HeDBRec['onlinetime'] < $GetSFBData['StartTime']) - OR - ($AllMissionsBlocked === true AND $HeDBRec['onlinetime'] > ($Now - $Protections['idleTime']) AND $HeDBRec['onlinetime'] < $GetSFBData['EndTime']) - )) - { - $BlockFleet = true; - $BlockReason = sprintf($_Lang['SFB_Stop_GlobalPostBlockade'], prettyDate('d m Y, H:i:s', $GetSFBData['PostEndTime'], 1)); - } - } - } - else if($GetSFBData['Type'] == 2) - { - // Per User Blockade - $BlockFleet = true; - $BlockGivenReason = (empty($GetSFBData['Reason']) ? $_Lang['SFB_Stop_ReasonNotGiven'] : "\"{$GetSFBData['Reason']}\""); - $BlockReason = sprintf(($GetSFBData['ElementID'] == $_User['id'] ? $_Lang['SFB_Stop_UserBlockadeOwn'] : $_Lang['SFB_Stop_UserBlockade']), prettyDate('d m Y', $GetSFBData['EndTime'], 1), date('H:i:s', $GetSFBData['EndTime']), $BlockGivenReason); - } - else if($GetSFBData['Type'] == 3) - { - // Per Planet Blockade - $BlockFleet = true; - $BlockGivenReason = (empty($GetSFBData['Reason']) ? $_Lang['SFB_Stop_ReasonNotGiven'] : "\"{$GetSFBData['Reason']}\""); - if($GetSFBData['ElementID'] == $_Planet['id']) - { - $UseLangVar = ($_Planet['planet_type'] == 1 ? $_Lang['SFB_Stop_PlanetBlockadeOwn_Planet'] : $_Lang['SFB_Stop_PlanetBlockadeOwn_Moon']); - } - else - { - $UseLangVar = ($Type == 1 ? $_Lang['SFB_Stop_PlanetBlockade_Planet'] : $_Lang['SFB_Stop_PlanetBlockade_Moon']); - } - $BlockReason = sprintf($UseLangVar, prettyDate('d m Y', $GetSFBData['EndTime'], 1), date('H:i:s', $GetSFBData['EndTime']), $BlockGivenReason); - } - } +$smartFleetsBlockadeStateValidationResult = FlightControl\Utils\Validators\validateSmartFleetsBlockadeState([ + 'timestamp' => $Now, + 'fleetData' => [ + 'Mission' => $Mission, + ], + 'fleetOwnerDetails' => [ + 'userId' => $_User['id'], + 'planetId' => $_Planet['id'], + ], + 'targetOwnerDetails' => ( + $PlanetData['id_owner'] > 0 ? + [ + 'userId' => $PlanetData['id_owner'], + 'planetId' => $PlanetData['id'], + 'onlinetime' => $HeDBRec['onlinetime'], + ] : + null + ), + 'settings' => [ + 'idleTime' => $Protections['idleTime'], + ], +]); - if($BlockFleet === true) - { - CreateReturn('626'); - } - } +if (!$smartFleetsBlockadeStateValidationResult['isValid']) { + CreateReturn('626'); } $CreateMIPAttack = ''; diff --git a/fleet3.php b/fleet3.php index bf3cd23a8..cfa275da5 100644 --- a/fleet3.php +++ b/fleet3.php @@ -241,96 +241,95 @@ function messageRed($Text, $Title) $CheckDebrisField = doquery("SELECT `galaxy_id`, `metal`, `crystal` FROM {{table}} WHERE galaxy = '{$Target['galaxy']}' AND system = '{$Target['system']}' AND planet = '{$Target['planet']}'", 'galaxy', true); } -// Fleet Blockade System -$SFBSelectWhere[] = "(`Type` = 1 AND (`EndTime` > UNIX_TIMESTAMP() OR `PostEndTime` > UNIX_TIMESTAMP()))"; -if($CheckPlanetOwner['owner'] > 0) -{ - $SFBSelectWhere[] = "(`Type` = 2 AND `ElementID` = {$CheckPlanetOwner['owner']} AND `EndTime` > UNIX_TIMESTAMP())"; - $SFBSelectWhere[] = "(`Type` = 3 AND `ElementID` = {$CheckPlanetOwner['id']} AND `EndTime` > UNIX_TIMESTAMP())"; -} -$SFBSelectWhere[] = "(`Type` = 2 AND `ElementID` = {$_User['id']} AND `EndTime` > UNIX_TIMESTAMP())"; -$SFBSelectWhere[] = "(`Type` = 3 AND `ElementID` = {$_Planet['id']} AND `EndTime` > UNIX_TIMESTAMP())"; - -$SFBSelect = ''; -$SFBSelect .= "SELECT `Type`, `BlockMissions`, `Reason`, `StartTime`, `EndTime`, `PostEndTime`, `ElementID`, `DontBlockIfIdle` FROM {{table}} WHERE `StartTime` <= UNIX_TIMESTAMP() AND "; -$SFBSelect .= implode(' OR ', $SFBSelectWhere); -$SFBSelect .= " ORDER BY `Type` ASC, `EndTime` DESC;"; +$smartFleetsBlockadeStateValidationResult = FlightControl\Utils\Validators\validateSmartFleetsBlockadeState([ + 'timestamp' => $Now, + 'fleetData' => $Fleet, + 'fleetOwnerDetails' => [ + 'userId' => $_User['id'], + 'planetId' => $_Planet['id'], + ], + 'targetOwnerDetails' => ( + $CheckPlanetOwner['owner'] > 0 ? + [ + 'userId' => $CheckPlanetOwner['owner'], + 'planetId' => $CheckPlanetOwner['id'], + 'onlinetime' => $CheckPlanetOwner['onlinetime'], + ] : + null + ), + 'settings' => [ + 'idleTime' => $Protections['idleTime'] + ], +]); -$SQLResult_GetSmartFleetBlockadeData = doquery($SFBSelect, 'smart_fleet_blockade'); +if (!$smartFleetsBlockadeStateValidationResult['isValid']) { + $firstValidationError = $smartFleetsBlockadeStateValidationResult['errors']; -if($SQLResult_GetSmartFleetBlockadeData->num_rows > 0) -{ - while($GetSFBData = $SQLResult_GetSmartFleetBlockadeData->fetch_assoc()) - { - $BlockedMissions = false; - if($GetSFBData['BlockMissions'] == '0') - { - $BlockedMissions = true; - $AllMissionsBlocked = true; - } - else - { - $BlockedMissions = explode(',', $GetSFBData['BlockMissions']); - } + $errorMessage = null; + switch ($firstValidationError['blockType']) { + case 'GLOBAL_ENDTIME': + $errorMessage = $_Lang['SFB_Stop_GlobalBlockade']; + break; + case 'GLOBAL_POSTENDTIME': + $errorMessage = sprintf( + $_Lang['SFB_Stop_GlobalPostBlockade'], + prettyDate('d m Y, H:i:s', $firstValidationError['details']['hardEndTime'], 1) + ); + break; + case 'USER': + $errorDetails = $firstValidationError['details']; + $reasonMessage = ( + empty($errorDetails['reason']) ? + $_Lang['SFB_Stop_ReasonNotGiven'] : + "\"{$errorDetails['reason']}\"" + ); + + $errorMessage = sprintf( + ($errorDetails['userId'] == $_User['id'] ? $_Lang['SFB_Stop_UserBlockadeOwn'] : $_Lang['SFB_Stop_UserBlockade']), + prettyDate('d m Y', $errorDetails['endTime'], 1), + date('H:i:s', $errorDetails['endTime']), + $reasonMessage + ); - if($BlockedMissions === true OR in_array($Fleet['Mission'], $BlockedMissions)) - { - if($GetSFBData['Type'] == 1) - { - // Global Blockade - if($GetSFBData['EndTime'] > $Now) - { - // Normal Blockade - if(!($GetSFBData['DontBlockIfIdle'] == 1 AND in_array($Fleet['Mission'], $_Vars_FleetMissions['military']) AND $CheckPlanetOwner['owner'] > 0 AND $CheckPlanetOwner['onlinetime'] <= ($Now - $Protections['idleTime']))) - { - $BlockFleet = true; - $BlockReason = $_Lang['SFB_Stop_GlobalBlockade']; - } - } - elseif($GetSFBData['PostEndTime'] > $Now) - { - // Post Blockade - if(in_array($Fleet['Mission'], $_Vars_FleetMissions['military']) AND $CheckPlanetOwner['owner'] > 0 AND - ( - ($AllMissionsBlocked !== true AND $CheckPlanetOwner['onlinetime'] > ($Now - $Protections['idleTime']) AND $CheckPlanetOwner['onlinetime'] < $GetSFBData['StartTime']) - OR - ($AllMissionsBlocked === true AND $CheckPlanetOwner['onlinetime'] > ($Now - $Protections['idleTime']) AND $CheckPlanetOwner['onlinetime'] < $GetSFBData['EndTime']) - )) - { - $BlockFleet = true; - $BlockReason = sprintf($_Lang['SFB_Stop_GlobalPostBlockade'], prettyDate('d m Y, H:i:s', $GetSFBData['PostEndTime'], 1)); - } - } - } - elseif($GetSFBData['Type'] == 2) - { - // Per User Blockade - $BlockFleet = true; - $BlockGivenReason = (empty($GetSFBData['Reason']) ? $_Lang['SFB_Stop_ReasonNotGiven'] : "\"{$GetSFBData['Reason']}\""); - $BlockReason = sprintf(($GetSFBData['ElementID'] == $_User['id'] ? $_Lang['SFB_Stop_UserBlockadeOwn'] : $_Lang['SFB_Stop_UserBlockade']), prettyDate('d m Y', $GetSFBData['EndTime'], 1), date('H:i:s', $GetSFBData['EndTime']), $BlockGivenReason); - } - elseif($GetSFBData['Type'] == 3) - { - // Per Planet Blockade - $BlockFleet = true; - $BlockGivenReason = (empty($GetSFBData['Reason']) ? $_Lang['SFB_Stop_ReasonNotGiven'] : "\"{$GetSFBData['Reason']}\""); - if($GetSFBData['ElementID'] == $_Planet['id']) - { - $UseLangVar = ($_Planet['planet_type'] == 1 ? $_Lang['SFB_Stop_PlanetBlockadeOwn_Planet'] : $_Lang['SFB_Stop_PlanetBlockadeOwn_Moon']); - } - else - { - $UseLangVar = ($Target['type'] == 1 ? $_Lang['SFB_Stop_PlanetBlockade_Planet'] : $_Lang['SFB_Stop_PlanetBlockade_Moon']); - } - $BlockReason = sprintf($UseLangVar, prettyDate('d m Y', $GetSFBData['EndTime'], 1), date('H:i:s', $GetSFBData['EndTime']), $BlockGivenReason); - } - } + break; + case 'PLANET': + $errorDetails = $firstValidationError['details']; + $reasonMessage = ( + empty($errorDetails['reason']) ? + $_Lang['SFB_Stop_ReasonNotGiven'] : + "\"{$errorDetails['reason']}\"" + ); + $errorMessageTemplate = ( + $errorDetails['planetId'] == $_Planet['id'] ? + ( + $_Planet['planet_type'] == 1 ? + $_Lang['SFB_Stop_PlanetBlockadeOwn_Planet'] : + $_Lang['SFB_Stop_PlanetBlockadeOwn_Moon'] + ) : + ( + $Target['type'] == 1 ? + $_Lang['SFB_Stop_PlanetBlockade_Planet'] : + $_Lang['SFB_Stop_PlanetBlockade_Moon'] + ) + ); + + $errorMessage = sprintf( + $errorMessageTemplate, + prettyDate('d m Y', $errorDetails['endTime'], 1), + date('H:i:s', $errorDetails['endTime']), + $reasonMessage + ); - if($BlockFleet === true) - { - messageRed($BlockReason.$_Lang['SFB_Stop_LearnMore'], $_Lang['SFB_BoxTitle']); - } + break; + default: + $errorMessage = $_Lang['fleet_generic_errors_unknown']; + break; } + + messageRed( + $errorMessage . $_Lang['SFB_Stop_LearnMore'], + $_Lang['SFB_BoxTitle'] + ); } // --- Parse Fleet Array @@ -1120,18 +1119,6 @@ function messageRed($Text, $Title) $IPIntersectionNow = 'true'; } - $FiltersData['place'] = 1; - $FiltersData['alertsender'] = 1; - $FiltersData['users'] = array($_User['id'], $TargetData['owner']); - $FiltersData['ips'] = $CheckIntersection['Intersect']; - $FiltersData['sender'] = $_User['id']; - $FiltersData['target'] = $TargetData['owner']; - foreach($CheckIntersection['Intersect'] as $IP) - { - $FiltersData['logcount'][$IP][$_User['id']] = $CheckIntersection['IPLogData'][$_User['id']][$IP]['Count']; - $FiltersData['logcount'][$IP][$TargetData['owner']] = $CheckIntersection['IPLogData'][$TargetData['owner']][$IP]['Count']; - } - if($_User['multiIP_DeclarationID'] > 0 AND $_User['multiIP_DeclarationID'] == $TargetData['multiIP_DeclarationID']) { $Query_CheckDeclaration = ''; @@ -1146,7 +1133,13 @@ function messageRed($Text, $Title) $DeclarationID = 0; } - $FilterResult = AlertUtils_CheckFilters($FiltersData); + $alertFiltersSearchParams = FlightControl\Utils\Factories\createAlertFiltersSearchParams([ + 'fleetOwner' => &$_User, + 'targetOwner' => $TargetData, + 'ipsIntersectionsCheckResult' => $CheckIntersection, + ]); + $FilterResult = AlertUtils_CheckFilters($alertFiltersSearchParams); + if($FilterResult['FilterUsed']) { $IPIntersectionFiltred = 'true'; @@ -1245,15 +1238,19 @@ function messageRed($Text, $Title) } } } - if($_Alert['PushAlert']['HasResources'] === true) - { - $FiltersData = array(); - $FiltersData['place'] = 1; - $FiltersData['alertsender'] = 1; - $FiltersData['users'] = array($_User['id'], $TargetData['owner']); - $FiltersData['sender'] = $_User['id']; - $FiltersData['target'] = $TargetData['owner']; - $FilterResult = AlertUtils_CheckFilters($FiltersData, array('DontLoad' => true, 'DontLoad_OnlyIfCacheEmpty' => true)); + if ($_Alert['PushAlert']['HasResources'] === true) { + $alertFiltersSearchParams = FlightControl\Utils\Factories\createAlertFiltersSearchParams([ + 'fleetOwner' => &$_User, + 'targetOwner' => $TargetData, + 'ipsIntersectionsCheckResult' => null, + ]); + $FilterResult = AlertUtils_CheckFilters( + $alertFiltersSearchParams, + [ + 'DontLoad' => true, + 'DontLoad_OnlyIfCacheEmpty' => true, + ] + ); if($FilterResult['SendAlert']) { diff --git a/modules/flightControl/_includes.php b/modules/flightControl/_includes.php index 1e0809e8b..43d397038 100644 --- a/modules/flightControl/_includes.php +++ b/modules/flightControl/_includes.php @@ -6,7 +6,9 @@ $includePath = $_EnginePath . 'modules/flightControl/'; + include($includePath . './utils/factories/createAlertFiltersSearchParams.factory.php'); include($includePath . './utils/factories/createFleetDevLogEntry.factory.php'); + include($includePath . './utils/fetchers/fetchActiveSmartFleetsBlockadeEntries.fetcher.php'); include($includePath . './utils/fetchers/fetchPlanetOwnerDetails.fetcher.php'); include($includePath . './utils/helpers/getAvailableHoldTimes.helper.php'); include($includePath . './utils/helpers/getAvailableSpeeds.helper.php'); @@ -18,6 +20,7 @@ include($includePath . './utils/validators/fleetArray.validator.php'); include($includePath . './utils/validators/joinUnion.validator.php'); include($includePath . './utils/validators/missionHold.validator.php'); + include($includePath . './utils/validators/smartFleetsBlockadeState.validator.php'); }); diff --git a/modules/flightControl/utils/factories/createAlertFiltersSearchParams.factory.php b/modules/flightControl/utils/factories/createAlertFiltersSearchParams.factory.php new file mode 100644 index 000000000..0cf4b5627 --- /dev/null +++ b/modules/flightControl/utils/factories/createAlertFiltersSearchParams.factory.php @@ -0,0 +1,49 @@ + [], + 'IPLogData' => [], + ] + ); + + $intersectingIps = $ipsIntersectionsCheckResult['Intersect']; + $ipsLogData = $ipsIntersectionsCheckResult['IPLogData']; + + $searchParams = [ + 'place' => 1, + 'alertsender' => 1, + 'users' => [ + $fleetOwner['id'], + $targetOwner['owner'], + ], + 'sender' => $fleetOwner['id'], + 'target' => $targetOwner['owner'], + 'ips' => $intersectingIps, + 'logcount' => [], + ]; + + foreach ($intersectingIps as $intersectingIp) { + $searchParams['logcount'][$intersectingIp] = [ + $fleetOwner['id'] => $ipsLogData[$fleetOwner['id']][$intersectingIp]['Count'], + $targetOwner['owner'] => $ipsLogData[$targetOwner['owner']][$intersectingIp]['Count'], + ]; + } + + return $searchParams; +} + +?> diff --git a/modules/flightControl/utils/fetchers/fetchActiveSmartFleetsBlockadeEntries.fetcher.php b/modules/flightControl/utils/fetchers/fetchActiveSmartFleetsBlockadeEntries.fetcher.php new file mode 100644 index 000000000..6e4832676 --- /dev/null +++ b/modules/flightControl/utils/fetchers/fetchActiveSmartFleetsBlockadeEntries.fetcher.php @@ -0,0 +1,58 @@ + {$timestamp} OR `PostEndTime` > {$timestamp})) OR " . + "(`Type` = 2 AND `ElementID` IN ({$userIdsToCheckString}) AND `EndTime` > {$timestamp}) OR " . + "(`Type` = 3 AND `ElementID` IN ({$planetIdsToCheckString}) AND `EndTime` > {$timestamp}) " . + ") " . + "ORDER BY `Type` ASC, `EndTime` DESC " . + ";" + ); + + return doquery($query, 'smart_fleet_blockade'); +} + +?> diff --git a/modules/flightControl/utils/validators/smartFleetsBlockadeState.validator.php b/modules/flightControl/utils/validators/smartFleetsBlockadeState.validator.php new file mode 100644 index 000000000..041037859 --- /dev/null +++ b/modules/flightControl/utils/validators/smartFleetsBlockadeState.validator.php @@ -0,0 +1,150 @@ + true, + ]; + }; + $isInvalid = function ($errors) { + return [ + 'isValid' => false, + 'errors' => $errors, + ]; + }; + + $timestamp = $props['timestamp']; + $fleetData = $props['fleetData']; + $fleetMissionTypeId = $fleetData['Mission']; + $targetIsOccupied = !empty($props['targetOwnerDetails']); + $isTargetOwnerIdle = ( + $targetIsOccupied ? + $props['targetOwnerDetails']['onlinetime'] <= ($timestamp - $props['settings']['idleTime']) : + false + ); + + $blockadeEntries = FlightControl\Utils\Fetchers\fetchActiveSmartFleetsBlockadeEntries($props); + + if ($blockadeEntries->num_rows == 0) { + return $isValid(); + } + + while ($blockadeEntry = $blockadeEntries->fetch_assoc()) { + $isAllMissionsBlockade = $blockadeEntry['BlockMissions'] == '0'; + $blockedMissionTypeIds = ( + $isAllMissionsBlockade ? + [] : + explode(',', $blockadeEntry['BlockMissions']) + ); + + if ( + !$isAllMissionsBlockade && + !in_array($fleetMissionTypeId, $blockedMissionTypeIds) + ) { + continue; + } + + if ($blockadeEntry['Type'] == 1) { + // Check if blockade is still in effect + if ($blockadeEntry['EndTime'] > $timestamp) { + $isNotProtectedBecauseIdle = ( + $blockadeEntry['DontBlockIfIdle'] == 1 && + $targetIsOccupied && + in_array($fleetMissionTypeId, $_Vars_FleetMissions['military']) && + $isTargetOwnerIdle + ); + + if ($isNotProtectedBecauseIdle) { + continue; + } + + return $isInvalid([ + 'blockType' => 'GLOBAL_ENDTIME', + 'details' => [ + 'endTime' => $blockadeEntry['EndTime'], + ], + ]); + } + + // Check if post-blockade lock is still in effect + if ($blockadeEntry['PostEndTime'] > $timestamp) { + if (!$targetIsOccupied) { + continue; + } + if ($isTargetOwnerIdle) { + continue; + } + + $isMilitaryMission = in_array($fleetMissionTypeId, $_Vars_FleetMissions['military']); + + if (!$isMilitaryMission) { + continue; + } + + $wasOnlineAfterBlockadeStarted = ($props['targetOwnerDetails']['onlinetime'] >= $blockadeEntry['StartTime']); + $wasOnlineAfterBlockadeEnded = ($props['targetOwnerDetails']['onlinetime'] >= $blockadeEntry['EndTime']); + + if ( + ($isAllMissionsBlockade && $wasOnlineAfterBlockadeStarted) || + (!$isAllMissionsBlockade && $wasOnlineAfterBlockadeEnded) + ) { + continue; + } + + return $isInvalid([ + 'blockType' => 'GLOBAL_POSTENDTIME', + 'details' => [ + 'hardEndTime' => $blockadeEntry['PostEndTime'], + ], + ]); + } + + continue; + } + + if ($blockadeEntry['Type'] == 2) { + return $isInvalid([ + 'blockType' => 'USER', + 'details' => [ + 'reason' => $blockadeEntry['Reason'], + 'userId' => $blockadeEntry['ElementID'], + 'endTime' => $blockadeEntry['EndTime'], + ], + ]); + } + + if ($blockadeEntry['Type'] == 3) { + return $isInvalid([ + 'blockType' => 'PLANET', + 'details' => [ + 'reason' => $blockadeEntry['Reason'], + 'planetId' => $blockadeEntry['ElementID'], + 'endTime' => $blockadeEntry['EndTime'], + ], + ]); + } + } + + return $isValid(); +} + +?>