🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Query servers for info - VB

Started by
14 comments, last by Epzilon 22 years, 9 months ago
I''d like some help with ''query server'' code, in VB. My goal is to query a Halflife server and the official explaination is to send Long data type set to -1. Then a String set to either "ping", "players", "info" or "rules". And last a zero byte to terminate. This zero byte I''m not familiar with. Yahn Bernier over at Valvesoftware told me that strings in c/c++ end with a zero character. This didn''t make any sense to me. He told me I should send a Byte or Long data type set to 0 at the end of the string. Well, I tried that without any success. Here''s a quote from the SDK: "Game servers will answer the following messages: Messages are sent to the server by sending 4 consecutive bytes of 255 (32-bit integer -1) and then the string command followed by a zero byte to terminate it" I''ve tried many, many variations but nothing works. All with UDP protocol of course. Any help is appreciated. Remember, in VB.
Advertisement
query_msg = query_msg & Chr(0)

Although I think if you are using the String datatype it may already null-terminated depending on how you send it.

The background is that C does not have a "proper" string class, it instead represents a string as an array of type char, and end of the string is signified with a null (or zero) character: '\0'

I believe STL defines a C++ String class, but even so, its internal representation is the same as in C for compatability.

You may need to use the above code to force a null byte onto the end of the string. Output the messages hex-reader to see what you get, because all ordinary text-readers will automatically see the null terminating character as nothing more than the end of the string, and they don't put it in the text control.
-------------
-WarMage
...VB is a terrible waste of mind...

Edited by - WarMage on September 18, 2001 3:56:43 PM
Thanks for your reply but I still can''t get it to work.
I did notice one thing though... after I compile the code and run it I get a run-time 126 error without any description but only if I run the compiled .exe
a 126 error, if I recall, doesn''t mean all that much, probably a buffer overrun. Post your message building code and your socket code so we can look for errors.

-------------
-WarMage
...lick my frozen metal ass! - Bender (is god!)...
What about this:
Get an IP Traffic monitor and check the in- and outgoing packets.
You can see then if you send the right data and what you get
returned.

I''m sorry, but I have currently no URL where to get one, try
any search engine.

Besides: go get a C compiler and go on programming in C/C++ )
Just as simple to write your own listener client that outputs all its bytes to hex. It also makes an excellent tooth-cutter for sockets, IMNSHO.

-----------
-WarMage
...report all problems to /dev/null...
Right, I can write down a simple example without any excess code.

---------------

btnSend_Click()
Dim lqm As Long, strqm As String
lqm = -1
strqm = "rules" & Chr(0)
Winsock.SendData lqm
DoEvents
Winsock.SendData strqm
End Sub

Form_Load()
Winsock.Protocol = sckUDPProtocol
Winsock.RemoteHost =
Winsock.RemotePort = 27015
Winsock.Bind 27016
End Sub

Winsock_DataArrival()
MsgBox "A simple messagebox to confirm that data was actually received"
End Sub

---------------------

Note that I''ve tried many more different methods in the btnSend_Click event.
One other thing, slightly off-topic...
It''s rare you can mention VB without people trying to convince you to start with c++
As a response to those people, don''t you think you need a teacher/friend to help you with the basics? Seems to me the more I try to understand c++, the more confused I get.
First time I laid eyes on VB programming was a few years ago while I sat beside a friend of mine. Having sat there a while watching him code, I noticed myself _correcting his errors_ without any previous knowledge of the language. It''s not hard to understand that I was hooked after that
quote: Original post by Epzilon
Right, I can write down a simple example without any excess code.

---------------

btnSend_Click()
Dim lqm As Long, strqm As String
lqm = -1
strqm = "rules" & Chr(0)
Winsock.SendData lqm
DoEvents
Winsock.SendData strqm
End Sub


You need to try something like
Winsock.SendData lqm & strqm
SendData is a blocking call, it posts the request to the server, then awaits a response, and closes the socket. All the server sees from your IP is the value in lqm, then a disconnect and reconnect, followed by the value in strqm.

Unless you write winsock event handlers and set your socket mode to non-blocking (which you may not be able to do easily in VB), you aren''t going to send any "real" message to the server, and hence no valid response.

--------------
-WarMage
...bleep the bleeping bleepers first...
I see.
Though I have tried to send all-in-one but no luck there either

This topic is closed to new replies.

Advertisement