-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-139 Move union joining attempt calculation into an util
- Loading branch information
Showing
4 changed files
with
112 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\FlightControl\Utils\Errors; | ||
|
||
/** | ||
* @param object $error As returned by FlightControl\Utils\Helpers\tryJoinUnion | ||
*/ | ||
function mapTryJoinUnionErrorToReadableMessage($error) { | ||
global $_Lang; | ||
|
||
$errorCode = $error['code']; | ||
|
||
$knownErrorsByCode = [ | ||
'INVALID_UNION_ID' => $_Lang['fl1_ACSNoExist'], | ||
'UNION_JOIN_TIME_EXPIRED' => $_Lang['fl1_ACSTimeUp'], | ||
]; | ||
|
||
if (!isset($knownErrorsByCode[$errorCode])) { | ||
return $_Lang['fleet_generic_errors_unknown']; | ||
} | ||
|
||
return $knownErrorsByCode[$errorCode]; | ||
} | ||
|
||
?> |
50 changes: 50 additions & 0 deletions
50
modules/flightControl/utils/helpers/tryJoinUnion.helper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\FlightControl\Utils\Helpers; | ||
|
||
/** | ||
* @param array $params | ||
* @param number $params['unionId'] | ||
* @param number $params['currentTimestamp'] | ||
*/ | ||
function tryJoinUnion($params) { | ||
$executor = function ($input, $resultHelpers) { | ||
$unionId = $input['unionId']; | ||
$currentTimestamp = $input['currentTimestamp']; | ||
|
||
$fetchUnionDataQuery = ( | ||
"SELECT " . | ||
"`id`, `name`, `start_time`, " . | ||
"`end_galaxy`, `end_system`, `end_planet`, `end_type` " . | ||
"FROM {{table}} " . | ||
"WHERE " . | ||
"`id` = {$unionId} " . | ||
"LIMIT 1 " . | ||
";" | ||
); | ||
$fetchUnionDataResult = doquery($fetchUnionDataQuery, 'acs', true); | ||
|
||
if (!$fetchUnionDataResult) { | ||
return $resultHelpers['createFailure']([ | ||
'code' => '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); | ||
} | ||
|
||
?> |