Advertisement
Guest User

Untitled

a guest
Mar 14th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. package me.ctucker.app.net.packet.impl;
  2.  
  3. import me.ctucker.app.net.Session;
  4. import me.ctucker.app.net.packet.Packet;
  5. import me.ctucker.app.net.packet.PacketOpcode;
  6. import me.ctucker.app.net.packet.PacketQueue;
  7.  
  8. import java.io.IOException;
  9. import java.nio.ByteBuffer;
  10.  
  11. @PacketOpcode(1)
  12. @PacketQueue(false) // Do not queue this packet.
  13. public class NonQueuedPacket extends Packet {
  14.  
  15.     private String username;
  16.     private String password;
  17.  
  18.     @Override
  19.     public void decodeTcp(Session session) throws IOException {
  20.         ByteBuffer buffer = session.getInputBuffer();
  21.         username = Packet.getString(buffer);
  22.         password = Packet.getString(buffer);
  23.     }
  24.  
  25.     @Override
  26.     public void execute(Session session) throws IOException {
  27.         if(username.equals("admin") && password.equals("admin")) {
  28.             Object[] data = new Object[] { 0, 1 };
  29.             Packet.send(
  30.                     PacketType.TCP, // The type of packet (UDP not implemented)
  31.                     session,        // The session to send the data to
  32.                     1,     // The opcode to send to the client.
  33.                     data            // The data to send to the client, this can be an Object[] OR use ... syntax
  34.             );
  35.         } else {
  36.             // Example of ... syntax below  This is the same as the above. You can add objects infinitely in parameters.
  37.             Packet.send(
  38.                     PacketType.TCP,
  39.                     session,
  40.                     1,
  41.                     0,
  42.                     1
  43.             );
  44.         }
  45.     }
  46.  
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement