mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 18:29:46 +00:00
Move IP/port to NetworkSession
This commit is contained in:
parent
f969f3b77f
commit
85647c03bf
@ -189,11 +189,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
/** @var int */
|
/** @var int */
|
||||||
protected $protocol = -1;
|
protected $protocol = -1;
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
protected $ip;
|
|
||||||
/** @var int */
|
|
||||||
protected $port;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
* Last measurement of player's latency in milliseconds.
|
* Last measurement of player's latency in milliseconds.
|
||||||
@ -698,8 +693,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
$this->perm = new PermissibleBase($this);
|
$this->perm = new PermissibleBase($this);
|
||||||
$this->namedtag = new CompoundTag();
|
$this->namedtag = new CompoundTag();
|
||||||
$this->server = Server::getInstance();
|
$this->server = Server::getInstance();
|
||||||
$this->ip = $ip;
|
|
||||||
$this->port = $port;
|
|
||||||
$this->loaderId = Level::generateChunkLoaderId($this);
|
$this->loaderId = Level::generateChunkLoaderId($this);
|
||||||
$this->chunksPerTick = (int) $this->server->getProperty("chunk-sending.per-tick", 4);
|
$this->chunksPerTick = (int) $this->server->getProperty("chunk-sending.per-tick", 4);
|
||||||
$this->spawnThreshold = (int) (($this->server->getProperty("chunk-sending.spawn-radius", 4) ** 2) * M_PI);
|
$this->spawnThreshold = (int) (($this->server->getProperty("chunk-sending.spawn-radius", 4) ** 2) * M_PI);
|
||||||
@ -711,7 +704,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
|
|
||||||
$this->allowMovementCheats = (bool) $this->server->getProperty("player.anti-cheat.allow-movement-cheats", false);
|
$this->allowMovementCheats = (bool) $this->server->getProperty("player.anti-cheat.allow-movement-cheats", false);
|
||||||
|
|
||||||
$this->networkSession = new NetworkSession($this->server, $this, $interface);
|
$this->networkSession = new NetworkSession($this->server, $this, $interface, $ip, $port);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -806,14 +799,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getAddress() : string{
|
public function getAddress() : string{
|
||||||
return $this->ip;
|
return $this->networkSession->getIp();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getPort() : int{
|
public function getPort() : int{
|
||||||
return $this->port;
|
return $this->networkSession->getPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2106,8 +2099,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
|
|
||||||
$this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logIn", [
|
$this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logIn", [
|
||||||
TextFormat::AQUA . $this->username . TextFormat::WHITE,
|
TextFormat::AQUA . $this->username . TextFormat::WHITE,
|
||||||
$this->ip,
|
$this->networkSession->getIp(),
|
||||||
$this->port,
|
$this->networkSession->getPort(),
|
||||||
$this->id,
|
$this->id,
|
||||||
$this->level->getName(),
|
$this->level->getName(),
|
||||||
round($this->x, 4),
|
round($this->x, 4),
|
||||||
@ -3301,6 +3294,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
if($this->isConnected() and !$this->closed){
|
if($this->isConnected() and !$this->closed){
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
$ip = $this->networkSession->getIp();
|
||||||
|
$port = $this->networkSession->getPort();
|
||||||
$this->networkSession->serverDisconnect($reason, $notify);
|
$this->networkSession->serverDisconnect($reason, $notify);
|
||||||
$this->networkSession = null;
|
$this->networkSession = null;
|
||||||
|
|
||||||
@ -3364,8 +3359,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
|
|
||||||
$this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logOut", [
|
$this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logOut", [
|
||||||
TextFormat::AQUA . $this->getName() . TextFormat::WHITE,
|
TextFormat::AQUA . $this->getName() . TextFormat::WHITE,
|
||||||
$this->ip,
|
$ip,
|
||||||
$this->port,
|
$port,
|
||||||
$this->getServer()->getLanguage()->translateString($reason)
|
$this->getServer()->getLanguage()->translateString($reason)
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
@ -152,11 +152,32 @@ class NetworkSession{
|
|||||||
private $player;
|
private $player;
|
||||||
/** @var NetworkInterface */
|
/** @var NetworkInterface */
|
||||||
private $interface;
|
private $interface;
|
||||||
|
/** @var string */
|
||||||
|
private $ip;
|
||||||
|
/** @var int */
|
||||||
|
private $port;
|
||||||
|
|
||||||
public function __construct(Server $server, Player $player, NetworkInterface $interface){
|
public function __construct(Server $server, Player $player, NetworkInterface $interface, string $ip, int $port){
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
$this->player = $player;
|
$this->player = $player;
|
||||||
$this->interface = $interface;
|
$this->interface = $interface;
|
||||||
|
|
||||||
|
$this->ip = $ip;
|
||||||
|
$this->port = $port;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getIp() : string{
|
||||||
|
return $this->ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getPort() : int{
|
||||||
|
return $this->port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleDataPacket(DataPacket $packet) : void{
|
public function handleDataPacket(DataPacket $packet) : void{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user