Valhalla Legends Forums Archive | Battle.net Bot Development | [VB][Closed-unsolved] Socket error... Still unsolved.

AuthorMessageTime
LockesRabb
The name of my winsock is BNET, and usually the packetbuffer class will call it as DMBot.BNET since it's in the DMBot form. There's a public string variable called bnetserver, which contains the server address. In the entire program, that variable is only assigned a value ONCE-- and it's hardcoded to "asia.battle.net".

With that much said, check this output from my bot out- very unusual...

[quote]DementedBot activated at [9/12/2005 4:07:27 PM] .
Loading configuration...
Username: Kyro[DM]
Password: ********
CDKey: **************
Client: Starcraft: Brood War
Client VerByte: CD
BNET Server: asia.battle.net
BNET Port: 6112
BNET Default Channel: op Kyro[DM]
Config loaded.
Connecting to port 6112 at the asia.battle.net server...
Connected!
Initating packetage...
Notifying server of emulation...
0x01 protocol packet sent.
Server notification done.
Assembling 0x50 Protocol packet...
0x50 SID_AUTH_INFO packet sent.
BNET: Ping?
Assembling 0x25 SID_PING Packet...
0x25 SID_PING packet sent.
DMBot: Pong!
BNET: Gimme your cdkey.
Assembling 0x51 SID_AUTH_CHECK Packet...
0x51 SID_AUTH_CHECK packet sent.
DMBot: Blah blah. There ya go. Happy?
BNET: Well...
BNET: Fine, I'll accept that...
BNET: But dude, who the heck are you?
Assembling 0x29 SID_LOGONRESPONSE Packet...
0x29 SID_LOGONRESPONSE packet sent.
DMBot: LOL! Well dude, I'm Kyro[DM]...
BNET: Uhhh...
BNET: Oh yea, I know you! Cool, welcome to BNET!
Assembling 0x14 SID_UDPPINGRESPONSE Packet...
0x14 SID_UDPPINGRESPONSE packet sent.
Assembling 0x0A SID_ENTERCHAT Packet...
Dumping packet [which was attempted to be sent]...

StrToHex Dump:
FF 0A 0F 00 4B 79 72 6F 5B 44 4D 5D 00 30 00

End of packet dump.
Fatal error. SOCKET value = asia.battle.net, PacketID Value =  10
Connection aborted locally.[/quote]

As you can see, somehow, the SOCKET value was assigned to asia.battle.net, which is biazzre; I say biazzre, because when the SendPacket function is called, it's always called as:

.SendPacket DMBot.BNET, &H29         'Where &H29 is the packet id, cld be 0x0A, 0x0B, they all result in same error

Since the hexdump showed that it was the 0x0A function, I checked it, but it looks fine:

[code]'SID_ENTERCHAT
Private Sub P0x0A()
    AddC vbWhite, "Assembling 0x0A SID_ENTERCHAT Packet..."
    With PacketBuf
        .InsertNTString bnetusername
        .InsertNTString &H0         'Null, CDKeyed product.
        .SendPacket DMBot.BNET, &HA
    End With
    AddC vbWhite, "0x14 SID_ENTERCHAT packet sent."
End Sub[/code]

As you can see, it's passing the exact name, not the server name, in that function. Also, here's the SendPacket function:

[code]Public Function SendPacket(SOCKET As Winsock, PacketID As Byte)
    On Error GoTo HexDump
    SOCKET.SendData Chr(&HFF)
    SOCKET.SendData Chr(PacketID)
    SOCKET.SendData MakeWORD(Len(Buffer) + 4)
    SOCKET.SendData Buffer
    Clear
    Exit Function
HexDump:
    DumpPacket (Chr(&HFF) & Chr(PacketID) & MakeWORD(Len(Buffer) + 4) & Buffer)
    AddC vbRed, "Fatal error. SOCKET value = " & SOCKET & ", PacketID Value =  " & PacketID
    Clear
    AddC vbRed, "Connection aborted locally."
    DMBot.BNET.Close
    Call DMBot.BNET_Close
End Function[/code]

The DMBot.BNET parts in the SendPacket function were originally SOCKET, but I changed it to DMBot.BNET for troubleshooting purposes...

What I can't see is, now how in the heck did "asia.battle.net" get somehow passed to the SendPacket function as the socket, if the bnetserver variable was never once used in conjunction with SendPacket? I checked the entire program- nowhere is it used in conjunction-- the only time that var is actually used is when first connecting to it using the following code:

[code]BNET.Connect bnetserver, bnetport[/code]

In the Form_Load() sub, bnetserver is assigned the string of "asia.battle.net" and bnetport is assigned the value of 6112. In the entire programs, both vars are only used twice: once to assign value, and once to get winsock to connect to server.

I'm confused like heck, as this seems very unusual and biazzre behavior...

Inputs would be very much appreciated...
September 12, 2005, 11:25 PM
HdxBmx27
Well, theres nothing wrong, your jsut not using SOCKET correctly -.-
You should NEVER use an object w/o adding a property.
w/o a property, It defults to .Remotehost I beleave. Thats why it does that.
~-~(HDX)~-~
September 12, 2005, 11:48 PM
LockesRabb
How do I prevent it from defaulting then? I mean, how am I not using SOCKET correctly? That function (before I added in the error handling code) is from Dark Minion's PacketBuffer class... This is driving me insane lol... If I hardcode the name of the socket, the bot works perfectly, but if I use SOCKET as a winsock object, and identify the socket by doing DMBOT.BNET, the program literally vomits >.<

[Edit: new info, edited to avoid double-posting.]

I just replaced all instances of SOCKET with DMBot.BNET, and changed all .SendPacket 's to only pass the packet ID. Insanely, it still errors out in that function. The error is a runtime error #6...

>.<
September 12, 2005, 11:54 PM
l2k-Shadow
[code]
'SID_ENTERCHAT
Private Sub P0x0A()
    AddC vbWhite, "Assembling 0x0A SID_ENTERCHAT Packet..."
    With PacketBuf
        .InsertNTString bnetusername
        .InsertNTString &H0        'Null, CDKeyed product.
        .SendPacket DMBot.BNET, &HA
    End With
    AddC vbWhite, "0x14 SID_ENTERCHAT packet sent."
End Sub
[/code]

[code]
        .InsertNTString &H0        'Null, CDKeyed product.
[/code]

I believe you are trying to assign an INTEGER arguement to a function to which you should assign a STRING arguement.

Why don't we try:
[code]
        .InsertNTString vbNullString        'Null, CDKeyed product.
[/code]

Now don't we just feel stupid?  ;)

EDIT:
[quote]
Assembling 0x29 SID_LOGONRESPONSE Packet...
0x29 SID_LOGONRESPONSE packet sent.
DMBot: LOL! Well dude, I'm Kyro[DM]...
BNET: Uhhh...
BNET: Oh yea, I know you! Cool, welcome to BNET!
Assembling 0x14 SID_UDPPINGRESPONSE Packet...
0x14 SID_UDPPINGRESPONSE packet sent.
Assembling 0x0A SID_ENTERCHAT Packet...
[/quote]
I also see you are sending the 0x14 packet after 0x29... the client sends 0x14 and then 0x29.

September 13, 2005, 3:14 AM
LockesRabb
Yes, I felt very foolish when you showed I was trying to cram a number into a string >.< Thanks tho, I did feel extremely stupid- I actually knocked myself in the head with my shoe...

As for the 14 before 29, are you sure? I thought I was supposed to send the ping AFTER login?

[Edited to avoid double posting]

Well, I fixed that integer into ntstring bug... Still the same. Here's the output:

[quote]DementedBot activated at [9/12/2005 9:02:40 PM] .
Loading configuration...
Username: Kyro[DM]
Password: ********
CDKey: **************
Client: Starcraft: Brood War
Client VerByte: CD
BNET Server: asia.battle.net
BNET Port: 6112
BNET Default Channel: op Kyro[DM]
Config loaded.
Connecting to port 6112 at the asia.battle.net server...
Connected!
Initating packetage...
Notifying server of emulation...
0x01 protocol packet sent.
Server notification done.
Assembling 0x50 Protocol packet...
0x50 SID_AUTH_INFO packet sent.
BNET: Ping?
Assembling 0x25 SID_PING Packet...
0x25 SID_PING packet sent.
DMBot: Pong!
BNET: Gimme your cdkey.
Assembling 0x51 SID_AUTH_CHECK Packet...
0x51 SID_AUTH_CHECK packet sent.
DMBot: Blah blah. There ya go. Happy?
BNET: Well...
BNET: Fine, I'll accept that...
BNET: But dude, who the heck are you?
Assembling 0x14 SID_UDPPINGRESPONSE Packet...
0x14 SID_UDPPINGRESPONSE packet sent.
Assembling 0x29 SID_LOGONRESPONSE Packet...
0x29 SID_LOGONRESPONSE packet sent.
DMBot: LOL! Well dude, I'm Kyro[DM]...
BNET: Uhhh...
BNET: Oh yea, I know you! Cool, welcome to BNET!
Assembling 0x0A SID_ENTERCHAT Packet...
Runtime Error #6, Overflow. Fatal error, connection terminated.
Server aborted connection!
Dumping packet...

StrToHex Dump:
FF 0A 0E 00 4B 79 72 6F 5B 44 4D 5D 00 00
HexToString Dump:


End of packet dump.
0x14 SID_ENTERCHAT packet sent.
Assembling 0x0B SID_GETCHANNELLIST Packet...
Runtime Error #6, Overflow. Fatal error, connection terminated.
Server aborted connection!
Dumping packet...

StrToHex Dump:
FF 0B 12 00 4B 79 72 6F 5B 44 4D 5D 00 00 50 58 45 53
HexToString Dump:
 
End of packet dump.[/quote]

This is the code for battlenet.bas which contains the parser, 0x0A, 0x0B, 0x0C, etc packet codes:

BattleNet.bas

This is the SendPacket function:

[code]Public Function SendPacket(SOCKET As Winsock, PacketID As Byte)
    On Error GoTo DumpHex
    SOCKET.SendData Chr$(&HFF)
    SOCKET.SendData Chr$(PacketID)
    SOCKET.SendData MakeWORD(Len(Buffer) + 4)
    SOCKET.SendData Buffer
    Clear
    Exit Function
DumpHex:
    DMBot.BNET.Close
    AddC vbRed, "Runtime Error #6, Overflow. Fatal error, connection terminated."
    Call DMBot.BNET_Close
    DumpPacket (Chr$(&HFF) & Chr$(PacketID) & MakeWORD(Len(Buffer) + 4) & Buffer)
End Function[/code]

The code also makes use of BNCSUtil.bas, if you need to see that code, let me know and I'll post a link to it as well. In fact, I'll post that one too, just in case:

BNCSUtil.bas

Man, I'm soooo confused as to what I did wrong, it was working great, I must have screwed it up somehow somewhere... It's only when it its the 0x0A packet that the errors pile up... I mean, a runtime error 6 buffer overflow?!? >.<

Thanks for your help, it's definitely appreciated-- I'm seriously hoping you'll be able to see whatever stupid ol' me missed! :p
September 13, 2005, 3:46 AM
l2k-Shadow
[quote author=Kyro link=topic=12790.msg127948#msg127948 date=1126583168]
Yes, I felt very foolish when you showed I was trying to cram a number into a string >.< Thanks tho, I did feel extremely stupid- I actually knocked myself in the head with my shoe...

As for the 14 before 29, are you sure? I thought I was supposed to send the ping AFTER login?
[/quote]

EEK... 0x14 [SIZE=7]IS NOT[/SIZE] the ping. 0x14 is to tell the server if your connection can accept UDP connections on port 6112, hence it's only used by STAR, SEXP, and W2BN.  If you respond to the packet with the DWORD value 0x626E6574, it tells Battle.net you may process the UDP packets, if you ignore this packet and don't respond to it... Battle.net will think you cannot process the UDP packets and give you the "lag plug".  And yes I'm sure you send 0x14 before 0x29, feel free to packet log the client.
September 13, 2005, 4:06 AM
LockesRabb
Alright, thanks for that info, I updated code to reflect that procedure. I also edited my previous post to show new code, as well posted a link to both BAS files...
September 13, 2005, 4:12 AM
l2k-Shadow
I don't know, the code seems fine. Try using this buffer//debuffer class, it might work better for you... Meh... that's all I can suggest, I don't see what could cause overflows, but give it a shot and see.
September 13, 2005, 5:03 AM
LockesRabb
Works perfectly- I compared your class with my class, and replaced the MakeWord line with:

SOCKET.SendData MakeMemory(Len(Buffer) + 4, pWORD)

And also copied over the MakeMemory function, as well as the pWORD definition. That solved the problem- the code executes perfectly now. Thanks!

Next up, figure out why it says op Kyro[DM] is restricted... Wish me luck! Thanks again for helping me to solve this!

Here's the output now:

[quote]DementedBot activated at [9/12/2005 11:47:06 PM] .
Loading configuration...
Username: Kyro[DM]
Password: ********
CDKey: **************
Client: Starcraft: Brood War
Client VerByte: CD
BNET Server: asia.battle.net
BNET Port: 6112
BNET Default Channel: op Kyro[DM]
Config loaded.
Connecting to port 6112 at the asia.battle.net server...
Connected!
Initating packetage...
Notifying server of emulation...
0x01 protocol packet sent.
Server notification done.
Assembling 0x50 Protocol packet...
0x50 SID_AUTH_INFO packet sent.
BNET: Ping?
Assembling 0x25 SID_PING Packet...
0x25 SID_PING packet sent.
DMBot: Pong!
BNET: Gimme your cdkey.
Assembling 0x51 SID_AUTH_CHECK Packet...
0x51 SID_AUTH_CHECK packet sent.
DMBot: Blah blah. There ya go. Happy?
BNET: Well...
BNET: Fine, I'll accept that...
BNET: But dude, who the heck are you?
Assembling 0x14 SID_UDPPINGRESPONSE Packet...
0x14 SID_UDPPINGRESPONSE packet sent.
Assembling 0x29 SID_LOGONRESPONSE Packet...
0x29 SID_LOGONRESPONSE packet sent.
DMBot: LOL! Well dude, I'm Kyro[DM]...
BNET: Uhhh...
BNET: Oh yea, I know you! Cool, welcome to BNET!
Assembling 0x0A SID_ENTERCHAT Packet...
0x14 SID_ENTERCHAT packet sent.
Assembling 0x0C SID_JOINCHANNEL Packet...
0x0C SID_JOINCHANNEL packet sent.
DMBot: By the way, I know my ABC's!!! :D
BNET: Cool! So do I! Anyway, welcome to BNET! :D
DMBot: Channel op Kyro[DM] is restricted.
BNET: Ping?
Assembling 0x25 SID_PING Packet...
0x25 SID_PING packet sent.
DMBot: Pong!
BNET: Ping?
Assembling 0x25 SID_PING Packet...
0x25 SID_PING packet sent.
DMBot: Pong![/quote]
September 13, 2005, 6:50 AM
LockesRabb
[Edit: My apologies for double post! Forgot >.<]

Bot just hit overflow AGAIN. It seems to work sometimes, and sometimes it won't. I just got ipbanned from asia.battle.net while trying to figure out problem...

Check this out:

[quote]DementedBot activated at [9/13/2005 12:01:44 AM] .
Loading configuration...
Username: Kyro[DM]
Password: ********
CDKey: **************
Client: Starcraft: Brood War
Client VerByte: CD
BNET Server: europe.battle.net
BNET Port: 6112
BNET Default Channel: op Kyro[DM]
Config loaded.
Connecting to port 6112 at the europe.battle.net server...
Connected!
Initating packetage...
Notifying server of emulation...
0x01 protocol packet sent.
Server notification done.
Assembling 0x50 Protocol packet...
0x50 SID_AUTH_INFO packet sent.
BNET: Ping?
Assembling 0x25 SID_PING Packet...
0x25 SID_PING packet sent.
DMBot: Pong!
BNET: Gimme your cdkey.
Assembling 0x51 SID_AUTH_CHECK Packet...
0x51 SID_AUTH_CHECK packet sent.
DMBot: Blah blah. There ya go. Happy?
BNET: Well...
BNET: Fine, I'll accept that...
BNET: But dude, who the heck are you?
Assembling 0x14 SID_UDPPINGRESPONSE Packet...
0x14 SID_UDPPINGRESPONSE packet sent.
Assembling 0x29 SID_LOGONRESPONSE Packet...
0x29 SID_LOGONRESPONSE packet sent.
DMBot: LOL! Well dude, I'm Kyro[DM]...
BNET: Uhhh...
BNET: Oh yea, I know you! Cool, welcome to BNET!
Assembling 0x0A SID_ENTERCHAT Packet...
Runtime Error #6, Overflow. Fatal error, connection terminated.
Server aborted connection!
Dumping packet...

StrToHex Dump:
FF 0A 0E 00 4B 79 72 6F 5B 44 4D 5D 00 00
HexToString Dump:


End of packet dump.
0x14 SID_ENTERCHAT packet sent.
Assembling 0x0C SID_JOINCHANNEL Packet...
Runtime Error #6, Overflow. Fatal error, connection terminated.
Server aborted connection!
Dumping packet...

StrToHex Dump:
FF 0C 1E 00 4B 79 72 6F 5B 44 4D 5D 00 00 00 00 00 00 6F 70 20 4B 79 72 6F 5B 44 4D 5D 00
HexToString Dump:
 
End of packet dump.
0x0C SID_JOINCHANNEL packet sent.
DMBot: By the way, I know my ABC's!!! :D[/quote]

I also posted the PacketBuffer class I'm using-- it's at:

PacketBuffer.cls

Any ideas?
September 13, 2005, 7:06 AM
l2k-Shadow
[code]
Private Sub P0x0C(TypeOfJoin As Long, ChanToJoin As String)
    Dim FakeVAr As Long
    FakeVAr = 123
    AddC vbWhite, "Assembling 0x0C SID_JOINCHANNEL Packet..."
    With PacketBuf
        .InsertDWORD TypeOfJoin
        .InsertNTString ChanToJoin  'Channel to join
        .SendPacket DMBot.BNET, &HC
    End With
    AddC vbWhite, "0x0C SID_JOINCHANNEL packet sent."
    DoEvents
End Sub
[/code]

What is your TypeOfJoin variable set to?
September 13, 2005, 1:31 PM
LockesRabb
That sub is called as:

P0x0C &H0, bnetmainchannel

bnetmainchannel is a string variable, and it is set to "op Kyro[DM]" at form load time. When I get back from class today, I'm going to see if I can find anything else different in my packet buffer class with your packet buffer class. I'm running out of ideas as to what's wrong with the bot.
September 13, 2005, 2:06 PM
l2k-Shadow
Try
P0x0C &H2, bnetmainchannel
September 13, 2005, 10:30 PM
LockesRabb
it isn't erroring at the join packet- it's erroring at the enter chat packet, sometimes the join chat packet, sometimes the 0x51 packet... error's the same at all three-- winsock buffer overflow.

in any case, i tried the suggested change, no difference.
September 13, 2005, 11:23 PM
l2k-Shadow
[code]
Public Function SendPacket(SOCKET As Winsock, PacketID As Byte)
    On Error GoTo DumpHex
    SOCKET.SendData Chr$(&HFF)
    SOCKET.SendData Chr$(PacketID)
    SOCKET.SendData MakeWORD(Len(Buffer) + 4)
    SOCKET.SendData Buffer
    Clear
    Exit Function
DumpHex:
    DMBot.BNET.Close
    AddC vbRed, "Runtime Error #6, Overflow. Fatal error, connection terminated."
    Call DMBot.BNET_Close
    DumpPacket (Chr$(&HFF) & Chr$(PacketID) & MakeWORD(Len(Buffer) + 4) & Buffer)
End Function
[/code]

ugh... try...

[code]
Public Function SendPacket(SOCKET As Winsock, PacketID As Byte)
    SOCKET.SendData Chr(&HFF) & Chr(PacketID) & MakeWORD(Len(Buffer) + 4) & Buffer
    Clear
End Function
[/code]
September 13, 2005, 11:49 PM
rabbit
On a side note, your error handler assumes that RTE 6 is the only error your program can encounter in that routine, but it's not.  Also, right before "Exit Function" you should have "On Error GoTo 0".
September 14, 2005, 12:31 AM
LockesRabb
@l2k-Shadow, tried what you suggested-- no difference, still overflows-- but here's something interesting- if I execute the program when I first open VB, no overflow occurs. HOWEVER, if I click disconnect, then click connect, it overflows when sending 0x51. Interesting stuff. Still driving me crazy like usual, lol.

Instead of trying to describe stuff, I decided to just zip up my source code, and make it available for download so you can check it out directly. Maybe it's computer specific? Maybe it overflows on my laptop, but works fine for other computers?

Anyway, here's the source:

DMBot.zip

Keep in mind it's my first binary bot, so if the code looks horrible, my apologies! lol...

If you'd take a gander at it, I'd be immensely grateful! :) No need to fix the code for me, if you see the problem, feel free to let me know and I'll see if I can figure out how to solve it... I owe you guys on vL alot- I've learned so much about botmaking, not enough, but still alot. 

@Rabbit-- yeah, I just put that there because that's the only error that occurs with the SendPacket sub-- but you do have a point. So I re-coded the error handler, and added some stuff to the sub:

[code]Public Function SendPacket(sck As Winsock, PacketID As Long, Optional PacketFormat As pPacketFormat = pBNET) As Boolean
    On Error GoTo DumpHex
    'Returns TRUE if packet was successfully sent. FALSE if not.
    If BNETSendComplete = False Then
        AddC vbRed, "Winsocket not available to send yet, please wait a moment..."
        Do
            DoEvents
        Loop Until BNETSendComplete = True
        AddC vbGreen, "Alright, it's open. Sending packet..."
    End If
    If sck.State = sckConnected Then
        'sck.SendData Chr(&HFF) & Chr(PacketID) & MakeMemory(Len(Buffer) + 4, pWORD) & Buffer
        sck.SendData Chr(&HFF) & Chr(PacketID) & MakeWORD(Len(Buffer) + 4) & Buffer
        SendPacket = True
    End If
    Clear
    On Error GoTo 0
    BNETSendComplete = False
    Exit Function
DumpHex:
    DMBot.BNET.Close
    AddC vbRed, " -- Error " & Err.Number & " (" & Err.Description & ") in procedure SendPacket in PacketBuffer class."
    Call DMBot.BNET_Close
    DumpPacket (Chr$(&HFF) & Chr$(PacketID) & MakeMemory(Len(Buffer) + 4, pWORD) & Buffer)
    Clear
End Function[/code]

Thanks for being so patient with me and my amateurish botmaking skills. :)

[Edited to avoid double posting]

Also, when you open the bot in vb, you'll need to put in your own login and cdkey, I removed mine for obvious reasons before zipping it up to upload. And the bot provides no way to set up the cdkey/login, it'll have to be done manually by setting the vars inside the Form_Load sub in DMBot.frm...
September 14, 2005, 6:34 PM

Search