The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Visual Basic Programming
|
query string decoding?
Discuss query string decoding? in the Visual Basic Programming forum on Dev Shed. query string decoding? Visual Basic Programming forum discussing VB specific programming information. Quickly prototype and build applications with this robust and simple language.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 9th, 2003, 03:37 PM
|
 |
Contributing User
|
|
Join Date: Mar 2002
Posts: 253

Time spent in forums: 2 Days 19 h 40 m 27 sec
Reputation Power: 12
|
|
query string decoding?
Does anyone know how to decode a HL server query string?
Here is a query code
Code:
Private Sub send_Click()
winsock.RemoteHost = ip 'server ip
winsock.RemotePort = CInt(Port) 'server port
winsock.SendData Char(255) & Char(255) & Char(255) & Char(255) & "players"
End Sub
Private Sub winsock_DataArrival(ByVal bytesTotal As Long)
Dim Data As String
winsock.GetData Data, , bytesTotal 'returned packet
End Sub
It returns some crazy string that needs to be decoded or something?
__________________
Thank you for any help.
|

February 10th, 2003, 06:15 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
Don't think anyone can help you unless you tell us what the encoding method from the server is first (or provide us a sample string possibly) 
|

February 22nd, 2003, 10:14 AM
|
 |
Contributing User
|
|
Join Date: Mar 2002
Posts: 253

Time spent in forums: 2 Days 19 h 40 m 27 sec
Reputation Power: 12
|
|
the return data is inthe following format
(int32) -1
(byte) ASCII 'D' (players response, S2A_PLAYER)
(byte) active client count
for each active client
(byte) client number / index
(string) player name
(int32) client's frag total
(float32) client's total time in-game
sample data returned , I recieved the data as string:
Quote:
ÿÿÿÿD
Cygnus )ŒBLee KUM Kee Êã’Cwildchild )ÿÙBMeMp|-|IS i2AiNeS ó6_DMr.Deagle
ùYE[needclan] CsMaster ótäD |
Most of the time asc() works to turn the strings into numbers but negative numbers dont work with asc()?
|

February 22nd, 2003, 01:14 PM
|
|
Contributing User
|
|
Join Date: Mar 2001
Location: Dublin
Posts: 413
Time spent in forums: 2 h 18 m 18 sec
Reputation Power: 13
|
|
|
have you tried defining the data variable as a user defined type / structure in the same format as the data?
or as a byte array while you debug...
|

February 22nd, 2003, 05:55 PM
|
 |
Contributing User
|
|
Join Date: Mar 2002
Posts: 253

Time spent in forums: 2 Days 19 h 40 m 27 sec
Reputation Power: 12
|
|
|
byte array is okay, but is it correct that say -1 ( negative one)
is 255 as a byte because thats what i get, and so on -2 = 254, -3 = 243 is that right?
|

February 22nd, 2003, 06:04 PM
|
|
Contributing User
|
|
Join Date: Mar 2001
Location: Dublin
Posts: 413
Time spent in forums: 2 h 18 m 18 sec
Reputation Power: 13
|
|
i would have thought that a 32 bit int would be spread over 4 bytes - and for -1 you'll get four 255's in each of the bytes ... but you're right that the negatives are 255 = 2^8-1 = -1, 254 = -2 etc. for 8 bit. 65535 = 2^16-1 = -1, 65534 = -2 for 16bit and so on, if you follow
if you read the first value into a long it should just come out as -1
ie (i guess)
Code:
Private Sub winsock_DataArrival(ByVal bytesTotal As Long)
Dim Data As String, MinusOne as Long
winsock.GetData MinusOne, , 4
winsock.GetData Data, , bytesTotal-4
End Sub
What do you think?
|

February 22nd, 2003, 06:11 PM
|
|
Contributing User
|
|
Join Date: Mar 2001
Location: Dublin
Posts: 413
Time spent in forums: 2 h 18 m 18 sec
Reputation Power: 13
|
|
i think the tidiest way might be to read into user defined structures like this (from the top of my head)
Code:
Private Type Header
MinusOne as Long
Response as Byte
PlayerCount as Byte
End Type
Private Type Player
Index as Byte
Name as String
FragTotal as Long
TimeTotal as Double
End Type
Private Sub winsock_DataArrival(ByVal bytesTotal As Long)
Dim Header as Header, Player as Player, i as Byte
call winsock.GetData(Header, , Len(Header))
For i=1 to Header.PlayerCount
call winsock.GetData(Player, , Len(Player))
Next i
End Sub
Does that make sense? Like I say, it's off the top of my head so I don't necessarily expect to to work straight off - just to illustrate what i mean
|

February 22nd, 2003, 06:41 PM
|
 |
Contributing User
|
|
Join Date: Mar 2002
Posts: 253

Time spent in forums: 2 Days 19 h 40 m 27 sec
Reputation Power: 12
|
|
it sounds good
I get error " only user-defined types defined in public objects modules can be coerced to or from a variant or passed to late-bound functions" and it points to "Call Winsock.GetData(Header, , Len(Header))" and hilights Header
|

February 22nd, 2003, 06:55 PM
|
|
Contributing User
|
|
Join Date: Mar 2001
Location: Dublin
Posts: 413
Time spent in forums: 2 h 18 m 18 sec
Reputation Power: 13
|
|
|
Try playing around a bit with where you declare the type (at the top of which module) and also try changing Private Type to Public Type etc. and see what the compiler accepts
|

February 22nd, 2003, 07:02 PM
|
 |
Contributing User
|
|
Join Date: Mar 2002
Posts: 253

Time spent in forums: 2 Days 19 h 40 m 27 sec
Reputation Power: 12
|
|
|
ya, i tried placing it everywhere and changed to public and stuff, still gives me that error....
|

March 19th, 2003, 07:51 PM
|
 |
Contributing User
|
|
Join Date: Mar 2002
Posts: 253

Time spent in forums: 2 Days 19 h 40 m 27 sec
Reputation Power: 12
|
|
|
I have problem with getting data from a winsock packet....
in the udp it returns int32 along with strings and float32
so the first int32
i go
dim num as long
winsock.getdata num,vblong,4
But i get an error saying that the "datagram is too large to fit into the buffer and is trucated", what does that mean? isnt Long 4 bytes?
Also if I just do the bytes array like
dim bytes() as byte
winsock.getdata bytes
the float32 is spread in 4 slots, like bytes(1), bytes(2), bytes(3), and bytes(4), so how can they be turn it into a single number?
|

March 20th, 2003, 04:43 AM
|
|
Contributing User
|
|
Join Date: Mar 2001
Location: Dublin
Posts: 413
Time spent in forums: 2 h 18 m 18 sec
Reputation Power: 13
|
|
|
yes, a long is 4 bytes (you can use LenB to check)
I think you can possibly load the float the same way (into a single?) ... otherwise you could experiment with some different numbers and see what you get in your byte array for different float values.
|

March 20th, 2003, 12:17 PM
|
 |
Contributing User
|
|
Join Date: Mar 2002
Posts: 253

Time spent in forums: 2 Days 19 h 40 m 27 sec
Reputation Power: 12
|
|
|
like turn those 4 bytes into one number, I tried
clng(bytes(1)&bytes(2)&bytes(3)&bytes(4))
but it doesnt work, it gives over flow error.
|

March 20th, 2003, 12:39 PM
|
|
Contributing User
|
|
Join Date: Mar 2001
Location: Dublin
Posts: 413
Time spent in forums: 2 h 18 m 18 sec
Reputation Power: 13
|
|
|
no, i mean find out (search the net, i guess) how vb stores floats and reconstruct the relevant value from the byte array. what happens if you read directly into a single?
|

March 20th, 2003, 01:42 PM
|
|
Contributing User
|
|
Join Date: Mar 2001
Location: Dublin
Posts: 413
Time spent in forums: 2 h 18 m 18 sec
Reputation Power: 13
|
|
some links...
an explanation of converting from single number to underlying bytes
http://www.cis.udel.edu/~sullivan/c...nternalRep.html
a microsoft description:
http://msdn.microsoft.com/library/d...tm/decla_36.asp
and a description of the byte representation:
http://msdn.microsoft.com/library/d...t_Languages.asp
(I think there's an error in that the sign bit is missing from the real * 4 definition and the mantissa has nine bits ... i guess that the first mantissa bit should, in fact, be the sign bit
here's a conversion function from the top of my head:
Code:
Option Base 0
Public Function bytesToSingle(ByRef bytes() As Byte) As Single
Dim sign As Integer, exponent As Byte, mantissa As Long
Let sign = IIf(bytes(0) \ 128, -1, 1)
Let exponent = (2 * (bytes(0) And 127) + bytes(1) \ 128)
Let mantissa = (bytes(1) Or 128) * 65536& _
+ bytes(2) * 256& _
+ bytes(3)
Let bytesToSingle = sign * mantissa * 2 ^ (exponent - 150)
End Function
Last edited by epl : March 21st, 2003 at 04:13 AM.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|