home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "Parsers"
- '
- ' Xceed Winsock Library Sample: Tron Sample
- ' Copyright (c) 2000 Xceed Software Inc.
- '
- ' [Code module with parser(s) for XML-style data]
- '
- ' This sample application for the Xceed Winsock Library demonstrates
- ' service advertising and service lookup using the SAP protocol, as
- ' well as connectionless asynchronous byte transfers using the IPX
- ' protocol. All transfer events are handled via the "Implements"
- ' statement. To successfully create a game, you must have the SAP
- ' protocol installed on your system. Otherwise, you can only list
- ' and join games.
- '
- ' This file is part of the Xceed Winsock Library Samples.
- ' The source code in this file is only intended as a supplement
- ' to Xceed Winsock Library's documentation, and is provided "as is",
- ' without warranty of any kind, either expressed or implied.
- '
-
- Option Explicit
-
- ' This function parses XML-style strings to extract player update information
- ' that was broadcast by the game server.
- '
- Public Function ParsePlayerData(Data As String, PlayerID As Integer) As PlayerUpdate
-
- Dim Player As PlayerUpdate
- Dim Pnum As Integer
- Dim PlayerData As String
- Dim Pstart As Integer
- Dim Pend As Integer
- Dim Ptag As Integer
- Dim Ptag2 As Integer
-
- ' Find the start of the player information
-
- Pstart = InStr(Data, "<player playerid=" & CStr(PlayerID))
-
- If Pstart > 0 Then
- Player.Found = True
- Pend = InStr(Pstart, Data, "</player>")
- PlayerData = Mid$(Data, Pstart, Pend - Pstart + 9)
-
- ' Obtain player's name
-
- Ptag = InStr(PlayerData, "name=" & Chr$(34))
- Ptag2 = InStr(Ptag + 6, PlayerData, Chr$(34))
-
- If Ptag > 0 And Ptag2 > Ptag Then
- Player.Name = Mid$(PlayerData, Ptag + 6, Ptag2 - Ptag - 6)
- End If
-
- ' Obtain X, Y position
-
- Ptag = InStr(PlayerData, "<pos x=")
- Player.X = Val(Mid$(PlayerData, Ptag + 7))
- Ptag = InStr(PlayerData, "y=")
- Player.Y = Val(Mid$(PlayerData, Ptag + 2))
-
- Player.IsAlive = (InStr(PlayerData, "alive=TRUE") > 0)
-
- Ptag = InStr(PlayerData, "updbrakes=")
- If Ptag > 0 Then
- Player.UpdateBrakes = Val(Mid$(PlayerData, Ptag + 10))
- End If
-
- Ptag = InStr(PlayerData, "updnitro=")
- If Ptag > 0 Then
- Player.UpdateNitro = Val(Mid$(PlayerData, Ptag + 9))
- End If
- Else
- Player.Found = False
- End If
-
- ParsePlayerData = Player
-
- End Function
-