clrghouz/app/Console/Commands/PacketProcess.php

55 lines
1.3 KiB
PHP

<?php
namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
use App\Classes\File;
use App\Classes\FTN\Packet;
use App\Jobs\MessageProcess as Job;
use App\Models\Address;
class PacketProcess extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'packet:process'
.' {file : Packet to process}'
.' {--N|nobot : Dont process bots}'
.' {ftn : System the packet is from}';
/**
* 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('file'));
$a = Address::findFTN($this->argument('ftn'));
foreach ($f as $packet) {
foreach (Packet::process($packet,$f->itemName(),$f->itemSize(),$a->system) as $msg) {
// @todo Quick check that the packet should be processed by us.
// @todo validate that the packet's zone is in the domain.
$this->info(sprintf('Processing message from [%s] with msgid [%s] in (%s)',$msg->fboss,$msg->msgid,$f->pktName()));
// Dispatch job.
Job::dispatchSync($msg,$f->pktName(),$a,$a,Carbon::now(),$this->option('nobot'));
}
}
}
}