(PHP) if User IP = xxx -> Servergroup

h1web

VIP
Sep 2, 2015
206
134
131
Hey,

is there any script available that sets a specific Servergroup, whenever a user that connects has IP "xxx.xxx.xxx.xx" ? :)
 
E

ewenjo

I don't know if there is a specific script that does that exact thing, but It's not hard to make if you need it.
 
Last edited by a moderator:

Flare

There's a place downtown.
VIP
Apr 24, 2016
34
24
98
Maybe something like this:

https://files.flareco.net/a/5sxw9.php.txt

PHP:
<?php

session_start();
require_once 'ts3admin.class.php';
$botname = "FLARECOAPI"; //Website Name
$ts3ip = "127.0.0.1"; //TS3IP
$ts3port = "9987"; //TS3Port
$ts3qport = "10011"; //TS3Query Port
$ts3user = "serveradmin"; //TS3User Login
$ts3pass = ""; //TS3Query Login



$appendrankgroupid = ""; // ID OF THE GROUP YOU WANT TO ADD TO THE IP!

$tsAdmin = new ts3admin($ts3ip, $ts3qport);
       
if($tsAdmin->getElement('success', $tsAdmin->connect())) {
    $tsAdmin->login($ts3user, $ts3pass);
    $tsAdmin->setName($botname);
    $tsAdmin->selectServer($ts3port);
    $clients = $tsAdmin->clientList("-uid -ip -groups -info");
           
    foreach($clients['data'] as $client) {
        $cname = $client['client_nickname'];
        $ip = $client['connection_client_ip'];
        $uid = $client['client_unique_identifier'];
        $groups = $client['client_servergroups'];
        $version = $client['client_version'];
        $platform = $client['client_platform'];
        $clid = $client['clid'];
        $cid = $client['cid'];
        $dbid = $client['client_database_id'];
        $time = time();
       
       
        // IP PART
       
        if($ip == ""){ // INSERT YOUR IP HERE!
            $appendrank = $tsAdmin->serverGroupAddClient($appendrankgroupid, $dbid);
        }
       
    }
    echo "RUN COMPLETED! ".time();
    exit;
} else {
    die("CONNECTION FAILED");
}


?>

*EDIT:
You need to run it as a cronjob every minute.
 

h1web

VIP
Sep 2, 2015
206
134
131
Thanks buddy!

EDIT: seems like its not working :/
 
Last edited:

h1web

VIP
Sep 2, 2015
206
134
131
Did you add the "ts3admin.class.php" lib file? It's common for users to forget adding the libs ;)
Yep, i've done that!

I used an older version of ts3admin class.

you can get my class file here:
https://files.flareco.net/a/ts3admin.class.php.txt

*You need to rename the file to ts3admin.class.php after downloading

I've used the original, last one from the official website, because i use that script on a TeaSpeak Server :)

EDIT: hm, your's also not working :eek:
 

Flare

There's a place downtown.
VIP
Apr 24, 2016
34
24
98
Yep, i've done that!



I've used the original, last one from the official website, because i use that script on a TeaSpeak Server :)

EDIT: hm, your's also not working :eek:

Everything works for me.
Maybe you can send me a screenshot of the error. (enable php log errors)
 

kalle

high minded
Contributor
Oct 28, 2015
411
253
178
Try this. Framework by ScP.

PHP:
<?php

require_once('TeamSpeak3/TeamSpeak3.php');

$ts3_host = "localhost";
$ts3_q_port = "10011";
$ts3_s_port = "9987";
$ts3_username = "serveradmin";
$ts3_password = "9kg6eRKk";
$ts3_nick = "R4P3.net";

$selectedOnes = array('127.0.0.1');
$group = '7';


$ts3 = TeamSpeak3::factory("serverquery://$ts3_username:$ts3_password@$ts3_host:$ts3_q_port/?server_port=$ts3_s_port&blocking=0");
$ts3->selfUpdate(array('client_nickname'=> $ts3_nick));

TeamSpeak3_Helper_Signal::getInstance()->subscribe("serverqueryWaitTimeout", "onWaitTimeout");
TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyCliententerview", "onClientEnterView");

$ts3->notifyRegister("server");



while(1)
{
    $ts3->getAdapter()->wait();
}

function onWaitTimeout($time, TeamSpeak3_Adapter_Abstract $adapter)
{
    if($adapter->getQueryLastTimestamp() < time()-300)
    {
        $adapter->request('clientupdate');
    }
}


function onClientEnterView(TeamSpeak3_Adapter_ServerQuery_Event $event){

    global $group;
    global $ts3;
    global $selectedOnes;

    $userInfo = $event->getData();
    $client = $ts3->clientGetByDbId($userInfo['client_database_id']);
    $groups = array_filter(explode(',', $client->client_servergroups));
   
    if(in_array($client->connection_client_ip, $selectedOnes)){

        if(in_array($group, $groups, TRUE)){
           
            return;  
        }else{

            $ts3->serverGroupClientAdd($group,$userInfo['client_database_id']);
            return;
        }
    }  
}

https://gist.github.com/kallefrombosnia/06ec96047b26f5a54d0385f5a24f28db
 
Last edited:
Top