• Welcome to Valhalla Legends Archive.
 

A little help needed...

Started by RedPhoenix, April 15, 2004, 02:00 AM

Previous topic - Next topic

RedPhoenix

#30
This does the conversion for me

Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(msgSend)
Dim stream As NetworkStream = client.GetStream()
stream.Write(data, 0, data.Length)


So I would need the string equivalent of &H0a, which I used
MsgBox(CStr(&H0a))  to get the string.

Private msgStart As String = "255" & "1" & "80" & "0" & "IX86" & "SEXP" & "10" & "0" & "0" & "300" & "0" & "0" & "USA" & "United States"

The above doesn't work, I get no response yet. I've already been IP banned a short length of time.

"255" = &HFF
"80" = &H50

I'm about ready to say heck with it lol.

MyndFyre

Quote from: iago on April 16, 2004, 06:38 PM
He also has some extra chr(0)'s in there.  He has 2 after country code and 2 after country.

Nah, .NET strings don't have a null-terminator byte implicit.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

RedPhoenix

So I need to add Environment.NewLine after each string?

o.OV

im not quite sure how .net works..
but it looks like VB so I'm just gonna make an assumption that strings work the same way.

[ code ]

Private msgStart As String = "255" & "1" & "80" & "0" & "IX86" & "SEXP" & "10" & "0" & "0" & "300" & "0" & "0" & "USA" & "United States"

[ / code ]

wow.. does that work with VB6? heh
perhaps you need to use chr$()


Chr$(255)
If the facts don't fit the theory, change the facts. - Albert Einstein

RedPhoenix

Technically it could, but you would have to figure out how this function actually processes the string conversion.

Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(msgSend)
Dim stream As NetworkStream = client.GetStream()
stream.Write(data, 0, data.Length)

And yes, I've tried using the Chr(255), but I don't need 255 in Chr() form, just string since "255" is 0xFF ~ ( CStr(&HFF) ) Also ( Hex(&HFF).ToString ) will both return "255"

o.OV

#35
Quote from: RedPhoenix on April 16, 2004, 08:07 PM
Technically it could, but you would have to figure out how this function actually processes the string conversion.

Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(msgSend)
Dim stream As NetworkStream = client.GetStream()
stream.Write(data, 0, data.Length)

And yes, I've tried using the Chr(255), but I don't need 255 in Chr() form, just string since "255" is 0xFF ~ ( CStr(&HFF) ) Also ( Hex(&HFF).ToString ) will both return "255"

Well.. ok.. if you are going to express them in plain bytes
why are you using a string? the dwords should be expressed in bytes as well and not as ascii characters
correct? depending on how your class file handles this.
You may want it as a string or a byte form. can't be both like you have right now. can it?
I don't know how .net and your tcp thing works. so I can't give a straight answer.

Add-On:
If you plan on storing the buffer in a string then..
In VB if you have it as "255" then that is three bytes..
50, 53, and 53
so that is why u need Chr$(255) so it is expressed as a single byte and not three.
If the facts don't fit the theory, change the facts. - Albert Einstein

RedPhoenix

That brought up something I thought I check out. Which kinda stumps me right now, I'll have to look into it. But this:

Private msgStart As [String] = Chr(3) & Chr(4) & AccName & vbCrLf & AccPw

Of course works, but how else would you express Chr(3) for the same effect?

'Just an example, I tried various conversions.
Private msgStart As [String] = &H3 & &H4 & AccName & vbCrLf & AccPw

I tried different conversions on Chr(3), just kept returning 3, and no matter how I expressed it. The server did not reckognize it and I couldn't get into the Public Chat channels.

Hex(Chr(3)).ToString
Hex(Asc(Chr(3)).ToString)
Hex(CInt(Chr(3)))

*shrugs*

Which in turn, when send the packet:

Private msgStart As String = Chr(255) & Chr(1) & "80" & "0" & "IX86" & "SEXP" & "10" & "0" & "0" & "300" & "0" & "0" & "USA" & "United States"

Should any of the values be expressed as Chr() as well........

Tuberload

Check out this thread: http://forum.valhallalegends.com/phpbbs/index.php?board=34;action=display;threadid=4547

It is a byte buffer created in Java, but you should be able to convert. If nothing else it should serve as a good reference in creating the packets.
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

iago

hmm, I've made some small changes to that since then.  Ah well, it's close enough.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


RedPhoenix

#39
Update: Here's where I'm at with this. As is, it connects to BNet, and doesn't return a response. Then, if you quit and try it again, you will notice an IO Exception. In other words you just got IP banned for a set length of time. In 3 to 5 minutes you can try again.

In the string I'm sending I almost positive the Chr(1) should start the message. Since Chr(3) started the other for public chat.

0x01 -> Game
0x02 -> Ftp
0x03 -> Chat

I've tried with and without the vbCrLf, and yes Myndfyre, I know about the vbCrLf hehe. Just trying to get somewhere first before I worry about interoperability and structure.


Imports System.Net.Sockets
Imports System.Text
Imports System.Threading

' Form designer generated code

Private client As New TcpClient()
Private strServer As String = "useast.battle.net"
'Private msgStart As [String] = Chr(3) & Chr(4) & AccountName & vbCrLf & AccountPassword

Private msgStart As String = Chr(1) & 80 & 0 & vbCrLf & "68XI" & vbCrLf & "PXES" & vbCrLf & 10 & _
vbCrLf & 0 & vbCrLf & 0 & vbCrLf & 300 & vbCrLf & 0 & vbCrLf & 0 & vbCrLf & "USA" & vbCrLf & "United States"

Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
       Dim strRec As String

       client.Connect(strServer, 6112)

       SendData(msgStart)

       strRec = RecieveData()
       txtRecieve.Text &= "Data: " & strRec

       Dim t As New Thread(New ThreadStart(AddressOf GetData))
       t.Start()
End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
       End
End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
       Dim msgSend As String = txtSend.Text & vbCrLf
       Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(msgSend)
       Dim stream As NetworkStream = client.GetStream()

       stream.Write(data, 0, data.Length)

       txtRecieve.Text &= "RedPhoenix[Hs]: " & msgSend
       txtSend.Text = ""
End Sub

Private Sub GetData()
       Try
           'This retrieves the messages from users every 500 milisecs..

           Dim data As [Byte]()
           Dim stream As NetworkStream = client.GetStream()

           data = New [Byte](256) {}

           Dim responseData As [String] = [String].Empty
           Dim bytes As Int32 = stream.Read(data, 0, data.Length)

           responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
           txtRecieve.Text &= responseData
           txtRecieve.SelectionStart = txtRecieve.TextLength

           Thread.CurrentThread.Sleep(500)
           If txtRecieve.Lines.Length > 20 Then
               txtRecieve.Text = ""
           End If
           GetData()
       Catch exc As Exception
           MsgBox(exc.ToString)
           End
       End Try
End Sub

Private Function SendData(ByRef msg As String)
       'Notice: this sends the message with a vbCrLf attached at the end.
       Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(msg & vbCrLf)
       Dim stream As NetworkStream = client.GetStream()
       stream.Write(data, 0, data.Length)
End Function

Private Function RecieveData() As String
       Dim data As [Byte]()
       Dim stream As NetworkStream = client.GetStream()

       data = New [Byte](256) {}

       Dim responseData As [String] = [String].Empty
       Dim bytes As Int32 = stream.Read(data, 0, data.Length)

       responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)

       Return responseData
End Function

o.OV

Don't use vbcrlf..
binary connections are totally different from telnet connections.

arta's bnetdocs was down earlier was it?
It is up now so you can check out the protocol header information and packet structures.

I'll paste it here but you will need to see it for yourself for a better understanding.

(BYTE)      StartPacket - always 0xFF
(BYTE)      Packet ID
(WORD)    Packet length, including this header

(DWORD)       Protocol ID (0)
(DWORD)       Platform ID
(DWORD)       Program ID
(DWORD)       Version Byte
(DWORD)       Product language
(DWORD)       Local IP for NAT compatibility*
(DWORD)       Time zone bias*
(DWORD)       Locale ID*
(DWORD)       Language ID*
(STRING)       Country abreviation
(STRING)       Country
If the facts don't fit the theory, change the facts. - Albert Einstein

Adron

Make sure you don't get implicit charset conversions from unicode to utf-8 for things like chr(255). You need to use chr() virtually everywhere, or just quit sending strings and start sending binary data.

MyndFyre

#42
Recall, though, that Chars in .NET are Unicode -- 2 bytes.  You'll need to use System.Text.Encoding.Ascii.GetBytes(string) to get a 1-byte number.  Also, use the Byte type.

Rather than using the Java class, this can be compiled directly and referenced as a DLL.

http://forum.valhallalegends.com/phpbbs/index.php?board=17;action=display;threadid=4150;start=msg34300#msg34300

After having talked extensively on the GotDotNet user area about performance of small functions like these, I've found out that the .NET JITter will inline many of these things, which was something Kp remarked at the very bottom of that thread.

What you'll do is call InsertDWORD(ByVal i As Integer) -- note that I'm using VB syntax for you -- for numbers that are marked DWORD.  If you're inserting one of those four-character strings like "IX86" that look reversed in your packetlog -- "68XI" -- use the .InsertNonNTString (that is what many people call a Non-Null-Terminated string -- although technically it's just a number that looks like a string), and for any other strings -- the ones that are variable-length or are marked "STRING" in BnetDocs -- use .InsertNTString(string).

Hope that helps.  I think it will clarify a lot for you.

Paclet 0x50 -- SID_AUTH_INFO -- is then made:

C#:


Packet pck = new BncsPacket(0x50);
pck.InsertDWORD(0);
pck.InsertNonNTString("IX86");
pck.InsertNonNTString("SEXP");
pck.InsertDWORD(0x0a); // replace your version byte here
pck.InsertDWORD(0); // prod. language; may be 0
pck.InsertDWORD(0); // local ip, for NAT compatibility
pck.InsertDWORD(timeZoneOffset * -60); // timeZoneOffset being an integer representing your hours off of GMT
pck.InsertDWORD(0); // locale ID, may be 0
pck.InsertDWORD(0); // language ID, may be 0
pck.InsertNTString("USA");
pck.InsertNTString("United States");


VB .NET:


Dim pck As New BncsPacket(&H50)
pck.InsertDWORD(0)
pck.InsertNonNTString("IX86")
pck.InsertNonNTString("SEXP")
pck.InsertDWORD(&H0a)  ' replace your version byte here
pck.InsertDWORD(0)  ' prod. language; may be 0
pck.InsertDWORD(0)  ' local ip, for NAT compatibility
pck.InsertDWORD(timeZoneOffset * -60)  ' timeZoneOffset being an integer representing your hours off of GMT
pck.InsertDWORD(0)  ' locale ID, may be 0
pck.InsertDWORD(0)  ' language ID, may be 0
pck.InsertNTString("USA")
pck.InsertNTString("United States")


Then, to send it, I just use:

sck.BeginSend(pck.Data, / * .. stuff */);

Hope that helps!
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

RedPhoenix

Check this out:


Private msgStart As [String] = Chr(3) & Chr(4) & "RedPhoenix[Hs]" & vbCrLf & Password


Is the same if we write it this way:


Private msgStart As [String] = Chr(&H3) & Chr(&H4) & Chr(&H52) & Chr(&H65) & Chr(&H64) & Chr(&H50) & Chr(&H68) & Chr(&H6F) _
        & Chr(&H65) & Chr(&H6E) & Chr(&H69) & Chr(&H78) & Chr(&H5B) & Chr(&H48) & Chr(&H73) & Chr(&H5D) & Chr(&HD) & Chr(&HA) & Chr(&H66) _
         & Chr(&H69) & Chr() & Chr() & Chr() & Chr() & Chr() & Chr() & Chr()


The last 7 chars have been erased since it was my password.  :P

Adron

Yes, you can write some things with either Chr() or the letters. There's a big difference between "50", Chr(50), and Chr(80) though.

|