Valhalla Legends Forums Archive | Battle.net Bot Development | 0x50 with C# Problem

AuthorMessageTime
PhoeNix_FasT
Im new to C# (learning it for 2 Month now) and i tried the simpliest thing : Sending 0x50 and receive an answer.
For this i use MBNCSUtil ( using MBNCSUtil; )
This is what i wrote

            IPHostEntry ip = Dns.GetHostByName("useast.battle.net");
            IPAddress[] ips = ip.AddressList;
            IPAddress battleNetIP = ips[0];

            richTextBox1.AppendText("Address of useast.battle.net : " + battleNetIP + "\n");

            m_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint ipEnd = new IPEndPoint(battleNetIP, battleNetPort);
            try
            {
                m_clientSocket.Connect(ipEnd);
            }
            catch (Exception exp)
            {
                richTextBox1.AppendText("Exception : " + exp.Message + "\n");
                return;
            }

            if(m_clientSocket.Connected)
                richTextBox1.AppendText("Connected\n");

            BncsPacket pck0x50 = new BncsPacket((byte)0x50);
            pck0x50.InsertInt32(0);           
            pck0x50.InsertDwordString("IX86"); 
            pck0x50.InsertDwordString("D2XP"); 
            pck0x50.InsertInt32(0);           
            pck0x50.InsertInt32(0);           
            pck0x50.InsertInt32(0);           
            pck0x50.InsertInt32(0);           
            pck0x50.InsertInt32(0);           
            pck0x50.InsertDwordString("", 0); 
            pck0x50.InsertCString("USA");     
            pck0x50.InsertCString("United States");

            byte[] byteData = new byte[32];

            try
            {
                m_clientSocket.Send(pck0x50.GetData(), SocketFlags.None); 
            }

            catch (Exception exp)
            {
                richTextBox1.AppendText("Exception : " + exp.Message + "\n");
                return;
            }

            int i = m_clientSocket.Receive(byteData);
            richTextBox1.AppendText("Bytes Received :" + i + "\n");

Its my first time i try to use Sockets in C#. Anyways .. i = 0, means i received 0 bytes.
What did i do wrong ?
August 15, 2007, 6:10 PM
BreW
Did you send the 0x01 protocol byte first? And I'm assuming pck0x50.InsertDwordString("D2XP"); 
reverses and concatinates "D2XP" to the buffer, amirite? Not to mention you're missing the verbyte dword (comes right after the client id) Also .... er... "pck0x50.InsertInt32(0);           
            pck0x50.InsertDwordString("", 0);  " Are you sure you have the basic format of the 0x50 packet down?
August 15, 2007, 6:35 PM
PhoeNix_FasT
0x01 ? Sorry didnt find that
I had a look right here : http://ersan.us/src/bnetdocs/sequence.html

it says:

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

So would it be enough with

BncsPacket pck0x01 = new BncsPacket((byte)0x01);

and then send this packet ?
August 15, 2007, 7:50 PM
HdxBmx27
No, its not a packet, its jsut a raw byte, i assume your packetbuffer adds the header info (0xff id length)
Which you wont need for the protocol byte.
As he also said, you're missing the version byte in your 0x50 build, fix that.
~Hdx
August 15, 2007, 8:04 PM
PhoeNix_FasT
            BncsPacket pck0x50 = new BncsPacket((byte)0x50);
            pck0x50.InsertInt32(0);           
            pck0x50.InsertDwordString("IX86"); 
            pck0x50.InsertDwordString("D2XP");
            pck0x50.InsertByte(0x0A);           
            pck0x50.InsertInt32(0);           
            pck0x50.InsertInt32(0);           
            pck0x50.InsertInt32(0);           
            pck0x50.InsertInt32(0);           
            pck0x50.InsertDwordString("", 0); 
            pck0x50.InsertCString("USA");     
            pck0x50.InsertCString("United States");

            byte[] byteData = new byte[511];

            try
            {
                m_clientSocket.Send(pck0x50.GetData(), SocketFlags.None);
                richTextBox1.AppendText("Sending 0x50\n");
            }

            catch (Exception exp)
            {
                richTextBox1.AppendText("Exception : " + exp.Message + "\n");
                return;
            }

            int i = m_clientSocket.Receive(byteData);
            richTextBox1.AppendText("Bytes Received :" + i + "\n");


i is still 0 ..  >:(
August 15, 2007, 8:39 PM
HdxBmx27
Where are you sending the protocol byte?
And the verbyte ix 0x0b...
~Hdx
August 15, 2007, 8:43 PM
BreW
Also not to mention that the verbyte is a dword, not a single byte. (see: "Not to mention you're missing the verbyte dword")
are you checking for FD_CLOSE on data arrival? And also checking WSAGetLastError()?
August 15, 2007, 9:31 PM
PhoeNix_FasT
Ok... i dont give up  :-\
So i updated the 0x50 Packet.
iRes = 58 Bytes (ok seems the packet reached the server)
i still = 0

to brew : FD_CLOSE and WSAGetLastError() is C++ not C#

Here's my Code now

            IPHostEntry ip = Dns.GetHostByName("useast.battle.net");
            IPAddress[] ips = ip.AddressList;
            IPAddress battleNetIP = ips[0];

            m_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint ipEnd = new IPEndPoint(battleNetIP, battleNetPort);
            m_clientSocket.Connect(ipEnd);

            BncsPacket pck0x50 = new BncsPacket((byte)0x50);
            pck0x50.InsertDwordString("0");          // (DWORD) Protocol ID (0)         
            pck0x50.InsertDwordString("IX86");      // (DWORD) Platform ID
            pck0x50.InsertDwordString("D2XP");      // (DWORD) Product ID
            pck0x50.InsertDwordString("0x0b");      // (DWORD) Version Byte
            pck0x50.InsertDwordString("");          // (DWORD) Product language
            pck0x50.InsertDwordString("");          // (DWORD) Local IP for NAT compatibility
            pck0x50.InsertDwordString("");          // (DWORD) Time zone bias
            pck0x50.InsertDwordString("");          // (DWORD) Locale ID           
            pck0x50.InsertDwordString("");          // (DWORD) Language ID
            pck0x50.InsertCString("USA");          // (STRING) Country abreviation   
            pck0x50.InsertCString("United States"); // (STRING) Country

            byte[] byteData = new byte[511];

            try
            {
                int iRes = m_clientSocket.Send(pck0x50.GetData(), SocketFlags.None);
                richTextBox1.AppendText("0x50 : " + iRes + " Bytes sent\n");
            }

            catch (Exception exp)
            {
                richTextBox1.AppendText("Exception : " + exp.Message + "\n");
                return;
            }

            int i = m_clientSocket.Receive(byteData);
            richTextBox1.AppendText("Bytes Received : " + i + "\n");

EDIT : Is it better to use Network Stream instead of this what i am doing here ?
August 15, 2007, 9:59 PM
HdxBmx27
-.-
The verbyte is a dword, not literally "0x0b"
it's actually "\xb\x0\x0\x0"
Also, where is the protocol byte!
I see the protocol version, but not the byte, directly after you create the connection, send a single byte 0x01
Why the HELL are you inserting them all as 'DwordStrings' there is no such thing.
~Hdx
August 15, 2007, 10:03 PM
BreW
Hdx, I think he knows that. Eh... Post us your insert dword string function maybe it's a problem with that? And how do you check for winsock errors in C#, by now if you've made that many errors in your code you probably have gotten ipbanned. But yeah, you still have to send that raw 0x01 byte to battle.net first before sending the 0x50 packet.
August 15, 2007, 10:23 PM
HdxBmx27
Naw, he doesn't know jack, he just PMed me with a bunch of bull, He needs to learn the basics of data handling in his language before he attempts to make a bot.
He still thinks he should use his packetbuffer for the protocol byte after we have all explained to him several times that its just one raw byte to be sent over to connection before anything else.
int i = clientSocket.send("\x1", SocketFlags.None);
How hard is that to comprehend?
~Hdx
August 15, 2007, 10:27 PM
BreW
Guess so, hdx. I'm glad we have this problem solved.
August 15, 2007, 10:56 PM
Myndfyr
[quote author=Hdx link=topic=16949.msg171623#msg171623 date=1187216833]
Naw, he doesn't know jack, he just PMed me with a bunch of bull, He needs to learn the basics of data handling in his language before he attempts to make a bot.
He still thinks he should use his packetbuffer for the protocol byte after we have all explained to him several times that its just one raw byte to be sent over to connection before anything else.
int i = clientSocket.send("\x1", SocketFlags.None);
How hard is that to comprehend?
~Hdx
[/quote]
Aside from not being C# or .NET-compliant, not too hard, since there's no overload that accepts (String, SocketFlags) in the parameter list.

[code]if (clientSocket.Send(new byte[] { 1 }) != 1)[/code] might be an interesting code concept.

[quote author=Hdx link=topic=16949.msg171620#msg171620 date=1187215432]
Why the HELL are you inserting them all as 'DwordStrings' there is no such thing.
[/quote]
As the documentation states:
[quote]
This method inserts a string with the maximum length of 4 into the buffer, reversed. This mimics the C-style declarations of 4-character integer literals:

[pre]unsigned long int star_product = 'STAR';[/pre]

which results in [pre]RATS[/pre] being in memory.
[/quote]
August 21, 2007, 7:12 AM
HdxBmx27
Who says he was using jinx's buffer class?
Anyways, Ya I messed up iy should of been a byte[] but I wrote it off the top of my head so meh.
And I still think they should be treated as the dwords they are not '"Dword String" of value "" '
Which sounds better when reading code, that or 'Dword of value 0'
~Hdx
August 21, 2007, 7:29 AM
Myndfyr
[quote author=Hdx link=topic=16949.msg171774#msg171774 date=1187681395]
Who says he was using jinx's buffer class?
[/quote]
He did:
[quote author=PhoeNix_FasT link=topic=16949.msg171606#msg171606 date=1187201449]
For this i use MBNCSUtil ( using MBNCSUtil; )
[/quote]
August 21, 2007, 8:38 AM
HdxBmx27
ah, my bad I haven't really bothered to look at MBNCSutil more hen to fix stupid little problems joe comes  me with.
none the less, Using 'DWordStrings' in this case is just... ya.
I can understand inserting the product/platform ids as such. IF C# dosen't allow for
[code]unsigned long int star_product = 'STAR';[/code]
It would make things simpler, but he should still get into the habbit of using things properly. If he were to use them only use on special occasions where the DWord value would be best represented/understood as a string (product/platform ids, as in BNI files)
And treating everything else as its proper numerical value.
/myopinion
~Hdx
August 21, 2007, 9:24 AM
Myndfyr
The thing is, it's not appropriate to say "InsertProductID" either, because these aren't strictly used for product IDs or platform IDs.  Another example of where they're used is Warcraft III stats.

It's my opinion that code clarity is significantly better when the string literal is present than when you encode the string into a series of bytes or an actual numeric value (which is what I take "treating everything else as its proper numerical value" to mean).  We all find it easier to understand a strings than a series of hex bytes.  Doing it this way also allows your library to black-box any endianness changes that might happen across platforms. 
August 21, 2007, 4:37 PM
Camel
MindFyre, using constants would avoid that problem. I use the numerical values exclusively, but never directly.
[code] public static final int PRODUCT_CHAT = 0x43484154;
public static final int PRODUCT_STAR = 0x53544152;
public static final int PRODUCT_SEXP = 0x53455850;
public static final int PRODUCT_W2BN = 0x5732424E;
public static final int PRODUCT_D2DV = 0x44324456;
public static final int PRODUCT_D2XP = 0x44325850;
public static final int PRODUCT_JSTR = 0x4A535452;
public static final int PRODUCT_WAR3 = 0x57415233;
public static final int PRODUCT_W3XP = 0x57335850;
public static final int PRODUCT_DRTL = 0x4452544C;
public static final int PRODUCT_DSHR = 0x44534852;
public static final int PRODUCT_SSHR = 0x53534852;[/code]
August 21, 2007, 8:13 PM
devcode
People who lack understanding of the language should stfu aka Hdx, fo reel
August 22, 2007, 4:54 PM
HdxBmx27
People who lack common decency, and just like to flame people should fuck off. Namely devcode.
I know enough about the language to make my way, and enough about descent (descent not excellent), to voice my opinion on a public forum of which I have been a member for many years.
~Hdx
August 22, 2007, 5:01 PM

Search