Update Spoondetector

This commit is contained in:
Matthew 2018-02-05 01:34:31 +01:00
parent 8ac1ac4a06
commit 4a41edef68

View File

@ -1,5 +1,4 @@
<?php
namespace Matthww\PlayerInfo\utils;
use pocketmine\plugin\PluginBase;
@ -10,7 +9,7 @@ use pocketmine\Server;
* Class SpoonDetector
* @package Matthww\PlayerInfo\utils\SpoonDetector
*/
class SpoonDetector {
final class SpoonDetector{
private static $subtleAsciiSpoon = "
___ _ __ ___ ___ _ __
@ -32,29 +31,64 @@ class SpoonDetector {
Have you read and understood the above (type 'yes' after the question mark)?";
private static $thingsThatAreNotSpoons = [
const THINGS_THAT_ARE_NOT_SPOONS = [
'PocketMine-MP'
];
public static function isThisSpoon(): bool {
return !in_array(Server::getInstance()->getName(), self::$thingsThatAreNotSpoons);
public final static function simpleCheck(Server $server) : bool {
return !in_array(Server::getInstance()->getName(), SpoonDetector::THINGS_THAT_ARE_NOT_SPOONS);
}
private static function contentValid(string $content): bool {
public static final function contentCheck(Server $server): bool{
$reflectionClass = new \ReflectionClass($server);
$method = $reflectionClass->getMethod("getName");
$start = $method->getStartLine();
$end = $method->getEndLine();
$filename = $method->getFileName();
$length = $end - $start;
$source = file($filename);
$body = implode("", array_slice($source, $start, $length));
if(strpos($body, "(") !== false || strpos($body, ")") !== false){
$server->getLogger()->info("Your server may be attempting to block SpoonDetector from running. SpoonDetector will continue to run regardless. If you are the developer of this spoon would like to be exempted from spoon detection, create a new API versioning system so existing PM plugins don't run, and then create an issue at Falkirks/spoondetector.");
return true;
}
foreach ($source as $line){
if(strpos($line, "SpoonDetector") !== false){
$server->getLogger()->info("Your server may be attempting to block SpoonDetector from running. SpoonDetector will continue to run regardless. If you are the developer of this spoon would like to be exempted from spoon detection, create a new API versioning system so existing PM plugins don't run, and then create an issue at Falkirks/spoondetector.");
return true;
}
}
return false;
}
public final static function isThisSpoon() : bool {
$server = Server::getInstance();
return self::simpleCheck($server) || self::contentCheck($server);
}
private final static function contentValid(string $content): bool {
return (strpos($content, self::$spoonTxtContent) !== false) && (strrpos($content, "yes") > strrpos($content, "?"));
}
public static function printSpoon(PluginBase $pluginBase, $fileToCheck = "spoon.txt") {
if (self::isThisSpoon()) {
if (!file_exists($pluginBase->getDataFolder() . $fileToCheck)) {
public final static function printSpoon(PluginBase $pluginBase, $fileToCheck = "spoon.txt"){
if(self::isThisSpoon()){
if(!file_exists($pluginBase->getDataFolder() . $fileToCheck)){
file_put_contents($pluginBase->getDataFolder() . $fileToCheck, self::$spoonTxtContent);
}
if (!self::contentValid(file_get_contents($pluginBase->getDataFolder() . $fileToCheck))) {
if(!self::contentValid(file_get_contents($pluginBase->getDataFolder() . $fileToCheck))) {
$pluginBase->getLogger()->info(self::$subtleAsciiSpoon);
$pluginBase->getLogger()->warning("You are attempting to run " . $pluginBase->getDescription()->getName() . " on a SPOON!");
$pluginBase->getLogger()->warning("Before using the plugin you will need to open /plugins/" . $pluginBase->getDescription()->getName() . "/" . $fileToCheck . " in a text editor and agree to the terms.");
$pluginBase->getServer()->getPluginManager()->disablePlugin($pluginBase);
return false;
}
}
return true;
}
}
}