Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ml.neoforex.engine.cryptography.habbo;
- import io.netty.buffer.ByteBuf;
- import io.netty.buffer.ByteBufOutputStream;
- import io.netty.buffer.Unpooled;
- import ml.neoforex.netty.session.Session;
- /**
- * Created by forex on 29/02/16.
- */
- public class ServerMessage {
- /**
- * Objects
- */
- private ByteBuf byteBuf;
- private ByteBufOutputStream byteBufOutputStream;
- /**
- * Constructors
- */
- public ServerMessage(short header) {
- this.byteBuf = Unpooled.buffer();
- this.byteBufOutputStream = new ByteBufOutputStream(this.byteBuf);
- // Write lenght(TO EDIT IN FINISH), and Header.
- this.writeInt(0);
- this.writeShort(header);
- }
- /**
- * Setters
- */
- public void writeShort(int num) {
- try {
- this.byteBufOutputStream.writeShort(num);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void writeInt(int num) {
- try {
- this.byteBufOutputStream.writeInt(num);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void writeLong(long num) {
- try {
- this.byteBufOutputStream.writeLong(num);
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
- public void writeDouble(double num) {
- try {
- this.byteBufOutputStream.writeDouble(num);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void writeBoolean(boolean is) {
- try {
- this.byteBufOutputStream.writeBoolean(is);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void writeUTF(String string) {
- try {
- this.byteBufOutputStream.writeUTF(string);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void writeByte(int num) {
- try {
- this.byteBufOutputStream.writeByte(num);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * Sender
- */
- public ByteBuf get() {
- this.byteBuf.setInt(0, this.byteBuf.writerIndex()-4);
- return this.byteBuf;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement