From 1d60fcc150ac8e9b09320ab8fda4867c384c5d3f Mon Sep 17 00:00:00 2001 From: Robin Date: Sun, 3 Sep 2023 20:21:17 +0200 Subject: [PATCH] Ignore group sync request instead of returning error (#3433) * Ignore group sync request instead of returning error * Fix condition * Remove return --- custom/languages/en_UK.json | 1 + .../endpoints/UpdateGroupsEndpoint.php | 29 ++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/custom/languages/en_UK.json b/custom/languages/en_UK.json index 2c2654f29a..4e893842b7 100644 --- a/custom/languages/en_UK.json +++ b/custom/languages/en_UK.json @@ -757,6 +757,7 @@ "api/finish_registration_link": "Please click on the following link to complete registration:", "api/group_updated": "Group updated successfully", "api/groups_updates_successfully": "Groups updated successfully", + "api/groups_updates_ignored": "Group sync request ignored, because the Minecraft integration is disabled or the server is not configured as the group sync server in StaffCP.", "api/integration_identifier_already_linked": "{{integration}} identifier is already linked to another user.", "api/integration_username_already_linked": "{{integration}} username is already linked to another user.", "api/report_created": "Report created successfully", diff --git a/modules/Core/includes/endpoints/UpdateGroupsEndpoint.php b/modules/Core/includes/endpoints/UpdateGroupsEndpoint.php index fa2373f40a..d74a3101fb 100644 --- a/modules/Core/includes/endpoints/UpdateGroupsEndpoint.php +++ b/modules/Core/includes/endpoints/UpdateGroupsEndpoint.php @@ -13,25 +13,28 @@ public function execute(Nameless2API $api): void { $api->validateParams($_POST, ['server_id', 'player_groups']); $server_id = $_POST['server_id']; - $group_sync_log = []; - if (Settings::get('mc_integration') && $server_id == Settings::get('group_sync_mc_server')) { - $integration = Integrations::getInstance()->getIntegration('Minecraft'); + if (!Settings::get('mc_integration') || $server_id != Settings::get('group_sync_mc_server')) { + $api->returnArray(['message' => $api->getLanguage()->get('api', 'groups_updates_ignored')]); + } - foreach ($_POST['player_groups'] as $uuid => $groups) { - $integrationUser = new IntegrationUser($integration, str_replace('-', '', $uuid), 'identifier'); - if ($integrationUser->exists()) { - $log = $this->updateGroups($integrationUser, $groups['groups']); - if (count($log)) { - $group_sync_log[] = $log; - } + $group_sync_log = []; + $integration = Integrations::getInstance()->getIntegration('Minecraft'); + + foreach ($_POST['player_groups'] as $uuid => $groups) { + $integrationUser = new IntegrationUser($integration, str_replace('-', '', $uuid), 'identifier'); + if ($integrationUser->exists()) { + $log = $this->updateGroups($integrationUser, $groups['groups']); + if (count($log)) { + $group_sync_log[] = $log; } } - - $api->returnArray(array_merge(['message' => $api->getLanguage()->get('api', 'groups_updates_successfully')], ['log' => $group_sync_log])); } - $api->throwError(CoreApiErrors::ERROR_INVALID_SERVER_ID, $server_id); + $api->returnArray([ + 'message' => $api->getLanguage()->get('api', 'groups_updates_successfully'), + 'log' => $group_sync_log, + ]); } private function updateGroups(IntegrationUser $integrationUser, array $groups): array {