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

Custom Nickname of TeamSpeak3 Instance #49

Closed chikovanreuden closed 5 years ago

chikovanreuden commented 5 years ago

Describe the bug Im not sure if this is a Bug or something i dont understand why its happening:

The Nickname in the Object passed to the TeamSpeak3 Instance Constructor will be ignored if the functions TeamSpeak3#useByPort or TeamSpeak3#useBySid are used correctly. Instead the the Nickname from the TeamSpeak3 Database will be used for the Connection. But, if i try to Connect with a invalid Port or SID (No Virtual Server binded to Port or SID) the Nickname from the Instance Constructer is used.

To Reproduce

const TeamSpeak3 = require("ts3-nodejs-library");
const conCfg = {
  host: "localhost",
  queryport: 10011,
  serverport: 9987,
  username: "queryLoginUsername",
  password: "Somepwd",
  nickname: "My_Desired_Nickname",
  keepalive: true
}

// throws an Error, connects anyway
ts3.useByPort(1, "queryLoginUsername"); // whoami: My_Desired_Nickname ( from conCfg.nickname )
ts3.useBySig(9987, "queryLoginUsername"); // whoami: My_Desired_Nickname ( from conCfg.nickname )

// as it should be used
ts3.useByPort(9987, "queryLoginUsername"); // whoami: Nickname in DB (e.g. queryLoginUsername
ts3.useBySig(1, "queryLoginUsername"); // whoami: Nickname in DB (e.g. queryLoginUsername

Expected behavior

Versions used

Additional context I am using the standard TeamSpeak Server SQLite Database, no MySQL. The TeamSpeak has only one Virtual Server Instance (SID: 1) running on Port 9987.

Error from "To Repreoduce":

Unhandled Rejection at: { [ResponseError: invalid serverID]
  id: 1024,
  msg: 'invalid serverID',
  extra_msg: undefined,
  failed_permid: undefined,
  message: 'invalid serverID' }
Promise {
  <rejected> { ResponseError: invalid serverID
    id: 1024,
    msg: 'invalid serverID',
    extra_msg: undefined,
    failed_permid: undefined,
    message: 'invalid serverID' } }
Multivit4min commented 5 years ago

I can not really follow where the actual problem is, it seems that at some point you execute a command at where the server needs to be connected to a server

Can you provide a complete example to reproduce?

chikovanreuden commented 5 years ago

The query credentials are not from serveradmin. It was generated via the official Teamspeak3 Client (somewhere under 'Extras').

Compare client_nickname in the Console from ts3.whoami(). If i use the 'useBy' functions wrong, the Nickname property of conCfg will be used. And a Error will be thrown. If i use the 'useBy' functions correct, the Nickname of the corresponding Client in the Teamspeak Database (in this case my TeamSpeak3 Client Identity because i created the Server Query Login with) will be used.

Everything from ts3.whoami() is similar, but the client_nickname property. client_nickname acts like a Displayname. recieving a Message of any of the Instances will display the Value of client_nickname.

Wrong usage of ts3.useByPort:

const TeamSpeak3 = require("ts3-nodejs-library");
const conCfg = {
  host: "localhost",
  queryport: 10011,
  serverport: 9987,
  username: "XCS_Message",
  password: "something", // censored
  nickname: "XCS_Message",
  keepalive: true
}

const ts3 = new TeamSpeak3(conCfg);
// throws an Error, connects anyway
ts3.useByPort(1, "XCS_Message");
// or ts3.useBySig(9987, "XCS_Message");

ts3.on("ready", () => {
  //ts.move(clid, 4);
  ts3.whoami().then(instanceInfo => {
    console.log(instanceInfo)
  })

  Promise.all([
    ts3.registerEvent("server"),
    ts3.registerEvent("channel", 0),
    ts3.registerEvent("textserver"),
    ts3.registerEvent("textchannel"),
    ts3.registerEvent("textprivate")
  ]).then(() => {
      console.log("Subscribed to all Events")
  }).catch(e => {
      console.log("CATCHED", e.message)
  })
})

process.on('unhandledRejection', (reason, promise) => {
  console.log('Unhandled Rejection at:', reason.stack || reason)
  console.log(promise)
})

The console:

C:\>node test.js
Unhandled Rejection at: { [ResponseError: invalid serverID]
  id: 1024,
  msg: 'invalid serverID',
  extra_msg: undefined,
  failed_permid: undefined,
  message: 'invalid serverID' }
Promise {
  <rejected> { ResponseError: invalid serverID
    id: 1024,
    msg: 'invalid serverID',
    extra_msg: undefined,
    failed_permid: undefined,
    message: 'invalid serverID' } }
{ virtualserver_status: 'online',
  virtualserver_id: 1,
  virtualserver_unique_identifier: '7aTbS7BbiCNPytdbcXbzESCakyg=',
  virtualserver_port: 9987,
  client_id: 9,
  client_channel_id: 1,
  client_nickname: 'XCS_Message',
  client_database_id: 2,
  client_login_name: 'XCS_Message',
  client_unique_identifier: '', // censored
  client_origin_server_id: 1 }
Subscribed to all Events

And here is the correct use of ts3.useByPort:

const TeamSpeak3 = require("ts3-nodejs-library");
const conCfg = {
  host: "localhost",
  queryport: 10011,
  serverport: 9987,
  username: "XCS_Message",
  password: "something", // censored
  nickname: "XCS_Message",
  keepalive: true
}

const ts3 = new TeamSpeak3(conCfg);

// as it should be used
ts3.useByPort(9987, "XCS_Message");
// Or ts3.useBySig(1, "XCS_Message");

ts3.on("ready", () => {
  //ts.move(clid, 4);
  ts3.whoami().then(instanceInfo => {
    console.log(instanceInfo)
  })

  Promise.all([
    ts3.registerEvent("server"),
    ts3.registerEvent("channel", 0),
    ts3.registerEvent("textserver"),
    ts3.registerEvent("textchannel"),
    ts3.registerEvent("textprivate")
  ]).then(() => {
      console.log("Subscribed to all Events")
  }).catch(e => {
      console.log("CATCHED", e.message)
  })
})

process.on('unhandledRejection', (reason, promise) => {
  console.log('Unhandled Rejection at:', reason.stack || reason)
  console.log(promise)
})

The Console:

C:\>node test.js
{ virtualserver_status: 'online',
  virtualserver_id: 1,
  virtualserver_unique_identifier: '7aTbS7BbiCNPytdbcXbzESCakyg=',
  virtualserver_port: 9987,
  client_id: 11,
  client_channel_id: 1,
  client_nickname: 'XCS_Chiko van Reuden',
  client_database_id: 2,
  client_login_name: 'XCS_Message',
  client_unique_identifier: '', // censored
  client_origin_server_id: 1 }
Subscribed to all Events
Multivit4min commented 5 years ago

Ok i see what is going on here, first of all if you use serverport: 9987, in your configuration then you will not need to trigger ts3.useByPort by yourself, either leave the config empty or remove the ts3.useByPort and only use it within the config

whats actually going on is this:

receive | TS3
receive | Welcome to the TeamSpeak 3 ServerQuery interface, type "help" for a list of commands and "help <command>" for information on a specific command.
receive | error id=0 msg=ok
send | whoami
receive | virtualserver_status=online virtualserver_id=1 virtualserver_unique_identifier=nme6S92mUSLl62y+JUdK\/22xrgk= virtualserver_port=9987 client_id=10 client_channel_id=1 client_nickname=XCS_Message client_database_id=0 client_login_name client_unique_identifier client_origin_server_id=0
receive | error id=0 msg=ok
send | version
receive | version=3.7.1 build=1553759186 platform=Windows
receive | error id=0 msg=ok
send | login serveradmin orkLN+hQ
receive | error id=0 msg=ok
send | use port=9987 client_nickname=XCS_Message
receive | error id=0 msg=ok
send | whoami
receive | virtualserver_status=online virtualserver_id=1 virtualserver_unique_identifier=nme6S92mUSLl62y+JUdK\/22xrgk= virtualserver_port=9987 client_id=11 client_channel_id=1 client_nickname=serveradmin client_database_id=1 client_login_name=serveradmin client_unique_identifier=serveradmin client_origin_server_id=0
receive | error id=0 msg=ok
send | servernotifyregister event=server
receive | error id=0 msg=ok
send | servernotifyregister event=channel id=0
receive | error id=0 msg=ok
send | servernotifyregister event=textserver
receive | error id=0 msg=ok
send | servernotifyregister event=textchannel
receive | error id=0 msg=ok
send | servernotifyregister event=textprivate
receive | error id=0 msg=ok

whats happening is that your useByPort sends first since its outside the ts3.on("ready", () => ...) function after this it logins and it will use the nickname from where the generated query comes from in your case you generated your query login data with a client with the nickname XCS_Chiko van Reuden And now since we already have selected a server and the query initialization tries to select the server but already has selected a server from your first query it is not able to select the server again, The TeamSpeak Server then just drops and ignores the command https://github.com/Multivit4min/TS3-NodeJS-Library/blob/master/TeamSpeak3.js#L115

chikovanreuden commented 5 years ago

Yeah, i removed ts3.useByPort and now everything is working as expected. I did not know it was unnecessary as you explained.