script can not find some members

Celso

Well-Known Member
Oct 1, 2017
142
47
119
Hello, I use this script on my site for members to assign tags.
some members the script can not find it on teamspeak. wanted to know if this is a bug or a bug in the script or something in the pc / network configuration of the members.

PHP:
try {
    $tsAdmin = getTeamspeakConnection("#no_query_clients");
    $tsAdmin->selfUpdate(["client_nickname" => $botname]);

    $userip = $_SERVER["REMOTE_ADDR"];

    if($userip === "::1")
        $userip = "127.0.0.1";

    $clients = $tsAdmin->clientList(["connection_client_ip" => $userip]);
    $servergroups = $tsAdmin->serverGroupList();

    if(!empty($clients)) {
        $client = array_values($clients)[0];
        $clientgroups = explode(",", $client["client_servergroups"]);
    }

    if(isset($client)) {
        $cacheutils = new CacheUtils('logincodes-' . $client["client_database_id"]);

        if(empty($_SESSION["loggedin"])) {
            if($cacheutils->isExpired()) {
                $logincode = mt_rand(100, 999);
                $client->poke(translate($lang["groupassigner"]["codepoke"], [$logincode]));
                $cacheutils->setValue($logincode, 120);
            } else {
                $logincode = $cacheutils->getValue();
            }

            if(!empty($_POST["logincode"])) {
                if($logincode === (int)$_POST["logincode"]) {
                    $cacheutils->remove();
                    $_SESSION["loggedin"] = true;
                } else {
                    $failedlogin = true;
                }
            }
        }

        if(!empty($_POST["submitted"]) && !empty($_SESSION["loggedin"])) {
            $allgroups = [];

            foreach ($assignerconfig as $item) {
                foreach ($item["sgids"] as $sgid) {
                    if(!in_array($sgid, $allgroups))
                        $allgroups[] = (int)$sgid;
                }
            }

            $submittedgroups = [];

            if(!empty($_POST["sgs"]) && is_array($_POST["sgs"])) {
                foreach ($_POST["sgs"] as $sg) {
                    $submittedgroups[] = (int)$sg;
                }
            }

            $groupsremove = array_diff($allgroups, $submittedgroups);

            foreach ($groupsremove as $grid) {
                try {
                    $client->remServerGroup((int)$grid);
                } catch (Exception $e) {}
            }

            foreach ($submittedgroups as $gaid) {
                try {
                    if(in_array($gaid, $allgroups)) {
                        $client->addServerGroup((int)$gaid);
                    }
                } catch (Exception $e) {}
            }

            $client = $tsAdmin->clientGetByDbid($client["client_database_id"]); // refresh
            $clientgroups = explode(",", $client["client_servergroups"]);

            $success = true;
        }
    }
} catch (Exception $e) {
    echo "Connection failed! $e";
}
?>
 

Asphyxia

Owner
Administrator
Apr 25, 2015
1,844
2
2,197
327
@Celso could you kindly provide more information to us? Like do you notice this happens specifically with users containing a (, or maybe a comma, and even perhaps other wild special characters? The more information you could provide us, the easier to troubleshoot.

I skimmed the code quickly, but without knowing for example the variable name I need to look at, (I would assume client or nickname).. I would be playing a guessing game.

So if you could certainly offer up a little more info I will happily help you ;)

P.S. maybe some of your groups have special characters too? Do not overlook any details, the more information - the easier to help!
 

kalle

high minded
Contributor
Oct 28, 2015
411
253
178
Like always users can fake in input almost everything. If you check user IP on TS I think that user can hide IP adress with TS3 Hook. So check users IP or what else you are using (didnt looked at the code).
 

Celso

Well-Known Member
Oct 1, 2017
142
47
119
@Celso could you kindly provide more information to us? Like do you notice this happens specifically with users containing a (, or maybe a comma, and even perhaps other wild special characters? The more information you could provide us, the easier to troubleshoot.

I skimmed the code quickly, but without knowing for example the variable name I need to look at, (I would assume client or nickname).. I would be playing a guessing game.

So if you could certainly offer up a little more info I will happily help you ;)

P.S. maybe some of your groups have special characters too? Do not overlook any details, the more information - the easier to help!

Hello, thank you for replying to me and sorry for the delay. end of the year I have no time to enter the computer.
this weekend I stopped to do some tests and not one of them worked out. this only happens with some members and is random.
the script simply ignores some members.

I can send you the complete script for you, I think it would be easier for you to see if you encounter any problems.

Like always users can fake in input almost everything. If you check user IP on TS I think that user can hide IP adress with TS3 Hook. So check users IP or what else you are using (didnt looked at the code).

I use the ts3 hook and I can use the wizard. That's not the problem. I believe it may be some configuration on the member's computer.

I'm going to have some free time this week and I'm going to get in touch with some members who have the problem to try to understand why.
 

Celso

Well-Known Member
Oct 1, 2017
142
47
119
I'll post the complete code, I find it easier to find the bug.

PHP:
<?php
require_once __DIR__ . "/include/header.php";
require_once __DIR__ . "/include/tsutils.php";
require_once __DIR__ . "/include/cacheutils.class.php";
require_once __DIR__ . "/config/assignerconfig.php";

$clientgroups = [];


//
//if($cacheutils->isExpired()) {
//    $cacheutils->setValue([getBanlist(), date('d.m.Y H:i:s')], 300);
//}
//
//$banlist = $cacheutils->getValue();

try {
    $tsAdmin = getTeamspeakConnection("#no_query_clients");
    $tsAdmin->selfUpdate(["client_nickname" => $botname]);

    $userip = $_SERVER["REMOTE_ADDR"];

    if($userip === "::1")
        $userip = "127.0.0.1";

    $clients = $tsAdmin->clientList(["connection_client_ip" => $userip]);
    $servergroups = $tsAdmin->serverGroupList();

    if(!empty($clients)) {
        $client = array_values($clients)[0];
        $clientgroups = explode(",", $client["client_servergroups"]);
    }

    if(isset($client)) {
        $cacheutils = new CacheUtils('logincodes-' . $client["client_database_id"]);

        if(empty($_SESSION["loggedin"])) {
            if($cacheutils->isExpired()) {
                $logincode = mt_rand(100, 999);
                $client->poke(translate($lang["groupassigner"]["codepoke"], [$logincode]));
                $cacheutils->setValue($logincode, 120);
            } else {
                $logincode = $cacheutils->getValue();
            }

            if(!empty($_POST["logincode"])) {
                if($logincode === (int)$_POST["logincode"]) {
                    $cacheutils->remove();
                    $_SESSION["loggedin"] = true;
                } else {
                    $failedlogin = true;
                }
            }
        }

        if(!empty($_POST["submitted"]) && !empty($_SESSION["loggedin"])) {
            $allgroups = [];

            foreach ($assignerconfig as $item) {
                foreach ($item["sgids"] as $sgid) {
                    if(!in_array($sgid, $allgroups))
                        $allgroups[] = (int)$sgid;
                }
            }

            $submittedgroups = [];

            if(!empty($_POST["sgs"]) && is_array($_POST["sgs"])) {
                foreach ($_POST["sgs"] as $sg) {
                    $submittedgroups[] = (int)$sg;
                }
            }

            $groupsremove = array_diff($allgroups, $submittedgroups);

            foreach ($groupsremove as $grid) {
                try {
                    $client->remServerGroup((int)$grid);
                } catch (Exception $e) {}
            }

            foreach ($submittedgroups as $gaid) {
                try {
                    if(in_array($gaid, $allgroups)) {
                        $client->addServerGroup((int)$gaid);
                    }
                } catch (Exception $e) {}
            }

            $client = $tsAdmin->clientGetByDbid($client["client_database_id"]); // refresh
            $clientgroups = explode(",", $client["client_servergroups"]);

            $success = true;
        }
    }
} catch (Exception $e) {
    echo "Connection failed! $e";
}
?>

<style>
    .bootstrap-select.btn-group .dropdown-menu .notify {
        color: #ebebeb;
        text-align: center;
        background-color: #d9534f;
        border: none;
    }

    .bootstrap-select.btn-group .dropdown-menu li a {
        /*margin: 3px 0;*/
        font-size: 16px;
    }

    .ga-icon {
        max-height: 16px;
        max-width: 16px;
        margin-right: 3px;
    }

    .bootstrap-select > .btn {
        background-color: #39444e;
    }

    .group-label {
        font-size: 24px;
    }

    .group-label .label {
        font-size: 14px;
        margin-top: 7px;
    }

    .ga-group {
        margin-bottom: 15px;
    }
</style>

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-picture-o" aria-hidden="true"></i> <?php tl($lang["groupassigner"]["title"]); ?></h3>
    </div>
    <div class="panel-body">
        <?php if(isset($success)) { ?>
            <div class="alert alert-success">
                <?php tl($lang["groupassigner"]["success"]) ?>
            </div>
        <?php } ?>

        <?php if (!isset($client)) { ?>
            <script>
                setTimeout(function () {
                    location.reload()
                }, 5000);
            </script>
            <div class="text-center">
                <h3><?php tl($lang["groupassigner"]["connectbeforeusing"]) ?></h3>
                <a class="btn btn-info" href="<?php echo "ts3server://" . $config['teamspeak']['displayip'] ?>"><i class="fa fa-sign-in"></i> <?php tl($lang["groupassigner"]["joints"]) ?></a>
            </div>
        <?php } else if (empty($_SESSION["loggedin"])) { ?>
            <div class="text-center">
                <h3><?php tl($lang["groupassigner"]["entercode"]) ?></h3>
                <form method="post">
                    <div class="row">
                        <div class="col-md-6 col-md-offset-3">
                            <div class="input-group">
                                <input name="logincode" type="number" class="form-control" placeholder="<?php tl($lang["groupassigner"]["logincode"]) ?>" required autofocus autocomplete="off">
                                <span class="input-group-btn">
                                <button class="btn btn-info">
                                    <i class="fa fa-arrow-right" style="margin: 0" aria-hidden="true"></i>
                                </button>
                            </span>
                            </div>
                        </div>
                    </div>
                </form>
                <?php if(isset($failedlogin)) { ?>
                <div class="alert alert-danger" style="display: inline-block; margin-top: 15px">
                    <?php tl($lang["groupassigner"]["failedlogin"]) ?>
                </div>
                <?php } ?>
            </div>
        <?php } else { ?>
            <form method="post">
                <?php foreach ($assignerconfig as $item) { ?>
                    <div class="ga-group">
                        <p class="group-label">
                            <?php echo $item["name"] ?><span class="label label-info pull-right"><?php tl($lang["groupassigner"]["limit"], [$item["limit"]]) ?></span>
                        </p>

                        <select name="sgs[]" class="selectpicker" multiple data-live-search="true" data-max-options="<?php echo $item["limit"] ?>" data-width="100%">
                            <?php
                            foreach ($item["sgids"] as $sgid) {
                                if (!isset($servergroups[$sgid])) continue;

                                $sg = $servergroups[$sgid];
                                $name = (string)$sg["name"];
                                $icon = $tsAdmin->serverGroupGetById($sgid)->iconDownload();
                                $iconhtml = '';

                                if ($icon)
                                    $iconhtml = 'data:' . TeamSpeak3_Helper_Convert::imageMimeType($icon) . ';base64,' . base64_encode($icon);
                                ?>
                                <option value="<?php echo $sgid ?>" data-content="<img class='ga-icon' src='<?php echo $iconhtml ?>'></img> <?php echo $name ?>"></option>
                            <?php } ?>
                        </select>
                    </div>
                <?php } ?>
                <input name="submitted" value="true" hidden>
                <button class="btn btn-primary btn-block" style="margin-top: 3rem"><i class="fa fa-floppy-o" aria-hidden="true"></i> <?php tl($lang["groupassigner"]["save"]) ?></button>
            </form>
        <?php } ?>
    </div>
</div>

<?php
require_once __DIR__ . "/include/footer.php";
?>

<script>
    $('.selectpicker').selectpicker('val', <?php echo json_encode($clientgroups) ?>);
</script>

PHP:
<?php

// You must leave the random number at the end!
$botname = "RankBot-" . mt_rand(10000, 99999);

$assignerconfig = [
    [
        "name" => "Sex",
        "limit" => 1,
        "sgids" => [47, 48]
    ],
    [
        "name" => "Age",
        "limit" => 1,
        "sgids" => [463, 37, 464, 38, 39, 468]
    ],
    [
        "name" => "Elo",
        "limit" => 1,
        "sgids" => [484, 103, 104, 105, 106, 106, 108, 109, 110]
    ],
    [
        "name" => "Jogos",
        "limit" => 5,
        "sgids" => [17, 18, 19, 20, 21]
    ]
];

I will also leave here my site, where I use the wizard, who has some time and wants to test and see if you can find out why some members are not recognized by the bot. site
 
Top