cn.nukkit.raknet.protocol.EncapsulatedPacket Java Examples
The following examples show how to use
cn.nukkit.raknet.protocol.EncapsulatedPacket.
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: ServerHandler.java From Jupiter with GNU General Public License v3.0 | 5 votes |
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 #2
Source File: ServerHandler.java From Nukkit with GNU General Public License v3.0 | 5 votes |
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 #3
Source File: RakNetInterface.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void handleEncapsulated(String identifier, EncapsulatedPacket packet, int flags) { if (this.players.containsKey(identifier)) { DataPacket pk = null; try { if (packet.buffer.length > 0) { if (packet.buffer[0] == PING_DataPacket.ID) { PING_DataPacket pingPacket = new PING_DataPacket(); pingPacket.buffer = packet.buffer; pingPacket.decode(); this.networkLatency.put(identifier, (int) pingPacket.pingID); return; } pk = this.getPacket(packet.buffer); if (pk != null) { pk.decode(); this.players.get(identifier).handleDataPacket(pk); } } } catch (Exception e) { this.server.getLogger().logException(e); if (Nukkit.DEBUG > 1 && pk != null) { MainLogger logger = this.server.getLogger(); // if (logger != null) { logger.debug("Packet " + pk.getClass().getName() + " 0x" + Binary.bytesToHexString(packet.buffer)); //logger.logException(e); // } } if (this.players.containsKey(identifier)) { this.handler.blockAddress(this.players.get(identifier).getAddress(), 5); } } } }
Example #4
Source File: Session.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void handleEncapsulatedPacket(EncapsulatedPacket packet) throws Exception { if (packet.messageIndex == null) { this.handleEncapsulatedPacketRoute(packet); } else { if (packet.messageIndex < this.reliableWindowStart || packet.messageIndex > this.reliableWindowEnd) { return; } if ((packet.messageIndex - this.lastReliableIndex) == 1) { this.lastReliableIndex++; this.reliableWindowStart++; this.reliableWindowEnd++; this.handleEncapsulatedPacketRoute(packet); if (!this.reliableWindow.isEmpty()) { TreeMap<Integer, EncapsulatedPacket> sortedMap = new TreeMap<>(this.reliableWindow); for (int index : sortedMap.keySet()) { EncapsulatedPacket pk = this.reliableWindow.get(index); if ((index - this.lastReliableIndex) != 1) { break; } this.lastReliableIndex++; this.reliableWindowStart++; this.reliableWindowEnd++; this.handleEncapsulatedPacketRoute(pk); this.reliableWindow.remove(index); } } } else { this.reliableWindow.put(packet.messageIndex, packet); } } }
Example #5
Source File: Session.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void handleSplit(EncapsulatedPacket packet) throws Exception { if (packet.splitCount >= MAX_SPLIT_SIZE || packet.splitIndex >= MAX_SPLIT_SIZE || packet.splitIndex < 0) { return; } if (!this.splitPackets.containsKey(packet.splitID)) { if (this.splitPackets.size() >= MAX_SPLIT_COUNT) { return; } this.splitPackets.put(packet.splitID, new HashMap<Integer, EncapsulatedPacket>() {{ put(packet.splitIndex, packet); }}); } else { this.splitPackets.get(packet.splitID).put(packet.splitIndex, packet); } if (this.splitPackets.get(packet.splitID).size() == packet.splitCount) { EncapsulatedPacket pk = new EncapsulatedPacket(); BinaryStream stream = new BinaryStream(); for (int i = 0; i < packet.splitCount; i++) { stream.put(this.splitPackets.get(packet.splitID).get(i).buffer); } pk.buffer = stream.getBuffer(); pk.length = pk.buffer.length; this.splitPackets.remove(packet.splitID); this.handleEncapsulatedPacketRoute(pk); } }
Example #6
Source File: RakNetInterface.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public void handleEncapsulated(String identifier, EncapsulatedPacket packet, int flags) { if (this.players.containsKey(identifier)) { DataPacket pk = null; try { if (packet.buffer.length > 0) { if (packet.buffer[0] == PING_DataPacket.ID) { PING_DataPacket pingPacket = new PING_DataPacket(); pingPacket.buffer = packet.buffer; pingPacket.decode(); this.networkLatency.put(identifier, (int) pingPacket.pingID); return; } pk = this.getPacket(packet.buffer); if (pk != null) { pk.decode(); this.players.get(identifier).handleDataPacket(pk); } } } catch (Exception e) { this.server.getLogger().logException(e); if (Nukkit.DEBUG > 1 && pk != null) { MainLogger logger = this.server.getLogger(); // if (logger != null) { logger.debug("Packet " + pk.getClass().getName() + " 0x" + Binary.bytesToHexString(packet.buffer)); //logger.logException(e); // } } if (this.players.containsKey(identifier)) { this.handler.blockAddress(this.players.get(identifier).getAddress(), 5); } } } }
Example #7
Source File: Session.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void addToQueue(EncapsulatedPacket pk, int flags) throws Exception { int priority = flags & 0b0000111; if (pk.needACK && pk.messageIndex != null) { if (!this.needACK.containsKey(pk.identifierACK)) { this.needACK.put(pk.identifierACK, new HashMap<>()); } this.needACK.get(pk.identifierACK).put(pk.messageIndex, pk.messageIndex); } if (priority == RakNet.PRIORITY_IMMEDIATE) { //Skip queues DataPacket packet = new DATA_PACKET_0(); packet.seqNumber = this.sendSeqNumber++; if (pk.needACK) { packet.packets.add(pk.clone()); pk.needACK = false; } else { packet.packets.add(pk.toBinary()); } this.sendPacket(packet); packet.sendTime = System.currentTimeMillis(); this.recoveryQueue.put(packet.seqNumber, packet); return; } int length = this.sendQueue.length(); if (length + pk.getTotalLength() > this.mtuSize) { this.sendQueue(); } if (pk.needACK) { this.sendQueue.packets.add(pk.clone()); pk.needACK = false; } else { this.sendQueue.packets.add(pk.toBinary()); } }
Example #8
Source File: SessionManager.java From Nukkit with GNU General Public License v3.0 | 5 votes |
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 #9
Source File: SessionManager.java From Nukkit with GNU General Public License v3.0 | 5 votes |
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 #10
Source File: RakNetInterface.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void handleEncapsulated(String identifier, EncapsulatedPacket packet, int flags) { if (this.players.containsKey(identifier)) { DataPacket pk = null; try { if (packet.buffer.length > 0) { if (packet.buffer[0] == PING_DataPacket.ID) { PING_DataPacket pingPacket = new PING_DataPacket(); pingPacket.buffer = packet.buffer; pingPacket.decode(); this.networkLatency.put(identifier, (int) pingPacket.pingID); return; } pk = this.getPacket(packet.buffer); if (pk != null) { pk.decode(); this.players.get(identifier).handleDataPacket(pk); } } } catch (Exception e) { this.server.getLogger().logException(e); if (Nukkit.DEBUG > 1 && pk != null) { MainLogger logger = this.server.getLogger(); // if (logger != null) { logger.debug("Packet " + pk.getClass().getName() + " 0x" + Binary.bytesToHexString(packet.buffer)); //logger.logException(e); // } } if (this.players.containsKey(identifier)) { this.handler.blockAddress(this.players.get(identifier).getAddress(), 5); } } } }
Example #11
Source File: Session.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void addToQueue(EncapsulatedPacket pk, int flags) throws Exception { int priority = flags & 0b0000111; if (pk.needACK && pk.messageIndex != null) { if (!this.needACK.containsKey(pk.identifierACK)) { this.needACK.put(pk.identifierACK, new HashMap<>()); } this.needACK.get(pk.identifierACK).put(pk.messageIndex, pk.messageIndex); } if (priority == RakNet.PRIORITY_IMMEDIATE) { //Skip queues DataPacket packet = new DATA_PACKET_0(); packet.seqNumber = this.sendSeqNumber++; if (pk.needACK) { packet.packets.add(pk.clone()); pk.needACK = false; } else { packet.packets.add(pk.toBinary()); } this.sendPacket(packet); packet.sendTime = System.currentTimeMillis(); this.recoveryQueue.put(packet.seqNumber, packet); return; } int length = this.sendQueue.length(); if (length + pk.getTotalLength() > this.mtuSize) { this.sendQueue(); } if (pk.needACK) { this.sendQueue.packets.add(pk.clone()); pk.needACK = false; } else { this.sendQueue.packets.add(pk.toBinary()); } }
Example #12
Source File: Session.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void handleSplit(EncapsulatedPacket packet) throws Exception { if (packet.splitCount >= MAX_SPLIT_SIZE || packet.splitIndex >= MAX_SPLIT_SIZE || packet.splitIndex < 0) { return; } if (!this.splitPackets.containsKey(packet.splitID)) { if (this.splitPackets.size() >= MAX_SPLIT_COUNT) { return; } this.splitPackets.put(packet.splitID, new HashMap<Integer, EncapsulatedPacket>() {{ put(packet.splitIndex, packet); }}); } else { this.splitPackets.get(packet.splitID).put(packet.splitIndex, packet); } if (this.splitPackets.get(packet.splitID).size() == packet.splitCount) { EncapsulatedPacket pk = new EncapsulatedPacket(); BinaryStream stream = new BinaryStream(); for (int i = 0; i < packet.splitCount; i++) { stream.put(this.splitPackets.get(packet.splitID).get(i).buffer); } pk.buffer = stream.getBuffer(); pk.length = pk.buffer.length; this.splitPackets.remove(packet.splitID); this.handleEncapsulatedPacketRoute(pk); } }
Example #13
Source File: Session.java From Jupiter with GNU General Public License v3.0 | 5 votes |
private void handleEncapsulatedPacket(EncapsulatedPacket packet) throws Exception { if (packet.messageIndex == null) { this.handleEncapsulatedPacketRoute(packet); } else { if (packet.messageIndex < this.reliableWindowStart || packet.messageIndex > this.reliableWindowEnd) { return; } if ((packet.messageIndex - this.lastReliableIndex) == 1) { this.lastReliableIndex++; this.reliableWindowStart++; this.reliableWindowEnd++; this.handleEncapsulatedPacketRoute(packet); if (!this.reliableWindow.isEmpty()) { TreeMap<Integer, EncapsulatedPacket> sortedMap = new TreeMap<>(this.reliableWindow); for (int index : sortedMap.keySet()) { EncapsulatedPacket pk = this.reliableWindow.get(index); if ((index - this.lastReliableIndex) != 1) { break; } this.lastReliableIndex++; this.reliableWindowStart++; this.reliableWindowEnd++; this.handleEncapsulatedPacketRoute(pk); this.reliableWindow.remove(index); } } } else { this.reliableWindow.put(packet.messageIndex, packet); } } }
Example #14
Source File: Session.java From Jupiter with GNU General Public License v3.0 | 5 votes |
private void handleSplit(EncapsulatedPacket packet) throws Exception { if (packet.splitCount >= MAX_SPLIT_SIZE || packet.splitIndex >= MAX_SPLIT_SIZE || packet.splitIndex < 0) { return; } if (!this.splitPackets.containsKey(packet.splitID)) { if (this.splitPackets.size() >= MAX_SPLIT_COUNT) { return; } this.splitPackets.put(packet.splitID, new HashMap<Integer, EncapsulatedPacket>() {{ put(packet.splitIndex, packet); }}); } else { this.splitPackets.get(packet.splitID).put(packet.splitIndex, packet); } if (this.splitPackets.get(packet.splitID).size() == packet.splitCount) { EncapsulatedPacket pk = new EncapsulatedPacket(); BinaryStream stream = new BinaryStream(); for (int i = 0; i < packet.splitCount; i++) { stream.put(this.splitPackets.get(packet.splitID).get(i).buffer); } pk.buffer = stream.getBuffer(); pk.length = pk.buffer.length; this.splitPackets.remove(packet.splitID); this.handleEncapsulatedPacketRoute(pk); } }
Example #15
Source File: Session.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void handleEncapsulatedPacket(EncapsulatedPacket packet) throws Exception { if (packet.messageIndex == null) { this.handleEncapsulatedPacketRoute(packet); } else { if (packet.messageIndex < this.reliableWindowStart || packet.messageIndex > this.reliableWindowEnd) { return; } if ((packet.messageIndex - this.lastReliableIndex) == 1) { this.lastReliableIndex++; this.reliableWindowStart++; this.reliableWindowEnd++; this.handleEncapsulatedPacketRoute(packet); if (!this.reliableWindow.isEmpty()) { TreeMap<Integer, EncapsulatedPacket> sortedMap = new TreeMap<>(this.reliableWindow); for (int index : sortedMap.keySet()) { EncapsulatedPacket pk = this.reliableWindow.get(index); if ((index - this.lastReliableIndex) != 1) { break; } this.lastReliableIndex++; this.reliableWindowStart++; this.reliableWindowEnd++; this.handleEncapsulatedPacketRoute(pk); this.reliableWindow.remove(index); } } } else { this.reliableWindow.put(packet.messageIndex, packet); } } }
Example #16
Source File: Session.java From Jupiter with GNU General Public License v3.0 | 5 votes |
private void addToQueue(EncapsulatedPacket pk, int flags) throws Exception { int priority = flags & 0b00000111; if (pk.needACK && pk.messageIndex != null) { if (!this.needACK.containsKey(pk.identifierACK)) { this.needACK.put(pk.identifierACK, new HashMap<>()); } this.needACK.get(pk.identifierACK).put(pk.messageIndex, pk.messageIndex); } if (priority == RakNet.PRIORITY_IMMEDIATE) { //Skip queues DataPacket packet = new DATA_PACKET_0(); packet.seqNumber = this.sendSeqNumber++; if (pk.needACK) { packet.packets.add(pk.clone()); pk.needACK = false; } else { packet.packets.add(pk.toBinary()); } this.sendPacket(packet); packet.sendTime = System.currentTimeMillis(); this.recoveryQueue.put(packet.seqNumber, packet); return; } int length = this.sendQueue.length(); if (length + pk.getTotalLength() > this.mtuSize) { this.sendQueue(); } if (pk.needACK) { this.sendQueue.packets.add(pk.clone()); pk.needACK = false; } else { this.sendQueue.packets.add(pk.toBinary()); } }
Example #17
Source File: SessionManager.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public void streamEncapsulated(Session session, EncapsulatedPacket packet, int flags) { String id = FastAppender.get(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 #18
Source File: ServerHandler.java From Nukkit with GNU General Public License v3.0 | 5 votes |
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 #19
Source File: Session.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void addEncapsulatedToQueue(EncapsulatedPacket packet) throws Exception { addEncapsulatedToQueue(packet, RakNet.PRIORITY_NORMAL); }
Example #20
Source File: Session.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void addEncapsulatedToQueue(EncapsulatedPacket packet) throws Exception { addEncapsulatedToQueue(packet, RakNet.PRIORITY_NORMAL); }
Example #21
Source File: Session.java From Nukkit with GNU General Public License v3.0 | 4 votes |
private void addToQueue(EncapsulatedPacket pk) throws Exception { addToQueue(pk, RakNet.PRIORITY_NORMAL); }
Example #22
Source File: SessionManager.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean receiveStream() throws Exception { byte[] packet = this.server.readMainToThreadPacket(); if (packet != null && packet.length > 0) { byte id = packet[0]; int offset = 1; switch (id) { case RakNet.PACKET_ENCAPSULATED: int len = packet[offset++]; String identifier = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; if (this.sessions.containsKey(identifier)) { byte flags = packet[offset++]; byte[] buffer = Binary.subBytes(packet, offset); this.sessions.get(identifier).addEncapsulatedToQueue(EncapsulatedPacket.fromBinary(buffer, true), flags); } else { this.streamInvalid(identifier); } break; case RakNet.PACKET_RAW: len = packet[offset++]; String address = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; int port = Binary.readShort(Binary.subBytes(packet, offset, 2)); offset += 2; byte[] payload = Binary.subBytes(packet, offset); this.socket.writePacket(payload, address, port); break; case RakNet.PACKET_CLOSE_SESSION: len = packet[offset++]; identifier = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); if (this.sessions.containsKey(identifier)) { this.removeSession(this.sessions.get(identifier)); } else { this.streamInvalid(identifier); } break; case RakNet.PACKET_INVALID_SESSION: len = packet[offset++]; identifier = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); if (this.sessions.containsKey(identifier)) { this.removeSession(this.sessions.get(identifier)); } break; case RakNet.PACKET_SET_OPTION: len = packet[offset++]; String name = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; String value = new String(Binary.subBytes(packet, offset), StandardCharsets.UTF_8); switch (name) { case "name": this.name = value; break; case "portChecking": this.portChecking = Boolean.valueOf(value); break; case "packetLimit": this.packetLimit = Integer.valueOf(value); break; } break; case RakNet.PACKET_BLOCK_ADDRESS: len = packet[offset++]; address = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; int timeout = Binary.readInt(Binary.subBytes(packet, offset, 4)); this.blockAddress(address, timeout); break; case RakNet.PACKET_UNBLOCK_ADDRESS: len = packet[offset++]; address = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); this.unblockAddress(address); break; case RakNet.PACKET_SHUTDOWN: for (Session session : new ArrayList<>(this.sessions.values())) { this.removeSession(session); } this.socket.close(); this.shutdown = true; break; case RakNet.PACKET_EMERGENCY_SHUTDOWN: this.shutdown = true; default: return false; } return true; } return false; }
Example #23
Source File: Session.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void close() throws Exception { byte[] data = new byte[]{0x60, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15}; //CLIENT_DISCONNECT packet 0x15 this.addEncapsulatedToQueue(EncapsulatedPacket.fromBinary(data)); this.sessionManager = null; }
Example #24
Source File: ServerHandler.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void sendEncapsulated(String identifier, EncapsulatedPacket packet) { this.sendEncapsulated(identifier, packet, RakNet.PRIORITY_NORMAL); }
Example #25
Source File: SessionManager.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void streamEncapsulated(Session session, EncapsulatedPacket packet) { this.streamEncapsulated(session, packet, RakNet.PRIORITY_NORMAL); }
Example #26
Source File: ServerHandler.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void sendEncapsulated(String identifier, EncapsulatedPacket packet) { this.sendEncapsulated(identifier, packet, RakNet.PRIORITY_NORMAL); }
Example #27
Source File: Session.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void close() throws Exception { byte[] data = new byte[]{0x60, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15}; //CLIENT_DISCONNECT packet 0x15 this.addEncapsulatedToQueue(EncapsulatedPacket.fromBinary(data)); this.sessionManager = null; }
Example #28
Source File: Session.java From Nukkit with GNU General Public License v3.0 | 4 votes |
private void addToQueue(EncapsulatedPacket pk) throws Exception { addToQueue(pk, RakNet.PRIORITY_NORMAL); }
Example #29
Source File: SessionManager.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean receiveStream() throws Exception { byte[] packet = this.server.readMainToThreadPacket(); if (packet != null && packet.length > 0) { byte id = packet[0]; int offset = 1; switch (id) { case RakNet.PACKET_ENCAPSULATED: int len = packet[offset++]; String identifier = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; if (this.sessions.containsKey(identifier)) { byte flags = packet[offset++]; byte[] buffer = Binary.subBytes(packet, offset); this.sessions.get(identifier).addEncapsulatedToQueue(EncapsulatedPacket.fromBinary(buffer, true), flags); } else { this.streamInvalid(identifier); } break; case RakNet.PACKET_RAW: len = packet[offset++]; String address = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; int port = Binary.readShort(Binary.subBytes(packet, offset, 2)); offset += 2; byte[] payload = Binary.subBytes(packet, offset); this.socket.writePacket(payload, address, port); break; case RakNet.PACKET_CLOSE_SESSION: len = packet[offset++]; identifier = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); if (this.sessions.containsKey(identifier)) { this.removeSession(this.sessions.get(identifier)); } else { this.streamInvalid(identifier); } break; case RakNet.PACKET_INVALID_SESSION: len = packet[offset++]; identifier = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); if (this.sessions.containsKey(identifier)) { this.removeSession(this.sessions.get(identifier)); } break; case RakNet.PACKET_SET_OPTION: len = packet[offset++]; String name = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; String value = new String(Binary.subBytes(packet, offset), StandardCharsets.UTF_8); switch (name) { case "name": this.name = value; break; case "portChecking": this.portChecking = Boolean.valueOf(value); break; case "packetLimit": this.packetLimit = Integer.valueOf(value); break; } break; case RakNet.PACKET_BLOCK_ADDRESS: len = packet[offset++]; address = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; int timeout = Binary.readInt(Binary.subBytes(packet, offset, 4)); this.blockAddress(address, timeout); break; case RakNet.PACKET_UNBLOCK_ADDRESS: len = packet[offset++]; address = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); this.unblockAddress(address); break; case RakNet.PACKET_SHUTDOWN: for (Session session : new ArrayList<>(this.sessions.values())) { this.removeSession(session); } this.socket.close(); this.shutdown = true; break; case RakNet.PACKET_EMERGENCY_SHUTDOWN: this.shutdown = true; default: return false; } return true; } return false; }
Example #30
Source File: SessionManager.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void streamEncapsulated(Session session, EncapsulatedPacket packet) { this.streamEncapsulated(session, packet, RakNet.PRIORITY_NORMAL); }