Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore group sync request instead of returning error #3433

Merged
merged 3 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 17 additions & 13 deletions modules/Core/includes/endpoints/UpdateGroupsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,29 @@ 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')]);
return;
Derkades marked this conversation as resolved.
Show resolved Hide resolved
}

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