Multivit4min / TS3-NodeJS-Library

TeamSpeak 3 Server Query Library supports SSH and RAW Query
https://multivit4min.github.io/TS3-NodeJS-Library/
MIT License
150 stars 19 forks source link

Some Icon ID's are invalid #39

Closed leapmotiondev closed 5 years ago

leapmotiondev commented 5 years ago

Describe the bug Some Icon id's are going negative. Pattern unknown. Seems like it's completly random what icons are affected. Trying to set the obtained icon id to a server/channel-group or server/channel returns "convert error".

I obtain the iconid by getChannelGroupByID() -> object.getCache(), which returns following: { cgid: 158, name: 'MyChannelGroup', type: '1', iconid: '-164414261', savedb: '1', sortid: '14500', namemode: '0', n_modifyp: '50', n_member_addp: '75', n_member_removep: '25' }

To Reproduce g_teamspeak.getChannelGroupByID(client['client_channel_group_id']).then(function(obj) { console(obj.getCache().iconid); // returns -543746121, valid icon id would be 1958946389 });

Expected behavior Valid channelgroup icon id that I can set as channel icon

Versions used

Additional context I'm getting the channelgroup icon of a user, the user creates a channel in a certain area, gets channel admin and the created channel should get the icon that the user had before he created the channel.

Multivit4min commented 5 years ago

TeamSpeak Internally saves them in the permission list as 32 bit signed int which means the numbers can go from −2147483648 to 2147483647 however when used in the icon name it gets converted to an unsigned 32 bit int which goes from 0 to 4294967295

how exactly do you try to set the channel icon in your code?

leapmotiondev commented 5 years ago
var icon_id = -1;
g_teamspeak.getChannelGroupByID(client['client_channel_group_id']).then(function(obj) {
    icon_id = obj.getCache().iconid;
});

// i then create a channel, get the promise, .then() this here ..
g_teamspeak.channelEdit(obj['_propcache']['cid'], {
    channel_icon_id: icon_id 
})
Multivit4min commented 5 years ago

This is a problem with the wrong usage of asynchronous functions in NodeJS ;)

ts3.getChannelGroupByID(client['client_channel_group_id'])
  //the "obj" you receive from here is this https://multivit4min.github.io/TS3-NodeJS-Library/#teamspeakchannel
  .then(channel => channel.edit({ channel_icon_id: channel.getCache().iconid }))

//if you would do call the edit here the iconid would still be -1
//the function inside "then" from the getChannelGroupByID Method would be called a few milliseconds later
leapmotiondev commented 5 years ago

Mhh, I do get other values than -1 tho. It's just an issue with converting it to a valid int64.

And shouldn't getChannelGroupByID return https://multivit4min.github.io/TS3-NodeJS-Library/#teamspeakchannelgroup?

see here:

            g_teamspeak.getChannelGroupByID(client['client_channel_group_id']).then(function(obj) {
                icon_id = obj['_propcache']['iconid'];
            });

            g_teamspeak
                .channelCreate("testchannel", {
                    cpid: 32,
                    channel_codec: 4
                .then(function(obj) {
                    console.log(icon_id); // returns int32 iconid
                    g_teamspeak
                        .channelEdit(obj['_propcache']['cid'], {
                            channel_icon_id: icon_id
                        })
                        .catch(e => {
                            console.log(e.message);
                        });
                })
                .catch(e => {
                    con.error('[TSLIB] ', e.message);
                });
leapmotiondev commented 5 years ago

I just compared the icon ids on teamspeak by hovering over those which aren't working and those that are. And indeed, the ones that aren't working exceed the limit of a int32, therefore setting them as iconid of a channel fails. It has something to do with the return of "convert error". There must be something wrong while updating/converting the icon id back to what teamspeak3 expects.

Multivit4min commented 5 years ago

alright i might get what is wrong, "channel_icon_id" requires a crc32 which is an unsigned int (so only a positive number) however teamspeak internally converts it in the permissions to a signed int (might get converted into a negative number in some cases)

so it will work when using channel.setPerm("i_icon_id", icon_id, true) but the channel edit wants it as valid crc32 name

The iconid which you receive from the getChannelGroupById is exact the response it would give when executed manually within a telnet client

image

so if you want to convert the number you get into a valid unsigned value you would need to do it like that

.channelEdit(obj['_propcache']['cid'], {
  channel_icon_id: icon_id & 0xFFFFFFFF
})

oor use the other example from above to set permissions directly

Multivit4min commented 5 years ago

Here is a perfect example where you can see how it converts them between a negative and a positive value image

however the fun part is that channelinfo also returns the converted signed int image

leapmotiondev commented 5 years ago

The second you answered, I made it set the permission and it worked. That's a good info to know cuz I don't like the gibberish teamspeak 3 does sometimes with weird values and all that.

It's solved!

Multivit4min commented 5 years ago

Added a report on the teamspeak forum https://forum.teamspeak.com/threads/139151-channel_icon_id-wrong-query-result?p=466936#post466936

leapmotiondev commented 5 years ago

Looks like they fixed it in 3.8.0 beta,

Changelog:

=== Server Release 3.8.0 20 May 2019

Important: This releases requires GNU C library (glibc) 2.17 or later on Linux. If 
           you need to check which version of glibc is installed on your system, You 
           can use `ldd -version`, which usually comes with any glibc installation.
Important: Client badge information is now signed to prevent using fake data. Badges 
           in the old format will not be visible on this server. New clients with 
           support for signed badges will be available soon.

Added: The query command "banlist" now supports pagination parameters. Please refer 
       to the ServerQuery documentation for details.
Added: Temporary passwords are now saved in the database and will load on start.
Added: New command line parameters 'daemon' and 'pid_file'. This makes it possible 
       for the Server to start as a deamon.

Changed: The restart parameter in startscript now allows to use more than one start 
         parameter.
Changed: New server logs are no longer created with a BOM.
Changed: Icons set in Server or Channel will not be negative values any longer when 
         requested in ServerQuery.
Changed: In query commands 'clientlist -ip' and 'clientinfo -ip' the IPv6 of a client 
         won't show brackets any longer.
Changed: Max size of text messages has been increased to improve usability for upcoming
         client releases.

Fixed: In some rare case the server did crash when shutting down a virtual server.
Fixed: The restart parameter in startscript could not be used when performed outside 
       the server directory.
Fixed: Server did send can create channels to the weblist in cases where a client could 
       not create any channel.
Fixed: No more 'Error querying client connection info: 1796' messages in the client log.