Valhalla Legends Forums Archive | Battle.net Bot Development | udp support

AuthorMessageTime
killer
can anyone give me a general idea of what all i have to do to get udp support working in my bot.

thanks in advance
July 14, 2003, 12:33 AM
Soul Taker
For true UDP support, you must send the UDP pings to Battle.net. To do this, bind a UDP socket to port 6112. Then when you recieve 0x50, send the server hash and the third DWORD from 0x50 as packet 0x09 on the UDP socket. Then, Bnet should send you packet 0x05 to the UDP socket. Take the first DWORD, and send that as packet 0x14 to Bnet (via TCP). That explaination sucks so here's some crappy code:

[code]
sckUDP.Bind 6112 'binds the UDP socket to port 6112

Upon recieving 0x50:
strUDPVal = Mid(strData, 13, 4) 'gets the value to send in the UDP pings
p.InsertDWORD ServerHash
p.InsertDWORD CVL(strUDPVal)
p.SendUDP &H9
p.InsertDWORD ServerHash
p.InsertDWORD CVL(strUDPVal)
p.SendUDP &H9
p.InsertDWORD ServerHash
p.InsertDWORD CVL(strUDPVal)
p.SendUDP &H9 'sends three UDP pings, I'd recommend making sure you actually are still connected to Bnet, cause it seems to not like getting UDP pings when not connected via TCP

Then just grab the DWORD (usually 'bnet', but hardcoding sucks) from 0x05 on the UDP socket, and send:
s.SID_UDPPINGRESPONSE Socket, frmMain.strUDPCheck

And here is the easy layout of that packet:
Public Function SID_UDPPINGRESPONSE(Socket As Integer, strVal As String)
p.InsertNonNTString strVal
p.SendPacket frmMain.sckBnet(Socket), &H14
End Function
[/code]
Hope you can figure that out, I'm kinda tired and not thinking straight right now.
July 14, 2003, 12:46 AM
UserLoser
What about UDP for games, such as Broodwar? Want to share on that? :P
July 14, 2003, 3:15 AM
killer
thanks for the info and is there any importent info i should know about in-game support?


EDIT-userloser posted the same reply 2 seconds befor me lol
July 14, 2003, 3:15 AM
UserLoser
I've got a start, never very far though. You need a UDP checksum formula.
July 14, 2003, 3:23 AM
Spht
[quote author=UserLoser link=board=17;threadid=1900;start=0#msg14734 date=1058153021]
I've got a start, never very far though. Apparently, you need some UDP checksum algorithm or something.
[/quote]

Such checksum is computed from Storm.dll. Enjoy.
July 14, 2003, 4:24 PM
Lenny
What ways are available not for "true" udp support but just avoiding that plug?...
August 14, 2003, 7:06 AM
Camel
[quote author=Lenny link=board=17;threadid=1900;start=0#msg18055 date=1060844771]
What ways are available not for "true" udp support but just avoiding that plug?...
[/quote]

The idea of requiring the client to connect via UDP and get the 'bnet' code is to prove that it really has udp support and isn't just faking it. Fortunately for the lazy among us, Blizzard has never to my knowledge changed the value -- it has always been 'bnet'. For that reason, it is probably safe to assume it will always be 'bnet' and you can send that value in 0x14 without connecting to battle.net via UDP.

[edit] 'bnet' not 'BNET'; my memory sucks.
August 14, 2003, 7:35 AM
Skywing
[quote author=Camel link=board=17;threadid=1900;start=0#msg18060 date=1060846517]
[quote author=Lenny link=board=17;threadid=1900;start=0#msg18055 date=1060844771]
What ways are available not for "true" udp support but just avoiding that plug?...
[/quote]

The idea of requiring the client to connect via UDP and get the 'BNET' code is to prove that it really has udp support and isn't just faking it. Fortunately for the lazy among us, Blizzard has never to my knowledge changed the value -- it has always been 'BNET'. For that reason, it is probably safe to assume it will always be 'BNET' and you can send that value in 0x14 without connecting to battle.net via UDP.
[/quote]
It might be a good idea to note that the value is actually 'bnet' and not 'BNET'.
August 14, 2003, 2:44 PM
FuZe
If you are on starcraft, I think starcraft binds to port 6112, so you cant send UDP packets on that port, but it doesn't really matter if you only want to get the plug.
August 14, 2003, 8:56 PM
TeamProx
UDP can bind to port 6112 while TCP is already bound to port 6112. This is because they are different network protocols, so sending and receiving data on UDP:6112 won't be sent and received from TCP:6112. However, under normal circumstances, you shouldn't be able to bind to port 6112 multiple times with the same protocol, without unbinding the previously-bound socket.
August 15, 2003, 1:09 AM
tA-Kane
[quote author=FuZe- link=board=17;threadid=1900;start=0#msg18100 date=1060894569]If you are on starcraft, I think starcraft binds to port 6112, so you cant send UDP packets on that port, but it doesn't really matter if you only want to get the plug.[/quote]Not sure about the Windows versions, but on the Mac, if UDP port 6112 is already taken, then StarCraft (and presumably the other games) increment the port number and try to bind again. I know this because I've had two copies of StarCraft playing in a game, one was bound to port 6112 and the other on 6113.

If StarCraft had given up if it couldn't get 6112, then the second client would not have been able to play (and would have even likely reported no UDP to the server when connecting).
August 15, 2003, 1:16 AM
Skywing
You can actually share port 6112 with Starcraft - it doesn't work perfectly, but it does (mostly) work. See SO_REUSEADDR and setsockopt.

You can set the game to use a specific UDP port by setting a REG_DWORD named Game Data Port in HKEY_CURRENT_USER\Software\Battle.net\Configuration.
August 15, 2003, 1:30 AM
TeamProx
[quote author=Skywing link=board=17;threadid=1900;start=0#msg18138 date=1060911012]
You can actually share port 6112 with Starcraft[/quote]How does this occur? Do both sockets receive the data? According to MSDN, what occurs when multiple sockets are bound to the same port is "undefined as to which port will receive packets."... personally, I wouldn't trust it to work in all versions of Windows, just because you've had luck with it.
August 15, 2003, 2:02 AM
Skywing
[quote author=TeamProx link=board=17;threadid=1900;start=0#msg18141 date=1060912931]
[quote author=Skywing link=board=17;threadid=1900;start=0#msg18138 date=1060911012]
You can actually share port 6112 with Starcraft[/quote]How does this occur? Do both sockets receive the data? According to MSDN, what occurs when multiple sockets are bound to the same port is "undefined as to which port will receive packets."... personally, I wouldn't trust it to work in all versions of Windows, just because you've had luck with it.
[/quote]
It sounded like what people wanted to do was send and not receive with that --- which works fine in my experience.

Of course, a much better solution is to let the operating system pick an unused port for you and use the port selection messages to tell Battle.net that you're using that port and not 6112. To observe this, set REG_DWORD Game Data Port in HKEY_CURRENT_USER\Software\Battle.net\Configuration.
August 15, 2003, 2:29 PM

Search