• Welcome to Valhalla Legends Archive.
 

[RB / BNLS] First character of packet?

Started by Luxer, September 10, 2004, 05:17 PM

Previous topic - Next topic

Luxer

I have been messing around with Kanes BNLS tester, and finaly managed to mimic it.  The only thing I am having a problem with is the first character of the packet. It seems to be differnt every time I change somthing. FYI: I am using packet 0x02. Could somone please tell me how to get that first character?

Kp

Quote from: Luxer on September 10, 2004, 05:17 PMI have been messing around with Kanes BNLS tester, and finaly managed to mimic it.  The only thing I am having a problem with is the first character of the packet. It seems to be differnt every time I change somthing. FYI: I am using packet 0x02. Could somone please tell me how to get that first character?

The first and second bytes are the length field of the header of the first message.  So, every time you change the length of the packet, the first byte will of course change.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Luxer

OK... So the length of my packet goes in the first byte (or character)?

Kp

[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

MyndFyre

Quote from: Luxer on September 10, 2004, 06:05 PM
OK... So the length of my packet goes in the first byte (or character)?

I don't think reading the BNLS protocol spec will necessarily help.  Luxer doesn't understand what little-endian is.

Let's say you have a length field (as in the case of BNLS).  If you want to use one byte (that's eight bits) to store it, you can choose to interpret the number as signed (which means either positive or negative, and the most significant bit determines whether or not the number is negative) to get values from -128 to 127; or you can interpret it as unsigned (all values are positive), which gives you another power of two to work with in values, from 0 to 255.

When dealing with values larger, though, there are four different types of integral numbers that are common among the platforms:

Byte -- an eight-bit value, which we just described.
Word -- a sixteen-bit, or two-byte, value.
Double Word, or DWORD -- a thirty-two bit, or four-byte, value.
Quad Word, or QWORD -- a sixty-four bit, or eight-byte, value.

The range of numbers you can use varies based on whether or not you use signed or unsigned numbers:
Byte -- Signed: -27 to ( 27-1 ).  Unsigned: 0 to 28-1
Word -- Signed: -215 to ( 215-1 ).  Unsigned: 0 to 216-1
Double Word -- Signed: -231 to ( 231-1 ).  Unsigned: 0 to 232-1
Quad Word -- Signed: -263 to ( 263-1 ).  Unsigned: 0 to 264-1

Another issue the two major chip manufacturers, Motorola and Intel, faced when dealing with numerical representation was how to represent multi-byte numbers; specifically, where do the most-significant bytes go in memory?  Motorola chose to use big-endian, because the "big end" (the most significant byte) comes first.  Intel, om the other hand, chose little-endian, because the least significant byte comes first.

What does this have to do with your size?

BNLS uses two bytes for the length, a word value.  The first byte is the little part, and will change most frequently.  The second byte is the more significant bits -- bits 8 through 15 (indexed at 0).  Since these are more significant (you'd need to go beyond a length of 255), they change less frequently than the bits in the first byte.

Hope that clarifies and answers your question.
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.

Vision

#5
[Kp edit: removed content of post which is not only completely wrong, but indicates a complete lack of understanding of the current context by the original poster.  There is no magic 0xff associated with BNLS, Vision.]

Luxer

 :-\   I guess I did not ask my question correctly. How do I find out what the first two bits of a packet should be?

Kp

Quote from: Luxer on September 11, 2004, 08:15 AM
:-\   I guess I did not ask my question correctly. How do I find out what the first two bits of a packet should be?

Compute the packet length, then perform a bitwise and with 3.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Luxer

Quote from: Kp on September 11, 2004, 11:23 AM
Quote from: Luxer on September 11, 2004, 08:15 AM
:-\   I guess I did not ask my question correctly. How do I find out what the first two bits of a packet should be?

Compute the packet length, then perform a bitwise and with 3.

Two things:

Bitwise And, or Bitwise OR? Is there a differnance?


Say my packet was:

Byte 1: ?
Byte 2: ?
Byte 3: 02
Byte 4: 00
After byte 4: Someusername (Say this was 10 bytes)
After that: 00 (1 byte)
After that: Somepassword (say this was 10 bytes)

Would I bitwise 25? Or do I not include the first two bytes in a bitwise?


MyndFyre

You're a moron.  Really.

First of all, the reason Kp said you should perform a bitwise AND with three, is because you asked how to determine the first two bits.  

So did you read my post?  You should be able to figure it out from that.

But if not....

1.) If the length is 255 or less, the length goes in the first byte, and 0 in the second byte.
2.) If the length is more than 255, you perform a bitwise AND with 255 and the length, and put that result in the first byte.  Then, you shift 255 to the left by 8, AND that with the length, shift that value right by 8, and then that's the second byte.

BNLS uses little-endian byte order.  If you didn't understand the above list, then you should be able to figure out how to do it from the post I made above.
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.

Luxer

#10
Oh, now I get it. Sorry, I am just used to using GOOD servers. I did not realize that BNLS is cruddy.... (No offense to Skywing... He did it like bnet, not like it should be)

"Send everything in ASCII, the universal language for computers, and you'll never have to worry about endianness." -BlankeyRat

Thanks for your time, bye!

A note to mods: He flames me, I flame him.

Quote from: MyndFyre on September 11, 2004, 01:55 PM
You're a moron.  Really.

First of all, the reason Kp said you should perform a bitwise AND with three, is because you asked how to determine the first two bits.  

So did you read my post?  You should be able to figure it out from that.

But if not....

1.) If the length is 255 or less, the length goes in the first byte, and 0 in the second byte.
2.) If the length is more than 255, you perform a bitwise AND with 255 and the length, and put that result in the first byte.  Then, you shift 255 to the left by 8, AND that with the length, shift that value right by 8, and then that's the second byte.

BNLS uses little-endian byte order.  If you didn't understand the above list, then you should be able to figure out how to do it from the post I made above.

Banana fanna fo fanna

Quote from: Luxer on September 11, 2004, 02:07 PM
I did not realize that BNLS is cruddy.... (No offense to Skywing... He did it like bnet, not like it should be)

1. That's a great way to get help
2. If you're bitching about endianness, then hot damn, Intel is cruddy, too. So is AMD.
3. I didn't realize that...YOUR MOM is cruddy.

Quote
"Send everything in ASCII, the universal language for computers, and you'll never have to worry about endianness." -BlankeyRat

Holy shit, that's a great idea! Let's have computer data, which doesn't need to be human-readable as it is, transmitted in an overly verbose language? Why fit 255 values into 1 byte, when we can fit 10!?!?!?

That's such a fantastic idea; instead of just copying the memory into an int variable, now we get to have the fun time of parsing it! PLUS, we get to worry about which base its in! That solves SO MANY problems!

Quote
A note to mods: He flames me, I flame him.

The only person around here who gets away with that is me, shithead. Not to mention Myndfyre's a cool guy.

MyndFyre

Quote from: Luxer on September 11, 2004, 02:07 PM
Oh, now I get it. Sorry, I am just used to using GOOD servers. I did not realize that BNLS is cruddy.... (No offense to Skywing... He did it like bnet, not like it should be)

"Send everything in ASCII, the universal language for computers, and you'll never have to worry about endianness." -BlankeyRat
That's the most idiotic thing I've ever heard.  Why not triple or quadruple the size of data?  Yes!  That would just be markedly efficient!!!

Quote from: Luxer on September 11, 2004, 02:07 PM
Thanks for your time, bye!
Are you finally leaving?  Don't let the door hit you on your way out.
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.

Kp

#13
Not only do I not get flamed for giving him answers that are technically exactly what he wants (but still completely useless since he asked the wrong question), but he then goes on to insult everybody else that really did try to help him?  I'm very offended to be left out of this!  Besides which, Myndfyre's very succinct remark that Luxer is a moron seems right on target, based on his performance in this thread.  I hardly consider it a flame, since Luxer definitely goes on to prove Myndfyre quite correct.  Luxer's probably the type of guy who thinks XML is the be-all end-all of data storage because it's text-based rather than packed data. :)

[Edit: fixed typo.]
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

LivedKrad

#14
Hmm.. why again did he want the first two bits of the packet? I believe it was mentioned at least three times that the packet length is stored as a WORD. A WORD as Myndfyre said, was two bytes. In which case, it would only be necessary to shift the two places and hold the value in some sort of Long value. Unless Luxer made a typo, I'd also call him a moron.

Edit: Fixed a typo.