Count Online Users Script from 2 servers or more?

cakooo

Member
Nov 21, 2015
19
6
35
Hello there

First of all can someone guide me for a php script that counts onlineusers from a ts3 server. I've found for ts2 but not for ts3.
I only need a script like OnlineUsers: xxx


And a second favor.
Can something like server 1 + server Onlineusers: xxxx be done?
Meaning to gather users from 2 servers and list the onlineusers as total

This will be used for a simple web

Thank you in advance
Sorry for my bad english
this is a copy paste but i need the same
 

Mr-Malone

You risk and you will win
Sep 11, 2015
69
25
108
You're referring to a php script that could monitor a spacer members online on a server and the spacer is selected you?
 

MadKill

Active Member
Sep 1, 2015
190
47
66
Type :

[cspacer]Clients online : X
[cspacer]Chanel name : X users

Something like that ?
 

cakooo

Member
Nov 21, 2015
19
6
35
For show in a webpage , example

Online : xxxx
This online are : server + server2 = total online
 

Agusanz

Active Member
Jul 18, 2015
239
148
88
I made this script for you.
https://github.com/Agusanz/TSUsers
i didn't made the spacer part because it's easy.. you can print this out into a website or maybe a spacer.. if you want that let me know and i will modify it for you if you don't know how to do it.. :eek:

Print $clientsOnlineTotal and $slotsAvailableTotal wherever you want.
Code:
<?php
/*/////////
//Agusanz//
*//////////
require_once("libraries/TeamSpeak3/TeamSpeak3.php");

TeamSpeak3::init();
//primary
$user1 = "username";//query username
$pass1 ="password";//query password
$serverIP1 = "192.168.0.1";//server ip
$serverPort1 = "9987";//server port
$nickname1 = "BotNameP";//bot nickname
//secondary
$user2 = "username";//query username
$pass2 ="password";//query password
$serverIP2 = "192.168.0.2";//server ip
$serverPort2 = "9987";//server port
$nickname2 = "BotNameS";//bot nickname

try
{
   $ts3Primary = TeamSpeak3::factory("serverquery://{$user1}:{$pass1}@{$serverIP1}:10011/?server_port={$serverPort1}&blocking=0&nickname={$nickname1}");
  $serverInfoPrimary = $ts3Primary->getInfo();
  $maxSlotsPrimary = $serverInfoPrimary["virtualserver_maxclients"];
  $clientsOnlinePrimary = $serverInfoPrimary["virtualserver_clientsonline"];
  $slotsReservedPrimary = $serverInfoPrimary["virtualserver_reserved_slots"];
  $slotsAvailablePrimary = $maxSlotsPrimary - $slotsReservedPrimary;
  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  echo $realTime."\t[INFO] Primary done. Users online: {$clientsOnlinePrimary}. Slots: {$slotsAvailablePrimary}.\n";

  $ts3Secondary = TeamSpeak3::factory("serverquery://{$user2}:{$pass2}@{$serverIP2}:10011/?server_port={$serverPort2}&blocking=0&nickname={$nickname2}");
  $serverInfoSecondary = $ts3Secondary->getInfo();
  $maxSlotsSecondary = $serverInfoSecondary["virtualserver_maxclients"];
  $clientsOnlineSecondary = $serverInfoSecondary["virtualserver_clientsonline"];
  $slotsReservedSecondary = $serverInfoSecondary["virtualserver_reserved_slots"];
  $slotsAvailableSecondary = $maxSlotsSecondary - $slotsReservedSecondary;
  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  echo $realTime."\t[INFO] Secondary done. Users online: {$clientsOnlineSecondary}. Slots: {$slotsAvailableSecondary}.\n";

  $clientsOnlineTotal = $clientsOnlinePrimary + $clientsOnlineSecondary;
  $slotsAvailableTotal = $slotsAvailablePrimary + $slotsAvailableSecondary;

  echo $clientsOnlineTotal."\n";
  echo $slotsAvailableTotal."\n";

  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  die($realTime."\t[INFO] Finished.\n");
}
catch(Exception $e)
{
  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  echo "Failed\n";
  die($realTime."\t[ERROR]  " . $e->getMessage() . "\n". $e->getTraceAsString() ."\n");
}
Enjoy..
 
Last edited:

cakooo

Member
Nov 21, 2015
19
6
35
I made this script for you.
https://github.com/Agusanz/TSUsers
i didn't made the spacer part because it's easy.. you can print this out into a website or maybe a spacer.. if you want that let me know and i will modify it for you if you don't know how to do it.. :eek:

Print $clientsOnlineTotal and $slotsAvailableTotal wherever you want.
Code:
<?php
/*/////////
//Agusanz//
*//////////
require_once("libraries/TeamSpeak3/TeamSpeak3.php");

TeamSpeak3::init();
//primary
$user1 = "username";//query username
$pass1 ="password";//query password
$serverIP1 = "192.168.0.1";//server ip
$serverPort1 = "9987";//server port
$nickname1 = "BotNameP";//bot nickname
//secondary
$user2 = "username";//query username
$pass2 ="password";//query password
$serverIP2 = "192.168.0.2";//server ip
$serverPort2 = "9987";//server port
$nickname2 = "BotNameS";//bot nickname

try
{
   $ts3Primary = TeamSpeak3::factory("serverquery://{$user1}:{$pass1}@{$serverIP1}:10011/?server_port={$serverPort1}&blocking=0&nickname={$nickname1}");
  $serverInfoPrimary = $ts3Primary->getInfo();
  $maxSlotsPrimary = $serverInfoPrimary["virtualserver_maxclients"];
  $clientsOnlinePrimary = $serverInfoPrimary["virtualserver_clientsonline"];
  $slotsReservedPrimary = $serverInfoPrimary["virtualserver_reserved_slots"];
  $slotsAvailablePrimary = $maxSlotsPrimary - $slotsReservedPrimary;
  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  echo $realTime."\t[INFO] Primary done. Users online: {$clientsOnlinePrimary}. Slots: {$slotsAvailablePrimary}.\n";

  $ts3Secondary = TeamSpeak3::factory("serverquery://{$user2}:{$pass2}@{$serverIP2}:10011/?server_port={$serverPort2}&blocking=0&nickname={$nickname2}");
  $serverInfoSecondary = $ts3Secondary->getInfo();
  $maxSlotsSecondary = $serverInfoSecondary["virtualserver_maxclients"];
  $clientsOnlineSecondary = $serverInfoSecondary["virtualserver_clientsonline"];
  $slotsReservedSecondary = $serverInfoSecondary["virtualserver_reserved_slots"];
  $slotsAvailableSecondary = $maxSlotsSecondary - $slotsReservedSecondary;
  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  echo $realTime."\t[INFO] Secondary done. Users online: {$clientsOnlineSecondary}. Slots: {$slotsAvailableSecondary}.\n";

  $clientsOnlineTotal = $clientsOnlinePrimary + $clientsOnlineSecondary;
  $slotsAvailableTotal = $slotsAvailablePrimary + $slotsAvailableSecondary;

  echo $clientsOnlineTotal."\n";
  echo $slotsAvailableTotal."\n";

  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  die($realTime."\t[INFO] Finished.\n");
}
catch(Exception $e)
{
  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  echo "Failed\n";
  die($realTime."\t[ERROR]  " . $e->getMessage() . "\n". $e->getTraceAsString() ."\n");
}
Enjoy..
Wow u are great!

Thanks very much!
 

cakooo

Member
Nov 21, 2015
19
6
35
I made this script for you.
https://github.com/Agusanz/TSUsers
i didn't made the spacer part because it's easy.. you can print this out into a website or maybe a spacer.. if you want that let me know and i will modify it for you if you don't know how to do it.. :eek:

Print $clientsOnlineTotal and $slotsAvailableTotal wherever you want.
Code:
<?php
/*/////////
//Agusanz//
*//////////
require_once("libraries/TeamSpeak3/TeamSpeak3.php");

TeamSpeak3::init();
//primary
$user1 = "username";//query username
$pass1 ="password";//query password
$serverIP1 = "192.168.0.1";//server ip
$serverPort1 = "9987";//server port
$nickname1 = "BotNameP";//bot nickname
//secondary
$user2 = "username";//query username
$pass2 ="password";//query password
$serverIP2 = "192.168.0.2";//server ip
$serverPort2 = "9987";//server port
$nickname2 = "BotNameS";//bot nickname

try
{
   $ts3Primary = TeamSpeak3::factory("serverquery://{$user1}:{$pass1}@{$serverIP1}:10011/?server_port={$serverPort1}&blocking=0&nickname={$nickname1}");
  $serverInfoPrimary = $ts3Primary->getInfo();
  $maxSlotsPrimary = $serverInfoPrimary["virtualserver_maxclients"];
  $clientsOnlinePrimary = $serverInfoPrimary["virtualserver_clientsonline"];
  $slotsReservedPrimary = $serverInfoPrimary["virtualserver_reserved_slots"];
  $slotsAvailablePrimary = $maxSlotsPrimary - $slotsReservedPrimary;
  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  echo $realTime."\t[INFO] Primary done. Users online: {$clientsOnlinePrimary}. Slots: {$slotsAvailablePrimary}.\n";

  $ts3Secondary = TeamSpeak3::factory("serverquery://{$user2}:{$pass2}@{$serverIP2}:10011/?server_port={$serverPort2}&blocking=0&nickname={$nickname2}");
  $serverInfoSecondary = $ts3Secondary->getInfo();
  $maxSlotsSecondary = $serverInfoSecondary["virtualserver_maxclients"];
  $clientsOnlineSecondary = $serverInfoSecondary["virtualserver_clientsonline"];
  $slotsReservedSecondary = $serverInfoSecondary["virtualserver_reserved_slots"];
  $slotsAvailableSecondary = $maxSlotsSecondary - $slotsReservedSecondary;
  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  echo $realTime."\t[INFO] Secondary done. Users online: {$clientsOnlineSecondary}. Slots: {$slotsAvailableSecondary}.\n";

  $clientsOnlineTotal = $clientsOnlinePrimary + $clientsOnlineSecondary;
  $slotsAvailableTotal = $slotsAvailablePrimary + $slotsAvailableSecondary;

  echo $clientsOnlineTotal."\n";
  echo $slotsAvailableTotal."\n";

  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  die($realTime."\t[INFO] Finished.\n");
}
catch(Exception $e)
{
  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  echo "Failed\n";
  die($realTime."\t[ERROR]  " . $e->getMessage() . "\n". $e->getTraceAsString() ."\n");
}
Enjoy..
for example, if I want to know the total number of online users across the server (more than 2 virtual servers) as I can do? entering data one by one?
 

Agusanz

Active Member
Jul 18, 2015
239
148
88
for example, if I want to know the total number of online users across the server (more than 2 virtual servers) as I can do? entering data one by one?
This script works using 2 virtual servers, modify these variables:
Code:
//primary
$user1 = "username";//query username
$pass1 ="password";//query password
$serverIP1 = "192.168.0.1";//server ip
$serverPort1 = "9987";//server port
$nickname1 = "BotNameP";//bot nickname
//secondary
$user2 = "username";//query username
$pass2 ="password";//query password
$serverIP2 = "192.168.0.2";//server ip
$serverPort2 = "9987";//server port
$nickname2 = "BotNameS";//bot nickname
You need a query account for each server, the ip (numeric, that's mandatory), server port, nickname of the bot.
if that server is running on another query port than 10011, you need to change that on the connection string.
 
Last edited:

cakooo

Member
Nov 21, 2015
19
6
35
This script works using 2 servers, modify these variables:
Code:
//primary
$user1 = "username";//query username
$pass1 ="password";//query password
$serverIP1 = "192.168.0.1";//server ip
$serverPort1 = "9987";//server port
$nickname1 = "BotNameP";//bot nickname
//secondary
$user2 = "username";//query username
$pass2 ="password";//query password
$serverIP2 = "192.168.0.2";//server ip
$serverPort2 = "9987";//server port
$nickname2 = "BotNameS";//bot nickname
You need a query account for each server, the ip (numeric, that's mandatory), server port, nickname of the bot.
if that server is running on another query port than 10011, you need to change that on the connection string.
Servers , not virtual server . Example i have 1 server with 40 vservers inside. as I can see the total connected on this server?
 

Agusanz

Active Member
Jul 18, 2015
239
148
88
Servers , not virtual server . Example i have 1 server with 40 vservers inside. as I can see the total connected on this server?

virtual servers.. sorry..
No, it will not count the total server virtualservers usersonline. If you want something like that i need to modify the script.

I'm using the teamspeak port 9987 to get the virtual server information
For example, if you want to get the info of 2 servers on the same port 9987 but different ip, you can do it changing the serverip variable..
otherwise if you want to get the same info but in the same ip but different port, you can do it as well changing the port variable..
 

Agusanz

Active Member
Jul 18, 2015
239
148
88
You're looking for the WHOLE SERVER count?

Can something like server 1 + server Onlineusers: xxxx be done?
Meaning to gather users from 2 servers and list the onlineusers as total

i understood that you were talking about 2 virtual servers :(.. confirm this i will work on it soon.
 

cakooo

Member
Nov 21, 2015
19
6
35
You're looking for the WHOLE SERVER count?



i understood that you were talking about 2 virtual servers :(.. confirm this i will work on it soon.

for 2 servers not , vserver

example:

server 1 have inside 40 vservers the total count of online users (vserver1,vserver2,etc...) = server1useronline = xx
 

Agusanz

Active Member
Jul 18, 2015
239
148
88
for 2 servers not , vserver

example:

server 1 have inside 40 vservers the total count of online users (vserver1,vserver2,etc...) = server1useronline = xx
okay.. when i come back tonight i will work on it, do you want the amount of total slots available as well?
 

Agusanz

Active Member
Jul 18, 2015
239
148
88
I did it for 1 server, you can copy paste everything and add a number 2 at the end of each variable to make it work with 2 different server like the last time..
I has been testing it and seems to work fine, i don't have the reserved slots, but i can get that info if you need it, not a big deal..

https://github.com/Agusanz/TSUsers
https://github.com/Agusanz/TSUsers/blob/master/TSUsersSv
It's the same proyect, download the TSUsersSv (server version)
Print this variables wherever you want: $clientsOnlineTotal and $maxSlotsTotal
Code:
<?php
/*/////////
//Agusanz//
*//////////
require_once("libraries/TeamSpeak3/TeamSpeak3.php");

TeamSpeak3::init();
//Config
$user = "serveradmin";
$pass ="password";
$serverIP = "127.0.0.1";
$serverQueryPort = "10011";
$nickname = "BotNameSv";

try
{
   $clientsOnlineTotal = 0;
   $maxSlotsTotal = 0;

   $ts3 = TeamSpeak3::factory("serverquery://{$user}:{$pass}@{$serverIP}:{$serverQueryPort}&blocking=0&nickname={$nickname}");
   $svList = $ts3->serverList();
  foreach ($svList as $sv)
  {
     $unixTime = time();
     $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
     echo $realTime."\t[INFO] VirtualServer information: \n";
  if ($sv["virtualserver_status"] == "online")
  {
      echo "\tPort: ".$sv["virtualserver_port"]."\n";
      echo "\tID: ".$sv["virtualserver_id"]."\n";
      echo "\tName: ".$sv["virtualserver_name"]."\n";
      echo "\tStatus: ".$sv["virtualserver_status"]."\n";
      echo "\tClients online: ".$sv["virtualserver_clientsonline"]."\n";
      echo "\tClients query online: ".$sv["virtualserver_queryclientsonline"]."\n";
      echo "\tMax slots: ".$sv["virtualserver_maxclients"]."\n";

      $clientsOnline = $sv["virtualserver_clientsonline"];
      $maxSlots = $sv["virtualserver_maxclients"];
      $clientsOnlineTotal = $clientsOnlineTotal + $clientsOnline;
      $maxSlotsTotal = $maxSlotsTotal + $maxSlots;
  }
  else
  {
  echo "\tPort: ".$sv["virtualserver_port"]."\n";
  echo "\tID: ".$sv["virtualserver_id"]."\n";
  echo "\tStatus: ".$sv["virtualserver_status"]."\n";
  }
    $unixTime = time();
     $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
     echo $realTime."\t[INFO] VirtualServer port: {$sv["virtualserver_port"]} done.\n\n";
   }

  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  echo $realTime."\t[INFO] Total clients online: ".$clientsOnlineTotal."\n";
  echo $realTime."\t[INFO] Total slots : ".$maxSlotsTotal."\n";
  die($realTime."\t[INFO] Finished.\n");
}
catch(Exception $e)
{
  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  echo "Failed\n";
  die($realTime."\t[ERROR]  " . $e->getMessage() . "\n". $e->getTraceAsString() ."\n");
}

My setup and console logs:
9f37748d2a.jpg

ly@ly:~/Downloads/TSUsersSv$ php -f TSUsersSv.php
[2016-04-06] [23:24:44] [INFO] VirtualServer information:
Port: 9987
ID: 1
Name: 1
Status: online
Clients online: 1
Clients query online: 0
Max slots: 7
[2016-04-06] [23:24:44] [INFO] VirtualServer done. Users online: 1. Slots: 7.

[2016-04-06] [23:24:44] [INFO] VirtualServer information:
Port: 9988
ID: 2
Name: 2
Status: online
Clients online: 1
Clients query online: 0
Max slots: 100
[2016-04-06] [23:24:44] [INFO] VirtualServer done. Users online: 1. Slots: 100.

[2016-04-06] [23:24:44] [INFO] VirtualServer information:
Port: 9989
ID: 3
Name: 3
Status: online
Clients online: 0
Clients query online: 0
Max slots: 101
[2016-04-06] [23:24:44] [INFO] VirtualServer done. Users online: 0. Slots: 101.

[2016-04-06] [23:24:44] [INFO] VirtualServer information:
Port: 9990
ID: 4
Name: 4
Status: online
Clients online: 0
Clients query online: 0
Max slots: 102
[2016-04-06] [23:24:44] [INFO] VirtualServer done. Users online: 0. Slots: 102.

[2016-04-06] [23:24:44] [INFO] Total clients online: 2
[2016-04-06] [23:24:44] [INFO] Total slots : 310
[2016-04-06] [23:24:44] [INFO] Finished.

Hopefully it's what you're looking for this time :rolleyes:
 
Last edited:

cakooo

Member
Nov 21, 2015
19
6
35
I did it for 1 server, you can copy paste everything and add a number 2 at the end of each variable to make it work with 2 different server like the last time..
I has been testing it and seems to work fine, i don't have the reserved slots, but i can get that info if you need it, not a big deal..

https://github.com/Agusanz/TSUsers
https://github.com/Agusanz/TSUsers/blob/master/TSUsersSv
It's the same proyect, download the TSUsersSv (server version)
Print this variables wherever you want: $clientsOnlineTotal and $maxSlotsTotal
Code:
<?php
/*/////////
//Agusanz//
*//////////
require_once("libraries/TeamSpeak3/TeamSpeak3.php");

TeamSpeak3::init();
//Config
$user = "serveradmin";
$pass ="password";
$serverIP = "127.0.0.1";
$serverQueryPort = "10011";
$nickname = "BotNameSv";

try
{
   $clientsOnlineTotal = 0;
   $maxSlotsTotal = 0;

   $ts3 = TeamSpeak3::factory("serverquery://{$user}:{$pass}@{$serverIP}:{$serverQueryPort}&blocking=0&nickname={$nickname}");
   $svList = $ts3->serverList();
  foreach ($svList as $sv)
  {
     $unixTime = time();
     $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
     echo $realTime."\t[INFO] VirtualServer information: \n";
     echo "\tPort: ".$sv["virtualserver_port"]."\n";
     echo "\tID: ".$sv["virtualserver_id"]."\n";
     echo "\tName: ".$sv["virtualserver_name"]."\n";
     echo "\tStatus: ".$sv["virtualserver_status"]."\n";
     echo "\tClients online: ".$sv["virtualserver_clientsonline"]."\n";
     echo "\tClients query online: ".$sv["virtualserver_queryclientsonline"]."\n";
     echo "\tMax slots: ".$sv["virtualserver_maxclients"]."\n";

     $clientsOnline = $sv["virtualserver_clientsonline"];
     $maxSlots = $sv["virtualserver_maxclients"];
     $clientsOnlineTotal = $clientsOnlineTotal + $clientsOnline;
     $maxSlotsTotal = $maxSlotsTotal + $maxSlots;

    $unixTime = time();
     $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
     echo $realTime."\t[INFO] VirtualServer done. Users online: {$clientsOnline}. Slots: {$maxSlots}.\n\n";
   }

  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  echo $realTime."\t[INFO] Total clients online: ".$clientsOnlineTotal."\n";
  echo $realTime."\t[INFO] Total slots : ".$maxSlotsTotal."\n";
  die($realTime."\t[INFO] Finished.\n");
}
catch(Exception $e)
{
  $unixTime = time();
  $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
  echo "Failed\n";
  die($realTime."\t[ERROR]  " . $e->getMessage() . "\n". $e->getTraceAsString() ."\n");
}

My setup and console logs:
9f37748d2a.jpg



Hopefully it's what you're looking for this time :rolleyes:

WoooW Thanks man really u re great!! <3
 

Agusanz

Active Member
Jul 18, 2015
239
148
88
Fixed a bug: when a virtualserver is offline you can't get the current players online or slots , sorry about it
 
Top