RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.net.packet.GamePacket Class Reference

Represents a single game packet. More...

Inheritance diagram for com.runehive.net.packet.GamePacket:
Collaboration diagram for com.runehive.net.packet.GamePacket:

Public Member Functions

 GamePacket (final int opcode, final PacketType header, final ByteBuf payload)
 Creates a GamePacket.
PacketType getHeader ()
 Gets the type.
int getOpcode ()
 Gets the opcode.
ByteBuf getPayload ()
 Gets the payload.
String getRS2String ()
 Reads a RuneScape string.
int getSize ()
 Gets the size of this payload.
int readByte ()
 Reads a STANDARD signed byte from the payload.
int readByte (boolean signed)
 Reads a STANDARD byte from the payload.
int readByte (boolean signed, ByteModification mod)
 Reads a single byte from the payload.
int readByte (ByteModification mod)
 Reads a signed byte from the payload.
byte[] readBytes (int amount)
 Reads the amount of bytes into the array, starting at the current position.
byte[] readBytes (int amount, ByteModification mod)
 Reads a series of bytes from a buffer.
byte[] readBytesReverse (int amount)
 Reads a series of bytes in reverse.
byte[] readBytesReverse (int amount, ByteModification mod)
 Reads a series of bytes in reverse.
int readInt ()
 Reads a STANDARD signed integer value from the payload in BIG order.
int readInt (boolean signed)
 Reads a STANDARD integer value from the payload in BIG order.
int readInt (boolean signed, ByteModification mod)
 Reads an integer value from the payload in BIG order.
int readInt (boolean signed, ByteOrder order)
 Reads a STANDARD integer value from the payload.
int readInt (boolean signed, ByteOrder order, ByteModification mod)
 Reads an integer value from the payload.
int readInt (ByteModification mod)
 Reads a signed integer value from the payload in ByteOrder BIG order.
long readLong ()
 Reads a STANDARD signed long value from the payload in BIG order.
long readLong (boolean signed)
 Reads a STANDARD long value from the payload in BIG order.
long readLong (boolean signed, ByteModification mod)
 Reads a long value from the payload in BIG order.
long readLong (boolean signed, ByteOrder order)
 Reads a STANDARD long value from the payload.
long readLong (boolean signed, ByteOrder order, ByteModification mod)
 Reads a long value from the payload.
long readLong (ByteModification mod)
 Reads a signed long value from the payload in BIG order.
int readShort ()
 Reads a STANDARD signed short value from the payload in BIG order.
int readShort (boolean signed)
 Reads a STANDARD short value from the payload in BIG order.
int readShort (boolean signed, ByteModification mod)
 Reads a short value from the payload in BIG order.
int readShort (boolean signed, ByteOrder order)
 Reads a STANDARD short value from the payload.
int readShort (boolean signed, ByteOrder order, ByteModification mod)
 Reads a short value from the payload.
int readShort (ByteModification mod)
 Reads a signed short value from the payload BIG order.
int readShort (ByteOrder order)
 Reads a STANDARD signed short value from the payload.
int readShort (ByteOrder order, ByteModification mod)
 Reads a signed short value from the payload.
String toString ()

Private Attributes

final PacketType header
 The header for this packet.
final int opcode
 The opcode for this packet.
final ByteBuf payload
 The buffer that contains the data for this packet.
final int size
 The size of this packet.

Detailed Description

Represents a single game packet.

Author
nshusa

Definition at line 13 of file GamePacket.java.

Constructor & Destructor Documentation

◆ GamePacket()

com.runehive.net.packet.GamePacket.GamePacket ( final int opcode,
final PacketType header,
final ByteBuf payload )

Creates a GamePacket.

Parameters
opcodeThe opcode.
headerThe header.
payloadThe payload.

Definition at line 45 of file GamePacket.java.

45 {
46 super(payload);
47
48 this.opcode = opcode;
49 this.header = header;
50 this.payload = payload;
51 this.size = payload.readableBytes();
52 }

References header, opcode, and payload.

Member Function Documentation

◆ getHeader()

PacketType com.runehive.net.packet.GamePacket.getHeader ( )

Gets the type.

Returns
The type.

Definition at line 77 of file GamePacket.java.

77 {
78 return header;
79 }

References header.

◆ getOpcode()

int com.runehive.net.packet.GamePacket.getOpcode ( )

Gets the opcode.

Returns
The opcode.

Definition at line 68 of file GamePacket.java.

68 {
69 return opcode;
70 }

References opcode.

◆ getPayload()

ByteBuf com.runehive.net.packet.GamePacket.getPayload ( )

Gets the payload.

Returns
The payload.

Definition at line 86 of file GamePacket.java.

86 {
87 return payload;
88 }

References payload.

◆ getRS2String()

String com.runehive.net.packet.GamePacket.getRS2String ( )

Reads a RuneScape string.

Returns
The string.

Definition at line 600 of file GamePacket.java.

600 {
601 final StringBuilder bldr = new StringBuilder();
602 byte b;
603 while (payload.isReadable() && (b = payload.readByte()) != 10) {
604 bldr.append((char) b);
605 }
606 return bldr.toString();
607 }

References payload.

◆ getSize()

int com.runehive.net.packet.GamePacket.getSize ( )

Gets the size of this payload.

Returns
The amount of readable bytes.

Definition at line 59 of file GamePacket.java.

59 {
60 return size;
61 }

References size.

◆ readByte() [1/4]

int com.runehive.net.packet.GamePacket.readByte ( )

Reads a STANDARD signed byte from the payload.

Returns
The byte.

Definition at line 95 of file GamePacket.java.

95 {
96 return payload.readByte();
97 }

References payload.

Referenced by readByte(), readByte(), readBytes(), readInt(), readLong(), and readShort().

Here is the caller graph for this function:

◆ readByte() [2/4]

int com.runehive.net.packet.GamePacket.readByte ( boolean signed )

Reads a STANDARD byte from the payload.

Parameters
signedThe flag that denotes this value is signed.
Returns
The byte.

Definition at line 107 of file GamePacket.java.

107 {
108 return readByte(signed, ByteModification.NONE);
109 }

References com.runehive.net.codec.ByteModification.NONE, and readByte().

Here is the call graph for this function:

◆ readByte() [3/4]

int com.runehive.net.packet.GamePacket.readByte ( boolean signed ,
ByteModification mod )

Reads a single byte from the payload.

Parameters
signedThe flag that denotes this value is signed.
modThe modification performed on this value.
Returns
The byte.

Definition at line 134 of file GamePacket.java.

134 {
135 int value = payload.readByte();
136 switch (mod) {
137 case ADD:
138 value = value - 128;
139 break;
140
141 case SUB:
142 value = 128 - value;
143 break;
144
145 case NEG:
146 value = -value;
147 break;
148
149 case NONE:
150 break;
151
152 }
153 return signed ? value : value & 0xFF;
154 }

References payload.

◆ readByte() [4/4]

int com.runehive.net.packet.GamePacket.readByte ( ByteModification mod)

Reads a signed byte from the payload.

Parameters
modThe modification performed on this value.
Returns
The signed byte.

Definition at line 119 of file GamePacket.java.

119 {
120 return readByte(true, mod);
121 }

References readByte().

Here is the call graph for this function:

◆ readBytes() [1/2]

byte[] com.runehive.net.packet.GamePacket.readBytes ( int amount)

Reads the amount of bytes into the array, starting at the current position.

Parameters
amountthe amount to read.
Returns
a buffer filled with the data.

Definition at line 518 of file GamePacket.java.

518 {
519 return readBytes(amount, ByteModification.NONE);
520 }

References com.runehive.net.codec.ByteModification.NONE, and readBytes().

Referenced by readBytes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readBytes() [2/2]

byte[] com.runehive.net.packet.GamePacket.readBytes ( int amount,
ByteModification mod )

Reads a series of bytes from a buffer.

Parameters
amountThe amount of bytes to read.
modThe modifications performed on the bytes values.
Returns
The bytes that where read.

Definition at line 533 of file GamePacket.java.

533 {
534 byte[] data = new byte[amount];
535 for (int i = 0; i < amount; i++) {
536 data[i] = (byte) readByte(mod);
537 }
538 return data;
539 }

References readByte().

Here is the call graph for this function:

◆ readBytesReverse() [1/2]

byte[] com.runehive.net.packet.GamePacket.readBytesReverse ( int amount)

Reads a series of bytes in reverse.

Parameters
amountThe amount of bytes to read.
Returns
The bytes in reverse.

Definition at line 549 of file GamePacket.java.

549 {
550 return readBytesReverse(amount, ByteModification.NONE);
551 }

References com.runehive.net.codec.ByteModification.NONE, and readBytesReverse().

Referenced by readBytesReverse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readBytesReverse() [2/2]

byte[] com.runehive.net.packet.GamePacket.readBytesReverse ( int amount,
ByteModification mod )

Reads a series of bytes in reverse.

Parameters
amountThe amount of bytes to read.
modThe modification performed on these bytes.
Returns
The bytes in reverse.

Definition at line 564 of file GamePacket.java.

564 {
565 byte[] data = new byte[amount];
566
567 int dataPosition = 0;
568
569 for (int index = payload.readerIndex() + amount - 1; index >= payload.readerIndex(); index--) {
570 int value = payload.getByte(index);
571
572 switch (mod) {
573
574 case ADD:
575 value -= 128;
576 break;
577
578 case NEG:
579 value = -value;
580 break;
581
582 case SUB:
583 value = 128 - value;
584 break;
585
586 case NONE:
587 break;
588
589 }
590 data[dataPosition++] = (byte) value;
591 }
592 return data;
593 }

References payload.

◆ readInt() [1/6]

int com.runehive.net.packet.GamePacket.readInt ( )

Reads a STANDARD signed integer value from the payload in BIG order.

Returns
The integer value.

Definition at line 290 of file GamePacket.java.

290 {
291 return readInt(true, ByteOrder.BE, ByteModification.NONE);
292 }

References com.runehive.net.codec.ByteOrder.BE, com.runehive.net.codec.ByteModification.NONE, and readInt().

Referenced by readInt(), readInt(), readInt(), readInt(), and readInt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readInt() [2/6]

int com.runehive.net.packet.GamePacket.readInt ( boolean signed )

Reads a STANDARD integer value from the payload in BIG order.

Parameters
signedThe flag that denotes this value is signed.
Returns
The integer value.

Definition at line 303 of file GamePacket.java.

303 {
304 return readInt(signed, ByteOrder.BE, ByteModification.NONE);
305 }

References com.runehive.net.codec.ByteOrder.BE, com.runehive.net.codec.ByteModification.NONE, and readInt().

Here is the call graph for this function:

◆ readInt() [3/6]

int com.runehive.net.packet.GamePacket.readInt ( boolean signed ,
ByteModification mod )

Reads an integer value from the payload in BIG order.

Parameters
signedThe flag that denotes this value is signed.
modThe modifications performed on this value.
Returns
The integer value.

Definition at line 331 of file GamePacket.java.

331 {
332 return readInt(signed, ByteOrder.BE, mod);
333 }

References com.runehive.net.codec.ByteOrder.BE, and readInt().

Here is the call graph for this function:

◆ readInt() [4/6]

int com.runehive.net.packet.GamePacket.readInt ( boolean signed ,
ByteOrder order )

Reads a STANDARD integer value from the payload.

Parameters
signedThe flag that denotes this value is signed.
orderThe order in which the value is written.
Returns
The integer value.

Definition at line 346 of file GamePacket.java.

346 {
347 return readInt(signed, order, ByteModification.NONE);
348 }

References com.runehive.net.codec.ByteModification.NONE, and readInt().

Here is the call graph for this function:

◆ readInt() [5/6]

int com.runehive.net.packet.GamePacket.readInt ( boolean signed ,
ByteOrder order,
ByteModification mod )

Reads an integer value from the payload.

Parameters
signedThe flag that denotes this value is signed.
orderThe order in which the value is written.
modThe modifications performed on this value.
Returns
The integer value.

Definition at line 364 of file GamePacket.java.

364 {
365 long value = 0;
366 switch (order) {
367 case BE:
368 value |= readByte(false) << 24;
369 value |= readByte(false) << 16;
370 value |= readByte(false) << 8;
371 value |= readByte(false, mod);
372 break;
373
374 case ME:
375 value |= readByte(false) << 8;
376 value |= readByte(false, mod);
377 value |= readByte(false) << 24;
378 value |= readByte(false) << 16;
379 break;
380 case IME:
381 value |= readByte(false) << 16;
382 value |= readByte(false) << 24;
383 value |= readByte(false, mod);
384 value |= readByte(false) << 8;
385 break;
386
387 case LE:
388 value |= readByte(false, mod);
389 value |= readByte(false) << 8;
390 value |= readByte(false) << 16;
391 value |= readByte(false) << 24;
392 break;
393
394 }
395 return (int) (signed ? value : value & 0xFFFFFFFFL);
396 }

References readByte().

Here is the call graph for this function:

◆ readInt() [6/6]

int com.runehive.net.packet.GamePacket.readInt ( ByteModification mod)

Reads a signed integer value from the payload in ByteOrder BIG order.

Parameters
modThe modifications performed on this value.
Returns
The integer value.

Definition at line 316 of file GamePacket.java.

316 {
317 return readInt(true, ByteOrder.BE, mod);
318 }

References com.runehive.net.codec.ByteOrder.BE, and readInt().

Here is the call graph for this function:

◆ readLong() [1/6]

long com.runehive.net.packet.GamePacket.readLong ( )

Reads a STANDARD signed long value from the payload in BIG order.

Returns
The long value.

Definition at line 404 of file GamePacket.java.

404 {
405 return readLong(true, ByteOrder.BE, ByteModification.NONE);
406 }

References com.runehive.net.codec.ByteOrder.BE, com.runehive.net.codec.ByteModification.NONE, and readLong().

Referenced by readLong(), readLong(), readLong(), readLong(), and readLong().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readLong() [2/6]

long com.runehive.net.packet.GamePacket.readLong ( boolean signed )

Reads a STANDARD long value from the payload in BIG order.

Parameters
signedThe flag that denotes this value is signed.
Returns
The long value.

Definition at line 417 of file GamePacket.java.

417 {
418 return readLong(signed, ByteOrder.BE, ByteModification.NONE);
419 }

References com.runehive.net.codec.ByteOrder.BE, com.runehive.net.codec.ByteModification.NONE, and readLong().

Here is the call graph for this function:

◆ readLong() [3/6]

long com.runehive.net.packet.GamePacket.readLong ( boolean signed ,
ByteModification mod )

Reads a long value from the payload in BIG order.

Parameters
signedThe flag that denotes this value is signed.
modThe modifications performed on this value.
Returns
The long value.

Definition at line 444 of file GamePacket.java.

444 {
445 return readLong(signed, ByteOrder.BE, mod);
446 }

References com.runehive.net.codec.ByteOrder.BE, and readLong().

Here is the call graph for this function:

◆ readLong() [4/6]

long com.runehive.net.packet.GamePacket.readLong ( boolean signed ,
ByteOrder order )

Reads a STANDARD long value from the payload.

Parameters
signedThe flag that denotes this value is signed.
orderThe order in which the value is written.
Returns
The long value.

Definition at line 459 of file GamePacket.java.

459 {
460 return readLong(signed, order, ByteModification.NONE);
461 }

References com.runehive.net.codec.ByteModification.NONE, and readLong().

Here is the call graph for this function:

◆ readLong() [5/6]

long com.runehive.net.packet.GamePacket.readLong ( boolean signed ,
ByteOrder order,
ByteModification mod )

Reads a long value from the payload.

Parameters
signedThe flag that denotes this value is signed.
orderThe order in which the value is written.
modThe modifications performed on this value.
Returns
The long value.

Definition at line 477 of file GamePacket.java.

477 {
478 long value = 0;
479 switch (order) {
480 case BE:
481 value |= (long) readByte(false) << 56L;
482 value |= (long) readByte(false) << 48L;
483 value |= (long) readByte(false) << 40L;
484 value |= (long) readByte(false) << 32L;
485 value |= (long) readByte(false) << 24L;
486 value |= (long) readByte(false) << 16L;
487 value |= (long) readByte(false) << 8L;
488 value |= readByte(false, mod);
489 break;
490
491 case ME:
492 case IME:
493 throw new UnsupportedOperationException("Middle and " + "inverse-middle value types not supported!");
494
495 case LE:
496 value |= readByte(false, mod);
497 value |= (long) readByte(false) << 8L;
498 value |= (long) readByte(false) << 16L;
499 value |= (long) readByte(false) << 24L;
500 value |= (long) readByte(false) << 32L;
501 value |= (long) readByte(false) << 40L;
502 value |= (long) readByte(false) << 48L;
503 value |= (long) readByte(false) << 56L;
504 break;
505
506 }
507 return signed ? value : value & 0xFFFFFFFFL;
508 }

References readByte().

Here is the call graph for this function:

◆ readLong() [6/6]

long com.runehive.net.packet.GamePacket.readLong ( ByteModification mod)

Reads a signed long value from the payload in BIG order.

Parameters
modThe modifications performed on this value.
Returns
The long value.

Definition at line 429 of file GamePacket.java.

429 {
430 return readLong(true, ByteOrder.BE, mod);
431 }

References com.runehive.net.codec.ByteOrder.BE, and readLong().

Here is the call graph for this function:

◆ readShort() [1/8]

int com.runehive.net.packet.GamePacket.readShort ( )

Reads a STANDARD signed short value from the payload in BIG order.

Returns
The standard signed short value.

Definition at line 162 of file GamePacket.java.

162 {
163 return payload.readShort();
164 }

References payload.

Referenced by readShort(), readShort(), readShort(), readShort(), readShort(), and readShort().

Here is the caller graph for this function:

◆ readShort() [2/8]

int com.runehive.net.packet.GamePacket.readShort ( boolean signed )

Reads a STANDARD short value from the payload in BIG order.

Parameters
signedThe flag that denotes this value is signed.
Returns
The standard short value.

Definition at line 175 of file GamePacket.java.

175 {
176 return readShort(signed, ByteOrder.BE, ByteModification.NONE);
177 }

References com.runehive.net.codec.ByteOrder.BE, com.runehive.net.codec.ByteModification.NONE, and readShort().

Here is the call graph for this function:

◆ readShort() [3/8]

int com.runehive.net.packet.GamePacket.readShort ( boolean signed ,
ByteModification mod )

Reads a short value from the payload in BIG order.

Parameters
signedThe flag that denotes this value is signed.
modThe modifications performed on this value.
Returns
The short value.

Definition at line 244 of file GamePacket.java.

244 {
245 return readShort(signed, ByteOrder.BE, mod);
246 }

References com.runehive.net.codec.ByteOrder.BE, and readShort().

Here is the call graph for this function:

◆ readShort() [4/8]

int com.runehive.net.packet.GamePacket.readShort ( boolean signed ,
ByteOrder order )

Reads a STANDARD short value from the payload.

Parameters
signedThe flag that denotes this value is signed.
orderThe order in which this value is written.
Returns
The standard short value.

Definition at line 202 of file GamePacket.java.

202 {
203 return readShort(signed, order, ByteModification.NONE);
204 }

References com.runehive.net.codec.ByteModification.NONE, and readShort().

Here is the call graph for this function:

◆ readShort() [5/8]

int com.runehive.net.packet.GamePacket.readShort ( boolean signed ,
ByteOrder order,
ByteModification mod )

Reads a short value from the payload.

Parameters
signedThe flag that denotes this value is signed.
orderThe order in which the value is written.
modThe modifications performed on this value.
Returns
The short value.

Definition at line 262 of file GamePacket.java.

262 {
263 int value = 0;
264 switch (order) {
265 case BE:
266 value |= readByte(false) << 8;
267 value |= readByte(false, mod);
268 break;
269
270 case IME:
271 throw new UnsupportedOperationException("Inverse-middle-endian short is impossible!");
272
273 case ME:
274 throw new UnsupportedOperationException("Middle-endian short " + "is impossible!");
275
276 case LE:
277 value |= readByte(false, mod);
278 value |= readByte(false) << 8;
279 break;
280 }
281 return signed ? value : value & 0xFFFF;
282 }

References readByte().

Here is the call graph for this function:

◆ readShort() [6/8]

int com.runehive.net.packet.GamePacket.readShort ( ByteModification mod)

Reads a signed short value from the payload BIG order.

Parameters
modThe modifications performed on this value.
Returns
The short value.

Definition at line 229 of file GamePacket.java.

229 {
230 return readShort(true, ByteOrder.BE, mod);
231 }

References com.runehive.net.codec.ByteOrder.BE, and readShort().

Here is the call graph for this function:

◆ readShort() [7/8]

int com.runehive.net.packet.GamePacket.readShort ( ByteOrder order)

Reads a STANDARD signed short value from the payload.

Parameters
orderThe order in which this value is written.
Returns
The signed standard short value.

Definition at line 187 of file GamePacket.java.

187 {
188 return readShort(true, order, ByteModification.NONE);
189 }

References com.runehive.net.codec.ByteModification.NONE, and readShort().

Here is the call graph for this function:

◆ readShort() [8/8]

int com.runehive.net.packet.GamePacket.readShort ( ByteOrder order,
ByteModification mod )

Reads a signed short value from the payload.

Parameters
orderThe order in which this value is written.
modThe modifications performed on this value.
Returns
The short value.

Definition at line 217 of file GamePacket.java.

217 {
218 return readShort(true, order, mod);
219 }

References readShort().

Here is the call graph for this function:

◆ toString()

String com.runehive.net.packet.GamePacket.toString ( )

Definition at line 610 of file GamePacket.java.

610 {
611 return String.format("[opcode=%d], [type=%s], [size= %d]", opcode, header.name(), size);
612 }

References header, opcode, and size.

Member Data Documentation

◆ header

final PacketType com.runehive.net.packet.GamePacket.header
private

The header for this packet.

Definition at line 23 of file GamePacket.java.

Referenced by GamePacket(), getHeader(), and toString().

◆ opcode

final int com.runehive.net.packet.GamePacket.opcode
private

The opcode for this packet.

Definition at line 18 of file GamePacket.java.

Referenced by GamePacket(), getOpcode(), and toString().

◆ payload

final ByteBuf com.runehive.net.packet.GamePacket.payload
private

The buffer that contains the data for this packet.

Definition at line 28 of file GamePacket.java.

Referenced by GamePacket(), getPayload(), getRS2String(), readByte(), readByte(), readBytesReverse(), and readShort().

◆ size

final int com.runehive.net.packet.GamePacket.size
private

The size of this packet.

Definition at line 33 of file GamePacket.java.

Referenced by getSize(), and toString().


The documentation for this class was generated from the following file: