Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 9th, 2003, 03:37 PM
irm_lexx's Avatar
irm_lexx irm_lexx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Posts: 253 irm_lexx User rank is Private First Class (20 - 50 Reputation Level)irm_lexx User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 19 h 40 m 27 sec
Reputation Power: 12
Question 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.

Reply With Quote
  #2  
Old February 10th, 2003, 06:15 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,382 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 20 h 34 m 6 sec
Reputation Power: 4080
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)

Reply With Quote
  #3  
Old February 22nd, 2003, 10:14 AM
irm_lexx's Avatar
irm_lexx irm_lexx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Posts: 253 irm_lexx User rank is Private First Class (20 - 50 Reputation Level)irm_lexx User rank is Private First Class (20 - 50 Reputation Level) 
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()?

Reply With Quote
  #4  
Old February 22nd, 2003, 01:14 PM
epl epl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Dublin
Posts: 413 epl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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...

Reply With Quote
  #5  
Old February 22nd, 2003, 05:55 PM
irm_lexx's Avatar
irm_lexx irm_lexx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Posts: 253 irm_lexx User rank is Private First Class (20 - 50 Reputation Level)irm_lexx User rank is Private First Class (20 - 50 Reputation Level) 
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?

Reply With Quote
  #6  
Old February 22nd, 2003, 06:04 PM
epl epl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Dublin
Posts: 413 epl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #7  
Old February 22nd, 2003, 06:11 PM
epl epl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Dublin
Posts: 413 epl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #8  
Old February 22nd, 2003, 06:41 PM
irm_lexx's Avatar
irm_lexx irm_lexx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Posts: 253 irm_lexx User rank is Private First Class (20 - 50 Reputation Level)irm_lexx User rank is Private First Class (20 - 50 Reputation Level) 
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

Reply With Quote
  #9  
Old February 22nd, 2003, 06:55 PM
epl epl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Dublin
Posts: 413 epl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #10  
Old February 22nd, 2003, 07:02 PM
irm_lexx's Avatar
irm_lexx irm_lexx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Posts: 253 irm_lexx User rank is Private First Class (20 - 50 Reputation Level)irm_lexx User rank is Private First Class (20 - 50 Reputation Level) 
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....

Reply With Quote
  #11  
Old March 19th, 2003, 07:51 PM
irm_lexx's Avatar
irm_lexx irm_lexx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Posts: 253 irm_lexx User rank is Private First Class (20 - 50 Reputation Level)irm_lexx User rank is Private First Class (20 - 50 Reputation Level) 
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?

Reply With Quote
  #12  
Old March 20th, 2003, 04:43 AM
epl epl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Dublin
Posts: 413 epl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #13  
Old March 20th, 2003, 12:17 PM
irm_lexx's Avatar
irm_lexx irm_lexx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Posts: 253 irm_lexx User rank is Private First Class (20 - 50 Reputation Level)irm_lexx User rank is Private First Class (20 - 50 Reputation Level) 
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.

Reply With Quote
  #14  
Old March 20th, 2003, 12:39 PM
epl epl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Dublin
Posts: 413 epl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #15  
Old March 20th, 2003, 01:42 PM
epl epl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Dublin
Posts: 413 epl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > query string decoding?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap