• Welcome to Valhalla Legends Archive.
 
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - werehamster

#1
Quote from: iago on March 02, 2005, 08:54 AM
PHP script running off a .asp file? That's crazy!

How else could you use PHP as a session so you could have global variables and stuff?

Could also use a shell with pipes, but can't use sessions there...
#2
I am workign on a Linux Bot Server which works off of PHP scripts and SQL calls. 

Uses events such as OnWhisper.asp?botid=x?user=x?message=x?flags=x

Will have remote access via telnet access to control the bot directly and see what is going on in the channel.

The PHP scripts will provide all the commands and access levels.

If anyone wants to help develope it, email me at [email protected] (without the -nospam)

So in a sense, we could provide a bot hosting service with a web control panel.
#3
Battle.net Bot Development / Version Check Failed
September 25, 2004, 05:08 AM
[BNET]ValueString = "A=167624937 B=186753965 C=221635188 4 A=A+S B=B-C C=C^A A=A^BA=167624937 B=186753965 C=221635188 4 A=A+S B=B-C C=C^A A=A^BA=613609190 B=433381174 C=662925260 4 A=A^S B=B^C C=C^A A=A^B"

Did BNET decide to crack down on the bots or something?  I've never seen this string this long.
#4
Problem Solved.  Feel free to close this topic.
#5

StealthBot Packet:
0000  22 00 01 D0 1C F1 48 45 4E 43 45 48 43 43 59 45    ".....HENCEHCCYE
0010  xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx    xxxxxxxxxxxxxxxx
0020  xx 00                                              x.

My Bot's Packet:
0000:  1E 00 01 65 6E 63 65 68 63 63 79 65 72 68 77 6B ...encehccyerhwk
0010:  65 xx xx xx xx xx xx xx xx xx xx xx xx 00       xxxxxxxxxxxxx.


Apparently I am doing something wrong.  What is supposed to be in the 4th and 5th byte of the packet?

To answer my own question, looks like a server token of some kind...
#6
I don't think so.  Unless I am formatting it incorrectly.  The CD-Key works in other bots and i did a fool-proof cut&paste method.

Anyway, just in case, I am going to packet log how stealthbot sends it to see how it looks.

I assume this is supposed to be a null-terminated string and is not case sensitive.
#7
Ok, I know BNLS was down for War3 for a while, but this is not related in any way.
I've been writing and re-writing my login code so many times, and I am having tons of problems getting the CD-Key to come back with a positive response.

Just to get rid of some of the usual responses I would expect, here are some details.

My CD-Key is not banned.
I am not IP banned.
I can log on with other bots.
I am not using any OCXs or other premade code, it is all origonal and written in borland delphi.
The key listed has been edited out so noone can steal my CD-Key.

If anyone can help, I would be extremely appreciative...


[BNET]Created
[BNET]Connecting to useast.battle.net:6112
[BNLS]Created
[BNLS]Connecting to bnls.valhallalegends.com:9367
[BNLS]Sent: BNLS_REQUESTVERSIONBYTE
0000:  07 00 10 07 00 00 00                            .......        
[BNLS]Recv: BNLS_REQUESTVERSIONBYTE
0000:  0B 00 10 07 00 00 00 11 00 00 00                ...........    
[BNET]Sent: SID_AUTH_INFO
0000:  FF 50 3A 00 00 00 00 00 36 38 58 49 33 52 41 57 .P:.....68XI3RAW
0010:  11 00 00 00 53 55 6E 65 18 BA 00 A6 F0 00 00 00 ....SUne........
0020:  09 04 00 00 09 04 00 00 55 53 41 00 55 6E 69 74 ........USA.Unit
0030:  65 64 20 53 74 61 74 65 73 00                   ed States.      
[BNET]Recv: SID_PING
0000:  FF 25 08 00 96 06 07 ED                         .%......        
[BNET]Sent: SID_PING
0000:  FF 25 08 00 96 06 07 ED                         .%......        
[BNET]Recv: SID_AUTH_INFO
0000:  FF 50 E3 00 02 00 00 00 56 A8 0B 85 C4 6F 35 00 .P......V....o5.
0010:  00 95 2E 62 91 E7 C3 01 49 58 38 36 76 65 72 30 ...b....IX86ver0
0020:  2E 6D 70 71 00 41 3D 34 31 33 32 35 30 39 39 36 .mpq.A=413250996
0030:  20 42 3D 34 32 31 37 30 33 34 39 34 20 43 3D 36  B=421703494 C=6
0040:  35 39 30 35 36 33 39 31 20 34 20 41 3D 41 5E 53 59056391 4 A=A^S
0050:  20 42 3D 42 2B 43 20 43 3D 43 5E 41 20 41 3D 41  B=B+C C=C^A A=A
0060:  5E 42 00 20 15 2A 60 74 98 6C 70 7D E7 00 B0 CD ^B. .*`t.lp}....
0070:  27 34 40 4F 21 55 96 5C 87 86 51 E3 41 A4 96 C5 '4@O!U.\..Q.A...
0080:  ED 35 D8 EC F4 C0 EC 68 98 75 02 B0 8F D8 88 7F .5.....h.u......
0090:  DF B5 70 69 98 76 53 BE 65 5E C8 4E B6 3B B2 D2 ..pi.vS.e^.N.;..
00A0:  FF 2D FF 6D 88 AC D8 36 FB B6 B3 5F CF BF 3E 17 .-.m...6..._..>.
00B0:  34 0A B2 63 4A 84 E8 37 A8 D6 65 5C D0 BE A2 B7 4..cJ..7..e\....
00C0:  CD 5A 98 F9 24 8D 1A D0 C5 11 CF 3F 20 51 3E 98 .Z..$......? Q>.
00D0:  20 26 9B C9 3B 76 E7 9C A2 4F 43 C6 FB 3E 3B E9  &..;v...OC..>;.
00E0:  5E 12 BB                                        ^..            
[BNET]Debug:DLL Revision: 0
[BNET]ValueString = "A=413250996 B=421703494 C=659056391 4 A=A^S B=B+C C=C^A A=A^B"
[BNLS]Sent: BNLS_CHOOSENLSREVISION
0000:  07 00 0D 02 00 00 00                            .......        
[BNLS]Recv: BNLS_CHOOSENLSREVISION
0000:  07 00 0D 01 00 00 00                            .......        
[BNLS]Debug:NLS Revision good.
[BNLS]Sent: BNLS_VERSIONCHECK
0000:  49 00 09 07 00 00 00 00 00 00 00 41 3D 34 31 33 I..........A=413
0010:  32 35 30 39 39 36 20 42 3D 34 32 31 37 30 33 34 250996 B=4217034
0020:  39 34 20 43 3D 36 35 39 30 35 36 33 39 31 20 34 94 C=659056391 4
0030:  20 41 3D 41 5E 53 20 42 3D 42 2B 43 20 43 3D 43  A=A^S B=B+C C=C
0040:  5E 41 20 41 3D 41 5E 42 00                      ^A A=A^B.      
[BNLS]Recv: BNLS_VERSIONCHECK
0000:  32 00 09 01 00 00 00 64 11 00 01 98 32 69 32 57 2......d....2i2W
0010:  61 72 33 2E 65 78 65 20 30 39 2F 31 35 2F 30 34 ar3.exe 09/15/04
0020:  20 32 32 3A 34 32 3A 31 36 20 31 35 36 38 32 31  22:42:16 156821
0030:  31 00                                           1.              
[BNLS]Sent: BNLS_CDKEY
0000:  1E 00 01 38 42 46 36 36 45 46 58 42 57 59 58 57 ...8BF66EFXBWYXW
0010:  xx xx xx xx xx xx xx xx xx xx xx xx xx 00       xxxxxxxxxxxxx.  
[BNLS]Recv: BNLS_CDKEY
0000:  07 00 01 00 00 00 00                            .......        
[BNET]Recv: SID_NULL
0000:  FF 00 04 00                                     ....            
[BNET]Sent: SID_NULL
0000:  FF 00 04 00  
#8
Just as a side question, is this the proper order I should be handling packets and their responses for War3?

>> BNLS_REQUESTVERSIONBYTE

<< BNLS_REQUESTVERSIONBYTE
>> BNET PROTOCOL BYTE
>> SID_AUTH_INFO

<< SID_AUTH_INFO
>> BNLS_CHOOSENLSREVISION

<< BNLS_CHOOSENLSREVISION
>> BNLS_VERSIONCHECK

<< BNLS_VERSIONCHECK
>> BNLS_CDKEY

<< BNLS_CDKEY
>> SID_AUTH_CHECK

<< SID_AUTH_CHECK
>> BNLS_LOGONCHALLENGE

<< BNLS_LOGONCHALLENGE
>> SID_GETICONDATA

<< SID_GETICONDATA
>> BNLS_LOGONPROOF

<< BNLS_LOGONPROOF
>> SID_AUTH_ACCOUNTLOGONPROOF

<< SID_AUTH_ACCOUNTLOGONPROOF
>> SID_ENTERCHAT

<< SID_ENTERCHAT
>> SID_GETCHANNELLIST

<< SID_GETCHANNELLIST

<<>> SID_CHATEVENT
#9
I realized after I posted.  I have 3 other bots that didn't go down so I never thought that BNLS server wasn't at full capacity.

Also, this is not the first time I posted this questing.  I had a problem with this in the past and I just finished re-writing the code from scrath and thought it wasn't fixed yet.

I do appologize.
#10
Greetings, I am making a bot from scratch and I am having problems at one point.  I don't know why I am getting a failed response.  Everything looks okay to me.  I need a fresh perspective....

[BNET]Created
[BNET]Connecting to useast.battle.net:6112
[BNLS]Connecting to: bnls.valhallalegends.com:9367
[BNLS]Created
[BNLS]Connecting to bnls.valhallalegends.com:9367
[BNLS]Sent: BNLS_REQUESTVERSIONBYTE
0000:  07 00 10 07 00 00 00                            .......        
[BNLS]Recv: BNLS_REQUESTVERSIONBYTE
0000:  0B 00 10 07 00 00 00 11 00 00 00                ...........    
[BNET]Sent: SID_AUTH_INFO
0000:  FF 50 3A 00 00 00 00 00 36 38 58 49 50 58 33 57 .P:.....68XIPX3W
0010:  11 00 00 00 53 55 6E 65 18 BA 00 A6 F0 00 00 00 ....SUne........
0020:  09 04 00 00 09 04 00 00 55 53 41 00 55 6E 69 74 ........USA.Unit
0030:  65 64 20 53 74 61 74 65 73 00                   ed States.      
[BNET]Recv: SID_PING
0000:  FF 25 08 00 79 76 01 7B                         .%..yv.{        
[BNET]Sent: SID_PING
0000:  FF 25 08 00 79 76 01 7B                         .%..yv.{        
[BNET]Recv: SID_AUTH_INFO
0000:  FF 50 E3 00 02 00 00 00 D7 9B 13 CE 83 F1 23 00 .P............#.
0010:  00 A0 99 7D 91 E7 C3 01 49 58 38 36 76 65 72 34 ...}....IX86ver4
0020:  2E 6D 70 71 00 41 3D 38 36 33 30 39 39 30 35 39 .mpq.A=863099059
0030:  20 42 3D 39 33 37 35 37 38 36 31 31 20 43 3D 39  B=937578611 C=9
0040:  33 35 38 30 31 37 31 30 20 34 20 41 3D 41 5E 53 35801710 4 A=A^S
0050:  20 42 3D 42 2D 43 20 43 3D 43 5E 41 20 41 3D 41  B=B-C C=C^A A=A
0060:  5E 42 00 2F 24 DB 71 88 1C A5 55 CA 2B C0 C9 D2 ^B./$.q...U.+...
0070:  C9 7C 05 4E D4 BF AA 94 19 F0 1C ED E8 A5 9A 56 .|.N...........V
0080:  74 8C EB 7D 0B 30 90 D1 10 48 E9 39 80 BD F5 B3 t..}.0...H.9....
0090:  FE 60 33 51 FE 1D 8C A1 56 5A 07 E1 EB 16 24 0C .`3Q....VZ....$.
00A0:  44 B2 F6 6E 9B A9 2A 86 FE 6D 67 C2 9A 76 EA 4F D..n..*..mg..v.O
00B0:  CA CF 32 1C 92 2E 20 F3 6F F2 1B 2C EC 88 04 81 ..2... .o..,....
00C0:  89 08 68 D4 04 D6 6A CF 85 52 A0 4E FE 94 0B 85 ..h...j..R.N....
00D0:  33 E3 50 BC 5D 26 B7 D6 7C 68 AE 01 40 23 DA E0 3.P.]&..|h..@#..
00E0:  8B 88 A7                                        ...            
[BNET]Debug:Enter: Process_SID_AUTH_INFO
[BNET]Debug:DLL Revision: 4
[BNLS]Sent: BNLS_CHOOSENLSREVISION
ValueString1 = A=863099059 B=937578611 C=935801710 4 A=A^S B=B-C C=C^A A=A^B
0000:  07 00 0D 02 00 00 00                            .......        
[BNLS]Recv: BNLS_CHOOSENLSREVISION
0000:  07 00 0D 01 00 00 00                            .......        
[BNET]Debug: Enter: Process_BNLS_CHOOSENLSREVISION
[BNLS]Debug:NLS Revision good.
[BNLS]Sent: BNLS_VERSIONCHECK
0000:  49 00 09 07 00 00 00 04 00 00 00 41 3D 38 36 33 I..........A=863
0010:  30 39 39 30 35 39 20 42 3D 39 33 37 35 37 38 36 099059 B=9375786
0020:  31 31 20 43 3D 39 33 35 38 30 31 37 31 30 20 34 11 C=935801710 4
0030:  20 41 3D 41 5E 53 20 42 3D 42 2D 43 20 43 3D 43  A=A^S B=B-C C=C
0040:  5E 41 20 41 3D 41 5E 42 00                      ^A A=A^B.      
[BNLS]Recv: BNLS_VERSIONCHECK
0000:  07 00 09 00 00 00 00                             <- Failed!  Why?
#11
After fixing the Ping, I did get a response, but I got a 203 failure.  The other problem listed seems like I did it right. Any confirmations?
#12
Quote
This one's easy.  You botched a length field. :)  Check out your SID_PING response:

Ah, how did I miss that!  :)

Though I think BNET may have that packet coded as a fixed length cause I think I got a response after that.

Quote... sending for your CD-key hash.  It looks like you extracting and/or storing it improperly.

I will have to take another look at this.  I thought I checked it 3 times.  I'm at work now so I don't really have time to check the references, but I thought I got this part right.  Anyone want to confirm it for me?  :)

Anyway, thanks guys.  I will see if these will fix my problems when I get home.  :)
#13
Anyway, I can't get BNET to reply with SID_AUTH_CHECK for some reason.


2  24.186.0.166:1592  63.240.202.139:6112  1  Send  
0000  01                                                 .

3  24.186.0.166:1593  63.161.183.202:9367  7  Send  
0000  07 00 10 07 00 00 00                               .......

4  63.161.183.202:9367  24.186.0.166:1593  11  Recv  
0000  0B 00 10 07 00 00 00 10 00 00 00                   ...........

5  24.186.0.166:1592  63.240.202.139:6112  58  Send  
0000  FF 50 3A 00 00 00 00 00 36 38 58 49 50 58 33 57    .P:.....68XIPX3W
0010  10 00 00 00 53 55 6E 65 18 BA 00 A6 F0 00 00 00    ....SUne........
0020  09 04 00 00 09 04 00 00 55 53 41 00 55 6E 69 74    ........USA.Unit
0030  65 64 20 53 74 61 74 65 73 00                      ed States.

6  63.240.202.139:6112  24.186.0.166:1592  235  Recv  
0000  FF 25 08 00 0E 25 15 D0

     FF 50 E3 00 02 00 00 00    .%...%...P......
0010  95 39 A9 89 5D A6 01 00 00 95 2E 62 91 E7 C3 01    .9..]......b....
0020  49 58 38 36 76 65 72 30 2E 6D 70 71 00 41 3D 32    IX86ver0.mpq.A=2
0030  31 35 36 36 31 31 37 33 20 42 3D 31 37 33 30 38    15661173 B=17308
0040  30 37 35 38 20 43 3D 34 30 39 30 32 38 38 39 38    0758 C=409028898
0050  20 34 20 41 3D 41 2D 53 20 42 3D 42 2B 43 20 43     4 A=A-S B=B+C C
0060  3D 43 5E 41 20 41 3D 41 2B 42 00 BD A0 92 6C 5C    =C^A A=A+B....l\
0070  B5 07 30 C3 A9 6A EB 3A EA 96 DA 52 B2 DF D4 BD    ..0..j.:...R....
0080  CE 7C 7B 83 4D D1 19 97 15 94 71 D9 98 01 2A 67    .|{.M.....q...*g
0090  C8 7C A5 8E 5E 4E 68 E1 FF B0 B6 56 3A 0B AE 09    .|..^Nh....V:...
00A0  43 2E 23 29 4E 83 AC 60 FE 12 8A 95 F7 DF 04 6F    C.#)N..`.......o
00B0  F3 BF A5 FA 06 43 D2 4E 18 FE DD D6 A2 EF DC 9D    .....C.N........
00C0  E9 80 BE A1 87 20 A0 4F 47 A2 B2 57 4F 5F 5B 67    ..... .OG..WO_[g
00D0  7E 1F 8B 19 A0 EB 6F 45 18 EE 94 56 BB A9 73 6B    ~.....oE...V..sk
00E0  31 34 8A A3 74 F0 EE 0F DA 25 5A                   14..t....%Z

7  24.186.0.166:1592  63.240.202.139:6112  8  Send  
0000  FF 25 00 08 0E 25 15 D0                            .%...%..

8  24.186.0.166:1593  63.161.183.202:9367  7  Send  
0000  07 00 0D 02 00 00 00                               .......

9  24.186.0.166:1593  63.161.183.202:9367  73  Send  
0000  49 00 09 07 00 00 00 00 00 00 00 41 3D 32 31 35    I..........A=215
0010  36 36 31 31 37 33 20 42 3D 31 37 33 30 38 30 37    661173 B=1730807
0020  35 38 20 43 3D 34 30 39 30 32 38 38 39 38 20 34    58 C=409028898 4
0030  20 41 3D 41 2D 53 20 42 3D 42 2B 43 20 43 3D 43     A=A-S B=B+C C=C
0040  5E 41 20 41 3D 41 2B 42 00                         ^A A=A+B.

10  63.161.183.202:9367  24.186.0.166:1593  7  Recv  
0000  07 00 0D 01 00 00 00                               .......

11  63.161.183.202:9367  24.186.0.166:1593  50  Recv  
0000  32 00 09 01 00 00 00 26 10 00 01 20 D6 F1 5D 57    2......&... ..]W
0010  61 72 33 2E 65 78 65 20 30 36 2F 32 38 2F 30 34    ar3.exe 06/28/04
0020  20 32 33 3A 33 37 3A 30 31 20 31 35 36 38 32 31     23:37:01 156821
0030  31 00                                              1.

12  24.186.0.166:1593  63.161.183.202:9367  34  Send  
0000  22 00 01 00 A6 01 00 65 6E 63 65 68 63 63 79 65    "......encehccye
0010  72 68 77 6B 65 77 6E 36 xx xx xx xx xx xx xx xx    rhwkewn6!!!!!!!!
0020  38 00                                              8.

13  63.161.183.202:9367  24.186.0.166:1593  47  Recv  
0000  2F 00 01 01 00 00 00 DC 52 45 43 1A 00 00 00 0E    /.......REC.....
0010  00 00 00 80 4E 20 00 00 00 00 00 79 EE 3E 23 30    ....N .....y.>#0
0020  88 A5 75 3D 3D 1F 74 5E 76 00 88 32 0A C6 D9       ..u==.t^v..2...

14  24.186.0.166:1592  63.240.202.139:6112  104  Send  
0000  FF 51 68 00 DC 52 45 43 26 10 00 01 20 D6 F1 5D    .Qh..REC&... ..]
0010  01 00 00 00 00 00 00 00 00 0E 00 00 00 80 4E 20    ..............N
0020  00 00 00 00 00 79 EE 3E 23 30 88 A5 75 3D 3D 1F    .....y.>#0..u==.
0030  74 5E 76 00 88 32 0A C6 D9 31 31 00 57 61 72 33    t^v..2...11.War3
0040  2E 65 78 65 20 30 36 2F 32 38 2F 30 34 20 32 33    .exe 06/28/04 23
0050  3A 33 37 3A 30 31 20 31 35 36 38 32 31 31 00 54    :37:01 1568211.T
0060  44 41 2D 42 6F 74 32 00                            DA-Bot2.


Now I don't get a response.  Some help?  All I am getting are SID_NULLs every minute or so.
#14
Obviousely I am using BNETDocs if I am using their constants and stuff.   ;)

Anyway, BNET docs does not explain the sequence of BNLS all that much.  There is a little bit of logon sequence for starcraft and war2bne, but not much for WC3.

My question involve the next step.  I know I have to send SID_AUTH_INFO data to BNLS and then take that info and send it back to BNET.  I am looking for details on this...
#15
I will be updating this message as I change things from time to time.  Lend me some help from time to time.  :)

Quote[BNET Connected]
<BNET Thread Started>
[BNLS Connected]
BNET Waiting: BNLS_REQUESTVERSIONBYTE
<BNLS Thread Started>
BNLS Send: BNLS_REQUESTVERSIONBYTE
BNLS Recv: BNLS_REQUESTVERSIONBYTE
BNLS INFO: Product ID = $07 (Warcraft)
BNLS INFO: Version Byte = $10
BNET Waiting: DONE!
Sent: SID_AUTH_INFO
BNET Recv: SID_PING
BNET Sent: SID_PING
BNET Recv: SID_AUTH_INFO
BNLS Send: BNLS_CHOOSENLSREVISION
BNET Info: Session Key = 00B00100
BNET Info: DLL Revision number = 1
BNET Info: Checksum = "A=143256995 B=515572255 C=472874471 4 A=A-S B=B+C C=C+A A=A^B"
BNLS Send: BNLS_VERSIONCHECK
BNLS Recv: BNLS_CHOOSENLSREVISION
BNLS Info: DLL Revision number Recognized!
BNLS Recv: BNLS_VERSIONCHECK
BNLS Info: Version Check Successful!
BNLS Info: Version = 0026
BNLS Info: CheckSum = 009C
BNLS Info: Version String = "War3.exe 06/28/04 23:37:01 1568211"
BNLS Send: BNLS_CDKEY
BNLS Recv: BNLS_CDKEY
BNLS Info: Successful CD-Key Encryption.
BNLS Info: Session Key = 00F2
BNET Send: SID_AUTH_CHECK

unit ClientUnit;

interface

uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
 IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, StdCtrls, PacketConsts;

type
 TBNETReadThread = class(TThread)
 public
   constructor Create(IndyClient: TIdTCPClient);
 private
   FIndyClient: TIdTCPClient;
   FStartPacket: Byte;
   FPacketID: Byte;
   FPacketLength: Word;
   FPacketData: Array[0..64000] of Byte;
   FMessage: String;
   procedure DisplayString;
   procedure ConnectBNLS;
 protected
   procedure Execute; override;
 end;

 TBNLSReadThread = class(TThread)
 public
   FVersionByte : Byte;
   FVersion : array[0..3] of Byte;
   FVersionString : String;
   FSessionKey : Array[0..3] of Byte;
   FCheckSum : array[0..3] of Byte;
   constructor Create(IndyClient: TIdTCPClient);
 private
   FIndyClient: TIdTCPClient;
   FPacketLength: Word;
   FPacketID: Byte;
   FPacketData: Array[0..64000] of Byte;
   FMessage: String;
   procedure DisplayString;
 protected
   procedure Execute; override;
 end;


 TForm1 = class(TForm)
   IdTCPClient1: TIdTCPClient;
   Memo1: TMemo;
   Button1: TButton;
   Edit1: TEdit;
   Memo2: TMemo;
   IdTCPClient2: TIdTCPClient;
   Edit2: TEdit;
   Edit3: TEdit;
   Edit4: TEdit;
   Edit5: TEdit;
   procedure Button1Click(Sender: TObject);
   procedure IdTCPClient1Connected(Sender: TObject);
   procedure IdTCPClient1Disconnected(Sender: TObject);
   procedure Edit1KeyPress(Sender: TObject; var Key: Char);
   procedure IdTCPClient2Connected(Sender: TObject);
   procedure IdTCPClient2Disconnected(Sender: TObject);
 private
   tr1: TBNETReadThread;
   tr2: TBNLSReadThread;
 public
 end;

var
 Form1: TForm1;

implementation

{$R *.DFM}

constructor TBNETReadThread.Create(IndyClient: TIdTCPClient);
begin
 FIndyClient := IndyClient;
 inherited Create(false);
end;

constructor TBNLSReadThread.Create(IndyClient: TIdTCPClient);
begin
 FIndyClient := IndyClient;
 FVersionByte := 0;
 inherited Create(false);
end;


procedure TBNETReadThread.DisplayString;
begin
 Form1.Memo1.Lines.Add(FMessage);
end;

procedure TBNETReadThread.ConnectBNLS;
begin
 try
   Form1.IdTCPClient2.Host := 'bnls.valhallalegends.com';
   Form1.IdTCPClient2.Port := 9367;
   Form1.IdTCPClient2.Connect;
 except
   on E: Exception do
     Begin
       Form1.Memo1.Lines.Add('BNLS Connection Error: '+E.Message);
       try
         Form1.IdTCPClient2.Disconnect;
       except
         on E: Exception do Form1.Memo1.Lines.Add('BNLS Connection Error Part 2: '+E.Message);
       end;
       Terminate;
     End;
 end;
end;


procedure TBNLSReadThread.DisplayString;
begin
 Form1.Memo1.Lines.Add(FMessage);
end;


procedure TBNETReadThread.Execute;
var
 AByte,AByte2,I : Byte;
 AString : String;
 procedure DoDisplay(S: String);
 begin
   FMessage := S;
   Synchronize(DisplayString);
 end;
begin
 If not terminated and FIndyClient.Connected then
   Begin
     DoDisplay('<BNET Thread Started>');
     Synchronize(ConnectBNLS);
     AByte := 1; // Protocol Byte
     FIndyClient.OpenWriteBuffer();
     FIndyClient.WriteBuffer(AByte,1,True);
     FIndyClient.FlushWriteBuffer();
     FIndyClient.OpenWriteBuffer();
     If Form1.tr2.FVersionByte = 0 then
       Begin
         DoDisplay('BNET Waiting: BNLS_REQUESTVERSIONBYTE');
         while Form1.IdTCPClient2.Connected and (Form1.tr2.FVersionByte = 0) do
           Windows.Sleep(0);
         DoDisplay('BNET Waiting: DONE!');
       End;
     If not Form1.IdTCPClient2.Connected then
       Begin
         DoDisplay('BNET Terminating: Requires BNLS connection.');
         Terminate;
         Exit;
       End;
     For I := $00 to $0F do
       FIndyClient.WriteBuffer(SID_AUTH_INFO_Data[I],1);
     AByte := Form1.tr2.FVersionByte;
     FIndyClient.WriteBuffer(AByte,1);
     For I := $11 to $39 do
       FIndyClient.WriteBuffer(SID_AUTH_INFO_Data[I],1);
     FIndyClient.FlushWriteBuffer();

     DoDisplay('Sent: SID_AUTH_INFO');
   End;

 while not Terminated and FIndyClient.Connected do
 try
   FIndyClient.ReadBuffer(FStartPacket,1);
   FIndyClient.ReadBuffer(FPacketID,1);
   FIndyClient.ReadBuffer(AByte,1);
   FIndyClient.ReadBuffer(FPacketLength,1);
   FPacketLength := (FPacketLength SHL 8) + AByte;
   FIndyClient.ReadBuffer(FPacketData,FPacketLength-4);
   Case FStartPacket of
     $FF :
       Case FPacketID of
         SID_NULL : DoDisplay('BNET Recv: SID_NULL');
         SID_CLIENTID : DoDisplay('BNET Recv: SID_CLIENTID');
         SID_STARTVERSIONING : DoDisplay('BNET Recv: SID_STARTVERSIONING');
         SID_REPORTVERSION : DoDisplay('BNET Recv: SID_REPORTVERSION');
         SID_GETADVLISTEX  : DoDisplay('BNET Recv: SID_GETADVLISTEX');
         SID_ENTERCHAT : DoDisplay('BNET Recv: SID_ENTERCHAT');
         SID_GETCHANNELLIST : DoDisplay('BNET Recv: SID_GETCHANNELLIST');
         SID_CHATEVENT : DoDisplay('BNET Recv: SID_CHATEVENT');
         SID_FLOODDETECTED : DoDisplay('BNET Recv: SID_FLOODDETECTED');
         SID_UDPPINGRESPONSE : DoDisplay('BNET Recv: SID_UDPPINGRESPONSE');
         SID_MESSAGEBOX : DoDisplay('BNET Recv: SID_MESSAGEBOX');
         SID_PING :
           Begin
             DoDisplay('BNET Recv: SID_PING');
             FIndyClient.OpenWriteBuffer();
             FIndyClient.WriteBuffer(FStartPacket,1);
             FIndyClient.WriteBuffer(FPacketID,1);
             AByte := FPacketLength SHR 8;
             FIndyClient.WriteBuffer(AByte,1);
             AByte := FPacketLength AND $FF;
             FIndyClient.WriteBuffer(AByte,1);
             FIndyClient.WriteBuffer(FPacketData,FPacketLength-4);
             FIndyClient.FlushWriteBuffer();
             DoDisplay('BNET Sent: SID_PING');
           End;
         SID_READUSERDATA : DoDisplay('BNET Recv: SID_READUSERDATA');
         SID_LOGONCHALLENGE : DoDisplay('BNET Recv: SID_LOGONCHALLENGE');
         SID_LOGONRESPONSE : DoDisplay('BNET Recv: SID_LOGONRESPONSE');
         SID_CREATEACCOUNT : DoDisplay('BNET Recv: SID_CREATEACCOUNT');
         SID_CHANGEPASSWORD : DoDisplay('BNET Recv: SID_CHANGEPASSWORD');
         SID_CDKEY2 : DoDisplay('BNET Recv: SID_CDKEY2');
         SID_CREATEACCOUNT2 : DoDisplay('BNET Recv: SID_CREATEACCOUNT2');
         SID_LOGONREALMEX : DoDisplay('BNET Recv: SID_LOGONREALMEX');
         SID_AUTH_INFO :
           Begin
             DoDisplay('BNET Recv: SID_AUTH_INFO');
             If not Form1.IdTCPClient2.Connected then
               Begin
                 DoDisplay('BNET: Cannot Continue further without BNLS.');
                 Terminate;
                 Exit;
               End;
             //---BNLS_CHOOSENLSREVISION---
             // FPacketData[01..00] = NLS revision
             with Form1.IdTCPClient2 do
               Begin
                 OpenWriteBuffer();
                 Abyte := 7; //Length header
                 WriteBuffer(AByte,1);
                 AByte := 0;
                 WriteBuffer(AByte,1);
                 AByte := BNLS_CHOOSENLSREVISION;

                 WriteBuffer(AByte,1);
                 WriteBuffer(FPacketData[0],2);
                 AByte := 0;
                 WriteBuffer(AByte,1);
                 WriteBuffer(AByte,1);
                 FlushWriteBuffer();
                 DoDisplay('BNLS Send: BNLS_CHOOSENLSREVISION');
               End;
             form1.tr2.FSessionKey[0] := FPacketData[8];
             form1.tr2.FSessionKey[1] := FPacketData[9];
             form1.tr2.FSessionKey[2] := FPacketData[10];
             form1.tr2.FSessionKey[0] := FPacketData[11];

             DoDisplay('BNET Info: Session Key = '
               +IntToHex(form1.tr2.FSessionKey[0],2)
               +IntToHex(form1.tr2.FSessionKey[1],2)
               +IntToHex(form1.tr2.FSessionKey[2],2)
               +IntToHex(form1.tr2.FSessionKey[3],2));

             AByte := $11;
             AString := '';
             AByte2 := 0;
             While FPacketData[AByte] <> 0 do
               Begin
                 AString := AString + Char(FPacketData[AByte]);
                 If Char(FPacketData[AByte]) = '.' then
                   AByte2 := StrToInt(Char(FPacketData[AByte-1]));
                 AByte := AByte + 1;
               End;
             DoDisplay('BNET Info: DLL Revision number = '+IntToStr(AByte2));
             AByte := AByte + 1;
             AString := '';
             While FPacketData[AByte] <> 0 do
               Begin
                 AString := AString + Char(FPacketData[AByte]);
                 AByte := AByte + 1;
               End;
             DoDisplay('BNET Info: Checksum = "'+AString+'"');
             //---BNLS_VERSIONCHECK---
             with Form1.IdTCPClient2 do
               Begin
                 OpenWriteBuffer();
                 AByte := 11; //header + id + ver
                 AByte := AByte + Length(AString) + 1;
                 WriteBuffer(AByte,1);
                 AByte := 0;
                 WriteBuffer(AByte,1);
                 AByte := BNLS_VERSIONCHECK;
                 WriteBuffer(AByte,1);
                 AByte := PRODUCT_WARCRAFT3;
                 WriteBuffer(AByte,1);
                 AByte := 0;
                 WriteBuffer(AByte,1);
                 WriteBuffer(AByte,1);
                 WriteBuffer(AByte,1);
                 WriteBuffer(AByte2,1);
                 WriteBuffer(AByte,1);
                 WriteBuffer(AByte,1);
                 WriteBuffer(AByte,1);
                 WriteBuffer(AString[1],Length(AString));
                 WriteBuffer(AByte,1);
                 FlushWriteBuffer();
                 DoDisplay('BNLS Send: BNLS_VERSIONCHECK');
               End;
           End;
         SID_AUTH_CHECK : DoDisplay('BNET Recv: SID_AUTH_CHECK');
         SID_FRIENDLIST : DoDisplay('BNET Recv: SID_FRIENDLIST');
         SID_FRIENDUPDATE : DoDisplay('BNET Recv: SID_FRIENDUPDATE');
         SID_FRIENDADDED : DoDisplay('BNET Recv: SID_FRIENDADDED');
         SID_FRIENDREMOVED : DoDisplay('BNET Recv: SID_FRIENDREMOVED');
         SID_FRIENDMOVED : DoDisplay('BNET Recv: SID_FRIENDMOVED');
         SID_FINDCLANCANDIDATES : DoDisplay('BNET Recv: SID_FINDCLANCANDIDATES');
         SID_INVITEMULTIPLEUSERS : DoDisplay('BNET Recv: SID_INVITEMULTIPLEUSERS');
         SID_DISBANDCLAN : DoDisplay('BNET Recv: SID_DISBANDCLAN');
         SID_CLANINFO : DoDisplay('BNET Recv: SID_CLANINFO');
         SID_CLANREQUEST : DoDisplay('BNET Recv: SID_CLANREQUEST');
         SID_CLANINVITE : DoDisplay('BNET Recv: SID_CLANINVITE');
         SID_CLANMOTD : DoDisplay('BNET Recv: SID_CLANMOTD');
         SID_CLANMEMBERLIST : DoDisplay('BNET Recv: SID_CLANMEMBERLIST');
         SID_CLANMEMBERUPDATE : DoDisplay('BNET Recv: SID_CLANMEMBERUPDATE');
         SID_CLANPROMOTION : DoDisplay('BNET Recv: SID_CLANPROMOTION');
       end;
     Else
       Begin
         DoDisplay('BNET Recv: Unknown Packet $'+IntToHex(FPacketID,2));
       End;
   End;
 except on E: Exception do Form1.Memo1.Lines.Add('BNET Thread Error: '+E.Message);
 end;
 DoDisplay('<BNET Thread Ended>');
end;

procedure TBNLSReadThread.Execute;
var
 AByte,I : Byte;
 AWord : Word;
 AString : String;
 PacketHeader : Byte;
 PacketLength : Word;
 PacketData   : Array[0..64000] of Byte;
 procedure DoDisplay(S: String);
 begin
   FMessage := S;
   Synchronize(DisplayString);
 end;
begin
 If not terminated and FIndyClient.Connected then
   Begin
     DoDisplay('<BNLS Thread Started>');
     FIndyClient.OpenWriteBuffer();
     AByte := 7; // Length DDWORD;
     FIndyClient.WriteBuffer(AByte,1);
     AByte := 0;
     FIndyClient.WriteBuffer(AByte,1);
     AByte := BNLS_REQUESTVERSIONBYTE;
     FIndyClient.WriteBuffer(AByte,1);
     AByte := PRODUCT_WARCRAFT3;
     FIndyClient.WriteBuffer(AByte,1);
     AByte := 0;
     FIndyClient.WriteBuffer(AByte,1);
     AByte := 0;
     FIndyClient.WriteBuffer(AByte,1);
     AByte := 0;
     FIndyClient.WriteBuffer(AByte,1);
     FIndyClient.FlushWriteBuffer();
     DoDisplay('BNLS Send: BNLS_REQUESTVERSIONBYTE');
   End;
 while not Terminated and FIndyClient.Connected do
 begin
   PacketLength := 0;
   FIndyClient.ReadBuffer(AByte,1);
   PacketLength := AByte;
   FIndyClient.ReadBuffer(AByte,1);
   PacketLength := PacketLength + AByte SHL 8;
   FIndyClient.ReadBuffer(PacketHeader,1);
   If PacketLength > 3 then
     FIndyClient.ReadBuffer(PacketData,PacketLength-3);
   Case PacketHeader of
     BNLS_NULL                : DoDisplay('BNLS Recv: BNLS_NULL');
     BNLS_CDKEY                :
       Begin
         DoDisplay('BNLS Recv: BNLS_CDKEY');
         If PacketData[0] = 1 then
           DoDisplay('BNLS Info: Successful CD-Key Encryption.')
         else
           Begin
             DoDisplay('BNLS Info: Unsuccessful CD-Key Encryption!  Halting.');
             FIndyClient.Disconnect;
             Terminate;
             Exit;
           End;
         FSessionKey[0] := PacketData[4];
         FSessionKey[1] := PacketData[5];
         FSessionKey[2] := PacketData[6];
         FSessionKey[3] := PacketData[7];
         DoDisplay('BNLS Info: Session Key = '+IntToHex(DWord(FSessionKey[0]),4));
         //---SID_AUTH_CHECK---
         with form1.IdTCPClient1 do
           Begin
             OpenWriteBuffer();
             AByte := $FF;
             WriteBuffer(AByte,1);
             AByte := SID_AUTH_CHECK;
             WriteBuffer(AByte,1);
           //Length xx 00
             AByte := 4 + 4 + 4 + 4 + 4 + 4 + (9*4)
               + Length(Form1.Edit2.text) + 1
               + Length(FVersionString) + 1;
             WriteBuffer(AByte,1);
             AByte := 0;
             WriteBuffer(AByte,1);
           //Session Key
             WriteBuffer(form1.tr2.FSessionKey[0],4);
           //Version
             WriteBuffer(form1.tr2.FVersion[0],4);
           //Checksum
             WriteBuffer(form1.tr2.FCheckSum[0],4);
           //# Keys xx 00
             AByte := $01;
             WriteBuffer(AByte,1);
             AByte := $00;
             WriteBuffer(AByte,1);
             WriteBuffer(AByte,1);
             WriteBuffer(AByte,1);
           //Bool 00 00
             WriteBuffer(AByte,1);
             WriteBuffer(AByte,1);
             WriteBuffer(AByte,1);
             WriteBuffer(AByte,1);
           //9 DWORDS CD-Key Data
             WriteBuffer(PacketData[11],36);
           //String Version Check Stat String
             WriteBuffer(FVersionString[1],Length(FVersionString));
             WriteBuffer(AByte,1);
           //String CD-Key Owner Name
             AString := Form1.Edit2.Text;
             WriteBuffer(AString[1],Length(AString));
             WriteBuffer(AByte,1);
             FlushWriteBuffer();
             DoDisplay('BNET Send: SID_AUTH_CHECK');
           End;

       End;
     BNLS_LOGONCHALLENGE        : DoDisplay('BNLS Recv: BNLS_LOGONCHALLENGE');
     BNLS_LOGONPROOF             : DoDisplay('BNLS Recv: BNLS_LOGONPROOF');
     BNLS_CREATEACCOUNT         : DoDisplay('BNLS Recv: BNLS_CREATEACCOUNT');
     BNLS_CHANGECHALLENGE       : DoDisplay('BNLS Recv: BNLS_CHANGECHALLENGE');
     BNLS_CHANGEPROOF           : DoDisplay('BNLS Recv: BNLS_CHANGEPROOF');
     BNLS_UPGRADECHALLENGE       : DoDisplay('BNLS Recv: BNLS_UPGRADECHALLENGE');
     BNLS_UPGRADEPROOF           : DoDisplay('BNLS Recv: BNLS_UPGRADEPROOF');
     BNLS_VERSIONCHECK           :
       Begin
         DoDisplay('BNLS Recv: BNLS_VERSIONCHECK');
         If PacketData[0] = 1 then
           DoDisplay('BNLS Info: Version Check Successful!')
         else
           Begin
             DoDisplay('BNLS Info: Version Check *NOT* Successful!  Halting.');
             FIndyClient.Disconnect;
             Terminate;
             Exit;
           End;
         FVersion[0] := PacketData[4];
         FVersion[1] := PacketData[5];
         FVersion[2] := PacketData[6];
         FVersion[3] := PacketData[7];
         DoDisplay('BNLS Info: Version = '+IntToHex(DWord(FVersion[0]),4));

         FCheckSum[0] := PacketData[8];
         FCheckSum[1] := PacketData[9];
         FCheckSum[2] := PacketData[10];
         FCheckSum[3] := PacketData[11];
         DoDisplay('BNLS Info: CheckSum = '+IntToHex(DWord(FCheckSum[0]),4));

         AString := '';
         AByte := 12;
         While PacketData[AByte] <> 0 do
           Begin
             AString := AString + Char(PacketData[AByte]);
             AByte := AByte + 1;
           End;
         FVersionString := AString;
         DoDisplay('BNLS Info: Version String = "'+FVersionString+'"');


         FIndyClient.OpenWriteBuffer();
         AString := Form1.Edit4.text;
         AByte := 3 + 4 + Length(AString) + 1;
         FIndyClient.WriteBuffer(AByte,1);
         AByte := 0;
         FIndyClient.WriteBuffer(AByte,1);
         AByte := BNLS_CDKEY;
         FIndyClient.WriteBuffer(AByte,1);
         FIndyClient.WriteBuffer(form1.tr2.FSessionKey[0],4);
         FIndyClient.WriteBuffer(AString[1],Length(AString));
         AByte := 0;
         FIndyClient.WriteBuffer(AByte,1);
         FIndyClient.FlushWriteBuffer();
         DoDisplay('BNLS Send: BNLS_CDKEY');
       End;
     BNLS_CONFIRMLOGON           : DoDisplay('BNLS Recv: BNLS_CONFIRMLOGON');
     BNLS_HASHDATA                : DoDisplay('BNLS Recv: BNLS_HASHDATA');
     BNLS_CDKEY_EX                : DoDisplay('BNLS Recv: BNLS_CDKEY_EX');
     BNLS_CHOOSENLSREVISION    :
       Begin
         DoDisplay('BNLS Recv: BNLS_CHOOSENLSREVISION');
         If PacketData[0] = 1 then
           DoDisplay('BNLS Info: DLL Revision number Recognized!')
         else
           Begin
             DoDisplay('BNLS Info: DLL Revision number *NOT* Recognized!  Halting.');
             FIndyClient.Disconnect;
             Terminate;
             Exit;
           End
       End;
     BNLS_AUTHORIZE             : DoDisplay('BNLS Recv: BNLS_AUTHORIZE');
     BNLS_AUTHORIZEPROOF         : DoDisplay('BNLS Recv: BNLS_AUTHORIZEPROOF');
     BNLS_REQUESTVERSIONBYTE    :
       Begin
         DoDisplay('BNLS Recv: BNLS_REQUESTVERSIONBYTE');
         AWord := PacketData[0] + PacketData[1] SHL 8;
         Case Aword of
           0 :
             Begin
               DoDisplay('BNLS INFO: Product ID = $'+IntToHex(Aword,2)+' (FAILED)');
               DoDisplay('BNLS INFO: Version Byte not recieved.');
             End;
           7 : //Warcraft
             Begin
               DoDisplay('BNLS INFO: Product ID = $'+IntToHex(Aword,2)+' (Warcraft)');
               DoDisplay('BNLS INFO: Version Byte = $'+IntToHex(PacketData[4],2));
               FVersionByte := PacketData[4];
             End;
         Else
           Begin
             DoDisplay('BNLS INFO: Product ID = $'+IntToHex(Aword,2)+' (UnSupport Yet)');
             DoDisplay('BNLS INFO: Version Byte = $'+IntToHex(PacketData[4],2));
             FVersionByte := PacketData[4];
           End;
         End;
       End;
     BNLS_VERIFYSERVER           : DoDisplay('BNLS Recv: BNLS_VERIFYSERVER');
     BNLS_RESERVESERVERSLOTS    : DoDisplay('BNLS Recv: BNLS_RESERVESERVERSLOTS');
     BNLS_SERVERLOGONCHALLENGE: DoDisplay('BNLS Recv: BNLS_SERVERLOGONCHALLENGE');
     BNLS_SERVERLOGONPROOF       : DoDisplay('BNLS Recv: BNLS_SERVERLOGONPROOF');
   Else
     DoDisplay('BNLS Recv: Unknown $'+IntToHex(PacketHeader,2));
   End;
 end;
 DoDisplay('<BNLS Thread Ended>');
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
 If Button1.Caption = 'Connect' then
 try
   Button1.Caption := 'Disconnect';
   //IdTCPClient1.Host := '63.240.202.129';
   //IdTCPClient1.Host := 'useast.battle.net';
   IdTCPClient1.Host := Edit5.Text;
   IdTCPClient1.Port := 6112;
   IdTCPClient1.Connect;
 except
   on E: Exception do
     Begin
       Memo1.Lines.Add('BNET Connection Error: '+E.Message);
       Button1.Caption := 'Connect';
     End;
 end
 else
 try
   Button1.Caption := 'Connect';
   IdTCPClient1.Disconnect;
 except
   on E: Exception do Memo1.Lines.Add('BNET Connection Error (part 2): '+E.Message);
 end;
end;

procedure TForm1.IdTCPClient1Connected(Sender: TObject);
begin
 Memo1.Lines.Add('[BNET Connected]');
 Button1.Caption := 'Disconnect';
 tr1 := TBNETReadThread.Create(IdTCPClient1);
end;

procedure TForm1.IdTCPClient2Connected(Sender: TObject);
begin
 Memo1.Lines.Add('[BNLS Connected]');
 tr2 := TBNLSReadThread.Create(IdTCPClient2);
end;


procedure TForm1.IdTCPClient1Disconnected(Sender: TObject);
begin
 if IdTCPClient1.ClosedGracefully then
   Memo1.Lines.Add('[BNET Disconnected gracefully]')
 else
   Memo1.Lines.Add('[BNET Disconnected abruptly]');
 tr1.Free;
 Button1.Caption := 'Connect';
end;

procedure TForm1.IdTCPClient2Disconnected(Sender: TObject);
begin
 if IdTCPClient2.ClosedGracefully then
   Memo1.Lines.Add('[BNLS Disconnected gracefully]')
 else
   Memo1.Lines.Add('[BNLS Disconnected abruptly]');
 tr2.Free;
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
 if (key = #13) then
 begin
//    IdTCPClient1.Write(Edit1.Text);
 end;
end;
end.