2019-03-03 14:29:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Classes;
|
|
|
|
|
2021-08-29 13:58:12 +00:00
|
|
|
use App\Models\{Address,Zone};
|
2021-06-29 10:43:29 +00:00
|
|
|
|
2019-03-03 14:29:35 +00:00
|
|
|
abstract class FTN
|
|
|
|
{
|
2021-08-29 13:58:12 +00:00
|
|
|
protected ?Zone $zone; // Zone the packet is from
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2023-09-05 09:57:34 +00:00
|
|
|
public function __get(string $key)
|
2021-06-29 10:43:29 +00:00
|
|
|
{
|
|
|
|
switch ($key) {
|
2024-05-17 12:10:54 +00:00
|
|
|
case 'fftn_t':
|
2021-06-29 10:43:29 +00:00
|
|
|
return sprintf('%d:%d/%d.%d',
|
|
|
|
$this->fz,
|
|
|
|
$this->fn,
|
|
|
|
$this->ff,
|
|
|
|
$this->fp,
|
2024-07-11 13:33:17 +00:00
|
|
|
).((isset($this->zone) && $this->zone) ? sprintf('@%s',$this->zone->domain->name) : '');
|
2021-06-29 10:43:29 +00:00
|
|
|
|
2024-05-17 12:10:54 +00:00
|
|
|
case 'tftn_t':
|
2021-06-29 10:43:29 +00:00
|
|
|
return sprintf('%d:%d/%d.%d',
|
|
|
|
$this->tz,
|
|
|
|
$this->tn,
|
|
|
|
$this->tf,
|
|
|
|
$this->tp,
|
2024-07-11 13:33:17 +00:00
|
|
|
).((isset($this->zone) && $this->zone) ? sprintf('@%s',$this->zone->domain->name) : '');
|
2021-06-29 10:43:29 +00:00
|
|
|
|
2024-05-17 12:10:54 +00:00
|
|
|
case 'fftn':
|
|
|
|
return Address::findFTN($this->fftn_t);
|
|
|
|
case 'tftn':
|
|
|
|
return Address::findFTN($this->tftn_t);
|
2021-08-18 14:20:34 +00:00
|
|
|
|
2021-06-29 10:43:29 +00:00
|
|
|
default:
|
|
|
|
throw new \Exception('Unknown key: '.$key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 14:29:35 +00:00
|
|
|
/**
|
|
|
|
* This function creates our unpack header
|
2021-06-29 10:43:29 +00:00
|
|
|
*
|
|
|
|
* @param array $pack
|
2019-03-03 14:29:35 +00:00
|
|
|
* @return string
|
2023-06-27 07:39:11 +00:00
|
|
|
* @throws \Exception
|
2019-03-03 14:29:35 +00:00
|
|
|
*/
|
2021-07-15 14:54:23 +00:00
|
|
|
protected static function unpackheader(array $pack): string
|
2019-03-03 14:29:35 +00:00
|
|
|
{
|
2023-06-25 10:45:02 +00:00
|
|
|
// Check that our header is correct
|
|
|
|
if (app()->environment('local')) {
|
|
|
|
$c = 0;
|
|
|
|
foreach (collect($pack) as $item) {
|
|
|
|
if ($c !== $item[0])
|
|
|
|
throw new \Exception('Invalid header');
|
|
|
|
|
|
|
|
$c += $item[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return collect($pack)
|
|
|
|
->sortBy(function($k,$v) {return $k[0];})
|
|
|
|
->transform(function($k,$v) {return $k[1].$v;})
|
|
|
|
->values()
|
|
|
|
->join('/');
|
2019-03-03 14:29:35 +00:00
|
|
|
}
|
|
|
|
}
|