planetteamspeak / ts3phpframework

Modern use-at-will framework that provides individual components to manage TeamSpeak 3 Server instances
https://www.planetteamspeak.com
GNU General Public License v3.0
211 stars 59 forks source link

Creating channel with an icon #108

Closed realKitsune closed 6 years ago

realKitsune commented 6 years ago

Hello.

I'm trying to make a one-click button to create a private channel. Here is my actual code:

    $ts3_VirtualServer->channelCreate(array('channel_flag_maxclients_unlimited' => TRUE, 'channel_codec_quality' => 10, 'channel_codec' => TeamSpeak3::CODEC_OPUS_VOICE, 'channel_flag_semi_permanent' => TRUE, 'channel_name' => 'Salon privé de '.$info_isOnlineName, 'channel_topic' => $info_isOnlineProfile, 'channel_icon_id' => $iconeid, 'channel_description' => 'Ceci est la description par défaut. Channel créé le: '.date("d/m/y H:i").' par '.$info_isOnlineName.' [#'.$info_isOnlineDbID.']'));
    $privateChannelList = $ts3_VirtualServer->channelList($privateChannelFilters); 
    foreach ($privateChannelList as $privChannelCount) {
        if($privChannelCount['channel_topic'] == $info_isOnlineProfile){ 
            $ownChannel_cid = $privChannelCount['cid'];
        }
    }

    $ts3_VirtualServer->clientGetByDbid($info_isOnlineDbID)->setChannelGroup($ownChannel_cid, 27);
    $ts3_VirtualServer->clientGetByDbid($info_isOnlineDbID)->move($ownChannel_cid);

'channel_icon_id' => $iconeid is set : $iconeid = -1452005422;

I checked the icon_id by setting it manually on a channel then checked with 'channel_icon_id' and it's -1452005422. The code works if I remove the icon id flag, it doesn't work when I add it.

Need some help here :)

ronindesign commented 6 years ago

Interesting, I'll have to test this locally.

I know there's some specific handling regarding the icon_id, something about max int, signed, etc and some special handling (i.e. this is why there is a negative sign). I'm not sure if this is the issue you're running into (you could search the forums for related issue with icon_id), but it may also be there is a problem with the channelCreate() logic.

In the meantime, as a testing step, you might also try:

snegrini commented 6 years ago

I was testing this in the morning using directly the ServerQuery (via SSH) and a "convert error" was returned (using both positive and negative iconid). The problem seems to be related to the ServerQuery directly, not this framework. Though, my test finishes here, I had no more time to investigate better.

ronindesign commented 6 years ago

Awesome, thanks for the insight @snegrini.

I remember correctly, there's specifically some conversion logic when mapping icon_ids between server <--> client.

I believe Janni goes into this a bit on his Redeemer / YaTQA site somewhere... Here is a post discussing it (unsure if this is still an issue in the framework): https://forum.teamspeak.com/threads/54132-API-TS3-PHP-Framework?p=416546#post416546

In any case, I'll still try to reproduce via framework, would be a great opportunity to add unit tests for icon management.

ronindesign commented 6 years ago

Also of possible relevance: https://forum.teamspeak.com/threads/54132-API-TS3-PHP-Framework?p=453588#post453588

ronindesign commented 6 years ago

I'm also finding lots of examples where setting channel_icon_id on channel creation is not working:

      $ts3->message("Přidávám dodatečné místnosti...");
      global $chann1, $chann2, $chann3;
      try {
      $chann1 = $ts3->channelCreate(array (
  "channel_name"           => "Additional public room #1",
  "channel_topic"          => "",
  "channel_codec"          => TeamSpeak3::CODEC_OPUS_VOICE,
  "channel_codec_quality"  => 6,
  "channel_flag_permanent" => TRUE,
  "channel_order"          => 370,
  //"channel_icon_id"        => 1513344601,
));
      $chann2 = $ts3->channelCreate(array (
  "channel_name"           => "Additional public room #2",
  "channel_topic"          => "",
  "channel_codec"          => TeamSpeak3::CODEC_OPUS_VOICE,
  "channel_codec_quality"  => 6,
  "channel_flag_permanent" => TRUE,
  //"channel_icon_id"        => 1031730392, //NOT working ATM, need to fix
  "channel_order"          => $chann1,
));}

At this point, it's seems a lot like, while channel_icon_id is a valid server property, it may be that server query does not accept it via channelcreate command. [ref]

I would recommend trying to set icon_id manually after creating channel and see if this works.

realKitsune commented 6 years ago

Doesn't work also with

$ts3_VirtualServer->execute("channeledit", array("cid" => $ownChannel_cid, "channel_icon_id" => -1452005422));

So this value can be grabbed with query but not modified?

Setting it manually works fine but that would not help. Is there a way then like uploading an icon and setting it directly to the channel with the API? Has someone did it before?

realKitsune commented 6 years ago
$ts3_VirtualServer->execute("channeledit", array("cid" => $ownChannel_cid, "channel_icon_id" =>  1646637303));

Seems to work fine, I think that might be related to negative value of icon_id.

EDIT:

After some tests, it works with positive values of icon_id when using channelEdit

ronindesign commented 6 years ago

Does channelCreate() work using those same positive values?

If so, this would clearly indicate that there is an issue with the negative numbers.

I'm almost positive this is a classic issue, as I've ran into it a couple times myself, but I thought it was resolved.

snegrini commented 6 years ago

This link could help: https://yat.qa/ressourcen/definitionen-und-algorithmen/#icons It seems that channeledit wants a unsigned value.

realKitsune commented 6 years ago

Does channelCreate() work using those same positive values?

If so, this would clearly indicate that there is an issue with the negative numbers.

I'm almost positive this is a classic issue, as I've ran into it a couple times myself, but I thought it was resolved.

No it doesn't seems to work, only when using channeledit and negative numbers.

svenpaulsen commented 6 years ago

That's the reason I added TeamSpeak3_Helper_Convert::iconId() a while ago... Also, please note that the icon ID is actually a channel permission. There are a few commands where setting the icon ID will work for convenience (if it has been implemented in the TeamSpeak Server)... but I'm not sure if channelcreate is one of those.

I'd recommend setting the channel permission after the channel was created. Here's an example:

$channel_id = $server->channelCreate($args);
$icon_id    = TeamSpeak3_Helper_Convert::iconId(-123);

$server->channelPermAssign($channel_id, "i_icon_id", $icon_id);
ronindesign commented 6 years ago

Looks like this solution should work for you. If you're still having issues, please let us know!

EDIT: todo - add example of icon conversion to wiki.

realKitsune commented 6 years ago

That's the reason I added TeamSpeak3_Helper_Convert::iconId() a while ago... Also, please note that the icon ID is actually a channel permission. There are a few commands where setting the icon ID will work for convenience (if it has been implemented in the TeamSpeak Server)... but I'm not sure if channelcreate is one of those.

I'd recommend setting the channel permission after the channel was created. Here's an example:

$channel_id = $server->channelCreate($args);
$icon_id    = TeamSpeak3_Helper_Convert::iconId(-123);

$server->channelPermAssign($channel_id, "i_icon_id", $icon_id);

Just to note: this method still gives me a negative number which doesn't work. But now it works for my solution. I edited a pixel of the image to change icon_id and I got a positive id.

ronindesign commented 6 years ago

Thanks for the report, I'll keep this on the list for testing so we can make sure to iron out how it behaves.

Glad you got it working with a workaround!