(PHP) if User IP = xxx -> Servergroup

h1web

VIP
Joined
Sep 2, 2015
Messages
133
Points
66
Location
Germany
Hey,

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

ewenjo

That norwegian guy
Joined
Dec 14, 2016
Messages
67
Points
57
Location
Norway
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:

TheHenker

Member
Joined
Apr 24, 2016
Messages
21
Points
38
Age
25
Location
Germany
Maybe something like this:

You do not have permission to view link Log in or register now.


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
Joined
Sep 2, 2015
Messages
133
Points
66
Location
Germany
Thanks buddy!

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

TheHenker

Member
Joined
Apr 24, 2016
Messages
21
Points
38
Age
25
Location
Germany
I used an older version of ts3admin class.

you can get my class file here:
You do not have permission to view link Log in or register now.


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

h1web

VIP
Joined
Sep 2, 2015
Messages
133
Points
66
Location
Germany
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:
You do not have permission to view link Log in or register now.


*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:
 

TheHenker

Member
Joined
Apr 24, 2016
Messages
21
Points
38
Age
25
Location
Germany
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
Joined
Oct 28, 2015
Messages
324
Points
118
Age
23
Location
Bosnia and Herzegovina
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:[email protected]$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;
        }
    }  
}
You do not have permission to view link Log in or register now.
 
Last edited:

Top