mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-04 21:01:02 -05:00
Expose local and remote addresses of Sessions.
This commit is contained in:
parent
f846b96ab4
commit
b5bfe24517
2 changed files with 28 additions and 0 deletions
|
@ -5,6 +5,8 @@ import org.spacehq.packetlib.event.session.SessionListener;
|
|||
import org.spacehq.packetlib.packet.Packet;
|
||||
import org.spacehq.packetlib.packet.PacketProtocol;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -38,6 +40,20 @@ public interface Session {
|
|||
*/
|
||||
public int getPort();
|
||||
|
||||
/**
|
||||
* Gets the local address of the session.
|
||||
*
|
||||
* @return The local address, or null if the session is not connected.
|
||||
*/
|
||||
public SocketAddress getLocalAddress();
|
||||
|
||||
/**
|
||||
* Gets the remote address of the session.
|
||||
*
|
||||
* @return The remote address, or null if the session is not connected.
|
||||
*/
|
||||
public SocketAddress getRemoteAddress();
|
||||
|
||||
/**
|
||||
* Gets the packet protocol of the session.
|
||||
*
|
||||
|
|
|
@ -22,6 +22,8 @@ import org.spacehq.packetlib.packet.Packet;
|
|||
import org.spacehq.packetlib.packet.PacketProtocol;
|
||||
|
||||
import java.net.ConnectException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -74,6 +76,16 @@ public abstract class TcpSession extends SimpleChannelInboundHandler<Packet> imp
|
|||
return this.port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getLocalAddress() {
|
||||
return this.channel != null ? this.channel.localAddress() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getRemoteAddress() {
|
||||
return this.channel != null ? this.channel.remoteAddress() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketProtocol getPacketProtocol() {
|
||||
return this.protocol;
|
||||
|
|
Loading…
Reference in a new issue