schroffl / teamspeak-query

Teamspeak-ServerQuery library
https://www.npmjs.com/package/teamspeak-query
MIT License
18 stars 8 forks source link

clientlist filter not working for me #12

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi guys, i tryed use

function parseList(data) {
    return data.raw()
      .split('|')
      .map(TeamspeakQuery.parse)
      .map(entry => entry.params);
  }

query.send('clientlist', { 'client_type': 0, 'connection_client_ip': ip })
.then((result) => {
var data = parseList(result)
conole.log(data)
})

where ip is some ip and it's return me list of all users, instead of 1 user with that ip Also i noticed it's returns users with client_type 1. So for some reason for me filter not working. Or i make something wrong? Pls can some help me?

schroffl commented 6 years ago

Looking at the documentation of clientlist I can't see anything about the options you specify. Neither client_type nor connection_client_ip are mentioned as arguments.

What you could try is to filter out your desired client after getting the list. ~However, you can't get the ip of the client this way so you will have to obtain it via other commands. This has the disadvantage that you need to send a single command for each client, which could lead to throttling problems if you don't have unrestricted access and many connected clients.~ Edit: It is possible, but not documented in the manual.

Here is a small example that uses the Array.prototype.find method and will return the first client with client_type 1. Alas, I could not get the ip-filtering working right now, but I will retry later today.

query.send('clientlist')
  .then(parseList)
  .then(list => list.find(client => client.client_type == 1))
  .then(console.log);

When running it:

$ node abc.js
{ clid: '6',
  cid: '1',
  client_database_id: '1',
  client_nickname: 'serveradmin',
  client_type: '1',
  raw: [Function] }
ghost commented 6 years ago

I just have an php example on ts3-framework, where ip filtering is working, will be nice if we will have this in teamspeak-query (sorry for english)

schroffl commented 6 years ago

Hey, can you send me a link to that example? No worries about your english, at least for me it is totally understandable :)

ghost commented 6 years ago

https://gitlab.com/NOFEAR/TS3-Client-Verifired/blob/master/index.php#L53 Russian in text, but i think you can understand code. It's working :O

schroffl commented 6 years ago

I need to sign in to view the repo, is it private? If yes, you could post only the relevant code without revealing too much (I suppose it's private for a reason :p).

ghost commented 6 years ago

https://gitlab.com/Satont/ts/blob/master/index.php#L53 then

schroffl commented 6 years ago

~Oh I know why, the -ip option actually lists the connection_client_ip of all connected clients, but this doesn't work for ServerQuery clients, which is why I couldn't see it.~ Edit: This actually was a bug. The server sends a connection_client_ip for ServerQuery clients, but without a value. So instead of …client_type=0 connection_client_ip=x.x.x.x… it responds with …client_type=1 connection_client_ip…. However, this doesn't change the fact that you cannot get the ip of such clients, you just can see that their connection_client_ip is undefined. Fixed in Version 2.1.1

So this should work (out of my head, I'm in a hurry):

query.send('clientlist', '-ip')
  .then(parseList)
  .then(list => list.find(client => client.client_type == 0 && client.connection_client_ip == ip))
  .then(console.log);
ghost commented 6 years ago

it's working :O Thx man!

schroffl commented 6 years ago

Nice, I'm glad I could help :)