From 0b8c506a821b89f2a82d38a87b8e8e691d3bf686 Mon Sep 17 00:00:00 2001 From: Francesco Paolocci Date: Sun, 8 Jan 2017 18:55:59 +0100 Subject: [PATCH] =?UTF-8?q?ts3admin=20integration=20eingef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 5 +- src/Exceptions/TeamspeakException.php | 16 ++++++ src/Providers/TeamspeakServiceProvider.php | 60 ++++++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 src/Exceptions/TeamspeakException.php create mode 100644 src/Providers/TeamspeakServiceProvider.php diff --git a/composer.json b/composer.json index b0c59e2..e6c1b8a 100644 --- a/composer.json +++ b/composer.json @@ -5,12 +5,13 @@ "license": "GPL-3.0", "minimum-stability": "stable", "require": { - "par0noid/ts3admin": "dev-composer" + "par0noid/ts3admin": "dev-composer", + "laravel/framework": "^5.3" }, "version": "0.0.1", "autoload": { "psr-4": { - "Micky5991\\laravel-ts3admin": "src" + "Micky5991\\laravel_ts3admin\\": "src" } }, "repositories": [ diff --git a/src/Exceptions/TeamspeakException.php b/src/Exceptions/TeamspeakException.php new file mode 100644 index 0000000..7bb9cf7 --- /dev/null +++ b/src/Exceptions/TeamspeakException.php @@ -0,0 +1,16 @@ +getDebugLog(); + parent::__construct(end($messages), 0, $previous); + } + +} \ No newline at end of file diff --git a/src/Providers/TeamspeakServiceProvider.php b/src/Providers/TeamspeakServiceProvider.php new file mode 100644 index 0000000..01ef84a --- /dev/null +++ b/src/Providers/TeamspeakServiceProvider.php @@ -0,0 +1,60 @@ +app->singleton(ts3admin::class, function ($app) { + $ts = new ts3admin( + env('TS_HOST', '127.0.0.1'), + env('TS_QUERY_PORT', 10011), + env('TS_QUERY_SOCKET_TIMEOUT', 2) + ); + if ($ts->succeeded($ts->connect())) { + if($ts->succeeded( + $ts->login( + env('TS_QUERY_USER', 'serveradmin'), + env('TS_QUERY_PASS') + ) + )) { + if ($ts->succeeded($ts->selectServer(env('TS_SERVER_PORT', 9987)))) { + return $ts; + } + } + } + throw new TeamspeakException($ts); + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return [ts3admin::class]; + } +}