Skip to content

Commit

Permalink
Fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Humerus committed Dec 25, 2015
2 parents a38dca2 + d8f20f8 commit 770957d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/PocketDockConsole/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public function sendFiles() {

public function onDisable() {
$this->getLogger()->info(TextFormat::DARK_RED . "Disabled");
$this->getServer()->getLogger()->removeAttachment($this->attachment);
//$this->getServer()->getLogger()->removeAttachment($this->attachment);
ThreadManager::getInstance()->remove($this->thread);
$this->thread->kill();
$this->thread->stop();
}

}
35 changes: 27 additions & 8 deletions src/PocketDockConsole/PDCServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PDCServer extends \pocketmine\Thread {
public $stuffToSend = "";
public $jsonStream = "";
public $stuffTitle = "";
public $loadPaths = array();
public $stop = false;

public function __construct($host, $port, $logger, $loader, $password, $html, $backlog, $legacy = false) {
$this->host = $host;
Expand All @@ -25,12 +25,12 @@ public function __construct($host, $port, $logger, $loader, $password, $html, $b
$this->data = $html;
$this->backlog = $backlog;
$this->clienttokill = "";
$this->sendUpate = false;
$this->sendUpate = false;;
$this->legacy = $legacy;
$loadPaths = array();
$this->addDependency($loadPaths, new \ReflectionClass($logger));
$this->addDependency($loadPaths, new \ReflectionClass($loader));
$this->loadPaths = array_reverse($loadPaths);
$oldloadPaths = array();
$this->addDependency($oldloadPaths, new \ReflectionClass($logger));
$this->addDependency($oldloadPaths, new \ReflectionClass($loader));
$this->loadPaths = array_reverse($oldloadPaths);
$this->start(PTHREADS_INHERIT_ALL & ~PTHREADS_INHERIT_CLASSES);
$this->log("Started SocksServer on " . $this->host . ":" . $this->port);
}
Expand All @@ -54,17 +54,25 @@ public function getBuffer() {
}

public function run() {
set_exception_handler(function ($ex) {
//var_dump($ex);
$this->logger->debug($ex->getMessage());
});

foreach ($this->loadPaths as $name => $path) {
if (!class_exists($name, false) and !interface_exists($name, false)) {
require ($path);
}
}
$this->loader->register(true);

if (!$this->legacy) {
Terminal::init();
}

$server = new \Wrench\Server('ws://' . $this->host . ':' . $this->port, array("logger" => function ($msg, $pri) {
}));
}), $this);

$server->registerApplication("app", new PDCApp($this, $this->password));
$server->addListener(\Wrench\Server::EVENT_SOCKET_CONNECT, function ($data, $other) {
$header = $other->getSocket()->receive();
Expand All @@ -75,7 +83,14 @@ public function run() {
$other->onData($header);
}
});
$server->run();

while($this->stop !== true) {
try {
$server->run();
} catch (\Exception $e) {

}
}
}

public function isHTTP($data) {
Expand All @@ -86,6 +101,10 @@ public function isHTTP($data) {
}
}

public function stop() {
$this->stop = true;
}

public function log($data) {
$this->logger->info("[PDC] " . $data);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Wrench/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ class Server extends Configurable
* be ignored
* @param array $options (optional) See configure
*/
public function __construct($uri, array $options = array())
public function __construct($uri, array $options = array(), $thread)
{
$this->uri = $uri;
$this->thread = $thread;

parent::__construct($options);

Expand Down Expand Up @@ -189,7 +190,7 @@ public function run()
{
$this->connectionManager->listen();

while (true) {
while ($this->thread->stop !== true) {
/*
* If there's nothing changed on any of the sockets, the server
* will sleep and other processes will have a change to run. Control
Expand Down

0 comments on commit 770957d

Please sign in to comment.