2021-07-25 22:54:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use App\Exceptions\InvalidGamePreferenceException;
|
|
|
|
use App\Exceptions\OptionNotFoundException;
|
|
|
|
use App\Facades\Options;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
class ConfigurationService
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @throws OptionNotFoundException|\Exception
|
|
|
|
*/
|
2023-01-15 00:04:00 +00:00
|
|
|
public function saveConfiguration($configuration)
|
|
|
|
{
|
2021-07-25 22:54:15 +01:00
|
|
|
foreach ($configuration as $optionName => $option) {
|
|
|
|
try {
|
|
|
|
Log::debug('Going through option '.$optionName);
|
|
|
|
if (Options::optionExists($optionName)) {
|
|
|
|
Log::debug('Option exists, updating to new values', [
|
|
|
|
'opt' => $optionName,
|
|
|
|
'new_value' => $option,
|
|
|
|
]);
|
|
|
|
Options::changeOption($optionName, $option);
|
|
|
|
}
|
|
|
|
} catch (\Exception $ex) {
|
|
|
|
Log::error('Unable to update options!', [
|
|
|
|
'msg' => $ex->getMessage(),
|
|
|
|
'trace' => $ex->getTraceAsString(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Let service caller handle this without failing here
|
|
|
|
throw $ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves the chosen game integration
|
|
|
|
*
|
|
|
|
* @throws InvalidGamePreferenceException
|
2023-01-15 00:04:00 +00:00
|
|
|
*
|
2021-07-25 22:54:15 +01:00
|
|
|
* @returns bool
|
|
|
|
*/
|
|
|
|
public function saveGameIntegration($gamePreference): bool
|
|
|
|
{
|
|
|
|
// TODO: Find solution to dynamically support games
|
|
|
|
|
|
|
|
$supportedGames = [
|
|
|
|
'RUST',
|
|
|
|
'MINECRAFT',
|
|
|
|
'SE',
|
2023-01-15 00:04:00 +00:00
|
|
|
'GMOD',
|
2021-07-25 22:54:15 +01:00
|
|
|
];
|
|
|
|
|
2023-01-15 00:04:00 +00:00
|
|
|
if (! is_null($gamePreference) && in_array($gamePreference, $supportedGames)) {
|
2021-07-25 22:54:15 +01:00
|
|
|
Options::changeOption('currentGame', $gamePreference);
|
2023-01-15 00:04:00 +00:00
|
|
|
|
2021-07-25 22:54:15 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-01-15 00:04:00 +00:00
|
|
|
throw new InvalidGamePreferenceException('Unsupported game '.$gamePreference);
|
2021-07-25 22:54:15 +01:00
|
|
|
}
|
|
|
|
}
|