PDA

View Full Version : Question about the ASP script


IRON_Sniper
19-12-2002, 17:46
First, thank you for making the ASP script!

I am trying to just get a simple list of on-line names from a TS server and spit it back out to file.

With the 1.5 TS servers, it was easy, because the server was sending out the user names to the ASP page every 3 minutes. (see an example at the top of http://iron-forums.homeip.net )

Now, in TS 2.0, the TS server does not send out the user names. Instead, we must query the TS server to get that information. To make this query, we need to use the methods provided by W3 Sockets.

Now, Dark-mixer has released ASP code that can do all of things, as long as you have installed W3 Sockets (again, Thanks!!!!!). I was looking through this code, and I understand how it all works. Using portions of this code, I am adapting my old TS 1.5 code to work with 2.0. However, there is one snippet of code that I cannot understand.

In FUNCTION.ASP where you define the GetUserInfo function, you have the following code:

Function GetUserInfo(usrData,xID)
tmpArray = Split(usrData,vbTab)
For I = 0 To UBound(tmpArray) - 1
If Len(tmpUsr) > 0 Then tmpUsr = tmpUsr & vbTab
tmpUsr = tmpUsr & tmpArray(I)
Next


Where is tmpUsr defined? I searched through all of the ASP pages provided, and I did not see it declared anywhere, but on the 4th line of the function, you are looking at the length of tmpUsr.

If tmpUsr should be declared, where should it be declared and what is the default value?



BTW, here is modified code I have right now:

T2WEBPOST.ASP
(note that I just pass the command directly to the GetServerData function, because I am only interested in getting a plain list of current nicknames on the TS server)


<%@ LANGUAGE = "VBScript" %>
<!--#include file="inc_ts2.asp"-->
<%
Server = Request.ServerVariables("REMOTE_ADDR")
ConnPort = Request.ServerVariables("server_queryport")
Port = Request.ServerVariables("server_port")

UserData = GetServerData(Server,ConnPort,Port,"pl")
UserNames = Split(GetUserInfo(UserData,14),vbCrLf)

DisplayNames = ""

If Ubound(UserNames) > 0 Then
For Ix = 0 To UBound(UserNames)
If Ix = UBound(UserName) Then
DisplayNames = DisplayNames & UserNames(Ix)
Else
DisplayNames = DisplayNames & UserNames(Ix) & ", "
End If
Next
Else
DisplayNames = "no players online at this time"
End If

Dim objFSO, objTextFile
Const ForReading = 1, ForWriting = 2, ForAppending = 8
If Request.QueryString <> "" Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\inetpub\wwwroot\ts2\ts2_001.js", ForWriting, True)
objTextFile.WriteLine "var dynText=''"
objTextFile.WriteLine "dynText+='Teamspeak users on <b>" & Request.QueryString("server_name") & "</b> (" & Server & ") <br>on " & Now & " CST<br><b>" & DisplayNames & "</b>'"
objTextFile.WriteLine "document.write(dynText)"
objTextFile.Close
Set objTextFile = Nothing
Set objFSO = Nothing
End If
%>




INC_TS2.ASP


Function GetServerData(xServer,xConnPort,xPort,xCommand)

'Open w3 Socket
set socket = Server.CreateObject("Socket.TCP")

'Setting up the virtual telnet session.
socket.DoTelnetEmulation = true
socket.TelnetEmulation = "vt100"
socket.Host = xServer & ":" & xConnPort

'Connection to the server.
socket.Open()
socket.WaitFor("[TS]")

'Send command to server.
socket.SendText(xCommand & " " & xPort & vbCrLf)
socket.WaitFor("OK")

'Storing the data
GetServerData = socket.Buffer

'Sending quit command to server.
socket.SendText("quit" & vbCrLf)
socket.WaitForDisconnect
socket.Close()
set socket = Nothing

End Function



Function GetUserInfo(usrData,xID)
tmpArray = Split(usrData,vbTab)
For I = 0 To UBound(tmpArray) - 1
If Len(tmpUsr) > 0 Then tmpUsr = tmpUsr & vbTab
tmpUsr = tmpUsr & tmpArray(I)
Next

xUsr = Split(tmpUsr,vbTab)
If UBound(xUsr) >= 15 Then
For I = 0 To UBound(xUsr) step 16
If Len(xOutUsr) > 0 Then xOutUsr = xOutUsr & vbCrLf
xOutUsr = xOutUsr & xUsr(I + int(xID))
Next
Else
xOutUsr = ""
End If
GetUserInfo = xOutUsr
End Function




Comments, suggestions, improvements??? Please let me know, and Thanks in advance!

Dark-mixer
23-12-2002, 19:42
Hello Iron
First of all thx for you comment :)

Second
The function are pretty simple.
if tmpUsr isn't defined it will by default have a zero length.
The variable are for the first time defined in the line :
tmpUsr = tmpUsr & tmpArray(I)

If you would like to have your script reviewed just mail a copy to me, and i'll go through it :)

/Dark-MiXer