Skip to content

Commit 5f803f8

Browse files
committed
patch
1 parent bce6f60 commit 5f803f8

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

app/Plugin.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,10 @@ static function sortByLengthDESC($array)
162162
*/
163163
function sendOutput($text, ...$params)
164164
{
165-
166165
$text = vsprintf($text, $params);
167166

168167
try {
169-
$client = $this->teamSpeak3Bot->node->clientGetById($this->info['invokerid']?$this->info['invokerid']:$this->info['clid']);
168+
$client = $this->teamSpeak3Bot->node->clientGetById(@$this->info['invokerid']?$this->info['invokerid']:$this->info['clid']);
170169

171170
if (\App\TeamSpeak3Bot::$config['newLineNewMessage'] === false) {
172171
$client->message($text);

app/TeamSpeak3Bot.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function __construct($username, $password, $host = "127.0.0.1", $port = 1
138138

139139
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' && posix_getuid() === 0) {
140140
$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);
142142
$response = rtrim(fgets(STDIN));
143143
if (strcasecmp($response,'y')) {
144144
$this->printOutput("Aborted.");
@@ -148,7 +148,7 @@ public function __construct($username, $password, $host = "127.0.0.1", $port = 1
148148

149149
if($username === "serveradmin") {
150150
$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);
152152
$response = rtrim(fgets(STDIN));
153153
if (strcasecmp($response,'y') ) {
154154
$this->printOutput("Aborted.");
@@ -176,8 +176,7 @@ public function run()
176176

177177
$this->subscribe();
178178
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");
181180
} catch (Ts3Exception $e) {
182181
$this->onException($e);
183182

@@ -202,7 +201,7 @@ protected function subscribe()
202201
Signal::getInstance()->subscribe("serverqueryConnected", [$this, "onConnect"]);
203202
Signal::getInstance()->subscribe("notifyTextmessage", [$this, "onMessage"]);
204203
Signal::getInstance()->subscribe("notifyEvent", [$this, "onEvent"]);
205-
Signal::getInstance()->subscribe("errorException", [$this, "onException"]);
204+
//Signal::getInstance()->subscribe("errorException", [$this, "onException"]);
206205
Signal::getInstance()->subscribe("serverqueryDisconnected", [$this, "onDisconnect"]);
207206
}
208207

@@ -220,21 +219,20 @@ protected function register()
220219
* @param $eol
221220
* @param $send
222221
*/
223-
public function printOutput($output, $eol = true, $send = false)
222+
public function printOutput($output, $eol = true, $send = true)
224223
{
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);
227227
} else {
228-
$this->text .= $output;
228+
echo $output;
229229
}
230230
if ($eol) {
231-
echo $this->text . PHP_EOL;
232-
$this->text = (unset)$this->text;
231+
echo PHP_EOL;
233232
}
234233

235234
if($send) {
236-
echo $this->text;
237-
$this->text = (unset)$this->text;
235+
ob_end_flush();
238236
}
239237
}
240238

@@ -301,10 +299,13 @@ private function setup()
301299
'name' => 'Nimda',
302300
'version' => $this::NIMDA_VERSION,
303301
]);
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);
306306

307-
$nimda->update(['version' => $this::NIMDA_VERSION]);
307+
$nimda->update(['version' => $this::NIMDA_VERSION]);
308+
}
308309
}
309310
}
310311

@@ -335,12 +336,12 @@ private function loadPlugin($configFile)
335336

336337
return false;
337338
} 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.") ;
339340

340341
return false;
341342
}
342343

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);
344345

345346
$config['class'] = \Plugin::class . '\\' . $config['name'];
346347

@@ -445,7 +446,7 @@ public function onMessage(Event $event)
445446
public function onEvent(Event $event)
446447
{
447448
$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") {
449450
return;
450451
} elseif ($this->lastEvent && $event->getMessage()->contains($this->lastEvent)) {
451452
return;
@@ -476,7 +477,7 @@ public function onEvent(Event $event)
476477

477478
public function onTimeout($time, AbstractAdapter $adapter)
478479
{
479-
if ($adapter->getQueryLastTimestamp() < time() - 120) {
480+
if ($adapter->getQueryLastTimestamp() < $this->carbon->now()->subSeconds(120)) {
480481
$adapter->request("clientupdate");
481482
}
482483

plugins/WelcomeMsg.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ public function isTriggered()
1414
$this->server = $this->teamSpeak3Bot->node;
1515

1616
$client = $this->server->clientGetById($this->info['clid']);
17-
$clientDbId = current($this->server->clientFindDb($client['client_nickname']));
18-
$clientInfo = $this->server->clientInfoDb($clientDbId);
17+
$clientInfo = $this->server->clientInfoDb($this->server->clientFindDb($client['client_nickname']));
1918

2019
$format = [
2120
"%CL_DATABASE_ID%" => $clientInfo["client_database_id"],

0 commit comments

Comments
 (0)