Giter VIP home page Giter VIP logo

tentaclesoftware.teamspeakquery's Introduction

TentacleSoftware.TeamSpeakQuery

A task-based event-driven TeamSpeak 3 ServerQuery client that supports SOCKS4 proxies.

Nuget package: https://www.nuget.org/packages/TentacleSoftware.TeamSpeakQuery

You should be familiar with the TS3 ServerQuery command syntax. Bedtime reading is available here: http://media.teamspeak.com/ts3_literature/TeamSpeak%203%20Server%20Query%20Manual.pdf

Step 1. Instantiate a shiny new ServerQueryClient, passing in destination host and ServerQuery port (this is 10011 by default).

Include a throttle timespan to avoid flooding the server. If you're not on the server's whitelist, your throttle will need to be higher. We don't want to get banned, do we?

ServerQueryClient client = new ServerQueryClient("host.teamspeakprovider.com", 10011, TimeSpan.FromSeconds(3));

Step 2. Subscribe to client events.

client.ConnectionClosed += (sender, eventArgs) => Console.WriteLine(":sadface:");

If you're planning to subscribe to server notifications (and your login credentials have the required permissions), saddle those event handlers up too:

  • NotifyChannelDescriptionChanged
  • NotifyChannelEdited
  • NotifyClientEnterView
  • NotifyClientLeftView
  • NotifyClientMoved
  • NotifyServerEdited
  • NotifyTextMessage

For example:

client.NotifyClientEnterView += (source, notification) => Console.WriteLine("ClientEnterView {0}: {1}", notification.Clid, notification.ClientNickname);

Step 3: Initialize the client and observe the task result. Once the task has completed, you are connected.

ServerQueryBaseResult connected = client.Initialize().Result;
Console.WriteLine("connected {0}", connected.Success);

You can pass in SOCKS4 proxy credentials instead:

ServerQueryBaseResult connected = client.Initialize("myproxy.proxy.com", 3453, null).Result;

Step 4: Log in if you have credentials. This is not your normal TeamSpeak username and password; see the manual above for instructions on creating a ServerQuery user.

ServerQueryBaseResult login = client.Login("myserverqueryuser", "s3cr3t").Result;
Console.WriteLine("login {0} {1} {2}", login.Success, login.ErrorId, login.ErrorMessage);

Step 5: Select the TeamSpeak instance you will be manipulating. You can select the instance using the port (which is the port number you connect to with your normal TeamSpeak client) or serverId if you know it. See the manual above for more information.

ServerQueryBaseResult use = client.Use(UseServerBy.Port, 5555).Result;
Console.WriteLine("use {0} {1} {2}", use.Success, use.ErrorId, use.ErrorMessage);

Step 6: If you're registering for server notifications later, you may want a keepalive. This is just a simple task loop that requests a "whoami" response from the server.

client.KeepAlive(TimeSpan.FromMinutes(2));

Step 7: Register for the server notifications you care about.

ServerQueryBaseResult registerTextChannel = client.ServerNotifyRegister(Event.textchannel).Result;
Console.WriteLine("registerTextChannel {0} {1} {2}", registerTextChannel.Success, registerTextChannel.ErrorId, registerTextChannel.ErrorMessage);

Step 8: Have your way with the poor, innocent server!

ClientListResult clientList = client.ClientList().Result;
Console.WriteLine("clientList {0} {1} [x{2}]", clientList.Success, clientList.ErrorId, clientList.Values != null ? clientList.Values.Count : 0);

Commands are named the same as the text commands in the TS3 ServerQuery manual. I've explicitly implemented some of the commands I most use as methods on ServerQueryClient:

  • Quit
  • Login
  • Logout
  • Use
  • ServerInfo
  • ChannelList
  • ChannelInfo
  • ClientList
  • ClientInfo
  • ClientMove
  • ClientKick
  • ClientPoke
  • WhoAmI
  • ServerNotifyRegister
  • ServerNotifyUnregister
  • SendTextMessage
  • BanList
  • BanAdd
  • BanDel
  • BanDellAll

Other commands can be created using the ServerQueryCommand class and adding parameters and options as per the TS3 ServerQuery manual. Send your new command using ServerQueryClient.SendCommandAsync() with an appropriate response class. The implementations above should give you a good starting point.

Or you can just send text commands and get back the raw response using the ServerQueryClient.SendCommandAsync(string command) overload.

Clean up: Be a good ServerQuery client and say goodbye.

ServerQueryBaseResult unregister = client.ServerNotifyUnregister().Result;
Console.WriteLine("unregister {0} {1} {2}", unregister.Success, unregister.ErrorId, unregister.ErrorMessage);

ServerQueryBaseResult logout = client.Logout().Result;
Console.WriteLine("logout {0} {1} {2}", logout.Success, logout.ErrorId, logout.ErrorMessage);

ServerQueryBaseResult quit = client.Quit().Result;
Console.WriteLine("quit {0} {1} {2}", quit.Success, quit.ErrorId, quit.ErrorMessage);

tentaclesoftware.teamspeakquery's People

Contributors

spksh avatar r15ch13 avatar jimmy062006 avatar j-mie avatar jtone123 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.