Skip to content

Commit f1678ef

Browse files
committed
1 parent 3c140be commit f1678ef

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ $serverInfo = $ts3->send('serverinfo');
5858

5959
var_dump($serverInfo->parseList());
6060

61-
$channelList = $ts3->send('channellist -topic -limits -flags -voice -icon -secondsempty');
61+
$channelList = $ts3->send('channellist', ['topic', 'limits', 'flags', 'voice', 'icon', 'secondsempty']);
6262
var_dump($channelList->parseList());
6363

64-
$clientList = $ts3->send('clientlist -uid -away -voice -times -groups -info -icon -country');
64+
$clientList = $ts3->send('clientlist', ['uid', 'away', 'voice', 'times', 'groups', 'info', 'icon', 'country']);
6565
var_dump($clientList->parseList());
6666

6767
// ...

src/TS3Client.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
use function fclose, fsockopen, fwrite, is_resource, restore_error_handler,
1818
set_error_handler, stream_get_contents, stream_set_timeout, trim;
19+
use function implode;
20+
use function is_int;
1921

2022
class TS3Client implements LoggerAwareInterface{
2123
use LoggerAwareTrait;
@@ -72,8 +74,12 @@ public function connect():TS3Client{
7274
restore_error_handler();
7375
stream_set_timeout($this->socket, 1);
7476

75-
$this->send('login client_login_name='.$this->config->query_user.' client_login_password='.$this->config->query_password);
76-
$this->send('use sid='.$this->config->vserver);
77+
$this->send('login', [
78+
'client_login_name' => $this->config->query_user,
79+
'client_login_password' => $this->config->query_password,
80+
]);
81+
82+
$this->send('use', ['sid' => $this->config->vserver]);
7783

7884
return $this;
7985
}
@@ -97,24 +103,34 @@ public function disconnect():TS3Client{
97103
}
98104

99105
/**
100-
* @param string $command
101-
*
102-
* @return \chillerlan\Teamspeak\TS3Response
103106
* @throws \chillerlan\Teamspeak\TS3ClientException
104107
*/
105-
public function send(string $command):TS3Response{
108+
public function send(string $command, array $params = null):TS3Response{
106109

107110
if(!$this->socket){
108111
throw new TS3ClientException('not connected');
109112
}
110113

111114
$command = trim($command);
112-
$this->logger->debug('command: '.$command);
113115

114116
if(empty($command)){
115117
throw new TS3ClientException('empty command');
116118
}
117119

120+
if(!empty($params)){
121+
$args = [];
122+
123+
foreach($params as $k => $param){
124+
$args[] = is_int($k)
125+
? '-'.trim($param)
126+
: trim($k).'='.$param;
127+
}
128+
129+
$command .= ' '.implode(' ', $args);
130+
}
131+
132+
$this->logger->debug('command: '.$command);
133+
118134
if(fwrite($this->socket, $command."\n") !== false){
119135
$response = stream_get_contents($this->socket);
120136

0 commit comments

Comments
 (0)