Online/Offline php script: Admin/Mod

tonnizi

Member
Sep 20, 2017
6
0
33
Does anyone have to make such a php script that would be an admin and a mode listing, and any one of the modes or admins will be online or going offline so the name will be getting online or offline.

for example:
admin:
tonimoN - Online (green)
tonni - Offline (red)

mod:
tonimoN - Online (green)
tonni - Offline (red)

Thanks for anybody can do or give me one
 

Kieran

Tag me
Contributor
Jan 1, 2016
459
286
122
I think that would be pretty easy. I'll look into it when I'm home
 

Kieran

Tag me
Contributor
Jan 1, 2016
459
286
122
@KuBaKoM @tonnizi
Here you go:
PHP:
<?php
//Path to library
require_once('./TeamSpeak3/TeamSpeak3.php');

$config = array(); //Creates Config Array
$config["Username"] = "loginname"; //Query Login
$config["Password"] = "password"; //Query Password
$config["IP"] = "192.168.1.80"; //Server IP/Domain
$config["Port"] = "9987"; //Server Port
$config["qPort"] = "10011"; // Query Port, Default 10011
$config["botName"] = rawurlencode("Query"); // Convertes Botname to a URI friendly Format

//Set UIDs. Format: array('Name', 'UID'),
$UIDs = array(
    array('Kieran', 'GV1o/OG88dpRoTwTq4HOA3BCEic='),
    array('JaSch', 'H1Jo/M3APZfw2usSVnIe3WVyJ5A='),
    array('Trust', 'DvucmM+o8MxCGz90JHvxgK3xu8I=')
    );

try{

    $ts3 = TeamSpeak3::factory("serverquery://" . $config["Username"] . ":" . $config["Password"] . "@" . $config["IP"] . ":" . $config["qPort"] . "/?server_port=" . $config["Port"] . "");
    //Query clients from Server
    $arr_ClientList = $ts3->clientList();
    //loop through UIDs, then through clients and check if any UIDs match, set third element in array of that UID to true
    for ($i = 0; $i < count($UIDs); $i++){
        foreach($arr_ClientList as $client){
            if($UIDs[$i][1] == $client['client_unique_identifier']){
                $UIDs[$i][2] = true;
            }
        }
    }
    //Loop through UIDs again and check if third element is true
    foreach($UIDs as $UID){
        if($UID[2] == true){
            echo $UID[0] . ': <span style="color:green;">Online</span><br>';
        }
        else{
            echo $UID[0] . ': <span style="color:red;">Offline</span><br>';
        }
    }

}
catch(TeamSpeak3_Exception $error)
{
 // print the error message returned by the server
 echo "Error " . $error->getCode() . ": " . $error->getMessage();
}
?>
You need this for it to work: https://github.com/planetteamspeak/ts3phpframework
Click "clone or download" then "Download ZIP". Open the zip and then go into "libraries" and move the TeamSpeak3 directory to the one the php file is in.

If you want I can put it in a var and echo it as a table. You only have to use <?php require_once('online.php');?> to display the table with the online and offline people.

I will do the Mod part now
 

Kieran

Tag me
Contributor
Jan 1, 2016
459
286
122
Alright this SHOULD work. It's ugly and could've been done better but eh it does the job.
PHP:
<?php
//Path to library
require_once('./TeamSpeak3/TeamSpeak3.php');

$config = array(); //Creates Config Array
$config["Username"] = "loginname"; //Query Login
$config["Password"] = "password"; //Query Password
$config["IP"] = "192.168.1.80"; //Server IP/Domain
$config["Port"] = "9987"; //Server Port
$config["qPort"] = "10011"; // Query Port, Default 10011
$config["botName"] = rawurlencode("Query"); // Convertes Botname to a URI friendly Format

$ts3 = TeamSpeak3::factory("serverquery://" . $config["Username"] . ":" . $config["Password"] . "@" . $config["IP"] . ":" . $config["qPort"] . "/?server_port=" . $config["Port"] . "");
//Set UIDs. Format: array('Name', 'UID'),
$UIDsAdmin = array(
    array('Kieran', 'BV1o/OG88OpRoTwTq4HOA3BCEic='),
    array('JaSch', 'Z1Jo/M3APZcw2usSVnIe3WVyJ5A='),
    array('Trust', 'hvucmM+o8MwCGz90JHvxgK3xu8I=')
);
$UIDsMod = array(
    array('Dude1', 'HV1o/OG88OpRoTwTq4HjA3BCEic='),
    array('Dude2', 'T1Jo/M3APZcw2usSVnIx3WVyJ5A='),
    array('Dude3', 'AvucmM+o8MwCGz90JHvbgK3xu8I=')
);

function online($UIDs, $ts3){
    //Query clients from Server
    $arr_ClientList = $ts3->clientList();
    //loop through UIDs, then through clients and check if any UIDs match, set third element in array of that UID to true
    for ($i = 0; $i < count($UIDs); $i++){
        foreach($arr_ClientList as $client){
            if($UIDs[$i][1] == $client['client_unique_identifier']){
                $UIDs[$i][2] = true;
            }
        }
    }
    $html = '';
    //Loop through UIDs again and check if third element is true
    foreach($UIDs as $UID){
        if($UID[2] == true){
            $html = $html . '<tr><td>' . $UID[0] . '</td><td><span style="color:green;">Online</span></td></tr>';
        }
        else{
            $html = $html . '<tr><td>' . $UID[0] . '</td><td><span style="color:red;">Offline</span></td></tr>';
        }
    }
    return $html;
}

try{
$htmlTable = '<table><tr><th>Admin</th><th>Status</th></tr>';
$htmlTable = $htmlTable . online($UIDsAdmin, $ts3);
$htmlTable = $htmlTable . '</table><br>';
echo $htmlTable;

$htmlTable = '<table><tr><th>Mod</th><th>Status</th></tr>';
$htmlTable = $htmlTable . online($UIDsMod, $ts3);
$htmlTable = $htmlTable . '</table>';
echo $htmlTable;

}
catch(TeamSpeak3_Exception $error)
{
 // print the error message returned by the server
 echo "Error " . $error->getCode() . ": " . $error->getMessage();
}
?>
tell me if this throws any errors.
 

tonnizi

Member
Sep 20, 2017
6
0
33
Alright this SHOULD work. It's ugly and could've been done better but eh it does the job.
PHP:
<?php
//Path to library
require_once('./TeamSpeak3/TeamSpeak3.php');

$config = array(); //Creates Config Array
$config["Username"] = "loginname"; //Query Login
$config["Password"] = "password"; //Query Password
$config["IP"] = "192.168.1.80"; //Server IP/Domain
$config["Port"] = "9987"; //Server Port
$config["qPort"] = "10011"; // Query Port, Default 10011
$config["botName"] = rawurlencode("Query"); // Convertes Botname to a URI friendly Format

$ts3 = TeamSpeak3::factory("serverquery://" . $config["Username"] . ":" . $config["Password"] . "@" . $config["IP"] . ":" . $config["qPort"] . "/?server_port=" . $config["Port"] . "");
//Set UIDs. Format: array('Name', 'UID'),
$UIDsAdmin = array(
    array('Kieran', 'BV1o/OG88OpRoTwTq4HOA3BCEic='),
    array('JaSch', 'Z1Jo/M3APZcw2usSVnIe3WVyJ5A='),
    array('Trust', 'hvucmM+o8MwCGz90JHvxgK3xu8I=')
);
$UIDsMod = array(
    array('Dude1', 'HV1o/OG88OpRoTwTq4HjA3BCEic='),
    array('Dude2', 'T1Jo/M3APZcw2usSVnIx3WVyJ5A='),
    array('Dude3', 'AvucmM+o8MwCGz90JHvbgK3xu8I=')
);

function online($UIDs, $ts3){
    //Query clients from Server
    $arr_ClientList = $ts3->clientList();
    //loop through UIDs, then through clients and check if any UIDs match, set third element in array of that UID to true
    for ($i = 0; $i < count($UIDs); $i++){
        foreach($arr_ClientList as $client){
            if($UIDs[$i][1] == $client['client_unique_identifier']){
                $UIDs[$i][2] = true;
            }
        }
    }
    $html = '';
    //Loop through UIDs again and check if third element is true
    foreach($UIDs as $UID){
        if($UID[2] == true){
            $html = $html . '<tr><td>' . $UID[0] . '</td><td><span style="color:green;">Online</span></td></tr>';
        }
        else{
            $html = $html . '<tr><td>' . $UID[0] . '</td><td><span style="color:red;">Offline</span></td></tr>';
        }
    }
    return $html;
}

try{
$htmlTable = '<table><tr><th>Admin</th><th>Status</th></tr>';
$htmlTable = $htmlTable . online($UIDsAdmin, $ts3);
$htmlTable = $htmlTable . '</table><br>';
echo $htmlTable;

$htmlTable = '<table><tr><th>Mod</th><th>Status</th></tr>';
$htmlTable = $htmlTable . online($UIDsMod, $ts3);
$htmlTable = $htmlTable . '</table>';
echo $htmlTable;

}
catch(TeamSpeak3_Exception $error)
{
 // print the error message returned by the server
 echo "Error " . $error->getCode() . ": " . $error->getMessage();
}
?>
tell me if this throws any errors.

Thank you.
 
Last edited:

KuBaKoM

Member
Apr 28, 2017
11
1
35
@KuBaKoM @tonnizi
Here you go:
PHP:
<?php
//Path to library
require_once('./TeamSpeak3/TeamSpeak3.php');

$config = array(); //Creates Config Array
$config["Username"] = "loginname"; //Query Login
$config["Password"] = "password"; //Query Password
$config["IP"] = "192.168.1.80"; //Server IP/Domain
$config["Port"] = "9987"; //Server Port
$config["qPort"] = "10011"; // Query Port, Default 10011
$config["botName"] = rawurlencode("Query"); // Convertes Botname to a URI friendly Format

//Set UIDs. Format: array('Name', 'UID'),
$UIDs = array(
    array('Kieran', 'GV1o/OG88dpRoTwTq4HOA3BCEic='),
    array('JaSch', 'H1Jo/M3APZfw2usSVnIe3WVyJ5A='),
    array('Trust', 'DvucmM+o8MxCGz90JHvxgK3xu8I=')
    );

try{

    $ts3 = TeamSpeak3::factory("serverquery://" . $config["Username"] . ":" . $config["Password"] . "@" . $config["IP"] . ":" . $config["qPort"] . "/?server_port=" . $config["Port"] . "");
    //Query clients from Server
    $arr_ClientList = $ts3->clientList();
    //loop through UIDs, then through clients and check if any UIDs match, set third element in array of that UID to true
    for ($i = 0; $i < count($UIDs); $i++){
        foreach($arr_ClientList as $client){
            if($UIDs[$i][1] == $client['client_unique_identifier']){
                $UIDs[$i][2] = true;
            }
        }
    }
    //Loop through UIDs again and check if third element is true
    foreach($UIDs as $UID){
        if($UID[2] == true){
            echo $UID[0] . ': <span style="color:green;">Online</span><br>';
        }
        else{
            echo $UID[0] . ': <span style="color:red;">Offline</span><br>';
        }
    }

}
catch(TeamSpeak3_Exception $error)
{
 // print the error message returned by the server
 echo "Error " . $error->getCode() . ": " . $error->getMessage();
}
?>
You need this for it to work: https://github.com/planetteamspeak/ts3phpframework
Click "clone or download" then "Download ZIP". Open the zip and then go into "libraries" and move the TeamSpeak3 directory to the one the php file is in.

If you want I can put it in a var and echo it as a table. You only have to use <?php require_once('online.php');?> to display the table with the online and offline people.

I will do the Mod part now

Thank's +1
 
Top