cn.nukkit.raknet.RakNet Java Examples

The following examples show how to use cn.nukkit.raknet.RakNet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OPEN_CONNECTION_REQUEST_1.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void encode() {
    super.encode();
    this.put(RakNet.MAGIC);
    this.putByte(this.protocol);
    this.put(new byte[this.mtuSize - 18]);
}
 
Example #2
Source File: SessionManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void streamOpen(Session session) {
    String identifier = session.getAddress() + ":" + session.getPort();
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_OPEN_SESSION,
            new byte[]{(byte) (identifier.length() & 0xff)},
            identifier.getBytes(StandardCharsets.UTF_8),
            new byte[]{(byte) (session.getAddress().length() & 0xff)},
            session.getAddress().getBytes(StandardCharsets.UTF_8),
            Binary.writeShort(session.getPort()),
            Binary.writeLong(session.getID())
    );
    this.server.pushThreadToMainPacket(buffer);
}
 
Example #3
Source File: SessionManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void streamRAW(String address, int port, byte[] payload) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_RAW,
            new byte[]{(byte) (address.length() & 0xff)},
            address.getBytes(StandardCharsets.UTF_8),
            Binary.writeShort(port),
            payload
    );
    this.server.pushThreadToMainPacket(buffer);
}
 
Example #4
Source File: SessionManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void streamEncapsulated(Session session, EncapsulatedPacket packet, int flags) {
    String id = session.getAddress() + ":" + session.getPort();
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_ENCAPSULATED,
            new byte[]{(byte) (id.length() & 0xff)},
            id.getBytes(StandardCharsets.UTF_8),
            new byte[]{(byte) (flags & 0xff)},
            packet.toBinary(true)
    );
    this.server.pushThreadToMainPacket(buffer);
}
 
Example #5
Source File: OPEN_CONNECTION_REPLY_2.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void encode() {
    super.encode();
    this.put(RakNet.MAGIC);
    this.putLong(this.serverID);
    this.putAddress(this.clientAddress, this.clientPort);
    this.putShort(this.mtuSize);
    this.putByte((byte) 0); //server security
}
 
Example #6
Source File: SessionManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void streamClose(String identifier, String reason) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_CLOSE_SESSION,
            new byte[]{(byte) (identifier.length() & 0xff)},
            identifier.getBytes(StandardCharsets.UTF_8),
            new byte[]{(byte) (reason.length() & 0xff)},
            reason.getBytes(StandardCharsets.UTF_8)
    );
    this.server.pushThreadToMainPacket(buffer);
}
 
Example #7
Source File: ServerHandler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void sendEncapsulated(String identifier, EncapsulatedPacket packet, int flags) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_ENCAPSULATED,
            new byte[]{(byte) (identifier.length() & 0xff)},
            identifier.getBytes(StandardCharsets.UTF_8),
            new byte[]{(byte) (flags & 0xff)},
            packet.toBinary(true)
    );
    this.server.pushMainToThreadPacket(buffer);
}
 
Example #8
Source File: ServerHandler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void sendRaw(String address, int port, byte[] payload) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_RAW,
            new byte[]{(byte) (address.length() & 0xff)},
            address.getBytes(StandardCharsets.UTF_8),
            Binary.writeShort(port),
            payload
    );
    this.server.pushMainToThreadPacket(buffer);
}
 
Example #9
Source File: ServerHandler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void closeSession(String identifier, String reason) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_CLOSE_SESSION,
            new byte[]{(byte) (identifier.length() & 0xff)},
            identifier.getBytes(StandardCharsets.UTF_8),
            new byte[]{(byte) (reason.length() & 0xff)},
            reason.getBytes(StandardCharsets.UTF_8)
    );
    this.server.pushMainToThreadPacket(buffer);
}
 
Example #10
Source File: ServerHandler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void sendOption(String name, String value) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_SET_OPTION,
            new byte[]{(byte) (name.length() & 0xff)},
            name.getBytes(StandardCharsets.UTF_8),
            value.getBytes(StandardCharsets.UTF_8)
    );
    this.server.pushMainToThreadPacket(buffer);
}
 
Example #11
Source File: ServerHandler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void blockAddress(String address, int timeout) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_BLOCK_ADDRESS,
            new byte[]{(byte) (address.length() & 0xff)},
            address.getBytes(StandardCharsets.UTF_8),
            Binary.writeInt(timeout)
    );
    this.server.pushMainToThreadPacket(buffer);
}
 
Example #12
Source File: ServerHandler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void unblockAddress(String address) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_UNBLOCK_ADDRESS,
            new byte[]{(byte) (address.length() & 0xff)},
            address.getBytes(StandardCharsets.UTF_8)
    );
    this.server.pushMainToThreadPacket(buffer);
}
 
Example #13
Source File: ServerHandler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void invalidSession(String identifier) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_INVALID_SESSION,
            new byte[]{(byte) (identifier.length() & 0xff)},
            identifier.getBytes(StandardCharsets.UTF_8)
    );
    this.server.pushMainToThreadPacket(buffer);
}
 
Example #14
Source File: SessionManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void streamOption(String name, String value) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_SET_OPTION,
            new byte[]{(byte) (name.length() & 0xff)},
            name.getBytes(StandardCharsets.UTF_8),
            value.getBytes(StandardCharsets.UTF_8)
    );
    this.server.pushThreadToMainPacket(buffer);
}
 
Example #15
Source File: OPEN_CONNECTION_REPLY_1.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void encode() {
    super.encode();
    this.put(RakNet.MAGIC);
    this.putLong(this.serverID);
    this.putByte((byte) 0); //server security
    this.putShort(this.mtuSize);
}
 
Example #16
Source File: UNCONNECTED_PONG.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void encode() {
    super.encode();
    this.putLong(this.pingID);
    this.putLong(this.serverID);
    this.put(RakNet.MAGIC);
    this.putString(this.serverName);
}
 
Example #17
Source File: OPEN_CONNECTION_REQUEST_2.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void encode() {
    super.encode();
    this.put(RakNet.MAGIC);
    this.putAddress(this.serverAddress, this.serverPort);
    this.putShort(this.mtuSize);
    this.putLong(this.clientID);
}
 
Example #18
Source File: ServerHandler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void invalidSession(String identifier) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_INVALID_SESSION,
            new byte[]{(byte) (identifier.length() & 0xff)},
            identifier.getBytes(StandardCharsets.UTF_8)
    );
    this.server.pushMainToThreadPacket(buffer);
}
 
Example #19
Source File: ServerHandler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void unblockAddress(String address) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_UNBLOCK_ADDRESS,
            new byte[]{(byte) (address.length() & 0xff)},
            address.getBytes(StandardCharsets.UTF_8)
    );
    this.server.pushMainToThreadPacket(buffer);
}
 
Example #20
Source File: ServerHandler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void blockAddress(String address, int timeout) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_BLOCK_ADDRESS,
            new byte[]{(byte) (address.length() & 0xff)},
            address.getBytes(StandardCharsets.UTF_8),
            Binary.writeInt(timeout)
    );
    this.server.pushMainToThreadPacket(buffer);
}
 
Example #21
Source File: ServerHandler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void sendOption(String name, String value) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_SET_OPTION,
            new byte[]{(byte) (name.length() & 0xff)},
            name.getBytes(StandardCharsets.UTF_8),
            value.getBytes(StandardCharsets.UTF_8)
    );
    this.server.pushMainToThreadPacket(buffer);
}
 
Example #22
Source File: ServerHandler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void closeSession(String identifier, String reason) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_CLOSE_SESSION,
            new byte[]{(byte) (identifier.length() & 0xff)},
            identifier.getBytes(StandardCharsets.UTF_8),
            new byte[]{(byte) (reason.length() & 0xff)},
            reason.getBytes(StandardCharsets.UTF_8)
    );
    this.server.pushMainToThreadPacket(buffer);
}
 
Example #23
Source File: ServerHandler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void sendRaw(String address, int port, byte[] payload) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_RAW,
            new byte[]{(byte) (address.length() & 0xff)},
            address.getBytes(StandardCharsets.UTF_8),
            Binary.writeShort(port),
            payload
    );
    this.server.pushMainToThreadPacket(buffer);
}
 
Example #24
Source File: ServerHandler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void sendEncapsulated(String identifier, EncapsulatedPacket packet, int flags) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_ENCAPSULATED,
            new byte[]{(byte) (identifier.length() & 0xff)},
            identifier.getBytes(StandardCharsets.UTF_8),
            new byte[]{(byte) (flags & 0xff)},
            packet.toBinary(true)
    );
    this.server.pushMainToThreadPacket(buffer);
}
 
Example #25
Source File: OPEN_CONNECTION_REQUEST_2.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void encode() {
    super.encode();
    this.put(RakNet.MAGIC);
    this.putAddress(this.serverAddress, this.serverPort);
    this.putShort(this.mtuSize);
    this.putLong(this.clientID);
}
 
Example #26
Source File: SessionManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void streamACK(String identifier, int identifierACK) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_ACK_NOTIFICATION,
            new byte[]{(byte) (identifier.length() & 0xff)},
            identifier.getBytes(StandardCharsets.UTF_8),
            Binary.writeInt(identifierACK)
    );
    this.server.pushThreadToMainPacket(buffer);
}
 
Example #27
Source File: SessionManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void streamOpen(Session session) {
    String identifier = session.getAddress() + ":" + session.getPort();
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_OPEN_SESSION,
            new byte[]{(byte) (identifier.length() & 0xff)},
            identifier.getBytes(StandardCharsets.UTF_8),
            new byte[]{(byte) (session.getAddress().length() & 0xff)},
            session.getAddress().getBytes(StandardCharsets.UTF_8),
            Binary.writeShort(session.getPort()),
            Binary.writeLong(session.getID())
    );
    this.server.pushThreadToMainPacket(buffer);
}
 
Example #28
Source File: SessionManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void streamInvalid(String identifier) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_INVALID_SESSION,
            new byte[]{(byte) (identifier.length() & 0xff)},
            identifier.getBytes(StandardCharsets.UTF_8)
    );
    this.server.pushThreadToMainPacket(buffer);
}
 
Example #29
Source File: SessionManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void streamClose(String identifier, String reason) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_CLOSE_SESSION,
            new byte[]{(byte) (identifier.length() & 0xff)},
            identifier.getBytes(StandardCharsets.UTF_8),
            new byte[]{(byte) (reason.length() & 0xff)},
            reason.getBytes(StandardCharsets.UTF_8)
    );
    this.server.pushThreadToMainPacket(buffer);
}
 
Example #30
Source File: SessionManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void streamRAW(String address, int port, byte[] payload) {
    byte[] buffer = Binary.appendBytes(
            RakNet.PACKET_RAW,
            new byte[]{(byte) (address.length() & 0xff)},
            address.getBytes(StandardCharsets.UTF_8),
            Binary.writeShort(port),
            payload
    );
    this.server.pushThreadToMainPacket(buffer);
}