diff --git a/fleet1.php b/fleet1.php index fa0d511f..2009ec80 100644 --- a/fleet1.php +++ b/fleet1.php @@ -122,39 +122,38 @@ } } -$_Lang['P_HideACSJoining'] = $Hide; -$GetACSData = intval($_POST['getacsdata']); -$SetPosNotEmpty = false; -if($GetACSData > 0) -{ - $ACSData = doquery("SELECT `id`, `name`, `end_galaxy`, `end_system`, `end_planet`, `end_type`, `start_time` FROM {{table}} WHERE `id` = {$GetACSData};", 'acs', true); - if($ACSData['id'] == $GetACSData) - { - if($ACSData['start_time'] > $Now) - { - $SetPos['g'] = $ACSData['end_galaxy']; - $SetPos['s'] = $ACSData['end_system']; - $SetPos['p'] = $ACSData['end_planet']; - $SetPos['t'] = $ACSData['end_type']; - - $SetPosNotEmpty = true; - $_Lang['P_HideACSJoining'] = ''; - $_Lang['fl1_ACSJoiningFleet'] = sprintf($_Lang['fl1_ACSJoiningFleet'], $ACSData['name'], $ACSData['end_galaxy'], $ACSData['end_system'], $ACSData['end_planet']); - $_Lang['P_DisableCoordSel'] = 'disabled'; - $_Lang['SelectedACSID'] = $GetACSData; - } - else - { - message($_Lang['fl1_ACSTimeUp'], $ErrorTitle, 'fleet.php', 3); - } - } - else - { - message($_Lang['fl1_ACSNoExist'], $ErrorTitle, 'fleet.php', 3); +$SetPos = []; + +$inputJoinUnionId = intval($_POST['getacsdata']); + +if ($inputJoinUnionId > 0) { + $joinUnionResult = FlightControl\Utils\Helpers\tryJoinUnion([ + 'unionId' => $inputJoinUnionId, + 'currentTimestamp' => $Now, + ]); + + if (!$joinUnionResult['isSuccess']) { + $errorMessage = FlightControl\Utils\Errors\mapTryJoinUnionErrorToReadableMessage($joinUnionResult['error']); + + message($errorMessage, $ErrorTitle, 'fleet.php', 3); } + + $unionData = $joinUnionResult['payload']['unionData']; + + $SetPos['g'] = $unionData['end_galaxy']; + $SetPos['s'] = $unionData['end_system']; + $SetPos['p'] = $unionData['end_planet']; + $SetPos['t'] = $unionData['end_type']; + + $_Lang['fl1_ACSJoiningFleet'] = sprintf( + $_Lang['fl1_ACSJoiningFleet'], + $unionData['name'], $unionData['end_galaxy'], $unionData['end_system'], $unionData['end_planet'] + ); + $_Lang['P_DisableCoordSel'] = 'disabled'; + $_Lang['SelectedACSID'] = $unionData['id']; } -if($SetPosNotEmpty !== true) +if(empty($SetPos)) { $SetPos['g'] = intval($_POST['galaxy']); $SetPos['s'] = intval($_POST['system']); @@ -300,6 +299,12 @@ $_Lang['P_HideNoFastLinks'] = ''; } +$_Lang['P_HideACSJoining'] = ( + empty($_Lang['SelectedACSID']) ? + $Hide : + null +); + $Page = parsetemplate(gettemplate('fleet1_body'), $_Lang); display($Page, $_Lang['fl_title']); diff --git a/modules/flightControl/_includes.php b/modules/flightControl/_includes.php index 34a8a7a7..6c99c6f7 100644 --- a/modules/flightControl/_includes.php +++ b/modules/flightControl/_includes.php @@ -76,6 +76,7 @@ include($includePath . './utils/helpers/getUserFleetSlotsCount.helper.php'); include($includePath . './utils/helpers/getValidMissionTypes.helper.php'); include($includePath . './utils/helpers/noobProtection.helper.php'); + include($includePath . './utils/helpers/tryJoinUnion.helper.php'); include($includePath . './utils/inputs/normalizeFleetResources.inputs.php'); include($includePath . './utils/inputs/normalizeGobackFleetArray.inputs.php'); include($includePath . './utils/updaters/createUnionEntry.updaters.php'); @@ -107,6 +108,7 @@ include($includePath . './utils/errors/quantumGate.utils.php'); include($includePath . './utils/errors/smartFleetsBlockade.utils.php'); include($includePath . './utils/errors/targetOwner.utils.php'); + include($includePath . './utils/errors/tryJoinUnion.utils.php'); }); diff --git a/modules/flightControl/utils/errors/tryJoinUnion.utils.php b/modules/flightControl/utils/errors/tryJoinUnion.utils.php new file mode 100644 index 00000000..2cfdabaa --- /dev/null +++ b/modules/flightControl/utils/errors/tryJoinUnion.utils.php @@ -0,0 +1,25 @@ + $_Lang['fl1_ACSNoExist'], + 'UNION_JOIN_TIME_EXPIRED' => $_Lang['fl1_ACSTimeUp'], + ]; + + if (!isset($knownErrorsByCode[$errorCode])) { + return $_Lang['fleet_generic_errors_unknown']; + } + + return $knownErrorsByCode[$errorCode]; +} + +?> diff --git a/modules/flightControl/utils/helpers/tryJoinUnion.helper.php b/modules/flightControl/utils/helpers/tryJoinUnion.helper.php new file mode 100644 index 00000000..da25aad6 --- /dev/null +++ b/modules/flightControl/utils/helpers/tryJoinUnion.helper.php @@ -0,0 +1,50 @@ + 'INVALID_UNION_ID', + ]); + } + + if ($fetchUnionDataResult['start_time'] <= $currentTimestamp) { + return $resultHelpers['createFailure']([ + 'code' => 'UNION_JOIN_TIME_EXPIRED', + ]); + } + + // TODO: To prevent union data leakage, + // check whether this union is accessible to this user + + return $resultHelpers['createSuccess']([ + 'unionData' => $fetchUnionDataResult, + ]); + }; + + return createFuncWithResultHelpers($executor)($params); +} + +?>