Advertisement
forextheblack

ServerMessage

Mar 1st, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. package ml.neoforex.engine.cryptography.habbo;
  2.  
  3. import io.netty.buffer.ByteBuf;
  4. import io.netty.buffer.ByteBufOutputStream;
  5. import io.netty.buffer.Unpooled;
  6. import ml.neoforex.netty.session.Session;
  7.  
  8. /**
  9.  * Created by forex on 29/02/16.
  10.  */
  11. public class ServerMessage {
  12.     /**
  13.      * Objects
  14.      */
  15.     private ByteBuf byteBuf;
  16.     private ByteBufOutputStream byteBufOutputStream;
  17.  
  18.  
  19.     /**
  20.      * Constructors
  21.      */
  22.     public ServerMessage(short header) {
  23.         this.byteBuf = Unpooled.buffer();
  24.         this.byteBufOutputStream = new ByteBufOutputStream(this.byteBuf);
  25.  
  26.         // Write lenght(TO EDIT IN FINISH), and Header.
  27.         this.writeInt(0);
  28.         this.writeShort(header);
  29.     }
  30.  
  31.  
  32.     /**
  33.      * Setters
  34.      */
  35.     public void writeShort(int num) {
  36.         try {
  37.             this.byteBufOutputStream.writeShort(num);
  38.         } catch (Exception e) {
  39.             e.printStackTrace();
  40.         }
  41.     }
  42.  
  43.     public void writeInt(int num) {
  44.         try {
  45.             this.byteBufOutputStream.writeInt(num);
  46.         } catch (Exception e) {
  47.             e.printStackTrace();
  48.         }
  49.     }
  50.  
  51.     public void writeLong(long num) {
  52.         try {
  53.             this.byteBufOutputStream.writeLong(num);
  54.         } catch(Exception e) {
  55.             e.printStackTrace();
  56.         }
  57.     }
  58.  
  59.     public void writeDouble(double num) {
  60.         try {
  61.             this.byteBufOutputStream.writeDouble(num);
  62.         } catch (Exception e) {
  63.             e.printStackTrace();
  64.         }
  65.     }
  66.  
  67.     public void writeBoolean(boolean is) {
  68.         try {
  69.             this.byteBufOutputStream.writeBoolean(is);
  70.         } catch (Exception e) {
  71.             e.printStackTrace();
  72.         }
  73.     }
  74.  
  75.     public void writeUTF(String string) {
  76.         try {
  77.             this.byteBufOutputStream.writeUTF(string);
  78.         } catch (Exception e) {
  79.             e.printStackTrace();
  80.         }
  81.     }
  82.  
  83.     public void writeByte(int num) {
  84.         try {
  85.             this.byteBufOutputStream.writeByte(num);
  86.         } catch (Exception e) {
  87.             e.printStackTrace();
  88.         }
  89.     }
  90.  
  91.  
  92.     /**
  93.      * Sender
  94.      */
  95.     public ByteBuf get() {
  96.         this.byteBuf.setInt(0, this.byteBuf.writerIndex()-4);        
  97.         return this.byteBuf;
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement