Script setup help

Celso

Well-Known Member
Oct 1, 2017
142
47
119
I have a script that creates channels through my website, however I want to add cspacer at the time of creation, but as the creation has a standard cpid cspacer does not work because it is like a sub channel of a primary channel. there is some other way to specify which channel will be followed by where the channel will be created.


PHP:
if (Auth::isLoggedIn()) {
    $tsServer = TeamSpeakUtils::i()->getTSNodeServer();

    $channelGroups = $tsServer->channelGroupClientList(Config::get("channel_creator_admin_group"), null, Auth::getCldbid());
    $hasChannel = !empty($channelGroups);
    $creatorConfig = Config::get("channel_creator");

    if (!$hasChannel && isset($_POST["name"], $_POST["password"], $_POST["game"], $_POST["subchannels"])) {
        $res = createChannel();

        if (is_int($res)) {
            $successMessage = "Você criou seu próprio canal de jogos";
        } else if (is_string($res)) {
            $errorMessage = $res;
        }
    }
}

TemplateUtils::i()->renderTemplate("channelcreator", [
    "hasChannel" => @$hasChannel,
    "channelCreatorConfig" => @$creatorConfig,
    "successMessage" => @$successMessage,
    "errorMessage" => @$errorMessage
]);

function createChannel() {
    global $creatorConfig, $tsServer;
    
    $name = $_POST["name"];
    $password = $_POST["password"];
    $game = $_POST["game"];
    $subchannels = (int)$_POST["subchannels"];
    $names = $_POST["names"];

    if (mb_strlen($name) < 1 || mb_strlen($name) > 25) {
        return "Nome de canal inválido";
    }
        if (mb_strlen($names) < 1 || mb_strlen($names) > 25) {
        return "Nome do sub canal inválido";
    }

    if (mb_strlen($password) < 4 || mb_strlen($password) > 20) {
        return "Senha de canal inválida";
    }

    if ($subchannels > 4) {
        return "Número inválido de subcanais";
    }

    $configItem = null;

    foreach ($creatorConfig as $item) {
        if ($item["name"] === $game) {
            $configItem = $item;
            break;
        }
    }

    if ($configItem === null) {
        return "Invalido game selecionado";
    }

    try {
        $client = $tsServer->clientGetByDbid(Auth::getCldbid());
    } catch (\TeamSpeak3_Exception $e) {
        return "Você precisa estar online no servidor TeamSpeak para criar um canal";
    }

    $channelName = $configItem["prefix"] . $name;


    try {
        $tsServer->channelGetByName($channelName);

        // no exception = channel already exists
        return "Já existe um canal com esse nome, escolha outro";
    } catch (\TeamSpeak3_Exception $e) {
        // good
    }
    
    // start creating stuff!
     date_default_timezone_set('America/Sao_Paulo');
                     $unixTime = time();
                    $realTime = date('[d-m-Y]-[H:i]',$unixTime);
    $properties = [
        "channel_flag_permanent" => true,
        "channel_flag_password" => true,
        "channel_topic" => "NEO Ts3 agradece a preferência!",
        "channel_password" => $password,
        "channel_flag_maxfamilyclients_inherited" => 0,
        "channel_flag_maxfamilyclients_unlimited" => 1,
        "channel_description" => '[center][b][u]'.$channelName.'[/u][/b][/center][hr][b][list][*]Data e hora que foi criado: '.$realTime.'[*]Criador: '.$client.'[/list][/b]',
   ];
    
       date_default_timezone_set('America/Sao_Paulo');
                     $unixTime = time();
                    $realTime = date('[d-m-Y]-[H:i]',$unixTime);

    // create private channel
            $cpid = $tsServer->channelCreate(array(
            "channel_name" => "[*spacer".rand(1,10000)."]_", //nome do canal aqui
            "channel_password" => $password, //você pode deixar ele sem senha ou deixar a mesma senha de família do canal
            "channel_flag_permanent" => TRUE, //Não permanente
            "cpid"                  => $configItem["parentCid"], //ID do Canal criado '
            "channel_flag_permanent" => TRUE //Canal semi-permanente para alterar permanente = ''channel_flag_permanent''
            ));
            
    $pid = $tsServer->channelCreate($properties + [
        "channel_name" => mb_substr($channelName, 0, 40),
        "cpid" => $configItem["parentCid"]
    ]);

    // icon for main channel
    //$tsServer->channelPermAssign($pid, "i_icon_id", $configItem["iconId"]);

    for ($i = 1; $i <= $subchannels; $i++) {
        $sid = $tsServer->channelCreate($properties + [
            "channel_name" => "$names #$i",
            "cpid" => $pid
        ]);

        // icon for subchannel
        //$tsServer->channelPermAssign($sid, "i_icon_id", $configItem["iconId"]);
    }

            

  $client->setChannelGroup($pid, Config::get("channel_creator_admin_group"));
    $client->move($pid);

    return $pid;
}

SQL:
[
    {
        "name": "Counter-Strike: Global Offensive",
        "parentCid": 55,
        "prefix": "CS:GO | ",
        "iconId": 2101350922
    },
    {
        "name": "GTA V",
        "parentCid": 58,
        "prefix": "GTA V | ",
        "iconId": 3509749744
    },
    {
        "name": "League of Legends",
        "parentCid": 61,
        "prefix": "LOL | ",
        "iconId": 3509749744
    },


    {
        "name": "VALORANT",
        "parentCid": 64,
        "prefix": "VALORANT | ",
        "iconId": 3509749744
    },

    {
        "name": "PUBG",
        "parentCid": 68,
        "prefix": "PUBG | ",
        "iconId": 3509749744
    },

    {
        "name": "BATTLEFIELD",
        "parentCid": 71,
        "prefix": "FIELD | ",
        "iconId": 3509749744
    },

    {
        "name": "TIBIA",
        "parentCid": 111,
        "prefix": "TIBIA | ",
        "iconId": 3509749744
    },

    {
        "name": "FORTNITE",
        "parentCid": 114,
        "prefix": "FORTNITE | ",
        "iconId": 3509749744
    },

    {
        "name": "OUTROS",
        "parentCid": 74,
        "prefix": "OUTROS | ",
        "iconId": 3509749744
 },

     {
        "name": "Teste",
        "parentCid": 84,
        "prefix": "teste| ",
        "iconId": 3509749744
    }

]


Thanks in advance
 

Yousef

Active Member
Nov 16, 2017
36
9
83
can u give me your teamspeak test server and explain to me what do you need to do ?
 

Celso

Well-Known Member
Oct 1, 2017
142
47
119
Hey!


Of course, I will send you private message
 
Top