Poke new Connections when 30 Clients are connected

h1web

VIP
Sep 2, 2015
206
134
131
Hey,

is there a script that pokes new connected clients with a Message, when the Server has 30 connected clients already?

Only 30 and above. All below 30 Clients there should be no poke message.

Thanks ;)
 

Jackbox

Active Member
Jan 2, 2016
197
96
74
Yes this would be easy. If connected users > 30 then alert user (on join). Not hard.. I can make this when home tonight. Unless someone wants to beat me for free lifetime VIP access :p
 

kalle

high minded
Contributor
Oct 28, 2015
411
253
178
JavaScript:
const TeamSpeak3 = require("ts3-nodejs-library")
const Promise = require("bluebird")

const needednumbertopoke = 30;
const message = "Hi man, you are special trust me!";

var ts3 = new TeamSpeak3({
    host: "",
    queryport: 10011,
    serverport: 9987,
    username: "serveradmin",
    password: "",
    nickname: "r4p3.net",
    antispam: true,
    antispamtimer: 350,
    keepalive: true
});


function pokeOnConnect(client) {
  Promise.all([
    ts3.serverInfo()
  ]).then(([{virtualserver_clientsonline}]) => {
      // Hack :D exclude query bot
      const online = (virtualserver_clientsonline - 1);
    if(online >= needednumbertopoke && client.getCache().client_type === 0){
        client.poke(message);
    }
  })
}


ts3.on("clientconnect", ev => {
    const client = ev.client;
    pokeOnConnect(client);
})

ts3.on("ready", () => {
    //This Part subscribes to all events available
    Promise.all([
        ts3.registerEvent("server"),
        ts3.registerEvent("channel", 0),
        ts3.registerEvent("textserver"),
        ts3.registerEvent("textchannel"),
        ts3.registerEvent("textprivate")
    ]).then(() => {
        console.log("Subscribed to all Events")
    }).catch(e => {
        console.log("CATCHED", e)
    })
})

//Error event gets fired when an Error during connecting or an Error during Processing of an Event happens
ts3.on("error", e => {
    console.log("Error", e)
})

//Close event gets fired when the Connection to the TeamSpeak Server has been closed
//the e variable is not always set
ts3.on("close", e => {
    console.log("Connection has been closed!", e)
})
 

FromLondon

Honk Honk
TeamSpeak Developer
VIP
May 20, 2016
264
107
136
JavaScript:
const TeamSpeak3 = require("ts3-nodejs-library")
const Promise = require("bluebird")

const needednumbertopoke = 30;
const message = "Hi man, you are special trust me!";

var ts3 = new TeamSpeak3({
    host: "",
    queryport: 10011,
    serverport: 9987,
    username: "serveradmin",
    password: "",
    nickname: "r4p3.net",
    antispam: true,
    antispamtimer: 350,
    keepalive: true
});


function pokeOnConnect(client) {
  Promise.all([
    ts3.serverInfo()
  ]).then(([{virtualserver_clientsonline}]) => {
      // Hack :D exclude query bot
      const online = (virtualserver_clientsonline - 1);
    if(online >= needednumbertopoke && client.getCache().client_type === 0){
        client.poke(message);
    }
  })
}


ts3.on("clientconnect", ev => {
    const client = ev.client;
    pokeOnConnect(client);
})

ts3.on("ready", () => {
    //This Part subscribes to all events available
    Promise.all([
        ts3.registerEvent("server"),
        ts3.registerEvent("channel", 0),
        ts3.registerEvent("textserver"),
        ts3.registerEvent("textchannel"),
        ts3.registerEvent("textprivate")
    ]).then(() => {
        console.log("Subscribed to all Events")
    }).catch(e => {
        console.log("CATCHED", e)
    })
})

//Error event gets fired when an Error during connecting or an Error during Processing of an Event happens
ts3.on("error", e => {
    console.log("Error", e)
})

//Close event gets fired when the Connection to the TeamSpeak Server has been closed
//the e variable is not always set
ts3.on("close", e => {
    console.log("Connection has been closed!", e)
})
You don't need Promise.all.
Also you should to do virtualserver_clientsonline - virtualserver_queryclientsonline instead -1
And as i know ts3-nodejs-lib already writed with promises. Simply use async function with await (look at https://github.com/Multivit4min/TS3-NodeJS-Library/blob/master/transport/TS3Query.js#L246)
 
Last edited:

kalle

high minded
Contributor
Oct 28, 2015
411
253
178

h1web

VIP
Sep 2, 2015
206
134
131
Thanks mates! ;-)

Is there a PHP version available as well?
 
E

ewenjo

Thanks mates! ;-)

Is there a PHP version available as well?
Of course there is! Don't forgot the ts3 php framework folder

PHP:
<?php
require_once("libraries/TeamSpeak3/TeamSpeak3.php");

TeamSpeak3::init();

// CONFIG

// Teamspeak Server Connection
$ts3['username'] = "serveradmin";
$ts3['password'] = "password";
$ts3['ip'] = "127.0.0.1";
$ts3['qport'] = "10011";
$ts3['vport'] = "9987";
$ts3['nickname'] = "PokerMan";

$neededNumberToPoke = 30;
$message = "Hi man, you are special trust me!";

// CONFIG END

$ts3['nickname'] = urlencode($ts3['nickname']);
echo "Bot Started\n\n";

try
{
  TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyServerselected", "onSelect");

  $tsHandle = TeamSpeak3::factory("serverquery://{$ts3['username']}:{$ts3['password']}@{$ts3['ip']}:{$ts3['qport']}/?server_port={$ts3['vport']}&timeout=5&blocking=0&nickname={$ts3['nickname']}");

  while(1) $tsHandle->getAdapter()->wait();

}
catch(Exception $e)
{
  die("[ERROR]  " . $e->getMessage() . "\n");
}


function onTimeout($seconds, TeamSpeak3_Adapter_ServerQuery $adapter)
{
  if($adapter->getQueryLastTimestamp() < time()-250)
  {
    $adapter->request("clientupdate");
  }
}


function onSelect(TeamSpeak3_Node_Host $host)
{
  TeamSpeak3_Helper_Signal::getInstance()->subscribe("serverqueryWaitTimeout", "onTimeout");
  TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyCliententerview", "onClientEnter");
  $host->serverGetSelected()->notifyRegister("server");
  echo "Connected to: " . $host->serverGetSelected()->getProperty("virtualserver_name") . "\n\n";

}

function onClientEnter(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3_Node_Host $host)
{
    try {
        global $neededNumberToPoke, $message;
        $count = $host->serverGetSelected()->getProperty("virtualserver_clientsonline") - $host->serverGetSelected()->getProperty("virtualserver_queryclientsonline");

        $client = $host->serverGetSelected()->clientGetById($event["clid"]);

        if ($count >= $neededNumberToPoke && $client['client_type'] == 0)  {
          $client->poke($message);
        }
    } catch(TeamSpeak3_Exception $e) {
        echo "Error ".$e->getCode().": ".$e->getMessage();
    }
}
?>
 
Last edited by a moderator:
Top