PDA

View Full Version : VB.NET (General .NET) API SDK Usage


DesoTron
17-12-2004, 06:18
I'll be writing a module to control the ts client using a cmdline access of the tscontrol program. Is there anything I should know before integrating the tscontrol software into my games I develope as far as licensing and stuff like that.

I'll also be submitting the results for use later when its done

m&m's
17-12-2004, 06:47
ts3 is in the works and will not work with ts2 as far as i know ? release is slated for 1st Q of 2005 . would be nice to have ts3 in some games , you will have to wate for the dev team to respond . i wish you luck ! hope all goes well

DesoTron
17-12-2004, 19:06
To use this you will need to have a folder called ts of the application directory which has the two files: tscontrol.exe and tscontrol.dll


Namespace TeamSpeak

Public Enum ENUM_PlayerFlags
ChannelCommander = 1
WantVoice = 2
NoWhisper = 4
Away = 8
InputMuted = 16
OutputMuted = 32
Recording = 64
End Enum

Public Enum ENUM_ChannelPrivilages
Admin = 1
Operator = 2
AutoOperator = 4
Voiced = 8
AutoVoice = 16
End Enum

Public Enum ENUM_Privilages
SuperServerAdmin = 1
ServerAdmin = 2
CanRegister = 4
Registered = 8
UnRegsitered = 16
End Enum


Public Structure Player
Public PlayerID As Integer
Public ChannelID As Integer
Public Name As String
Public Flags As ENUM_PlayerFlags
Public ChannelPrivilages As ENUM_ChannelPrivilages
Public Privilages As ENUM_Privilages
End Structure

Public Structure Channel
Public ChannelID As Integer
Public ParentChannelID As Integer
Public Name As String
Public PlayerCount As Integer
Public Flags As ENUM_PlayerFlags
End Structure

Public Structure ServerInfo
Public ServerName As String
Public WelcomeMessage As String
Public Version As String
Public Platform As String
Public IP As String
Public Host As String
Public MaxUsers As Integer
Public CurrentUserCount As Integer
Public CurrentChannelCount As Integer
Public ServerType As String
End Structure

Public Class Client

Public Function Connect(ByVal TeamSpeakURL As String) As String
Dim R() As String

R = UseTsControl("connect " & TeamSpeakURL)

Return R(0)
End Function

Public Function Disconnect() As String
Dim R() As String

R = UseTsControl("disconnect")

Return R(0)
End Function

Public Function Quit() As String
Dim R() As String

R = UseTsControl("quit")

Return R(0)
End Function

Public Function SwitchChannel(ByVal ChannelID As Integer, Optional ByVal Password As String = "") As String
Dim R() As String

R = UseTsControl("switch_channel " & ChannelID & " " & Password)

Return R(0)
End Function

Public Function GetClientVersion() As String
Dim R() As String

R = UseTsControl("get_client_version")

If R(0) = "OK" Then
Return Mid(R(1), 10)
End If

Return R(0) 'Return the fail message instead
End Function

'Returns a Server info structure
Public Function GetServerInfo() As ServerInfo
Dim R() As String, SInfo As ServerInfo

R = UseTsControl("get_server_info")

If R(0) = "OK" Then
With SInfo
.ServerName = Mid(R(1), 13)
.WelcomeMessage = Mid(R(2), 18)
.Version = Mid(R(3), 10)
.Platform = Mid(R(4), 13)
.IP = Mid(R(5), 5)
.Host = Mid(R(6), 7)
.MaxUsers = Mid(R(7), 13)
.CurrentUserCount = Mid(R(8), 21)
.CurrentChannelCount = Mid(R(9), 24)
.ServerType = Mid(R(10), 14)
End With
End If

Return SInfo
End Function

Public Function GetUserInfo(ByRef ret_PlayerInfo As Player, ByRef ret_ChannelInfo As Channel) As String
Dim R() As String

R = UseTsControl("get_user_info")

If R(0) = "OK" Then
Dim pLine() As String

pLine = Split(R(2), " ")
With ret_PlayerInfo
.PlayerID = Val(Mid(pLine(0), 4))
.ChannelID = Val(Mid(pLine(1), 10))
.Name = Mid(pLine(2), 7)

pLine = Split(R(3), " ")
.ChannelPrivilages = Val("&H" & Mid(pLine(0), 17, 2))
.Privilages = Val("&H" & Mid(pLine(1), 10, 2))
.Flags = Val("&H" & Mid(pLine(2), 10, 2))
End With

pLine = Split(R(6), " ")
With ret_ChannelInfo
.ChannelID = Val(Mid(pLine(0), 4))
.ParentChannelID = Val(Mid(pLine(1), 9))
.Name = Mid(pLine(2), 7)
.PlayerCount = Val(Mid(pLine(3), 14))
.Flags = Val("&H" & Mid(pLine(4), 10))
End With

End If

Return R(0)
End Function

'Returns an array of channel structures
'can also return a blank array
Public Function GetChannels() As Channel()
Dim R() As String, CINFO() As Channel

R = UseTsControl("get_channels")

If R(0) = "OK" Then

Dim ChannelCount As Integer
ChannelCount = Val(Mid(R(1), 15))

If ChannelCount = 0 Then Return Nothing

ReDim CINFO(ChannelCount - 1)

Dim I As Integer = 2
Do While I < ChannelCount + 2

Dim pLine() As String
pLine = Split(R(I), " ")

With CINFO(I - 2)
.ChannelID = Val(Mid(pLine(0), 4))
.ParentChannelID = Val(Mid(pLine(1), 9))
.Name = Mid(pLine(2), 7)
.PlayerCount = Val(Mid(pLine(3), 14))
.Flags = Val("&H" & Mid(pLine(4), 10))
End With

I += 1
Loop

End If

Return CINFO
End Function


'Returns an array of player information
'Can also return nothing if no players are there
Public Function GetPlayers() As Player()
Dim R() As String, PINFO() As Player

R = UseTsControl("get_players")

If R(0) = "OK" Then

Dim PlayerCount As Integer
PlayerCount = Val(Mid(R(1), 14))

If PlayerCount = 0 Then Return Nothing

ReDim PINFO(PlayerCount - 1)

Dim I As Integer = 2
Do While I < PlayerCount + 2

Dim pLine() As String
pLine = Split(R(I), " ")

With PINFO(I - 2)
.PlayerID = Val(Mid(pLine(0), 4))
.ChannelID = Val(Mid(pLine(1), 10))
.Name = Mid(pLine(2), 7)
.ChannelPrivilages = Val("&H" & Mid(pLine(3), 17))
.Privilages = Val("&H" & Mid(pLine(4), 10))
.Flags = Val("&H" & Mid(pLine(5), 10))
End With

I += 1
Loop

End If

Return PINFO
End Function

'Returnes PlayerID's that are currently speaking
'Also returns empty array if there are no speakers
Public Function GetSpeakers() As Integer()
Dim R() As String, PIDS() As Integer
R = UseTsControl("get_speakers")

If R(0) = "OK" Then

Dim SpeakerCount As Integer
SpeakerCount = Val(Mid(R(1), 15))

If SpeakerCount > 0 Then Return Nothing

ReDim PIDS(SpeakerCount - 1)

Dim I As Integer = 2
Do While I < SpeakerCount + 2

PIDS(I - 2) = R(I)

I += 1
Loop

End If

Return PIDS
End Function

Public Function Mute() As String
Dim R() As String
R = UseTsControl("mute")
Return R(0)
End Function

Public Function UnMute() As String
Dim R() As String
R = UseTsControl("unmute")
Return R(0)
End Function

Public Function SetOperator(ByVal PlayerID As Integer, ByVal Grant As Boolean) As String
'Convert Grant to "GRANT" or "REVOKE" in str
Dim R() As String
Dim GStr As String = "REVOKE"
If Grant Then GStr = "GRANT"
R = UseTsControl("set_operator " & PlayerID & " " & GStr)
Return R(0)
End Function

Public Function SetVoice(ByVal PlayerID As Integer, ByVal Grant As Boolean) As String
'Convert Grant to "GRANT" or "REVOKE" in str
Dim R() As String
Dim GStr As String = "REVOKE"
If Grant Then GStr = "GRANT"
R = UseTsControl("set_voice " & PlayerID & " " & GStr)
Return R(0)
End Function

Public Function KickPlayerFromChannel(ByVal PlayerID As Integer, ByVal Reason As String) As String
'KickPlayerChannel
Dim R() As String
R = UseTsControl("kick_player_channel " & PlayerID & " " & Reason)
Return R(0)

End Function

Public Function KickPlayerFromServer(ByVal PlayerID As Integer, ByVal Reason As String) As String
'KickPlayerServer
Dim R() As String
R = UseTsControl("kick_player_server " & PlayerID & " " & Reason)
Return R(0)

End Function

Public Function SendTextMessageToChannel(ByVal ChannelID As Integer, ByVal Message As String) As String
'SendMessageCannel
Dim R() As String
R = UseTsControl("send_message_channel " & ChannelID & " " & Message)
Return R(0)

End Function

Public Function SendMessageToAll(ByVal Message As String) As String
'SendMessage
Dim R() As String
R = UseTsControl("send_message " & Message)
Return R(0)
End Function


Private Function UseTsControl(ByVal CommandArgs As String) As String()
Dim psi As ProcessStartInfo
psi = New ProcessStartInfo

'Configure for startup
psi.Arguments = CommandArgs
psi.CreateNoWindow = True
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.RedirectStandardOutput = True
psi.FileName = "ts\tscontrol.exe"
psi.UseShellExecute = False
Dim tscontrol As Process
Dim sr As IO.StreamReader

'Start the tscontrol.exe
tscontrol = Process.Start(psi)

'Wait till it's done running
tscontrol.WaitForExit()

'Read outputted lines from the console app
sr = tscontrol.StandardOutput

Dim Result() As String, count As Integer

Do While sr.Peek > 0
ReDim Preserve Result(count)
Result(count) = sr.ReadLine()
count += 1
Loop

Return Result
End Function

End Class
End Namespace

DesoTron
18-12-2004, 10:12
I'm now working on actuallly making something that uses the dll based api's

I'll be making some of the functions more user friendly in the good-ol-.net style fashion.

DOMINATION
20-12-2004, 09:30
I have successfully written a coldfusion based tcp/ip client (telnet). Try not to make this too difficult guys ;). You will run into a problem if your server gets several setups at the same time. When you run into that problem, post it and I will help you out. My test server has successfully setup 463 servers with 0 errors. It has also setup 47 servers at the same time. Enjoy guys!

DesoTron
20-12-2004, 09:38
okay forget that, obviously something stupid is wrong and it gives me a null refferrence exception when i try to use structures with the api, so i'll just stick to the old tscontrol thing.

m&m's
20-12-2004, 19:31
DOMINATION
responded to you in this thread .

http://forum.goteamspeak.com/showthread.php?t=19360

best of luck

DOMINATION
22-12-2004, 06:23
Thanks m&m's