From e9a87978a60fe567cb52cd93b955f77cb282e072 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 7 Apr 2019 15:07:24 +0100 Subject: [PATCH 1/4] Fixed usages of commands.generic.permission apparently this doesn't exist in the client anymore --- src/pocketmine/command/defaults/KillCommand.php | 4 ++-- src/pocketmine/command/defaults/TimeCommand.php | 10 +++++----- src/pocketmine/command/defaults/WhitelistCommand.php | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/command/defaults/KillCommand.php b/src/pocketmine/command/defaults/KillCommand.php index 7d2216915e..b6326aedd7 100644 --- a/src/pocketmine/command/defaults/KillCommand.php +++ b/src/pocketmine/command/defaults/KillCommand.php @@ -55,7 +55,7 @@ class KillCommand extends VanillaCommand{ if(count($args) === 1){ if(!$sender->hasPermission("pocketmine.command.kill.other")){ - $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission")); + $sender->sendMessage($sender->getServer()->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission")); return true; } @@ -74,7 +74,7 @@ class KillCommand extends VanillaCommand{ if($sender instanceof Player){ if(!$sender->hasPermission("pocketmine.command.kill.self")){ - $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission")); + $sender->sendMessage($sender->getServer()->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission")); return true; } diff --git a/src/pocketmine/command/defaults/TimeCommand.php b/src/pocketmine/command/defaults/TimeCommand.php index 61a9967e14..db88d63fbc 100644 --- a/src/pocketmine/command/defaults/TimeCommand.php +++ b/src/pocketmine/command/defaults/TimeCommand.php @@ -50,7 +50,7 @@ class TimeCommand extends VanillaCommand{ if($args[0] === "start"){ if(!$sender->hasPermission("pocketmine.command.time.start")){ - $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission")); + $sender->sendMessage($sender->getServer()->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission")); return true; } @@ -61,7 +61,7 @@ class TimeCommand extends VanillaCommand{ return true; }elseif($args[0] === "stop"){ if(!$sender->hasPermission("pocketmine.command.time.stop")){ - $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission")); + $sender->sendMessage($sender->getServer()->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission")); return true; } @@ -72,7 +72,7 @@ class TimeCommand extends VanillaCommand{ return true; }elseif($args[0] === "query"){ if(!$sender->hasPermission("pocketmine.command.time.query")){ - $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission")); + $sender->sendMessage($sender->getServer()->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission")); return true; } @@ -92,7 +92,7 @@ class TimeCommand extends VanillaCommand{ if($args[0] === "set"){ if(!$sender->hasPermission("pocketmine.command.time.set")){ - $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission")); + $sender->sendMessage($sender->getServer()->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission")); return true; } @@ -111,7 +111,7 @@ class TimeCommand extends VanillaCommand{ Command::broadcastCommandMessage($sender, new TranslationContainer("commands.time.set", [$value])); }elseif($args[0] === "add"){ if(!$sender->hasPermission("pocketmine.command.time.add")){ - $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission")); + $sender->sendMessage($sender->getServer()->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission")); return true; } diff --git a/src/pocketmine/command/defaults/WhitelistCommand.php b/src/pocketmine/command/defaults/WhitelistCommand.php index 81fb16f0bf..ddf43866cd 100644 --- a/src/pocketmine/command/defaults/WhitelistCommand.php +++ b/src/pocketmine/command/defaults/WhitelistCommand.php @@ -117,7 +117,7 @@ class WhitelistCommand extends VanillaCommand{ private function badPerm(CommandSender $sender, string $perm) : bool{ if(!$sender->hasPermission("pocketmine.command.whitelist.$perm")){ - $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission")); + $sender->sendMessage($sender->getServer()->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission")); return true; } From 95313e0a9025f8a4c7f4fc7a3ed40a1831f5ae29 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 8 Apr 2019 14:42:33 +0100 Subject: [PATCH 2/4] Updated some entity metadata properties --- src/pocketmine/entity/Entity.php | 44 ++++++++++++++----- src/pocketmine/entity/Human.php | 7 --- .../entity/projectile/Projectile.php | 2 - 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index c72116386c..8bd32e06ee 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -107,6 +107,10 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ public const DATA_TYPE_LONG = 7; public const DATA_TYPE_VECTOR3F = 8; + /* + * Readers beware: this isn't a nice list. Some of the properties have different types for different entities, and + * are used for entirely different things. + */ public const DATA_FLAGS = 0; public const DATA_HEALTH = 1; //int (minecart/boat) public const DATA_VARIANT = 2; //int @@ -124,17 +128,21 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ public const DATA_PADDLE_TIME_RIGHT = 14; //float public const DATA_EXPERIENCE_VALUE = 15; //int (xp orb) public const DATA_MINECART_DISPLAY_BLOCK = 16; //int (id | (data << 16)) + public const DATA_HORSE_FLAGS = 16; //int + /* 16 (byte) used by wither skull */ public const DATA_MINECART_DISPLAY_OFFSET = 17; //int + public const DATA_SHOOTER_ID = 17; //long (used by arrows) public const DATA_MINECART_HAS_DISPLAY = 18; //byte (must be 1 for minecart to show block inside) - - //TODO: add more properties - + public const DATA_HORSE_TYPE = 19; //byte + /* 20 (unknown) + * 21 (unknown) */ + public const DATA_CHARGE_AMOUNT = 22; //int8, used for ghasts and also crossbow charging public const DATA_ENDERMAN_HELD_ITEM_ID = 23; //short public const DATA_ENTITY_AGE = 24; //short - - /* 26 (byte) player-specific flags - * 27 (int) player "index"? - * 28 (block coords) bed position */ + /* 25 (int) used by horse, (byte) used by witch */ + public const DATA_PLAYER_FLAGS = 26; //byte + public const DATA_PLAYER_INDEX = 27; //int, used for marker colours and agent nametag colours + public const DATA_PLAYER_BED_POSITION = 28; //blockpos public const DATA_FIREBALL_POWER_X = 29; //float public const DATA_FIREBALL_POWER_Y = 30; public const DATA_FIREBALL_POWER_Z = 31; @@ -145,7 +153,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ public const DATA_POTION_AUX_VALUE = 36; //short public const DATA_LEAD_HOLDER_EID = 37; //long public const DATA_SCALE = 38; //float - public const DATA_INTERACTIVE_TAG = 39; //string (button text) + public const DATA_HAS_NPC_COMPONENT = 39; //byte (???) public const DATA_NPC_SKIN_ID = 40; //string public const DATA_URL_TAG = 41; //string public const DATA_MAX_AIR = 42; //short @@ -195,8 +203,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ public const DATA_BOAT_BUBBLE_TIME = 86; //int (time in bubble column) public const DATA_PLAYER_AGENT_EID = 87; //long /* 88 (float) related to panda sitting - * 89 (float) related to panda sitting - * 90 (unknown) */ + * 89 (float) related to panda sitting */ + public const DATA_EAT_COUNTER = 90; //int (used by pandas) public const DATA_FLAGS2 = 91; //long (extended data flags) /* 92 (float) related to panda lying down * 93 (float) related to panda lying down */ @@ -205,7 +213,9 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ public const DATA_AREA_EFFECT_CLOUD_RADIUS_PER_TICK = 96; //float, usually negative public const DATA_AREA_EFFECT_CLOUD_RADIUS_CHANGE_ON_PICKUP = 97; //float public const DATA_AREA_EFFECT_CLOUD_PICKUP_COUNT = 98; //int - + public const DATA_INTERACTIVE_TAG = 99; //string (button text) + public const DATA_TRADE_TIER = 100; //int + public const DATA_MAX_TRADE_TIER = 101; //int public const DATA_FLAG_ONFIRE = 0; public const DATA_FLAG_SNEAKING = 1; @@ -278,6 +288,18 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ public const DATA_FLAG_IN_SCAFFOLDING = 68; public const DATA_FLAG_OVER_SCAFFOLDING = 69; public const DATA_FLAG_FALL_THROUGH_SCAFFOLDING = 70; + public const DATA_FLAG_BLOCKING = 71; //shield + public const DATA_FLAG_DISABLE_BLOCKING = 72; + //73 is set when a player is attacked while using shield, unclear on purpose + public const DATA_FLAG_SLEEPING = 74; + //75 related to sleeping, unclear usage + public const DATA_FLAG_TRADE_INTEREST = 76; + public const DATA_FLAG_DOOR_BREAKER = 77; //... + public const DATA_FLAG_BREAKING_OBSTRUCTION = 78; + public const DATA_FLAG_DOOR_OPENER = 79; //... + + public const DATA_PLAYER_FLAG_SLEEP = 1; + public const DATA_PLAYER_FLAG_DEAD = 2; //TODO: CHECK public static $entityCount = 1; /** @var Entity[] */ diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index d24b4f5365..1ab41d691f 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -70,13 +70,6 @@ use const INT32_MIN; class Human extends Creature implements ProjectileSource, InventoryHolder{ - public const DATA_PLAYER_FLAG_SLEEP = 1; - public const DATA_PLAYER_FLAG_DEAD = 2; //TODO: CHECK - - public const DATA_PLAYER_FLAGS = 26; - - public const DATA_PLAYER_BED_POSITION = 28; - /** @var PlayerInventory */ protected $inventory; diff --git a/src/pocketmine/entity/projectile/Projectile.php b/src/pocketmine/entity/projectile/Projectile.php index c1bb3e881a..2544f79ed0 100644 --- a/src/pocketmine/entity/projectile/Projectile.php +++ b/src/pocketmine/entity/projectile/Projectile.php @@ -50,8 +50,6 @@ use const PHP_INT_MAX; abstract class Projectile extends Entity{ - public const DATA_SHOOTER_ID = 17; - /** @var float */ protected $damage = 0.0; From 383ec8a8e3a167f332bb97f1c6260fb03ca23eea Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 8 Apr 2019 15:45:26 +0100 Subject: [PATCH 3/4] TextFormat: Fixed tokenize() not being Unicode-aware --- src/pocketmine/utils/TextFormat.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/utils/TextFormat.php b/src/pocketmine/utils/TextFormat.php index 6e5f817e95..90d1441d83 100644 --- a/src/pocketmine/utils/TextFormat.php +++ b/src/pocketmine/utils/TextFormat.php @@ -74,7 +74,7 @@ abstract class TextFormat{ * @return array */ public static function tokenize(string $string) : array{ - return preg_split("/(" . TextFormat::ESCAPE . "[0-9a-fk-or])/", $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); + return preg_split("/(" . TextFormat::ESCAPE . "[0-9a-fk-or])/u", $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); } /** From 3925e598d60d16b8cb374a43e3554fa09f4fc402 Mon Sep 17 00:00:00 2001 From: Dylan T Date: Mon, 8 Apr 2019 20:31:24 +0100 Subject: [PATCH 4/4] Acquire exclusive lock on /server.lock to avoid data corruption (#2858) this fixes #2855. --- src/pocketmine/PocketMine.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index dbb5277061..d1168645cf 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -189,6 +189,14 @@ namespace pocketmine { mkdir(\pocketmine\DATA, 0777, true); } + define('pocketmine\LOCK_FILE_PATH', \pocketmine\DATA . 'server.lock'); + define('pocketmine\LOCK_FILE', fopen(\pocketmine\LOCK_FILE_PATH, "cb")); + if(!flock(\pocketmine\LOCK_FILE, LOCK_EX | LOCK_NB)){ + critical_error("Another " . \pocketmine\NAME . " instance is already using this folder (" . realpath(\pocketmine\DATA) . ")."); + critical_error("Please stop the other server first before running a new one."); + exit(1); + } + //Logger has a dependency on timezone $tzError = Timezone::init();