Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: Luxer on July 19, 2004, 06:37 PM

Title: [RB] Useing BNLS
Post by: Luxer on July 19, 2004, 06:37 PM
Could somone point me in the right direction? Completly clueless about packets....
Title: Re:[RB] Useing BNLS
Post by: Eric on July 19, 2004, 07:15 PM
Quote from: Luxer on July 19, 2004, 06:37 PM
Could somone point me in the right direction? Completly clueless about packets....
Search for a copy of the CleanSlateBot ocx.
Title: Re:[RB] Useing BNLS
Post by: ChR0NiC on July 19, 2004, 07:16 PM
Quote
BNLS Headers
BNLS is the Battle.Net Logon Server, and can be used by bot authors to perform the hashing required during a Battle.net logon. It also allows bot authors to obtain useful information such as the current version byte for a game client, and has provisions for BNCS server emulator authors. It has the following headers:
(WORD)    Packet Length, including this header
(BYTE)      Packet ID
(VOID)      Packet Data

Edit:
Quote
String - Null terminated character array
DWORD - 32 bit unsigned integer
Word - 16 bit unsigned integer
Byte - 8 bit unsigned integer

Edit:
BNLS Protcol Spec (http://www.valhallalegends.com/yoni/BNLSProtocolSpec.txt) <~ This wouldn't hurt either.

Edit:
BNET Docs (http://bnetdocs.valhallalegends.com) <~ Has very nice documentation about most of the BNLS packets about three quarters down the page.
Title: Re:[RB] Useing BNLS
Post by: Warrior on July 20, 2004, 12:26 AM
Im pretty sure Feanor wrote a Tut on Packetlogging try snooping around Clan Exiles Site
Title: Re:[RB] Useing BNLS
Post by: tA-Kane on July 20, 2004, 01:54 AM
Quote from: LoRd[nK] on July 19, 2004, 07:15 PMSearch for a copy of the CleanSlateBot ocx.
Not helpful when you're using a Mac (eg, RB).  :P

Luxor, I just sent a similar email to someone along the same lines (perhaps even he is you?); read this:

Quote1) You need to maintain a "lag buffer", whereas even if packets are lagged (that is, received between multiple DataAvailable events), you still receive them in their full entirety.

This can be accomplished with something like this:

In your BNLSSocket object, create a property:
LagBuffer As String

Then, in your DataAvailable event:
Me.LagBuffer = Me.LagBuffer + Me.ReadAll

Check to see if the length of the LagBuffer property is greater than or equal to the length of the first packet in the buffer. If so, then process the packet. If not, then return from DataAvailable and wait for more data (wait for another DataAvailable event).

After processing the packet, be sure to remove the packet's header and data from the lag buffer, so that you don't process it again.

All of the processing could (should) be done in a loop, in case you receive multiple packets in a single DataAvailable event.


2) You'll also need to be able to convert integers to binary strings and vice versa (that is, add a 32-bit number to a string as 4 bytes as well as read 4 bytes into a 32-bit number). Memory Blocks are useful for such.

Function IntToStr32(Value As Integer) As String
 Dim Mem As MemoryBlock
 
 Mem = NewMemoryBlock(4)
 Mem.Long(0) = Value
 Return Mem.StringValue(0,4)
End Function

Function StrToInt32(Value As String) As Integer
 Dim Mem As MemoryBlock
 
 Mem = NewMemoryBlock(4)
 Mem.StringValue(0,4) = MidB(Value,1,4)
 Return Mem.Long(0)
End Function

Function IntToStr16(Value As Integer) As String
 Dim Mem As MemoryBlock
 
 Mem = NewMemoryBlock(2)
 Mem.Short(0) = Value
 Return Mem.StringValue(0,2)
End Function

Function StrToInt16(Value As String) As Integer
 Dim Mem As MemoryBlock
 
 Mem = NewMemoryBlock(2)
 Mem.StringValue(0,2) = MidB(Value,1,2)
 Return Mem.Shortg(0)
End Function

Function SwapEndian(Value As Integer) As Integer
 Dim A, B As MemoryBlock
 
 A = NewMemoryBlock(4)
 B = NewMemoryBlock(4)
 A.Long(0) = Value
 B.Byte(0) = A.Byte(3)
 B.Byte(1) = A.Byte(2)
 B.Byte(2) = A.Byte(1)
 B.Byte(3) = A.Byte(0)
 Return B.Long(0)
End Function


Note that those simple functions are not enough; you will need to be able to convert integers between little endian and big endian format, as well as know when endian conversion is necessary.


3) Getting packet datas and IDs is simple enough..., here's some code taken (almost) straight from my BNLSSocket object, with a ton of comments added:

Sub BNLSSocket.DataAvailable()
 Dim PacketID, PacketLength, BufferLength As Integer
 Dim Data As String
 
 Me.LagBuffer = Me.LagBuffer + Me.ReadAll
 Me.BufferLength = LenB(Me.LagBuffer)
 
 Do
   If BufferLength < 3 Then
     'Buffer length is less than even a simple header
     'either no packet available, or it's an incomplete packet
     Return
   End If
   ID = AscB(MidB(Me.LagBuffer,3,1))
   PacketLength = StrToInt16(MidB(Me.LagBuffer,1,2))
   #if TargetMacOS
   'Endian conversion is going to be needed for DataLength!
   PacketLength = SwapEndian(PacketLength)
   #endif
   If PacketLength < 3 Then
     Beep
     MsgBox "Sanity failure! Total packet length is less than the length of the header!"
   Else
     If BufferLength >= DataLength Then
       'Lag buffer is long enough to contain the packet
       Data = MidB(Me.LagBuffer, 4, PacketLength-4)
       'why DataLength-4, you ask? Well, Data variable should contain only
       'the packet data, not packet header; so need to remove length of
       'header from total packet length
       
       'Now, remove the packet from the lag buffer
       Me.LagBuffer = MidB(Me.LagBuffer, PacketLength + 1)
       'Now, process the packet
       Me.PacketReceived(ID, Data)
     Else'If BufferLength < DataLength Then
       'Lag buffer is not long enough to contain the packet;
       'Must wait for next DataAvailable event.
       Return
     End If
   End If
   'Make sure BufferLength is still accurate, for next iteration of the loop!
   BufferLength = LenB(Me.LagBuffer)
 Loop
 
Exception Error
 Beep
 MsgBox "Error!"
End Sub


Here's my definition of PacketReceived:

Sub BNLSSocket.PacketReceived(ID As Integer, Data As String)
 'hopefully you can fill this in, eh?
End Sub




All of that should be plenty enough to get you started on BNLS.



--
Thanks,
Keith Bennett, tA-Kane
Author of KaneBot
Battle.net binary bot for Macintosh.
http://linkware.clan-mac.com/kanebot



> From: MacSc <email removed for this post>
> Date: Mon, 19 Jul 2004 17:34:53 -0600
> To: Keith Bennett <[email protected]>
> Subject: Connecting with BNLS using RB
>
> Hey Keith,
> I was wondering if you could give me some tips about BNLS connection. I
> am completely clueless about these packets. Could you help?
>
> */\*\/*/\*\/*/\*\/*/\*\/*/\*\/*/\*\/*/\*\/*/\*\/*/\*\/*/\*\/*
> Thanks,
>
> MacSc
> email removed for this post

So uhh... yeah. Have fun with that.
Title: Re:[RB] Useing BNLS
Post by: Luxer on July 22, 2004, 12:17 PM
Yep. That was me. Its Broken SHA-1, right? (If I ever want to to do local hashing)
Title: Re:[RB] Useing BNLS
Post by: tA-Kane on July 22, 2004, 12:27 PM
Quote from: Luxer on July 22, 2004, 12:17 PMYep. That was me.
Neato.
Quote from: Luxer on July 22, 2004, 12:17 PMIts Broken SHA-1, right? (If I ever want to to do ocal hashing)
Yes, but I haven't written it for REALbasic, nor do I know anyone that has. Feel free to try if you want, there's plenty of source code available, and there's one that I wrote for C and use here:
http://www.cubedivision.org/phpBB2/viewtopic.php?t=72
BNCSHashData() would be what you're looking for.
Title: Re:[RB] Useing BNLS
Post by: Luxer on July 22, 2004, 12:30 PM
Thanks
Title: Re:[RB] Useing BNLS
Post by: eBeL on August 07, 2004, 04:28 PM
Quote from: tA-Kane on July 20, 2004, 01:54 AM
Quote from: LoRd[nK] on July 19, 2004, 07:15 PMSearch for a copy of the CleanSlateBot ocx.
Not helpful when you're using a Mac (eg, RB).  :P

Luxor, I just sent a similar email to someone along the same lines (perhaps even he is you?); read this:

{CLIPPED EMAIL}

Keith, That makes absolutly no sense.
Title: Re:[RB] Useing BNLS
Post by: tA-Kane on August 09, 2004, 12:48 PM
It makes perfect sense to me. What part don't you understand?  :-\
Title: Re:[RB] Useing BNLS
Post by: shadypalm88 on August 09, 2004, 10:03 PM
Quote from: eBeL on August 07, 2004, 04:28 PMKeith, That makes absolutly no sense.

Quote from: LoRd[nK] on July 19, 2004, 07:15 PMSearch for a copy of the CleanSlateBot ocx.
CleanSlateBot.ocx is a Visual Basic control (Windows).

Quote from: tA-Kane on July 20, 2004, 01:54 AMNot helpful when you're using a Mac
Therefore, it will not work so well on Macintosh computers.

Quote from: tA-Kane on July 20, 2004, 01:54 AM(eg, RB).  :P
RB = RealBasic = a language/IDE similar to Visual Basic that can be used to write programs for Windows, Mac, and Linux computers.

(Made sense to me. :P)
Title: Re:[RB] Useing BNLS
Post by: eBeL on August 10, 2004, 06:50 PM
The entire email! Does anyone have a sample -> REALBASIC <- bot I can experiment with? I learn better and faster when I can actually see what is doing what  :-\
Title: Re:[RB] Useing BNLS
Post by: MyndFyre on August 10, 2004, 07:31 PM
Quote from: eBeL on August 10, 2004, 06:50 PM
The entire email! Does anyone have a sample -> REALBASIC <- bot I can experiment with? I learn better and faster when I can actually see what is doing what  :-\

Chr0nic made a good point in the other post....  Here are my two cents about using source code.

Don't lie.  If you're using source code, use it and modify it as needed.  Give credit to the person who wrote the code, and also ask permission to use it first.

The point of programming is seeing a problem and and answering or fixing it.  Your problem: you want a binary Battle.net bot.  How do you solve it?  By programming.

If you don't want to learn how to solve the problem, I'm sure Kane's bot is nice :)
Title: Re:[RB] Useing BNLS
Post by: eBeL on August 10, 2004, 08:07 PM
I would prefer to use someone elses an build off of that until I understand how to do it on my own.

And I also understand what it feels like to have a project idea or application stolen from you.
Title: Re:[RB] Useing BNLS
Post by: tA-Kane on August 11, 2004, 12:04 PM
Janky has abandoned his JXBot. His source code is (and has been for the last two years) freely available. I have a quick download link on my bot's website.

Even though I'm told that the source code for JXBot doesn't even compile anymore with recent compilers, it wouldn't be hard to make it do so. All it would take is a minimal of effort to remove and/or fix (change?) linked images, language updates, and etc.

Sure, JXBot isn't binary. I'd have to give you a point if you said that. But that doesn't mean that the code base isn't there. It supports a colored chat field (though you'd have to add your own 'Battle.net-style' color parser). Something it has that my KaneBot doesn't is that it has proxy support (though I don't know to what extent). And hey, here's another one-up on my bot: you can write your own commands in JXBot. I'm sure just about everyone would agree JXBot has a better interface than mine  ;)

Sure, the code might not be able to compile. But if you could get it to compile, there's many people out there who liked JXBot more than my bot. Get JXBot to compile, and release it as-is for Carbon (for Mac OS X), and you'd get an instant user base. Then it's just a matter of learning JXBot's code and redoing the connection code to support a binary connection. I could do all of this in two weeks. If I didn't have a job, I could do it in two days. But you see, I'm not interesting in bringing JXBot back. I don't like JXBot, nor do I need it. Why would I work on something which I don't want or need, and won't benefit me in some way?
Title: Re:[RB] Useing BNLS
Post by: eBeL on August 11, 2004, 03:27 PM
Last I checked JXBot doesnt join private channels :|
Title: Re:[RB] Useing BNLS
Post by: eBeL on August 11, 2004, 03:54 PM
Quote from: eBeL on August 11, 2004, 03:27 PM
Last I checked JXBot doesnt join private channels :|

I compiled it fine after doing TONS of changes... but it doesnt connect!
Title: Re:[RB] Useing BNLS
Post by: MyndFyre on August 11, 2004, 04:01 PM
Quote from: eBeL on August 11, 2004, 03:54 PM
I compiled it fine after doing TONS of changes... but it doesnt connect!
Quote from: tA-Kane on August 11, 2004, 12:04 PM
Then it's just a matter of learning JXBot's code and redoing the connection code to support a binary connection.

Also, please do not post twice in a row.  If you are the last person to have posted, please click the "Modify" link of your post, unless the content matter has changed significantly enough to warrant everyone reading it again.
Title: Re:[RB] Useing BNLS
Post by: eBeL on August 11, 2004, 07:52 PM
Oh sry I normally look for "Edit"

The thing is, I DO NOT KNOW BINARY :(
Title: Re:[RB] Useing BNLS
Post by: MyndFyre on August 11, 2004, 07:55 PM
Quote from: eBeL on August 11, 2004, 07:52 PM
Oh sry I normally look for "Edit"

The thing is, I DO NOT KNOW BINARY :(

Quit whining and learn it then.

I didn't know how to make a binary connection to Battle.net before about a year ago.  If you demonstrate that you have motivation to work here, people will help you.

And now look at me!

011000110101101000110101001101011010111001011001110101001101110
001110011010101100011010000101000101010001111001010101000111100
0101010010111001010001101101010000111110101001011101010010101110101010101

[edit] I put in line breaks. [/edit]

And that's just a small portion of what I know!
Title: Re:[RB] Useing BNLS
Post by: Eli_1 on August 11, 2004, 08:49 PM
01100011 01011010 00110101 00110101 10101110 01011001 11010100 11011100 01110011 01010110 00110100 00101000 10101000 11110010 10101000 11110001 01010010 11100101 00011011 01010000 11111010 10010111 01010010 10111010
1010101

---->

cZ55®YÔÜsV4(¨ò¨ñRåPú&#8212;Rºª



You haven't learned anything!
Title: Re:[RB] Useing BNLS
Post by: MyndFyre on August 11, 2004, 08:59 PM
LMAO!  omg Eli!  I was totally just typing random 1's and 0's, and after you posted what you posted -- was that what you had on the other thread -- we got the first 24 identically?!?

Psh that's not what you posted:
Quote from: Eli_1 on August 11, 2004, 06:09 PM
00111110 01100101 01101011 01101111 01101010 00101111 00111100 00100000 01010000 00111010 00100000 00100001 01111001 01110010 01100001 01101110 01101001 01100010 00100000 01110111 01101111 01101110 01101011 00100000 01001001

Title: Re:[RB] Useing BNLS
Post by: Eli_1 on August 11, 2004, 09:07 PM
No, mine actually means somthing. I just spaced yours like mine so it lined up, oh so nicely.  :)
Title: Re:[RB] Useing BNLS
Post by: MyndFyre on August 11, 2004, 09:08 PM
Quote from: Eli_1 on August 11, 2004, 09:07 PM
No, mine actually means somthing. I just spaced yours like mine so it lined up, oh so nicely.  :)

Oh I see what you're saying now.

Mine is.... uh.... in... North...  Korean.....  They are just using the wrong encoding.  Yeah, that's it.
Title: Re:[RB] Useing BNLS
Post by: eBeL on August 12, 2004, 10:11 AM
Quote from: MyndFyre on August 11, 2004, 07:55 PM
Quote from: eBeL on August 11, 2004, 07:52 PM
Oh sry I normally look for "Edit"

The thing is, I DO NOT KNOW BINARY :(

Quit whining and learn it then.

I didn't know how to make a binary connection to Battle.net before about a year ago.  If you demonstrate that you have motivation to work here, people will help you.

And now look at me!

011000110101101000110101001101011010111001011001110101001101110
001110011010101100011010000101000101010001111001010101000111100
0101010010111001010001101101010000111110101001011101010010101110101010101

[edit] I put in line breaks. [/edit]

And that's just a small portion of what I know!

How or where can I do that?
Title: Re:[RB] Useing BNLS
Post by: l)ragon on August 12, 2004, 10:43 AM
Quote from: eBeL on August 12, 2004, 10:11 AM
Quote from: MyndFyre on August 11, 2004, 07:55 PM
Quote from: eBeL on August 11, 2004, 07:52 PM
Oh sry I normally look for "Edit"

The thing is, I DO NOT KNOW BINARY :(

Quit whining and learn it then.

I didn't know how to make a binary connection to Battle.net before about a year ago.  If you demonstrate that you have motivation to work here, people will help you.

And now look at me!

011000110101101000110101001101011010111001011001110101001101110
001110011010101100011010000101000101010001111001010101000111100
0101010010111001010001101101010000111110101001011101010010101110101010101

[edit] I put in line breaks. [/edit]

And that's just a small portion of what I know!



How or where can I do that?

Grade 9 'general or advanced' intro to computers class.
Title: Re:[RB] Useing BNLS
Post by: tA-Kane on August 12, 2004, 11:11 AM
Quote from: dRAgoN on August 12, 2004, 10:43 AM
Quote from: eBeL on August 12, 2004, 10:11 AMHow or where can I do that?
Grade 9 'general or advanced' intro to computers class.
I never went to 8th grade. I also have not been to 9th grade either.

eBeL, if you've seriously been able to get JXBot to compile after a number of fixes, then I congradulate you. You've now been further than about 20 other people I've talked to over emails.

Take some time and learn JXBot's code. REALbasic has a built-in debugger. Use that. Figure out why JXBot isn't connecting. Is it actually connecting, but parsing wrong? Are you telling it to connect, but it has the wrong address information input into the socket? All of these could be possible, it's your problem to find a solution.

If it were me, I'd set a breakpoint on the menu handler for connect (if I remember correctly, JXBot would connect via a menu). Then, I'd always do command-[ (step-into) to follow along the code as it goes, and find where it's going awry.

Also, even though JXBot is a CHAT bot (thusly, it cannot go into private channels, as you've stated), it's still a good code base. Chip away the old and bring about the new, and you will have a ready-made bot with ready users. Just don't be silly enough to change the name  ;)

I beleive you and Luxer were working on LuxerBot's auto-update feature together, were you not? If so, you could both look at this JXBot source code and try to devise a solution. Two heads are usually better than one.

If you can get JXBot to connect to the CHAT gateway, talk, display whispers and joins and leaves and all that, and have bot actions, I might help you with getting it working on a binary connection. Take the initiative to show you've got the intelligence.
Title: Re:[RB] Useing BNLS
Post by: eBeL on August 12, 2004, 11:38 AM
Alright, well I am off to get JXBot to connect :P
I think it may have to do with the IP for the Bnet servers.

EDIT:
I changes the server IPS and connect but this is what I get:
<••©2000 Kevin Wood••>
<••All rights reserved••>
Connected! Logging in...
Connectionfrom[**********]

Enteryouraccountnameandpassword.
Use'anonymous'ifyouonlywanttoissuequeries.


Username:
Title: Re:[RB] Useing BNLS
Post by: MyndFyre on August 12, 2004, 01:30 PM
Quote from: eBeL on August 12, 2004, 11:38 AM
Alright, well I am off to get JXBot to connect :P
I think it may have to do with the IP for the Bnet servers.

EDIT:
I changes the server IPS and connect but this is what I get:
<••©2000 Kevin Wood••>
<••All rights reserved••>
Connected! Logging in...
Connectionfrom[**********]

Enteryouraccountnameandpassword.
Use'anonymous'ifyouonlywanttoissuequeries.


Username:


As Kane has said no less than twice.... JXBot is a CHAT bot.  That means it uses the CHAT protocol, not binary protocol.  The CHAT protocol is essentially a telnet connection over port 6112.

Anyway, you'll enter your name and password there manually and be able to log in and chat in *public* channels.

What Kane also suggested you do after that is to look into converting into a binary connection.

There are ooodles and ooodles of information on binary connections in the vL forums.  Check out the forum above this one (Battle.net Bot Development Reference I believe it is called), and look for information on getting started.  Better yet, search!
Title: Re:[RB] Useing BNLS
Post by: eBeL on August 12, 2004, 02:21 PM
It connects but doesnt log in, then loses the connection, I am going to look at the TCPsocket, it was usng a regular socket before, and get it to log in like with my chat bot I made before. (It is just a simple client with no commands and a very bad interface)

EDIT: I got it to connect!
Here is a screenshot, how can I fix the editfield? (the main chat box that receives people actions)
http://www.theipn.com/JX-OSX.jpg