Valhalla Legends Forums Archive | Battle.net Bot Development | A little help needed...

AuthorMessageTime
RedPhoenix
I working on making a bot using Visual Basic .Net. So far I'm able to connect to Battle Net and get on the Public chats. Now if I want to expand my region my bot can go. Lets say for example StarCraft, and enter Broad War USA-01. How should the string to first initialize the chat logon be structured? Right now I'm using this string to logon:

Chr(3) & Chr(4) & AccountName & Chr(13) & Chr(10) & AccountPassword & Chr(13) & Chr(10)
April 15, 2004, 7:00 AM
Tuberload
BNetDocs is a good place to start. It might not be enough, but it would be worth looking at.
April 15, 2004, 7:03 AM
Maddox
Chr(13) & Chr(10) is VbCrLf.
April 15, 2004, 7:06 AM
RedPhoenix
Lol I know, I got some of the basis for it from a vb 6 source I found. Just left it like it was, either way works.
April 15, 2004, 7:13 AM
LoRd
Resources to help you (in order from simplest to hardest):

1. http://www.valhallalegends.com/CupHead/ => CleanSlateBot
2. http://www.valhallalegends.com/yoni/BNLSProtocolSpec.txt
3. http://bnetdocs.valhallalegends.com/
April 15, 2004, 7:18 AM
RedPhoenix
The links are not much help, I'll just use the method of trial and error. I'll eventually end up getting the strings needed to connect to the *restricted* servers eventually.
April 15, 2004, 9:11 AM
Eli_1
[quote] I'll just use the method of trial and error. I'll eventually end up getting the strings needed. [/quote]

I'm under the impression that you still think you only need to modify the login packet from the CHAT connection. If that's the case then no you wont. I suggest you read this post, https://davnit.net/bnet/vL/phpbbs/index.php?board=17;action=display;threadid=6023;start=msg52131. This person seems to have the same problem as you, and there's a lot of good links that you should read if you want to learn.
April 15, 2004, 10:42 AM
iago
I am interested in seeing this "Broad War"

But anyway, there are TONS of posts here just like yours. Try reading through them.
April 15, 2004, 1:09 PM
Myndfyr
[quote author=LoRd[nK] link=board=17;threadid=6315;start=0#msg55223 date=1082013493]
Resources to help you (in order from simplest to hardest):

1. http://www.valhallalegends.com/CupHead/ => CleanSlateBot
2. http://www.valhallalegends.com/yoni/BNLSProtocolSpec.txt
3. http://bnetdocs.valhallalegends.com/
[/quote]

Eww @ using a COM OCX in Visual Basic .NET. :P

I'm developing a .NET component (assembly) that takes care of all of the underlying connection mechanism (similarly to how CSB does it). The Alpha 4 version, which has support for Warcraft III clans, should be ready to go by the end of April or early May.

I'd be willing to share it as long as you're not a lamer. You have to put forth *some* effort to understand how it works.
April 15, 2004, 1:32 PM
RedPhoenix
Here's what I got so far, It still needs more features etc... I just started this last night, this will connect you to the Public Chat 1 server in Battle Net.

Imports System.Net.Sockets
Imports System.Text
Imports System.Threading

Dim client As New TcpClient()

Private strServer As String = "useast.battle.net"
Private msgStart As [String] = Chr(3) & Chr(4) & AccountName & Chr(13) & Chr(10) & AccountPassword & Chr(13) & Chr(10)

Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
Try
' Create a TcpClient.
' Note, for this client to work you need to have a TcpServer
' connected to the same address as specified by the server, port
' combination.
client.Connect(strServer, 6112)

' Translate the passed message into ASCII and store it as a Byte array.
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(msgStart)

' Get a client stream for reading and writing.
' Stream stream = client.GetStream();
Dim stream As NetworkStream = client.GetStream()
stream.Write(data, 0, data.Length)
txtRecieve.Text &= "Initializing....." & vbCrLf

' Receive the TcpServer.response.
' Buffer to store the response bytes.
data = New [Byte](256) {}

' String to store the response ASCII representation.
Dim responseData As [String] = [String].Empty

' Read the first batch of the TcpServer response bytes.
Dim bytes As Int32 = stream.Read(data, 0, data.Length)
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
txtRecieve.Text &= "Connected to Battle net: " & Format(Now, "mm/dd/yyy hh:mm:ss tt") & vbCrLf

Dim t As New Thread(New ThreadStart(AddressOf GetData))
t.Start()

Catch ex As ArgumentNullException
txtRecieve.Text &= "ArgumentNullException: " & ex.ToString

Catch exc As SocketException
txtRecieve.Text &= "SocketException: " & exc.ToString

End Try
End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim msgSend As String = txtSend.Text & Chr(13) & Chr(10)
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(msgSend)
Dim stream As NetworkStream = client.GetStream()

' Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length)

txtRecieve.Text &= AccountName & msgSend
txtRecieve.SelectionStart = txtRecieve.TextLength - 1
txtSend.Text = ""
End Sub

Private Sub GetData()
'This retrieves the messages from users every 2 secs.
Dim msgSend As String = "0x00" & Chr(13) & Chr(10)
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(msgSend)
Dim stream As NetworkStream = client.GetStream()

data = New [Byte](256) {}

Dim responseData As [String] = [String].Empty
Dim bytes As Int32 = stream.Read(data, 0, data.Length)

responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
txtRecieve.Text &= responseData
txtRecieve.SelectionStart = txtRecieve.TextLength - 1

Thread.CurrentThread.Sleep(500)
If txtRecieve.TextLength > 1100 Then
txtRecieve.Text = ""
End If
GetData()
End Sub
April 15, 2004, 4:49 PM
RedPhoenix
Where AccountName and AccountPassword = just place in quotes your games account name & password you made. Or at the top make something like this:

Dim AccountName As String = "YourName"
Dim AccountPassword As String = "YourPassword"


Lol I keep wanting to end my lines with a dang semicolon!

P.S. The code above is written in Visual Basic .Net 2002
April 15, 2004, 4:55 PM
iago
You're nowhere near what you will need to make a binary connection. There's A LOT more to it.
April 15, 2004, 4:59 PM
LordNevar
Dang, that's all I had to do to make a binary connection, and all this time wasted working with BNLS, and Hash Files. aw..... :(

Note the sarcasm.
April 15, 2004, 6:33 PM
iago
lmao, I just noticed the subject is "A little help needed..."

ha'
April 15, 2004, 6:57 PM
Myndfyr
[quote author=RedPhoenix link=board=17;threadid=6315;start=0#msg55271 date=1082048145]
Where AccountName and AccountPassword = just place in quotes your games account name & password you made. Or at the top make something like this:

Dim AccountName As String = "YourName"
Dim AccountPassword As String = "YourPassword"


Lol I keep wanting to end my lines with a dang semicolon!

P.S. The code above is written in Visual Basic .Net 2002
[/quote]

Well congrats, I must say that if you've gotten past the connection part, that was the biggest hurdle for me to get over :)

What everyone else here means by saying that you need to have a "binary" connection is that you need to be able to deal with data that you don't use with just strings, both sending and receiving. It's a lot more involved than this.

Heh -- I feel your pain; I'm guessing that you found some VB bot source code online, and rather than porting it to C#, you just ran the conversion wizard to VB .NET, didn't you? :P Whenever I work in VB, invariably I have a couple compile-time errors from ending my lines in semicolons;

Anyway, like I said, if you're an experienced programmer, I'm willing to work with you on the bot. Give me a holler on e-mail or MSN; if you want to catch me on AIM, I need to add you first. PM me your name, or have it in your profile.
April 15, 2004, 8:16 PM
RedPhoenix
First I got a vb 6 source that used the winsock control. Knowing that I couldn't use the winsock control I had to find an alternate route. Search the internet and found the TcpClient class. The samples listed showed only how to connect, not to keep looping and recieving messages as I did with the thread class. Only use I got from the vb 6 source was the server name, port number, and string to connect. Even though I had to alter the string that was in the vb 6 code. I found the majority of the code on MSDN, just had to work with the syntax a little to get it to do something. I have an Associates in Computer Programming if that helps to let you know how my background in programming is.
April 15, 2004, 10:25 PM
RedPhoenix
By the way, I know the source I posted looks like plain ol' crap. I felt bad after posting it. It's just a early early skeleton chat client. I built it in less than 24 hours. So please excuse the poor structure. :-\
April 15, 2004, 10:27 PM
Tuberload
[quote author=RedPhoenix link=board=17;threadid=6315;start=15#msg55317 date=1082068072]
By the way, I know the source I posted looks like plain ol' crap. I felt bad after posting it. It's just a early early skeleton chat client. I built it in less than 24 hours. So please excuse the poor structure. :-\
[/quote]

You should see the original prototype of my bot. I like to get things working, and then make them look pretty. There is nothing wrong with that. ;)
April 15, 2004, 10:34 PM
iago
[quote author=Tuberload link=board=17;threadid=6315;start=15#msg55320 date=1082068464]
[quote author=RedPhoenix link=board=17;threadid=6315;start=15#msg55317 date=1082068072]
By the way, I know the source I posted looks like plain ol' crap. I felt bad after posting it. It's just a early early skeleton chat client. I built it in less than 24 hours. So please excuse the poor structure. :-\
[/quote]

You should see the original prototype of my bot. I like to get things working, and then make them look pretty. There is nothing wrong with that. ;)
[/quote]

I tried that and it involves TONS of rewriting later. I wish I'd done it better from the start.

I've also rewritten tons of code people at work wrote because it was poorly planned and ended up as a mess.
April 15, 2004, 11:03 PM
RedPhoenix
Myndfyre, I added you to my msn and icq. Plus I have downloaded an IP packet logger and have been looking it over as compared to the docs.
April 15, 2004, 11:24 PM
Tuberload
[quote author=iago link=board=17;threadid=6315;start=15#msg55328 date=1082070203]
[quote author=Tuberload link=board=17;threadid=6315;start=15#msg55320 date=1082068464]
[quote author=RedPhoenix link=board=17;threadid=6315;start=15#msg55317 date=1082068072]
By the way, I know the source I posted looks like plain ol' crap. I felt bad after posting it. It's just a early early skeleton chat client. I built it in less than 24 hours. So please excuse the poor structure. :-\
[/quote]

You should see the original prototype of my bot. I like to get things working, and then make them look pretty. There is nothing wrong with that. ;)
[/quote]

I tried that and it involves TONS of rewriting later. I wish I'd done it better from the start.

I've also rewritten tons of code people at work wrote because it was poorly planned and ended up as a mess.
[/quote]

What I meant by that was, I first get the bot connected in a procedural matter, then I convert it to a more OO event driven system. I do that right after I figure out how to do what it is I am doing. So for me at least, it usually does not end up requiring too much re-writing. More or less it just involves re-organizing and separating functionality to separate classes. I like to build one piece at a time, so when it is complete I don't have to mess with it much, accept maintenance and additions.
April 16, 2004, 12:04 AM
RedPhoenix
I didn't know how far I would get, wasn't going to invest alot of time into it if I couldn't even connect. But, here I am still trying to figure out the binary string to send it lol. The packets I logged, doesn't interpret that easy:

68XIPXES
USA.United States

starcraft.exe 03/28/03 04:21:56

[Server List Version]..VER=1001....[Server Gateways]..1=uswest.battle.net..2=useast.battle.net..3=asia.battle.net..4=europe.battle.net....[uswest.battle.net]..ZONE=8..ENU=U.S. West..FRA=U.S. Ouest....[useast.battle.net]..ZONE=6..ENU=U.S. East..FRA=U.S. Est....[asia.battle.net]..ZONE=-9..ENU=Asia..FRA=Asie....[europe.battle.net]..ZONE=-1..ENU=Europe..FRA=Europe..


**Note: I excluded some data I found due to I don't know how the content of it. Another thing I noticed that looked wierd was this:

A=####### B=####### C=######## 4A=A+S B=B-C C=C^A A=A-B

Where # was a series of numbers. I never messed with network packets before, maybe you all can point me to some material on where to decipher this data. I've tried sending the server the different strings (Converted to Ascii) but, didn't have much luck getting a response. Plus, I can't use Ethreal, it's only for high speed internet users. Me, I'm still in the stoneage with a 56k modem.
April 16, 2004, 6:37 AM
Myndfyr
[quote author=RedPhoenix link=board=17;threadid=6315;start=15#msg55376 date=1082097479]
I didn't know how far I would get, wasn't going to invest alot of time into it if I couldn't even connect. But, here I am still trying to figure out the binary string to send it lol. The packets I logged, doesn't interpret that easy:

68XIPXES
USA.United States

starcraft.exe 03/28/03 04:21:56

[Server List Version]..VER=1001....[Server Gateways]..1=uswest.battle.net..2=useast.battle.net..3=asia.battle.net..4=europe.battle.net....[uswest.battle.net]..ZONE=8..ENU=U.S. West..FRA=U.S. Ouest....[useast.battle.net]..ZONE=6..ENU=U.S. East..FRA=U.S. Est....[asia.battle.net]..ZONE=-9..ENU=Asia..FRA=Asie....[europe.battle.net]..ZONE=-1..ENU=Europe..FRA=Europe..


**Note: I excluded some data I found due to I don't know how the content of it. Another thing I noticed that looked wierd was this:

A=####### B=####### C=######## 4A=A+S B=B-C C=C^A A=A-B

Where # was a series of numbers. I never messed with network packets before, maybe you all can point me to some material on where to decipher this data. I've tried sending the server the different strings (Converted to Ascii) but, didn't have much luck getting a response. Plus, I can't use Ethreal, it's only for high speed internet users. Me, I'm still in the stoneage with a 56k modem.
[/quote]

From Open Bnetdocs:

C->S SID_AUTH_INFO
Packet id: 0x50 - &H50

Format:
(DWORD) Protocol ID (Use zero)
(DWORD) Platform ID 'IX86', which is what you see as "68XI"
(DWORD) Product ID 'SEXP', which is what you see as "PXES"
(DWORD) Version byte (I think the present one is 10 dec, so you would see 0a 00 00 00 in hex)
(DWORD) Product language (I think probably 1033 decimal, 09 04 00 00 hex)
(DWORD) Local IP (This is used for NAT translation; it CAN be 0).
(DWORD) Time zone (this is your timezone bias multiplied by -60. So, I'm GMT -7, the number to send is 420, or A4 01 00 00 as you would see it from a capture)
(DWORD) ?Locale ID (We don't know, probably 0)
(DWORD) ?Language ID (I don't know, you can leave it as 0)
(STRING) Country abreviation (Don't believe Open BnetDocs when it says it's a DWORD. It's a null-terminated string, "USA" + (char)0.
(STRING) Country name "United States" + (char)0.

That A=, B= junk is the response Checksum Equation for response 0x50, SID_AUTH_INFO

(STRING) Exe information
is what you see in starcraft.exe, blah blah blah :)

Hope that helps. You never re-IMed me, and I didn't save your name.

April 16, 2004, 6:48 AM
RedPhoenix
**Please note I'm not asking for anyone's code. I won't learn anything by that route.

After checking all 59 pages, tell me if I have the right concept.

Connecting with Chr(3) & Chr(4) is telling the server your wanting to join the regular chat. Now to join the private admin chats I would use 0x01 and then the rest of the data. Soon as I can get back on the bnetdocs page. I'll take a look at the order in which to send the data. I also read that the server may not want the data in a specific way each time, that it could change the order in which it wants the user data.
April 16, 2004, 8:27 AM
Tuberload
[quote author=RedPhoenix link=board=17;threadid=6315;start=15#msg55386 date=1082102182]
Is the site down? http://bnetdocs.valhallalegends.com/ and http://valhallalegends.com/ ?? Hasn't loaded for me in several hours.
[/quote]

Yes, the valhallalegends.com has been up and down for a little while now. I am sure it will be up and running shortly.

As for some of your previous questions:

I recommend getting WPE Pro as a packet sniffer. It is really simple and easy to use, and gets the job done effectively. I have been pleased with it so far.

You do not have to login to the chat gateway to use the binary gateway. They are completely different protocols. When you connect to battle.net, send (byte) 0x01. That will tell the server that you want to use the binary gateway. 0x03 is the chat gateway, and 0x02 is the file server.

Battle.net packets follow the following format (please excuse any errors):
(byte) header (byte) packet id (word) packet length, followed by the packet message.

header: for the majority of the battle.net packets, this will always be 0xFF

packet id: this verifies what the packets purpose is, i.e. is it a chat event,a logon challenge, etc...

packet length: the lenght, in bytes, of the packet including the three byte header

The main data types used in the packet message are BYTE's, WORD's, DWORD's, and NTString's.

BYTE: an 8-bit integer, i.e. 0xFF
WORD: a 16-bit, or two byte integer i.e. 0xFF3A
DWORD: a 32-bit, or four byte integer i.e. 0xFF3AFF3A
NTString: a null (0x0) terminated string, i.e. "Tuberload" == 0x54 0x75 0x62 0x65 0x72 0x6C 0x6F 0x61 0x64 0x0

In the battle.net packets, WORD’s and DWORD’s are represented little endian, or the least signifigant byte first. So the DWORD 2882400018 (0xABCDEF12) would be stored in the packet as 0x12EFCDAB. WORD’s follow the same format. Depending on the language you use, signed integers can be a problem. They can be easily addressed though.

Please excuse the brevity of this post, and I am sorry for any possible falsification’s that may be present. You should be able to get an overall idea for what is going on, and I am sure someone will correct any of my mistakes.

As soon as valhallelends.com is back up I would recommend thoroughly reading BnetDocs, and possible looking into BNLS to aid you in the login procedure.

Edit: Fixed an error
April 16, 2004, 8:48 AM
Myndfyr
[quote author=Tuberload link=board=17;threadid=6315;start=15#msg55389 date=1082105312]
Please excuse the brevity of this post, and I am sorry for any possible falsification’s that may be present. You should be able to get an overall idea for what is going on, and I am sure someone will correct any of my mistakes.
[/quote]

LoL Tuberload, it's the "cover my ass" qualifier :P

Phoenix: I recommend that, rather than posting three times in a row, just use "Modify" if nobody has posted since you last did. It's nicer that way. :) If you want to chat w/ me, you need to message me, or put your MSN in your profile.
April 16, 2004, 1:26 PM
Tuberload
[quote author=Myndfyre link=board=17;threadid=6315;start=15#msg55413 date=1082122017]
[quote author=Tuberload link=board=17;threadid=6315;start=15#msg55389 date=1082105312]
Please excuse the brevity of this post, and I am sorry for any possible falsification’s that may be present. You should be able to get an overall idea for what is going on, and I am sure someone will correct any of my mistakes.
[/quote]
LoL Tuberload, it's the "cover my ass" qualifier :P
[/quote]

Exactly! I didn’t have access to any documentation, and I don’t have it all 100% committed to memory yet. I don't like being caught with my pants down, so I state right away the possibility of errors. If I was completely correct, great, otherwise I don't look too stupid. ;)
April 16, 2004, 6:53 PM
RedPhoenix
So I send this first two, and I should recieve a response correct??

SEND -> Protocol byte (01)
SEND -> SID_AUTH_INFO (0x50)

RECV <- SID_PING (0x25)
RECV <- SID_AUTH_INFO (0x50)


Here's where I'm at:

Public Const GAME_PACKET = "1"

'SID Authorization Info
Public Const PROTOCOL_ID = "0"
Public Const PLATFORM_ID = "68XI"
Public Const PROGRAM_ID = "PXES"
Public Const VERSION_BYTE = "1064960"
Public Const PRODUCT_LANGUAGE = "ENU"
Public Const LOCAL_IP = "0" 'for NAT compatibility
Public Const TIME_ZONE_BIAS = "03/28/03 04:21:56"
Public Const LOCALE_ID = "0"
Public Const LANGUAGE_ID = "0"
Public Const COUNTRY_ABBREVIATION = "USA" & Chr(0)
Public Const COUNTRY = "United States" & Chr(0)

'Send this first, should get a response if correct.
msgStart = Chr(1) & Chr(4) & "68XI" & "SEXP" & "1064960" _
& "ENU" & Chr(0) & "03/28/03 04:21:56" & Chr(0) & Chr(0) & _
"USA" & Chr(0) & "United States" & Chr(0)

***Note: I have the data as strings, I'm aware of the binary concept. What I'm thinking is since I can connect and chat on Public servers. That sending data the way I am now, technically should work.

'Convert string to Ascii encoding
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(msgSend)
Dim stream As NetworkStream = client.GetStream()

stream.Write(data, 0, data.Length)

Now with the string I'm sending (msgStart), I'm not sure if there should be (vbCrLf) between each string ("68XI" & vbCrLf & "SEXP"), or if my structure of it is way off.
April 16, 2004, 10:02 PM
Myndfyr
You're wrong about time-zone bias; that is the number of hours you are off of GMT multiplied by -60. I am GMT -7, and so I send the decimal value of 420. It is a double-word (System.Int32 or System.UInt32), not a string.

Never, ever, ever, EVER do you need to send vbCrLf when using this packet; in fact, I think you will be IP-banned if you do. (Also, it is now better programming practice to use Environment.NewLine rather than vbCrLf, for cross-platform interoperability, when using .NET).

I also believe that is the incorrect version byte. I'm pretty sure it's just 0x0a for Starcraft, or &H0a. Version byte is also a double-word, not a string.

Product language may or may not be "enu" -- you can just use a 0 there as a double-word.
Local IP should be 0, not a string (as that is hex 0x30), but the literal 0 double-word.
Locale ID should be a double-word 0, not a string.
Language ID should be a double-word 0, not a string.
Protocol ID should be a double-word 0, not a string.

That's about it....
April 16, 2004, 10:35 PM
iago
He also has some extra chr(0)'s in there. He has 2 after country code and 2 after country.
April 16, 2004, 11:38 PM
RedPhoenix
This does the conversion for me

Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(msgSend)
Dim stream As NetworkStream = client.GetStream()
stream.Write(data, 0, data.Length)


So I would need the string equivalent of &H0a, which I used
MsgBox(CStr(&H0a)) to get the string.

Private msgStart As String = "255" & "1" & "80" & "0" & "IX86" & "SEXP" & "10" & "0" & "0" & "300" & "0" & "0" & "USA" & "United States"

The above doesn't work, I get no response yet. I've already been IP banned a short length of time.

"255" = &HFF
"80" = &H50

I'm about ready to say heck with it lol.
April 16, 2004, 11:59 PM
Myndfyr
[quote author=iago link=board=17;threadid=6315;start=15#msg55466 date=1082158722]
He also has some extra chr(0)'s in there. He has 2 after country code and 2 after country.
[/quote]

Nah, .NET strings don't have a null-terminator byte implicit.
April 17, 2004, 12:26 AM
RedPhoenix
So I need to add Environment.NewLine after each string?
April 17, 2004, 12:37 AM
o.OV
im not quite sure how .net works..
but it looks like VB so I'm just gonna make an assumption that strings work the same way.

[ code ]
[code]
Private msgStart As String = "255" & "1" & "80" & "0" & "IX86" & "SEXP" & "10" & "0" & "0" & "300" & "0" & "0" & "USA" & "United States"
[/code]
[ / code ]

wow.. does that work with VB6? heh
perhaps you need to use chr$()

[code]
Chr$(255)
[/code]
April 17, 2004, 12:52 AM
RedPhoenix
Technically it could, but you would have to figure out how this function actually processes the string conversion.

Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(msgSend)
Dim stream As NetworkStream = client.GetStream()
stream.Write(data, 0, data.Length)

And yes, I've tried using the Chr(255), but I don't need 255 in Chr() form, just string since "255" is 0xFF ~ ( CStr(&HFF) ) Also ( Hex(&HFF).ToString ) will both return "255"
April 17, 2004, 1:07 AM
o.OV
[quote author=RedPhoenix link=board=17;threadid=6315;start=30#msg55478 date=1082164023]
Technically it could, but you would have to figure out how this function actually processes the string conversion.

Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(msgSend)
Dim stream As NetworkStream = client.GetStream()
stream.Write(data, 0, data.Length)

And yes, I've tried using the Chr(255), but I don't need 255 in Chr() form, just string since "255" is 0xFF ~ ( CStr(&HFF) ) Also ( Hex(&HFF).ToString ) will both return "255"
[/quote]

Well.. ok.. if you are going to express them in plain bytes
why are you using a string? the dwords should be expressed in bytes as well and not as ascii characters
correct? depending on how your class file handles this.
You may want it as a string or a byte form. can't be both like you have right now. can it?
I don't know how .net and your tcp thing works. so I can't give a straight answer.

Add-On:
If you plan on storing the buffer in a string then..
In VB if you have it as "255" then that is three bytes..
50, 53, and 53
so that is why u need Chr$(255) so it is expressed as a single byte and not three.
April 17, 2004, 1:19 AM
RedPhoenix
That brought up something I thought I check out. Which kinda stumps me right now, I'll have to look into it. But this:

Private msgStart As [String] = Chr(3) & Chr(4) & AccName & vbCrLf & AccPw

Of course works, but how else would you express Chr(3) for the same effect?

'Just an example, I tried various conversions.
Private msgStart As [String] = &H3 & &H4 & AccName & vbCrLf & AccPw

I tried different conversions on Chr(3), just kept returning 3, and no matter how I expressed it. The server did not reckognize it and I couldn't get into the Public Chat channels.

Hex(Chr(3)).ToString
Hex(Asc(Chr(3)).ToString)
Hex(CInt(Chr(3)))

*shrugs*

Which in turn, when send the packet:

Private msgStart As String = Chr(255) & Chr(1) & "80" & "0" & "IX86" & "SEXP" & "10" & "0" & "0" & "300" & "0" & "0" & "USA" & "United States"

Should any of the values be expressed as Chr() as well........
April 17, 2004, 2:29 AM
Tuberload
Check out this thread: https://davnit.net/bnet/vL/phpbbs/index.php?board=34;action=display;threadid=4547

It is a byte buffer created in Java, but you should be able to convert. If nothing else it should serve as a good reference in creating the packets.
April 17, 2004, 6:22 AM
iago
hmm, I've made some small changes to that since then. Ah well, it's close enough.
April 17, 2004, 7:55 AM
RedPhoenix
Update: Here's where I'm at with this. As is, it connects to BNet, and doesn't return a response. Then, if you quit and try it again, you will notice an IO Exception. In other words you just got IP banned for a set length of time. In 3 to 5 minutes you can try again.

In the string I'm sending I almost positive the Chr(1) should start the message. Since Chr(3) started the other for public chat.

0x01 -> Game
0x02 -> Ftp
0x03 -> Chat

I've tried with and without the vbCrLf, and yes Myndfyre, I know about the vbCrLf hehe. Just trying to get somewhere first before I worry about interoperability and structure.

[code]
Imports System.Net.Sockets
Imports System.Text
Imports System.Threading

' Form designer generated code

Private client As New TcpClient()
Private strServer As String = "useast.battle.net"
'Private msgStart As [String] = Chr(3) & Chr(4) & AccountName & vbCrLf & AccountPassword

Private msgStart As String = Chr(1) & 80 & 0 & vbCrLf & "68XI" & vbCrLf & "PXES" & vbCrLf & 10 & _
vbCrLf & 0 & vbCrLf & 0 & vbCrLf & 300 & vbCrLf & 0 & vbCrLf & 0 & vbCrLf & "USA" & vbCrLf & "United States"

Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
Dim strRec As String

client.Connect(strServer, 6112)

SendData(msgStart)

strRec = RecieveData()
txtRecieve.Text &= "Data: " & strRec

Dim t As New Thread(New ThreadStart(AddressOf GetData))
t.Start()
End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim msgSend As String = txtSend.Text & vbCrLf
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(msgSend)
Dim stream As NetworkStream = client.GetStream()

stream.Write(data, 0, data.Length)

txtRecieve.Text &= "RedPhoenix[Hs]: " & msgSend
txtSend.Text = ""
End Sub

Private Sub GetData()
Try
'This retrieves the messages from users every 500 milisecs..

Dim data As [Byte]()
Dim stream As NetworkStream = client.GetStream()

data = New [Byte](256) {}

Dim responseData As [String] = [String].Empty
Dim bytes As Int32 = stream.Read(data, 0, data.Length)

responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
txtRecieve.Text &= responseData
txtRecieve.SelectionStart = txtRecieve.TextLength

Thread.CurrentThread.Sleep(500)
If txtRecieve.Lines.Length > 20 Then
txtRecieve.Text = ""
End If
GetData()
Catch exc As Exception
MsgBox(exc.ToString)
End
End Try
End Sub

Private Function SendData(ByRef msg As String)
'Notice: this sends the message with a vbCrLf attached at the end.
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(msg & vbCrLf)
Dim stream As NetworkStream = client.GetStream()
stream.Write(data, 0, data.Length)
End Function

Private Function RecieveData() As String
Dim data As [Byte]()
Dim stream As NetworkStream = client.GetStream()

data = New [Byte](256) {}

Dim responseData As [String] = [String].Empty
Dim bytes As Int32 = stream.Read(data, 0, data.Length)

responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)

Return responseData
End Function
[/code]
April 17, 2004, 9:47 AM
o.OV
Don't use vbcrlf..
binary connections are totally different from telnet connections.

arta's bnetdocs was down earlier was it?
It is up now so you can check out the protocol header information and packet structures.

I'll paste it here but you will need to see it for yourself for a better understanding.

(BYTE) StartPacket - always 0xFF
(BYTE) Packet ID
(WORD) Packet length, including this header

(DWORD)       Protocol ID (0)
(DWORD)       Platform ID
(DWORD)       Program ID
(DWORD)       Version Byte
(DWORD)       Product language
(DWORD)       Local IP for NAT compatibility*
(DWORD)       Time zone bias*
(DWORD)       Locale ID*
(DWORD)       Language ID*
(STRING)       Country abreviation
(STRING)       Country
April 17, 2004, 12:46 PM
Adron
Make sure you don't get implicit charset conversions from unicode to utf-8 for things like chr(255). You need to use chr() virtually everywhere, or just quit sending strings and start sending binary data.
April 17, 2004, 6:15 PM
Myndfyr
Recall, though, that Chars in .NET are Unicode -- 2 bytes. You'll need to use System.Text.Encoding.Ascii.GetBytes(string) to get a 1-byte number. Also, use the Byte type.

Rather than using the Java class, this can be compiled directly and referenced as a DLL.

https://davnit.net/bnet/vL/phpbbs/index.php?board=17;action=display;threadid=4150;start=msg34300#msg34300

After having talked extensively on the GotDotNet user area about performance of small functions like these, I've found out that the .NET JITter will inline many of these things, which was something Kp remarked at the very bottom of that thread.

What you'll do is call InsertDWORD(ByVal i As Integer) -- note that I'm using VB syntax for you -- for numbers that are marked DWORD. If you're inserting one of those four-character strings like "IX86" that look reversed in your packetlog -- "68XI" -- use the .InsertNonNTString (that is what many people call a Non-Null-Terminated string -- although technically it's just a number that looks like a string), and for any other strings -- the ones that are variable-length or are marked "STRING" in BnetDocs -- use .InsertNTString(string).

Hope that helps. I think it will clarify a lot for you.

Paclet 0x50 -- SID_AUTH_INFO -- is then made:

C#:
[code]

Packet pck = new BncsPacket(0x50);
pck.InsertDWORD(0);
pck.InsertNonNTString("IX86");
pck.InsertNonNTString("SEXP");
pck.InsertDWORD(0x0a); // replace your version byte here
pck.InsertDWORD(0); // prod. language; may be 0
pck.InsertDWORD(0); // local ip, for NAT compatibility
pck.InsertDWORD(timeZoneOffset * -60); // timeZoneOffset being an integer representing your hours off of GMT
pck.InsertDWORD(0); // locale ID, may be 0
pck.InsertDWORD(0); // language ID, may be 0
pck.InsertNTString("USA");
pck.InsertNTString("United States");
[/code]

VB .NET:
[code]

Dim pck As New BncsPacket(&H50)
pck.InsertDWORD(0)
pck.InsertNonNTString("IX86")
pck.InsertNonNTString("SEXP")
pck.InsertDWORD(&H0a) ' replace your version byte here
pck.InsertDWORD(0) ' prod. language; may be 0
pck.InsertDWORD(0) ' local ip, for NAT compatibility
pck.InsertDWORD(timeZoneOffset * -60) ' timeZoneOffset being an integer representing your hours off of GMT
pck.InsertDWORD(0) ' locale ID, may be 0
pck.InsertDWORD(0) ' language ID, may be 0
pck.InsertNTString("USA")
pck.InsertNTString("United States")
[/code]

Then, to send it, I just use:

sck.BeginSend(pck.Data, / * .. stuff */);

Hope that helps!
April 17, 2004, 6:33 PM
RedPhoenix
Check this out:

[code]
Private msgStart As [String] = Chr(3) & Chr(4) & "RedPhoenix[Hs]" & vbCrLf & Password
[/code]

Is the same if we write it this way:

[code]
Private msgStart As [String] = Chr(&H3) & Chr(&H4) & Chr(&H52) & Chr(&H65) & Chr(&H64) & Chr(&H50) & Chr(&H68) & Chr(&H6F) _
& Chr(&H65) & Chr(&H6E) & Chr(&H69) & Chr(&H78) & Chr(&H5B) & Chr(&H48) & Chr(&H73) & Chr(&H5D) & Chr(&HD) & Chr(&HA) & Chr(&H66) _
& Chr(&H69) & Chr() & Chr() & Chr() & Chr() & Chr() & Chr() & Chr()
[/code]

The last 7 chars have been erased since it was my password. :P
April 17, 2004, 11:14 PM
Adron
Yes, you can write some things with either Chr() or the letters. There's a big difference between "50", Chr(50), and Chr(80) though.
April 17, 2004, 11:31 PM
RedPhoenix
Anyone know what the replacement for a null char would be?

0x00 - &H0

When I use that char in a string, for example:

[code]
Dim myString As String = "Str" & Chr(&H0) & "ing"
MsgBox myString
[/code]

It only shows Str in the message box, any reason and a suitable replacement for this?
April 18, 2004, 3:18 AM
Myndfyr
[code]
Dim myString As String = "Str" & Chr(&H0) & "ing"
MsgBox myString.Replace(Chr(&H0), String.Empty)
[/code]

The reason is that Windows uses the null (0x0) character to determine where a marshalled string ends. Once it hits the 0x0 in your string, it stops.
April 18, 2004, 7:27 AM
o.OV
In VB6 I use vbNullChar in place of Chr$(0)
April 18, 2004, 8:41 AM
Adron
[quote author=RedPhoenix link=board=17;threadid=6315;start=45#msg55617 date=1082258302]
It only shows Str in the message box, any reason and a suitable replacement for this?
[/quote]

Why would you want to display a Chr(0)? It's not a letter or something you could write on paper. If it's for debugging purposes, make yourself a hexdump function. You'll need that for all the other non-printable or badly printable things that have to be sent on a binary b.net connection anyway.
April 18, 2004, 10:10 AM
RedPhoenix
I figured since this form:

[code]
Private msgStart As [String] = Chr(&H3) & Chr(&H4) & Chr(&H52) & Chr(&H65) & Chr(&H64) & Chr(&H50) & Chr(&H68) & Chr(&H6F) _
& Chr(&H65) & Chr(&H6E) & Chr(&H69) & Chr(&H78) & Chr(&H5B) & Chr(&H48) & Chr(&H73) & Chr(&H5D) & Chr(&HD) & Chr(&HA) & Chr(&H66) _
& Chr(&H69) & Chr() & Chr() & Chr() & Chr() & Chr() & Chr() & Chr()
[/code]

gets me into Public Chat, which I got the hex values from Ethereal. That I could do the same method to get into the other channels. Which I'm in the progess of testing right now. Just when looking at the packet in Ethereal, there was alot of 0x00 ( . ). Which interupted my string. But, I got it worked out now. Just testing, debugging and getting IP banned now.

**Tested what I thought would work. I grabbed all the hex values from the data my pc sent to the server. Stored them into a file, then read from that file storing each value in an array of char. I have like 13 different arrays for each packet that was sent. Then per array, I send each value. Once all the values within an array have been sent. Then I pause sending the next packet by 200 miliseconds. But, right now, even though I have all the same hex values stored correctly. I'm getting IP banned after I send the third packet. Maybe my delay isn't long enough. I'll try different delay intervals between packets. *shrugs*

By the way, after sending the second packet though, Ethereal picked up that the server replied back with a data packet ...tenb and other garbage.
April 18, 2004, 4:04 PM
Adron
The problem is that your PC doesn't send the same string every time it connects. Your packets must contain different data depending on what the server has previously sent you.

You can send all the packets up until the first time b.net sends you data from the file, but then you need to start parsing what b.net sends you and respond appropriately.

April 18, 2004, 4:32 PM
Myndfyr
Phoenix, you CAN NOT get into non-public channels with a CHAT connection that begins with Chr(3).

You MUST log in via a binary product connection that begins with Chr(1).
April 18, 2004, 5:58 PM
RedPhoenix
I know that already:

&H1 = game
&H2 = Ftp
&H3 = Chat

I start my logon sequence by sending &H1 right off the bat.

I just posted the code above as an example. That if I send the logon sequence in the form of: Chr(hex), that the server acknowledges it. So in turn, if I log the regular logon sequence. Then resend it through my program, it should work. But, the part of each requests to connect changes, is throwing me off. I get to packet 3 and I get IP banned. But, after I send the second packet, I get a response of ( .....tenb... ). Noticed that by using ethereal.

Also I noticed tat the logon sequence uses UDP for 3 of the packets. Should I switch over to UDP for them 3 packets? I think that is where I'm getting banned.
April 18, 2004, 7:03 PM

Search