1616
1717use 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
2022class 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