@@ -138,7 +138,7 @@ public function __construct($username, $password, $host = "127.0.0.1", $port = 1
138
138
139
139
if (strtoupper (substr (PHP_OS , 0 , 3 )) !== 'WIN ' && posix_getuid () === 0 ) {
140
140
$ this ->printOutput ("[WARNING] Running Nimda as root is bad! " );
141
- $ this ->printOutput ("Start anyway? Y/N: " , false , true );
141
+ $ this ->printOutput ("Start anyway? Y/N: " , false );
142
142
$ response = rtrim (fgets (STDIN ));
143
143
if (strcasecmp ($ response ,'y ' )) {
144
144
$ this ->printOutput ("Aborted. " );
@@ -148,7 +148,7 @@ public function __construct($username, $password, $host = "127.0.0.1", $port = 1
148
148
149
149
if ($ username === "serveradmin " ) {
150
150
$ this ->printOutput ("[WARNING] Running Nimda logged in as serveradmin is bad! " );
151
- $ this ->printOutput ("Start anyway? Y/N: " , false , true );
151
+ $ this ->printOutput ("Start anyway? Y/N: " , false );
152
152
$ response = rtrim (fgets (STDIN ));
153
153
if (strcasecmp ($ response ,'y ' ) ) {
154
154
$ this ->printOutput ("Aborted. " );
@@ -176,8 +176,7 @@ public function run()
176
176
177
177
$ this ->subscribe ();
178
178
try {
179
- $ this ->node = TeamSpeak3::factory ("serverquery:// {$ this ->username }: {$ this ->password }@ {$ this ->host }: {$ this ->port }/ " .
180
- "?server_port= {$ this ->serverPort }&blocking=0&nickname= {$ this ->name }&timeout= {$ this ->timeout }" );
179
+ $ this ->node = TeamSpeak3::factory ("serverquery:// {$ this ->username }: {$ this ->password }@ {$ this ->host }: {$ this ->port }/?server_port= {$ this ->serverPort }&blocking=0&nickname= {$ this ->name }&timeout= {$ this ->timeout }&no_query_clients=1 " );
181
180
} catch (Ts3Exception $ e ) {
182
181
$ this ->onException ($ e );
183
182
@@ -202,7 +201,7 @@ protected function subscribe()
202
201
Signal::getInstance ()->subscribe ("serverqueryConnected " , [$ this , "onConnect " ]);
203
202
Signal::getInstance ()->subscribe ("notifyTextmessage " , [$ this , "onMessage " ]);
204
203
Signal::getInstance ()->subscribe ("notifyEvent " , [$ this , "onEvent " ]);
205
- Signal::getInstance ()->subscribe ("errorException " , [$ this , "onException " ]);
204
+ // Signal::getInstance()->subscribe("errorException", [$this, "onException"]);
206
205
Signal::getInstance ()->subscribe ("serverqueryDisconnected " , [$ this , "onDisconnect " ]);
207
206
}
208
207
@@ -220,21 +219,20 @@ protected function register()
220
219
* @param $eol
221
220
* @param $send
222
221
*/
223
- public function printOutput ($ output , $ eol = true , $ send = false )
222
+ public function printOutput ($ output , $ eol = true , $ send = true )
224
223
{
225
- if (empty ($ this ->text )) {
226
- $ this ->text = sprintf ("[%s]: %s " , $ this ->carbon ->now ()->toTimeString (), $ output );
224
+ if (!ob_get_contents ()) {
225
+ ob_start (null , 1024 );
226
+ printf ("[%s]: %s " , $ this ->carbon ->now ()->toTimeString (), $ output );
227
227
} else {
228
- $ this -> text .= $ output ;
228
+ echo $ output ;
229
229
}
230
230
if ($ eol ) {
231
- echo $ this ->text . PHP_EOL ;
232
- $ this ->text = (unset )$ this ->text ;
231
+ echo PHP_EOL ;
233
232
}
234
233
235
234
if ($ send ) {
236
- echo $ this ->text ;
237
- $ this ->text = (unset )$ this ->text ;
235
+ ob_end_flush ();
238
236
}
239
237
}
240
238
@@ -301,10 +299,13 @@ private function setup()
301
299
'name ' => 'Nimda ' ,
302
300
'version ' => $ this ::NIMDA_VERSION ,
303
301
]);
304
- } elseif (version_compare (($ nimda = Plugin::where ('name ' , 'Nimda ' )->first ())->version , $ this ::NIMDA_VERSION , '< ' )) {
305
- $ this ->update ($ nimda ->version );
302
+ } else {
303
+ $ nimda = Plugin::where ('name ' , 'Nimda ' )->first ();
304
+ if (version_compare ($ nimda ->version , $ this ::NIMDA_VERSION , '< ' )) {
305
+ $ this ->update ($ nimda ->version );
306
306
307
- $ nimda ->update (['version ' => $ this ::NIMDA_VERSION ]);
307
+ $ nimda ->update (['version ' => $ this ::NIMDA_VERSION ]);
308
+ }
308
309
}
309
310
}
310
311
@@ -335,12 +336,12 @@ private function loadPlugin($configFile)
335
336
336
337
return false ;
337
338
} elseif (!isset ($ config ['name ' ])) {
338
- $ this ->printOutput ("Plugin with config file {$ configFile } has not been loaded because it has no name. " );
339
+ $ this ->printOutput ("Plugin with config file {$ configFile } has not been loaded because it has no name. " ) ;
339
340
340
341
return false ;
341
342
}
342
343
343
- $ this ->printOutput (sprintf ("%- 80s %s " , "Loading plugin [ {$ config ['name ' ]}] by {$ config ['author ' ]} " , ":: " ), false );
344
+ $ this ->printOutput (sprintf ("%- 80s %s " , "Loading plugin [ {$ config ['name ' ]}] by {$ config ['author ' ]} " , ":: " ), false , false );
344
345
345
346
$ config ['class ' ] = \Plugin::class . '\\' . $ config ['name ' ];
346
347
@@ -445,7 +446,7 @@ public function onMessage(Event $event)
445
446
public function onEvent (Event $ event )
446
447
{
447
448
$ data = $ event ->getData ();
448
- if (@$ data ['invokername ' ] == $ this ->name || @$ data ['invokeruid ' ] == 'serveradmin ' ) {
449
+ if (@$ data ['invokername ' ] == $ this ->name || @$ data ['invokeruid ' ] == 'serveradmin ' || @ $ data [ " client_unique_identifier " ] == " ServerQuery " ) {
449
450
return ;
450
451
} elseif ($ this ->lastEvent && $ event ->getMessage ()->contains ($ this ->lastEvent )) {
451
452
return ;
@@ -476,7 +477,7 @@ public function onEvent(Event $event)
476
477
477
478
public function onTimeout ($ time , AbstractAdapter $ adapter )
478
479
{
479
- if ($ adapter ->getQueryLastTimestamp () < time () - 120 ) {
480
+ if ($ adapter ->getQueryLastTimestamp () < $ this -> carbon -> now ()-> subSeconds ( 120 ) ) {
480
481
$ adapter ->request ("clientupdate " );
481
482
}
482
483
0 commit comments