TheHolyWaffle / TeamSpeak-3-Java-API

A Java wrapper of TeamSpeak's 3 server query API.
MIT License
306 stars 107 forks source link

Get Ban-ID? #322

Open YourGameSpace opened 5 years ago

YourGameSpace commented 5 years ago

Hello, it's me again. :P

I am currently in the process of reprogramming my TS3Bot for my network and I would like to improve some of that. Now it is my concern to banish the Bot clients. For every Ban, there seems to be a Ban ID, which is VERY GOOD FIND! However, my wish would be that if I ban a client, that the Ban ID is in the ban reason.

Unfortunately I have absolutely no idea how I get the Ban-ID of a spell .. Although I could do api#getBanns but that would be too expensive just synonymous with what you resources.

I first thought that you Ban ban = api#addBan(...); Unfortunately this is not possible.

So please help! Thank you!

Tumbledore commented 5 years ago

And its me again ;) The ’api.addBan()’ is returning the Ban ID. Now you just Need to get the Ban again and change the Ban Message. I would Need to Look that Up Howe to do this with the API, but im currently on my phone ^^

YourGameSpace commented 5 years ago

Ok thanks! Have you already figured out how to integrate the Ban-ID into the Ban Text, or subsequently add it?

Tumbledore commented 5 years ago

Hi @TUBEOF , this is atm the only way I could think of doing your thing:

int newBan = api.addBan("","","",12,"");
List<Ban> bans = api.getBans();
Optional<Ban> optionalBan = bans.stream().filter(s->newBan == s.getId()).findFirst();
if (optionalBan.isPresent()){
     StringBuilder sb = new StringBuilder();
     Ban newlyBan  = optionalBan.get();
     sb.append(newlyBan.getReason());
     sb.append(" " + newlyBan.getId());
api.addBan(newlyBan.getBannedIp(),newlyBan.getBannedName(),newlyBan.getBannedUId(),newlyBan.getDuration(),sb.toString());
      api.deleteBan(newlyBan.getId());
}

there is the expensive getBans call but that's because there is no getBan(int ID), maybe this could be an improvement @rogermb

TheHolyWaffle commented 5 years ago

Unfortunately, there is no such query that only allows you to query for a ban with a given ID. You'll have to do with keeping a local cache of all bans, and synchronizing them with the server if needed.

YourGameSpace commented 5 years ago

Alright, so far so good. How can I check if a client is already banned? So far I have tried it (see screenshot below), but unfortunately this does not work?

https://i.imgur.com/SwipUAf.png

Tumbledore commented 5 years ago

Hey, you are working with an Optional<T> here. These normally cant be null. Instead your if(...) return true just use return optional.isPresent()

YourGameSpace commented 5 years ago

Did it all now: https://hastebin.com/idikotalut.java However, now I always get "false" .. Although the client is banned.

Tumbledore commented 5 years ago

Hey, I dont know if getDatabaseClientInfo() works if the Client is banned. If it does, then i need to investigate further.