Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Logger log = LoggerFactory.getLogger(ServerMessage.class);
- private int Header;
- private ByteArrayOutputStream byteArray;
- public ServerMessage() {
- this.byteArray = new ByteArrayOutputStream();
- }
- public ServerMessage(int header) {
- // TODO Auto-generated constructor stub
- this.byteArray = new ByteArrayOutputStream();
- this.Header = header;
- }
- public void writeByte(int Int) {
- try {
- this.byteArray.write(Int);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void writeUtf(String UTF)
- /* */ {
- /* */ try {
- /* 19 */ this.byteArray.write(HabboEncoding.WriteShort(UTF.length()));
- /* 20 */ this.byteArray.write(UTF.getBytes());
- /* */ }
- /* */ catch (IOException e) {
- /* 23 */ e.printStackTrace();
- /* */ }
- /* */ }
- /* */
- /* */ public void writeInt(int Int)
- /* */ {
- /* */ try {
- /* 30 */ this.byteArray.write(HabboEncoding.WriteInt(Int));
- /* */ }
- /* */ catch (Exception e) {
- /* 33 */ e.printStackTrace();
- /* */ }
- /* */ }
- /* */
- /* */ public void writeShort(int Short)
- /* */ {
- /* */ try {
- /* 40 */ this.byteArray.write(HabboEncoding.WriteShort(Short));
- /* */ }
- /* */ catch (Exception e) {
- /* 43 */ e.printStackTrace();
- /* */ }
- /* */ }
- /* */
- /* */ public void writeLength()
- /* */ {
- /* 49 */ int Length = this.byteArray.size();
- /* */
- /* 51 */ ServerMessage Array = new ServerMessage();
- /* */
- /* 53 */ Array.writeInt(Length);
- /* 54 */ Array.writeByteArray(this);
- /* */
- /* 56 */ this.byteArray = Array.getByteArray();
- /* */ }
- /* */
- /* */ public void writeByteArray(ServerMessage ByteArray)
- /* */ {
- /* */ try {
- /* 62 */ this.byteArray.write(ByteArray.getBytes());
- /* */ }
- /* */ catch (Exception e) {
- /* 65 */
- /* */ }
- /* */ }
- /* */
- /* */ public void writeBoolean(Boolean Boolean) {
- /* 70 */ this.byteArray.write(Boolean.booleanValue() ? 1 : 0);
- /* */ }
- /* */
- /* */ public byte[] getBytes()
- /* */ {
- /* 75 */ return this.byteArray.toByteArray();
- /* */ }
- /* */
- /* */ public ByteArrayOutputStream getByteArray()
- /* */ {
- /* 80 */ return this.byteArray;
- /* */ }
- /* */
- /* */ public void finalize() throws Throwable
- /* */ {
- /* 85 */ Clear();
- /* 86 */ super.finalize();
- /* */ }
- /* */
- /* */ private void Clear() {
- /* 90 */ this.byteArray.reset();
- /* */ }
- public void Send(Channel Session) {
- ServerMessage ToSend = new ServerMessage();
- ToSend.writeShort(Header);
- ToSend.writeByteArray(this);
- ToSend.writeLength();
- Session.write(ChannelBuffers.wrappedBuffer(ToSend.getBytes()));
- if(nexus.environment.NexusEnv.active_packetlog)
- log.info("[OUTGOING PACKET] [" + Header + "]" + ConnectionHandler.getCharFilter(ChannelBuffers.wrappedBuffer(ToSend.getBytes())));
- }
- public void writeByte(byte[] bytes) {
- // TODO Auto-generated method stub
- try {
- this.byteArray.write(bytes);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement