DC: TeamSpeak 3 & Icons

Introducing “Dirty-Commits”

Welcome to “Dirty-Commits”.
The format/category where I talk about non-fancy (or even ugly) work-arounds I had to commit into my git history in order to get things working.


The TeamSpeak 3 Server Query API provides a command to retrieve information on the channels of the server (channellist). Using the -icon flag includes the channel_icon_id property.
That icon ID is a CRC32 checksum which is used to identify the icon.

The problem

Earlier this year, I experimented with a plugin that would enforce channel icons for certain channels so they would not be changed even by permitted users.
I quickly noticed that the plugin went totally haywire, editing every watched channel in each check cycle.

At first, I thought that I had mistakenly messed up the check for the icon ID but that turned out to be false pretty quickly. Upon checking the messages returned by the server I discovered that the channel icon ID sent by the server looked weird in that it was negative.

Let’s take a look at the example I was examining:
The icon in question has the ID 3948173233 and setting the channel property to that ID did result in the correct icon being set.
But, for some reason, when returning the channel list, TeamSpeak always returns -346794063 which obviously is not correct.

I went into hours of googling for any hints of other people encountering that issue but it seemed that this issue was unique to our setup. At some point I realized that setups using MariaDB as the database do not seem to be that common. So I tried reproducing this issue with no database server configured.
And it went away? So something must be wrong with the data transition from the database to the query connection. Having previously checked that the data lands in the tables correctly that seemed like the only place where the issue could be caused.

Just having recently had to attend a technical fundamentals of computer science course I had the 2-complement swirling around in my head.
I thought myself: “Why not use this as an exercise for converting numbers between decimals and binary” although I was not really sure what to expect at that moment.

This however, showed me how to work around the issue:
-346794063 in 2-complementary representation is 111010110101010001010111101 which in turn is 3948173233 when interpreted as an unsigned integer.
But wait! That is the real icon ID!

So yeah. It appears that TeamSpeak messes up the integer representation when constructing the query message and reads the unsigned integer as a signed one.

The “solution”

Commit ff5a7631 in the server bot framework will make sure this issue will never be passed to any plugins of the framework.
Whenever a negative icon ID is passed to the framework, it will be re-interpreted as an unsigned integer, resulting in the correct ID being stored.