clrghouz/app/Console/Commands/CommEMSIReceive.php

54 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2021-04-01 10:59:15 +00:00
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
2021-07-02 13:44:01 +00:00
use App\Classes\Protocol\EMSI;
use App\Classes\Sock\Exception\SocketException;
2021-04-01 10:59:15 +00:00
use App\Classes\Sock\SocketServer;
use App\Models\Setup;
2021-04-01 10:59:15 +00:00
class CommEMSIReceive extends Command
2021-04-01 10:59:15 +00:00
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'comm:emsi:receive';
2021-04-01 10:59:15 +00:00
/**
* The console command description.
*
* @var string
*/
protected $description = 'EMSI receive';
/**
* Execute the console command.
*
* @return mixed
* @throws \Exception
2021-04-01 10:59:15 +00:00
*/
public function handle()
{
Log::info('Listening for EMSI connections...');
$o = Setup::findOrFail(config('app.id'));
2021-04-01 10:59:15 +00:00
2023-07-31 09:14:27 +00:00
$server = new SocketServer($o->emsi_port,$o->emsi_bind);
$server->handler = [new EMSI,'onConnect'];
2021-04-01 10:59:15 +00:00
try {
$server->listen();
} catch (SocketException $e) {
2023-06-27 07:39:11 +00:00
if ($e->getMessage() === 'Can\'t accept connections: "Success"')
2021-04-01 10:59:15 +00:00
Log::debug('Server Terminated');
else
Log::emergency('Uncaught Message: '.$e->getMessage());
}
}
}