mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-11 14:38:39 +00:00
Changing logging
This commit is contained in:
parent
401e251f4c
commit
24089965e7
|
|
@ -71,19 +71,6 @@ class Server extends SocketAbstract
|
||||||
*/
|
*/
|
||||||
private $app = null;
|
private $app = null;
|
||||||
|
|
||||||
public static function hasInternet() : bool
|
|
||||||
{
|
|
||||||
$connected = @fsockopen("www.google.com", 80);
|
|
||||||
|
|
||||||
if ($connected) {
|
|
||||||
fclose($connected);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
|
@ -99,14 +86,35 @@ class Server extends SocketAbstract
|
||||||
$this->packetManager = new PacketManager(new CommandManager(), new ClientManager());
|
$this->packetManager = new PacketManager(new CommandManager(), new ClientManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has internet connection.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public static function hasInternet() : bool
|
||||||
|
{
|
||||||
|
$connected = @fsockopen("www.google.com", 80);
|
||||||
|
|
||||||
|
if ($connected) {
|
||||||
|
fclose($connected);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function create(string $ip, int $port)
|
public function create(string $ip, int $port)
|
||||||
{
|
{
|
||||||
$this->app->logger->console('Creating socket...', $this->verbose);
|
$this->app->logger->info('Creating socket...');
|
||||||
parent::create($ip, $port);
|
parent::create($ip, $port);
|
||||||
$this->app->logger->console('Binding socket...', $this->verbose);
|
$this->app->logger->info('Binding socket...');
|
||||||
socket_bind($this->sock, $this->ip, $this->port);
|
socket_bind($this->sock, $this->ip, $this->port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,6 +135,9 @@ class Server extends SocketAbstract
|
||||||
|
|
||||||
public function handshake($client, $headers)
|
public function handshake($client, $headers)
|
||||||
{
|
{
|
||||||
|
// todo: different handshake for normal tcp connection
|
||||||
|
return true;
|
||||||
|
|
||||||
if (preg_match("/Sec-WebSocket-Version: (.*)\r\n/", $headers, $match)) {
|
if (preg_match("/Sec-WebSocket-Version: (.*)\r\n/", $headers, $match)) {
|
||||||
$version = $match[1];
|
$version = $match[1];
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -172,12 +183,12 @@ class Server extends SocketAbstract
|
||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
$this->app->logger->console('Start listening...', $this->verbose);
|
$this->app->logger->info('Start listening...');
|
||||||
socket_listen($this->sock);
|
socket_listen($this->sock);
|
||||||
socket_set_nonblock($this->sock);
|
socket_set_nonblock($this->sock);
|
||||||
$this->conn[] = $this->sock;
|
$this->conn[] = $this->sock;
|
||||||
|
|
||||||
$this->app->logger->console('Start running...', $this->verbose);
|
$this->app->logger->info('Start running...');
|
||||||
while ($this->run) {
|
while ($this->run) {
|
||||||
$read = $this->conn;
|
$read = $this->conn;
|
||||||
|
|
||||||
|
|
@ -200,11 +211,11 @@ class Server extends SocketAbstract
|
||||||
$data = socket_read($socket, 1024);
|
$data = socket_read($socket, 1024);
|
||||||
|
|
||||||
if (!$client->getHandshake()) {
|
if (!$client->getHandshake()) {
|
||||||
$this->app->logger->console('Doing handshake...', $this->verbose);
|
$this->app->logger->debug('Doing handshake...');
|
||||||
if ($this->handshake($client, $data)) {
|
if ($this->handshake($client, $data)) {
|
||||||
$this->app->logger->console('Handshake succeeded.', $this->verbose);
|
$this->app->logger->debug('Handshake succeeded.');
|
||||||
} else {
|
} else {
|
||||||
$this->app->logger->console('Handshake failed.', $this->verbose);
|
$this->app->logger->debug('Handshake failed.');
|
||||||
$this->disconnectClient($client);
|
$this->disconnectClient($client);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -219,15 +230,15 @@ class Server extends SocketAbstract
|
||||||
|
|
||||||
public function connectClient($socket)
|
public function connectClient($socket)
|
||||||
{
|
{
|
||||||
$this->app->logger->console('Connecting client...', $this->verbose);
|
$this->app->logger->debug('Connecting client...');
|
||||||
$this->clientManager->add($client = new ClientConnection(uniqid(), $socket));
|
$this->clientManager->add($client = new ClientConnection(uniqid(), $socket));
|
||||||
$this->conn[$client->getId()] = $socket;
|
$this->conn[$client->getId()] = $socket;
|
||||||
$this->app->logger->console('Connected client.', $this->verbose);
|
$this->app->logger->debug('Connected client.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function disconnectClient($client)
|
public function disconnectClient($client)
|
||||||
{
|
{
|
||||||
$this->app->logger->console('Disconnecting client...', $this->verbose);
|
$this->app->logger->debug('Disconnecting client...');
|
||||||
$client->setConnected(false);
|
$client->setConnected(false);
|
||||||
$client->setHandshake(false);
|
$client->setHandshake(false);
|
||||||
socket_shutdown($client->getSocket(), 2);
|
socket_shutdown($client->getSocket(), 2);
|
||||||
|
|
@ -238,7 +249,7 @@ class Server extends SocketAbstract
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->clientManager->remove($client->getId());
|
$this->clientManager->remove($client->getId());
|
||||||
$this->app->logger->console('Disconnected client.', $this->verbose);
|
$this->app->logger->debug('Disconnected client.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ abstract class SocketAbstract implements SocketInterface
|
||||||
$this->ip = $ip;
|
$this->ip = $ip;
|
||||||
$this->port = $port;
|
$this->port = $port;
|
||||||
|
|
||||||
|
// todo: if local network connect use AF_UNIX
|
||||||
$this->sock = \socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
$this->sock = \socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user