Advertisement
Tyluur

Untitled

Jun 29th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. package com.tyluur.network.decoders;
  2.  
  3. import java.util.NoSuchElementException;
  4.  
  5. import org.jboss.netty.buffer.ChannelBuffer;
  6. import org.jboss.netty.channel.Channel;
  7. import org.jboss.netty.channel.ChannelHandlerContext;
  8. import org.jboss.netty.handler.codec.frame.FrameDecoder;
  9.  
  10. import com.tyluur.network.packet.OutgoingPacket;
  11. import com.tyluur.utility.Constants;
  12.  
  13. /**
  14. * @author Tykuur
  15. */
  16.  
  17. public class ClientDecoder extends FrameDecoder {
  18.  
  19. /**
  20. * The opcode sent by the client to signal the file request start.
  21. */
  22. private static final int FILE_REQUEST = 15,
  23.  
  24. /**
  25. * The opcode sent to the server to initiate login.
  26. */
  27. LOGIN_REQUEST = 14;
  28.  
  29. @Override
  30. protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
  31. try {
  32. ctx.getPipeline().remove(this);
  33. } catch (NoSuchElementException e) { }
  34. int opcode = buffer.readByte() & 0xFF;
  35. OutgoingPacket response = new OutgoingPacket(null, opcode);
  36. switch(opcode) {
  37. case FILE_REQUEST:
  38. int revision = buffer.readInt();
  39. if (revision != Constants.REVISION) {
  40. response.put(6);
  41. channel.close();
  42. } else {
  43. response.put(6);
  44. OutgoingPacket packet = new OutgoingPacket(null, 6).put(3);
  45. packet.get();
  46. if (4 <= buffer.readableBytes()) {
  47. buffer.skipBytes(4);
  48. for (final int key : Constants.UPDATE_KEYS) {
  49. response.put((byte) key);
  50. }
  51. return true;
  52. }
  53. }
  54. break;
  55. case LOGIN_REQUEST:
  56. break;
  57. }
  58. return null;
  59. }
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement