mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-06 08:39:06 +00:00
d876a923b9
* Clean up part 1 - Removed lots of dead code - Removed unncessary files not in use - Cleaned up small bits of code - Removed a few warnings - Server.java ---> GameEngine.java - Constants.java ---> GameConstants.java * Cape Dye Rewrote cape dying * Packaging - redone ----> com.rebotted * PacketSender/clean up - ActionSender ---> PacketSender - Moved many more packets to packetsender - Cleaned up more dead code * Merge Client/Player - Merged Client.java with Player.java (both were doing same thing so redundant to have both) - Removed some more dead code - Tidy a few small things up * Quests/more clean up - Removed more dead code - Made quests static in order to clean them up a bit * More cleanup - Removed some more of the dead quest code - Correcting naming of some of the shop variables
105 lines
1.8 KiB
Java
105 lines
1.8 KiB
Java
package com.rebotted.net;
|
|
|
|
/**
|
|
* Represents a packet buffer.
|
|
*
|
|
* @author Ultimate1
|
|
* @author blakeman8192
|
|
*/
|
|
|
|
public class PacketBuffer {
|
|
|
|
private int caret;
|
|
private byte[] buffer;
|
|
|
|
public PacketBuffer(int capcity) {
|
|
buffer = new byte[capcity];
|
|
caret = 0;
|
|
}
|
|
|
|
public void setBuffer(byte[] buffer) {
|
|
this.buffer = buffer;
|
|
caret = 0;
|
|
}
|
|
|
|
public PacketBuffer setOpcode(int opcode) {
|
|
return addByte(opcode);
|
|
}
|
|
|
|
public PacketBuffer addByte(int i) {
|
|
buffer[caret++] = (byte) i;
|
|
return this;
|
|
}
|
|
|
|
public int getByte() {
|
|
return buffer[caret++] & 0xff;
|
|
}
|
|
|
|
public PacketBuffer addBoolean(boolean val) {
|
|
return addByte(val == true ? 1 : 0);
|
|
}
|
|
|
|
public boolean getBoolean() {
|
|
return getByte() == 1;
|
|
}
|
|
|
|
public PacketBuffer addShort(int i) {
|
|
return addByte(i >> 8).addByte(i);
|
|
}
|
|
|
|
public int getShort() {
|
|
return getByte() << 8 | getByte();
|
|
}
|
|
|
|
public PacketBuffer addInt(int i) {
|
|
return addShort(i >> 16).addShort(i);
|
|
}
|
|
|
|
public int getInt() {
|
|
return getShort() << 16 | getShort();
|
|
}
|
|
|
|
public PacketBuffer addLong(long i) {
|
|
return addInt((int) (i >> 32)).addInt((int) i);
|
|
}
|
|
|
|
public long getLong() {
|
|
return (long) getInt() << 32L | getInt();
|
|
}
|
|
|
|
public PacketBuffer addString(String s) {
|
|
for (byte b : s.getBytes()) {
|
|
addByte(b);
|
|
}
|
|
return addByte('\n');
|
|
}
|
|
|
|
public String getString() {
|
|
int c;
|
|
StringBuilder builder = new StringBuilder();
|
|
while ((c = getByte()) != '\n') {
|
|
builder.append((char) c);
|
|
}
|
|
return builder.toString();
|
|
}
|
|
|
|
public byte[] getBuffer() {
|
|
byte[] newBuffer = new byte[caret + 1];
|
|
newBuffer[0] = (byte) caret;
|
|
System.arraycopy(buffer, 0, newBuffer, 1, caret);
|
|
return newBuffer;
|
|
}
|
|
|
|
public int getLength() {
|
|
return buffer.length;
|
|
}
|
|
|
|
public void reset() {
|
|
caret = 0;
|
|
for (int i = 0; i < buffer.length; i++) {
|
|
buffer[i] = 0;
|
|
}
|
|
buffer = null;
|
|
}
|
|
}
|