Remove all Groups of a Client

ServerVerwaltung

New Member
May 14, 2017
11
1
15
Hello, im searching for a Script like these...
Name of the script: Client Group Cleaner
Functions of the script: The Script will remove all groups from a client (so that he is only in the guest server group)
Why do you want it: Im new to coding and want to learn something about it and i think this would be nice for cleaning up old clients or members that leave a clan
Screenshots:
Original source (if any):
Other notes: Based on PHP. It shoud be based on Teamspeak PHP Framework or ts3adminclass. Thank you a lot :)
 

ServerVerwaltung

New Member
May 14, 2017
11
1
15
I want to keep some informations about the client like first connect and number of connections, but thanks to share that kind of information.
Has got anybody a Script like im searching for O.O :D ?
 

Kieran

Tag me
Contributor
Jan 1, 2016
459
286
122
Doesn't look like anybody is on this so I'm gonna try to make something decent. One sec
 

Norvik

Retired Staff
Contributor
Jul 18, 2015
635
588
157
Just loop through his groups and remove them? That's like 10 lines of code.
 

Kieran

Tag me
Contributor
Jan 1, 2016
459
286
122
Usage: http://example.com/remove_groups.php?uid=vK6YEsyil2NLRnytCjfbHump8Hk= (works with offline client)
OR
http://example.com/remove_groups.php?name=Kieran (only works if the client is online)
PHP:
<?php
//Path to the TS3 PHP Framework
require_once('./TeamSpeak3/TeamSpeak3.php');
//Path to your QueryLogin
require_once('./config.php');


try{
$ts3 = TeamSpeak3::factory("serverquery://" . $config["Username"] . ":" . $config["Password"] . "@" . $config["IP"] . ":" . $config["qPort"] . "/?server_port=" . $config["Port"] . "&nickname=" . $config["Nickname"] . "");


if (isset($_GET['uid'])) {
    $UID = $_GET['uid'];
}else{
    $UID = '';
}

if (isset($_GET['name'])){
    $name = $_GET['name'];
}else{
    $name = '';
}

if ( $name == '' AND $UID == ''){
    echo 'Nah fam';
}
else{
        //If name method is used, it gets the client data via username, then gets the DBID from the UID. Only works if client is ONLINE
        if ( isset($_GET['name']) ){
            $client = $ts3->clientGetByName($name);
            $clientdbid = $ts3->clientFindDb($client['client_unique_identifier'], TRUE);
        }
        //Searches for DBID with specified UID then gets client data
        else if ( isset($_GET['uid']) ){
            $clientdbid = $ts3->clientFindDb($UID, TRUE);
            $client = $ts3->clientGetByDbid($clientdbid[0]);
        }
        //Explodes all groupIDs into an array
        $groupsArr = explode(',', $client['client_servergroups']);
        //Prints all groups the client has
        print_r($groupsArr);
        //Loops throught the array and removes the groups from the DBID
        foreach($groupsArr as $group){
            $ts3->serverGroupClientDel($group, $clientdbid);
        }
        //echo $client['client_servergroups'];
    }
}
catch(TeamSpeak3_Exception $error)
{
    $errorCode = $error->getCode();
    $errorMessage = "Error " . $error->getCode() . ": " . $error->getMessage();
    echo $errorMessage;
}

Example of config:
PHP:
<?php
$config = array(
  'Username'   =>    'name',                          //Query Login tsBot
  'Password'   =>    'pass',                          //Query Password zbaTudRH
  'IP'         =>    '1.1.1.1',                       //Server IP/Domain
  'Port'       =>    '9987',                          //Server Port
  'qPort'      =>    '10011',                         //Query Port, Default 10011
  'Username'   =>    rawurlencode('Name'.rand(1,99))  //Convertes Botname to a URI friendly Format
);
?>
 
Last edited:

Bluscream

Retired Staff
Contributor
May 8, 2015
967
934
211
Such a feature exists in yatqa

ZtC9NX0.png
 

Norvik

Retired Staff
Contributor
Jul 18, 2015
635
588
157
Why would you define the config values after you defined the var as an array? Just set all values while you create the var. You should also check if the get var you are checking is existing before you check if it's empty. Not required but recommend :)
 

Kieran

Tag me
Contributor
Jan 1, 2016
459
286
122
List All client > Delete from db?? :>

Regards
I want to keep some informations about the client like first connect and number of connections, but thanks to share that kind of information.
Has got anybody a Script like im searching for O.O :D ?


Why would you define the config values after you defined the var as an array? Just set all values while you create the var. You should also check if the get var you are checking is existing before you check if it's empty. Not required but recommend :)
I wanted to do that first but I don't really know how so I left it out lol. Do you have an example? Or just wrap another if(isset(get)) around the "empty-check"? What I would do is split the empty check in 2 checks and wrap one if(isset(get[uid or name])) around each of them
EDIT: Okay what do you think of this? It's ugly but that should work, right?

About the config, I think it looks better this way and is easier to change.
 
Last edited:

ServerVerwaltung

New Member
May 14, 2017
11
1
15
Usage: http://example.com/remove_groups.php?uid=vK6YEsyil2NLRnytCjfbHump8Hk= (works with offline client)
OR
http://example.com/remove_groups.php?name=Kieran (only works if the client is online)
PHP:
<?php
//Path to the TS3 PHP Framework
require_once('./TeamSpeak3/TeamSpeak3.php');
//Path to your QueryLogin
require_once('./config.php');


try{
$ts3 = TeamSpeak3::factory("serverquery://" . $config["Username"] . ":" . $config["Password"] . "@" . $config["IP"] . ":" . $config["qPort"] . "/?server_port=" . $config["Port"] . "&nickname=" . $config["Nickname"] . "");


if (isset($_GET['uid'])) {
    $UID = $_GET['uid'];
}else{
    $UID = '';
}

if (isset($_GET['name'])){
    $name = $_GET['name'];
}else{
    $name = '';
}

if ( $name == '' AND $UID == ''){
    echo 'Nah fam';
}
else{
        //If name method is used, it gets the client data via username, then gets the DBID from the UID. Only works if client is ONLINE
        if ( isset($_GET['name']) ){
            $client = $ts3->clientGetByName($name);
            $clientdbid = $ts3->clientFindDb($client['client_unique_identifier'], TRUE);
        }
        //Searches for DBID with specified UID then gets client data
        else if ( isset($_GET['uid']) ){
            $clientdbid = $ts3->clientFindDb($UID, TRUE);
            $client = $ts3->clientGetByDbid($clientdbid[0]);
        }
        //Explodes all groupIDs into an array
        $groupsArr = explode(',', $client['client_servergroups']);
        //Prints all groups the client has
        print_r($groupsArr);
        //Loops throught the array and removes the groups from the DBID
        foreach($groupsArr as $group){
            $ts3->serverGroupClientDel($group, $clientdbid);
        }
        //echo $client['client_servergroups'];
    }
}
catch(TeamSpeak3_Exception $error)
{
    $errorCode = $error->getCode();
    $errorMessage = "Error " . $error->getCode() . ": " . $error->getMessage();
    echo $errorMessage;
}

Example of config:
PHP:
<?php
$config = array(); //Creates Config Array
$config["Username"] = "name"; //Query Login tsAGB
$config["Password"] = "pass"; //Query Password zbCTuqRH
$config["IP"] = "1.1.1.1"; //Server IP/Domain
$config["Port"] = "9987"; //Server Port
$config["qPort"] = "10011"; // Query Port, Default 10011
$config["Nickname"] = rawurlencode("Name".rand(1,99)); // Convertes Botname to a URI friendly Format
?>
This is what i was looking for :)
Thank you so much :))
The removing of groups works great but only for the ?name variable not for the uid :-/
I got an : Error 1281: database empty result set
but if i try to reset this client over name it works great!
I Think the issue is the removing of a character.
Ive got echo the variables in the error i will become an result like this "M18Z M5uZnr4PGSusd/smft3Y9g=" there will be removed the "+" the original id will called "M18Z+M5uZnr4PGSusd/smft3Y9g="
Have you got an idea to solve this ?
 

Kieran

Tag me
Contributor
Jan 1, 2016
459
286
122
This is what i was looking for :)
Thank you so much :))
The removing of groups works great but only for the ?name variable not for the uid :-/
I got an : Error 1281: database empty result set
but if i try to reset this client over name it works great!
I Think the issue is the removing of a character.
Ive got echo the variables in the error i will become an result like this "M18Z M5uZnr4PGSusd/smft3Y9g=" there will be removed the "+" the original id will called "M18Z+M5uZnr4PGSusd/smft3Y9g="
Have you got an idea to solve this ?
Oh yea you have to replace the + with %2B. It's a reserved character or something like that.
So yours would look like this: http://example.com/remove_groups.php?uid=M18Z%2BM5uZnr4PGSusd/smft3Y9g=
I don't think there's a way to do replace this server-side because it's how URLs work and the browser already translates it. You could just put $UID = 'M18Z+M5uZnr4PGSusd/smft3Y9g='; in the file I think.

That's like the %20. You can't have a space in an URL so it get's replaced with %20.
 

Norvik

Retired Staff
Contributor
Jul 18, 2015
635
588
157
I wanted to do that first but I don't really know how so I left it out lol. Do you have an example? Or just wrap another if(isset(get)) around the "empty-check"? What I would do is split the empty check in 2 checks and wrap one if(isset(get[uid or name])) around each of them
EDIT: Okay what do you think of this? It's ugly but that should work, right?

About the config, I think it looks better this way and is easier to change.
PHP:
if(isset($_GET['name'] && !empty($_GET['name'])
{ 
 //Do something
}
But keep in mind that empty considers 0 as false so it's not possible to set the name to 0 by using an int.

Btw the config file could look like this.
PHP:
$config = array(
  'Username'   =>    'name',                          //Query Login tsAGB
  'Password'   =>    'pass',                          //Query Password zbCTuqRH
  'IP'         =>    '1.1.1.1',                       //Server IP/Domain
  'Port'       =>    '9987',                          //Server Port
  'qPort'      =>    '10011',                         //Query Port, Default 10011
  'Username'   =>    rawurlencode('Name'.rand(1,99))  //Convertes Botname to a URI friendly Format
);
 

ServerVerwaltung

New Member
May 14, 2017
11
1
15
Oh yea you have to replace the + with %2B. It's a reserved character or something like that.
So yours would look like this: http://example.com/remove_groups.php?uid=M18Z%2BM5uZnr4PGSusd/smft3Y9g=
I don't think there's a way to do replace this server-side because it's how URLs work and the browser already translates it. You could just put $UID = 'M18Z+M5uZnr4PGSusd/smft3Y9g='; in the file I think.

That's like the %20. You can't have a space in an URL so it get's replaced with %20.
Ive got an idea to fix that, ive tested it sometimes and it works if + is the only character that have to be replaced.
Code:
<?php
$RUID = $UID;
$RUID = str_ireplace(" ", "+", $text);
echo $RUID;
?>
for example:
Code:
<?php
$text = "M18Z M5uZnr4PGSusd/smft3Y9g=";
$text = str_ireplace(" ", "+", $text);
echo $text;
?>

With this we clone and rename a variable and than search for an empty character (space) and replace it with an +.
If anybody has an better idea, it will be nice to hear.
Thanks you a lot :)
 

Kieran

Tag me
Contributor
Jan 1, 2016
459
286
122
Ive got an idea to fix that, ive tested it sometimes and it works if + is the only character that have to be replaced.
Code:
<?php
$RUID = $UID;
$RUID = str_ireplace(" ", "+", $text);
echo $RUID;
?>
for example:
Code:
<?php
$text = "M18Z M5uZnr4PGSusd/smft3Y9g=";
$text = str_ireplace(" ", "+", $text);
echo $text;
?>

With this we clone and rename a variable and than search for an empty character (space) and replace it with an +.
If anybody has an better idea, it will be nice to hear.
Thanks you a lot :)
Oh that is a smart idea. Didn't even think about that.
 
Top