Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.ctucker.app.net.packet.impl;
- import me.ctucker.app.net.Session;
- import me.ctucker.app.net.packet.Packet;
- import me.ctucker.app.net.packet.PacketOpcode;
- import me.ctucker.app.net.packet.PacketQueue;
- import java.io.IOException;
- import java.nio.ByteBuffer;
- @PacketOpcode(1)
- @PacketQueue(false) // Do not queue this packet.
- public class NonQueuedPacket extends Packet {
- private String username;
- private String password;
- @Override
- public void decodeTcp(Session session) throws IOException {
- ByteBuffer buffer = session.getInputBuffer();
- username = Packet.getString(buffer);
- password = Packet.getString(buffer);
- }
- @Override
- public void execute(Session session) throws IOException {
- if(username.equals("admin") && password.equals("admin")) {
- Object[] data = new Object[] { 0, 1 };
- Packet.send(
- PacketType.TCP, // The type of packet (UDP not implemented)
- session, // The session to send the data to
- 1, // The opcode to send to the client.
- data // The data to send to the client, this can be an Object[] OR use ... syntax
- );
- } else {
- // Example of ... syntax below This is the same as the above. You can add objects infinitely in parameters.
- Packet.send(
- PacketType.TCP,
- session,
- 1,
- 0,
- 1
- );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement