Skip to content

Commit

Permalink
Ignore group sync request instead of returning error (#3433)
Browse files Browse the repository at this point in the history
* Ignore group sync request instead of returning error

* Fix condition

* Remove return
  • Loading branch information
Derkades authored Sep 3, 2023
1 parent 055acb3 commit 1d60fcc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions custom/languages/en_UK.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 16 additions & 13 deletions modules/Core/includes/endpoints/UpdateGroupsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1d60fcc

Please sign in to comment.