Script do not ignore groups

Celso

Member
Joined
Oct 1, 2017
Messages
142
Points
59
Age
21
Location
Brasil
I'm trying to modify a script that I took here in the forum to ignore some groups, but it is not ignoring the groups I select and does not show error logs.
I'm learning now so I do not understand much.
the script works only does not ignore the groups, I have also tried to bypass UID but gave the same error.

PHP:
<?PHP
// Teamspeak config
$teamspeakInfo = array(
    'username' => 'serveradmin',
    'password' => '1234',
    'host' => '127.0.0.1',
    'portQuery' => '10011',
    'portServer' => '2000',
    'displayname' => 'BOT_IP'
);

$blacklist = array('DE'); // array('BR', 'US');
$whitelist = array('DE'); // array('BR', 'US');
$ignore_groups = array('283'); //para ignorar grupos selecionados
$clientType = 2; // 1 = Todos, 2 = Ignorar Query, 3 = Ignorar Clients
$listMode = 2; // 1 = blacklist, 2 = whitelist
$punishMode = 1; // 1 = kick, 2 = ban
$punishMessage = 'Seu país não tem permissão para entrar no nosso servidor.'; // mensagem de banimento/kick


echo "|--------------------------------------|\n|      Não permitir países específicos     |\n|--------------------------------------|\n";
require_once("ts3admin.class.php");
$tsAdmin = new ts3admin($teamspeakInfo['host'], $teamspeakInfo['portQuery']);

if($tsAdmin->getElement('success', $tsAdmin->connect())) {
    echo "> Conectado com sucesso ao servidor teamspeak\n";
    $tsAdmin->login($teamspeakInfo['username'], $teamspeakInfo['password']);
    echo "> Logado com sucesso\n";
    $tsAdmin->selectServer($teamspeakInfo['portServer']);
    echo "> Servidor selecionado com sucesso ".$teamspeakInfo['portServer']."\n";
    $tsAdmin->setName($teamspeakInfo['displayname']);
    echo "> Nome alterado com sucesso para ".$teamspeakInfo['displayname']."\n";

    $connectionInfo = $tsAdmin->whoAmI()['data'];

    for(;;){
        $clientList = $tsAdmin->clientList("-country -ip -groups");
        
        foreach($clientList['data'] as $val) {
        $groups = explode(",", $val['client_servergroups'] );
        if(is_array($ignore_groups)){
            foreach($ignore_groups as $ig){
                if(in_array($ig, $groups) || ($val['client_type'] == 1)) {
                    continue;   
                }
            }
        }else{
            if(in_array($ignore_groups, $groups) || ($val['client_type'] == 1)) {
                continue;
            }
        }

        foreach($clientList['data'] as $client) {
            if ($listMode == 1) {
                $invalidCountry = false;
                foreach($blacklist as $blacklistCountry){
                    if ($client['client_country'] == $blacklistCountry || $client['client_country'] == "") {
                        switch ($clientType) {
                            case '1':
                                $invalidCountry = true;
                                break;

                            case '2':
                                if ($client['client_type'] == 0) {
                                    $invalidCountry = true;
                                }
                                break;

                            case '3':
                                if ($client['client_type'] == 1) {
                                    $invalidCountry = true;
                                }
                                break;
                        }
                    }
                }
            } else if ($listMode == 2) {
                $invalidCountry = true;
                foreach($whitelist as $whitelistCountry){
                    if ($client['client_country'] == $whitelistCountry) {
                        switch ($clientType) {
                            case '1':
                                $invalidCountry = false;
                                break;

                            case '2':
                                if ($client['client_type'] == 0) {
                                    $invalidCountry = false;
                                }
                                break;

                            case '3':
                                if ($client['client_type'] == 1) {
                                    $invalidCountry = false;
                                }
                                break;
                        }
                    }
                }
            }

            if ($invalidCountry && $connectionInfo['client_id'] != $client['clid']) {
                if ($punishMode == 1) {
                    $tsAdmin->clientKick($client['clid'], "server", $punishMessage);
                    echo "> Kickado com sucesso ".$client['client_nickname']." por ".$client['client_country']." -> ".$client['connection_client_ip']."\n";
                } else if ($punishMode == 2) {
                    $tsAdmin->banClient($client['clid'], 0, $punishMessage);
                    echo "> Banido com sucesso ".$client['client_nickname']." por ".$client['client_country']."\n";
                }
            }
        }
    }
}
}
?>
Sorry for bad English
 

kalle

high minded
VIP
Contributor
Joined
Oct 28, 2015
Messages
341
Points
118
Age
23
Location
Bosnia and Herzegovina
You messed up ignore group check. Why do you separate

foreach($clientList['data'] as $val) { $groups = explode(",", $val['client_servergroups'] ); if(is_array($ignore_groups)){ foreach($ignore_groups as $ig){ if(in_array($ig, $groups) || ($val['client_type'] == 1)) { continue; } } }else{ if(in_array($ignore_groups, $groups) || ($val['client_type'] == 1)) { continue; } }
and this?

foreach($clientList['data'] as $client) { if ($listMode == 1) { $invalidCountry = false; foreach($blacklist as $blacklistCountry){ if ($client['client_country'] == $blacklistCountry || $client['client_country'] == "") { switch ($clientType) { case '1': $invalidCountry = true; break; case '2': if ($client['client_type'] == 0) { $invalidCountry = true; } break; case '3': if ($client['client_type'] == 1) { $invalidCountry = true; } break; } } } } else if ($listMode == 2) { $invalidCountry = true; foreach($whitelist as $whitelistCountry){ if ($client['client_country'] == $whitelistCountry) { switch ($clientType) { case '1': $invalidCountry = false; break; case '2': if ($client['client_type'] == 0) { $invalidCountry = false; } break; case '3': if ($client['client_type'] == 1) { $invalidCountry = false; } break; } } } }
You need to check this in second foreach with same results. Less code that works.
Also use array_intersect to check two arrays, instead of looping them.
And you use in_array with array as a search parametar, idk if that is gonna work. Thats why you need to use array_intersect.

If I catch free time, will fix it for sure.
 

XARON

get over here!
Joined
Nov 24, 2016
Messages
124
Points
103
Location
Venus
have fun.

PHP:
/**
     * Created by PhpStorm.
     * User: XARON
     * Date: 22.11.2018
     * Time: 08:54
     */
    require_once('./ts3admin.class.php');
    $config = array(
            'blacklisted_countries' => array('GR'),
            'whitelisted_countries' => array('TR'),
            'ignored_groups' => array('2'),
            'punish_mode' => 1,
            'punish_message' => '>.<'
    );
    $query = new ts3admin('127.0.0.1', 10011);
    if($query->getElement('success', $query->connect())) {
        $query->login('serveradmin', 'password');
        $query->selectServer(9987);
        for(;;) {
            foreach($query->clientList('-country -ip -groups')['data'] as $k => $v) {
                if($v['client_type'] == 1) continue;
                if(!array_intersect($config['ignored_groups'], explode(',', $v['client_servergroups']))) {
                    if(in_array($v['client_country'], $config['blacklisted_countries']) && !in_array($v['client_country'], $config['whitelisted_countries'])) {
                        if($config['punish_mode'] == 1) {
                            $query->clientKick($v['clid'], 'server', $config['punish_message']);
                        } else {
                            $query->banClient($v['clid'], 0, $config['punish_message']);
                        }
                    }
                }
            }
        }
    }
 

Celso

Member
Joined
Oct 1, 2017
Messages
142
Points
59
Age
21
Location
Brasil
I have this error with the script

Code:
PHP Fatal error:  Maximum execution time of 30 seconds exceeded in /var/www/html/vpn/ts3admin.class.php on line 4944
 

XARON

get over here!
Joined
Nov 24, 2016
Messages
124
Points
103
Location
Venus
I have this error with the script

Code:
PHP Fatal error:  Maximum execution time of 30 seconds exceeded in /var/www/html/vpn/ts3admin.class.php on line 4944
Can u check connection? Because working fine.
 

XARON

get over here!
Joined
Nov 24, 2016
Messages
124
Points
103
Location
Venus
Yes, everything is working. I am trying to fix the error in the other script and testing this but this one has this error.
The codes in the other file are misspelled. You'il have a performance problem. Use my codes.
 

kalle

high minded
VIP
Contributor
Joined
Oct 28, 2015
Messages
341
Points
118
Age
23
Location
Bosnia and Herzegovina
I have this error with the script

Code:
PHP Fatal error:  Maximum execution time of 30 seconds exceeded in /var/www/html/vpn/ts3admin.class.php on line 4944
If you have safe mode off, set
set_time_limit(0);
for infinite execution.
 

Celso

Member
Joined
Oct 1, 2017
Messages
142
Points
59
Age
21
Location
Brasil
If you have safe mode off, set
set_time_limit(0);
for infinite execution.
Now the logs fail and the script still does not work.

Now no error appears in the logs and the script still does not work.
The script I posted that was created by you works, but the function I tried to ignore for some groups still does not work

---- Automatically Merged Double Post ----

now the script is in an infinite loop
 
Last edited:

kalle

high minded
VIP
Contributor
Joined
Oct 28, 2015
Messages
341
Points
118
Age
23
Location
Bosnia and Herzegovina
Now the logs fail and the script still does not work.

Now no error appears in the logs and the script still does not work.
The script I posted that was created by you works, but the function I tried to ignore for some groups still does not work

---- Automatically Merged Double Post ----

now the script is in an infinite loop
I didnt create this, and point is to create infinite loop. Without bot cant do whats usualy doing automatic, instead you need to manual run bot.
 

Celso

Member
Joined
Oct 1, 2017
Messages
142
Points
59
Age
21
Location
Brasil
Yes, sorry it actually was @Norvik who did this script.
what I said was you did that I tried to add to the code to ignore groups was this
 

kalle

high minded
VIP
Contributor
Joined
Oct 28, 2015
Messages
341
Points
118
Age
23
Location
Bosnia and Herzegovina
Idk whats problem with this script, I just tested and it works like a charm. Also ignore groups works here.
Its same code so I just added feature to kick people who use hook to cover country.

PHP:
<?php
/**
* Created by PhpStorm.
* User: XARON
* Date: 22.11.2018
* Time: 08:54
*/

// || $v['client_country'] == ""

require_once('./ts3admin.class.php');
$config = array(
        'blacklisted_countries' => array('BA'),
        'whitelisted_countries' => array('TR'),
        'ignored_groups' => array('1'),
        'punish_mode' => 1,
        'punish_message' => '>.<'
);
$query = new ts3admin('127.0.0.1', 10011);
if($query->getElement('success', $query->connect())) {
    $query->login('serveradmin', 'password');
    $query->selectServer(9987);
    for(;;) {
        foreach($query->clientList('-country -ip -groups')['data'] as $v) {
            if($v['client_type'] == 1) continue;
            if(!array_intersect($config['ignored_groups'], explode(',', $v['client_servergroups']))) {
                if(in_array($v['client_country'], $config['blacklisted_countries']) && !in_array($v['client_country'], $config['whitelisted_countries']) || $v['client_country'] == "") {
                    if($config['punish_mode'] == 1) {
                        $query->clientKick($v['clid'], 'server', $config['punish_message']);
                    } else {
                        $query->banClient($v['clid'], 0, $config['punish_message']);
                    }
                }
            }
        }
    }
}
?>
 
Last edited:

Top