Auto assign icon per country

Status
Not open for further replies.

Junichirou

Member
Sep 22, 2015
4
0
56
Greetings friends, I would like to know if it is possible to create a script that assigns an icon automatically depending on the country of the person,
Following by example the lock code created by a r4p3 user
Code:
<?PHP
// Teamspeak config
$teamspeakInfo = array(
    'username' => 'serveradmin',
    'password' => 'your password',
    'host' => '127.0.0.1',
    'portQuery' => '10011',
    'portServer' => '9987',
    'displayname' => 'R4P3.NET'
);

$blacklist = array('DE'); // array('DE', 'HU');
$whitelist = array('DE'); // array('DE', 'HU');
$clientType = 2; // 1 = Everyone, 2 = Ignore Query, 3 = Ignore Clients
$listMode = 1; // 1 = blacklist, 2 = whitelist
$punishMode = 1; // 1 = kick, 2 = ban
$punishMessage = 'Your country is not allowed to join our server.'; // Message the user will see once he got kicked/banned

/*
|--------------------------------------------------------------------------------
|   Do not modify anything below this area unless you know what you're doing.
|--------------------------------------------------------------------------------
*/

echo "|--------------------------------------|\n|      Disallow specific countries     |\n|--------------------------------------|\n";
require_once("ts3admin.class.php");
$tsAdmin = new ts3admin($teamspeakInfo['host'], $teamspeakInfo['portQuery']);

if($tsAdmin->getElement('success', $tsAdmin->connect())) {
    echo "> Successfully connected to the teamspeak server\n";
    $tsAdmin->login($teamspeakInfo['username'], $teamspeakInfo['password']);
    echo "> Successfully logged in\n";
    $tsAdmin->selectServer($teamspeakInfo['portServer']);
    echo "> Successfully selected server ".$teamspeakInfo['portServer']."\n";
    $tsAdmin->setName($teamspeakInfo['displayname']);
    echo "> Successfully changed name to ".$teamspeakInfo['displayname']."\n";

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

    for(;;){
        $clients = $tsAdmin->clientList("-country -ip");

        foreach($clients['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 "> Successfully kicked ".$client['client_nickname']." from ".$client['client_country']." -> ".$client['connection_client_ip']."\n";
                } else if ($punishMode == 2) {
                    $tsAdmin->banClient($client['clid'], 0, $punishMessage);
                    echo "> Successfully banned ".$client['client_nickname']." from ".$client['client_country']."\n";
                }
            }
        }
    }
} else {
    die('Connection could not be established.');
}
?>
 

Mr_omar

Active Member
Jan 5, 2017
83
33
68
Greetings friends, I would like to know if it is possible to create a script that assigns an icon automatically depending on the country of the person,
Following by example the lock code created by a r4p3 user
Code:
<?PHP
// Teamspeak config
$teamspeakInfo = array(
    'username' => 'serveradmin',
    'password' => 'your password',
    'host' => '127.0.0.1',
    'portQuery' => '10011',
    'portServer' => '9987',
    'displayname' => 'R4P3.NET'
);

$blacklist = array('DE'); // array('DE', 'HU');
$whitelist = array('DE'); // array('DE', 'HU');
$clientType = 2; // 1 = Everyone, 2 = Ignore Query, 3 = Ignore Clients
$listMode = 1; // 1 = blacklist, 2 = whitelist
$punishMode = 1; // 1 = kick, 2 = ban
$punishMessage = 'Your country is not allowed to join our server.'; // Message the user will see once he got kicked/banned

/*
|--------------------------------------------------------------------------------
|   Do not modify anything below this area unless you know what you're doing.
|--------------------------------------------------------------------------------
*/

echo "|--------------------------------------|\n|      Disallow specific countries     |\n|--------------------------------------|\n";
require_once("ts3admin.class.php");
$tsAdmin = new ts3admin($teamspeakInfo['host'], $teamspeakInfo['portQuery']);

if($tsAdmin->getElement('success', $tsAdmin->connect())) {
    echo "> Successfully connected to the teamspeak server\n";
    $tsAdmin->login($teamspeakInfo['username'], $teamspeakInfo['password']);
    echo "> Successfully logged in\n";
    $tsAdmin->selectServer($teamspeakInfo['portServer']);
    echo "> Successfully selected server ".$teamspeakInfo['portServer']."\n";
    $tsAdmin->setName($teamspeakInfo['displayname']);
    echo "> Successfully changed name to ".$teamspeakInfo['displayname']."\n";

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

    for(;;){
        $clients = $tsAdmin->clientList("-country -ip");

        foreach($clients['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 "> Successfully kicked ".$client['client_nickname']." from ".$client['client_country']." -> ".$client['connection_client_ip']."\n";
                } else if ($punishMode == 2) {
                    $tsAdmin->banClient($client['clid'], 0, $punishMessage);
                    echo "> Successfully banned ".$client['client_nickname']." from ".$client['client_country']."\n";
                }
            }
        }
    }
} else {
    die('Connection could not be established.');
}
?>
Just make servergroup for each country on the whitelist example:
PHP:
if ($client['client_country'] == $whitelistCountry ) {
$client->addservergroup(88); // 88 = Country servergroup id
:D
 

Kleberstoff

Knowledge Seeker
VIP
Dec 29, 2015
308
214
158
First of all, i gonna yell at you for posting this in the wrong section.
correct section would be: https://r4p3.net/forums/script-requests.169/
also adjust it to this: https://r4p3.net/threads/read-before-requesting.2391/
/Move Request

Example Code because i'm lazy.
Code:
if($client['client_country'] == "DE")
{
$client->addservergroup(1); //Servergroup for German Country
}
if($client['client_country'] == "UK")
{
$client->addservergroup(1); //Servergroup for the UK Country
}
do that for each Country
//could also use case but it's only an example.
edit: or use omar's code to add it a client icon
 

Norvik

Retired Staff
Contributor
Jul 18, 2015
635
588
157
Code:
if($client['client_country'] == "DE")
{
$client->addservergroup(1); //Servergroup for German Country
}
if($client['client_country'] == "UK")
{
$client->addservergroup(1); //Servergroup for the UK Country
}
do that for each Country
//could also use case but it's only an example.
edit: or use omar's code to add it a client icon
[/spoiler]
Using a switch would be way better in that case.

/Moved
/Closed -> Please follow the request template
 
Status
Not open for further replies.
Top