mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 14:35:35 +00:00
Merge branch 'master' into mcpe-1.2
This commit is contained in:
commit
fbe2567e58
@ -33,27 +33,45 @@ class MemoryManager{
|
|||||||
/** @var Server */
|
/** @var Server */
|
||||||
private $server;
|
private $server;
|
||||||
|
|
||||||
|
/** @var int */
|
||||||
private $memoryLimit;
|
private $memoryLimit;
|
||||||
|
/** @var int */
|
||||||
private $globalMemoryLimit;
|
private $globalMemoryLimit;
|
||||||
|
/** @var int */
|
||||||
private $checkRate;
|
private $checkRate;
|
||||||
|
/** @var int */
|
||||||
private $checkTicker = 0;
|
private $checkTicker = 0;
|
||||||
|
/** @var bool */
|
||||||
private $lowMemory = false;
|
private $lowMemory = false;
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
private $continuousTrigger = true;
|
private $continuousTrigger = true;
|
||||||
|
/** @var int */
|
||||||
private $continuousTriggerRate;
|
private $continuousTriggerRate;
|
||||||
|
/** @var int */
|
||||||
private $continuousTriggerCount = 0;
|
private $continuousTriggerCount = 0;
|
||||||
|
/** @var int */
|
||||||
private $continuousTriggerTicker = 0;
|
private $continuousTriggerTicker = 0;
|
||||||
|
|
||||||
|
/** @var int */
|
||||||
private $garbageCollectionPeriod;
|
private $garbageCollectionPeriod;
|
||||||
|
/** @var int */
|
||||||
private $garbageCollectionTicker = 0;
|
private $garbageCollectionTicker = 0;
|
||||||
|
/** @var bool */
|
||||||
private $garbageCollectionTrigger;
|
private $garbageCollectionTrigger;
|
||||||
|
/** @var bool */
|
||||||
private $garbageCollectionAsync;
|
private $garbageCollectionAsync;
|
||||||
|
|
||||||
|
/** @var int */
|
||||||
private $chunkRadiusOverride;
|
private $chunkRadiusOverride;
|
||||||
|
/** @var bool */
|
||||||
private $chunkCollect;
|
private $chunkCollect;
|
||||||
|
/** @var bool */
|
||||||
private $chunkTrigger;
|
private $chunkTrigger;
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
private $chunkCache;
|
private $chunkCache;
|
||||||
|
/** @var bool */
|
||||||
private $cacheTrigger;
|
private $cacheTrigger;
|
||||||
|
|
||||||
public function __construct(Server $server){
|
public function __construct(Server $server){
|
||||||
@ -116,10 +134,16 @@ class MemoryManager{
|
|||||||
gc_enable();
|
gc_enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function isLowMemory() : bool{
|
public function isLowMemory() : bool{
|
||||||
return $this->lowMemory;
|
return $this->lowMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function canUseChunkCache() : bool{
|
public function canUseChunkCache() : bool{
|
||||||
return !($this->lowMemory and $this->chunkTrigger);
|
return !($this->lowMemory and $this->chunkTrigger);
|
||||||
}
|
}
|
||||||
@ -132,10 +156,18 @@ class MemoryManager{
|
|||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getViewDistance(int $distance) : int{
|
public function getViewDistance(int $distance) : int{
|
||||||
return $this->lowMemory ? min($this->chunkRadiusOverride, $distance) : $distance;
|
return $this->lowMemory ? (int) min($this->chunkRadiusOverride, $distance) : $distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function trigger($memory, $limit, $global = false, $triggerCount = 0){
|
/**
|
||||||
|
* Triggers garbage collection and cache cleanup to try and free memory.
|
||||||
|
*
|
||||||
|
* @param int $memory
|
||||||
|
* @param int $limit
|
||||||
|
* @param bool $global
|
||||||
|
* @param int $triggerCount
|
||||||
|
*/
|
||||||
|
public function trigger(int $memory, int $limit, bool $global = false, int $triggerCount = 0){
|
||||||
$this->server->getLogger()->debug(sprintf("[Memory Manager] %sLow memory triggered, limit %gMB, using %gMB",
|
$this->server->getLogger()->debug(sprintf("[Memory Manager] %sLow memory triggered, limit %gMB, using %gMB",
|
||||||
$global ? "Global " : "", round(($limit / 1024) / 1024, 2), round(($memory / 1024) / 1024, 2)));
|
$global ? "Global " : "", round(($limit / 1024) / 1024, 2), round(($memory / 1024) / 1024, 2)));
|
||||||
if($this->cacheTrigger){
|
if($this->cacheTrigger){
|
||||||
@ -161,6 +193,9 @@ class MemoryManager{
|
|||||||
$this->server->getLogger()->debug(sprintf("[Memory Manager] Freed %gMB, $cycles cycles", round(($ev->getMemoryFreed() / 1024) / 1024, 2)));
|
$this->server->getLogger()->debug(sprintf("[Memory Manager] Freed %gMB, $cycles cycles", round(($ev->getMemoryFreed() / 1024) / 1024, 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called every tick to update the memory manager state.
|
||||||
|
*/
|
||||||
public function check(){
|
public function check(){
|
||||||
Timings::$memoryManagerTimer->startTiming();
|
Timings::$memoryManagerTimer->startTiming();
|
||||||
|
|
||||||
@ -198,7 +233,10 @@ class MemoryManager{
|
|||||||
Timings::$memoryManagerTimer->stopTiming();
|
Timings::$memoryManagerTimer->stopTiming();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function triggerGarbageCollector(){
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function triggerGarbageCollector() : int{
|
||||||
Timings::$garbageCollectorTimer->startTiming();
|
Timings::$garbageCollectorTimer->startTiming();
|
||||||
|
|
||||||
if($this->garbageCollectionAsync){
|
if($this->garbageCollectionAsync){
|
||||||
@ -215,7 +253,14 @@ class MemoryManager{
|
|||||||
return $cycles;
|
return $cycles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dumpServerMemory($outputFolder, $maxNesting, $maxStringSize){
|
/**
|
||||||
|
* Dumps the server memory into the specified output folder.
|
||||||
|
*
|
||||||
|
* @param string $outputFolder
|
||||||
|
* @param int $maxNesting
|
||||||
|
* @param int $maxStringSize
|
||||||
|
*/
|
||||||
|
public function dumpServerMemory(string $outputFolder, int $maxNesting, int $maxStringSize){
|
||||||
$hardLimit = ini_get('memory_limit');
|
$hardLimit = ini_get('memory_limit');
|
||||||
ini_set('memory_limit', '-1');
|
ini_set('memory_limit', '-1');
|
||||||
gc_disable();
|
gc_disable();
|
||||||
@ -328,7 +373,16 @@ class MemoryManager{
|
|||||||
gc_enable();
|
gc_enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function continueDump($from, &$data, &$objects, &$refCounts, $recursion, $maxNesting, $maxStringSize){
|
/**
|
||||||
|
* @param mixed $from
|
||||||
|
* @param mixed &$data
|
||||||
|
* @param object[] &$objects
|
||||||
|
* @param int[] &$refCounts
|
||||||
|
* @param int $recursion
|
||||||
|
* @param int $maxNesting
|
||||||
|
* @param int $maxStringSize
|
||||||
|
*/
|
||||||
|
private function continueDump($from, &$data, array &$objects, array &$refCounts, int $recursion, int $maxNesting, int $maxStringSize){
|
||||||
if($maxNesting <= 0){
|
if($maxNesting <= 0){
|
||||||
$data = "(error) NESTING LIMIT REACHED";
|
$data = "(error) NESTING LIMIT REACHED";
|
||||||
return;
|
return;
|
||||||
|
@ -119,20 +119,20 @@ class OfflinePlayer implements IPlayer, Metadatable{
|
|||||||
return $this->namedtag instanceof CompoundTag;
|
return $this->namedtag instanceof CompoundTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMetadata($metadataKey, MetadataValue $metadataValue){
|
public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){
|
||||||
$this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $metadataValue);
|
$this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $newMetadataValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMetadata($metadataKey){
|
public function getMetadata(string $metadataKey){
|
||||||
return $this->server->getPlayerMetadata()->getMetadata($this, $metadataKey);
|
return $this->server->getPlayerMetadata()->getMetadata($this, $metadataKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasMetadata($metadataKey){
|
public function hasMetadata(string $metadataKey) : bool{
|
||||||
return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey);
|
return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeMetadata($metadataKey, Plugin $plugin){
|
public function removeMetadata(string $metadataKey, Plugin $owningPlugin){
|
||||||
$this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $plugin);
|
$this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3878,20 +3878,20 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMetadata($metadataKey, MetadataValue $metadataValue){
|
public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){
|
||||||
$this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $metadataValue);
|
$this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $newMetadataValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMetadata($metadataKey){
|
public function getMetadata(string $metadataKey){
|
||||||
return $this->server->getPlayerMetadata()->getMetadata($this, $metadataKey);
|
return $this->server->getPlayerMetadata()->getMetadata($this, $metadataKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasMetadata($metadataKey){
|
public function hasMetadata(string $metadataKey) : bool{
|
||||||
return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey);
|
return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeMetadata($metadataKey, Plugin $plugin){
|
public function removeMetadata(string $metadataKey, Plugin $owningPlugin){
|
||||||
$this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $plugin);
|
$this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onChunkChanged(Chunk $chunk){
|
public function onChunkChanged(Chunk $chunk){
|
||||||
|
@ -436,7 +436,7 @@ class Block extends Position implements BlockIds, Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if the item can be broken with an specific Item
|
* Returns if the block can be broken with an specific Item
|
||||||
*
|
*
|
||||||
* @param Item $item
|
* @param Item $item
|
||||||
*
|
*
|
||||||
@ -830,13 +830,13 @@ class Block extends Position implements BlockIds, Metadatable{
|
|||||||
return MovingObjectPosition::fromBlock($this->x, $this->y, $this->z, $f, $vector->add($this->x, $this->y, $this->z));
|
return MovingObjectPosition::fromBlock($this->x, $this->y, $this->z, $f, $vector->add($this->x, $this->y, $this->z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMetadata($metadataKey, MetadataValue $metadataValue){
|
public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){
|
||||||
if($this->getLevel() instanceof Level){
|
if($this->getLevel() instanceof Level){
|
||||||
$this->getLevel()->getBlockMetadata()->setMetadata($this, $metadataKey, $metadataValue);
|
$this->getLevel()->getBlockMetadata()->setMetadata($this, $metadataKey, $newMetadataValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMetadata($metadataKey){
|
public function getMetadata(string $metadataKey){
|
||||||
if($this->getLevel() instanceof Level){
|
if($this->getLevel() instanceof Level){
|
||||||
return $this->getLevel()->getBlockMetadata()->getMetadata($this, $metadataKey);
|
return $this->getLevel()->getBlockMetadata()->getMetadata($this, $metadataKey);
|
||||||
}
|
}
|
||||||
@ -844,15 +844,17 @@ class Block extends Position implements BlockIds, Metadatable{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasMetadata($metadataKey){
|
public function hasMetadata(string $metadataKey) : bool{
|
||||||
if($this->getLevel() instanceof Level){
|
if($this->getLevel() instanceof Level){
|
||||||
$this->getLevel()->getBlockMetadata()->hasMetadata($this, $metadataKey);
|
return $this->getLevel()->getBlockMetadata()->hasMetadata($this, $metadataKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeMetadata($metadataKey, Plugin $plugin){
|
public function removeMetadata(string $metadataKey, Plugin $owningPlugin){
|
||||||
if($this->getLevel() instanceof Level){
|
if($this->getLevel() instanceof Level){
|
||||||
$this->getLevel()->getBlockMetadata()->removeMetadata($this, $metadataKey, $plugin);
|
$this->getLevel()->getBlockMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ class PardonIpCommand extends VanillaCommand{
|
|||||||
|
|
||||||
if(preg_match("/^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$/", $args[0])){
|
if(preg_match("/^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$/", $args[0])){
|
||||||
$sender->getServer()->getIPBans()->remove($args[0]);
|
$sender->getServer()->getIPBans()->remove($args[0]);
|
||||||
|
$sender->getServer()->getNetwork()->unblockAddress($args[0]);
|
||||||
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.unbanip.success", [$args[0]]));
|
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.unbanip.success", [$args[0]]));
|
||||||
}else{
|
}else{
|
||||||
$sender->sendMessage(new TranslationContainer("commands.unbanip.invalid"));
|
$sender->sendMessage(new TranslationContainer("commands.unbanip.invalid"));
|
||||||
|
@ -1902,20 +1902,21 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
$this->close();
|
$this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMetadata($metadataKey, MetadataValue $metadataValue){
|
|
||||||
$this->server->getEntityMetadata()->setMetadata($this, $metadataKey, $metadataValue);
|
public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){
|
||||||
|
$this->server->getEntityMetadata()->setMetadata($this, $metadataKey, $newMetadataValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMetadata($metadataKey){
|
public function getMetadata(string $metadataKey){
|
||||||
return $this->server->getEntityMetadata()->getMetadata($this, $metadataKey);
|
return $this->server->getEntityMetadata()->getMetadata($this, $metadataKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasMetadata($metadataKey){
|
public function hasMetadata(string $metadataKey) : bool{
|
||||||
return $this->server->getEntityMetadata()->hasMetadata($this, $metadataKey);
|
return $this->server->getEntityMetadata()->hasMetadata($this, $metadataKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeMetadata($metadataKey, Plugin $plugin){
|
public function removeMetadata(string $metadataKey, Plugin $owningPlugin){
|
||||||
$this->server->getEntityMetadata()->removeMetadata($this, $metadataKey, $plugin);
|
$this->server->getEntityMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(){
|
public function __toString(){
|
||||||
|
@ -2905,19 +2905,19 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMetadata($metadataKey, MetadataValue $metadataValue){
|
public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){
|
||||||
$this->server->getLevelMetadata()->setMetadata($this, $metadataKey, $metadataValue);
|
$this->server->getLevelMetadata()->setMetadata($this, $metadataKey, $newMetadataValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMetadata($metadataKey){
|
public function getMetadata(string $metadataKey){
|
||||||
return $this->server->getLevelMetadata()->getMetadata($this, $metadataKey);
|
return $this->server->getLevelMetadata()->getMetadata($this, $metadataKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasMetadata($metadataKey){
|
public function hasMetadata(string $metadataKey) : bool{
|
||||||
return $this->server->getLevelMetadata()->hasMetadata($this, $metadataKey);
|
return $this->server->getLevelMetadata()->hasMetadata($this, $metadataKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeMetadata($metadataKey, Plugin $plugin){
|
public function removeMetadata(string $metadataKey, Plugin $owningPlugin){
|
||||||
$this->server->getLevelMetadata()->removeMetadata($this, $metadataKey, $plugin);
|
$this->server->getLevelMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,8 @@ interface Metadatable{
|
|||||||
*
|
*
|
||||||
* @param string $metadataKey
|
* @param string $metadataKey
|
||||||
* @param MetadataValue $newMetadataValue
|
* @param MetadataValue $newMetadataValue
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function setMetadata($metadataKey, MetadataValue $newMetadataValue);
|
public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of previously set metadata values from the implementing
|
* Returns a list of previously set metadata values from the implementing
|
||||||
@ -45,7 +43,7 @@ interface Metadatable{
|
|||||||
*
|
*
|
||||||
* @return MetadataValue[]
|
* @return MetadataValue[]
|
||||||
*/
|
*/
|
||||||
public function getMetadata($metadataKey);
|
public function getMetadata(string $metadataKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests to see whether the implementing object contains the given
|
* Tests to see whether the implementing object contains the given
|
||||||
@ -55,7 +53,7 @@ interface Metadatable{
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function hasMetadata($metadataKey);
|
public function hasMetadata(string $metadataKey) : bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the given metadata value from the implementing object's
|
* Removes the given metadata value from the implementing object's
|
||||||
@ -63,9 +61,7 @@ interface Metadatable{
|
|||||||
*
|
*
|
||||||
* @param string $metadataKey
|
* @param string $metadataKey
|
||||||
* @param Plugin $owningPlugin
|
* @param Plugin $owningPlugin
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function removeMetadata($metadataKey, Plugin $owningPlugin);
|
public function removeMetadata(string $metadataKey, Plugin $owningPlugin);
|
||||||
|
|
||||||
}
|
}
|
@ -34,6 +34,11 @@ interface AdvancedSourceInterface extends SourceInterface{
|
|||||||
*/
|
*/
|
||||||
public function blockAddress(string $address, int $timeout = 300);
|
public function blockAddress(string $address, int $timeout = 300);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $address
|
||||||
|
*/
|
||||||
|
public function unblockAddress(string $address);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Network $network
|
* @param Network $network
|
||||||
*/
|
*/
|
||||||
|
@ -171,4 +171,10 @@ class Network{
|
|||||||
$interface->blockAddress($address, $timeout);
|
$interface->blockAddress($address, $timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function unblockAddress(string $address){
|
||||||
|
foreach($this->advancedInterfaces as $interface){
|
||||||
|
$interface->unblockAddress($address);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,6 +152,10 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
|
|||||||
$this->interface->blockAddress($address, $timeout);
|
$this->interface->blockAddress($address, $timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function unblockAddress(string $address){
|
||||||
|
$this->interface->unblockAddress($address);
|
||||||
|
}
|
||||||
|
|
||||||
public function handleRaw($address, $port, $payload){
|
public function handleRaw($address, $port, $payload){
|
||||||
$this->server->handlePacket($address, $port, $payload);
|
$this->server->handlePacket($address, $port, $payload);
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit ddd953f0e2a6577dd39f0a450546dad12a472b01
|
Subproject commit 5d1c052cc6668576d116a7ab246820d75c885382
|
Loading…
x
Reference in New Issue
Block a user