mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 01:39:52 +00:00
Fixed raw packets in the buffer pre-ban still getting processed post-ban
This commit is contained in:
parent
6990d6239e
commit
d0940e4be2
@ -33,6 +33,8 @@ use function bin2hex;
|
|||||||
use function get_class;
|
use function get_class;
|
||||||
use function preg_match;
|
use function preg_match;
|
||||||
use function spl_object_id;
|
use function spl_object_id;
|
||||||
|
use function time;
|
||||||
|
use const PHP_INT_MAX;
|
||||||
|
|
||||||
class Network{
|
class Network{
|
||||||
/** @var NetworkInterface[] */
|
/** @var NetworkInterface[] */
|
||||||
@ -44,6 +46,9 @@ class Network{
|
|||||||
/** @var RawPacketHandler[] */
|
/** @var RawPacketHandler[] */
|
||||||
private $rawPacketHandlers = [];
|
private $rawPacketHandlers = [];
|
||||||
|
|
||||||
|
/** @var int[] */
|
||||||
|
private $bannedIps = [];
|
||||||
|
|
||||||
private $upload = 0;
|
private $upload = 0;
|
||||||
private $download = 0;
|
private $download = 0;
|
||||||
|
|
||||||
@ -118,6 +123,9 @@ class Network{
|
|||||||
if($interface instanceof AdvancedNetworkInterface){
|
if($interface instanceof AdvancedNetworkInterface){
|
||||||
$this->advancedInterfaces[$hash] = $interface;
|
$this->advancedInterfaces[$hash] = $interface;
|
||||||
$interface->setNetwork($this);
|
$interface->setNetwork($this);
|
||||||
|
foreach($this->bannedIps as $ip => $until){
|
||||||
|
$interface->blockAddress($ip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$interface->setName($this->name);
|
$interface->setName($this->name);
|
||||||
}
|
}
|
||||||
@ -179,12 +187,14 @@ class Network{
|
|||||||
* @param int $timeout
|
* @param int $timeout
|
||||||
*/
|
*/
|
||||||
public function blockAddress(string $address, int $timeout = 300) : void{
|
public function blockAddress(string $address, int $timeout = 300) : void{
|
||||||
|
$this->bannedIps[$address] = $timeout > 0 ? time() + $timeout : PHP_INT_MAX;
|
||||||
foreach($this->advancedInterfaces as $interface){
|
foreach($this->advancedInterfaces as $interface){
|
||||||
$interface->blockAddress($address, $timeout);
|
$interface->blockAddress($address, $timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unblockAddress(string $address) : void{
|
public function unblockAddress(string $address) : void{
|
||||||
|
unset($this->bannedIps[$address]);
|
||||||
foreach($this->advancedInterfaces as $interface){
|
foreach($this->advancedInterfaces as $interface){
|
||||||
$interface->unblockAddress($address);
|
$interface->unblockAddress($address);
|
||||||
}
|
}
|
||||||
@ -220,6 +230,10 @@ class Network{
|
|||||||
* @param string $packet
|
* @param string $packet
|
||||||
*/
|
*/
|
||||||
public function processRawPacket(AdvancedNetworkInterface $interface, string $address, int $port, string $packet) : void{
|
public function processRawPacket(AdvancedNetworkInterface $interface, string $address, int $port, string $packet) : void{
|
||||||
|
if(isset($this->bannedIps[$address]) and time() < $this->bannedIps[$address]){
|
||||||
|
$this->logger->debug("Dropped raw packet from banned address $address $port");
|
||||||
|
return;
|
||||||
|
}
|
||||||
$handled = false;
|
$handled = false;
|
||||||
foreach($this->rawPacketHandlers as $handler){
|
foreach($this->rawPacketHandlers as $handler){
|
||||||
if(preg_match($handler->getPattern(), $packet) === 1){
|
if(preg_match($handler->getPattern(), $packet) === 1){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user