Valhalla Legends Forums Archive | Java Programming | Need some help

AuthorMessageTime
Imperceptus
[code]
            Init startPacket = new Init();
            _out.write(startPacket.getLength() & 0xff);
            _out.write(startPacket.getLength() >> 8 &0xff);
            _out.write(startPacket.getContent());
            _out.flush();
[/code]

_out is declared like this

[code]private OutputStream _out;[/code]

Could someone give me a psuedo explanation of what is going on here line for line if possible?
March 26, 2005, 4:44 AM
iago
[code]
// Create an Init object called startPacket
            Init startPacket = new Init();
// write the right byte of the length (this looks like it would incorrectly add 4 bytes, though)
            _out.write(startPacket.getLength() & 0xff);
// write the second byte from the right (again, looks like it would add 4 bytes)
            _out.write(startPacket.getLength() >> 8 &0xff);
// write the content
            _out.write(startPacket.getContent());
// Sendt he data
            _out.flush();
[/code]

March 26, 2005, 5:38 AM
Imperceptus
It is supose to be the login packet 0x08 I believe for a login server ive been working on. The ssource im reading appears to use static init packet and static key for blowfish, but official servers send non static init packet:
1) first byte is always 0 (offset 0)
2) next 4 bytes are random (offset 1-4)
3) and the last 4 bytes are static (offset 5-8 )

Im just abit not able to understand half of java.
March 27, 2005, 6:56 PM
Lenny
[quote author=iago link=topic=11046.msg105621#msg105621 date=1111815514]
[code]
// Create an Init object called startPacket
            Init startPacket = new Init();
// write the right byte of the length (this looks like it would incorrectly add 4 bytes, though)
            _out.write(startPacket.getLength() & 0xff);
// write the second byte from the right (again, looks like it would add 4 bytes)
            _out.write(startPacket.getLength() >> 8 &0xff);
// write the content
            _out.write(startPacket.getContent());
// Sendt he data
            _out.flush();
[/code]


[/quote]

Well according to the API, write(int b) will write the first eight low-order bits, so the implementation would only add a byte...

Not the best way to do it though...
March 28, 2005, 12:03 AM

Search