2021-07-15 14:54:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Symfony\Component\HttpFoundation\File\File;
|
|
|
|
|
|
|
|
use App\Classes\FTN\Packet;
|
2021-09-06 13:39:32 +00:00
|
|
|
use App\Jobs\MessageProcess as Job;
|
2021-08-29 14:24:40 +00:00
|
|
|
use App\Models\Zone;
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2021-08-29 14:24:40 +00:00
|
|
|
class PacketProcess extends Command
|
2021-07-15 14:54:23 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2021-09-10 14:38:11 +00:00
|
|
|
protected $signature = 'packet:process'
|
|
|
|
.' {pkt : Packet to process}'
|
|
|
|
.' {--N|nobot : Dont process bots}'
|
|
|
|
.' {zone? : Zone the packet is from}';
|
2021-07-15 14:54:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Process Packet';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
* @throws \App\Classes\FTN\InvalidPacketException
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$f = new File($this->argument('pkt'));
|
2021-08-29 14:24:40 +00:00
|
|
|
$z = $this->argument('zone') ? Zone::where('zone_id',$this->argument('zone'))->singleOrFail() : NULL;
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2021-08-29 14:24:40 +00:00
|
|
|
foreach (Packet::open($f,$z) as $msg) {
|
2021-07-15 14:54:23 +00:00
|
|
|
// @todo Quick check that the packet should be processed by us.
|
|
|
|
// @todo validate that the packet's zone is in the domain.
|
|
|
|
|
2021-09-12 13:06:17 +00:00
|
|
|
$this->info(sprintf('Processing message from [%s] with msgid [%s]',$msg->fboss,$msg->msgid));
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
// Dispatch job.
|
2021-11-21 05:53:56 +00:00
|
|
|
Job::dispatchSync($msg,$this->option('nobot'));
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|