TeamSpeak-3-Java-API icon indicating copy to clipboard operation
TeamSpeak-3-Java-API copied to clipboard

totalClients rip

Open qeinz opened this issue 1 year ago • 13 comments

I am slowly freaking out with the teamspeak server system, how can it be that there is the function "totalclients", but NOTHING is returned, I know that you can not do that and only use the values of teamspeak, but maybe you know where the problem is with me.

My problem: I want to see if a client is alone in the channel, and I want to do this as "efficiently" as possible, so I tried to use the following method:

My code:

        try {
            final Client musicCustomBot = Main.api.getClientByUId("MyClientUid");
            final int channelID = musicCustomBot.getChannelId();
            final String totalClients =
                    Main.api.getChannelInfo(channelID).get(ChannelProperty.TOTAL_CLIENTS);
            System.out.println(totalClients + "total");
            if (Integer.parseInt(totalClients) <= 1) Main.api.moveClient(musicCustomBot.getId(),
                    ChannelIdService.musikAfkChannel_ID);
        } catch (Exception exception) {
            System.out.println("Couldn't move team bots");
        }

The Log Output on my Server:

2024-04-20T23:10:53.266343745Z total
2024-04-20T23:10:53.266395063Z Couldn't move team bots

My question: Am I currently doing something wrong or am I misinterpreting the problems?

qeinz avatar Apr 20 '24 23:04 qeinz

Hi @qeinz

Yeah, this part of the serverquery interface is very counter-intuitive. The current number of clients in the channel is only included in the channellist response, but not in the channelinfo response. Usually, you'd assume that channelinfo would always deliver more information about the given channel than channellist, but this is unfortunately not the case with TS3...

As far as I can see, you essentially have 2 options, but neither of those is "minimal":

  • Call TS3Api#getChannels to get a list of all channels, iterate over the list, pick out the Channel object you're interested in, and call Channel#getTotalClients or Channel#getTotalClientsFamily on it (depending on whether you want to include clients in sub-channels in the count), or
  • Call TS3Api#getClients and manually count the number of clients whose Client#getChannelId is the channel you're interested in. This approach doesn't work if you also want to count clients in sub-channels.

rogermb avatar Apr 22 '24 01:04 rogermb

Big thx to u <3 thx so much man!

it worked with the following code as u said:

    public static void moveTeamBots() {

        try {
            final Client musicCustomBot = Main.api.getClientByUId("uid=");
            final int channelID = musicCustomBot.getChannelId();

            for (Channel channels : Main.api.getChannels()) {
                if (channels.getId() == channelID) {
                    if (channels.getTotalClients() <= 1) Main.api.moveClient(musicCustomBot.getId(),
                            ChannelIdService.musikAfkChannel_ID);
                }
            }

        } catch (Exception exception) {
            System.out.println("Couldn't move team bots");
        }

qeinz avatar Apr 24 '24 16:04 qeinz

so wait is there a problem with spacer? like: [*cspacer1981245353541] if i move the bot in this channel the code doesnt move him out?

qeinz avatar Apr 25 '24 20:04 qeinz

I can't really tell you too much without a server error message, but I have a hunch what might be going on:

The way these spacer channels are usually set up to prevent people from joining them is by raising the required join, subscribe, etc. powers up to a higher value. Now, if the channel subscribe power of the server query client you're using is lower than the required subscribe power for the spacer channel, you won't be able to subscribe to the channel, and thus your server query client will be unable to see any clients in such channels. In effect, the music bot will be invisible to you.

That's just my guess, though. If that's not it, please feel free to share any server errors / exceptions / whatever you're getting 😄

rogermb avatar Apr 26 '24 23:04 rogermb

Ahh thats a wild guess, might be true, i will check it, thx for your massive help :D

qeinz avatar Apr 26 '24 23:04 qeinz

u were right again my friend! it was the subscription power of the admin query which didnt had enougth, so i changed it, now its working :D thx <3

qeinz avatar Apr 26 '24 23:04 qeinz

Awesome, great to hear that 😄

rogermb avatar Apr 26 '24 23:04 rogermb

hey i unfortunately have the problem that sometimes it works and sometimes it doesn't, do you have a rough idea why that might be?

in some channels it works and in some it doesn't???

qeinz avatar Apr 29 '24 23:04 qeinz

Sorry, no, nothing comes to mind. The only recommendation I can give you is to enable server query command logging and to inspect the logs when you notice that your application isn't working 🙂

rogermb avatar May 01 '24 23:05 rogermb

Alright thx, how can i enable this ?

qeinz avatar May 01 '24 23:05 qeinz

Call TS3Config#setEnableCommunicationsLogging(true) before passing the TS3Config object to the TS3Query constructor.

rogermb avatar May 01 '24 23:05 rogermb

@qeinz If I'm following your intent and issue properly, you could do a check before moving to each channel, to ensure that it has the proper permissions. You could explicitly check if it's a spacer (those were mentioned earlier) if that actually is causing the issue. Also I definitetly recommend logging which channels cause the issue, if you're not.

astrolamb-gaming avatar May 22 '24 23:05 astrolamb-gaming

thx guys for your help, will check it out asap!

qeinz avatar May 23 '24 10:05 qeinz

so idk how and why, but this code is working right now:

    public static void moveTeamBots() {
        try {
            final Client musicCustomBot = Main.api.getClientByUId("uid");
            final int channelID = musicCustomBot.getChannelId();

            if(channelID == ChannelIdService.musikAfkChannel_ID) return;

            for (Channel channels : Main.api.getChannels()) {
                if (channels.getId() == channelID && channels.getTotalClients() == 1) {
                    Main.api.moveClient(musicCustomBot.getId(), ChannelIdService.musikAfkChannel_ID);
                }
            }

        } catch (Exception exception) {
            System.out.println("exceptin; " + exception);
            System.out.println("Couldn't move team bots");
        }
    }

I've added: if(channelID == ChannelIdService.musikAfkChannel_ID) return; xD
    

qeinz avatar Jun 20 '24 21:06 qeinz