This project has moved. For the latest updates, please go here.

Add Ban Rule

This Adds a new ban rule on the selected virtual server. All parameters are optional but at least one of the following must be set: ip, name, or uid.

Parameters:

ipPattern: the ip pattern
namePattern: the name pattern
clientUniqueId: the clients unique id
duration: the duration
banReason: the reason for the ban

Sample Code vb.net

Imports TS3QueryLib.Core.Query
...
queryRunner.SelectVirtualServerById(1)
queryRunner.AddBanRule(ByVal ipPattern As String, ByVal namePattern As String, ByVal clientUniqueId As String, ByVal duration As System.TimeSpan?, ByVal banReason As String) 

Sample Code C#

using TS3QueryLib.Core.Query;
...
queryRunner.SelectVirtualServerById(1);
queryRunner.AddBanRule(string ipPattern, string namePattern, string clientUniqueId, System.TimeSpan? duration, string banReason);
The two code Examples above show the QueryRunner Call used for the Add ban Rule. This can be used after the login to the Server Query. Which can be Found on Connect to a server
There are Also 2 Code Examples Below using VB.net and C#

Example Usage vb.net

Imports TS3QueryLib.Core
Imports TS3QueryLib.Core.Query
Imports TS3QueryLib.Core.Query.Responses
Imports System
...
Dim targetHost As String = "127.0.0.1"
Dim targetQueryPort As UShort = 10011
Dim login As String = "serveradmin"
' the username used in Login-Method
Dim password As String = "ANicePassword"
' the password for the login
' The QueryRunner is used to send queries. All Queries are implemented type save and return objects with properties
Using queryRunner As New QueryRunner(New SyncTcpDispatcher(targetHost, targetQueryPort))
            ' host and port
            ' connection to the TS3-Server is established with the first query command when using SyncTcpDispatcher
            ' login using the provided username and password and show a dump-output of the response in a textbox
            Dim loginResponse As SimpleResponse = queryRunner.Login(login, password)

            If loginResponse.IsErroneous Then
                ' login failed! Use loginResponse.ErrorMessage and loginResponse.ErrorId to get the reason
                MsgBox("There was An Error")
            Else
                Dim ipPattern As String = "1.2.3.4"
                Dim namePattern As String = "Client Name"
                Dim clientUniqueId As String = "FPMPSC6MXqXq751dX7BKV0JniSo="
                Dim banReason As String = "Reason Goes Here"
                Dim duration As New TimeSpan(2)
                'Selects The Virtual Server By ID
                queryRunner.SelectVirtualServerById(1)
                'Adds the Ban Rule IP, NamePattern, Unique ID, Ban Duration, Reason of Ban
                queryRunner.AddBanRule(ipPattern.ToString(), namePattern.ToString(), clientUniqueId.ToString(), duration, banReason.ToString())
            End If
        End Using

Example Usage C#

using TS3QueryLib.Core;
using TS3QueryLib.Core.Query;
using TS3QueryLib.Core.Query.Responses;
using System;
...
string targetHost = "127.0.0.1"; // the IP or Hostname of the teamspeak server to connect to
ushort targetQueryPort = 10011; // the query port of the teamspeak server to connect to
string login = "serveradmin"; // the username used in Login-Method
string password = "ANicePassword"; // the password for the login

// The QueryRunner is used to send queries. All Queries are implemented type save and return objects with properties
using (QueryRunner queryRunner = new QueryRunner(new SyncTcpDispatcher(targetHost, targetQueryPort))) // host and port
{
	// connection to the TS3-Server is established with the first query command when using SyncTcpDispatcher

	// login using the provided username and password and show a dump-output of the response in a textbox
	SimpleResponse loginResponse = queryRunner.Login(login, password); 

	if (loginResponse.IsErroneous)
	{
		// login failed! Use loginResponse.ErrorMessage and loginResponse.ErrorId to get the reason
		MessageBox.Show("There was an Error");
	}
	else
	{
	string ipPattern = "1.2.3.4";
	string namePattern = "Clients Name";
	string clientUniqueId = "FPMPSC6MXqXq751dX7BKV0JniSo=";
	string banReason = "Reason Goes Here"
	duration = new TimeSpan(2);
	// Selects Virtual Server By ID
	queryRunner.SelectVirtualServerById(1);
	// Adds the Ban Rule IP, Name Pattern, Client Unique ID, Ban Time, Reason of Ban
	queryRunner.AddBanRule(ipPattern.ToString(), namePattern.ToString(), clientUniqueId.ToString(), duration, banReason.ToString());
	}
}
The two Example Uses above show how to Use AddBanRule in the queryRunner Class. This is Done by Connecting to the Server, then Selecting the Virtual Server by its ID Using the SelectVirtualServerById then Using AddBanRule.
After the Code Checks if there are any Errors or not it will Either give an Error Message saying "There was An Error" if there is an Error or if there is no Errors It will continue and add the ban rule.

Last edited Jul 3, 2011 at 10:47 AM by JoshuaK456, version 3

Comments

No comments yet.