• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.
TeamSpeak ServerQuery

TeamSpeak ServerQuery 1.0.0

No permission to download
This Library allows you to connect to a TeamSpeak 3 Server Query
Notice: This is a Library which may be required by other Scripts! This is not a standalone Script!

FOR ALL WHO INSTALL THIS LIBRARY

To be able to use the Script the User needs to alter the config.ini and add this 2 lines:
Code:
[Scripts.Privileges]
  ServerQuery = ["net"]


For Developers:

After loading the ServerQuery with var ServerQuery = require("ServerQuery.js")
You need to instance it first with var ts3 = new ServerQuery({host: "127.0.0.1", port: 10011})

The constructor of ServerQuery expects one object as an argument
host -> the teamspeak server host ip, default value if empty is "127.0.0.1"
port -> the teamspeak query telnet port, default value if empty is 10011
net -> fully optional to load the net module from a different script

you can subscribe to events with ts3.on(event_name, function(ev) { ... })

Events you can subscribe to are
connect -> gets fired when the connection to the TCP Socket was successfull
close -> gets fired when the connection to the TeamSpeak gets closed
error -> when something bad happens
notify -> gets called when you receive a TeamSpeak Event

to send a query command you can call the execute function
it takes multiple arguments in a non specific order:
string -> the command which should be sent
object -> object with keys which will get escaped { msg: "Hello World!" } will be sent like msg=Hello\sWorld!
array -> flags for example within the clientlist command ["-uid", "-away", "-country"]
function -> the callback function

JavaScript:
registerPlugin({
  name: "Example Plugin for ServerQuery.js",
  version: "1.0.0",
  description: "Example Script to interact with a TeamSpeak Server Query",
  author: "Multivitamin <[email protected]>",
  vars: []
}, function() {

  var engine = require("engine")
  var event = require("event")

  //wait for all scripts to finnish loading
  event.on("load", function() {
    //load the external library
    var ServerQuery = require("ServerQuery.js")
    //check if the Library has been loaded
    if (typeof ServerQuery !== "function") return engine.log("This Script requires to have ServerQuery.js installed!")

    //create a new instance of it
    var ts3 = new ServerQuery({ host: "127.0.0.1", port: 10011 })

    //event connect gets fired when the Query has successfully connected with the TeamSpeak Server
    ts3.on("connect", function() {
      engine.log("TS3 CONNECTED!")
      //authenticate with the TeamSpeak Server
      ts3.send("login", ["serveradmin", "qGH9i3rs"], function(err) {
        if (err) return engine.log("Query Error: "+JSON.stringify(err))
        //select a virtualserver
        ts3.send("use", {port: 9987}, function(err) {
          if (err) return engine.log("Query Error: "+JSON.stringify(err))
          //send a whoami to get info about the own client
          ts3.send("whoami", function(err, res) {
            if (err) return engine.log("Query Error: "+JSON.stringify(err))
            engine.log("TeamSpeak Logged in and selected Port 9987 and got a WhoAmI Response")
            engine.log(res)
          })
        })
      })
    })

  })

})
Author
Multivitamin
Downloads
157
Views
4,540
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from Multivitamin

Top