Skip to content

Commit

Permalink
Finished identification for MonitoredWebsiteData
Browse files Browse the repository at this point in the history
  • Loading branch information
Falkirks committed Dec 20, 2014
1 parent 4f0ccd1 commit 4840cba
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
7 changes: 3 additions & 4 deletions src/volt/ServerTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public function __construct($path, \ClassLoader $loader, \Logger $logger) {
print "socket_listen() failed: reason: " . socket_strerror(socket_last_error($this->sock)) . "\n";
$this->stop();
}
$this->getLogger()->info("[SUCCESS] HTTP Server Status: " . TextFormat::GREEN . "Active" . TextFormat::WHITE . " on port " . volt::$serverConfig->get("server-port") . "\n");
$this->getLogger()->info("[SUCCESS] Server Status: " . TextFormat::GREEN . "Active" . TextFormat::WHITE . " on port " . volt::$serverConfig->get("server-port") . "\n");
$this->start();
}
public function stop() {
$this->getLogger()->warning("HTTP Server Status: " . TextFormat::RED . "Stopped\n");
$this->getLogger()->info("Server Status: " . TextFormat::RED . "Stopped\n");
$this->stop = true;
}
public function run() {
Expand Down Expand Up @@ -111,5 +111,4 @@ public function setValue($name, $value){
public function getLogger(){
return $this->logger;
}
}

}
23 changes: 4 additions & 19 deletions src/volt/Volt.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php
namespace volt;

use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;
use pocketmine\utils\TextFormat;
use volt\api\DynamicPage;
use volt\api\MonitoredWebsiteData;

class Volt extends PluginBase{
/** @var Config */
Expand All @@ -16,29 +17,13 @@ public function onEnable(){
$this->getLogger()->warning("Volt 3.0 preview is mystical, magical and " . TextFormat::RED . "buggy" . TextFormat::YELLOW . ".");
if(!is_dir($this->getServer()->getDataPath() . "volt")) mkdir($this->getServer()->getDataPath() . "volt");
$this->server = new ServerTask($this->getServer()->getDataPath() . "volt", $this->getServer()->getLoader(), $this->getServer()->getLogger());
/*if ($this->server->stop === false){
$this->task = new PostCollectionTask($this);
$this->getServer()->getScheduler()->scheduleRepeatingTask($this->task, 5);
}*/

(new MonitoredWebsiteData());
}
public function addValue($n, $v){
/*if($this->server instanceof ServerTask){
$this->server->synchronized(function($thread, $n, $v){
$c = unserialize($thread->vars);
$c[$n] = $v;
$thread->vars = serialize($c);
}, $this->server, $n, $v);
return true;
}
return false;*/
$this->getLogger()->warning(TextFormat::DARK_AQUA . 'addValue($n, $v)' . TextFormat::RESET . TextFormat::YELLOW . " is no longer supported.");
}
public function bindTo($n, Callable $func){
/*if($this->server instanceof ServerTask){
$this->bound[$n][] = $func;
return true;
}
return false;*/
$this->getLogger()->warning(TextFormat::DARK_AQUA . 'bindTo($n, Callable $func)' . TextFormat::RESET . TextFormat::YELLOW . " is no longer supported.");
}
public function getVoltServer(){
Expand Down
23 changes: 21 additions & 2 deletions src/volt/api/MonitoredWebsiteData.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,30 @@
namespace volt\api;

use pocketmine\plugin\PluginBase;
use pocketmine\Server;
use volt\exception\PluginIdentificationException;

class MonitoredWebsiteData extends WebsiteData{

final public function __construct($name){
$this->name = ($name instanceof PluginBase ? $name->getName() : $name);
final public function __construct($name = false){
if($name == false){
$trace = debug_backtrace();
if (isset($trace[1])) {
$fullClass = explode("\\", $trace[1]['class']);
$name = array_pop($fullClass);

}
}

if($name instanceof PluginBase) {
$this->name = $name->getName();
}
else{
if(Server::getInstance()->getPluginManager()->getPlugin($name) instanceof PluginBase){
$this->name = $name;
}
}
if($this->name == null) throw new PluginIdentificationException;
parent::__construct();
}

Expand Down
6 changes: 6 additions & 0 deletions src/volt/exception/PluginIdentificationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
namespace volt\exception;

class PluginIdentificationException extends \Exception{

}

0 comments on commit 4840cba

Please sign in to comment.