• Welcome to Valhalla Legends Archive.
 

[VB6] Whats going wrong?

Started by Sorc_Polgara, June 21, 2004, 03:18 PM

Previous topic - Next topic

Sorc_Polgara

I'm trying to use the winsock component and connect, send, and recieve the response using the BNLS_AUTHORIZE message...

Since I'm just doing a test, I just made a little program using a listbox as a debug-like thing.  The listbox is "lstDebug" and my winsock is named "ws".  Here is the code that I am having trouble with.


Private Sub mnuConnect_Click()
   Dim wsHost As String
   Dim wsPort As Long
   wsHost = "bnls.valhallalegends.com"
   wsPort = 9367
   
   ws.Connect wsHost, wsPort
End Sub

Private Sub mnuDisconnect_Click()
   ws.Close
End Sub
Private Sub ws_Connect()
   lstDebug.AddItem "Connected!"
   
   ws.SendData &HB
   ws.SendData &HE
   ws.SendData "polgara\0"
End Sub

Private Sub ws_SendComplete()
   lstDebug.AddItem "Sent Login ID"
   ws_Is_Sending = False
End Sub

Private Sub ws_DataArrival(ByVal bytesTotal As Long)
   Dim strData As String
   
   ws.GetData strData, vbString, bytesTotal
   
   lstDebug.AddItem "Data Recieved"
   lstDebug.AddItem strData
End Sub

Private Sub ws_Close()
   lstDebug.AddItem "Disconnected!"
End Sub

Private Sub ws_SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long)
   ws_Is_Sending = True
End Sub


&HB is the message size including the 3-byte headerpart of the BNLS message format.  "polgara" is like 8 bytes (including the NT byte) + 3 more bytes which is 11.

&HE is the message ID, BNLS_AUTHORIZE (0x0e)

Its not all but most of the basic code.  I made a menu named "mnuConnect" so that when I click on it I will... doh, connect :).

When I click the menu, the debug listbox shows

Connected!
Sent Login ID
Disconnected!


It seems like I am able to connect to BNLS and send my login ID "polgara" but get no response from BNLS...  Probably something to do with what I am sending.  Can I get some help on what I am doing wrong?

Stealth

#1
Edit: You are appending a header. Nevermind. I should read posts before replying.

In that case, the problem is here:

Quote"polgara\0"

VB doesn't have escape characters like other languages do. What you sent above was the string "polgara\0", forward slash, zero and all, which the BNLS server will probably reject because the packet size is now 12 but the header says it's 11. If that doesn't occur, it will reject you because the BNLS account "polgara\0" probably doesn't exist.

In order to null-terminate it you have to say:

Quote"polgara" & Chr(0)

Hope that helps.
- Stealth
Author of StealthBot

StepAside

By the why, what is the reponse type? A boolean contained in a DWORD? Or something to that effect? Listboxes and RTB's have trouble displaying such data types as you may THINK they will be displayed, but I'd try Stealth's idea first.

Stealth

He's right, you should probably use something like DebugOutput to produce a more easily-readable format for that incoming data. The listbox won't like a bunch of null characters.
- Stealth
Author of StealthBot

Sorc_Polgara

Its the BNLS_AUTHORIZE.. suppose to responed with a DWORD, servercode

I have a BNLS account, "polgara" it exists... I've used CSB with it...

Problem is that it doesn't even recognize that data has arrived.


Private Sub ws_DataArrival(ByVal bytesTotal As Long)
   Dim strData As String
   
   ws.GetData strData, vbString, bytesTotal
   
   lstDebug.AddItem "Data Recieved"
   lstDebug.AddItem strData
End Sub


Even if it were the list box, I would of atleast know that data has arrived...

Here is what I get from the list box, again.


Connected!
Sent Login ID
Disconnected!


if any data has arrived... I would of seen


Connected!
Sent Login ID
Data Recieved
Disconnected!


I'm not getting any data response... therefore even if I knew how to use the debugoutput module (which I don't) it would be useless until I recived data :\

I tried changing  "polgara\0" to what stealth said, "polgara" & chr(0)

still no data recieved.

UserLoser.

#5
You're sending 11 (0xb) as the length, when (("polgera" * chr(0) = 8) + (id = 1) + (packet len byte = 1)) = 10, not 11.  Since you're sending 11, the server is probably waiting for 2 more bytes of data from you

Sorc_Polgara

#6
Changed it to 10 (0x0A)


ws.SendData &HA
ws.SendData &HE
ws.SendData "polgara" & Chr(0)


Wow, BNLS_AUTHORIZE is like the fking easiest looking BNLS packet...

Quote
BNLS_AUTHORIZE (0x0e)
---------------------

This message logs on to the BNLS server.

(String) Bot ID.

Note: The bot ID is not case sensitive, and is limited to 31 characters.
This message must be sent before sending any other message.

Response:
---------

If the bot ID isn't recognized by the server, the connection is terminated.
Otherwise, a response is sent:

(DWORD) Server code.

I can't even fking get this to work... so frustrating, I give up.

Stealth

Hah! The packet length portion of the header needs to be a WORD. You're sending it as a byte, plus 0x0E - so the server is waiting for quite a bit more data.
- Stealth
Author of StealthBot

UserLoser.

#8
Quote from: Stealth on June 26, 2004, 05:36 PM
Hah! The packet length portion of the header needs to be a WORD. You're sending it as a byte, plus 0x0E - so the server is waiting for quite a bit more data.

Bah, by him doing .SendData 3 times, I didn't even realize that the first one should be a WORD and not a BYTE >:(

Edit: After doing small calculations, you're sending 28686 (0x700E) as the length ;)

For putting the size to a WORD, try using this function:


Private Function WORD(ByVal Data As Long) As String
   Dim strResult As String * 2

   Call RtlMoveMemory(ByVal strResult, Data, 2) 'RtlMoveMemory is more commonly refered to as CopyMemory
   WORD = strResult
End Function


Then you could do:


ws.SendData WORD(&HB) ' 2 bytes (packet len)
ws.SendData &HE ' + 1 byte = 3 bytes (packet id)
ws.SendData "polgara" & Chr(0) ' + 7 bytes + 1 null byte = 11 bytes (packet data)


Hope this helps, let us know.

Sorc_Polgara

Well, I can't give feed back on if it worked mainly b/c of this hehehehe

http://forum.valhallalegends.com/phpbbs/index.php?board=17;action=display;threadid=7476

So I don't have to worry about it anymore hehehehe

I actually learned alot though from this post and I want to thank all of you that gave helpful replies and/or tried to help me.  Thanks again. :)